Ejemplo n.º 1
0
Archivo: proc.php Proyecto: tapiau/muyo
 /**
  * @param string|callable $command_getter
  * @param array|callable $output_setter
  * @param array|callable $retval_setter
  * @return callable
  */
 function proc_exec_dg($command_getter, &$output_setter = array(), &$retval_setter = null)
 {
     return function () use($command_getter, &$output_setter, &$retval_setter) {
         $args = func_get_args();
         if (is_callable($command_getter)) {
             $command = call_user_func_array($command_getter, $args);
         } else {
             $command = $command_getter;
         }
         $ret = proc_exec($command, $output, $retval);
         if (is_callable($output_setter)) {
             $output_setter($output);
         } else {
             $output_setter = $output;
         }
         if (is_callable($retval_setter)) {
             $retval_setter($retval);
         } else {
             $retval_setter = $retval;
         }
         return $ret;
     };
 }
</head>
<body>
<div style="clear: both"></div>

<div class="content1">
';
?>
<p>

<form action="restart_nginx.php" method="post">
<strong><font color="#0570b9">Restart ApacheBooster Server </font></strong> <input type="submit" name="submit" value="Restart">
</form>
<?php 
if (isset($_POST['submit'])) {
    $f = fopen("/usr/local/varnish/varnish_restart/restart.file", 'w');
    fwrite($f, "dummy");
    fclose($f);
    echo "<b>ApacheBooster restart process completed </b><br />";
    echo "<pre>";
    proc_exec("/etc/init.d/httpd status");
    echo "</pre>";
}
?>

</p>
<br /><br /><br /><br /><br />
<?php 
include 'footer.php';
?>

Ejemplo n.º 3
0
 /**
  * Convert HTML file to image and save it to $target
  * @param string $source path
  * @param string $target path
  * @param array $options
  */
 function wk_conv_file_to_img_file($source, $target, $options)
 {
     debug_enforce(file_exists($source) && is_file($source), "File '{$source}' doesn't exists.");
     proc_exec(wk_pdf_cli_build($source, $target, $options));
     debug_enforce(file_exists($target) && is_file($target) && is_readable($target), "Could not generate '{$source}'.");
 }
