forked from mikelynn2/blacklistmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hosts.php
203 lines (186 loc) · 6.08 KB
/
hosts.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
<?php
class_exists('Setup', false) or include('classes/Setup.class.php');
class_exists('Utilities', false) or include('classes/Utilities.class.php');
class_exists('_MySQL', false) or include('classes/_MySQL.class.php');
$searchS = array_key_exists('searchS', $_GET) ? trim($_GET['searchS']) : '';
$oc = array_key_exists('oc', $_GET) ? (int)$_GET['oc'] : 4;
$limit = array_key_exists('l', $_GET) ? (int)$_GET['l'] : 100;
if(Utilities::isLoggedIn()===false){
header('Location: login.php?location='.urlencode('hosts.php'));
exit();
}
$titlePreFix = "Hosts";
$user = Utilities::getAccount();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
$searchSQL = "";
$orderSQL = " order by ";
$limitSQL = "";
switch($oc){
case 1:
$searchSQL .= " and lastStatusChanged = 1 ";
$orderSQL .= " lastStatusChangeTime desc ";
break;
case 2:
$searchSQL .= " and isBlocked = 1 ";
$orderSQL .= " lastStatusChangeTime desc ";
break;
case 3:
$searchSQL .= " and isBlocked = 0 ";
$orderSQL .= " lastStatusChangeTime desc ";
break;
default:
$searchSQL .= " ";
$orderSQL .= " lastStatusChangeTime desc ";
break;
}
switch($limit){
case 20:
$orderSQL .= " limit 20 ";
break;
case 100:
$orderSQL .= " limit 100 ";
break;
default:
break;
}
if($searchS != ''){
$searchSQL .= " and (
ipDomain like '%".$mysql->escape($searchS)."%'
or rDNS like '%".$mysql->escape($searchS)."%'
or status like '%".$mysql->escape($searchS)."%' ) ";
}
$sql = "
select isBlocked,lastUpdate,ipDomain,lastStatusChangeTime,rDNS,status
from monitors
where 1=1 $searchSQL
$orderSQL
";
$rs = $mysql->runQuery($sql);
include('header.inc.php');
include('accountSubnav.inc.php');
$hostsCount = Utilities::getHostCount($mysql);
$hostsCountError = Utilities::getHostErrorCount($mysql);
?>
<script src="js/jquery.tablesorter.min.js"></script>
<script>
$(document).ready(function() {
$("#hostTable").tablesorter();
$(".reportType").change(function() {
$("#reportForm").submit();
});
$(".recentFilter").change(function() {
$("#reportForm").submit();
});
});
</script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Hosts', 'Status'],
['Blocked',<?php echo($hostsCountError);?>],
['Clean',<?php echo($hostsCount-$hostsCountError);?>]
]);
data.setFormattedValue(0, 0, data.getValue(0, 0) + ' ' + (<?php echo(number_format($hostsCountError));?>));
data.setFormattedValue(1, 0, data.getValue(1, 0) + ' ' + (<?php echo(number_format($hostsCount-$hostsCountError));?>));
var options = {
title: 'Current Network Status',
is3D: true,
sliceVisibilityThreshold:0,
slices: {
0: { color: 'red' },
1: { color: 'blue' }
}
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
<div id="piechart_3d" style="width: 100%; height: 90px;"></div>
<div style="margin-bottom:5px;">
<form class="form-inline" id="reportForm" role="form">
<label class="radio-inline">
<input class="reportType" type="radio" name="oc" value="1"<?php if($oc==1) echo(' checked');?>>Last Status Changed
</label>
<label class="radio-inline">
<input class="reportType" type="radio" name="oc" value="2"<?php if($oc==2) echo(' checked');?>>Blocked
</label>
<label class="radio-inline">
<input class="reportType" type="radio" name="oc" value="3"<?php if($oc==3) echo(' checked');?>>Clean
</label>
<label class="radio-inline">
<input class="reportType" type="radio" name="oc" value="4"<?php if($oc==4) echo(' checked');?>>All
</label>
<div class="form-group">
<div class="col-md-2">
<select id="l" name="l" class="form-control recentFilter">
<option value="0"<?php if($limit==0) echo(' selected');?>>all</option>
<option value="20"<?php if($limit==20) echo(' selected');?>>20 most recent</option>
<option value="100"<?php if($limit==100) echo(' selected');?>>100 most recent</option>
</select>
</div>
</div>
<div class="form-group">
<label class="sr-only" for="searchS">Search</label>
<input type="text" class="form-control input-sm" id="searchS" name="searchS" placeholder="search" value="<?php echo($searchS);?>">
</div>
<button type="submit" class="btn btn-default">Go</button>
</form>
</div>
<div class="table-responsive">
<table id="hostTable" class="tablesorter table table-bordered table-striped">
<thead>
<tr>
<th style="white-space: nowrap">Host</th>
<th style="white-space: nowrap">Last Checked</th>
<th style="white-space: nowrap">Last Change</th>
<th>DNS</th>
<th>Current Status</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($rs, MYSQL_ASSOC)){
echo('<tr>');
echo('<td><a href="hostHistory.php?host='.urlencode($row['ipDomain']).'">'.$row['ipDomain'].'</a></td>');
if('0000-00-00 00:00:00'==$row['lastUpdate']){
echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>');
echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>');
echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>');
echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>');
}else{
echo('<td style="white-space: nowrap">');
echo(date("Y-n-j g:i a",strtotime($row['lastUpdate'])));
echo('</td>');
if('0000-00-00 00:00:00'==$row['lastStatusChangeTime']){
echo('<td style="white-space: nowrap">n/a</td>');
}else{
echo('<td style="white-space: nowrap">');
echo(date("Y-n-j g:i a",strtotime($row['lastStatusChangeTime'])));
echo('</td>');
}
echo('<td>'.$row['rDNS'].'</td>');
echo('<td>');
if($row['isBlocked']==1){
$s = unserialize($row['status']);
foreach($s as $r){
if($r[1] == false || $r[1] == ''){
}else{
echo htmlentities($r[0]) . " - " . htmlentities($r[1])."<br>\n";
}
}
}else{
echo('OK');
}
echo('</td>');
}
echo('</tr>');
}
$mysql->close();
?>
</tbody>
</table>
</div>
<?php include('footer.inc.php'); ?>