-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathVlan_Search.inc.php
113 lines (102 loc) · 2.95 KB
/
Vlan_Search.inc.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
<?php
/*
* Copyright (c) 2014 Neil Lathwood <https://github.com/librenms-plugins/ http://www.lathwood.co.uk>
*
* 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 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if(isset($_POST['vlans']))
{
$orig_vlans = $_POST['vlans'];
if(strpos($_POST['vlans'], ',') !== false)
{
$vlans = explode(',',mres($_POST['vlans']));
}
elseif(strstr($_POST['vlans'], PHP_EOL) !== false)
{
$vlans = preg_split("/[\s,]+/",$_POST['vlans']);
}
else
{
$vlans = array(mres($_POST['vlans']));
}
}
if(isset($_POST['hostname']))
{
$hostname = mres($_POST['hostname']);
}
else
{
$hostname = '';
}
?>
<h4>Search for VLANs</h4>
<form method="post" name="vlan" id="vlan" role="form" class="form-horizontal">
<input type="hidden" name="search" id="search" value="search">
<div class="form-group">
<label for="vlans" class="col-sm-3 control-label">Search for VLANs (seperate by commas or new lines)</label>
<div class="col-sm-6">
<textarea name="vlans" id="vlans" class="form-control" rows="3"><?php echo $orig_vlans;?></textarea>
</div>
</div>
<div class="form-group">
<label for="hostname" class="col-sm-3 control-label">Enter hostname</label>
<div class="col-sm-6">
<input name="hostname" id="hostname" class="form-control" placeholder="Hostname" value="<?php echo $hostname;?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-default">Search</button>
</div>
</div>
</form>
<?php
if(isset($_POST['search']))
{
$vlans = implode(',',$vlans);
if(isset($vlans) && !empty($vlans))
{
$vlan_sql = "AND V.vlan_vlan IN ($vlans)";
}
else
{
$vlan_sql = '';
}
if(isset($hostname) && !empty($hostname))
{
$hostname_sql = " AND D.hostname LIKE '%$hostname%'";
}
else
{
$hostname_sql = '';
}
echo('
<table class="table table-striped table-condensed table-bordered">
<tr>
<th>Device</th>
<th>VLANs</th>
<th>VLAN Names</th>
</tr>
');
foreach (dbFetchRows("SELECT D.hostname,GROUP_CONCAT(`V`.`vlan_vlan`) AS vlan_vlan,GROUP_CONCAT(`V`.`vlan_name`) AS vlan_name FROM `vlans` AS V JOIN devices AS D ON V.device_id=D.device_id WHERE D.disabled=0 AND D.ignore=0 $vlan_sql $hostname_sql GROUP BY D.hostname") as $vlans)
{
$pattern = '/,/';
$device_vlan_id = preg_replace($pattern,'<br />', $vlans['vlan_vlan']);
$device_vlan_name = preg_replace($pattern, '<br />', $vlans['vlan_name']);
echo('
</tr>
<td><a href="./device/device='.$vlans['hostname'].'">'.$vlans['hostname'].'</a></td>
<td>'.$device_vlan_id.'</td>
<td>'.$device_vlan_name.'</td>
</tr>
');
}
}
echo('
</table>
');
?>