Example #1
0
require 'inc/config.php';
include 'inc/define.php';
include 'inc/common.php';
include "inc/header.php";
function cmpGoodChange($a, $b)
{
    return $b['diff'] - $a['diff'];
}
function cmpBadChange($a, $b)
{
    return $a['diff'] - $b['diff'];
}
$res = $db->query("SELECT idRun,dateStart,dateStop,pid,haveError,timediff(dateStop,dateStart) diff FROM `" . SQL_PREFIX . "run` ORDER BY dateStart DESC LIMIT 1");
if ($res && ($run = mysql_fetch_assoc($res))) {
    if ($run['dateStop'] == null) {
        if (!is_pid_alive($run['pid'])) {
            // in this case the pid have been killed externally
            // from command line or max execution time reached
            $db->query("UPDATE `" . SQL_PREFIX . "run` SET haveError=1, dateStop=now(), " . "logs=CONCAT(logs,'ERROR ABNORMAL TERMINATION : process may have been killed or reached max execution time\n') " . "WHERE idRun = " . $run['idRun']);
            echo "<div class='alert alert-error' >Last run done in " . $run['diff'] . " with error (PID: " . $run['pid'] . " started: " . $run['dateStart'] . ")<span class='pull-right' >[<a href='logs.php?id=" . $run['idRun'] . "' >LOG</a>]</span></div>";
        } else {
            echo "<div class='alert' >Warning: cron is still running (PID: " . $run['pid'] . " started: " . $run['dateStart'] . ") <span class='pull-right' >[<a href='logs.php?id=" . $run['idRun'] . "' >LOG</a>] [<a style='color:red;' id='stop' data-pid=" . $run['pid'] . " data-runid=" . $run['idRun'] . " href='#' >STOP</a>]</span></div>";
        }
    } else {
        if ($run['haveError']) {
            echo "<div class='alert alert-error' >Last run done in " . $run['diff'] . " with error (PID: " . $run['pid'] . " started: " . $run['dateStart'] . ")<span class='pull-right' >[<a href='logs.php?id=" . $run['idRun'] . "' >LOG</a>]</span></div>";
        } else {
            echo "<div class='alert alert-success' >Last run successfully done in " . $run['diff'] . " (PID: " . $run['pid'] . " started: " . $run['dateStart'] . ")<span class='pull-right' >[<a href='logs.php?id=" . $run['idRun'] . "' >LOG</a>]</span></div>";
        }
    }
}
Example #2
0
 case "swap":
     if (isset($_POST['source']) && is_numeric($_POST['source']) && isset($_POST['target']) && is_numeric($_POST['target'])) {
         // elite query
         $query = "UPDATE " . "`" . SQL_PREFIX . "group` AS g1 JOIN `" . SQL_PREFIX . "group` AS g2 " . "ON ( g1.idGroup = " . intval($_POST['source']) . " AND g2.idGroup = " . intval($_POST['target']) . " ) " . "SET g1.position = g2.position, g2.position = g1.position";
         $swap = $db->query($query);
         die(json_encode(array("swap" => $swap)));
     }
     break;
     // kill a running process
 // kill a running process
 case "kill":
     if (isset($_POST['pid']) && is_numeric($_POST['pid']) && isset($_POST['runid']) && is_numeric($_POST['runid'])) {
         portable_kill($_POST['pid']);
         sleep(1);
         // hacking, should wait for pid to exit
         if (is_pid_alive($_POST['pid'])) {
             die(json_encode(array("kill" => FALSE)));
         }
         $db->query("UPDATE `" . SQL_PREFIX . "run` SET haveError=1, dateStop=now(), " . "logs=CONCAT(logs,'ERROR KILLED FROM WEB PANEL\n') " . "WHERE idRun = " . intval($_POST['runid']));
         die(json_encode(array("kill" => TRUE)));
     }
     break;
 case "getSiteInfo":
     if (isset($_POST['target']) && is_numeric($_POST['target'])) {
         $q = "SELECT info FROM `" . SQL_PREFIX . "target` WHERE idTarget = " . intval($_POST['target']);
         $result = $db->query($q);
         if ($result && ($row = mysql_fetch_assoc($result))) {
             die(json_encode($row));
         }
     }
     break;