forked from netniV/plugin_murlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmURLin.php
365 lines (283 loc) · 13.3 KB
/
mURLin.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
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2009 The Cacti Group |
| |
| 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. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/*******************************************************************************
Author ......... James Payne
Contact ........ [email protected]
Home Site ...... http://withjames.co.uk
Program ........ Cacti URL Monitoring Plugin
Purpose ........ Creates URL Monitoring Structure
*******************************************************************************/
chdir('../../');
include_once("./include/auth.php");
include_once("./include/config.php");
include_once("./lib/data_query.php");
include_once("./plugins/mURLin/scripts/functions.php");
$_SESSION['custom']=false;
/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
switch ($_REQUEST["action"])
{
case '':
// Show Cacti top
include_once("./include/top_header.php");
mURLin_ShowURLs();
// Show cacti bottom
include_once("./include/bottom_footer.php");
break;
case 'delete':
// Delete the Host Mapping
$id = $_SESSION['urlselect'];
foreach($id as $i)
{
input_validate_input_number($i);
}
foreach($id as $i)
{
// What host is mapped to $i
$sql = "SELECT host_id FROM plugin_mURLin_index WHERE id = $i";
$hostid = db_fetch_cell($sql);
$sql = "DELETE FROM plugin_mURLin_index WHERE id = $i";
db_execute($sql);
// ReIndex the Data Query
$sql = "SELECT id FROM snmp_query WHERE name='mURLin - URL Agent'";
$snmpid = db_fetch_cell($sql);
data_query_update_host_cache_from_buffer($hostid, $snmpid, $tmp);
}
// Redirect
header( "Location: mURLin.php" );
break;
case 'confirmdelete':
// Confirm the delete
$id = $_POST['urlselect'];
$hostmappings = "";
foreach($id as $i)
{
input_validate_input_number($i);
$sql = "
SELECT m.id as id, m.host_id as host_id, m.url as url, m.timeout as timeout, m.text_match as text_match, h.description as hostname, h.hostname as dns
FROM plugin_mURLin_index m
INNER JOIN host h
ON m.host_id = h.id
WHERE m.id = $i";
$row = db_fetch_row($sql);
$host = $row['hostname'];
$url = $row['url'];
$hostmappings .= "$host ---> <strong>$url</strong><br/><br/>";
}
// Set details
$_SESSION['urlselect'] = $id;
mURLin_PostMessage("Confirm Delete" ,"Are you sure you want to delete the following host mapping(s)?<br/><br/><br/><div style='text-align:center;'>$hostmappings</div>", "mURLin.php?action=delete", "mURLin.php");
break;
case 'duplicate':
// Duplicate a report
$id = $_POST['urlselect'];
foreach ($id as $i)
{
input_validate_input_number($i);
$sql = "SELECT * FROM plugin_mURLin_index WHERE id = $i";
$row = db_fetch_row($sql);
$host_id = $row['host_id'];
$url = $row['url'];
$text_match = $row['text_match'];
$timeout = $row['timeout'];
// Duplicate this row
$sql = "INSERT INTO plugin_mURLin_index (host_id, url, text_match, timeout) VALUES ($host_id, '$url', '$text_match', $timeout)";
db_execute($sql);
}
// Redirect
header( "Location: mURLin.php" );
break;
}
function mURLin_PostMessage($messagetitle, $message, $confirmaction, $cancelaction)
{
// Include cacti top
include_once("./include/top_header.php");
print "<table align='center' width='60%' cellpadding='0' cellspacing='0' border='0' class='cactiTable' bgcolor='#6d88ad'>
<tbody><tr>
<td>";
print '<table cellpadding="3" cellspacing="0" border="0" bgcolor="#6d88ad" width="100%"><tbody><tr><td class="textHeaderDark">';
print "<strong>" . $messagetitle . "</strong>";
print '</td></tr></tbody></table>';
print '<table cellpadding="3" cellspacing="0" border="0" bgcolor="#f5f5f5" width="100%"><tbody><tr><td class="textArea">';
print "<br/><br/>" . $message . "<br/><br/>";
print '</td></tr></tbody></table>';
print '<table cellpadding="3" cellspacing="0" border="0" bgcolor="#e1e1e1" width="100%"><tbody><tr><td>';
print "<form method='post' style='float:right; margin:0 0 0 0;'>";
print " <input type='button' title='Cancel' value='Cancel' onClick=\"window.location='$cancelaction'\"/>
<input type='button' title='Confirm' value='Confirm' onClick=\"window.location='$confirmaction'\"/>";
print '</td></tr></tbody></table>';
print " </td>
</tr>
</tbody>
</table>";
// Show cacti bottom
include_once("./include/bottom_footer.php");
}
function mURLin_ShowURLs()
{
mURLin_includejavascript("./plugins/mURLin/functions.js");
// Show the mapped URLs
$sql = "SELECT * FROM plugin_mURLin_index";
$results = db_fetch_assoc($sql);
// Draw table header
// Show Availability Reports
echo <<<HTMLBLOCK
<form method='POST'>
<div style="position:static;" id="main">
<table align="center" width="100%" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td>
<table style="width:100%;" class="cactiTable" bgcolor="#00438C"><tbody>
<tr><td class="textHeaderDark" style="padding:3px; text-align:left; width:50%;">
<strong>Map URLs to Hosts</strong>
</td>
<td class="textHeaderDark" style="padding:3px; text-align:right; width:50%;">
<strong><a class='linkOverDark' href='url_edit.php?id=NEW'>Add</a></strong>
</td>
</tr>
</tbody></table>
</td>
<tr bgcolor="#e5e5e5">
<td>
HTMLBLOCK;
print mURLin_CreateURLTable($results);
echo <<<HTMLBLOCK
</td>
</tr>
<tr>
<td>
<table style='float:right;'>
<tbody>
<tr>
<td>
Choose an Action:
</td>
<td>
<select name="action">
<option value="confirmdelete">Delete</option>
<option value="duplicate">Duplicate</option>
</select>
</td>
<td>
<input type='submit' value='Go' title='Execute Action'/>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</form>
HTMLBLOCK;
}
function mURLin_CreateURLTable($results)
{
// Cycle through each result and draw the table
print "
<table width='100%'>
<tbody>";
// Print Title Row
print "<tr width='100%' bgcolor='#d5d5d5'>";
print "<td>";
print "<strong>Hostname</strong>";
print "</td>";
print "<td>";
print "<strong>DNS/IP</strong>";
print "</td>";
print "<td>";
print "<strong>URL</strong>";
print "</td>";
print "<td>";
print "<strong>Timeout (Seconds)</strong>";
print "</td>";
print "<td>";
print "<strong>Regex Text Match</strong>";
print "</td>";
print "<td>";
print "<strong>Proxy Address</strong>";
print "</td>";
print "<td width='1%' style='padding:1px;'>";
print "<input type='checkbox' id='select_all' name='all' title='Select All' onclick='CheckAll(\"urlselect[]\", this.checked)'>";
print "</td>";
// Colour switch
// One colour for odd one for even
$bgswitch = 0;
foreach ($results as $row)
{
// Colour Switch
if (($bgswitch % 2) === 1)
$bgcolor = "#f5f5f5";
else
$bgcolor = "#E7E9F2";
// Host id to host name
$sql = "SELECT description, hostname from host WHERE id = " . $row['host_id'];
$temp = db_fetch_row($sql);
$hostname = $temp['description'];
$DNS = $temp['hostname'];
$id = $row['id'];
$url = $row['url'];
$timeout = $row['timeout'];
$text_match = $row['text_match'];
$proxyserver = $row['proxyserver'];
$proxystring = "";
if ($proxyserver != 0)
{
$proxyaddress = $row['proxyaddress'];
$proxystring = "&proxy=" . $row['proxyaddress'] . "&proxyusername=" . $row['proxyusername'] . "&proxypassword=" . $row['proxypassword'];
}
else
$proxyaddress = "N/A";
print "<tr width='100%' bgcolor='$bgcolor' id='row_$id' onMouseOver=\"this.bgColor='#F7EEC0';\" onMouseOut=\"this.bgColor='$bgcolor';\">
<td onClick=\"CheckBox('chk_$id','select_all');\">";
print "<a href='url_edit.php?id=$id'><strong>$hostname</strong></a> "; // Print Hostname and Link
print "</td>";
print "<td onClick=\"CheckBox('chk_$id','select_all');\">";
print $DNS;
print "</td>";
print "<td onClick=\"CheckBox('chk_$id','select_all');\">";
// Encode the URL so it doesn't inject extra information into the showpage.php page
$urlenc = urlencode($url);
print "<strong><a href='showpage.php?page=$url' onclick=\"window.open('showpage.php?page=$urlenc&timeout=$timeout$proxystring', 'myWin', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=600, height=400'); return false\">" . $url . "</a></strong>";
print "</td>";
print "<td onClick=\"CheckBox('chk_$id','select_all');\">";
print $timeout;
print "</td>";
print "<td onClick=\"CheckBox('chk_$id','select_all');\" width='40%'>";
print "<PRE style='margin:3px;'>" . $text_match . "</PRE>";
print "</td>";
print "<td onClick=\"CheckBox('chk_$id','select_all');\" >";
print $proxyaddress;
print "</td>";
print "<td>";
print "<input type='checkbox' id='chk_$id' name='urlselect[]' value='$id' onClick=\"CheckAllFunction(this.checked, 'select_all');\">";
print "</td>";
print "</tr>";
$bgswitch += 1;
}
print " </tbody>
</table>";
}
?>