Exemple #1
0
/**
 * Launcher to request Mediboard
 * 
 * @param string $rootURL  Host to request (ie, https://localhost/mediboard)
 * @param string $username Username requesting
 * @param string $password Password of the user
 * @param string $params   Parameters to send (ie, "m=dPpatients&tab=vw_medecins")
 * @param int    $times    How many repeats
 * @param int    $delay    Delay (in seconds) between repeats
 * @param string $file     Output file
 * 
 * @return void
 */
function request($rootURL, $username, $password, $params, $times, $delay, $file)
{
    announce_script("Mediboard request launcher");
    if ($times === "") {
        $times = 1;
    }
    if ($delay === "") {
        $delay = 1;
    }
    $times = intval($times);
    $delay = intval($delay);
    $login = "******";
    $username = "******" . $username;
    $password = "******" . $password;
    $url = $rootURL . "/index.php?" . $login . "&" . $username . "&" . $password . "&" . $params;
    // Make mediboard path
    $MEDIBOARDPATH = "/var/log/mediboard";
    force_dir($MEDIBOARDPATH);
    $log = $MEDIBOARDPATH . "/jobs.log";
    force_file($log);
    if ($times > 1) {
        while ($times > 0) {
            $times--;
            mediboard_request($url, $log, $file);
            sleep($delay);
        }
    } else {
        mediboard_request($url, $log, $file);
    }
}
Exemple #2
0
/**
 * Update Mediboard
 * 
 * @param string $action   action to perform: info|real|noup
 * @param string $revision revision number you want to update to
 * 
 * @return void
 */
function update($action, $revision)
{
    $currentDir = dirname(__FILE__);
    announce_script("Mediboard SVN updater");
    $MB_PATH = $currentDir . "/..";
    $log = $MB_PATH . "/tmp/svnlog.txt";
    $tmp = $MB_PATH . "/tmp/svnlog.tmp";
    $dif = $MB_PATH . "/tmp/svnlog.dif";
    $status = $MB_PATH . "/tmp/svnstatus.txt";
    $event = $MB_PATH . "/tmp/monitevent.txt";
    $prefixes = array("erg", "fnc", "fct", "bug", "war", "edi", "sys", "svn");
    if ($revision === "") {
        $revision = "HEAD";
    }
    // Choose the target revision
    switch ($action) {
        case "info":
            $out = array();
            exec("svn info {$MB_PATH}", $out, $ret);
            if (check_errs($ret, null, "SVN info error", "SVN info successful!")) {
                echo $out[5] . "\n";
            }
            $out = array();
            exec("svn log {$MB_PATH} -r BASE:{$revision}", $out, $ret);
            if (check_errs($ret, null, "SVN log error", "SVN log successful!")) {
                $out = filter_commit_messages($out);
                echo implode("\n", $out) . "\n";
            }
            $out = array();
            exec("svn info {$MB_PATH} -r {$revision}", $out, $ret);
            if (check_errs($ret, null, "SVN info error", "SVN info successful!")) {
                echo $out[5] . "\n";
            }
            break;
        case "real":
            // Concat the source (BASE) revision number : 5th line of SVN info (!)
            $out = array();
            exec("svn info {$MB_PATH}", $out, $ret);
            if (check_errs($ret, null, "Failed to get source revision info", "SVN Revision source info written!")) {
                $fic = fopen($tmp, "w");
                if (check_errs($fic, false, "Failed to open tmp file", "Tmp file opened!")) {
                    fwrite($fic, $out[5] . "\n");
                    fclose($fic);
                }
            }
            // Concat SVN Log from BASE to target revision
            $out = array();
            exec("svn log {$MB_PATH} -r BASE:{$revision}", $out, $ret);
            if (check_errs($ret, null, "Failed to retrieve SVN log", "SVN log retrieved!")) {
                $fic = fopen($dif, "w");
                if (check_errs($fic, false, "Failed to open dif file", "Dif file opened!")) {
                    fwrite($fic, implode("\n", $out) . "\n");
                    fclose($fic);
                    $fic = fopen($dif, "r");
                    $fic2 = fopen($tmp, "a+");
                    // TODO: use filter_commit_messages()
                    while (!feof($fic)) {
                        $buffer = fgets($fic);
                        if (preg_match("/(erg:|fnc:|fct:|bug:|war:|edi:|sys:|svn:)/i", $buffer)) {
                            fwrite($fic2, $buffer);
                        }
                    }
                    fclose($fic);
                    fclose($fic2);
                    echo "SVN log parsed!\n";
                    unlink($dif);
                }
            }
            // Perform actual update
            $out = array();
            exec("svn update {$MB_PATH} --revision {$revision}", $out, $ret);
            echo implode("\n", $out) . "\n";
            check_errs($ret, null, "Failed to perform SVN update", "SVN update performed!");
            // Concat the target revision number
            $fic = fopen($tmp, "a+");
            $out = array();
            exec("svn info {$MB_PATH}", $out, $ret);
            if (check_errs($ret, null, "Failed to get target revision info", "SVN Revision target info written!")) {
                fwrite($fic, "\n" . implode("\n", $out));
                fclose($fic);
            }
            // Contact dating info
            $fic = fopen($tmp, "a+");
            fwrite($fic, "--- Updated Mediboard on " . strftime("%Y-%m-%d %H:%M:%S") . " ---\n");
            fclose($fic);
            // Concat tmp file to log file //
            // Ensure log file exists
            force_file($log);
            // Log file is reversed, make it straight
            shell_exec("tac " . $log . " > " . $log . ".straight");
            // Concat tmp file
            shell_exec("cat " . $tmp . " >> " . $log . ".straight");
            // Reverse the log file for user convenience
            shell_exec("tac " . $log . ".straight > " . $log);
            // Clean files
            unlink($log . ".straight");
            unlink($tmp);
            // Write status file
            $svn = shell_exec("svn info " . $MB_PATH . " | awk 'NR==5'");
            if (check_errs($svn, null, "Failed to write status file", "Status file written!")) {
                $fic = fopen($status, "w");
                fwrite($fic, $svn . "Date: " . strftime("%Y-%m-%d %H:%M:%S") . "\n");
                fclose($fic);
                if (file_exists($event)) {
                    $fic = fopen($event, "a");
                } else {
                    $fic = fopen($event, "w");
                }
                fwrite($fic, "\n#" . date('Y-m-d H:i:s'));
                fwrite($fic, "\nMise a jour. " . $svn);
                fclose($fic);
            }
            break;
    }
}