combined all cronscripts into one master-cronfile (user only needs to add one file to the crontab);

This commit is contained in:
Michael Kaufmann (d00p)
2010-01-25 12:50:38 +00:00
parent d1d872942a
commit 9fdece761e
26 changed files with 187 additions and 291 deletions

View File

@@ -136,27 +136,6 @@ fwrite($debugHandler, 'Table definitions included' . "\n");
fwrite($debugHandler, 'Database Class has been loaded' . "\n");
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']);
// If one cronscript needs root, it should say $needrootdb = true before the include
if(isset($needrootdb)
&& $needrootdb === true)
{
$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], '');
if($db_root->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler);
unlink($lockfile);
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
unset($db_root->password);
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
}
if($db->link_id == 0)
{
/**
@@ -198,45 +177,6 @@ fwrite($debugHandler, 'Froxlor Version and Database Version are correct' . "\n")
$cronscriptDebug = ($settings['system']['debug_cron'] == '1') ? true : false;
$cronbasedir = makeCorrectDir($pathtophpfiles . '/scripts/');
$crondir = new DirectoryIterator($cronbasedir);
$cronfilename = basename($_SERVER['PHP_SELF'], '.php');
$cronscriptFullName = makeCorrectFile($cronbasedir . basename($_SERVER['PHP_SELF']));
$inc_crons = array();
foreach($crondir as $file)
{
if(!$file->isDot()
&& !$file->isDir()
&& preg_match("/^" . $cronfilename . "\.inc\.(.*)\.php$/D", $file->getFilename()))
{
if(fileowner($cronscriptFullName) == $file->getOwner()
&& filegroup($cronscriptFullName) == $file->getGroup()
&& $file->isReadable())
{
$inc_crons[] = $file->getPathname();
}
else
{
fwrite($debugHandler, 'WARNING! uid and/or gid of "' . $cronscriptFullName . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!' . "\n");
fclose($debugHandler);
die('WARNING! uid and/or gid of "' . $cronscriptFullName . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!');
}
}
}
if(isset($inc_crons[0]))
{
natsort($inc_crons);
foreach($inc_crons as $cfile)
{
fwrite($debugHandler, 'Including ...' . $cfile . "\n");
include_once ($cfile);
}
}
unset($file, $crondir, $cronname, $cronscriptFullName, $cronfilename, $cronbasedir);
fwrite($debugHandler, 'Functions have been included' . "\n");
/**
* Create a new idna converter
*/

View File

@@ -0,0 +1,44 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
* @version $Id: $
*/
function includeCronjobs($path, $debugHandler)
{
$cronbasedir = makeCorrectDir($path);
$crondir = new DirectoryIterator($cronbasedir);
foreach($crondir as $file)
{
if($file->isDot()) continue;
if($file->isFile())
{
if(fileowner(__FILE__) == $file->getOwner()
&& filegroup(__FILE__) == $file->getGroup()
&& $file->isReadable())
{
fwrite($debugHandler, 'Including ...' . $file->getPathname() . "\n");
include_once($file->getPathname());
}
else
{
fwrite($debugHandler, 'WARNING! uid and/or gid of "' . __FILE__ . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!' . "\n");
fclose($debugHandler);
die('WARNING! uid and/or gid of "' . __FILE__ . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!');
}
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
* @version $Id: $
*/
/*
* Function openRootDB
*
* creates a mysql-connection as root-user
* and stores it in the global variable $db_root
*
* @param int debugHandler (file-object)
* @param int lockfile (file-object)
*
* @return null
*/
function openRootDB($debugHandler, $lockfile)
{
global $db_root;
// If one cronscript needs root, it should say $needrootdb = true before the include
if(isset($needrootdb)
&& $needrootdb === true)
{
$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], '');
if($db_root->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler);
unlink($lockfile);
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
unset($db_root->password);
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
}
}
function closeRootDB()
{
global $db_root;
if(isset($db_root)) unset($db_root);
}