@@ -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 (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) |
|
13 | + if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) |
|
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'] ) { |
@@ -13,7 +13,7 @@ |
||
13 | 13 | $err = NULL; |
14 | 14 | |
15 | 15 | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
16 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
16 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
17 | 17 | |
18 | 18 | if (addtolist ($mysqli,$user,$_POST['value'],$tables["$typedesc"],$_POST['unit'],$_POST['quantity'],$_POST['reason'],$err)) |
19 | 19 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> first time listed for '.$_POST['quantity'].$_POST['unit'].'.'; |
@@ -4,18 +4,18 @@ 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 | |
12 | 12 | |
13 | 13 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
14 | - $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
14 | + $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
15 | 15 | $mysqli = new mysqli($host, $user, $pass, $db, $port); |
16 | - if ($mysqli->connect_error) { |
|
17 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
18 | - . $mysqli->connect_error); |
|
16 | + if ($mysqli->connect_error) { |
|
17 | + syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
18 | + . $mysqli->connect_error); |
|
19 | 19 | return FALSE; |
20 | 20 | } |
21 | 21 | syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | } |
58 | 58 | list($sub['net'],$sub['mask'])=explode('/',$value); |
59 | - $query= sprintf("INSERT INTO `$table` ( |
|
59 | + $query= sprintf("INSERT INTO `$table` ( |
|
60 | 60 | `$type` , |
61 | 61 | `netmask`, |
62 | 62 | `date` , |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
70 | 70 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
71 | 71 | )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
72 | - break; |
|
72 | + break; |
|
73 | 73 | |
74 | 74 | default: |
75 | - $query= sprintf("INSERT INTO `$table` ( |
|
75 | + $query= sprintf("INSERT INTO `$table` ( |
|
76 | 76 | `$type` , |
77 | 77 | `date` , |
78 | 78 | `exp` , |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | if ($myconn->query($query) === TRUE) { |
90 | - syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
91 | - $result=TRUE; |
|
90 | + syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
91 | + $result=TRUE; |
|
92 | 92 | } |
93 | 93 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
94 | 94 | return $result; |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | |
99 | 99 | $result=FALSE; |
100 | 100 | |
101 | - switch ($type) { |
|
101 | + switch ($type) { |
|
102 | 102 | case 'ip': |
103 | - $query= sprintf("UPDATE `$table` SET |
|
103 | + $query= sprintf("UPDATE `$table` SET |
|
104 | 104 | `active` = '1', |
105 | 105 | `user` = '%s', |
106 | 106 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | `reason` = '%s' |
109 | 109 | WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
110 | 110 | break; |
111 | - case 'network': |
|
111 | + case 'network': |
|
112 | 112 | list($sub['net'],$sub['mask'])=explode('/',$value); |
113 | - $query= sprintf("UPDATE `$table` SET |
|
113 | + $query= sprintf("UPDATE `$table` SET |
|
114 | 114 | `active` = '1', |
115 | 115 | `user` = '%s', |
116 | 116 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); |
120 | 120 | break; |
121 | 121 | default: |
122 | - $query= sprintf("UPDATE `$table` SET |
|
122 | + $query= sprintf("UPDATE `$table` SET |
|
123 | 123 | `active` = '1', |
124 | 124 | `user` = '%s', |
125 | 125 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -128,18 +128,18 @@ discard block |
||
128 | 128 | WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
129 | 129 | } |
130 | 130 | |
131 | - if ($myconn->query($query) === TRUE) { |
|
132 | - syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
|
131 | + if ($myconn->query($query) === TRUE) { |
|
132 | + syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
|
133 | 133 | $result=TRUE; |
134 | - } |
|
135 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
134 | + } |
|
135 | + else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
136 | 136 | return $result; |
137 | 137 | } |
138 | 138 | |
139 | 139 | function remove ($myconn,$user,$value,$type,$table) { |
140 | 140 | |
141 | - switch ($type) { |
|
142 | - case 'ip': |
|
141 | + switch ($type) { |
|
142 | + case 'ip': |
|
143 | 143 | $query = sprintf("DELETE FROM `$table` WHERE |
144 | 144 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
145 | 145 | break; |
@@ -155,18 +155,18 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | |
158 | - if ($return=$myconn->query($query) === TRUE) |
|
159 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
160 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
158 | + if ($return=$myconn->query($query) === TRUE) |
|
159 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
160 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
161 | 161 | |
162 | - return $return; |
|
162 | + return $return; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
166 | 166 | function changestatus ($myconn,$user,$value,$status,$type,$table) { |
167 | 167 | |
168 | 168 | switch ($type) { |
169 | - case 'ip': |
|
169 | + case 'ip': |
|
170 | 170 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
171 | 171 | break; |
172 | 172 | case 'network': |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
178 | 178 | } |
179 | 179 | |
180 | - if ($return=$myconn->query($query) === TRUE) { |
|
181 | - syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
182 | - } |
|
183 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
180 | + if ($return=$myconn->query($query) === TRUE) { |
|
181 | + syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
182 | + } |
|
183 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
184 | 184 | return $return; |
185 | 185 | } |
186 | 186 | |
187 | 187 | |
188 | 188 | function expire ($myconn,$user,$tables,$expireTime) { |
189 | - $return=TRUE; |
|
189 | + $return=TRUE; |
|
190 | 190 | $log=array(); |
191 | 191 | $desc = array_keys($tables); |
192 | 192 | foreach ($desc as $tdesc) { |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | /* END OF QUERY */ |
197 | 197 | $log[0] = 'expired for'; |
198 | 198 | $log[1] = 'disabled for'; |
199 | - if ($myconn->multi_query($query)) { |
|
199 | + if ($myconn->multi_query($query)) { |
|
200 | 200 | $j = 0; |
201 | 201 | do { |
202 | - $numdel = $myconn->affected_rows; |
|
203 | - syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
202 | + $numdel = $myconn->affected_rows; |
|
203 | + syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
204 | 204 | $j++; |
205 | 205 | |
206 | 206 | } while ($myconn->next_result()); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | } |
213 | 213 | if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
214 | 214 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
215 | - return $return; |
|
215 | + return $return; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | if ( $entry->num_rows ) { |
286 | 286 | if ( $entry->num_rows == 1 ) { |
287 | 287 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
288 | - if (isListed($riga)) { |
|
288 | + if (isListed($riga)) { |
|
289 | 289 | $warn = "<$value> is already present in <$listdep> list!"; |
290 | 290 | $entry->free(); |
291 | 291 | return FALSE; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | function searchentry ($myconn,$value,$tablelist) { |
303 | 303 | /* Make a MYSQL query and return result */ |
304 | 304 | |
305 | - $type = $tablelist['field']; |
|
305 | + $type = $tablelist['field']; |
|
306 | 306 | |
307 | 307 | if ( $tablelist['milter'] ) { |
308 | 308 | $table = milterTable($type); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | case 'ip': |
327 | 327 | $query = sprintf('SELECT * FROM ( |
328 | 328 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)' . |
329 | - 'WHERE `ip` = INET_ATON(\'%s\') |
|
329 | + 'WHERE `ip` = INET_ATON(\'%s\') |
|
330 | 330 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
331 | 331 | break; |
332 | 332 | default: |
@@ -337,33 +337,33 @@ discard block |
||
337 | 337 | } |
338 | 338 | |
339 | 339 | else { |
340 | - $table = $tablelist['name']; |
|
341 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
342 | - else { |
|
343 | - switch ($type) { |
|
344 | - case 'ip': |
|
345 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
346 | - break; |
|
347 | - case 'network': |
|
348 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
349 | - $query= sprintf('select * from `%s` |
|
340 | + $table = $tablelist['name']; |
|
341 | + if ($value == 'ALL') $query = 'select * from '.$table; |
|
342 | + else { |
|
343 | + switch ($type) { |
|
344 | + case 'ip': |
|
345 | + $query= "select * from $table where $type = INET_ATON('$value')"; |
|
346 | + break; |
|
347 | + case 'network': |
|
348 | + list($sub['net'],$sub['mask'])=explode('/',$value); |
|
349 | + $query= sprintf('select * from `%s` |
|
350 | 350 | WHERE ( |
351 | 351 | inet_aton(\'%s\') >= network AND |
352 | 352 | ( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) ) |
353 | 353 | <= network | ( netmask ^ (power(2,32)-1) ) |
354 | 354 | )', $table, $sub['net'], $sub['net'], $sub['mask']); |
355 | 355 | ; |
356 | - break; |
|
357 | - default: |
|
358 | - $query= "select * from $table where $type = '$value'"; |
|
359 | - } |
|
360 | - } |
|
356 | + break; |
|
357 | + default: |
|
358 | + $query= "select * from $table where $type = '$value'"; |
|
359 | + } |
|
360 | + } |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | $result = $myconn->query($query); |
364 | 364 | if($result === false) |
365 | 365 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
366 | - return $result; |
|
366 | + return $result; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | function countListed ($myconn,$table) { |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | |
379 | 379 | |
380 | 380 | function isFull($myconn,$typedesc,$alltables) { |
381 | - if (isset($alltables["$typedesc"]['limit'])) { |
|
381 | + if (isset($alltables["$typedesc"]['limit'])) { |
|
382 | 382 | if ( $alltables["$typedesc"]['milter'] ) |
383 | 383 | $tab = 'net'; |
384 | 384 | else |
385 | 385 | $tab = $alltables["$typedesc"]['name']; |
386 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
387 | - return TRUE; |
|
388 | - } |
|
386 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
387 | + return TRUE; |
|
388 | + } |
|
389 | 389 | return FALSE; |
390 | 390 | } |
391 | 391 | |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | if ($result) { |
406 | 406 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
407 | 407 | |
408 | - /* Check for limit in number of listed items */ |
|
408 | + /* Check for limit in number of listed items */ |
|
409 | 409 | $full = isFull($myconn,$typedesc,$tables); |
410 | 410 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
411 | 411 | |
412 | 412 | if ($result->num_rows) { |
413 | 413 | print $tabhtm; |
414 | 414 | $i=0; |
415 | - while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
415 | + while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
416 | 416 | if (isListed($riga)) { |
417 | 417 | if ($tables["$typedesc"]['bl']) $listed='Listed'; |
418 | 418 | else $listed='WhiteListed'; |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | 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", |
439 | 439 | $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)); |
440 | 440 | $i++; |
441 | - } |
|
441 | + } |
|
442 | 442 | print '</tbody></table>'; |
443 | 443 | } |
444 | 444 | else { |
@@ -458,15 +458,15 @@ discard block |
||
458 | 458 | |
459 | 459 | function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
460 | 460 | $now = time(); |
461 | - setlocale (LC_TIME, 'it_IT'); |
|
462 | - $date = date("r",$now); |
|
461 | + setlocale (LC_TIME, 'it_IT'); |
|
462 | + $date = date("r",$now); |
|
463 | 463 | $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; |
464 | 464 | $mua = 'PHP/' . phpversion(); |
465 | 465 | |
466 | 466 | /* Parsing headers */ |
467 | 467 | if (!file_exists($tplf['header'])) { |
468 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
469 | - exit; |
|
468 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
469 | + exit; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | $head_tmpl = file_get_contents($tplf['header']); |
@@ -475,35 +475,35 @@ discard block |
||
475 | 475 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
476 | 476 | $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
477 | 477 | |
478 | - /* Parsing body */ |
|
478 | + /* Parsing body */ |
|
479 | 479 | |
480 | - if (!file_exists($tplf['body'])) { |
|
481 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
482 | - exit; |
|
483 | - } |
|
480 | + if (!file_exists($tplf['body'])) { |
|
481 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
482 | + exit; |
|
483 | + } |
|
484 | 484 | |
485 | - $body_tmpl = file_get_contents($tplf['body']); |
|
486 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
487 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
488 | - $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
489 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
485 | + $body_tmpl = file_get_contents($tplf['body']); |
|
486 | + $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
487 | + $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
488 | + $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
489 | + $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
490 | 490 | $body = wordwrap ( $body, 75 , "\r\n" ); |
491 | 491 | |
492 | 492 | /* Send the mail! */ |
493 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
494 | - $old_mailfrom = ini_get("sendmail_from"); |
|
495 | - ini_set("sendmail_from", $from); |
|
496 | - $params = sprintf("-oi -f %s", '<>'); |
|
497 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
498 | - else $flag=TRUE; |
|
499 | - if (isset($old_mailfrom)) |
|
500 | - ini_set("sendmail_from", $old_mailfrom); |
|
501 | - } |
|
502 | - else { |
|
503 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
504 | - else $flag=TRUE; |
|
505 | - } |
|
506 | - return $flag; |
|
493 | + if ( strlen(ini_get("safe_mode"))< 1) { |
|
494 | + $old_mailfrom = ini_get("sendmail_from"); |
|
495 | + ini_set("sendmail_from", $from); |
|
496 | + $params = sprintf("-oi -f %s", '<>'); |
|
497 | + if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
498 | + else $flag=TRUE; |
|
499 | + if (isset($old_mailfrom)) |
|
500 | + ini_set("sendmail_from", $old_mailfrom); |
|
501 | + } |
|
502 | + else { |
|
503 | + if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
504 | + else $flag=TRUE; |
|
505 | + } |
|
506 | + return $flag; |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | function emailToNotify($notify_file,$dom) { |
@@ -517,59 +517,59 @@ discard block |
||
517 | 517 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
518 | 518 | |
519 | 519 | /* Search and list value */ |
520 | - $type = $tables["$typedesc"]['field']; |
|
521 | - $table = $tables["$typedesc"]['name']; |
|
522 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
523 | - |
|
524 | - /* Manage abnormal conditions */ |
|
525 | - /* Value already present in db more than once. This is absurd. Panic! */ |
|
526 | - if ($result->num_rows > 1) { |
|
527 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
528 | - $result->free(); |
|
529 | - return FALSE; |
|
530 | - } |
|
520 | + $type = $tables["$typedesc"]['field']; |
|
521 | + $table = $tables["$typedesc"]['name']; |
|
522 | + $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
523 | + |
|
524 | + /* Manage abnormal conditions */ |
|
525 | + /* Value already present in db more than once. This is absurd. Panic! */ |
|
526 | + if ($result->num_rows > 1) { |
|
527 | + syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
528 | + $result->free(); |
|
529 | + return FALSE; |
|
530 | + } |
|
531 | 531 | |
532 | - /* Value already present in db or not present: to list anyway */ |
|
533 | - if ($result->num_rows >= 0) { |
|
534 | - /* First, check for limit in number of listed items */ |
|
535 | - if (isFull($myconn,$typedesc,$tables)) { |
|
536 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
537 | - $result->free(); |
|
538 | - return FALSE; |
|
539 | - } |
|
540 | - /* Second, check if the (re)list would be consistent now */ |
|
541 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
542 | - syslog(LOG_ERR, $loguser.': '.$whynot); |
|
543 | - $result->free(); |
|
544 | - return FALSE; |
|
545 | - } |
|
546 | - } |
|
547 | - /* End of abnormal conditions */ |
|
532 | + /* Value already present in db or not present: to list anyway */ |
|
533 | + if ($result->num_rows >= 0) { |
|
534 | + /* First, check for limit in number of listed items */ |
|
535 | + if (isFull($myconn,$typedesc,$tables)) { |
|
536 | + syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
537 | + $result->free(); |
|
538 | + return FALSE; |
|
539 | + } |
|
540 | + /* Second, check if the (re)list would be consistent now */ |
|
541 | + if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
542 | + syslog(LOG_ERR, $loguser.': '.$whynot); |
|
543 | + $result->free(); |
|
544 | + return FALSE; |
|
545 | + } |
|
546 | + } |
|
547 | + /* End of abnormal conditions */ |
|
548 | 548 | |
549 | 549 | |
550 | - /* Finally, here I can list the value! */ |
|
550 | + /* Finally, here I can list the value! */ |
|
551 | 551 | $thisentry = $result->fetch_array(MYSQLI_ASSOC); |
552 | - switch ($result->num_rows) { |
|
553 | - /* Relist value if already present */ |
|
554 | - case 1: |
|
555 | - /* Entry already listed */ |
|
556 | - if ( isListed($thisentry) ) { |
|
557 | - syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
|
558 | - $result->free(); |
|
559 | - return FALSE; |
|
560 | - } |
|
561 | - |
|
562 | - /* Entry delisted */ |
|
563 | - $result->free(); |
|
552 | + switch ($result->num_rows) { |
|
553 | + /* Relist value if already present */ |
|
554 | + case 1: |
|
555 | + /* Entry already listed */ |
|
556 | + if ( isListed($thisentry) ) { |
|
557 | + syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
|
558 | + $result->free(); |
|
559 | + return FALSE; |
|
560 | + } |
|
561 | + |
|
562 | + /* Entry delisted */ |
|
563 | + $result->free(); |
|
564 | 564 | $quantity *= $thisentry['nlist']; |
565 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
565 | + return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
566 | 566 | |
567 | 567 | |
568 | - /* First time list value */ |
|
569 | - case 0: |
|
570 | - $result->free(); |
|
571 | - return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
572 | - } |
|
568 | + /* First time list value */ |
|
569 | + case 0: |
|
570 | + $result->free(); |
|
571 | + return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
572 | + } |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | return FALSE; |
603 | 603 | } |
604 | 604 | $result = searchentry ($myconn,'ALL',$tabletype); |
605 | - if ($result->num_rows) { |
|
605 | + if ($result->num_rows) { |
|
606 | 606 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
607 | 607 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
608 | 608 | if ( isIn($thisNet, $net) ) { |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | /* For miltermap */ |
623 | 623 | function checkMilterConf($table) { |
624 | 624 | if (isset($table['milter'])) { |
625 | - if ($table['milter'] === TRUE) { |
|
625 | + if ($table['milter'] === TRUE) { |
|
626 | 626 | switch ( $table['field'] ) { |
627 | 627 | case 'network': |
628 | 628 | case 'ip': |
@@ -645,15 +645,15 @@ discard block |
||
645 | 645 | |
646 | 646 | function milterTable($t) { |
647 | 647 | /* Return the milter object table for type t or FALSE on error */ |
648 | - switch ($t) { |
|
649 | - case 'network': |
|
650 | - return 'net'; |
|
651 | - case 'ip': |
|
652 | - return 'ips'; |
|
653 | - default: |
|
648 | + switch ($t) { |
|
649 | + case 'network': |
|
650 | + return 'net'; |
|
651 | + case 'ip': |
|
652 | + return 'ips'; |
|
653 | + default: |
|
654 | 654 | syslog(LOG_EMERG, "ALERT: type <$t> not allowed in configuration. "); |
655 | - return FALSE; |
|
656 | - } |
|
655 | + return FALSE; |
|
656 | + } |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | $milters=array(); |
662 | 662 | $query = 'SELECT `name` FROM `config`'; |
663 | 663 | |
664 | - $result = $myconn->query($query); |
|
665 | - if($result === false) { |
|
666 | - syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
664 | + $result = $myconn->query($query); |
|
665 | + if($result === false) { |
|
666 | + syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
667 | 667 | return FALSE; |
668 | 668 | } |
669 | 669 | if ($result->num_rows) { |
@@ -10,7 +10,7 @@ |
||
10 | 10 | $user = username(); |
11 | 11 | |
12 | 12 | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
13 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
13 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
14 | 14 | if (remove ($mysqli,$user,$_POST['value'],$type,$table)) |
15 | 15 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; |
16 | 16 | else |
@@ -12,7 +12,7 @@ |
||
12 | 12 | $user = username(); |
13 | 13 | |
14 | 14 | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
15 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
15 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
16 | 16 | |
17 | 17 | if (changestatus($mysqli,username(),$_POST['value'],'0',$type,$table)) |
18 | 18 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> delisted.'; |