GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ee8cca...a9843c )
by Marco
03:21
created
contrib/ipImap/function.php 1 patch
Braces   +127 added lines, -79 removed lines patch added patch discarded remove patch
@@ -10,21 +10,25 @@  discard block
 block discarded – undo
10 10
 	if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) {
11 11
 		for ($i = count($received[0])-1;$i>=0;$i--) {
12 12
 #			print "Examine ".$received[0][$i]."\n";
13
-			if ( preg_match($msa,$received['host'][$i]) )
14
-				$dateR = $received['date'][$i];
13
+			if ( preg_match($msa,$received['host'][$i]) ) {
14
+							$dateR = $received['date'][$i];
15
+			}
15 16
         		foreach ($mxserver as $mx) {
16
-        			if (!$ip)
17
-					if ($mx == $received['host'][$i]) {
17
+        			if (!$ip) {
18
+        								if ($mx == $received['host'][$i]) {
18 19
 						$host = $received['host'][$i];
20
+        			}
19 21
 						$ip = $received['ip'][$i];
20 22
                     			}
21 23
                 	}
22 24
         	}
23 25
 	}
24
-	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1)
25
-		$dateC['date'] = 'Not found';
26
-	if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1)
27
-		$mid['mid'] = NULL;
26
+	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) {
27
+			$dateC['date'] = 'Not found';
28
+	}
29
+	if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) {
30
+			$mid['mid'] = NULL;
31
+	}
28 32
 	return array($ip,$host,$dateR,$dateC['date'],$mid['mid']);
29 33
 }
30 34
 
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
 function summaryBadReport ($uidvet) {
42 46
         $nuid = $uidvet['count'];
43
-        if ( empty($uidvet) ) return NULL;
47
+        if ( empty($uidvet) ) {
48
+        	return NULL;
49
+        }
44 50
         $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n";
45 51
 
46 52
         /* Remove count index */
@@ -75,8 +81,12 @@  discard block
 block discarded – undo
75 81
     foreach ($colarr as $col => $arr) {
76 82
         foreach ($arr as $k => $v) {
77 83
             $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];
84
+            if (!isset($ret[$k])) {
85
+            	$ret[$k] = $array[$k];
86
+            }
87
+            if (isset ($array[$k][$col])) {
88
+            	$ret[$k][$col] = $array[$k][$col];
89
+            }
80 90
         }
81 91
     }
82 92
     return $ret;
@@ -87,14 +97,18 @@  discard block
 block discarded – undo
