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 ( f156e7...9e397c )
by Marco
02:06
created
contrib/ipImap/function.php 4 patches
Doc Comments   +34 added lines patch added patch discarded remove patch
@@ -1,4 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) );
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function getIP($header,$mxserver,$msa) {
2
+function getIP($header, $mxserver, $msa) {
3 3
 /* Get submission server's IP from header's mail */
4 4
 /* Each line must end with /r/n			 */
5 5
 /* IP is the first one written by your mxserver	 */
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
 	$ip = FALSE;
8 8
 	$host = FALSE;
9 9
 	$dateR = FALSE;
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
-		for ($i = count($received[0])-1;$i>=0;$i--) {
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
+		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]) )
13
+			if (preg_match($msa, $received['host'][$i]))
14 14
 				$dateR = $received['date'][$i];
15 15
         		foreach ($mxserver as $mx) {
16 16
         			if (!$ip)
@@ -21,38 +21,38 @@  discard block
 block discarded – undo
21 21
                 	}
22 22
         	}
23 23
 	}
24
-	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1)
24
+	if (preg_match('/\r\nDate:\s(?P<date>.*)\r\n/', $header, $dateC) != 1)
25 25
 		$dateC['date'] = 'Not found';
26
-	if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1)
26
+	if (preg_match('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/', $header, $mid) != 1)
27 27
 		$mid['mid'] = NULL;
28
-	return array($ip,$host,$dateR,$dateC['date'],$mid['mid']);
28
+	return array($ip, $host, $dateR, $dateC['date'], $mid['mid']);
29 29
 }
30 30
 
31
-function updateReport ($ip,$uid,$ipcount,$uidcount,$hostname,$dateC,$msgid,$dateL) {
31
+function updateReport($ip, $uid, $ipcount, $uidcount, $hostname, $dateC, $msgid, $dateL) {
32 32
 
33
-	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) );
33
+	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 34
 }
35 35
 
36
-function updatebadReport ( $uid,$dateC,$msgid,$dateL,$text ) {
37
-	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 );
36
+function updatebadReport($uid, $dateC, $msgid, $dateL, $text) {
37
+	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 38
 }
39 39
 
40 40
 
