[PC-BSD Commits] r1886 - in websites/pbidir.com/bibivu: bin etc etc/periodic/daily etc/periodic/hourly sbin
svn at pcbsd.org
svn at pcbsd.org
Fri May 9 22:54:08 PDT 2008
Author: fabry
Date: 2008-05-09 22:54:08 -0700 (Fri, 09 May 2008)
New Revision: 1886
Added:
websites/pbidir.com/bibivu/bin/bibivu_cron.php
websites/pbidir.com/bibivu/etc/periodic/daily/pbis_watcher.php
Modified:
websites/pbidir.com/bibivu/bin/start.php
websites/pbidir.com/bibivu/etc/cron.conf.php
websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php
websites/pbidir.com/bibivu/sbin/cron.php
Log:
created new script that will send daily emails to the root users about PBis were the URL is invalid.
Added: websites/pbidir.com/bibivu/bin/bibivu_cron.php
Modified: websites/pbidir.com/bibivu/bin/start.php
===================================================================
--- websites/pbidir.com/bibivu/bin/start.php 2008-05-10 02:00:01 UTC (rev 1885)
+++ websites/pbidir.com/bibivu/bin/start.php 2008-05-10 05:54:08 UTC (rev 1886)
@@ -19,6 +19,7 @@
$this->load_library($task);
return true;
break;
+/*
case 'mirrors':
set_time_limit(0);
$mirrors = load_library('mirror');
@@ -37,6 +38,7 @@
return true;
}
break;
+*/
case 'lang':
load_library('lang')->set_lang($this->uri->get_num(3));
if($this->permissions->is_logged()){
Modified: websites/pbidir.com/bibivu/etc/cron.conf.php
===================================================================
--- websites/pbidir.com/bibivu/etc/cron.conf.php 2008-05-10 02:00:01 UTC (rev 1885)
+++ websites/pbidir.com/bibivu/etc/cron.conf.php 2008-05-10 05:54:08 UTC (rev 1886)
@@ -1,42 +1,42 @@
-<?php
-/*********************************
- * cron jobs
- *
- * use the same format as unix files
- *
- * * * * * * command to be executed
- * - - - - -
- * | | | | |
- * | | | | +----- day of week (0 - 6) (Sunday=0)
- * | | | +------- month (1 - 12)
- * | | +--------- day of month (1 - 31)
- * | +----------- hour (0 - 23)
- * +------------- min (0 - 59)
- *
- *
- * this will execute only the programs that are located into the /etc/periodic/other folder
- * the hourly, daily, weekly, monthly scripts are automatically executed is located into the folder
- * I.E.: to execute "script.php" at the 5th minute of the new year day (January 1st):
- * 5 0 1 1 * script.php
- *
- * those are samples used to autoscheduled the hourly, daily, weekly, and monthly scripts
-
-$cron['jobs'][] = '0 * * * * hourly';
-$cron['jobs'][] = '1 0 * * * daily';
-$cron['jobs'][] = '2 1 * * 0 weekly';
-$cron['jobs'][] = '3 2 1 * * monthly';
-$cron['jobs'][] = '4 3 1 1 * yearly';
-
- ********************************/
-
-//$cron['php'] = '/usr/local/bibivu/php/bin/php -q '; //php path, comment out to use "php"
-$cron['php'] = '/usr/local/bin/php -q '; //php path, comment out to use "php"
-
-$cron['hourly'] = '0 * * * *';
-$cron['daily'] = '1 0 * * *';
-$cron['weekly'] = '2 1 * * 0';
-$cron['monthly'] = '3 2 1 * *';
-$cron['yearly'] = '4 3 1 1 *';
-$cron['jobs'] = array();
-
-?>
\ No newline at end of file
+<?php
+/*********************************
+ * cron jobs
+ *
+ * use the same format as unix files
+ *
+ * * * * * * command to be executed
+ * - - - - -
+ * | | | | |
+ * | | | | +----- day of week (0 - 6) (Sunday=0)
+ * | | | +------- month (1 - 12)
+ * | | +--------- day of month (1 - 31)
+ * | +----------- hour (0 - 23)
+ * +------------- min (0 - 59)
+ *
+ *
+ * this will execute only the programs that are located into the /etc/periodic/other folder
+ * the hourly, daily, weekly, monthly scripts are automatically executed is located into the folder
+ * I.E.: to execute "script.php" at the 5th minute of the new year day (January 1st):
+ * 5 0 1 1 * script.php
+ *
+ * those are samples used to autoscheduled the hourly, daily, weekly, and monthly scripts
+
+$cron['jobs'][] = '0 * * * * hourly';
+$cron['jobs'][] = '1 0 * * * daily';
+$cron['jobs'][] = '2 1 * * 0 weekly';
+$cron['jobs'][] = '3 2 1 * * monthly';
+$cron['jobs'][] = '4 3 1 1 * yearly';
+
+ ********************************/
+
+//$cron['php'] = '/usr/local/bibivu/php/bin/php -q '; //php path, comment out to use "php"
+$cron['php'] = '/usr/local/bin/php -q '; //php path, comment out to use "php"
+
+$cron['hourly'] = '0 * * * *';
+$cron['daily'] = '1 0 * * *';
+$cron['weekly'] = '2 1 * * 0';
+$cron['monthly'] = '3 2 1 * *';
+$cron['yearly'] = '4 3 1 1 *';
+$cron['jobs'] = array();
+
+?>
Added: websites/pbidir.com/bibivu/etc/periodic/daily/pbis_watcher.php
Modified: websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php
===================================================================
--- websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php 2008-05-10 02:00:01 UTC (rev 1885)
+++ websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php 2008-05-10 05:54:08 UTC (rev 1886)
@@ -4,6 +4,7 @@
header('location: /');
exit(0);
}
+$_GET['bm'] = 'bibivu_cron';
$_GET['bt'] = 'mirrors';
$_GET['update'] = true;
require_once dirname(__FILE__).'/../../index_file.conf.php';
Modified: websites/pbidir.com/bibivu/sbin/cron.php
===================================================================
--- websites/pbidir.com/bibivu/sbin/cron.php 2008-05-10 02:00:01 UTC (rev 1885)
+++ websites/pbidir.com/bibivu/sbin/cron.php 2008-05-10 05:54:08 UTC (rev 1886)
@@ -1,154 +1,154 @@
-<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
-// ------------------------------------------------------------------------
-/************************************
- * this class is its own beast
- * it allows to execute scripts
- * that are located into the
- * ETCPATH/priodic folder
- *
- * some of this code has been borrowed from:
- * ------------------
- * PHPCron v1.00
- * written by Katy Coe - http://www.djkaty.com
- * (c) Intelligent Streaming 2006
- * ------------------
- *
- * This needs to be croned or scheduled to run every minute
- * It is not build to run 24hours a day, as I want to save memory and CPU as much as possible
- *
- ***********************************/
-class cron{
- public function __construct(){
- if (!isset($_SERVER['argc']) || $_SERVER['argc'] == 0 || $_SERVER['argv'][0] != $_SERVER['PHP_SELF']){
- //called from the web.. BAD BAD BAD BOYS
- header('location: /');
- exit(0);
- }
-
- $config = load_class('config')->load_config('cron');
- $jobs = $config->get('cron_jobs',array());
- //I need to add the folders content depending on the name of the folder
- //hourly, daily, weekly, monthly, and yearly
- //then I need the read the conf file, and parse the parameters
- //if they match the current time, I need to go to "exec" for each job
- $hourly = $this->load_folder('hourly'); array_walk($hourly, create_function('&$v,$k', '$v = "'.$config->get('cron_hourly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
- $daily = $this->load_folder('daily'); array_walk($daily, create_function('&$v,$k', '$v = "'.$config->get('cron_daily').' '.$config->get('cron_php','php').' \"".$v."\"";'));
- $weekly = $this->load_folder('weekly'); array_walk($weekly, create_function('&$v,$k', '$v = "'.$config->get('cron_weekly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
- $monthly = $this->load_folder('monthly'); array_walk($monthly, create_function('&$v,$k', '$v = "'.$config->get('cron_monthly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
- $yearly = $this->load_folder('yearly'); array_walk($yearly, create_function('&$v,$k', '$v = "'.$config->get('cron_yearly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
-
- $jobs = array_merge($jobs, $hourly, $daily, $weekly, $monthly, $yearly);
-
- foreach($jobs as $jobText){
- $jobParams = split(' ', preg_replace('#[\s|\t]{1,}#', ' ', $jobText), 6);
- // If insufficient parameters supplied, go to the next silently
- if (count($jobParams) < 6)
- continue;
-
- // Parse time parameters
- $job['minutes'] = $this->parse_param($jobParams[0], 0, 59);
- $job['hours'] = $this->parse_param($jobParams[1], 0, 23);
- $job['dates'] = $this->parse_param($jobParams[2], 1, 31);
- $job['months'] = $this->parse_param($jobParams[3], 1, 12);
- $job['weekdays'] = $this->parse_param($jobParams[4], 0, 7);
- $job['command'] = implode(' ', array_slice($jobParams, 5));
-
- // 0 and 7 are both counted as Sunday
- if ($job['weekdays'] == 7)
- $job['weekdays'] = 0;
-
- $now = @getdate(time());
-
- if (array_search($now['minutes'], $job['minutes']) !== false &&
- array_search($now['hours'], $job['hours']) !== false &&
- array_search($now['mon'], $job['months']) !== false &&
- (array_search($now['mday'], $job['dates']) !== false || array_search($now['wday'], $job['weekdays']) !== false)
- ){
- // Shell job command
- $this->run($job['command']);
- }
- }
- }
-
- private function run($command){
- if (substr(PHP_OS, 0, 3) == 'WIN'){
- $proc = popen('start /b "' . $command, 'r');
- }else{
- $proc = popen($command . ' &', 'r');
- }
- pclose($proc); //I don't care about the output
- }
-
- function startFork($path, $file, $args){
- if (substr(PHP_OS, 0, 3) == 'WIN'){
- $proc = popen('start /b php "' . $path . '\\' . $file . '" ' . $args, 'r');
- }else{
- $proc = popen('php ' . $path . '/' . $file . ' ' . $args . ' &', 'r');
- }
- return $proc;
- }
-
- private function parse_param($text, $min, $max){
- $result = array();
-
- if ($text == '*') {
- // * - all possible values
- for ($i = $min; $i <= $max; $i++) $result[] = $i;
- }elseif (substr($text, 0, 2) == '*/'){
- // "*/n" syntax - starts at $min and recurs every n
- for ($i = $min; $i <= $max; $i += substr($text, 2)) $result[] = $i;
- }else{
- // Split by commas
- $timeItems = split(',', $text);
-
- foreach ($timeItems as $timeItem){
- // X-Y syntax - starts at X and increments by 1 to Y inclusive,
- // wrapping around from $max to $min if necessary
- if (strpos($timeItem, '-') !== false){
- list ($first, $last) = split('-', $timeItem, 2);
-
- // Bound specified range within min/max parameters
- $first = max(min($first, $max), $min);
- $last = max(min($last, $max), $min);
-
- if ($first <= $last){
- // Non-wrapping range
- for ($i = $first; $i <= $last; $i++) $result[] = $i;
- }else{
- // Wrapping range
- for ($i = $first; $i <= $max; $i++) $result[] = $i;
- for ($i = $min; $i <= $last; $i++) $result[] = $i;
- }
- } else {
- // Single number
- $result[] = $timeItem;
- }
- }
- }
- return $result;
- }
- private function load_folder($folder){
- $output = array();
- $allow_folders = array('hourly','daily','weekly','monthly','yearly');
- if(in_array($folder,$allow_folders)){
- $dir = ETCPATH.'periodic/'.$folder;
- if(is_dir($dir)){
- $handle = opendir($dir);
- while(false !== ($readdir = readdir($handle))){
- if($readdir != '.' && $readdir != '..'){
- $path = $dir.'/'.$readdir;
- if (is_file($path)) {
- $output[] = $path;
- } elseif (is_dir($path)) {
- //is a folder, nothing to do in it... for now
- //$output = array_merge($output, build_tree($path));
- }
- }
- }
- closedir($handle);
- }
- }
- return $output;
- }
-}
-?>
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+// ------------------------------------------------------------------------
+/************************************
+ * this class is its own beast
+ * it allows to execute scripts
+ * that are located into the
+ * ETCPATH/periodic folder
+ *
+ * some of this code has been borrowed from:
+ * ------------------
+ * PHPCron v1.00
+ * written by Katy Coe - http://www.djkaty.com
+ * (c) Intelligent Streaming 2006
+ * ------------------
+ *
+ * This needs to be croned or scheduled to run every minute
+ * It is not build to run 24hours a day, as I want to save memory and CPU as much as possible
+ *
+ ***********************************/
+class cron{
+ public function __construct(){
+ if (!isset($_SERVER['argc']) || $_SERVER['argc'] == 0 || $_SERVER['argv'][0] != $_SERVER['PHP_SELF']){
+ //called from the web.. BAD BAD BAD BOYS
+ header('location: /');
+ exit(0);
+ }
+
+ $config = load_class('config')->load_config('cron');
+ $jobs = $config->get('cron_jobs',array());
+ //I need to add the folders content depending on the name of the folder
+ //hourly, daily, weekly, monthly, and yearly
+ //then I need the read the conf file, and parse the parameters
+ //if they match the current time, I need to go to "exec" for each job
+ $hourly = $this->load_folder('hourly'); array_walk($hourly, create_function('&$v,$k', '$v = "'.$config->get('cron_hourly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
+ $daily = $this->load_folder('daily'); array_walk($daily, create_function('&$v,$k', '$v = "'.$config->get('cron_daily').' '.$config->get('cron_php','php').' \"".$v."\"";'));
+ $weekly = $this->load_folder('weekly'); array_walk($weekly, create_function('&$v,$k', '$v = "'.$config->get('cron_weekly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
+ $monthly = $this->load_folder('monthly'); array_walk($monthly, create_function('&$v,$k', '$v = "'.$config->get('cron_monthly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
+ $yearly = $this->load_folder('yearly'); array_walk($yearly, create_function('&$v,$k', '$v = "'.$config->get('cron_yearly').' '.$config->get('cron_php','php').' \"".$v."\"";'));
+
+ $jobs = array_merge($jobs, $hourly, $daily, $weekly, $monthly, $yearly);
+
+ foreach($jobs as $jobText){
+ $jobParams = split(' ', preg_replace('#[\s|\t]{1,}#', ' ', $jobText), 6);
+ // If insufficient parameters supplied, go to the next silently
+ if (count($jobParams) < 6)
+ continue;
+
+ // Parse time parameters
+ $job['minutes'] = $this->parse_param($jobParams[0], 0, 59);
+ $job['hours'] = $this->parse_param($jobParams[1], 0, 23);
+ $job['dates'] = $this->parse_param($jobParams[2], 1, 31);
+ $job['months'] = $this->parse_param($jobParams[3], 1, 12);
+ $job['weekdays'] = $this->parse_param($jobParams[4], 0, 7);
+ $job['command'] = implode(' ', array_slice($jobParams, 5));
+
+ // 0 and 7 are both counted as Sunday
+ if ($job['weekdays'] == 7)
+ $job['weekdays'] = 0;
+
+ $now = @getdate(time());
+
+ if (array_search($now['minutes'], $job['minutes']) !== false &&
+ array_search($now['hours'], $job['hours']) !== false &&
+ array_search($now['mon'], $job['months']) !== false &&
+ (array_search($now['mday'], $job['dates']) !== false || array_search($now['wday'], $job['weekdays']) !== false)
+ ){
+ // Shell job command
+ $this->run($job['command']);
+ }
+ }
+ }
+
+ private function run($command){
+ if (substr(PHP_OS, 0, 3) == 'WIN'){
+ $proc = popen('start /b "' . $command, 'r');
+ }else{
+ $proc = popen($command . ' &', 'r');
+ }
+ pclose($proc); //I don't care about the output
+ }
+
+ function startFork($path, $file, $args){
+ if (substr(PHP_OS, 0, 3) == 'WIN'){
+ $proc = popen('start /b php "' . $path . '\\' . $file . '" ' . $args, 'r');
+ }else{
+ $proc = popen('php ' . $path . '/' . $file . ' ' . $args . ' &', 'r');
+ }
+ return $proc;
+ }
+
+ private function parse_param($text, $min, $max){
+ $result = array();
+
+ if ($text == '*') {
+ // * - all possible values
+ for ($i = $min; $i <= $max; $i++) $result[] = $i;
+ }elseif (substr($text, 0, 2) == '*/'){
+ // "*/n" syntax - starts at $min and recurs every n
+ for ($i = $min; $i <= $max; $i += substr($text, 2)) $result[] = $i;
+ }else{
+ // Split by commas
+ $timeItems = split(',', $text);
+
+ foreach ($timeItems as $timeItem){
+ // X-Y syntax - starts at X and increments by 1 to Y inclusive,
+ // wrapping around from $max to $min if necessary
+ if (strpos($timeItem, '-') !== false){
+ list ($first, $last) = split('-', $timeItem, 2);
+
+ // Bound specified range within min/max parameters
+ $first = max(min($first, $max), $min);
+ $last = max(min($last, $max), $min);
+
+ if ($first <= $last){
+ // Non-wrapping range
+ for ($i = $first; $i <= $last; $i++) $result[] = $i;
+ }else{
+ // Wrapping range
+ for ($i = $first; $i <= $max; $i++) $result[] = $i;
+ for ($i = $min; $i <= $last; $i++) $result[] = $i;
+ }
+ } else {
+ // Single number
+ $result[] = $timeItem;
+ }
+ }
+ }
+ return $result;
+ }
+ private function load_folder($folder){
+ $output = array();
+ $allow_folders = array('hourly','daily','weekly','monthly','yearly');
+ if(in_array($folder,$allow_folders)){
+ $dir = ETCPATH.'periodic/'.$folder;
+ if(is_dir($dir)){
+ $handle = opendir($dir);
+ while(false !== ($readdir = readdir($handle))){
+ if($readdir != '.' && $readdir != '..'){
+ $path = $dir.'/'.$readdir;
+ if (is_file($path)) {
+ $output[] = $path;
+ } elseif (is_dir($path)) {
+ //is a folder, nothing to do in it... for now
+ //$output = array_merge($output, build_tree($path));
+ }
+ }
+ }
+ closedir($handle);
+ }
+ }
+ return $output;
+ }
+}
+?>
More information about the Commits
mailing list