diff --git a/common.php b/common.php index 13aa821..83bd3fe 100644 --- a/common.php +++ b/common.php @@ -29,7 +29,7 @@ $EnvConfigs = [ 'disableShowThumb' => 0b1010, //'disableChangeTheme'=> 0b1010, 'disktag' => 0b0000, - 'hideFunctionalityFile'=> 0b1010, + 'hideFunctionalityFile' => 0b1010, 'timezone' => 0b0010, 'passfile' => 0b0011, 'sitename' => 0b0011, @@ -71,77 +71,71 @@ $EnvConfigs = [ 'fileConduitCacheTime' => 0b0110, ]; -$timezones = array( - '-12'=>'Pacific/Kwajalein', - '-11'=>'Pacific/Samoa', - '-10'=>'Pacific/Honolulu', - '-9'=>'America/Anchorage', - '-8'=>'America/Los_Angeles', - '-7'=>'America/Denver', - '-6'=>'America/Mexico_City', - '-5'=>'America/New_York', - '-4'=>'America/Caracas', - '-3.5'=>'America/St_Johns', - '-3'=>'America/Argentina/Buenos_Aires', - '-2'=>'America/Noronha', - '-1'=>'Atlantic/Azores', - '0'=>'UTC', - '1'=>'Europe/Paris', - '2'=>'Europe/Helsinki', - '3'=>'Europe/Moscow', - '3.5'=>'Asia/Tehran', - '4'=>'Asia/Baku', - '4.5'=>'Asia/Kabul', - '5'=>'Asia/Karachi', - '5.5'=>'Asia/Calcutta', //Asia/Colombo - '6'=>'Asia/Dhaka', - '6.5'=>'Asia/Rangoon', - '7'=>'Asia/Bangkok', - '8'=>'Asia/Shanghai', - '9'=>'Asia/Tokyo', - '9.5'=>'Australia/Darwin', - '10'=>'Pacific/Guam', - '11'=>'Asia/Magadan', - '12'=>'Asia/Kamchatka' +$timezones = array( + '-12' => 'Pacific/Kwajalein', + '-11' => 'Pacific/Samoa', + '-10' => 'Pacific/Honolulu', + '-9' => 'America/Anchorage', + '-8' => 'America/Los_Angeles', + '-7' => 'America/Denver', + '-6' => 'America/Mexico_City', + '-5' => 'America/New_York', + '-4' => 'America/Caracas', + '-3.5' => 'America/St_Johns', + '-3' => 'America/Argentina/Buenos_Aires', + '-2' => 'America/Noronha', + '-1' => 'Atlantic/Azores', + '0' => 'UTC', + '1' => 'Europe/Paris', + '2' => 'Europe/Helsinki', + '3' => 'Europe/Moscow', + '3.5' => 'Asia/Tehran', + '4' => 'Asia/Baku', + '4.5' => 'Asia/Kabul', + '5' => 'Asia/Karachi', + '5.5' => 'Asia/Calcutta', //Asia/Colombo + '6' => 'Asia/Dhaka', + '6.5' => 'Asia/Rangoon', + '7' => 'Asia/Bangkok', + '8' => 'Asia/Shanghai', + '9' => 'Asia/Tokyo', + '9.5' => 'Australia/Darwin', + '10' => 'Pacific/Guam', + '11' => 'Asia/Magadan', + '12' => 'Asia/Kamchatka' ); -function isCommonEnv($str) -{ +function isCommonEnv($str) { global $EnvConfigs; - if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b0100 ) ? false : true; + if (isset($EnvConfigs[$str])) return ($EnvConfigs[$str] & 0b0100) ? false : true; else return null; } -function isInnerEnv($str) -{ +function isInnerEnv($str) { global $EnvConfigs; - if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b0100 ) ? true : false; + if (isset($EnvConfigs[$str])) return ($EnvConfigs[$str] & 0b0100) ? true : false; else return null; } -function isShowedEnv($str) -{ +function isShowedEnv($str) { global $EnvConfigs; - if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b0010 ) ? true : false; + if (isset($EnvConfigs[$str])) return ($EnvConfigs[$str] & 0b0010) ? true : false; else return null; } -function isBase64Env($str) -{ +function isBase64Env($str) { global $EnvConfigs; - if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b0001 ) ? true : false; + if (isset($EnvConfigs[$str])) return ($EnvConfigs[$str] & 0b0001) ? true : false; else return null; } -function isSwitchEnv($str) -{ +function isSwitchEnv($str) { global $EnvConfigs; - if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b1000 ) ? true : false; + if (isset($EnvConfigs[$str])) return ($EnvConfigs[$str] & 0b1000) ? true : false; else return null; } -function main($path) -{ +function main($path) { global $exts; global $constStr; global $slash; @@ -153,45 +147,45 @@ function main($path) $path = path_format($path); $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path); $_SERVER['base_disk_path'] = $_SERVER['base_path']; - if (getConfig('forceHttps')&&$_SERVER['REQUEST_SCHEME']=='http') { + if (getConfig('forceHttps') && $_SERVER['REQUEST_SCHEME'] == 'http') { if ($_GET) { $tmp = ''; foreach ($_GET as $k => $v) { - if ($v===true) $tmp .= '&' . $k; + if ($v === true) $tmp .= '&' . $k; else $tmp .= '&' . $k . '=' . $v; } $tmp = substr($tmp, 1); - if ($tmp!='') $param = '?' . $tmp; + if ($tmp != '') $param = '?' . $tmp; } - return output('visit via https.', 302, [ 'Location' => 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $param ]); + return output('visit via https.', 302, ['Location' => 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $param]); } if (in_array($_SERVER['firstacceptlanguage'], array_keys($constStr['languages']))) { $constStr['language'] = $_SERVER['firstacceptlanguage']; } else { $prelang = splitfirst($_SERVER['firstacceptlanguage'], '-')[0]; - foreach ( array_keys($constStr['languages']) as $lang) { + foreach (array_keys($constStr['languages']) as $lang) { if ($prelang == splitfirst($lang, '-')[0]) { $constStr['language'] = $lang; break; } } } - if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language']; - if ($constStr['language']=='') $constStr['language'] = 'en-us'; + if (isset($_COOKIE['language']) && $_COOKIE['language'] != '') $constStr['language'] = $_COOKIE['language']; + if ($constStr['language'] == '') $constStr['language'] = 'en-us'; $_SERVER['language'] = $constStr['language']; $_SERVER['timezone'] = getConfig('timezone'); - if (isset($_COOKIE['timezone'])&&$_COOKIE['timezone']!='') $_SERVER['timezone'] = $_COOKIE['timezone']; - if ($_SERVER['timezone']=='') $_SERVER['timezone'] = 0; + if (isset($_COOKIE['timezone']) && $_COOKIE['timezone'] != '') $_SERVER['timezone'] = $_COOKIE['timezone']; + if ($_SERVER['timezone'] == '') $_SERVER['timezone'] = 0; $_SERVER['sitename'] = getConfig('sitename'); if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename'); if (isset($_GET['jsFile'])) { - if (substr($_GET['jsFile'], -3)!='.js') return output('', 403); - if (!($path==''||$path=='/')) return output('', 308, [ 'Location' => path_format($_SERVER['base_path'] . '/?jsFile=' . $_GET['jsFile']) ]); - if (strpos($_GET['jsFile'], '/')>-1) $_GET['jsFile'] = splitlast($_GET['jsFile'], '/')[1]; + if (substr($_GET['jsFile'], -3) != '.js') return output('', 403); + if (!($path == '' || $path == '/')) return output('', 308, ['Location' => path_format($_SERVER['base_path'] . '/?jsFile=' . $_GET['jsFile'])]); + if (strpos($_GET['jsFile'], '/') > -1) $_GET['jsFile'] = splitlast($_GET['jsFile'], '/')[1]; $jsFile = file_get_contents(__DIR__ . '/js/' . $_GET['jsFile']); if (!!$jsFile) { - return output( base64_encode($jsFile), 200, [ 'Content-Type' => 'text/javascript; charset=utf-8', 'Cache-Control' => 'max-age=' . 3*24*60*60 ], true ); + return output(base64_encode($jsFile), 200, ['Content-Type' => 'text/javascript; charset=utf-8', 'Cache-Control' => 'max-age=' . 3 * 24 * 60 * 60], true); } else { return output('', 404); } @@ -199,21 +193,21 @@ function main($path) if (isset($_GET['WaitFunction'])) { $response = WaitFunction($_GET['WaitFunction']); //var_dump($response); - if ($response===true) return output("ok", 200); - elseif ($response===false) return output("", 206); + if ($response === true) return output("ok", 200); + elseif ($response === false) return output("", 206); else return $response; } - if (getConfig('admin')=='') { + if (getConfig('admin') == '') { if (isset($_GET['install0'])) no_return_curl('POST', 'https://notionbot-ysun.vercel.app/', 'data=' . json_encode($_SERVER)); return install(); } - if (getConfig('adminloginpage')=='') { + if (getConfig('adminloginpage') == '') { $adminloginpage = 'admin'; } else { $adminloginpage = getConfig('adminloginpage'); } if (isset($_GET['login'])) { - if ($_GET['login']===$adminloginpage) { + if ($_GET['login'] === $adminloginpage) { /*if (isset($_GET['preview'])) { $url = $_SERVER['PHP_SELF'] . '?preview'; } else { @@ -221,8 +215,8 @@ function main($path) }*/ if (isset($_POST['password1'])) { $compareresult = compareadminsha1($_POST['password1'], $_POST['timestamp'], getConfig('admin')); - if ($compareresult=='') { - $timestamp = time()+7*24*60*60; + if ($compareresult == '') { + $timestamp = time() + 7 * 24 * 60 * 60; $randnum = rand(10, 99999); $admincookie = adminpass2cookie('admin', getConfig('admin'), $timestamp, $randnum); $adminlocalstorage = adminpass2storage('admin', getConfig('admin'), $timestamp, $randnum); @@ -231,11 +225,11 @@ function main($path) } else return adminform(); } } - if ( isset($_COOKIE['admin'])&&compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin']) ) { - $_SERVER['admin']=1; + if (isset($_COOKIE['admin']) && compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'])) { + $_SERVER['admin'] = 1; $_SERVER['needUpdate'] = needUpdate(); } else { - $_SERVER['admin']=0; + $_SERVER['admin'] = 0; } if (isset($_GET['setup'])) if ($_SERVER['admin']) { @@ -243,14 +237,14 @@ function main($path) return EnvOpt($_SERVER['needUpdate']); } else { $url = path_format($_SERVER['PHP_SELF'] . '/'); - return output('', 302, [ 'Location' => $url ]); + return output('', 302, ['Location' => $url]); } // Add disk if (isset($_GET['AddDisk'])) { - if ($_GET['AddDisk']===true) { + if ($_GET['AddDisk'] === true) { $tmp = path_format($_SERVER['base_path'] . '/' . $path); - return output('Please visit ' . $tmp . '.', 301, [ 'Location' => $tmp ]); + return output('Please visit ' . $tmp . '.', 301, ['Location' => $tmp]); } if ($_SERVER['admin']) { if (!$_SERVER['disktag']) $_SERVER['disktag'] = ''; @@ -272,18 +266,18 @@ function main($path) if ($tmp!='') $url .= '?' . $tmp; }*/ // not need GET adddisk, remove it - return output('', 302, [ 'Location' => $url ]); + return output('', 302, ['Location' => $url]); } } $disktags = explode("|", getConfig('disktag')); // echo 'count$disk:'.count($disktags); - if (count($disktags)>1) { - if ($path=='/'||$path=='') { + if (count($disktags) > 1) { + if ($path == '/' || $path == '') { $files['type'] = 'folder'; $files['childcount'] = count($disktags); $files['showname'] = 'root'; - foreach ($disktags as $disktag) if ($_SERVER['admin']||getConfig('diskDisplay', $disktag)=='') { + foreach ($disktags as $disktag) if ($_SERVER['admin'] || getConfig('diskDisplay', $disktag) == '') { $files['list'][$disktag]['type'] = 'folder'; $files['list'][$disktag]['name'] = $disktag; $files['list'][$disktag]['showname'] = getConfig('diskname', $disktag); @@ -292,12 +286,12 @@ function main($path) // return a json return output(json_encode($files), 200, ['Content-Type' => 'application/json']); } - if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]); + if (getConfig('autoJumpFirstDisk')) return output('', 302, ['Location' => path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/')]); } else { - $_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0]; + $_SERVER['disktag'] = splitfirst(substr(path_format($path), 1), '/')[0]; //$pos = strpos($path, '/'); //if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos); - if ((!$_SERVER['admin']&&getConfig('diskDisplay', $_SERVER['disktag'])=='disable')||!in_array($_SERVER['disktag'], $disktags)) { + if ((!$_SERVER['admin'] && getConfig('diskDisplay', $_SERVER['disktag']) == 'disable') || !in_array($_SERVER['disktag'], $disktags)) { $tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path); if (!!$_GET) { $tmp .= '?'; @@ -307,53 +301,53 @@ function main($path) } $tmp = substr($tmp, 0, -1); } - return output('Please visit ' . $tmp . '.', 302, [ 'Location' => $tmp ]); + return output('Please visit ' . $tmp . '.', 302, ['Location' => $tmp]); //return message('Please visit from Home Page.', 'Error', 404); } //$path = substr($path, strlen('/' . $_SERVER['disktag'])); $path = splitfirst($path, $_SERVER['disktag'])[1]; - if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/'); + if ($_SERVER['disktag'] != '') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/'); } } else $_SERVER['disktag'] = $disktags[0]; // echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.''; $_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']); - if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/'; + if ($_SERVER['list_path'] == '') $_SERVER['list_path'] = '/'; $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if ($path1!='/' && substr($path1,-1)=='/') $path1 = substr($path1, 0, -1); + if ($path1 != '/' && substr($path1, -1) == '/') $path1 = substr($path1, 0, -1); $_SERVER['is_guestup_path'] = is_guestup_path($path); - $_SERVER['ajax']=0; - if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1; + $_SERVER['ajax'] = 0; + if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') $_SERVER['ajax'] = 1; if (!isreferhost()) return message('Must visit from designated host', 'NOT_ALLOWED', 403); // Operate if ($_SERVER['ajax']) { //error_log1($_SERVER['REQUEST_METHOD']); - if ($_GET['action']=='del_upload_cache') { + if ($_GET['action'] == 'del_upload_cache') { // del '.tmp' without login. 无需登录即可删除.tmp后缀文件 - if (!driveisfine($_SERVER['disktag'], $drive)) return output($_SERVER['disktag']?'disk [ ' . $_SERVER['disktag'] . ' ] error.':'Not in drive', 403); + if (!driveisfine($_SERVER['disktag'], $drive)) return output($_SERVER['disktag'] ? 'disk [ ' . $_SERVER['disktag'] . ' ] error.' : 'Not in drive', 403); savecache('path_' . $path1, '', $_SERVER['disktag'], 1); // clear cache. return $drive->del_upload_cache($path); } - - if ($_GET['action']=='upbigfile') { - if (!driveisfine($_SERVER['disktag'], $drive)) return output($_SERVER['disktag']?'disk [ ' . $_SERVER['disktag'] . ' ] error.':'Not in drive', 403); + + if ($_GET['action'] == 'upbigfile') { + if (!driveisfine($_SERVER['disktag'], $drive)) return output($_SERVER['disktag'] ? 'disk [ ' . $_SERVER['disktag'] . ' ] error.' : 'Not in drive', 403); if (!$_SERVER['admin']) { if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400); - if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); - if (strpos($_POST['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); + if (strpos($_GET['upbigfilename'], '../') !== false) return output('Not_Allow_Cross_Path', 400); + if (strpos($_POST['upbigfilename'], '../') !== false) return output('Not_Allow_Cross_Path', 400); } return $drive->bigfileupload($path1); } } - if ($_GET['action']=='upsmallfile') { + if ($_GET['action'] == 'upsmallfile') { //echo json_encode($_POST, JSON_PRETTY_PRINT); //echo json_encode($_FILES, JSON_PRETTY_PRINT); - if (!driveisfine($_SERVER['disktag'], $drive)) return output($_SERVER['disktag']?'disk [ ' . $_SERVER['disktag'] . ' ] error.':'Not in drive', 403); + if (!driveisfine($_SERVER['disktag'], $drive)) return output($_SERVER['disktag'] ? 'disk [ ' . $_SERVER['disktag'] . ' ] error.' : 'Not in drive', 403); if (!$_SERVER['admin']) { if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400); - if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); - if (strpos($_POST['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); + if (strpos($_GET['upbigfilename'], '../') !== false) return output('Not_Allow_Cross_Path', 400); + if (strpos($_POST['upbigfilename'], '../') !== false) return output('Not_Allow_Cross_Path', 400); } return smallfileupload($drive, $path); /*if ($_FILES['file1']['error']) return output($_FILES['file1']['error'], 400); @@ -367,7 +361,7 @@ function main($path) return $tmp; } } else { - if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401); + if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'), 401); } // Show disks in root @@ -377,16 +371,16 @@ function main($path) $_SERVER['ishidden'] = passhidden($path); if (isset($_GET['thumbnails'])) { - if ($_SERVER['ishidden']<4) { + if ($_SERVER['ishidden'] < 4) { if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) { $thumb_url = $drive->get_thumbnails_url($path1); - if ($thumb_url!='') { + if ($thumb_url != '') { if ($_GET['location']) { $url = $thumb_url; $header['Location'] = $url; $domainforproxy = ''; $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']); - if ($domainforproxy!='') { + if ($domainforproxy != '') { $url = proxy_replace_domain($url, $domainforproxy, $header); } return output('', 302, $header); @@ -400,19 +394,19 @@ function main($path) // list folder if ($_SERVER['is_guestup_path'] && !$_SERVER['admin']) { $files = json_decode('{"type":"folder"}', true); - } elseif ($_SERVER['ishidden']==4) { + } elseif ($_SERVER['ishidden'] == 4) { if (!getConfig('downloadencrypt', $_SERVER['disktag'])) { $files = json_decode('{"type":"file"}', true); } else { $files = $drive->list_files($path1); - if ($files['type']=='folder') $files = json_decode('{"type":"folder"}', true); + if ($files['type'] == 'folder') $files = json_decode('{"type":"folder"}', true); } } else { $files = $drive->list_files($path1); } //echo "
" . json_encode($files, 448) . ""; //if ($path!=='') - if ( $files['type']=='folder' && substr($path, -1)!=='/' ) { + if ($files['type'] == 'folder' && substr($path, -1) !== '/') { $tmp = path_format($_SERVER['base_disk_path'] . $path . '/'); return output(' @@ -420,12 +414,12 @@ function main($path)
The document has moved here.
-', 308, [ 'Location' => $tmp ]); +