Ejemplo n.º 1
0
function str_between($startstr, $stopstr, $infile, $is_file_or_str = "str")
{
    if ($is_file_or_str == "file" && !is_file($infile)) {
        getout("infile = {$infile}");
    }
    if ($is_file_or_str != "file" && $is_file_or_str != "str") {
        getout("is_file_or_str = {$is_file_or_str}");
    }
    if ($is_file_or_str == "file") {
        $filestr = file_get_contents($infile);
    } else {
        if ($is_file_or_str == "str") {
            $filestr = $infile;
        }
    }
    $X = strstr($filestr, $startstr);
    $X = substr($X, strlen($startstr), strlen($X));
    if ($X == "") {
        // Start string not found
        return null;
    }
    if ($stopstr != "") {
        $pos = strpos($X, $stopstr);
        if (!is_numeric($pos)) {
            // echo "\nFound startstr but not stopstr \n";
            return null;
        } else {
            $Y = substr($X, 0, $pos);
        }
    } else {
        $Y = $X;
    }
    return $Y;
}
function error($msg)
{
    global $response;
    $response['message'] = $msg;
    $response['success'] = false;
    getout();
}
Ejemplo n.º 3
0
function free_tbspc($token)
{
    if (is_null($token) || $token != "" && !is_numeric($token)) {
        getout("");
    }
    //-------------------------------------
    $ch = curl_init();
    $server = "localhost";
    // HARD CODED
    $port = 8000;
    // HARD CODED
    $urlpre = "http://" . $server . ":" . $port . "/";
    // free tablespace
    $url = $urlpre . "free?TOKEN={$token}";
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    $output = curl_exec($ch);
    // close curl resource to free up system resources
    curl_close($ch);
}
Ejemplo n.º 4
0
    header("HTTP/1.1 200 OK ");
    switch ($query) {
        case "q1":
            $str = trim(file_get_contents($tempfile));
            $X = array('n' => $str);
            break;
        case "q2":
            $fp = fopen($tempfile, "r");
            if (!$fp) {
                getout("");
            }
            $n1 = trim(fgets($fp));
            $n2 = trim(fgets($fp));
            fclose($fp);
            $X = array('n1' => $n1, 'n2' => $n2);
            break;
        default:
            getout("");
            break;
    }
    $Y = json_encode($X);
    echo $Y;
} else {
    header("HTTP/1.1 500 Internal Server Error");
    $str = file_get_contents($errfile);
    echo $str;
}
unlink($errfile);
unlink($tempfile);
free_tbspc($token);
// echo "<H1> Released token $token </H1> \n";
Ejemplo n.º 5
0
        $err_msg = "not numeric token [ {$token}]";
        return false;
    }
    if (!is_null($ram_data_dir) && $ram_data_dir != "") {
        if (!is_dir($ram_data_dir)) {
            $err_msg = "missing ram_data_dir [{$ram_data_dir}]";
            return false;
        }
    }
    return true;
}
$is_cli = true;
$tbspc = "";
if ($is_cli) {
    if ($argc != 2) {
        getout("");
    }
    $tbspc = $argv[1];
    $token = "";
    $q_docroot = "";
    $q_data_dir = "";
    $err_msg = "";
    $rslt = init_tbspc($tbspc, $token, $q_docroot, $dsk_data_dir, $ram_data_dir, $err_msg);
    if ($rslt === false) {
        getout($err_msg);
    }
    echo "TOKEN={$token} \n";
    echo "Q_DOCROOT={$q_docroot} \n";
    echo "DSK_DATA_DIR={$dsk_data_dir} \n";
    echo "RAM_DATA_DIR={$ram_data_dir} \n";
}