41
-function summaryBadReport ($uidvet) {
41
+function summaryBadReport($uidvet) {
42 42
         $nuid = $uidvet['count'];
43
-        if ( empty($uidvet) ) return NULL;
43
+        if (empty($uidvet)) return NULL;
44 44
         $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n";
45 45
 
46 46
         /* Remove count index */
47 47
         $uids = array_keys($uidvet['uid']);
48 48
 	$totlearn = 0;
49 49
 
50
-        foreach ( $uids as $uid ) {
51
-		$totlearn += $uidvet['uid']["$uid"]['count'];; 
52
-		$return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']);
50
+        foreach ($uids as $uid) {
51
+		$totlearn += $uidvet['uid']["$uid"]['count']; ; 
52
+		$return .= sprintf('<tr><td>%s</td><td>%u</td></tr>', $uid, $uidvet['uid']["$uid"]['count']);
53 53
 	}
54
-	$return .= sprintf ('<tr><th>%s</th><th>%u</th></tr></table>','TOT',$totlearn);
55
-	$return .= sprintf ('<p>%s : %u</p>','Unique UID',$nuid);
54
+	$return .= sprintf('<tr><th>%s</th><th>%u</th></tr></table>', 'TOT', $totlearn);
55
+	$return .= sprintf('<p>%s : %u</p>', 'Unique UID', $nuid);
56 56
 
57 57
 	return $return;
58 58
 }
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
     foreach ($cols as $col => $order) {
70 70
         $eval .= '$colarr[\''.$col.'\'],'.$order.',';
71 71
     }
72
-    $eval = substr($eval,0,-1).');';
72
+    $eval = substr($eval, 0, -1).');';
73 73
     eval($eval);
74 74
     $ret = array();
75 75
     foreach ($colarr as $col => $arr) {
76 76
         foreach ($arr as $k => $v) {
77
-            $k = substr($k,1);
77
+            $k = substr($k, 1);
78 78
             if (!isset($ret[$k])) $ret[$k] = $array[$k];
79 79
             if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col];
80 80
         }
@@ -84,33 +84,33 @@  discard block
 block discarded – undo
84 84
 }
85 85
 
86 86
 
87
-function summaryReportAndList ($cf,$myconn,$tables,$category,$vet,$key) {
87
+function summaryReportAndList($cf, $myconn, $tables, $category, $vet, $key) {
88 88
 	$nk = $vet['count'];
89 89
 
90
-	if ( empty($vet) ) return NULL;
90
+	if (empty($vet)) return NULL;
91 91
 	
92
-	$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);
92
+	$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 93
 	
94 94
 	$values = array_keys($vet["$key"]);
95 95
 
96
-	foreach ( $values as $value ) {
97
-		if ( $value == 'count' ) continue;
96
+	foreach ($values as $value) {
97
+		if ($value == 'count') continue;
98 98
                 $nlearn = $vet["$key"]["$value"]['count'];
99 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"]);
103
-		if ( !$cf["listing$key"]['onlyReport']["$category"] ) {
104
-			if ( ($nlearn >= $cf["listing$key"]['threshold']["$category"])&&($nuid >= $cf["listing$key"]['thresholduid']["$category"]) ) {
103
+		if (!$cf["listing$key"]['onlyReport']["$category"]) {
104
+			if (($nlearn>=$cf["listing$key"]['threshold']["$category"]) && ($nuid>=$cf["listing$key"]['thresholduid']["$category"])) {
105 105
 				$reason = sprintf(
106 106
 				'The %s <%s> has been listed because was marked %u times as %s by %u different accounts during last %u days.',
107
-				strtoupper($key),$value,$nlearn,$category,$nuid,$cf['imap']['oldestday']);
108
-				$listed = searchAndList ($myconn,$cf['syslog']['user'],$tables,$cf["listing$key"]['list']["$category"],$value,$cf["listing$key"]['unit']["$category"],$quantity,$reason);
107
+				strtoupper($key), $value, $nlearn, $category, $nuid, $cf['imap']['oldestday']);
108
+				$listed = searchAndList($myconn, $cf['syslog']['user'], $tables, $cf["listing$key"]['list']["$category"], $value, $cf["listing$key"]['unit']["$category"], $quantity, $reason);
109 109
 			}
110 110
 			else $listed = FALSE;
111 111
 		}
112 112
 		else $listed = FALSE;
113
-		$nowlist = array( TRUE =>  array(
113
+		$nowlist = array(TRUE =>  array(
114 114
 					'style' => 'id=\'ipfound\'',
115 115
 					'name'  => 'YES',
116 116
 				  ),
@@ -124,46 +124,46 @@  discard block
 block discarded – undo
124 124
 				  )
125 125
 		);
126 126
 		
127
-		$return .='<tr><td rowspan="'.$nuid.'">'.$value.'</td>';
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
-		$rowuid=NULL;
130
-                for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>';
127
+		$return .= '<tr><td rowspan="'.$nuid.'">'.$value.'</td>';
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
+		$rowuid = NULL;
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
-	$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);
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);
136 136
 
137 137
 
138 138
 	/* Statistics by UID */
139 139
 	/* Not used for listing purpose, but useful to you! */
140
-	$return .= sprintf('<h3>Statistics by UID</h3><table><tr><th>UID</th><th>%s learned</th><th>Learned times</th></tr>'."\n",$key);
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 ) {
143
-		if ( $uid == 'count' ) continue;	
142
+        foreach ($uids as $uid) {
143
+		if ($uid == 'count') continue;	
144 144
 	        $nlearn = $vet['uid']["$uid"]['count'];
145
-	        unset ( $vet['uid']["$uid"]['count'] );
145
+	        unset ($vet['uid']["$uid"]['count']);
146 146
 		$nip = count($vet['uid']["$uid"]);
147
-		$return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>';
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>';
147
+		$return .= '<tr><td rowspan="'.$nip.'">'.$uid.'</td>';
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 151
                 array_shift($vet['uid']["$uid"]);
152
-                $return .= vsprintf ($rowuid,$vet['uid']["$uid"]);
152
+                $return .= vsprintf($rowuid, $vet['uid']["$uid"]);
153 153
 
154 154
         }
155
-        $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique %s">%u</th><th>%u</th></table>',
156
-			$vet['uid']['count'],$key,$vet["$key"]['count'],$nk);
155
+        $return .= sprintf('<tr><th title="unique uids">%u</th><th title="unique %s">%u</th><th>%u</th></table>',
156
+			$vet['uid']['count'], $key, $vet["$key"]['count'], $nk);
157 157
 
158 158
 
159 159
 	return $return;
160 160
 }
161 161
 
162 162
 
163
-function splunksearch ($service,$message_id,$date) {
163
+function splunksearch($service, $message_id, $date) {
164 164
 
165 165
 	// Run a blocking search
166
-	$searchQueryBlocking = 'search (message_id="'. addslashes( $message_id ) .
166
+	$searchQueryBlocking = 'search (message_id="'.addslashes($message_id).
167 167
 				'" OR sasl_username) | transaction message_id queue_id maxspan=3m maxpause=2m | search sasl_username message_id=* | table sasl_username';
168 168
 
169 169
 	/* Doesn't work on Splunk 6.6 for HTTP exceptions
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
 
183 183
 	// A one shot search
184 184
         $searchParams = array(
185
-                'earliest_time' => date("c",strtotime ($date)-120),
186
-                'latest_time' => date("c",strtotime ($date)+60)
185
+                'earliest_time' => date("c", strtotime($date)-120),
186
+                'latest_time' => date("c", strtotime($date)+60)
187 187
         );
188 188
 
189 189
         // Run a oneshot search that returns the job's results
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	    {
198 198
 	      // More than one field attribute returned by search
199 199
 	      // You must redefine the search
200
-	      if ( count($result->getFieldNames()) > 1 ) return FALSE;
200
+	      if (count($result->getFieldNames())>1) return FALSE;
201 201
 	    }
202 202
 	    else if ($result instanceof Splunk_ResultsMessage)
203 203
 	    {
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 
236 236
 function flattenParts($messageParts, $flattenedParts = array(), $prefix = '', $index = 1, $fullPrefix = true) {
237 237
 
238
-        foreach($messageParts as $part) {
238
+        foreach ($messageParts as $part) {
239 239
                 $flattenedParts[$prefix.$index] = $part;
240
-                if(isset($part->parts)) {
241
-                        if($part->type == 2) {
240
+                if (isset($part->parts)) {
241
+                        if ($part->type == 2) {
242 242
                                 $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false);
243 243
                         }
244
-                        elseif($fullPrefix) {
244
+                        elseif ($fullPrefix) {
245 245
                                 $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.');
246 246
                         }
247 247
                         else {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 function getPart($connection, $messageNumber, $partNumber, $encoding) {
260 260
 
261 261
         $data = imap_fetchbody($connection, $messageNumber, $partNumber);
262
-        switch($encoding) {
262
+        switch ($encoding) {
263 263
                 case 0: return $data; // 7BIT
264 264
                 case 1: return $data; // 8BIT
265 265
                 case 2: return $data; // BINARY
@@ -272,25 +272,25 @@  discard block
 block discarded – undo
272 272
 }
273 273
 /***********************************/
274 274
 
275
-function getDomains ($text) {
275
+function getDomains($text) {
276 276
 	$pattern = '~[a-z]+://\S+~';
277 277
 	$ret = array();
278 278
 	$num_found = preg_match_all($pattern, $text, $out);
279
-	if ( ($num_found !== FALSE) && ($num_found>0) ) {
279
+	if (($num_found !== FALSE) && ($num_found>0)) {
280 280
 		foreach ($out[0] as $url)
281 281
 			$ret[] = parse_url($url, PHP_URL_HOST);
282 282
 	}
283 283
 	return array_values(array_unique($ret));
284 284
 }
285 285
 
286
-function parseURL ($connection,$messageNumber) {
286
+function parseURL($connection, $messageNumber) {
287 287
 	$message = '';
288 288
 	$structure = imap_fetchstructure($connection, $messageNumber);
289 289
 	if (isset($structure->parts)) {
290 290
 		$flattenedParts = flattenParts($structure->parts);
291
-		foreach($flattenedParts as $partNumber => $part) {
291
+		foreach ($flattenedParts as $partNumber => $part) {
292 292
 
293
-			switch($part->type) {
293
+			switch ($part->type) {
294 294
 		
295 295
 				case 0:
296 296
 					// the HTML or plain text part of the email
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
 	else
320 320
 		$message = getPart($connection, $messageNumber, 1, $structure->encoding);
321 321
 
322
-	if ( !empty($message) )
322
+	if (!empty($message))
323 323
 		return getDomains($message);
324 324
 	return array();
325 325
 }
326 326
 
327 327
 function humanKey($key) {
328
-	switch($key) {
328
+	switch ($key) {
329 329
 		case 'ip':
330 330
 			return 'ips';
331 331
 		case 'dom':
@@ -334,67 +334,67 @@  discard block
 block discarded – undo
334 334
 	return $key;
335 335
 }
336 336
 
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) );
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 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
-		strtoupper(humanKey($key))) );
341
+                fwrite($f, sprintf('<p>None of the below %s have been listed because listing is not active in configuration.</p>',
342
+		strtoupper(humanKey($key))));
343 343
 		syslog(LOG_INFO, sprintf('%s: Report only for %s %s: no listing activated in configuration.',
344
-			$conf['syslog']['user'],$type,humanKey($key))
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>',
348
-	strtoupper($key),strtoupper($key),strtoupper($key)) );
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
+	strtoupper($key), strtoupper($key), strtoupper($key)));
349 349
 }
350 350
 
351 351
 
352
-function imapReport ($cf,$myconnArray,$splunkconn,$tables,$type) {
353
-	$file = dirname(__FILE__) . '/' . $cf['report']['reportFile']["$type"];
354
-	$filed = dirname(__FILE__) . '/' . $cf['report']['reportDomFile']["$type"];
355
-	$fileb= dirname(__FILE__) . '/' . $cf['report']['badreportFile']["$type"];
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());
358
-	if ( !$m_mail ) exit(254);
352
+function imapReport($cf, $myconnArray, $splunkconn, $tables, $type) {
353
+	$file = dirname(__FILE__).'/'.$cf['report']['reportFile']["$type"];
354
+	$filed = dirname(__FILE__).'/'.$cf['report']['reportDomFile']["$type"];
355
+	$fileb = dirname(__FILE__).'/'.$cf['report']['badreportFile']["$type"];
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());
358
+	if (!$m_mail) exit(254);
359 359
 		
360 360
 
361
-	syslog (LOG_INFO,$cf['syslog']['user'].': Successfully connected to <'.$cf['imap']['mailhost'].">; Reading $type messages of last ".$cf['imap']['oldestday'].' days...');
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
-	$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\"" );
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\"");
366 366
 
367 367
 	// Order results starting from newest message
368
-	if ( empty($m_search) ) {
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");
376
-		imap_close( $m_mail );
377
-		if ( file_exists( $file ) ) unlink ($file);
378
-		if ( file_exists( $filed ) ) unlink ($filed);
379
-		if ( file_exists( $fileb ) ) unlink ($fileb);
368
+	if (empty($m_search)) {
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");
376
+		imap_close($m_mail);
377
+		if (file_exists($file)) unlink($file);
378
+		if (file_exists($filed)) unlink($filed);
379
+		if (file_exists($fileb)) unlink($fileb);
380 380
 		return FALSE;
381 381
 	}
382
-	$nmes = count ($m_search);
383
-	syslog (LOG_INFO,$cf['syslog']['user'].": Found $nmes mail in $type folder.");
382
+	$nmes = count($m_search);
383
+	syslog(LOG_INFO, $cf['syslog']['user'].": Found $nmes mail in $type folder.");
384 384
 	if ($nmes>0) rsort($m_search);
385 385
 
386 386
 	// Create report file
387 387
 
388 388
 	$fp = fopen($file, 'w');
389
-	$fpd= fopen($filed, 'w');
390
-	$fpb= fopen($fileb, 'w');
391
-	$lastup = "Last Update: " . date ("d F Y H:i", time());
392
-	writeFileHeader($fp,$cf,'ip',$type,$lastup);
393
-	writeFileHeader($fpd,$cf,'dom',$type,$lastup);
389
+	$fpd = fopen($filed, 'w');
390
+	$fpb = fopen($fileb, 'w');
391
+	$lastup = "Last Update: ".date("d F Y H:i", time());
392
+	writeFileHeader($fp, $cf, 'ip', $type, $lastup);
393
+	writeFileHeader($fpd, $cf, 'dom', $type, $lastup);
394 394
 
395
-	fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateHeader']) );
396
-	fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" );
397
-	fwrite( $fpb,'<table><tr><th title="taken from Received header" nowrap>Date Learn</th><th title="taken from Date header" nowrap>Date Received</th><th nowrap>UID</th><th>Message-Id</th><th title="Why is this a bad report?">Reason</th></tr>' );
395
+	fwrite($fpb, file_get_contents(dirname(__FILE__).'/'.$cf['report']['reportTemplateHeader']));
396
+	fwrite($fpb, "<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>");
397
+	fwrite($fpb, '<table><tr><th title="taken from Received header" nowrap>Date Learn</th><th title="taken from Date header" nowrap>Date Received</th><th nowrap>UID</th><th>Message-Id</th><th title="Why is this a bad report?">Reason</th></tr>');
398 398
 
399 399
 	$ipuid = array();
400 400
 	$ipuid['count'] = 0;
@@ -418,105 +418,105 @@  discard block
 block discarded – undo
418 418
 	        //get imap header info for obj thang
419 419
 	        //$headers = imap_headerinfo($m_mail, $onem);
420 420
 	        //$head = imap_fetchheader($m_mail, $headers->Msgno);
421
-		$head = imap_fetchheader($m_mail, $onem );
421
+		$head = imap_fetchheader($m_mail, $onem);
422 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
-			$uid='NA';
427
-			syslog (LOG_ERR, $cf['syslog']['user'].": Error retrieving data for empty Message-ID.");
428
-		} else {
426
+			$uid = 'NA';
427
+			syslog(LOG_ERR, $cf['syslog']['user'].": Error retrieving data for empty Message-ID.");
428
+		}else {
429 429
 			if ($dateReceived === FALSE) {
430
-				$uid='unauthenticated';
431
-				syslog (LOG_ERR, $cf['syslog']['user'].": Error retrieving date for $mid. Maybe this mail was not submitted to Learner MSA");
432
-			} else  
433
-				if ( !($uid = splunksearch ($splunkconn, trim($mid,'<>'), $dateReceived)) ) {
434
-					syslog (LOG_ERR, $cf['syslog']['user'].": Error retrieving uid from Splunk log for $mid.");
435
-					$uid='unknown';
430
+				$uid = 'unauthenticated';
431
+				syslog(LOG_ERR, $cf['syslog']['user'].": Error retrieving date for $mid. Maybe this mail was not submitted to Learner MSA");
432
+			}else  
433
+				if (!($uid = splunksearch($splunkconn, trim($mid, '<>'), $dateReceived))) {
434
+					syslog(LOG_ERR, $cf['syslog']['user'].": Error retrieving uid from Splunk log for $mid.");
435
+					$uid = 'unknown';
436 436
 				}
437 437
 		}
438 438
 
439 439
 		/* Extract domains url in body */
440
-		$domains = parseURL ($m_mail,$onem);
440
+		$domains = parseURL($m_mail, $onem);
441 441
 
442 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
-			$ipuid['count']++;					//number of right messages
443
+	        if ($host and ($uid != 'NA') and ($uid != 'unauthenticated') and ($uid != 'unknown')) { /* IP is received by MX servers  and learned by valid uid */
444
+			$ipuid['count']++; //number of right messages
445 445
 
446
-	                if (in_array($uid,array_keys($ipuid['uid']))) {
447
-				$ipuid['uid']["$uid"]['count']++;		//number of learn by this uid
448
-				if (!in_array($ip,$ipuid['uid']["$uid"])) 
449
-					$ipuid['uid']["$uid"][]=$ip;		//ips learned by this uid
446
+	                if (in_array($uid, array_keys($ipuid['uid']))) {
447
+				$ipuid['uid']["$uid"]['count']++; //number of learn by this uid
448
+				if (!in_array($ip, $ipuid['uid']["$uid"])) 
449
+					$ipuid['uid']["$uid"][] = $ip; //ips learned by this uid
450 450
 			}
451 451
 			else {
452 452
 				$ipuid['uid']["$uid"]['count'] = 1;
453
-				$ipuid['uid']["$uid"][]=$ip;
454
-				$ipuid['uid']['count']++;                	//number of unique uids
453
+				$ipuid['uid']["$uid"][] = $ip;
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
459
-				if (!in_array($uid,$ipuid['ip']["$ip"]))
460
-					$ipuid['ip']["$ip"][]=$uid;		//uids that learned this ip
457
+                        if (in_array($ip, array_keys($ipuid['ip']))) {
458
+                                $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages
459
+				if (!in_array($uid, $ipuid['ip']["$ip"]))
460
+					$ipuid['ip']["$ip"][] = $uid; //uids that learned this ip
461 461
 			}
462 462
                         else {
463 463
                                 $ipuid['ip']["$ip"]['count'] = 1;
464
-				$ipuid['ip']["$ip"][]=$uid;
465
-				$ipuid['ip']['count']++;			//number of unique ips
464
+				$ipuid['ip']["$ip"][] = $uid;
465
+				$ipuid['ip']['count']++; //number of unique ips
466 466
                         }
467 467
 
468 468
 			foreach ($domains as $dom) {
469 469
 				$domuid['count']++;
470
-				if (in_array($uid,array_keys($domuid['uid']))) {
471
-					$domuid['uid']["$uid"]['count']++;               //number of learn by this uid
472
-					if (!in_array($dom,$domuid['uid']["$uid"]))
473
-						$domuid['uid']["$uid"][]=$dom;		//domains learned by this uid
470
+				if (in_array($uid, array_keys($domuid['uid']))) {
471
+					$domuid['uid']["$uid"]['count']++; //number of learn by this uid
472
+					if (!in_array($dom, $domuid['uid']["$uid"]))
473
+						$domuid['uid']["$uid"][] = $dom; //domains learned by this uid
474 474
 				}
475 475
 				else {
476 476
 					$domuid['uid']["$uid"]['count'] = 1;
477
-					$domuid['uid']["$uid"][]=$dom;
478
-					$domuid['uid']['count']++;			//number of unique uids
477
+					$domuid['uid']["$uid"][] = $dom;
478
+					$domuid['uid']['count']++; //number of unique uids
479 479
 				}
480 480
 
481
-				if (in_array($dom,array_keys($domuid['dom']))) {
482
-					$domuid['dom']["$dom"]['count']++;	//number of learn with this domain
483
-					if (!in_array($uid,$domuid['dom']["$dom"]))
484
-						$domuid['dom']["$dom"][]=$uid;	//uids that learned this domain
481
+				if (in_array($dom, array_keys($domuid['dom']))) {
482
+					$domuid['dom']["$dom"]['count']++; //number of learn with this domain
483
+					if (!in_array($uid, $domuid['dom']["$dom"]))
484
+						$domuid['dom']["$dom"][] = $uid; //uids that learned this domain
485 485
 				}
486 486
 				else {
487 487
 					$domuid['dom']["$dom"]['count'] = 1;
488
-					$domuid['dom']["$dom"][]=$uid;
489
-					$domuid['dom']['count']++;		//number of unique domains
488
+					$domuid['dom']["$dom"][] = $uid;
489
+					$domuid['dom']['count']++; //number of unique domains
490 490
 				}
491 491
 
492 492
 				fwrite($fpd,
493
-					updateReport (
494
-						$dom,$uid,$domuid['dom']["$dom"]['count'],
495
-						$domuid['uid']["$uid"]['count'],$host,
496
-						$dateClient,$mid,$dateReceived
493
+					updateReport(
494
+						$dom, $uid, $domuid['dom']["$dom"]['count'],
495
+						$domuid['uid']["$uid"]['count'], $host,
496
+						$dateClient, $mid, $dateReceived
497 497
 					)
498 498
 				);
499 499
 			}
500 500
 
501 501
 	        	/* Update HTML report */
502
-	        	fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) );
502
+	        	fwrite($fp, updateReport($ip, $uid, $ipuid['ip']["$ip"]['count'], $ipuid['uid']["$uid"]['count'], $host, $dateClient, $mid, $dateReceived));
503 503
 		}
504 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
506
+                        if (in_array($uid, array_keys($uidbad['uid']))) 
507
+                                $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid
508 508
                         else {
509 509
                                 $uidbad['uid']["$uid"]['count'] = 1;
510
-				$uidbad['uid']["$uid"][]=$uid;
511
-                                $uidbad['count']++;                       //numeber of unique bad uids
510
+				$uidbad['uid']["$uid"][] = $uid;
511
+                                $uidbad['count']++; //numeber of unique bad uids
512 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';
516
-			if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log';
516
+			if ($uid == 'unknown') $reason = 'The uid of this mail was not found in splunk log';
517 517
 			if (!isset($reason)) $reason = '?';
518 518
 				
519
-			fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) );
519
+			fwrite($fpb, updatebadReport($uid, $dateClient, $mid, $dateReceived, $reason));
520 520
 		}
521 521
 	}
522 522
 
@@ -524,54 +524,54 @@  discard block
 block discarded – undo
524 524
 	//close report file and mailbox
525 525
 
526 526
 	/* Summary Report */
527
-	$ipuid['ip'] = array_msort( $ipuid['ip'], array('count'=>SORT_DESC) );
528
-	$ipuid['uid'] = array_msort( $ipuid['uid'], array('count'=>SORT_DESC) );
529
-	$domuid['dom'] = array_msort( $domuid['dom'], array('count'=>SORT_DESC) );
530
-	$domuid['uid'] = array_msort( $domuid['uid'], array('count'=>SORT_DESC) );
531
-	$uidbad['uid'] = array_msort( $uidbad['uid'], array('count'=>SORT_DESC) );
527
+	$ipuid['ip'] = array_msort($ipuid['ip'], array('count'=>SORT_DESC));
528
+	$ipuid['uid'] = array_msort($ipuid['uid'], array('count'=>SORT_DESC));
529
+	$domuid['dom'] = array_msort($domuid['dom'], array('count'=>SORT_DESC));
530
+	$domuid['uid'] = array_msort($domuid['uid'], array('count'=>SORT_DESC));
531
+	$uidbad['uid'] = array_msort($uidbad['uid'], array('count'=>SORT_DESC));
532 532
 	
533 533
 	fwrite($fp, '</table>');
534 534
 	fwrite($fpd, '</table>');
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
-	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>' );
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
+	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 538
         /* Make MYSQL connection */
539
-	if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] )
539
+	if ($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"])
540 540
 		$mysqli = NULL;
541 541
 	else {
542 542
         	$mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']);
543 543
         	if ($mysqli->connect_error) {
544
-                	syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') '
544
+                	syslog(LOG_EMERG, $cf['syslog']['user'].': Connect Error ('.$mysqli->connect_errno.') '
545 545
                 	. $mysqli->connect_error);
546 546
                 	exit (254);
547 547
         	}
548
-        	syslog(LOG_INFO, $cf['syslog']['user'].': Successfully mysql connected to ' . $mysqli->host_info) ;
548
+        	syslog(LOG_INFO, $cf['syslog']['user'].': Successfully mysql connected to '.$mysqli->host_info);
549 549
 	}
550 550
 	/***********************/
551 551
 
552
-	fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid, 'ip') );
553
-	fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateFooter']));
552
+	fwrite($fp, summaryReportAndList($cf, $mysqli, $tables, $type, $ipuid, 'ip'));
553
+	fwrite($fp, file_get_contents(dirname(__FILE__).'/'.$cf['report']['reportTemplateFooter']));
554 554
 	fclose($fp);
555 555
 
556
-	fwrite($fpd, summaryReportAndList ($cf,$mysqli,$tables,$type,$domuid, 'dom') );
557
-	fwrite($fpd,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateFooter']));
556
+	fwrite($fpd, summaryReportAndList($cf, $mysqli, $tables, $type, $domuid, 'dom'));
557
+	fwrite($fpd, file_get_contents(dirname(__FILE__).'/'.$cf['report']['reportTemplateFooter']));
558 558
 	fclose($fpd);
559 559
 	
560
-	if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) )
560
+	if (!($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]))
561 561
 		$mysqli->close();
