forked from chilek/lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemoninstanceedit.php
103 lines (87 loc) · 3.61 KB
/
daemoninstanceedit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2016 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id$
*/
$id = intval($_GET['id']);
$instance = $DB->GetRow('SELECT id, name, hostid, description, module, crontab, priority, disabled FROM daemoninstances WHERE id=?', array($id));
$layout['pagetitle'] = trans('Instance Edit: $a', $instance['name']);
if(isset($_POST['instance']))
{
$instedit = $_POST['instance'];
foreach($instedit as $idx => $key)
$instedit[$idx] = trim($key);
$instedit['id'] = $instance['id'];
if($instedit['name'] == '')
$error['name'] = trans('Instance name is required!');
elseif($instedit['name']!=$instance['name'])
if($DB->GetOne('SELECT id FROM daemoninstances WHERE name=? AND hostid=?', array($instedit['name'], $instedit['hostid'])))
$error['name'] = trans('Instance with specified name exists on that host!');
if($instedit['module'] == '')
$error['module'] = trans('Instance module is required!');
if(!$instedit['hostid'])
$error['hostid'] = trans('Instance host is required!');
if($instedit['crontab'] != '' && !preg_match('/^[0-9\/\*,-]+[ \t][0-9\/\*,-]+[ \t][0-9\/\*,-]+[ \t][0-9\/\*,-]+[ \t][0-9\/\*,-]+$/', $instedit['crontab']))
$error['crontab'] = trans('Incorrect crontab format!');
if(!isset($instedit['disabled'])) $instedit['disabled'] = 0;
if($instedit['priority'] == '')
$instedit['priority'] = 0;
elseif(!is_numeric($instedit['priority']))
$error['priority'] = trans('Priority must be integer!');
if (!$error) {
$args = array(
'name' => $instedit['name'],
SYSLOG::RES_HOST => $instedit['hostid'],
'description' => $instedit['description'],
'module' => $instedit['module'],
'crontab' => $instedit['crontab'],
'priority' => $instedit['priority'],
'disabled' => $instedit['disabled'],
SYSLOG::RES_DAEMONINST => $instedit['id']
);
$DB->Execute('UPDATE daemoninstances SET name=?, hostid=?, description=?, module=?, crontab=?, priority=?, disabled=? WHERE id=?',
array_values($args));
if ($SYSLOG)
$SYSLOG->AddMessage(SYSLOG::RES_DAEMONINST, SYSLOG::OPER_UPDATE, $args);
$SESSION->redirect('?m=daemoninstancelist');
}
} elseif(isset($_GET['statuschange'])) {
if ($SYSLOG) {
$args = array(
SYSLOG::RES_DAEMONINST => $id,
SYSLOG::RES_HOST => $instance['hostid'],
'disabled' => $instance['disabled'] ? 0 : 1
);
$SYSLOG->AddMessage(SYSLOG::RES_DAEMONINST, SYSLOG::OPER_UPDATE, $args);
}
if($instance['disabled'])
$DB->Execute('UPDATE daemoninstances SET disabled=0 WHERE id=?', array($id));
else
$DB->Execute('UPDATE daemoninstances SET disabled=1 WHERE id=?', array($id));
$SESSION->redirect('?m=daemoninstancelist');
}
$SESSION->save('backto', $_SERVER['QUERY_STRING']);
$SMARTY->assign('error', $error);
$SMARTY->assign('instance', isset($instedit) ? $instedit : $instance);
$SMARTY->assign('hosts', $DB->GetAll('SELECT id, name FROM hosts ORDER BY name'));
$SMARTY->display('daemon/daemoninstanceedit.html');
?>