| @@ -1,4 +1,7 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | +/** | |
| 3 | + * @param string $header | |
| 4 | + */ | |
| 2 | 5 |  function getIP($header,$mxserver,$msa) { | 
| 3 | 6 | /* Get submission server's IP from header's mail */ | 
| 4 | 7 | /* Each line must end with /r/n */ | 
| @@ -28,11 +31,23 @@ discard block | ||
| 28 | 31 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); | 
| 29 | 32 | } | 
| 30 | 33 | |
| 34 | +/** | |
| 35 | + * @param string $hostname | |
| 36 | + * @param string $dateC | |
| 37 | + * @param string|null $msgid | |
| 38 | + * @param string|false $dateL | |
| 39 | + */ | |
| 31 | 40 |  function updateReport ($ip,$uid,$ipcount,$uidcount,$hostname,$dateC,$msgid,$dateL) { | 
| 32 | 41 | |
| 33 | 42 |  	return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td><td>%s</td><td>%s</td></tr>'."\n",$dateL,$dateC,$uid,$ip,$uidcount,$ipcount,$hostname,htmlentities($msgid) ); | 
| 34 | 43 | } | 
| 35 | 44 | |
| 45 | +/** | |
| 46 | + * @param string $dateC | |
| 47 | + * @param string|null $msgid | |
| 48 | + * @param false|string $dateL | |
| 49 | + * @param string $text | |
| 50 | + */ | |
| 36 | 51 |  function updatebadReport ( $uid,$dateC,$msgid,$dateL,$text ) { | 
| 37 | 52 |  	return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td nowrap>%s</td></tr>'."\n",$dateL,$dateC,$uid,htmlentities($msgid),$text ); | 
| 38 | 53 | } | 
| @@ -84,6 +99,10 @@ discard block | ||
| 84 | 99 | } | 
| 85 | 100 | |
| 86 | 101 | |
| 102 | +/** | |
| 103 | + * @param null|mysqli $myconn | |
| 104 | + * @param string $key | |
| 105 | + */ | |
| 87 | 106 |  function summaryReportAndList ($cf,$myconn,$tables,$category,$vet,$key) { | 
| 88 | 107 | $nk = $vet['count']; | 
| 89 | 108 | |
| @@ -160,6 +179,10 @@ discard block | ||
| 160 | 179 | } | 
| 161 | 180 | |
| 162 | 181 | |
| 182 | +/** | |
| 183 | + * @param string $message_id | |
| 184 | + * @param string $date | |
| 185 | + */ | |
| 163 | 186 |  function splunksearch ($service,$message_id,$date) { | 
| 164 | 187 | |
| 165 | 188 | // Run a blocking search | 
| @@ -272,6 +295,9 @@ discard block | ||
| 272 | 295 | } | 
| 273 | 296 | /***********************************/ | 
| 274 | 297 | |
| 298 | +/** | |
| 299 | + * @param string $text | |
| 300 | + */ | |
| 275 | 301 |  function getDomains ($text) { | 
| 276 | 302 | $pattern = '~[a-z]+://\S+~'; | 
| 277 | 303 | $ret = array(); | 
| @@ -324,6 +350,9 @@ discard block | ||
| 324 | 350 | return array(); | 
| 325 | 351 | } | 
| 326 | 352 | |
| 353 | +/** | |
| 354 | + * @return string | |
| 355 | + */ | |
| 327 | 356 |  function humanKey($key) { | 
| 328 | 357 |  	switch($key) { | 
| 329 | 358 | case 'ip': | 
| @@ -334,6 +363,11 @@ discard block | ||
| 334 | 363 | return $key; | 
| 335 | 364 | } | 
| 336 | 365 | |
| 366 | +/** | |
| 367 | + * @param resource $f | |
| 368 | + * @param string $key | |
| 369 | + * @param string $rtime | |
| 370 | + */ | |
| 337 | 371 |  function writeFileHeader($f,$conf,$key,$type,$rtime) { | 
| 338 | 372 | fwrite( $f, file_get_contents(dirname(__FILE__) . '/' . $conf['report']['reportTemplateHeader']) ); | 
| 339 | 373 |          fwrite( $f,sprintf('<h1> Report of %s %s</h1><h5>%s</h5><h2>Detailed Report</h2>',$type, strtoupper(humanKey($key)),$rtime) ); | 
| @@ -12,14 +12,14 @@ discard block | ||
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; | 
| 13 | 13 | if ( preg_match($msa,$received['host'][$i]) ) | 
| 14 | 14 | $dateR = $received['date'][$i]; | 
| 15 | -        		foreach ($mxserver as $mx) { | |
| 16 | - if (!$ip) | |
| 15 | +				foreach ($mxserver as $mx) { | |
| 16 | + if (!$ip) | |
| 17 | 17 |  					if ($mx == $received['host'][$i]) { | 
| 18 | 18 | $host = $received['host'][$i]; | 
| 19 | 19 | $ip = $received['ip'][$i]; | 
| 20 | - } | |
| 21 | - } | |
| 22 | - } | |
| 20 | + } | |
| 21 | + } | |
| 22 | + } | |
| 23 | 23 | } | 
| 24 | 24 |  	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) | 
| 25 | 25 | $dateC['date'] = 'Not found'; | 
| @@ -39,15 +39,15 @@ discard block | ||
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 |  function summaryBadReport ($uidvet) { | 
| 42 | - $nuid = $uidvet['count']; | |
| 43 | - if ( empty($uidvet) ) return NULL; | |
| 44 | - $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; | |
| 42 | + $nuid = $uidvet['count']; | |
| 43 | + if ( empty($uidvet) ) return NULL; | |
| 44 | + $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; | |
| 45 | 45 | |
| 46 | - /* Remove count index */ | |
| 47 | - $uids = array_keys($uidvet['uid']); | |
| 46 | + /* Remove count index */ | |
| 47 | + $uids = array_keys($uidvet['uid']); | |
| 48 | 48 | $totlearn = 0; | 
| 49 | 49 | |
| 50 | -        foreach ( $uids as $uid ) { | |
| 50 | +		foreach ( $uids as $uid ) { | |
| 51 | 51 | $totlearn += $uidvet['uid']["$uid"]['count'];; | 
| 52 | 52 |  		$return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']); | 
| 53 | 53 | } | 
| @@ -60,26 +60,26 @@ discard block | ||
| 60 | 60 | |
| 61 | 61 | function array_msort($array, $cols) | 
| 62 | 62 |  { | 
| 63 | - $colarr = array(); | |
| 64 | -    foreach ($cols as $col => $order) { | |
| 65 | - $colarr[$col] = array(); | |
| 66 | -        foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } | |
| 67 | - } | |
| 68 | -    $eval = 'array_multisort('; | |
| 69 | -    foreach ($cols as $col => $order) { | |
| 70 | - $eval .= '$colarr[\''.$col.'\'],'.$order.','; | |
| 71 | - } | |
| 72 | - $eval = substr($eval,0,-1).');'; | |
| 73 | - eval($eval); | |
| 74 | - $ret = array(); | |
| 75 | -    foreach ($colarr as $col => $arr) { | |
| 76 | -        foreach ($arr as $k => $v) { | |
| 77 | - $k = substr($k,1); | |
| 78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; | |
| 79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; | |
| 80 | - } | |
| 81 | - } | |
| 82 | - return $ret; | |
| 63 | + $colarr = array(); | |
| 64 | +	foreach ($cols as $col => $order) { | |
| 65 | + $colarr[$col] = array(); | |
| 66 | +		foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } | |
| 67 | + } | |
| 68 | +	$eval = 'array_multisort('; | |
| 69 | +	foreach ($cols as $col => $order) { | |
| 70 | + $eval .= '$colarr[\''.$col.'\'],'.$order.','; | |
| 71 | + } | |
| 72 | + $eval = substr($eval,0,-1).');'; | |
| 73 | + eval($eval); | |
| 74 | + $ret = array(); | |
| 75 | +	foreach ($colarr as $col => $arr) { | |
| 76 | +		foreach ($arr as $k => $v) { | |
| 77 | + $k = substr($k,1); | |
| 78 | + if (!isset($ret[$k])) $ret[$k] = $array[$k]; | |
| 79 | + if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + return $ret; | |
| 83 | 83 | |
| 84 | 84 | } | 
| 85 | 85 | |
| @@ -95,8 +95,8 @@ discard block | ||
| 95 | 95 | |
| 96 | 96 |  	foreach ( $values as $value ) { | 
| 97 | 97 | if ( $value == 'count' ) continue; | 
| 98 | - $nlearn = $vet["$key"]["$value"]['count']; | |
| 99 | - unset($vet["$key"]["$value"]['count']); | |
| 98 | + $nlearn = $vet["$key"]["$value"]['count']; | |
| 99 | + unset($vet["$key"]["$value"]['count']); | |
| 100 | 100 | $quantity = $cf["listing$key"]['quantity']["$category"]; /* In searchAndList this value is | 
| 101 | 101 | passed by reference and modified */ | 
| 102 | 102 | $nuid = count($vet["$key"]["$value"]); | 
| @@ -127,9 +127,9 @@ discard block | ||
| 127 | 127 | $return .='<tr><td rowspan="'.$nuid.'">'.$value.'</td>'; | 
| 128 | 128 |  		$return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$vet["$key"]["$value"][0],$nlearn,$nowlist["$listed"]['name']); | 
| 129 | 129 | $rowuid=NULL; | 
| 130 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 130 | + for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 131 | 131 | array_shift($vet["$key"]["$value"]); | 
| 132 | - $return .= vsprintf ($rowuid,$vet["$key"]["$value"]); | |
| 132 | + $return .= vsprintf ($rowuid,$vet["$key"]["$value"]); | |
| 133 | 133 | |
| 134 | 134 | } | 
| 135 | 135 |  	$return .= sprintf ('<tr><th title="unique %s">%u</th><th title="unique uids">%u</th><th>%u</th></table>',$key,$vet["$key"]['count'],$vet['uid']['count'],$nk); | 
| @@ -139,20 +139,20 @@ discard block | ||
| 139 | 139 | /* Not used for listing purpose, but useful to you! */ | 
| 140 | 140 |  	$return .= sprintf('<h3>Statistics by UID</h3><table><tr><th>UID</th><th>%s learned</th><th>Learned times</th></tr>'."\n",$key); | 
| 141 | 141 | $uids = array_keys($vet['uid']); | 
| 142 | -        foreach ( $uids as $uid ) { | |
| 142 | +		foreach ( $uids as $uid ) { | |
| 143 | 143 | if ( $uid == 'count' ) continue; | 
| 144 | - $nlearn = $vet['uid']["$uid"]['count']; | |
| 145 | - unset ( $vet['uid']["$uid"]['count'] ); | |
| 144 | + $nlearn = $vet['uid']["$uid"]['count']; | |
| 145 | + unset ( $vet['uid']["$uid"]['count'] ); | |
| 146 | 146 | $nip = count($vet['uid']["$uid"]); | 
| 147 | 147 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; | 
| 148 | 148 |  		$return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$vet['uid']["$uid"][0],$nlearn); | 
| 149 | - $rowuid=NULL; | |
| 150 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 151 | - array_shift($vet['uid']["$uid"]); | |
| 152 | - $return .= vsprintf ($rowuid,$vet['uid']["$uid"]); | |
| 149 | + $rowuid=NULL; | |
| 150 | + for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 151 | + array_shift($vet['uid']["$uid"]); | |
| 152 | + $return .= vsprintf ($rowuid,$vet['uid']["$uid"]); | |
| 153 | 153 | |
| 154 | - } | |
| 155 | -        $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique %s">%u</th><th>%u</th></table>', | |
| 154 | + } | |
| 155 | +		$return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique %s">%u</th><th>%u</th></table>', | |
| 156 | 156 | $vet['uid']['count'],$key,$vet["$key"]['count'],$nk); | 
| 157 | 157 | |
| 158 | 158 | |
| @@ -181,50 +181,50 @@ discard block | ||
| 181 | 181 | */ | 
| 182 | 182 | |
| 183 | 183 | // A one shot search | 
| 184 | - $searchParams = array( | |
| 185 | -                'earliest_time' => date("c",strtotime ($date)-120), | |
| 186 | -                'latest_time' => date("c",strtotime ($date)+60) | |
| 187 | - ); | |
| 184 | + $searchParams = array( | |
| 185 | +				'earliest_time' => date("c",strtotime ($date)-120), | |
| 186 | +				'latest_time' => date("c",strtotime ($date)+60) | |
| 187 | + ); | |
| 188 | 188 | |
| 189 | - // Run a oneshot search that returns the job's results | |
| 190 | - $resultsStream = $service->oneshotSearch($searchQueryBlocking, $searchParams); | |
| 191 | - $resultSearch = new Splunk_ResultsReader($resultsStream); | |
| 189 | + // Run a oneshot search that returns the job's results | |
| 190 | + $resultsStream = $service->oneshotSearch($searchQueryBlocking, $searchParams); | |
| 191 | + $resultSearch = new Splunk_ResultsReader($resultsStream); | |
| 192 | 192 | |
| 193 | 193 | // Use the built-in XML parser to display the job results | 
| 194 | 194 | foreach ($resultSearch as $result) | 
| 195 | 195 |  	  { | 
| 196 | - if ($result instanceof Splunk_ResultsFieldOrder) | |
| 197 | -	    { | |
| 198 | - // More than one field attribute returned by search | |
| 199 | - // You must redefine the search | |
| 200 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; | |
| 201 | - } | |
| 202 | - else if ($result instanceof Splunk_ResultsMessage) | |
| 203 | -	    { | |
| 204 | - // I don't want messages in my search | |
| 205 | - return FALSE; | |
| 206 | - } | |
| 207 | - else if (is_array($result)) | |
| 208 | -	    { | |
| 209 | - // Process a row | |
| 210 | - foreach ($result as $key => $valueOrValues) | |
| 211 | -	        { | |
| 212 | - if (is_array($valueOrValues)) | |
| 213 | -	          { | |
| 214 | - return FALSE; | |
| 215 | - } | |
| 216 | - else | |
| 217 | -	          { | |
| 218 | - return $valueOrValues; | |
| 219 | -	            #print "  {$key} => {$value}\r\n"; | |
| 220 | - } | |
| 221 | - } | |
| 222 | - } | |
| 223 | - else | |
| 224 | -	    { | |
| 225 | - #print "Unknow result type"; | |
| 226 | - return FALSE; | |
| 227 | - } | |
| 196 | + if ($result instanceof Splunk_ResultsFieldOrder) | |
| 197 | +		{ | |
| 198 | + // More than one field attribute returned by search | |
| 199 | + // You must redefine the search | |
| 200 | + if ( count($result->getFieldNames()) > 1 ) return FALSE; | |
| 201 | + } | |
| 202 | + else if ($result instanceof Splunk_ResultsMessage) | |
| 203 | +		{ | |
| 204 | + // I don't want messages in my search | |
| 205 | + return FALSE; | |
| 206 | + } | |
| 207 | + else if (is_array($result)) | |
| 208 | +		{ | |
| 209 | + // Process a row | |
| 210 | + foreach ($result as $key => $valueOrValues) | |
| 211 | +			{ | |
| 212 | + if (is_array($valueOrValues)) | |
| 213 | +			  { | |
| 214 | + return FALSE; | |
| 215 | + } | |
| 216 | + else | |
| 217 | +			  { | |
| 218 | + return $valueOrValues; | |
| 219 | +				#print "  {$key} => {$value}\r\n"; | |
| 220 | + } | |
| 221 | + } | |
| 222 | + } | |
| 223 | + else | |
| 224 | +		{ | |
| 225 | + #print "Unknow result type"; | |
| 226 | + return FALSE; | |
| 227 | + } | |
| 228 | 228 | } | 
| 229 | 229 | } | 
| 230 | 230 | |
| @@ -235,38 +235,38 @@ discard block | ||
| 235 | 235 | |
| 236 | 236 |  function flattenParts($messageParts, $flattenedParts = array(), $prefix = '', $index = 1, $fullPrefix = true) { | 
| 237 | 237 | |
| 238 | -        foreach($messageParts as $part) { | |
| 239 | - $flattenedParts[$prefix.$index] = $part; | |
| 240 | -                if(isset($part->parts)) { | |
| 241 | -                        if($part->type == 2) { | |
| 242 | - $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false); | |
| 243 | - } | |
| 244 | -                        elseif($fullPrefix) { | |
| 245 | - $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.'); | |
| 246 | - } | |
| 247 | -                        else { | |
| 248 | - $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix); | |
| 249 | - } | |
| 250 | - unset($flattenedParts[$prefix.$index]->parts); | |
| 251 | - } | |
| 252 | - $index++; | |
| 253 | - } | |
| 254 | - | |
| 255 | - return $flattenedParts; | |
| 238 | +		foreach($messageParts as $part) { | |
| 239 | + $flattenedParts[$prefix.$index] = $part; | |
| 240 | +				if(isset($part->parts)) { | |
| 241 | +						if($part->type == 2) { | |
| 242 | + $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false); | |
| 243 | + } | |
| 244 | +						elseif($fullPrefix) { | |
| 245 | + $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.'); | |
| 246 | + } | |
| 247 | +						else { | |
| 248 | + $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix); | |
| 249 | + } | |
| 250 | + unset($flattenedParts[$prefix.$index]->parts); | |
| 251 | + } | |
| 252 | + $index++; | |
| 253 | + } | |
| 254 | + | |
| 255 | + return $flattenedParts; | |
| 256 | 256 | |
| 257 | 257 | } | 
| 258 | 258 | |
| 259 | 259 |  function getPart($connection, $messageNumber, $partNumber, $encoding) { | 
| 260 | 260 | |
| 261 | - $data = imap_fetchbody($connection, $messageNumber, $partNumber); | |
| 262 | -        switch($encoding) { | |
| 263 | - case 0: return $data; // 7BIT | |
| 264 | - case 1: return $data; // 8BIT | |
| 265 | - case 2: return $data; // BINARY | |
| 266 | - case 3: return base64_decode($data); // BASE64 | |
| 267 | - case 4: return quoted_printable_decode($data); // QUOTED_PRINTABLE | |
| 268 | - case 5: return $data; // OTHER | |
| 269 | - } | |
| 261 | + $data = imap_fetchbody($connection, $messageNumber, $partNumber); | |
| 262 | +		switch($encoding) { | |
| 263 | + case 0: return $data; // 7BIT | |
| 264 | + case 1: return $data; // 8BIT | |
| 265 | + case 2: return $data; // BINARY | |
| 266 | + case 3: return base64_decode($data); // BASE64 | |
| 267 | + case 4: return quoted_printable_decode($data); // QUOTED_PRINTABLE | |
| 268 | + case 5: return $data; // OTHER | |
| 269 | + } | |
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | } | 
| @@ -335,16 +335,16 @@ discard block | ||
| 335 | 335 | } | 
| 336 | 336 | |
| 337 | 337 |  function writeFileHeader($f,$conf,$key,$type,$rtime) { | 
| 338 | - fwrite( $f, file_get_contents(dirname(__FILE__) . '/' . $conf['report']['reportTemplateHeader']) ); | |
| 339 | -        fwrite( $f,sprintf('<h1> Report of %s %s</h1><h5>%s</h5><h2>Detailed Report</h2>',$type, strtoupper(humanKey($key)),$rtime) ); | |
| 340 | -        if ($conf["listing$key"]['onlyReport']["$type"]) { | |
| 341 | -                fwrite( $f,sprintf('<p>None of the below %s have been listed because listing is not active in configuration.</p>', | |
| 338 | + fwrite( $f, file_get_contents(dirname(__FILE__) . '/' . $conf['report']['reportTemplateHeader']) ); | |
| 339 | +		fwrite( $f,sprintf('<h1> Report of %s %s</h1><h5>%s</h5><h2>Detailed Report</h2>',$type, strtoupper(humanKey($key)),$rtime) ); | |
| 340 | +		if ($conf["listing$key"]['onlyReport']["$type"]) { | |
| 341 | +				fwrite( $f,sprintf('<p>None of the below %s have been listed because listing is not active in configuration.</p>', | |
| 342 | 342 | strtoupper(humanKey($key))) ); | 
| 343 | 343 |  		syslog(LOG_INFO, sprintf('%s: Report only for %s %s: no listing activated in configuration.', | 
| 344 | 344 | $conf['syslog']['user'],$type,humanKey($key)) | 
| 345 | 345 | ); | 
| 346 | 346 | } | 
| 347 | -        fwrite( $f,sprintf('<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>%s</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned %s appears in different mails">#%s</th><th nowrap>Received by</th><th>Message-Id</th></tr>', | |
| 347 | +		fwrite( $f,sprintf('<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>%s</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned %s appears in different mails">#%s</th><th nowrap>Received by</th><th>Message-Id</th></tr>', | |
| 348 | 348 | strtoupper($key),strtoupper($key),strtoupper($key)) ); | 
| 349 | 349 | } | 
| 350 | 350 | |
| @@ -354,25 +354,25 @@ discard block | ||
| 354 | 354 | $filed = dirname(__FILE__) . '/' . $cf['report']['reportDomFile']["$type"]; | 
| 355 | 355 | $fileb= dirname(__FILE__) . '/' . $cf['report']['badreportFile']["$type"]; | 
| 356 | 356 |  	$m_mail = imap_open('{'.$cf['imap']['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['imap']['authuser'].'}'.$cf['imap']['folder']["$type"], $cf['imap']['account'],$cf['imap']['authpassword'], OP_READONLY) | 
| 357 | - or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error()); | |
| 357 | + or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error()); | |
| 358 | 358 | if ( !$m_mail ) exit(254); | 
| 359 | 359 | |
| 360 | 360 | |
| 361 | 361 | syslog (LOG_INFO,$cf['syslog']['user'].': Successfully connected to <'.$cf['imap']['mailhost'].">; Reading $type messages of last ".$cf['imap']['oldestday'].' days...'); | 
| 362 | 362 | //get all messages | 
| 363 | 363 | $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['imap']['oldestday'].' days' ) ); | 
| 364 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); | |
| 365 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); | |
| 364 | + $dateN = date ( "d-M-Y", strToTime ( "now" ) ); | |
| 365 | + $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); | |
| 366 | 366 | |
| 367 | 367 | // Order results starting from newest message | 
| 368 | 368 |  	if ( empty($m_search) ) { | 
| 369 | 369 | syslog (LOG_INFO,$cf['syslog']['user'].": No mail found in $type folder. No reports written for $type."); | 
| 370 | - if ( $ierr = imap_errors() ) | |
| 371 | - foreach ( $ierr as $thiserr ) | |
| 372 | - syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); | |
| 373 | - if ( $ierr = imap_alerts() ) | |
| 374 | - foreach ( $ierr as $thiserr ) | |
| 375 | - syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); | |
| 370 | + if ( $ierr = imap_errors() ) | |
| 371 | + foreach ( $ierr as $thiserr ) | |
| 372 | + syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); | |
| 373 | + if ( $ierr = imap_alerts() ) | |
| 374 | + foreach ( $ierr as $thiserr ) | |
| 375 | + syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); | |
| 376 | 376 | imap_close( $m_mail ); | 
| 377 | 377 | if ( file_exists( $file ) ) unlink ($file); | 
| 378 | 378 | if ( file_exists( $filed ) ) unlink ($filed); | 
| @@ -412,16 +412,16 @@ discard block | ||
| 412 | 412 | $uidbad['count'] = 0; | 
| 413 | 413 | $uidbad['uid'] = array(); | 
| 414 | 414 | |
| 415 | - // loop for each message | |
| 415 | + // loop for each message | |
| 416 | 416 |  	foreach ($m_search as $onem) { | 
| 417 | 417 | |
| 418 | - //get imap header info for obj thang | |
| 419 | - //$headers = imap_headerinfo($m_mail, $onem); | |
| 420 | - //$head = imap_fetchheader($m_mail, $headers->Msgno); | |
| 418 | + //get imap header info for obj thang | |
| 419 | + //$headers = imap_headerinfo($m_mail, $onem); | |
| 420 | + //$head = imap_fetchheader($m_mail, $headers->Msgno); | |
| 421 | 421 | $head = imap_fetchheader($m_mail, $onem ); | 
| 422 | - //$obj = imap_rfc822_parse_headers( $head); | |
| 422 | + //$obj = imap_rfc822_parse_headers( $head); | |
| 423 | 423 | |
| 424 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx_hostname']['mx'],$cf['msa']['msalearn'] ); | |
| 424 | + list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx_hostname']['mx'],$cf['msa']['msalearn'] ); | |
| 425 | 425 |  		if (empty($mid)) { | 
| 426 | 426 | $uid='NA'; | 
| 427 | 427 | syslog (LOG_ERR, $cf['syslog']['user'].": Error retrieving data for empty Message-ID."); | 
| @@ -439,11 +439,11 @@ discard block | ||
| 439 | 439 | /* Extract domains url in body */ | 
| 440 | 440 | $domains = parseURL ($m_mail,$onem); | 
| 441 | 441 | |
| 442 | - /* Update count of each ip */ | |
| 443 | -	        if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers  and learned by valid uid */ | |
| 442 | + /* Update count of each ip */ | |
| 443 | +			if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers  and learned by valid uid */ | |
| 444 | 444 | $ipuid['count']++; //number of right messages | 
| 445 | 445 | |
| 446 | -	                if (in_array($uid,array_keys($ipuid['uid']))) { | |
| 446 | +					if (in_array($uid,array_keys($ipuid['uid']))) { | |
| 447 | 447 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid | 
| 448 | 448 | if (!in_array($ip,$ipuid['uid']["$uid"])) | 
| 449 | 449 | $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid | 
| @@ -454,16 +454,16 @@ discard block | ||
| 454 | 454 | $ipuid['uid']['count']++; //number of unique uids | 
| 455 | 455 | } | 
| 456 | 456 | |
| 457 | -                        if (in_array($ip,array_keys($ipuid['ip']))) { | |
| 458 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | |
| 457 | +						if (in_array($ip,array_keys($ipuid['ip']))) { | |
| 458 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | |
| 459 | 459 | if (!in_array($uid,$ipuid['ip']["$ip"])) | 
| 460 | 460 | $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip | 
| 461 | 461 | } | 
| 462 | -                        else { | |
| 463 | - $ipuid['ip']["$ip"]['count'] = 1; | |
| 462 | +						else { | |
| 463 | + $ipuid['ip']["$ip"]['count'] = 1; | |
| 464 | 464 | $ipuid['ip']["$ip"][]=$uid; | 
| 465 | 465 | $ipuid['ip']['count']++; //number of unique ips | 
| 466 | - } | |
| 466 | + } | |
| 467 | 467 | |
| 468 | 468 |  			foreach ($domains as $dom) { | 
| 469 | 469 | $domuid['count']++; | 
| @@ -498,18 +498,18 @@ discard block | ||
| 498 | 498 | ); | 
| 499 | 499 | } | 
| 500 | 500 | |
| 501 | - /* Update HTML report */ | |
| 502 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); | |
| 501 | + /* Update HTML report */ | |
| 502 | + fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); | |
| 503 | 503 | } | 
| 504 | -	        else {	/* Bad learn */ | |
| 504 | +			else {	/* Bad learn */ | |
| 505 | 505 | |
| 506 | - if (in_array($uid,array_keys($uidbad['uid']))) | |
| 507 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 508 | -                        else { | |
| 509 | - $uidbad['uid']["$uid"]['count'] = 1; | |
| 506 | + if (in_array($uid,array_keys($uidbad['uid']))) | |
| 507 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 508 | +						else { | |
| 509 | + $uidbad['uid']["$uid"]['count'] = 1; | |
| 510 | 510 | $uidbad['uid']["$uid"][]=$uid; | 
| 511 | - $uidbad['count']++; //numeber of unique bad uids | |
| 512 | - } | |
| 511 | + $uidbad['count']++; //numeber of unique bad uids | |
| 512 | + } | |
| 513 | 513 | /* The reason of bad report */ | 
| 514 | 514 | if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; | 
| 515 | 515 | if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; | 
| @@ -535,17 +535,17 @@ discard block | ||
| 535 | 535 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['listingip']['threshold']["$type"].' times from at least '.$cf['listingip']['thresholduid']["$type"].' different valid uids.</h5>' ); | 
| 536 | 536 | fwrite($fpd, '<hr><h2>Summary Report</h2><h5>Listing policy: domains must be learned at least '.$cf['listingdom']['threshold']["$type"].' times from at least '.$cf['listingdom']['thresholduid']["$type"].' different valid uids.</h5>' ); | 
| 537 | 537 | |
| 538 | - /* Make MYSQL connection */ | |
| 538 | + /* Make MYSQL connection */ | |
| 539 | 539 | if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] ) | 
| 540 | 540 | $mysqli = NULL; | 
| 541 | 541 |  	else { | 
| 542 | - $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); | |
| 543 | -        	if ($mysqli->connect_error) { | |
| 544 | -                	syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 545 | - . $mysqli->connect_error); | |
| 546 | - exit (254); | |
| 547 | - } | |
| 548 | - syslog(LOG_INFO, $cf['syslog']['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; | |
| 542 | + $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); | |
| 543 | +			if ($mysqli->connect_error) { | |
| 544 | +					syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 545 | + . $mysqli->connect_error); | |
| 546 | + exit (254); | |
| 547 | + } | |
| 548 | + syslog(LOG_INFO, $cf['syslog']['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; | |
| 549 | 549 | } | 
| 550 | 550 | /***********************/ | 
| 551 | 551 | |
| @@ -570,8 +570,8 @@ discard block | ||
| 570 | 570 | foreach ( $ierr as $thiserr ) | 
| 571 | 571 | syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr"); | 
| 572 | 572 | if ( $ierr = imap_alerts() ) | 
| 573 | - foreach ( $ierr as $thiserr ) | |
| 574 | - syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); | |
| 573 | + foreach ( $ierr as $thiserr ) | |
| 574 | + syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr"); | |
| 575 | 575 | imap_close($m_mail); | 
| 576 | 576 | } | 
| 577 | 577 | ?> | 
| @@ -5,10 +5,10 @@ discard block | ||
| 5 | 5 | include_once($path.'config.php'); | 
| 6 | 6 | require_once($path.'function.php'); | 
| 7 | 7 |  if ( !isset($version) ) { | 
| 8 | -        openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); | |
| 9 | - syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); | |
| 10 | - closelog(); | |
| 11 | - exit(255); | |
| 8 | +		openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); | |
| 9 | + syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); | |
| 10 | + closelog(); | |
| 11 | + exit(255); | |
| 12 | 12 | } | 
| 13 | 13 | include_once(dirname(__FILE__) . '/function.php'); | 
| 14 | 14 | $conf = parse_ini_file($confImap_file, TRUE, INI_SCANNER_TYPED); | 
| @@ -35,50 +35,50 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 | /* check you select a right list */ | 
| 37 | 37 |  	if ( !$tables[$conf['listingip']['list']['spam']]['bl'] ) { | 
| 38 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); | |
| 39 | - exit (254); | |
| 38 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); | |
| 39 | + exit (254); | |
| 40 | 40 | } | 
| 41 | 41 |  	if ( !$tables[$conf['listingip']['list']['spam']]['active'] ) { | 
| 42 | 42 | syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['spam'].'> is not active. Please, activate it to continue with this process.'); | 
| 43 | 43 | exit (254); | 
| 44 | - } | |
| 44 | + } | |
| 45 | 45 | } | 
| 46 | 46 | |
| 47 | 47 |  if ( !$conf['listingip']['onlyReport']['ham'] ) { | 
| 48 | 48 |  	if ( $tables[$conf['listingip']['list']['ham']]['bl'] ) { | 
| 49 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); | |
| 50 | - exit (254); | |
| 49 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); | |
| 50 | + exit (254); | |
| 51 | 51 | } | 
| 52 | -        if ( !$tables[$conf['listingip']['list']['ham']]['active'] ) { | |
| 53 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is not active. Please, activate it | |
| 52 | +		if ( !$tables[$conf['listingip']['list']['ham']]['active'] ) { | |
| 53 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingip']['list']['ham'].'> is not active. Please, activate it | |
| 54 | 54 | to continue with this process.'); | 
| 55 | - exit (254); | |
| 56 | - } | |
| 55 | + exit (254); | |
| 56 | + } | |
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | 59 |  if ( !$conf['listingdom']['onlyReport']['spam'] ) { | 
| 60 | 60 | |
| 61 | - /* check you select a right list */ | |
| 62 | -        if ( !$tables[$conf['listingdom']['list']['spam']]['bl'] ) { | |
| 63 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spam domain? I refuse to continue.'); | |
| 64 | - exit (254); | |
| 65 | - } | |
| 66 | -        if ( !$tables[$conf['listingdom']['list']['spam']]['active'] ) { | |
| 67 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not active. Please, activate it to continue with this process.'); | |
| 68 | - exit (254); | |
| 69 | - } | |
| 61 | + /* check you select a right list */ | |
| 62 | +		if ( !$tables[$conf['listingdom']['list']['spam']]['bl'] ) { | |
| 63 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spam domain? I refuse to continue.'); | |
| 64 | + exit (254); | |
| 65 | + } | |
| 66 | +		if ( !$tables[$conf['listingdom']['list']['spam']]['active'] ) { | |
| 67 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not active. Please, activate it to continue with this process.'); | |
| 68 | + exit (254); | |
| 69 | + } | |
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | 72 |  if ( !$conf['listingdom']['onlyReport']['ham'] ) { | 
| 73 | -        if ( $tables[$conf['listingdom']['list']['ham']]['bl'] ) { | |
| 74 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); | |
| 75 | - exit (254); | |
| 76 | - } | |
| 77 | -        if ( !$tables[$conf['listingdom']['list']['ham']]['active'] ) { | |
| 78 | - syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is not active. Please, activate it | |
| 73 | +		if ( $tables[$conf['listingdom']['list']['ham']]['bl'] ) { | |
| 74 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); | |
| 75 | + exit (254); | |
| 76 | + } | |
| 77 | +		if ( !$tables[$conf['listingdom']['list']['ham']]['active'] ) { | |
| 78 | + syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['ham'].'> is not active. Please, activate it | |
| 79 | 79 | to continue with this process.'); | 
| 80 | - exit (254); | |
| 81 | - } | |
| 80 | + exit (254); | |
| 81 | + } | |
| 82 | 82 | |
| 83 | 83 | } | 
| 84 | 84 | /* End of check list */ |