Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f457e1044e
Fetching contributors…

Cannot retrieve contributors at this time

executable file 156 lines (137 sloc) 5.101 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
<?php
/**
* filename: $Source$
* begin: Friday, Aug 06, 2004
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Florian Lippert <flo@redenswert.de>
* @copyright (C) 2003-2004 Florian Lippert
* @package System
* @version $Id$
*/

if(@php_sapi_name() != 'cli' && @php_sapi_name() != 'cgi' && @php_sapi_name() != 'cgi-fcgi')
{
die('This script will only work in the shell.');
}

$cronscriptDebug = false;
$lockdir = '/var/run/';
$lockFilename = 'syscp_cron.lock-';
$lockfName = $lockFilename.time();
$lockfile = $lockdir.$lockfName;

// guess the syscp installation path
// normally you should not need to modify this script anymore, if your
// syscp installation isn't in /var/www/syscp
if( substr($_SERVER['PHP_SELF'], 0, 1) != '/' )
{
$pathtophpfiles = $_SERVER['PWD'];
}
$pathtophpfiles .= '/'.$_SERVER['PHP_SELF'];
$pathtophpfiles = str_replace('/./', '/', $pathtophpfiles );
$pathtophpfiles = str_replace('//','/', $pathtophpfiles );
$pathtophpfiles = dirname(dirname( $pathtophpfiles ));

// should the syscp installation guessing not work correctly,
// uncomment the following line, and put your path in there!
//$pathtophpfiles = '/var/www/syscp';

$filename = 'cronscript.php';

// create and open the lockfile!
$debugHandler = fopen( $lockfile, 'w' );
fwrite( $debugHandler, 'Setting Lockfile to '.$lockfile );
fwrite( $debugHandler, 'Setting SysCP installation path to '.$pathtophpfiles);

// open the lockfile directory and scan for existing lockfiles
$lockDirHandle = opendir($lockdir);
while ($fName = readdir($lockDirHandle))
{
if ( $lockFilename == substr($fName, 0, strlen($lockFilename)) && $lockfName != $fName )
{
// close the current lockfile
fclose( $debugHandler );
// ... and delete it
unlink($lockfile);
die('There is already a lockfile. Exiting...' . "\n" .
'Take a look into the contents of ' . $lockdir . $lockFilename .
'* for more information!' );
}
}

/**
* Includes the Usersettings eg. MySQL-Username/Passwort etc.
*/
require("$pathtophpfiles/lib/userdata.inc.php");
fwrite( $debugHandler, 'Userdatas included');

/**
* Includes the MySQL-Tabledefinitions etc.
*/
require("$pathtophpfiles/lib/tables.inc.php");
fwrite( $debugHandler, 'Table definitions included' );

/**
* Includes the MySQL-Connection-Class
*/
require("$pathtophpfiles/lib/class_mysqldb.php");
fwrite( $debugHandler, 'Database Class has been loaded');
$db = new db($sql['host'],$sql['user'],$sql['password'],$sql['db']);
$db_root = new db($sql['host'],$sql['root_user'],$sql['root_password'],'');
if($db->link_id == 0 || $db_root->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established (either normal or root)
*/
fclose( $debugHandler );
unlink($lockfile);
die('Cant connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
fwrite( $debugHandler, 'Database Connection established' );

unset( $sql );
unset( $db->password );
unset( $db_root->password );

$result=$db->query("SELECT `settingid`, `settinggroup`, `varname`, `value` FROM `".TABLE_PANEL_SETTINGS."`");
while($row=$db->fetch_array($result))
{
$settings["$row[settinggroup]"]["$row[varname]"]=$row['value'];
}
unset($row);
unset($result);
fwrite( $debugHandler, 'SysCP Settings has been loaded from the datbase');


if(!isset($settings['panel']['version']) || $settings['panel']['version'] != $version)
{
/**
* Do not proceed further if the Database version is not the same as the script version
*/
fclose( $debugHandler );
unlink($lockfile);
die('Version of File doesnt match Version of Database. Exiting...');
}
fwrite( $debugHandler, 'SysCP Version and Database Version are correct');

/**
* Includes the Functions
*/
require("$pathtophpfiles/lib/functions.php");
fwrite( $debugHandler, 'Functions has been included' );

/**
* Backend Wrapper
*/
$query =
'SELECT * ' .
'FROM `'.TABLE_PANEL_CRONSCRIPT.'` ';
$cronFileIncludeResult = $db->query($query);
while ($cronFileIncludeRow = $db->fetch_array($cronFileIncludeResult))
{
fwrite( $debugHandler, 'Processing ...'.$pathtophpfiles.'/scripts/'.$cronFileIncludeRow['file']);
include_once $pathtophpfiles.'/scripts/'.$cronFileIncludeRow['file'];
fwrite( $debugHandler, 'Processing done!');
}

fclose( $debugHandler );
unlink($lockfile);

$db->query(
'UPDATE `'.TABLE_PANEL_SETTINGS.'` ' .
'SET `value` = UNIX_TIMESTAMP() ' .
'WHERE `settinggroup` = \'system\' ' .
' AND `varname` = \'lastcronrun\' '
);

$db->close();
?>
Something went wrong with that request. Please try again.