@@ -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 exceedes 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 exceedes 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 | } |