function curl_cache_exec($curl_opt, $proxy, $usecache = true) { if (!empty($curl_opt[CURLOPT_URL])) { $curl_opt = $curl_opt + buildCurlOptions($proxy); d('Curl', "GET " . $curl_opt[CURLOPT_URL] . " via " . proxyToString($proxy) . " (mem: " . debug_memory() . ")"); $cacheFile = CACHE_DIR . sha1($curl_opt[CURLOPT_URL]); if ($usecache && file_exists($cacheFile)) { //$cache_hto = intval(isset($options['general']['cache_lifetime']) ? $options['general']['cache_lifetime'] : 4); $cache_hto = CACHE_LIFETIME; // echo "DEBUG CACHE Now : ".time()." cacheFile: ". filemtime($cacheFile)." hto : ".($cache_hto*3600)."\n"; // HIT if (time() - filemtime($cacheFile) < $cache_hto * 3600) { $cacheData = @file_get_contents($cacheFile); if ($cacheData !== FALSE) { // use the cache $response['cache'] = true; $response['data'] = $cacheData; $response['status'] = 200; // we only cache 200, no problem $response['cache_age'] = time() - filemtime($cacheFile); $response['redir'] = null; $response['error'] = null; } d('Curl', "GOT status=200 cache=HIT age=" . $response['cache_age'] . " (mem: " . debug_memory() . ")"); return $response; } } $ch = curl_init(); curl_setopt_array($ch, $curl_opt); $data = curl_exec($ch); $response = array(); $response['cache'] = false; $response['data'] = $data; $response['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); $response['cache_age'] = 0; $response['redir'] = curl_getinfo($ch, CURLINFO_REDIRECT_URL); $response['error'] = curl_error($ch); curl_close($ch); // only cache 200 OK if ($usecache && $response['status'] == 200 && strlen($data) > 0) { // try to cache the stuff if (!file_exists(CACHE_DIR)) { @mkdir(CACHE_DIR); } @file_put_contents($cacheFile, $data); } d('Curl', "GOT status=" . $response['status'] . " cache=MISS age=0 (mem: " . debug_memory() . ")"); return $response; } return null; }
include 'inc/common.php'; header('Content-Type: text/plain'); if (isset($_POST['action'])) { switch ($_POST['action']) { case "is_running": $res = $db->query("SELECT 1 FROM `" . SQL_PREFIX . "run` WHERE ISNULL(dateStop)"); die(json_encode(array("running" => mysql_num_rows($res) > 0))); case "checkproxy": if (isset($_POST['id']) && is_numeric($_POST['id'])) { $query = "SELECT * FROM `" . SQL_PREFIX . "proxy` WHERE id = " . intval($_POST['id']); $result = $db->query($query); $proxy = mysql_fetch_assoc($result); if (!is_array($proxy)) { die(json_encode(array("result" => "no proxy with this id"))); } $opts = array(CURLOPT_URL => "http://revolt.vu.cx/") + buildCurlOptions($proxy); if (isset($_POST['to']) && is_numeric($_POST['to'])) { $opts[CURLOPT_TIMEOUT] = intval($_POST['to']); } $curl = curl_init(); curl_setopt_array($curl, $opts); $data = curl_exec($curl); $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($http_status != 200 || strstr($data, "Your IP:") === FALSE) { die(json_encode(array("result" => "error"))); } die(json_encode(array("result" => "ok"))); } break; case "deleteproxy": if (isset($_POST['id']) && is_array($_POST['id'])) {