-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathedit.php
193 lines (167 loc) · 6.65 KB
/
edit.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
<?php
# edit message - general
# functions
require('../../functions/functions.php');
# Objects
$Database = new Database_PDO;
$Result = new Result;
$User = new User ($Database);
# snmp class
$Trap = new Trap_read ($Database);
$Modal = new Modal ();
$Common = new Database_wrapper ();
# make sure user is operator
$User->is_operator (true, true);
# strip tags
$_GET = $User->strip_input_tags ($_GET);
# fetch item
$item = $Trap->fetch_snmp_trap ($_GET['id']);
# validate
if ($item!==false) {
// set title
$title = ucwords($_GET['action'])." message";
// footer text
$btn_text = ucwords($_GET['action']);
// add exception
if ($_GET['action']=="ignore") {
// distinct hosts
$uniq = $Common->fetch_unique_items ("traps", "hostname");
if ($uniq!==false) {
foreach ($uniq as $u) {
$unique_hosts[] = $u->hostname;
}
// add all
$unique_hosts = array_filter(array_merge(array("all"=>"all"), $unique_hosts));
}
// title
$title = "Ignore message";
// content
$html[] = "Here you define for some OID to be excluded from processing. All existing records with this OID will be deleted.<br><br>";
$html[] = "<form id='modal-form'>";
$html[] = "<table class='table table-noborder table-condensed'>";
$html[] = "<tr>";
$html[] = " <td style='width:160px;'>OID:</td><td><strong>".$item->oid."</strong></td>";
$html[] = "</tr>";
$html[] = " <td>Hostname:</td>";
$html[] = " <td>";
$html[] = " <select name='hostname' class='form-control input-w-auto input-sm'>";
// loop
foreach ($unique_hosts as $h) {
$selected = $h == $item->hostname ? "selected" : "";
// print
$html[] = "<option value='$h' $selected>$h</option>";
}
$html[] = " </select>";
$html[] = " <input type='hidden' name='oid' value='".$item->oid."'>";
$html[] = " <input type='hidden' name='action' value='".$_GET['action']."'>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Content</td>";
$html[] = " <td>";
$html[] = " <input type='text' class='form-control input-sm' name='content' value='".$item->content."'>";
$html[] = " <span class='text-muted'>* Leave blank to match full OID</span>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Comment</td>";
$html[] = " <td>";
$html[] = " <input type='text' class='form-control input-sm' name='comment'>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "</table>";
$html[] = " </form>";
// save content
$content = implode("\n", $html);
}
// define
elseif ($_GET['action']=="define") {
// title
$title = "Define severity for message";
// content
$html[] = "Here you can change severities for OID messages. All existing records with this OID will be updated.<br><br>";
$html[] = "<form id='modal-form'>";
$html[] = "<table class='table table-noborder table-condensed'>";
$html[] = "<tr>";
$html[] = " <td style='width:160px;'>OID:</td><td><strong>".$item->oid."</strong></td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Current severity:</td><td><strong>".$item->severity."</strong></td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>New severity:</td>";
$html[] = " <td>";
$html[] = " <select name='newseverity' class='form-control input-w-auto input-sm'>";
// loop
foreach ($Trap->severities as $s) {
$selected = $s == $item->severity ? "selected" : "";
// print
$html[] = "<option value='$s' $selected>$s</option>";
}
$html[] = " </select>";
$html[] = " <input type='hidden' name='oldseverity' value='".$item->severity."'>";
$html[] = " <input type='hidden' name='oid' value='".$item->oid."'>";
$html[] = " <input type='hidden' name='id' value='".$item->id."'>";
$html[] = " <input type='hidden' name='action' value='".$_GET['action']."'>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Message</td>";
$html[] = " <td>";
$html[] = " <input type='text' class='form-control input-sm' name='content' value='".$item->message."'>";
$html[] = " <span class='text-muted'>* Leave blank to match full OID</span>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Comment</td>";
$html[] = " <td>";
$html[] = " <input type='text' class='form-control input-sm' name='comment'>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "</table>";
$html[] = " </form>";
// save content
$content = implode("\n", $html);
}
// delete all
elseif ($_GET['action']=="delete") {
// title
$title = "Delete all traps for oid";
// content
$html[] = "Here you can remove all traps for specific OID. All existing records with this OID will be removed. If content is defined than it will search by content also.<br><br>";
$html[] = "<form id='modal-form'>";
$html[] = "<table class='table table-noborder table-condensed'>";
$html[] = "<tr>";
$html[] = " <td style='width:160px;'>OID:</td><td><strong>".$item->oid."</strong></td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Severity:</td><td><strong>".$item->severity."</strong></td>";
$html[] = "</tr>";
$html[] = "<tr>";
$html[] = " <td>Content</td>";
$html[] = " <td>";
$html[] = " <input type='text' class='form-control input-sm' name='content' value='".$item->content."'>";
$html[] = " <input type='hidden' name='oid' value='".$item->oid."'>";
$html[] = " <input type='hidden' name='action' value='".$_GET['action']."'>";
$html[] = " </td>";
$html[] = "</tr>";
$html[] = "</table>";
$html[] = " </form>";
// save content
$content = implode("\n", $html);
}
// false
else {
$title = "Error";
$btn_text = "";
$content = $Result->show ("danger", _('Invalid action'), false, false, true);
}
}
else {
$title = "Error";
$btn_text = "";
$content = $Result->show ("danger", _('Invalid item'), false, false, true);
}
# print modal
$Modal->modal_print ($title, $content, $btn_text, "app/message/edit-submit.php");
?>