2013-08-28 22:47:04 +02:00
|
|
|
<?php
|
2013-10-16 20:59:18 +02:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
/**
|
|
|
|
* File: jobs.php.
|
|
|
|
* Author: Ulrich Block
|
|
|
|
* Date: 26.05.12
|
|
|
|
* Time: 10:56
|
|
|
|
* Contact: <ulrich.block@easy-wi.com>
|
|
|
|
*
|
|
|
|
* This file is part of Easy-WI.
|
|
|
|
*
|
|
|
|
* Easy-WI 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Easy-WI 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Easy-WI. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Diese Datei ist Teil von Easy-WI.
|
|
|
|
*
|
|
|
|
* Easy-WI ist Freie Software: Sie koennen es unter den Bedingungen
|
|
|
|
* der GNU General Public License, wie von der Free Software Foundation,
|
|
|
|
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder spaeteren
|
|
|
|
* veroeffentlichten Version, weiterverbreiten und/oder modifizieren.
|
|
|
|
*
|
|
|
|
* Easy-WI wird in der Hoffnung, dass es nuetzlich sein wird, aber
|
|
|
|
* OHNE JEDE GEWAEHELEISTUNG, bereitgestellt; sogar ohne die implizite
|
|
|
|
* Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK.
|
|
|
|
* Siehe die GNU General Public License fuer weitere Details.
|
|
|
|
*
|
|
|
|
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
|
|
|
|
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-10-13 11:42:31 +02:00
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
2013-10-20 12:02:02 +02:00
|
|
|
$timelimit = ini_get('max_execution_time') - 10;
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
} else {
|
2013-10-20 12:02:02 +02:00
|
|
|
$timelimit = 600;
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-10-20 12:02:02 +02:00
|
|
|
$deamon = false;
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
if (isset($argv)) {
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-09-29 15:29:58 +02:00
|
|
|
$args = array();
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
foreach ($argv as $a) {
|
2013-10-20 12:02:02 +02:00
|
|
|
if ($a == 'deamon') {
|
|
|
|
$deamon = true;
|
|
|
|
} else if (is_numeric($a)) {
|
|
|
|
$sleep = $a;
|
|
|
|
} else {
|
2014-03-23 13:15:54 +01:00
|
|
|
|
|
|
|
$e = explode(':', $a);
|
|
|
|
|
|
|
|
if (isset($e[1])) {
|
|
|
|
$args[$e[0]] = $e[1];
|
|
|
|
}
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-20 12:02:02 +02:00
|
|
|
|
|
|
|
if ($deamon == false) {
|
2013-12-29 12:39:48 +01:00
|
|
|
print 'Running job management as cronjob' . "\r\n";
|
2013-08-28 22:47:04 +02:00
|
|
|
set_time_limit($timelimit);
|
|
|
|
} else {
|
2013-12-29 12:39:48 +01:00
|
|
|
print 'Running job management as Deamon' . "\r\n";
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2013-10-20 12:02:02 +02:00
|
|
|
|
|
|
|
if (!isset($sleep)) {
|
|
|
|
$sleep = 60;
|
|
|
|
}
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2013-10-20 12:02:02 +02:00
|
|
|
|
|
|
|
define('EASYWIDIR', dirname(__FILE__));
|
|
|
|
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/methods/vorlage.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/functions.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/class_validator.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/class_rootserver.php');
|
2014-11-09 12:06:25 +01:00
|
|
|
include(EASYWIDIR . '/stuff/methods/class_ftp.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/class_app.php');
|
2014-03-23 13:15:54 +01:00
|
|
|
include(EASYWIDIR . '/stuff/methods/class_httpd.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
include(EASYWIDIR . '/stuff/settings.php');
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/methods/functions_gs.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/class_ts3.php');
|
|
|
|
include(EASYWIDIR . '/stuff/methods/functions_ts3.php');
|
2014-03-23 13:15:54 +01:00
|
|
|
include(EASYWIDIR . '/stuff/methods/class_mysql.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
include(EASYWIDIR . '/stuff/keyphrasefile.php');
|
|
|
|
|
2015-10-11 16:31:47 +02:00
|
|
|
$logreseller = 0;
|
|
|
|
$logsubuser = 0;
|
|
|
|
$loguserip = '127.0.0.1';
|
|
|
|
$userHostname = 'localhost';
|
|
|
|
$logusername = 'Cronjob';
|
|
|
|
$logusertype = 'cron';
|
|
|
|
|
2013-10-20 12:02:02 +02:00
|
|
|
if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip, ipstoarray($rSA['cronjob_ips']))) {
|
2014-03-23 13:15:54 +01:00
|
|
|
|
2013-10-20 12:02:02 +02:00
|
|
|
$gsprache = getlanguagefile('general', 'uk', 0);
|
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
class runGraph {
|
2013-12-29 12:39:48 +01:00
|
|
|
|
|
|
|
private $jobsDone = 0, $startTime = 0, $newLine = "\r\n", $jobCount = 0, $spinnerCount = 0, $spinners = array('-', '/', '-', '\\', '|', '/', '-', '\\', '|', '/'), $spinner = '-', $oneJobPercent = 1;
|
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
function __construct($jobCount,$newLine) {
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
$this->startTime=strtotime('now');
|
2013-10-13 11:42:31 +02:00
|
|
|
$this->jobCount = $jobCount;
|
2013-12-29 12:39:48 +01:00
|
|
|
|
|
|
|
$this->oneJobPercent = ($jobCount > 0) ? 100 / $jobCount : 100;
|
|
|
|
|
2013-10-13 11:42:31 +02:00
|
|
|
$this->newLine = $newLine;
|
2013-12-29 12:39:48 +01:00
|
|
|
$this->startTime = strtotime('now');
|
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
public function updateCount($jobCount) {
|
2013-10-13 11:42:31 +02:00
|
|
|
$this->jobCount = $jobCount;
|
2013-12-29 12:39:48 +01:00
|
|
|
$this->oneJobPercent = ($jobCount > 0) ? 100 / $jobCount : 100;
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
public function printGraph ($newCommand) {
|
2013-12-29 12:39:48 +01:00
|
|
|
|
|
|
|
$this->jobsDone = $this->jobsDone + 1;
|
|
|
|
$percentDone = number_format($this->jobsDone * $this->oneJobPercent, 2);
|
|
|
|
$elapsedSeconds = strtotime('now') - $this->startTime;
|
|
|
|
|
|
|
|
print $this->spinner . ' ' . $percentDone . '% done; ' . $elapsedSeconds . ' Seconds elapsed; Last job: ' . $newCommand.$this->newLine;
|
2013-08-28 22:47:04 +02:00
|
|
|
flush();
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
$this->runSpinner();
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
private function runSpinner () {
|
2013-12-29 12:39:48 +01:00
|
|
|
if ($this->newLine == "\r") {
|
|
|
|
|
|
|
|
if ($this->spinnerCount < 9) {
|
2013-08-28 22:47:04 +02:00
|
|
|
$this->spinnerCount++;
|
|
|
|
} else {
|
2013-09-29 15:29:58 +02:00
|
|
|
$this->spinnerCount = 0;
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2013-12-29 12:39:48 +01:00
|
|
|
|
|
|
|
$this->spinner = $this->spinners[$this->spinnerCount] . ' ';
|
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
} else {
|
2013-09-29 15:29:58 +02:00
|
|
|
$this->spinner = '';
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-08-28 22:47:04 +02:00
|
|
|
function __destruct() {
|
2013-10-13 11:42:31 +02:00
|
|
|
$this->jobsDone = null;
|
|
|
|
$this->startTime = null;
|
|
|
|
$this->newLine = null;
|
|
|
|
$this->jobCount = null;
|
|
|
|
$this->spinnerCount = null;
|
|
|
|
$this->spinners = null;
|
|
|
|
$this->spinner = null;
|
|
|
|
$this->oneJobPercent = null;
|
2013-08-28 22:47:04 +02:00
|
|
|
unset($this->jobsDone,$this->startTime,$this->newLine,$this->jobCount,$this->spinnerCount,$this->spinners,$this->spinner,$this->oneJobPercent);
|
|
|
|
}
|
|
|
|
}
|
2013-10-20 12:02:02 +02:00
|
|
|
|
2013-10-03 12:49:13 +02:00
|
|
|
$runJobs = true;
|
2013-10-20 12:02:02 +02:00
|
|
|
|
2014-03-23 13:15:54 +01:00
|
|
|
$newLine = (isset($ip)) ? "\r\n" : "\r";
|
2013-10-20 12:02:02 +02:00
|
|
|
|
|
|
|
$counJobs = $sql->prepare("SELECT COUNT(`jobID`) AS `jobCount` FROM `jobs` WHERE `status` IS NULL OR `status`='1'");
|
2013-10-13 11:42:31 +02:00
|
|
|
while ($runJobs == true) {
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-12-29 12:39:48 +01:00
|
|
|
print 'Total jobs open: ' . $jobCount . '. Cleaning up outdated and duplicated entries' . "\r\n";
|
2013-09-07 13:33:50 +02:00
|
|
|
updateStates('dl','us');
|
|
|
|
updateStates('dl');
|
|
|
|
updateStates('ad');
|
|
|
|
updateStates('md');
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after cleanup: ' . $jobCount . "\r\n";
|
|
|
|
print 'Executing user cleanup jobs' . "\r\n";
|
2013-11-23 20:48:22 +01:00
|
|
|
$startTime = strtotime('now');
|
|
|
|
$theOutput = new runGraph($jobCount,$newLine);
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2014-03-23 13:15:54 +01:00
|
|
|
# us > vo > gs > my > vs > wv
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_user.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-08-28 22:47:04 +02:00
|
|
|
$theOutput->updateCount($jobCount);
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after user cleanup jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
|
|
|
print 'Executing voice jobs' . "\r\n";
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_voice.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-08-28 22:47:04 +02:00
|
|
|
$theOutput->updateCount($jobCount);
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after voice jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
|
|
|
print 'Executing TS DNS jobs' . "\r\n";
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_tsdns.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-08-28 22:47:04 +02:00
|
|
|
$theOutput->updateCount($jobCount);
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after TS DNS jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
|
|
|
print 'Executing mysql jobs' . "\r\n";
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_mysql.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-08-28 22:47:04 +02:00
|
|
|
$theOutput->updateCount($jobCount);
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after mysql jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
|
|
|
print 'Executing gameserver jobs' . "\r\n";
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_gserver.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-08-28 22:47:04 +02:00
|
|
|
$theOutput->updateCount($jobCount);
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after gameserver jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
|
|
|
print 'Executing root server jobs' . "\r\n";
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_roots.php');
|
2013-10-20 12:02:02 +02:00
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
2013-08-28 22:47:04 +02:00
|
|
|
$theOutput->updateCount($jobCount);
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Total jobs open after root server jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
2014-03-23 13:15:54 +01:00
|
|
|
print 'Executing Fastdownload jobs' . "\r\n";
|
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_webspace.php');
|
|
|
|
$counJobs->execute();
|
|
|
|
$jobCount = $counJobs->rowCount();
|
|
|
|
$theOutput->updateCount($jobCount);
|
|
|
|
print "\r\n" . 'Total jobs open after Fastdownload jobs are done: ' . $jobCount . "\r\n";
|
|
|
|
|
2013-12-29 12:39:48 +01:00
|
|
|
print 'Executing user remove jobs' . "\r\n";
|
2014-02-23 13:13:48 +01:00
|
|
|
include(EASYWIDIR . '/stuff/jobs/jobs_user_rm.php');
|
2013-08-28 22:47:04 +02:00
|
|
|
print "\n";
|
2013-12-29 12:39:48 +01:00
|
|
|
|
2013-10-13 11:42:31 +02:00
|
|
|
if ($deamon == true) {
|
|
|
|
$sql = null;
|
|
|
|
$theOutput = null;
|
2013-08-28 22:47:04 +02:00
|
|
|
unset($sql,$theOutput);
|
2013-10-03 12:49:13 +02:00
|
|
|
if ($dbConnect['type'] == 'mysql') {
|
|
|
|
$sql=new PDO($dbConnect['connect'],$dbConnect['user'],$dbConnect['pwd'], array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES utf8") );
|
2013-08-28 22:47:04 +02:00
|
|
|
} else {
|
|
|
|
$sql=new PDO($dbConnect['connect'],$dbConnect['user'],$dbConnect['pwd']);
|
|
|
|
}
|
|
|
|
if ($dbConnect['debug']==1) {
|
|
|
|
$sql->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
|
|
|
|
}
|
|
|
|
flush();
|
2013-12-29 12:39:48 +01:00
|
|
|
print "\r\n" . 'Deamon run finished. Current memory usage is: '.memory_get_usage().' Bytes. Waiting ' . $sleep.' seconds before next job run'."\r\n\r\n";
|
2013-08-28 22:47:04 +02:00
|
|
|
sleep($sleep);
|
|
|
|
} else {
|
2013-09-29 15:29:58 +02:00
|
|
|
$runJobs = false;
|
2013-08-28 22:47:04 +02:00
|
|
|
}
|
2014-01-10 22:16:51 +01:00
|
|
|
$query = $sql->prepare("UPDATE `settings` SET `lastCronJobs`=UNIX_TIMESTAMP()");
|
2013-08-28 22:47:04 +02:00
|
|
|
$query->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|