@@ -144,11 +144,12 @@ discard block |
||
| 144 | 144 | $thisVal = $data[1]; |
| 145 | 145 | unset($data[1]); |
| 146 | 146 | $data = array_values($data); |
| 147 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 148 | - $tolist["$thisVal"] = $data; |
|
| 149 | - else if ($data[3]>$tolist[$thisVal][3]) |
|
| 150 | - $tolist["$thisVal"] = $data; |
|
| 151 | -} |
|
| 147 | + if ( !in_array($thisVal,array_keys($tolist)) ) { |
|
| 148 | + $tolist["$thisVal"] = $data; |
|
| 149 | + } else if ($data[3]>$tolist[$thisVal][3]) { |
|
| 150 | + $tolist["$thisVal"] = $data; |
|
| 151 | + } |
|
| 152 | + } |
|
| 152 | 153 | |
| 153 | 154 | /* Make MYSQL connection */ |
| 154 | 155 | |
@@ -177,17 +178,18 @@ discard block |
||
| 177 | 178 | $recip = emailToNotify($domainNotify_file,$domain); |
| 178 | 179 | $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
| 179 | 180 | $tables["$typedesc"]['field'], $value); |
| 180 | - if (!empty($recip)) |
|
| 181 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 181 | + if (!empty($recip)) { |
|
| 182 | + if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 182 | 183 | $subject,$value,"$quantity $unit",$reason) ) |
| 183 | 184 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 184 | 188 | } |
| 185 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 186 | 189 | } |
| 187 | 190 | } |
| 188 | 191 | } |
| 189 | - } |
|
| 190 | - else { |
|
| 192 | + } else { |
|
| 191 | 193 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
| 192 | 194 | syslog (LOG_INFO, "$user: ".$reason); |
| 193 | 195 | } |
@@ -3,9 +3,13 @@ discard block |
||
| 3 | 3 | ini_set('error_log', 'syslog'); |
| 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 | |
@@ -89,8 +93,9 @@ discard block |
||
| 89 | 93 | if ($myconn->query($query) === TRUE) { |
| 90 | 94 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 91 | 95 | $result=TRUE; |
| 96 | + } else { |
|
| 97 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 92 | 98 | } |
| 93 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 94 | 99 | return $result; |
| 95 | 100 | } |
| 96 | 101 | |
@@ -100,8 +105,7 @@ discard block |
||
| 100 | 105 | if ( $exptime ) { /* Entry already listed */ |
| 101 | 106 | $nlist = '`nlist`'; |
| 102 | 107 | $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
| 103 | - } |
|
| 104 | - else { |
|
| 108 | + } else { |
|
| 105 | 109 | $exptime = 'CURRENT_TIMESTAMP'; |
| 106 | 110 | $nlist = '`nlist` + 1'; |
| 107 | 111 | } |
@@ -139,8 +143,9 @@ discard block |
||
| 139 | 143 | if ($myconn->query($query) === TRUE) { |
| 140 | 144 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
| 141 | 145 | $result=TRUE; |
| 146 | + } else { |
|
| 147 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 142 | 148 | } |
| 143 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 144 | 149 | return $result; |
| 145 | 150 | } |
| 146 | 151 | |
@@ -163,9 +168,11 @@ discard block |
||
| 163 | 168 | } |
| 164 | 169 | |
| 165 | 170 | |
| 166 | - if ($return=$myconn->query($query) === TRUE) |
|
| 167 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 168 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 171 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 172 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 173 | + } else { |
|
| 174 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 175 | + } |
|
| 169 | 176 | |
| 170 | 177 | return $return; |
| 171 | 178 | } |
@@ -187,8 +194,9 @@ discard block |
||
| 187 | 194 | |
| 188 | 195 | if ($return=$myconn->query($query) === TRUE) { |
| 189 | 196 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 197 | + } else { |
|
| 198 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 190 | 199 | } |
| 191 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 192 | 200 | return $return; |
| 193 | 201 | } |
| 194 | 202 | |
@@ -212,14 +220,16 @@ discard block |
||
| 212 | 220 | $j++; |
| 213 | 221 | |
| 214 | 222 | } while ($myconn->next_result()); |
| 215 | - } |
|
| 216 | - else { |
|
| 223 | + } else { |
|
| 217 | 224 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
| 218 | 225 | $return = FALSE; |
| 219 | 226 | } |
| 220 | 227 | } |
| 221 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 222 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 228 | + if ( !($return) ) { |
|
| 229 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 230 | + } else { |
|
| 231 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 232 | + } |
|
| 223 | 233 | return $return; |
| 224 | 234 | } |
| 225 | 235 | |
@@ -228,8 +238,11 @@ discard block |
||
| 228 | 238 | |
| 229 | 239 | $exp=new DateTime($row['exp']); |
| 230 | 240 | $now=new DateTime('NOW'); |
| 231 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 232 | - else return false; |
|
| 241 | + if (($exp > $now) and ($row['active'])) { |
|
| 242 | + return true; |
|
| 243 | + } else { |
|
| 244 | + return false; |
|
| 245 | + } |
|
| 233 | 246 | |
| 234 | 247 | } |
| 235 | 248 | |
@@ -249,10 +262,11 @@ discard block |
||
| 249 | 262 | END; |
| 250 | 263 | $activeMilts = explode(',',$value); |
| 251 | 264 | foreach ( $milts as $milter ) { |
| 252 | - if ( in_array($milter, $activeMilts) ) |
|
| 253 | - $selected= 'selected'; |
|
| 254 | - else |
|
| 255 | - $selected= NULL; |
|
| 265 | + if ( in_array($milter, $activeMilts) ) { |
|
| 266 | + $selected= 'selected'; |
|
| 267 | + } else { |
|
| 268 | + $selected= NULL; |
|
| 269 | + } |
|
| 256 | 270 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
| 257 | 271 | } |
| 258 | 272 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -269,9 +283,12 @@ discard block |
||
| 269 | 283 | $whynot=NULL; |
| 270 | 284 | switch ($what) { |
| 271 | 285 | case 'Ok': |
| 272 | - if ($lock) return NULL; |
|
| 273 | - if (in_array($user,array_keys($adm))) |
|
| 274 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 286 | + if ($lock) { |
|
| 287 | + return NULL; |
|
| 288 | + } |
|
| 289 | + if (in_array($user,array_keys($adm))) { |
|
| 290 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 291 | + } |
|
| 275 | 292 | return htmlspecialchars($whynot); |
| 276 | 293 | case 'Listed': |
| 277 | 294 | case 'WhiteListed': |
@@ -283,7 +300,9 @@ discard block |
||
| 283 | 300 | function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
| 284 | 301 | /* Check if there are no pending mislisting */ |
| 285 | 302 | $warn = NULL; |
| 286 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
| 303 | + if (! isset($alltables["$typed"]['depend']) ) { |
|
| 304 | + return TRUE; |
|
| 305 | + } |
|
| 287 | 306 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 288 | 307 | if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
| 289 | 308 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
@@ -314,10 +333,10 @@ discard block |
||
| 314 | 333 | |
| 315 | 334 | if ( $tablelist['milter'] ) { |
| 316 | 335 | $table = milterTable($type); |
| 317 | - if ($value == 'ALL') |
|
| 318 | - $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 336 | + if ($value == 'ALL') { |
|
| 337 | + $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 319 | 338 | $table,$table); |
| 320 | - else { |
|
| 339 | + } else { |
|
| 321 | 340 | switch ($type) { |
| 322 | 341 | case 'network': |
| 323 | 342 | list($sub['net'],$sub['mask'])=explode('/',$value); |
@@ -342,12 +361,11 @@ discard block |
||
| 342 | 361 | return FALSE; |
| 343 | 362 | } |
| 344 | 363 | } |
| 345 | - } |
|
| 346 | - |
|
| 347 | - else { |
|
| 364 | + } else { |
|
| 348 | 365 | $table = $tablelist['name']; |
| 349 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 350 | - else { |
|
| 366 | + if ($value == 'ALL') { |
|
| 367 | + $query = 'select * from '.$table; |
|
| 368 | + } else { |
|
| 351 | 369 | switch ($type) { |
| 352 | 370 | case 'ip': |
| 353 | 371 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -369,8 +387,9 @@ discard block |
||
| 369 | 387 | } |
| 370 | 388 | |
| 371 | 389 | $result = $myconn->query($query); |
| 372 | - if($result === false) |
|
| 373 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 390 | + if($result === false) { |
|
| 391 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 392 | + } |
|
| 374 | 393 | return $result; |
| 375 | 394 | } |
| 376 | 395 | |
@@ -387,12 +406,14 @@ discard block |
||
| 387 | 406 | |
| 388 | 407 | function isFull($myconn,$typedesc,$alltables) { |
| 389 | 408 | if (isset($alltables["$typedesc"]['limit'])) { |
| 390 | - if ( $alltables["$typedesc"]['milter'] ) |
|
| 391 | - $tab = 'net'; |
|
| 392 | - else |
|
| 393 | - $tab = $alltables["$typedesc"]['name']; |
|
| 394 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 395 | - return TRUE; |
|
| 409 | + if ( $alltables["$typedesc"]['milter'] ) { |
|
| 410 | + $tab = 'net'; |
|
| 411 | + } else { |
|
| 412 | + $tab = $alltables["$typedesc"]['name']; |
|
| 413 | + } |
|
| 414 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) { |
|
| 415 | + return TRUE; |
|
| 416 | + } |
|
| 396 | 417 | } |
| 397 | 418 | return FALSE; |
| 398 | 419 | } |
@@ -405,8 +426,9 @@ discard block |
||
| 405 | 426 | $tabhtm = <<<END |
| 406 | 427 | <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> |
| 407 | 428 | END; |
| 408 | - if ( $tables["$typedesc"]['milter'] ) |
|
| 409 | - $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 429 | + if ( $tables["$typedesc"]['milter'] ) { |
|
| 430 | + $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 431 | + } |
|
| 410 | 432 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 411 | 433 | |
| 412 | 434 | $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
@@ -415,18 +437,23 @@ discard block |
||
| 415 | 437 | |
| 416 | 438 | /* Check for limit in number of listed items */ |
| 417 | 439 | $full = isFull($myconn,$typedesc,$tables); |
| 418 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 440 | + if ($full) { |
|
| 441 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 442 | + } |
|
| 419 | 443 | |
| 420 | 444 | if ($result->num_rows) { |
| 421 | 445 | print $tabhtm; |
| 422 | 446 | $i=0; |
| 423 | 447 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 424 | 448 | if (isListed($riga)) { |
| 425 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 426 | - else $listed='WhiteListed'; |
|
| 427 | - } |
|
| 428 | - else |
|
| 429 | - $listed='Ok'; |
|
| 449 | + if ($tables["$typedesc"]['bl']) { |
|
| 450 | + $listed='Listed'; |
|
| 451 | + } else { |
|
| 452 | + $listed='WhiteListed'; |
|
| 453 | + } |
|
| 454 | + } else { |
|
| 455 | + $listed='Ok'; |
|
| 456 | + } |
|
| 430 | 457 | |
| 431 | 458 | switch ($type) { |
| 432 | 459 | case 'ip': |
@@ -439,27 +466,30 @@ discard block |
||
| 439 | 466 | $element = $riga["$type"]; |
| 440 | 467 | } |
| 441 | 468 | |
| 442 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
| 443 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 469 | + if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) { |
|
| 470 | + printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 444 | 471 | $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn,$i,$element,$typedesc,$riga['idmilt'],$riga['miltnames'],$user,$adm), $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
| 445 | - else |
|
| 446 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 472 | + } else { |
|
| 473 | + printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 447 | 474 | $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
| 475 | + } |
|
| 448 | 476 | $i++; |
| 449 | 477 | } |
| 450 | 478 | print '</tbody></table>'; |
| 451 | - } |
|
| 452 | - else { |
|
| 479 | + } else { |
|
| 453 | 480 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 454 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 455 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 456 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 481 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
| 482 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 483 | + } else { |
|
| 484 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 485 | + } |
|
| 457 | 486 | |
| 458 | 487 | } |
| 459 | 488 | $result->free(); |
| 489 | + } else { |
|
| 490 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 491 | + } |
|
| 460 | 492 | } |
| 461 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 462 | -} |
|
| 463 | 493 | |
| 464 | 494 | |
| 465 | 495 | |
@@ -502,24 +532,32 @@ discard block |
||
| 502 | 532 | $old_mailfrom = ini_get("sendmail_from"); |
| 503 | 533 | ini_set("sendmail_from", $from); |
| 504 | 534 | $params = sprintf("-oi -f %s", '<>'); |
| 505 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 506 | - else $flag=TRUE; |
|
| 507 | - if (isset($old_mailfrom)) |
|
| 508 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 509 | - } |
|
| 510 | - else { |
|
| 511 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 512 | - else $flag=TRUE; |
|
| 535 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
| 536 | + $flag=FALSE; |
|
| 537 | + } else { |
|
| 538 | + $flag=TRUE; |
|
| 539 | + } |
|
| 540 | + if (isset($old_mailfrom)) { |
|
| 541 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 542 | + } |
|
| 543 | + } else { |
|
| 544 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
| 545 | + $flag=FALSE; |
|
| 546 | + } else { |
|
| 547 | + $flag=TRUE; |
|
| 548 | + } |
|
| 513 | 549 | } |
| 514 | 550 | return $flag; |
| 515 | 551 | } |
| 516 | 552 | |
| 517 | 553 | function emailToNotify($notify_file,$dom) { |
| 518 | 554 | $ini_array = parse_ini_file($notify_file); |
| 519 | - if (in_array($dom,array_keys($ini_array))) |
|
| 520 | - return $ini_array["$dom"]; |
|
| 521 | - else return FALSE; |
|
| 522 | -} |
|
| 555 | + if (in_array($dom,array_keys($ini_array))) { |
|
| 556 | + return $ini_array["$dom"]; |
|
| 557 | + } else { |
|
| 558 | + return FALSE; |
|
| 559 | + } |
|
| 560 | + } |
|
| 523 | 561 | |
| 524 | 562 | |
| 525 | 563 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
@@ -567,8 +605,7 @@ discard block |
||
| 567 | 605 | $reason); |
| 568 | 606 | $quantity = 1; |
| 569 | 607 | $unit = 'DAY'; |
| 570 | - } |
|
| 571 | - else { |
|
| 608 | + } else { |
|
| 572 | 609 | /* Entry delisted */ |
| 573 | 610 | $quantity *= $thisentry['nlist']; |
| 574 | 611 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
@@ -599,9 +636,10 @@ discard block |
||
| 599 | 636 | $net = new \dautkom\ipv4\IPv4(); |
| 600 | 637 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
| 601 | 638 | $ips = ipRange($range); |
| 602 | - foreach ( $ips as $ip ) |
|
| 603 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 639 | + foreach ( $ips as $ip ) { |
|
| 640 | + if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 604 | 641 | return TRUE; |
| 642 | + } |
|
| 605 | 643 | return FALSE; |
| 606 | 644 | } |
| 607 | 645 | |
@@ -678,8 +716,9 @@ discard block |
||
| 678 | 716 | return FALSE; |
| 679 | 717 | } |
| 680 | 718 | if ($result->num_rows) { |
| 681 | - while ($milt = $result->fetch_array(MYSQLI_ASSOC)) |
|
| 682 | - $milters[] = $milt['name']; |
|
| 719 | + while ($milt = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 720 | + $milters[] = $milt['name']; |
|
| 721 | + } |
|
| 683 | 722 | } |
| 684 | 723 | $result->free(); |
| 685 | 724 | return $milters; |
@@ -705,12 +744,14 @@ discard block |
||
| 705 | 744 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
| 706 | 745 | } |
| 707 | 746 | } |
| 708 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 747 | + if ( count($query) ) { |
|
| 748 | + /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 709 | 749 | /* I update datemod because the user couldn't change */ |
| 710 | 750 | $query[] = sprintf('UPDATE `%s` SET |
| 711 | 751 | `user`=\'%s\', |
| 712 | 752 | `datemod`= CURRENT_TIMESTAMP |
| 713 | 753 | WHERE `idmilt`=%d', $table, $loguser, $miltID); |
| 754 | + } |
|
| 714 | 755 | |
| 715 | 756 | |
| 716 | 757 | /* Start a safe transaction: it commits only if all queries happen */ |
@@ -724,19 +765,20 @@ discard block |
||
| 724 | 765 | } |
| 725 | 766 | } |
| 726 | 767 | if ( $ok ) { |
| 727 | - if ( $myconn->commit() ) |
|
| 728 | - syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 729 | - else { |
|
| 768 | + if ( $myconn->commit() ) { |
|
| 769 | + syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 770 | + } else { |
|
| 730 | 771 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
| 731 | - if ( $myconn->rollback() ) |
|
| 732 | - syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 733 | - else |
|
| 734 | - syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 772 | + if ( $myconn->rollback() ) { |
|
| 773 | + syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 774 | + } else { |
|
| 775 | + syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 776 | + } |
|
| 735 | 777 | $ok = FALSE; |
| 736 | 778 | } |
| 779 | + } else { |
|
| 780 | + syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 737 | 781 | } |
| 738 | - else |
|
| 739 | - syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 740 | 782 | return $ok; |
| 741 | 783 | |
| 742 | 784 | } |