Ejemplo n.º 4
0
function compileProgram($sourcefile, $sourcedir, $classfile, $class, $inputs, $args, $processname, $data, $problem_number, $file_input_title, $file_input_data, $file_output_data, $problem_timeout, $team)
{
    @mkdir($sourcedir, 0755, true);
    $outputfile = "{$classfile}";
    chdir("/tmp/{$processname}");
    $handle = fopen($sourcefile, 'w+');
    fwrite($handle, $data);
    fclose($handle);
    if ($file_input_data !== "") {
        $handle = fopen($file_input_title . '.in', 'w+');
        fwrite($handle, $file_input_data);
        fclose($handle);
    }
    $conn = mysqli_connect(host, user, pw, db);
    $data = mysqli_real_escape_string($conn, $data);
    mysqli_close($conn);
    $compile_error = false;
    $runtime_error = false;
    $compile_data = proc_exec("javac -cp . {$sourcefile} 2>&1", "", "compile", $problem_timeout);
    if ($compile_data["output"] != "") {
        $compile_error = true;
    }
    #chdir(dirname(__FILE__));
    #$exec_data = proc_exec("java -classpath ../classloader ContestJudge /tmp/$processname/ ".substr($classfile,0,strlen($classfile)-6), $inputs, "execute");
    $exec_data = proc_exec("java -classpath {$sourcedir} {$class} {$args} 2>&1", $inputs, "execute", $problem_timeout);
    if ($exec_data["success"] === "false") {
        $conn = mysqli_connect(host, user, pw, db);
        $cur_time = date("Y-m-d H:i:s");
        $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$cur_time}','{$processname}','{$data}','', 'No', 'Timeout', '{$file_output_data}')";
        mysqli_query($conn, $query);
        mysqli_close($conn);
        return array("success" => "false", "error" => "Your program ran longer than the time alotted! Please make sure you don't go above the time limit. [Timeout error]");
    }
    if (preg_match("/.?Exception in thread/", $exec_data["output"]) == 1) {
        $runtime_error = true;
    }
    exec("rm -rf /tmp/{$processname}*");
    //compilation successful
    if ($compile_data["success"] === "true" && $exec_data["success"] === "true" && $compile_error === false && $runtime_error === false) {
        $conn = mysqli_connect(host, user, pw, db);
        $timestamp_a = $exec_data['timestamp'];
        $output_a = mysqli_real_escape_string($conn, $exec_data['output']);
        if (judge($file_output_data, $exec_data['output'])) {
            //correct answer
            $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$timestamp_a}','{$processname}','{$data}','{$output_a}', 'Yes', 'None', '{$file_output_data}')";
            mysqli_query($conn, $query);
            mysqli_close($conn);
            return array("success" => "true", "time" => $exec_data['time']);
        } else {
            //incorrect answer
            $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$timestamp_a}','{$processname}','{$data}','{$output_a}', 'No', 'None', '{$file_output_data}')";
            mysqli_query($conn, $query);
            mysqli_close($conn);
            return array("success" => "false", "error" => "Your output was incorrect!");
        }
    } else {
        if ($compile_error) {
            $conn = mysqli_connect(host, user, pw, db);
            $cur_time = date("Y-m-d H:i:s");
            $output_a = mysqli_real_escape_string($conn, $compile_data['output']);
            $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$cur_time}','{$processname}','{$data}','{$output_a}', 'No', 'Syntax', '{$file_output_data}')";
            mysqli_query($conn, $query);
            mysqli_close($conn);
            return array("success" => "false", "error" => "Your program was unable to compile! Please check for syntax errors and resubmit. [Syntax error]");
        } else {
            if ($runtime_error) {
                $conn = mysqli_connect(host, user, pw, db);
                $cur_time = date("Y-m-d H:i:s");
                $output_a = mysqli_real_escape_string($conn, $exec_data['output']);
                $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$cur_time}','{$processname}','{$data}','{$output_a}', 'No', 'Runtime', '{$file_output_data}')";
                mysqli_query($conn, $query);
                mysqli_close($conn);
                return array("success" => "false", "error" => "Your program encountered an error while running! Please check your program logic and resubmit. [Runtime error]");
            }
        }
    }
    //something terrible occured
    return array("success" => "false", "error" => "Unknown error, something huge has gone wrong!");
}
Ejemplo n.º 5
0
    if (!strlen($pstatus["exitcode"]) || $pstatus["running"]) {
        /* we can trust the retval of proc_close() */
        if ($pstatus["running"]) {
            proc_terminate($ptr);
        }
        $ret = proc_close($ptr);
    } else {
        if (($first_exitcode + 256) % 256 == 255 && ($pstatus["exitcode"] + 256) % 256 != 255) {
            $ret = $pstatus["exitcode"];
        } elseif (!strlen($first_exitcode)) {
            $ret = $pstatus["exitcode"];
        } elseif (($first_exitcode + 256) % 256 != 255) {
            $ret = $first_exitcode;
        } else {
            $ret = 0;
        }
        /* we "deduce" an EXIT_SUCCESS ;) */
        proc_close($ptr);
    }
    return ($ret + 256) % 256;
}
/* __init__ */
if (isset($argv) && count($argv) > 1 && !empty($argv[1])) {
    if (($ret = proc_exec($argv[1])) === false) {
        die("Error: not enough FD or out of memory.\n");
    } elseif ($ret == 127) {
        die("Command not found (returned by sh).\n");
    } else {
        exit($ret);
    }
}
function action_varnish($action)
{
    proc_exec($action);
    echo "Finished";
}
Ejemplo n.º 7
0
function tune_varnish($action)
{
    proc_exec($action);
}
Ejemplo n.º 8
0
// Just a dummy job
$worker->teach("test", function ($parameters = []) {
    echo "-> PW execution with parameters: " . json_encode($parameters) . "\n";
    sleep(5);
    // Simulate hard work
    // TODO: Acquire locks, check that the job has not been started and update so
});
// Meant for testing recovery
$worker->teach("test_kill", function ($parameters = []) {
    aadfg();
});
// This is far from the actual executor, but useful for simple tests
$worker->teach("pw_simple", function ($parameters = []) {
    $output = "";
    $error = "";
    $retval = proc_exec("php vendor/bin/pw_exec.php", json_encode($parameters), $output, $error);
    $haveOutput = false;
    $failed = false;
    if (strlen($output)) {
        echo $output;
    }
    if (strlen($error)) {
        file_put_contents("php://stderr", $error);
    }
    if ($retval != 0) {
        file_put_contents("php://stderr", "-> Sub process failed with exit code {$retval}\n");
    } else {
        echo "-> OK!\n";
    }
});
// To peek on the env
<?php 
//echo $imagetag
//if (!$basedir = mkdir($CFG->dataroot.'/temp/hocr')) {
//error("The site administrator needs to fix the file permissions");
//}
echo "<br/>";
$imagefile = str_ireplace("{$CFG->wwwroot}/file.php/", "", $imageurl);
$tempocrfile = $CFG->dataroot . '/temp/hocr/' . $USER->id . '_' . time() . '.text';
echo "<br/>";
if (file_exists('/usr/bin/hocr')) {
    $exec_string = '/usr/bin/hocr -d --no-gtk -o ' . $tempocrfile . ' -i ' . $CFG->dataroot . '/' . $imagefile;
    //$exec_string = '/usr/bin/hocr -h';
    //$exec_string = '/var/www/moodle-latest-stable/lib/editor/htmlarea/custom_plugins/hocr/hocr -h';
    echo $exec_string . "<br/>";
    $ret = proc_exec($exec_string);
    //echo exec('whoami');
    //echo "HOCR - YES [$exec_string]<hr/>";
    //$hocrtext = file_get_contents($tempocrfile, FILE_USE_INCLUDE_PATH);
    //echo $hocrtext;
    //exec('rm -rf '.$toFile); // Linux specific!
}
/*
 * Wrapper for proc_*() functions.
 * The first parameter $cmd is the command line to execute.
 * Return the exit code of the process.
 */
function proc_exec($cmd)
{
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $ptr = proc_open($cmd, $descriptorspec, $pipes, NULL, $_ENV);
Ejemplo n.º 10
0
 /**
  * @param string $backupFile
  * @return array
  */
 function tar_ls($backupFile)
 {
     proc_exec("tar -ztvf {$backupFile} | awk '{print \$6}'", $output);
     return $output;
 }