Ejemplo n.º 1
0
function httpsocket($url, $query)
{
    $url = str_replace('http://', '', $url);
    $path = explode('/', $url);
    $url = $path[0];
    unset($path[0]);
    $path = '/' . implode('/', $path);
    $fp = @fsockopen($url, 80, $errno, $errstr, 6);
    if (!$fp) {
        return "error ({$errno})";
    }
    $q = "query=" . array_encode($query);
    $out = 'POST ' . $path . ' HTTP/1.1' . "\r\n";
    $out .= 'Host: ' . $url . "\r\n";
    $out .= 'Connection: close' . "\r\n";
    $out .= 'Content-Length: ' . strlen($q) . "\r\n";
    $out .= 'Content-Type: application/x-www-form-urlencoded; charset=iso-8859-1' . "\r\n\r\n";
    $out .= $q . "\r\n";
    fwrite($fp, $out);
    $buf = "";
    while (!feof($fp)) {
        $buf .= fgets($fp, 128);
    }
    fclose($fp);
    $arr = explode("<return>", $buf);
    return $arr[1];
}
Ejemplo n.º 2
0
function parseGoogle($item)
{
    $page = ripoff("http://www.google.com/search?hl=en&q=" . $item);
    preg_match_all("|<a\\ href=\"([^\"]*)\"\\ class=\"?l\"?>(.*)<\\/a>.*<font[^>]*>(.*)<span|U", $page, $tmp, PREG_PATTERN_ORDER);
    unset($tmp[0]);
    $json = array_encode($tmp);
    $json = preg_replace('/<b>(...)<\\/b>/', "\$1", $json);
    return $json;
}
Ejemplo n.º 3
0
function cacheHistory($stream)
{
    if ($stream['song'] == 'Not found') {
        return;
    }
    $year = date('Y');
    $month = date('m');
    $day = date('d');
    if (!is_dir('history')) {
        mkdir('history', 0777);
    }
    if (!is_dir('history/' . $year)) {
        mkdir('history/' . $year);
    }
    if (!is_dir('history/' . $year . '/' . $month)) {
        mkdir('history/' . $year . '/' . $month);
    }
    $file = 'history/' . $year . '/' . $month . '/' . $day . '.json';
    $history['time'] = gmdate('c');
    $history['artist'] = $stream['info']['artist'];
    $history['song'] = $stream['info']['song'];
    $history['image'] = $stream['album']['image_s'];
    $history['itunes'] = $stream['track']['buylink']['download']['iTunes']['link'];
    $history['Amazon'] = $stream['track']['buylink']['download']['Amazon']['link'];
    $history = array_encode($history);
    file_put_contents($file, json_encode($history));
    createHistory();
}
Ejemplo n.º 4
0
function grade($query)
{
    global $compiledir, $datadir;
    $i = $query['grade'];
    $memorylimit = $query['memorylimit'] * 1024;
    getdir($query);
    createlink($i, $query);
    $data = dataset($query['pname'], $i);
    $tmp['noindata'] = $tmp['noansdata'] = 0;
    $tmp['input'] = file_get_contents($data['input']);
    $tmp['timeout'] = false;
    $tmp['runerr'] = false;
    $tmp['noreport'] = false;
    if ($query['language'] == 3) {
        $cpcmd = "mv output/{$query['pname']}{$i}.out {$query['pname']}.out";
        //if(file_exists("{$query['pname']}.out"))
        //    exec("rm {$query['pname']}.out");
        exec($cpcmd);
        exec("ls output/{$query['pname']}*.out > tmpp");
    } else {
        $execute = "(ulimit -v {$memorylimit}; ./{$query['pname']})";
        $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
        $process = proc_open($execute, $descriptorspec, $pipes);
        $status = proc_get_status($process);
        $pid = $status['pid'] + 2;
        exec("ps v -C {$query['pname']}", $mem);
        sscanf($mem[1], "%ld%s%s%s%s%ld%ld", &$ar[1], &$ar[2], &$ar[3], &$ar[4], &$ar[5], &$ar[6], &$ar[7]);
        fwrite($pipes[0], "1");
        fclose($pipes[0]);
        $tmp['memory'] = $memory = $ar[7];
        $time_start = getmicrotime();
        setrunning(1);
        for (;;) {
            $status = proc_get_status($process);
            if (!$status['running']) {
                break;
            }
            $time_now = getmicrotime();
            $tmp['rtime'] = ($time_now - $time_start) * 950;
            if ($tmp['rtime'] > $query['timelimit']) {
                proc_terminate($process);
                //posix_kill($pid,1);
                exec("killall {$query['pname']}");
                $tmp['timeout'] = true;
                break;
            }
        }
        setrunning(-1);
        $tmp['exitcode'] = $status['exitcode'];
        if ($tmp['exitcode'] == 137) {
            $tmp['memoryout'] = true;
        }
        if ($tmp['exitcode'] != 0) {
            $tmp['runerr'] = true;
        }
    }
    if (!file_exists("{$query['pname']}.out")) {
        $tmp['noreport'] = true;
    } else {
        $inn = $data['input'];
        $ansn = $data['answer'];
        $outn = "{$query['pname']}.out";
        if ($query['plugin'] == 0 || $query['plugin'] == 3) {
            $tmp['score'] = plugin($query['pname'], $inn, $outn, $ansn);
        } else {
            $fin = fopen($inn, "r");
            $fans = fopen($ansn, "r");
            $fout = fopen($outn, "r");
            $tmp['score'] = standard_compare($fans, $fout);
            fclose($fin);
            fclose($fout);
            fclose($fans);
        }
    }
    if (!file_exists($data['input'])) {
        $tmp['noindata'] = 1;
    }
    if (!file_exists($data['answer'])) {
        $tmp['noansdata'] = 1;
    }
    if ($tmp['timeout'] == true || $tmp['runerr'] == true || $tmp['noindata'] + $tmp['noansdata']) {
        $tmp['score'] = 0;
    }
    if ($tmp['score'] < 1.0) {
        $fians = $data['answer'];
        $fiout = "{$query['pname']}.out";
        $fistr = "diff -b -U0 {$fiout} {$fians}";
        exec($fistr . " > tmp", $diff);
        $tmp['diff'] = file_get_contents("tmp");
    }
    proc_close($process);
    destroylink($i, $query);
    if (file_exists("{$query['pname']}.out")) {
        rename("{$query['pname']}.out", "{$query['pname']}{$i}.out");
    }
    echo array_encode($tmp);
}
Ejemplo n.º 5
0
function cacheVar($stream)
{
    $stream = array_encode($stream);
    file_put_contents('var/info.json', json_encode($stream));
}