diff --git a/common.php b/common.php index 121e18d..f12a28b 100644 --- a/common.php +++ b/common.php @@ -182,11 +182,15 @@ function main($path) if (isset($_POST['password1'])) { $compareresult = compareadminsha1($_POST['password1'], $_POST['timestamp'], getConfig('admin')); if ($compareresult=='') { - return adminform('admin', adminpass2cookie('admin', getConfig('admin')), $url); + $timestamp = time()+7*24*60*60; + $randnum = rand(10, 99999); + $admincookie = adminpass2cookie('admin', getConfig('admin'), $timestamp, $randnum); + $adminlocalstorage = adminpass2storage('admin', getConfig('admin'), $timestamp, $randnum); + return adminform('admin', $admincookie, $adminlocalstorage, $url); } else return adminform($compareresult); } else return adminform(); } - if ( isset($_COOKIE['admin'])&&compareadminmd5($_COOKIE['admin'], 'admin', getConfig('admin')) ) { + if ( isset($_COOKIE['admin'])&&compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin']) ) { $_SERVER['admin']=1; $_SERVER['needUpdate'] = needUpdate(); } else { @@ -394,6 +398,7 @@ function main($path) $url = $files['url']; if ( strtolower(splitlast($files['name'], '.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']); else { + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($files['time'])==strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) return output('', 304); $fileConduitSize = getConfig('fileConduitSize', $_SERVER['disktag']); $fileConduitCacheTime = getConfig('fileConduitCacheTime', $_SERVER['disktag']); if (!!$fileConduitSize || !!$fileConduitCacheTime) { @@ -401,10 +406,27 @@ function main($path) else $fileConduitSize = 1024*1024; if ($fileConduitCacheTime>1) $fileConduitCacheTime *= 3600; else $fileConduitCacheTime = 3600; + /*if ($_SERVER['HTTP_RANGE']!='') { + $header['Range'] = $_SERVER['HTTP_RANGE']; + $response = curl('GET', $files['url'], '', $header, 1); + //return output($header['Range'] . json_encode($response['returnhead'])); + return output( + $response['body'], + $response['stat'], + //$response['returnhead'], + ['Content-Type' => $files['mime'], 'Cache-Control' => 'max-age=' . $fileConduitCacheTime], + false + ); + }*/ if ($files['size']<$fileConduitSize) return output( base64_encode(file_get_contents($files['url'])), 200, - ['Content-Type' => $files['mime'], 'Cache-Control' => 'max-age=' . $fileConduitCacheTime], + [ + 'Content-Type' => $files['mime'], + 'Cache-Control' => 'max-age=' . $fileConduitCacheTime, + //'Cache-Control' => 'max-age=0', + 'Last-Modified' => gmdate('D, d M Y H:i:s T', strtotime($files['time'])) + ], true ); } @@ -482,20 +504,31 @@ function isreferhost() { return false; } -function adminpass2cookie($name, $pass) +function adminpass2cookie($name, $pass, $timestamp) { - $timestamp = time()+7*24*60*60; return md5($name . ':' . md5($pass) . '@' . $timestamp) . "(" . $timestamp . ")"; } -function compareadminmd5($admincookie, $name, $pass) +function adminpass2storage($name, $pass, $timestamp, $rand) { + return md5($timestamp . '/' . $pass . '^' . $name . '*' . $rand) . "(" . $rand . ")"; +} +function compareadminmd5($name, $pass, $cookie, $storage = 'default') { - $c = splitfirst($admincookie, '('); + $c = splitfirst($cookie, '('); $c_md5 = $c[0]; $c_time = substr($c[1], 0, -1); if (!is_numeric($c_time)) return false; if (time() > $c_time) return false; - if (md5($name . ':' . md5($pass) . '@' . $c_time) == $c_md5) return true; - else return false; + if ($storage == 'default') { + if (md5($name . ':' . md5($pass) . '@' . $c_time) == $c_md5) return true; + else return false; + } else { + $s = splitfirst($storage, '('); + $s_md5 = $s[0]; + $s_rand = substr($s[1], 0, -1); + if (md5($c_time . '/' . $pass . '^' . $name . '*' . $s_rand) == $s_md5) return true; + else return false; + } + return false; } function compareadminsha1($adminsha1, $timestamp, $pass) @@ -720,6 +753,7 @@ function curl($method, $url, $data = '', $headers = [], $returnheader = 0, $loca //$response['body'] = curl_exec($ch); if ($returnheader) { list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch)); + //echo "HEAD:" . $returnhead; foreach (explode("\r\n", $returnhead) as $head) { $tmp = explode(': ', $head); $heads[$tmp[0]] = $tmp[1]; @@ -971,15 +1005,19 @@ function time_format($ISO) return date('Y-m-d H:i:s',strtotime($ISO . " UTC")); } -function adminform($name = '', $pass = '', $path = '') +function adminform($name = '', $pass = '', $storage = '', $path = '') { $html = '