-
Notifications
You must be signed in to change notification settings - Fork 3
/
applications.php
404 lines (340 loc) · 12.6 KB
/
applications.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php
/*
** ZABBIX
** Copyright (C) 2000-2010 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
?>
<?php
require_once('include/config.inc.php');
require_once('include/hosts.inc.php');
require_once('include/forms.inc.php');
$page['title'] = 'S_APPLICATIONS';
$page['file'] = 'applications.php';
$page['hist_arg'] = array('groupid', 'hostid');
$page['scripts'] = array();
include_once('include/page_header.php');
?>
<?php
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields=array(
'hosts'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'groups'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'hostids'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'groupids'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'applications'=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'hostid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
'groupid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
// application
'applicationid'=> array(T_ZBX_INT,O_OPT, P_SYS, DB_ID, 'isset({form})&&({form}=="update")'),
'appname'=> array(T_ZBX_STR, O_NO, NULL, NOT_EMPTY, 'isset({save})'),
'apphostid'=> array(T_ZBX_INT, O_OPT, NULL, DB_ID.'{}>0', 'isset({save})'),
'apptemplateid'=> array(T_ZBX_INT,O_OPT, NULL, DB_ID, NULL),
// actions
'go'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
// form
'add_to_group'=> array(T_ZBX_INT, O_OPT, P_SYS|P_ACT, DB_ID, NULL),
'delete_from_group'=> array(T_ZBX_INT, O_OPT, P_SYS|P_ACT, DB_ID, NULL),
'save'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'clone'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'delete'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
'cancel'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
/* other */
'form'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
'form_refresh'=>array(T_ZBX_STR, O_OPT, NULL, NULL, NULL)
);
check_fields($fields);
validate_sort_and_sortorder('name', ZBX_SORT_UP);
$_REQUEST['go'] = get_request('go', 'none');
// PERMISSIONS
if(get_request('groupid', 0) > 0){
$groupids = available_groups($_REQUEST['groupid'], 1);
if(empty($groupids)) access_deny();
}
if(get_request('hostid', 0) > 0){
$hostids = available_hosts($_REQUEST['hostid'], 1);
if(empty($hostids)) access_deny();
}
if(get_request('apphostid', 0) > 0){
$hostids = available_hosts($_REQUEST['apphostid'], 1);
if(empty($hostids)) access_deny();
}
?>
<?php
/****** APPLICATIONS **********/
if(isset($_REQUEST['save'])){
DBstart();
if(isset($_REQUEST['applicationid'])){
$applicationid = update_application($_REQUEST['applicationid'],$_REQUEST['appname'], $_REQUEST['apphostid']);
$action = AUDIT_ACTION_UPDATE;
$msg_ok = S_APPLICATION_UPDATED;
$msg_fail = S_CANNOT_UPDATE_APPLICATION;
}
else {
$applicationid = add_application($_REQUEST['appname'], $_REQUEST['apphostid']);
$action = AUDIT_ACTION_ADD;
$msg_ok = S_APPLICATION_ADDED;
$msg_fail = S_CANNOT_ADD_APPLICATION;
}
$result = DBend($applicationid);
show_messages($result, $msg_ok, $msg_fail);
if($result){
add_audit($action,AUDIT_RESOURCE_APPLICATION,S_APPLICATION.' ['.$_REQUEST['appname'].' ] ['.$applicationid.']');
unset($_REQUEST['form']);
}
unset($_REQUEST['save']);
}
else if(isset($_REQUEST['delete'])){
if(isset($_REQUEST['applicationid'])){
$result = false;
if($app = get_application_by_applicationid($_REQUEST['applicationid'])){
$host = get_host_by_hostid($app['hostid']);
DBstart();
$result = CApplication::delete($_REQUEST['applicationid']);
$result = DBend($result);
}
show_messages($result, S_APPLICATION_DELETED, S_CANNOT_DELETE_APPLICATION);
if($result){
add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_APPLICATION,'Application ['.$app['name'].'] from host ['.$host['host'].']');
}
unset($_REQUEST['form']);
unset($_REQUEST['applicationid']);
}
}
// -------- GO ---------------
else if($_REQUEST['go'] == 'delete'){
/* group operations */
$go_result = true;
$applications = get_request('applications',array());
DBstart();
$sql = 'SELECT a.applicationid, a.name, a.hostid '.
' FROM applications a'.
' WHERE '.DBin_node('a.applicationid').
' AND '.DBcondition('a.applicationid', $applications);
$db_applications = DBselect($sql);
while($db_app = DBfetch($db_applications)){
if(!isset($applications[$db_app['applicationid']])) continue;
$go_result &= (bool) CApplication::delete($db_app['applicationid']);
if($go_result){
$host = get_host_by_hostid($db_app['hostid']);
add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_APPLICATION,'Application ['.$db_app['name'].'] from host ['.$host['host'].']');
}
}
$go_result = DBend($go_result);
show_messages($go_result, S_APPLICATION_DELETED, S_CANNOT_DELETE_APPLICATION);
}
else if(str_in_array($_REQUEST['go'], array('activate','disable'))){
/* group operations */
$go_result = true;
$applications = get_request('applications',array());
DBstart();
foreach($applications as $id => $appid){
$sql = 'SELECT ia.itemid,i.hostid,i.key_'.
' FROM items_applications ia '.
' LEFT JOIN items i ON ia.itemid=i.itemid '.
' WHERE ia.applicationid='.$appid.
' AND i.hostid='.$_REQUEST['hostid'].
' AND i.type<>9'.
' AND '.DBin_node('ia.applicationid');
$res_items = DBselect($sql);
while($item=DBfetch($res_items)){
if($_REQUEST['go'] == 'activate'){
$go_result&=activate_item($item['itemid']);
}
else{
$go_result&=disable_item($item['itemid']);
}
}
}
$go_result = DBend($go_result);
if($_REQUEST['go'] == 'activate')
show_messages($go_result, S_ITEMS_ACTIVATED, null);
else
show_messages($go_result, S_ITEMS_DISABLED, null);
}
if(($_REQUEST['go'] != 'none') && isset($go_result) && $go_result){
$url = new CUrl();
$path = $url->getPath();
insert_js('cookie.eraseArray("'.$path.'")');
}
?>
<?php
$options = array(
'groups' => array('editable' => 1),
'hosts' => array('editable' => 1, 'templated_hosts' => 1),
'hostid' => get_request('hostid', null),
'groupid' => get_request('groupid', null),
);
$pageFilter = new CPageFilter($options);
$_REQUEST['groupid'] = $pageFilter->groupid;
$_REQUEST['hostid'] = $pageFilter->hostid;
?>
<?php
$app_wdgt = new CWidget();
$frmForm = new CForm(null, 'get');
$frmForm->addVar('hostid',get_request('hostid', 0));
if(!isset($_REQUEST['form'])){
$frmForm->addItem(new CButton('form', S_CREATE_APPLICATION));
}
$app_wdgt->addPageheader(S_CONFIGURATION_OF_APPLICATIONS, $frmForm);
?>
<?php
if(isset($_REQUEST['form'])){
$frm_title = S_NEW_APPLICATION;
if(isset($_REQUEST['applicationid'])){
$result=DBselect('SELECT * FROM applications WHERE applicationid='.$_REQUEST['applicationid']);
$row=DBfetch($result);
$frm_title = S_APPLICATION.': "'.$row['name'].'"';
}
if(isset($_REQUEST["applicationid"]) && !isset($_REQUEST["form_refresh"])){
$appname = $row["name"];
$apphostid = $row['hostid'];
}
else{
$appname = get_request("appname","");
$apphostid = get_request("apphostid",get_request("hostid",0));
}
$db_host = get_host_by_hostid($apphostid,1 /* no error message */);
if($db_host){
$apphost = $db_host["host"];
}
else{
$apphost = '';
$apphostid = 0;
}
$frmApp = new CFormTable($frm_title);
$frmApp->setHelp("web.applications.php");
if(isset($_REQUEST["applicationid"]))
$frmApp->addVar("applicationid",$_REQUEST["applicationid"]);
$frmApp->addRow(S_NAME,new CTextBox("appname",$appname,32));
$frmApp->addVar("apphostid",$apphostid);
if(!isset($_REQUEST["applicationid"])){
// any new application can SELECT host
$frmApp->addRow(S_HOST,array(
new CTextBox("apphost",$apphost,32,'yes'),
new CButton("btn1",S_SELECT,
"return PopUp('popup.php?dstfrm=".$frmApp->getName().
"&dstfld1=apphostid&dstfld2=apphost&srctbl=hosts_and_templates&srcfld1=hostid&srcfld2=host&noempty=1',450,450);",
'T')
));
}
$frmApp->addItemToBottomRow(new CButton('save',S_SAVE));
if(isset($_REQUEST['applicationid'])){
$frmApp->addItemToBottomRow(SPACE);
$frmApp->addItemToBottomRow(new CButtonDelete(S_DELETE_APPLICATION,
url_param('config').url_param('hostid').url_param('groupid').
url_param('form').url_param('applicationid')));
}
$frmApp->addItemToBottomRow(SPACE);
$frmApp->addItemToBottomRow(new CButtonCancel(url_param("config").url_param("hostid").url_param('groupid')));
$app_wdgt->addItem($frmApp);
}
else{
$form = new CForm(null, 'get');
$form->addItem(array(S_GROUP.SPACE,$pageFilter->getGroupsCB()));
$form->addItem(array(SPACE.S_HOST.SPACE,$pageFilter->getHostsCB()));
$numrows = new CDiv();
$numrows->setAttribute('name','numrows');
$app_wdgt->addHeader(S_APPLICATIONS_BIG, $form);
$app_wdgt->addHeader($numrows);
$form = new CForm();
$table = new CTableInfo('...');
if($pageFilter->hostsSelected){
// Header Host
if($_REQUEST['hostid'] > 0){
$tbl_header_host = get_header_host_table($_REQUEST['hostid'], array('items', 'triggers', 'graphs'));
$app_wdgt->addItem($tbl_header_host);
}
$form->setName('applications');
$form->addVar('groupid', $_REQUEST['groupid']);
$form->addVar('hostid', $_REQUEST['hostid']);
$table->setHeader(array(
new CCheckBox('all_applications',NULL,"checkAll('".$form->getName()."','all_applications','applications');"),
(($_REQUEST['hostid'] > 0) ? null : S_HOST),
make_sorting_header(S_APPLICATION, 'name'),
S_SHOW
));
$sortfield = getPageSortField('name');
$sortorder = getPageSortOrder();
$options = array(
'output' => API_OUTPUT_SHORTEN,
'editable' => 1,
'sortfield' => $sortfield,
'sortorder' => $sortorder,
'limit' => ($config['search_limit']+1)
);
if($pageFilter->hostid > 0)
$options['hostids'] = $pageFilter->hostid;
else if($pageFilter->groupid > 0)
$options['groupids'] = $pageFilter->groupid;
$applications = CApplication::get($options);
$paging = getPagingLine($applications);
$options = array(
'applicationids' => zbx_objectValues($applications, 'applicationid'),
'output' => API_OUTPUT_EXTEND,
'select_items' => API_OUTPUT_REFER,
'expandData' => 1,
);
$applications = CApplication::get($options);
order_result($applications, $sortfield, $sortorder);
foreach($applications as $anum => $application){
$applicationid = $application['applicationid'];
if($application['templateid']==0){
$name = new CLink($application['name'],'applications.php?form=update&applicationid='.$applicationid);
}
else{
$template_host = get_realhost_by_applicationid($application['templateid']);
$name = array(
new CLink($template_host['host'], 'applications.php?hostid='.$template_host['hostid'], 'unknown'),
':',
$application['name']
);
}
$table->addRow(array(
new CCheckBox('applications['.$applicationid.']',NULL,NULL,$applicationid),
(($_REQUEST['hostid'] > 0) ? null : $application['host']),
$name,
array(new CLink(S_ITEMS,'items.php?hostid='.$_REQUEST['hostid'].'&filter_set=1&filter_application='.urlencode($application['name'])),
SPACE.'('.count($application['items']).')')
));
}
// goBox
$goBox = new CComboBox('go');
$goOption = new CComboItem('activate', S_ACTIVATE_SELECTED);
$goOption->setAttribute('confirm', S_ACTIVATE_SELECTED_APPLICATIONS);
$goBox->addItem($goOption);
$goOption = new CComboItem('disable', S_DISABLE_SELECTED);
$goOption->setAttribute('confirm', S_DISABLE_SELECTED_APPLICATIONS);
$goBox->addItem($goOption);
$goOption = new CComboItem('delete', S_DELETE_SELECTED);
$goOption->setAttribute('confirm', S_DELETE_SELECTED_APPLICATIONS);
$goBox->addItem($goOption);
// goButton name is necessary!!!
$goButton = new CButton('goButton',S_GO.' (0)');
$goButton->setAttribute('id','goButton');
zbx_add_post_js('chkbxRange.pageGoName = "applications";');
$footer = get_table_header(new CCol(array($goBox, $goButton)));
//----
$table = array($paging,$table,$paging,$footer);
}
$form->addItem($table);
$app_wdgt->addItem($form);
}
$app_wdgt->show();
?>
<?php
include_once('include/page_footer.php');
?>