@@ -10,21 +10,25 @@ discard block |
||
| 10 | 10 | if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) { |
| 11 | 11 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
| 13 | - if ( preg_match($msa,$received['host'][$i]) ) |
|
| 14 | - $dateR = $received['date'][$i]; |
|
| 13 | + if ( preg_match($msa,$received['host'][$i]) ) { |
|
| 14 | + $dateR = $received['date'][$i]; |
|
| 15 | + } |
|
| 15 | 16 | foreach ($mxserver as $mx) { |
| 16 | - if (!$ip) |
|
| 17 | - if ($mx == $received['host'][$i]) { |
|
| 17 | + if (!$ip) { |
|
| 18 | + if ($mx == $received['host'][$i]) { |
|
| 18 | 19 | $host = $received['host'][$i]; |
| 20 | + } |
|
| 19 | 21 | $ip = $received['ip'][$i]; |
| 20 | 22 | } |
| 21 | 23 | } |
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
|
| 25 | - $dateC['date'] = 'Not found'; |
|
| 26 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) |
|
| 27 | - $mid['mid'] = NULL; |
|
| 26 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) { |
|
| 27 | + $dateC['date'] = 'Not found'; |
|
| 28 | + } |
|
| 29 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) { |
|
| 30 | + $mid['mid'] = NULL; |
|
| 31 | + } |
|
| 28 | 32 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); |
| 29 | 33 | } |
| 30 | 34 | |
@@ -40,7 +44,9 @@ discard block |
||
| 40 | 44 | |
| 41 | 45 | function summaryBadReport ($uidvet) { |
| 42 | 46 | $nuid = $uidvet['count']; |
| 43 | - if ( empty($uidvet) ) return NULL; |
|
| 47 | + if ( empty($uidvet) ) { |
|
| 48 | + return NULL; |
|
| 49 | + } |
|
| 44 | 50 | $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
| 45 | 51 | |
| 46 | 52 | /* Remove count index */ |
@@ -75,8 +81,12 @@ discard block |
||
| 75 | 81 | foreach ($colarr as $col => $arr) { |
| 76 | 82 | foreach ($arr as $k => $v) { |
| 77 | 83 | $k = substr($k,1); |
| 78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
| 79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
| 84 | + if (!isset($ret[$k])) { |
|
| 85 | + $ret[$k] = $array[$k]; |
|
| 86 | + } |
|
| 87 | + if (isset ($array[$k][$col])) { |
|
| 88 | + $ret[$k][$col] = $array[$k][$col]; |
|
| 89 | + } |
|
| 80 | 90 | } |
| 81 | 91 | } |
| 82 | 92 | return $ret; |
@@ -87,13 +97,17 @@ discard block |
||
| 87 | 97 | function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { |
| 88 | 98 | $nips = $ipvet['count']; |
| 89 | 99 | |
| 90 | - if ( empty($ipvet) ) return NULL; |
|
| 100 | + if ( empty($ipvet) ) { |
|
| 101 | + return NULL; |
|
| 102 | + } |
|
| 91 | 103 | $return = '<h3>Statistics by IP</h3><table><tr><th>IP</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this ip is currently listed, but it says if this IP has listed now!">Listed Now</th></tr>'."\n"; |
| 92 | 104 | |
| 93 | 105 | $ips = array_keys($ipvet['ip']); |
| 94 | 106 | |
| 95 | 107 | foreach ( $ips as $ip ) { |
| 96 | - if ( $ip == 'count' ) continue; |
|
| 108 | + if ( $ip == 'count' ) { |
|
| 109 | + continue; |
|
| 110 | + } |
|
| 97 | 111 | $nlearn = $ipvet['ip']["$ip"]['count']; |
| 98 | 112 | unset($ipvet['ip']["$ip"]['count']); |
| 99 | 113 | $nuid = count($ipvet['ip']["$ip"]); |
@@ -101,10 +115,12 @@ discard block |
||
| 101 | 115 | if ( ($nlearn >= $cf['thresholdip']["$category"])&&($nuid >= $cf['thresholduid']["$category"]) ) { |
| 102 | 116 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; |
| 103 | 117 | $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$cf['quantity']["$category"],$reason); |
| 118 | + } else { |
|
| 119 | + $listed = FALSE; |
|
| 104 | 120 | } |
| 105 | - else $listed = FALSE; |
|
| 121 | + } else { |
|
| 122 | + $listed = FALSE; |
|
| 106 | 123 | } |
| 107 | - else $listed = FALSE; |
|
| 108 | 124 | $nowlist = array( TRUE => array( |
| 109 | 125 | 'style' => 'id=\'ipfound\'', |
| 110 | 126 | 'name' => 'YES', |
@@ -122,7 +138,9 @@ discard block |
||
| 122 | 138 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
| 123 | 139 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$ipvet['ip']["$ip"][0],$nlearn,$nowlist["$listed"]['name']); |
| 124 | 140 | $rowuid=NULL; |
| 125 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 141 | + for ($j=1;$j<$nuid;$j++) { |
|
| 142 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 143 | + } |
|
| 126 | 144 | array_shift($ipvet['ip']["$ip"]); |
| 127 | 145 | $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
| 128 | 146 | |
@@ -135,14 +153,18 @@ discard block |
||
| 135 | 153 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
| 136 | 154 | $uids = array_keys($ipvet['uid']); |
| 137 | 155 | foreach ( $uids as $uid ) { |
| 138 | - if ( $uid == 'count' ) continue; |
|
| 156 | + if ( $uid == 'count' ) { |
|
| 157 | + continue; |
|
| 158 | + } |
|
| 139 | 159 | $nlearn = $ipvet['uid']["$uid"]['count']; |
| 140 | 160 | unset ( $ipvet['uid']["$uid"]['count'] ); |
| 141 | 161 | $nip = count($ipvet['uid']["$uid"]); |
| 142 | 162 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 143 | 163 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
| 144 | 164 | $rowuid=NULL; |
| 145 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 165 | + for ($j=1;$j<$nip;$j++) { |
|
| 166 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 167 | + } |
|
| 146 | 168 | array_shift($ipvet['uid']["$uid"]); |
| 147 | 169 | $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
| 148 | 170 | |
@@ -170,7 +192,9 @@ discard block |
||
| 170 | 192 | )); |
| 171 | 193 | |
| 172 | 194 | |
| 173 | - if ($job['resultCount'] == 0) return FALSE; |
|
| 195 | + if ($job['resultCount'] == 0) { |
|
| 196 | + return FALSE; |
|
| 197 | + } |
|
| 174 | 198 | |
| 175 | 199 | // Get job results |
| 176 | 200 | $resultSearch = $job->getResults(); |
@@ -183,14 +207,14 @@ discard block |
||
| 183 | 207 | { |
| 184 | 208 | // More than one field attribute returned by search |
| 185 | 209 | // You must redefine the search |
| 186 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 187 | - } |
|
| 188 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 210 | + if ( count($result->getFieldNames()) > 1 ) { |
|
| 211 | + return FALSE; |
|
| 212 | + } |
|
| 213 | + } else if ($result instanceof Splunk_ResultsMessage) |
|
| 189 | 214 | { |
| 190 | 215 | // I don't want messages in my search |
| 191 | 216 | return FALSE; |
| 192 | - } |
|
| 193 | - else if (is_array($result)) |
|
| 217 | + } else if (is_array($result)) |
|
| 194 | 218 | { |
| 195 | 219 | // Process a row |
| 196 | 220 | foreach ($result as $key => $valueOrValues) |
@@ -198,15 +222,13 @@ discard block |
||
| 198 | 222 | if (is_array($valueOrValues)) |
| 199 | 223 | { |
| 200 | 224 | return FALSE; |
| 201 | - } |
|
| 202 | - else |
|
| 225 | + } else |
|
| 203 | 226 | { |
| 204 | 227 | return $valueOrValues; |
| 205 | 228 | #print " {$key} => {$value}\r\n"; |
| 206 | 229 | } |
| 207 | 230 | } |
| 208 | - } |
|
| 209 | - else |
|
| 231 | + } else |
|
| 210 | 232 | { |
| 211 | 233 | #print "Unknow result type"; |
| 212 | 234 | return FALSE; |
@@ -220,7 +242,9 @@ discard block |
||
| 220 | 242 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
| 221 | 243 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
| 222 | 244 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
| 223 | - if ( !$m_mail ) exit(254); |
|
| 245 | + if ( !$m_mail ) { |
|
| 246 | + exit(254); |
|
| 247 | + } |
|
| 224 | 248 | |
| 225 | 249 | |
| 226 | 250 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
@@ -233,20 +257,28 @@ discard block |
||
| 233 | 257 | // Order results starting from newest message |
| 234 | 258 | if ( empty($m_search) ) { |
| 235 | 259 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
| 236 | - if ( $ierr = imap_errors() ) |
|
| 237 | - foreach ( $ierr as $thiserr ) |
|
| 260 | + if ( $ierr = imap_errors() ) { |
|
| 261 | + foreach ( $ierr as $thiserr ) |
|
| 238 | 262 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 239 | - if ( $ierr = imap_alerts() ) |
|
| 240 | - foreach ( $ierr as $thiserr ) |
|
| 263 | + } |
|
| 264 | + if ( $ierr = imap_alerts() ) { |
|
| 265 | + foreach ( $ierr as $thiserr ) |
|
| 241 | 266 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 267 | + } |
|
| 242 | 268 | imap_close( $m_mail ); |
| 243 | - if ( file_exists( $file ) ) unlink ($file); |
|
| 244 | - if ( file_exists( $fileb ) ) unlink ($fileb); |
|
| 269 | + if ( file_exists( $file ) ) { |
|
| 270 | + unlink ($file); |
|
| 271 | + } |
|
| 272 | + if ( file_exists( $fileb ) ) { |
|
| 273 | + unlink ($fileb); |
|
| 274 | + } |
|
| 245 | 275 | return FALSE; |
| 246 | 276 | } |
| 247 | 277 | $nmes = count ($m_search); |
| 248 | 278 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); |
| 249 | - if ($nmes>0) rsort($m_search); |
|
| 279 | + if ($nmes>0) { |
|
| 280 | + rsort($m_search); |
|
| 281 | + } |
|
| 250 | 282 | |
| 251 | 283 | // Create report file |
| 252 | 284 | |
@@ -255,7 +287,9 @@ discard block |
||
| 255 | 287 | $lastup = "Last Update: " . date ("d F Y H:i", time()); |
| 256 | 288 | fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
| 257 | 289 | fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
| 258 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 290 | + if ($cf['onlyReport']) { |
|
| 291 | + fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 292 | + } |
|
| 259 | 293 | fwrite( $fp,'<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>' ); |
| 260 | 294 | fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
| 261 | 295 | fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
@@ -301,10 +335,11 @@ discard block |
||
| 301 | 335 | |
| 302 | 336 | if (in_array($uid,array_keys($ipuid['uid']))) { |
| 303 | 337 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 304 | - if (!in_array($ip,$ipuid['uid']["$uid"])) |
|
| 305 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
|
| 306 | - } |
|
| 307 | - else { |
|
| 338 | + if (!in_array($ip,$ipuid['uid']["$uid"])) { |
|
| 339 | + $ipuid['uid']["$uid"][]=$ip; |
|
| 340 | + } |
|
| 341 | + //ips learned by this uid |
|
| 342 | + } else { |
|
| 308 | 343 | $ipuid['uid']["$uid"]['count'] = 1; |
| 309 | 344 | $ipuid['uid']["$uid"][]=$ip; |
| 310 | 345 | $ipuid['uid']['count']++; //number of unique uids |
@@ -312,10 +347,11 @@ discard block |
||
| 312 | 347 | |
| 313 | 348 | if (in_array($ip,array_keys($ipuid['ip']))) { |
| 314 | 349 | $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
| 315 | - if (!in_array($uid,$ipuid['ip']["$ip"])) |
|
| 316 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
|
| 317 | - } |
|
| 318 | - else { |
|
| 350 | + if (!in_array($uid,$ipuid['ip']["$ip"])) { |
|
| 351 | + $ipuid['ip']["$ip"][]=$uid; |
|
| 352 | + } |
|
| 353 | + //uids that learned this ip |
|
| 354 | + } else { |
|
| 319 | 355 | $ipuid['ip']["$ip"]['count'] = 1; |
| 320 | 356 | $ipuid['ip']["$ip"][]=$uid; |
| 321 | 357 | $ipuid['ip']['count']++; //number of unique ips |
@@ -323,21 +359,30 @@ discard block |
||
| 323 | 359 | |
| 324 | 360 | /* Update HTML report */ |
| 325 | 361 | fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
| 326 | - } |
|
| 327 | - else { /* Bad learn */ |
|
| 362 | + } else { /* Bad learn */ |
|
| 328 | 363 | |
| 329 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 330 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 364 | + if (in_array($uid,array_keys($uidbad['uid']))) { |
|
| 365 | + $uidbad['uid']["$uid"]['count']++; |
|
| 366 | + } |
|
| 367 | + //number of bad learn by this uid |
|
| 331 | 368 | else { |
| 332 | 369 | $uidbad['uid']["$uid"]['count'] = 1; |
| 333 | 370 | $uidbad['uid']["$uid"][]=$uid; |
| 334 | 371 | $uidbad['count']++; //numeber of unique bad uids |
| 335 | 372 | } |
| 336 | 373 | /* The reason of bad report */ |
| 337 | - if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
|
| 338 | - if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 339 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
| 340 | - if (!isset($reason)) $reason = '?'; |
|
| 374 | + if ($host === FALSE) { |
|
| 375 | + $reason = 'This mail was not received by recognized MX host'; |
|
| 376 | + } |
|
| 377 | + if ($dateReceived === FALSE) { |
|
| 378 | + $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 379 | + } |
|
| 380 | + if ($uid=='unknown') { |
|
| 381 | + $reason = 'The uid of this mail was not found in splunk log'; |
|
| 382 | + } |
|
| 383 | + if (!isset($reason)) { |
|
| 384 | + $reason = '?'; |
|
| 385 | + } |
|
| 341 | 386 | |
| 342 | 387 | fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); |
| 343 | 388 | } |
@@ -355,9 +400,9 @@ discard block |
||
| 355 | 400 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>' ); |
| 356 | 401 | |
| 357 | 402 | /* Make MYSQL connection */ |
| 358 | - if ( $cf['onlyReport'] ) |
|
| 359 | - $mysqli = NULL; |
|
| 360 | - else { |
|
| 403 | + if ( $cf['onlyReport'] ) { |
|
| 404 | + $mysqli = NULL; |
|
| 405 | + } else { |
|
| 361 | 406 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
| 362 | 407 | if ($mysqli->connect_error) { |
| 363 | 408 | syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
@@ -369,8 +414,9 @@ discard block |
||
| 369 | 414 | /***********************/ |
| 370 | 415 | |
| 371 | 416 | fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); |
| 372 | - if ( !$cf['onlyReport'] ) |
|
| 373 | - $mysqli->close(); |
|
| 417 | + if ( !$cf['onlyReport'] ) { |
|
| 418 | + $mysqli->close(); |
|
| 419 | + } |
|
| 374 | 420 | fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); |
| 375 | 421 | fclose($fp); |
| 376 | 422 | |
@@ -380,12 +426,14 @@ discard block |
||
| 380 | 426 | fclose($fpb); |
| 381 | 427 | syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); |
| 382 | 428 | |
| 383 | - if ( $ierr = imap_errors() ) |
|
| 384 | - foreach ( $ierr as $thiserr ) |
|
| 429 | + if ( $ierr = imap_errors() ) { |
|
| 430 | + foreach ( $ierr as $thiserr ) |
|
| 385 | 431 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 386 | - if ( $ierr = imap_alerts() ) |
|
| 387 | - foreach ( $ierr as $thiserr ) |
|
| 432 | + } |
|
| 433 | + if ( $ierr = imap_alerts() ) { |
|
| 434 | + foreach ( $ierr as $thiserr ) |
|
| 388 | 435 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 436 | + } |
|
| 389 | 437 | imap_close($m_mail); |
| 390 | 438 | } |
| 391 | 439 | ?> |
@@ -3,9 +3,13 @@ discard block |
||
| 3 | 3 | $version='1.9d'; |
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | - if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
|
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 6 | + if (isset ($_SERVER['REMOTE_USER'])) { |
|
| 7 | + $user = $_SERVER['REMOTE_USER']; |
|
| 8 | + } else if (isset ($_SERVER['USER'])) { |
|
| 9 | + $user = $_SERVER['USER']; |
|
| 10 | + } else { |
|
| 11 | + $user='unknown'; |
|
| 12 | + } |
|
| 9 | 13 | return $user; |
| 10 | 14 | } |
| 11 | 15 | |
@@ -68,8 +72,9 @@ discard block |
||
| 68 | 72 | if ($myconn->query($query) === TRUE) { |
| 69 | 73 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 70 | 74 | $result=TRUE; |
| 75 | + } else { |
|
| 76 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 71 | 77 | } |
| 72 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 73 | 78 | return $result; |
| 74 | 79 | } |
| 75 | 80 | |
@@ -110,8 +115,9 @@ discard block |
||
| 110 | 115 | if ($myconn->query($query) === TRUE) { |
| 111 | 116 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
| 112 | 117 | $result=TRUE; |
| 118 | + } else { |
|
| 119 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 113 | 120 | } |
| 114 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 115 | 121 | return $result; |
| 116 | 122 | } |
| 117 | 123 | |
@@ -134,9 +140,11 @@ discard block |
||
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | |
| 137 | - if ($return=$myconn->query($query) === TRUE) |
|
| 138 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 139 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 143 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 144 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 145 | + } else { |
|
| 146 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 147 | + } |
|
| 140 | 148 | |
| 141 | 149 | return $return; |
| 142 | 150 | } |
@@ -158,8 +166,9 @@ discard block |
||
| 158 | 166 | |
| 159 | 167 | if ($return=$myconn->query($query) === TRUE) { |
| 160 | 168 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 169 | + } else { |
|
| 170 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 161 | 171 | } |
| 162 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 163 | 172 | return $return; |
| 164 | 173 | } |
| 165 | 174 | |
@@ -183,14 +192,16 @@ discard block |
||
| 183 | 192 | $j++; |
| 184 | 193 | |
| 185 | 194 | } while ($myconn->next_result()); |
| 186 | - } |
|
| 187 | - else { |
|
| 195 | + } else { |
|
| 188 | 196 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
| 189 | 197 | $return = FALSE; |
| 190 | 198 | } |
| 191 | 199 | } |
| 192 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 193 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 200 | + if ( !($return) ) { |
|
| 201 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 202 | + } else { |
|
| 203 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 204 | + } |
|
| 194 | 205 | return $return; |
| 195 | 206 | } |
| 196 | 207 | |
@@ -199,8 +210,11 @@ discard block |
||
| 199 | 210 | |
| 200 | 211 | $exp=new DateTime($row['exp']); |
| 201 | 212 | $now=new DateTime('NOW'); |
| 202 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 203 | - else return false; |
|
| 213 | + if (($exp > $now) and ($row['active'])) { |
|
| 214 | + return true; |
|
| 215 | + } else { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 204 | 218 | |
| 205 | 219 | } |
| 206 | 220 | |
@@ -210,9 +224,12 @@ discard block |
||
| 210 | 224 | $whynot=NULL; |
| 211 | 225 | switch ($what) { |
| 212 | 226 | case 'Ok': |
| 213 | - if ($lock) return NULL; |
|
| 214 | - if (in_array($user,array_keys($adm))) |
|
| 215 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 227 | + if ($lock) { |
|
| 228 | + return NULL; |
|
| 229 | + } |
|
| 230 | + if (in_array($user,array_keys($adm))) { |
|
| 231 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 232 | + } |
|
| 216 | 233 | return htmlspecialchars($whynot); |
| 217 | 234 | case 'Listed': |
| 218 | 235 | case 'WhiteListed': |
@@ -253,8 +270,9 @@ discard block |
||
| 253 | 270 | $type = $tablelist['field']; |
| 254 | 271 | $table = $tablelist['name']; |
| 255 | 272 | |
| 256 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 257 | - else { |
|
| 273 | + if ($value == 'ALL') { |
|
| 274 | + $query = 'select * from '.$table; |
|
| 275 | + } else { |
|
| 258 | 276 | switch ($type) { |
| 259 | 277 | case 'ip': |
| 260 | 278 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -269,8 +287,9 @@ discard block |
||
| 269 | 287 | } |
| 270 | 288 | |
| 271 | 289 | $result = $myconn->query($query); |
| 272 | - if($result === false) |
|
| 273 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 290 | + if($result === false) { |
|
| 291 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 292 | + } |
|
| 274 | 293 | return $result; |
| 275 | 294 | } |
| 276 | 295 | |
@@ -287,8 +306,9 @@ discard block |
||
| 287 | 306 | |
| 288 | 307 | function isFull($myconn,$typedesc,$alltables) { |
| 289 | 308 | if (isset($alltables["$typedesc"]['limit'])) { |
| 290 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) |
|
| 291 | - return TRUE; |
|
| 309 | + if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) { |
|
| 310 | + return TRUE; |
|
| 311 | + } |
|
| 292 | 312 | } |
| 293 | 313 | return FALSE; |
| 294 | 314 | } |
@@ -304,18 +324,23 @@ discard block |
||
| 304 | 324 | |
| 305 | 325 | /* Check for limit in number of listed items */ |
| 306 | 326 | $full = isFull($myconn,$typedesc,$tables); |
| 307 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 327 | + if ($full) { |
|
| 328 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 329 | + } |
|
| 308 | 330 | |
| 309 | 331 | if ($result->num_rows) { |
| 310 | 332 | print '<table><thead><tr><th>'.$type.'</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th><th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 311 | 333 | $i=0; |
| 312 | 334 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 313 | 335 | if (isListed($riga)) { |
| 314 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 315 | - else $listed='WhiteListed'; |
|
| 316 | - } |
|
| 317 | - else |
|
| 318 | - $listed='Ok'; |
|
| 336 | + if ($tables["$typedesc"]['bl']) { |
|
| 337 | + $listed='Listed'; |
|
| 338 | + } else { |
|
| 339 | + $listed='WhiteListed'; |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $listed='Ok'; |
|
| 343 | + } |
|
| 319 | 344 | |
| 320 | 345 | switch ($type) { |
| 321 | 346 | case 'ip': |
@@ -332,18 +357,20 @@ discard block |
||
| 332 | 357 | $i++; |
| 333 | 358 | } |
| 334 | 359 | print '</tbody></table>'; |
| 335 | - } |
|
| 336 | - else { |
|
| 360 | + } else { |
|
| 337 | 361 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 338 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 339 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 340 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 362 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
| 363 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 364 | + } else { |
|
| 365 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 366 | + } |
|
| 341 | 367 | |
| 342 | 368 | } |
| 343 | 369 | $result->free(); |
| 370 | + } else { |
|
| 371 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 372 | + } |
|
| 344 | 373 | } |
| 345 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 346 | -} |
|
| 347 | 374 | |
| 348 | 375 | |
| 349 | 376 | function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
@@ -384,24 +411,32 @@ discard block |
||
| 384 | 411 | $old_mailfrom = ini_get("sendmail_from"); |
| 385 | 412 | ini_set("sendmail_from", $from); |
| 386 | 413 | $params = sprintf("-oi -f %s", '<>'); |
| 387 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 388 | - else $flag=TRUE; |
|
| 389 | - if (isset($old_mailfrom)) |
|
| 390 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 391 | - } |
|
| 392 | - else { |
|
| 393 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 394 | - else $flag=TRUE; |
|
| 414 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
| 415 | + $flag=FALSE; |
|
| 416 | + } else { |
|
| 417 | + $flag=TRUE; |
|
| 418 | + } |
|
| 419 | + if (isset($old_mailfrom)) { |
|
| 420 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 421 | + } |
|
| 422 | + } else { |
|
| 423 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
| 424 | + $flag=FALSE; |
|
| 425 | + } else { |
|
| 426 | + $flag=TRUE; |
|
| 427 | + } |
|
| 395 | 428 | } |
| 396 | 429 | return $flag; |
| 397 | 430 | } |
| 398 | 431 | |
| 399 | 432 | function emailToNotify($notify_file,$dom) { |
| 400 | 433 | $ini_array = parse_ini_file($notify_file); |
| 401 | - if (in_array($dom,array_keys($ini_array))) |
|
| 402 | - return $ini_array["$dom"]; |
|
| 403 | - else return FALSE; |
|
| 404 | -} |
|
| 434 | + if (in_array($dom,array_keys($ini_array))) { |
|
| 435 | + return $ini_array["$dom"]; |
|
| 436 | + } else { |
|
| 437 | + return FALSE; |
|
| 438 | + } |
|
| 439 | + } |
|
| 405 | 440 | |
| 406 | 441 | |
| 407 | 442 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
@@ -16,10 +16,11 @@ |
||
| 16 | 16 | } |
| 17 | 17 | syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); |
| 18 | 18 | |
| 19 | -if (remove ($mysqli,$user,$_POST['value'],$type,$table)) |
|
| 19 | +if (remove ($mysqli,$user,$_POST['value'],$type,$table)) { |
|
| 20 | 20 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; |
| 21 | -else |
|
| 21 | +} else { |
|
| 22 | 22 | print 'Delete operation ERROR on '.$typedesc.' <'.$_POST['value'].'>; check log.'; |
| 23 | +} |
|
| 23 | 24 | $mysqli->close(); |
| 24 | 25 | closelog(); |
| 25 | 26 | ?> |