562 562
 
563 563
 	fwrite($fpb, '</table>');
564
-	fwrite( $fpb,summaryBadReport( $uidbad ) );
565
-	fwrite($fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateFooter']));
564
+	fwrite($fpb, summaryBadReport($uidbad));
565
+	fwrite($fpb, file_get_contents(dirname(__FILE__).'/'.$cf['report']['reportTemplateFooter']));
566 566
 	fclose($fpb);
567
-	syslog (LOG_INFO,$cf['syslog']['user'].': Report files written. Listing job for '.$type.' terminated.');
568
-
569
-	if ( $ierr = imap_errors() )
570
-		foreach ( $ierr as $thiserr )
571
-			syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr");
572
-	if ( $ierr = imap_alerts() )
573
-                foreach ( $ierr as $thiserr )
574
-                        syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr");
567
+	syslog(LOG_INFO, $cf['syslog']['user'].': Report files written. Listing job for '.$type.' terminated.');
568
+
569
+	if ($ierr = imap_errors())
570
+		foreach ($ierr as $thiserr)
571
+			syslog(LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr");
572
+	if ($ierr = imap_alerts())
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
 ?>
Please login to merge, or discard this 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);
@@ -277,8 +295,9 @@  discard block
 block discarded – undo
277 295
 	$ret = array();
278 296
 	$num_found = preg_match_all($pattern, $text, $out);
279 297
 	if ( ($num_found !== FALSE) && ($num_found>0) ) {
280
-		foreach ($out[0] as $url)
281
-			$ret[] = parse_url($url, PHP_URL_HOST);
298
+		foreach ($out[0] as $url) {
299
+					$ret[] = parse_url($url, PHP_URL_HOST);
300
+		}
282 301
 	}
283 302
 	return array_values(array_unique($ret));
284 303
 }
