@@ -1,8 +1,9 @@ |
||
| 1 | 1 | #!/usr/bin/php |
| 2 | 2 | <?php |
| 3 | 3 | |
| 4 | -if (PHP_SAPI != "cli") |
|
| 4 | +if (PHP_SAPI != "cli") { |
|
| 5 | 5 | exit; |
| 6 | +} |
|
| 6 | 7 | |
| 7 | 8 | $home = '/var/www/html/RBL'; |
| 8 | 9 | require_once($home.'/config.php'); |
@@ -51,9 +51,7 @@ |
||
| 51 | 51 | 'db' => $db, |
| 52 | 52 | 'dbport' => $dbport |
| 53 | 53 | ); |
| 54 | -} |
|
| 55 | - |
|
| 56 | -else { |
|
| 54 | +} else { |
|
| 57 | 55 | $mysqlconf = NULL; |
| 58 | 56 | syslog(LOG_INFO, $conf['user'].': Report only, no listing activated in configuration.') ; |
| 59 | 57 | } |
@@ -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 | $quantity = $cf['quantity']["$category"]; /* In searchAndList this value is passed by reference and modified */ |
@@ -102,10 +116,12 @@ discard block |
||
| 102 | 116 | if ( ($nlearn >= $cf['thresholdip']["$category"])&&($nuid >= $cf['thresholduid']["$category"]) ) { |
| 103 | 117 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; |
| 104 | 118 | $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$quantity,$reason); |
| 119 | + } else { |
|
| 120 | + $listed = FALSE; |
|
| 105 | 121 | } |
| 106 | - else $listed = FALSE; |
|
| 122 | + } else { |
|
| 123 | + $listed = FALSE; |
|
| 107 | 124 | } |
| 108 | - else $listed = FALSE; |
|
| 109 | 125 | $nowlist = array( TRUE => array( |
| 110 | 126 | 'style' => 'id=\'ipfound\'', |
| 111 | 127 | 'name' => 'YES', |
@@ -123,7 +139,9 @@ discard block |
||
| 123 | 139 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
| 124 | 140 | $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']); |
| 125 | 141 | $rowuid=NULL; |
| 126 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 142 | + for ($j=1;$j<$nuid;$j++) { |
|
| 143 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 144 | + } |
|
| 127 | 145 | array_shift($ipvet['ip']["$ip"]); |
| 128 | 146 | $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
| 129 | 147 | |
@@ -136,14 +154,18 @@ discard block |
||
| 136 | 154 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
| 137 | 155 | $uids = array_keys($ipvet['uid']); |
| 138 | 156 | foreach ( $uids as $uid ) { |
| 139 | - if ( $uid == 'count' ) continue; |
|
| 157 | + if ( $uid == 'count' ) { |
|
| 158 | + continue; |
|
| 159 | + } |
|
| 140 | 160 | $nlearn = $ipvet['uid']["$uid"]['count']; |
| 141 | 161 | unset ( $ipvet['uid']["$uid"]['count'] ); |
| 142 | 162 | $nip = count($ipvet['uid']["$uid"]); |
| 143 | 163 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 144 | 164 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
| 145 | 165 | $rowuid=NULL; |
| 146 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 166 | + for ($j=1;$j<$nip;$j++) { |
|
| 167 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 168 | + } |
|
| 147 | 169 | array_shift($ipvet['uid']["$uid"]); |
| 148 | 170 | $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
| 149 | 171 | |
@@ -192,14 +214,14 @@ discard block |
||
| 192 | 214 | { |
| 193 | 215 | // More than one field attribute returned by search |
| 194 | 216 | // You must redefine the search |
| 195 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 196 | - } |
|
| 197 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 217 | + if ( count($result->getFieldNames()) > 1 ) { |
|
| 218 | + return FALSE; |
|
| 219 | + } |
|
| 220 | + } else if ($result instanceof Splunk_ResultsMessage) |
|
| 198 | 221 | { |
| 199 | 222 | // I don't want messages in my search |
| 200 | 223 | return FALSE; |
| 201 | - } |
|
| 202 | - else if (is_array($result)) |
|
| 224 | + } else if (is_array($result)) |
|
| 203 | 225 | { |
| 204 | 226 | // Process a row |
| 205 | 227 | foreach ($result as $key => $valueOrValues) |
@@ -207,15 +229,13 @@ discard block |
||
| 207 | 229 | if (is_array($valueOrValues)) |
| 208 | 230 | { |
| 209 | 231 | return FALSE; |
| 210 | - } |
|
| 211 | - else |
|
| 232 | + } else |
|
| 212 | 233 | { |
| 213 | 234 | return $valueOrValues; |
| 214 | 235 | #print " {$key} => {$value}\r\n"; |
| 215 | 236 | } |
| 216 | 237 | } |
| 217 | - } |
|
| 218 | - else |
|
| 238 | + } else |
|
| 219 | 239 | { |
| 220 | 240 | #print "Unknow result type"; |
| 221 | 241 | return FALSE; |
@@ -229,7 +249,9 @@ discard block |
||
| 229 | 249 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
| 230 | 250 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
| 231 | 251 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
| 232 | - if ( !$m_mail ) exit(254); |
|
| 252 | + if ( !$m_mail ) { |
|
| 253 | + exit(254); |
|
| 254 | + } |
|
| 233 | 255 | |
| 234 | 256 | |
| 235 | 257 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
@@ -242,20 +264,28 @@ discard block |
||
| 242 | 264 | // Order results starting from newest message |
| 243 | 265 | if ( empty($m_search) ) { |
| 244 | 266 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
| 245 | - if ( $ierr = imap_errors() ) |
|
| 246 | - foreach ( $ierr as $thiserr ) |
|
| 267 | + if ( $ierr = imap_errors() ) { |
|
| 268 | + foreach ( $ierr as $thiserr ) |
|
| 247 | 269 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 248 | - if ( $ierr = imap_alerts() ) |
|
| 249 | - foreach ( $ierr as $thiserr ) |
|
| 270 | + } |
|
| 271 | + if ( $ierr = imap_alerts() ) { |
|
| 272 | + foreach ( $ierr as $thiserr ) |
|
| 250 | 273 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 274 | + } |
|
| 251 | 275 | imap_close( $m_mail ); |
| 252 | - if ( file_exists( $file ) ) unlink ($file); |
|
| 253 | - if ( file_exists( $fileb ) ) unlink ($fileb); |
|
| 276 | + if ( file_exists( $file ) ) { |
|
| 277 | + unlink ($file); |
|
| 278 | + } |
|
| 279 | + if ( file_exists( $fileb ) ) { |
|
| 280 | + unlink ($fileb); |
|
| 281 | + } |
|
| 254 | 282 | return FALSE; |
| 255 | 283 | } |
| 256 | 284 | $nmes = count ($m_search); |
| 257 | 285 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); |
| 258 | - if ($nmes>0) rsort($m_search); |
|
| 286 | + if ($nmes>0) { |
|
| 287 | + rsort($m_search); |
|
| 288 | + } |
|
| 259 | 289 | |
| 260 | 290 | // Create report file |
| 261 | 291 | |
@@ -264,7 +294,9 @@ discard block |
||
| 264 | 294 | $lastup = "Last Update: " . date ("d F Y H:i", time()); |
| 265 | 295 | fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
| 266 | 296 | fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
| 267 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 297 | + if ($cf['onlyReport']) { |
|
| 298 | + fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 299 | + } |
|
| 268 | 300 | 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>' ); |
| 269 | 301 | fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
| 270 | 302 | fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
@@ -310,10 +342,11 @@ discard block |
||
| 310 | 342 | |
| 311 | 343 | if (in_array($uid,array_keys($ipuid['uid']))) { |
| 312 | 344 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 313 | - if (!in_array($ip,$ipuid['uid']["$uid"])) |
|
| 314 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
|
| 315 | - } |
|
| 316 | - else { |
|
| 345 | + if (!in_array($ip,$ipuid['uid']["$uid"])) { |
|
| 346 | + $ipuid['uid']["$uid"][]=$ip; |
|
| 347 | + } |
|
| 348 | + //ips learned by this uid |
|
| 349 | + } else { |
|
| 317 | 350 | $ipuid['uid']["$uid"]['count'] = 1; |
| 318 | 351 | $ipuid['uid']["$uid"][]=$ip; |
| 319 | 352 | $ipuid['uid']['count']++; //number of unique uids |
@@ -321,10 +354,11 @@ discard block |
||
| 321 | 354 | |
| 322 | 355 | if (in_array($ip,array_keys($ipuid['ip']))) { |
| 323 | 356 | $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
| 324 | - if (!in_array($uid,$ipuid['ip']["$ip"])) |
|
| 325 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
|
| 326 | - } |
|
| 327 | - else { |
|
| 357 | + if (!in_array($uid,$ipuid['ip']["$ip"])) { |
|
| 358 | + $ipuid['ip']["$ip"][]=$uid; |
|
| 359 | + } |
|
| 360 | + //uids that learned this ip |
|
| 361 | + } else { |
|
| 328 | 362 | $ipuid['ip']["$ip"]['count'] = 1; |
| 329 | 363 | $ipuid['ip']["$ip"][]=$uid; |
| 330 | 364 | $ipuid['ip']['count']++; //number of unique ips |
@@ -332,21 +366,30 @@ discard block |
||
| 332 | 366 | |
| 333 | 367 | /* Update HTML report */ |
| 334 | 368 | fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
| 335 | - } |
|
| 336 | - else { /* Bad learn */ |
|
| 369 | + } else { /* Bad learn */ |
|
| 337 | 370 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 371 | + if (in_array($uid,array_keys($uidbad['uid']))) { |
|
| 372 | + $uidbad['uid']["$uid"]['count']++; |
|
| 373 | + } |
|
| 374 | + //number of bad learn by this uid |
|
| 340 | 375 | else { |
| 341 | 376 | $uidbad['uid']["$uid"]['count'] = 1; |
| 342 | 377 | $uidbad['uid']["$uid"][]=$uid; |
| 343 | 378 | $uidbad['count']++; //numeber of unique bad uids |
| 344 | 379 | } |
| 345 | 380 | /* The reason of bad report */ |
| 346 | - if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
|
| 347 | - if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 348 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
| 349 | - if (!isset($reason)) $reason = '?'; |
|
| 381 | + if ($host === FALSE) { |
|
| 382 | + $reason = 'This mail was not received by recognized MX host'; |
|
| 383 | + } |
|
| 384 | + if ($dateReceived === FALSE) { |
|
| 385 | + $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 386 | + } |
|
| 387 | + if ($uid=='unknown') { |
|
| 388 | + $reason = 'The uid of this mail was not found in splunk log'; |
|
| 389 | + } |
|
| 390 | + if (!isset($reason)) { |
|
| 391 | + $reason = '?'; |
|
| 392 | + } |
|
| 350 | 393 | |
| 351 | 394 | fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); |
| 352 | 395 | } |
@@ -364,9 +407,9 @@ discard block |
||
| 364 | 407 | 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>' ); |
| 365 | 408 | |
| 366 | 409 | /* Make MYSQL connection */ |
| 367 | - if ( $cf['onlyReport'] ) |
|
| 368 | - $mysqli = NULL; |
|
| 369 | - else { |
|
| 410 | + if ( $cf['onlyReport'] ) { |
|
| 411 | + $mysqli = NULL; |
|
| 412 | + } else { |
|
| 370 | 413 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
| 371 | 414 | if ($mysqli->connect_error) { |
| 372 | 415 | syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
@@ -378,8 +421,9 @@ discard block |
||
| 378 | 421 | /***********************/ |
| 379 | 422 | |
| 380 | 423 | fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); |
| 381 | - if ( !$cf['onlyReport'] ) |
|
| 382 | - $mysqli->close(); |
|
| 424 | + if ( !$cf['onlyReport'] ) { |
|
| 425 | + $mysqli->close(); |
|
| 426 | + } |
|
| 383 | 427 | fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); |
| 384 | 428 | fclose($fp); |
| 385 | 429 | |
@@ -389,12 +433,14 @@ discard block |
||
| 389 | 433 | fclose($fpb); |
| 390 | 434 | syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); |
| 391 | 435 | |
| 392 | - if ( $ierr = imap_errors() ) |
|
| 393 | - foreach ( $ierr as $thiserr ) |
|
| 436 | + if ( $ierr = imap_errors() ) { |
|
| 437 | + foreach ( $ierr as $thiserr ) |
|
| 394 | 438 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 395 | - if ( $ierr = imap_alerts() ) |
|
| 396 | - foreach ( $ierr as $thiserr ) |
|
| 439 | + } |
|
| 440 | + if ( $ierr = imap_alerts() ) { |
|
| 441 | + foreach ( $ierr as $thiserr ) |
|
| 397 | 442 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 443 | + } |
|
| 398 | 444 | imap_close($m_mail); |
| 399 | 445 | } |
| 400 | 446 | ?> |
@@ -4,8 +4,9 @@ discard block |
||
| 4 | 4 | $typedesc=$_POST['type']; |
| 5 | 5 | $type = $tables["$typedesc"]['field']; |
| 6 | 6 | $col = milterTable($type); |
| 7 | -if ( $col === FALSE ) |
|
| 7 | +if ( $col === FALSE ) { |
|
| 8 | 8 | exit ("<p>Error in you config at field <b>$type</b>.</p>"); |
| 9 | +} |
|
| 9 | 10 | ?> |
| 10 | 11 | <td colspan="10" style="text-align: center"> |
| 11 | 12 | |
@@ -14,31 +15,35 @@ discard block |
||
| 14 | 15 | $user = $_POST['user']; |
| 15 | 16 | |
| 16 | 17 | /* Compare old values with new ones */ |
| 17 | -if (isset($_POST['newvalues'])) |
|
| 18 | +if (isset($_POST['newvalues'])) { |
|
| 18 | 19 | $new = $_POST['newvalues']; |
| 19 | -else |
|
| 20 | +} else { |
|
| 20 | 21 | $new = array(); |
| 21 | -if (! empty($_POST['oldvalues'])) |
|
| 22 | +} |
|
| 23 | +if (! empty($_POST['oldvalues'])) { |
|
| 22 | 24 | $old = explode(',', $_POST['oldvalues']); |
| 23 | -else |
|
| 25 | +} else { |
|
| 24 | 26 | $old=array(); |
| 27 | +} |
|
| 25 | 28 | $values=array(); |
| 26 | 29 | $logs=array(); |
| 27 | 30 | |
| 28 | 31 | print '<pre>'; |
| 29 | 32 | /* Check need to disable all milters, removing unnecessary setting */ |
| 30 | -if ( in_array('DISABLE ALL', $new) ) |
|
| 33 | +if ( in_array('DISABLE ALL', $new) ) { |
|
| 31 | 34 | $new = array('DISABLE ALL'); |
| 35 | +} |
|
| 32 | 36 | |
| 33 | 37 | /* Compare the values determining what to do */ |
| 34 | 38 | if (count(array_diff(array_merge($new, $old), array_intersect($new, $old))) !== 0) { |
| 35 | 39 | /* New and old are different (we assume we don't have duplicate values) */ |
| 36 | 40 | if (! empty($new) ) { |
| 37 | 41 | foreach ($new as $item) { |
| 38 | - if ( in_array($item, $old) ) |
|
| 39 | - $values["$item"] = 'keep'; |
|
| 40 | - else |
|
| 41 | - $values["$item"] = 'add'; |
|
| 42 | + if ( in_array($item, $old) ) { |
|
| 43 | + $values["$item"] = 'keep'; |
|
| 44 | + } else { |
|
| 45 | + $values["$item"] = 'add'; |
|
| 46 | + } |
|
| 42 | 47 | $logs[] = "<$item>: ". $values["$item"]; |
| 43 | 48 | } |
| 44 | 49 | } |
@@ -53,22 +58,25 @@ discard block |
||
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | /* Logging */ |
| 56 | -if ( empty($values) ) |
|
| 61 | +if ( empty($values) ) { |
|
| 57 | 62 | print 'No values to change.'; |
| 58 | -else { |
|
| 63 | +} else { |
|
| 59 | 64 | $msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.',$user,$typedesc,$type, $_POST['object']); |
| 60 | 65 | syslog(LOG_INFO, $msg); |
| 61 | - foreach ($logs as $log) |
|
| 62 | - syslog(LOG_INFO, "$user: milter $log"); |
|
| 66 | + foreach ($logs as $log) { |
|
| 67 | + syslog(LOG_INFO, "$user: milter $log"); |
|
| 68 | + } |
|
| 63 | 69 | |
| 64 | 70 | /* Store new values */ |
| 65 | - if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 66 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 71 | + if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 72 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 73 | + } |
|
| 67 | 74 | |
| 68 | - if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) |
|
| 69 | - print 'OK milter setting changed.'; |
|
| 70 | - else |
|
| 71 | - print 'ERROR updating milter setting; check your syslog. No changes made.'; |
|
| 75 | + if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) { |
|
| 76 | + print 'OK milter setting changed.'; |
|
| 77 | + } else { |
|
| 78 | + print 'ERROR updating milter setting; check your syslog. No changes made.'; |
|
| 79 | + } |
|
| 72 | 80 | |
| 73 | 81 | $mysqli->close(); |
| 74 | 82 | } |
@@ -1,11 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | -if (in_array($user,array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
| 3 | -else $extopt = NULL; |
|
| 2 | +if (in_array($user,array_keys(array_filter($adm)))) { |
|
| 3 | + $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
| 4 | +} else { |
|
| 5 | + $extopt = NULL; |
|
| 6 | +} |
|
| 4 | 7 | |
| 5 | 8 | if ( $tables["$typedesc"]['milter'] ) { |
| 6 | - if ( checkMilterConf($tables["$typedesc"]) ) |
|
| 7 | - print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
|
| 8 | - else { |
|
| 9 | + if ( checkMilterConf($tables["$typedesc"]) ) { |
|
| 10 | + print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
|
| 11 | + } else { |
|
| 9 | 12 | $err = "Error in config about <$typedesc>. Check at your config.php."; |
| 10 | 13 | syslog (LOG_EMERG, $err); |
| 11 | 14 | printf ('<p>%s</p>', htmlspecialchars($err) ); |
@@ -9,19 +9,26 @@ |
||
| 9 | 9 | <td colspan="<?php echo $cl; ?>" style="text-align: center"> |
| 10 | 10 | <?php |
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | -if (empty($_POST['reason'])) die ("Specify a reason, please!</td>"); |
|
| 13 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
| 12 | +if (empty($_POST['reason'])) { |
|
| 13 | + die ("Specify a reason, please!</td>"); |
|
| 14 | +} |
|
| 15 | +if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) { |
|
| 14 | 16 | exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
| 17 | +} |
|
| 15 | 18 | $user = username(); |
| 16 | 19 | |
| 17 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 20 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 18 | 21 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
| 22 | +} |
|
| 19 | 23 | |
| 20 | -if (isFull($mysqli,$typedesc,$tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
| 21 | -if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
|
| 24 | +if (isFull($mysqli,$typedesc,$tables)) { |
|
| 25 | + die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
| 26 | +} |
|
| 27 | +if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) { |
|
| 22 | 28 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> relisted for '.$_POST['quantity'].$_POST['unit']; |
| 23 | -else |
|
| 29 | +} else { |
|
| 24 | 30 | print 'ERROR in relist; check log'; |
| 31 | +} |
|
| 25 | 32 | $mysqli->close(); |
| 26 | 33 | closelog(); |
| 27 | 34 | print '</td>'; |
@@ -6,20 +6,27 @@ |
||
| 6 | 6 | $table = ($tables["$typedesc"]['milter']) ? milterTable($type) : $tables["$typedesc"]['name']; |
| 7 | 7 | |
| 8 | 8 | openlog($tag, LOG_PID, $fac); |
| 9 | -if (empty($_POST['reason'])) die ("<p>Please, specify a reason!</p>"); |
|
| 10 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
| 9 | +if (empty($_POST['reason'])) { |
|
| 10 | + die ("<p>Please, specify a reason!</p>"); |
|
| 11 | +} |
|
| 12 | +if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) { |
|
| 11 | 13 | exit('<p>ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); |
| 14 | +} |
|
| 12 | 15 | $user = username(); |
| 13 | 16 | $err = NULL; |
| 14 | 17 | |
| 15 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 18 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 16 | 19 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
| 20 | +} |
|
| 17 | 21 | |
| 18 | -if (addtolist ($mysqli,$user,$_POST['value'],$tables["$typedesc"],$_POST['unit'],$_POST['quantity'],$_POST['reason'],$err)) |
|
| 22 | +if (addtolist ($mysqli,$user,$_POST['value'],$tables["$typedesc"],$_POST['unit'],$_POST['quantity'],$_POST['reason'],$err)) { |
|
| 19 | 23 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> first time listed for '.$_POST['quantity'].$_POST['unit'].'.'; |
| 20 | -else |
|
| 24 | +} else { |
|
| 21 | 25 | print 'List operation ERROR; check log.'; |
| 22 | -if (!is_null($err) ) print htmlentities(' Error: ' . $err); |
|
| 26 | +} |
|
| 27 | +if (!is_null($err) ) { |
|
| 28 | + print htmlentities(' Error: ' . $err); |
|
| 29 | +} |
|
| 23 | 30 | $mysqli->close(); |
| 24 | 31 | closelog(); |
| 25 | 32 | ?> |
@@ -9,12 +9,14 @@ |
||
| 9 | 9 | openlog($tag, LOG_PID, $fac); |
| 10 | 10 | $user = username(); |
| 11 | 11 | |
| 12 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 12 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 13 | 13 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
| 14 | -if (remove ($mysqli,$user,$_POST['value'],$type,$table)) |
|
| 14 | +} |
|
| 15 | +if (remove ($mysqli,$user,$_POST['value'],$type,$table)) { |
|
| 15 | 16 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; |
| 16 | -else |
|
| 17 | +} else { |
|
| 17 | 18 | print 'Delete operation ERROR on '.$typedesc.' <'.$_POST['value'].'>; check log.'; |
| 19 | +} |
|
| 18 | 20 | print '</td>'; |
| 19 | 21 | $mysqli->close(); |
| 20 | 22 | closelog(); |
@@ -1,7 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | $adm = unserialize($_POST["adm"]); |
| 3 | -if (in_array($_POST["user"],array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
| 4 | -else $extopt = NULL; |
|
| 3 | +if (in_array($_POST["user"],array_keys(array_filter($adm)))) { |
|
| 4 | + $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
| 5 | +} else { |
|
| 6 | + $extopt = NULL; |
|
| 7 | +} |
|
| 5 | 8 | |
| 6 | 9 | require_once('config.php'); |
| 7 | 10 | $typedesc=$_POST['type']; |