@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | class_exists('_MySQL', false) or include('classes/_MySQL.class.php'); |
6 | 6 | class_exists('PHPMailer', false) or include('classes/class.phpmailer.php'); |
7 | 7 | |
8 | -if(Utilities::isLoggedIn()===false){ |
|
8 | +if (Utilities::isLoggedIn()===false) { |
|
9 | 9 | header('Location: login.php'); |
10 | 10 | exit(); |
11 | 11 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | $params = array_merge($_GET, $_POST); |
16 | 16 | $id = array_key_exists('id', $params) ? (int)$params['id'] : 0; |
17 | -$groupName = array_key_exists('groupName', $params) ? substr(trim($params['groupName']),0,100) : ''; |
|
17 | +$groupName = array_key_exists('groupName', $params) ? substr(trim($params['groupName']), 0, 100) : ''; |
|
18 | 18 | $domains = array_key_exists('domains', $params) ? trim(strtolower($params['domains'])) : ''; |
19 | 19 | $ips = array_key_exists('ips', $params) ? trim($params['ips']) : ''; |
20 | 20 | $deleteGroup = array_key_exists('deleteGroup', $params) ? trim($params['deleteGroup']) : ''; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $mysql->connect(Setup::$connectionArray); |
25 | 25 | |
26 | 26 | |
27 | -if($deleteGroup!=''){ |
|
27 | +if ($deleteGroup!='') { |
|
28 | 28 | $mysql->runQuery("delete from monitorGroup where id = $id"); |
29 | 29 | $mysql->runQuery("delete from monitors where monitorGroupId = $id"); |
30 | 30 | echo("<script>window.location='monitorGroup.php';</script>"); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | if (isset($_POST["submit"])) { |
35 | 35 | |
36 | 36 | //TODO: make sure blacklists are domains with an ip address on them |
37 | - if($id !== 0){ |
|
37 | + if ($id!==0) { |
|
38 | 38 | //update |
39 | 39 | $mysql->runQuery(" |
40 | 40 | update monitorGroup set groupName = '".$mysql->escape($groupName)."', |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | domains = '".$mysql->escape($domains)."' |
43 | 43 | where id = $id |
44 | 44 | "); |
45 | - }else{ |
|
45 | + }else { |
|
46 | 46 | $mysql->runQuery(" |
47 | 47 | insert into monitorGroup set groupName = '".$mysql->escape($groupName)."', |
48 | 48 | ips = '".$mysql->escape($ips)."', |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | 'domains'=>'', |
63 | 63 | ); |
64 | 64 | $rs = $mysql->runQuery("select * from monitorGroup where id = $id"); |
65 | -while($row = mysqli_fetch_array($rs)){ |
|
65 | +while ($row = mysqli_fetch_array($rs)) { |
|
66 | 66 | $group = $row; |
67 | 67 | } |
68 | 68 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | <div class="form-group"> |
87 | 87 | <label class="col-sm-3 control-label" for="username">Group Name</label> |
88 | 88 | <div class="col-sm-6"> |
89 | - <input class="form-control" required="true" type="text" id="groupName" name="groupName" value="<?php echo($group['groupName']);?>" placeholder="group name"> |
|
89 | + <input class="form-control" required="true" type="text" id="groupName" name="groupName" value="<?php echo($group['groupName']); ?>" placeholder="group name"> |
|
90 | 90 | </div> |
91 | 91 | </div> |
92 | 92 | <div class="form-group"> |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | <div class="form-group"> |
105 | 105 | <div class="col-sm-offset-3 col-sm-6"> |
106 | 106 | <button type="submit" name="submit" value="submit" class="btn btn-primary">Save changes</button> |
107 | - <?php if($id>0) { ?> <button type="submit" onclick="return clickDelete();" name="deleteGroup" value="deleteGroup" class="btn btn-danger">Delete Group</button><?php } ?> |
|
107 | + <?php if ($id > 0) { ?> <button type="submit" onclick="return clickDelete();" name="deleteGroup" value="deleteGroup" class="btn btn-danger">Delete Group</button><?php } ?> |
|
108 | 108 | </div> |
109 | 109 | </div> |
110 | - <input type="hidden" value="<?php echo($id);?>" name="id"/> |
|
110 | + <input type="hidden" value="<?php echo($id); ?>" name="id"/> |
|
111 | 111 | </form> |
112 | 112 | |
113 | 113 | <br/><br/><br/><br/> |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | ); |
19 | 19 | |
20 | 20 | $id = Utilities::validateLogin($username, $passwd, true, $apiKey); |
21 | -if($id == 0) { |
|
21 | +if ($id==0) { |
|
22 | 22 | $result['status'] = 'invalid login'; |
23 | 23 | output(); |
24 | 24 | } |
25 | 25 | |
26 | -switch($type){ |
|
26 | +switch ($type) { |
|
27 | 27 | case 'updateDomains': |
28 | - if($groupName=='') { |
|
28 | + if ($groupName=='') { |
|
29 | 29 | $result['status'] = 'groupName is required'; |
30 | 30 | break; |
31 | 31 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | break; |
36 | 36 | |
37 | 37 | case 'updateIPs': |
38 | - if($groupName=='') { |
|
38 | + if ($groupName=='') { |
|
39 | 39 | $result['status'] = 'groupName is required'; |
40 | 40 | break; |
41 | 41 | } |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | $localCache = new _FileCache('blacklistmonitor-api', 90); |
63 | 63 | $cacheKey = md5("$username|$passwd|$apiKey|$type|$data"); |
64 | 64 | $cacheData = $localCache->get($cacheKey); |
65 | - if ($cacheData !== false) { |
|
65 | + if ($cacheData!==false) { |
|
66 | 66 | output($cacheData); |
67 | 67 | } |
68 | 68 | $mysql = new _MySQL(); |
69 | 69 | $mysql->connect(Setup::$connectionArray); |
70 | 70 | $searchSQL = ''; |
71 | - switch($data){ |
|
71 | + switch ($data) { |
|
72 | 72 | case 'changed': |
73 | 73 | $searchSQL .= " and lastStatusChanged = 1 "; |
74 | 74 | break; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | where 1=1 $searchSQL"); |
88 | 88 | $result['status'] = 'success'; |
89 | 89 | $result['result'] = array(); |
90 | - while($row = mysqli_fetch_array($rs)){ |
|
90 | + while ($row = mysqli_fetch_array($rs)) { |
|
91 | 91 | $result['result'][] = array( |
92 | 92 | 'host'=>$row['ipDomain'], |
93 | 93 | 'isBlocked'=>$row['isBlocked'], |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | |
108 | 108 | output(); |
109 | 109 | |
110 | -function output($data = false){ |
|
110 | +function output($data = false) { |
|
111 | 111 | global $result; |
112 | - if($data!==false){ |
|
112 | + if ($data!==false) { |
|
113 | 113 | echo(json_encode($data)); |
114 | - }else{ |
|
114 | + }else { |
|
115 | 115 | echo(json_encode($result)); |
116 | 116 | } |
117 | 117 | exit(); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | $monitorGroupId = array_key_exists('monitorGroupId', $_GET) ? (int)$_GET['monitorGroupId'] : 0; |
10 | 10 | $limit = array_key_exists('l', $_GET) ? (int)$_GET['l'] : 100; |
11 | 11 | |
12 | -if(Utilities::isLoggedIn()===false){ |
|
12 | +if (Utilities::isLoggedIn()===false) { |
|
13 | 13 | header('Location: login.php?location='.urlencode('hosts.php')); |
14 | 14 | exit(); |
15 | 15 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | $hostTypeSQL = ""; |
24 | 24 | $orderSQL = " order by "; |
25 | 25 | $limitSQL = ($limit > 0) ? " limit $limit " : ''; |
26 | -switch($oc){ |
|
26 | +switch ($oc) { |
|
27 | 27 | case 1: |
28 | 28 | $searchSQL .= " and lastStatusChanged = 1 "; |
29 | 29 | $orderSQL .= " lastStatusChangeTime desc "; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | break; |
43 | 43 | } |
44 | 44 | |
45 | -if($monitorGroupId != 0) $searchSQL .= " and monitorGroupId = $monitorGroupId "; |
|
45 | +if ($monitorGroupId!=0) $searchSQL .= " and monitorGroupId = $monitorGroupId "; |
|
46 | 46 | |
47 | -switch($hostType){ |
|
47 | +switch ($hostType) { |
|
48 | 48 | case 'domains': |
49 | 49 | $hostTypeSQL .= " and isDomain = 1 "; |
50 | 50 | break; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | break; |
54 | 54 | } |
55 | 55 | |
56 | -if($searchS != ''){ |
|
56 | +if ($searchS!='') { |
|
57 | 57 | $searchSQL .= " and ( |
58 | 58 | ipDomain like '%".$mysql->escape($searchS)."%' |
59 | 59 | or rDNS like '%".$mysql->escape($searchS)."%' |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | function drawChart() { |
102 | 102 | var data = google.visualization.arrayToDataTable([ |
103 | 103 | ['Hosts', 'Status'], |
104 | - ['Blocked',<?php echo($hostsCountError);?>], |
|
105 | - ['Clean',<?php echo($hostsCount-$hostsCountError);?>] |
|
104 | + ['Blocked',<?php echo($hostsCountError); ?>], |
|
105 | + ['Clean',<?php echo($hostsCount-$hostsCountError); ?>] |
|
106 | 106 | ]); |
107 | - data.setFormattedValue(0, 0, data.getValue(0, 0) + ' ' + (<?php echo($hostsCountError);?>)); |
|
108 | - data.setFormattedValue(1, 0, data.getValue(1, 0) + ' ' + (<?php echo($hostsCount-$hostsCountError);?>)); |
|
107 | + data.setFormattedValue(0, 0, data.getValue(0, 0) + ' ' + (<?php echo($hostsCountError); ?>)); |
|
108 | + data.setFormattedValue(1, 0, data.getValue(1, 0) + ' ' + (<?php echo($hostsCount-$hostsCountError); ?>)); |
|
109 | 109 | var options = { |
110 | 110 | title: 'Current Network Status', |
111 | 111 | is3D: true, |
@@ -125,39 +125,39 @@ discard block |
||
125 | 125 | <div style="margin-bottom:5px;"> |
126 | 126 | <form class="form-inline" id="reportForm" role="form"> |
127 | 127 | <label class="radio-inline"> |
128 | - <input class="reportType" type="radio" name="oc" value="1"<?php if($oc==1) echo(' checked');?>>Last Status Changed |
|
128 | + <input class="reportType" type="radio" name="oc" value="1"<?php if ($oc==1) echo(' checked'); ?>>Last Status Changed |
|
129 | 129 | </label> |
130 | 130 | <label class="radio-inline"> |
131 | - <input class="reportType" type="radio" name="oc" value="2"<?php if($oc==2) echo(' checked');?>>Blocked |
|
131 | + <input class="reportType" type="radio" name="oc" value="2"<?php if ($oc==2) echo(' checked'); ?>>Blocked |
|
132 | 132 | </label> |
133 | 133 | <label class="radio-inline"> |
134 | - <input class="reportType" type="radio" name="oc" value="3"<?php if($oc==3) echo(' checked');?>>Clean |
|
134 | + <input class="reportType" type="radio" name="oc" value="3"<?php if ($oc==3) echo(' checked'); ?>>Clean |
|
135 | 135 | </label> |
136 | 136 | <label class="radio-inline"> |
137 | - <input class="reportType" type="radio" name="oc" value="4"<?php if($oc==4) echo(' checked');?>>All |
|
137 | + <input class="reportType" type="radio" name="oc" value="4"<?php if ($oc==4) echo(' checked'); ?>>All |
|
138 | 138 | </label> |
139 | 139 | <div class="form-group"> |
140 | 140 | <div class="col-md-6"> |
141 | 141 | <select id="l" name="l" class="form-control recentFilter input-sm"> |
142 | - <option value="0"<?php if($limit==0) echo(' selected');?>>all</option> |
|
143 | - <option value="20"<?php if($limit==20) echo(' selected');?>>20 most recent</option> |
|
144 | - <option value="100"<?php if($limit==100) echo(' selected');?>>100 most recent</option> |
|
145 | - <option value="500"<?php if($limit==500) echo(' selected');?>>500 most recent</option> |
|
142 | + <option value="0"<?php if ($limit==0) echo(' selected'); ?>>all</option> |
|
143 | + <option value="20"<?php if ($limit==20) echo(' selected'); ?>>20 most recent</option> |
|
144 | + <option value="100"<?php if ($limit==100) echo(' selected'); ?>>100 most recent</option> |
|
145 | + <option value="500"<?php if ($limit==500) echo(' selected'); ?>>500 most recent</option> |
|
146 | 146 | </select> |
147 | 147 | </div> |
148 | 148 | </div> |
149 | 149 | <div class="form-group"> |
150 | 150 | <div class="col-md-6"> |
151 | 151 | <select id="ht" name="ht" class="form-control hostType input-sm"> |
152 | - <option value="all"<?php if($hostType=='all') echo(' selected');?>>all</option> |
|
153 | - <option value="ips"<?php if($hostType=='ips') echo(' selected');?>>ips</option> |
|
154 | - <option value="domain"<?php if($hostType=='domains') echo(' selected');?>>domains</option> |
|
152 | + <option value="all"<?php if ($hostType=='all') echo(' selected'); ?>>all</option> |
|
153 | + <option value="ips"<?php if ($hostType=='ips') echo(' selected'); ?>>ips</option> |
|
154 | + <option value="domain"<?php if ($hostType=='domains') echo(' selected'); ?>>domains</option> |
|
155 | 155 | </select> |
156 | 156 | </div> |
157 | 157 | </div> |
158 | 158 | <div class="form-group"> |
159 | 159 | <label class="sr-only" for="searchS">Search</label> |
160 | - <input type="text" class="form-control input-sm" id="searchS" name="searchS" placeholder="search" value="<?php echo($searchS);?>"> |
|
160 | + <input type="text" class="form-control input-sm" id="searchS" name="searchS" placeholder="search" value="<?php echo($searchS); ?>"> |
|
161 | 161 | </div> |
162 | 162 | <button type="submit" class="btn btn-default">Go</button> |
163 | 163 | <input type="hidden" name="monitorGroupId" value="<?php echo($monitorGroupId); ?>"> |
@@ -178,37 +178,37 @@ discard block |
||
178 | 178 | </thead> |
179 | 179 | <tbody> |
180 | 180 | <?php |
181 | - while($row = mysqli_fetch_array($rs)){ |
|
181 | + while ($row = mysqli_fetch_array($rs)) { |
|
182 | 182 | echo('<tr>'); |
183 | 183 | echo('<td><a href="hostHistory.php?host='.urlencode($row['ipDomain']).'">'.$row['ipDomain'].'</a></td>'); |
184 | 184 | echo('<td><a href="editHostGroup.php?id='.$row['id'].'">'.$row['groupName'].'</a></td>'); |
185 | - if('0000-00-00 00:00:00'==$row['lastUpdate']){ |
|
185 | + if ('0000-00-00 00:00:00'==$row['lastUpdate']) { |
|
186 | 186 | echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>'); |
187 | 187 | echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>'); |
188 | 188 | echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>'); |
189 | 189 | echo('<td style="white-space: nowrap">'.Utilities::$hostNotCheckedMessage.'</td>'); |
190 | - }else{ |
|
190 | + }else { |
|
191 | 191 | echo('<td style="white-space: nowrap">'); |
192 | - echo(date("Y-n-j g:i a",strtotime($row['lastUpdate']))); |
|
192 | + echo(date("Y-n-j g:i a", strtotime($row['lastUpdate']))); |
|
193 | 193 | echo('</td>'); |
194 | - if('0000-00-00 00:00:00'==$row['lastStatusChangeTime']){ |
|
194 | + if ('0000-00-00 00:00:00'==$row['lastStatusChangeTime']) { |
|
195 | 195 | echo('<td style="white-space: nowrap">n/a</td>'); |
196 | - }else{ |
|
196 | + }else { |
|
197 | 197 | echo('<td style="white-space: nowrap">'); |
198 | - echo(date("Y-n-j g:i a",strtotime($row['lastStatusChangeTime']))); |
|
198 | + echo(date("Y-n-j g:i a", strtotime($row['lastStatusChangeTime']))); |
|
199 | 199 | echo('</td>'); |
200 | 200 | } |
201 | 201 | echo('<td>'.$row['rDNS'].'</td>'); |
202 | 202 | echo('<td>'); |
203 | - if($row['isBlocked']==1){ |
|
203 | + if ($row['isBlocked']==1) { |
|
204 | 204 | $s = unserialize($row['status']); |
205 | - foreach($s as $r){ |
|
206 | - if($r[1] == false || $r[1] == ''){ |
|
207 | - }else{ |
|
208 | - echo htmlentities($r[0]) . " - " . htmlentities($r[1])."<br>\n"; |
|
205 | + foreach ($s as $r) { |
|
206 | + if ($r[1]==false || $r[1]=='') { |
|
207 | + }else { |
|
208 | + echo htmlentities($r[0])." - ".htmlentities($r[1])."<br>\n"; |
|
209 | 209 | } |
210 | 210 | } |
211 | - }else{ |
|
211 | + }else { |
|
212 | 212 | echo('OK'); |
213 | 213 | } |
214 | 214 | echo('</td>'); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | |
6 | 6 | $groupName = array_key_exists('searchS', $_GET) ? trim($_GET['searchS']) : ''; |
7 | 7 | |
8 | -if(Utilities::isLoggedIn()===false){ |
|
8 | +if (Utilities::isLoggedIn()===false) { |
|
9 | 9 | header('Location: login.php?location='.urlencode('monitorGroup.php')); |
10 | 10 | exit(); |
11 | 11 | } |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | </thead> |
58 | 58 | <tbody> |
59 | 59 | <?php |
60 | - while($row = mysqli_fetch_array($rs)){ |
|
60 | + while ($row = mysqli_fetch_array($rs)) { |
|
61 | 61 | echo('<tr>'); |
62 | 62 | echo('<td><a href="hosts.php?monitorGroupId='.$row['id'].'"><div class="glyphicon glyphicon-stats glyphicon-stats-lg"></div></a> <a href="editHostGroup.php?id='.urlencode($row['id']).'">'.$row['groupName'].'</a></td>'); |
63 | - echo('<td>'.number_format($row['hostCount'],0).'</td>'); |
|
64 | - echo('<td>'.number_format($row['hostCountError'],0).'</td>'); |
|
65 | - echo('<td>'.number_format($row['hostRecentBlock'],0).'</td>'); |
|
66 | - echo('<td>'.number_format((($row['hostCount']>0) ? ($row['hostCountError']/$row['hostCount']*100) : 0),1).'</td>'); |
|
63 | + echo('<td>'.number_format($row['hostCount'], 0).'</td>'); |
|
64 | + echo('<td>'.number_format($row['hostCountError'], 0).'</td>'); |
|
65 | + echo('<td>'.number_format($row['hostRecentBlock'], 0).'</td>'); |
|
66 | + echo('<td>'.number_format((($row['hostCount'] > 0) ? ($row['hostCountError']/$row['hostCount']*100) : 0), 1).'</td>'); |
|
67 | 67 | echo('</tr>'); |
68 | 68 | } |
69 | 69 | $mysql->close(); |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | public static $frequencyCheckOptions = array('1hour', '2hour', '8hour', 'daily', 'weekly'); |
13 | 13 | public static $mysql = false; |
14 | 14 | |
15 | - public static function setBlockLists(){ |
|
15 | + public static function setBlockLists() { |
|
16 | 16 | $localCache = new _FileCache('blacklistmonitor-Utilities-BlockLists', 60); |
17 | 17 | $cacheKey = 'bl'; |
18 | 18 | $cacheData = $localCache->get($cacheKey); |
19 | - if ($cacheData !== false) { |
|
20 | - if(isset($cacheData['domains']) && isset($cacheData['ips']) ) { |
|
19 | + if ($cacheData!==false) { |
|
20 | + if (isset($cacheData['domains']) && isset($cacheData['ips'])) { |
|
21 | 21 | self::$domainBlacklists = $cacheData['domains']; |
22 | 22 | self::$ipBlacklists = $cacheData['ips']; |
23 | 23 | return true; |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | $rs = $mysql->runQuery($sql); |
30 | 30 | $cacheData['domains'] = array(); |
31 | 31 | $cacheData['ips'] = array(); |
32 | - while($row = mysqli_fetch_array($rs)){ |
|
33 | - if($row['monitorType']=='ip'){ |
|
32 | + while ($row = mysqli_fetch_array($rs)) { |
|
33 | + if ($row['monitorType']=='ip') { |
|
34 | 34 | $cacheData['ips'][] = $row['host']; |
35 | - }else{ |
|
35 | + }else { |
|
36 | 36 | $cacheData['domains'][] = $row['host']; |
37 | 37 | } |
38 | 38 | } |
@@ -43,46 +43,46 @@ discard block |
||
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | |
46 | - public static function randomDNSServer(){ |
|
47 | - return Setup::$settings['dns_servers'][mt_rand(0,(count(Setup::$settings['dns_servers'])-1))]; |
|
46 | + public static function randomDNSServer() { |
|
47 | + return Setup::$settings['dns_servers'][mt_rand(0, (count(Setup::$settings['dns_servers'])-1))]; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public static $isBlocked = 0; |
51 | 51 | |
52 | - public static function checkBlacklists($domainOrIp, $reportClean=false){ |
|
52 | + public static function checkBlacklists($domainOrIp, $reportClean = false) { |
|
53 | 53 | self::$isBlocked = 0; |
54 | 54 | $return = array(); |
55 | - if(_IpAddresses::isIPAddress($domainOrIp)){ |
|
56 | - foreach(self::$ipBlacklists as $server){ |
|
55 | + if (_IpAddresses::isIPAddress($domainOrIp)) { |
|
56 | + foreach (self::$ipBlacklists as $server) { |
|
57 | 57 | $r = self::ipCheck($domainOrIp, $server); |
58 | - if($r!='') { |
|
58 | + if ($r!='') { |
|
59 | 59 | self::$isBlocked = 1; |
60 | 60 | self::logBlockListStats($server, 'ip', true); |
61 | - }else{ |
|
61 | + }else { |
|
62 | 62 | self::logBlockListStats($server, 'ip', false); |
63 | 63 | } |
64 | - if($r!='' || $reportClean==true) { |
|
65 | - $return[] = array(trim($server),$r); |
|
64 | + if ($r!='' || $reportClean==true) { |
|
65 | + $return[] = array(trim($server), $r); |
|
66 | 66 | } |
67 | 67 | } |
68 | - }else{ |
|
69 | - foreach(self::$domainBlacklists as $server){ |
|
68 | + }else { |
|
69 | + foreach (self::$domainBlacklists as $server) { |
|
70 | 70 | $r = self::domainCheck($domainOrIp, $server); |
71 | - if($r!='') { |
|
71 | + if ($r!='') { |
|
72 | 72 | self::$isBlocked = 1; |
73 | 73 | self::logBlockListStats($server, 'domain', true); |
74 | - }else{ |
|
74 | + }else { |
|
75 | 75 | self::logBlockListStats($server, 'domain', false); |
76 | 76 | } |
77 | - if($r!='' || $reportClean==true) { |
|
78 | - $return[] = array(trim($server),$r); |
|
77 | + if ($r!='' || $reportClean==true) { |
|
78 | + $return[] = array(trim($server), $r); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | } |
82 | 82 | return $return; |
83 | 83 | } |
84 | 84 | |
85 | - public static function domainCheck($domain, $server){ |
|
85 | + public static function domainCheck($domain, $server) { |
|
86 | 86 | $server = trim($server); |
87 | 87 | $host = escapeshellarg("$domain.$server"); |
88 | 88 | $t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host"; |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | $testArray = explode("\t", $test); |
99 | 99 | $test = end($testArray); |
100 | 100 | |
101 | - if(trim($test)!=''){ |
|
102 | - if(Setup::$settings['rbl_txt_extended_status']){ |
|
101 | + if (trim($test)!='') { |
|
102 | + if (Setup::$settings['rbl_txt_extended_status']) { |
|
103 | 103 | $t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host txt"; |
104 | 104 | // echo("$t</br>"); |
105 | 105 | $text = shell_exec($t); |
@@ -112,18 +112,18 @@ discard block |
||
112 | 112 | true); |
113 | 113 | $testArray = explode("\t", $test); |
114 | 114 | $test = end($testArray); |
115 | - $test = str_replace(array('\'','"'),'',$test); |
|
116 | - }else{ |
|
115 | + $test = str_replace(array('\'', '"'), '', $test); |
|
116 | + }else { |
|
117 | 117 | $test = 'blocked'; |
118 | 118 | } |
119 | 119 | } |
120 | - if(strripos($test,'not found')!==false) return ''; |
|
121 | - if(strripos($test,'SERVFAIL')!==false) return ''; |
|
120 | + if (strripos($test, 'not found')!==false) return ''; |
|
121 | + if (strripos($test, 'SERVFAIL')!==false) return ''; |
|
122 | 122 | return trim($test); |
123 | 123 | } |
124 | 124 | |
125 | - public static function ipCheck($ip, $server){ |
|
126 | - if(_IpAddresses::isIPAddress($ip)===false) return ''; |
|
125 | + public static function ipCheck($ip, $server) { |
|
126 | + if (_IpAddresses::isIPAddress($ip)===false) return ''; |
|
127 | 127 | $server = trim($server); |
128 | 128 | |
129 | 129 | $parts = explode('.', $ip); |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | $testArray = preg_split("/IN\s+A\s+/i", $test); |
144 | 144 | $test = trim(end($testArray)); |
145 | 145 | // echo "<pre>$test</pre>\n"; |
146 | - if(trim($test)!=''){ |
|
147 | - if(Setup::$settings['rbl_txt_extended_status']){ |
|
146 | + if (trim($test)!='') { |
|
147 | + if (Setup::$settings['rbl_txt_extended_status']) { |
|
148 | 148 | $t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host txt"; |
149 | 149 | // echo("$t</br>"); |
150 | 150 | $text = shell_exec($t); |
@@ -157,41 +157,41 @@ discard block |
||
157 | 157 | true); |
158 | 158 | $testArray = preg_split("/IN\s+TXT\s+/i", $test2); |
159 | 159 | $test2 = trim(end($testArray)); |
160 | - $test2 = str_replace(array('\'','"'),'',$test2); |
|
161 | - switch($server){ |
|
160 | + $test2 = str_replace(array('\'', '"'), '', $test2); |
|
161 | + switch ($server) { |
|
162 | 162 | case 'bl.mailspike.net': |
163 | - $a = explode("|",$test2); |
|
164 | - $test = (isset($a[1])) ? 'Listed ' . $a[1] : $test2; |
|
163 | + $a = explode("|", $test2); |
|
164 | + $test = (isset($a[1])) ? 'Listed '.$a[1] : $test2; |
|
165 | 165 | break; |
166 | 166 | } |
167 | - if($test2!='') $test = $test2; |
|
168 | - }else{ |
|
167 | + if ($test2!='') $test = $test2; |
|
168 | + }else { |
|
169 | 169 | $test = 'blocked'; |
170 | 170 | } |
171 | 171 | } |
172 | - if(strripos($test,'not found')!==false) return ''; |
|
173 | - if(strripos($test,'SERVFAIL')!==false) return ''; |
|
172 | + if (strripos($test, 'not found')!==false) return ''; |
|
173 | + if (strripos($test, 'SERVFAIL')!==false) return ''; |
|
174 | 174 | return trim($test); |
175 | 175 | } |
176 | 176 | |
177 | - public static function logBlockListStats($server, $monitorType, $isBlocked){ |
|
178 | - if(Setup::$settings['log_rbl_stats']==0) return true; |
|
177 | + public static function logBlockListStats($server, $monitorType, $isBlocked) { |
|
178 | + if (Setup::$settings['log_rbl_stats']==0) return true; |
|
179 | 179 | $mysql = new _MySQL(); |
180 | 180 | $mysql->connect(Setup::$connectionArray); |
181 | - if($isBlocked){ |
|
181 | + if ($isBlocked) { |
|
182 | 182 | $sql = "update blockLists set blocksToday=(blocksToday+1), lastBlockReport=now() where host = '".$mysql->escape($server)."' and monitorType = '$monitorType';"; |
183 | - }else{ |
|
183 | + }else { |
|
184 | 184 | $sql = "update blockLists set cleanToday=(cleanToday+1) where host = '".$mysql->escape($server)."' and monitorType = '$monitorType';"; |
185 | 185 | } |
186 | 186 | $mysql->runQuery($sql); |
187 | 187 | $mysql->close(); |
188 | 188 | } |
189 | 189 | |
190 | - public static function ensureGroupExists($groupName){ |
|
190 | + public static function ensureGroupExists($groupName) { |
|
191 | 191 | $mysql = new _MySQL(); |
192 | 192 | $mysql->connect(Setup::$connectionArray); |
193 | 193 | $id = $mysql->runQueryReturnVar("select id from monitorGroup where groupName = '".$mysql->escape($groupName)."'"); |
194 | - if($id===false){ |
|
194 | + if ($id===false) { |
|
195 | 195 | $mysql->runQuery("insert into monitorGroup set groupName = '".$mysql->escape($groupName)."'"); |
196 | 196 | $id = $mysql->identity; |
197 | 197 | } |
@@ -199,23 +199,23 @@ discard block |
||
199 | 199 | return $id; |
200 | 200 | } |
201 | 201 | |
202 | - public static function updateDomains($domains, $monitorGroupId){ |
|
202 | + public static function updateDomains($domains, $monitorGroupId) { |
|
203 | 203 | $domains = trim($domains); |
204 | 204 | $monitorGroupId = (int)$monitorGroupId; |
205 | - if($monitorGroupId===0) return false; |
|
205 | + if ($monitorGroupId===0) return false; |
|
206 | 206 | $mysql = new _MySQL(); |
207 | 207 | $mysql->connect(Setup::$connectionArray); |
208 | 208 | $mysql->runQuery("update monitors set keepOnUpdate = 0 where isDomain = 1 and monitorGroupId = $monitorGroupId"); |
209 | 209 | $mysql->runQuery("update users set lastUpdate = '".$mysql->escape(date('Y-m-d H:i:s'))."'"); |
210 | 210 | $mysql->runQuery("update monitorGroup set domains = '".$mysql->escape($domains)."' where id = $monitorGroupId"); |
211 | 211 | $domainArray = preg_split('/\s+/', $domains); |
212 | - foreach($domainArray as $d){ |
|
212 | + foreach ($domainArray as $d) { |
|
213 | 213 | $d = trim($d); |
214 | 214 | $d = str_ireplace('http://', '', $d); |
215 | 215 | $d = str_ireplace('https://', '', $d); |
216 | 216 | $d = str_ireplace('/', '', $d); |
217 | 217 | $d = preg_replace('/[[:^print:]]/', '', $d); |
218 | - if($d != ''){ |
|
218 | + if ($d!='') { |
|
219 | 219 | $mysql->runQuery(" |
220 | 220 | update monitors set |
221 | 221 | keepOnUpdate = 1 |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | and ipDomain = '".$mysql->escape($d)."' |
225 | 225 | and isDomain = 1 |
226 | 226 | "); |
227 | - if($mysql->affectedRows == 0){ |
|
227 | + if ($mysql->affectedRows==0) { |
|
228 | 228 | $mysql->runQuery("insert ignore into monitors set |
229 | 229 | monitorGroupId = $monitorGroupId, |
230 | 230 | ipDomain = '".$mysql->escape($d)."', |
@@ -238,19 +238,19 @@ discard block |
||
238 | 238 | $mysql->close(); |
239 | 239 | } |
240 | 240 | |
241 | - public static function updateIPs($ips, $monitorGroupId){ |
|
241 | + public static function updateIPs($ips, $monitorGroupId) { |
|
242 | 242 | $ips = trim($ips); |
243 | 243 | $monitorGroupId = (int)$monitorGroupId; |
244 | - if($monitorGroupId===0) return false; |
|
244 | + if ($monitorGroupId===0) return false; |
|
245 | 245 | $mysql = new _MySQL(); |
246 | 246 | $mysql->connect(Setup::$connectionArray); |
247 | 247 | $mysql->runQuery("update monitors set keepOnUpdate = 0 where isDomain = 0 and monitorGroupId = $monitorGroupId"); |
248 | 248 | $mysql->runQuery("update users set lastUpdate = '".$mysql->escape(date('Y-m-d H:i:s'))."'"); |
249 | 249 | $mysql->runQuery("update monitorGroup set ips = '".$mysql->escape($ips)."' where id = $monitorGroupId"); |
250 | - $ipsArray = preg_split('/\s+/', $ips); |
|
251 | - foreach($ipsArray as $i){ |
|
250 | + $ipsArray = preg_split('/\s+/', $ips); |
|
251 | + foreach ($ipsArray as $i) { |
|
252 | 252 | // ip checks |
253 | - if(_IpAddresses::isIPAddress($i)){ |
|
253 | + if (_IpAddresses::isIPAddress($i)) { |
|
254 | 254 | $mysql->runQuery(" |
255 | 255 | update monitors set |
256 | 256 | keepOnUpdate = 1 |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | and ipDomain = '".$mysql->escape($i)."' |
260 | 260 | and isDomain = 0 |
261 | 261 | "); |
262 | - if($mysql->affectedRows == 0){ |
|
262 | + if ($mysql->affectedRows==0) { |
|
263 | 263 | $mysql->runQuery("insert ignore into monitors set |
264 | 264 | monitorGroupId = $monitorGroupId, |
265 | 265 | ipDomain = '".$mysql->escape($i)."', |
@@ -267,19 +267,19 @@ discard block |
||
267 | 267 | keepOnUpdate = 1 |
268 | 268 | "); |
269 | 269 | } |
270 | - }else{ |
|
270 | + }else { |
|
271 | 271 | //cidr /24's max... |
272 | - if(trim($i)!=''){ |
|
273 | - if(strpos($i, ' ')!==false) continue; |
|
274 | - if(strpos($i, ':')!==false) continue; |
|
272 | + if (trim($i)!='') { |
|
273 | + if (strpos($i, ' ')!==false) continue; |
|
274 | + if (strpos($i, ':')!==false) continue; |
|
275 | 275 | $range = _IpAddresses::cidrToRange($i); |
276 | - if($range===false) continue; |
|
276 | + if ($range===false) continue; |
|
277 | 277 | $start = explode('.', $range[0]); |
278 | 278 | $end = explode('.', $range[1]); |
279 | - if($range[0]==0) continue;// starts with 0 |
|
280 | - for($i = $start[3]; $i <= $end[3]; $i++){ |
|
279 | + if ($range[0]==0) continue; // starts with 0 |
|
280 | + for ($i = $start[3]; $i <= $end[3]; $i++) { |
|
281 | 281 | $host = "{$start[0]}.{$start[1]}.{$start[2]}.$i"; |
282 | - if(_IpAddresses::isIPAddress($host)){ |
|
282 | + if (_IpAddresses::isIPAddress($host)) { |
|
283 | 283 | $mysql->runQuery(" |
284 | 284 | update monitors set |
285 | 285 | keepOnUpdate = 1 |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | and ipDomain = '".$mysql->escape($host)."' |
289 | 289 | and isDomain = 0 |
290 | 290 | "); |
291 | - if($mysql->affectedRows == 0){ |
|
291 | + if ($mysql->affectedRows==0) { |
|
292 | 292 | $mysql->runQuery("insert ignore into monitors set |
293 | 293 | monitorGroupId = $monitorGroupId, |
294 | 294 | ipDomain = '".$mysql->escape($host)."', |
@@ -305,15 +305,15 @@ discard block |
||
305 | 305 | $mysql->close(); |
306 | 306 | } |
307 | 307 | |
308 | - public static function isLoggedIn(){ |
|
309 | - if(isset($_SESSION['id']) && (int)$_SESSION['id'] > 0){ |
|
308 | + public static function isLoggedIn() { |
|
309 | + if (isset($_SESSION['id']) && (int)$_SESSION['id'] > 0) { |
|
310 | 310 | return $_SESSION['id']; |
311 | - }else{ |
|
311 | + }else { |
|
312 | 312 | return false; |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - public static function getAccount(){ |
|
316 | + public static function getAccount() { |
|
317 | 317 | $mysql = new _MySQL(); |
318 | 318 | $mysql->connect(Setup::$connectionArray); |
319 | 319 | $ret = false; |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | apiCallbackURL, |
331 | 331 | checkFrequency |
332 | 332 | from users limit 1"); |
333 | - while($row = mysqli_fetch_array($rs)){ |
|
333 | + while ($row = mysqli_fetch_array($rs)) { |
|
334 | 334 | $ret = $row; |
335 | 335 | } |
336 | 336 | $mysql->close(); |
337 | 337 | |
338 | - if(!$ret){ |
|
338 | + if (!$ret) { |
|
339 | 339 | //account |
340 | 340 | _Logging::appLog("no user account"); |
341 | 341 | exit(); |
@@ -344,44 +344,44 @@ discard block |
||
344 | 344 | return $ret; |
345 | 345 | } |
346 | 346 | |
347 | - public static function validateLogin($userName, $passwd, $api = false, $apiKey = ''){ |
|
347 | + public static function validateLogin($userName, $passwd, $api = false, $apiKey = '') { |
|
348 | 348 | $mysql = new _MySQL(); |
349 | 349 | $mysql->connect(Setup::$connectionArray); |
350 | 350 | $sql = " |
351 | 351 | select username |
352 | 352 | from users |
353 | 353 | where "; |
354 | - if(trim($apiKey) != ''){ |
|
354 | + if (trim($apiKey)!='') { |
|
355 | 355 | $sql .= " apiKey = '".$mysql->escape($apiKey)."'"; |
356 | - }else{ |
|
356 | + }else { |
|
357 | 357 | $sql .= " passwd = '".$mysql->escape(md5($passwd))."' |
358 | 358 | and username = '".$mysql->escape($userName)."'"; |
359 | 359 | } |
360 | 360 | $rs = $mysql->runQuery($sql); |
361 | 361 | $id = 0; |
362 | - while($row = mysqli_fetch_array($rs)){ |
|
362 | + while ($row = mysqli_fetch_array($rs)) { |
|
363 | 363 | $id = 1; |
364 | 364 | } |
365 | 365 | $mysql->close(); |
366 | 366 | return $id; |
367 | 367 | } |
368 | 368 | |
369 | - public static function lookupHostDNS($host){ |
|
370 | - if(_IpAddresses::isIPAddress($host)){ |
|
369 | + public static function lookupHostDNS($host) { |
|
370 | + if (_IpAddresses::isIPAddress($host)) { |
|
371 | 371 | return _IpAddresses::getHostByIp($host); |
372 | - }else{ |
|
372 | + }else { |
|
373 | 373 | $host = escapeshellarg($host); |
374 | 374 | exec('host -t a -W 2 '.$host, $output, $return); |
375 | - if ($return !== 0) { |
|
375 | + if ($return!==0) { |
|
376 | 376 | return ''; |
377 | - }else{ |
|
377 | + }else { |
|
378 | 378 | $output = implode($output); |
379 | 379 | $ips = _IpAddresses::getAllIPsFromString($output, true); |
380 | 380 | $ir = ""; |
381 | - foreach($ips as $ip){ |
|
381 | + foreach ($ips as $ip) { |
|
382 | 382 | $ir .= "$ip,"; |
383 | 383 | } |
384 | - return trim($ir,','); |
|
384 | + return trim($ir, ','); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /* |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | - public static function testAPICallback($url){ |
|
397 | + public static function testAPICallback($url) { |
|
398 | 398 | return self::makeAPICallback($url, |
399 | 399 | 'samplehosttest.com', |
400 | 400 | true, |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | ); |
404 | 404 | } |
405 | 405 | |
406 | - public static function makeAPICallback($url, $host, $isBlocked, $rDNS, $status){ |
|
407 | - if(substr($url,0,4)!='http') return false; |
|
406 | + public static function makeAPICallback($url, $host, $isBlocked, $rDNS, $status) { |
|
407 | + if (substr($url, 0, 4)!='http') return false; |
|
408 | 408 | |
409 | 409 | $vars = json_encode( |
410 | 410 | array( |
@@ -415,14 +415,14 @@ discard block |
||
415 | 415 | ) |
416 | 416 | ); |
417 | 417 | $err = true; |
418 | - try{ |
|
418 | + try { |
|
419 | 419 | $ch = curl_init(); |
420 | - curl_setopt($ch,CURLOPT_URL,$url); |
|
421 | - curl_setopt($ch,CURLOPT_POST,true); |
|
422 | - curl_setopt($ch,CURLOPT_FAILONERROR,true); |
|
423 | - curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); |
|
424 | - curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); |
|
425 | - curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
|
420 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
421 | + curl_setopt($ch, CURLOPT_POST, true); |
|
422 | + curl_setopt($ch, CURLOPT_FAILONERROR, true); |
|
423 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
424 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); |
|
425 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
|
426 | 426 | curl_exec($ch); |
427 | 427 | if (curl_errno($ch)) $err = false; |
428 | 428 | } catch (Exception $e) { |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | return $err; |
432 | 432 | } |
433 | 433 | |
434 | - public static function isValidEmail($emailAddress){ |
|
434 | + public static function isValidEmail($emailAddress) { |
|
435 | 435 | if (filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { |
436 | 436 | return true; |
437 | 437 | } |
@@ -442,36 +442,36 @@ discard block |
||
442 | 442 | $text, |
443 | 443 | $beginText, |
444 | 444 | $endText, |
445 | - $removeSpace=true, |
|
446 | - $removeHtmlTags=true, |
|
447 | - $firstResultOnlyNoArray=false) { |
|
445 | + $removeSpace = true, |
|
446 | + $removeHtmlTags = true, |
|
447 | + $firstResultOnlyNoArray = false) { |
|
448 | 448 | $results = array(); |
449 | 449 | $endPos = 0; |
450 | - while(true) { |
|
450 | + while (true) { |
|
451 | 451 | $beginPos = stripos($text, $beginText, $endPos); |
452 | - if($beginPos===false) break; |
|
452 | + if ($beginPos===false) break; |
|
453 | 453 | $beginPos = $beginPos+strlen($beginText); |
454 | 454 | $endPos = stripos($text, $endText, $beginPos); |
455 | - if($endPos===false) break; |
|
455 | + if ($endPos===false) break; |
|
456 | 456 | $result = substr($text, $beginPos, $endPos-$beginPos); |
457 | - if($removeSpace){ |
|
458 | - $result = str_replace("\t","",$result); |
|
459 | - $result = str_replace("\n","",$result); |
|
460 | - $result = preg_replace("/ /"," ",$result); |
|
461 | - $result = preg_replace("~[\s]{2}?[\t]?~i"," ",$result); |
|
462 | - $result = str_replace(" "," ",$result); |
|
457 | + if ($removeSpace) { |
|
458 | + $result = str_replace("\t", "", $result); |
|
459 | + $result = str_replace("\n", "", $result); |
|
460 | + $result = preg_replace("/ /", " ", $result); |
|
461 | + $result = preg_replace("~[\s]{2}?[\t]?~i", " ", $result); |
|
462 | + $result = str_replace(" ", " ", $result); |
|
463 | 463 | $result = trim($result); |
464 | 464 | } |
465 | - if($removeHtmlTags){ |
|
465 | + if ($removeHtmlTags) { |
|
466 | 466 | $result = strip_tags($result); |
467 | 467 | } |
468 | - if($firstResultOnlyNoArray) return $result; |
|
469 | - if($result != '') $results[] = $result; |
|
468 | + if ($firstResultOnlyNoArray) return $result; |
|
469 | + if ($result!='') $results[] = $result; |
|
470 | 470 | } |
471 | 471 | return ($firstResultOnlyNoArray && empty($results) ? '' : $results); |
472 | 472 | } |
473 | 473 | |
474 | - public static function getNextMonitor($mysql){ |
|
474 | + public static function getNextMonitor($mysql) { |
|
475 | 475 | $ipDomain = $mysql->runQueryReturnVar("select ipDomain from monitors where beenChecked = 0"); |
476 | 476 | $mysql->runQuery("update monitors set beenChecked = 1 where ipDomain = '".$mysql->escape($ipDomain)."'"); |
477 | 477 | return $ipDomain; |
@@ -480,49 +480,49 @@ discard block |
||
480 | 480 | public static function getHostChangeCount($mysql, $monitorGroupId = 0) { |
481 | 481 | $sql = ''; |
482 | 482 | $monitorGroupId = (int)$monitorGroupId; |
483 | - if($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
483 | + if ($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
484 | 484 | return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors where lastStatusChanged = 1 $sql"); |
485 | 485 | } |
486 | 486 | |
487 | 487 | public static function getHostErrorCount($mysql, $monitorGroupId = 0, $onlyNew = false) { |
488 | 488 | $sql = ''; |
489 | 489 | $monitorGroupId = (int)$monitorGroupId; |
490 | - if($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
491 | - if($onlyNew) $sql .= " and lastStatusChanged = 1 "; |
|
490 | + if ($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
491 | + if ($onlyNew) $sql .= " and lastStatusChanged = 1 "; |
|
492 | 492 | return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors where isBlocked = 1 $sql"); |
493 | 493 | } |
494 | 494 | |
495 | 495 | public static function getHostCleanCount($mysql, $monitorGroupId = 0, $onlyNew = false) { |
496 | 496 | $sql = ''; |
497 | 497 | $monitorGroupId = (int)$monitorGroupId; |
498 | - if($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
499 | - if($onlyNew) $sql .= " and lastStatusChanged = 1 "; |
|
498 | + if ($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
499 | + if ($onlyNew) $sql .= " and lastStatusChanged = 1 "; |
|
500 | 500 | return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors where isBlocked = 0 $sql"); |
501 | 501 | } |
502 | 502 | |
503 | 503 | public static function getHostCount($mysql, $monitorGroupId = 0) { |
504 | 504 | $sql = ''; |
505 | 505 | $monitorGroupId = (int)$monitorGroupId; |
506 | - if($monitorGroupId > 0) $sql = " where monitorGroupId = $monitorGroupId"; |
|
506 | + if ($monitorGroupId > 0) $sql = " where monitorGroupId = $monitorGroupId"; |
|
507 | 507 | return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors $sql"); |
508 | 508 | } |
509 | 509 | |
510 | 510 | //CREDIT: http://braincrafted.com/php-background-processes/ |
511 | - public static function is_process_running($pid){ |
|
511 | + public static function is_process_running($pid) { |
|
512 | 512 | $pid = (int)$pid; |
513 | - if($pid == 0) return false; |
|
514 | - if(file_exists('/proc/'.$pid)){ |
|
513 | + if ($pid==0) return false; |
|
514 | + if (file_exists('/proc/'.$pid)) { |
|
515 | 515 | return true; |
516 | - }else{ |
|
516 | + }else { |
|
517 | 517 | return false; |
518 | 518 | } |
519 | 519 | } |
520 | 520 | |
521 | 521 | public static function run_in_background($command, $priority = 0) { |
522 | 522 | $log = Setup::$settings['log_path']; |
523 | - if($priority !=0){ |
|
523 | + if ($priority!=0) { |
|
524 | 524 | $pid = shell_exec("nohup nice -n $priority $command >> $log 2>&1 & echo $!"); |
525 | - }else{ |
|
525 | + }else { |
|
526 | 526 | $pid = shell_exec("nohup $command >> $log 2>&1 & echo $!"); |
527 | 527 | } |
528 | 528 | return($pid); |
@@ -62,14 +62,18 @@ |
||
62 | 62 | ) { |
63 | 63 | $this->affectedRows = mysqli_affected_rows($this->mysqlCon); |
64 | 64 | } |
65 | - if (stripos($query, 'INSERT')!==false) $this->identity = mysqli_insert_id($this->mysqlCon); |
|
65 | + if (stripos($query, 'INSERT')!==false) { |
|
66 | + $this->identity = mysqli_insert_id($this->mysqlCon); |
|
67 | + } |
|
66 | 68 | return $result; |
67 | 69 | } |
68 | 70 | |
69 | 71 | public function runQueryReturnVar($query) { |
70 | 72 | $result = false; |
71 | 73 | $rs = $this->runQuery($query." limit 1;"); |
72 | - while ($row = mysqli_fetch_array($rs)) $result = $row[0]; |
|
74 | + while ($row = mysqli_fetch_array($rs)) { |
|
75 | + $result = $row[0]; |
|
76 | + } |
|
73 | 77 | mysqli_free_result($rs); |
74 | 78 | return $result; |
75 | 79 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | ini_set('memory_limit', '1024M'); |
5 | 5 | |
6 | 6 | //prevent non cli access |
7 | -if(php_sapi_name()!=='cli') exit(); |
|
7 | +if (php_sapi_name()!=='cli') exit(); |
|
8 | 8 | |
9 | 9 | $dir = dirname(dirname(__FILE__)); |
10 | 10 | class_exists('Setup', false) or include($dir.'/classes/Setup.class.php'); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $options = getopt("i:"); |
20 | 20 | $parentProcessId = isset($options['i']) ? (int)$options['i'] : 0; |
21 | 21 | |
22 | -if($parentProcessId == 0){ |
|
22 | +if ($parentProcessId==0) { |
|
23 | 23 | _Logging::appLog("userJob called without all params"); |
24 | 24 | exit(); |
25 | 25 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | // get the accounts blacklists |
38 | 38 | Utilities::setBlockLists(); |
39 | 39 | |
40 | -if( (empty(Utilities::$domainBlacklists)===true) && (empty(Utilities::$ipBlacklists)===true) ){ |
|
40 | +if ((empty(Utilities::$domainBlacklists)===true) && (empty(Utilities::$ipBlacklists)===true)) { |
|
41 | 41 | _Logging::appLog("no blacklists configured"); |
42 | 42 | // mark this one as ran |
43 | 43 | $mysql->runQuery("update users set beenChecked = 1, lastChecked = '".date('Y-m-d H:i:s')."'"); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | //anything to monitor? |
48 | 48 | $monitorCount = Utilities::getHostCount($mysql); |
49 | -if($monitorCount==0){ |
|
49 | +if ($monitorCount==0) { |
|
50 | 50 | _Logging::appLog("nothing to monitor"); |
51 | 51 | exit(); |
52 | 52 | } |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | $mysql->runQuery("update monitors set beenChecked = 0"); |
56 | 56 | |
57 | 57 | // wait for results |
58 | -while(true){ |
|
59 | - if(!Utilities::is_process_running($parentProcessId)){ |
|
58 | +while (true) { |
|
59 | + if (!Utilities::is_process_running($parentProcessId)) { |
|
60 | 60 | _Logging::appLog("parent died - userJob exited"); |
61 | 61 | exit(); |
62 | 62 | } |
63 | 63 | $rs = $mysql->runQuery("select ipDomain from monitors where beenChecked = 0 limit 1;"); |
64 | - if($row = mysqli_fetch_array($rs)){ |
|
65 | - sleep(4);//wait 4 seconds for them to finish |
|
66 | - }else{ |
|
64 | + if ($row = mysqli_fetch_array($rs)) { |
|
65 | + sleep(4); //wait 4 seconds for them to finish |
|
66 | + }else { |
|
67 | 67 | break; |
68 | 68 | } |
69 | 69 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $newCleanHosts = Utilities::getHostCleanCount($mysql, 0, true); |
83 | 83 | |
84 | 84 | |
85 | -if($hostsChanged > 0 && $user['disableEmailNotices']==0){ |
|
85 | +if ($hostsChanged > 0 && $user['disableEmailNotices']==0) { |
|
86 | 86 | $table = ""; |
87 | 87 | $summary = ""; |
88 | 88 | $summaryText = ""; |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | |
101 | 101 | $summary .= "<br><div><a href='$url/m.php'>Monitor Groups</a></div><br>"; |
102 | 102 | |
103 | - if( (isset(Setup::$settings['email_report_detailed_host_changes'])) |
|
104 | - && (Setup::$settings['email_report_detailed_host_changes']==true) ){ |
|
103 | + if ((isset(Setup::$settings['email_report_detailed_host_changes'])) |
|
104 | + && (Setup::$settings['email_report_detailed_host_changes']==true)) { |
|
105 | 105 | $table .= '<hr>'; |
106 | 106 | $table .= '<strong>New Blocks</strong><br>'; |
107 | 107 | $rs = $mysql->runQuery("select m.ipDomain, mg.groupName FROM monitors m inner join monitorGroup mg on mg.id = m.monitorGroupId where m.isBlocked = 1 and m.lastStatusChanged = 1 order by m.isDomain desc, m.ipDomain"); |
108 | 108 | $table .= '<table width="100%">'; |
109 | - while($row = mysqli_fetch_array($rs)){ |
|
109 | + while ($row = mysqli_fetch_array($rs)) { |
|
110 | 110 | $table .= '<tr>'; |
111 | 111 | $table .= '<td><a href="'.$url.'"/hostHistory.php?host='.urlencode($row['ipDomain']).'">'.$row['ipDomain'].'</a></td><td>'.$row['groupName'].'</td>'; |
112 | 112 | $table .= '</tr>'; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $table .= '<strong>New Clean</strong><br>'; |
118 | 118 | $rs = $mysql->runQuery("select m.ipDomain, mg.groupName FROM monitors m inner join monitorGroup mg on mg.id = m.monitorGroupId where m.isBlocked = 0 and m.lastStatusChanged = 1 order by m.isDomain desc, m.ipDomain"); |
119 | 119 | $table .= '<table width="100%">'; |
120 | - while($row = mysqli_fetch_array($rs)){ |
|
120 | + while ($row = mysqli_fetch_array($rs)) { |
|
121 | 121 | $table .= '<tr>'; |
122 | 122 | $table .= '<td><a href="'.$url.'"/hostHistory.php?host='.urlencode($row['ipDomain']).'">'.$row['ipDomain'].'</a></td><td>'.$row['groupName'].'</td>'; |
123 | 123 | $table .= '</tr>'; |
@@ -133,16 +133,16 @@ discard block |
||
133 | 133 | $summaryText .= "New Blocked: ".number_format($newErrorHosts)."\n"; |
134 | 134 | $summaryText .= "New Clean: ".number_format($newCleanHosts)."\n"; |
135 | 135 | |
136 | - $e = explode("\n",$user['noticeEmailAddresses']); |
|
137 | - if( (count($e) > 0) && (Setup::$settings['smtp_server']!='') ){ |
|
136 | + $e = explode("\n", $user['noticeEmailAddresses']); |
|
137 | + if ((count($e) > 0) && (Setup::$settings['smtp_server']!='')) { |
|
138 | 138 | // regular email |
139 | 139 | $mail = new PHPMailer(); |
140 | 140 | $mail->IsSMTP(); |
141 | 141 | $mail->Host = Setup::$settings['smtp_server']; |
142 | 142 | $mail->From = Setup::$settings['from_email']; |
143 | 143 | $mail->FromName = Setup::$settings['from_name']; |
144 | - foreach($e as $a){ |
|
145 | - if(trim($a)!=''){ |
|
144 | + foreach ($e as $a) { |
|
145 | + if (trim($a)!='') { |
|
146 | 146 | $mail->AddAddress($a); |
147 | 147 | } |
148 | 148 | } |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | // text message |
156 | - $e = explode("\n",$user['textMessageEmails']); |
|
157 | - if( (count($e) > 0) && (Setup::$settings['smtp_server']!='') ){ |
|
156 | + $e = explode("\n", $user['textMessageEmails']); |
|
157 | + if ((count($e) > 0) && (Setup::$settings['smtp_server']!='')) { |
|
158 | 158 | $mail = new PHPMailer(); |
159 | 159 | $mail->IsSMTP(); |
160 | 160 | $mail->Host = Setup::$settings['smtp_server']; |
161 | 161 | $mail->From = Setup::$settings['from_email']; |
162 | 162 | $mail->FromName = Setup::$settings['from_name']; |
163 | - foreach($e as $a){ |
|
164 | - if(trim($a)!=''){ |
|
163 | + foreach ($e as $a) { |
|
164 | + if (trim($a)!='') { |
|
165 | 165 | $mail->AddAddress($a); |
166 | 166 | } |
167 | 167 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $mail->Send(); |
172 | 172 | } |
173 | 173 | |
174 | - if($user['twitterHandle']!=''){ |
|
174 | + if ($user['twitterHandle']!='') { |
|
175 | 175 | $t = new Twitter(); |
176 | 176 | $t->message($user['twitterHandle'], $summaryText); |
177 | 177 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | ini_set('memory_limit', '64M'); |
6 | 6 | |
7 | 7 | //prevent non cli access |
8 | -if(php_sapi_name()!=='cli') exit(); |
|
8 | +if (php_sapi_name()!=='cli') exit(); |
|
9 | 9 | |
10 | 10 | $dir = dirname(dirname(__FILE__)); |
11 | 11 | class_exists('Setup', false) or include($dir.'/classes/Setup.class.php'); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | $options = getopt("h:"); |
17 | 17 | $options['h'] = isset($options['h']) ? trim($options['h']) : ''; |
18 | 18 | |
19 | -if($options['h'] == ''){ |
|
19 | +if ($options['h']=='') { |
|
20 | 20 | _Logging::appLog("monitorJob called without params"); |
21 | 21 | exit(); |
22 | 22 | } |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | select * |
29 | 29 | from monitors |
30 | 30 | where ipDomain = '".$mysql->escape($options['h'])."'"); |
31 | -while($row = mysqli_fetch_array($rs)) { |
|
31 | +while ($row = mysqli_fetch_array($rs)) { |
|
32 | 32 | $monitor = $row; |
33 | 33 | } |
34 | 34 | |
35 | 35 | // get blacklists |
36 | 36 | Utilities::setBlockLists(); |
37 | 37 | |
38 | -if( (empty(Utilities::$domainBlacklists)===true) && (empty(Utilities::$ipBlacklists)===true) ){ |
|
38 | +if ((empty(Utilities::$domainBlacklists)===true) && (empty(Utilities::$ipBlacklists)===true)) { |
|
39 | 39 | _Logging::appLog("no blacklists configured"); |
40 | 40 | exit(); |
41 | 41 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | |
61 | 61 | // status change on this host |
62 | -if(strcasecmp($result, $monitor['status']) != 0){ |
|
62 | +if (strcasecmp($result, $monitor['status'])!=0) { |
|
63 | 63 | //update current status |
64 | 64 | $mysql->runQuery(" |
65 | 65 | update monitors |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | //make api callback |
84 | 84 | $user = Utilities::getAccount(); |
85 | - if($user['apiCallbackURL']!=''){ |
|
85 | + if ($user['apiCallbackURL']!='') { |
|
86 | 86 | Utilities::makeAPICallback($user['apiCallbackURL'], |
87 | 87 | $monitor['ipDomain'], |
88 | 88 | $isBlocked, |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class_exists('Utilities', false) or include('classes/Utilities.class.php'); |
4 | 4 | class_exists('_MySQL', false) or include('classes/_MySQL.class.php'); |
5 | 5 | |
6 | -if(Utilities::isLoggedIn()===false){ |
|
6 | +if (Utilities::isLoggedIn()===false) { |
|
7 | 7 | header('Location: login.php?location='.urlencode('hosts.php')); |
8 | 8 | exit(); |
9 | 9 | } |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | $user = Utilities::getAccount(); |
16 | 16 | $mysql = new _MySQL(); |
17 | 17 | $mysql->connect(Setup::$connectionArray); |
18 | -if($host != ''){ |
|
19 | - if($toggle==0){ |
|
18 | +if ($host!='') { |
|
19 | + if ($toggle==0) { |
|
20 | 20 | $mysql->runQuery(" |
21 | 21 | update blockLists |
22 | 22 | set isActive = '0' |
23 | 23 | where md5(host) = '".$mysql->escape($host)."'"); |
24 | - }else{ |
|
24 | + }else { |
|
25 | 25 | $mysql->runQuery(" |
26 | 26 | update blockLists |
27 | 27 | set isActive = '1' |
@@ -98,28 +98,28 @@ discard block |
||
98 | 98 | </thead> |
99 | 99 | <tbody> |
100 | 100 | <?php |
101 | - while($row = mysqli_fetch_array($rs)){ |
|
101 | + while ($row = mysqli_fetch_array($rs)) { |
|
102 | 102 | echo('<tr>'); |
103 | 103 | echo('<td style="text-align: center;">'); |
104 | - if($row['isActive']==0){ |
|
104 | + if ($row['isActive']==0) { |
|
105 | 105 | echo('<a data-blstatus="0" data-host="'.md5($row['host']).'" id="'.md5($row['host']).'" class="blockListLinks glyphicon glyphicon-remove" href="#"></a></td>'); |
106 | - }else{ |
|
106 | + }else { |
|
107 | 107 | echo('<a data-blstatus="1" data-host="'.md5($row['host']).'" id="'.md5($row['host']).'" class="blockListLinks glyphicon glyphicon-ok" href="#"></a></td>'); |
108 | 108 | } |
109 | 109 | echo('<td style="white-space: nowrap"><a target="_blank" href="'.$row['website'].'">'.$row['host'].'</a></td>'); |
110 | 110 | echo('<td style="white-space: nowrap">'.($row['monitorType']=='ip' ? 'IP' : 'Domain').'</td>'); |
111 | 111 | echo('<td>'.$row['description'].'</td>'); |
112 | 112 | echo('<td style="text-align: center;">'); |
113 | - switch($row['importance']){ |
|
113 | + switch ($row['importance']) { |
|
114 | 114 | case 3: echo('<span class="label label-primary">High</span>'); break; |
115 | 115 | case 2: echo('<span class="label label-info">Medium</span>'); break; |
116 | 116 | case 1: echo('<span class="label label-default">Low</span>'); break; |
117 | 117 | } |
118 | 118 | echo('</td>'); |
119 | - echo('<td style="white-space: nowrap">'.number_format($row['blocksToday'],0).'</td>'); |
|
120 | - echo('<td style="white-space: nowrap">'.number_format($row['cleanToday'],0).'</td>'); |
|
121 | - echo('<td style="white-space: nowrap">'.number_format($row['blocksYesterday'],0).'</td>'); |
|
122 | - echo('<td style="white-space: nowrap">'.number_format($row['cleanYesterday'],0).'</td>'); |
|
119 | + echo('<td style="white-space: nowrap">'.number_format($row['blocksToday'], 0).'</td>'); |
|
120 | + echo('<td style="white-space: nowrap">'.number_format($row['cleanToday'], 0).'</td>'); |
|
121 | + echo('<td style="white-space: nowrap">'.number_format($row['blocksYesterday'], 0).'</td>'); |
|
122 | + echo('<td style="white-space: nowrap">'.number_format($row['cleanYesterday'], 0).'</td>'); |
|
123 | 123 | echo('</tr>'); |
124 | 124 | } |
125 | 125 | $mysql->close(); |