87 97
 function summaryReportAndList ($cf,$myconn,$tables,$category,$vet,$key) {
88 98
 	$nk = $vet['count'];
89 99
 
90
-	if ( empty($vet) ) return NULL;
100
+	if ( empty($vet) ) {
101
+		return NULL;
102
+	}
91 103
 	
92 104
 	$return = sprintf('<h3>Statistics by %s</h3><table><tr><th>%s</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this %s is currently listed, but it says if this %s has listed now!">Listed Now</th></tr>'."\n", strtoupper($key),strtoupper($key),$key,$key);
93 105
 	
94 106
 	$values = array_keys($vet["$key"]);
95 107
 
96 108
 	foreach ( $values as $value ) {
97
-		if ( $value == 'count' ) continue;
109
+		if ( $value == 'count' ) {
110
+			continue;
111
+		}
98 112
                 $nlearn = $vet["$key"]["$value"]['count'];
99 113
                 unset($vet["$key"]["$value"]['count']);
100 114
 		$quantity = $cf["listing$key"]['quantity']["$category"]; /* In searchAndList this value is
@@ -106,10 +120,12 @@  discard block
 block discarded – undo
106 120
 				'The %s <%s> has been listed because was marked %u times as %s by %u different accounts during last %u days.',
107 121
 				strtoupper($key),$value,$nlearn,$category,$nuid,$cf['imap']['oldestday']);
108 122
 				$listed = searchAndList ($myconn,$cf['syslog']['user'],$tables,$cf["listing$key"]['list']["$category"],$value,$cf["listing$key"]['unit']["$category"],$quantity,$reason);
123
+			} else {
124
+				$listed = FALSE;
109 125
 			}
110
-			else $listed = FALSE;
126
+		} else {
127
+			$listed = FALSE;
111 128
 		}
112
-		else $listed = FALSE;
113 129
 		$nowlist = array( TRUE =>  array(
114 130
 					'style' => 'id=\'ipfound\'',
115 131
 					'name'  => 'YES',
@@ -127,7 +143,9 @@  discard block
 block discarded – undo
127 143
 		$return .='<tr><td rowspan="'.$nuid.'">'.$value.'</td>';
128 144
 		$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 145
 		$rowuid=NULL;
130
-                for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>';
146
+                for ($j=1;$j<$nuid;$j++) {
147
+                	$rowuid .= '<tr><td>%s</td></tr>';
148
+                }
131 149
 		array_shift($vet["$key"]["$value"]);
132 150
                 $return .= vsprintf ($rowuid,$vet["$key"]["$value"]);
133 151
 
@@ -140,14 +158,18 @@  discard block
 block discarded – undo
140 158
 	$return .= sprintf('<h3>Statistics by UID</h3><table><tr><th>UID</th><th>%s learned</th><th>Learned times</th></tr>'."\n",$key);
141 159
 	$uids = array_keys($vet['uid']);
142 160
         foreach ( $uids as $uid ) {
143
-		if ( $uid == 'count' ) continue;	
161
+		if ( $uid == 'count' ) {
162
+			continue;
163
+		}
144 164
 	        $nlearn = $vet['uid']["$uid"]['count'];
145 165
 	        unset ( $vet['uid']["$uid"]['count'] );
146 166
 		$nip = count($vet['uid']["$uid"]);
147 167
 		$return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>';
148 168
 		$return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$vet['uid']["$uid"][0],$nlearn);
149 169
                 $rowuid=NULL;
150
-                for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>';
170
+                for ($j=1;$j<$nip;$j++) {
171
+                	$rowuid .= '<tr><td>%s</td></tr>';
172
+                }
151 173
                 array_shift($vet['uid']["$uid"]);
152 174
                 $return .= vsprintf ($rowuid,$vet['uid']["$uid"]);
153 175
 
@@ -197,14 +219,14 @@  discard block
 block discarded – undo
197 219
 	    {
198 220
 	      // More than one field attribute returned by search
199 221
 	      // You must redefine the search
200
-	      if ( count($result->getFieldNames()) > 1 ) return FALSE;
201
-	    }
202
-	    else if ($result instanceof Splunk_ResultsMessage)
222
+	      if ( count($result->getFieldNames()) > 1 ) {
223
+	      	return FALSE;
224
+	      }
225
+	    } else if ($result instanceof Splunk_ResultsMessage)
203 226
 	    {
204 227
 	      // I don't want messages in my search
205 228
 	      return FALSE;
206
-	    }
207
-	    else if (is_array($result))
229
+	    } else if (is_array($result))
208 230
 	    {
209 231
 	      // Process a row
210 232
 	      foreach ($result as $key => $valueOrValues)
@@ -212,15 +234,13 @@  discard block
 block discarded – undo
212 234
 	         if (is_array($valueOrValues))
213 235
 	          {
214 236
 	            return FALSE;
215
-	          }
216
-	         else
237
+	          } else
217 238
 	          {
218 239
 	            return $valueOrValues;
219 240
 	            #print "  {$key} => {$value}\r\n";
220 241
 	          }
221 242
 	        }
222
-	    }
223
-	    else
243
+	    } else
224 244
 	    {
225 245
 	      #print "Unknow result type";
226 246
 	      return FALSE;
@@ -240,11 +260,9 @@  discard block
 block discarded – undo
240 260
                 if(isset($part->parts)) {
241 261
                         if($part->type == 2) {
242 262
                                 $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false);
243
-                        }
244
-                        elseif($fullPrefix) {
263
+                        } elseif($fullPrefix) {
245 264
                                 $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.');
246
-                        }
247
-                        else {
265
+                        } else {
248 266
                                 $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix);
249 267
                         }
250 268
                         unset($flattenedParts[$prefix.$index]->parts);
@@ -281,8 +299,9 @@  discard block
 block discarded – undo
281 299
 	if ( ($num_found !== FALSE) && ($num_found>0) ) {
282 300
 		foreach ($out[0] as $url) {
283 301
 			$dom=parse_url($url, PHP_URL_HOST);
284
-			if (!( empty($dom) || in_array($dom,$exclude) ))
285
-				$ret[] = $dom;
302
+			if (!( empty($dom) || in_array($dom,$exclude) )) {
303
+							$ret[] = $dom;
304
+			}
286 305
 		}
287 306
 	}
288 307
 	print_r($out[0]);
@@ -321,12 +340,13 @@  discard block
 block discarded – undo
321 340
 			}
322 341
 	
323 342
 		}
343
+	} else {
344
+			$message = getPart($connection, $messageNumber, 1, $structure->encoding);
324 345
 	}
325
-	else
326
-		$message = getPart($connection, $messageNumber, 1, $structure->encoding);
327 346
 
328
-	if ( !empty($message) )
329
-		return getDomains($message, $exclusionList);
347
+	if ( !empty($message) ) {
348
+			return getDomains($message, $exclusionList);
349
+	}
330 350
 	return array();
331 351
 }
332 352
 
@@ -361,7 +381,9 @@  discard block
 block discarded – undo
361 381
 	$fileb= dirname(__FILE__) . '/' . $cf['report']['badreportFile']["$type"];
362 382
 	$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)
363 383
         	or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error());
364
-	if ( !$m_mail ) exit(254);
384
+	if ( !$m_mail ) {
385
+		exit(254);
386
+	}
365 387
 		
366 388
 
367 389
 	syslog (LOG_INFO,$cf['syslog']['user'].': Successfully connected to <'.$cf['imap']['mailhost'].">; Reading $type messages of last ".$cf['imap']['oldestday'].' days...');
@@ -373,21 +395,31 @@  discard block
 block discarded – undo
373 395
 	// Order results starting from newest message
374 396
 	if ( empty($m_search) ) {
375 397
 		syslog (LOG_INFO,$cf['syslog']['user'].": No mail found in $type folder. No reports written for $type.");
376
-	        if ( $ierr = imap_errors() )
377
-	                foreach ( $ierr as $thiserr )
398
+	        if ( $ierr = imap_errors() ) {
399
+	        	                foreach ( $ierr as $thiserr )
378 400
 	                        syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr");
379
-	        if ( $ierr = imap_alerts() )
380
-	                foreach ( $ierr as $thiserr )
401
+	        }
402
+	        if ( $ierr = imap_alerts() ) {
403
+	        	                foreach ( $ierr as $thiserr )
381 404
 	                        syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr");
405
+	        }
382 406
 		imap_close( $m_mail );
383
-		if ( file_exists( $file ) ) unlink ($file);
384
-		if ( file_exists( $filed ) ) unlink ($filed);
385
-		if ( file_exists( $fileb ) ) unlink ($fileb);
407
+		if ( file_exists( $file ) ) {
408
+			unlink ($file);
409
+		}
410
+		if ( file_exists( $filed ) ) {
411
+			unlink ($filed);
412
+		}
413
+		if ( file_exists( $fileb ) ) {
414
+			unlink ($fileb);
415
+		}
386 416
 		return FALSE;
387 417
 	}
388 418
 	$nmes = count ($m_search);
389 419
 	syslog (LOG_INFO,$cf['syslog']['user'].": Found $nmes mail in $type folder.");
390
-	if ($nmes>0) rsort($m_search);
420
+	if ($nmes>0) {
421
+		rsort($m_search);
422
+	}
391 423
 
392 424
 	// Create report file
393 425
 
@@ -451,10 +483,11 @@  discard block
 block discarded – undo
451 483
 
452 484
 	                if (in_array($uid,array_keys($ipuid['uid']))) {
453 485
 				$ipuid['uid']["$uid"]['count']++;		//number of learn by this uid
454
-				if (!in_array($ip,$ipuid['uid']["$uid"])) 
455
-					$ipuid['uid']["$uid"][]=$ip;		//ips learned by this uid
456
-			}
457
-			else {
486
+				if (!in_array($ip,$ipuid['uid']["$uid"])) {
487
+									$ipuid['uid']["$uid"][]=$ip;
488
+				}
489
+				//ips learned by this uid
490
+			} else {
458 491
 				$ipuid['uid']["$uid"]['count'] = 1;
459 492
 				$ipuid['uid']["$uid"][]=$ip;
460 493
 				$ipuid['uid']['count']++;                	//number of unique uids
@@ -462,10 +495,11 @@  discard block
 block discarded – undo
462 495
 
463 496
                         if (in_array($ip,array_keys($ipuid['ip']))) {
464 497
                                 $ipuid['ip']["$ip"]['count']++;			//number of time this ip appears in different messages
465
-				if (!in_array($uid,$ipuid['ip']["$ip"]))
466
-					$ipuid['ip']["$ip"][]=$uid;		//uids that learned this ip
467
-			}
468
-                        else {
498
+				if (!in_array($uid,$ipuid['ip']["$ip"])) {
499
+									$ipuid['ip']["$ip"][]=$uid;
500
+				}
501
+				//uids that learned this ip
502
+			} else {
469 503
                                 $ipuid['ip']["$ip"]['count'] = 1;
470 504
 				$ipuid['ip']["$ip"][]=$uid;
471 505
 				$ipuid['ip']['count']++;			//number of unique ips
@@ -475,10 +509,11 @@  discard block
 block discarded – undo
475 509
 				$domuid['count']++;
476 510
 				if (in_array($uid,array_keys($domuid['uid']))) {
477 511
 					$domuid['uid']["$uid"]['count']++;               //number of learn by this uid
478
-					if (!in_array($dom,$domuid['uid']["$uid"]))
479
-						$domuid['uid']["$uid"][]=$dom;		//domains learned by this uid
480
-				}
481
-				else {
512
+					if (!in_array($dom,$domuid['uid']["$uid"])) {
513
+											$domuid['uid']["$uid"][]=$dom;
514
+					}
515
+					//domains learned by this uid
516
+				} else {
482 517
 					$domuid['uid']["$uid"]['count'] = 1;
483 518
 					$domuid['uid']["$uid"][]=$dom;
484 519
 					$domuid['uid']['count']++;			//number of unique uids
@@ -486,10 +521,11 @@  discard block
 block discarded – undo
486 521
 
487 522
 				if (in_array($dom,array_keys($domuid['dom']))) {
488 523
 					$domuid['dom']["$dom"]['count']++;	//number of learn with this domain
489
-					if (!in_array($uid,$domuid['dom']["$dom"]))
490
-						$domuid['dom']["$dom"][]=$uid;	//uids that learned this domain
491
-				}
492
-				else {
524
+					if (!in_array($uid,$domuid['dom']["$dom"])) {
525
+											$domuid['dom']["$dom"][]=$uid;
526
+					}
527
+					//uids that learned this domain
528
+				} else {
493 529
 					$domuid['dom']["$dom"]['count'] = 1;
494 530
 					$domuid['dom']["$dom"][]=$uid;
495 531
 					$domuid['dom']['count']++;		//number of unique domains
@@ -506,21 +542,30 @@  discard block
 block discarded – undo
506 542
 
507 543
 	        	/* Update HTML report */
508 544
 	        	fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) );
