@@ -26,17 +26,17 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | /* Conf */ |
| 28 | 28 | if (!isset($_GET['conf'])) { |
| 29 | - syslog(LOG_ALERT, |
|
| 30 | - sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf', |
|
| 31 | - $user, $_SERVER['SCRIPT_NAME']) ); |
|
| 32 | - exit(254); |
|
| 29 | + syslog(LOG_ALERT, |
|
| 30 | + sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf', |
|
| 31 | + $user, $_SERVER['SCRIPT_NAME']) ); |
|
| 32 | + exit(254); |
|
| 33 | 33 | } |
| 34 | 34 | $fileconf = $_GET['conf']; |
| 35 | 35 | if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) { |
| 36 | - syslog(LOG_ALERT, |
|
| 37 | - sprintf('%s: the configuration file <%s> doesn\'t exist.', |
|
| 38 | - $user, $fileconf )); |
|
| 39 | - exit(254); |
|
| 36 | + syslog(LOG_ALERT, |
|
| 37 | + sprintf('%s: the configuration file <%s> doesn\'t exist.', |
|
| 38 | + $user, $fileconf )); |
|
| 39 | + exit(254); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | closelog(); |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | /* check you select a blocklist */ |
| 66 | 66 | if ( !$tables["$typedesc"]['bl'] ) { |
| 67 | - syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
| 68 | - exit (254); |
|
| 67 | + syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
| 68 | + exit (254); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | if (preg_match_all('/^https?\:\/\/(?<splunkhost>[\w\.\-]+)\:8000(?:\/[\w\-\_\d]+)*\/app\/(?<splunkapp>[\w\.\-\_\d]+)\/\@go\?sid=(?<job>[\w\.\-\d]+)$/', |
| 96 | 96 | $webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) { |
| 97 | 97 | syslog(LOG_ALERT, |
| 98 | - sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
|
| 98 | + sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
|
| 99 | 99 | $user, $webhook['results_link']) ); |
| 100 | 100 | return 255; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if ( $webhook['app'] != $out['splunkapp'][0] ) { |
| 104 | 104 | syslog(LOG_ALERT, |
| 105 | - sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.', |
|
| 106 | - $user, $webhook['app'], $out['splunkapp'][0] ) ); |
|
| 105 | + sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.', |
|
| 106 | + $user, $webhook['app'], $out['splunkapp'][0] ) ); |
|
| 107 | 107 | return 255; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $nr = count ($results); |
| 139 | 139 | for ($i=1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
| 140 | - $data = str_getcsv($results[$i], ','); |
|
| 141 | - $thisVal = $data[1]; |
|
| 142 | - unset($data[1]); |
|
| 143 | - $data = array_values($data); |
|
| 144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 145 | - $tolist["$thisVal"] = $data; |
|
| 146 | - else if ($data[3]>$tolist[$thisVal][3]) |
|
| 147 | - $tolist["$thisVal"] = $data; |
|
| 140 | + $data = str_getcsv($results[$i], ','); |
|
| 141 | + $thisVal = $data[1]; |
|
| 142 | + unset($data[1]); |
|
| 143 | + $data = array_values($data); |
|
| 144 | + if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 145 | + $tolist["$thisVal"] = $data; |
|
| 146 | + else if ($data[3]>$tolist[$thisVal][3]) |
|
| 147 | + $tolist["$thisVal"] = $data; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /* Make MYSQL connection */ |
@@ -154,34 +154,34 @@ discard block |
||
| 154 | 154 | exit (254); |
| 155 | 155 | |
| 156 | 156 | foreach ( array_keys($tolist) as $value) { |
| 157 | - $quantity = $conf['quantity']; |
|
| 158 | - $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
|
| 159 | - if ( $tolist["$value"][3] >= $threshold ) { |
|
| 160 | - if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
| 161 | - syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
| 162 | - /* Send a email to domain admin if you list an email */ |
|
| 163 | - if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
| 164 | - /* Sometime uid are in the form of <user>@<domain> ... */ |
|
| 165 | - if ( strpos($value, '@') !== FALSE ) { |
|
| 166 | - $domain = substr(strrchr($value, '@'), 1); |
|
| 167 | - if ( strpos($domain, '@') === FALSE ) { |
|
| 168 | - $recip = emailToNotify($domainNotify_file,$domain); |
|
| 169 | - $subject = sprintf('%s <%s> is now blocked because exceeds limits on outgoing emails', |
|
| 170 | - $tables["$typedesc"]['field'], $value); |
|
| 171 | - if (!empty($recip)) |
|
| 172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | - $subject,$value,"$quantity $unit",$reason) ) |
|
| 174 | - syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
|
| 175 | - } |
|
| 176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - else { |
|
| 182 | - $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
|
| 183 | - syslog (LOG_INFO, "$user: ".$reason); |
|
| 184 | - } |
|
| 157 | + $quantity = $conf['quantity']; |
|
| 158 | + $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
|
| 159 | + if ( $tolist["$value"][3] >= $threshold ) { |
|
| 160 | + if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
| 161 | + syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
| 162 | + /* Send a email to domain admin if you list an email */ |
|
| 163 | + if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
| 164 | + /* Sometime uid are in the form of <user>@<domain> ... */ |
|
| 165 | + if ( strpos($value, '@') !== FALSE ) { |
|
| 166 | + $domain = substr(strrchr($value, '@'), 1); |
|
| 167 | + if ( strpos($domain, '@') === FALSE ) { |
|
| 168 | + $recip = emailToNotify($domainNotify_file,$domain); |
|
| 169 | + $subject = sprintf('%s <%s> is now blocked because exceeds limits on outgoing emails', |
|
| 170 | + $tables["$typedesc"]['field'], $value); |
|
| 171 | + if (!empty($recip)) |
|
| 172 | + if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | + $subject,$value,"$quantity $unit",$reason) ) |
|
| 174 | + syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
|
| 175 | + } |
|
| 176 | + else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + else { |
|
| 182 | + $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
|
| 183 | + syslog (LOG_INFO, "$user: ".$reason); |
|
| 184 | + } |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /* Close connection */ |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | /************** Conf *******************/ |
| 18 | 18 | $base = '/var/www/html/RBL'; |
| 19 | -require_once($base . '/config.php'); |
|
| 19 | +require_once($base.'/config.php'); |
|
| 20 | 20 | |
| 21 | 21 | /* Syslog basic */ |
| 22 | -$tag .= 'SplunkLister'; |
|
| 23 | -$user = 'Splunk'; |
|
| 22 | +$tag .= 'SplunkLister'; |
|
| 23 | +$user = 'Splunk'; |
|
| 24 | 24 | |
| 25 | 25 | openlog($tag, LOG_PID, $fac); |
| 26 | 26 | |
@@ -28,43 +28,43 @@ discard block |
||
| 28 | 28 | if (!isset($_GET['conf'])) { |
| 29 | 29 | syslog(LOG_ALERT, |
| 30 | 30 | sprintf('%s: you must insert the config file name as a GET parameter, such as %s?conf=listEmail.conf', |
| 31 | - $user, $_SERVER['SCRIPT_NAME']) ); |
|
| 31 | + $user, $_SERVER['SCRIPT_NAME'])); |
|
| 32 | 32 | exit(254); |
| 33 | 33 | } |
| 34 | 34 | $fileconf = $_GET['conf']; |
| 35 | -if ( !file_exists(dirname(__FILE__) . '/../' . $fileconf) ) { |
|
| 35 | +if (!file_exists(dirname(__FILE__).'/../'.$fileconf)) { |
|
| 36 | 36 | syslog(LOG_ALERT, |
| 37 | 37 | sprintf('%s: the configuration file <%s> doesn\'t exist.', |
| 38 | - $user, $fileconf )); |
|
| 38 | + $user, $fileconf)); |
|
| 39 | 39 | exit(254); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | closelog(); |
| 43 | -$conf = parse_ini_file( dirname(__FILE__) . '/../' . $fileconf ); |
|
| 43 | +$conf = parse_ini_file(dirname(__FILE__).'/../'.$fileconf); |
|
| 44 | 44 | |
| 45 | 45 | /* Splunk inherited parameters */ |
| 46 | -$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
| 46 | +$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
| 47 | 47 | |
| 48 | 48 | /* Blacklist name */ |
| 49 | 49 | $typedesc = $conf['typedesc']; |
| 50 | 50 | |
| 51 | 51 | /* How long to list's parameters */ |
| 52 | -$unit = $conf['unit']; /* MySQL language ;) */ |
|
| 52 | +$unit = $conf['unit']; /* MySQL language ;) */ |
|
| 53 | 53 | |
| 54 | 54 | /* Syslog extended info */ |
| 55 | -$tag .= $conf['tag']; |
|
| 55 | +$tag .= $conf['tag']; |
|
| 56 | 56 | |
| 57 | 57 | /* Splunk password of alert owner*/ |
| 58 | 58 | $splpwd = $conf['splunkpassword']; |
| 59 | 59 | /************** End of conf *************************/ |
| 60 | 60 | |
| 61 | 61 | openlog($tag, LOG_PID, $fac); |
| 62 | -require_once($base . '/function.php'); |
|
| 62 | +require_once($base.'/function.php'); |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | /* check you select a blocklist */ |
| 66 | -if ( !$tables["$typedesc"]['bl'] ) { |
|
| 67 | - syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
| 66 | +if (!$tables["$typedesc"]['bl']) { |
|
| 67 | + syslog(LOG_EMERG, "$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
| 68 | 68 | exit (254); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | $webhook['results_link'], $out, PREG_PATTERN_ORDER) === FALSE) { |
| 97 | 97 | syslog(LOG_ALERT, |
| 98 | 98 | sprintf('%s: unexpected error: can\'t parse the results link returned by webhook (<%s>).', |
| 99 | - $user, $webhook['results_link']) ); |
|
| 99 | + $user, $webhook['results_link'])); |
|
| 100 | 100 | return 255; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | -if ( $webhook['app'] != $out['splunkapp'][0] ) { |
|
| 103 | +if ($webhook['app'] != $out['splunkapp'][0]) { |
|
| 104 | 104 | syslog(LOG_ALERT, |
| 105 | 105 | sprintf('%s: unexpected error: the APP returned by webhook (<%s>) doesn\'t match the app (<%s>) in result link.', |
| 106 | - $user, $webhook['app'], $out['splunkapp'][0] ) ); |
|
| 106 | + $user, $webhook['app'], $out['splunkapp'][0])); |
|
| 107 | 107 | return 255; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $tolist = array(); |
| 137 | 137 | |
| 138 | -$nr = count ($results); |
|
| 139 | -for ($i=1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
|
| 138 | +$nr = count($results); |
|
| 139 | +for ($i = 1; $i<$nr; $i++) { /* We skip first header line (i=0) */ |
|
| 140 | 140 | $data = str_getcsv($results[$i], ','); |
| 141 | 141 | $thisVal = $data[1]; |
| 142 | 142 | unset($data[1]); |
| 143 | 143 | $data = array_values($data); |
| 144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 144 | + if (!in_array($thisVal, array_keys($tolist))) |
|
| 145 | 145 | $tolist["$thisVal"] = $data; |
| 146 | 146 | else if ($data[3]>$tolist[$thisVal][3]) |
| 147 | 147 | $tolist["$thisVal"] = $data; |
@@ -150,42 +150,42 @@ discard block |
||
| 150 | 150 | /* Make MYSQL connection */ |
| 151 | 151 | |
| 152 | 152 | $mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user); |
| 153 | -if ( $mysqli === FALSE ) |
|
| 153 | +if ($mysqli === FALSE) |
|
| 154 | 154 | exit (254); |
| 155 | 155 | |
| 156 | -foreach ( array_keys($tolist) as $value) { |
|
| 156 | +foreach (array_keys($tolist) as $value) { |
|
| 157 | 157 | $quantity = $conf['quantity']; |
| 158 | 158 | $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
| 159 | - if ( $tolist["$value"][3] >= $threshold ) { |
|
| 160 | - if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
| 161 | - syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
| 159 | + if ($tolist["$value"][3]>=$threshold) { |
|
| 160 | + if (searchAndList($mysqli, $user, $tables, $typedesc, $value, $unit, $quantity, $reason)) { |
|
| 161 | + syslog(LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
| 162 | 162 | /* Send a email to domain admin if you list an email */ |
| 163 | - if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
| 163 | + if (($tables["$typedesc"]['field'] == 'email') OR ($tables["$typedesc"]['field'] == 'username')) { |
|
| 164 | 164 | /* Sometime uid are in the form of <user>@<domain> ... */ |
| 165 | - if ( strpos($value, '@') !== FALSE ) { |
|
| 165 | + if (strpos($value, '@') !== FALSE) { |
|
| 166 | 166 | $domain = substr(strrchr($value, '@'), 1); |
| 167 | - if ( strpos($domain, '@') === FALSE ) { |
|
| 168 | - $recip = emailToNotify($domainNotify_file,$domain); |
|
| 167 | + if (strpos($domain, '@') === FALSE) { |
|
| 168 | + $recip = emailToNotify($domainNotify_file, $domain); |
|
| 169 | 169 | $subject = sprintf('%s <%s> is now blocked because exceeds limits on outgoing emails', |
| 170 | 170 | $tables["$typedesc"]['field'], $value); |
| 171 | 171 | if (!empty($recip)) |
| 172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | - $subject,$value,"$quantity $unit",$reason) ) |
|
| 172 | + if (sendEmailWarn($tplfile, '[email protected]', $recip, |
|
| 173 | + $subject, $value, "$quantity $unit", $reason)) |
|
| 174 | 174 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
| 175 | 175 | } |
| 176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 176 | + else syslog(LOG_ERR, "$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | else { |
| 182 | 182 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
| 183 | - syslog (LOG_INFO, "$user: ".$reason); |
|
| 183 | + syslog(LOG_INFO, "$user: ".$reason); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /* Close connection */ |
| 188 | -syslog (LOG_INFO, "$user: ".'Successfully end of session.'); |
|
| 188 | +syslog(LOG_INFO, "$user: ".'Successfully end of session.'); |
|
| 189 | 189 | $mysqli->close(); |
| 190 | 190 | closelog(); |
| 191 | 191 | |
@@ -141,17 +141,19 @@ discard block |
||
| 141 | 141 | $thisVal = $data[1]; |
| 142 | 142 | unset($data[1]); |
| 143 | 143 | $data = array_values($data); |
| 144 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
| 145 | - $tolist["$thisVal"] = $data; |
|
| 146 | - else if ($data[3]>$tolist[$thisVal][3]) |
|
| 147 | - $tolist["$thisVal"] = $data; |
|
| 148 | -} |
|
| 144 | + if ( !in_array($thisVal,array_keys($tolist)) ) { |
|
| 145 | + $tolist["$thisVal"] = $data; |
|
| 146 | + } else if ($data[3]>$tolist[$thisVal][3]) { |
|
| 147 | + $tolist["$thisVal"] = $data; |
|
| 148 | + } |
|
| 149 | + } |
|
| 149 | 150 | |
| 150 | 151 | /* Make MYSQL connection */ |
| 151 | 152 | |
| 152 | 153 | $mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user); |
| 153 | -if ( $mysqli === FALSE ) |
|
| 154 | +if ( $mysqli === FALSE ) { |
|
| 154 | 155 | exit (254); |
| 156 | +} |
|
| 155 | 157 | |
| 156 | 158 | foreach ( array_keys($tolist) as $value) { |
| 157 | 159 | $quantity = $conf['quantity']; |
@@ -168,17 +170,18 @@ discard block |
||
| 168 | 170 | $recip = emailToNotify($domainNotify_file,$domain); |
| 169 | 171 | $subject = sprintf('%s <%s> is now blocked because exceeds limits on outgoing emails', |
| 170 | 172 | $tables["$typedesc"]['field'], $value); |
| 171 | - if (!empty($recip)) |
|
| 172 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | + if (!empty($recip)) { |
|
| 174 | + if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
| 173 | 175 | $subject,$value,"$quantity $unit",$reason) ) |
| 174 | 176 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
| 177 | + } |
|
| 178 | + } else { |
|
| 179 | + syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 175 | 180 | } |
| 176 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
| 177 | 181 | } |
| 178 | 182 | } |
| 179 | 183 | } |
| 180 | - } |
|
| 181 | - else { |
|
| 184 | + } else { |
|
| 182 | 185 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
| 183 | 186 | syslog (LOG_INFO, "$user: ".$reason); |
| 184 | 187 | } |
@@ -3,22 +3,27 @@ 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 | |
| 12 | 16 | function checkSSL() { |
| 13 | - if ( empty( $_SERVER['HTTPS'] ) ) |
|
| 14 | - printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
| 17 | + if ( empty( $_SERVER['HTTPS'] ) ) { |
|
| 18 | + printf ('<div id="content">Ehi sysadmin! Your site is not secure. Please enable SSL on your server and configure a redirect, such as' . |
|
| 15 | 19 | '<pre>' . |
| 16 | 20 | htmlspecialchars('<VirtualHost *:80>' . "\n" . |
| 17 | 21 | ' ServerName %s' . "\n" . |
| 18 | 22 | ' Redirect permanent / https://%s/' . "\n" . |
| 19 | 23 | '</VirtualHost>') . |
| 20 | 24 | '</pre></div>', gethostname(), gethostname()); |
| 21 | -} |
|
| 25 | + } |
|
| 26 | + } |
|
| 22 | 27 | |
| 23 | 28 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
| 24 | 29 | $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
@@ -99,8 +104,9 @@ discard block |
||
| 99 | 104 | if ($myconn->query($query) === TRUE) { |
| 100 | 105 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 101 | 106 | $result=TRUE; |
| 107 | + } else { |
|
| 108 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 102 | 109 | } |
| 103 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 104 | 110 | return $result; |
| 105 | 111 | } |
| 106 | 112 | |
@@ -110,8 +116,7 @@ discard block |
||
| 110 | 116 | if ( $exptime ) { /* Entry already listed */ |
| 111 | 117 | $nlist = '`nlist`'; |
| 112 | 118 | $exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */ |
| 113 | - } |
|
| 114 | - else { |
|
| 119 | + } else { |
|
| 115 | 120 | $exptime = 'CURRENT_TIMESTAMP'; |
| 116 | 121 | $nlist = '`nlist` + 1'; |
| 117 | 122 | } |
@@ -149,8 +154,9 @@ discard block |
||
| 149 | 154 | if ($myconn->query($query) === TRUE) { |
| 150 | 155 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime."); |
| 151 | 156 | $result=TRUE; |
| 157 | + } else { |
|
| 158 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 152 | 159 | } |
| 153 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 154 | 160 | return $result; |
| 155 | 161 | } |
| 156 | 162 | |
@@ -173,9 +179,11 @@ discard block |
||
| 173 | 179 | } |
| 174 | 180 | |
| 175 | 181 | |
| 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); |
|
| 182 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 183 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 184 | + } else { |
|
| 185 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 186 | + } |
|
| 179 | 187 | |
| 180 | 188 | return $return; |
| 181 | 189 | } |
@@ -197,8 +205,9 @@ discard block |
||
| 197 | 205 | |
| 198 | 206 | if ($return=$myconn->query($query) === TRUE) { |
| 199 | 207 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 208 | + } else { |
|
| 209 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 200 | 210 | } |
| 201 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 202 | 211 | return $return; |
| 203 | 212 | } |
| 204 | 213 | |
@@ -222,14 +231,16 @@ discard block |
||
| 222 | 231 | $j++; |
| 223 | 232 | |
| 224 | 233 | } while ($myconn->next_result()); |
| 225 | - } |
|
| 226 | - else { |
|
| 234 | + } else { |
|
| 227 | 235 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
| 228 | 236 | $return = FALSE; |
| 229 | 237 | } |
| 230 | 238 | } |
| 231 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 232 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 239 | + if ( !($return) ) { |
|
| 240 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 241 | + } else { |
|
| 242 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 243 | + } |
|
| 233 | 244 | return $return; |
| 234 | 245 | } |
| 235 | 246 | |
@@ -238,8 +249,11 @@ discard block |
||
| 238 | 249 | |
| 239 | 250 | $exp=new DateTime($row['exp']); |
| 240 | 251 | $now=new DateTime('NOW'); |
| 241 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 242 | - else return false; |
|
| 252 | + if (($exp > $now) and ($row['active'])) { |
|
| 253 | + return true; |
|
| 254 | + } else { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 243 | 257 | |
| 244 | 258 | } |
| 245 | 259 | |
@@ -259,10 +273,11 @@ discard block |
||
| 259 | 273 | END; |
| 260 | 274 | $activeMilts = explode(',',$value); |
| 261 | 275 | foreach ( $milts as $milter ) { |
| 262 | - if ( in_array($milter, $activeMilts) ) |
|
| 263 | - $selected= 'selected'; |
|
| 264 | - else |
|
| 265 | - $selected= NULL; |
|
| 276 | + if ( in_array($milter, $activeMilts) ) { |
|
| 277 | + $selected= 'selected'; |
|
| 278 | + } else { |
|
| 279 | + $selected= NULL; |
|
| 280 | + } |
|
| 266 | 281 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
| 267 | 282 | } |
| 268 | 283 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -279,9 +294,12 @@ discard block |
||
| 279 | 294 | $whynot=NULL; |
| 280 | 295 | switch ($what) { |
| 281 | 296 | case 'Ok': |
| 282 | - if ($lock) return NULL; |
|
| 283 | - if (in_array($user,array_keys($adm))) |
|
| 284 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 297 | + if ($lock) { |
|
| 298 | + return NULL; |
|
| 299 | + } |
|
| 300 | + if (in_array($user,array_keys($adm))) { |
|
| 301 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 302 | + } |
|
| 285 | 303 | return htmlspecialchars($whynot); |
| 286 | 304 | case 'Listed': |
| 287 | 305 | case 'WhiteListed': |
@@ -293,7 +311,9 @@ discard block |
||
| 293 | 311 | function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
| 294 | 312 | /* Check if there are no pending mislisting */ |
| 295 | 313 | $warn = NULL; |
| 296 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
| 314 | + if (! isset($alltables["$typed"]['depend']) ) { |
|
| 315 | + return TRUE; |
|
| 316 | + } |
|
| 297 | 317 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 298 | 318 | if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
| 299 | 319 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
@@ -324,10 +344,10 @@ discard block |
||
| 324 | 344 | |
| 325 | 345 | if ( $tablelist['milter'] ) { |
| 326 | 346 | $table = milterTable($type); |
| 327 | - if ($value == 'ALL') |
|
| 328 | - $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 347 | + if ($value == 'ALL') { |
|
| 348 | + $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 329 | 349 | $table,$table); |
| 330 | - else { |
|
| 350 | + } else { |
|
| 331 | 351 | switch ($type) { |
| 332 | 352 | case 'network': |
| 333 | 353 | list($sub['net'],$sub['mask'])=explode('/',$value); |
@@ -352,12 +372,11 @@ discard block |
||
| 352 | 372 | return FALSE; |
| 353 | 373 | } |
| 354 | 374 | } |
| 355 | - } |
|
| 356 | - |
|
| 357 | - else { |
|
| 375 | + } else { |
|
| 358 | 376 | $table = $tablelist['name']; |
| 359 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 360 | - else { |
|
| 377 | + if ($value == 'ALL') { |
|
| 378 | + $query = 'select * from '.$table; |
|
| 379 | + } else { |
|
| 361 | 380 | switch ($type) { |
| 362 | 381 | case 'ip': |
| 363 | 382 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -379,8 +398,9 @@ discard block |
||
| 379 | 398 | } |
| 380 | 399 | |
| 381 | 400 | $result = $myconn->query($query); |
| 382 | - if($result === false) |
|
| 383 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 401 | + if($result === false) { |
|
| 402 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 403 | + } |
|
| 384 | 404 | return $result; |
| 385 | 405 | } |
| 386 | 406 | |
@@ -397,12 +417,14 @@ discard block |
||
| 397 | 417 | |
| 398 | 418 | function isFull($myconn,$typedesc,$alltables) { |
| 399 | 419 | if (isset($alltables["$typedesc"]['limit'])) { |
| 400 | - if ( $alltables["$typedesc"]['milter'] ) |
|
| 401 | - $tab = 'net'; |
|
| 402 | - else |
|
| 403 | - $tab = $alltables["$typedesc"]['name']; |
|
| 404 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 405 | - return TRUE; |
|
| 420 | + if ( $alltables["$typedesc"]['milter'] ) { |
|
| 421 | + $tab = 'net'; |
|
| 422 | + } else { |
|
| 423 | + $tab = $alltables["$typedesc"]['name']; |
|
| 424 | + } |
|
| 425 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) { |
|
| 426 | + return TRUE; |
|
| 427 | + } |
|
| 406 | 428 | } |
| 407 | 429 | return FALSE; |
| 408 | 430 | } |
@@ -415,14 +437,17 @@ discard block |
||
| 415 | 437 | $tabhtm = <<<END |
| 416 | 438 | <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> |
| 417 | 439 | END; |
| 418 | - if ( $tables["$typedesc"]['milter'] ) |
|
| 419 | - $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 440 | + if ( $tables["$typedesc"]['milter'] ) { |
|
| 441 | + $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 442 | + } |
|
| 420 | 443 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 421 | 444 | |
| 422 | - if (($type == 'domain') AND ($value != 'ALL')) |
|
| 423 | - $value = nsdom($value); |
|
| 424 | - if (is_null($value)) |
|
| 425 | - return FALSE; |
|
| 445 | + if (($type == 'domain') AND ($value != 'ALL')) { |
|
| 446 | + $value = nsdom($value); |
|
| 447 | + } |
|
| 448 | + if (is_null($value)) { |
|
| 449 | + return FALSE; |
|
| 450 | + } |
|
| 426 | 451 | |
| 427 | 452 | $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
| 428 | 453 | if ($result) { |
@@ -430,18 +455,23 @@ discard block |
||
| 430 | 455 | |
| 431 | 456 | /* Check for limit in number of listed items */ |
| 432 | 457 | $full = isFull($myconn,$typedesc,$tables); |
| 433 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 458 | + if ($full) { |
|
| 459 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 460 | + } |
|
| 434 | 461 | |
| 435 | 462 | if ($result->num_rows) { |
| 436 | 463 | print $tabhtm; |
| 437 | 464 | $i=0; |
| 438 | 465 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 439 | 466 | if (isListed($riga)) { |
| 440 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 441 | - else $listed='WhiteListed'; |
|
| 442 | - } |
|
| 443 | - else |
|
| 444 | - $listed='Ok'; |
|
| 467 | + if ($tables["$typedesc"]['bl']) { |
|
| 468 | + $listed='Listed'; |
|
| 469 | + } else { |
|
| 470 | + $listed='WhiteListed'; |
|
| 471 | + } |
|
| 472 | + } else { |
|
| 473 | + $listed='Ok'; |
|
| 474 | + } |
|
| 445 | 475 | |
| 446 | 476 | switch ($type) { |
| 447 | 477 | case 'ip': |
@@ -454,27 +484,30 @@ discard block |
||
| 454 | 484 | $element = $riga["$type"]; |
| 455 | 485 | } |
| 456 | 486 | |
| 457 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
| 458 | - 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", |
|
| 487 | + if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) { |
|
| 488 | + 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", |
|
| 459 | 489 | $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)); |
| 460 | - else |
|
| 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", |
|
| 490 | + } else { |
|
| 491 | + 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 | 492 | $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)); |
| 493 | + } |
|
| 463 | 494 | $i++; |
| 464 | 495 | } |
| 465 | 496 | print '</tbody></table>'; |
| 466 | - } |
|
| 467 | - else { |
|
| 497 | + } else { |
|
| 468 | 498 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 469 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 470 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 471 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 499 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
| 500 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 501 | + } else { |
|
| 502 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 503 | + } |
|
| 472 | 504 | |
| 473 | 505 | } |
| 474 | 506 | $result->free(); |
| 507 | + } else { |
|
| 508 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 509 | + } |
|
| 475 | 510 | } |
| 476 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 477 | -} |
|
| 478 | 511 | |
| 479 | 512 | |
| 480 | 513 | |
@@ -517,24 +550,32 @@ discard block |
||
| 517 | 550 | $old_mailfrom = ini_get("sendmail_from"); |
| 518 | 551 | ini_set("sendmail_from", $from); |
| 519 | 552 | $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; |
|
| 553 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
| 554 | + $flag=FALSE; |
|
| 555 | + } else { |
|
| 556 | + $flag=TRUE; |
|
| 557 | + } |
|
| 558 | + if (isset($old_mailfrom)) { |
|
| 559 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 560 | + } |
|
| 561 | + } else { |
|
| 562 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
| 563 | + $flag=FALSE; |
|
| 564 | + } else { |
|
| 565 | + $flag=TRUE; |
|
| 566 | + } |
|
| 528 | 567 | } |
| 529 | 568 | return $flag; |
| 530 | 569 | } |
| 531 | 570 | |
| 532 | 571 | function emailToNotify($notify_file,$dom) { |
| 533 | 572 | $ini_array = parse_ini_file($notify_file); |
| 534 | - if (in_array($dom,array_keys($ini_array))) |
|
| 535 | - return $ini_array["$dom"]; |
|
| 536 | - else return FALSE; |
|
| 537 | -} |
|
| 573 | + if (in_array($dom,array_keys($ini_array))) { |
|
| 574 | + return $ini_array["$dom"]; |
|
| 575 | + } else { |
|
| 576 | + return FALSE; |
|
| 577 | + } |
|
| 578 | + } |
|
| 538 | 579 | |
| 539 | 580 | |
| 540 | 581 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) { |
@@ -582,8 +623,7 @@ discard block |
||
| 582 | 623 | $reason); |
| 583 | 624 | $quantity = 1; |
| 584 | 625 | $unit = 'DAY'; |
| 585 | - } |
|
| 586 | - else { |
|
| 626 | + } else { |
|
| 587 | 627 | /* Entry delisted */ |
| 588 | 628 | $quantity *= $thisentry['nlist']; |
| 589 | 629 | $expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */ |
@@ -614,9 +654,10 @@ discard block |
||
| 614 | 654 | $net = new \dautkom\ipv4\IPv4(); |
| 615 | 655 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
| 616 | 656 | $ips = ipRange($range); |
| 617 | - foreach ( $ips as $ip ) |
|
| 618 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 657 | + foreach ( $ips as $ip ) { |
|
| 658 | + if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 619 | 659 | return TRUE; |
| 660 | + } |
|
| 620 | 661 | return FALSE; |
| 621 | 662 | } |
| 622 | 663 | |
@@ -693,8 +734,9 @@ discard block |
||
| 693 | 734 | return FALSE; |
| 694 | 735 | } |
| 695 | 736 | if ($result->num_rows) { |
| 696 | - while ($milt = $result->fetch_array(MYSQLI_ASSOC)) |
|
| 697 | - $milters[] = $milt['name']; |
|
| 737 | + while ($milt = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 738 | + $milters[] = $milt['name']; |
|
| 739 | + } |
|
| 698 | 740 | } |
| 699 | 741 | $result->free(); |
| 700 | 742 | return $milters; |
@@ -720,12 +762,14 @@ discard block |
||
| 720 | 762 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
| 721 | 763 | } |
| 722 | 764 | } |
| 723 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 765 | + if ( count($query) ) { |
|
| 766 | + /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 724 | 767 | /* I update datemod because the user couldn't change */ |
| 725 | 768 | $query[] = sprintf('UPDATE `%s` SET |
| 726 | 769 | `user`=\'%s\', |
| 727 | 770 | `datemod`= CURRENT_TIMESTAMP |
| 728 | 771 | WHERE `idmilt`=%d', $table, $loguser, $miltID); |
| 772 | + } |
|
| 729 | 773 | |
| 730 | 774 | |
| 731 | 775 | /* Start a safe transaction: it commits only if all queries happen */ |
@@ -739,19 +783,20 @@ discard block |
||
| 739 | 783 | } |
| 740 | 784 | } |
| 741 | 785 | if ( $ok ) { |
| 742 | - if ( $myconn->commit() ) |
|
| 743 | - syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 744 | - else { |
|
| 786 | + if ( $myconn->commit() ) { |
|
| 787 | + syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 788 | + } else { |
|
| 745 | 789 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
| 746 | - if ( $myconn->rollback() ) |
|
| 747 | - syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 748 | - else |
|
| 749 | - syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 790 | + if ( $myconn->rollback() ) { |
|
| 791 | + syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 792 | + } else { |
|
| 793 | + syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 794 | + } |
|
| 750 | 795 | $ok = FALSE; |
| 751 | 796 | } |
| 797 | + } else { |
|
| 798 | + syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 752 | 799 | } |
| 753 | - else |
|
| 754 | - syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 755 | 800 | return $ok; |
| 756 | 801 | |
| 757 | 802 | } |
@@ -780,20 +825,24 @@ discard block |
||
| 780 | 825 | function nsdom($dom) { |
| 781 | 826 | /* Return the first lowercase upper domain (or domain itself) with NS record */ |
| 782 | 827 | /* checkdnsrr doesn't work with alias... use dns_get_record */ |
| 783 | - if (dns_get_record ( $dom , DNS_NS )) |
|
| 784 | - return strtolower(rtrim($dom, '.')); |
|
| 785 | - if (dns_get_record ( $dom , DNS_A )) |
|
| 786 | - return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
| 828 | + if (dns_get_record ( $dom , DNS_NS )) { |
|
| 829 | + return strtolower(rtrim($dom, '.')); |
|
| 830 | + } |
|
| 831 | + if (dns_get_record ( $dom , DNS_A )) { |
|
| 832 | + return nsdom( ltrim(strstr($dom, '.'), '.') ); |
|
| 833 | + } |
|
| 787 | 834 | return NULL; |
| 788 | 835 | } |
| 789 | 836 | |
| 790 | 837 | function isValid($dom) { |
| 791 | 838 | /* Return TRUE id domain has NS or A record */ |
| 792 | 839 | if (preg_match('/^(?!:\/\/)([a-zA-Z0-9-]+\.){0,5}[a-zA-Z0-9-][a-zA-Z0-9-]+\.[a-zA-Z]{2,64}?\.{0,1}$/i',$dom) === 1) { |
| 793 | - if (checkdnsrr ( $dom , 'NS' )) |
|
| 794 | - return TRUE; |
|
| 795 | - if (checkdnsrr ( $dom , 'A' )) |
|
| 796 | - return TRUE; |
|
| 840 | + if (checkdnsrr ( $dom , 'NS' )) { |
|
| 841 | + return TRUE; |
|
| 842 | + } |
|
| 843 | + if (checkdnsrr ( $dom , 'A' )) { |
|
| 844 | + return TRUE; |
|
| 845 | + } |
|
| 797 | 846 | } |
| 798 | 847 | return FALSE; |
| 799 | 848 | } |