@@ -315,12 +334,13 @@  discard block
 block discarded – undo
315 334
 			}
316 335
 	
317 336
 		}
337
+	} else {
338
+			$message = getPart($connection, $messageNumber, 1, $structure->encoding);
318 339
 	}
319
-	else
320
-		$message = getPart($connection, $messageNumber, 1, $structure->encoding);
321 340
 
322
-	if ( !empty($message) )
323
-		return getDomains($message);
341
+	if ( !empty($message) ) {
342
+			return getDomains($message);
343
+	}
324 344
 	return array();
325 345
 }
326 346
 
@@ -355,7 +375,9 @@  discard block
 block discarded – undo
355 375
 	$fileb= dirname(__FILE__) . '/' . $cf['report']['badreportFile']["$type"];
356 376
 	$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 377
         	or syslog (LOG_EMERG, $cf['syslog']['user'].': Error in IMAP connection to <'.$cf['imap']['mailhost'].'>: ' . imap_last_error());
358
-	if ( !$m_mail ) exit(254);
378
+	if ( !$m_mail ) {
379
+		exit(254);
380
+	}
359 381
 		
360 382
 
361 383
 	syslog (LOG_INFO,$cf['syslog']['user'].': Successfully connected to <'.$cf['imap']['mailhost'].">; Reading $type messages of last ".$cf['imap']['oldestday'].' days...');
@@ -367,21 +389,31 @@  discard block
 block discarded – undo
367 389
 	// Order results starting from newest message
368 390
 	if ( empty($m_search) ) {
369 391
 		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 )
392
+	        if ( $ierr = imap_errors() ) {
393
+	        	                foreach ( $ierr as $thiserr )
372 394
 	                        syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr");
373
-	        if ( $ierr = imap_alerts() )
374
-	                foreach ( $ierr as $thiserr )
395
+	        }
396
+	        if ( $ierr = imap_alerts() ) {
397
+	        	                foreach ( $ierr as $thiserr )
375 398
 	                        syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr");
399
+	        }
376 400
 		imap_close( $m_mail );
377
-		if ( file_exists( $file ) ) unlink ($file);
378
-		if ( file_exists( $filed ) ) unlink ($filed);
379
-		if ( file_exists( $fileb ) ) unlink ($fileb);
401
+		if ( file_exists( $file ) ) {
402
+			unlink ($file);
403
+		}
404
+		if ( file_exists( $filed ) ) {
405
+			unlink ($filed);
406
+		}
407
+		if ( file_exists( $fileb ) ) {
408
+			unlink ($fileb);
409
+		}
380 410
 		return FALSE;
381 411
 	}
382 412
 	$nmes = count ($m_search);
383 413
 	syslog (LOG_INFO,$cf['syslog']['user'].": Found $nmes mail in $type folder.");
384
-	if ($nmes>0) rsort($m_search);
414
+	if ($nmes>0) {
415
+		rsort($m_search);
416
+	}
385 417
 
386 418
 	// Create report file
387 419
 
@@ -445,10 +477,11 @@  discard block
 block discarded – undo
445 477
 
446 478
 	                if (in_array($uid,array_keys($ipuid['uid']))) {
447 479
 				$ipuid['uid']["$uid"]['count']++;		//number of learn by this uid
448
-				if (!in_array($ip,$ipuid['uid']["$uid"])) 
449
-					$ipuid['uid']["$uid"][]=$ip;		//ips learned by this uid
450
-			}
451
-			else {
480
+				if (!in_array($ip,$ipuid['uid']["$uid"])) {
481
+									$ipuid['uid']["$uid"][]=$ip;
482
+				}
483
+				//ips learned by this uid
484
+			} else {
452 485
 				$ipuid['uid']["$uid"]['count'] = 1;
453 486
 				$ipuid['uid']["$uid"][]=$ip;
454 487
 				$ipuid['uid']['count']++;                	//number of unique uids
@@ -456,10 +489,11 @@  discard block
 block discarded – undo
456 489
 
457 490
                         if (in_array($ip,array_keys($ipuid['ip']))) {
458 491
                                 $ipuid['ip']["$ip"]['count']++;			//number of time this ip appears in different messages
459
-				if (!in_array($uid,$ipuid['ip']["$ip"]))
460
-					$ipuid['ip']["$ip"][]=$uid;		//uids that learned this ip
461
-			}
462
-                        else {
492
+				if (!in_array($uid,$ipuid['ip']["$ip"])) {
493
+									$ipuid['ip']["$ip"][]=$uid;
494
+				}
495
+				//uids that learned this ip
496
+			} else {
463 497
                                 $ipuid['ip']["$ip"]['count'] = 1;
464 498
 				$ipuid['ip']["$ip"][]=$uid;
465 499
 				$ipuid['ip']['count']++;			//number of unique ips
@@ -469,10 +503,11 @@  discard block
 block discarded – undo
469 503
 				$domuid['count']++;
470 504
 				if (in_array($uid,array_keys($domuid['uid']))) {
471 505
 					$domuid['uid']["$uid"]['count']++;               //number of learn by this uid
472
-					if (!in_array($dom,$domuid['uid']["$uid"]))
473
-						$domuid['uid']["$uid"][]=$dom;		//domains learned by this uid
474
-				}
475
-				else {
506
+					if (!in_array($dom,$domuid['uid']["$uid"])) {
507
+											$domuid['uid']["$uid"][]=$dom;
508
+					}
509
+					//domains learned by this uid
510
+				} else {
476 511
 					$domuid['uid']["$uid"]['count'] = 1;
477 512
 					$domuid['uid']["$uid"][]=$dom;
478 513
 					$domuid['uid']['count']++;			//number of unique uids
@@ -480,10 +515,11 @@  discard block
 block discarded – undo
480 515
 
481 516
 				if (in_array($dom,array_keys($domuid['dom']))) {
482 517
 					$domuid['dom']["$dom"]['count']++;	//number of learn with this domain
483
-					if (!in_array($uid,$domuid['dom']["$dom"]))
484
-						$domuid['dom']["$dom"][]=$uid;	//uids that learned this domain
485
-				}
486
-				else {
518
+					if (!in_array($uid,$domuid['dom']["$dom"])) {
519
+											$domuid['dom']["$dom"][]=$uid;
520
+					}
521
+					//uids that learned this domain
522
+				} else {
487 523
 					$domuid['dom']["$dom"]['count'] = 1;
488 524
 					$domuid['dom']["$dom"][]=$uid;
489 525
 					$domuid['dom']['count']++;		//number of unique domains
@@ -500,21 +536,30 @@  discard block
 block discarded – undo
500 536
 
501 537
 	        	/* Update HTML report */
502 538
 	        	fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) );
503
-		}
504
-	        else {	/* Bad learn */
539
+		} else {	/* Bad learn */
505 540
 			
506
-                        if (in_array($uid,array_keys($uidbad['uid']))) 
507
-                                $uidbad['uid']["$uid"]['count']++;               //number of bad learn by this uid
541
+                        if (in_array($uid,array_keys($uidbad['uid']))) {
542
+                                                        $uidbad['uid']["$uid"]['count']++;
543
+                        }
544
+                        //number of bad learn by this uid
508 545
                         else {
509 546
                                 $uidbad['uid']["$uid"]['count'] = 1;
510 547
 				$uidbad['uid']["$uid"][]=$uid;
511 548
                                 $uidbad['count']++;                       //numeber of unique bad uids
512 549
                         }
513 550
 			/* The reason of bad report */
514
-			if ($host === FALSE) $reason = 'This mail was not received by recognized MX host';
515
-			if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn';
516
-			if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log';
517
-			if (!isset($reason)) $reason = '?';
551
+			if ($host === FALSE) {
552
+				$reason = 'This mail was not received by recognized MX host';
553
+			}
554
+			if ($dateReceived === FALSE) {
555
+				$reason = 'This mail was not submitted to recognized MSA for learn';
556
+			}
557
+			if ($uid=='unknown') {
558
+				$reason = 'The uid of this mail was not found in splunk log';
559
+			}
560
+			if (!isset($reason)) {
561
+				$reason = '?';
562
+			}
518 563
 				
519 564
 			fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) );
520 565
 		}
@@ -536,9 +581,9 @@  discard block
 block discarded – undo
536 581
 	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 582
 
538 583
         /* Make MYSQL connection */
