@@ -1,4 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | +/** |
|
| 3 | + * @param string $header |
|
| 4 | + */ |
|
| 2 | 5 | function getIP($header,$mxserver,$msa) { |
| 3 | 6 | /* Get submission server's IP from header's mail */ |
| 4 | 7 | /* Each line must end with /r/n */ |
@@ -28,11 +31,24 @@ discard block |
||
| 28 | 31 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); |
| 29 | 32 | } |
| 30 | 33 | |
| 34 | +/** |
|
| 35 | + * @param string|false $ip |
|
| 36 | + * @param string $hostname |
|
| 37 | + * @param string $dateC |
|
| 38 | + * @param string|null $msgid |
|
| 39 | + * @param string|false $dateL |
|
| 40 | + */ |
|
| 31 | 41 | function updateReport ($ip,$uid,$ipcount,$uidcount,$hostname,$dateC,$msgid,$dateL) { |
| 32 | 42 | |
| 33 | 43 | 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 | 44 | } |
| 35 | 45 | |
| 46 | +/** |
|
| 47 | + * @param string $dateC |
|
| 48 | + * @param string|null $msgid |
|
| 49 | + * @param false|string $dateL |
|
| 50 | + * @param string $text |
|
| 51 | + */ |
|
| 36 | 52 | function updatebadReport ( $uid,$dateC,$msgid,$dateL,$text ) { |
| 37 | 53 | 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 | 54 | } |
@@ -84,6 +100,9 @@ discard block |
||
| 84 | 100 | } |
| 85 | 101 | |
| 86 | 102 | |
| 103 | +/** |
|
| 104 | + * @param null|mysqli $myconn |
|
| 105 | + */ |
|
| 87 | 106 | function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { |
| 88 | 107 | $nips = $ipvet['count']; |
| 89 | 108 | |
@@ -154,6 +173,10 @@ discard block |
||
| 154 | 173 | } |
| 155 | 174 | |
| 156 | 175 | |
| 176 | +/** |
|
| 177 | + * @param string $message_id |
|
| 178 | + * @param string $date |
|
| 179 | + */ |
|
| 157 | 180 | function splunksearch ($service,$message_id,$date) { |
| 158 | 181 | |
| 159 | 182 | // Run a blocking search |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
| 13 | 13 | if ( preg_match($msa,$received['host'][$i]) ) |
| 14 | 14 | $dateR = $received['date'][$i]; |
| 15 | - foreach ($mxserver as $mx) { |
|
| 16 | - if (!$ip) |
|
| 15 | + foreach ($mxserver as $mx) { |
|
| 16 | + if (!$ip) |
|
| 17 | 17 | if ($mx == $received['host'][$i]) { |
| 18 | 18 | $host = $received['host'][$i]; |
| 19 | 19 | $ip = $received['ip'][$i]; |
| 20 | - } |
|
| 21 | - } |
|
| 22 | - } |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
| 25 | 25 | $dateC['date'] = 'Not found'; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | function summaryBadReport ($uidvet) { |
| 42 | - $nuid = $uidvet['count']; |
|
| 43 | - if ( empty($uidvet) ) return NULL; |
|
| 44 | - $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
|
| 42 | + $nuid = $uidvet['count']; |
|
| 43 | + if ( empty($uidvet) ) return NULL; |
|
| 44 | + $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
|
| 45 | 45 | |
| 46 | - /* Remove count index */ |
|
| 47 | - $uids = array_keys($uidvet['uid']); |
|
| 46 | + /* Remove count index */ |
|
| 47 | + $uids = array_keys($uidvet['uid']); |
|
| 48 | 48 | $totlearn = 0; |
| 49 | 49 | |
| 50 | - foreach ( $uids as $uid ) { |
|
| 50 | + foreach ( $uids as $uid ) { |
|
| 51 | 51 | $totlearn += $uidvet['uid']["$uid"]['count'];; |
| 52 | 52 | $return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']); |
| 53 | 53 | } |
@@ -60,26 +60,26 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | function array_msort($array, $cols) |
| 62 | 62 | { |
| 63 | - $colarr = array(); |
|
| 64 | - foreach ($cols as $col => $order) { |
|
| 65 | - $colarr[$col] = array(); |
|
| 66 | - foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
|
| 67 | - } |
|
| 68 | - $eval = 'array_multisort('; |
|
| 69 | - foreach ($cols as $col => $order) { |
|
| 70 | - $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
|
| 71 | - } |
|
| 72 | - $eval = substr($eval,0,-1).');'; |
|
| 73 | - eval($eval); |
|
| 74 | - $ret = array(); |
|
| 75 | - foreach ($colarr as $col => $arr) { |
|
| 76 | - foreach ($arr as $k => $v) { |
|
| 77 | - $k = substr($k,1); |
|
| 78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
| 79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - return $ret; |
|
| 63 | + $colarr = array(); |
|
| 64 | + foreach ($cols as $col => $order) { |
|
| 65 | + $colarr[$col] = array(); |
|
| 66 | + foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
|
| 67 | + } |
|
| 68 | + $eval = 'array_multisort('; |
|
| 69 | + foreach ($cols as $col => $order) { |
|
| 70 | + $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
|
| 71 | + } |
|
| 72 | + $eval = substr($eval,0,-1).');'; |
|
| 73 | + eval($eval); |
|
| 74 | + $ret = array(); |
|
| 75 | + foreach ($colarr as $col => $arr) { |
|
| 76 | + foreach ($arr as $k => $v) { |
|
| 77 | + $k = substr($k,1); |
|
| 78 | + if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
| 79 | + if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + return $ret; |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | foreach ( $ips as $ip ) { |
| 96 | 96 | if ( $ip == 'count' ) continue; |
| 97 | - $nlearn = $ipvet['ip']["$ip"]['count']; |
|
| 98 | - unset($ipvet['ip']["$ip"]['count']); |
|
| 97 | + $nlearn = $ipvet['ip']["$ip"]['count']; |
|
| 98 | + unset($ipvet['ip']["$ip"]['count']); |
|
| 99 | 99 | $nuid = count($ipvet['ip']["$ip"]); |
| 100 | 100 | if ( !$cf['onlyReport'] ) { |
| 101 | 101 | if ( ($nlearn >= $cf['thresholdip']["$category"])&&($nuid >= $cf['thresholduid']["$category"]) ) { |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
| 123 | 123 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$ipvet['ip']["$ip"][0],$nlearn,$nowlist["$listed"]['name']); |
| 124 | 124 | $rowuid=NULL; |
| 125 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 125 | + for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 126 | 126 | array_shift($ipvet['ip']["$ip"]); |
| 127 | - $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
|
| 127 | + $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
|
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | $return .= sprintf ('<tr><th title="unique ips">%u</th><th title="unique uids">%u</th><th>%u</th></table>',$ipvet['ip']['count'],$ipvet['uid']['count'],$nips); |
@@ -134,20 +134,20 @@ discard block |
||
| 134 | 134 | /* Not used for listing purpose, but useful to you! */ |
| 135 | 135 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
| 136 | 136 | $uids = array_keys($ipvet['uid']); |
| 137 | - foreach ( $uids as $uid ) { |
|
| 137 | + foreach ( $uids as $uid ) { |
|
| 138 | 138 | if ( $uid == 'count' ) continue; |
| 139 | - $nlearn = $ipvet['uid']["$uid"]['count']; |
|
| 140 | - unset ( $ipvet['uid']["$uid"]['count'] ); |
|
| 139 | + $nlearn = $ipvet['uid']["$uid"]['count']; |
|
| 140 | + unset ( $ipvet['uid']["$uid"]['count'] ); |
|
| 141 | 141 | $nip = count($ipvet['uid']["$uid"]); |
| 142 | 142 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 143 | 143 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
| 144 | - $rowuid=NULL; |
|
| 145 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 146 | - array_shift($ipvet['uid']["$uid"]); |
|
| 147 | - $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
|
| 144 | + $rowuid=NULL; |
|
| 145 | + for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 146 | + array_shift($ipvet['uid']["$uid"]); |
|
| 147 | + $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
|
| 148 | 148 | |
| 149 | - } |
|
| 150 | - $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique ips">%u</th><th>%u</th></table>',$ipvet['uid']['count'],$ipvet['ip']['count'],$nips); |
|
| 149 | + } |
|
| 150 | + $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique ips">%u</th><th>%u</th></table>',$ipvet['uid']['count'],$ipvet['ip']['count'],$nips); |
|
| 151 | 151 | |
| 152 | 152 | |
| 153 | 153 | return $return; |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | // A blocking search returns the job when the search is done |
| 165 | 165 | /* Wait to finish */ |
| 166 | 166 | $job = $service->getJobs()->create($searchQueryBlocking, array( |
| 167 | - 'exec_mode' => 'blocking', |
|
| 168 | - 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 169 | - 'latest_time' => date("c",strtotime ($date)+60) |
|
| 167 | + 'exec_mode' => 'blocking', |
|
| 168 | + 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 169 | + 'latest_time' => date("c",strtotime ($date)+60) |
|
| 170 | 170 | )); |
| 171 | 171 | |
| 172 | 172 | |
@@ -179,38 +179,38 @@ discard block |
||
| 179 | 179 | // Use the built-in XML parser to display the job results |
| 180 | 180 | foreach ($resultSearch as $result) |
| 181 | 181 | { |
| 182 | - if ($result instanceof Splunk_ResultsFieldOrder) |
|
| 183 | - { |
|
| 184 | - // More than one field attribute returned by search |
|
| 185 | - // You must redefine the search |
|
| 186 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 187 | - } |
|
| 188 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 189 | - { |
|
| 190 | - // I don't want messages in my search |
|
| 191 | - return FALSE; |
|
| 192 | - } |
|
| 193 | - else if (is_array($result)) |
|
| 194 | - { |
|
| 195 | - // Process a row |
|
| 196 | - foreach ($result as $key => $valueOrValues) |
|
| 197 | - { |
|
| 198 | - if (is_array($valueOrValues)) |
|
| 199 | - { |
|
| 200 | - return FALSE; |
|
| 201 | - } |
|
| 202 | - else |
|
| 203 | - { |
|
| 204 | - return $valueOrValues; |
|
| 205 | - #print " {$key} => {$value}\r\n"; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - else |
|
| 210 | - { |
|
| 211 | - #print "Unknow result type"; |
|
| 212 | - return FALSE; |
|
| 213 | - } |
|
| 182 | + if ($result instanceof Splunk_ResultsFieldOrder) |
|
| 183 | + { |
|
| 184 | + // More than one field attribute returned by search |
|
| 185 | + // You must redefine the search |
|
| 186 | + if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 187 | + } |
|
| 188 | + else if ($result instanceof Splunk_ResultsMessage) |
|
| 189 | + { |
|
| 190 | + // I don't want messages in my search |
|
| 191 | + return FALSE; |
|
| 192 | + } |
|
| 193 | + else if (is_array($result)) |
|
| 194 | + { |
|
| 195 | + // Process a row |
|
| 196 | + foreach ($result as $key => $valueOrValues) |
|
| 197 | + { |
|
| 198 | + if (is_array($valueOrValues)) |
|
| 199 | + { |
|
| 200 | + return FALSE; |
|
| 201 | + } |
|
| 202 | + else |
|
| 203 | + { |
|
| 204 | + return $valueOrValues; |
|
| 205 | + #print " {$key} => {$value}\r\n"; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + else |
|
| 210 | + { |
|
| 211 | + #print "Unknow result type"; |
|
| 212 | + return FALSE; |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -219,26 +219,26 @@ discard block |
||
| 219 | 219 | $file = dirname(__FILE__) . '/' . $cf['reportFile']["$type"]; |
| 220 | 220 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
| 221 | 221 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
| 222 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 222 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 223 | 223 | if ( !$m_mail ) exit(254); |
| 224 | 224 | |
| 225 | 225 | |
| 226 | 226 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
| 227 | 227 | //get all messages |
| 228 | 228 | $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); |
| 229 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 230 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 229 | + $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 230 | + $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | // Order results starting from newest message |
| 234 | 234 | if ( empty($m_search) ) { |
| 235 | 235 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
| 236 | - if ( $ierr = imap_errors() ) |
|
| 237 | - foreach ( $ierr as $thiserr ) |
|
| 238 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 239 | - if ( $ierr = imap_alerts() ) |
|
| 240 | - foreach ( $ierr as $thiserr ) |
|
| 241 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 236 | + if ( $ierr = imap_errors() ) |
|
| 237 | + foreach ( $ierr as $thiserr ) |
|
| 238 | + syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 239 | + if ( $ierr = imap_alerts() ) |
|
| 240 | + foreach ( $ierr as $thiserr ) |
|
| 241 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 242 | 242 | imap_close( $m_mail ); |
| 243 | 243 | if ( file_exists( $file ) ) unlink ($file); |
| 244 | 244 | if ( file_exists( $fileb ) ) unlink ($fileb); |
@@ -271,16 +271,16 @@ discard block |
||
| 271 | 271 | $uidbad['count'] = 0; |
| 272 | 272 | $uidbad['uid'] = array(); |
| 273 | 273 | |
| 274 | - // loop for each message |
|
| 274 | + // loop for each message |
|
| 275 | 275 | foreach ($m_search as $onem) { |
| 276 | 276 | |
| 277 | - //get imap header info for obj thang |
|
| 278 | - //$headers = imap_headerinfo($m_mail, $onem); |
|
| 279 | - //$head = imap_fetchheader($m_mail, $headers->Msgno); |
|
| 277 | + //get imap header info for obj thang |
|
| 278 | + //$headers = imap_headerinfo($m_mail, $onem); |
|
| 279 | + //$head = imap_fetchheader($m_mail, $headers->Msgno); |
|
| 280 | 280 | $head = imap_fetchheader($m_mail, $onem ); |
| 281 | - //$obj = imap_rfc822_parse_headers( $head); |
|
| 281 | + //$obj = imap_rfc822_parse_headers( $head); |
|
| 282 | 282 | |
| 283 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); |
|
| 283 | + list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); |
|
| 284 | 284 | if (empty($mid)) { |
| 285 | 285 | $uid='NA'; |
| 286 | 286 | syslog (LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); |
@@ -295,11 +295,11 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - /* Update count of each ip */ |
|
| 299 | - if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 298 | + /* Update count of each ip */ |
|
| 299 | + if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 300 | 300 | $ipuid['count']++; //number of right messages |
| 301 | 301 | |
| 302 | - if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 302 | + if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 303 | 303 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 304 | 304 | if (!in_array($ip,$ipuid['uid']["$uid"])) |
| 305 | 305 | $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
@@ -310,29 +310,29 @@ discard block |
||
| 310 | 310 | $ipuid['uid']['count']++; //number of unique uids |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 314 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 313 | + if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 314 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 315 | 315 | if (!in_array($uid,$ipuid['ip']["$ip"])) |
| 316 | 316 | $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
| 317 | 317 | } |
| 318 | - else { |
|
| 319 | - $ipuid['ip']["$ip"]['count'] = 1; |
|
| 318 | + else { |
|
| 319 | + $ipuid['ip']["$ip"]['count'] = 1; |
|
| 320 | 320 | $ipuid['ip']["$ip"][]=$uid; |
| 321 | 321 | $ipuid['ip']['count']++; //number of unique ips |
| 322 | - } |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /* Update HTML report */ |
|
| 325 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 324 | + /* Update HTML report */ |
|
| 325 | + fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 326 | 326 | } |
| 327 | - else { /* Bad learn */ |
|
| 327 | + else { /* Bad learn */ |
|
| 328 | 328 | |
| 329 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 330 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 331 | - else { |
|
| 332 | - $uidbad['uid']["$uid"]['count'] = 1; |
|
| 329 | + if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 330 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 331 | + else { |
|
| 332 | + $uidbad['uid']["$uid"]['count'] = 1; |
|
| 333 | 333 | $uidbad['uid']["$uid"][]=$uid; |
| 334 | - $uidbad['count']++; //numeber of unique bad uids |
|
| 335 | - } |
|
| 334 | + $uidbad['count']++; //numeber of unique bad uids |
|
| 335 | + } |
|
| 336 | 336 | /* The reason of bad report */ |
| 337 | 337 | if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
| 338 | 338 | if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
@@ -354,17 +354,17 @@ discard block |
||
| 354 | 354 | fwrite($fp, '</table>'); |
| 355 | 355 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>' ); |
| 356 | 356 | |
| 357 | - /* Make MYSQL connection */ |
|
| 357 | + /* Make MYSQL connection */ |
|
| 358 | 358 | if ( $cf['onlyReport'] ) |
| 359 | 359 | $mysqli = NULL; |
| 360 | 360 | else { |
| 361 | - $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
|
| 362 | - if ($mysqli->connect_error) { |
|
| 363 | - syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 364 | - . $mysqli->connect_error); |
|
| 365 | - exit (254); |
|
| 366 | - } |
|
| 367 | - syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 361 | + $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
|
| 362 | + if ($mysqli->connect_error) { |
|
| 363 | + syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 364 | + . $mysqli->connect_error); |
|
| 365 | + exit (254); |
|
| 366 | + } |
|
| 367 | + syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 368 | 368 | } |
| 369 | 369 | /***********************/ |
| 370 | 370 | |
@@ -384,8 +384,8 @@ discard block |
||
| 384 | 384 | foreach ( $ierr as $thiserr ) |
| 385 | 385 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 386 | 386 | if ( $ierr = imap_alerts() ) |
| 387 | - foreach ( $ierr as $thiserr ) |
|
| 388 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 387 | + foreach ( $ierr as $thiserr ) |
|
| 388 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 389 | 389 | imap_close($m_mail); |
| 390 | 390 | } |
| 391 | 391 | ?> |
@@ -205,6 +205,11 @@ discard block |
||
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
| 208 | +/** |
|
| 209 | + * @param integer $id |
|
| 210 | + * @param string $what |
|
| 211 | + * @param boolean $lock |
|
| 212 | + */ |
|
| 208 | 213 | function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
| 209 | 214 | |
| 210 | 215 | $whynot=NULL; |
@@ -404,6 +409,9 @@ discard block |
||
| 404 | 409 | } |
| 405 | 410 | |
| 406 | 411 | |
| 412 | +/** |
|
| 413 | + * @param string $reason |
|
| 414 | + */ |
|
| 407 | 415 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
| 408 | 416 | |
| 409 | 417 | /* Search and list value */ |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 7 | + else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | + else $user='unknown'; |
|
| 9 | 9 | return $user; |
| 10 | 10 | } |
| 11 | 11 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | case 'network': |
| 37 | 37 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 38 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 38 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 39 | 39 | `$type` , |
| 40 | 40 | `netmask`, |
| 41 | 41 | `date` , |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 49 | 49 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 50 | 50 | )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
| 51 | - break; |
|
| 51 | + break; |
|
| 52 | 52 | |
| 53 | 53 | default: |
| 54 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 54 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 55 | 55 | `$type` , |
| 56 | 56 | `date` , |
| 57 | 57 | `exp` , |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ($myconn->query($query) === TRUE) { |
| 69 | - syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 70 | - $result=TRUE; |
|
| 69 | + syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 70 | + $result=TRUE; |
|
| 71 | 71 | } |
| 72 | 72 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 73 | 73 | return $result; |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | $result=FALSE; |
| 79 | 79 | |
| 80 | - switch ($type) { |
|
| 80 | + switch ($type) { |
|
| 81 | 81 | case 'ip': |
| 82 | - $query= sprintf("UPDATE `$table` SET |
|
| 82 | + $query= sprintf("UPDATE `$table` SET |
|
| 83 | 83 | `active` = '1', |
| 84 | 84 | `user` = '%s', |
| 85 | 85 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | `reason` = '%s' |
| 88 | 88 | WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
| 89 | 89 | break; |
| 90 | - case 'network': |
|
| 90 | + case 'network': |
|
| 91 | 91 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 92 | - $query= sprintf("UPDATE `$table` SET |
|
| 92 | + $query= sprintf("UPDATE `$table` SET |
|
| 93 | 93 | `active` = '1', |
| 94 | 94 | `user` = '%s', |
| 95 | 95 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); |
| 99 | 99 | break; |
| 100 | 100 | default: |
| 101 | - $query= sprintf("UPDATE `$table` SET |
|
| 101 | + $query= sprintf("UPDATE `$table` SET |
|
| 102 | 102 | `active` = '1', |
| 103 | 103 | `user` = '%s', |
| 104 | 104 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -107,18 +107,18 @@ discard block |
||
| 107 | 107 | WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ($myconn->query($query) === TRUE) { |
|
| 111 | - syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
|
| 110 | + if ($myconn->query($query) === TRUE) { |
|
| 111 | + syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
|
| 112 | 112 | $result=TRUE; |
| 113 | - } |
|
| 114 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 113 | + } |
|
| 114 | + else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 115 | 115 | return $result; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | function remove ($myconn,$user,$value,$type,$table) { |
| 119 | 119 | |
| 120 | - switch ($type) { |
|
| 121 | - case 'ip': |
|
| 120 | + switch ($type) { |
|
| 121 | + case 'ip': |
|
| 122 | 122 | $query = sprintf("DELETE FROM `$table` WHERE |
| 123 | 123 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
| 124 | 124 | break; |
@@ -134,18 +134,18 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
| 137 | - if ($return=$myconn->query($query) === TRUE) |
|
| 138 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 139 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 137 | + if ($return=$myconn->query($query) === TRUE) |
|
| 138 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 139 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 140 | 140 | |
| 141 | - return $return; |
|
| 141 | + return $return; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
| 145 | 145 | function changestatus ($myconn,$user,$value,$status,$type,$table) { |
| 146 | 146 | |
| 147 | 147 | switch ($type) { |
| 148 | - case 'ip': |
|
| 148 | + case 'ip': |
|
| 149 | 149 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
| 150 | 150 | break; |
| 151 | 151 | case 'network': |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ($return=$myconn->query($query) === TRUE) { |
|
| 160 | - syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 161 | - } |
|
| 162 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 159 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 160 | + syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 161 | + } |
|
| 162 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 163 | 163 | return $return; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
| 167 | 167 | function expire ($myconn,$user,$tables,$expireTime) { |
| 168 | - $return=TRUE; |
|
| 168 | + $return=TRUE; |
|
| 169 | 169 | $log=array(); |
| 170 | 170 | $desc = array_keys($tables); |
| 171 | 171 | foreach ($desc as $tdesc) { |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | /* END OF QUERY */ |
| 176 | 176 | $log[0] = 'expired for'; |
| 177 | 177 | $log[1] = 'disabled for'; |
| 178 | - if ($myconn->multi_query($query)) { |
|
| 178 | + if ($myconn->multi_query($query)) { |
|
| 179 | 179 | $j = 0; |
| 180 | 180 | do { |
| 181 | - $numdel = $myconn->affected_rows; |
|
| 182 | - syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 181 | + $numdel = $myconn->affected_rows; |
|
| 182 | + syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 183 | 183 | $j++; |
| 184 | 184 | |
| 185 | 185 | } while ($myconn->next_result()); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
| 193 | 193 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
| 194 | - return $return; |
|
| 194 | + return $return; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | if ( $entry->num_rows ) { |
| 234 | 234 | if ( $entry->num_rows == 1 ) { |
| 235 | 235 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 236 | - if (isListed($riga)) { |
|
| 236 | + if (isListed($riga)) { |
|
| 237 | 237 | $warn = "<$value> is already present in <$listdep> list!"; |
| 238 | 238 | $entry->free(); |
| 239 | 239 | return FALSE; |
@@ -250,28 +250,28 @@ discard block |
||
| 250 | 250 | function searchentry ($myconn,$value,$tablelist) { |
| 251 | 251 | /* Make a MYSQL query and return result */ |
| 252 | 252 | |
| 253 | - $type = $tablelist['field']; |
|
| 254 | - $table = $tablelist['name']; |
|
| 255 | - |
|
| 256 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 257 | - else { |
|
| 258 | - switch ($type) { |
|
| 259 | - case 'ip': |
|
| 260 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 261 | - break; |
|
| 262 | - case 'network': |
|
| 263 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 264 | - $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; |
|
| 265 | - break; |
|
| 266 | - default: |
|
| 267 | - $query= "select * from $table where $type = '$value'"; |
|
| 268 | - } |
|
| 269 | - } |
|
| 253 | + $type = $tablelist['field']; |
|
| 254 | + $table = $tablelist['name']; |
|
| 255 | + |
|
| 256 | + if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 257 | + else { |
|
| 258 | + switch ($type) { |
|
| 259 | + case 'ip': |
|
| 260 | + $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 261 | + break; |
|
| 262 | + case 'network': |
|
| 263 | + list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 264 | + $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; |
|
| 265 | + break; |
|
| 266 | + default: |
|
| 267 | + $query= "select * from $table where $type = '$value'"; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | $result = $myconn->query($query); |
| 272 | 272 | if($result === false) |
| 273 | 273 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 274 | - return $result; |
|
| 274 | + return $result; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | function countListed ($myconn,$table) { |
@@ -286,10 +286,10 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | |
| 288 | 288 | function isFull($myconn,$typedesc,$alltables) { |
| 289 | - if (isset($alltables["$typedesc"]['limit'])) { |
|
| 290 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) |
|
| 291 | - return TRUE; |
|
| 292 | - } |
|
| 289 | + if (isset($alltables["$typedesc"]['limit'])) { |
|
| 290 | + if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) |
|
| 291 | + return TRUE; |
|
| 292 | + } |
|
| 293 | 293 | return FALSE; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -302,14 +302,14 @@ discard block |
||
| 302 | 302 | if ($result) { |
| 303 | 303 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 304 | 304 | |
| 305 | - /* Check for limit in number of listed items */ |
|
| 305 | + /* Check for limit in number of listed items */ |
|
| 306 | 306 | $full = isFull($myconn,$typedesc,$tables); |
| 307 | 307 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
| 308 | 308 | |
| 309 | 309 | if ($result->num_rows) { |
| 310 | 310 | print '<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><th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 311 | 311 | $i=0; |
| 312 | - while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 312 | + while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 313 | 313 | if (isListed($riga)) { |
| 314 | 314 | if ($tables["$typedesc"]['bl']) $listed='Listed'; |
| 315 | 315 | else $listed='WhiteListed'; |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | $element = $riga["$type"]; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - 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", $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)); |
|
| 331 | + 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", $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)); |
|
| 332 | 332 | $i++; |
| 333 | - } |
|
| 333 | + } |
|
| 334 | 334 | print '</tbody></table>'; |
| 335 | 335 | } |
| 336 | 336 | else { |
@@ -348,15 +348,15 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
| 350 | 350 | $now = time(); |
| 351 | - setlocale (LC_TIME, 'it_IT'); |
|
| 352 | - $date = date("r",$now); |
|
| 351 | + setlocale (LC_TIME, 'it_IT'); |
|
| 352 | + $date = date("r",$now); |
|
| 353 | 353 | $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; |
| 354 | 354 | $mua = 'PHP/' . phpversion(); |
| 355 | 355 | |
| 356 | 356 | /* Parsing headers */ |
| 357 | 357 | if (!file_exists($tplf['header'])) { |
| 358 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 359 | - exit; |
|
| 358 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 359 | + exit; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | $head_tmpl = file_get_contents($tplf['header']); |
@@ -365,35 +365,35 @@ discard block |
||
| 365 | 365 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 366 | 366 | $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
| 367 | 367 | |
| 368 | - /* Parsing body */ |
|
| 368 | + /* Parsing body */ |
|
| 369 | 369 | |
| 370 | - if (!file_exists($tplf['body'])) { |
|
| 371 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 372 | - exit; |
|
| 373 | - } |
|
| 370 | + if (!file_exists($tplf['body'])) { |
|
| 371 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 372 | + exit; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - $body_tmpl = file_get_contents($tplf['body']); |
|
| 376 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 377 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 378 | - $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 379 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 375 | + $body_tmpl = file_get_contents($tplf['body']); |
|
| 376 | + $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 377 | + $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 378 | + $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 379 | + $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 380 | 380 | $body = wordwrap ( $body, 75 , "\r\n" ); |
| 381 | 381 | |
| 382 | 382 | /* Send the mail! */ |
| 383 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 384 | - $old_mailfrom = ini_get("sendmail_from"); |
|
| 385 | - ini_set("sendmail_from", $from); |
|
| 386 | - $params = sprintf("-oi -f %s", '<>'); |
|
| 387 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 388 | - else $flag=TRUE; |
|
| 389 | - if (isset($old_mailfrom)) |
|
| 390 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 391 | - } |
|
| 392 | - else { |
|
| 393 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 394 | - else $flag=TRUE; |
|
| 395 | - } |
|
| 396 | - return $flag; |
|
| 383 | + if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 384 | + $old_mailfrom = ini_get("sendmail_from"); |
|
| 385 | + ini_set("sendmail_from", $from); |
|
| 386 | + $params = sprintf("-oi -f %s", '<>'); |
|
| 387 | + if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 388 | + else $flag=TRUE; |
|
| 389 | + if (isset($old_mailfrom)) |
|
| 390 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 391 | + } |
|
| 392 | + else { |
|
| 393 | + if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 394 | + else $flag=TRUE; |
|
| 395 | + } |
|
| 396 | + return $flag; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | function emailToNotify($notify_file,$dom) { |
@@ -407,59 +407,59 @@ discard block |
||
| 407 | 407 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
| 408 | 408 | |
| 409 | 409 | /* Search and list value */ |
| 410 | - $type = $tables["$typedesc"]['field']; |
|
| 411 | - $table = $tables["$typedesc"]['name']; |
|
| 412 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 413 | - |
|
| 414 | - /* Manage abnormal conditions */ |
|
| 415 | - /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 416 | - if ($result->num_rows > 1) { |
|
| 417 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 418 | - $result->free(); |
|
| 419 | - return FALSE; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /* Value already present in db or not present: to list anyway */ |
|
| 423 | - if ($result->num_rows >= 0) { |
|
| 424 | - /* First, check for limit in number of listed items */ |
|
| 425 | - if (isFull($myconn,$typedesc,$tables)) { |
|
| 426 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 427 | - $result->free(); |
|
| 428 | - return FALSE; |
|
| 429 | - } |
|
| 430 | - /* Second, check if the (re)list would be consistent now */ |
|
| 431 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 432 | - syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 433 | - $result->free(); |
|
| 434 | - return FALSE; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - /* End of abnormal conditions */ |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /* Finally, here I can list the value! */ |
|
| 410 | + $type = $tables["$typedesc"]['field']; |
|
| 411 | + $table = $tables["$typedesc"]['name']; |
|
| 412 | + $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 413 | + |
|
| 414 | + /* Manage abnormal conditions */ |
|
| 415 | + /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 416 | + if ($result->num_rows > 1) { |
|
| 417 | + syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 418 | + $result->free(); |
|
| 419 | + return FALSE; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /* Value already present in db or not present: to list anyway */ |
|
| 423 | + if ($result->num_rows >= 0) { |
|
| 424 | + /* First, check for limit in number of listed items */ |
|
| 425 | + if (isFull($myconn,$typedesc,$tables)) { |
|
| 426 | + syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 427 | + $result->free(); |
|
| 428 | + return FALSE; |
|
| 429 | + } |
|
| 430 | + /* Second, check if the (re)list would be consistent now */ |
|
| 431 | + if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 432 | + syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 433 | + $result->free(); |
|
| 434 | + return FALSE; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + /* End of abnormal conditions */ |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /* Finally, here I can list the value! */ |
|
| 441 | 441 | $thisentry = $result->fetch_array(MYSQLI_ASSOC); |
| 442 | - switch ($result->num_rows) { |
|
| 443 | - /* Relist value if already present */ |
|
| 444 | - case 1: |
|
| 445 | - /* Entry already listed */ |
|
| 446 | - if ( isListed($thisentry) ) { |
|
| 447 | - syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
|
| 448 | - $result->free(); |
|
| 449 | - return FALSE; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /* Entry delisted */ |
|
| 453 | - $result->free(); |
|
| 442 | + switch ($result->num_rows) { |
|
| 443 | + /* Relist value if already present */ |
|
| 444 | + case 1: |
|
| 445 | + /* Entry already listed */ |
|
| 446 | + if ( isListed($thisentry) ) { |
|
| 447 | + syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
|
| 448 | + $result->free(); |
|
| 449 | + return FALSE; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /* Entry delisted */ |
|
| 453 | + $result->free(); |
|
| 454 | 454 | $quantity *= $thisentry['nlist']; |
| 455 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 455 | + return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 456 | 456 | |
| 457 | 457 | |
| 458 | - /* First time list value */ |
|
| 459 | - case 0: |
|
| 460 | - $result->free(); |
|
| 461 | - return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 462 | - } |
|
| 458 | + /* First time list value */ |
|
| 459 | + case 0: |
|
| 460 | + $result->free(); |
|
| 461 | + return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 462 | + } |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | |