phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/base/cron.php

    r295 r485  
    1 <?php  
     1<?php 
    22        $loginNoKick=true; 
    33        $loginNoDisplayError=true; 
    4          
     4 
    55        include("../../include/session.php"); 
    6                  
     6 
    77        $now = gmdate('Y-m-d H:i', strtotime('now')); 
    8          
    9         $querystatment="SELECT id,name,crontab,job,startdatetime,enddatetime FROM scheduler WHERE inactive=0 AND startdatetime<NOW() AND (enddatetime>NOW() OR enddatetime IS NULL);"; 
     8 
     9        $querystatment = " 
     10                SELECT 
     11                        id, 
     12                        name, 
     13                        crontab, 
     14                        job, 
     15                        startdatetime, 
     16                        enddatetime 
     17                FROM 
     18                        scheduler 
     19                WHERE 
     20                        inactive = 0 
     21                        AND startdatetime < NOW() 
     22                        AND (enddatetime > NOW() OR enddatetime IS NULL)"; 
     23 
    1024        $queryresult=$db->query($querystatment); 
    11          
     25 
    1226        while($schedule_record=$db->fetchArray($queryresult)){ 
     27 
    1328                $datetimearray=explode(" ",$schedule_record["startdatetime"]); 
    1429                $schedule_record["startdate"]=stringToDate($datetimearray[0],"SQL"); 
     
    1631 
    1732                if($schedule_record["enddatetime"]){ 
     33 
    1834                        $datetimearray=explode(" ",$schedule_record["enddatetime"]); 
    1935                        $schedule_record["enddate"]=stringToDate($datetimearray[0],"SQL"); 
    2036                        $schedule_record["endtime"]=stringToTime($datetimearray[1],"24 Hour"); 
    21                 } 
    22  
    23                 $validTimes=getTimes($schedule_record); 
     37 
     38                }//endif enddateiem 
     39 
     40                $validTimes = getTimes($schedule_record); 
     41 
    2442                if(is_array($validTimes) && in_array($now, $validTimes)){ 
     43 
    2544                        $success = @ include($schedule_record["job"]); 
     45 
    2646                        if($success){ 
     47 
    2748                                $updatestatement="UPDATE scheduler SET lastrun=NOW() WHERE id=".$schedule_record["id"]; 
    2849                                $db->query($updatestatement); 
    29                                 $log = new phpbmsLog("Secheduled Job ".$schedule_record["name"]." (".$schedule_record["id"].") completed","SCHEDULER",-2); 
    30                         } else { 
    31                                 $log = new phpbmsLog("Secheduled Job ".$schedule_record["name"]." (".$schedule_record["id"].") returned errors","SCHEDULER",-2); 
    32                         } 
    33                                  
    34                 }                
    35         } 
    36          
     50                                $log = new phpbmsLog("Scheduled Job ".$schedule_record["name"]." (".$schedule_record["id"].") completed","SCHEDULER",-2); 
     51 
     52                        } else { 
     53 
     54                                $log = new phpbmsLog("Scheduled Job ".$schedule_record["name"]." (".$schedule_record["id"].") returned errors","SCHEDULER",-2); 
     55 
     56                        }//endif success 
     57 
     58                }//endif is_array(); 
     59 
     60        }//endwhile 
     61 
     62 
    3763        function getTimes($recordarray){ 
    38          
     64 
    3965                $dayInt = array('*',1,2,3,4,5,6,7); 
    4066                $dayLabel = array('*',"Monday","Tuesday","Wedensday","Thursday","Friday","Saturday","Sunday"); 
     
    4369                $metricsVar = array("*", "/", "-", ","); 
    4470                $metricsVal = array(' every ','',' thru ',' and '); 
    45                          
     71 
    4672                $dateTimes = array(); 
    4773                $ints   = explode('::', str_replace(' ','',$recordarray["crontab"])); 
     
    5985                        $theDay = str_replace('*/','',$days); 
    6086                        $dayName[] = str_replace($dayInt, $dayLabel, $theDay); 
    61                 } elseif($days != '*') {  
     87                } elseif($days != '*') { 
    6288                        if(strstr($days, ',')) { 
    6389                                $exDays = explode(',',$days); 
    6490                                foreach($exDays as $k1 => $dayGroup) { 
    6591                                        if(strstr($dayGroup,'-')) { 
    66                                                 $exDayGroup = explode('-', $dayGroup);  
     92                                                $exDayGroup = explode('-', $dayGroup); 
    6793                                                for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) { 
    6894                                                        $dayName[] = str_replace($dayInt, $dayLabel, $i); 
     
    7399                                } 
    74100                        } elseif(strstr($days, '-')) { 
    75                                 $exDayGroup = explode('-', $days);  
     101                                $exDayGroup = explode('-', $days); 
    76102                                for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) { 
    77103                                        $dayName[] = str_replace($dayInt, $dayLabel, $i); 
     
    80106                                $dayName[] = str_replace($dayInt, $dayLabel, $days); 
    81107                        } 
    82                          
     108 
    83109                        // check the day to be in scope: 
    84110                        if(!in_array($today['weekday'], $dayName)) { 
     
    88114                        return false; 
    89115                } 
    90                  
    91                  
     116 
     117 
    92118                // derive months part 
    93119                if($mons == '*') { 
     
    104130                        // this month is not in one of the multiplier months 
    105131                        if(!in_array($today['mon'],$compMons)) { 
    106                                 return false;    
     132                                return false; 
    107133                        } 
    108134                } elseif($mons != '*') { 
     
    127153                                $monName[] = $mons; 
    128154                        } 
    129                          
     155 
    130156                        // check that particular months are in scope 
    131157                        if(!in_array($today['mon'], $monName)) { 
     
    133159                        } 
    134160                } 
    135                  
     161 
    136162 
    137163                // derive dates part 
     
    147173                                $i += $mult; 
    148174                        } 
    149                          
     175 
    150176                        if(!in_array($today['mday'], $dateName)) { 
    151                                 return false;    
     177                                return false; 
    152178                        } 
    153179                } elseif($dates != '*') { 
     
    158184                                                $exDateGroup = explode('-', $dateGroup); 
    159185                                                for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) { 
    160                                                         $dateName[] = $i;  
     186                                                        $dateName[] = $i; 
    161187                                                } 
    162188                                        } else { 
     
    167193                                $exDateGroup = explode('-', $dates); 
    168194                                for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) { 
    169                                         $dateName[] = $i;  
     195                                        $dateName[] = $i; 
    170196                                } 
    171197                        } else { 
    172198                                $dateName[] = $dates; 
    173199                        } 
    174                          
     200 
    175201                        // check that dates are in scope 
    176202                        if(!in_array($today['mday'], $dateName)) { 
     
    178204                        } 
    179205                } 
    180                  
     206 
    181207                // derive hours part 
    182208                $currentHour = date('G', strtotime('00:00')); 
     
    213239                        } 
    214240                } 
    215                  
     241 
    216242                // derive minutes 
    217243                $currentMin = date('i', strtotime($recordarray["starttime"])); 
     
    239265                                $i += $mult; 
    240266                        } 
    241                          
     267 
    242268                } elseif($mins != '*') { 
    243269                        if(strstr($mins, ',')) { 
     
    261287                                $minName[] = $mins; 
    262288                        } 
    263                 }  
     289                } 
    264290 
    265291                // prep some boundaries - these are not in GMT b/c gmt is a 24hour period, possibly bridging 2 local days 
     
    281307                        $hourSeen++; 
    282308                        foreach($minName as $kMin=>$min) { 
    283                                 if($hr < $currentHour || $hourSeen == 25)  
     309                                if($hr < $currentHour || $hourSeen == 25) 
    284310                                        $theDate = date('Y-m-d', strtotime('+1 day')); 
    285311                                else 
     
    287313 
    288314                                $tsGmt = strtotime($theDate.' '.str_pad($hr,2,'0',STR_PAD_LEFT).":".str_pad($min,2,'0',STR_PAD_LEFT).":00"); // this is LOCAL 
    289                                 $validJobTime[] = gmdate('Y-m-d H:i', $tsGmt);                           
     315                                $validJobTime[] = gmdate('Y-m-d H:i', $tsGmt); 
    290316                        } 
    291317                } 
    292318                sort($validJobTime); 
    293319 
    294                 return $validJobTime;            
     320                return $validJobTime; 
    295321        }//end function 
    296322?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.