539
-	if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] )
540
-		$mysqli = NULL;
541
-	else {
584
+	if ( $cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"] ) {
585
+			$mysqli = NULL;
586
+	} else {
542 587
         	$mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']);
543 588
         	if ($mysqli->connect_error) {
544 589
                 	syslog (LOG_EMERG, $cf['syslog']['user'].': Connect Error (' . $mysqli->connect_errno . ') '
@@ -557,8 +602,9 @@  discard block
 block discarded – undo
557 602
 	fwrite($fpd,file_get_contents(dirname(__FILE__) . '/' . $cf['report']['reportTemplateFooter']));
558 603
 	fclose($fpd);
559 604
 	
560
-	if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) )
561
-		$mysqli->close();
605
+	if ( !($cf['listingip']['onlyReport']["$type"] && $cf['listingdom']['onlyReport']["$type"]) ) {
606
+			$mysqli->close();
607
+	}
562 608
 
563 609
 	fwrite($fpb, '</table>');
564 610
 	fwrite( $fpb,summaryBadReport( $uidbad ) );
@@ -566,12 +612,14 @@  discard block
 block discarded – undo
566 612
 	fclose($fpb);
567 613
 	syslog (LOG_INFO,$cf['syslog']['user'].': Report files written. Listing job for '.$type.' terminated.');
568 614
 
569
-	if ( $ierr = imap_errors() )
570
-		foreach ( $ierr as $thiserr )
615
+	if ( $ierr = imap_errors() ) {
616
+			foreach ( $ierr as $thiserr )
571 617
 			syslog (LOG_ERR, $cf['syslog']['user'].": IMAP Error: $thiserr");
572
-	if ( $ierr = imap_alerts() )
573
-                foreach ( $ierr as $thiserr )
618
+	}
619
+	if ( $ierr = imap_alerts() ) {
620
+	                foreach ( $ierr as $thiserr )
574 621
                         syslog (LOG_ALERT, $cf['syslog']['user'].": IMAP Alert: $thiserr");
622
+	}
575 623
 	imap_close($m_mail);
576 624
 }
577 625
 ?>
Please login to merge, or discard this patch.
contrib/ipImap/getip.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 */
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 #!/usr/bin/php
2 2
 <?php
3 3
 /* Config */
4
-$path='/var/www/html/RBL/';
4
+$path = '/var/www/html/RBL/';
5 5
 include_once($path.'config.php');
6 6
 require_once($path.'function.php');
7
-if ( !isset($version) ) {
7
+if (!isset($version)) {
8 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?');
9
+        syslog(LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?');
10 10
         closelog();
11 11
         exit(255);
12 12
 }
13
-include_once(dirname(__FILE__) . '/function.php');
13
+include_once(dirname(__FILE__).'/function.php');
14 14
 $conf = parse_ini_file($confImap_file, TRUE, INI_SCANNER_TYPED);
15 15
 
16 16
 
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 openlog($tag, LOG_PID, $fac);
20 20
 
21 21
 
22
-if ( !$imapListActive ) {
23
-	syslog (LOG_INFO, $conf['syslog']['user'].': This plugin isn\'t active.');
22
+if (!$imapListActive) {
23
+	syslog(LOG_INFO, $conf['syslog']['user'].': This plugin isn\'t active.');
24 24
 	closelog();
25 25
 	exit(255);
26 26
 }
@@ -31,50 +31,50 @@  discard block
 block discarded – undo
31 31
 $arr_tpl_data = array(date("Y-m-d", time()));
32 32
 
33 33
 /* Start of check list */
34
-if ( !$conf['listingip']['onlyReport']['spam'] ) {
34
+if (!$conf['listingip']['onlyReport']['spam']) {
35 35
 
36 36
 	/* check you select a right list */
37
-	if ( !$tables[$conf['listingip']['list']['spam']]['bl'] ) {
37
+	if (!$tables[$conf['listingip']['list']['spam']]['bl']) {
38 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 39
 	       	exit (254);
40 40
 	}
41
-	if ( !$tables[$conf['listingip']['list']['spam']]['active'] ) {
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
-if ( !$conf['listingip']['onlyReport']['ham'] ) {
48
-	if ( $tables[$conf['listingip']['list']['ham']]['bl'] ) {
47
+if (!$conf['listingip']['onlyReport']['ham']) {
48
+	if ($tables[$conf['listingip']['list']['ham']]['bl']) {
49 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 50
 	        exit (254);
51 51
 	}
52
-        if ( !$tables[$conf['listingip']['list']['ham']]['active'] ) {
52
+        if (!$tables[$conf['listingip']['list']['ham']]['active']) {
53 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 55
                 exit (254);
56 56
         }
57 57
 }
58 58
 
59
-if ( !$conf['listingdom']['onlyReport']['spam'] ) {
59
+if (!$conf['listingdom']['onlyReport']['spam']) {
60 60
 
61 61
         /* check you select a right list */
62
-        if ( !$tables[$conf['listingdom']['list']['spam']]['bl'] ) {
62
+        if (!$tables[$conf['listingdom']['list']['spam']]['bl']) {
63 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 64
                 exit (254);
65 65
         }
66
-        if ( !$tables[$conf['listingdom']['list']['spam']]['active'] ) {
66
+        if (!$tables[$conf['listingdom']['list']['spam']]['active']) {
67 67
                 syslog(LOG_EMERG, $conf['syslog']['user'].': <'.$conf['listingdom']['list']['spam'].'> is not active. Please, activate it to continue with this process.');
68 68
                 exit (254);
69 69
         }
70 70
 }
71 71
 
72
-if ( !$conf['listingdom']['onlyReport']['ham'] ) {
73
-        if ( $tables[$conf['listingdom']['list']['ham']]['bl'] ) {
72
+if (!$conf['listingdom']['onlyReport']['ham']) {
73
+        if ($tables[$conf['listingdom']['list']['ham']]['bl']) {
74 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 75
                 exit (254);
76 76
         }
77
-        if ( !$tables[$conf['listingdom']['list']['ham']]['active'] ) {
77
+        if (!$tables[$conf['listingdom']['list']['ham']]['active']) {
78 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 80
                 exit (254);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 /* End of check list */
85 85
 
86 86
 /* Make MYSQL connection Array */
87
-$mysqlconf= array(
87
+$mysqlconf = array(
88 88
 	'dbhost' => $dbhost,
89 89
 	'userdb' => $userdb,
90 90
 	'pwd'	 => $pwd,
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
 
102 102
 
103 103
 /* The hard work has hidden in imapReport */
104
-$learnfromArray = array('ham','spam');
105
-foreach ( $learnfromArray as $learnfrom ) {
104
+$learnfromArray = array('ham', 'spam');
105
+foreach ($learnfromArray as $learnfrom) {
106 106
 	$conf['report']['reportFile']["$learnfrom"] = str_replace($arr_tpl_vars, $arr_tpl_data, $conf['report']['reportFile']["$learnfrom"]);
107 107
 	$conf['report']['badreportFile']["$learnfrom"] = str_replace($arr_tpl_vars, $arr_tpl_data, $conf['report']['badreportFile']["$learnfrom"]);
108 108
 	$conf['report']['reportDomFile']["$learnfrom"] = str_replace($arr_tpl_vars, $arr_tpl_data, $conf['report']['reportDomFile']["$learnfrom"]);
109
-	imapReport ($conf,$mysqlconf,$splservice,$tables,$learnfrom);
109
+	imapReport($conf, $mysqlconf, $splservice, $tables, $learnfrom);
110 110
 }
111 111
 
112
-syslog (LOG_INFO, $conf['syslog']['user'].': End of session.');
112
+syslog(LOG_INFO, $conf['syslog']['user'].': End of session.');
113 113
 closelog();
114 114
 ?>
Please login to merge, or discard this patch.
function.php 2 patches
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -5,46 +5,46 @@  discard block
 block discarded – undo
5 5
 function username() {
6 6
 	if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER'];
7 7
         	else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER'];
8
-                	else $user='unknown';
8
+                	else $user = 'unknown';
9 9
 	return $user;
10 10
 }
11 11
 
12 12
 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' .
15
-			'<pre>' .
16
-			htmlspecialchars('<VirtualHost *:80>' . "\n" .
17
-			'  ServerName %s' . "\n" .
18
-			'  Redirect permanent / https://%s/' . "\n" .
19
-			'</VirtualHost>') .
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'.
15
+			'<pre>'.
16
+			htmlspecialchars('<VirtualHost *:80>'."\n".
17
+			'  ServerName %s'."\n".
18
+			'  Redirect permanent / https://%s/'."\n".
19
+			'</VirtualHost>').
20 20
 			'</pre></div>', gethostname(), gethostname());
21 21
 }
22 22
 
23 23
 function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) {
24
-        $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db;
24
+        $db = ($tablelist["$typedesc"]['milter']) ? $tablelist["$typedesc"]['name'] : $db;
25 25
 	$mysqli = new mysqli($host, $user, $pass, $db, $port);
26 26
         if ($mysqli->connect_error) {
27
-           	syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') '
27
+           	syslog(LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> ('.$mysqli->connect_errno.') '
28 28
                     		. $mysqli->connect_error);
29 29
 		return FALSE;
30 30
 	}
31
-	syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ;
31
+	syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to '.$mysqli->host_info);
32 32
 	return $mysqli;
33 33
 }
34 34
 
35
-function addtolist ($myconn,$user,$value,$tabledesc,$expUnit,$expQ,$myreason,&$err) {
35
+function addtolist($myconn, $user, $value, $tabledesc, $expUnit, $expQ, $myreason, &$err) {
36 36
 // See MySQL manual for $expQ and $expUnit at
37 37
 // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd
38 38
 
39
-	$result=FALSE;
40
-	$sub=array();
39
+	$result = FALSE;
40
+	$sub = array();
41 41
 	$type = $tabledesc['field'];
42 42
 	$milt = $tabledesc['milter'];
43 43
 	$table = ($milt) ? milterTable($type) : $tabledesc['name'];
44 44
 
45 45
 	switch ($type) {
46 46
 	  case 'ip':
47
-		$query= sprintf("INSERT INTO `$table` (
47
+		$query = sprintf("INSERT INTO `$table` (
48 48
 			`$type` ,
49 49
 			`date` ,
50 50
 			`exp` ,
@@ -55,18 +55,18 @@  discard block
 block discarded – undo
55 55
 		VALUES (
56 56
 			INET_ATON( '%s' ) ,
57 57
 			CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
58
-		)" ,$value,$expUnit,$expQ,$user,$myreason);
58
+		)", $value, $expUnit, $expQ, $user, $myreason);
59 59
 		break;
60 60
 
61 61
 	  case 'network':
62 62
 		if (!$milt) {
63
-			if ( netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user) ) {
63
+			if (netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user)) {
64 64
 				$err = "<$value> overlaps the existing network <$overlappedNet>";
65 65
 				return FALSE;
66 66
 			}
67 67
 		}
68
-		list($sub['net'],$sub['mask'])=explode('/',$value);
69
-                $query= sprintf("INSERT INTO `$table` (
68
+		list($sub['net'], $sub['mask']) = explode('/', $value);
69
+                $query = sprintf("INSERT INTO `$table` (
70 70
                         `$type` ,
71 71
 			`netmask`,
72 72
                         `date` ,
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
                 VALUES (
79 79
                         INET_ATON( '%s' ) , INET_ATON( '%s' ) ,
80 80
                         CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
81
-                )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason);
81
+                )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason);
82 82
                 break;
83 83
 
84 84
 	  default:
85
-                $query= sprintf("INSERT INTO `$table` (
85
+                $query = sprintf("INSERT INTO `$table` (
86 86
                         `$type` ,
87 87
                         `date` ,
88 88
                         `exp` ,
@@ -93,23 +93,23 @@  discard block
 block discarded – undo
93 93
                 VALUES (
94 94
                         '%s' ,
95 95
                         CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s'
96
-                )" ,$value,$expUnit,$expQ,$user,$myreason);
96
+                )", $value, $expUnit, $expQ, $user, $myreason);
97 97
 	}
98 98
 
99 99
 	if ($myconn->query($query) === TRUE) {
100 100
 	    syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit.");
101
-	    $result=TRUE;
101
+	    $result = TRUE;
102 102
 	}
103 103
 	else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
104 104
 	return $result;
105 105
 }
106 106
 
107
-function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason, $exptime = 0) {
107
+function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason, $exptime = 0) {
108 108
 
109
-	$result=FALSE;
110
-	if ( $exptime ) { /* Entry already listed */
109
+	$result = FALSE;
110
+	if ($exptime) { /* Entry already listed */
111 111
 		$nlist = '`nlist`';
112
-		$exptime = sprintf('\'%s\'', $exptime);  /* Eh MySQL... an hour lost to notice this */
112
+		$exptime = sprintf('\'%s\'', $exptime); /* Eh MySQL... an hour lost to notice this */
113 113
 	}
114 114
 	else {
115 115
 		$exptime = 'CURRENT_TIMESTAMP';
@@ -118,43 +118,43 @@  discard block
 block discarded – undo
118 118
 
119 119
         switch ($type) {
120 120
 	  case 'ip':
121
-                $query= sprintf("UPDATE `$table` SET
121
+                $query = sprintf("UPDATE `$table` SET
122 122
 			`active` = '1',
123 123
 			`user` = '%s',
124 124
 			`exp` = TIMESTAMPADD(%s,%d,%s),
125 125
 			`nlist` = %s,
126 126
 			`reason` = '%s'
127
-			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value);
127
+			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value);
128 128
 		break;
129 129
           case 'network':
130
-		list($sub['net'],$sub['mask'])=explode('/',$value);
131
-                $query= sprintf("UPDATE `$table` SET
130
+		list($sub['net'], $sub['mask']) = explode('/', $value);
131
+                $query = sprintf("UPDATE `$table` SET
132 132
                         `active` = '1',
133 133
                         `user` = '%s',
134 134
                         `exp` = TIMESTAMPADD(%s,%d,%s),
135 135
                         `nlist` = %s,
136 136
                         `reason` = '%s'
137
-                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$sub['net'],$sub['mask']);
137
+                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $sub['net'], $sub['mask']);
138 138
 		break;
139 139
 	  default:
140
-                $query= sprintf("UPDATE `$table` SET
140
+                $query = sprintf("UPDATE `$table` SET
141 141
                         `active` = '1',
142 142
                         `user` = '%s',
143 143
                         `exp` = TIMESTAMPADD(%s,%d,%s),
144 144
                         `nlist` = %s,
145 145
                         `reason` = '%s'
146
-			WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$exptime,$nlist,$myreason,$value);
146
+			WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $exptime, $nlist, $myreason, $value);
147 147
 	}
148 148
 
149 149
         if ($myconn->query($query) === TRUE) {
150 150
             syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit from $exptime.");
151
-		$result=TRUE;
151
+		$result = TRUE;
152 152
         }
153
-        else syslog (LOG_ERR, "$user: Error: ". $myconn->error);
153
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
154 154
 	return $result;
155 155
 }
156 156
 
157
-function remove ($myconn,$user,$value,$type,$table) {
157
+function remove($myconn, $user, $value, $type, $table) {
158 158
 
159 159
         switch ($type) {
160 160
           case 'ip':
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
                         `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value);
163 163
 		break;
164 164
 	  case 'network':
165
-		list($sub['net'],$sub['mask'])=explode('/',$value);
165
+		list($sub['net'], $sub['mask']) = explode('/', $value);
166 166
 		$query = sprintf("DELETE FROM `$table` WHERE
167 167
 			`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1",
168
-			$sub['net'],$sub['mask']);
168
+			$sub['net'], $sub['mask']);
169 169
 		break;
170 170
 	  default:
171 171
 		$query = sprintf("DELETE FROM `$table` WHERE
@@ -173,39 +173,39 @@  discard block
 block discarded – undo
173 173
 	}
174 174
 
175 175
 
176
-        if ($return=$myconn->query($query) === TRUE) 
176
+        if ($return = $myconn->query($query) === TRUE) 
177 177
             syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>.");
178
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
178
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
179 179
 
180 180
         return $return;
181 181
 }
182 182
 
183 183
 
184
-function changestatus ($myconn,$user,$value,$status,$type,$table) {
184
+function changestatus($myconn, $user, $value, $status, $type, $table) {
185 185
 
186 186
 	switch ($type) {
187 187
           case 'ip':
188
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value);
188
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $value);
189 189
 		break;
190 190
 	  case 'network':
191
-		list($sub['net'],$sub['mask'])=explode('/',$value);
192
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user, $sub['net'],$sub['mask']);
191
+		list($sub['net'], $sub['mask']) = explode('/', $value);
192
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $sub['net'], $sub['mask']);
193 193
 		break;
194 194
 	  default:
195
-		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value);
195
+		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $value);
196 196
 	}
197 197
 
198
-        if ($return=$myconn->query($query) === TRUE) {
198
+        if ($return = $myconn->query($query) === TRUE) {
199 199
             syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>");
200 200
         }
201
-        else syslog(LOG_ERR, "$user: Error: ". $myconn->error);
201
+        else syslog(LOG_ERR, "$user: Error: ".$myconn->error);
202 202
 	return $return;	
203 203
 }
204 204
 
205 205
 
206
-function expire ($myconn,$user,$tables,$expireTime) {
207
-        $return=TRUE;
208
-	$log=array();
206
+function expire($myconn, $user, $tables, $expireTime) {
207
+        $return = TRUE;
208
+	$log = array();
209 209
 	$desc = array_keys($tables);
210 210
 	foreach ($desc as $tdesc) { 
211 211
 		/* QUERY */
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
 			} while ($myconn->next_result());
225 225
 		}
226 226
 		else {
227
-			syslog(LOG_ERR, "Expire job - Error: ". $myconn->error);
227
+			syslog(LOG_ERR, "Expire job - Error: ".$myconn->error);
228 228
 			$return = FALSE;
229 229
 		}
230 230
 	}
231
-	if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
231
+	if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated');
232 232
 	else  syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.');
233 233
         return $return;
234 234
 }
@@ -236,18 +236,18 @@  discard block
 block discarded – undo
236 236
 
237 237
 function isListed($row) {
238 238
 
239
-	$exp=new DateTime($row['exp']);
240
-	$now=new DateTime('NOW');
241
-	if (($exp > $now) and ($row['active'])) return true;
239
+	$exp = new DateTime($row['exp']);
240
+	$now = new DateTime('NOW');
241
+	if (($exp>$now) and ($row['active'])) return true;
242 242
 	else return false;
243 243
 
244 244
 }
245 245
 
246 246
 
247
-function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm)  {
248
-	$milts = readMiltName($myconn,$user);
247
+function askMilter($myconn, $id, $obj, $typedesc, $miltId, $value, $user, $adm) {
248
+	$milts = readMiltName($myconn, $user);
249 249
 	$size = count($milts);
250
-	if (in_array($user,array_keys($adm))) {
250
+	if (in_array($user, array_keys($adm))) {
251 251
 		$button = <<<END
252 252
 		<form style="margin:0; display:inline;" name="Milter$id" enctype="text/plain" method="post" target="_self" action="changeMilter.php" onSubmit="xmlhttpPost('changeMilter.php', 'Milter$id', 'id$id', '<img src=\'/include/pleasewait.gif\'>'); return false;" />
253 253
 		<input name="object" type="hidden" value="$obj" /><input name="oldvalues" type="hidden" value="$value" />
@@ -257,12 +257,12 @@  discard block
 block discarded – undo
257 257
 		<div class="noscroll">
258 258
 		<select class="input_text" name="newvalues[]" multiple size="$size">
259 259
 END;
260
-		$activeMilts = explode(',',$value);
261
-		foreach ( $milts as $milter ) {
262
-			if ( in_array($milter, $activeMilts) )
263
-				$selected= 'selected';
260
+		$activeMilts = explode(',', $value);
261
+		foreach ($milts as $milter) {
262
+			if (in_array($milter, $activeMilts))
263
+				$selected = 'selected';
264 264
 			else
265
-				$selected= NULL;
265
+				$selected = NULL;
266 266
 			$button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter);
267 267
 		}	
268 268
 		$button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>';
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
 }
275 275
 
276 276
 
277
-function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) {
277
+function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) {
278 278
 
279
-	$whynot=NULL;
279
+	$whynot = NULL;
280 280
 	switch ($what) {
281 281
 		case 'Ok':
282 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');
283
+			if (in_array($user, array_keys($adm)))
284
+				if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php');
285 285
 			return htmlspecialchars($whynot);
286 286
 		case 'Listed':
287 287
 		case 'WhiteListed':
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 }
291 291
 
292 292
 
293
-function consistentListing($myconn,$alltables,$typed,$value,&$warn) {
293
+function consistentListing($myconn, $alltables, $typed, $value, &$warn) {
294 294
 /* Check if there are no pending mislisting */
295 295
 	$warn = NULL;
296
-	if (! isset($alltables["$typed"]['depend']) ) return TRUE;
296
+	if (!isset($alltables["$typed"]['depend'])) return TRUE;
297 297
 	foreach ($alltables["$typed"]['depend'] as $listdep) {
298
-		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) {
298
+		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) {
299 299
 			$warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!";
300 300
 			return FALSE;
301 301
 		}
302
-		$entry = searchentry($myconn,$value,$alltables["$listdep"]);
303
-		if ( $entry->num_rows ) {
304
-			if ( $entry->num_rows == 1 ) {
302
+		$entry = searchentry($myconn, $value, $alltables["$listdep"]);
303
+		if ($entry->num_rows) {
304
+			if ($entry->num_rows == 1) {
305 305
 				$riga = $entry->fetch_array(MYSQLI_ASSOC);
306 306
                         	if (isListed($riga)) {
307 307
 					$warn = "<$value> is already present in <$listdep> list!";
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 					return FALSE;
310 310
 				}
311 311
 			}
312
-			if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";}
312
+			if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; }
313 313
 		}
314 314
 		$entry->free();
315 315
 	}
@@ -317,20 +317,20 @@  discard block
 block discarded – undo
317 317
 	return TRUE;
318 318
 }
319 319
 
320
-function searchentry ($myconn,$value,$tablelist) {
320
+function searchentry($myconn, $value, $tablelist) {
321 321
 /* Make a MYSQL query and return result */
322 322
 
323 323
         $type = $tablelist['field'];
324 324
 	
325
-	if ( $tablelist['milter'] ) {
325
+	if ($tablelist['milter']) {
326 326
 		$table = milterTable($type);
327 327
 		if ($value == 'ALL')
328 328
 			$query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt',
329
-				$table,$table);
329
+				$table, $table);
330 330
 		else {
331 331
 			switch ($type) {
332 332
 				case 'network':
333
-					list($sub['net'],$sub['mask'])=explode('/',$value);
333
+					list($sub['net'], $sub['mask']) = explode('/', $value);
334 334
 					$query = sprintf('SELECT * FROM (
335 335
 							SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)
336 336
 				 				WHERE (
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 							 ) AS val WHERE val.ip IS NOT null', $table, $table, $value);
349 349
 					break;
350 350
 				default:
351
-					syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.' );
351
+					syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.');
352 352
 					return FALSE;
353 353
 			}
354 354
 		}
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
 	        else {
361 361
 	                switch ($type) {
362 362
 	                  case 'ip':
363
-	                        $query= "select * from $table where $type =  INET_ATON('$value')";
363
+	                        $query = "select * from $table where $type =  INET_ATON('$value')";
364 364
 	                        break;
365 365
 	                  case 'network':
366
-	                        list($sub['net'],$sub['mask'])=explode('/',$value);
367
-	                        $query= sprintf('select * from `%s`
366
+	                        list($sub['net'], $sub['mask']) = explode('/', $value);
367
+	                        $query = sprintf('select * from `%s`
368 368
 						WHERE (
369 369
 							inet_aton(\'%s\') >= network AND
370 370
 							( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) )
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
 ;
374 374
 	                        break;
375 375
 	                  default:
376
-	                        $query= "select * from $table where $type = '$value'";
376
+	                        $query = "select * from $table where $type = '$value'";
377 377
 	                }
378 378
 	        }
379 379
 	}
380 380
 
381 381
 	$result = $myconn->query($query);
382
-	if($result === false)
382
+	if ($result === false)
383 383
 		syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error);
384 384
         return $result;
385 385
 }
386 386
 
387
-function countListed ($myconn,$table) {
387
+function countListed($myconn, $table) {
388 388
 /* Return number of current listed items into a rbl table */
389 389
 	$query = "SELECT COUNT(*) as `count` FROM `$table` WHERE (`active`=1 AND TIMESTAMPDIFF(MICROSECOND,NOW(),`exp`)>0) GROUP BY `active` ORDER BY `count` DESC LIMIT 1";
390 390
 	$row = $myconn->query($query);
@@ -395,27 +395,27 @@  discard block
 block discarded – undo
395 395
 }
396 396
 
397 397
 
398
-function isFull($myconn,$typedesc,$alltables) {
398
+function isFull($myconn, $typedesc, $alltables) {
399 399
         if (isset($alltables["$typedesc"]['limit'])) {
400
-		if ( $alltables["$typedesc"]['milter'] )
400
+		if ($alltables["$typedesc"]['milter'])
401 401
 			$tab = 'net';
402 402
 		else
403 403
 			$tab = $alltables["$typedesc"]['name'];
404
-                if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) 
404
+                if (countListed($myconn, $tab)>=$alltables["$typedesc"]['limit']) 
405 405
                         return TRUE;
406 406
         }
407 407
 	return FALSE;
408 408
 }
409 409
 
410
-function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) {
410
+function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) {
411 411
 
412 412
 	$type = $tables["$typedesc"]['field'];
413
-	$whynot=NULL;
413
+	$whynot = NULL;
414 414
 
415 415
 	$tabhtm = <<<END
416 416
 	<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 417
 END;
418
-	if ( $tables["$typedesc"]['milter'] )
418
+	if ($tables["$typedesc"]['milter'])
419 419
 		$tabhtm .= '<th title="Milter active for this object">Milters</th>';
420 420
 	$tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n";
421 421
 
@@ -424,24 +424,24 @@  discard block
 block discarded – undo
424 424
 	if (is_null($value))
425 425
 		return FALSE;
426 426
 
427
-	$result = searchentry ($myconn,$value,$tables["$typedesc"]);
427
+	$result = searchentry($myconn, $value, $tables["$typedesc"]);
428 428
 	if ($result) {
429 429
 		printf("<pre>Your request for $type &lt;$value&gt; returned %d items.\n</pre>", $result->num_rows);
430 430
 
431 431
         /* Check for limit in number of listed items */
432
-	$full = isFull($myconn,$typedesc,$tables);
432
+	$full = isFull($myconn, $typedesc, $tables);
433 433
 	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>';
434 434
 
435 435
 		if ($result->num_rows) {
436 436
 			print $tabhtm;
437
-			$i=0;
437
+			$i = 0;
438 438
         		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) {
439 439
 				if (isListed($riga)) {
440
-					if ($tables["$typedesc"]['bl']) $listed='Listed';
441
-					else $listed='WhiteListed';
440
+					if ($tables["$typedesc"]['bl']) $listed = 'Listed';
441
+					else $listed = 'WhiteListed';
442 442
 				}	
443 443
 				else
444
-					$listed='Ok';
444
+					$listed = 'Ok';
445 445
 
446 446
 				switch ($type) {
447 447
 				  case 'ip':
@@ -454,20 +454,20 @@  discard block
 block discarded – undo
454 454
 					$element = $riga["$type"];
455 455
 				}
456 456
 
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",
459
-					$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));
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",
459
+					$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 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",
462
-					$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));
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",
462
+					$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));
463 463
 				$i++;
464 464
         		}
465 465
 			print '</tbody></table>';
466 466
 		}
467 467
 		else {
468 468
 			print "<pre>$type &lt;$value&gt; 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');
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 471
 									else print '<p>'.htmlspecialchars($whynot).'</p>';
472 472
 				
473 473
 		}
@@ -479,12 +479,12 @@  discard block
 block discarded – undo
479 479
 
480 480
 
481 481
         
482
-function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) {
482
+function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) {
483 483
 	$now = time();
484
-        setlocale (LC_TIME, 'it_IT');
485
-        $date = date("r",$now);
486
-	$messageID = md5(uniqid($now,1)) . '@' . gethostname();
487
-	$mua = 'PHP/' . phpversion();
484
+        setlocale(LC_TIME, 'it_IT');
485
+        $date = date("r", $now);
486
+	$messageID = md5(uniqid($now, 1)).'@'.gethostname();
487
+	$mua = 'PHP/'.phpversion();
488 488
 
489 489
 	/* Parsing headers */
490 490
 	if (!file_exists($tplf['header'])) {
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 	}
494 494
 
495 495
 	$head_tmpl = file_get_contents($tplf['header']);
496
-	$arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}');
497
-	$arr_tpl_data = array($from,$to,$date,$messageID,$mua);
496
+	$arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}');
497
+	$arr_tpl_data = array($from, $to, $date, $messageID, $mua);
498 498
 	$headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl);
499
-	$headers = preg_replace( '/\r|\n/', "\r\n", $headers );
499
+	$headers = preg_replace('/\r|\n/', "\r\n", $headers);
500 500
 
501 501
         /* Parsing body */
502 502
 
@@ -506,62 +506,62 @@  discard block
 block discarded – undo
506 506
         }
507 507
 
508 508
         $body_tmpl = file_get_contents($tplf['body']);
509
-        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}');
510
-        $arr_tpl_data = array($emailListed,$intervalToExpire,$detail);
509
+        $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}');
510
+        $arr_tpl_data = array($emailListed, $intervalToExpire, $detail);
511 511
         $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl);
512
-        $body = preg_replace( "/\r|\n/", "\r\n", $body );
513
-	$body = wordwrap ( $body, 75 , "\r\n" );	
512
+        $body = preg_replace("/\r|\n/", "\r\n", $body);
513
+	$body = wordwrap($body, 75, "\r\n");	
514 514
 
515 515
 	/* Send the mail! */
516
-        if ( strlen(ini_get("safe_mode"))< 1) {
516
+        if (strlen(ini_get("safe_mode"))<1) {
517 517
                 $old_mailfrom = ini_get("sendmail_from");
518 518
                 ini_set("sendmail_from", $from);
519 519
                 $params = sprintf("-oi -f %s", '<>');
520
-                if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE;
521
-                else $flag=TRUE;
520
+                if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE;
521
+                else $flag = TRUE;
522 522
                 if (isset($old_mailfrom))
523 523
                         ini_set("sendmail_from", $old_mailfrom);
524 524
         }
525 525
         else {
526
-                if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE;
527
-                else $flag=TRUE;
526
+                if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE;
527
+                else $flag = TRUE;
528 528
         }
529 529
         return $flag;
530 530
 }
531 531
 
532
-function emailToNotify($notify_file,$dom) {
532
+function emailToNotify($notify_file, $dom) {
533 533
 	$ini_array = parse_ini_file($notify_file);
534
-	if (in_array($dom,array_keys($ini_array)))
534
+	if (in_array($dom, array_keys($ini_array)))
535 535
 		return $ini_array["$dom"];
536 536
 	else return FALSE;
537 537
 }
538 538
 
539 539
 
540
-function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,&$reason) {
540
+function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, &$reason) {
541 541
 
542 542
 /* Search and list value */
543 543
         $type = $tables["$typedesc"]['field'];
544 544
         $table = $tables["$typedesc"]['name'];
545
-        $result = searchentry ($myconn,$value,$tables["$typedesc"]);
545
+        $result = searchentry($myconn, $value, $tables["$typedesc"]);
546 546
 
547 547
         /* Manage abnormal conditions */
548 548
         /* Value already present in db more than once. This is absurd. Panic! */
549
-        if ($result->num_rows > 1) {
550
-                syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer.");
549
+        if ($result->num_rows>1) {
550
+                syslog(LOG_EMERG, "$loguser: PANIC! Select for $type '$value' returned ".$result->num_rows." items instead of one. Abnormal. Contact a sysadmin or a developer.");
551 551
                 $result->free();
552 552
                 return FALSE;
553 553
         }
554 554
 
555 555
         /* Value already present in db or not present: to list anyway */
556
-        if ($result->num_rows >= 0) {
556
+        if ($result->num_rows>=0) {
557 557
                 /* First, check for limit in number of listed items */
558
-                if (isFull($myconn,$typedesc,$tables)) {
559
-                        syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
558
+                if (isFull($myconn, $typedesc, $tables)) {
559
+                        syslog(LOG_EMERG, "$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.');
560 560
                         $result->free();
561 561
                         return FALSE;
562 562
                 }
563 563
                 /* Second, check if the (re)list would be consistent now */
564
-                if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) {
564
+                if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) {
565 565
                         syslog(LOG_ERR, $loguser.': '.$whynot);
566 566
                         $result->free();
567 567
                         return FALSE;
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         switch ($result->num_rows) {
576 576
                 /* Relist value if already present */
577 577
                 case 1:
578
-                        if ( isListed($thisentry) ) {
578
+                        if (isListed($thisentry)) {
579 579
 				/* Entry already listed */
580 580
 				$expdate = $thisentry['exp'];
581 581
 				$reason = sprintf('%s. Already listed. Adding 1 DAY to previous expire date.',
@@ -589,33 +589,33 @@  discard block
 block discarded – undo
589 589
 				$expdate = 0; /* This forces expiration from CURRENT_TIMESTAMP */
590 590
 			}
591 591
 			$result->free();
592
-                        return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason, $expdate);
592
+                        return relist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason, $expdate);
593 593
 
594 594
                 /* First time list value */
595 595
                 case 0:
596 596
                         $result->free();
597
-                        return addtolist ($myconn,$loguser,$value,$tables["$typedesc"],$unit,$quantity,$reason,$_);
597
+                        return addtolist($myconn, $loguser, $value, $tables["$typedesc"], $unit, $quantity, $reason, $_);
598 598
         }
599 599
 }
600 600
 
601 601
 
602 602
 /*************** Functions to check if two net overlap each other ********************/
603 603
 
604
-function ipRange ($range) {
604
+function ipRange($range) {
605 605
 /* List IP in range */
606
-	return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) );
606
+	return array_map('long2ip', range(ip2long($range[0]), ip2long($range[1])));
607 607
 }
608 608
 
609 609
 function isIn($netA, $netB) {
610 610
 /* TRUE if an IP of $netA is contained in netB */
611
-	list($addressA,$maskA) = explode('/', $netA);
612
-	list($addressB,$maskB) = explode('/', $netB);
611
+	list($addressA, $maskA) = explode('/', $netA);
612
+	list($addressB, $maskB) = explode('/', $netB);
613 613
 	require_once 'vendor/autoload.php';
614 614
 	$net = new \dautkom\ipv4\IPv4();
615 615
 	$range = $net->address($addressA)->mask($maskA)->getRange();
616 616
 	$ips = ipRange($range);
617
-	foreach ( $ips as $ip )
618
-		if ( $net->address($addressB)->mask($maskB)->has($ip) )
617
+	foreach ($ips as $ip)
618
+		if ($net->address($addressB)->mask($maskB)->has($ip))
619 619
 			return TRUE;
620 620
 	return FALSE;
621 621
 }
@@ -627,11 +627,11 @@  discard block
 block discarded – undo
627 627
 		syslog(LOG_ERR, $loguser.': '.$tabletype['name'].' is not a network list.');
628 628
 		return FALSE;
629 629
 	}
630
-	$result = searchentry ($myconn,'ALL',$tabletype);
630
+	$result = searchentry($myconn, 'ALL', $tabletype);
631 631
         if ($result->num_rows) {
632 632
 		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
633 633
 			$thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']);
634
-			if ( isIn($thisNet, $net) ) {
634
+			if (isIn($thisNet, $net)) {
635 635
 				$result->free();
636 636
 				syslog(LOG_INFO, "$loguser: the net <$net> overlaps the existing network <$thisNet>.");
637 637
 				return TRUE;
@@ -648,8 +648,8 @@  discard block
 block discarded – undo
648 648
 /* For miltermap */
649 649
 function checkMilterConf($table) {
650 650
 	if (isset($table['milter'])) {
651
-        	if ($table['milter'] ===  TRUE) {
652
-			switch ( $table['field'] ) {
651
+        	if ($table['milter'] === TRUE) {
652
+			switch ($table['field']) {
653 653
 				case 'network':
654 654
 				case 'ip':
655 655
 					return TRUE;
@@ -683,12 +683,12 @@  discard block
 block discarded – undo
683 683
 }
684 684
 
685 685
 
686
-function readMiltName($myconn,$loguser) {
687
-	$milters=array();
686
+function readMiltName($myconn, $loguser) {
687
+	$milters = array();
688 688
 	$query = 'SELECT `name` FROM `config`';
689 689
 
690 690
         $result = $myconn->query($query);
691
-        if($result === false) {
691
+        if ($result === false) {
692 692
                 syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error);
693 693
 		return FALSE;
694 694
 	}
@@ -700,27 +700,27 @@  discard block
 block discarded – undo
700 700
 	return $milters;
701 701
 }
702 702
 
703
-function changeMilter ($myconn,$loguser,$miltVal,$table,$miltID) {
703
+function changeMilter($myconn, $loguser, $miltVal, $table, $miltID) {
704 704
 	$query = array();
705
-	foreach ( $miltVal as $value => $action ) {
706
-		switch ( $action ) {
705
+	foreach ($miltVal as $value => $action) {
706
+		switch ($action) {
707 707
 			case 'keep':
708 708
 				break;
709 709
 			case 'add':
710
-				$query[] = sprintf( "INSERT INTO `milt` (
710
+				$query[] = sprintf("INSERT INTO `milt` (
711 711
                 		        	`id` ,
712 712
                         			`name` 
713 713
                 			)
714 714
                 			VALUES (
715 715
                         			%d ,
716 716
 						'%s'
717
-					)",$miltID,$value);
717
+					)",$miltID, $value);
718 718
 				break;
719 719
 			case 'del':
720 720
 				$query[] = "DELETE FROM  `milt` WHERE (`id` = '$miltID' AND `name` = '$value')";
721 721
 		}
722 722
 	}
723
-	if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */
723
+	if (count($query)) /* This "if" is redundant, because if I call this I already checked there is a change */
724 724
 		/* I update datemod because the user couldn't change */
725 725
 		$query[] = sprintf('UPDATE `%s` SET
726 726
 						`user`=\'%s\',
@@ -732,18 +732,18 @@  discard block
 block discarded – undo
732 732
 	$myconn->autocommit(FALSE);
733 733
 	$myconn->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);
734 734
 	$ok = TRUE;
735
-	foreach ( $query as $q ) {
735
+	foreach ($query as $q) {
736 736
 		if ($myconn->query($q) !== TRUE) {
737 737
 			$ok = FALSE;
738 738
 			syslog(LOG_ERR, "$loguser: Error: ".$myconn->error);
739 739
 		}
740 740
 	}
741
-	if ( $ok ) {
742
-		if ( $myconn->commit() )
741
+	if ($ok) {
742
+		if ($myconn->commit())
743 743
 			syslog(LOG_INFO, "$loguser: Milter setting changed successfully.");
744 744
 		else {
745 745
 			syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error.");
746
-			if ( $myconn->rollback() )
746
+			if ($myconn->rollback())
747 747
 				syslog(LOG_INFO, "$loguser: rollback succeeded.");
748 748
 			else
749 749
 				syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!");
@@ -760,15 +760,15 @@  discard block
 block discarded – undo
760 760
 function curl_get($url, array $get = NULL, array $options = array(), $loguser)
761 761
 {
762 762
     $defaults = array(
763
-        CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
763
+        CURLOPT_URL => $url.(strpos($url, '?') === FALSE ? '?' : '').http_build_query($get),
764 764
         CURLOPT_HEADER => 0,
765 765
         CURLOPT_RETURNTRANSFER => TRUE,
766 766
         CURLOPT_TIMEOUT => 4
767 767
     );
768 768
 
769 769
     $ch = curl_init();
770
-    curl_setopt_array($ch, ($options + $defaults));
771
-    if( ! $result = curl_exec($ch))
770
+    curl_setopt_array($ch, ($options+$defaults));
771
+    if (!$result = curl_exec($ch))
772 772
     {
773 773
         syslog(LOG_ERR, sprintf('%s: CURL Error: <%s>', $loguser, curl_error($ch)));
774 774
     }
@@ -780,19 +780,19 @@  discard block
 block discarded – undo
780 780
 function nsdom($dom) {
781 781
 /* Return the first upper domain (or domain itself) with NS record */
782 782
 /* checkdnsrr doesn't work with alias... use dns_get_record */
783
-	if (dns_get_record ( $dom , DNS_NS ))
783
+	if (dns_get_record($dom, DNS_NS))
784 784
 		return rtrim($dom, '.');
785
-	if (dns_get_record ( $dom , DNS_A )) 
786
-		return nsdom( ltrim(strstr($dom, '.'), '.') );
785
+	if (dns_get_record($dom, DNS_A)) 
786
+		return nsdom(ltrim(strstr($dom, '.'), '.'));
787 787
 	return NULL;
788 788
 }
789 789
 
790 790
 function isValid($dom) {
791 791
 /* Return TRUE id domain has NS or A record */
792
-	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' ))
792
+	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 794
 			return TRUE;
795
-		if (checkdnsrr ( $dom , 'A' ))
795
+		if (checkdnsrr($dom, 'A'))
796 796
 			return TRUE;
797 797
 	}
798 798
 	return FALSE;
Please login to merge, or discard this patch.
Braces   +152 added lines, -103 removed lines patch added patch discarded remove patch
@@ -3,22 +3,27 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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')
423
-		$value = nsdom($value);
424
-	if (is_null($value))
425
-		return FALSE;
445
+	if ($type == 'domain') {
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
 block discarded – undo
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
 block discarded – undo
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 &lt;$value&gt; 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
780 825
 function nsdom($dom) {
781 826
 /* Return the first 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 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 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
 }
Please login to merge, or discard this patch.