| @@ -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 string|false $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"])AND($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 | /* | 
| @@ -190,38 +190,38 @@ discard block | ||
| 190 | 190 | // Use the built-in XML parser to display the job results | 
| 191 | 191 | foreach ($resultSearch as $result) | 
| 192 | 192 |  	  { | 
| 193 | - if ($result instanceof Splunk_ResultsFieldOrder) | |
| 194 | -	    { | |
| 195 | - // More than one field attribute returned by search | |
| 196 | - // You must redefine the search | |
| 197 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; | |
| 198 | - } | |
| 199 | - else if ($result instanceof Splunk_ResultsMessage) | |
| 200 | -	    { | |
| 201 | - // I don't want messages in my search | |
| 202 | - return FALSE; | |
| 203 | - } | |
| 204 | - else if (is_array($result)) | |
| 205 | -	    { | |
| 206 | - // Process a row | |
| 207 | - foreach ($result as $key => $valueOrValues) | |
| 208 | -	        { | |
| 209 | - if (is_array($valueOrValues)) | |
| 210 | -	          { | |
| 211 | - return FALSE; | |
| 212 | - } | |
| 213 | - else | |
| 214 | -	          { | |
| 215 | - return $valueOrValues; | |
| 216 | -	            #print "  {$key} => {$value}\r\n"; | |
| 217 | - } | |
| 218 | - } | |
| 219 | - } | |
| 220 | - else | |
| 221 | -	    { | |
| 222 | - #print "Unknow result type"; | |
| 223 | - return FALSE; | |
| 224 | - } | |
| 193 | + if ($result instanceof Splunk_ResultsFieldOrder) | |
| 194 | +		{ | |
| 195 | + // More than one field attribute returned by search | |
| 196 | + // You must redefine the search | |
| 197 | + if ( count($result->getFieldNames()) > 1 ) return FALSE; | |
| 198 | + } | |
| 199 | + else if ($result instanceof Splunk_ResultsMessage) | |
| 200 | +		{ | |
| 201 | + // I don't want messages in my search | |
| 202 | + return FALSE; | |
| 203 | + } | |
| 204 | + else if (is_array($result)) | |
| 205 | +		{ | |
| 206 | + // Process a row | |
| 207 | + foreach ($result as $key => $valueOrValues) | |
| 208 | +			{ | |
| 209 | + if (is_array($valueOrValues)) | |
| 210 | +			  { | |
| 211 | + return FALSE; | |
| 212 | + } | |
| 213 | + else | |
| 214 | +			  { | |
| 215 | + return $valueOrValues; | |
| 216 | +				#print "  {$key} => {$value}\r\n"; | |
| 217 | + } | |
| 218 | + } | |
| 219 | + } | |
| 220 | + else | |
| 221 | +		{ | |
| 222 | + #print "Unknow result type"; | |
| 223 | + return FALSE; | |
| 224 | + } | |
| 225 | 225 | } | 
| 226 | 226 | } | 
| 227 | 227 | |
| @@ -230,26 +230,26 @@ discard block | ||
| 230 | 230 | $file = dirname(__FILE__) . '/' . $cf['reportFile']["$type"]; | 
| 231 | 231 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; | 
| 232 | 232 |  	$m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) | 
| 233 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); | |
| 233 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); | |
| 234 | 234 | if ( !$m_mail ) exit(254); | 
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); | 
| 238 | 238 | //get all messages | 
| 239 | 239 | $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); | 
| 240 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); | |
| 241 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); | |
| 240 | + $dateN = date ( "d-M-Y", strToTime ( "now" ) ); | |
| 241 | + $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); | |
| 242 | 242 | |
| 243 | 243 | |
| 244 | 244 | // Order results starting from newest message | 
| 245 | 245 |  	if (!$m_search) { | 
| 246 | 246 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); | 
| 247 | - if ( $ierr = imap_errors() ) | |
| 248 | - foreach ( $ierr as $thiserr ) | |
| 249 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | |
| 250 | - if ( $ierr = imap_alerts() ) | |
| 251 | - foreach ( $ierr as $thiserr ) | |
| 252 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 247 | + if ( $ierr = imap_errors() ) | |
| 248 | + foreach ( $ierr as $thiserr ) | |
| 249 | + syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | |
| 250 | + if ( $ierr = imap_alerts() ) | |
| 251 | + foreach ( $ierr as $thiserr ) | |
| 252 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 253 | 253 | imap_close( $m_mail ); | 
| 254 | 254 | if ( file_exists( $file ) ) unlink ($file); | 
| 255 | 255 | if ( file_exists( $fileb ) ) unlink ($fileb); | 
| @@ -280,16 +280,16 @@ discard block | ||
| 280 | 280 | $uidbad['count'] = 0; | 
| 281 | 281 | $uidbad['uid'] = array(); | 
| 282 | 282 | |
| 283 | - // loop for each message | |
| 283 | + // loop for each message | |
| 284 | 284 |  	foreach ($m_search as $onem) { | 
| 285 | 285 | |
| 286 | - //get imap header info for obj thang | |
| 287 | - //$headers = imap_headerinfo($m_mail, $onem); | |
| 288 | - //$head = imap_fetchheader($m_mail, $headers->Msgno); | |
| 286 | + //get imap header info for obj thang | |
| 287 | + //$headers = imap_headerinfo($m_mail, $onem); | |
| 288 | + //$head = imap_fetchheader($m_mail, $headers->Msgno); | |
| 289 | 289 | $head = imap_fetchheader($m_mail, $onem ); | 
| 290 | - //$obj = imap_rfc822_parse_headers( $head); | |
| 290 | + //$obj = imap_rfc822_parse_headers( $head); | |
| 291 | 291 | |
| 292 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); | |
| 292 | + list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); | |
| 293 | 293 |  		if (empty($mid)) { | 
| 294 | 294 | $uid='NA'; | 
| 295 | 295 | syslog (LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); | 
| @@ -304,11 +304,11 @@ discard block | ||
| 304 | 304 | } | 
| 305 | 305 | } | 
| 306 | 306 | |
| 307 | - /* Update count of each ip */ | |
| 308 | -	        if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers  and learned by valid uid */ | |
| 307 | + /* Update count of each ip */ | |
| 308 | +			if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers  and learned by valid uid */ | |
| 309 | 309 | $ipuid['count']++; //number of right messages | 
| 310 | 310 | |
| 311 | -	                if (in_array($uid,array_keys($ipuid['uid']))) { | |
| 311 | +					if (in_array($uid,array_keys($ipuid['uid']))) { | |
| 312 | 312 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid | 
| 313 | 313 | if (!in_array($ip,$ipuid['uid']["$uid"])) | 
| 314 | 314 | $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid | 
| @@ -319,29 +319,29 @@ discard block | ||
| 319 | 319 | $ipuid['uid']['count']++; //number of unique uids | 
| 320 | 320 | } | 
| 321 | 321 | |
| 322 | -                        if (in_array($ip,array_keys($ipuid['ip']))) { | |
| 323 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | |
| 322 | +						if (in_array($ip,array_keys($ipuid['ip']))) { | |
| 323 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | |
| 324 | 324 | if (!in_array($uid,$ipuid['ip']["$ip"])) | 
| 325 | 325 | $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip | 
| 326 | 326 | } | 
| 327 | -                        else { | |
| 328 | - $ipuid['ip']["$ip"]['count'] = 1; | |
| 327 | +						else { | |
| 328 | + $ipuid['ip']["$ip"]['count'] = 1; | |
| 329 | 329 | $ipuid['ip']["$ip"][]=$uid; | 
| 330 | 330 | $ipuid['ip']['count']++; //number of unique ips | 
| 331 | - } | |
| 331 | + } | |
| 332 | 332 | |
| 333 | - /* Update HTML report */ | |
| 334 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); | |
| 333 | + /* Update HTML report */ | |
| 334 | + fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); | |
| 335 | 335 | } | 
| 336 | -	        else {	/* Bad learn */ | |
| 336 | +			else {	/* Bad learn */ | |
| 337 | 337 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) | |
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 340 | -                        else { | |
| 341 | - $uidbad['uid']["$uid"]['count'] = 1; | |
| 338 | + if (in_array($uid,array_keys($uidbad['uid']))) | |
| 339 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 340 | +						else { | |
| 341 | + $uidbad['uid']["$uid"]['count'] = 1; | |
| 342 | 342 | $uidbad['uid']["$uid"][]=$uid; | 
| 343 | - $uidbad['count']++; //numeber of unique bad uids | |
| 344 | - } | |
| 343 | + $uidbad['count']++; //numeber of unique bad uids | |
| 344 | + } | |
| 345 | 345 | /* The reason of bad report */ | 
| 346 | 346 | if (!$host) $reason = 'This mail was not received by recognized MX host'; | 
| 347 | 347 | if (!$dateReceived) $reason = 'This mail was not submitted to recognized MSA for learn'; | 
| @@ -363,17 +363,17 @@ discard block | ||
| 363 | 363 | fwrite($fp, '</table>'); | 
| 364 | 364 | 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>' ); | 
| 365 | 365 | |
| 366 | - /* Make MYSQL connection */ | |
| 366 | + /* Make MYSQL connection */ | |
| 367 | 367 | if ( $cf['onlyReport'] ) | 
| 368 | 368 | $mysqli = NULL; | 
| 369 | 369 |  	else { | 
| 370 | - $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); | |
| 371 | -        	if ($mysqli->connect_error) { | |
| 372 | -                	syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 373 | - . $mysqli->connect_error); | |
| 374 | - exit (254); | |
| 375 | - } | |
| 376 | - syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; | |
| 370 | + $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); | |
| 371 | +			if ($mysqli->connect_error) { | |
| 372 | +					syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 373 | + . $mysqli->connect_error); | |
| 374 | + exit (254); | |
| 375 | + } | |
| 376 | + syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; | |
| 377 | 377 | } | 
| 378 | 378 | /***********************/ | 
| 379 | 379 | |
| @@ -393,8 +393,8 @@ discard block | ||
| 393 | 393 | foreach ( $ierr as $thiserr ) | 
| 394 | 394 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | 
| 395 | 395 | if ( $ierr = imap_alerts() ) | 
| 396 | - foreach ( $ierr as $thiserr ) | |
| 397 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 396 | + foreach ( $ierr as $thiserr ) | |
| 397 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 398 | 398 | imap_close($m_mail); | 
| 399 | 399 | } | 
| 400 | 400 | ?> | 
| @@ -1,5 +1,5 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -function getIP($header,$mxserver,$msa) { | |
| 2 | +function getIP($header, $mxserver, $msa) { | |
| 3 | 3 | /* Get submission server's IP from header's mail */ | 
| 4 | 4 | /* Each line must end with /r/n */ | 
| 5 | 5 | /* IP is the first one written by your mxserver */ | 
| @@ -7,10 +7,10 @@ discard block | ||
| 7 | 7 | $ip = FALSE; | 
| 8 | 8 | $host = FALSE; | 
| 9 | 9 | $dateR = FALSE; | 
| 10 | -	if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) { | |
| 11 | -		for ($i = count($received[0])-1;$i>=0;$i--) { | |
| 10 | +	if (preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m', $header, $received)) { | |
| 11 | +		for ($i = count($received[0])-1; $i>=0; $i--) { | |
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; | 
| 13 | - if ( preg_match($msa,$received['host'][$i]) ) | |
| 13 | + if (preg_match($msa, $received['host'][$i])) | |
| 14 | 14 | $dateR = $received['date'][$i]; | 
| 15 | 15 |          		foreach ($mxserver as $mx) { | 
| 16 | 16 | if (!$ip) | 
| @@ -21,38 +21,38 @@ discard block | ||
| 21 | 21 | } | 
| 22 | 22 | } | 
| 23 | 23 | } | 
| 24 | -	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) | |
| 24 | +	if (preg_match('/\r\nDate:\s(?P<date>.*)\r\n/', $header, $dateC) != 1) | |
| 25 | 25 | $dateC['date'] = 'Not found'; | 
| 26 | -	if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) | |
| 26 | +	if (preg_match('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/', $header, $mid) != 1) | |
| 27 | 27 | $mid['mid'] = NULL; | 
| 28 | - return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); | |
| 28 | + return array($ip, $host, $dateR, $dateC['date'], $mid['mid']); | |
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | -function updateReport ($ip,$uid,$ipcount,$uidcount,$hostname,$dateC,$msgid,$dateL) { | |
| 31 | +function updateReport($ip, $uid, $ipcount, $uidcount, $hostname, $dateC, $msgid, $dateL) { | |
| 32 | 32 | |
| 33 | -	return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td><td>%s</td><td>%s</td></tr>'."\n",$dateL,$dateC,$uid,$ip,$uidcount,$ipcount,$hostname,htmlentities($msgid) ); | |
| 33 | +	return sprintf('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td><td>%s</td><td>%s</td></tr>'."\n", $dateL, $dateC, $uid, $ip, $uidcount, $ipcount, $hostname, htmlentities($msgid)); | |
| 34 | 34 | } | 
| 35 | 35 | |
| 36 | -function updatebadReport ( $uid,$dateC,$msgid,$dateL,$text ) { | |
| 37 | -	return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td nowrap>%s</td></tr>'."\n",$dateL,$dateC,$uid,htmlentities($msgid),$text ); | |
| 36 | +function updatebadReport($uid, $dateC, $msgid, $dateL, $text) { | |
| 37 | +	return sprintf('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td nowrap>%s</td></tr>'."\n", $dateL, $dateC, $uid, htmlentities($msgid), $text); | |
| 38 | 38 | } | 
| 39 | 39 | |
| 40 | 40 | |
| 41 | -function summaryBadReport ($uidvet) { | |
| 41 | +function summaryBadReport($uidvet) { | |
| 42 | 42 | $nuid = $uidvet['count']; | 
| 43 | - if ( empty($uidvet) ) return NULL; | |
| 43 | + if (empty($uidvet)) return NULL; | |
| 44 | 44 | $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; | 
| 45 | 45 | |
| 46 | 46 | /* Remove count index */ | 
| 47 | 47 | $uids = array_keys($uidvet['uid']); | 
| 48 | 48 | $totlearn = 0; | 
| 49 | 49 | |
| 50 | -        foreach ( $uids as $uid ) { | |
| 51 | - $totlearn += $uidvet['uid']["$uid"]['count'];; | |
| 52 | -		$return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']); | |
| 50 | +        foreach ($uids as $uid) { | |
| 51 | + $totlearn += $uidvet['uid']["$uid"]['count']; ; | |
| 52 | +		$return .= sprintf('<tr><td>%s</td><td>%u</td></tr>', $uid, $uidvet['uid']["$uid"]['count']); | |
| 53 | 53 | } | 
| 54 | -	$return .= sprintf ('<tr><th>%s</th><th>%u</th></tr></table>','TOT',$totlearn); | |
| 55 | -	$return .= sprintf ('<p>%s : %u</p>','Unique UID',$nuid); | |
| 54 | +	$return .= sprintf('<tr><th>%s</th><th>%u</th></tr></table>', 'TOT', $totlearn); | |
| 55 | +	$return .= sprintf('<p>%s : %u</p>', 'Unique UID', $nuid); | |
| 56 | 56 | |
| 57 | 57 | return $return; | 
| 58 | 58 | } | 
| @@ -69,12 +69,12 @@ discard block | ||
| 69 | 69 |      foreach ($cols as $col => $order) { | 
| 70 | 70 | $eval .= '$colarr[\''.$col.'\'],'.$order.','; | 
| 71 | 71 | } | 
| 72 | - $eval = substr($eval,0,-1).');'; | |
| 72 | + $eval = substr($eval, 0, -1).');'; | |
| 73 | 73 | eval($eval); | 
| 74 | 74 | $ret = array(); | 
| 75 | 75 |      foreach ($colarr as $col => $arr) { | 
| 76 | 76 |          foreach ($arr as $k => $v) { | 
| 77 | - $k = substr($k,1); | |
| 77 | + $k = substr($k, 1); | |
| 78 | 78 | if (!isset($ret[$k])) $ret[$k] = $array[$k]; | 
| 79 | 79 | if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; | 
| 80 | 80 | } | 
| @@ -84,28 +84,28 @@ discard block | ||
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | 86 | |
| 87 | -function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { | |
| 87 | +function summaryReportAndList($cf, $myconn, $tables, $category, $ipvet) { | |
| 88 | 88 | $nips = $ipvet['count']; | 
| 89 | 89 | |
| 90 | - if ( empty($ipvet) ) return NULL; | |
| 90 | + if (empty($ipvet)) return NULL; | |
| 91 | 91 | $return = '<h3>Statistics by IP</h3><table><tr><th>IP</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this ip is currently listed, but it says if this IP has listed now!">Listed Now</th></tr>'."\n"; | 
| 92 | 92 | |
| 93 | 93 | $ips = array_keys($ipvet['ip']); | 
| 94 | 94 | |
| 95 | -	foreach ( $ips as $ip ) { | |
| 96 | - if ( $ip == 'count' ) continue; | |
| 95 | +	foreach ($ips as $ip) { | |
| 96 | + if ($ip == 'count') continue; | |
| 97 | 97 | $nlearn = $ipvet['ip']["$ip"]['count']; | 
| 98 | 98 | unset($ipvet['ip']["$ip"]['count']); | 
| 99 | 99 | $nuid = count($ipvet['ip']["$ip"]); | 
| 100 | -		if ( !$cf['onlyReport'] ) { | |
| 101 | -			if ( ($nlearn >= $cf['thresholdip']["$category"])AND($nuid >= $cf['thresholduid']["$category"]) ) { | |
| 100 | +		if (!$cf['onlyReport']) { | |
| 101 | +			if (($nlearn>=$cf['thresholdip']["$category"]) AND ($nuid>=$cf['thresholduid']["$category"])) { | |
| 102 | 102 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; | 
| 103 | - $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$cf['quantity']["$category"],$reason); | |
| 103 | + $listed = searchAndList($myconn, $cf['user'], $tables, $cf['list']["$category"], $ip, $cf['unit']["$category"], $cf['quantity']["$category"], $reason); | |
| 104 | 104 | } | 
| 105 | 105 | else $listed = FALSE; | 
| 106 | 106 | } | 
| 107 | 107 | else $listed = FALSE; | 
| 108 | - $nowlist = array( TRUE => array( | |
| 108 | + $nowlist = array(TRUE => array( | |
| 109 | 109 | 'style' => 'id=\'ipfound\'', | 
| 110 | 110 | 'name' => 'YES', | 
| 111 | 111 | ), | 
| @@ -119,45 +119,45 @@ discard block | ||
| 119 | 119 | ) | 
| 120 | 120 | ); | 
| 121 | 121 | |
| 122 | - $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; | |
| 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 | - $rowuid=NULL; | |
| 125 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 122 | + $return .= '<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; | |
| 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 | + $rowuid = NULL; | |
| 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 | -	$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); | |
| 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); | |
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | /* Statistics by UID */ | 
| 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 ) { | |
| 138 | - if ( $uid == 'count' ) continue; | |
| 137 | +        foreach ($uids as $uid) { | |
| 138 | + if ($uid == 'count') continue; | |
| 139 | 139 | $nlearn = $ipvet['uid']["$uid"]['count']; | 
| 140 | - unset ( $ipvet['uid']["$uid"]['count'] ); | |
| 140 | + unset ($ipvet['uid']["$uid"]['count']); | |
| 141 | 141 | $nip = count($ipvet['uid']["$uid"]); | 
| 142 | - $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; | |
| 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>'; | |
| 142 | + $return .= '<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; | |
| 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 | 146 | array_shift($ipvet['uid']["$uid"]); | 
| 147 | - $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); | |
| 147 | + $return .= vsprintf($rowuid, $ipvet['uid']["$uid"]); | |
| 148 | 148 | |
| 149 | 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);	 | |
| 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; | 
| 154 | 154 | } | 
| 155 | 155 | |
| 156 | 156 | |
| 157 | -function splunksearch ($service,$message_id,$date) { | |
| 157 | +function splunksearch($service, $message_id, $date) { | |
| 158 | 158 | |
| 159 | 159 | // Run a blocking search | 
| 160 | - $searchQueryBlocking = 'search (message_id="'. addslashes( $message_id ) . | |
| 160 | + $searchQueryBlocking = 'search (message_id="'.addslashes($message_id). | |
| 161 | 161 | '" OR sasl_username) | transaction message_id queue_id maxspan=3m maxpause=2m | search sasl_username message_id=* | table sasl_username'; | 
| 162 | 162 | |
| 163 | 163 | |
| @@ -165,8 +165,8 @@ discard block | ||
| 165 | 165 | /* Wait to finish */ | 
| 166 | 166 | $job = $service->getJobs()->create($searchQueryBlocking, array( | 
| 167 | 167 | 'exec_mode' => 'blocking', | 
| 168 | -	    'earliest_time' => date("c",strtotime ($date)-120), | |
| 169 | -	    'latest_time' => date("c",strtotime ($date)+60) | |
| 168 | +	    'earliest_time' => date("c", strtotime($date)-120), | |
| 169 | +	    'latest_time' => date("c", strtotime($date)+60) | |
| 170 | 170 | )); | 
| 171 | 171 | |
| 172 | 172 | /* | 
| @@ -194,7 +194,7 @@ discard block | ||
| 194 | 194 |  	    { | 
| 195 | 195 | // More than one field attribute returned by search | 
| 196 | 196 | // You must redefine the search | 
| 197 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; | |
| 197 | + if (count($result->getFieldNames())>1) return FALSE; | |
| 198 | 198 | } | 
| 199 | 199 | else if ($result instanceof Splunk_ResultsMessage) | 
| 200 | 200 |  	    { | 
| @@ -226,51 +226,51 @@ discard block | ||
| 226 | 226 | } | 
| 227 | 227 | |
| 228 | 228 | |
| 229 | -function imapReport ($cf,$myconnArray,$splunkconn,$tables,$type) { | |
| 230 | - $file = dirname(__FILE__) . '/' . $cf['reportFile']["$type"]; | |
| 231 | - $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; | |
| 232 | -	$m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) | |
| 233 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); | |
| 234 | - if ( !$m_mail ) exit(254); | |
| 229 | +function imapReport($cf, $myconnArray, $splunkconn, $tables, $type) { | |
| 230 | + $file = dirname(__FILE__).'/'.$cf['reportFile']["$type"]; | |
| 231 | + $fileb = dirname(__FILE__).'/'.$cf['badreportFile']["$type"]; | |
| 232 | +	$m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'], $cf['authpassword'], OP_READONLY) | |
| 233 | + or syslog(LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: '.imap_last_error()); | |
| 234 | + if (!$m_mail) exit(254); | |
| 235 | 235 | |
| 236 | 236 | |
| 237 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); | |
| 237 | + syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); | |
| 238 | 238 | //get all messages | 
| 239 | - $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); | |
| 240 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); | |
| 241 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); | |
| 239 | +	$dateTh = date("d-M-Y", strToTime('-'.$cf['oldestday'].' days')); | |
| 240 | +        $dateN = date("d-M-Y", strToTime("now")); | |
| 241 | + $m_search = imap_search($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\""); | |
| 242 | 242 | |
| 243 | 243 | |
| 244 | 244 | // Order results starting from newest message | 
| 245 | 245 |  	if (!$m_search) { | 
| 246 | - syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); | |
| 247 | - if ( $ierr = imap_errors() ) | |
| 248 | - foreach ( $ierr as $thiserr ) | |
| 249 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | |
| 250 | - if ( $ierr = imap_alerts() ) | |
| 251 | - foreach ( $ierr as $thiserr ) | |
| 252 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 253 | - imap_close( $m_mail ); | |
| 254 | - if ( file_exists( $file ) ) unlink ($file); | |
| 255 | - if ( file_exists( $fileb ) ) unlink ($fileb); | |
| 246 | + syslog(LOG_INFO, $cf['user'].": No mail found in $type folder. No reports written for $type."); | |
| 247 | + if ($ierr = imap_errors()) | |
| 248 | + foreach ($ierr as $thiserr) | |
| 249 | + syslog(LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | |
| 250 | + if ($ierr = imap_alerts()) | |
| 251 | + foreach ($ierr as $thiserr) | |
| 252 | + syslog(LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 253 | + imap_close($m_mail); | |
| 254 | + if (file_exists($file)) unlink($file); | |
| 255 | + if (file_exists($fileb)) unlink($fileb); | |
| 256 | 256 | return FALSE; | 
| 257 | 257 | } | 
| 258 | - $nmes = count ($m_search); | |
| 259 | - syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); | |
| 258 | + $nmes = count($m_search); | |
| 259 | + syslog(LOG_INFO, $cf['user'].": Found $nmes mail in $type folder."); | |
| 260 | 260 | if ($nmes>0) rsort($m_search); | 
| 261 | 261 | |
| 262 | 262 | // Create report file | 
| 263 | 263 | |
| 264 | 264 | $fp = fopen($file, 'w'); | 
| 265 | - $fpb= fopen($fileb, 'w'); | |
| 266 | -	$lastup = "Last Update: " . date ("d F Y H:i", time()); | |
| 267 | - fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); | |
| 268 | - fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); | |
| 269 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); | |
| 270 | - fwrite( $fp,'<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>' ); | |
| 271 | - fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); | |
| 272 | - fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); | |
| 273 | - fwrite( $fpb,'<table><tr><th title="taken from Received header" nowrap>Date Learn</th><th title="taken from Date header" nowrap>Date Received</th><th nowrap>UID</th><th>Message-Id</th><th title="Why is this a bad report?">Reason</th></tr>' ); | |
| 265 | + $fpb = fopen($fileb, 'w'); | |
| 266 | +	$lastup = "Last Update: ".date("d F Y H:i", time()); | |
| 267 | + fwrite($fp, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateHeader'])); | |
| 268 | + fwrite($fp, "<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>"); | |
| 269 | + if ($cf['onlyReport']) fwrite($fp, '<p>None of the below IP has been listed because listing is not active in configuration.</p>'); | |
| 270 | + fwrite($fp, '<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>'); | |
| 271 | + fwrite($fpb, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateHeader'])); | |
| 272 | + fwrite($fpb, "<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>"); | |
| 273 | + fwrite($fpb, '<table><tr><th title="taken from Received header" nowrap>Date Learn</th><th title="taken from Date header" nowrap>Date Received</th><th nowrap>UID</th><th>Message-Id</th><th title="Why is this a bad report?">Reason</th></tr>'); | |
| 274 | 274 | |
| 275 | 275 | $ipuid['count'] = 0; | 
| 276 | 276 | $ipuid['uid'] = array(); | 
| @@ -286,69 +286,69 @@ discard block | ||
| 286 | 286 | //get imap header info for obj thang | 
| 287 | 287 | //$headers = imap_headerinfo($m_mail, $onem); | 
| 288 | 288 | //$head = imap_fetchheader($m_mail, $headers->Msgno); | 
| 289 | - $head = imap_fetchheader($m_mail, $onem ); | |
| 289 | + $head = imap_fetchheader($m_mail, $onem); | |
| 290 | 290 | //$obj = imap_rfc822_parse_headers( $head); | 
| 291 | 291 | |
| 292 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); | |
| 292 | + list ($ip, $host, $dateReceived, $dateClient, $mid) = getIP($head, $cf['mx'], $cf['msalearn']); | |
| 293 | 293 |  		if (empty($mid)) { | 
| 294 | - $uid='NA'; | |
| 295 | - syslog (LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); | |
| 296 | -		} else { | |
| 294 | + $uid = 'NA'; | |
| 295 | + syslog(LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); | |
| 296 | +		}else { | |
| 297 | 297 |  			if (!$dateReceived) { | 
| 298 | - $uid='unauthenticated'; | |
| 299 | - syslog (LOG_ERR, $cf['user'].": Error retrieving date for $mid. Maybe this mail was not submitted to Learner MSA"); | |
| 300 | - } else | |
| 301 | -				if ( !($uid = splunksearch ($splunkconn, trim($mid,'<>'), $dateReceived)) ) { | |
| 302 | - syslog (LOG_ERR, $cf['user'].": Error retrieving uid from Splunk log for $mid."); | |
| 303 | - $uid='unknown'; | |
| 298 | + $uid = 'unauthenticated'; | |
| 299 | + syslog(LOG_ERR, $cf['user'].": Error retrieving date for $mid. Maybe this mail was not submitted to Learner MSA"); | |
| 300 | + }else | |
| 301 | +				if (!($uid = splunksearch($splunkconn, trim($mid, '<>'), $dateReceived))) { | |
| 302 | + syslog(LOG_ERR, $cf['user'].": Error retrieving uid from Splunk log for $mid."); | |
| 303 | + $uid = 'unknown'; | |
| 304 | 304 | } | 
| 305 | 305 | } | 
| 306 | 306 | |
| 307 | 307 | /* Update count of each ip */ | 
| 308 | -	        if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers  and learned by valid uid */ | |
| 309 | - $ipuid['count']++; //number of right messages | |
| 308 | +	        if ($host and ($uid != 'NA') and ($uid != 'unauthenticated') and ($uid != 'unknown')) { /* IP is received by MX servers  and learned by valid uid */ | |
| 309 | + $ipuid['count']++; //number of right messages | |
| 310 | 310 | |
| 311 | -	                if (in_array($uid,array_keys($ipuid['uid']))) { | |
| 312 | - $ipuid['uid']["$uid"]['count']++; //number of learn by this uid | |
| 313 | - if (!in_array($ip,$ipuid['uid']["$uid"])) | |
| 314 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid | |
| 311 | +	                if (in_array($uid, array_keys($ipuid['uid']))) { | |
| 312 | + $ipuid['uid']["$uid"]['count']++; //number of learn by this uid | |
| 313 | + if (!in_array($ip, $ipuid['uid']["$uid"])) | |
| 314 | + $ipuid['uid']["$uid"][] = $ip; //ips learned by this uid | |
| 315 | 315 | } | 
| 316 | 316 |  			else { | 
| 317 | 317 | $ipuid['uid']["$uid"]['count'] = 1; | 
| 318 | - $ipuid['uid']["$uid"][]=$ip; | |
| 319 | - $ipuid['uid']['count']++; //number of unique uids | |
| 318 | + $ipuid['uid']["$uid"][] = $ip; | |
| 319 | + $ipuid['uid']['count']++; //number of unique uids | |
| 320 | 320 | } | 
| 321 | 321 | |
| 322 | -                        if (in_array($ip,array_keys($ipuid['ip']))) { | |
| 323 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | |
| 324 | - if (!in_array($uid,$ipuid['ip']["$ip"])) | |
| 325 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip | |
| 322 | +                        if (in_array($ip, array_keys($ipuid['ip']))) { | |
| 323 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | |
| 324 | + if (!in_array($uid, $ipuid['ip']["$ip"])) | |
| 325 | + $ipuid['ip']["$ip"][] = $uid; //uids that learned this ip | |
| 326 | 326 | } | 
| 327 | 327 |                          else { | 
| 328 | 328 | $ipuid['ip']["$ip"]['count'] = 1; | 
| 329 | - $ipuid['ip']["$ip"][]=$uid; | |
| 330 | - $ipuid['ip']['count']++; //number of unique ips | |
| 329 | + $ipuid['ip']["$ip"][] = $uid; | |
| 330 | + $ipuid['ip']['count']++; //number of unique ips | |
| 331 | 331 | } | 
| 332 | 332 | |
| 333 | 333 | /* Update HTML report */ | 
| 334 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); | |
| 334 | + fwrite($fp, updateReport($ip, $uid, $ipuid['ip']["$ip"]['count'], $ipuid['uid']["$uid"]['count'], $host, $dateClient, $mid, $dateReceived)); | |
| 335 | 335 | } | 
| 336 | 336 |  	        else {	/* Bad learn */ | 
| 337 | 337 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) | |
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 338 | + if (in_array($uid, array_keys($uidbad['uid']))) | |
| 339 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 340 | 340 |                          else { | 
| 341 | 341 | $uidbad['uid']["$uid"]['count'] = 1; | 
| 342 | - $uidbad['uid']["$uid"][]=$uid; | |
| 343 | - $uidbad['count']++; //numeber of unique bad uids | |
| 342 | + $uidbad['uid']["$uid"][] = $uid; | |
| 343 | + $uidbad['count']++; //numeber of unique bad uids | |
| 344 | 344 | } | 
| 345 | 345 | /* The reason of bad report */ | 
| 346 | 346 | if (!$host) $reason = 'This mail was not received by recognized MX host'; | 
| 347 | 347 | if (!$dateReceived) $reason = 'This mail was not submitted to recognized MSA for learn'; | 
| 348 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; | |
| 348 | + if ($uid == 'unknown') $reason = 'The uid of this mail was not found in splunk log'; | |
| 349 | 349 | if (!isset($reason)) $reason = '?'; | 
| 350 | 350 | |
| 351 | - fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); | |
| 351 | + fwrite($fpb, updatebadReport($uid, $dateClient, $mid, $dateReceived, $reason)); | |
| 352 | 352 | } | 
| 353 | 353 | } | 
| 354 | 354 | |
| @@ -356,45 +356,45 @@ discard block | ||
| 356 | 356 | //close report file and mailbox | 
| 357 | 357 | |
| 358 | 358 | /* Summary Report */ | 
| 359 | -	$ipuid['ip'] = array_msort( $ipuid['ip'], array('count'=>SORT_DESC) ); | |
| 360 | -	$ipuid['uid'] = array_msort( $ipuid['uid'], array('count'=>SORT_DESC) ); | |
| 361 | -	$uidbad['uid'] = array_msort( $uidbad['uid'], array('count'=>SORT_DESC) ); | |
| 359 | +	$ipuid['ip'] = array_msort($ipuid['ip'], array('count'=>SORT_DESC)); | |
| 360 | +	$ipuid['uid'] = array_msort($ipuid['uid'], array('count'=>SORT_DESC)); | |
| 361 | +	$uidbad['uid'] = array_msort($uidbad['uid'], array('count'=>SORT_DESC)); | |
| 362 | 362 | |
| 363 | 363 | fwrite($fp, '</table>'); | 
| 364 | - 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>' ); | |
| 364 | + 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>'); | |
| 365 | 365 | |
| 366 | 366 | /* Make MYSQL connection */ | 
| 367 | - if ( $cf['onlyReport'] ) | |
| 367 | + if ($cf['onlyReport']) | |
| 368 | 368 | $mysqli = NULL; | 
| 369 | 369 |  	else { | 
| 370 | 370 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); | 
| 371 | 371 |          	if ($mysqli->connect_error) { | 
| 372 | -                	syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 372 | +                	syslog(LOG_EMERG, $cf['user'].': Connect Error ('.$mysqli->connect_errno.') ' | |
| 373 | 373 | . $mysqli->connect_error); | 
| 374 | 374 | exit (254); | 
| 375 | 375 | } | 
| 376 | - syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; | |
| 376 | + syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to '.$mysqli->host_info); | |
| 377 | 377 | } | 
| 378 | 378 | /***********************/ | 
| 379 | 379 | |
| 380 | - fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); | |
| 381 | - if ( !$cf['onlyReport'] ) | |
| 380 | + fwrite($fp, summaryReportAndList($cf, $mysqli, $tables, $type, $ipuid)); | |
| 381 | + if (!$cf['onlyReport']) | |
| 382 | 382 | $mysqli->close(); | 
| 383 | - fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); | |
| 383 | + fwrite($fp, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateFooter'])); | |
| 384 | 384 | fclose($fp); | 
| 385 | 385 | |
| 386 | 386 | fwrite($fpb, '</table>'); | 
| 387 | - fwrite( $fpb,summaryBadReport( $uidbad ) ); | |
| 388 | - fwrite($fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); | |
| 387 | + fwrite($fpb, summaryBadReport($uidbad)); | |
| 388 | + fwrite($fpb, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateFooter'])); | |
| 389 | 389 | fclose($fpb); | 
| 390 | - syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); | |
| 391 | - | |
| 392 | - if ( $ierr = imap_errors() ) | |
| 393 | - foreach ( $ierr as $thiserr ) | |
| 394 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | |
| 395 | - if ( $ierr = imap_alerts() ) | |
| 396 | - foreach ( $ierr as $thiserr ) | |
| 397 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 390 | + syslog(LOG_INFO, $cf['user'].': Report files written. Listing job for '.$type.' terminated.'); | |
| 391 | + | |
| 392 | + if ($ierr = imap_errors()) | |
| 393 | + foreach ($ierr as $thiserr) | |
| 394 | + syslog(LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | |
| 395 | + if ($ierr = imap_alerts()) | |
| 396 | + foreach ($ierr as $thiserr) | |
| 397 | + syslog(LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | |
| 398 | 398 | imap_close($m_mail); | 
| 399 | 399 | } | 
| 400 | 400 | ?> | 
| @@ -10,21 +10,25 @@ discard block | ||
| 10 | 10 |  	if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) { | 
| 11 | 11 |  		for ($i = count($received[0])-1;$i>=0;$i--) { | 
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; | 
| 13 | - if ( preg_match($msa,$received['host'][$i]) ) | |
| 14 | - $dateR = $received['date'][$i]; | |
| 13 | +			if ( preg_match($msa,$received['host'][$i]) ) { | |
| 14 | + $dateR = $received['date'][$i]; | |
| 15 | + } | |
| 15 | 16 |          		foreach ($mxserver as $mx) { | 
| 16 | - if (!$ip) | |
| 17 | -					if ($mx == $received['host'][$i]) { | |
| 17 | +        			if (!$ip) { | |
| 18 | +        								if ($mx == $received['host'][$i]) { | |
| 18 | 19 | $host = $received['host'][$i]; | 
| 20 | + } | |
| 19 | 21 | $ip = $received['ip'][$i]; | 
| 20 | 22 | } | 
| 21 | 23 | } | 
| 22 | 24 | } | 
| 23 | 25 | } | 
| 24 | -	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) | |
| 25 | - $dateC['date'] = 'Not found'; | |
| 26 | -	if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) | |
| 27 | - $mid['mid'] = NULL; | |
| 26 | +	if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) { | |
| 27 | + $dateC['date'] = 'Not found'; | |
| 28 | + } | |
| 29 | +	if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) { | |
| 30 | + $mid['mid'] = NULL; | |
| 31 | + } | |
| 28 | 32 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); | 
| 29 | 33 | } | 
| 30 | 34 | |
| @@ -40,7 +44,9 @@ discard block | ||
| 40 | 44 | |
| 41 | 45 |  function summaryBadReport ($uidvet) { | 
| 42 | 46 | $nuid = $uidvet['count']; | 
| 43 | - if ( empty($uidvet) ) return NULL; | |
| 47 | +        if ( empty($uidvet) ) { | |
| 48 | + return NULL; | |
| 49 | + } | |
| 44 | 50 | $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; | 
| 45 | 51 | |
| 46 | 52 | /* Remove count index */ | 
| @@ -75,8 +81,12 @@ discard block | ||
| 75 | 81 |      foreach ($colarr as $col => $arr) { | 
| 76 | 82 |          foreach ($arr as $k => $v) { | 
| 77 | 83 | $k = substr($k,1); | 
| 78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; | |
| 79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; | |
| 84 | +            if (!isset($ret[$k])) { | |
| 85 | + $ret[$k] = $array[$k]; | |
| 86 | + } | |
| 87 | +            if (isset ($array[$k][$col])) { | |
| 88 | + $ret[$k][$col] = $array[$k][$col]; | |
| 89 | + } | |
| 80 | 90 | } | 
| 81 | 91 | } | 
| 82 | 92 | return $ret; | 
| @@ -87,13 +97,17 @@ discard block | ||
| 87 | 97 |  function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { | 
| 88 | 98 | $nips = $ipvet['count']; | 
| 89 | 99 | |
| 90 | - if ( empty($ipvet) ) return NULL; | |
| 100 | +	if ( empty($ipvet) ) { | |
| 101 | + return NULL; | |
| 102 | + } | |
| 91 | 103 | $return = '<h3>Statistics by IP</h3><table><tr><th>IP</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this ip is currently listed, but it says if this IP has listed now!">Listed Now</th></tr>'."\n"; | 
| 92 | 104 | |
| 93 | 105 | $ips = array_keys($ipvet['ip']); | 
| 94 | 106 | |
| 95 | 107 |  	foreach ( $ips as $ip ) { | 
| 96 | - if ( $ip == 'count' ) continue; | |
| 108 | +		if ( $ip == 'count' ) { | |
| 109 | + continue; | |
| 110 | + } | |
| 97 | 111 | $nlearn = $ipvet['ip']["$ip"]['count']; | 
| 98 | 112 | unset($ipvet['ip']["$ip"]['count']); | 
| 99 | 113 | $nuid = count($ipvet['ip']["$ip"]); | 
| @@ -101,10 +115,12 @@ discard block | ||
| 101 | 115 |  			if ( ($nlearn >= $cf['thresholdip']["$category"])AND($nuid >= $cf['thresholduid']["$category"]) ) { | 
| 102 | 116 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; | 
| 103 | 117 | $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$cf['quantity']["$category"],$reason); | 
| 118 | +			} else { | |
| 119 | + $listed = FALSE; | |
| 104 | 120 | } | 
| 105 | - else $listed = FALSE; | |
| 121 | +		} else { | |
| 122 | + $listed = FALSE; | |
| 106 | 123 | } | 
| 107 | - else $listed = FALSE; | |
| 108 | 124 | $nowlist = array( TRUE => array( | 
| 109 | 125 | 'style' => 'id=\'ipfound\'', | 
| 110 | 126 | 'name' => 'YES', | 
| @@ -122,7 +138,9 @@ discard block | ||
| 122 | 138 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; | 
| 123 | 139 |  		$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 | 140 | $rowuid=NULL; | 
| 125 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 141 | +                for ($j=1;$j<$nuid;$j++) { | |
| 142 | + $rowuid .= '<tr><td>%s</td></tr>'; | |
| 143 | + } | |
| 126 | 144 | array_shift($ipvet['ip']["$ip"]); | 
| 127 | 145 | $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); | 
| 128 | 146 | |
| @@ -135,14 +153,18 @@ discard block | ||
| 135 | 153 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; | 
| 136 | 154 | $uids = array_keys($ipvet['uid']); | 
| 137 | 155 |          foreach ( $uids as $uid ) { | 
| 138 | - if ( $uid == 'count' ) continue; | |
| 156 | +		if ( $uid == 'count' ) { | |
| 157 | + continue; | |
| 158 | + } | |
| 139 | 159 | $nlearn = $ipvet['uid']["$uid"]['count']; | 
| 140 | 160 | unset ( $ipvet['uid']["$uid"]['count'] ); | 
| 141 | 161 | $nip = count($ipvet['uid']["$uid"]); | 
| 142 | 162 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; | 
| 143 | 163 |  		$return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); | 
| 144 | 164 | $rowuid=NULL; | 
| 145 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; | |
| 165 | +                for ($j=1;$j<$nip;$j++) { | |
| 166 | + $rowuid .= '<tr><td>%s</td></tr>'; | |
| 167 | + } | |
| 146 | 168 | array_shift($ipvet['uid']["$uid"]); | 
| 147 | 169 | $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); | 
| 148 | 170 | |
| @@ -181,7 +203,9 @@ discard block | ||
| 181 | 203 | echo ' seconds</p>'; | 
| 182 | 204 | */ | 
| 183 | 205 | |
| 184 | - if ($job['resultCount'] == 0) return FALSE; | |
| 206 | +	if ($job['resultCount'] == 0) { | |
| 207 | + return FALSE; | |
| 208 | + } | |
| 185 | 209 | |
| 186 | 210 | // Get job results | 
| 187 | 211 | $resultSearch = $job->getResults(); | 
| @@ -194,14 +218,14 @@ discard block | ||
| 194 | 218 |  	    { | 
| 195 | 219 | // More than one field attribute returned by search | 
| 196 | 220 | // You must redefine the search | 
| 197 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; | |
| 198 | - } | |
| 199 | - else if ($result instanceof Splunk_ResultsMessage) | |
| 221 | +	      if ( count($result->getFieldNames()) > 1 ) { | |
| 222 | + return FALSE; | |
| 223 | + } | |
| 224 | + } else if ($result instanceof Splunk_ResultsMessage) | |
| 200 | 225 |  	    { | 
| 201 | 226 | // I don't want messages in my search | 
| 202 | 227 | return FALSE; | 
| 203 | - } | |
| 204 | - else if (is_array($result)) | |
| 228 | + } else if (is_array($result)) | |
| 205 | 229 |  	    { | 
| 206 | 230 | // Process a row | 
| 207 | 231 | foreach ($result as $key => $valueOrValues) | 
| @@ -209,15 +233,13 @@ discard block | ||
| 209 | 233 | if (is_array($valueOrValues)) | 
| 210 | 234 |  	          { | 
| 211 | 235 | return FALSE; | 
| 212 | - } | |
| 213 | - else | |
| 236 | + } else | |
| 214 | 237 |  	          { | 
| 215 | 238 | return $valueOrValues; | 
| 216 | 239 |  	            #print "  {$key} => {$value}\r\n"; | 
| 217 | 240 | } | 
| 218 | 241 | } | 
| 219 | - } | |
| 220 | - else | |
| 242 | + } else | |
| 221 | 243 |  	    { | 
| 222 | 244 | #print "Unknow result type"; | 
| 223 | 245 | return FALSE; | 
| @@ -231,7 +253,9 @@ discard block | ||
| 231 | 253 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; | 
| 232 | 254 |  	$m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) | 
| 233 | 255 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); | 
| 234 | - if ( !$m_mail ) exit(254); | |
| 256 | +	if ( !$m_mail ) { | |
| 257 | + exit(254); | |
| 258 | + } | |
| 235 | 259 | |
| 236 | 260 | |
| 237 | 261 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); | 
| @@ -244,20 +268,28 @@ discard block | ||
| 244 | 268 | // Order results starting from newest message | 
| 245 | 269 |  	if (!$m_search) { | 
| 246 | 270 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); | 
| 247 | - if ( $ierr = imap_errors() ) | |
| 248 | - foreach ( $ierr as $thiserr ) | |
| 271 | +	        if ( $ierr = imap_errors() ) { | |
| 272 | + foreach ( $ierr as $thiserr ) | |
| 249 | 273 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | 
| 250 | - if ( $ierr = imap_alerts() ) | |
| 251 | - foreach ( $ierr as $thiserr ) | |
| 274 | + } | |
| 275 | +	        if ( $ierr = imap_alerts() ) { | |
| 276 | + foreach ( $ierr as $thiserr ) | |
| 252 | 277 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | 
| 278 | + } | |
| 253 | 279 | imap_close( $m_mail ); | 
| 254 | - if ( file_exists( $file ) ) unlink ($file); | |
| 255 | - if ( file_exists( $fileb ) ) unlink ($fileb); | |
| 280 | +		if ( file_exists( $file ) ) { | |
| 281 | + unlink ($file); | |
| 282 | + } | |
| 283 | +		if ( file_exists( $fileb ) ) { | |
| 284 | + unlink ($fileb); | |
| 285 | + } | |
| 256 | 286 | return FALSE; | 
| 257 | 287 | } | 
| 258 | 288 | $nmes = count ($m_search); | 
| 259 | 289 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); | 
| 260 | - if ($nmes>0) rsort($m_search); | |
| 290 | +	if ($nmes>0) { | |
| 291 | + rsort($m_search); | |
| 292 | + } | |
| 261 | 293 | |
| 262 | 294 | // Create report file | 
| 263 | 295 | |
| @@ -266,7 +298,9 @@ discard block | ||
| 266 | 298 |  	$lastup = "Last Update: " . date ("d F Y H:i", time()); | 
| 267 | 299 | fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); | 
| 268 | 300 | fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); | 
| 269 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); | |
| 301 | +	if ($cf['onlyReport']) { | |
| 302 | + fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); | |
| 303 | + } | |
| 270 | 304 | fwrite( $fp,'<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>' ); | 
| 271 | 305 | fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); | 
| 272 | 306 | fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); | 
| @@ -310,10 +344,11 @@ discard block | ||
| 310 | 344 | |
| 311 | 345 |  	                if (in_array($uid,array_keys($ipuid['uid']))) { | 
| 312 | 346 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid | 
| 313 | - if (!in_array($ip,$ipuid['uid']["$uid"])) | |
| 314 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid | |
| 315 | - } | |
| 316 | -			else { | |
| 347 | +				if (!in_array($ip,$ipuid['uid']["$uid"])) { | |
| 348 | + $ipuid['uid']["$uid"][]=$ip; | |
| 349 | + } | |
| 350 | + //ips learned by this uid | |
| 351 | +			} else { | |
| 317 | 352 | $ipuid['uid']["$uid"]['count'] = 1; | 
| 318 | 353 | $ipuid['uid']["$uid"][]=$ip; | 
| 319 | 354 | $ipuid['uid']['count']++; //number of unique uids | 
| @@ -321,10 +356,11 @@ discard block | ||
| 321 | 356 | |
| 322 | 357 |                          if (in_array($ip,array_keys($ipuid['ip']))) { | 
| 323 | 358 | $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages | 
| 324 | - if (!in_array($uid,$ipuid['ip']["$ip"])) | |
| 325 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip | |
| 326 | - } | |
| 327 | -                        else { | |
| 359 | +				if (!in_array($uid,$ipuid['ip']["$ip"])) { | |
| 360 | + $ipuid['ip']["$ip"][]=$uid; | |
| 361 | + } | |
| 362 | + //uids that learned this ip | |
| 363 | +			} else { | |
| 328 | 364 | $ipuid['ip']["$ip"]['count'] = 1; | 
| 329 | 365 | $ipuid['ip']["$ip"][]=$uid; | 
| 330 | 366 | $ipuid['ip']['count']++; //number of unique ips | 
| @@ -332,21 +368,30 @@ discard block | ||
| 332 | 368 | |
| 333 | 369 | /* Update HTML report */ | 
| 334 | 370 | fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); | 
| 335 | - } | |
| 336 | -	        else {	/* Bad learn */ | |
| 371 | +		} else {	/* Bad learn */ | |
| 337 | 372 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) | |
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid | |
| 373 | +                        if (in_array($uid,array_keys($uidbad['uid']))) { | |
| 374 | + $uidbad['uid']["$uid"]['count']++; | |
| 375 | + } | |
| 376 | + //number of bad learn by this uid | |
| 340 | 377 |                          else { | 
| 341 | 378 | $uidbad['uid']["$uid"]['count'] = 1; | 
| 342 | 379 | $uidbad['uid']["$uid"][]=$uid; | 
| 343 | 380 | $uidbad['count']++; //numeber of unique bad uids | 
| 344 | 381 | } | 
| 345 | 382 | /* The reason of bad report */ | 
| 346 | - if (!$host) $reason = 'This mail was not received by recognized MX host'; | |
| 347 | - if (!$dateReceived) $reason = 'This mail was not submitted to recognized MSA for learn'; | |
| 348 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; | |
| 349 | - if (!isset($reason)) $reason = '?'; | |
| 383 | +			if (!$host) { | |
| 384 | + $reason = 'This mail was not received by recognized MX host'; | |
| 385 | + } | |
| 386 | +			if (!$dateReceived) { | |
| 387 | + $reason = 'This mail was not submitted to recognized MSA for learn'; | |
| 388 | + } | |
| 389 | +			if ($uid=='unknown') { | |
| 390 | + $reason = 'The uid of this mail was not found in splunk log'; | |
| 391 | + } | |
| 392 | +			if (!isset($reason)) { | |
| 393 | + $reason = '?'; | |
| 394 | + } | |
| 350 | 395 | |
| 351 | 396 | fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); | 
| 352 | 397 | } | 
| @@ -364,9 +409,9 @@ discard block | ||
| 364 | 409 | 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>' ); | 
| 365 | 410 | |
| 366 | 411 | /* Make MYSQL connection */ | 
| 367 | - if ( $cf['onlyReport'] ) | |
| 368 | - $mysqli = NULL; | |
| 369 | -	else { | |
| 412 | +	if ( $cf['onlyReport'] ) { | |
| 413 | + $mysqli = NULL; | |
| 414 | +	} else { | |
| 370 | 415 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); | 
| 371 | 416 |          	if ($mysqli->connect_error) { | 
| 372 | 417 |                  	syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' | 
| @@ -378,8 +423,9 @@ discard block | ||
| 378 | 423 | /***********************/ | 
| 379 | 424 | |
| 380 | 425 | fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); | 
| 381 | - if ( !$cf['onlyReport'] ) | |
| 382 | - $mysqli->close(); | |
| 426 | +	if ( !$cf['onlyReport'] ) { | |
| 427 | + $mysqli->close(); | |
| 428 | + } | |
| 383 | 429 | fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); | 
| 384 | 430 | fclose($fp); | 
| 385 | 431 | |
| @@ -389,12 +435,14 @@ discard block | ||
| 389 | 435 | fclose($fpb); | 
| 390 | 436 | syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); | 
| 391 | 437 | |
| 392 | - if ( $ierr = imap_errors() ) | |
| 393 | - foreach ( $ierr as $thiserr ) | |
| 438 | +	if ( $ierr = imap_errors() ) { | |
| 439 | + foreach ( $ierr as $thiserr ) | |
| 394 | 440 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); | 
| 395 | - if ( $ierr = imap_alerts() ) | |
| 396 | - foreach ( $ierr as $thiserr ) | |
| 441 | + } | |
| 442 | +	if ( $ierr = imap_alerts() ) { | |
| 443 | + foreach ( $ierr as $thiserr ) | |
| 397 | 444 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); | 
| 445 | + } | |
| 398 | 446 | imap_close($m_mail); | 
| 399 | 447 | } | 
| 400 | 448 | ?> | 
| @@ -1,4 +1,7 @@ | ||
| 1 | 1 | <?php | 
| 2 | +/** | |
| 3 | + * @param string $str | |
| 4 | + */ | |
| 2 | 5 |  function filterInput($str, $type = "text"){
 | 
| 3 | 6 |  	switch(strtolower($type)){
 | 
| 4 | 7 | case "number": | 
| @@ -1,13 +1,13 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -function filterInput($str, $type = "text"){
 | |
| 3 | -	switch(strtolower($type)){
 | |
| 2 | +function filterInput($str, $type = "text") {
 | |
| 3 | +	switch (strtolower($type)) {
 | |
| 4 | 4 | case "number": | 
| 5 | - if(is_numeric($str)) | |
| 5 | + if (is_numeric($str)) | |
| 6 | 6 | return array(true, $str); | 
| 7 | 7 | else return array(false, "Invalid input - '$str', required number"); | 
| 8 | 8 | break; | 
| 9 | 9 | case "boolean": | 
| 10 | - if($str == "" || $str == 0 || $str == 1 || is_bool($str)) | |
| 10 | + if ($str == "" || $str == 0 || $str == 1 || is_bool($str)) | |
| 11 | 11 | return array(true, $str); | 
| 12 | 12 | else return array(false, "Invalid input - '$str', required boolean"); | 
| 13 | 13 | break; | 
| @@ -19,23 +19,23 @@ discard block | ||
| 19 | 19 | } | 
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | -function getParameter($name, $type='text', $default=""){
 | |
| 22 | +function getParameter($name, $type = 'text', $default = "") {
 | |
| 23 | 23 | $v = isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default; | 
| 24 | 24 | |
| 25 | 25 | $results = filterInput($v, $type); | 
| 26 | 26 | $result_txt = isset($results[1]) ? $results[1] : ""; | 
| 27 | -	if(isset($results[0]) && $results[0] === true){
 | |
| 27 | +	if (isset($results[0]) && $results[0] === true) {
 | |
| 28 | 28 | return $result_txt; | 
| 29 | 29 |  	}else exit("Error returned '$name' - ".$result_txt);
 | 
| 30 | 30 | } | 
| 31 | 31 | |
| 32 | -function getTranslatedTxt($txt, $allow_tag = false, $maps = array()){
 | |
| 32 | +function getTranslatedTxt($txt, $allow_tag = false, $maps = array()) {
 | |
| 33 | 33 | $content = $txt; | 
| 34 | 34 | |
| 35 | 35 | //$content = unhtmlentities($content); | 
| 36 | 36 | $content = htmlspecialchars_decode($content, ENT_QUOTES); | 
| 37 | 37 | |
| 38 | -	foreach($maps as $map_key=>$map_value){
 | |
| 38 | +	foreach ($maps as $map_key=>$map_value) {
 | |
| 39 | 39 | $content = str_replace($map_key, $map_value, $content); | 
| 40 | 40 | } | 
| 41 | 41 | |
| @@ -43,7 +43,7 @@ discard block | ||
| 43 | 43 | $content = stripslashes($content); | 
| 44 | 44 | $content = stripslashes($content); | 
| 45 | 45 | |
| 46 | -	if(!$allow_tag){
 | |
| 46 | +	if (!$allow_tag) {
 | |
| 47 | 47 | $content = strip_tags($content); | 
| 48 | 48 | } | 
| 49 | 49 | |
| @@ -2,14 +2,18 @@ discard block | ||
| 2 | 2 |  function filterInput($str, $type = "text"){
 | 
| 3 | 3 |  	switch(strtolower($type)){
 | 
| 4 | 4 | case "number": | 
| 5 | - if(is_numeric($str)) | |
| 6 | - return array(true, $str); | |
| 7 | - else return array(false, "Invalid input - '$str', required number"); | |
| 5 | +			if(is_numeric($str)) { | |
| 6 | + return array(true, $str); | |
| 7 | +			} else { | |
| 8 | + return array(false, "Invalid input - '$str', required number"); | |
| 9 | + } | |
| 8 | 10 | break; | 
| 9 | 11 | case "boolean": | 
| 10 | - if($str == "" || $str == 0 || $str == 1 || is_bool($str)) | |
| 11 | - return array(true, $str); | |
| 12 | - else return array(false, "Invalid input - '$str', required boolean"); | |
| 12 | +			if($str == "" || $str == 0 || $str == 1 || is_bool($str)) { | |
| 13 | + return array(true, $str); | |
| 14 | +			} else { | |
| 15 | + return array(false, "Invalid input - '$str', required boolean"); | |
| 16 | + } | |
| 13 | 17 | break; | 
| 14 | 18 | default: | 
| 15 | 19 | //$str = addslashes($str); | 
| @@ -26,8 +30,10 @@ discard block | ||
| 26 | 30 | $result_txt = isset($results[1]) ? $results[1] : ""; | 
| 27 | 31 |  	if(isset($results[0]) && $results[0] === true){
 | 
| 28 | 32 | return $result_txt; | 
| 29 | -	}else exit("Error returned '$name' - ".$result_txt);
 | |
| 30 | -} | |
| 33 | +	} else { | |
| 34 | +		exit("Error returned '$name' - ".$result_txt); | |
| 35 | + } | |
| 36 | + } | |
| 31 | 37 | |
| 32 | 38 |  function getTranslatedTxt($txt, $allow_tag = false, $maps = array()){
 | 
| 33 | 39 | $content = $txt; | 
| @@ -122,6 +122,11 @@ discard block | ||
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | //get the total day of each month in year | 
| 125 | + | |
| 126 | + /** | |
| 127 | + * @param integer $month | |
| 128 | + * @param integer $year | |
| 129 | + */ | |
| 125 | 130 |      function total_days($month,$year){
 | 
| 126 | 131 | $days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | 
| 127 | 132 |  		if($month > 0 && $year > 0){
 | 
| @@ -170,6 +175,12 @@ discard block | ||
| 170 | 175 | } | 
| 171 | 176 | |
| 172 | 177 | //set default selected date | 
| 178 | + | |
| 179 | + /** | |
| 180 | + * @param integer $day | |
| 181 | + * @param integer $month | |
| 182 | + * @param integer $year | |
| 183 | + */ | |
| 173 | 184 |  	function setDate($day, $month, $year){
 | 
| 174 | 185 | //get system timezone before set the date | 
| 175 | 186 | $this->system_timezone = date_default_timezone_get(); | 
| @@ -516,6 +527,9 @@ discard block | ||
| 516 | 527 | return $str; | 
| 517 | 528 | } | 
| 518 | 529 | |
| 530 | + /** | |
| 531 | + * @param string $suffix | |
| 532 | + */ | |
| 519 | 533 |  	function eHidden($suffix, $value) {
 | 
| 520 | 534 |  		if(trim($value) != ""){
 | 
| 521 | 535 | if($suffix) $suffix = "_".$suffix; | 
| @@ -849,6 +863,9 @@ discard block | ||
| 849 | 863 | return true; | 
| 850 | 864 | } | 
| 851 | 865 | |
| 866 | + /** | |
| 867 | + * @return string | |
| 868 | + */ | |
| 852 | 869 |  	function check_json_encode($obj){
 | 
| 853 | 870 | //try customize to get it work, should replace with better solution in the future | 
| 854 | 871 |  		if(is_array($obj)){
 | 
| @@ -997,6 +1014,9 @@ discard block | ||
| 997 | 1014 | } | 
| 998 | 1015 | } | 
| 999 | 1016 | |
| 1017 | + /** | |
| 1018 | + * @param string $tz | |
| 1019 | + */ | |
| 1000 | 1020 |  	function setTimezone($tz){
 | 
| 1001 | 1021 | $this->timezone = $tz; | 
| 1002 | 1022 | @date_default_timezone_set($tz); | 
| @@ -117,17 +117,17 @@ | ||
| 117 | 117 | |
| 118 | 118 | //check for leapyear | 
| 119 | 119 |  	function is_leapyear($year){
 | 
| 120 | - return ($year % 4 == 0) ? | |
| 121 | - !($year % 100 == 0 && $year % 400 <> 0) : false; | |
| 122 | - } | |
| 120 | + return ($year % 4 == 0) ? | |
| 121 | + !($year % 100 == 0 && $year % 400 <> 0) : false; | |
| 122 | + } | |
| 123 | 123 | |
| 124 | 124 | //get the total day of each month in year | 
| 125 | -    function total_days($month,$year){
 | |
| 126 | - $days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
| 125 | +	function total_days($month,$year){
 | |
| 126 | + $days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
| 127 | 127 |  		if($month > 0 && $year > 0){
 | 
| 128 | - return ($month == 2 && $this->is_leapYear($year)) ? 29 : $days[$month-1]; | |
| 128 | + return ($month == 2 && $this->is_leapYear($year)) ? 29 : $days[$month-1]; | |
| 129 | 129 | }else return 31; | 
| 130 | - } | |
| 130 | + } | |
| 131 | 131 | |
| 132 | 132 | //Deprecate since v1.6 | 
| 133 | 133 |  	function getDayNum($day){
 | 
| @@ -12,7 +12,7 @@ discard block | ||
| 12 | 12 | |
| 13 | 13 |  require_once('tc_date.php');
 | 
| 14 | 14 | |
| 15 | -class tc_calendar{
 | |
| 15 | +class tc_calendar {
 | |
| 16 | 16 | public $version = "3.75"; | 
| 17 | 17 | public $check_new_version = false; | 
| 18 | 18 | |
| @@ -98,12 +98,12 @@ discard block | ||
| 98 | 98 | private $theme = "default"; | 
| 99 | 99 | |
| 100 | 100 | //calendar constructor | 
| 101 | -	function __construct($objname, $date_picker = false, $show_input = true, $timezone = ""){
 | |
| 101 | +	function __construct($objname, $date_picker = false, $show_input = true, $timezone = "") {
 | |
| 102 | 102 | $this->objname = $objname; | 
| 103 | 103 | //$this->year_display_from_current = 50; | 
| 104 | 104 | $this->date_picker = $date_picker; | 
| 105 | 105 | |
| 106 | - if($timezone != "") $this->setTimezone($timezone); | |
| 106 | + if ($timezone != "") $this->setTimezone($timezone); | |
| 107 | 107 | |
| 108 | 108 | //set default year display from current year | 
| 109 | 109 |  		$thisyear = date('Y');
 | 
| @@ -116,36 +116,36 @@ discard block | ||
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | 118 | //check for leapyear | 
| 119 | -	function is_leapyear($year){
 | |
| 119 | +	function is_leapyear($year) {
 | |
| 120 | 120 | return ($year % 4 == 0) ? | 
| 121 | - !($year % 100 == 0 && $year % 400 <> 0) : false; | |
| 121 | + !($year % 100 == 0 && $year % 400 <> 0) : false; | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | //get the total day of each month in year | 
| 125 | -    function total_days($month,$year){
 | |
| 125 | +    function total_days($month, $year) {
 | |
| 126 | 126 | $days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | 
| 127 | -		if($month > 0 && $year > 0){
 | |
| 127 | +		if ($month>0 && $year>0) {
 | |
| 128 | 128 | return ($month == 2 && $this->is_leapYear($year)) ? 29 : $days[$month-1]; | 
| 129 | 129 | }else return 31; | 
| 130 | 130 | } | 
| 131 | 131 | |
| 132 | 132 | //Deprecate since v1.6 | 
| 133 | -	function getDayNum($day){
 | |
| 133 | +	function getDayNum($day) {
 | |
| 134 | 134 | $headers = $this->getDayHeaders(); | 
| 135 | 135 | return isset($headers[$day]) ? $headers[$day] : 0; | 
| 136 | 136 | } | 
| 137 | 137 | |
| 138 | 138 | //get the day headers start from sunday till saturday | 
| 139 | -	function getDayHeaders(){
 | |
| 139 | +	function getDayHeaders() {
 | |
| 140 | 140 | $rtn_hdrs = array(); | 
| 141 | 141 |  		$hdrs = array("0"=>"Su", "1"=>"Mo", "2"=>"Tu", "3"=>"We", "4"=>"Th", "5"=>"Fr", "6"=>"Sa");
 | 
| 142 | 142 | |
| 143 | 143 | $startdate = $this->startDate; | 
| 144 | 144 | |
| 145 | -		for($i=0; $i<=6; $i++){
 | |
| 146 | - if($startdate >= sizeof($hdrs)) $startdate = 0; | |
| 145 | +		for ($i = 0; $i<=6; $i++) {
 | |
| 146 | + if ($startdate>=sizeof($hdrs)) $startdate = 0; | |
| 147 | 147 | //if(isset($hdrs[(string)$startdate])) | 
| 148 | - $rtn_hdrs[] = $hdrs[(string)$startdate]; | |
| 148 | + $rtn_hdrs[] = $hdrs[(string) $startdate]; | |
| 149 | 149 | |
| 150 | 150 | $startdate++; | 
| 151 | 151 | } | 
| @@ -153,11 +153,11 @@ discard block | ||
| 153 | 153 | return $rtn_hdrs; | 
| 154 | 154 | } | 
| 155 | 155 | |
| 156 | -	function setIcon($icon){
 | |
| 156 | +	function setIcon($icon) {
 | |
| 157 | 157 | $this->icon = $icon; | 
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | -	function setText($txt){
 | |
| 160 | +	function setText($txt) {
 | |
| 161 | 161 | $this->txt = $txt; | 
| 162 | 162 | } | 
| 163 | 163 | |
| @@ -165,12 +165,12 @@ discard block | ||
| 165 | 165 | //input the date format according to php date format | 
| 166 | 166 | // for example: 'd F y' or 'Y-m-d' | 
| 167 | 167 | //----------------------------------------------------------- | 
| 168 | -	function setDateFormat($format){
 | |
| 168 | +	function setDateFormat($format) {
 | |
| 169 | 169 | $this->date_format = $format; | 
| 170 | 170 | } | 
| 171 | 171 | |
| 172 | 172 | //set default selected date | 
| 173 | -	function setDate($day, $month, $year){
 | |
| 173 | +	function setDate($day, $month, $year) {
 | |
| 174 | 174 | //get system timezone before set the date | 
| 175 | 175 | $this->system_timezone = date_default_timezone_get(); | 
| 176 | 176 |  		$this->system_timezone_offset = date('Z');
 | 
| @@ -185,7 +185,7 @@ discard block | ||
| 185 | 185 | $this->year = $year; | 
| 186 | 186 | } | 
| 187 | 187 | |
| 188 | -	function setDateYMD($date){
 | |
| 188 | +	function setDateYMD($date) {
 | |
| 189 | 189 |  		list($year, $month, $day) = explode("-", $date, 3);
 | 
| 190 | 190 | $this->day = $day; | 
| 191 | 191 | $this->month = $month; | 
| @@ -193,52 +193,52 @@ discard block | ||
| 193 | 193 | } | 
| 194 | 194 | |
| 195 | 195 | //specified location of the calendar_form.php | 
| 196 | -	function setPath($path){
 | |
| 196 | +	function setPath($path) {
 | |
| 197 | 197 | $last_char = substr($path, strlen($path)-1, strlen($path)); | 
| 198 | - if($last_char != "/") $path .= "/"; | |
| 198 | + if ($last_char != "/") $path .= "/"; | |
| 199 | 199 | $this->path = $path; | 
| 200 | 200 | } | 
| 201 | 201 | |
| 202 | -	function writeScript(){
 | |
| 202 | +	function writeScript() {
 | |
| 203 | 203 | $this->processScript(); | 
| 204 | 204 | } | 
| 205 | 205 | |
| 206 | -	function getScript(){
 | |
| 206 | +	function getScript() {
 | |
| 207 | 207 | return $this->processScript(true); | 
| 208 | 208 | } | 
| 209 | 209 | |
| 210 | -	function processScript($buffer = false){
 | |
| 210 | +	function processScript($buffer = false) {
 | |
| 211 | 211 | $str = ""; | 
| 212 | 212 | |
| 213 | 213 | //check valid default date | 
| 214 | -		if(!$this->checkDefaultDateValid()){
 | |
| 214 | +		if (!$this->checkDefaultDateValid()) {
 | |
| 215 | 215 | //unset default date | 
| 216 | 216 | $this->setDate(00, 00, 0000); | 
| 217 | 217 | } | 
| 218 | 218 | |
| 219 | 219 | //check date set to the timezone | 
| 220 | -		if($this->year>0 && $this->month>0 && $this->day>0){
 | |
| 220 | +		if ($this->year>0 && $this->month>0 && $this->day>0) {
 | |
| 221 | 221 | //date has been set | 
| 222 | -			if($this->timezone != "" && $this->system_timezone != "" && $this->timezone != $this->system_timezone){
 | |
| 222 | +			if ($this->timezone != "" && $this->system_timezone != "" && $this->timezone != $this->system_timezone) {
 | |
| 223 | 223 |  				//echo("<br />TZ! ".$this->system_timezone);
 | 
| 224 | 224 |  				//echo("<br />OFFSET: ".$this->system_timezone_offset.",".$this->timezone_offset);
 | 
| 225 | 225 | //timezone has been set and different from system timezone | 
| 226 | 226 | $a_date = $this->year."-".$this->month."-".$this->day." ".$this->system_timezone_h.":".$this->system_timezone_i.":".$this->system_timezone_s; | 
| 227 | 227 |  				//echo(", date: $a_date");
 | 
| 228 | 228 | |
| 229 | -				if ((version_compare(PHP_VERSION, '5.3.0') <= 0 && checkdate($this->month, $this->day, $this->year)) || true) {
 | |
| 229 | +				if ((version_compare(PHP_VERSION, '5.3.0')<=0 && checkdate($this->month, $this->day, $this->year)) || true) {
 | |
| 230 | 230 | //get the timezone difference | 
| 231 | 231 | $tz_sys_ms = $this->system_timezone_offset; | 
| 232 | 232 | $tz_new_ms = $this->timezone_offset; | 
| 233 | 233 | |
| 234 | -					if($tz_sys_ms>=0 && $tz_new_ms<=0){
 | |
| 234 | +					if ($tz_sys_ms>=0 && $tz_new_ms<=0) {
 | |
| 235 | 235 | $timezone_diff = 0-($tz_sys_ms+abs($tz_new_ms)); | 
| 236 | -					}elseif($tz_sys_ms<=0 && $tz_new_ms>=0){
 | |
| 236 | +					}elseif ($tz_sys_ms<=0 && $tz_new_ms>=0) {
 | |
| 237 | 237 | $timezone_diff = abs($tz_sys_ms)+$tz_new_ms; | 
| 238 | -					}else{
 | |
| 238 | +					}else {
 | |
| 239 | 239 | $timezone_diff = $tz_sys_ms-$tz_new_ms; | 
| 240 | 240 | } | 
| 241 | - $timezone_diff_hr = $timezone_diff/3600; | |
| 241 | + $timezone_diff_hr = $timezone_diff / 3600; | |
| 242 | 242 |  					//echo("<br />Diff: ".$timezone_diff_hr);
 | 
| 243 | 243 | |
| 244 | 244 | $a_time = strtotime($a_date); | 
| @@ -255,7 +255,7 @@ discard block | ||
| 255 | 255 |  					$this->year = date("Y", $n_time);
 | 
| 256 | 256 |  					$this->month = date("m", $n_time);
 | 
| 257 | 257 |  					$this->day = date("d", $n_time);
 | 
| 258 | -				}else{
 | |
| 258 | +				}else {
 | |
| 259 | 259 | $date = new DateTime($a_date, new DateTimeZone($this->system_timezone)); | 
| 260 | 260 | $date->setTimezone(new DateTimeZone($this->timezone)); | 
| 261 | 261 |  					$this->year = $date->format('Y');
 | 
| @@ -269,21 +269,21 @@ discard block | ||
| 269 | 269 | $str .= $this->writeHidden(); | 
| 270 | 270 | |
| 271 | 271 | //check whether it is a date picker | 
| 272 | -		if($this->date_picker){
 | |
| 272 | +		if ($this->date_picker) {
 | |
| 273 | 273 |  			$str .= "<div style=\"position: relative; z-index: ".$this->zindex."; display: inline-block; vertical-align: top;\" id=\"container_".$this->objname."\" onmouseover=\"javascript:focusCalendar('".$this->objname."');\" onmouseout=\"javascript:unFocusCalendar('".$this->objname."', ".$this->zindex.");\">";
 | 
| 274 | 274 | |
| 275 | -			if($this->show_input){
 | |
| 275 | +			if ($this->show_input) {
 | |
| 276 | 276 | $str .= $this->writeDay(); | 
| 277 | 277 | $str .= $this->writeMonth(); | 
| 278 | 278 | $str .= $this->writeYear(); | 
| 279 | -			}else{
 | |
| 279 | +			}else {
 | |
| 280 | 280 |  				$str .= " <a href=\"javascript:toggleCalendar('".$this->objname."', ".$this->auto_hide.", ".$this->auto_hide_time.");\" class=\"tclabel\">";
 | 
| 281 | 281 | $str .= $this->writeDateContainer(); | 
| 282 | 282 | $str .= "</a>"; | 
| 283 | 283 | } | 
| 284 | 284 | |
| 285 | 285 |  			$str .= " <a href=\"javascript:toggleCalendar('".$this->objname."', ".$this->auto_hide.", ".$this->auto_hide_time.");\">";
 | 
| 286 | -			if(is_file($this->icon)){
 | |
| 286 | +			if (is_file($this->icon)) {
 | |
| 287 | 287 | $str .= "<img src=\"".$this->icon."\" id=\"tcbtn_".$this->objname."\" name=\"tcbtn_".$this->objname."\" border=\"0\" align=\"absmiddle\" style=\"vertical-align:middle;\" alt=\"".$this->txt."\" title=\"".$this->txt."\" />"; | 
| 288 | 288 | }else $str .= $this->txt; | 
| 289 | 289 | $str .= "</a>"; | 
| @@ -291,123 +291,123 @@ discard block | ||
| 291 | 291 | $str .= $this->writeCalendarContainer(); | 
| 292 | 292 | |
| 293 | 293 | $str .= "</div>"; | 
| 294 | -		}else{
 | |
| 294 | +		}else {
 | |
| 295 | 295 | $str .= $this->writeCalendarContainer(); | 
| 296 | 296 | } | 
| 297 | 297 | |
| 298 | -		if($buffer){
 | |
| 298 | +		if ($buffer) {
 | |
| 299 | 299 | return $str; | 
| 300 | -		}else{
 | |
| 300 | +		}else {
 | |
| 301 | 301 | echo($str); | 
| 302 | 302 | } | 
| 303 | 303 | } | 
| 304 | 304 | |
| 305 | -	function writeCalendarContainer(){
 | |
| 305 | +	function writeCalendarContainer() {
 | |
| 306 | 306 | $params = array(); | 
| 307 | 307 | $params[] = "objname=".$this->objname; | 
| 308 | 308 | |
| 309 | 309 | $param = $this->day; | 
| 310 | - if($param != "") $params[] = "selected_day=".$param; | |
| 310 | + if ($param != "") $params[] = "selected_day=".$param; | |
| 311 | 311 | |
| 312 | 312 | $param = $this->month; | 
| 313 | - if($param != "") $params[] = "selected_month=".$param; | |
| 313 | + if ($param != "") $params[] = "selected_month=".$param; | |
| 314 | 314 | |
| 315 | 315 | $param = $this->year; | 
| 316 | - if($param != "") $params[] = "selected_year=".$param; | |
| 316 | + if ($param != "") $params[] = "selected_year=".$param; | |
| 317 | 317 | |
| 318 | 318 | $param = $this->year_start_input; | 
| 319 | - if($param != "") $params[] = "year_start=".$param; | |
| 319 | + if ($param != "") $params[] = "year_start=".$param; | |
| 320 | 320 | |
| 321 | 321 | $param = $this->year_end_input; | 
| 322 | - if($param != "") $params[] = "year_end=".$param; | |
| 322 | + if ($param != "") $params[] = "year_end=".$param; | |
| 323 | 323 | |
| 324 | 324 | $param = ($this->date_picker) ? 1 : 0; | 
| 325 | - if($param != "") $params[] = "dp=".$param; | |
| 325 | + if ($param != "") $params[] = "dp=".$param; | |
| 326 | 326 | |
| 327 | 327 | $param = $this->time_allow1; | 
| 328 | - if($param != "") $params[] = "da1=".$param; | |
| 328 | + if ($param != "") $params[] = "da1=".$param; | |
| 329 | 329 | |
| 330 | 330 | $param = $this->time_allow2; | 
| 331 | - if($param != "") $params[] = "da2=".$param; | |
| 331 | + if ($param != "") $params[] = "da2=".$param; | |
| 332 | 332 | |
| 333 | 333 | $param = $this->show_not_allow; | 
| 334 | - if($param != "") $params[] = "sna=".$param; | |
| 334 | + if ($param != "") $params[] = "sna=".$param; | |
| 335 | 335 | |
| 336 | 336 | $param = $this->auto_submit; | 
| 337 | - if($param != "") $params[] = "aut=".$param; | |
| 337 | + if ($param != "") $params[] = "aut=".$param; | |
| 338 | 338 | |
| 339 | 339 | $param = $this->form_container; | 
| 340 | - if($param != "") $params[] = "frm=".$param; | |
| 340 | + if ($param != "") $params[] = "frm=".$param; | |
| 341 | 341 | |
| 342 | 342 | $param = $this->target_url; | 
| 343 | - if($param != "") $params[] = "tar=".$param; | |
| 343 | + if ($param != "") $params[] = "tar=".$param; | |
| 344 | 344 | |
| 345 | 345 | $param = $this->show_input; | 
| 346 | - if($param != "") $params[] = "inp=".$param; | |
| 346 | + if ($param != "") $params[] = "inp=".$param; | |
| 347 | 347 | |
| 348 | 348 | $param = $this->date_format; | 
| 349 | - if($param != "") $params[] = "fmt=".$param; | |
| 349 | + if ($param != "") $params[] = "fmt=".$param; | |
| 350 | 350 | |
| 351 | 351 |  		$param = implode(",", $this->dsb_days);
 | 
| 352 | - if($param != "") $params[] = "dis=".$param; | |
| 352 | + if ($param != "") $params[] = "dis=".$param; | |
| 353 | 353 | |
| 354 | 354 | $param = $this->date_pair1; | 
| 355 | - if($param != "") $params[] = "pr1=".$param; | |
| 355 | + if ($param != "") $params[] = "pr1=".$param; | |
| 356 | 356 | |
| 357 | 357 | $param = $this->date_pair2; | 
| 358 | - if($param != "") $params[] = "pr2=".$param; | |
| 358 | + if ($param != "") $params[] = "pr2=".$param; | |
| 359 | 359 | |
| 360 | 360 | $param = $this->date_pair_value; | 
| 361 | - if($param != "") $params[] = "prv=".$param; | |
| 361 | + if ($param != "") $params[] = "prv=".$param; | |
| 362 | 362 | |
| 363 | 363 | $param = $this->path; | 
| 364 | - if($param != "") $params[] = "pth=".$param; | |
| 364 | + if ($param != "") $params[] = "pth=".$param; | |
| 365 | 365 | |
| 366 | 366 | $param = htmlspecialchars($this->check_json_encode($this->sp_dates), ENT_QUOTES); | 
| 367 | - if($param != "") $params[] = "spd=".$param; | |
| 367 | + if ($param != "") $params[] = "spd=".$param; | |
| 368 | 368 | |
| 369 | 369 | $param = $this->sp_type; | 
| 370 | - if($param != "") $params[] = "spt=".$param; | |
| 370 | + if ($param != "") $params[] = "spt=".$param; | |
| 371 | 371 | |
| 372 | 372 | $param = rawurlencode($this->tc_onchanged); | 
| 373 | - if($param != "") $params[] = "och=".$param; | |
| 373 | + if ($param != "") $params[] = "och=".$param; | |
| 374 | 374 | |
| 375 | 375 | $param = $this->startDate; | 
| 376 | - if($param != "") $params[] = "str=".$param; | |
| 376 | + if ($param != "") $params[] = "str=".$param; | |
| 377 | 377 | |
| 378 | 378 | $param = $this->rtl; | 
| 379 | - if($param != "") $params[] = "rtl=".$param; | |
| 379 | + if ($param != "") $params[] = "rtl=".$param; | |
| 380 | 380 | |
| 381 | 381 | $param = $this->show_week; | 
| 382 | - if($param != "") $params[] = "wks=".$param; | |
| 382 | + if ($param != "") $params[] = "wks=".$param; | |
| 383 | 383 | |
| 384 | 384 | $param = $this->interval; | 
| 385 | - if($param != "") $params[] = "int=".$param; | |
| 385 | + if ($param != "") $params[] = "int=".$param; | |
| 386 | 386 | |
| 387 | 387 | $param = $this->auto_hide; | 
| 388 | - if($param != "") $params[] = "hid=".$param; | |
| 388 | + if ($param != "") $params[] = "hid=".$param; | |
| 389 | 389 | |
| 390 | 390 | $param = $this->auto_hide_time; | 
| 391 | - if($param != "") $params[] = "hdt=".$param; | |
| 391 | + if ($param != "") $params[] = "hdt=".$param; | |
| 392 | 392 | |
| 393 | 393 | $param = $this->timezone; | 
| 394 | - if($param != "") $params[] = "tmz=".$param; | |
| 394 | + if ($param != "") $params[] = "tmz=".$param; | |
| 395 | 395 | |
| 396 | 396 | //$param = $this->system_timezone; | 
| 397 | 397 | //if($param != "") $params[] = "stz=".$param; | 
| 398 | 398 | |
| 399 | 399 | $param = $this->theme; | 
| 400 | - if($param != "") $params[] = "thm=".$param; | |
| 400 | + if ($param != "") $params[] = "thm=".$param; | |
| 401 | 401 | |
| 402 | 402 |  		$paramStr = (sizeof($params)>0) ? "?".implode("&", $params) : "";
 | 
| 403 | 403 | |
| 404 | -		if($this->date_picker){
 | |
| 404 | +		if ($this->date_picker) {
 | |
| 405 | 405 | $div_display = "hidden"; | 
| 406 | 406 | $div_position = "absolute"; | 
| 407 | 407 | |
| 408 | 408 | $line_height = $this->line_height; | 
| 409 | 409 | |
| 410 | -			if(is_file($this->icon)){
 | |
| 410 | +			if (is_file($this->icon)) {
 | |
| 411 | 411 | $img_attribs = getimagesize($this->icon); | 
| 412 | 412 | $line_height = $img_attribs[1]+2; | 
| 413 | 413 | } | 
| @@ -415,7 +415,7 @@ discard block | ||
| 415 | 415 | $div_align = ""; | 
| 416 | 416 | |
| 417 | 417 | //adjust alignment | 
| 418 | -			switch($this->v_align){
 | |
| 418 | +			switch ($this->v_align) {
 | |
| 419 | 419 | case "top": | 
| 420 | 420 | $div_align .= "bottom:".$line_height."px;"; | 
| 421 | 421 | break; | 
| @@ -424,7 +424,7 @@ discard block | ||
| 424 | 424 | $div_align .= "top:".$line_height."px;"; | 
| 425 | 425 | } | 
| 426 | 426 | |
| 427 | -			switch($this->h_align){
 | |
| 427 | +			switch ($this->h_align) {
 | |
| 428 | 428 | case "left": | 
| 429 | 429 | $div_align .= "left:0px;"; | 
| 430 | 430 | break; | 
| @@ -432,7 +432,7 @@ discard block | ||
| 432 | 432 | default: | 
| 433 | 433 | $div_align .= "right:0px;"; | 
| 434 | 434 | } | 
| 435 | -		}else{
 | |
| 435 | +		}else {
 | |
| 436 | 436 | $div_display = "visible"; | 
| 437 | 437 | $div_position = "relative"; | 
| 438 | 438 | $div_align = ""; | 
| @@ -452,15 +452,15 @@ discard block | ||
| 452 | 452 | } | 
| 453 | 453 | |
| 454 | 454 | //write the select box of days | 
| 455 | -	function writeDay(){
 | |
| 455 | +	function writeDay() {
 | |
| 456 | 456 | $total_days = $this->total_days($this->month, $this->year); | 
| 457 | 457 | |
| 458 | 458 | $str = ""; | 
| 459 | 459 |  		$str .= "<select name=\"".$this->objname."_day\" id=\"".$this->objname."_day\" onChange=\"javascript:tc_setDay('".$this->objname."', this[this.selectedIndex].value);\" class=\"tcday\"".($this->rtl ? " dir=\"rtl\"" : "").">";
 | 
| 460 | 460 | $str .= "<option value=\"00\"".($this->rtl ? " dir=\"rtl\"" : "").">Day</option>"; | 
| 461 | -		for($i=1; $i<=$total_days; $i++){
 | |
| 462 | - $selected = ((int)$this->day == $i) ? " selected='selected'" : ""; | |
| 463 | - $str .= "<option value=\"".str_pad($i, 2 , "0", STR_PAD_LEFT)."\"".$selected.($this->rtl ? " dir=\"rtl\"" : "").">".$i."</option>"; | |
| 461 | +		for ($i = 1; $i<=$total_days; $i++) {
 | |
| 462 | + $selected = ((int) $this->day == $i) ? " selected='selected'" : ""; | |
| 463 | + $str .= "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"".$selected.($this->rtl ? " dir=\"rtl\"" : "").">".$i."</option>"; | |
| 464 | 464 | } | 
| 465 | 465 | $str .= "</select> "; | 
| 466 | 466 | |
| @@ -468,14 +468,14 @@ discard block | ||
| 468 | 468 | } | 
| 469 | 469 | |
| 470 | 470 | //write the select box of months | 
| 471 | -	function writeMonth(){
 | |
| 471 | +	function writeMonth() {
 | |
| 472 | 472 | $str = ""; | 
| 473 | 473 |  		$str .= "<select name=\"".$this->objname."_month\" id=\"".$this->objname."_month\" onChange=\"javascript:tc_setMonth('".$this->objname."', this[this.selectedIndex].value);\" class=\"tcmonth\"".($this->rtl ? " dir=\"rtl\"" : "").">";
 | 
| 474 | 474 | $str .= "<option value=\"00\"".($this->rtl ? " dir=\"rtl\"" : "").">Month</option>"; | 
| 475 | 475 | |
| 476 | 476 | $monthnames = $this->getMonthNames(); | 
| 477 | -		for($i=1; $i<=sizeof($monthnames); $i++){
 | |
| 478 | - $selected = ((int)$this->month == $i) ? " selected='selected'" : ""; | |
| 477 | +		for ($i = 1; $i<=sizeof($monthnames); $i++) {
 | |
| 478 | + $selected = ((int) $this->month == $i) ? " selected='selected'" : ""; | |
| 479 | 479 | $str .= "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"".$selected.($this->rtl ? " dir=\"rtl\"" : "").">".$monthnames[$i-1]."</option>"; | 
| 480 | 480 | } | 
| 481 | 481 | $str .= "</select> "; | 
| @@ -484,7 +484,7 @@ discard block | ||
| 484 | 484 | } | 
| 485 | 485 | |
| 486 | 486 | //write the year textbox | 
| 487 | -	function writeYear(){
 | |
| 487 | +	function writeYear() {
 | |
| 488 | 488 | $str = ""; | 
| 489 | 489 |  		//echo("<input type=\"textbox\" name=\"".$this->objname."_year\" id=\"".$this->objname."_year\" value=\"$this->year\" maxlength=4 size=5 onBlur=\"javascript:tc_setYear('".$this->objname."', this.value, '$this->path');\" onKeyPress=\"javascript:if(yearEnter(event)){ tc_setYear('".$this->objname."', this.value, '$this->path'); return false; }\"> ");
 | 
| 490 | 490 |  		$str .= "<select name=\"".$this->objname."_year\" id=\"".$this->objname."_year\" onChange=\"javascript:tc_setYear('".$this->objname."', this[this.selectedIndex].value);\" class=\"tcyear\"".($this->rtl ? " dir=\"rtl\"" : "").">";
 | 
| @@ -494,21 +494,21 @@ discard block | ||
| 494 | 494 | $year_end = $this->year_end; | 
| 495 | 495 | |
| 496 | 496 | //check year to be selected in case of time_allow is set | 
| 497 | -		if(!$this->show_not_allow && ($this->time_allow1 || $this->time_allow2)){
 | |
| 498 | -			if($this->time_allow1 && $this->time_allow2){
 | |
| 497 | +		if (!$this->show_not_allow && ($this->time_allow1 || $this->time_allow2)) {
 | |
| 498 | +			if ($this->time_allow1 && $this->time_allow2) {
 | |
| 499 | 499 |  				$year_start = $this->mydate->getDate("Y", $this->time_allow1);
 | 
| 500 | 500 |  				$year_end = $this->mydate->getDate("Y", $this->time_allow2);
 | 
| 501 | -			}elseif($this->time_allow1){
 | |
| 501 | +			}elseif ($this->time_allow1) {
 | |
| 502 | 502 | //only date 1 specified | 
| 503 | 503 |  				$year_start = $this->mydate->getDate("Y", $this->time_allow1);
 | 
| 504 | -			}elseif($this->time_allow2){
 | |
| 504 | +			}elseif ($this->time_allow2) {
 | |
| 505 | 505 | //only date 2 specified | 
| 506 | 506 |  				$year_end = $this->mydate->getDate("Y", $this->time_allow2);
 | 
| 507 | 507 | } | 
| 508 | 508 | } | 
| 509 | 509 | |
| 510 | -		for($i=$year_end; $i>=$year_start; $i--){
 | |
| 511 | - $selected = ((int)$this->year == $i) ? " selected='selected'" : ""; | |
| 510 | +		for ($i = $year_end; $i>=$year_start; $i--) {
 | |
| 511 | + $selected = ((int) $this->year == $i) ? " selected='selected'" : ""; | |
| 512 | 512 | $str .= "<option value=\"".$i."\"".$selected.($this->rtl ? " dir=\"rtl\"" : "").">".$i."</option>"; | 
| 513 | 513 | } | 
| 514 | 514 | $str .= "</select> "; | 
| @@ -517,14 +517,14 @@ discard block | ||
| 517 | 517 | } | 
| 518 | 518 | |
| 519 | 519 |  	function eHidden($suffix, $value) {
 | 
| 520 | -		if(trim($value) != ""){
 | |
| 521 | - if($suffix) $suffix = "_".$suffix; | |
| 520 | +		if (trim($value) != "") {
 | |
| 521 | + if ($suffix) $suffix = "_".$suffix; | |
| 522 | 522 | return "<input type=\"hidden\" name=\"".$this->objname.$suffix."\" id=\"".$this->objname.$suffix."\" value=\"".$value."\" />"; | 
| 523 | 523 | } | 
| 524 | 524 | } | 
| 525 | 525 | |
| 526 | 526 | //write hidden components | 
| 527 | -	function writeHidden(){
 | |
| 527 | +	function writeHidden() {
 | |
| 528 | 528 | $str = ""; | 
| 529 | 529 | |
| 530 | 530 |  		$str .= $this->eHidden('', $this->getDate());
 | 
| @@ -574,8 +574,8 @@ discard block | ||
| 574 | 574 | // Deprecated since version 2.9 | 
| 575 | 575 | // Auto sizing is applied | 
| 576 | 576 | //--------------------------- | 
| 577 | -	function setWidth($width){
 | |
| 578 | - if($width) $this->width = $width; | |
| 577 | +	function setWidth($width) {
 | |
| 578 | + if ($width) $this->width = $width; | |
| 579 | 579 | } | 
| 580 | 580 | |
| 581 | 581 | //set height of calendar | 
| @@ -583,27 +583,27 @@ discard block | ||
| 583 | 583 | // Deprecated since version 2.9 | 
| 584 | 584 | // Auto sizing is applied | 
| 585 | 585 | //--------------------------- | 
| 586 | -	function setHeight($height){
 | |
| 587 | - if($height) $this->height = $height; | |
| 586 | +	function setHeight($height) {
 | |
| 587 | + if ($height) $this->height = $height; | |
| 588 | 588 | } | 
| 589 | 589 | |
| 590 | -	function setYearInterval($start, $end){
 | |
| 590 | +	function setYearInterval($start, $end) {
 | |
| 591 | 591 | $this->year_start_input = $start; | 
| 592 | 592 | $this->year_end_input = $end; | 
| 593 | 593 | |
| 594 | - if(!$start) $start = $this->year_start; | |
| 595 | - if(!$end) $end = $this->year_end; | |
| 594 | + if (!$start) $start = $this->year_start; | |
| 595 | + if (!$end) $end = $this->year_end; | |
| 596 | 596 | |
| 597 | -		if($start < $end){
 | |
| 597 | +		if ($start<$end) {
 | |
| 598 | 598 | $this->year_start = $start; | 
| 599 | 599 | $this->year_end = $end; | 
| 600 | -		}else{
 | |
| 600 | +		}else {
 | |
| 601 | 601 | $this->year_start = $end; | 
| 602 | 602 | $this->year_end = $start; | 
| 603 | 603 | } | 
| 604 | 604 | } | 
| 605 | 605 | |
| 606 | -	function getMonthNames(){
 | |
| 606 | +	function getMonthNames() {
 | |
| 607 | 607 |  		return array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
 | 
| 608 | 608 | } | 
| 609 | 609 | |
| @@ -611,24 +611,24 @@ discard block | ||
| 611 | 611 | // Deprecated since version 3.61 | 
| 612 | 612 | // override by startDate() | 
| 613 | 613 | //------------------------------- | 
| 614 | -	function startMonday($flag){
 | |
| 614 | +	function startMonday($flag) {
 | |
| 615 | 615 | //$this->startMonday = $flag; | 
| 616 | 616 | |
| 617 | 617 | //change it so that it will not cause an error after version 3.61 | 
| 618 | - if($flag) $this->startDate = 1; | |
| 618 | + if ($flag) $this->startDate = 1; | |
| 619 | 619 | } | 
| 620 | 620 | |
| 621 | -	function startDate($num){
 | |
| 622 | - if(is_numeric($num) && $num >= 0 && $num <= 6) | |
| 621 | +	function startDate($num) {
 | |
| 622 | + if (is_numeric($num) && $num>=0 && $num<=6) | |
| 623 | 623 | $this->startDate = $num; | 
| 624 | 624 | } | 
| 625 | 625 | |
| 626 | -	function dateAllow($from = "", $to = "", $show_not_allow = true){
 | |
| 626 | +	function dateAllow($from = "", $to = "", $show_not_allow = true) {
 | |
| 627 | 627 | $time_from = $this->mydate->validDate($from) ? $from : null; | 
| 628 | 628 | $time_to = $this->mydate->validDate($to) ? $to : null; | 
| 629 | 629 | |
| 630 | 630 | // sanity check, ensure time_from earlier than time_to | 
| 631 | -		if($time_from != null && $time_to != null && $this->mydate->dateAfter($time_to, $time_from, true)){
 | |
| 631 | +		if ($time_from != null && $time_to != null && $this->mydate->dateAfter($time_to, $time_from, true)) {
 | |
| 632 | 632 | $tmp = $time_from; | 
| 633 | 633 | $time_from = $time_to; | 
| 634 | 634 | $time_to = $tmp; | 
| @@ -637,40 +637,40 @@ discard block | ||
| 637 | 637 |  		if ($time_from != null) {
 | 
| 638 | 638 | $this->time_allow1 = $time_from; | 
| 639 | 639 |  			$y = $this->mydate->getDate('Y', $time_from);
 | 
| 640 | - if($this->year_start && $y > $this->year_start) $this->year_start = $y; | |
| 640 | + if ($this->year_start && $y>$this->year_start) $this->year_start = $y; | |
| 641 | 641 | |
| 642 | 642 | //setup year end from year start | 
| 643 | - if($time_to == null && !$this->year_end) $this->year_end = $this->year_start + $this->year_display_from_current; | |
| 643 | + if ($time_to == null && !$this->year_end) $this->year_end = $this->year_start+$this->year_display_from_current; | |
| 644 | 644 | } | 
| 645 | 645 | |
| 646 | 646 |  		if ($time_to>0) {
 | 
| 647 | 647 | $this->time_allow2 = $time_to; | 
| 648 | 648 |  			$y = $this->mydate->getDate('Y', $time_to);
 | 
| 649 | - if($this->year_end && $y < $this->year_end) $this->year_end = $y; | |
| 649 | + if ($this->year_end && $y<$this->year_end) $this->year_end = $y; | |
| 650 | 650 | |
| 651 | 651 | //setup year start from year end | 
| 652 | - if($time_from == null && !$this->year_start) $this->year_start = $this->year_end - $this->year_display_from_current; | |
| 652 | + if ($time_from == null && !$this->year_start) $this->year_start = $this->year_end-$this->year_display_from_current; | |
| 653 | 653 | } | 
| 654 | 654 | |
| 655 | 655 | $this->show_not_allow = $show_not_allow; | 
| 656 | 656 | } | 
| 657 | 657 | |
| 658 | -	function autoSubmit($auto, $form_name, $target = ""){
 | |
| 658 | +	function autoSubmit($auto, $form_name, $target = "") {
 | |
| 659 | 659 | $this->auto_submit = $auto; | 
| 660 | 660 | $this->form_container = $form_name; | 
| 661 | 661 | $this->target_url = $target; | 
| 662 | 662 | } | 
| 663 | 663 | |
| 664 | -	function getDate(){
 | |
| 664 | +	function getDate() {
 | |
| 665 | 665 | return str_pad($this->year, 4, "0", STR_PAD_LEFT)."-".str_pad($this->month, 2, "0", STR_PAD_LEFT)."-".str_pad($this->day, 2, "0", STR_PAD_LEFT); | 
| 666 | 666 | } | 
| 667 | 667 | |
| 668 | -	function showInput($flag){
 | |
| 668 | +	function showInput($flag) {
 | |
| 669 | 669 | $this->show_input = $flag; | 
| 670 | 670 | } | 
| 671 | 671 | |
| 672 | -	function writeDateContainer(){
 | |
| 673 | -		if($this->day && $this->month && $this->year){
 | |
| 672 | +	function writeDateContainer() {
 | |
| 673 | +		if ($this->day && $this->month && $this->year) {
 | |
| 674 | 674 | $dd = $this->mydate->getDate($this->date_format, $this->year."-".$this->month."-".$this->day); | 
| 675 | 675 | }else $dd = "Select Date"; | 
| 676 | 676 | |
| @@ -681,47 +681,47 @@ discard block | ||
| 681 | 681 | // This function disable day column as specified value | 
| 682 | 682 | // day values : Sun, Mon, Tue, Wed, Thu, Fri, Sat | 
| 683 | 683 | //------------------------------------------------------ | 
| 684 | -	function disabledDay($day){
 | |
| 684 | +	function disabledDay($day) {
 | |
| 685 | 685 | $day = strtolower($day); //make it not case-sensitive | 
| 686 | - if(in_array($day, $this->dsb_days) === false) | |
| 686 | + if (in_array($day, $this->dsb_days) === false) | |
| 687 | 687 | $this->dsb_days[] = $day; | 
| 688 | 688 | } | 
| 689 | 689 | |
| 690 | -	function setAlignment($h_align, $v_align){
 | |
| 690 | +	function setAlignment($h_align, $v_align) {
 | |
| 691 | 691 | $this->h_align = $h_align; | 
| 692 | 692 | $this->v_align = $v_align; | 
| 693 | 693 | } | 
| 694 | 694 | |
| 695 | -	function setDatePair($calendar_name1, $calendar_name2, $pair_value = "0000-00-00 00:00:00"){
 | |
| 696 | -		if($calendar_name1 != $this->objname){
 | |
| 695 | +	function setDatePair($calendar_name1, $calendar_name2, $pair_value = "0000-00-00 00:00:00") {
 | |
| 696 | +		if ($calendar_name1 != $this->objname) {
 | |
| 697 | 697 | $this->date_pair1 = $calendar_name1; | 
| 698 | - if($pair_value != "0000-00-00 00:00:00") | |
| 698 | + if ($pair_value != "0000-00-00 00:00:00") | |
| 699 | 699 | $this->date_pair_value = $pair_value; | 
| 700 | -		}elseif($calendar_name2 != $this->objname){
 | |
| 700 | +		}elseif ($calendar_name2 != $this->objname) {
 | |
| 701 | 701 | $this->date_pair2 = $calendar_name2; | 
| 702 | - if($pair_value != "0000-00-00 00:00:00") | |
| 702 | + if ($pair_value != "0000-00-00 00:00:00") | |
| 703 | 703 | $this->date_pair_value = $pair_value; | 
| 704 | 704 | } | 
| 705 | 705 | } | 
| 706 | 706 | |
| 707 | -	function setSpecificDate($dates, $type=0, $recursive=""){
 | |
| 708 | -		if(is_array($dates)){
 | |
| 707 | +	function setSpecificDate($dates, $type = 0, $recursive = "") {
 | |
| 708 | +		if (is_array($dates)) {
 | |
| 709 | 709 | $recursive = strtolower($recursive); | 
| 710 | 710 | |
| 711 | 711 | //change specific date to time | 
| 712 | -			foreach($dates as $sp_date){
 | |
| 713 | -				if($this->mydate->validDate($sp_date)){
 | |
| 714 | -					switch($recursive){
 | |
| 712 | +			foreach ($dates as $sp_date) {
 | |
| 713 | +				if ($this->mydate->validDate($sp_date)) {
 | |
| 714 | +					switch ($recursive) {
 | |
| 715 | 715 | case "month": //add to monthly | 
| 716 | - if(!in_array($sp_date, $this->sp_dates[1])) | |
| 716 | + if (!in_array($sp_date, $this->sp_dates[1])) | |
| 717 | 717 | $this->sp_dates[1][] = $sp_date; | 
| 718 | 718 | break; | 
| 719 | 719 | case "year": //add to yearly | 
| 720 | - if(!in_array($sp_date, $this->sp_dates[2])) | |
| 720 | + if (!in_array($sp_date, $this->sp_dates[2])) | |
| 721 | 721 | $this->sp_dates[2][] = $sp_date; | 
| 722 | 722 | break; | 
| 723 | 723 | default: //add to no recursive | 
| 724 | - if(!in_array($sp_date, $this->sp_dates[0])) | |
| 724 | + if (!in_array($sp_date, $this->sp_dates[0])) | |
| 725 | 725 | $this->sp_dates[0][] = $sp_date; | 
| 726 | 726 | } | 
| 727 | 727 | } | 
| @@ -762,7 +762,7 @@ discard block | ||
| 762 | 762 | } | 
| 763 | 763 | */ | 
| 764 | 764 | |
| 765 | -	function checkDefaultDateValid($reset = true){
 | |
| 765 | +	function checkDefaultDateValid($reset = true) {
 | |
| 766 | 766 | $date_str = $this->year."-".str_pad($this->month, 2, "0", STR_PAD_LEFT)."-".str_pad($this->day, 2, "0", STR_PAD_LEFT); | 
| 767 | 767 | //$default_datetime = $this->mydate->getTimestamp($date_str); | 
| 768 | 768 | /* | 
| @@ -776,72 +776,72 @@ discard block | ||
| 776 | 776 | $end_interval = $this->year_end."-12-31"; | 
| 777 | 777 | |
| 778 | 778 | //check if set date is before start_interval | 
| 779 | -		if($this->mydate->dateBefore($start_interval, $date_str)){
 | |
| 779 | +		if ($this->mydate->dateBefore($start_interval, $date_str)) {
 | |
| 780 | 780 | return false; | 
| 781 | 781 | } | 
| 782 | 782 | |
| 783 | 783 | //check if set date is after end_interval | 
| 784 | -		if($this->mydate->dateAfter($end_interval, $date_str)){
 | |
| 784 | +		if ($this->mydate->dateAfter($end_interval, $date_str)) {
 | |
| 785 | 785 | return false; | 
| 786 | 786 | } | 
| 787 | 787 | |
| 788 | 788 | //check with allow date | 
| 789 | -		if($this->time_allow1 && $this->time_allow2){
 | |
| 790 | -			if($this->mydate->dateBefore($this->time_allow1, $date_str, false) || $this->mydate->dateAfter($this->time_allow2, $date_str, false)){
 | |
| 789 | +		if ($this->time_allow1 && $this->time_allow2) {
 | |
| 790 | +			if ($this->mydate->dateBefore($this->time_allow1, $date_str, false) || $this->mydate->dateAfter($this->time_allow2, $date_str, false)) {
 | |
| 791 | 791 | return false; | 
| 792 | 792 | } | 
| 793 | -		}elseif($this->time_allow1){
 | |
| 794 | - if($this->mydate->dateBefore($this->time_allow1, $date_str, false)) return false; | |
| 795 | -		}elseif($this->time_allow2){
 | |
| 796 | - if($this->mydate->dateAfter($this->time_allow2, $date_str, false)) return false; | |
| 793 | +		}elseif ($this->time_allow1) {
 | |
| 794 | + if ($this->mydate->dateBefore($this->time_allow1, $date_str, false)) return false; | |
| 795 | +		}elseif ($this->time_allow2) {
 | |
| 796 | + if ($this->mydate->dateAfter($this->time_allow2, $date_str, false)) return false; | |
| 797 | 797 | } | 
| 798 | 798 | |
| 799 | 799 | //check with specific date | 
| 800 | -		if(is_array($this->sp_dates) && sizeof($this->sp_dates) > 0){
 | |
| 800 | +		if (is_array($this->sp_dates) && sizeof($this->sp_dates)>0) {
 | |
| 801 | 801 | //check if it is current date | 
| 802 | 802 | $sp_found = false; | 
| 803 | 803 | |
| 804 | -			if(isset($this->sp_dates[2])){
 | |
| 805 | -				foreach($this->sp_dates[2] as $sp_time){
 | |
| 804 | +			if (isset($this->sp_dates[2])) {
 | |
| 805 | +				foreach ($this->sp_dates[2] as $sp_time) {
 | |
| 806 | 806 |  					$this_md = $this->mydate->getDate("md", $date_str);
 | 
| 807 | 807 |  					$sp_time_md = $this->mydate->getDate("md", $sp_time);
 | 
| 808 | -					if($sp_time_md == $this_md){
 | |
| 808 | +					if ($sp_time_md == $this_md) {
 | |
| 809 | 809 | $sp_found = true; | 
| 810 | 810 | break; | 
| 811 | 811 | } | 
| 812 | 812 | } | 
| 813 | 813 | } | 
| 814 | 814 | |
| 815 | -			if(isset($this->sp_dates[1]) && !$sp_found){
 | |
| 816 | -				foreach($this->sp_dates[1] as $sp_time){
 | |
| 815 | +			if (isset($this->sp_dates[1]) && !$sp_found) {
 | |
| 816 | +				foreach ($this->sp_dates[1] as $sp_time) {
 | |
| 817 | 817 |  					$sp_time_d = $this->mydate->getDate("d", $sp_time);
 | 
| 818 | -					if($sp_time_d == $this->day){
 | |
| 818 | +					if ($sp_time_d == $this->day) {
 | |
| 819 | 819 | $sp_found = true; | 
| 820 | 820 | break; | 
| 821 | 821 | } | 
| 822 | 822 | } | 
| 823 | 823 | } | 
| 824 | 824 | |
| 825 | -			if(isset($this->sp_dates[0]) && !$sp_found){
 | |
| 825 | +			if (isset($this->sp_dates[0]) && !$sp_found) {
 | |
| 826 | 826 | $sp_found = in_array($date_str, $this->sp_dates[0]); | 
| 827 | 827 | } | 
| 828 | 828 | |
| 829 | -			switch($this->sp_type){
 | |
| 829 | +			switch ($this->sp_type) {
 | |
| 830 | 830 | case 0: | 
| 831 | 831 | default: | 
| 832 | 832 | //disabled specific and enabled others | 
| 833 | - if($sp_found) return false; | |
| 833 | + if ($sp_found) return false; | |
| 834 | 834 | break; | 
| 835 | 835 | case 1: | 
| 836 | 836 | //enabled specific and disabled others | 
| 837 | - if(!$sp_found) return false; | |
| 837 | + if (!$sp_found) return false; | |
| 838 | 838 | break; | 
| 839 | 839 | } | 
| 840 | 840 | } | 
| 841 | 841 | |
| 842 | -		if(is_array($this->dsb_days) && sizeof($this->dsb_days) > 0){
 | |
| 842 | +		if (is_array($this->dsb_days) && sizeof($this->dsb_days)>0) {
 | |
| 843 | 843 |  			$day_txt = $this->mydate->getDate("D", $date_str);
 | 
| 844 | -			if(in_array(strtolower($day_txt), $this->dsb_days) !== false){
 | |
| 844 | +			if (in_array(strtolower($day_txt), $this->dsb_days) !== false) {
 | |
| 845 | 845 | return false; | 
| 846 | 846 | } | 
| 847 | 847 | } | 
| @@ -849,16 +849,16 @@ discard block | ||
| 849 | 849 | return true; | 
| 850 | 850 | } | 
| 851 | 851 | |
| 852 | -	function check_json_encode($obj){
 | |
| 852 | +	function check_json_encode($obj) {
 | |
| 853 | 853 | //try customize to get it work, should replace with better solution in the future | 
| 854 | -		if(is_array($obj)){
 | |
| 855 | -			if(function_exists("json_encode") && false){
 | |
| 854 | +		if (is_array($obj)) {
 | |
| 855 | +			if (function_exists("json_encode") && false) {
 | |
| 856 | 856 | return json_encode($obj); | 
| 857 | -			}else{
 | |
| 857 | +			}else {
 | |
| 858 | 858 | //only array is assumed for now | 
| 859 | 859 | $return_arr = array(); | 
| 860 | -				foreach($obj as $arr){
 | |
| 861 | - if(is_array($arr) && sizeof($arr)>0) | |
| 860 | +				foreach ($obj as $arr) {
 | |
| 861 | + if (is_array($arr) && sizeof($arr)>0) | |
| 862 | 862 |  						$return_arr[] = "[\"".implode("\",\"", $arr)."\"]";
 | 
| 863 | 863 | else $return_arr[] = "[]"; | 
| 864 | 864 | } | 
| @@ -870,17 +870,17 @@ discard block | ||
| 870 | 870 |  	function &check_json_decode($str){
 | 
| 871 | 871 | //should replace with better solution in the future | 
| 872 | 872 | |
| 873 | -		if(function_exists("json_decode") && false){
 | |
| 873 | +		if (function_exists("json_decode") && false) {
 | |
| 874 | 874 | return json_decode($str); | 
| 875 | -		}else{
 | |
| 875 | +		}else {
 | |
| 876 | 876 | //only array is assume for now | 
| 877 | 877 | $str = stripslashes(rawurldecode($str)); | 
| 878 | 878 | $str = trim($str); | 
| 879 | 879 | |
| 880 | -			if($str && strlen($str) > 2){
 | |
| 880 | +			if ($str && strlen($str)>2) {
 | |
| 881 | 881 | $str = substr($str, 1, strlen($str)-2); | 
| 882 | 882 | |
| 883 | -				if($str && strlen($str) > 2){
 | |
| 883 | +				if ($str && strlen($str)>2) {
 | |
| 884 | 884 | $str = substr($str, 1, strlen($str)-2); | 
| 885 | 885 | |
| 886 | 886 | $return_arr = array(); | 
| @@ -888,15 +888,15 @@ discard block | ||
| 888 | 888 | $offset = 0; | 
| 889 | 889 | |
| 890 | 890 |  					$arr = explode("],[", $str);
 | 
| 891 | -					for($i=0; $i<sizeof($arr); $i++){
 | |
| 891 | +					for ($i = 0; $i<sizeof($arr); $i++) {
 | |
| 892 | 892 | $this_v = $arr[$i]; | 
| 893 | - if($this_v == "") | |
| 893 | + if ($this_v == "") | |
| 894 | 894 | $return_arr[] = array(); | 
| 895 | -						else{
 | |
| 895 | +						else {
 | |
| 896 | 896 |  							$this_arr = explode(",", $this_v);
 | 
| 897 | 897 | |
| 898 | -							for($j=0; $j<sizeof($this_arr); $j++){
 | |
| 899 | -								if(substr($this_arr[$j], 0, 1)=="\"" && substr($this_arr[$j], strlen($this_arr[$j])-1, 1)=="\""){
 | |
| 898 | +							for ($j = 0; $j<sizeof($this_arr); $j++) {
 | |
| 899 | +								if (substr($this_arr[$j], 0, 1) == "\"" && substr($this_arr[$j], strlen($this_arr[$j])-1, 1) == "\"") {
 | |
| 900 | 900 | $this_arr[$j] = substr($this_arr[$j], 1, strlen($this_arr[$j])-2); | 
| 901 | 901 | } | 
| 902 | 902 | } | 
| @@ -910,17 +910,17 @@ discard block | ||
| 910 | 910 | } | 
| 911 | 911 | } | 
| 912 | 912 | |
| 913 | -	function setOnChange($value){
 | |
| 913 | +	function setOnChange($value) {
 | |
| 914 | 914 | $this->tc_onchanged = $value; | 
| 915 | 915 | } | 
| 916 | 916 | |
| 917 | -	function showWeeks($flag){
 | |
| 917 | +	function showWeeks($flag) {
 | |
| 918 | 918 | $this->show_week = $flag; | 
| 919 | 919 | } | 
| 920 | 920 | |
| 921 | -	function setAutoHide($auto, $time = ""){
 | |
| 921 | +	function setAutoHide($auto, $time = "") {
 | |
| 922 | 922 | $this->auto_hide = ($auto) ? 1 : 0; | 
| 923 | -		if($time != "" && $time >= 0){
 | |
| 923 | +		if ($time != "" && $time>=0) {
 | |
| 924 | 924 | $this->auto_hide_time = $time; | 
| 925 | 925 | } | 
| 926 | 926 | } | 
| @@ -928,66 +928,66 @@ discard block | ||
| 928 | 928 | //***************** | 
| 929 | 929 | // Validate the today date of calendar | 
| 930 | 930 | //***************** | 
| 931 | -	function validTodayDate(){
 | |
| 931 | +	function validTodayDate() {
 | |
| 932 | 932 | $today = $this->mydate->getDate(); | 
| 933 | 933 | |
| 934 | 934 | //check if today is year 2038 and later | 
| 935 | -		if(!$this->mydate->compatible && $this->mydate->getDate("Y") >= 2038){
 | |
| 935 | +		if (!$this->mydate->compatible && $this->mydate->getDate("Y")>=2038) {
 | |
| 936 | 936 | return false; | 
| 937 | 937 | } | 
| 938 | 938 | |
| 939 | 939 | //check if today is in range of date allow | 
| 940 | -		if($this->time_allow1 != ""){
 | |
| 940 | +		if ($this->time_allow1 != "") {
 | |
| 941 | 941 | //check valid if today is after date_allow1 | 
| 942 | - if($this->mydate->validDate($this->time_allow1) && !$this->mydate->dateAfter($this->time_allow1, $today)) | |
| 942 | + if ($this->mydate->validDate($this->time_allow1) && !$this->mydate->dateAfter($this->time_allow1, $today)) | |
| 943 | 943 | return false; | 
| 944 | 944 | } | 
| 945 | 945 | |
| 946 | -		if($this->time_allow2 > 0){
 | |
| 946 | +		if ($this->time_allow2>0) {
 | |
| 947 | 947 | //check valid if today is before date_allow2 | 
| 948 | - if($this->mydate->validDate($this->time_allow2) && !$this->mydate->dateBefore($this->time_allow2, $today)) | |
| 948 | + if ($this->mydate->validDate($this->time_allow2) && !$this->mydate->dateBefore($this->time_allow2, $today)) | |
| 949 | 949 | return false; | 
| 950 | 950 | } | 
| 951 | 951 | return true; | 
| 952 | 952 | } | 
| 953 | 953 | |
| 954 | 954 | //Tooltips | 
| 955 | -	function setToolTips($dates, $tooltip="", $recursive=""){
 | |
| 955 | +	function setToolTips($dates, $tooltip = "", $recursive = "") {
 | |
| 956 | 956 | |
| 957 | -		if(is_array($dates)){
 | |
| 957 | +		if (is_array($dates)) {
 | |
| 958 | 958 | $recursive = strtolower($recursive); | 
| 959 | 959 | |
| 960 | 960 | //change specific date to time | 
| 961 | -			foreach($dates as $tt_date){
 | |
| 961 | +			foreach ($dates as $tt_date) {
 | |
| 962 | 962 | $tt_time = $tt_date; | 
| 963 | 963 |  //				if($tt_time > 0){
 | 
| 964 | -				switch($recursive){
 | |
| 964 | +				switch ($recursive) {
 | |
| 965 | 965 | case "year": //add to yearly | 
| 966 | -						if(!in_array($tt_time, $this->tt_dates[2])){
 | |
| 966 | +						if (!in_array($tt_time, $this->tt_dates[2])) {
 | |
| 967 | 967 | $this->tt_dates[2][] = $tt_time; | 
| 968 | 968 | $this->tt_tooltips[2][] = $tooltip; | 
| 969 | 969 | } | 
| 970 | -						else{
 | |
| 970 | +						else {
 | |
| 971 | 971 | $tt_key = array_search($tt_time, $this->tt_dates[2]); | 
| 972 | 972 | $this->tt_tooltips[2][$tt_key] = $this->tt_tooltips[2][$tt_key]."\n".$tooltip; | 
| 973 | 973 | } | 
| 974 | 974 | break; | 
| 975 | 975 | case "month": //add to monthly | 
| 976 | -						if(!in_array($tt_time, $this->tt_dates[1])){
 | |
| 976 | +						if (!in_array($tt_time, $this->tt_dates[1])) {
 | |
| 977 | 977 | $this->tt_dates[1][] = $tt_time; | 
| 978 | 978 | $this->tt_tooltips[1][] = $tooltip; | 
| 979 | 979 | } | 
| 980 | -						else{
 | |
| 980 | +						else {
 | |
| 981 | 981 | $tt_key = array_search($tt_time, $this->tt_dates[1]); | 
| 982 | 982 | $this->tt_tooltips[1][$tt_key] = $this->tt_tooltips[1][$tt_key]."\n".$tooltip; | 
| 983 | 983 | } | 
| 984 | 984 | break; | 
| 985 | 985 | default: //add to no recursive | 
| 986 | -						if(!in_array($tt_time, $this->tt_dates[0])){
 | |
| 986 | +						if (!in_array($tt_time, $this->tt_dates[0])) {
 | |
| 987 | 987 | $this->tt_dates[0][] = $tt_time; | 
| 988 | 988 | $this->tt_tooltips[0][] = $tooltip; | 
| 989 | 989 | } | 
| 990 | -						else{
 | |
| 990 | +						else {
 | |
| 991 | 991 | $tt_key = array_search($tt_time, $this->tt_dates[0]); | 
| 992 | 992 | $this->tt_tooltips[0][$tt_key] = $this->tt_tooltips[0][$tt_key]."\n".$tooltip; | 
| 993 | 993 | } | 
| @@ -997,23 +997,23 @@ discard block | ||
| 997 | 997 | } | 
| 998 | 998 | } | 
| 999 | 999 | |
| 1000 | -	function setTimezone($tz){
 | |
| 1000 | +	function setTimezone($tz) {
 | |
| 1001 | 1001 | $this->timezone = $tz; | 
| 1002 | 1002 | @date_default_timezone_set($tz); | 
| 1003 | 1003 |  		$this->timezone_offset = date('Z');
 | 
| 1004 | 1004 |  		//echo("new timezone: ".$this->timezone);
 | 
| 1005 | 1005 | } | 
| 1006 | 1006 | |
| 1007 | -	function setTheme($theme){
 | |
| 1007 | +	function setTheme($theme) {
 | |
| 1008 | 1008 | $this->theme = $theme; | 
| 1009 | 1009 | } | 
| 1010 | 1010 | |
| 1011 | -	function getThemes(){
 | |
| 1011 | +	function getThemes() {
 | |
| 1012 | 1012 | $themes = array(); | 
| 1013 | 1013 |  		$themesDirectory = dir('./css/');
 | 
| 1014 | - while($thname = $themesDirectory->read()) | |
| 1014 | + while ($thname = $themesDirectory->read()) | |
| 1015 | 1015 |  		{
 | 
| 1016 | -			if(is_dir('./css/'.$thname) && file_exists('./css/'.$thname.'/calendar.css') && !preg_match("/^[\.]/", $thname))
 | |
| 1016 | +			if (is_dir('./css/'.$thname) && file_exists('./css/'.$thname.'/calendar.css') && !preg_match("/^[\.]/", $thname))
 | |
| 1017 | 1017 |  			{
 | 
| 1018 | 1018 | $themes[$thname] = "./css/".$thname."/calendar.css"; | 
| 1019 | 1019 | }; | 
| @@ -1023,7 +1023,7 @@ discard block | ||
| 1023 | 1023 | return $themes; | 
| 1024 | 1024 | } | 
| 1025 | 1025 | |
| 1026 | -	function getThemePath($theme){
 | |
| 1026 | +	function getThemePath($theme) {
 | |
| 1027 | 1027 | $all_themes = $this->getThemes(); | 
| 1028 | 1028 | return isset($all_themes[$theme]) ? $all_themes[$theme] : ""; | 
| 1029 | 1029 | } | 
| @@ -103,7 +103,9 @@ discard block | ||
| 103 | 103 | //$this->year_display_from_current = 50; | 
| 104 | 104 | $this->date_picker = $date_picker; | 
| 105 | 105 | |
| 106 | - if($timezone != "") $this->setTimezone($timezone); | |
| 106 | +		if($timezone != "") { | |
| 107 | + $this->setTimezone($timezone); | |
| 108 | + } | |
| 107 | 109 | |
| 108 | 110 | //set default year display from current year | 
| 109 | 111 |  		$thisyear = date('Y');
 | 
| @@ -126,7 +128,9 @@ discard block | ||
| 126 | 128 | $days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | 
| 127 | 129 |  		if($month > 0 && $year > 0){
 | 
| 128 | 130 | return ($month == 2 && $this->is_leapYear($year)) ? 29 : $days[$month-1]; | 
| 129 | - }else return 31; | |
| 131 | +		} else { | |
| 132 | + return 31; | |
| 133 | + } | |
| 130 | 134 | } | 
| 131 | 135 | |
| 132 | 136 | //Deprecate since v1.6 | 
| @@ -143,7 +147,9 @@ discard block | ||
| 143 | 147 | $startdate = $this->startDate; | 
| 144 | 148 | |
| 145 | 149 |  		for($i=0; $i<=6; $i++){
 | 
| 146 | - if($startdate >= sizeof($hdrs)) $startdate = 0; | |
| 150 | +			if($startdate >= sizeof($hdrs)) { | |
| 151 | + $startdate = 0; | |
| 152 | + } | |
| 147 | 153 | //if(isset($hdrs[(string)$startdate])) | 
| 148 | 154 | $rtn_hdrs[] = $hdrs[(string)$startdate]; | 
| 149 | 155 | |
| @@ -195,7 +201,9 @@ discard block | ||
| 195 | 201 | //specified location of the calendar_form.php | 
| 196 | 202 |  	function setPath($path){
 | 
| 197 | 203 | $last_char = substr($path, strlen($path)-1, strlen($path)); | 
| 198 | - if($last_char != "/") $path .= "/"; | |
| 204 | +		if($last_char != "/") { | |
| 205 | + $path .= "/"; | |
| 206 | + } | |
| 199 | 207 | $this->path = $path; | 
| 200 | 208 | } | 
| 201 | 209 | |
| @@ -233,9 +241,9 @@ discard block | ||
| 233 | 241 | |
| 234 | 242 |  					if($tz_sys_ms>=0 && $tz_new_ms<=0){
 | 
| 235 | 243 | $timezone_diff = 0-($tz_sys_ms+abs($tz_new_ms)); | 
| 236 | -					}elseif($tz_sys_ms<=0 && $tz_new_ms>=0){
 | |
| 244 | +					} elseif($tz_sys_ms<=0 && $tz_new_ms>=0){
 | |
| 237 | 245 | $timezone_diff = abs($tz_sys_ms)+$tz_new_ms; | 
| 238 | -					}else{
 | |
| 246 | +					} else{
 | |
| 239 | 247 | $timezone_diff = $tz_sys_ms-$tz_new_ms; | 
| 240 | 248 | } | 
| 241 | 249 | $timezone_diff_hr = $timezone_diff/3600; | 
| @@ -255,7 +263,7 @@ discard block | ||
| 255 | 263 |  					$this->year = date("Y", $n_time);
 | 
| 256 | 264 |  					$this->month = date("m", $n_time);
 | 
| 257 | 265 |  					$this->day = date("d", $n_time);
 | 
| 258 | -				}else{
 | |
| 266 | +				} else{
 | |
| 259 | 267 | $date = new DateTime($a_date, new DateTimeZone($this->system_timezone)); | 
| 260 | 268 | $date->setTimezone(new DateTimeZone($this->timezone)); | 
| 261 | 269 |  					$this->year = $date->format('Y');
 | 
| @@ -276,7 +284,7 @@ discard block | ||
| 276 | 284 | $str .= $this->writeDay(); | 
| 277 | 285 | $str .= $this->writeMonth(); | 
| 278 | 286 | $str .= $this->writeYear(); | 
| 279 | -			}else{
 | |
| 287 | +			} else{
 | |
| 280 | 288 |  				$str .= " <a href=\"javascript:toggleCalendar('".$this->objname."', ".$this->auto_hide.", ".$this->auto_hide_time.");\" class=\"tclabel\">";
 | 
| 281 | 289 | $str .= $this->writeDateContainer(); | 
| 282 | 290 | $str .= "</a>"; | 
| @@ -285,19 +293,21 @@ discard block | ||
| 285 | 293 |  			$str .= " <a href=\"javascript:toggleCalendar('".$this->objname."', ".$this->auto_hide.", ".$this->auto_hide_time.");\">";
 | 
| 286 | 294 |  			if(is_file($this->icon)){
 | 
| 287 | 295 | $str .= "<img src=\"".$this->icon."\" id=\"tcbtn_".$this->objname."\" name=\"tcbtn_".$this->objname."\" border=\"0\" align=\"absmiddle\" style=\"vertical-align:middle;\" alt=\"".$this->txt."\" title=\"".$this->txt."\" />"; | 
| 288 | - }else $str .= $this->txt; | |
| 296 | +			} else { | |
| 297 | + $str .= $this->txt; | |
| 298 | + } | |
| 289 | 299 | $str .= "</a>"; | 
| 290 | 300 | |
| 291 | 301 | $str .= $this->writeCalendarContainer(); | 
| 292 | 302 | |
| 293 | 303 | $str .= "</div>"; | 
| 294 | -		}else{
 | |
| 304 | +		} else{
 | |
| 295 | 305 | $str .= $this->writeCalendarContainer(); | 
| 296 | 306 | } | 
| 297 | 307 | |
| 298 | 308 |  		if($buffer){
 | 
| 299 | 309 | return $str; | 
| 300 | -		}else{
 | |
| 310 | +		} else{
 | |
| 301 | 311 | echo($str); | 
| 302 | 312 | } | 
| 303 | 313 | } | 
| @@ -307,97 +317,157 @@ discard block | ||
| 307 | 317 | $params[] = "objname=".$this->objname; | 
| 308 | 318 | |
| 309 | 319 | $param = $this->day; | 
| 310 | - if($param != "") $params[] = "selected_day=".$param; | |
| 320 | +		if($param != "") { | |
| 321 | + $params[] = "selected_day=".$param; | |
| 322 | + } | |
| 311 | 323 | |
| 312 | 324 | $param = $this->month; | 
| 313 | - if($param != "") $params[] = "selected_month=".$param; | |
| 325 | +		if($param != "") { | |
| 326 | + $params[] = "selected_month=".$param; | |
| 327 | + } | |
| 314 | 328 | |
| 315 | 329 | $param = $this->year; | 
| 316 | - if($param != "") $params[] = "selected_year=".$param; | |
| 330 | +		if($param != "") { | |
| 331 | + $params[] = "selected_year=".$param; | |
| 332 | + } | |
| 317 | 333 | |
| 318 | 334 | $param = $this->year_start_input; | 
| 319 | - if($param != "") $params[] = "year_start=".$param; | |
| 335 | +		if($param != "") { | |
| 336 | + $params[] = "year_start=".$param; | |
| 337 | + } | |
| 320 | 338 | |
| 321 | 339 | $param = $this->year_end_input; | 
| 322 | - if($param != "") $params[] = "year_end=".$param; | |
| 340 | +		if($param != "") { | |
| 341 | + $params[] = "year_end=".$param; | |
| 342 | + } | |
| 323 | 343 | |
| 324 | 344 | $param = ($this->date_picker) ? 1 : 0; | 
| 325 | - if($param != "") $params[] = "dp=".$param; | |
| 345 | +		if($param != "") { | |
| 346 | + $params[] = "dp=".$param; | |
| 347 | + } | |
| 326 | 348 | |
| 327 | 349 | $param = $this->time_allow1; | 
| 328 | - if($param != "") $params[] = "da1=".$param; | |
| 350 | +		if($param != "") { | |
| 351 | + $params[] = "da1=".$param; | |
| 352 | + } | |
| 329 | 353 | |
| 330 | 354 | $param = $this->time_allow2; | 
| 331 | - if($param != "") $params[] = "da2=".$param; | |
| 355 | +		if($param != "") { | |
| 356 | + $params[] = "da2=".$param; | |
| 357 | + } | |
| 332 | 358 | |
| 333 | 359 | $param = $this->show_not_allow; | 
| 334 | - if($param != "") $params[] = "sna=".$param; | |
| 360 | +		if($param != "") { | |
| 361 | + $params[] = "sna=".$param; | |
| 362 | + } | |
| 335 | 363 | |
| 336 | 364 | $param = $this->auto_submit; | 
| 337 | - if($param != "") $params[] = "aut=".$param; | |
| 365 | +		if($param != "") { | |
| 366 | + $params[] = "aut=".$param; | |
| 367 | + } | |
| 338 | 368 | |
| 339 | 369 | $param = $this->form_container; | 
| 340 | - if($param != "") $params[] = "frm=".$param; | |
| 370 | +		if($param != "") { | |
| 371 | + $params[] = "frm=".$param; | |
| 372 | + } | |
| 341 | 373 | |
| 342 | 374 | $param = $this->target_url; | 
| 343 | - if($param != "") $params[] = "tar=".$param; | |
| 375 | +		if($param != "") { | |
| 376 | + $params[] = "tar=".$param; | |
| 377 | + } | |
| 344 | 378 | |
| 345 | 379 | $param = $this->show_input; | 
| 346 | - if($param != "") $params[] = "inp=".$param; | |
| 380 | +		if($param != "") { | |
| 381 | + $params[] = "inp=".$param; | |
| 382 | + } | |
| 347 | 383 | |
| 348 | 384 | $param = $this->date_format; | 
| 349 | - if($param != "") $params[] = "fmt=".$param; | |
| 385 | +		if($param != "") { | |
| 386 | + $params[] = "fmt=".$param; | |
| 387 | + } | |
| 350 | 388 | |
| 351 | 389 |  		$param = implode(",", $this->dsb_days);
 | 
| 352 | - if($param != "") $params[] = "dis=".$param; | |
| 390 | +		if($param != "") { | |
| 391 | + $params[] = "dis=".$param; | |
| 392 | + } | |
| 353 | 393 | |
| 354 | 394 | $param = $this->date_pair1; | 
| 355 | - if($param != "") $params[] = "pr1=".$param; | |
| 395 | +		if($param != "") { | |
| 396 | + $params[] = "pr1=".$param; | |
| 397 | + } | |
| 356 | 398 | |
| 357 | 399 | $param = $this->date_pair2; | 
| 358 | - if($param != "") $params[] = "pr2=".$param; | |
| 400 | +		if($param != "") { | |
| 401 | + $params[] = "pr2=".$param; | |
| 402 | + } | |
| 359 | 403 | |
| 360 | 404 | $param = $this->date_pair_value; | 
| 361 | - if($param != "") $params[] = "prv=".$param; | |
| 405 | +		if($param != "") { | |
| 406 | + $params[] = "prv=".$param; | |
| 407 | + } | |
| 362 | 408 | |
| 363 | 409 | $param = $this->path; | 
| 364 | - if($param != "") $params[] = "pth=".$param; | |
| 410 | +		if($param != "") { | |
| 411 | + $params[] = "pth=".$param; | |
| 412 | + } | |
| 365 | 413 | |
| 366 | 414 | $param = htmlspecialchars($this->check_json_encode($this->sp_dates), ENT_QUOTES); | 
| 367 | - if($param != "") $params[] = "spd=".$param; | |
| 415 | +		if($param != "") { | |
| 416 | + $params[] = "spd=".$param; | |
| 417 | + } | |
| 368 | 418 | |
| 369 | 419 | $param = $this->sp_type; | 
| 370 | - if($param != "") $params[] = "spt=".$param; | |
| 420 | +		if($param != "") { | |
| 421 | + $params[] = "spt=".$param; | |
| 422 | + } | |
| 371 | 423 | |
| 372 | 424 | $param = rawurlencode($this->tc_onchanged); | 
| 373 | - if($param != "") $params[] = "och=".$param; | |
| 425 | +		if($param != "") { | |
| 426 | + $params[] = "och=".$param; | |
| 427 | + } | |
| 374 | 428 | |
| 375 | 429 | $param = $this->startDate; | 
| 376 | - if($param != "") $params[] = "str=".$param; | |
| 430 | +		if($param != "") { | |
| 431 | + $params[] = "str=".$param; | |
| 432 | + } | |
| 377 | 433 | |
| 378 | 434 | $param = $this->rtl; | 
| 379 | - if($param != "") $params[] = "rtl=".$param; | |
| 435 | +		if($param != "") { | |
| 436 | + $params[] = "rtl=".$param; | |
| 437 | + } | |
| 380 | 438 | |
| 381 | 439 | $param = $this->show_week; | 
| 382 | - if($param != "") $params[] = "wks=".$param; | |
| 440 | +		if($param != "") { | |
| 441 | + $params[] = "wks=".$param; | |
| 442 | + } | |
| 383 | 443 | |
| 384 | 444 | $param = $this->interval; | 
| 385 | - if($param != "") $params[] = "int=".$param; | |
| 445 | +		if($param != "") { | |
| 446 | + $params[] = "int=".$param; | |
| 447 | + } | |
| 386 | 448 | |
| 387 | 449 | $param = $this->auto_hide; | 
| 388 | - if($param != "") $params[] = "hid=".$param; | |
| 450 | +		if($param != "") { | |
| 451 | + $params[] = "hid=".$param; | |
| 452 | + } | |
| 389 | 453 | |
| 390 | 454 | $param = $this->auto_hide_time; | 
| 391 | - if($param != "") $params[] = "hdt=".$param; | |
| 455 | +		if($param != "") { | |
| 456 | + $params[] = "hdt=".$param; | |
| 457 | + } | |
| 392 | 458 | |
| 393 | 459 | $param = $this->timezone; | 
| 394 | - if($param != "") $params[] = "tmz=".$param; | |
| 460 | +		if($param != "") { | |
| 461 | + $params[] = "tmz=".$param; | |
| 462 | + } | |
| 395 | 463 | |
| 396 | 464 | //$param = $this->system_timezone; | 
| 397 | 465 | //if($param != "") $params[] = "stz=".$param; | 
| 398 | 466 | |
| 399 | 467 | $param = $this->theme; | 
| 400 | - if($param != "") $params[] = "thm=".$param; | |
| 468 | +		if($param != "") { | |
| 469 | + $params[] = "thm=".$param; | |
| 470 | + } | |
| 401 | 471 | |
| 402 | 472 |  		$paramStr = (sizeof($params)>0) ? "?".implode("&", $params) : "";
 | 
| 403 | 473 | |
| @@ -432,7 +502,7 @@ discard block | ||
| 432 | 502 | default: | 
| 433 | 503 | $div_align .= "right:0px;"; | 
| 434 | 504 | } | 
| 435 | -		}else{
 | |
| 505 | +		} else{
 | |
| 436 | 506 | $div_display = "visible"; | 
| 437 | 507 | $div_position = "relative"; | 
| 438 | 508 | $div_align = ""; | 
| @@ -498,10 +568,10 @@ discard block | ||
| 498 | 568 |  			if($this->time_allow1 && $this->time_allow2){
 | 
| 499 | 569 |  				$year_start = $this->mydate->getDate("Y", $this->time_allow1);
 | 
| 500 | 570 |  				$year_end = $this->mydate->getDate("Y", $this->time_allow2);
 | 
| 501 | -			}elseif($this->time_allow1){
 | |
| 571 | +			} elseif($this->time_allow1){
 | |
| 502 | 572 | //only date 1 specified | 
| 503 | 573 |  				$year_start = $this->mydate->getDate("Y", $this->time_allow1);
 | 
| 504 | -			}elseif($this->time_allow2){
 | |
| 574 | +			} elseif($this->time_allow2){
 | |
| 505 | 575 | //only date 2 specified | 
| 506 | 576 |  				$year_end = $this->mydate->getDate("Y", $this->time_allow2);
 | 
| 507 | 577 | } | 
| @@ -518,7 +588,9 @@ discard block | ||
| 518 | 588 | |
| 519 | 589 |  	function eHidden($suffix, $value) {
 | 
| 520 | 590 |  		if(trim($value) != ""){
 | 
| 521 | - if($suffix) $suffix = "_".$suffix; | |
| 591 | +			if($suffix) { | |
| 592 | + $suffix = "_".$suffix; | |
| 593 | + } | |
| 522 | 594 | return "<input type=\"hidden\" name=\"".$this->objname.$suffix."\" id=\"".$this->objname.$suffix."\" value=\"".$value."\" />"; | 
| 523 | 595 | } | 
| 524 | 596 | } | 
| @@ -575,7 +647,9 @@ discard block | ||
| 575 | 647 | // Auto sizing is applied | 
| 576 | 648 | //--------------------------- | 
| 577 | 649 |  	function setWidth($width){
 | 
| 578 | - if($width) $this->width = $width; | |
| 650 | +		if($width) { | |
| 651 | + $this->width = $width; | |
| 652 | + } | |
| 579 | 653 | } | 
| 580 | 654 | |
| 581 | 655 | //set height of calendar | 
| @@ -584,20 +658,26 @@ discard block | ||
| 584 | 658 | // Auto sizing is applied | 
| 585 | 659 | //--------------------------- | 
| 586 | 660 |  	function setHeight($height){
 | 
| 587 | - if($height) $this->height = $height; | |
| 661 | +		if($height) { | |
| 662 | + $this->height = $height; | |
| 663 | + } | |
| 588 | 664 | } | 
| 589 | 665 | |
| 590 | 666 |  	function setYearInterval($start, $end){
 | 
| 591 | 667 | $this->year_start_input = $start; | 
| 592 | 668 | $this->year_end_input = $end; | 
| 593 | 669 | |
| 594 | - if(!$start) $start = $this->year_start; | |
| 595 | - if(!$end) $end = $this->year_end; | |
| 670 | +		if(!$start) { | |
| 671 | + $start = $this->year_start; | |
| 672 | + } | |
| 673 | +		if(!$end) { | |
| 674 | + $end = $this->year_end; | |
| 675 | + } | |
| 596 | 676 | |
| 597 | 677 |  		if($start < $end){
 | 
| 598 | 678 | $this->year_start = $start; | 
| 599 | 679 | $this->year_end = $end; | 
| 600 | -		}else{
 | |
| 680 | +		} else{
 | |
| 601 | 681 | $this->year_start = $end; | 
| 602 | 682 | $this->year_end = $start; | 
| 603 | 683 | } | 
| @@ -615,12 +695,15 @@ discard block | ||
| 615 | 695 | //$this->startMonday = $flag; | 
| 616 | 696 | |
| 617 | 697 | //change it so that it will not cause an error after version 3.61 | 
| 618 | - if($flag) $this->startDate = 1; | |
| 698 | +		if($flag) { | |
| 699 | + $this->startDate = 1; | |
| 700 | + } | |
| 619 | 701 | } | 
| 620 | 702 | |
| 621 | 703 |  	function startDate($num){
 | 
| 622 | - if(is_numeric($num) && $num >= 0 && $num <= 6) | |
| 623 | - $this->startDate = $num; | |
| 704 | +		if(is_numeric($num) && $num >= 0 && $num <= 6) { | |
| 705 | + $this->startDate = $num; | |
| 706 | + } | |
| 624 | 707 | } | 
| 625 | 708 | |
| 626 | 709 |  	function dateAllow($from = "", $to = "", $show_not_allow = true){
 | 
| @@ -637,19 +720,27 @@ discard block | ||
| 637 | 720 |  		if ($time_from != null) {
 | 
| 638 | 721 | $this->time_allow1 = $time_from; | 
| 639 | 722 |  			$y = $this->mydate->getDate('Y', $time_from);
 | 
| 640 | - if($this->year_start && $y > $this->year_start) $this->year_start = $y; | |
| 723 | +			if($this->year_start && $y > $this->year_start) { | |
| 724 | + $this->year_start = $y; | |
| 725 | + } | |
| 641 | 726 | |
| 642 | 727 | //setup year end from year start | 
| 643 | - if($time_to == null && !$this->year_end) $this->year_end = $this->year_start + $this->year_display_from_current; | |
| 728 | +			if($time_to == null && !$this->year_end) { | |
| 729 | + $this->year_end = $this->year_start + $this->year_display_from_current; | |
| 730 | + } | |
| 644 | 731 | } | 
| 645 | 732 | |
| 646 | 733 |  		if ($time_to>0) {
 | 
| 647 | 734 | $this->time_allow2 = $time_to; | 
| 648 | 735 |  			$y = $this->mydate->getDate('Y', $time_to);
 | 
| 649 | - if($this->year_end && $y < $this->year_end) $this->year_end = $y; | |
| 736 | +			if($this->year_end && $y < $this->year_end) { | |
| 737 | + $this->year_end = $y; | |
| 738 | + } | |
| 650 | 739 | |
| 651 | 740 | //setup year start from year end | 
| 652 | - if($time_from == null && !$this->year_start) $this->year_start = $this->year_end - $this->year_display_from_current; | |
| 741 | +			if($time_from == null && !$this->year_start) { | |
| 742 | + $this->year_start = $this->year_end - $this->year_display_from_current; | |
| 743 | + } | |
| 653 | 744 | } | 
| 654 | 745 | |
| 655 | 746 | $this->show_not_allow = $show_not_allow; | 
| @@ -672,7 +763,9 @@ discard block | ||
| 672 | 763 |  	function writeDateContainer(){
 | 
| 673 | 764 |  		if($this->day && $this->month && $this->year){
 | 
| 674 | 765 | $dd = $this->mydate->getDate($this->date_format, $this->year."-".$this->month."-".$this->day); | 
| 675 | - }else $dd = "Select Date"; | |
| 766 | +		} else { | |
| 767 | + $dd = "Select Date"; | |
| 768 | + } | |
| 676 | 769 | |
| 677 | 770 | return "<div id=\"divCalendar_".$this->objname."_lbl\" class=\"date-tccontainer\">$dd</div>"; | 
| 678 | 771 | } | 
| @@ -683,8 +776,9 @@ discard block | ||
| 683 | 776 | //------------------------------------------------------ | 
| 684 | 777 |  	function disabledDay($day){
 | 
| 685 | 778 | $day = strtolower($day); //make it not case-sensitive | 
| 686 | - if(in_array($day, $this->dsb_days) === false) | |
| 687 | - $this->dsb_days[] = $day; | |
| 779 | +		if(in_array($day, $this->dsb_days) === false) { | |
| 780 | + $this->dsb_days[] = $day; | |
| 781 | + } | |
| 688 | 782 | } | 
| 689 | 783 | |
| 690 | 784 |  	function setAlignment($h_align, $v_align){
 | 
| @@ -695,12 +789,14 @@ discard block | ||
| 695 | 789 |  	function setDatePair($calendar_name1, $calendar_name2, $pair_value = "0000-00-00 00:00:00"){
 | 
| 696 | 790 |  		if($calendar_name1 != $this->objname){
 | 
| 697 | 791 | $this->date_pair1 = $calendar_name1; | 
| 698 | - if($pair_value != "0000-00-00 00:00:00") | |
| 699 | - $this->date_pair_value = $pair_value; | |
| 700 | -		}elseif($calendar_name2 != $this->objname){
 | |
| 792 | +			if($pair_value != "0000-00-00 00:00:00") { | |
| 793 | + $this->date_pair_value = $pair_value; | |
| 794 | + } | |
| 795 | +		} elseif($calendar_name2 != $this->objname){
 | |
| 701 | 796 | $this->date_pair2 = $calendar_name2; | 
| 702 | - if($pair_value != "0000-00-00 00:00:00") | |
| 703 | - $this->date_pair_value = $pair_value; | |
| 797 | +			if($pair_value != "0000-00-00 00:00:00") { | |
| 798 | + $this->date_pair_value = $pair_value; | |
| 799 | + } | |
| 704 | 800 | } | 
| 705 | 801 | } | 
| 706 | 802 | |
| @@ -713,16 +809,19 @@ discard block | ||
| 713 | 809 |  				if($this->mydate->validDate($sp_date)){
 | 
| 714 | 810 |  					switch($recursive){
 | 
| 715 | 811 | case "month": //add to monthly | 
| 716 | - if(!in_array($sp_date, $this->sp_dates[1])) | |
| 717 | - $this->sp_dates[1][] = $sp_date; | |
| 812 | +							if(!in_array($sp_date, $this->sp_dates[1])) { | |
| 813 | + $this->sp_dates[1][] = $sp_date; | |
| 814 | + } | |
| 718 | 815 | break; | 
| 719 | 816 | case "year": //add to yearly | 
| 720 | - if(!in_array($sp_date, $this->sp_dates[2])) | |
| 721 | - $this->sp_dates[2][] = $sp_date; | |
| 817 | +							if(!in_array($sp_date, $this->sp_dates[2])) { | |
| 818 | + $this->sp_dates[2][] = $sp_date; | |
| 819 | + } | |
| 722 | 820 | break; | 
| 723 | 821 | default: //add to no recursive | 
| 724 | - if(!in_array($sp_date, $this->sp_dates[0])) | |
| 725 | - $this->sp_dates[0][] = $sp_date; | |
| 822 | +							if(!in_array($sp_date, $this->sp_dates[0])) { | |
| 823 | + $this->sp_dates[0][] = $sp_date; | |
| 824 | + } | |
| 726 | 825 | } | 
| 727 | 826 | } | 
| 728 | 827 | } | 
| @@ -790,10 +889,14 @@ discard block | ||
| 790 | 889 |  			if($this->mydate->dateBefore($this->time_allow1, $date_str, false) || $this->mydate->dateAfter($this->time_allow2, $date_str, false)){
 | 
| 791 | 890 | return false; | 
| 792 | 891 | } | 
| 793 | -		}elseif($this->time_allow1){
 | |
| 794 | - if($this->mydate->dateBefore($this->time_allow1, $date_str, false)) return false; | |
| 795 | -		}elseif($this->time_allow2){
 | |
| 796 | - if($this->mydate->dateAfter($this->time_allow2, $date_str, false)) return false; | |
| 892 | +		} elseif($this->time_allow1){
 | |
| 893 | +			if($this->mydate->dateBefore($this->time_allow1, $date_str, false)) { | |
| 894 | + return false; | |
| 895 | + } | |
| 896 | +		} elseif($this->time_allow2){
 | |
| 897 | +			if($this->mydate->dateAfter($this->time_allow2, $date_str, false)) { | |
| 898 | + return false; | |
| 899 | + } | |
| 797 | 900 | } | 
| 798 | 901 | |
| 799 | 902 | //check with specific date | 
| @@ -830,11 +933,15 @@ discard block | ||
| 830 | 933 | case 0: | 
| 831 | 934 | default: | 
| 832 | 935 | //disabled specific and enabled others | 
| 833 | - if($sp_found) return false; | |
| 936 | +					if($sp_found) { | |
| 937 | + return false; | |
| 938 | + } | |
| 834 | 939 | break; | 
| 835 | 940 | case 1: | 
| 836 | 941 | //enabled specific and disabled others | 
| 837 | - if(!$sp_found) return false; | |
| 942 | +					if(!$sp_found) { | |
| 943 | + return false; | |
| 944 | + } | |
| 838 | 945 | break; | 
| 839 | 946 | } | 
| 840 | 947 | } | 
| @@ -854,17 +961,21 @@ discard block | ||
| 854 | 961 |  		if(is_array($obj)){
 | 
| 855 | 962 |  			if(function_exists("json_encode") && false){
 | 
| 856 | 963 | return json_encode($obj); | 
| 857 | -			}else{
 | |
| 964 | +			} else{
 | |
| 858 | 965 | //only array is assumed for now | 
| 859 | 966 | $return_arr = array(); | 
| 860 | 967 |  				foreach($obj as $arr){
 | 
| 861 | - if(is_array($arr) && sizeof($arr)>0) | |
| 862 | -						$return_arr[] = "[\"".implode("\",\"", $arr)."\"]";
 | |
| 863 | - else $return_arr[] = "[]"; | |
| 968 | +					if(is_array($arr) && sizeof($arr)>0) { | |
| 969 | +											$return_arr[] = "[\"".implode("\",\"", $arr)."\"]"; | |
| 970 | +					} else { | |
| 971 | + $return_arr[] = "[]"; | |
| 972 | + } | |
| 864 | 973 | } | 
| 865 | 974 |  				return "[".implode(",", $return_arr)."]";
 | 
| 866 | 975 | } | 
| 867 | - }else return ""; | |
| 976 | +		} else { | |
| 977 | + return ""; | |
| 978 | + } | |
| 868 | 979 | } | 
| 869 | 980 | |
| 870 | 981 |  	function &check_json_decode($str){
 | 
| @@ -872,7 +983,7 @@ discard block | ||
| 872 | 983 | |
| 873 | 984 |  		if(function_exists("json_decode") && false){
 | 
| 874 | 985 | return json_decode($str); | 
| 875 | -		}else{
 | |
| 986 | +		} else{
 | |
| 876 | 987 | //only array is assume for now | 
| 877 | 988 | $str = stripslashes(rawurldecode($str)); | 
| 878 | 989 | $str = trim($str); | 
| @@ -890,9 +1001,9 @@ discard block | ||
| 890 | 1001 |  					$arr = explode("],[", $str);
 | 
| 891 | 1002 |  					for($i=0; $i<sizeof($arr); $i++){
 | 
| 892 | 1003 | $this_v = $arr[$i]; | 
| 893 | - if($this_v == "") | |
| 894 | - $return_arr[] = array(); | |
| 895 | -						else{
 | |
| 1004 | +						if($this_v == "") { | |
| 1005 | + $return_arr[] = array(); | |
| 1006 | +						} else{
 | |
| 896 | 1007 |  							$this_arr = explode(",", $this_v);
 | 
| 897 | 1008 | |
| 898 | 1009 |  							for($j=0; $j<sizeof($this_arr); $j++){
 | 
| @@ -905,8 +1016,12 @@ discard block | ||
| 905 | 1016 | } | 
| 906 | 1017 | } | 
| 907 | 1018 | return $return_arr; | 
| 908 | - }else return array(); | |
| 909 | - }else return array(); | |
| 1019 | +				} else { | |
| 1020 | + return array(); | |
| 1021 | + } | |
| 1022 | +			} else { | |
| 1023 | + return array(); | |
| 1024 | + } | |
| 910 | 1025 | } | 
| 911 | 1026 | } | 
| 912 | 1027 | |
| @@ -939,14 +1054,16 @@ discard block | ||
| 939 | 1054 | //check if today is in range of date allow | 
| 940 | 1055 |  		if($this->time_allow1 != ""){
 | 
| 941 | 1056 | //check valid if today is after date_allow1 | 
| 942 | - if($this->mydate->validDate($this->time_allow1) && !$this->mydate->dateAfter($this->time_allow1, $today)) | |
| 943 | - return false; | |
| 1057 | +			if($this->mydate->validDate($this->time_allow1) && !$this->mydate->dateAfter($this->time_allow1, $today)) { | |
| 1058 | + return false; | |
| 1059 | + } | |
| 944 | 1060 | } | 
| 945 | 1061 | |
| 946 | 1062 |  		if($this->time_allow2 > 0){
 | 
| 947 | 1063 | //check valid if today is before date_allow2 | 
| 948 | - if($this->mydate->validDate($this->time_allow2) && !$this->mydate->dateBefore($this->time_allow2, $today)) | |
| 949 | - return false; | |
| 1064 | +			if($this->mydate->validDate($this->time_allow2) && !$this->mydate->dateBefore($this->time_allow2, $today)) { | |
| 1065 | + return false; | |
| 1066 | + } | |
| 950 | 1067 | } | 
| 951 | 1068 | return true; | 
| 952 | 1069 | } | 
| @@ -966,8 +1083,7 @@ discard block | ||
| 966 | 1083 |  						if(!in_array($tt_time, $this->tt_dates[2])){
 | 
| 967 | 1084 | $this->tt_dates[2][] = $tt_time; | 
| 968 | 1085 | $this->tt_tooltips[2][] = $tooltip; | 
| 969 | - } | |
| 970 | -						else{
 | |
| 1086 | +						} else{
 | |
| 971 | 1087 | $tt_key = array_search($tt_time, $this->tt_dates[2]); | 
| 972 | 1088 | $this->tt_tooltips[2][$tt_key] = $this->tt_tooltips[2][$tt_key]."\n".$tooltip; | 
| 973 | 1089 | } | 
| @@ -976,8 +1092,7 @@ discard block | ||
| 976 | 1092 |  						if(!in_array($tt_time, $this->tt_dates[1])){
 | 
| 977 | 1093 | $this->tt_dates[1][] = $tt_time; | 
| 978 | 1094 | $this->tt_tooltips[1][] = $tooltip; | 
| 979 | - } | |
| 980 | -						else{
 | |
| 1095 | +						} else{
 | |
| 981 | 1096 | $tt_key = array_search($tt_time, $this->tt_dates[1]); | 
| 982 | 1097 | $this->tt_tooltips[1][$tt_key] = $this->tt_tooltips[1][$tt_key]."\n".$tooltip; | 
| 983 | 1098 | } | 
| @@ -986,8 +1101,7 @@ discard block | ||
| 986 | 1101 |  						if(!in_array($tt_time, $this->tt_dates[0])){
 | 
| 987 | 1102 | $this->tt_dates[0][] = $tt_time; | 
| 988 | 1103 | $this->tt_tooltips[0][] = $tooltip; | 
| 989 | - } | |
| 990 | -						else{
 | |
| 1104 | +						} else{
 | |
| 991 | 1105 | $tt_key = array_search($tt_time, $this->tt_dates[0]); | 
| 992 | 1106 | $this->tt_tooltips[0][$tt_key] = $this->tt_tooltips[0][$tt_key]."\n".$tooltip; | 
| 993 | 1107 | } | 
| @@ -54,6 +54,9 @@ discard block | ||
| 54 | 54 | } | 
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | + /** | |
| 58 | + * @return string | |
| 59 | + */ | |
| 57 | 60 |  	function getDate($format = "Y-m-d", $cdate = ""){
 | 
| 58 | 61 |  		if(!$this->compatible){
 | 
| 59 | 62 | return tc_date_main::getDate($format, $cdate); | 
| @@ -123,6 +126,9 @@ discard block | ||
| 123 | 126 | } | 
| 124 | 127 | } | 
| 125 | 128 | |
| 129 | + /** | |
| 130 | + * @param string $timespan | |
| 131 | + */ | |
| 126 | 132 |  	function addDate($format = "Y-m-d", $timespan, $cdate = ""){
 | 
| 127 | 133 |  		if($this->compatible){
 | 
| 128 | 134 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| @@ -148,6 +154,10 @@ discard block | ||
| 148 | 154 | |
| 149 | 155 | //check if date1 is before date2 | 
| 150 | 156 | //if date1 omitted use set date | 
| 157 | + | |
| 158 | + /** | |
| 159 | + * @param string|boolean $date2 | |
| 160 | + */ | |
| 151 | 161 |  	function dateBefore($date2, $date1 = "", $equal = true){
 | 
| 152 | 162 |  		if(!$this->compatible){
 | 
| 153 | 163 | return tc_date_main::dateBefore($date2, $date1, $equal); | 
| @@ -162,6 +172,10 @@ discard block | ||
| 162 | 172 | |
| 163 | 173 | //check if date1 is after date2 | 
| 164 | 174 | //if date1 omitted use set date | 
| 175 | + | |
| 176 | + /** | |
| 177 | + * @param string|boolean $date2 | |
| 178 | + */ | |
| 165 | 179 |  	function dateAfter($date2, $date1 = "", $equal = true){
 | 
| 166 | 180 |  		if(!$this->compatible){
 | 
| 167 | 181 | return tc_date_main::dateAfter($date2, $date1, $equal); | 
| @@ -7,88 +7,88 @@ discard block | ||
| 7 | 7 | |
| 8 | 8 |  require_once('tc_date_main.php');
 | 
| 9 | 9 | |
| 10 | -class tc_date extends tc_date_main{
 | |
| 10 | +class tc_date extends tc_date_main {
 | |
| 11 | 11 | var $compatible; | 
| 12 | 12 | |
| 13 | -	function tc_date(){
 | |
| 13 | +	function tc_date() {
 | |
| 14 | 14 | //check if we should use DateTime that comes with 5.3.0 and later | 
| 15 | -		if (version_compare(PHP_VERSION, '5.3.0') <= 0) {
 | |
| 15 | +		if (version_compare(PHP_VERSION, '5.3.0')<=0) {
 | |
| 16 | 16 | $this->compatible = false; | 
| 17 | 17 | }else $this->compatible = true; | 
| 18 | 18 | |
| 19 | -		if(!$this->compatible){
 | |
| 19 | +		if (!$this->compatible) {
 | |
| 20 | 20 | $this->tc_date_main(); | 
| 21 | -		}else{
 | |
| 21 | +		}else {
 | |
| 22 | 22 |  			$this->mydate = new DateTime('now');
 | 
| 23 | 23 | } | 
| 24 | 24 | } | 
| 25 | 25 | |
| 26 | -	function getDayOfWeek($cdate = ""){
 | |
| 27 | -		if(!$this->compatible){
 | |
| 26 | +	function getDayOfWeek($cdate = "") {
 | |
| 27 | +		if (!$this->compatible) {
 | |
| 28 | 28 | return tc_date_main::getDayOfWeek($cdate); | 
| 29 | -		}else{
 | |
| 30 | -			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | |
| 29 | +		}else {
 | |
| 30 | +			if (($cdate != "" && $this->validDate($cdate)) || $cdate == "") {
 | |
| 31 | 31 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 32 | 32 |  				return $tmp_date->format('w');
 | 
| 33 | 33 | }else return ""; | 
| 34 | 34 | } | 
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | -	function getWeekNumber($cdate = ""){
 | |
| 38 | -		if(!$this->compatible){
 | |
| 37 | +	function getWeekNumber($cdate = "") {
 | |
| 38 | +		if (!$this->compatible) {
 | |
| 39 | 39 | return tc_date_main::getWeekNumber($cdate); | 
| 40 | -		}else{
 | |
| 41 | -			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | |
| 40 | +		}else {
 | |
| 41 | +			if (($cdate != "" && $this->validDate($cdate)) || $cdate == "") {
 | |
| 42 | 42 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 43 | 43 |  				return $tmp_date->format('W');
 | 
| 44 | 44 | }else return ""; | 
| 45 | 45 | } | 
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | -	function setDate($sdate){
 | |
| 49 | -		if(!$this->compatible){
 | |
| 48 | +	function setDate($sdate) {
 | |
| 49 | +		if (!$this->compatible) {
 | |
| 50 | 50 | tc_date_main::setDate($sdate); | 
| 51 | -		}else{
 | |
| 52 | - if(tc_date_main::validDate($sdate)) | |
| 51 | +		}else {
 | |
| 52 | + if (tc_date_main::validDate($sdate)) | |
| 53 | 53 | $this->mydate = new DateTime($sdate); | 
| 54 | 54 | } | 
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | -	function getDate($format = "Y-m-d", $cdate = ""){
 | |
| 58 | -		if(!$this->compatible){
 | |
| 57 | +	function getDate($format = "Y-m-d", $cdate = "") {
 | |
| 58 | +		if (!$this->compatible) {
 | |
| 59 | 59 | return tc_date_main::getDate($format, $cdate); | 
| 60 | -		}else{
 | |
| 61 | -			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | |
| 60 | +		}else {
 | |
| 61 | +			if (($cdate != "" && $this->validDate($cdate)) || $cdate == "") {
 | |
| 62 | 62 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 63 | 63 | return $tmp_date->format($format); | 
| 64 | 64 | }else return ""; | 
| 65 | 65 | } | 
| 66 | 66 | } | 
| 67 | 67 | |
| 68 | -	function setTimestamp($stime){
 | |
| 69 | -		if(!$this->compatible){
 | |
| 68 | +	function setTimestamp($stime) {
 | |
| 69 | +		if (!$this->compatible) {
 | |
| 70 | 70 | tc_date_main::setTimestamp($stime); | 
| 71 | -		}else{
 | |
| 71 | +		}else {
 | |
| 72 | 72 | $this->mydate->setTimestamp($stime); | 
| 73 | 73 | } | 
| 74 | 74 | } | 
| 75 | 75 | |
| 76 | -	function getTimestamp($cdate = ""){
 | |
| 77 | -		if(!$this->compatible){
 | |
| 76 | +	function getTimestamp($cdate = "") {
 | |
| 77 | +		if (!$this->compatible) {
 | |
| 78 | 78 | return tc_date_main::getTimestamp($cdate); | 
| 79 | -		}else{
 | |
| 80 | -			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | |
| 79 | +		}else {
 | |
| 80 | +			if (($cdate != "" && $this->validDate($cdate)) || $cdate == "") {
 | |
| 81 | 81 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 82 | 82 | return $tmp_date->getTimestamp(); | 
| 83 | 83 | }else return 0; | 
| 84 | 84 | } | 
| 85 | 85 | } | 
| 86 | 86 | |
| 87 | -	function getDateFromTimestamp($stime, $format = 'Y-m-d'){
 | |
| 88 | -		if($stime){
 | |
| 89 | -			if(!$this->compatible){
 | |
| 87 | +	function getDateFromTimestamp($stime, $format = 'Y-m-d') {
 | |
| 88 | +		if ($stime) {
 | |
| 89 | +			if (!$this->compatible) {
 | |
| 90 | 90 | return tc_date_main::getDateFromTimestamp($stime, $format); | 
| 91 | -			}else{
 | |
| 91 | +			}else {
 | |
| 92 | 92 | $tmp_date = new DateTime(); | 
| 93 | 93 | $tmp_date->setTimestamp($stime); | 
| 94 | 94 | return $tmp_date->format($format); | 
| @@ -96,35 +96,35 @@ discard block | ||
| 96 | 96 | }else return ""; | 
| 97 | 97 | } | 
| 98 | 98 | |
| 99 | -	function addDay($format = "Y-m-d", $timespan, $cdate = ""){
 | |
| 100 | -		if(!$this->compatible){
 | |
| 99 | +	function addDay($format = "Y-m-d", $timespan, $cdate = "") {
 | |
| 100 | +		if (!$this->compatible) {
 | |
| 101 | 101 | return tc_date_main::addDay($format, $timespan, $cdate); | 
| 102 | -		}else{
 | |
| 102 | +		}else {
 | |
| 103 | 103 | $timespan = "P".$timespan."D"; | 
| 104 | 104 | return $this->addDate($format, $timespan, $cdate); | 
| 105 | 105 | } | 
| 106 | 106 | } | 
| 107 | 107 | |
| 108 | -	function addMonth($format = "Y-m-d", $timespan, $cdate = ""){
 | |
| 109 | -		if(!$this->compatible){
 | |
| 108 | +	function addMonth($format = "Y-m-d", $timespan, $cdate = "") {
 | |
| 109 | +		if (!$this->compatible) {
 | |
| 110 | 110 | return tc_date_main::addMonth($format, $timespan, $cdate); | 
| 111 | -		}else{
 | |
| 111 | +		}else {
 | |
| 112 | 112 | $timespan = "P".$timespan."M"; | 
| 113 | 113 | return $this->addDate($format, $timespan, $cdate); | 
| 114 | 114 | } | 
| 115 | 115 | } | 
| 116 | 116 | |
| 117 | -	function addYear($format = "Y-m-d", $timespan, $cdate = ""){
 | |
| 118 | -		if(!$this->compatible){
 | |
| 117 | +	function addYear($format = "Y-m-d", $timespan, $cdate = "") {
 | |
| 118 | +		if (!$this->compatible) {
 | |
| 119 | 119 | return tc_date_main::addYear($format, $timespan, $cdate); | 
| 120 | -		}else{
 | |
| 120 | +		}else {
 | |
| 121 | 121 | $timespan = "P".$timespan."Y"; | 
| 122 | 122 | return $this->addDate($format, $timespan, $cdate); | 
| 123 | 123 | } | 
| 124 | 124 | } | 
| 125 | 125 | |
| 126 | -	function addDate($format = "Y-m-d", $timespan, $cdate = ""){
 | |
| 127 | -		if($this->compatible){
 | |
| 126 | +	function addDate($format = "Y-m-d", $timespan, $cdate = "") {
 | |
| 127 | +		if ($this->compatible) {
 | |
| 128 | 128 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 129 | 129 | $tmp_date->add(new DateInterval($timespan)); | 
| 130 | 130 | return $tmp_date->format($format); | 
| @@ -133,10 +133,10 @@ discard block | ||
| 133 | 133 | |
| 134 | 134 | //return the number of day different between date1 and date2 | 
| 135 | 135 | //if date1 omitted use set date | 
| 136 | -	function differentDate($date2, $date1 = ""){
 | |
| 137 | -		if(!$this->compatible){
 | |
| 136 | +	function differentDate($date2, $date1 = "") {
 | |
| 137 | +		if (!$this->compatible) {
 | |
| 138 | 138 | return tc_date_main::differentDate($date2, $date1); | 
| 139 | -		}else{
 | |
| 139 | +		}else {
 | |
| 140 | 140 |  			$date1 = ($date1 != "") ? $date1 : $this->getDate('Y-m-d');
 | 
| 141 | 141 | |
| 142 | 142 | $date1 = new DateTime($date1); | 
| @@ -148,10 +148,10 @@ discard block | ||
| 148 | 148 | |
| 149 | 149 | //check if date1 is before date2 | 
| 150 | 150 | //if date1 omitted use set date | 
| 151 | -	function dateBefore($date2, $date1 = "", $equal = true){
 | |
| 152 | -		if(!$this->compatible){
 | |
| 151 | +	function dateBefore($date2, $date1 = "", $equal = true) {
 | |
| 152 | +		if (!$this->compatible) {
 | |
| 153 | 153 | return tc_date_main::dateBefore($date2, $date1, $equal); | 
| 154 | -		}else{
 | |
| 154 | +		}else {
 | |
| 155 | 155 |  			$date1 = ($date1 != "") ? $date1 : $this->getDate('Y-m-d');
 | 
| 156 | 156 | |
| 157 | 157 | $date1 = new DateTime($date1); | 
| @@ -162,10 +162,10 @@ discard block | ||
| 162 | 162 | |
| 163 | 163 | //check if date1 is after date2 | 
| 164 | 164 | //if date1 omitted use set date | 
| 165 | -	function dateAfter($date2, $date1 = "", $equal = true){
 | |
| 166 | -		if(!$this->compatible){
 | |
| 165 | +	function dateAfter($date2, $date1 = "", $equal = true) {
 | |
| 166 | +		if (!$this->compatible) {
 | |
| 167 | 167 | return tc_date_main::dateAfter($date2, $date1, $equal); | 
| 168 | -		}else{
 | |
| 168 | +		}else {
 | |
| 169 | 169 |  			$date1 = ($date1 != "") ? $date1 : $this->getDate('Y-m-d');
 | 
| 170 | 170 | |
| 171 | 171 | $date1 = new DateTime($date1); | 
| @@ -14,11 +14,13 @@ discard block | ||
| 14 | 14 | //check if we should use DateTime that comes with 5.3.0 and later | 
| 15 | 15 |  		if (version_compare(PHP_VERSION, '5.3.0') <= 0) {
 | 
| 16 | 16 | $this->compatible = false; | 
| 17 | - }else $this->compatible = true; | |
| 17 | +		} else { | |
| 18 | + $this->compatible = true; | |
| 19 | + } | |
| 18 | 20 | |
| 19 | 21 |  		if(!$this->compatible){
 | 
| 20 | 22 | $this->tc_date_main(); | 
| 21 | -		}else{
 | |
| 23 | +		} else{
 | |
| 22 | 24 |  			$this->mydate = new DateTime('now');
 | 
| 23 | 25 | } | 
| 24 | 26 | } | 
| @@ -26,49 +28,56 @@ discard block | ||
| 26 | 28 |  	function getDayOfWeek($cdate = ""){
 | 
| 27 | 29 |  		if(!$this->compatible){
 | 
| 28 | 30 | return tc_date_main::getDayOfWeek($cdate); | 
| 29 | -		}else{
 | |
| 31 | +		} else{
 | |
| 30 | 32 |  			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | 
| 31 | 33 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 32 | 34 |  				return $tmp_date->format('w');
 | 
| 33 | - }else return ""; | |
| 35 | +			} else { | |
| 36 | + return ""; | |
| 37 | + } | |
| 34 | 38 | } | 
| 35 | 39 | } | 
| 36 | 40 | |
| 37 | 41 |  	function getWeekNumber($cdate = ""){
 | 
| 38 | 42 |  		if(!$this->compatible){
 | 
| 39 | 43 | return tc_date_main::getWeekNumber($cdate); | 
| 40 | -		}else{
 | |
| 44 | +		} else{
 | |
| 41 | 45 |  			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | 
| 42 | 46 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 43 | 47 |  				return $tmp_date->format('W');
 | 
| 44 | - }else return ""; | |
| 48 | +			} else { | |
| 49 | + return ""; | |
| 50 | + } | |
| 45 | 51 | } | 
| 46 | 52 | } | 
| 47 | 53 | |
| 48 | 54 |  	function setDate($sdate){
 | 
| 49 | 55 |  		if(!$this->compatible){
 | 
| 50 | 56 | tc_date_main::setDate($sdate); | 
| 51 | -		}else{
 | |
| 52 | - if(tc_date_main::validDate($sdate)) | |
| 53 | - $this->mydate = new DateTime($sdate); | |
| 57 | +		} else{
 | |
| 58 | +			if(tc_date_main::validDate($sdate)) { | |
| 59 | + $this->mydate = new DateTime($sdate); | |
| 60 | + } | |
| 54 | 61 | } | 
| 55 | 62 | } | 
| 56 | 63 | |
| 57 | 64 |  	function getDate($format = "Y-m-d", $cdate = ""){
 | 
| 58 | 65 |  		if(!$this->compatible){
 | 
| 59 | 66 | return tc_date_main::getDate($format, $cdate); | 
| 60 | -		}else{
 | |
| 67 | +		} else{
 | |
| 61 | 68 |  			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | 
| 62 | 69 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 63 | 70 | return $tmp_date->format($format); | 
| 64 | - }else return ""; | |
| 71 | +			} else { | |
| 72 | + return ""; | |
| 73 | + } | |
| 65 | 74 | } | 
| 66 | 75 | } | 
| 67 | 76 | |
| 68 | 77 |  	function setTimestamp($stime){
 | 
| 69 | 78 |  		if(!$this->compatible){
 | 
| 70 | 79 | tc_date_main::setTimestamp($stime); | 
| 71 | -		}else{
 | |
| 80 | +		} else{
 | |
| 72 | 81 | $this->mydate->setTimestamp($stime); | 
| 73 | 82 | } | 
| 74 | 83 | } | 
| @@ -76,11 +85,13 @@ discard block | ||
| 76 | 85 |  	function getTimestamp($cdate = ""){
 | 
| 77 | 86 |  		if(!$this->compatible){
 | 
| 78 | 87 | return tc_date_main::getTimestamp($cdate); | 
| 79 | -		}else{
 | |
| 88 | +		} else{
 | |
| 80 | 89 |  			if(($cdate != "" && $this->validDate($cdate)) || $cdate == ""){
 | 
| 81 | 90 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 82 | 91 | return $tmp_date->getTimestamp(); | 
| 83 | - }else return 0; | |
| 92 | +			} else { | |
| 93 | + return 0; | |
| 94 | + } | |
| 84 | 95 | } | 
| 85 | 96 | } | 
| 86 | 97 | |
| @@ -88,18 +99,20 @@ discard block | ||
| 88 | 99 |  		if($stime){
 | 
| 89 | 100 |  			if(!$this->compatible){
 | 
| 90 | 101 | return tc_date_main::getDateFromTimestamp($stime, $format); | 
| 91 | -			}else{
 | |
| 102 | +			} else{
 | |
| 92 | 103 | $tmp_date = new DateTime(); | 
| 93 | 104 | $tmp_date->setTimestamp($stime); | 
| 94 | 105 | return $tmp_date->format($format); | 
| 95 | 106 | } | 
| 96 | - }else return ""; | |
| 107 | +		} else { | |
| 108 | + return ""; | |
| 109 | + } | |
| 97 | 110 | } | 
| 98 | 111 | |
| 99 | 112 |  	function addDay($format = "Y-m-d", $timespan, $cdate = ""){
 | 
| 100 | 113 |  		if(!$this->compatible){
 | 
| 101 | 114 | return tc_date_main::addDay($format, $timespan, $cdate); | 
| 102 | -		}else{
 | |
| 115 | +		} else{
 | |
| 103 | 116 | $timespan = "P".$timespan."D"; | 
| 104 | 117 | return $this->addDate($format, $timespan, $cdate); | 
| 105 | 118 | } | 
| @@ -108,7 +121,7 @@ discard block | ||
| 108 | 121 |  	function addMonth($format = "Y-m-d", $timespan, $cdate = ""){
 | 
| 109 | 122 |  		if(!$this->compatible){
 | 
| 110 | 123 | return tc_date_main::addMonth($format, $timespan, $cdate); | 
| 111 | -		}else{
 | |
| 124 | +		} else{
 | |
| 112 | 125 | $timespan = "P".$timespan."M"; | 
| 113 | 126 | return $this->addDate($format, $timespan, $cdate); | 
| 114 | 127 | } | 
| @@ -117,7 +130,7 @@ discard block | ||
| 117 | 130 |  	function addYear($format = "Y-m-d", $timespan, $cdate = ""){
 | 
| 118 | 131 |  		if(!$this->compatible){
 | 
| 119 | 132 | return tc_date_main::addYear($format, $timespan, $cdate); | 
| 120 | -		}else{
 | |
| 133 | +		} else{
 | |
| 121 | 134 | $timespan = "P".$timespan."Y"; | 
| 122 | 135 | return $this->addDate($format, $timespan, $cdate); | 
| 123 | 136 | } | 
| @@ -128,7 +141,9 @@ discard block | ||
| 128 | 141 | $tmp_date = ($cdate != "") ? new DateTime($cdate) : $this->mydate; | 
| 129 | 142 | $tmp_date->add(new DateInterval($timespan)); | 
| 130 | 143 | return $tmp_date->format($format); | 
| 131 | - }else return "0000-00-00"; | |
| 144 | +		} else { | |
| 145 | + return "0000-00-00"; | |
| 146 | + } | |
| 132 | 147 | } | 
| 133 | 148 | |
| 134 | 149 | //return the number of day different between date1 and date2 | 
| @@ -136,7 +151,7 @@ discard block | ||
| 136 | 151 |  	function differentDate($date2, $date1 = ""){
 | 
| 137 | 152 |  		if(!$this->compatible){
 | 
| 138 | 153 | return tc_date_main::differentDate($date2, $date1); | 
| 139 | -		}else{
 | |
| 154 | +		} else{
 | |
| 140 | 155 |  			$date1 = ($date1 != "") ? $date1 : $this->getDate('Y-m-d');
 | 
| 141 | 156 | |
| 142 | 157 | $date1 = new DateTime($date1); | 
| @@ -151,7 +166,7 @@ discard block | ||
| 151 | 166 |  	function dateBefore($date2, $date1 = "", $equal = true){
 | 
| 152 | 167 |  		if(!$this->compatible){
 | 
| 153 | 168 | return tc_date_main::dateBefore($date2, $date1, $equal); | 
| 154 | -		}else{
 | |
| 169 | +		} else{
 | |
| 155 | 170 |  			$date1 = ($date1 != "") ? $date1 : $this->getDate('Y-m-d');
 | 
| 156 | 171 | |
| 157 | 172 | $date1 = new DateTime($date1); | 
| @@ -165,7 +180,7 @@ discard block | ||
| 165 | 180 |  	function dateAfter($date2, $date1 = "", $equal = true){
 | 
| 166 | 181 |  		if(!$this->compatible){
 | 
| 167 | 182 | return tc_date_main::dateAfter($date2, $date1, $equal); | 
| 168 | -		}else{
 | |
| 183 | +		} else{
 | |
| 169 | 184 |  			$date1 = ($date1 != "") ? $date1 : $this->getDate('Y-m-d');
 | 
| 170 | 185 | |
| 171 | 186 | $date1 = new DateTime($date1); | 
| @@ -204,6 +204,11 @@ discard block | ||
| 204 | 204 | } | 
| 205 | 205 | |
| 206 | 206 | |
| 207 | +/** | |
| 208 | + * @param integer $id | |
| 209 | + * @param string $what | |
| 210 | + * @param boolean $lock | |
| 211 | + */ | |
| 207 | 212 |  function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { | 
| 208 | 213 | |
| 209 | 214 |  	switch ($what) { | 
| @@ -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 | |
| @@ -34,7 +34,7 @@ discard block | ||
| 34 | 34 | |
| 35 | 35 | case 'network': | 
| 36 | 36 |  		list($sub['net'],$sub['mask'])=explode('/',$value); | 
| 37 | -                $query= sprintf("INSERT INTO `$table` ( | |
| 37 | +				$query= sprintf("INSERT INTO `$table` ( | |
| 38 | 38 | `$type` , | 
| 39 | 39 | `netmask`, | 
| 40 | 40 | `date` , | 
| @@ -47,10 +47,10 @@ discard block | ||
| 47 | 47 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , | 
| 48 | 48 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' | 
| 49 | 49 | )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); | 
| 50 | - break; | |
| 50 | + break; | |
| 51 | 51 | |
| 52 | 52 | default: | 
| 53 | -                $query= sprintf("INSERT INTO `$table` ( | |
| 53 | +				$query= sprintf("INSERT INTO `$table` ( | |
| 54 | 54 | `$type` , | 
| 55 | 55 | `date` , | 
| 56 | 56 | `exp` , | 
| @@ -65,8 +65,8 @@ discard block | ||
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 |  	if ($myconn->query($query) === TRUE) { | 
| 68 | - syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); | |
| 69 | - $result=TRUE; | |
| 68 | + syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); | |
| 69 | + $result=TRUE; | |
| 70 | 70 | } | 
| 71 | 71 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); | 
| 72 | 72 | return $result; | 
| @@ -76,9 +76,9 @@ discard block | ||
| 76 | 76 | |
| 77 | 77 | $result=FALSE; | 
| 78 | 78 | |
| 79 | -        switch ($type) { | |
| 79 | +		switch ($type) { | |
| 80 | 80 | case 'ip': | 
| 81 | -                $query= sprintf("UPDATE `$table` SET | |
| 81 | +				$query= sprintf("UPDATE `$table` SET | |
| 82 | 82 | `active` = '1', | 
| 83 | 83 | `user` = '%s', | 
| 84 | 84 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), | 
| @@ -86,9 +86,9 @@ discard block | ||
| 86 | 86 | `reason` = '%s' | 
| 87 | 87 |  			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); | 
| 88 | 88 | break; | 
| 89 | - case 'network': | |
| 89 | + case 'network': | |
| 90 | 90 |  		list($sub['net'],$sub['mask'])=explode('/',$value); | 
| 91 | -                $query= sprintf("UPDATE `$table` SET | |
| 91 | +				$query= sprintf("UPDATE `$table` SET | |
| 92 | 92 | `active` = '1', | 
| 93 | 93 | `user` = '%s', | 
| 94 | 94 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 |                          WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); | 
| 98 | 98 | break; | 
| 99 | 99 | default: | 
| 100 | -                $query= sprintf("UPDATE `$table` SET | |
| 100 | +				$query= sprintf("UPDATE `$table` SET | |
| 101 | 101 | `active` = '1', | 
| 102 | 102 | `user` = '%s', | 
| 103 | 103 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), | 
| @@ -106,19 +106,19 @@ discard block | ||
| 106 | 106 | WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); | 
| 107 | 107 | } | 
| 108 | 108 | |
| 109 | -        if ($myconn->query($query) === TRUE) { | |
| 110 | - syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); | |
| 109 | +		if ($myconn->query($query) === TRUE) { | |
| 110 | + syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); | |
| 111 | 111 | $result=TRUE; | 
| 112 | - } | |
| 113 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); | |
| 112 | + } | |
| 113 | + else syslog (LOG_ERR, "$user: Error: ". $myconn->error); | |
| 114 | 114 | return $result; | 
| 115 | 115 | } | 
| 116 | 116 | |
| 117 | 117 |  function remove ($myconn,$user,$value,$type,$table) { | 
| 118 | - $result=FALSE; | |
| 118 | + $result=FALSE; | |
| 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 | $desc = array_keys($tables); | 
| 170 | 170 |  	foreach ($desc as $tdesc) {  | 
| 171 | 171 | /* QUERY */ | 
| @@ -174,11 +174,11 @@ discard block | ||
| 174 | 174 | /* END OF QUERY */ | 
| 175 | 175 | $log[0] = 'expired for'; | 
| 176 | 176 | $log[1] = 'disabled for'; | 
| 177 | -        	if ($myconn->multi_query($query)) { | |
| 177 | +			if ($myconn->multi_query($query)) { | |
| 178 | 178 | $j = 0; | 
| 179 | 179 |  			do { | 
| 180 | - $numdel = $myconn->affected_rows; | |
| 181 | - syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); | |
| 180 | + $numdel = $myconn->affected_rows; | |
| 181 | + syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); | |
| 182 | 182 | $j++; | 
| 183 | 183 | |
| 184 | 184 | } while ($myconn->next_result()); | 
| @@ -190,7 +190,7 @@ discard block | ||
| 190 | 190 | } | 
| 191 | 191 | if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); | 
| 192 | 192 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); | 
| 193 | - return $return; | |
| 193 | + return $return; | |
| 194 | 194 | } | 
| 195 | 195 | |
| 196 | 196 | |
| @@ -231,7 +231,7 @@ discard block | ||
| 231 | 231 |  		if ( $entry->num_rows ) { | 
| 232 | 232 |  			if ( $entry->num_rows == 1 ) { | 
| 233 | 233 | $riga = $entry->fetch_array(MYSQLI_ASSOC); | 
| 234 | -                        	if (isListed($riga)) { | |
| 234 | +							if (isListed($riga)) { | |
| 235 | 235 | $warn = "<$value> is already present in <$listdep> list!"; | 
| 236 | 236 | $entry->free(); | 
| 237 | 237 | return FALSE; | 
| @@ -248,28 +248,28 @@ discard block | ||
| 248 | 248 |  function searchentry ($myconn,$value,$tablelist) { | 
| 249 | 249 | /* Make a MYSQL query and return result */ | 
| 250 | 250 | |
| 251 | - $type = $tablelist['field']; | |
| 252 | - $table = $tablelist['name']; | |
| 253 | - | |
| 254 | - if ($value == 'ALL') $query = 'select * from '.$table; | |
| 255 | -        else { | |
| 256 | -                switch ($type) { | |
| 257 | - case 'ip': | |
| 258 | -                        $query= "select * from $table where $type =  INET_ATON('$value')"; | |
| 259 | - break; | |
| 260 | - case 'network': | |
| 261 | -                        list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 262 | - $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; | |
| 263 | - break; | |
| 264 | - default: | |
| 265 | - $query= "select * from $table where $type = '$value'"; | |
| 266 | - } | |
| 267 | - } | |
| 251 | + $type = $tablelist['field']; | |
| 252 | + $table = $tablelist['name']; | |
| 253 | + | |
| 254 | + if ($value == 'ALL') $query = 'select * from '.$table; | |
| 255 | +		else { | |
| 256 | +				switch ($type) { | |
| 257 | + case 'ip': | |
| 258 | +						$query= "select * from $table where $type =  INET_ATON('$value')"; | |
| 259 | + break; | |
| 260 | + case 'network': | |
| 261 | +						list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 262 | + $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; | |
| 263 | + break; | |
| 264 | + default: | |
| 265 | + $query= "select * from $table where $type = '$value'"; | |
| 266 | + } | |
| 267 | + } | |
| 268 | 268 | |
| 269 | 269 | $result = $myconn->query($query); | 
| 270 | 270 | if($result === false) | 
| 271 | 271 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); | 
| 272 | - return $result; | |
| 272 | + return $result; | |
| 273 | 273 | } | 
| 274 | 274 | |
| 275 | 275 |  function countListed ($myconn,$table) { | 
| @@ -285,10 +285,10 @@ discard block | ||
| 285 | 285 | |
| 286 | 286 | |
| 287 | 287 |  function isFull($myconn,$typedesc,$alltables) { | 
| 288 | -        if (isset($alltables["$typedesc"]['limit'])) { | |
| 289 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) | |
| 290 | - return TRUE; | |
| 291 | - } | |
| 288 | +		if (isset($alltables["$typedesc"]['limit'])) { | |
| 289 | + if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) | |
| 290 | + return TRUE; | |
| 291 | + } | |
| 292 | 292 | return FALSE; | 
| 293 | 293 | } | 
| 294 | 294 | |
| @@ -301,14 +301,14 @@ discard block | ||
| 301 | 301 |  	if ($result) { | 
| 302 | 302 |  		printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); | 
| 303 | 303 | |
| 304 | - /* Check for limit in number of listed items */ | |
| 304 | + /* Check for limit in number of listed items */ | |
| 305 | 305 | $full = isFull($myconn,$typedesc,$tables); | 
| 306 | 306 |  	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; | 
| 307 | 307 | |
| 308 | 308 |  		if ($result->num_rows) { | 
| 309 | 309 | 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"; | 
| 310 | 310 | $i=0; | 
| 311 | -        		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { | |
| 311 | +				while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { | |
| 312 | 312 |  				if (isListed($riga)) { | 
| 313 | 313 | if ($tables["$typedesc"]['bl']) $listed='Listed'; | 
| 314 | 314 | else $listed='WhiteListed'; | 
| @@ -327,9 +327,9 @@ discard block | ||
| 327 | 327 | $element = $riga["$type"]; | 
| 328 | 328 | } | 
| 329 | 329 | |
| 330 | -                		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)); | |
| 330 | +						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 | 331 | $i++; | 
| 332 | - } | |
| 332 | + } | |
| 333 | 333 | print '</tbody></table>'; | 
| 334 | 334 | } | 
| 335 | 335 |  		else { | 
| @@ -347,15 +347,15 @@ discard block | ||
| 347 | 347 | |
| 348 | 348 |  function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { | 
| 349 | 349 | $now = time(); | 
| 350 | - setlocale (LC_TIME, 'it_IT'); | |
| 351 | -        $date = date("r",$now); | |
| 350 | + setlocale (LC_TIME, 'it_IT'); | |
| 351 | +		$date = date("r",$now); | |
| 352 | 352 | $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; | 
| 353 | 353 | $mua = 'PHP/' . phpversion(); | 
| 354 | 354 | |
| 355 | 355 | /* Parsing headers */ | 
| 356 | 356 |  	if (!file_exists($tplf['header'])) { | 
| 357 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); | |
| 358 | - exit; | |
| 357 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); | |
| 358 | + exit; | |
| 359 | 359 | } | 
| 360 | 360 | |
| 361 | 361 | $head_tmpl = file_get_contents($tplf['header']); | 
| @@ -364,36 +364,36 @@ discard block | ||
| 364 | 364 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); | 
| 365 | 365 | $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); | 
| 366 | 366 | |
| 367 | - /* Parsing body */ | |
| 367 | + /* Parsing body */ | |
| 368 | 368 | |
| 369 | -        if (!file_exists($tplf['body'])) { | |
| 370 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); | |
| 371 | - exit; | |
| 372 | - } | |
| 369 | +		if (!file_exists($tplf['body'])) { | |
| 370 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); | |
| 371 | + exit; | |
| 372 | + } | |
| 373 | 373 | |
| 374 | - $body_tmpl = file_get_contents($tplf['body']); | |
| 375 | -        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); | |
| 376 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); | |
| 377 | - $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); | |
| 378 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); | |
| 374 | + $body_tmpl = file_get_contents($tplf['body']); | |
| 375 | +		$arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); | |
| 376 | + $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); | |
| 377 | + $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); | |
| 378 | + $body = preg_replace( "/\r|\n/", "\r\n", $body ); | |
| 379 | 379 | $body = wordwrap ( $body, 75 , "\r\n" ); | 
| 380 | 380 | |
| 381 | 381 | /* Send the mail! */ | 
| 382 | 382 | $params = NULL; | 
| 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 | |
| @@ -1,24 +1,24 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -$version='1.9d'; | |
| 3 | +$version = '1.9d'; | |
| 4 | 4 | |
| 5 | 5 |  function username() { | 
| 6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; | 
| 7 | 7 | else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; | 
| 8 | - else $user='unknown'; | |
| 8 | + else $user = 'unknown'; | |
| 9 | 9 | return $user; | 
| 10 | 10 | } | 
| 11 | 11 | |
| 12 | 12 | |
| 13 | -function addtolist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason) { | |
| 13 | +function addtolist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) { | |
| 14 | 14 | // See MySQL manual for $expQ and $expUnit at | 
| 15 | 15 | // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd | 
| 16 | 16 | |
| 17 | - $result=FALSE; | |
| 17 | + $result = FALSE; | |
| 18 | 18 | |
| 19 | 19 |  	switch ($type) { | 
| 20 | 20 | case 'ip': | 
| 21 | -		$query= sprintf("INSERT INTO `$table` ( | |
| 21 | +		$query = sprintf("INSERT INTO `$table` ( | |
| 22 | 22 | `$type` , | 
| 23 | 23 | `date` , | 
| 24 | 24 | `exp` , | 
| @@ -29,12 +29,12 @@ discard block | ||
| 29 | 29 | VALUES ( | 
| 30 | 30 | INET_ATON( '%s' ) , | 
| 31 | 31 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' | 
| 32 | - )" ,$value,$expUnit,$expQ,$user,$myreason); | |
| 32 | + )", $value, $expUnit, $expQ, $user, $myreason); | |
| 33 | 33 | break; | 
| 34 | 34 | |
| 35 | 35 | case 'network': | 
| 36 | -		list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 37 | -                $query= sprintf("INSERT INTO `$table` ( | |
| 36 | +		list($sub['net'], $sub['mask']) = explode('/', $value); | |
| 37 | +                $query = sprintf("INSERT INTO `$table` ( | |
| 38 | 38 | `$type` , | 
| 39 | 39 | `netmask`, | 
| 40 | 40 | `date` , | 
| @@ -46,11 +46,11 @@ discard block | ||
| 46 | 46 | VALUES ( | 
| 47 | 47 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , | 
| 48 | 48 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' | 
| 49 | - )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); | |
| 49 | + )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason); | |
| 50 | 50 | break; | 
| 51 | 51 | |
| 52 | 52 | default: | 
| 53 | -                $query= sprintf("INSERT INTO `$table` ( | |
| 53 | +                $query = sprintf("INSERT INTO `$table` ( | |
| 54 | 54 | `$type` , | 
| 55 | 55 | `date` , | 
| 56 | 56 | `exp` , | 
| @@ -61,61 +61,61 @@ discard block | ||
| 61 | 61 | VALUES ( | 
| 62 | 62 | '%s' , | 
| 63 | 63 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' | 
| 64 | - )" ,$value,$expUnit,$expQ,$user,$myreason); | |
| 64 | + )", $value, $expUnit, $expQ, $user, $myreason); | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 |  	if ($myconn->query($query) === TRUE) { | 
| 68 | 68 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); | 
| 69 | - $result=TRUE; | |
| 69 | + $result = TRUE; | |
| 70 | 70 | } | 
| 71 | 71 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); | 
| 72 | 72 | return $result; | 
| 73 | 73 | } | 
| 74 | 74 | |
| 75 | -function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason) { | |
| 75 | +function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) { | |
| 76 | 76 | |
| 77 | - $result=FALSE; | |
| 77 | + $result = FALSE; | |
| 78 | 78 | |
| 79 | 79 |          switch ($type) { | 
| 80 | 80 | case 'ip': | 
| 81 | -                $query= sprintf("UPDATE `$table` SET | |
| 81 | +                $query = sprintf("UPDATE `$table` SET | |
| 82 | 82 | `active` = '1', | 
| 83 | 83 | `user` = '%s', | 
| 84 | 84 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), | 
| 85 | 85 | `nlist` = `nlist` + 1, | 
| 86 | 86 | `reason` = '%s' | 
| 87 | -			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); | |
| 87 | +			WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); | |
| 88 | 88 | break; | 
| 89 | 89 | case 'network': | 
| 90 | -		list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 91 | -                $query= sprintf("UPDATE `$table` SET | |
| 90 | +		list($sub['net'], $sub['mask']) = explode('/', $value); | |
| 91 | +                $query = sprintf("UPDATE `$table` SET | |
| 92 | 92 | `active` = '1', | 
| 93 | 93 | `user` = '%s', | 
| 94 | 94 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), | 
| 95 | 95 | `nlist` = `nlist` + 1, | 
| 96 | 96 | `reason` = '%s' | 
| 97 | -                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); | |
| 97 | +                        WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $myreason, $sub['net'], $sub['mask']); | |
| 98 | 98 | break; | 
| 99 | 99 | default: | 
| 100 | -                $query= sprintf("UPDATE `$table` SET | |
| 100 | +                $query = sprintf("UPDATE `$table` SET | |
| 101 | 101 | `active` = '1', | 
| 102 | 102 | `user` = '%s', | 
| 103 | 103 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), | 
| 104 | 104 | `nlist` = `nlist` + 1, | 
| 105 | 105 | `reason` = '%s' | 
| 106 | - WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); | |
| 106 | + WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); | |
| 107 | 107 | } | 
| 108 | 108 | |
| 109 | 109 |          if ($myconn->query($query) === TRUE) { | 
| 110 | 110 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); | 
| 111 | - $result=TRUE; | |
| 111 | + $result = TRUE; | |
| 112 | 112 | } | 
| 113 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); | |
| 113 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); | |
| 114 | 114 | return $result; | 
| 115 | 115 | } | 
| 116 | 116 | |
| 117 | -function remove ($myconn,$user,$value,$type,$table) { | |
| 118 | - $result=FALSE; | |
| 117 | +function remove($myconn, $user, $value, $type, $table) { | |
| 118 | + $result = FALSE; | |
| 119 | 119 | |
| 120 | 120 |          switch ($type) { | 
| 121 | 121 | case 'ip': | 
| @@ -123,10 +123,10 @@ discard block | ||
| 123 | 123 |                          `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); | 
| 124 | 124 | break; | 
| 125 | 125 | case 'network': | 
| 126 | -		list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 126 | +		list($sub['net'], $sub['mask']) = explode('/', $value); | |
| 127 | 127 |  		$query = sprintf("DELETE FROM `$table` WHERE | 
| 128 | 128 |  			`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1", | 
| 129 | - $sub['net'],$sub['mask']); | |
| 129 | + $sub['net'], $sub['mask']); | |
| 130 | 130 | break; | 
| 131 | 131 | default: | 
| 132 | 132 |  		$query = sprintf("DELETE FROM `$table` WHERE | 
| @@ -134,38 +134,38 @@ discard block | ||
| 134 | 134 | } | 
| 135 | 135 | |
| 136 | 136 | |
| 137 | - if ($return=$myconn->query($query) === TRUE) | |
| 137 | + if ($return = $myconn->query($query) === TRUE) | |
| 138 | 138 | syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); | 
| 139 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); | |
| 139 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); | |
| 140 | 140 | |
| 141 | 141 | return $return; | 
| 142 | 142 | } | 
| 143 | 143 | |
| 144 | 144 | |
| 145 | -function changestatus ($myconn,$user,$value,$status,$type,$table) { | |
| 145 | +function changestatus($myconn, $user, $value, $status, $type, $table) { | |
| 146 | 146 | |
| 147 | 147 |  	switch ($type) { | 
| 148 | 148 | case 'ip': | 
| 149 | -		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); | |
| 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': | 
| 152 | -		list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 153 | -		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user, $sub['net'],$sub['mask']); | |
| 152 | +		list($sub['net'], $sub['mask']) = explode('/', $value); | |
| 153 | +		$query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $sub['net'], $sub['mask']); | |
| 154 | 154 | break; | 
| 155 | 155 | default: | 
| 156 | -		$query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); | |
| 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) { | |
| 159 | +        if ($return = $myconn->query($query) === TRUE) { | |
| 160 | 160 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); | 
| 161 | 161 | } | 
| 162 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); | |
| 162 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); | |
| 163 | 163 | return $return; | 
| 164 | 164 | } | 
| 165 | 165 | |
| 166 | 166 | |
| 167 | -function expire ($myconn,$user,$tables,$expireTime) { | |
| 168 | - $return=TRUE; | |
| 167 | +function expire($myconn, $user, $tables, $expireTime) { | |
| 168 | + $return = TRUE; | |
| 169 | 169 | $desc = array_keys($tables); | 
| 170 | 170 |  	foreach ($desc as $tdesc) {  | 
| 171 | 171 | /* QUERY */ | 
| @@ -184,11 +184,11 @@ discard block | ||
| 184 | 184 | } while ($myconn->next_result()); | 
| 185 | 185 | } | 
| 186 | 186 |  		else { | 
| 187 | - syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); | |
| 187 | + syslog(LOG_ERR, "Expire job - Error: ".$myconn->error); | |
| 188 | 188 | $return = FALSE; | 
| 189 | 189 | } | 
| 190 | 190 | } | 
| 191 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); | |
| 191 | + if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); | |
| 192 | 192 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); | 
| 193 | 193 | return $return; | 
| 194 | 194 | } | 
| @@ -196,21 +196,21 @@ discard block | ||
| 196 | 196 | |
| 197 | 197 |  function isListed($row) { | 
| 198 | 198 | |
| 199 | - $exp=new DateTime($row['exp']); | |
| 200 | -	$now=new DateTime('NOW'); | |
| 201 | - if (($exp > $now) and ($row['active'])) return true; | |
| 199 | + $exp = new DateTime($row['exp']); | |
| 200 | +	$now = new DateTime('NOW'); | |
| 201 | + if (($exp>$now) and ($row['active'])) return true; | |
| 202 | 202 | else return false; | 
| 203 | 203 | |
| 204 | 204 | } | 
| 205 | 205 | |
| 206 | 206 | |
| 207 | -function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { | |
| 207 | +function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) { | |
| 208 | 208 | |
| 209 | 209 |  	switch ($what) { | 
| 210 | 210 | case 'Ok': | 
| 211 | 211 | if ($lock) return NULL; | 
| 212 | - if (in_array($user,array_keys($adm))) | |
| 213 | -				if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); | |
| 212 | + if (in_array($user, array_keys($adm))) | |
| 213 | +				if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php'); | |
| 214 | 214 | return htmlspecialchars($whynot); | 
| 215 | 215 | case 'Listed': | 
| 216 | 216 | case 'WhiteListed': | 
| @@ -219,17 +219,17 @@ discard block | ||
| 219 | 219 | } | 
| 220 | 220 | |
| 221 | 221 | |
| 222 | -function consistentListing($myconn,$alltables,$typed,$value,&$warn) { | |
| 222 | +function consistentListing($myconn, $alltables, $typed, $value, &$warn) { | |
| 223 | 223 | /* Check if there are no pending mislisting */ | 
| 224 | 224 | $warn = NULL; | 
| 225 | 225 |  	foreach ($alltables["$typed"]['depend'] as $listdep) { | 
| 226 | -		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { | |
| 226 | +		if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) { | |
| 227 | 227 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; | 
| 228 | 228 | return FALSE; | 
| 229 | 229 | } | 
| 230 | - $entry = searchentry($myconn,$value,$alltables["$listdep"]); | |
| 231 | -		if ( $entry->num_rows ) { | |
| 232 | -			if ( $entry->num_rows == 1 ) { | |
| 230 | + $entry = searchentry($myconn, $value, $alltables["$listdep"]); | |
| 231 | +		if ($entry->num_rows) { | |
| 232 | +			if ($entry->num_rows == 1) { | |
| 233 | 233 | $riga = $entry->fetch_array(MYSQLI_ASSOC); | 
| 234 | 234 |                          	if (isListed($riga)) { | 
| 235 | 235 | $warn = "<$value> is already present in <$listdep> list!"; | 
| @@ -237,7 +237,7 @@ discard block | ||
| 237 | 237 | return FALSE; | 
| 238 | 238 | } | 
| 239 | 239 | } | 
| 240 | -			if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";} | |
| 240 | +			if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; } | |
| 241 | 241 | } | 
| 242 | 242 | $entry->free(); | 
| 243 | 243 | } | 
| @@ -245,7 +245,7 @@ discard block | ||
| 245 | 245 | return TRUE; | 
| 246 | 246 | } | 
| 247 | 247 | |
| 248 | -function searchentry ($myconn,$value,$tablelist) { | |
| 248 | +function searchentry($myconn, $value, $tablelist) { | |
| 249 | 249 | /* Make a MYSQL query and return result */ | 
| 250 | 250 | |
| 251 | 251 | $type = $tablelist['field']; | 
| @@ -255,24 +255,24 @@ discard block | ||
| 255 | 255 |          else { | 
| 256 | 256 |                  switch ($type) { | 
| 257 | 257 | case 'ip': | 
| 258 | -                        $query= "select * from $table where $type =  INET_ATON('$value')"; | |
| 258 | +                        $query = "select * from $table where $type =  INET_ATON('$value')"; | |
| 259 | 259 | break; | 
| 260 | 260 | case 'network': | 
| 261 | -                        list($sub['net'],$sub['mask'])=explode('/',$value); | |
| 262 | - $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; | |
| 261 | +                        list($sub['net'], $sub['mask']) = explode('/', $value); | |
| 262 | + $query = 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; | |
| 263 | 263 | break; | 
| 264 | 264 | default: | 
| 265 | - $query= "select * from $table where $type = '$value'"; | |
| 265 | + $query = "select * from $table where $type = '$value'"; | |
| 266 | 266 | } | 
| 267 | 267 | } | 
| 268 | 268 | |
| 269 | 269 | $result = $myconn->query($query); | 
| 270 | - if($result === false) | |
| 270 | + if ($result === false) | |
| 271 | 271 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); | 
| 272 | 272 | return $result; | 
| 273 | 273 | } | 
| 274 | 274 | |
| 275 | -function countListed ($myconn,$table) { | |
| 275 | +function countListed($myconn, $table) { | |
| 276 | 276 | /* Return number of current listed items into a rbl table */ | 
| 277 | 277 | $number = 0; | 
| 278 | 278 | $query = "SELECT COUNT(*) as `count` FROM `$table` WHERE (`active`=1 AND TIMESTAMPDIFF(MICROSECOND,NOW(),`exp`)>0) GROUP BY `active` ORDER BY `count` DESC LIMIT 1"; | 
| @@ -284,37 +284,37 @@ discard block | ||
| 284 | 284 | } | 
| 285 | 285 | |
| 286 | 286 | |
| 287 | -function isFull($myconn,$typedesc,$alltables) { | |
| 287 | +function isFull($myconn, $typedesc, $alltables) { | |
| 288 | 288 |          if (isset($alltables["$typedesc"]['limit'])) { | 
| 289 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) | |
| 289 | + if (countListed($myconn, $alltables["$typedesc"]['name'])>=$alltables["$typedesc"]['limit']) | |
| 290 | 290 | return TRUE; | 
| 291 | 291 | } | 
| 292 | 292 | return FALSE; | 
| 293 | 293 | } | 
| 294 | 294 | |
| 295 | -function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) { | |
| 295 | +function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) { | |
| 296 | 296 | |
| 297 | 297 | $type = $tables["$typedesc"]['field']; | 
| 298 | 298 | $table = $tables["$typedesc"]['name']; | 
| 299 | 299 | |
| 300 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); | |
| 300 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); | |
| 301 | 301 |  	if ($result) { | 
| 302 | 302 |  		printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); | 
| 303 | 303 | |
| 304 | 304 | /* Check for limit in number of listed items */ | 
| 305 | - $full = isFull($myconn,$typedesc,$tables); | |
| 305 | + $full = isFull($myconn, $typedesc, $tables); | |
| 306 | 306 |  	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; | 
| 307 | 307 | |
| 308 | 308 |  		if ($result->num_rows) { | 
| 309 | 309 | 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"; | 
| 310 | - $i=0; | |
| 310 | + $i = 0; | |
| 311 | 311 |          		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { | 
| 312 | 312 |  				if (isListed($riga)) { | 
| 313 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; | |
| 314 | - else $listed='WhiteListed'; | |
| 313 | + if ($tables["$typedesc"]['bl']) $listed = 'Listed'; | |
| 314 | + else $listed = 'WhiteListed'; | |
| 315 | 315 | } | 
| 316 | 316 | else | 
| 317 | - $listed='Ok'; | |
| 317 | + $listed = 'Ok'; | |
| 318 | 318 | |
| 319 | 319 |  				switch ($type) { | 
| 320 | 320 | case 'ip': | 
| @@ -327,15 +327,15 @@ discard block | ||
| 327 | 327 | $element = $riga["$type"]; | 
| 328 | 328 | } | 
| 329 | 329 | |
| 330 | -                		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)); | |
| 330 | +                		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 | 331 | $i++; | 
| 332 | 332 | } | 
| 333 | 333 | print '</tbody></table>'; | 
| 334 | 334 | } | 
| 335 | 335 |  		else { | 
| 336 | 336 | print "<pre>$type <$value> is not listed!\n</pre>"; | 
| 337 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) | |
| 338 | -				if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); | |
| 337 | + if (in_array($user, array_keys($adm)) AND ($value != 'ALL')) | |
| 338 | +				if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php'); | |
| 339 | 339 | else print '<p>'.htmlspecialchars($whynot).'</p>'; | 
| 340 | 340 | |
| 341 | 341 | } | 
| @@ -345,12 +345,12 @@ discard block | ||
| 345 | 345 | } | 
| 346 | 346 | |
| 347 | 347 | |
| 348 | -function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { | |
| 348 | +function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) { | |
| 349 | 349 | $now = time(); | 
| 350 | - setlocale (LC_TIME, 'it_IT'); | |
| 351 | -        $date = date("r",$now); | |
| 352 | - $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; | |
| 353 | - $mua = 'PHP/' . phpversion(); | |
| 350 | + setlocale(LC_TIME, 'it_IT'); | |
| 351 | +        $date = date("r", $now); | |
| 352 | + $messageID = md5(uniqid($now, 1)).'@'.$_SERVER["HOSTNAME"]; | |
| 353 | + $mua = 'PHP/'.phpversion(); | |
| 354 | 354 | |
| 355 | 355 | /* Parsing headers */ | 
| 356 | 356 |  	if (!file_exists($tplf['header'])) { | 
| @@ -359,10 +359,10 @@ discard block | ||
| 359 | 359 | } | 
| 360 | 360 | |
| 361 | 361 | $head_tmpl = file_get_contents($tplf['header']); | 
| 362 | -	$arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}'); | |
| 363 | - $arr_tpl_data = array($from,$to,$date,$messageID,$mua); | |
| 362 | +	$arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}'); | |
| 363 | + $arr_tpl_data = array($from, $to, $date, $messageID, $mua); | |
| 364 | 364 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); | 
| 365 | - $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); | |
| 365 | +	$headers = preg_replace('/\r|\n/', "\r\n", $headers); | |
| 366 | 366 | |
| 367 | 367 | /* Parsing body */ | 
| 368 | 368 | |
| @@ -372,63 +372,63 @@ discard block | ||
| 372 | 372 | } | 
| 373 | 373 | |
| 374 | 374 | $body_tmpl = file_get_contents($tplf['body']); | 
| 375 | -        $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); | |
| 376 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); | |
| 375 | +        $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}'); | |
| 376 | + $arr_tpl_data = array($emailListed, $intervalToExpire, $detail); | |
| 377 | 377 | $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); | 
| 378 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); | |
| 379 | - $body = wordwrap ( $body, 75 , "\r\n" ); | |
| 378 | +        $body = preg_replace("/\r|\n/", "\r\n", $body); | |
| 379 | + $body = wordwrap($body, 75, "\r\n"); | |
| 380 | 380 | |
| 381 | 381 | /* Send the mail! */ | 
| 382 | 382 | $params = NULL; | 
| 383 | -        if ( strlen(ini_get("safe_mode"))< 1) { | |
| 383 | +        if (strlen(ini_get("safe_mode"))<1) { | |
| 384 | 384 |                  $old_mailfrom = ini_get("sendmail_from"); | 
| 385 | 385 |                  ini_set("sendmail_from", $from); | 
| 386 | 386 |                  $params = sprintf("-oi -f %s", '<>'); | 
| 387 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; | |
| 388 | - else $flag=TRUE; | |
| 387 | + if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE; | |
| 388 | + else $flag = TRUE; | |
| 389 | 389 | if (isset($old_mailfrom)) | 
| 390 | 390 |                          ini_set("sendmail_from", $old_mailfrom); | 
| 391 | 391 | } | 
| 392 | 392 |          else { | 
| 393 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; | |
| 394 | - else $flag=TRUE; | |
| 393 | + if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE; | |
| 394 | + else $flag = TRUE; | |
| 395 | 395 | } | 
| 396 | 396 | return $flag; | 
| 397 | 397 | } | 
| 398 | 398 | |
| 399 | -function emailToNotify($notify_file,$dom) { | |
| 399 | +function emailToNotify($notify_file, $dom) { | |
| 400 | 400 | $ini_array = parse_ini_file($notify_file); | 
| 401 | - if (in_array($dom,array_keys($ini_array))) | |
| 401 | + if (in_array($dom, array_keys($ini_array))) | |
| 402 | 402 | return $ini_array["$dom"]; | 
| 403 | 403 | else return FALSE; | 
| 404 | 404 | } | 
| 405 | 405 | |
| 406 | 406 | |
| 407 | -function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { | |
| 407 | +function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, $reason) { | |
| 408 | 408 | |
| 409 | 409 | /* Search and list value */ | 
| 410 | 410 | $type = $tables["$typedesc"]['field']; | 
| 411 | 411 | $table = $tables["$typedesc"]['name']; | 
| 412 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); | |
| 412 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); | |
| 413 | 413 | |
| 414 | 414 | /* Manage abnormal conditions */ | 
| 415 | 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."); | |
| 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 | 418 | $result->free(); | 
| 419 | 419 | return FALSE; | 
| 420 | 420 | } | 
| 421 | 421 | |
| 422 | 422 | /* Value already present in db or not present: to list anyway */ | 
| 423 | -        if ($result->num_rows >= 0) { | |
| 423 | +        if ($result->num_rows>=0) { | |
| 424 | 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.'); | |
| 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 | 427 | $result->free(); | 
| 428 | 428 | return FALSE; | 
| 429 | 429 | } | 
| 430 | 430 | /* Second, check if the (re)list would be consistent now */ | 
| 431 | -                if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { | |
| 431 | +                if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) { | |
| 432 | 432 | syslog(LOG_ERR, $loguser.': '.$whynot); | 
| 433 | 433 | $result->free(); | 
| 434 | 434 | return FALSE; | 
| @@ -443,7 +443,7 @@ discard block | ||
| 443 | 443 | /* Relist value if already present */ | 
| 444 | 444 | case 1: | 
| 445 | 445 | /* Entry already listed */ | 
| 446 | -                        if ( isListed($thisentry) ) { | |
| 446 | +                        if (isListed($thisentry)) { | |
| 447 | 447 | syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); | 
| 448 | 448 | $result->free(); | 
| 449 | 449 | return FALSE; | 
| @@ -452,13 +452,13 @@ discard block | ||
| 452 | 452 | /* Entry delisted */ | 
| 453 | 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 | 458 | /* First time list value */ | 
| 459 | 459 | case 0: | 
| 460 | 460 | $result->free(); | 
| 461 | - return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); | |
| 461 | + return addtolist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason); | |
| 462 | 462 | } | 
| 463 | 463 | } | 
| 464 | 464 | |
| @@ -3,9 +3,13 @@ discard block | ||
| 3 | 3 | $version='1.9d'; | 
| 4 | 4 | |
| 5 | 5 |  function username() { | 
| 6 | - if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; | |
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; | |
| 8 | - else $user='unknown'; | |
| 6 | +	if (isset ($_SERVER['REMOTE_USER'])) { | |
| 7 | + $user = $_SERVER['REMOTE_USER']; | |
| 8 | +	} else if (isset ($_SERVER['USER'])) { | |
| 9 | + $user = $_SERVER['USER']; | |
| 10 | +        	} else { | |
| 11 | + $user='unknown'; | |
| 12 | + } | |
| 9 | 13 | return $user; | 
| 10 | 14 | } | 
| 11 | 15 | |
| @@ -67,8 +71,9 @@ discard block | ||
| 67 | 71 |  	if ($myconn->query($query) === TRUE) { | 
| 68 | 72 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); | 
| 69 | 73 | $result=TRUE; | 
| 74 | +	} else { | |
| 75 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); | |
| 70 | 76 | } | 
| 71 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); | |
| 72 | 77 | return $result; | 
| 73 | 78 | } | 
| 74 | 79 | |
| @@ -109,8 +114,9 @@ discard block | ||
| 109 | 114 |          if ($myconn->query($query) === TRUE) { | 
| 110 | 115 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); | 
| 111 | 116 | $result=TRUE; | 
| 117 | +        } else { | |
| 118 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); | |
| 112 | 119 | } | 
| 113 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); | |
| 114 | 120 | return $result; | 
| 115 | 121 | } | 
| 116 | 122 | |
| @@ -134,9 +140,11 @@ discard block | ||
| 134 | 140 | } | 
| 135 | 141 | |
| 136 | 142 | |
| 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); | |
| 143 | +        if ($return=$myconn->query($query) === TRUE) { | |
| 144 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); | |
| 145 | +        } else { | |
| 146 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); | |
| 147 | + } | |
| 140 | 148 | |
| 141 | 149 | return $return; | 
| 142 | 150 | } | 
| @@ -158,8 +166,9 @@ discard block | ||
| 158 | 166 | |
| 159 | 167 |          if ($return=$myconn->query($query) === TRUE) { | 
| 160 | 168 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); | 
| 169 | +        } else { | |
| 170 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); | |
| 161 | 171 | } | 
| 162 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); | |
| 163 | 172 | return $return; | 
| 164 | 173 | } | 
| 165 | 174 | |
| @@ -182,14 +191,16 @@ discard block | ||
| 182 | 191 | $j++; | 
| 183 | 192 | |
| 184 | 193 | } while ($myconn->next_result()); | 
| 185 | - } | |
| 186 | -		else { | |
| 194 | +		} else { | |
| 187 | 195 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); | 
| 188 | 196 | $return = FALSE; | 
| 189 | 197 | } | 
| 190 | 198 | } | 
| 191 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); | |
| 192 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); | |
| 199 | +	if ( !($return) ) { | |
| 200 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); | |
| 201 | +	} else { | |
| 202 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); | |
| 203 | + } | |
| 193 | 204 | return $return; | 
| 194 | 205 | } | 
| 195 | 206 | |
| @@ -198,8 +209,11 @@ discard block | ||
| 198 | 209 | |
| 199 | 210 | $exp=new DateTime($row['exp']); | 
| 200 | 211 |  	$now=new DateTime('NOW'); | 
| 201 | - if (($exp > $now) and ($row['active'])) return true; | |
| 202 | - else return false; | |
| 212 | +	if (($exp > $now) and ($row['active'])) { | |
| 213 | + return true; | |
| 214 | +	} else { | |
| 215 | + return false; | |
| 216 | + } | |
| 203 | 217 | |
| 204 | 218 | } | 
| 205 | 219 | |
| @@ -208,9 +222,12 @@ discard block | ||
| 208 | 222 | |
| 209 | 223 |  	switch ($what) { | 
| 210 | 224 | case 'Ok': | 
| 211 | - if ($lock) return NULL; | |
| 212 | - if (in_array($user,array_keys($adm))) | |
| 213 | -				if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); | |
| 225 | +			if ($lock) { | |
| 226 | + return NULL; | |
| 227 | + } | |
| 228 | +			if (in_array($user,array_keys($adm))) { | |
| 229 | +							if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); | |
| 230 | + } | |
| 214 | 231 | return htmlspecialchars($whynot); | 
| 215 | 232 | case 'Listed': | 
| 216 | 233 | case 'WhiteListed': | 
| @@ -251,8 +268,9 @@ discard block | ||
| 251 | 268 | $type = $tablelist['field']; | 
| 252 | 269 | $table = $tablelist['name']; | 
| 253 | 270 | |
| 254 | - if ($value == 'ALL') $query = 'select * from '.$table; | |
| 255 | -        else { | |
| 271 | +        if ($value == 'ALL') { | |
| 272 | + $query = 'select * from '.$table; | |
| 273 | +        } else { | |
| 256 | 274 |                  switch ($type) { | 
| 257 | 275 | case 'ip': | 
| 258 | 276 |                          $query= "select * from $table where $type =  INET_ATON('$value')"; | 
| @@ -267,8 +285,9 @@ discard block | ||
| 267 | 285 | } | 
| 268 | 286 | |
| 269 | 287 | $result = $myconn->query($query); | 
| 270 | - if($result === false) | |
| 271 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); | |
| 288 | +	if($result === false) { | |
| 289 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); | |
| 290 | + } | |
| 272 | 291 | return $result; | 
| 273 | 292 | } | 
| 274 | 293 | |
| @@ -286,8 +305,9 @@ discard block | ||
| 286 | 305 | |
| 287 | 306 |  function isFull($myconn,$typedesc,$alltables) { | 
| 288 | 307 |          if (isset($alltables["$typedesc"]['limit'])) { | 
| 289 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) | |
| 290 | - return TRUE; | |
| 308 | +                if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) { | |
| 309 | + return TRUE; | |
| 310 | + } | |
| 291 | 311 | } | 
| 292 | 312 | return FALSE; | 
| 293 | 313 | } | 
| @@ -303,18 +323,23 @@ discard block | ||
| 303 | 323 | |
| 304 | 324 | /* Check for limit in number of listed items */ | 
| 305 | 325 | $full = isFull($myconn,$typedesc,$tables); | 
| 306 | -	if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; | |
| 326 | +	if ($full) { | |
| 327 | +		print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; | |
| 328 | + } | |
| 307 | 329 | |
| 308 | 330 |  		if ($result->num_rows) { | 
| 309 | 331 | 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"; | 
| 310 | 332 | $i=0; | 
| 311 | 333 |          		while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { | 
| 312 | 334 |  				if (isListed($riga)) { | 
| 313 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; | |
| 314 | - else $listed='WhiteListed'; | |
| 315 | - } | |
| 316 | - else | |
| 317 | - $listed='Ok'; | |
| 335 | +					if ($tables["$typedesc"]['bl']) { | |
| 336 | + $listed='Listed'; | |
| 337 | +					} else { | |
| 338 | + $listed='WhiteListed'; | |
| 339 | + } | |
| 340 | +				} else { | |
| 341 | + $listed='Ok'; | |
| 342 | + } | |
| 318 | 343 | |
| 319 | 344 |  				switch ($type) { | 
| 320 | 345 | case 'ip': | 
| @@ -331,18 +356,20 @@ discard block | ||
| 331 | 356 | $i++; | 
| 332 | 357 | } | 
| 333 | 358 | print '</tbody></table>'; | 
| 334 | - } | |
| 335 | -		else { | |
| 359 | +		} else { | |
| 336 | 360 | print "<pre>$type <$value> is not listed!\n</pre>"; | 
| 337 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) | |
| 338 | -				if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); | |
| 339 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; | |
| 361 | +			if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { | |
| 362 | +							if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); | |
| 363 | +			} else { | |
| 364 | + print '<p>'.htmlspecialchars($whynot).'</p>'; | |
| 365 | + } | |
| 340 | 366 | |
| 341 | 367 | } | 
| 342 | 368 | $result->free(); | 
| 369 | +	} else { | |
| 370 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; | |
| 371 | + } | |
| 343 | 372 | } | 
| 344 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; | |
| 345 | -} | |
| 346 | 373 | |
| 347 | 374 | |
| 348 | 375 |  function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { | 
| @@ -384,24 +411,32 @@ discard block | ||
| 384 | 411 |                  $old_mailfrom = ini_get("sendmail_from"); | 
| 385 | 412 |                  ini_set("sendmail_from", $from); | 
| 386 | 413 |                  $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; | |
| 414 | +                if (!(mail($to,$sbj, $body,$headers,$params))) { | |
| 415 | + $flag=FALSE; | |
| 416 | +                } else { | |
| 417 | + $flag=TRUE; | |
| 418 | + } | |
| 419 | +                if (isset($old_mailfrom)) { | |
| 420 | +                                        ini_set("sendmail_from", $old_mailfrom); | |
| 421 | + } | |
| 422 | +        } else { | |
| 423 | +                if (!(mail($to,$sbj, $body,$headers))) { | |
| 424 | + $flag=FALSE; | |
| 425 | +                } else { | |
| 426 | + $flag=TRUE; | |
| 427 | + } | |
| 395 | 428 | } | 
| 396 | 429 | return $flag; | 
| 397 | 430 | } | 
| 398 | 431 | |
| 399 | 432 |  function emailToNotify($notify_file,$dom) { | 
| 400 | 433 | $ini_array = parse_ini_file($notify_file); | 
| 401 | - if (in_array($dom,array_keys($ini_array))) | |
| 402 | - return $ini_array["$dom"]; | |
| 403 | - else return FALSE; | |
| 404 | -} | |
| 434 | +	if (in_array($dom,array_keys($ini_array))) { | |
| 435 | + return $ini_array["$dom"]; | |
| 436 | +	} else { | |
| 437 | + return FALSE; | |
| 438 | + } | |
| 439 | + } | |
| 405 | 440 | |
| 406 | 441 | |
| 407 | 442 |  function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { | 
| @@ -10,7 +10,7 @@ discard block | ||
| 10 | 10 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid email address.</pre>'); | 
| 11 | 11 | |
| 12 | 12 | if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) | 
| 13 | - if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) | |
| 13 | + if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) | |
| 14 | 14 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); | 
| 15 | 15 | |
| 16 | 16 | if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) | 
| @@ -26,8 +26,8 @@ discard block | ||
| 26 | 26 | } | 
| 27 | 27 | |
| 28 | 28 |  if ( ($tables["$_"]['field']=='username') AND ($_POST['Value']!='ALL') ) { | 
| 29 | - if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) | |
| 30 | -                exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); | |
| 29 | + if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) | |
| 30 | +				exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); | |
| 31 | 31 |  	if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) | 
| 32 | 32 |  		exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); | 
| 33 | 33 |  	switch ( $_POST['Value'] ) { | 
| @@ -49,10 +49,10 @@ discard block | ||
| 49 | 49 | |
| 50 | 50 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| 51 | 51 |  if ($mysqli->connect_error) { | 
| 52 | -            syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 53 | - . $mysqli->connect_error); | |
| 54 | -            exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 55 | - . $mysqli->connect_error); | |
| 52 | +			syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 53 | + . $mysqli->connect_error); | |
| 54 | +			exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 55 | + . $mysqli->connect_error); | |
| 56 | 56 | } | 
| 57 | 57 | |
| 58 | 58 | syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ; | 
| @@ -5,36 +5,36 @@ discard block | ||
| 5 | 5 | $net = new \dautkom\ipv4\IPv4(); | 
| 6 | 6 | |
| 7 | 7 | $_ = $_POST['genere']; | 
| 8 | -if ( ($tables["$_"]['field']=='email') AND ($_POST['Value']!='ALL') ) | |
| 8 | +if (($tables["$_"]['field'] == 'email') AND ($_POST['Value'] != 'ALL')) | |
| 9 | 9 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_EMAIL))) | 
| 10 | 10 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid email address.</pre>'); | 
| 11 | 11 | |
| 12 | -if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) | |
| 12 | +if (($tables["$_"]['field'] == 'domain') AND ($_POST['Value'] != 'ALL')) | |
| 13 | 13 | if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) | 
| 14 | 14 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); | 
| 15 | 15 | |
| 16 | -if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) | |
| 16 | +if (($tables["$_"]['field'] == 'ip') AND ($_POST['Value'] != 'ALL')) | |
| 17 | 17 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))) | 
| 18 | 18 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid IP address.</pre>'); | 
| 19 | 19 | |
| 20 | -if ( ($tables["$_"]['field']=='network') AND ($_POST['Value']!='ALL') ) { | |
| 21 | -	$value = explode('/',$_POST['Value']); | |
| 20 | +if (($tables["$_"]['field'] == 'network') AND ($_POST['Value'] != 'ALL')) { | |
| 21 | +	$value = explode('/', $_POST['Value']); | |
| 22 | 22 | if (count($value) != 2) | 
| 23 | 23 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask pair.</pre>'); | 
| 24 | 24 | if (!$net->address($value[0])->mask($value[1])->isValid(1)) | 
| 25 | 25 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask.</pre>'); | 
| 26 | 26 | } | 
| 27 | 27 | |
| 28 | -if ( ($tables["$_"]['field']=='username') AND ($_POST['Value']!='ALL') ) { | |
| 29 | - if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) | |
| 28 | +if (($tables["$_"]['field'] == 'username') AND ($_POST['Value'] != 'ALL')) { | |
| 29 | +        if (preg_match('/[^\x20-\x7f]/', $_POST['Value'])) | |
| 30 | 30 |                  exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); | 
| 31 | -	if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) | |
| 31 | +	if (preg_match('/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value'])) | |
| 32 | 32 |  		exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); | 
| 33 | -	switch ( $_POST['Value'] ) { | |
| 33 | +	switch ($_POST['Value']) { | |
| 34 | 34 | case 'anonymous': | 
| 35 | 35 | case 'anybody': | 
| 36 | 36 | case 'anyone': | 
| 37 | - case ( preg_match( '/^anyone@/',$_POST['Value']) == TRUE ) : | |
| 37 | +		case (preg_match('/^anyone@/', $_POST['Value']) == TRUE) : | |
| 38 | 38 |  			exit('<pre><'.$_POST['Value'].'> is not allowed.</pre>'); | 
| 39 | 39 | } | 
| 40 | 40 | } | 
| @@ -49,14 +49,14 @@ discard block | ||
| 49 | 49 | |
| 50 | 50 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| 51 | 51 |  if ($mysqli->connect_error) { | 
| 52 | -            syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 52 | +            syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' | |
| 53 | 53 | . $mysqli->connect_error); | 
| 54 | -            exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 54 | +            exit ($user.': Connect Error ('.$mysqli->connect_errno.') ' | |
| 55 | 55 | . $mysqli->connect_error); | 
| 56 | 56 | } | 
| 57 | 57 | |
| 58 | -syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ; | |
| 59 | -rlookup($mysqli,username(),$admins,$_POST['Value'],$_POST['genere'],$tables); | |
| 58 | +syslog(LOG_INFO, $user.': Successfully mysql connected to '.$mysqli->host_info); | |
| 59 | +rlookup($mysqli, username(), $admins, $_POST['Value'], $_POST['genere'], $tables); | |
| 60 | 60 | $mysqli->close(); | 
| 61 | 61 | closelog(); | 
| 62 | 62 | ?> | 
| @@ -5,31 +5,38 @@ discard block | ||
| 5 | 5 | $net = new \dautkom\ipv4\IPv4(); | 
| 6 | 6 | |
| 7 | 7 | $_ = $_POST['genere']; | 
| 8 | -if ( ($tables["$_"]['field']=='email') AND ($_POST['Value']!='ALL') ) | |
| 8 | +if ( ($tables["$_"]['field']=='email') AND ($_POST['Value']!='ALL') ) { | |
| 9 | 9 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_EMAIL))) | 
| 10 | 10 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid email address.</pre>'); | 
| 11 | +} | |
| 11 | 12 | |
| 12 | -if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) | |
| 13 | +if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) { | |
| 13 | 14 | if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) | 
| 14 | 15 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); | 
| 16 | +} | |
| 15 | 17 | |
| 16 | -if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) | |
| 18 | +if ( ($tables["$_"]['field']=='ip')  AND ($_POST['Value']!='ALL') ) { | |
| 17 | 19 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))) | 
| 18 | 20 |  		exit ('<pre><'.$_POST['Value'].'> is NOT a valid IP address.</pre>'); | 
| 21 | +} | |
| 19 | 22 | |
| 20 | 23 |  if ( ($tables["$_"]['field']=='network') AND ($_POST['Value']!='ALL') ) { | 
| 21 | 24 |  	$value = explode('/',$_POST['Value']); | 
| 22 | - if (count($value) != 2) | |
| 23 | -		exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask pair.</pre>'); | |
| 24 | - if (!$net->address($value[0])->mask($value[1])->isValid(1)) | |
| 25 | -		exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask.</pre>'); | |
| 26 | -} | |
| 25 | +	if (count($value) != 2) { | |
| 26 | +			exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask pair.</pre>'); | |
| 27 | + } | |
| 28 | +	if (!$net->address($value[0])->mask($value[1])->isValid(1)) { | |
| 29 | +			exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask.</pre>'); | |
| 30 | + } | |
| 31 | + } | |
| 27 | 32 | |
| 28 | 33 |  if ( ($tables["$_"]['field']=='username') AND ($_POST['Value']!='ALL') ) { | 
| 29 | - if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) | |
| 30 | -                exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); | |
| 31 | -	if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) | |
| 32 | -		exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); | |
| 34 | +        if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) { | |
| 35 | +                        exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); | |
| 36 | + } | |
| 37 | +	if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) { | |
| 38 | +			exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); | |
| 39 | + } | |
| 33 | 40 |  	switch ( $_POST['Value'] ) { | 
| 34 | 41 | case 'anonymous': | 
| 35 | 42 | case 'anybody': | 
| @@ -40,9 +47,12 @@ discard block | ||
| 40 | 47 | } | 
| 41 | 48 | |
| 42 | 49 |  if (empty($_GET)) { | 
| 43 | - if ($tables["$_"]['bl']) print "<p><i>$_</i> is a blocklist of ".$tables["$_"]['field'].'.</p>'; | |
| 44 | - else print "<p><i>$_</i> is a whitelist of ".$tables["$_"]['field'].'.</p>'; | |
| 45 | -} | |
| 50 | +	if ($tables["$_"]['bl']) { | |
| 51 | + print "<p><i>$_</i> is a blocklist of ".$tables["$_"]['field'].'.</p>'; | |
| 52 | +	} else { | |
| 53 | + print "<p><i>$_</i> is a whitelist of ".$tables["$_"]['field'].'.</p>'; | |
| 54 | + } | |
| 55 | + } | |
| 46 | 56 | |
| 47 | 57 | openlog($tag, LOG_PID, $fac); | 
| 48 | 58 | $user = username(); | 
| @@ -14,10 +14,10 @@ discard block | ||
| 14 | 14 |  require_once('function.php'); | 
| 15 | 15 | |
| 16 | 16 | |
| 17 | -if ( $require_auth ) if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); | |
| 17 | +if ($require_auth) if (username() == 'unknown') exit ("<p>You MUST configure your server to use authentication.</p>"); | |
| 18 | 18 | |
| 19 | 19 | |
| 20 | -if ( $imapListActive ) | |
| 20 | +if ($imapListActive) | |
| 21 | 21 | print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>'; | 
| 22 | 22 | |
| 23 | 23 | print <<<END | 
| @@ -26,10 +26,10 @@ discard block | ||
| 26 | 26 | END; | 
| 27 | 27 | |
| 28 | 28 | |
| 29 | -$option=NULL; | |
| 29 | +$option = NULL; | |
| 30 | 30 | $desc = array_keys($tables); | 
| 31 | 31 |  foreach ($desc as $description) {  | 
| 32 | - $disabled = $tables["$description"]['active']==TRUE ? '' : ' disabled'; | |
| 32 | + $disabled = $tables["$description"]['active'] == TRUE ? '' : ' disabled'; | |
| 33 | 33 | $option .= '<option value="'.$description."\"$disabled>$description</option>"; | 
| 34 | 34 | } | 
| 35 | 35 | |
| @@ -14,11 +14,14 @@ | ||
| 14 | 14 |  require_once('function.php'); | 
| 15 | 15 | |
| 16 | 16 | |
| 17 | -if ( $require_auth ) if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); | |
| 17 | +if ( $require_auth ) { | |
| 18 | +	if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); | |
| 19 | +} | |
| 18 | 20 | |
| 19 | 21 | |
| 20 | -if ( $imapListActive ) | |
| 22 | +if ( $imapListActive ) { | |
| 21 | 23 | print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>'; | 
| 24 | +} | |
| 22 | 25 | |
| 23 | 26 | print <<<END | 
| 24 | 27 |  <form name="check" action="result.php" onSubmit="xmlhttpPost('result.php', 'check', 'Risultato', '<img src=\'/include/pleasewait.gif\'>'); return false;" enctype="text/plain" method="post" target="_self"> | 
| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| 11 | 11 |  if ($mysqli->connect_error) { | 
| 12 | 12 |  	syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | 
| 13 | - . $mysqli->connect_error); | |
| 14 | -        die($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 15 | - . $mysqli->connect_error); | |
| 13 | + . $mysqli->connect_error); | |
| 14 | +		die($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 15 | + . $mysqli->connect_error); | |
| 16 | 16 | } | 
| 17 | 17 | syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); | 
| 18 | 18 | |
| @@ -1,22 +1,22 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |  require_once('config.php'); | 
| 3 | 3 |  require_once('function.php'); | 
| 4 | -$typedesc=$_POST['type']; | |
| 5 | -$type = $tables["$typedesc"]['field']; | |
| 4 | +$typedesc = $_POST['type']; | |
| 5 | +$type = $tables["$typedesc"]['field']; | |
| 6 | 6 | $table = $tables["$typedesc"]['name']; | 
| 7 | 7 | |
| 8 | 8 | openlog($tag, LOG_PID, $fac); | 
| 9 | 9 | $user = username(); | 
| 10 | 10 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| 11 | 11 |  if ($mysqli->connect_error) { | 
| 12 | -	syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 12 | +	syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' | |
| 13 | 13 | . $mysqli->connect_error); | 
| 14 | -        die($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 14 | +        die($user.': Connect Error ('.$mysqli->connect_errno.') ' | |
| 15 | 15 | . $mysqli->connect_error); | 
| 16 | 16 | } | 
| 17 | -syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); | |
| 17 | +syslog(LOG_INFO, $user.': Successfully connected to '.$mysqli->host_info); | |
| 18 | 18 | |
| 19 | -if (remove ($_POST['value'],$type,$table)) | |
| 19 | +if (remove($_POST['value'], $type, $table)) | |
| 20 | 20 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; | 
| 21 | 21 | else | 
| 22 | 22 | print 'Delete operation ERROR on '.$typedesc.' <'.$_POST['value'].'>; check log.'; | 
| @@ -16,10 +16,11 @@ | ||
| 16 | 16 | } | 
| 17 | 17 | syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); | 
| 18 | 18 | |
| 19 | -if (remove ($_POST['value'],$type,$table)) | |
| 19 | +if (remove ($_POST['value'],$type,$table)) { | |
| 20 | 20 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; | 
| 21 | -else | |
| 21 | +} else { | |
| 22 | 22 | print 'Delete operation ERROR on '.$typedesc.' <'.$_POST['value'].'>; check log.'; | 
| 23 | +} | |
| 23 | 24 | $mysqli->close(); | 
| 24 | 25 | closelog(); | 
| 25 | 26 | ?> | 
| @@ -12,12 +12,12 @@ | ||
| 12 | 12 | $user = username(); | 
| 13 | 13 | |
| 14 | 14 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| 15 | -        if ($mysqli->connect_error) { | |
| 16 | -            syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 17 | - . $mysqli->connect_error); | |
| 18 | -            die($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 19 | - . $mysqli->connect_error); | |
| 20 | - } | |
| 15 | +		if ($mysqli->connect_error) { | |
| 16 | +			syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 17 | + . $mysqli->connect_error); | |
| 18 | +			die($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 19 | + . $mysqli->connect_error); | |
| 20 | + } | |
| 21 | 21 | syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); | 
| 22 | 22 | |
| 23 | 23 | if (addtolist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) | 
| @@ -1,26 +1,26 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |  require_once('config.php'); | 
| 3 | 3 |  require_once('function.php'); | 
| 4 | -$typedesc=$_POST['type']; | |
| 4 | +$typedesc = $_POST['type']; | |
| 5 | 5 | $type = $tables["$typedesc"]['field']; | 
| 6 | 6 | $table = $tables["$typedesc"]['name']; | 
| 7 | 7 | |
| 8 | 8 | openlog($tag, LOG_PID, $fac); | 
| 9 | 9 |  if (empty($_POST['reason'])) die ("<p>Please, specify a reason!</p>"); | 
| 10 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) | |
| 11 | -	exit('<p>ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); | |
| 10 | +if (preg_match('/[^\x20-\x7f]/', $_POST['reason'])) | |
| 11 | +	exit('<p>ERROR: <'.htmlentities($_POST['reason'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); | |
| 12 | 12 | $user = username(); | 
| 13 | 13 | |
| 14 | 14 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| 15 | 15 |          if ($mysqli->connect_error) { | 
| 16 | -            syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 16 | +            syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' | |
| 17 | 17 | . $mysqli->connect_error); | 
| 18 | -            die($user.': Connect Error (' . $mysqli->connect_errno . ') ' | |
| 18 | +            die($user.': Connect Error ('.$mysqli->connect_errno.') ' | |
| 19 | 19 | . $mysqli->connect_error); | 
| 20 | 20 | } | 
| 21 | -syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); | |
| 21 | +syslog(LOG_INFO, $user.': Successfully connected to '.$mysqli->host_info); | |
| 22 | 22 | |
| 23 | -if (addtolist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) | |
| 23 | +if (addtolist($mysqli, username(), $_POST['value'], $type, $table, $_POST['unit'], $_POST['quantity'], $_POST['reason'])) | |
| 24 | 24 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> first time listed for '.$_POST['quantity'].$_POST['unit'].'.'; | 
| 25 | 25 | else | 
| 26 | 26 | print 'List operation ERROR; check log.'; | 
| @@ -6,9 +6,12 @@ discard block | ||
| 6 | 6 | $table = $tables["$typedesc"]['name']; | 
| 7 | 7 | |
| 8 | 8 | openlog($tag, LOG_PID, $fac); | 
| 9 | -if (empty($_POST['reason'])) die ("<p>Please, specify a reason!</p>"); | |
| 10 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) | |
| 9 | +if (empty($_POST['reason'])) { | |
| 10 | +	die ("<p>Please, specify a reason!</p>"); | |
| 11 | +} | |
| 12 | +if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) { | |
| 11 | 13 |  	exit('<p>ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); | 
| 14 | +} | |
| 12 | 15 | $user = username(); | 
| 13 | 16 | |
| 14 | 17 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); | 
| @@ -20,10 +23,11 @@ discard block | ||
| 20 | 23 | } | 
| 21 | 24 | syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); | 
| 22 | 25 | |
| 23 | -if (addtolist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) | |
| 26 | +if (addtolist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) { | |
| 24 | 27 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> first time listed for '.$_POST['quantity'].$_POST['unit'].'.'; | 
| 25 | -else | |
| 28 | +} else { | |
| 26 | 29 | print 'List operation ERROR; check log.'; | 
| 30 | +} | |
| 27 | 31 | $mysqli->close(); | 
| 28 | 32 | closelog(); | 
| 29 | 33 | ?> |