509
-		}
510
-	        else {	/* Bad learn */
545
+		} else {	/* Bad learn */
511 546
 			
512
-                        if (in_array($uid,array_keys($uidbad['uid']))) 
513
-                                $uidbad['uid']["$uid"]['count']++;               //number of bad learn by this uid
547
+                        if (in_array($uid,array_keys($uidbad['uid']))) {
548
+                                                        $uidbad['uid']["$uid"]['count']++;
549
+                        }
550
+                        //number of bad learn by this uid
514 551
                         else {
515 552
                                 $uidbad['uid']["$uid"]['count'] = 1;
516 553
 				$uidbad['uid']["$uid"][]=$uid;
517 554
                                 $uidbad['count']++;                       //numeber of unique bad uids
518 555
                         }
519 556
 			/* The reason of bad report */
520
-			if ($host === FALSE) $reason = 'This mail was not received by recognized MX host';
521
-			if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn';
522
-			if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log';
523
-			if (!isset($reason)) $reason = '?';
557
+			if ($host === FALSE) {
558
+				$reason = 'This mail was not received by recognized MX host';
559
+			}
560
+			if ($dateReceived === FALSE) {
561
+				$reason = 'This mail was not submitted to recognized MSA for learn';
562
+			}
563
+			if ($uid=='unknown') {
564
+				$reason = 'The uid of this mail was not found in splunk log';
565
+			}
566
+			if (!isset($reason)) {
567
+				$reason = '?';
568
+			}
524 569
 				
525 570
 			fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) );
526 571
 		}
@@ -542,9 +587,9 @@  discard block
 block discarded – undo
542 587
 	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>' );
543 588
 
544 589
         /* Make MYSQL connection */
545
-	if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] )
546
-		$mysqli = NULL;
547
-	else {
590
+	if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] ) {
591
+			$mysqli = NULL;
592
+	} else {
548 593
         	$mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']);
549 594
         	if ($mysqli->connect_error) {
550 595
                 	syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') '
@@ -563,8 +608,9 @@  discard block
 block discarded – undo
563 608
 	fwrite($fpd,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateFooter']));
564 609
 	fclose($fpd);
565 610
 	
566
-	if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) )
567
-		$mysqli->close();
611
+	if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) ) {
612
+			$mysqli->close();
613
+	}
568 614
 
569 615
 	fwrite($fpb, '</table>');
570 616
 	fwrite( $fpb,summaryBadReport( $uidbad ) );
@@ -572,12 +618,14 @@  discard block
 block discarded – undo
572 618
 	fclose($fpb);
573 619
 	syslog (LOG_INFO,$cf['syslog']['user'].': Report files written. Listing job for '.$type.' terminated.');
574 620
 
575
-	if ( $ierr = imap_errors() )
576
-		foreach ( $ierr as $thiserr )
621
+	if ( $ierr = imap_errors() ) {
622
+			foreach ( $ierr as $thiserr )
577 623
 			syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr");
578
-	if ( $ierr = imap_alerts() )
579
-                foreach ( $ierr as $thiserr )
624
+	}
625
+	if ( $ierr = imap_alerts() ) {
626
+	                foreach ( $ierr as $thiserr )
580 627
                         syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr");
628
+	}
581 629
 	imap_close($m_mail);
582 630
 }
583 631
 ?>
Please login to merge, or discard this patch.