@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 7 | + else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | + else $user='unknown'; |
|
| 9 | 9 | return $user; |
| 10 | 10 | } |
| 11 | 11 | |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
| 24 | - $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 24 | + $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 25 | 25 | $mysqli = new mysqli($host, $user, $pass, $db, $port); |
| 26 | - if ($mysqli->connect_error) { |
|
| 27 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 28 | - . $mysqli->connect_error); |
|
| 26 | + if ($mysqli->connect_error) { |
|
| 27 | + syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 28 | + . $mysqli->connect_error); |
|
| 29 | 29 | return FALSE; |
| 30 | 30 | } |
| 31 | 31 | syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 69 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 69 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 70 | 70 | `$type` , |
| 71 | 71 | `netmask`, |
| 72 | 72 | `date` , |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 80 | 80 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 81 | 81 | )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
| 82 | - break; |
|
| 82 | + break; |
|
| 83 | 83 | |
| 84 | 84 | default: |
| 85 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 85 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 86 | 86 | `$type` , |
| 87 | 87 | `date` , |
| 88 | 88 | `exp` , |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | if ($myconn->query($query) === TRUE) { |
| 100 | - syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 101 | - $result=TRUE; |
|
| 100 | + syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 101 | + $result=TRUE; |
|
| 102 | 102 | } |
| 103 | 103 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 104 | 104 | return $result; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | $nlist = '`nlist` + 1'; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - switch ($type) { |
|
| 119 | + switch ($type) { |
|
| 120 | 120 | case 'ip': |
| 121 | - $query= sprintf("UPDATE `$table` SET |
|
| 121 | + $query= sprintf("UPDATE `$table` SET |
|
| 122 | 122 | `active` = '1', |
| 123 | 123 | `user` = '%s', |
| 124 | 124 | `exp` = TIMESTAMPADD(%s,%d,%s), |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | `reason` = '%s' |
| 127 | 127 | WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
| 128 | 128 | break; |
| 129 | - case 'network': |
|
| 129 | + case 'network': |
|
| 130 | 130 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 131 | - $query= sprintf("UPDATE `$table` SET |
|
| 131 | + $query= sprintf("UPDATE `$table` SET |
|
| 132 | 132 | `active` = '1', |
| 133 | 133 | `user` = '%s', |
| 134 | 134 | `exp` = TIMESTAMPADD(%s,%d,%s), |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$sub['net'],$sub['mask']); |
| 138 | 138 | break; |
| 139 | 139 | default: |
| 140 | - $query= sprintf("UPDATE `$table` SET |
|
| 140 | + $query= sprintf("UPDATE `$table` SET |
|
| 141 | 141 | `active` = '1', |
| 142 | 142 | `user` = '%s', |
| 143 | 143 | `exp` = TIMESTAMPADD(%s,%d,%s), |
@@ -146,18 +146,18 @@ discard block |
||
| 146 | 146 | WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - if ($myconn->query($query) === TRUE) { |
|
| 150 | - syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
|
| 149 | + if ($myconn->query($query) === TRUE) { |
|
| 150 | + syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
|
| 151 | 151 | $result=TRUE; |
| 152 | - } |
|
| 153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 152 | + } |
|
| 153 | + else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 154 | 154 | return $result; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function remove ($myconn,$user,$value,$type,$table) { |
| 158 | 158 | |
| 159 | - switch ($type) { |
|
| 160 | - case 'ip': |
|
| 159 | + switch ($type) { |
|
| 160 | + case 'ip': |
|
| 161 | 161 | $query = sprintf("DELETE FROM `$table` WHERE |
| 162 | 162 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
| 163 | 163 | break; |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | - if ($return=$myconn->query($query) === TRUE) |
|
| 177 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 178 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 176 | + if ($return=$myconn->query($query) === TRUE) |
|
| 177 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 178 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 179 | 179 | |
| 180 | - return $return; |
|
| 180 | + return $return; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | function changestatus ($myconn,$user,$value,$status,$type,$table) { |
| 185 | 185 | |
| 186 | 186 | switch ($type) { |
| 187 | - case 'ip': |
|
| 187 | + case 'ip': |
|
| 188 | 188 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
| 189 | 189 | break; |
| 190 | 190 | case 'network': |
@@ -195,16 +195,16 @@ discard block |
||
| 195 | 195 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if ($return=$myconn->query($query) === TRUE) { |
|
| 199 | - syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 200 | - } |
|
| 201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 198 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 199 | + syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 200 | + } |
|
| 201 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 202 | 202 | return $return; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | function expire ($myconn,$user,$tables,$expireTime) { |
| 207 | - $return=TRUE; |
|
| 207 | + $return=TRUE; |
|
| 208 | 208 | $log=array(); |
| 209 | 209 | $desc = array_keys($tables); |
| 210 | 210 | foreach ($desc as $tdesc) { |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | /* END OF QUERY */ |
| 215 | 215 | $log[0] = 'expired for'; |
| 216 | 216 | $log[1] = 'disabled for'; |
| 217 | - if ($myconn->multi_query($query)) { |
|
| 217 | + if ($myconn->multi_query($query)) { |
|
| 218 | 218 | $j = 0; |
| 219 | 219 | do { |
| 220 | - $numdel = $myconn->affected_rows; |
|
| 221 | - syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 220 | + $numdel = $myconn->affected_rows; |
|
| 221 | + syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 222 | 222 | $j++; |
| 223 | 223 | |
| 224 | 224 | } while ($myconn->next_result()); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
| 232 | 232 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
| 233 | - return $return; |
|
| 233 | + return $return; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | if ( $entry->num_rows ) { |
| 304 | 304 | if ( $entry->num_rows == 1 ) { |
| 305 | 305 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 306 | - if (isListed($riga)) { |
|
| 306 | + if (isListed($riga)) { |
|
| 307 | 307 | $warn = "<$value> is already present in <$listdep> list!"; |
| 308 | 308 | $entry->free(); |
| 309 | 309 | return FALSE; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | function searchentry ($myconn,$value,$tablelist) { |
| 321 | 321 | /* Make a MYSQL query and return result */ |
| 322 | 322 | |
| 323 | - $type = $tablelist['field']; |
|
| 323 | + $type = $tablelist['field']; |
|
| 324 | 324 | |
| 325 | 325 | if ( $tablelist['milter'] ) { |
| 326 | 326 | $table = milterTable($type); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | case 'ip': |
| 345 | 345 | $query = sprintf('SELECT * FROM ( |
| 346 | 346 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)' . |
| 347 | - 'WHERE `ip` = INET_ATON(\'%s\') |
|
| 347 | + 'WHERE `ip` = INET_ATON(\'%s\') |
|
| 348 | 348 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
| 349 | 349 | break; |
| 350 | 350 | default: |
@@ -355,33 +355,33 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | else { |
| 358 | - $table = $tablelist['name']; |
|
| 359 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 360 | - else { |
|
| 361 | - switch ($type) { |
|
| 362 | - case 'ip': |
|
| 363 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 364 | - break; |
|
| 365 | - case 'network': |
|
| 366 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 367 | - $query= sprintf('select * from `%s` |
|
| 358 | + $table = $tablelist['name']; |
|
| 359 | + if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 360 | + else { |
|
| 361 | + switch ($type) { |
|
| 362 | + case 'ip': |
|
| 363 | + $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 364 | + break; |
|
| 365 | + case 'network': |
|
| 366 | + list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 367 | + $query= sprintf('select * from `%s` |
|
| 368 | 368 | WHERE ( |
| 369 | 369 | inet_aton(\'%s\') >= network AND |
| 370 | 370 | ( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) ) |
| 371 | 371 | <= network | ( netmask ^ (power(2,32)-1) ) |
| 372 | 372 | )', $table, $sub['net'], $sub['net'], $sub['mask']); |
| 373 | 373 | ; |
| 374 | - break; |
|
| 375 | - default: |
|
| 376 | - $query= "select * from $table where $type = '$value'"; |
|
| 377 | - } |
|
| 378 | - } |
|
| 374 | + break; |
|
| 375 | + default: |
|
| 376 | + $query= "select * from $table where $type = '$value'"; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | $result = $myconn->query($query); |
| 382 | 382 | if($result === false) |
| 383 | 383 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 384 | - return $result; |
|
| 384 | + return $result; |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | function countListed ($myconn,$table) { |
@@ -396,14 +396,14 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | |
| 398 | 398 | function isFull($myconn,$typedesc,$alltables) { |
| 399 | - if (isset($alltables["$typedesc"]['limit'])) { |
|
| 399 | + if (isset($alltables["$typedesc"]['limit'])) { |
|
| 400 | 400 | if ( $alltables["$typedesc"]['milter'] ) |
| 401 | 401 | $tab = 'net'; |
| 402 | 402 | else |
| 403 | 403 | $tab = $alltables["$typedesc"]['name']; |
| 404 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 405 | - return TRUE; |
|
| 406 | - } |
|
| 404 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 405 | + return TRUE; |
|
| 406 | + } |
|
| 407 | 407 | return FALSE; |
| 408 | 408 | } |
| 409 | 409 | |
@@ -428,14 +428,14 @@ discard block |
||
| 428 | 428 | if ($result) { |
| 429 | 429 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 430 | 430 | |
| 431 | - /* Check for limit in number of listed items */ |
|
| 431 | + /* Check for limit in number of listed items */ |
|
| 432 | 432 | $full = isFull($myconn,$typedesc,$tables); |
| 433 | 433 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
| 434 | 434 | |
| 435 | 435 | if ($result->num_rows) { |
| 436 | 436 | print $tabhtm; |
| 437 | 437 | $i=0; |
| 438 | - while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 438 | + while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 439 | 439 | if (isListed($riga)) { |
| 440 | 440 | if ($tables["$typedesc"]['bl']) $listed='Listed'; |
| 441 | 441 | else $listed='WhiteListed'; |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | 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", |
| 462 | 462 | $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)); |
| 463 | 463 | $i++; |
| 464 | - } |
|
| 464 | + } |
|
| 465 | 465 | print '</tbody></table>'; |
| 466 | 466 | } |
| 467 | 467 | else { |
@@ -481,15 +481,15 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
| 483 | 483 | $now = time(); |
| 484 | - setlocale (LC_TIME, 'it_IT'); |
|
| 485 | - $date = date("r",$now); |
|
| 484 | + setlocale (LC_TIME, 'it_IT'); |
|
| 485 | + $date = date("r",$now); |
|
| 486 | 486 | $messageID = md5(uniqid($now,1)) . '@' . gethostname(); |
| 487 | 487 | $mua = 'PHP/' . phpversion(); |
| 488 | 488 | |
| 489 | 489 | /* Parsing headers */ |
| 490 | 490 | if (!file_exists($tplf['header'])) { |
| 491 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 492 | - exit; |
|
| 491 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 492 | + exit; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | $head_tmpl = file_get_contents($tplf['header']); |
@@ -498,35 +498,35 @@ discard block |
||
| 498 | 498 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 499 | 499 | $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
| 500 | 500 | |
| 501 | - /* Parsing body */ |
|
| 501 | + /* Parsing body */ |
|
| 502 | 502 | |
| 503 | - if (!file_exists($tplf['body'])) { |
|
| 504 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 505 | - exit; |
|
| 506 | - } |
|
| 503 | + if (!file_exists($tplf['body'])) { |
|
| 504 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 505 | + exit; |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - $body_tmpl = file_get_contents($tplf['body']); |
|
| 509 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 510 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 511 | - $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 512 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 508 | + $body_tmpl = file_get_contents($tplf['body']); |
|
| 509 | + $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 510 | + $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 511 | + $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 512 | + $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 513 | 513 | $body = wordwrap ( $body, 75 , "\r\n" ); |
| 514 | 514 | |
| 515 | 515 | /* Send the mail! */ |
| 516 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 517 | - $old_mailfrom = ini_get("sendmail_from"); |
|
| 518 | - ini_set("sendmail_from", $from); |
|
| 519 | - $params = sprintf("-oi -f %s", '<>'); |
|
| 520 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 521 | - else $flag=TRUE; |
|
| 522 | - if (isset($old_mailfrom)) |
|
| 523 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 524 | - } |
|
| 525 | - else { |
|
| 526 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 527 | - else $flag=TRUE; |
|
| 528 | - } |
|
| 529 | - return $flag; |
|
| 516 | + if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 517 | + $old_mailfrom = ini_get("sendmail_from"); |
|
| 518 | + ini_set("sendmail_from", $from); |
|
| 519 | + $params = sprintf("-oi -f %s", '<>'); |
|
| 520 | + if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 521 | + else $flag=TRUE; |
|
| 522 | + if (isset($old_mailfrom)) |
|
| 523 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 524 | + } |
|
| 525 | + else { |
|
| 526 | + if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 527 | + else $flag=TRUE; |
|
| 528 | + } |
|
| 529 | + return $flag; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | function emailToNotify($notify_file,$dom) { |
@@ -540,62 +540,62 @@ discard block |
||
| 540 | 540 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
| 541 | 541 | |
| 542 | 542 | /* Search and list value */ |
| 543 | - $type = $tables["$typedesc"]['field']; |
|
| 544 | - $table = $tables["$typedesc"]['name']; |
|
| 545 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 546 | - |
|
| 547 | - /* Manage abnormal conditions */ |
|
| 548 | - /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 549 | - if ($result->num_rows > 1) { |
|
| 550 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 551 | - $result->free(); |
|
| 552 | - return FALSE; |
|
| 553 | - } |
|
| 543 | + $type = $tables["$typedesc"]['field']; |
|
| 544 | + $table = $tables["$typedesc"]['name']; |
|
| 545 | + $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 546 | + |
|
| 547 | + /* Manage abnormal conditions */ |
|
| 548 | + /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 549 | + if ($result->num_rows > 1) { |
|
| 550 | + syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 551 | + $result->free(); |
|
| 552 | + return FALSE; |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | - /* Value already present in db or not present: to list anyway */ |
|
| 556 | - if ($result->num_rows >= 0) { |
|
| 557 | - /* First, check for limit in number of listed items */ |
|
| 558 | - if (isFull($myconn,$typedesc,$tables)) { |
|
| 559 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 560 | - $result->free(); |
|
| 561 | - return FALSE; |
|
| 562 | - } |
|
| 563 | - /* Second, check if the (re)list would be consistent now */ |
|
| 564 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 565 | - syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 566 | - $result->free(); |
|
| 567 | - return FALSE; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - /* End of abnormal conditions */ |
|
| 555 | + /* Value already present in db or not present: to list anyway */ |
|
| 556 | + if ($result->num_rows >= 0) { |
|
| 557 | + /* First, check for limit in number of listed items */ |
|
| 558 | + if (isFull($myconn,$typedesc,$tables)) { |
|
| 559 | + syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 560 | + $result->free(); |
|
| 561 | + return FALSE; |
|
| 562 | + } |
|
| 563 | + /* Second, check if the (re)list would be consistent now */ |
|
| 564 | + if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 565 | + syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 566 | + $result->free(); |
|
| 567 | + return FALSE; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + /* End of abnormal conditions */ |
|
| 571 | 571 | |
| 572 | 572 | |
| 573 | - /* Finally, here I can list the value! */ |
|
| 573 | + /* Finally, here I can list the value! */ |
|
| 574 | 574 | $thisentry = $result->fetch_array(MYSQLI_ASSOC); |
| 575 | - switch ($result->num_rows) { |
|
| 576 | - /* Relist value if already present */ |
|
| 577 | - case 1: |
|
| 578 | - if ( isListed($thisentry) ) { |
|
| 575 | + switch ($result->num_rows) { |
|
| 576 | + /* Relist value if already present */ |
|
| 577 | + case 1: |
|
| 578 | + if ( isListed($thisentry) ) { |
|
| 579 | 579 | /* Entry already listed */ |
| 580 | 580 | $expdate = $thisentry['exp']; |
| 581 | 581 | $reason = sprintf('%s. Already listed. Adding 1 DAY to previous expire date.', |
| 582 | 582 | $reason); |
| 583 | 583 | $quantity = 1; |
| 584 | 584 | $unit = 'DAY'; |
| 585 | - } |
|
| 585 | + } |
|
| 586 | 586 | else { |
| 587 | - /* Entry delisted */ |
|
| 587 | + /* Entry delisted */ |
|
| 588 | 588 | $quantity *= $thisentry['nlist']; |
| 589 | 589 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
| 590 | 590 | } |
| 591 | 591 | $result->free(); |
| 592 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate); |
|
| 592 | + return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate); |
|
| 593 | 593 | |
| 594 | - /* First time list value */ |
|
| 595 | - case 0: |
|
| 596 | - $result->free(); |
|
| 597 | - return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_); |
|
| 598 | - } |
|
| 594 | + /* First time list value */ |
|
| 595 | + case 0: |
|
| 596 | + $result->free(); |
|
| 597 | + return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_); |
|
| 598 | + } |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | return FALSE; |
| 629 | 629 | } |
| 630 | 630 | $result = searchentry ($myconn,'ALL',$tabletype); |
| 631 | - if ($result->num_rows) { |
|
| 631 | + if ($result->num_rows) { |
|
| 632 | 632 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
| 633 | 633 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
| 634 | 634 | if ( isIn($thisNet, $net) ) { |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | /* For miltermap */ |
| 649 | 649 | function checkMilterConf($table) { |
| 650 | 650 | if (isset($table['milter'])) { |
| 651 | - if ($table['milter'] === TRUE) { |
|
| 651 | + if ($table['milter'] === TRUE) { |
|
| 652 | 652 | switch ( $table['field'] ) { |
| 653 | 653 | case 'network': |
| 654 | 654 | case 'ip': |
@@ -671,15 +671,15 @@ discard block |
||
| 671 | 671 | |
| 672 | 672 | function milterTable($t) { |
| 673 | 673 | /* Return the milter object table for type t or FALSE on error */ |
| 674 | - switch ($t) { |
|
| 675 | - case 'network': |
|
| 676 | - return 'net'; |
|
| 677 | - case 'ip': |
|
| 678 | - return 'ips'; |
|
| 679 | - default: |
|
| 674 | + switch ($t) { |
|
| 675 | + case 'network': |
|
| 676 | + return 'net'; |
|
| 677 | + case 'ip': |
|
| 678 | + return 'ips'; |
|
| 679 | + default: |
|
| 680 | 680 | syslog(LOG_EMERG, "ALERT: type <$t> not allowed in configuration. "); |
| 681 | - return FALSE; |
|
| 682 | - } |
|
| 681 | + return FALSE; |
|
| 682 | + } |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | |
@@ -687,9 +687,9 @@ discard block |
||
| 687 | 687 | $milters=array(); |
| 688 | 688 | $query = 'SELECT `name` FROM `config`'; |
| 689 | 689 | |
| 690 | - $result = $myconn->query($query); |
|
| 691 | - if($result === false) { |
|
| 692 | - syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
| 690 | + $result = $myconn->query($query); |
|
| 691 | + if($result === false) { |
|
| 692 | + syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
| 693 | 693 | return FALSE; |
| 694 | 694 | } |
| 695 | 695 | if ($result->num_rows) { |
@@ -759,21 +759,21 @@ discard block |
||
| 759 | 759 | |
| 760 | 760 | function curl_get($url, array $get = NULL, array $options = array(), $loguser) |
| 761 | 761 | { |
| 762 | - $defaults = array( |
|
| 763 | - CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get), |
|
| 764 | - CURLOPT_HEADER => 0, |
|
| 765 | - CURLOPT_RETURNTRANSFER => TRUE, |
|
| 766 | - CURLOPT_TIMEOUT => 4 |
|
| 767 | - ); |
|
| 768 | - |
|
| 769 | - $ch = curl_init(); |
|
| 770 | - curl_setopt_array($ch, ($options + $defaults)); |
|
| 771 | - if( ! $result = curl_exec($ch)) |
|
| 772 | - { |
|
| 773 | - syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch))); |
|
| 774 | - } |
|
| 775 | - curl_close($ch); |
|
| 776 | - return $result; |
|
| 762 | + $defaults = array( |
|
| 763 | + CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get), |
|
| 764 | + CURLOPT_HEADER => 0, |
|
| 765 | + CURLOPT_RETURNTRANSFER => TRUE, |
|
| 766 | + CURLOPT_TIMEOUT => 4 |
|
| 767 | + ); |
|
| 768 | + |
|
| 769 | + $ch = curl_init(); |
|
| 770 | + curl_setopt_array($ch, ($options + $defaults)); |
|
| 771 | + if( ! $result = curl_exec($ch)) |
|
| 772 | + { |
|
| 773 | + syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch))); |
|
| 774 | + } |
|
| 775 | + curl_close($ch); |
|
| 776 | + return $result; |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid email address.</pre>'); |
| 11 | 11 | |
| 12 | 12 | if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) |
| 13 | - if (!(isValid($_POST['Value']))) |
|
| 13 | + if (!(isValid($_POST['Value']))) |
|
| 14 | 14 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); |
| 15 | 15 | |
| 16 | 16 | if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | if ( ($tables["$_"]['field']=='username') AND ($_POST['Value']!='ALL') ) { |
| 30 | - if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) |
|
| 31 | - exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); |
|
| 30 | + if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) |
|
| 31 | + exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); |
|
| 32 | 32 | if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) |
| 33 | 33 | exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); |
| 34 | 34 | switch ( $_POST['Value'] ) { |