@@ -55,6 +55,10 @@ |
||
55 | 55 | return $head; |
56 | 56 | } |
57 | 57 | |
58 | +/** |
|
59 | + * @param null|string $prob |
|
60 | + * @param null|string $conf |
|
61 | + */ |
|
58 | 62 | function dspamLevel($prob, $conf) { |
59 | 63 | /* Calculate DSPAM Level as the Spamassassin Plugin */ |
60 | 64 | if (is_null($prob) or is_null($conf)) return '-'; |
@@ -2,13 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | function imapFolder($cf, $username) { |
4 | 4 | $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
5 | - $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
|
6 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
7 | - if ( !$m_mail ) exit(254); |
|
5 | + $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
|
6 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
7 | + if ( !$m_mail ) exit(254); |
|
8 | 8 | |
9 | 9 | |
10 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
11 | - //get all folder |
|
10 | + syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
11 | + //get all folder |
|
12 | 12 | $list = imap_list($m_mail, $open, "*"); |
13 | 13 | imap_close($m_mail); |
14 | 14 | if (is_array($list)) |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | function imapFind ($cf, $username, $folder) { |
23 | 23 | $head=array(); |
24 | 24 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY) |
25 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
25 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
26 | 26 | if ( !$m_mail ) exit(254); |
27 | 27 | |
28 | 28 | |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | // Order results starting from newest message |
36 | 36 | if ( empty($m_search) ) { |
37 | 37 | syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder."); |
38 | - if ( $ierr = imap_errors() ) |
|
39 | - foreach ( $ierr as $thiserr ) |
|
40 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
41 | - if ( $ierr = imap_alerts() ) |
|
42 | - foreach ( $ierr as $thiserr ) |
|
43 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
38 | + if ( $ierr = imap_errors() ) |
|
39 | + foreach ( $ierr as $thiserr ) |
|
40 | + syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
41 | + if ( $ierr = imap_alerts() ) |
|
42 | + foreach ( $ierr as $thiserr ) |
|
43 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
44 | 44 | imap_close( $m_mail ); |
45 | 45 | return FALSE; |
46 | 46 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
49 | 49 | if ($nmes>0) rsort($m_search); |
50 | 50 | |
51 | - // loop for each message |
|
51 | + // loop for each message |
|
52 | 52 | foreach ($m_search as $onem) |
53 | 53 | $head[] = imap_fetchheader($m_mail, $onem ); |
54 | 54 | imap_close($m_mail); |
@@ -66,55 +66,55 @@ discard block |
||
66 | 66 | /* Get relevant Info from header's mail */ |
67 | 67 | /* Each line must end with /r/n */ |
68 | 68 | |
69 | - $dateC = NULL; |
|
69 | + $dateC = NULL; |
|
70 | 70 | $mid = NULL; |
71 | 71 | $result = array( |
72 | - 'date' => NULL, |
|
73 | - 'from' => NULL, |
|
74 | - 'messageid' => NULL, |
|
72 | + 'date' => NULL, |
|
73 | + 'from' => NULL, |
|
74 | + 'messageid' => NULL, |
|
75 | 75 | 'dmarc' => array( |
76 | 76 | 'result' => NULL, |
77 | 77 | 'dom' => NULL |
78 | 78 | ), |
79 | 79 | 'spf' => array( |
80 | - 'result' => NULL, |
|
81 | - 'dom' => NULL |
|
82 | - ), |
|
80 | + 'result' => NULL, |
|
81 | + 'dom' => NULL |
|
82 | + ), |
|
83 | 83 | 'dkim' => array( |
84 | - 'result' => NULL, |
|
85 | - 'dom' => NULL |
|
86 | - ), |
|
87 | - 'spam' => array( |
|
88 | - 'status' => NULL, |
|
89 | - 'score' => NULL, |
|
90 | - 'th' => NULL, |
|
91 | - ), |
|
92 | - 'dspam' => array( |
|
93 | - 'type' => NULL, |
|
94 | - 'level' => NULL, |
|
84 | + 'result' => NULL, |
|
85 | + 'dom' => NULL |
|
86 | + ), |
|
87 | + 'spam' => array( |
|
88 | + 'status' => NULL, |
|
89 | + 'score' => NULL, |
|
90 | + 'th' => NULL, |
|
91 | + ), |
|
92 | + 'dspam' => array( |
|
93 | + 'type' => NULL, |
|
94 | + 'level' => NULL, |
|
95 | 95 | 'learn' => NULL |
96 | - ), |
|
96 | + ), |
|
97 | 97 | 'warn' => NULL |
98 | - ); |
|
98 | + ); |
|
99 | 99 | |
100 | 100 | |
101 | - if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
101 | + if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
102 | 102 | $k=0; |
103 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
104 | - foreach ($ARhosts as $mx) { |
|
103 | + for ($i = count($received[0])-1;$i>=0;$i--) { |
|
104 | + foreach ($ARhosts as $mx) { |
|
105 | 105 | if ($mx == $received['host'][$i]) { |
106 | 106 | /* This is a trusted AR result */ |
107 | 107 | $result['dmarc']['result']=$received['dmarc'][$i]; |
108 | 108 | $result['dmarc']['dom'] = $received['DMARCfrom'][$i]; |
109 | 109 | $k++; |
110 | 110 | } |
111 | - } |
|
111 | + } |
|
112 | + } |
|
112 | 113 | } |
113 | - } |
|
114 | 114 | $received=NULL; |
115 | 115 | if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
116 | 116 | |
117 | - if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m',$header,$received) ) { |
|
117 | + if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m',$header,$received) ) { |
|
118 | 118 | $k=0; |
119 | 119 | for ($i = count($received[0])-1;$i>=0;$i--) { |
120 | 120 | foreach ($ARhosts as $mx) { |
@@ -123,25 +123,25 @@ discard block |
||
123 | 123 | $result['spf']['result']=$received['spf'][$i]; |
124 | 124 | $result['spf']['dom'] = $received['SPFfrom'][$i]; |
125 | 125 | $k++; |
126 | - } |
|
127 | - } |
|
128 | - } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | 129 | } |
130 | 130 | $received=NULL; |
131 | 131 | if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
132 | 132 | |
133 | - if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
|
133 | + if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
|
134 | 134 | $k=0; |
135 | 135 | for ($i = count($received[0])-1;$i>=0;$i--) { |
136 | - foreach ($ARhosts as $mx) { |
|
137 | - if ($mx == $received['host'][$i]) { |
|
138 | - /* This is a trusted AR result */ |
|
139 | - $result['dkim']['result']=$received['dkim'][$i]; |
|
140 | - $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
136 | + foreach ($ARhosts as $mx) { |
|
137 | + if ($mx == $received['host'][$i]) { |
|
138 | + /* This is a trusted AR result */ |
|
139 | + $result['dkim']['result']=$received['dkim'][$i]; |
|
140 | + $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
141 | 141 | $k++; |
142 | - } |
|
143 | - } |
|
144 | - } |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | 145 | } |
146 | 146 | $received=NULL; |
147 | 147 | if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
@@ -149,59 +149,59 @@ discard block |
||
149 | 149 | if ($dpl) { /* Use Spamassassin Plugin */ |
150 | 150 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*DSPAM_(?P<dtype>SPAM|HAM)_(?P<dlevel>\d\d)(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
151 | 151 | $result['spam']['status']=$received['spamstatus'][0]; |
152 | - $result['spam']['score'] = $received['score'][0]; |
|
152 | + $result['spam']['score'] = $received['score'][0]; |
|
153 | 153 | $result['spam']['th'] = $received['th'][0]; |
154 | 154 | $result['dspam']['type'] = $received['dtype'][0]; |
155 | 155 | $result['dspam']['level'] =$received['dlevel'][0]; |
156 | - } |
|
157 | - if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
156 | + } |
|
157 | + if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
158 | 158 | } |
159 | 159 | else { /* Parse apart all DSPAM Header and calculate a level */ |
160 | 160 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
161 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
162 | - $result['spam']['score'] = $received['score'][0]; |
|
163 | - $result['spam']['th'] = $received['th'][0]; |
|
161 | + $result['spam']['status']=$received['spamstatus'][0]; |
|
162 | + $result['spam']['score'] = $received['score'][0]; |
|
163 | + $result['spam']['th'] = $received['th'][0]; |
|
164 | 164 | if (count($received[0])>1) |
165 | 165 | $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
166 | 166 | } |
167 | 167 | if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
168 | - $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
169 | - else |
|
170 | - $result['dspam']['type']=$received['result']; |
|
168 | + $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
169 | + else |
|
170 | + $result['dspam']['type']=$received['result']; |
|
171 | 171 | $prob = NULL; |
172 | 172 | $conf = NULL; |
173 | - if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
174 | - $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
173 | + if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
174 | + $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
175 | 175 | else |
176 | 176 | $prob = $received['prob']; |
177 | 177 | if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
178 | - $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
178 | + $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
179 | 179 | else |
180 | 180 | $conf = $received['conf']; |
181 | 181 | $result['dspam']['level'] = dspamLevel($prob,$conf); |
182 | 182 | } |
183 | 183 | $received=NULL; |
184 | 184 | if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
185 | - $result['warn'][] = 'From header invalid or not present'; |
|
186 | - else |
|
187 | - $result['from'] = $received['from']; |
|
185 | + $result['warn'][] = 'From header invalid or not present'; |
|
186 | + else |
|
187 | + $result['from'] = $received['from']; |
|
188 | 188 | |
189 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
190 | - $result['warn'][] = 'Date header invalid or not present'; |
|
189 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
190 | + $result['warn'][] = 'Date header invalid or not present'; |
|
191 | 191 | else |
192 | 192 | $result['date'] = $received['date']; |
193 | 193 | |
194 | 194 | $received=NULL; |
195 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
196 | - $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
195 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
196 | + $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
197 | 197 | else |
198 | 198 | $result['messageid']=$received['mid']; |
199 | 199 | |
200 | - $received=NULL; |
|
200 | + $received=NULL; |
|
201 | 201 | |
202 | - switch ($learn) { |
|
202 | + switch ($learn) { |
|
203 | 203 | case 'dspamc': |
204 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
204 | + if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
205 | 205 | $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
206 | 206 | else |
207 | 207 | $result['dspam']['learn']=$received['sig']; |
@@ -212,23 +212,23 @@ discard block |
||
212 | 212 | syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
213 | 213 | } |
214 | 214 | |
215 | - return $result; |
|
215 | + return $result; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | 220 | |
221 | 221 | function printTableHeader($title,$content,$footer=FALSE,$fcontent) { |
222 | - print <<<END |
|
222 | + print <<<END |
|
223 | 223 | <caption>$title</caption> |
224 | 224 | <thead> |
225 | 225 | <tr> |
226 | 226 | END; |
227 | 227 | $kcontent = array_keys($content); |
228 | - $cols = count($kcontent); |
|
229 | - for ($i=0; $i<$cols; $i++) { |
|
228 | + $cols = count($kcontent); |
|
229 | + for ($i=0; $i<$cols; $i++) { |
|
230 | 230 | $key = $kcontent[$i]; |
231 | - printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
231 | + printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
232 | 232 | !is_array($content[$key]) ?: |
233 | 233 | count(array_keys($content[$key])) ?: '1', |
234 | 234 | !is_array($content[$key]) ?: |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - print '</tr></thead>'; |
|
248 | - if ($footer) { |
|
249 | - print '<tfoot><tr>'; |
|
250 | - print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
251 | - print '</tr></tfoot>'; |
|
252 | - } |
|
253 | - return TRUE; |
|
247 | + print '</tr></thead>'; |
|
248 | + if ($footer) { |
|
249 | + print '<tfoot><tr>'; |
|
250 | + print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
251 | + print '</tr></tfoot>'; |
|
252 | + } |
|
253 | + return TRUE; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | } |
328 | 328 | /* Spamassassin format */ |
329 | 329 | if (isset($row['status'])) |
330 | - switch($row['status']) { |
|
330 | + switch($row['status']) { |
|
331 | 331 | case 'No': |
332 | 332 | $color = 'rgba(0,255,0, %.1f)'; |
333 | 333 | break; |
@@ -1,56 +1,56 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | function imapFolder($cf, $username) { |
4 | - $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
|
4 | + $open = '{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
|
5 | 5 | $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
6 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
7 | - if ( !$m_mail ) exit(254); |
|
6 | + or syslog(LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: '.imap_last_error()); |
|
7 | + if (!$m_mail) exit(254); |
|
8 | 8 | |
9 | 9 | |
10 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
10 | + syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
11 | 11 | //get all folder |
12 | 12 | $list = imap_list($m_mail, $open, "*"); |
13 | 13 | imap_close($m_mail); |
14 | 14 | if (is_array($list)) |
15 | 15 | foreach ($list as $mbox) |
16 | - $return[] = explode($open,$mbox,2)[1]; |
|
16 | + $return[] = explode($open, $mbox, 2)[1]; |
|
17 | 17 | else |
18 | - syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() ); |
|
18 | + syslog(LOG_INFO, $cf['user'].': imap_list failed: '.imap_last_error()); |
|
19 | 19 | return $return; |
20 | 20 | } |
21 | 21 | |
22 | -function imapFind ($cf, $username, $folder) { |
|
23 | - $head=array(); |
|
24 | - $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY) |
|
25 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
26 | - if ( !$m_mail ) exit(254); |
|
22 | +function imapFind($cf, $username, $folder) { |
|
23 | + $head = array(); |
|
24 | + $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username, $cf['authpassword'], OP_READONLY) |
|
25 | + or syslog(LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: '.imap_last_error()); |
|
26 | + if (!$m_mail) exit(254); |
|
27 | 27 | |
28 | 28 | |
29 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...'); |
|
29 | + syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...'); |
|
30 | 30 | //get all messages |
31 | - $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); |
|
32 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" TEXT \"Authentication-Results: \"" ); |
|
31 | + $dateTh = date("d-M-Y", strToTime('-'.$cf['oldestday'].' days')); |
|
32 | + $m_search = imap_search($m_mail, "SINCE \"$dateTh\" TEXT \"Authentication-Results: \""); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | // Order results starting from newest message |
36 | - if ( empty($m_search) ) { |
|
37 | - syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder."); |
|
38 | - if ( $ierr = imap_errors() ) |
|
39 | - foreach ( $ierr as $thiserr ) |
|
40 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
41 | - if ( $ierr = imap_alerts() ) |
|
42 | - foreach ( $ierr as $thiserr ) |
|
43 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
44 | - imap_close( $m_mail ); |
|
36 | + if (empty($m_search)) { |
|
37 | + syslog(LOG_INFO, $cf['user'].": No suitable mail found in <$folder> folder."); |
|
38 | + if ($ierr = imap_errors()) |
|
39 | + foreach ($ierr as $thiserr) |
|
40 | + syslog(LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
41 | + if ($ierr = imap_alerts()) |
|
42 | + foreach ($ierr as $thiserr) |
|
43 | + syslog(LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
44 | + imap_close($m_mail); |
|
45 | 45 | return FALSE; |
46 | 46 | } |
47 | - $nmes = count ($m_search); |
|
48 | - syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
|
47 | + $nmes = count($m_search); |
|
48 | + syslog(LOG_INFO, $cf['user'].": Found $nmes mail in <$folder> folder."); |
|
49 | 49 | if ($nmes>0) rsort($m_search); |
50 | 50 | |
51 | 51 | // loop for each message |
52 | 52 | foreach ($m_search as $onem) |
53 | - $head[] = imap_fetchheader($m_mail, $onem ); |
|
53 | + $head[] = imap_fetchheader($m_mail, $onem); |
|
54 | 54 | imap_close($m_mail); |
55 | 55 | return $head; |
56 | 56 | } |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | function dspamLevel($prob, $conf) { |
59 | 59 | /* Calculate DSPAM Level as the Spamassassin Plugin */ |
60 | 60 | if (is_null($prob) or is_null($conf)) return '-'; |
61 | - $t_prob = abs((($prob - 0.5) * 2) * 100); |
|
62 | - return round(($t_prob + ($conf*100)) / 2); |
|
61 | + $t_prob = abs((($prob-0.5) * 2) * 100); |
|
62 | + return round(($t_prob+($conf * 100)) / 2); |
|
63 | 63 | } |
64 | 64 | |
65 | -function imapInfo($header,$ARhosts,$dpl=false, $learn=false) { |
|
65 | +function imapInfo($header, $ARhosts, $dpl = false, $learn = false) { |
|
66 | 66 | /* Get relevant Info from header's mail */ |
67 | 67 | /* Each line must end with /r/n */ |
68 | 68 | |
@@ -98,118 +98,118 @@ discard block |
||
98 | 98 | ); |
99 | 99 | |
100 | 100 | |
101 | - if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
102 | - $k=0; |
|
103 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
101 | + if (preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m', $header, $received)) { |
|
102 | + $k = 0; |
|
103 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
104 | 104 | foreach ($ARhosts as $mx) { |
105 | 105 | if ($mx == $received['host'][$i]) { |
106 | 106 | /* This is a trusted AR result */ |
107 | - $result['dmarc']['result']=$received['dmarc'][$i]; |
|
107 | + $result['dmarc']['result'] = $received['dmarc'][$i]; |
|
108 | 108 | $result['dmarc']['dom'] = $received['DMARCfrom'][$i]; |
109 | 109 | $k++; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
113 | 113 | } |
114 | - $received=NULL; |
|
114 | + $received = NULL; |
|
115 | 115 | if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
116 | 116 | |
117 | - if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m',$header,$received) ) { |
|
118 | - $k=0; |
|
119 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
117 | + if (preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m', $header, $received)) { |
|
118 | + $k = 0; |
|
119 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
120 | 120 | foreach ($ARhosts as $mx) { |
121 | 121 | if ($mx == $received['host'][$i]) { |
122 | 122 | /* This is a trusted AR result */ |
123 | - $result['spf']['result']=$received['spf'][$i]; |
|
123 | + $result['spf']['result'] = $received['spf'][$i]; |
|
124 | 124 | $result['spf']['dom'] = $received['SPFfrom'][$i]; |
125 | 125 | $k++; |
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
130 | - $received=NULL; |
|
130 | + $received = NULL; |
|
131 | 131 | if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
132 | 132 | |
133 | - if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
|
134 | - $k=0; |
|
135 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
133 | + if (preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m', $header, $received)) { |
|
134 | + $k = 0; |
|
135 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
136 | 136 | foreach ($ARhosts as $mx) { |
137 | 137 | if ($mx == $received['host'][$i]) { |
138 | 138 | /* This is a trusted AR result */ |
139 | - $result['dkim']['result']=$received['dkim'][$i]; |
|
139 | + $result['dkim']['result'] = $received['dkim'][$i]; |
|
140 | 140 | $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
141 | 141 | $k++; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
146 | - $received=NULL; |
|
146 | + $received = NULL; |
|
147 | 147 | if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
148 | 148 | |
149 | 149 | if ($dpl) { /* Use Spamassassin Plugin */ |
150 | - if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*DSPAM_(?P<dtype>SPAM|HAM)_(?P<dlevel>\d\d)(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
|
151 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
150 | + if (preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*DSPAM_(?P<dtype>SPAM|HAM)_(?P<dlevel>\d\d)(?:.|\r\n\s+)*\]/m', $header, $received)) { |
|
151 | + $result['spam']['status'] = $received['spamstatus'][0]; |
|
152 | 152 | $result['spam']['score'] = $received['score'][0]; |
153 | 153 | $result['spam']['th'] = $received['th'][0]; |
154 | 154 | $result['dspam']['type'] = $received['dtype'][0]; |
155 | - $result['dspam']['level'] =$received['dlevel'][0]; |
|
155 | + $result['dspam']['level'] = $received['dlevel'][0]; |
|
156 | 156 | } |
157 | 157 | if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
158 | 158 | } |
159 | 159 | else { /* Parse apart all DSPAM Header and calculate a level */ |
160 | - if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
|
161 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
160 | + if (preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*\]/m', $header, $received)) { |
|
161 | + $result['spam']['status'] = $received['spamstatus'][0]; |
|
162 | 162 | $result['spam']['score'] = $received['score'][0]; |
163 | 163 | $result['spam']['th'] = $received['th'][0]; |
164 | 164 | if (count($received[0])>1) |
165 | - $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
165 | + $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
166 | 166 | } |
167 | - if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
|
167 | + if (preg_match('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/', $header, $received) != 1) |
|
168 | 168 | $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
169 | 169 | else |
170 | - $result['dspam']['type']=$received['result']; |
|
170 | + $result['dspam']['type'] = $received['result']; |
|
171 | 171 | $prob = NULL; |
172 | 172 | $conf = NULL; |
173 | - if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
173 | + if (preg_match('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/', $header, $received) != 1) |
|
174 | 174 | $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
175 | 175 | else |
176 | 176 | $prob = $received['prob']; |
177 | - if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
|
177 | + if (preg_match('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/', $header, $received) != 1) |
|
178 | 178 | $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
179 | 179 | else |
180 | 180 | $conf = $received['conf']; |
181 | - $result['dspam']['level'] = dspamLevel($prob,$conf); |
|
181 | + $result['dspam']['level'] = dspamLevel($prob, $conf); |
|
182 | 182 | } |
183 | - $received=NULL; |
|
184 | - if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
|
183 | + $received = NULL; |
|
184 | + if (preg_match('/\r\nFrom:\s(?P<from>.*)\r\n/', $header, $received) != 1) |
|
185 | 185 | $result['warn'][] = 'From header invalid or not present'; |
186 | 186 | else |
187 | 187 | $result['from'] = $received['from']; |
188 | 188 | |
189 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
189 | + if (preg_match('/\r\nDate:\s(?P<date>.*)\r\n/', $header, $received) != 1) |
|
190 | 190 | $result['warn'][] = 'Date header invalid or not present'; |
191 | 191 | else |
192 | 192 | $result['date'] = $received['date']; |
193 | 193 | |
194 | - $received=NULL; |
|
195 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
194 | + $received = NULL; |
|
195 | + if (preg_match('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/', $header, $received) != 1) |
|
196 | 196 | $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
197 | 197 | else |
198 | - $result['messageid']=$received['mid']; |
|
198 | + $result['messageid'] = $received['mid']; |
|
199 | 199 | |
200 | - $received=NULL; |
|
200 | + $received = NULL; |
|
201 | 201 | |
202 | 202 | switch ($learn) { |
203 | 203 | case 'dspamc': |
204 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
204 | + if (preg_match('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/', $header, $received) != 1) |
|
205 | 205 | $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
206 | 206 | else |
207 | - $result['dspam']['learn']=$received['sig']; |
|
207 | + $result['dspam']['learn'] = $received['sig']; |
|
208 | 208 | break; |
209 | 209 | case false: |
210 | 210 | break; |
211 | 211 | default: |
212 | - syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
|
212 | + syslog(LOG_INFO, $user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return $result; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | |
220 | 220 | |
221 | -function printTableHeader($title,$content,$footer=FALSE,$fcontent) { |
|
221 | +function printTableHeader($title, $content, $footer = FALSE, $fcontent) { |
|
222 | 222 | print <<<END |
223 | 223 | <caption>$title</caption> |
224 | 224 | <thead> |
@@ -226,21 +226,19 @@ discard block |
||
226 | 226 | END; |
227 | 227 | $kcontent = array_keys($content); |
228 | 228 | $cols = count($kcontent); |
229 | - for ($i=0; $i<$cols; $i++) { |
|
229 | + for ($i = 0; $i<$cols; $i++) { |
|
230 | 230 | $key = $kcontent[$i]; |
231 | - printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
232 | - !is_array($content[$key]) ?: |
|
233 | - count(array_keys($content[$key])) ?: '1', |
|
234 | - !is_array($content[$key]) ?: |
|
235 | - empty(array_keys($content[$key])) ? '2' : '1', |
|
231 | + printf('<th colspan="%d" rowspan="%d">%s</th>', |
|
232 | + !is_array($content[$key]) ?: count(array_keys($content[$key])) ?: '1', |
|
233 | + !is_array($content[$key]) ?: empty(array_keys($content[$key])) ? '2' : '1', |
|
236 | 234 | $kcontent[$i]); |
237 | 235 | } |
238 | 236 | print '</tr><tr>'; |
239 | - for ($i=0; $i<$cols; $i++) { |
|
237 | + for ($i = 0; $i<$cols; $i++) { |
|
240 | 238 | $key = $kcontent[$i]; |
241 | - if (is_array($content[$key])&&($hs = array_keys($content[$key]))) { |
|
239 | + if (is_array($content[$key]) && ($hs = array_keys($content[$key]))) { |
|
242 | 240 | foreach ($hs as $h) |
243 | - printf('<th>%s</th>',$h); |
|
241 | + printf('<th>%s</th>', $h); |
|
244 | 242 | } |
245 | 243 | } |
246 | 244 | |
@@ -256,7 +254,7 @@ discard block |
||
256 | 254 | |
257 | 255 | function formatVal($val, $learn) { |
258 | 256 | foreach (array_keys($val) as $key) { |
259 | - if (is_array($val["$key"]) and ($key!='warn')) |
|
257 | + if (is_array($val["$key"]) and ($key != 'warn')) |
|
260 | 258 | $val["$key"] = formatVal($val["$key"], $learn); |
261 | 259 | else { |
262 | 260 | switch ($key) { |
@@ -264,7 +262,7 @@ discard block |
||
264 | 262 | if (empty($val["$key"])) |
265 | 263 | $val["$key"] = '-'; |
266 | 264 | else |
267 | - $val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n")); |
|
265 | + $val["$key"] = sprintf('<div title="%s">Y</div>', implode($val["$key"], "\n")); |
|
268 | 266 | break; |
269 | 267 | case 'learn': |
270 | 268 | $val["$key"] = formLearn($learn, $val); |
@@ -286,9 +284,9 @@ discard block |
||
286 | 284 | $par['class'] = $class; |
287 | 285 | $val["$class"] = sprintf('dspamc --user dspam --deliver=summary --class=%s --source=error --signature=%s', |
288 | 286 | strtolower($class), $par['learn']); |
289 | - if (($class != $par['type'])||($par['level']<99)) |
|
287 | + if (($class != $par['type']) || ($par['level']<99)) |
|
290 | 288 | $return .= sprintf(file_get_contents('formLearnDSPAM.htm'), |
291 | - $class,$class,$val["$class"],base64_encode(json_encode($par)),$class); |
|
289 | + $class, $class, $val["$class"], base64_encode(json_encode($par)), $class); |
|
292 | 290 | } |
293 | 291 | default: |
294 | 292 | return $return; |
@@ -296,18 +294,18 @@ discard block |
||
296 | 294 | return $return; |
297 | 295 | } |
298 | 296 | |
299 | -function printTableRow($row, $learn, $init=true) { |
|
297 | +function printTableRow($row, $learn, $init = true) { |
|
300 | 298 | $bg = NULL; |
301 | 299 | $color = 'inherit'; |
302 | 300 | if ($init) |
303 | - $row=formatVal($row,$learn); |
|
304 | - foreach( $row as $key => $val) { |
|
301 | + $row = formatVal($row, $learn); |
|
302 | + foreach ($row as $key => $val) { |
|
305 | 303 | if (is_array($val)) |
306 | 304 | printTableRow($val, $learn, false); |
307 | 305 | else { |
308 | 306 | /* DSPAM format */ |
309 | 307 | if (isset($row['type'])) |
310 | - switch($row['type']) { |
|
308 | + switch ($row['type']) { |
|
311 | 309 | case 'Innocent': |
312 | 310 | case 'HAM': |
313 | 311 | $color = 'rgba(0,255,0, %.1f)'; |
@@ -318,7 +316,7 @@ discard block |
||
318 | 316 | } |
319 | 317 | /* DMARC, DKIM, SPF format */ |
320 | 318 | if (isset($row['result'])) |
321 | - switch($row['result']) { |
|
319 | + switch ($row['result']) { |
|
322 | 320 | case 'pass': |
323 | 321 | $color = 'rgba(0,255,0, %.1f)'; |
324 | 322 | break; |
@@ -327,7 +325,7 @@ discard block |
||
327 | 325 | } |
328 | 326 | /* Spamassassin format */ |
329 | 327 | if (isset($row['status'])) |
330 | - switch($row['status']) { |
|
328 | + switch ($row['status']) { |
|
331 | 329 | case 'No': |
332 | 330 | $color = 'rgba(0,255,0, %.1f)'; |
333 | 331 | break; |
@@ -335,9 +333,9 @@ discard block |
||
335 | 333 | $color = 'rgba(255,0,0,%.1f)'; |
336 | 334 | } |
337 | 335 | |
338 | - $alpha = (is_numeric($val)AND($key=='type')) ? round($val/100,1) : 1.0; |
|
336 | + $alpha = (is_numeric($val) AND ($key == 'type')) ? round($val / 100, 1) : 1.0; |
|
339 | 337 | $bg = sprintf(" style=\"background-color: $color\"", $alpha); |
340 | - printf ('<td%s>%s</td>',$bg, $val); |
|
338 | + printf('<td%s>%s</td>', $bg, $val); |
|
341 | 339 | } |
342 | 340 | } |
343 | 341 | } |
@@ -4,18 +4,21 @@ discard block |
||
4 | 4 | $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
5 | 5 | $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
6 | 6 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
7 | - if ( !$m_mail ) exit(254); |
|
7 | + if ( !$m_mail ) { |
|
8 | + exit(254); |
|
9 | + } |
|
8 | 10 | |
9 | 11 | |
10 | 12 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
11 | 13 | //get all folder |
12 | 14 | $list = imap_list($m_mail, $open, "*"); |
13 | 15 | imap_close($m_mail); |
14 | - if (is_array($list)) |
|
15 | - foreach ($list as $mbox) |
|
16 | + if (is_array($list)) { |
|
17 | + foreach ($list as $mbox) |
|
16 | 18 | $return[] = explode($open,$mbox,2)[1]; |
17 | - else |
|
18 | - syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() ); |
|
19 | + } else { |
|
20 | + syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() ); |
|
21 | + } |
|
19 | 22 | return $return; |
20 | 23 | } |
21 | 24 | |
@@ -23,7 +26,9 @@ discard block |
||
23 | 26 | $head=array(); |
24 | 27 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY) |
25 | 28 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
26 | - if ( !$m_mail ) exit(254); |
|
29 | + if ( !$m_mail ) { |
|
30 | + exit(254); |
|
31 | + } |
|
27 | 32 | |
28 | 33 | |
29 | 34 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...'); |
@@ -35,29 +40,36 @@ discard block |
||
35 | 40 | // Order results starting from newest message |
36 | 41 | if ( empty($m_search) ) { |
37 | 42 | syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder."); |
38 | - if ( $ierr = imap_errors() ) |
|
39 | - foreach ( $ierr as $thiserr ) |
|
43 | + if ( $ierr = imap_errors() ) { |
|
44 | + foreach ( $ierr as $thiserr ) |
|
40 | 45 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
41 | - if ( $ierr = imap_alerts() ) |
|
42 | - foreach ( $ierr as $thiserr ) |
|
46 | + } |
|
47 | + if ( $ierr = imap_alerts() ) { |
|
48 | + foreach ( $ierr as $thiserr ) |
|
43 | 49 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
50 | + } |
|
44 | 51 | imap_close( $m_mail ); |
45 | 52 | return FALSE; |
46 | 53 | } |
47 | 54 | $nmes = count ($m_search); |
48 | 55 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
49 | - if ($nmes>0) rsort($m_search); |
|
56 | + if ($nmes>0) { |
|
57 | + rsort($m_search); |
|
58 | + } |
|
50 | 59 | |
51 | 60 | // loop for each message |
52 | - foreach ($m_search as $onem) |
|
53 | - $head[] = imap_fetchheader($m_mail, $onem ); |
|
61 | + foreach ($m_search as $onem) { |
|
62 | + $head[] = imap_fetchheader($m_mail, $onem ); |
|
63 | + } |
|
54 | 64 | imap_close($m_mail); |
55 | 65 | return $head; |
56 | 66 | } |
57 | 67 | |
58 | 68 | function dspamLevel($prob, $conf) { |
59 | 69 | /* Calculate DSPAM Level as the Spamassassin Plugin */ |
60 | - if (is_null($prob) or is_null($conf)) return '-'; |
|
70 | + if (is_null($prob) or is_null($conf)) { |
|
71 | + return '-'; |
|
72 | + } |
|
61 | 73 | $t_prob = abs((($prob - 0.5) * 2) * 100); |
62 | 74 | return round(($t_prob + ($conf*100)) / 2); |
63 | 75 | } |
@@ -112,7 +124,9 @@ discard block |
||
112 | 124 | } |
113 | 125 | } |
114 | 126 | $received=NULL; |
115 | - if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
|
127 | + if ($k>1) { |
|
128 | + $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
|
129 | + } |
|
116 | 130 | |
117 | 131 | if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m',$header,$received) ) { |
118 | 132 | $k=0; |
@@ -128,7 +142,9 @@ discard block |
||
128 | 142 | } |
129 | 143 | } |
130 | 144 | $received=NULL; |
131 | - if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
|
145 | + if ($k>1) { |
|
146 | + $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
|
147 | + } |
|
132 | 148 | |
133 | 149 | if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
134 | 150 | $k=0; |
@@ -144,7 +160,9 @@ discard block |
||
144 | 160 | } |
145 | 161 | } |
146 | 162 | $received=NULL; |
147 | - if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
|
163 | + if ($k>1) { |
|
164 | + $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
|
165 | + } |
|
148 | 166 | |
149 | 167 | if ($dpl) { /* Use Spamassassin Plugin */ |
150 | 168 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*DSPAM_(?P<dtype>SPAM|HAM)_(?P<dlevel>\d\d)(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
@@ -154,57 +172,66 @@ discard block |
||
154 | 172 | $result['dspam']['type'] = $received['dtype'][0]; |
155 | 173 | $result['dspam']['level'] =$received['dlevel'][0]; |
156 | 174 | } |
157 | - if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
158 | - } |
|
159 | - else { /* Parse apart all DSPAM Header and calculate a level */ |
|
175 | + if (count($received[0])>1) { |
|
176 | + $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
177 | + } |
|
178 | + } else { /* Parse apart all DSPAM Header and calculate a level */ |
|
160 | 179 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
161 | 180 | $result['spam']['status']=$received['spamstatus'][0]; |
162 | 181 | $result['spam']['score'] = $received['score'][0]; |
163 | 182 | $result['spam']['th'] = $received['th'][0]; |
164 | - if (count($received[0])>1) |
|
165 | - $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
183 | + if (count($received[0])>1) { |
|
184 | + $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
185 | + } |
|
166 | 186 | } |
167 | - if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
|
168 | - $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
169 | - else |
|
170 | - $result['dspam']['type']=$received['result']; |
|
187 | + if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) { |
|
188 | + $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
189 | + } else { |
|
190 | + $result['dspam']['type']=$received['result']; |
|
191 | + } |
|
171 | 192 | $prob = NULL; |
172 | 193 | $conf = NULL; |
173 | - if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
174 | - $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
175 | - else |
|
176 | - $prob = $received['prob']; |
|
177 | - if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
|
178 | - $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
179 | - else |
|
180 | - $conf = $received['conf']; |
|
194 | + if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) { |
|
195 | + $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
196 | + } else { |
|
197 | + $prob = $received['prob']; |
|
198 | + } |
|
199 | + if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) { |
|
200 | + $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
201 | + } else { |
|
202 | + $conf = $received['conf']; |
|
203 | + } |
|
181 | 204 | $result['dspam']['level'] = dspamLevel($prob,$conf); |
182 | 205 | } |
183 | 206 | $received=NULL; |
184 | - if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
|
185 | - $result['warn'][] = 'From header invalid or not present'; |
|
186 | - else |
|
187 | - $result['from'] = $received['from']; |
|
207 | + if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) { |
|
208 | + $result['warn'][] = 'From header invalid or not present'; |
|
209 | + } else { |
|
210 | + $result['from'] = $received['from']; |
|
211 | + } |
|
188 | 212 | |
189 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
190 | - $result['warn'][] = 'Date header invalid or not present'; |
|
191 | - else |
|
192 | - $result['date'] = $received['date']; |
|
213 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) { |
|
214 | + $result['warn'][] = 'Date header invalid or not present'; |
|
215 | + } else { |
|
216 | + $result['date'] = $received['date']; |
|
217 | + } |
|
193 | 218 | |
194 | 219 | $received=NULL; |
195 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
196 | - $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
197 | - else |
|
198 | - $result['messageid']=$received['mid']; |
|
220 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) { |
|
221 | + $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
222 | + } else { |
|
223 | + $result['messageid']=$received['mid']; |
|
224 | + } |
|
199 | 225 | |
200 | 226 | $received=NULL; |
201 | 227 | |
202 | 228 | switch ($learn) { |
203 | 229 | case 'dspamc': |
204 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
205 | - $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
|
206 | - else |
|
207 | - $result['dspam']['learn']=$received['sig']; |
|
230 | + if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) { |
|
231 | + $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
|
232 | + } else { |
|
233 | + $result['dspam']['learn']=$received['sig']; |
|
234 | + } |
|
208 | 235 | break; |
209 | 236 | case false: |
210 | 237 | break; |
@@ -239,8 +266,9 @@ discard block |
||
239 | 266 | for ($i=0; $i<$cols; $i++) { |
240 | 267 | $key = $kcontent[$i]; |
241 | 268 | if (is_array($content[$key])&&($hs = array_keys($content[$key]))) { |
242 | - foreach ($hs as $h) |
|
243 | - printf('<th>%s</th>',$h); |
|
269 | + foreach ($hs as $h) { |
|
270 | + printf('<th>%s</th>',$h); |
|
271 | + } |
|
244 | 272 | } |
245 | 273 | } |
246 | 274 | |
@@ -256,15 +284,16 @@ discard block |
||
256 | 284 | |
257 | 285 | function formatVal($val, $learn) { |
258 | 286 | foreach (array_keys($val) as $key) { |
259 | - if (is_array($val["$key"]) and ($key!='warn')) |
|
260 | - $val["$key"] = formatVal($val["$key"], $learn); |
|
261 | - else { |
|
287 | + if (is_array($val["$key"]) and ($key!='warn')) { |
|
288 | + $val["$key"] = formatVal($val["$key"], $learn); |
|
289 | + } else { |
|
262 | 290 | switch ($key) { |
263 | 291 | case 'warn': |
264 | - if (empty($val["$key"])) |
|
265 | - $val["$key"] = '-'; |
|
266 | - else |
|
267 | - $val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n")); |
|
292 | + if (empty($val["$key"])) { |
|
293 | + $val["$key"] = '-'; |
|
294 | + } else { |
|
295 | + $val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n")); |
|
296 | + } |
|
268 | 297 | break; |
269 | 298 | case 'learn': |
270 | 299 | $val["$key"] = formLearn($learn, $val); |
@@ -286,9 +315,10 @@ discard block |
||
286 | 315 | $par['class'] = $class; |
287 | 316 | $val["$class"] = sprintf('dspamc --user dspam --deliver=summary --class=%s --source=error --signature=%s', |
288 | 317 | strtolower($class), $par['learn']); |
289 | - if (($class != $par['type'])||($par['level']<99)) |
|
290 | - $return .= sprintf(file_get_contents('formLearnDSPAM.htm'), |
|
318 | + if (($class != $par['type'])||($par['level']<99)) { |
|
319 | + $return .= sprintf(file_get_contents('formLearnDSPAM.htm'), |
|
291 | 320 | $class,$class,$val["$class"],base64_encode(json_encode($par)),$class); |
321 | + } |
|
292 | 322 | } |
293 | 323 | default: |
294 | 324 | return $return; |
@@ -299,37 +329,41 @@ discard block |
||
299 | 329 | function printTableRow($row, $learn, $init=true) { |
300 | 330 | $bg = NULL; |
301 | 331 | $color = 'inherit'; |
302 | - if ($init) |
|
303 | - $row=formatVal($row,$learn); |
|
332 | + if ($init) { |
|
333 | + $row=formatVal($row,$learn); |
|
334 | + } |
|
304 | 335 | foreach( $row as $key => $val) { |
305 | - if (is_array($val)) |
|
306 | - printTableRow($val, $learn, false); |
|
307 | - else { |
|
336 | + if (is_array($val)) { |
|
337 | + printTableRow($val, $learn, false); |
|
338 | + } else { |
|
308 | 339 | /* DSPAM format */ |
309 | - if (isset($row['type'])) |
|
310 | - switch($row['type']) { |
|
340 | + if (isset($row['type'])) { |
|
341 | + switch($row['type']) { |
|
311 | 342 | case 'Innocent': |
312 | 343 | case 'HAM': |
313 | 344 | $color = 'rgba(0,255,0, %.1f)'; |
345 | + } |
|
314 | 346 | break; |
315 | 347 | case 'Spam': |
316 | 348 | case 'SPAM': |
317 | 349 | $color = 'rgba(255,0,0,%.1f)'; |
318 | 350 | } |
319 | 351 | /* DMARC, DKIM, SPF format */ |
320 | - if (isset($row['result'])) |
|
321 | - switch($row['result']) { |
|
352 | + if (isset($row['result'])) { |
|
353 | + switch($row['result']) { |
|
322 | 354 | case 'pass': |
323 | 355 | $color = 'rgba(0,255,0, %.1f)'; |
356 | + } |
|
324 | 357 | break; |
325 | 358 | case 'fail': |
326 | 359 | $color = 'rgba(255,0,0,%.1f)'; |
327 | 360 | } |
328 | 361 | /* Spamassassin format */ |
329 | - if (isset($row['status'])) |
|
330 | - switch($row['status']) { |
|
362 | + if (isset($row['status'])) { |
|
363 | + switch($row['status']) { |
|
331 | 364 | case 'No': |
332 | 365 | $color = 'rgba(0,255,0, %.1f)'; |
366 | + } |
|
333 | 367 | break; |
334 | 368 | case 'Yes': |
335 | 369 | $color = 'rgba(255,0,0,%.1f)'; |
@@ -14,7 +14,7 @@ |
||
14 | 14 | $folders=imapFolder($conf['imap'], $_POST['username']); |
15 | 15 | print '<option value="" selected disabled>Choose a folder</option>'; |
16 | 16 | foreach ( $folders as $folder ) |
17 | - printf('<option value="%s">%s</option>', |
|
17 | + printf('<option value="%s">%s</option>', |
|
18 | 18 | $folder, |
19 | 19 | htmlspecialchars(mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"))); |
20 | 20 | closelog(); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <select name="folder" style="width:215px" onChange="xmlhttpPost('result.php', 'Classify', 'Result', '<img src=\'/include/pleasewait.gif\'>', true); return false;"> |
2 | 2 | <?php |
3 | -$path='/var/www/html/RBL/'; |
|
3 | +$path = '/var/www/html/RBL/'; |
|
4 | 4 | require_once($path.'function.php'); |
5 | 5 | require_once($path.'config.php'); |
6 | 6 | require_once('function.php'); |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | openlog($tag, LOG_PID, $fac); |
12 | 12 | |
13 | 13 | $conf['imap']['user'] = username(); |
14 | -$folders=imapFolder($conf['imap'], $_POST['username']); |
|
14 | +$folders = imapFolder($conf['imap'], $_POST['username']); |
|
15 | 15 | print '<option value="" selected disabled>Choose a folder</option>'; |
16 | -foreach ( $folders as $folder ) |
|
16 | +foreach ($folders as $folder) |
|
17 | 17 | printf('<option value="%s">%s</option>', |
18 | 18 | $folder, |
19 | 19 | htmlspecialchars(mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"))); |
@@ -13,10 +13,11 @@ |
||
13 | 13 | $conf['imap']['user'] = username(); |
14 | 14 | $folders=imapFolder($conf['imap'], $_POST['username']); |
15 | 15 | print '<option value="" selected disabled>Choose a folder</option>'; |
16 | -foreach ( $folders as $folder ) |
|
16 | +foreach ( $folders as $folder ) { |
|
17 | 17 | printf('<option value="%s">%s</option>', |
18 | 18 | $folder, |
19 | 19 | htmlspecialchars(mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"))); |
20 | +} |
|
20 | 21 | closelog(); |
21 | 22 | ?> |
22 | 23 | </select> |
@@ -27,32 +27,32 @@ |
||
27 | 27 | |
28 | 28 | |
29 | 29 | $data = array( |
30 | - 'date' => NULL, |
|
31 | - 'from' => NULL, |
|
32 | - 'messageid' => NULL, |
|
33 | - 'dmarc' => array( |
|
34 | - 'result' => NULL, |
|
35 | - 'dom' => NULL |
|
36 | - ), |
|
37 | - 'spf' => array( |
|
38 | - 'result' => NULL, |
|
39 | - 'dom' => NULL |
|
40 | - ), |
|
41 | - 'dkim' => array( |
|
42 | - 'result' => NULL, |
|
43 | - 'dom' => NULL |
|
44 | - ), |
|
45 | - 'spam' => array( |
|
46 | - 'status' => NULL, |
|
47 | - 'score' => NULL, |
|
48 | - 'th' => NULL, |
|
49 | - ), |
|
50 | - 'dspam' => array( |
|
51 | - 'type' => NULL, |
|
52 | - 'level' => NULL, |
|
53 | - 'learn' => NULL |
|
54 | - ), |
|
55 | - 'warn' => NULL |
|
30 | + 'date' => NULL, |
|
31 | + 'from' => NULL, |
|
32 | + 'messageid' => NULL, |
|
33 | + 'dmarc' => array( |
|
34 | + 'result' => NULL, |
|
35 | + 'dom' => NULL |
|
36 | + ), |
|
37 | + 'spf' => array( |
|
38 | + 'result' => NULL, |
|
39 | + 'dom' => NULL |
|
40 | + ), |
|
41 | + 'dkim' => array( |
|
42 | + 'result' => NULL, |
|
43 | + 'dom' => NULL |
|
44 | + ), |
|
45 | + 'spam' => array( |
|
46 | + 'status' => NULL, |
|
47 | + 'score' => NULL, |
|
48 | + 'th' => NULL, |
|
49 | + ), |
|
50 | + 'dspam' => array( |
|
51 | + 'type' => NULL, |
|
52 | + 'level' => NULL, |
|
53 | + 'learn' => NULL |
|
54 | + ), |
|
55 | + 'warn' => NULL |
|
56 | 56 | ); |
57 | 57 | |
58 | 58 | if (empty($folder)) exit ('<p>No folder found.</p>'); /* This should not occur */ |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -$path='/var/www/html/RBL/'; |
|
2 | +$path = '/var/www/html/RBL/'; |
|
3 | 3 | include_once($path.'config.php'); |
4 | 4 | require_once($path.'function.php'); |
5 | 5 | |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | $tag .= $conf['syslog']['tag']; |
15 | 15 | openlog($tag, LOG_PID, $fac); |
16 | 16 | |
17 | -if ( $confimap['learn']=='dspamc' ) { |
|
17 | +if ($confimap['learn'] == 'dspamc') { |
|
18 | 18 | $cmd = escapeshellcmd('which dspamc'); |
19 | 19 | $cmd = escapeshellcmd('which ls'); |
20 | - exec ( $cmd, $out, $ret ); |
|
20 | + exec($cmd, $out, $ret); |
|
21 | 21 | if ($ret != 0) { |
22 | 22 | $err = 'No DSPAM Client found on your system. Please, force your sysadmin to install "dspamc".'; |
23 | 23 | syslog(LOG_ERR, $username.': Error: '.$err); |
24 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
24 | + exit (sprintf('<p>%s</p>', htmlentities($err))); |
|
25 | 25 | } |
26 | 26 | } |
27 | 27 | |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | $headers = imapFind($confimap, $account, $folder); |
61 | 61 | if (empty($headers)) exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>"))); |
62 | 62 | print '<table>'; |
63 | -printTableHeader($folder,$data,TRUE,sprintf('Found %d suitable mails.',count($headers))); |
|
63 | +printTableHeader($folder, $data, TRUE, sprintf('Found %d suitable mails.', count($headers))); |
|
64 | 64 | |
65 | -foreach ( $headers AS $header ) { |
|
66 | - $values = imapInfo($header,$conf['host']['ar'],$confimap['dspamtospamass'],$confimap['learn']); |
|
65 | +foreach ($headers AS $header) { |
|
66 | + $values = imapInfo($header, $conf['host']['ar'], $confimap['dspamtospamass'], $confimap['learn']); |
|
67 | 67 | print '<tr>'; |
68 | 68 | printTableRow($values, $confimap['learn']); |
69 | 69 | print '</tr>'; |
@@ -55,10 +55,15 @@ |
||
55 | 55 | 'warn' => NULL |
56 | 56 | ); |
57 | 57 | |
58 | -if (empty($folder)) exit ('<p>No folder found.</p>'); /* This should not occur */ |
|
58 | +if (empty($folder)) { |
|
59 | + exit ('<p>No folder found.</p>'); |
|
60 | +} |
|
61 | +/* This should not occur */ |
|
59 | 62 | $confimap['user'] = $username; |
60 | 63 | $headers = imapFind($confimap, $account, $folder); |
61 | -if (empty($headers)) exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>"))); |
|
64 | +if (empty($headers)) { |
|
65 | + exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>"))); |
|
66 | +} |
|
62 | 67 | print '<table>'; |
63 | 68 | printTableHeader($folder,$data,TRUE,sprintf('Found %d suitable mails.',count($headers))); |
64 | 69 |
@@ -16,10 +16,10 @@ |
||
16 | 16 | require_once('function.php'); |
17 | 17 | |
18 | 18 | if ( !isset($version) ) { |
19 | - openlog('mailClassifierEmergency', LOG_PID, LOG_LOCAL0); |
|
20 | - syslog (LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
21 | - closelog(); |
|
22 | - exit(255); |
|
19 | + openlog('mailClassifierEmergency', LOG_PID, LOG_LOCAL0); |
|
20 | + syslog (LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
21 | + closelog(); |
|
22 | + exit(255); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | checkSSL(); |
@@ -10,24 +10,24 @@ |
||
10 | 10 | <body> |
11 | 11 | <h1> Mail Classifier</h1> |
12 | 12 | <?php |
13 | -$path='/var/www/html/RBL/'; |
|
13 | +$path = '/var/www/html/RBL/'; |
|
14 | 14 | require_once($path.'config.php'); |
15 | 15 | require_once($path.'function.php'); |
16 | 16 | require_once('function.php'); |
17 | 17 | |
18 | -if ( !isset($version) ) { |
|
18 | +if (!isset($version)) { |
|
19 | 19 | openlog('mailClassifierEmergency', LOG_PID, LOG_LOCAL0); |
20 | - syslog (LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
20 | + syslog(LOG_EMERG, sprintf('unknown: I can\'t read the config files. Do you have configured the $path in %s?', __FILE__)); |
|
21 | 21 | closelog(); |
22 | 22 | exit(255); |
23 | 23 | } |
24 | 24 | |
25 | 25 | checkSSL(); |
26 | 26 | $user = username(); |
27 | -$isAdmin = in_array($user,array_keys($admins)); |
|
27 | +$isAdmin = in_array($user, array_keys($admins)); |
|
28 | 28 | $canChange = ($isAdmin) ? '' : 'readonly'; |
29 | -if ( $require_auth ) |
|
30 | - if ( $user == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
29 | +if ($require_auth) |
|
30 | + if ($user == 'unknown') exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
31 | 31 | |
32 | 32 | |
33 | 33 | print <<<END |
@@ -26,8 +26,9 @@ |
||
26 | 26 | $user = username(); |
27 | 27 | $isAdmin = in_array($user,array_keys($admins)); |
28 | 28 | $canChange = ($isAdmin) ? '' : 'readonly'; |
29 | -if ( $require_auth ) |
|
29 | +if ( $require_auth ) { |
|
30 | 30 | if ( $user == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
31 | +} |
|
31 | 32 | |
32 | 33 | |
33 | 34 | print <<<END |
@@ -26,12 +26,12 @@ |
||
26 | 26 | if ( preg_match ('/^X-DSPAM-Result:\s+(?P<user>[\w\.\@]+);\s+result="(?P<result>\w+)";\s+class="(?P<class>\w+)";\s+probability=(?P<prob>[\d\.]+);\s+confidence=(?P<conf>[\d\.]+);\s+signature=(?P<sig>[\w\,]+)$/',$out[0],$received) != 1) { |
27 | 27 | $err = 'DSPAM Client returned an unparseable result.'; |
28 | 28 | syslog(LOG_ERR, $username.': Learn Error: '.$err); |
29 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
29 | + exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | printf('<p>Message learned successfully with following result:</p><ul><li>Owner: <b>%s</b></li><li>Result: <b>%s</b></li><li>Class: <b>%s</b></li></ul>', |
33 | 33 | htmlentities($received['user']), |
34 | - $received['result'], $received['class']); |
|
34 | + $received['result'], $received['class']); |
|
35 | 35 | ?> |
36 | 36 | closelog(); |
37 | 37 | </div> |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <div id="content"> |
2 | 2 | <h3>Log</h3> |
3 | 3 | <?php |
4 | -$path='/var/www/html/RBL/'; |
|
4 | +$path = '/var/www/html/RBL/'; |
|
5 | 5 | require_once($path.'function.php'); |
6 | 6 | require_once($path.'config.php'); |
7 | 7 | $conf = parse_ini_file('imap.conf', TRUE); |
@@ -16,17 +16,17 @@ discard block |
||
16 | 16 | |
17 | 17 | syslog(LOG_INFO, sprintf('%s: Learn as <%s> on signature: <%s>', $username, $par->class, $par->learn)); |
18 | 18 | $cmd = escapeshellcmd($_POST['cmd']); |
19 | -exec ( $cmd, $out, $ret ); |
|
19 | +exec($cmd, $out, $ret); |
|
20 | 20 | if ($ret != 0) { |
21 | 21 | $err = 'DSPAM Client returns a bad exit state. Sorry, probably the learn was successful, but I don\'t know...'; |
22 | 22 | syslog(LOG_ERR, $username.': Learn Error: '.$err); |
23 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
23 | + exit (sprintf('<p>%s</p>', htmlentities($err))); |
|
24 | 24 | } |
25 | -syslog(LOG_INFO,'%s: Learn result: "%s"',$username, $out[0]); |
|
26 | -if ( preg_match ('/^X-DSPAM-Result:\s+(?P<user>[\w\.\@]+);\s+result="(?P<result>\w+)";\s+class="(?P<class>\w+)";\s+probability=(?P<prob>[\d\.]+);\s+confidence=(?P<conf>[\d\.]+);\s+signature=(?P<sig>[\w\,]+)$/',$out[0],$received) != 1) { |
|
25 | +syslog(LOG_INFO, '%s: Learn result: "%s"', $username, $out[0]); |
|
26 | +if (preg_match('/^X-DSPAM-Result:\s+(?P<user>[\w\.\@]+);\s+result="(?P<result>\w+)";\s+class="(?P<class>\w+)";\s+probability=(?P<prob>[\d\.]+);\s+confidence=(?P<conf>[\d\.]+);\s+signature=(?P<sig>[\w\,]+)$/', $out[0], $received) != 1) { |
|
27 | 27 | $err = 'DSPAM Client returned an unparseable result.'; |
28 | 28 | syslog(LOG_ERR, $username.': Learn Error: '.$err); |
29 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
29 | + exit (sprintf('<p>%s</p>', htmlentities($err))); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | printf('<p>Message learned successfully with following result:</p><ul><li>Owner: <b>%s</b></li><li>Result: <b>%s</b></li><li>Class: <b>%s</b></li></ul>', |