Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/data/php/hop.php
Views: 11766
<?php1$magic = 'TzGq';2$tempdir = sys_get_temp_dir() . "/hop" . $magic;3if(!is_dir($tempdir)){4mkdir($tempdir); //make sure it's there5}67//get url8$url = $_SERVER["QUERY_STRING"];9//like /path/hop.php?/uRIcksm_lOnGidENTifIEr1011//Looks for a file with a name or contents prefix, if found, send it and deletes it12function findSendDelete($tempdir, $prefix, $one=true){13if($dh = opendir($tempdir)){14while(($file = readdir($dh)) !== false){15if(strpos($file, $prefix) !== 0){16continue;17}18readfile($tempdir."/".$file);19unlink($tempdir."/".$file);20if($one){21break;22}23}24}25}2627//handle control28if($url === "/control"){29if($_SERVER['REQUEST_METHOD'] === 'POST'){30//handle data for payload - save in a "down" file or the "init" file31$postdata = file_get_contents("php://input");32if(array_key_exists('HTTP_X_INIT', $_SERVER)){33$f = fopen($tempdir."/init", "w"); //only one init file34}else{35$prefix = "down_" . sha1($_SERVER['HTTP_X_URLFRAG']);36$f = fopen(tempnam($tempdir,$prefix), "w");37}38fwrite($f, $postdata);39fclose($f);40}else{41findSendDelete($tempdir, "up_", false);42}43}else if($_SERVER['REQUEST_METHOD'] === 'POST'){44//get data45$postdata = file_get_contents("php://input");46//See if we should send anything down47if($postdata === "RECV\x00" || $postdata === "RECV"){48findSendDelete($tempdir, "down_" . sha1($url));49$fname = $tempdir . "/up_recv_" . sha1($url); //Only keep one RECV poll50}else{51$fname = tempnam($tempdir, "up_"); //actual data gets its own filename52}53//find free and write new file54$f = fopen($fname, "w");55fwrite($f, $magic);56//Little-endian pack length and data57$urlen = strlen($url);58fwrite($f, pack('V', $urlen));59fwrite($f, $url);60$postdatalen = strlen($postdata);61fwrite($f, pack('V', $postdatalen));62fwrite($f, $postdata);63fclose($f);64//Initial query will be a GET and have a 12345 in it65}else if(strpos($url, "12345") !== FALSE){66readfile($tempdir."/init");67}686970