OneManager-php/common.php

2890 lines
128 KiB
PHP
Raw Normal View History

2020-01-18 12:12:21 +00:00
<?php
2020-08-16 03:37:28 +00:00
global $timezones;
2021-01-15 03:10:08 +00:00
global $slash;
global $drive;
global $EnvConfigs;
$EnvConfigs = [
// 1 inner, 0 common
// 1 showed/enableEdit, 0 hidden/disableEdit
// 1 base64 to save, 0 not base64
'APIKey' => 0b000, // used in heroku.
2021-03-01 09:38:15 +00:00
'SecretId' => 0b000, // used in SCF/CFC.
'SecretKey' => 0b000, // used in SCF/CFC.
2021-01-15 03:10:08 +00:00
'AccessKeyID' => 0b000, // used in FC.
'AccessKeySecret' => 0b000, // used in FC.
'HW_urn' => 0b000, // used in FG.
'HW_key' => 0b000, // used in FG.
'HW_secret' => 0b000, // used in FG.
2021-03-01 09:38:15 +00:00
'HerokuappId' => 0b000, // used in heroku.
2021-01-15 03:10:08 +00:00
2021-01-15 03:18:42 +00:00
'admin' => 0b000,
2021-01-15 03:10:08 +00:00
'adminloginpage' => 0b010,
'autoJumpFirstDisk' => 0b010,
'background' => 0b011,
'backgroundm' => 0b011,
'disableShowThumb' => 0b010,
//'disableChangeTheme'=> 0b010,
2021-01-15 03:10:08 +00:00
'disktag' => 0b000,
'hideFunctionalityFile'=> 0b010,
'timezone' => 0b010,
'passfile' => 0b011,
'sitename' => 0b011,
'customScript' => 0b011,
'customCss' => 0b011,
'customTheme' => 0b011,
'theme' => 0b010,
2021-08-09 04:27:25 +00:00
'useBasicAuth' => 0b010,
2021-02-23 09:20:19 +00:00
'referrer' => 0b011,
2021-05-12 08:35:34 +00:00
'forceHttps' => 0b010,
2021-01-15 03:10:08 +00:00
'Driver' => 0b100,
'client_id' => 0b100,
'client_secret' => 0b101,
'sharepointSite' => 0b101,
'shareurl' => 0b101,
//'sharecookie' => 0b101,
'shareapiurl' => 0b101,
'siteid' => 0b100,
'refresh_token' => 0b100,
'token_expires' => 0b100,
2021-03-06 07:51:04 +00:00
'activeLimit' => 0b100,
2021-03-13 05:49:46 +00:00
'driveId' => 0b100,
2021-01-18 07:59:39 +00:00
'diskname' => 0b111,
2021-03-01 09:38:15 +00:00
'diskDescription' => 0b111,
2021-01-18 07:59:39 +00:00
'domain_path' => 0b111,
'downloadencrypt' => 0b110,
'guestup_path' => 0b111,
'domainforproxy' => 0b111,
'public_path' => 0b111,
2021-09-08 10:07:03 +00:00
'fileConduitSize' => 0b110,
'fileConduitCacheTime' => 0b110,
2020-02-20 04:07:51 +00:00
];
2020-04-05 06:32:23 +00:00
$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'
);
2021-01-15 03:10:08 +00:00
function isCommonEnv($str)
{
global $EnvConfigs;
if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b100 ) ? false : true;
else return null;
}
function isInnerEnv($str)
{
global $EnvConfigs;
if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b100 ) ? true : false;
else return null;
}
function isShowedEnv($str)
{
global $EnvConfigs;
if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b010 ) ? true : false;
else return null;
}
function isBase64Env($str)
{
global $EnvConfigs;
if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b001 ) ? true : false;
else return null;
}
function main($path)
{
global $exts;
global $constStr;
2021-01-15 03:10:08 +00:00
global $slash;
global $drive;
2021-01-15 03:10:08 +00:00
$slash = '/';
if (strpos(__DIR__, ':')) $slash = '\\';
2020-05-14 10:05:43 +00:00
$_SERVER['php_starttime'] = microtime(true);
2020-05-11 05:11:07 +00:00
$path = path_format($path);
2021-05-12 08:35:34 +00:00
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
if (getConfig('forceHttps')&&$_SERVER['REQUEST_SCHEME']=='http') {
if ($_GET) {
$tmp = '';
foreach ($_GET as $k => $v) {
if ($v===true) $tmp .= '&' . $k;
else $tmp .= '&' . $k . '=' . $v;
}
$tmp = substr($tmp, 1);
if ($tmp!='') $param = '?' . $tmp;
}
return output('visit via https.', 302, [ 'Location' => 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $param ]);
}
2020-04-04 05:50:29 +00:00
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) {
if ($prelang == splitfirst($lang, '-')[0]) {
$constStr['language'] = $lang;
break;
}
}
}
2020-04-02 10:18:08 +00:00
if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language'];
if ($constStr['language']=='') $constStr['language'] = 'en-us';
$_SERVER['language'] = $constStr['language'];
2020-04-05 05:45:28 +00:00
$_SERVER['timezone'] = getConfig('timezone');
if (isset($_COOKIE['timezone'])&&$_COOKIE['timezone']!='') $_SERVER['timezone'] = $_COOKIE['timezone'];
if ($_SERVER['timezone']=='') $_SERVER['timezone'] = 0;
if (getConfig('admin')=='') return install();
if (getConfig('adminloginpage')=='') {
$adminloginpage = 'admin';
} else {
$adminloginpage = getConfig('adminloginpage');
}
if (isset($_GET[$adminloginpage])) {
if (isset($_GET['preview'])) {
$url = $_SERVER['PHP_SELF'] . '?preview';
} else {
$url = path_format($_SERVER['PHP_SELF'] . '/');
}
2021-03-11 10:48:43 +00:00
if (isset($_POST['password1'])) {
$compareresult = compareadminsha1($_POST['password1'], $_POST['timestamp'], getConfig('admin'));
if ($compareresult=='') {
2021-10-06 08:01:31 +00:00
$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);
2021-03-11 10:48:43 +00:00
} else return adminform($compareresult);
} else return adminform();
}
2021-10-06 08:01:31 +00:00
if ( isset($_COOKIE['admin'])&&compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin']) ) {
$_SERVER['admin']=1;
$_SERVER['needUpdate'] = needUpdate();
} else {
$_SERVER['admin']=0;
}
if (isset($_GET['setup']))
if ($_SERVER['admin']) {
// setup Environments. 设置,对环境变量操作
return EnvOpt($_SERVER['needUpdate']);
} else {
$url = path_format($_SERVER['PHP_SELF'] . '/');
return output('<script>alert(\''.getconstStr('SetSecretsFirst').'\');</script>', 302, [ 'Location' => $url ]);
}
2021-08-17 11:51:17 +00:00
if (isset($_GET['WaitFunction'])) {
$response = WaitFunction($_GET['WaitFunction']);
//var_dump($response);
if ($response===true) return output("ok", 200);
elseif ($response===false) return output("", 206);
else return $response;
}
2020-08-04 06:38:20 +00:00
$_SERVER['sitename'] = getConfig('sitename');
if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
$_SERVER['base_disk_path'] = $_SERVER['base_path'];
$disktags = explode("|", getConfig('disktag'));
// echo 'count$disk:'.count($disktags);
if (count($disktags)>1) {
2020-08-04 06:38:20 +00:00
if ($path=='/'||$path=='') {
2021-01-15 03:10:08 +00:00
$files['type'] = 'folder';
$files['childcount'] = count($disktags);
$files['showname'] = 'root';
2020-08-17 09:31:51 +00:00
foreach ($disktags as $disktag) {
2021-01-15 03:10:08 +00:00
$files['list'][$disktag]['type'] = 'folder';
$files['list'][$disktag]['name'] = $disktag;
$files['list'][$disktag]['showname'] = getConfig('diskname', $disktag);
2020-08-17 09:31:51 +00:00
}
2020-08-04 06:38:20 +00:00
if ($_GET['json']) {
// return a json
2021-01-16 04:27:41 +00:00
return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
2020-08-17 09:31:51 +00:00
}
2021-01-16 04:27:41 +00:00
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
} else {
$_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
//$pos = strpos($path, '/');
//if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
if (!in_array($_SERVER['disktag'], $disktags)) {
$tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path);
if (!!$_GET) {
$tmp .= '?';
foreach ($_GET as $k => $v) {
if ($v === true) $tmp .= $k . '&';
else $tmp .= $k . '=' . $v . '&';
}
$tmp = substr($tmp, 0, -1);
}
return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 302, [ 'Location' => $tmp ]);
//return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404);
}
$path = substr($path, strlen('/' . $_SERVER['disktag']));
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
2020-05-11 05:11:07 +00:00
}
} 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'] = '/';
$_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;
2021-01-15 03:10:08 +00:00
// Add disk
if (isset($_GET['AddDisk'])) {
if ($_SERVER['admin']) {
if (!class_exists($_GET['AddDisk'])) require 'disk' . $slash . $_GET['AddDisk'] . '.php';
2021-01-17 10:57:26 +00:00
$drive = new $_GET['AddDisk']($_GET['disktag']);
2021-01-15 03:10:08 +00:00
return $drive->AddDisk();
} else {
$url = $_SERVER['PHP_SELF'];
if ($_GET) {
$tmp = null;
$tmp = '';
foreach ($_GET as $k => $v) {
if ($k!='setup') {
if ($v===true) $tmp .= '&' . $k;
else $tmp .= '&' . $k . '=' . $v;
}
}
2021-01-15 03:10:08 +00:00
$tmp = substr($tmp, 1);
if ($tmp!='') $url .= '?' . $tmp;
}
2021-01-15 03:10:08 +00:00
return output('<script>alert(\''.getconstStr('SetSecretsFirst').'\');</script>', 302, [ 'Location' => $url ]);
}
2021-01-15 03:10:08 +00:00
}
2021-02-23 09:20:19 +00:00
if (!isreferhost()) return message('Must visit from designated host', 'NOT_ALLOWED', 403);
2021-01-15 03:10:08 +00:00
// Show disks in root
if ($files['showname'] == 'root') return render_list($path, $files);
2021-01-15 11:24:14 +00:00
if (!driveisfine($_SERVER['disktag'], $drive)) return render_list();
2021-01-15 03:10:08 +00:00
// Operate
if ($_SERVER['ajax']) {
if ($_GET['action']=='del_upload_cache') {
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件
2021-01-16 04:18:19 +00:00
return $drive->del_upload_cache($path);
}
2021-01-15 03:10:08 +00:00
if ($_GET['action']=='upbigfile') {
if (!$_SERVER['admin']) {
2021-01-17 03:33:05 +00:00
if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400);
2021-01-15 03:10:08 +00:00
if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400);
2021-03-13 05:49:46 +00:00
if (strpos($_POST['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400);
2021-01-15 03:10:08 +00:00
}
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
return $drive->bigfileupload($path1);
}
2021-01-15 03:10:08 +00:00
}
2021-08-17 11:51:17 +00:00
2021-01-15 03:10:08 +00:00
if ($_SERVER['admin']) {
$tmp = adminoperate($path);
if ($tmp['statusCode'] > 0) {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
2021-02-25 10:29:13 +00:00
if ($path1!='/'&&substr($path1,-1)=='/') $path1 = substr($path1, 0, -1);
savecache('path_' . $path1, '', $_SERVER['disktag'], 1);
2021-01-15 03:10:08 +00:00
return $tmp;
}
2021-01-15 03:10:08 +00:00
} else {
if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401);
}
$_SERVER['ishidden'] = passhidden($path);
if (isset($_GET['thumbnails'])) {
if ($_SERVER['ishidden']<4) {
if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
$thumb_url = $drive->get_thumbnails_url($path1);
if ($thumb_url!='') {
if ($_GET['location']) {
$url = $thumb_url;
2021-05-12 08:35:34 +00:00
$header['Location'] = $url;
2021-01-15 03:10:08 +00:00
$domainforproxy = '';
$domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']);
if ($domainforproxy!='') {
2021-05-12 08:35:34 +00:00
$url = proxy_replace_domain($url, $domainforproxy, $header);
2021-01-15 03:10:08 +00:00
}
2021-05-12 08:35:34 +00:00
return output('', 302, $header);
2021-01-15 03:10:08 +00:00
} else return output($thumb_url);
}
2021-01-15 03:10:08 +00:00
return output('', 404);
} else return output(json_encode($exts['img']), 400);
} else return output('', 401);
}
// list folder
if ($_SERVER['is_guestup_path'] && !$_SERVER['admin']) {
$files = json_decode('{"type":"folder"}', true);
} elseif ($_SERVER['ishidden']==4) {
if (!getConfig('downloadencrypt', $_SERVER['disktag'])) {
$files = json_decode('{"type":"folder"}', true);
} else {
2021-01-15 03:10:08 +00:00
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1);
$files = $drive->list_files($path1);
if ($files['type']=='folder') $files = json_decode('{"type":"folder"}', true);
2021-01-17 05:13:37 +00:00
}
2021-01-15 03:10:08 +00:00
} else {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1);
$files = $drive->list_files($path1);
}
if ($_GET['json']) {
// return a json
2021-06-23 08:11:13 +00:00
if ($files['type']=='folder' && !$_SERVER['admin']) {
foreach ($files['list'] as $k => $v) {
if (isHideFile($k)) unset($files['list'][$k]);
}
}
2021-01-16 04:27:41 +00:00
return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
2021-01-15 03:10:08 +00:00
}
// random file
if (isset($_GET['random'])&&$_GET['random']!=='') {
if ($_SERVER['ishidden']<4) {
$tmp = [];
foreach (array_keys($files['list']) as $filename) {
if (strtolower(splitlast($filename, '.')[1])==strtolower($_GET['random'])) $tmp[$filename] = $files['list'][$filename]['url'];
}
$tmp = array_values($tmp);
if (count($tmp)>0) {
$url = $tmp[rand(0, count($tmp)-1)];
if (isset($_GET['url'])) return output($url, 200);
2021-05-12 08:35:34 +00:00
$header['Location'] = $url;
$domainforproxy = '';
2021-01-15 03:10:08 +00:00
$domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']);
if ($domainforproxy!='') {
2021-05-12 08:35:34 +00:00
$url = proxy_replace_domain($url, $domainforproxy, $header);
}
2021-05-12 08:35:34 +00:00
return output('', 302, $header);
2021-01-15 03:10:08 +00:00
} else return output('No ' . $_GET['random'] . 'file', 404);
} else return output('Hidden', 401);
}
// is file && not preview mode, download file
if ($files['type']=='file' && !isset($_GET['preview'])) {
if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt', $_SERVER['disktag'])&&$files['name']!=getConfig('passfile')) ) {
$url = $files['url'];
if ( strtolower(splitlast($files['name'], '.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']);
else {
2021-10-06 08:01:31 +00:00
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($files['time'])==strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) return output('', 304);
2021-09-08 10:07:03 +00:00
$fileConduitSize = getConfig('fileConduitSize', $_SERVER['disktag']);
$fileConduitCacheTime = getConfig('fileConduitCacheTime', $_SERVER['disktag']);
if (!!$fileConduitSize || !!$fileConduitCacheTime) {
if ($fileConduitSize>1) $fileConduitSize *= 1024*1024;
else $fileConduitSize = 1024*1024;
if ($fileConduitCacheTime>1) $fileConduitCacheTime *= 3600;
else $fileConduitCacheTime = 3600;
2021-10-06 08:01:31 +00:00
/*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
);
}*/
2021-09-08 10:07:03 +00:00
if ($files['size']<$fileConduitSize) return output(
2021-09-08 05:03:36 +00:00
base64_encode(file_get_contents($files['url'])),
200,
2021-10-06 08:01:31 +00:00
[
'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']))
],
2021-09-08 05:03:36 +00:00
true
);
}
2021-01-15 03:10:08 +00:00
if ($_SERVER['HTTP_RANGE']!='') $header['Range'] = $_SERVER['HTTP_RANGE'];
$header['Location'] = $url;
2021-05-12 08:35:34 +00:00
$domainforproxy = '';
$domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']);
if ($domainforproxy!='') {
$url = proxy_replace_domain($url, $domainforproxy, $header);
}
2021-01-15 03:10:08 +00:00
return output('', 302, $header);
}
}
}
2021-01-15 03:10:08 +00:00
// Show folder
if ( $files['type']=='folder' || $files['type']=='file' ) {
return render_list($path, $files);
} else {
if (!isset($files['error'])) {
if (is_array($files)) $files['error']['message'] = json_encode($files, JSON_PRETTY_PRINT);
else $files['error']['message'] = $files;
$files['error']['code'] = 'unknownError';
$files['error']['stat'] = 500;
}
2021-02-25 10:29:13 +00:00
return message('<div style="margin:8px;"><pre>' . $files['error']['message'] . '</pre></div><a href="javascript:history.back(-1)">'.getconstStr('Back').'</a>', $files['error']['code'], $files['error']['stat']);
2021-01-15 03:10:08 +00:00
}
}
function get_content($path)
{
global $drive;
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1);
$file = $drive->list_files($path1);
//var_dump($file);
return $file;
}
2021-01-15 11:24:14 +00:00
function driveisfine($tag, &$drive = null)
2021-01-15 03:10:08 +00:00
{
global $slash;
$disktype = getConfig('Driver', $tag);
if (!$disktype) return false;
if (!class_exists($disktype)) require 'disk' . $slash . $disktype . '.php';
$drive = new $disktype($tag);
if ($drive->isfine()) return true;
else return false;
}
2021-01-17 10:57:26 +00:00
function baseclassofdrive($d = null)
2021-01-15 03:10:08 +00:00
{
global $drive;
2021-01-17 10:57:26 +00:00
if (!$d) $dr = $drive;
else $dr = $d;
if (!$dr) return false;
return $dr->show_base_class();
}
function extendShow_diskenv($drive)
{
2021-01-18 07:04:42 +00:00
if (!$drive) return [];
2021-01-17 10:57:26 +00:00
return $drive->ext_show_innerenv();
}
2021-02-23 09:20:19 +00:00
function isreferhost() {
$referer = $_SERVER['referhost'];
if ($referer=='') return true;
if ($referer==$_SERVER['HTTP_HOST']) return true;
$referrer = getConfig('referrer');
if ($referrer=='') return true;
$arr = explode('|', $referrer);
foreach ($arr as $host) {
if ($host == $referer) return true;
}
return false;
}
2021-10-06 08:01:31 +00:00
function adminpass2cookie($name, $pass, $timestamp)
2020-08-21 08:44:55 +00:00
{
2021-03-09 08:04:19 +00:00
return md5($name . ':' . md5($pass) . '@' . $timestamp) . "(" . $timestamp . ")";
}
2021-10-06 08:01:31 +00:00
function adminpass2storage($name, $pass, $timestamp, $rand) {
return md5($timestamp . '/' . $pass . '^' . $name . '*' . $rand) . "(" . $rand . ")";
}
function compareadminmd5($name, $pass, $cookie, $storage = 'default')
2021-03-09 08:04:19 +00:00
{
2021-10-06 08:01:31 +00:00
$c = splitfirst($cookie, '(');
2021-03-09 08:04:19 +00:00
$c_md5 = $c[0];
$c_time = substr($c[1], 0, -1);
if (!is_numeric($c_time)) return false;
if (time() > $c_time) return false;
2021-10-06 08:01:31 +00:00
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;
2021-03-09 08:04:19 +00:00
}
2021-05-12 08:35:34 +00:00
2021-03-09 08:04:19 +00:00
function compareadminsha1($adminsha1, $timestamp, $pass)
{
2021-03-11 10:48:43 +00:00
if (!is_numeric($timestamp)) return 'Timestamp not Number';
2021-03-11 12:01:49 +00:00
if (abs(time()-$timestamp) > 5*60) {
date_default_timezone_set('UTC');
2021-03-13 05:49:46 +00:00
return 'The timestamp in server is ' . time() . ' (' . date("Y-m-d H:i:s") . ' UTC),<br>and your posted timestamp is ' . $timestamp . ' (' . date("Y-m-d H:i:s", $timestamp) . ' UTC)';
2021-03-11 12:01:49 +00:00
}
2021-03-11 10:48:43 +00:00
if ($adminsha1 == sha1($timestamp . $pass)) return '';
else return 'Error password';
2020-08-21 08:44:55 +00:00
}
2021-05-12 08:35:34 +00:00
function proxy_replace_domain($url, $domainforproxy, &$header)
{
2021-05-12 08:35:34 +00:00
global $drive;
$tmp = splitfirst($url, '//');
$http = $tmp[0];
$tmp = splitfirst($tmp[1], '/');
$domain = $tmp[0];
$uri = $tmp[1];
if (substr($domainforproxy, 0, 7)=='http://' || substr($domainforproxy, 0, 8)=='https://') $aim = $domainforproxy;
else $aim = $http . '//' . $domainforproxy;
if (substr($aim, -1)=='/') $aim = substr($aim, 0, -1);
2021-05-12 08:35:34 +00:00
//$header['Location'] = $aim . '/' . $uri;
//return $aim . '/' . $uri;
2021-03-01 09:38:15 +00:00
if (strpos($url, '?')>0) $sp = '&';
else $sp = '?';
2021-05-12 08:35:34 +00:00
$aim .= '/' . $uri . $sp . 'Origindomain=' . $domain;
if ($drive->show_base_class()=='Aliyundrive') $aim .= '&Aliyundrive';
$header['Location'] = $aim;
2021-03-01 09:38:15 +00:00
return $aim . '/' . $uri . $sp . 'Origindomain=' . $domain;
}
2020-03-17 03:39:16 +00:00
function isHideFile($name)
{
$FunctionalityFile = [
'head.md',
'readme.md',
2020-05-03 10:17:18 +00:00
'head.omf',
'foot.omf',
2020-03-17 03:39:16 +00:00
'favicon.ico',
2021-05-12 08:35:34 +00:00
'robots.txt',
2020-05-03 10:17:18 +00:00
'index.html',
2020-03-17 03:39:16 +00:00
];
if ($name == getConfig('passfile')) return true;
if (substr($name,0,1) == '.') return true;
if (getConfig('hideFunctionalityFile')) if (in_array(strtolower($name), $FunctionalityFile)) return true;
return false;
}
2020-09-15 07:00:19 +00:00
function getcache($str, $disktag = '')
2020-01-18 12:12:21 +00:00
{
2020-09-15 07:00:19 +00:00
$cache = filecache($disktag);
2020-01-18 12:12:21 +00:00
return $cache->fetch($str);
}
2020-09-15 07:00:19 +00:00
function savecache($key, $value, $disktag = '', $exp = 1800)
2020-01-18 12:12:21 +00:00
{
2020-09-15 07:00:19 +00:00
$cache = filecache($disktag);
2020-08-17 08:26:22 +00:00
return $cache->save($key, $value, $exp);
}
2020-09-15 07:00:19 +00:00
function filecache($disktag)
2020-08-17 08:26:22 +00:00
{
$dir = sys_get_temp_dir();
if (!is_writable($dir)) {
$tmp = __DIR__ . '/tmp/';
if (file_exists($tmp)) {
if ( is_writable($tmp) ) $dir = $tmp;
} elseif ( mkdir($tmp) ) $dir = $tmp;
2020-08-17 08:26:22 +00:00
}
2020-09-15 07:00:19 +00:00
$tag = __DIR__ . '/OneManager/' . $disktag;
2020-08-17 08:26:22 +00:00
while (strpos($tag, '/')>-1) $tag = str_replace('/', '_', $tag);
2020-08-18 07:48:32 +00:00
if (strpos($tag, ':')>-1) {
2020-09-15 07:00:19 +00:00
$tag = str_replace(':', '_', $tag);
$tag = str_replace('\\', '_', $tag);
2020-08-18 07:48:32 +00:00
}
// error_log1('DIR:' . $dir . ' TAG: ' . $tag);
2020-08-17 08:26:22 +00:00
$cache = new \Doctrine\Common\Cache\FilesystemCache($dir, $tag);
return $cache;
2020-01-18 12:12:21 +00:00
}
2021-01-15 03:10:08 +00:00
function sortConfig(&$arr)
2020-01-18 12:12:21 +00:00
{
2021-01-15 03:10:08 +00:00
ksort($arr);
2020-01-18 12:12:21 +00:00
2021-01-15 03:10:08 +00:00
$tags = explode('|', $arr['disktag']);
unset($arr['disktag']);
if ($tags[0]!='') {
foreach($tags as $tag) {
$disks[$tag] = $arr[$tag];
unset($arr[$tag]);
}
$arr['disktag'] = implode('|', $tags);
foreach($disks as $k => $v) {
$arr[$k] = $v;
}
}
2021-01-15 03:10:08 +00:00
return $arr;
2020-01-18 12:12:21 +00:00
}
2021-01-15 03:10:08 +00:00
function getconstStr($str)
2020-03-25 16:03:35 +00:00
{
2021-01-15 03:10:08 +00:00
global $constStr;
if ($constStr[$str][$constStr['language']]!='') return $constStr[$str][$constStr['language']];
return $constStr[$str]['en-us'];
2020-03-25 16:03:35 +00:00
}
2020-01-18 12:12:21 +00:00
function getListpath($domain)
{
2021-01-15 03:10:08 +00:00
$domain_path1 = getConfig('domain_path', $_SERVER['disktag']);
$public_path = getConfig('public_path', $_SERVER['disktag']);
2020-01-20 05:23:52 +00:00
$tmp_path='';
if ($domain_path1!='') {
$tmp = explode("|",$domain_path1);
2020-01-18 12:12:21 +00:00
foreach ($tmp as $multidomain_paths){
$pos = strpos($multidomain_paths,":");
2020-01-20 10:47:08 +00:00
if ($pos>0) {
$domain1 = substr($multidomain_paths,0,$pos);
$tmp_path = path_format(substr($multidomain_paths,$pos+1));
$domain_path[$domain1] = $tmp_path;
if ($public_path=='') $public_path = $tmp_path;
2020-01-20 05:23:52 +00:00
//if (substr($multidomain_paths,0,$pos)==$host_name) $private_path=$tmp_path;
2020-01-20 10:47:08 +00:00
}
2020-01-18 12:12:21 +00:00
}
2020-01-20 05:23:52 +00:00
}
2020-01-18 12:12:21 +00:00
if (isset($domain_path[$domain])) return spurlencode($domain_path[$domain],'/');
2021-02-23 09:20:19 +00:00
return spurlencode($public_path, '/');
2020-01-18 12:12:21 +00:00
}
function path_format($path)
{
$path = '/' . $path;
while (strpos($path, '//') !== FALSE) {
$path = str_replace('//', '/', $path);
}
return $path;
}
function spurlencode($str, $split='')
2020-01-18 12:12:21 +00:00
{
2021-01-15 03:10:08 +00:00
$str = str_replace(' ', '%20', $str);
2020-01-18 12:12:21 +00:00
$tmp='';
2020-02-22 08:52:38 +00:00
if ($split!='') {
$tmparr=explode($split, $str);
foreach ($tmparr as $str1) {
$tmp .= urlencode($str1) . $split;
2020-01-18 12:12:21 +00:00
}
2021-01-15 03:10:08 +00:00
$tmp = substr($tmp, 0, strlen($tmp)-strlen($split));
2020-01-18 12:12:21 +00:00
} else {
$tmp = urlencode($str);
}
2021-01-15 03:10:08 +00:00
$tmp = str_replace('%2520', '%20', $tmp);
$tmp = str_replace('%26amp%3B', '&', $tmp);
2020-01-18 12:12:21 +00:00
return $tmp;
}
function base64y_encode($str)
{
$str = base64_encode($str);
while (substr($str,-1)=='=') $str=substr($str,0,-1);
while (strpos($str, '+')!==false) $str = str_replace('+', '-', $str);
while (strpos($str, '/')!==false) $str = str_replace('/', '_', $str);
return $str;
}
function base64y_decode($str)
{
while (strpos($str, '_')!==false) $str = str_replace('_', '/', $str);
while (strpos($str, '-')!==false) $str = str_replace('-', '+', $str);
while (strlen($str)%4) $str .= '=';
$str = base64_decode($str);
2021-01-15 03:10:08 +00:00
//if (strpos($str, '%')!==false) $str = urldecode($str);
2020-02-20 04:07:51 +00:00
return $str;
}
function error_log1($str)
{
error_log($str);
}
2020-01-18 12:12:21 +00:00
function is_guestup_path($path)
{
2021-01-15 03:10:08 +00:00
if (getConfig('guestup_path', $_SERVER['disktag'])!='') {
$a1 = path_format(path_format(urldecode($_SERVER['list_path'].path_format($path))).'/');
$a2 = path_format(path_format(getConfig('guestup_path', $_SERVER['disktag'])).'/');
if (strtolower($a1)==strtolower($a2)) return 1;
}
2020-01-18 12:12:21 +00:00
return 0;
}
2020-02-15 08:53:15 +00:00
function array_value_isnot_null($arr)
{
return $arr!=='';
}
2021-03-01 09:38:15 +00:00
function curl($method, $url, $data = '', $headers = [], $returnheader = 0, $location = 0)
2020-08-16 03:37:28 +00:00
{
//if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
//if (!isset($headers['Referer'])) $headers['Referer'] = $url;
//if (!isset($headers['Content-Type'])) $headers['Content-Type'] = 'application/x-www-form-urlencoded';
2021-03-01 09:38:15 +00:00
if (!isset($headers['Content-Type'])&&!isset($headers['content-type'])) $headers['Content-Type'] = '';
2020-08-16 03:37:28 +00:00
$sendHeaders = array();
foreach ($headers as $headerName => $headerVal) {
$sendHeaders[] = $headerName . ': ' . $headerVal;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, $returnheader);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
2021-03-01 09:38:15 +00:00
if ($location) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
2020-08-16 03:37:28 +00:00
//$response['body'] = curl_exec($ch);
if ($returnheader) {
list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch));
2021-10-06 08:01:31 +00:00
//echo "HEAD:" . $returnhead;
2020-08-16 03:37:28 +00:00
foreach (explode("\r\n", $returnhead) as $head) {
$tmp = explode(': ', $head);
$heads[$tmp[0]] = $tmp[1];
}
$response['returnhead'] = $heads;
} else {
$response['body'] = curl_exec($ch);
}
$response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
return $response;
}
2020-01-18 12:12:21 +00:00
function clearbehindvalue($path,$page1,$maxpage,$pageinfocache)
{
for ($page=$page1+1;$page<$maxpage;$page++) {
$pageinfocache['nextlink_' . $path . '_page_' . $page] = '';
}
2020-02-15 08:53:15 +00:00
$pageinfocache = array_filter($pageinfocache, 'array_value_isnot_null');
2020-01-18 12:12:21 +00:00
return $pageinfocache;
}
function comppass($pass)
{
if ($_POST['password1'] !== '') if (md5($_POST['password1']) === $pass ) {
date_default_timezone_set('UTC');
$_SERVER['Set-Cookie'] = 'password='.$pass.'; expires='.date(DATE_COOKIE,strtotime('+1hour'));
2020-04-05 05:45:28 +00:00
date_default_timezone_set(get_timezone($_SERVER['timezone']));
2020-01-18 12:12:21 +00:00
return 2;
}
if ($_COOKIE['password'] !== '') if ($_COOKIE['password'] === $pass ) return 3;
2021-08-09 04:27:25 +00:00
if (getConfig('useBasicAuth')) {
2021-01-17 03:33:05 +00:00
// use Basic Auth
//$_SERVER['PHP_AUTH_USER']
if ($_SERVER['PHP_AUTH_PW'] !== '') if (md5($_SERVER['PHP_AUTH_PW']) === $pass ) {
date_default_timezone_set('UTC');
$_SERVER['Set-Cookie'] = 'password='.$pass.'; expires='.date(DATE_COOKIE,strtotime('+1hour'));
date_default_timezone_set(get_timezone($_SERVER['timezone']));
return 2;
}
}
2020-01-18 12:12:21 +00:00
return 4;
}
function encode_str_replace($str)
{
2021-03-07 15:07:54 +00:00
$str = str_replace('%','%25',$str);
2021-05-16 12:12:17 +00:00
if (strpos($str, '&amp;')) $str = str_replace('&amp;', '&amp;amp;', $str);
2020-01-18 12:12:21 +00:00
$str = str_replace('+','%2B',$str);
$str = str_replace('#','%23',$str);
return $str;
}
function gethiddenpass($path,$passfile)
{
2020-03-03 07:17:38 +00:00
$path1 = path_format($_SERVER['list_path'] . path_format($path));
2020-03-22 11:32:42 +00:00
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
2020-09-15 07:00:19 +00:00
$password=getcache('path_' . $path1 . '/?password', $_SERVER['disktag']);
2020-02-03 12:03:04 +00:00
if ($password=='') {
2021-01-15 03:10:08 +00:00
$ispassfile = get_content(path_format($path . '/' . urlencode($passfile)));
2020-03-24 15:02:41 +00:00
//echo $path . '<pre>' . json_encode($ispassfile, JSON_PRETTY_PRINT) . '</pre>';
2021-01-15 03:10:08 +00:00
if ($ispassfile['type']=='file') {
$arr = curl('GET', $ispassfile['url']);
2020-03-24 15:02:41 +00:00
if ($arr['stat']==200) {
$passwordf=explode("\n",$arr['body']);
$password=$passwordf[0];
2021-01-17 05:13:37 +00:00
if ($password==='') {
return '';
} else {
$password=md5($password);
savecache('path_' . $path1 . '/?password', $password, $_SERVER['disktag']);
return $password;
}
2020-03-24 15:02:41 +00:00
} else {
//return md5('DefaultP@sswordWhenNetworkError');
return md5( md5(time()).rand(1000,9999) );
}
2020-01-18 12:12:21 +00:00
} else {
2020-09-15 07:00:19 +00:00
savecache('path_' . $path1 . '/?password', 'null', $_SERVER['disktag']);
2020-03-24 15:02:41 +00:00
if ($path !== '' ) {
$path = substr($path,0,strrpos($path,'/'));
return gethiddenpass($path,$passfile);
} else {
return '';
}
2020-01-18 12:12:21 +00:00
}
2020-02-03 12:03:04 +00:00
} elseif ($password==='null') {
if ($path !== '' ) {
$path = substr($path,0,strrpos($path,'/'));
return gethiddenpass($path,$passfile);
} else {
return '';
}
} else return $password;
// return md5('DefaultP@sswordWhenNetworkError');
2020-01-18 12:12:21 +00:00
}
function get_timezone($timezone = '8')
{
2020-04-05 06:32:23 +00:00
global $timezones;
2020-01-18 12:12:21 +00:00
if ($timezone=='') $timezone = '8';
return $timezones[$timezone];
}
2021-08-17 11:51:17 +00:00
function message($message, $title = 'Message', $statusCode = 200, $wainstat = 0)
2020-01-18 12:12:21 +00:00
{
2021-08-17 11:51:17 +00:00
$html = '
2020-03-03 05:27:18 +00:00
<html lang="' . $_SERVER['language'] . '">
2020-02-23 05:39:11 +00:00
<html>
<meta charset=utf-8>
2020-03-08 04:37:10 +00:00
<meta name=viewport content="width=device-width,initial-scale=1">
2020-02-23 05:39:11 +00:00
<body>
2021-02-23 09:20:19 +00:00
<a href="' . $_SERVER['base_path'] . '">' . getconstStr('Back') . getconstStr('Home') . '</a>
2021-08-24 03:31:59 +00:00
<h1>' . $title . '</h1>
2021-08-17 11:51:17 +00:00
<div id="dis" style="display: none;">
2020-09-13 05:04:58 +00:00
2020-02-23 05:39:11 +00:00
' . $message . '
2020-09-13 05:04:58 +00:00
2021-08-17 11:51:17 +00:00
</div>';
if ($wainstat) {
$html .= '
<div id="err"></div>
<script>
var dis = document.getElementById("dis");
var errordiv = document.getElementById("err");
//var deployTime = new Date().getTime();
dis.style.display = "none";
var x = "";
var min = 0;
function getStatus() {
x += ".";
min++;
var xhr = new XMLHttpRequest();
2021-08-26 10:09:57 +00:00
var url = "?WaitFunction=" + (status!=""?status:"1");
2021-08-17 11:51:17 +00:00
xhr.open("GET", url);
//xhr.setRequestHeader("Authorization", "Bearer ");
xhr.onload = function(e) {
if (xhr.status==200) {
//var deployStat = JSON.parse(xhr.responseText).readyState;
if (xhr.responseText=="ok") {
errordiv.innerHTML = "";
dis.style.display = "";
} else {
errordiv.innerHTML = "ERROR<br>" + xhr.responseText;
//setTimeout(function() { getStatus() }, 1000);
}
} else if (xhr.status==206) {
errordiv.innerHTML = min + "<br>' . getconstStr('Wait') . '" + x;
setTimeout(function() { getStatus() }, 1000);
} else {
errordiv.innerHTML = "ERROR<br>" + xhr.status + "<br>" + xhr.responseText;
console.log(xhr.status);
console.log(xhr.responseText);
}
}
xhr.send(null);
}
getStatus();
</script>';
} else {
$html .= '
<script>document.getElementById("dis").style.display = "";</script>';
}
$html .= '
2020-02-23 05:39:11 +00:00
</body>
2020-03-13 02:53:19 +00:00
</html>
2021-08-17 11:51:17 +00:00
';
return output($html, $statusCode);
2020-01-18 12:12:21 +00:00
}
function needUpdate()
{
2021-01-15 03:10:08 +00:00
global $slash;
2020-09-13 05:04:58 +00:00
$current_version = file_get_contents(__DIR__ . $slash . 'version');
$current_ver = substr($current_version, strpos($current_version, '.')+1);
2020-01-22 15:35:52 +00:00
$current_ver = explode(urldecode('%0A'),$current_ver)[0];
$current_ver = explode(urldecode('%0D'),$current_ver)[0];
$split = splitfirst($current_version, '.' . $current_ver)[0] . '.' . $current_ver;
2021-01-15 03:10:08 +00:00
if (!($github_version = getcache('github_version'))) {
$tmp = curl('GET', 'https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
if ($tmp['stat']==0) return 0;
$github_version = $tmp['body'];
savecache('github_version', $github_version);
}
2020-01-22 15:35:52 +00:00
$github_ver = substr($github_version, strpos($github_version, '.')+1);
$github_ver = explode(urldecode('%0A'),$github_ver)[0];
$github_ver = explode(urldecode('%0D'),$github_ver)[0];
if ($current_ver != $github_ver) {
//$_SERVER['github_version'] = $github_version;
$_SERVER['github_ver_new'] = splitfirst($github_version, $split)[0];
$_SERVER['github_ver_old'] = splitfirst($github_version, $_SERVER['github_ver_new'])[1];
2020-01-22 15:35:52 +00:00
return 1;
2020-01-18 12:12:21 +00:00
}
return 0;
}
function output($body, $statusCode = 200, $headers = ['Content-Type' => 'text/html'], $isBase64Encoded = false)
{
2021-02-23 09:20:19 +00:00
if (isset($_SERVER['Set-Cookie'])) $headers['Set-Cookie'] = $_SERVER['Set-Cookie'];
2021-05-13 01:43:57 +00:00
if (baseclassofdrive()=='Aliyundrive') $headers['Referrer-Policy'] = 'no-referrer';
2021-05-12 08:35:34 +00:00
//$headers['Referrer-Policy'] = 'same-origin';
//$headers['X-Frame-Options'] = 'sameorigin';
2020-01-18 12:12:21 +00:00
return [
'isBase64Encoded' => $isBase64Encoded,
'statusCode' => $statusCode,
'headers' => $headers,
'body' => $body
];
}
function passhidden($path)
{
if ($_SERVER['admin']) return 0;
2020-01-18 12:12:21 +00:00
$path = str_replace('+','%2B',$path);
$path = str_replace('&amp;','&', path_format(urldecode($path)));
if (getConfig('passfile') != '') {
2020-03-03 09:45:33 +00:00
$path = spurlencode($path,'/');
2020-01-18 12:12:21 +00:00
if (substr($path,-1)=='/') $path=substr($path,0,-1);
2021-01-15 03:10:08 +00:00
$hiddenpass=gethiddenpass($path, getConfig('passfile'));
2020-01-18 12:12:21 +00:00
if ($hiddenpass != '') {
return comppass($hiddenpass);
} else {
return 1;
}
} else {
return 0;
}
return 4;
}
function size_format($byte)
{
$i = 0;
while (abs($byte) >= 1024) {
$byte = $byte / 1024;
$i++;
2021-03-14 08:58:30 +00:00
if ($i == 4) break;
2020-01-18 12:12:21 +00:00
}
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$ret = round($byte, 2);
return ($ret . ' ' . $units[$i]);
}
function time_format($ISO)
{
2020-08-23 11:25:36 +00:00
if ($ISO=='') return date('Y-m-d H:i:s');
2020-01-18 12:12:21 +00:00
$ISO = str_replace('T', ' ', $ISO);
$ISO = str_replace('Z', ' ', $ISO);
return date('Y-m-d H:i:s',strtotime($ISO . " UTC"));
}
2021-10-06 08:01:31 +00:00
function adminform($name = '', $pass = '', $storage = '', $path = '')
2020-01-18 12:12:21 +00:00
{
2021-03-11 10:48:43 +00:00
$html = '<html><head><title>' . getconstStr('AdminLogin') . '</title><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"></head>';
if ($name=='admin'&&$pass!='') {
2021-01-15 03:10:08 +00:00
$html .= '<meta http-equiv="refresh" content="3;URL=' . $path . '">
2021-10-06 08:01:31 +00:00
<body>' . getconstStr('LoginSuccess') . '
<script>
localStorage.setItem("admin", "' . $storage . '");
</script>
</body></html>';
2020-08-26 02:27:20 +00:00
$statusCode = 201;
2020-01-18 12:12:21 +00:00
date_default_timezone_set('UTC');
2021-10-06 08:01:31 +00:00
$_SERVER['Set-Cookie'] = $name . '=' . $pass . '; path=' . $_SERVER['base_path'] . '; expires=' . date(DATE_COOKIE, strtotime('+7day'));
2021-02-23 09:20:19 +00:00
return output($html, $statusCode);
2020-01-18 12:12:21 +00:00
}
2020-08-24 01:13:27 +00:00
$statusCode = 401;
2020-01-18 12:12:21 +00:00
$html .= '
2021-01-15 03:10:08 +00:00
<body>
<div>
<center><h4>' . getconstStr('InputPassword') . '</h4>
2021-03-11 10:48:43 +00:00
' . $name . '
2021-03-09 08:04:19 +00:00
<form action="" method="post" onsubmit="return sha1loginpass(this);">
2021-01-15 03:10:08 +00:00
<div>
2021-03-09 08:04:19 +00:00
<input id="password1" name="password1" type="password"/>
2021-01-15 03:10:08 +00:00
<input name="timestamp" type="hidden"/>
<input type="submit" value="' . getconstStr('Login') . '">
</div>
</form>
</center>
</div>
</body>';
$html .= '
<script>
2021-03-09 08:04:19 +00:00
document.getElementById("password1").focus();
function sha1loginpass(f) {
if (f.password1.value=="") return false;
2021-03-11 12:01:49 +00:00
try {
timestamp = new Date().getTime() + "";
timestamp = timestamp.substr(0, timestamp.length-3);
f.timestamp.value = timestamp;
f.password1.value = sha1(timestamp + "" + f.password1.value);
return true;
} catch {
alert("sha1.js not loaded.");
return false;
}
2021-01-15 03:10:08 +00:00
}
2021-03-11 12:01:49 +00:00
</script>
<script src="https://cdn.bootcss.com/js-sha1/0.6.0/sha1.min.js"></script>';
2021-01-15 03:10:08 +00:00
$html .= '</html>';
2020-08-24 01:13:27 +00:00
return output($html, $statusCode);
2020-01-18 12:12:21 +00:00
}
function adminoperate($path)
{
2021-01-15 03:10:08 +00:00
global $drive;
2020-01-18 12:12:21 +00:00
$path1 = path_format($_SERVER['list_path'] . path_format($path));
2021-01-15 03:10:08 +00:00
if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
2020-12-15 04:52:03 +00:00
$tmpget = $_GET;
$tmppost = $_POST;
2020-01-18 12:12:21 +00:00
$tmparr['statusCode'] = 0;
2021-10-06 08:01:31 +00:00
if (isset($tmpget['RefreshCache'])) {
//$path1 = path_format($_SERVER['list_path'] . path_format($path));
//if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1);
savecache('customTheme', '', '', 1);
return message('<meta http-equiv="refresh" content="2;URL=./">
<meta name=viewport content="width=device-width,initial-scale=1">', getconstStr('RefreshCache'), 202);
}
2020-12-15 04:52:03 +00:00
if ( (isset($tmpget['rename_newname'])&&$tmpget['rename_newname']!=$tmpget['rename_oldname'] && $tmpget['rename_newname']!='') || (isset($tmppost['rename_newname'])&&$tmppost['rename_newname']!=$tmppost['rename_oldname'] && $tmppost['rename_newname']!='') ) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-12-15 04:52:03 +00:00
if (isset($tmppost['rename_newname'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
2020-01-18 12:12:21 +00:00
// rename 重命名
2021-01-15 03:10:08 +00:00
$file['path'] = $path1;
$file['name'] = ${$VAR}['rename_oldname'];
$file['id'] = ${$VAR}['rename_fileid'];
return $drive->Rename($file, ${$VAR}['rename_newname']);
2020-01-18 12:12:21 +00:00
}
2020-12-15 04:52:03 +00:00
if (isset($tmpget['delete_name']) || isset($tmppost['delete_name'])) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-12-15 04:52:03 +00:00
if (isset($tmppost['delete_name'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
2020-01-18 12:12:21 +00:00
// delete 删除
2021-01-15 03:10:08 +00:00
$file['path'] = $path1;
$file['name'] = ${$VAR}['delete_name'];
$file['id'] = ${$VAR}['delete_fileid'];
return $drive->Delete($file);
2020-01-18 12:12:21 +00:00
}
2020-12-15 04:52:03 +00:00
if ( (isset($tmpget['operate_action'])&&$tmpget['operate_action']==getconstStr('Encrypt')) || (isset($tmppost['operate_action'])&&$tmppost['operate_action']==getconstStr('Encrypt')) ) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-12-15 04:52:03 +00:00
if (isset($tmppost['operate_action'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
2020-01-18 12:12:21 +00:00
// encrypt 加密
if (getConfig('passfile')=='') return message(getconstStr('SetpassfileBfEncrypt'),'',403);
2020-12-15 04:52:03 +00:00
if (${$VAR}['encrypt_folder']=='/') ${$VAR}['encrypt_folder']=='';
2021-01-15 03:10:08 +00:00
$folder['path'] = path_format($path1 . '/' . spurlencode(${$VAR}['encrypt_folder'], '/'));
$folder['name'] = ${$VAR}['encrypt_folder'];
$folder['id'] = ${$VAR}['id'];
return $drive->Encrypt($folder, getConfig('passfile'), ${$VAR}['encrypt_newpass']);
2020-01-18 12:12:21 +00:00
}
2020-12-15 04:52:03 +00:00
if (isset($tmpget['move_folder']) || isset($tmppost['move_folder'])) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-12-15 04:52:03 +00:00
if (isset($tmppost['move_folder'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
2020-01-18 12:12:21 +00:00
// move 移动
$moveable = 1;
2020-12-15 04:52:03 +00:00
if ($path == '/' && ${$VAR}['move_folder'] == '/../') $moveable=0;
if (${$VAR}['move_folder'] == ${$VAR}['move_name']) $moveable=0;
2020-01-18 12:12:21 +00:00
if ($moveable) {
2021-01-15 03:10:08 +00:00
$file['path'] = $path1;
$file['name'] = ${$VAR}['move_name'];
$file['id'] = ${$VAR}['move_fileid'];
2020-12-15 04:52:03 +00:00
if (${$VAR}['move_folder'] == '/../') {
2021-01-15 03:10:08 +00:00
$foldername = path_format('/' . urldecode($path1 . '/'));
2020-11-09 10:05:02 +00:00
$foldername = substr($foldername, 0, -1);
$foldername = splitlast($foldername, '/')[0];
2020-12-15 04:52:03 +00:00
} else $foldername = path_format('/' . urldecode($path1) . '/' . ${$VAR}['move_folder']);
2021-01-15 03:10:08 +00:00
$folder['path'] = $foldername;
$folder['name'] = ${$VAR}['move_folder'];
$folder['id'] = '';
return $drive->Move($file, $folder);
2020-01-18 12:12:21 +00:00
} else {
2021-01-15 03:10:08 +00:00
return output('{"error":"' . getconstStr('CannotMove') . '"}', 403);
2020-01-18 12:12:21 +00:00
}
}
2020-12-15 04:52:03 +00:00
if (isset($tmpget['copy_name']) || isset($tmppost['copy_name'])) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-12-15 04:52:03 +00:00
if (isset($tmppost['copy_name'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
2020-02-22 08:52:38 +00:00
// copy 复制
2021-01-15 03:10:08 +00:00
$file['path'] = $path1;
$file['name'] = ${$VAR}['copy_name'];
$file['id'] = ${$VAR}['copy_fileid'];
return $drive->Copy($file);
2020-02-22 08:52:38 +00:00
}
2020-12-15 04:52:03 +00:00
if (isset($tmppost['editfile'])) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-01-18 12:12:21 +00:00
// edit 编辑
2021-01-15 03:10:08 +00:00
$file['path'] = $path1;
$file['name'] = '';
$file['id'] = '';
return $drive->Edit($file, $tmppost['editfile']);
2020-01-18 12:12:21 +00:00
}
2020-12-15 04:52:03 +00:00
if (isset($tmpget['create_name']) || isset($tmppost['create_name'])) {
2021-10-06 08:01:31 +00:00
if (!compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) return ['statusCode'=>403];
2020-12-15 04:52:03 +00:00
if (isset($tmppost['create_name'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
2020-01-18 12:12:21 +00:00
// create 新建
2021-01-15 03:10:08 +00:00
$parent['path'] = $path1;
$parent['name'] = '';
$parent['id'] = ${$VAR}['create_fileid'];
return $drive->Create($parent, ${$VAR}['create_type'], ${$VAR}['create_name'], ${$VAR}['create_text']);
2020-01-18 12:12:21 +00:00
}
return $tmparr;
}
2020-04-02 10:18:08 +00:00
function splitfirst($str, $split)
{
$len = strlen($split);
$pos = strpos($str, $split);
if ($pos===false) {
$tmp[0] = $str;
$tmp[1] = '';
} elseif ($pos>0) {
$tmp[0] = substr($str, 0, $pos);
$tmp[1] = substr($str, $pos+$len);
} else {
$tmp[0] = '';
$tmp[1] = substr($str, $len);
}
return $tmp;
}
2020-02-22 08:52:38 +00:00
function splitlast($str, $split)
{
2020-04-02 10:18:08 +00:00
$len = strlen($split);
2020-02-22 08:52:38 +00:00
$pos = strrpos($str, $split);
if ($pos===false) {
$tmp[0] = $str;
$tmp[1] = '';
} elseif ($pos>0) {
$tmp[0] = substr($str, 0, $pos);
2020-04-02 10:18:08 +00:00
$tmp[1] = substr($str, $pos+$len);
2020-02-22 08:52:38 +00:00
} else {
$tmp[0] = '';
2020-04-02 10:18:08 +00:00
$tmp[1] = substr($str, $len);
2020-02-22 08:52:38 +00:00
}
return $tmp;
}
2020-03-15 12:50:29 +00:00
function children_name($children)
{
$tmp = [];
foreach ($children as $file) {
$tmp[strtolower($file['name'])] = $file;
2020-03-15 12:50:29 +00:00
}
return $tmp;
}
2020-05-07 10:45:10 +00:00
function EnvOpt($needUpdate = 0)
{
global $constStr;
2021-01-15 03:10:08 +00:00
global $EnvConfigs;
2020-05-07 10:45:10 +00:00
global $timezones;
2021-01-15 03:10:08 +00:00
global $slash;
global $drive;
ksort($EnvConfigs);
2021-03-01 09:38:15 +00:00
$disktags = explode('|', getConfig('disktag'));
2020-12-27 06:22:18 +00:00
$envs = '';
2021-02-23 09:20:19 +00:00
//foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', ';
$envs = substr(json_encode(array_keys ($EnvConfigs)), 1, -1);
2020-12-27 06:22:18 +00:00
2020-05-07 10:45:10 +00:00
$html = '<title>OneManager '.getconstStr('Setup').'</title>';
2021-10-06 08:01:31 +00:00
if (isset($_POST['updateProgram'])&&$_POST['updateProgram']==getconstStr('updateProgram')) if (compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) {
2020-08-04 06:38:20 +00:00
$response = setConfigResponse(OnekeyUpate($_POST['auth'], $_POST['project'], $_POST['branch']));
2020-05-07 10:45:10 +00:00
if (api_error($response)) {
$html = api_error_msg($response);
$title = 'Error';
2021-08-17 11:51:17 +00:00
return message($html, $title, 400);
2020-05-03 10:17:18 +00:00
} else {
2020-05-07 10:45:10 +00:00
//WaitSCFStat();
2021-08-26 10:09:57 +00:00
$html .= getconstStr('UpdateSuccess') . '<br><a href="">' . getconstStr('Back') . '</a><script>var status = "' . $response['DplStatus'] . '";</script>';
2020-05-07 10:45:10 +00:00
$title = getconstStr('Setup');
2021-08-17 11:51:17 +00:00
return message($html, $title, 202, 1);
2020-05-03 10:17:18 +00:00
}
2021-10-06 08:01:31 +00:00
} else return message('please login again', 'Need login', 403);
if (isset($_POST['submit1'])) if (compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) {
2020-05-07 10:45:10 +00:00
$_SERVER['disk_oprating'] = '';
foreach ($_POST as $k => $v) {
2021-01-18 07:59:39 +00:00
if (isShowedEnv($k) || $k=='disktag_del' || $k=='disktag_add' || $k=='disktag_rename' || $k=='disktag_copy') {
2020-05-07 10:45:10 +00:00
$tmp[$k] = $v;
2020-05-03 10:17:18 +00:00
}
2020-12-27 06:22:18 +00:00
if ($k=='disktag_newname') {
$v = preg_replace('/[^0-9a-zA-Z|_]/i', '', $v);
$f = substr($v, 0, 1);
if (strlen($v)==1) $v .= '_';
2021-01-15 03:10:08 +00:00
if (isCommonEnv($v)) {
2021-08-17 11:51:17 +00:00
return message('Do not input ' . $envs . '<br><a href="">' . getconstStr('Back') . '</a>', 'Error', 400);
2020-12-27 06:22:18 +00:00
} elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) {
2021-08-17 11:51:17 +00:00
return message('<a href="">' . getconstStr('Back') . '</a>', 'Please start with letters', 400);
2021-01-18 08:36:45 +00:00
} elseif (getConfig($v)) {
2021-08-17 11:51:17 +00:00
return message('<a href="">' . getconstStr('Back') . '</a>', 'Same tag', 400);
2020-12-27 06:22:18 +00:00
} else {
$tmp[$k] = $v;
}
}
if ($k=='disktag_sort') {
$td = implode('|', json_decode($v));
if (strlen($td)==strlen(getConfig('disktag'))) $tmp['disktag'] = $td;
2021-08-17 11:51:17 +00:00
else return message('Something wrong.', 'ERROR', 400);
2020-12-27 06:22:18 +00:00
}
2020-05-07 10:45:10 +00:00
if ($k == 'disk') $_SERVER['disk_oprating'] = $v;
2020-05-03 10:17:18 +00:00
}
2020-05-07 10:45:10 +00:00
/*if ($tmp['domain_path']!='') {
$tmp1 = explode("|",$tmp['domain_path']);
$tmparr = [];
foreach ($tmp1 as $multidomain_paths){
$pos = strpos($multidomain_paths,":");
if ($pos>0) $tmparr[substr($multidomain_paths, 0, $pos)] = path_format(substr($multidomain_paths, $pos+1));
2020-05-03 10:17:18 +00:00
}
2020-05-07 10:45:10 +00:00
$tmp['domain_path'] = $tmparr;
}*/
$response = setConfigResponse( setConfig($tmp, $_SERVER['disk_oprating']) );
if (api_error($response)) {
$html = api_error_msg($response);
$title = 'Error';
2021-08-17 11:51:17 +00:00
return message($html, $title, 409);
} else {
2020-05-07 10:45:10 +00:00
$html .= getconstStr('Success') . '!<br>
2021-08-17 11:51:17 +00:00
<a href="">' . getconstStr('Back') . '</a>
<script>
2021-08-26 10:09:57 +00:00
var status = "' . $response['DplStatus'] . '";
2021-08-17 11:51:17 +00:00
</script>';
2020-05-07 10:45:10 +00:00
$title = getconstStr('Setup');
2021-08-17 11:51:17 +00:00
return message($html, $title, 200, 1);
2020-05-03 10:17:18 +00:00
}
2021-10-06 08:01:31 +00:00
} else return message('please login again', 'Need login', 403);
if (isset($_POST['config_b'])) if (compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) {
2021-03-09 08:04:19 +00:00
if (!$_POST['pass']) return output("{\"Error\": \"No admin pass\"}", 403);
if (!is_numeric($_POST['timestamp'])) return output("{\"Error\": \"Error time\"}", 403);
if (abs(time() - $_POST['timestamp']/1000) > 5*60) return output("{\"Error\": \"Timeout\"}", 403);
if ($_POST['pass']==sha1(getConfig('admin') . $_POST['timestamp'])) {
2021-03-01 09:38:15 +00:00
if ($_POST['config_b'] == 'export') {
foreach ($EnvConfigs as $env => $v) {
if (isCommonEnv($env)) {
$value = getConfig($env);
if ($value) $tmp[$env] = $value;
}
}
foreach ($disktags as $disktag) {
$d = getConfig($disktag);
2021-04-07 13:16:37 +00:00
if ($d == '') {
2021-03-01 09:38:15 +00:00
$d = '';
} elseif (gettype($d)=='array') {
$tmp[$disktag] = $d;
} else {
$tmp[$disktag] = json_decode($d, true);
}
}
unset($tmp['admin']);
return output(json_encode($tmp, JSON_PRETTY_PRINT));
}
if ($_POST['config_b'] == 'import') {
if (!$_POST['config_t']) return output("{\"Error\": \"Empty config.\"}", 403);
$c = '{' . splitfirst($_POST['config_t'], '{')[1];
$c = splitlast($c, '}')[0] . '}';
$tmp = json_decode($c, true);
if (!!!$tmp) return output("{\"Error\": \"Config input error. " . $c . "\"}", 403);
2021-04-07 13:16:37 +00:00
if (isset($tmp['disktag'])) $tmptag = $tmp['disktag'];
2021-03-01 09:38:15 +00:00
foreach ($EnvConfigs as $env => $v) {
if (isCommonEnv($env)) {
if (isShowedEnv($env)) {
if (getConfig($env)!=''&&!isset($tmp[$env])) $tmp[$env] = '';
} else {
unset($tmp[$env]);
}
}
}
2021-04-07 13:16:37 +00:00
if ($disktags) foreach ($disktags as $disktag) {
if ($disktag!=''&&!isset($tmp[$disktag])) $tmp[$disktag] = '';
2021-03-01 09:38:15 +00:00
}
2021-04-07 13:16:37 +00:00
if ($tmptag) $tmp['disktag'] = $tmptag;
$response = setConfigResponse( setConfig($tmp) );
2021-03-01 09:38:15 +00:00
if (api_error($response)) {
return output("{\"Error\": \"" . api_error_msg($response) . "\"}", 500);
} else {
return output("{\"Success\": \"Success\"}", 200);
}
}
return output(json_encode($_POST), 500);
} else {
2021-03-09 08:04:19 +00:00
return output("{\"Error\": \"Admin pass error\"}", 403);
2021-03-01 09:38:15 +00:00
}
2021-10-06 08:01:31 +00:00
} else return message('please login again', 'Need login', 403);
if (isset($_POST['changePass'])) if (compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) {
2021-03-09 09:18:59 +00:00
if (!is_numeric($_POST['timestamp'])) return message("Error time<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
if (abs(time() - $_POST['timestamp']/1000) > 5*60) return message("Timeout<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
if ($_POST['newPass1']==''||$_POST['newPass2']=='') return message("Empty new pass<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
if ($_POST['newPass1']!==$_POST['newPass2']) return message("Twice new pass not the same<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
if ($_POST['newPass1']==getConfig('admin')) return message("New pass same to old one<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
if ($_POST['oldPass']==sha1(getConfig('admin') . $_POST['timestamp'])) {
$tmp['admin'] = $_POST['newPass1'];
$response = setConfigResponse( setConfig($tmp) );
if (api_error($response)) {
return message(api_error_msg($response) . "<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
} else {
2021-08-26 10:09:57 +00:00
return message("Success<a href=\"\">" . getconstStr('Back') . "</a><script>var status = \"" . $response['DplStatus'] . "\";</script>", "Success", 200, 1);
2021-03-09 09:18:59 +00:00
}
} else {
return message("Old pass error<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
}
2021-10-06 08:01:31 +00:00
} else return message('please login again', 'Need login', 403);
2021-03-01 09:38:15 +00:00
2020-05-07 10:45:10 +00:00
if (isset($_GET['preview'])) {
$preurl = $_SERVER['PHP_SELF'] . '?preview';
} else {
$preurl = path_format($_SERVER['PHP_SELF'] . '/');
}
$html .= '
2021-03-13 05:49:46 +00:00
<a href="' . $preurl . '">' . getconstStr('Back') . '</a><br>
';
2021-09-03 01:04:56 +00:00
if ($_GET['setup']==='cmd') {
$statusCode = 200;
$html .= '
<form name="form1" method="POST" action="">
<input id="inputarea" name="cmd" style="width:100%" value="' . $_POST['cmd'] . '"><br>
<input type="submit" value="post">
</form>';
if ($_POST['cmd']!='') {
$html .= '
<pre>';
@ob_start();
passthru($_POST['cmd'], $cmdstat);
$html .= '
stat: ' . $cmdstat . '
output:
';
if ($cmdstat>0) $statusCode = 400;
if ($cmdstat===1) $statusCode = 403;
if ($cmdstat===127) $statusCode = 404;
$html .= htmlspecialchars(ob_get_clean());
$html .= '</pre>';
}
$html .= '
<script>
setTimeout(function () {
let inputarea = document.getElementById(\'inputarea\');
//console.log(a + ", " + inputarea.value);
inputarea.focus();
inputarea.setSelectionRange(0, inputarea.value.length);
}, 500);
</script>';
return message($html, 'Run cmd', $statusCode);
}
if ($_GET['setup']==='platform') {
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
<table border=1 width=100%>
2021-10-06 08:01:31 +00:00
<form name="common" action="" method="post">
<input name="_admin" type="hidden" value="">';
2021-01-15 03:10:08 +00:00
foreach ($EnvConfigs as $key => $val) if (isCommonEnv($key) && isShowedEnv($key)) {
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
<tr>
<td><label>' . $key . '</label></td>
2021-02-23 09:20:19 +00:00
<td width=100%>';
if ($key=='timezone') {
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
<select name="' . $key .'">';
foreach (array_keys($timezones) as $zone) {
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
<option value="'.$zone.'" '.($zone==getConfig($key)?'selected="selected"':'').'>'.$zone.'</option>';
2020-05-03 10:17:18 +00:00
}
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
</select>
2021-02-23 09:20:19 +00:00
' . getconstStr('EnvironmentsDescription')[$key];
2020-05-07 10:45:10 +00:00
} elseif ($key=='theme') {
2020-09-13 05:21:02 +00:00
$theme_arr = scandir(__DIR__ . $slash . 'theme');
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
<select name="' . $key .'">
<option value=""></option>';
foreach ($theme_arr as $v1) {
2021-03-13 05:49:46 +00:00
if ($v1!='.' && $v1!='..') $frame .= '
2020-05-07 10:45:10 +00:00
<option value="'.$v1.'" '.($v1==getConfig($key)?'selected="selected"':'').'>'.$v1.'</option>';
2020-05-03 10:17:18 +00:00
}
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
</select>
2021-02-23 09:20:19 +00:00
' . getconstStr('EnvironmentsDescription')[$key];
2020-05-07 10:45:10 +00:00
} /*elseif ($key=='domain_path') {
$tmp = getConfig($key);
$domain_path = '';
foreach ($tmp as $k1 => $v1) {
$domain_path .= $k1 . ':' . $v1 . '|';
2020-05-03 10:17:18 +00:00
}
2020-05-07 10:45:10 +00:00
$domain_path = substr($domain_path, 0, -1);
2021-03-13 05:49:46 +00:00
$frame .= '
2020-05-07 10:45:10 +00:00
<tr>
<td><label>' . $key . '</label></td>
<td width=100%><input type="text" name="' . $key .'" value="' . $domain_path . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td>
</tr>';
2021-03-13 05:49:46 +00:00
}*/ else $frame .= '
2021-02-23 09:20:19 +00:00
<input type="text" name="' . $key . '" value="' . htmlspecialchars(getConfig($key)) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%">';
2021-03-13 05:49:46 +00:00
$frame .= '
2021-02-23 09:20:19 +00:00
</td>
2020-05-07 10:45:10 +00:00
</tr>';
}
2021-03-13 05:49:46 +00:00
$frame .= '
<tr><td><input type="submit" name="submit1" value="' . getconstStr('Setup') . '"></td><td></td></tr>
2020-05-07 10:45:10 +00:00
</form>
</table><br>';
} elseif (isset($_GET['disktag'])&&in_array($_GET['disktag'], $disktags)) {
$disktag = $_GET['disktag'];
2021-03-13 05:49:46 +00:00
$disk_tmp = null;
$diskok = driveisfine($disktag, $disk_tmp);
$frame .= '
<table width=100%>
<tr>
<td>
<form action="" method="post" style="margin: 0" onsubmit="return renametag(this);">
<input type="hidden" name="disktag_rename" value="' . $disktag . '">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-03-13 05:49:46 +00:00
<input type="text" name="disktag_newname" value="' . $disktag . '" placeholder="' . getconstStr('EnvironmentsDescription')['disktag'] . '">
<input type="submit" name="submit1" value="' . getconstStr('RenameDisk') . '">
</form>
</td>
</tr>
2021-04-19 11:03:52 +00:00
</table><br>
<table>
<tr>
<td>
<form action="" method="post" style="margin: 0" onsubmit="return deldiskconfirm(this);">
<input type="hidden" name="disktag_del" value="' . $disktag . '">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-04-19 11:03:52 +00:00
<input type="submit" name="submit1" value="' . getconstStr('DelDisk') . '">
</form>
</td>
<td>
<form action="" method="post" style="margin: 0" onsubmit="return cpdiskconfirm(this);">
<input type="hidden" name="disktag_copy" value="' . $disktag . '">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-04-19 11:03:52 +00:00
<input type="submit" name="submit1" value="' . getconstStr('CopyDisk') . '">
</form>
</td>
</tr>
2021-03-13 05:49:46 +00:00
</table>
<table border=1 width=100%>
2021-03-14 08:58:30 +00:00
<tr>
<td>Driver</td>
<td>' . getConfig('Driver', $disktag);
2021-03-13 05:49:46 +00:00
if ($diskok) $frame .= ' <a href="?AddDisk=' . get_class($disk_tmp) . '&disktag=' . $disktag . '&SelectDrive">' . getconstStr('ChangeDrivetype') . '</a>';
$frame .= '</td>
2021-03-14 08:58:30 +00:00
</tr>';
2021-03-13 05:49:46 +00:00
if ($diskok) {
2021-03-14 08:58:30 +00:00
$frame .= '
<tr>
<td>diskSpace</td><td>' . $disk_tmp->getDiskSpace() . '</td>
</tr>';
2021-03-13 05:49:46 +00:00
foreach (extendShow_diskenv($disk_tmp) as $ext_env) {
2021-03-14 08:58:30 +00:00
$frame .= '
<tr>
<td>' . $ext_env . '</td>
<td>' . getConfig($ext_env, $disktag) . '</td>
</tr>';
2021-03-13 05:49:46 +00:00
}
2021-04-19 11:03:52 +00:00
2021-03-13 05:49:46 +00:00
$frame .= '
<form name="' . $disktag . '" action="" method="post">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-03-13 05:49:46 +00:00
<input type="hidden" name="disk" value="' . $disktag . '">';
foreach ($EnvConfigs as $key => $val) if (isInnerEnv($key) && isShowedEnv($key)) {
$frame .= '
<tr>
<td><label>' . $key . '</label></td>
<td width=100%><input type="text" name="' . $key . '" value="' . getConfig($key, $disktag) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td>
</tr>';
}
$frame .= '
2021-03-14 08:58:30 +00:00
<tr><td></td><td><input type="submit" name="submit1" value="' . getconstStr('Setup') . '"></td></tr>
2021-03-13 05:49:46 +00:00
</form>';
} else {
$frame .= '
<tr>
<td colspan="2">' . ($disk_tmp->error['body']?$disk_tmp->error['stat'] . '<br>' . $disk_tmp->error['body']:'Add this disk again.') . '</td>
</tr>';
}
$frame .= '
</table>
2021-04-19 11:03:52 +00:00
2021-03-13 05:49:46 +00:00
<script>
function deldiskconfirm(t) {
var msg="' . getconstStr('Delete') . ' ??";
if (confirm(msg)==true) return true;
else return false;
}
function cpdiskconfirm(t) {
var msg="' . getconstStr('Copy') . ' ??";
if (confirm(msg)==true) return true;
//else
return false;
}
function renametag(t) {
if (t.disktag_newname.value==\'\') {
alert(\'' . getconstStr('DiskTag') . '\');
return false;
}
if (t.disktag_newname.value==t.disktag_rename.value) {
return false;
}
envs = [' . $envs . '];
if (envs.indexOf(t.disktag_newname.value)>-1) {
alert(\'Do not input ' . $envs . '\');
return false;
}
var reg = /^[a-zA-Z]([_a-zA-Z0-9]{1,20})$/;
if (!reg.test(t.disktag_newname.value)) {
alert(\'' . getconstStr('TagFormatAlert') . '\');
return false;
}
return true;
}
</script>';
} else {
//$_GET['disktag'] = '';
2021-03-13 05:49:46 +00:00
$Driver_arr = scandir(__DIR__ . $slash . 'disk');
if (count($disktags)>1) {
$frame .= '
2020-12-27 06:22:18 +00:00
<script src="//cdn.bootcss.com/Sortable/1.8.3/Sortable.js"></script>
<style>
.sortable-ghost {
opacity: 0.4;
background-color: #1748ce;
}
#sortdisks td {
cursor: move;
}
</style>
<table border=1>
<form id="sortdisks_form" action="" method="post" style="margin: 0" onsubmit="return dragsort(this);">
<tr id="sortdisks">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2020-12-27 06:22:18 +00:00
<input type="hidden" name="disktag_sort" value="">';
2021-03-13 05:49:46 +00:00
$num = 0;
foreach ($disktags as $disktag) {
if ($disktag!='') {
$num++;
$frame .= '
2020-12-27 06:22:18 +00:00
<td>' . $disktag . '</td>';
2021-03-13 05:49:46 +00:00
}
2020-12-27 06:22:18 +00:00
}
2021-03-13 05:49:46 +00:00
$frame .= '
2020-12-27 06:22:18 +00:00
</tr>
<tr><td colspan="' . $num . '">' . getconstStr('DragSort') . '<input type="submit" name="submit1" value="' . getconstStr('SubmitSortdisks') . '"></td></tr>
</form>
</table>
<script>
var disks=' . json_encode($disktags) . ';
2020-12-27 06:22:18 +00:00
function change(arr, oldindex, newindex) {
//console.log(oldindex + "," + newindex);
tmp=arr.splice(oldindex-1, 1);
if (oldindex > newindex) {
tmp1=JSON.parse(JSON.stringify(arr));
tmp1.splice(newindex-1, arr.length-newindex+1);
tmp2=JSON.parse(JSON.stringify(arr));
tmp2.splice(0, newindex-1);
} else {
tmp1=JSON.parse(JSON.stringify(arr));
tmp1.splice(newindex-1, arr.length-newindex+1);
tmp2=JSON.parse(JSON.stringify(arr));
tmp2.splice(0, newindex-1);
}
arr=tmp1.concat(tmp, tmp2);
//console.log(arr);
return arr;
}
function dragsort(t) {
if (t.disktag_sort.value==\'\') {
alert(\'' . getconstStr('DragSort') . '\');
return false;
}
envs = [' . $envs . '];
if (envs.indexOf(t.disktag_sort.value)>-1) {
2021-02-23 09:20:19 +00:00
alert(\'Do not input ' . $envs . '\');
2020-12-27 06:22:18 +00:00
return false;
}
return true;
}
Sortable.create(document.getElementById(\'sortdisks\'), {
animation: 150,
onEnd: function (evt) { //拖拽完毕之后发生该事件
//console.log(evt.oldIndex);
//console.log(evt.newIndex);
if (evt.oldIndex!=evt.newIndex) {
disks=change(disks, evt.oldIndex, evt.newIndex);
document.getElementById(\'sortdisks_form\').disktag_sort.value=JSON.stringify(disks);
}
}
});
</script><br>';
2021-03-13 05:49:46 +00:00
}
2021-04-19 11:03:52 +00:00
$frame .= '
<select name="DriveType" onchange="changedrivetype(this.options[this.options.selectedIndex].value)">';
foreach ($Driver_arr as $v1) {
if ($v1!='.' && $v1!='..') {
//$v1 = substr($v1, 0, -4);
$v2 = splitlast($v1, '.php')[0];
if ($v2 . '.php'==$v1) $frame .= '
<option value="' . $v2 . '"' . ($v2=='Onedrive'?' selected="selected"':'') . '>' . $v2 . '</option>';
}
}
$frame .= '
</select>
<a id="AddDisk_link" href="?AddDisk=Onedrive">' . getconstStr('AddDisk') . '</a><br><br>
<script>
function changedrivetype(d) {
document.getElementById(\'AddDisk_link\').href="?AddDisk=" + d;
}
</script>';
2021-03-13 05:49:46 +00:00
$canOneKeyUpate = 0;
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
$canOneKeyUpate = 1;
2021-08-04 07:28:58 +00:00
} elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME'])&&$_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
2021-03-13 05:49:46 +00:00
$canOneKeyUpate = 1;
2021-08-04 07:28:58 +00:00
} elseif (isset($_SERVER['_APP_SHARE_DIR'])&&$_SERVER['_APP_SHARE_DIR']==='/var/share/CFF/processrouter') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user') {
2021-03-13 05:49:46 +00:00
$canOneKeyUpate = 1;
} else {
$tmp = time();
if ( mkdir(''.$tmp, 0777) ) {
rmdir(''.$tmp);
$canOneKeyUpate = 1;
}
}
2021-03-13 06:16:17 +00:00
$frame .= '<a href="https://github.com/qkqpttgf/OneManager-php" target="_blank">Github</a>';
2021-03-13 05:49:46 +00:00
if (!$canOneKeyUpate) {
$frame .= '
' . getconstStr('CannotOneKeyUpate') . '<br>';
} else {
$frame .= '
<form name="updateform" action="" method="post">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-03-13 05:49:46 +00:00
<input type="text" name="auth" size="6" placeholder="auth" value="qkqpttgf">
<input type="text" name="project" size="12" placeholder="project" value="OneManager-php">
<button name="QueryBranchs" onclick="querybranchs();return false;">' . getconstStr('QueryBranchs') . '</button>
<select name="branch">
<option value="master">master</option>
</select>
<input type="submit" name="updateProgram" value="' . getconstStr('updateProgram') . '">
</form>
<script>
function querybranchs()
{
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.github.com/repos/"+document.updateform.auth.value+"/"+document.updateform.project.value+"/branches");
//xhr.setRequestHeader("User-Agent","qkqpttgf/OneManager");
xhr.onload = function(e){
console.log(xhr.responseText+","+xhr.status);
if (xhr.status==200) {
document.updateform.branch.options.length=0;
JSON.parse(xhr.responseText).forEach( function (e) {
document.updateform.branch.options.add(new Option(e.name,e.name));
if ("master"==e.name) document.updateform.branch.options[document.updateform.branch.options.length-1].selected = true;
});
document.updateform.QueryBranchs.style.display="none";
2020-07-13 09:33:47 +00:00
} else {
2021-03-13 05:49:46 +00:00
alert(xhr.responseText+"\n"+xhr.status);
2020-05-03 10:17:18 +00:00
}
}
2021-03-13 05:49:46 +00:00
xhr.onerror = function(e){
alert("Network Error "+xhr.status);
}
xhr.send(null);
2020-05-07 10:45:10 +00:00
}
2021-03-13 05:49:46 +00:00
</script>
';
}
if ($needUpdate) {
$frame .= '<div style="position: relative; word-wrap: break-word;">
' . str_replace("\r", '<br>', $_SERVER['github_ver_new']) . '
</div>
<button onclick="document.getElementById(\'github_ver_old\').style.display=(document.getElementById(\'github_ver_old\').style.display==\'none\'?\'\':\'none\');">More...</button>
<div id="github_ver_old" style="position: relative; word-wrap: break-word; display: none">
' . str_replace("\r", '<br>', $_SERVER['github_ver_old']) . '
</div>';
}/* else {
$frame .= getconstStr('NotNeedUpdate');
}*/
$frame .= '<br><br>
2021-03-11 12:01:49 +00:00
<script src="https://cdn.bootcss.com/js-sha1/0.6.0/sha1.min.js"></script>
2021-03-09 09:18:59 +00:00
<table>
<form id="change_pass" name="change_pass" action="" method="POST" onsubmit="return changePassword(this);">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-03-09 09:18:59 +00:00
<tr>
<td>' . getconstStr('OldPassword') . ':</td><td><input type="password" name="oldPass">
2021-03-09 09:18:59 +00:00
<input type="hidden" name="timestamp"></td>
</tr>
<tr>
<td>' . getconstStr('NewPassword') . ':</td><td><input type="password" name="newPass1"></td>
2021-03-09 09:18:59 +00:00
</tr>
<tr>
<td>' . getconstStr('ReInput') . ':</td><td><input type="password" name="newPass2"></td>
2021-03-09 09:18:59 +00:00
</tr>
<tr>
<td></td><td><button name="changePass" value="changePass">' . getconstStr('ChangAdminPassword') . '</button></td>
2021-03-09 09:18:59 +00:00
</tr>
</form>
</table><br>
2021-03-01 09:38:15 +00:00
<table>
<form id="config_f" name="config" action="" method="POST" onsubmit="return false;">
2021-10-06 08:01:31 +00:00
<input name="_admin" type="hidden" value="">
2021-03-01 09:38:15 +00:00
<tr>
<td>' . getconstStr('AdminPassword') . ':<input type="password" name="pass">
<button name="config_b" value="export" onclick="exportConfig(this);">' . getconstStr('export') . '</button></td>
2021-03-01 09:38:15 +00:00
</tr>
<tr>
<td>' . getconstStr('config') . ':<textarea name="config_t"></textarea>
<button name="config_b" value="import" onclick="importConfig(this);">' . getconstStr('import') . '</button></td>
2021-03-01 09:38:15 +00:00
</tr>
</form>
2021-04-19 11:03:52 +00:00
</table><br>
2021-03-01 09:38:15 +00:00
<script>
var config_f = document.getElementById("config_f");
function exportConfig(b) {
if (config_f.pass.value=="") {
alert("admin pass");
return false;
}
2021-04-19 11:03:52 +00:00
try {
sha1(1);
} catch {
alert("sha1.js not loaded.");
return false;
}
2021-03-09 08:04:19 +00:00
var timestamp = new Date().getTime();
2021-03-01 09:38:15 +00:00
var xhr = new XMLHttpRequest();
xhr.open("POST", "");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
xhr.onload = function(e){
console.log(xhr.responseText+","+xhr.status);
if (xhr.status==200) {
var res = JSON.parse(xhr.responseText);
config_f.config_t.value = xhr.responseText;
config_f.parentNode.style = "width: 100%";
config_f.config_t.style = "width: 100%";
config_f.config_t.style.height = config_f.config_t.scrollHeight + "px";
} else {
alert(xhr.status+"\n"+xhr.responseText);
}
}
xhr.onerror = function(e){
alert("Network Error "+xhr.status);
}
2021-03-09 08:04:19 +00:00
xhr.send("pass=" + sha1(config_f.pass.value + "" + timestamp) + "&config_b=" + b.value + "&timestamp=" + timestamp);
2021-03-01 09:38:15 +00:00
}
function importConfig(b) {
if (config_f.pass.value=="") {
alert("admin pass");
return false;
}
if (config_f.config_t.value=="") {
alert("input config");
return false;
} else {
try {
var tmp = JSON.parse(config_f.config_t.value);
} catch(e) {
alert("config error!");
return false;
}
}
2021-04-19 11:03:52 +00:00
try {
sha1(1);
} catch {
alert("sha1.js not loaded.");
return false;
}
2021-03-09 08:04:19 +00:00
var timestamp = new Date().getTime();
2021-03-01 09:38:15 +00:00
var xhr = new XMLHttpRequest();
xhr.open("POST", "");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
xhr.onload = function(e){
console.log(xhr.responseText+","+xhr.status);
if (xhr.status==200) {
//var res = JSON.parse(xhr.responseText);
alert("Import success");
} else {
alert(xhr.status+"\n"+xhr.responseText);
}
}
xhr.onerror = function(e){
alert("Network Error "+xhr.status);
}
2021-03-09 08:04:19 +00:00
xhr.send("pass=" + sha1(config_f.pass.value + "" + timestamp) + "&config_t=" + encodeURIComponent(config_f.config_t.value) + "&config_b=" + b.value + "&timestamp=" + timestamp);
2021-03-01 09:38:15 +00:00
}
2021-03-09 09:18:59 +00:00
function changePassword(f) {
if (f.oldPass.value==""||f.newPass1.value==""||f.newPass2.value=="") {
alert("Input");
return false;
}
if (f.oldPass.value==f.newPass1.value) {
alert("Same password");
return false;
}
if (f.newPass1.value!==f.newPass1.value) {
alert("Input twice new password");
return false;
}
2021-04-19 11:03:52 +00:00
try {
sha1(1);
} catch {
alert("sha1.js not loaded.");
return false;
}
2021-03-09 09:18:59 +00:00
var timestamp = new Date().getTime();
f.timestamp.value = timestamp;
f.oldPass.value = sha1(f.oldPass.value + "" + timestamp);
return true;
}
2021-04-19 11:03:52 +00:00
</script>';
2021-01-15 03:10:08 +00:00
}
$html .= '
2021-03-13 06:55:26 +00:00
<style type="text/css">
2021-03-14 08:58:30 +00:00
.tabs td { padding: 5px; }
2021-03-13 06:55:26 +00:00
</style>
2021-03-13 05:49:46 +00:00
<table border=0>
2021-03-13 06:55:26 +00:00
<tr class="tabs">';
if ($_GET['disktag']=='') {
if ($_GET['setup']==='platform') $html .= '
<td><a href="?setup">' . getconstStr('Home') . '</a></td>
<td>' . getconstStr('PlatformConfig') . '</td>';
else $html .= '
<td>' . getconstStr('Home') . '</td>
<td><a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a></td>';
} else $html .= '
<td><a href="?setup">' . getconstStr('Home') . '</a></td>
<td><a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a></td>';
2021-03-13 05:49:46 +00:00
foreach ($disktags as $disktag) {
if ($disktag!='') {
if ($_GET['disktag']==$disktag) $html .= '
<td>' . $disktag . '</td>';
2021-03-13 05:49:46 +00:00
else $html .= '
<td><a href="?setup&disktag=' . $disktag . '">' . $disktag . '</a></td>';
2020-05-07 10:45:10 +00:00
}
}
2021-03-13 05:49:46 +00:00
$html .= '
</tr>
</table><br>';
$html .= $frame;
2021-10-06 08:01:31 +00:00
$html .= '<script>
var inputAdminStorage = document.getElementsByName("_admin");
for (i=0;i<inputAdminStorage.length;i++) {
inputAdminStorage[i].value = localStorage.getItem("admin");
}
</script>';
2020-05-07 10:45:10 +00:00
return message($html, getconstStr('Setup'));
}
function render_list($path = '', $files = [])
2020-05-07 10:45:10 +00:00
{
global $exts;
global $constStr;
2021-01-15 03:10:08 +00:00
global $slash;
2020-05-07 10:45:10 +00:00
2021-01-15 03:10:08 +00:00
if (isset($files['list']['index.html']) && !$_SERVER['admin']) {
//$htmlcontent = fetch_files(spurlencode(path_format(urldecode($path) . '/index.html'), '/'))['content'];
$htmlcontent = get_content(spurlencode(path_format(urldecode($path) . '/index.html'), '/'))['content'];
2020-05-07 10:45:10 +00:00
return output($htmlcontent['body'], $htmlcontent['stat']);
2021-10-06 08:01:31 +00:00
}//echo $path . "<br>\n";
//$path = str_replace('%20','%2520',$path);
2020-05-07 10:45:10 +00:00
$path = str_replace('+','%2B',$path);
$path = str_replace('&','&amp;',path_format(urldecode($path))) ;
2021-10-06 08:01:31 +00:00
//echo $path . "<br>\n";
//$path = str_replace('%20',' ',$path);
2020-05-07 10:45:10 +00:00
$path = str_replace('#','%23',$path);
$p_path='';
if ($path !== '/') {
2021-01-15 03:10:08 +00:00
if ($files['type']=='file') {
2020-05-07 10:45:10 +00:00
$pretitle = str_replace('&','&amp;', $files['name']);
$n_path = $pretitle;
$tmp = splitlast(splitlast($path,'/')[0],'/');
if ($tmp[1]=='') {
$p_path = $tmp[0];
} else {
$p_path = $tmp[1];
}
} else {
if (substr($path, 0, 1)=='/') $pretitle = substr($path, 1);
if (substr($path, -1)=='/') $pretitle = substr($pretitle, 0, -1);
$tmp=splitlast($pretitle,'/');
if ($tmp[1]=='') {
$n_path = $tmp[0];
} else {
$n_path = $tmp[1];
$tmp = splitlast($tmp[0],'/');
if ($tmp[1]=='') {
$p_path = $tmp[0];
} else {
$p_path = $tmp[1];
}
}
}
} else {
$pretitle = getconstStr('Home');
2021-01-15 03:10:08 +00:00
$n_path = $pretitle;
2020-05-07 10:45:10 +00:00
}
2021-01-15 03:10:08 +00:00
$n_path = str_replace('&amp;','&',$n_path);
$p_path = str_replace('&amp;','&',$p_path);
2020-05-07 10:45:10 +00:00
$pretitle = str_replace('%23','#',$pretitle);
2021-01-15 03:10:08 +00:00
$statusCode = 200;
2020-05-07 10:45:10 +00:00
date_default_timezone_set(get_timezone($_SERVER['timezone']));
2021-01-15 03:10:08 +00:00
$authinfo = '
<!--
2020-05-07 10:45:10 +00:00
OneManager: An index & manager of Onedrive auth by ysun.
2020-05-14 10:05:43 +00:00
Github: https://github.com/qkqpttgf/OneManager-php
2020-05-07 10:45:10 +00:00
-->';
//$authinfo = $path . '<br><pre>' . json_encode($files, JSON_PRETTY_PRINT) . '</pre>';
2020-05-07 10:45:10 +00:00
//if (isset($_COOKIE['theme'])&&$_COOKIE['theme']!='') $theme = $_COOKIE['theme'];
//if ( !file_exists(__DIR__ . $slash .'theme' . $slash . $theme) ) $theme = '';
if ($_SERVER['admin']) $theme = 'classic.html';
2020-05-24 07:07:56 +00:00
if ( $theme=='' ) {
$tmp = getConfig('customTheme');
if ( $tmp!='' ) $theme = $tmp;
}
if ( $theme=='' ) {
$theme = getConfig('theme');
2020-09-13 05:21:02 +00:00
if ( $theme=='' || !file_exists(__DIR__ . $slash .'theme' . $slash . $theme) ) $theme = 'classic.html';
2020-05-24 07:07:56 +00:00
}
2020-05-07 10:45:10 +00:00
if (substr($theme,-4)=='.php') {
@ob_start();
2021-01-15 03:10:08 +00:00
include 'theme/' . $theme;
2020-05-07 10:45:10 +00:00
$html = ob_get_clean();
} else {
2020-09-13 05:21:02 +00:00
if (file_exists(__DIR__ . $slash .'theme' . $slash . $theme)) {
$file_path = __DIR__ . $slash .'theme' . $slash . $theme;
2020-05-24 07:07:56 +00:00
$html = file_get_contents($file_path);
} else {
if (!($html = getcache('customTheme'))) {
$file_path = $theme;
2021-05-12 08:35:34 +00:00
$tmp = curl('GET', $file_path, '', [], 1);
2020-05-24 07:07:56 +00:00
if ($tmp['stat']==302) {
error_log1(json_encode($tmp));
2021-01-15 03:10:08 +00:00
$tmp = curl('GET', $tmp["returnhead"]["Location"]);
2020-05-24 07:07:56 +00:00
}
if (!!$tmp['body']) $html = $tmp['body'];
2020-09-15 07:00:19 +00:00
savecache('customTheme', $html, '', 9999);
2020-05-24 07:07:56 +00:00
}
}
2020-05-07 10:45:10 +00:00
$tmp = splitfirst($html, '<!--IconValuesStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IconValuesEnd-->');
$IconValues = json_decode($tmp[0], true);
$html .= $tmp[1];
if (!$files) {
//$html = '<pre>'.json_encode($files, JSON_PRETTY_PRINT).'</pre>' . $html;
2020-05-03 10:17:18 +00:00
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFileStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
$html .= $tmp[1];
}
2020-05-07 10:45:10 +00:00
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFolderStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
$html .= $tmp[1];
2020-05-03 10:17:18 +00:00
}
2020-05-07 10:45:10 +00:00
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--ListStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ListEnd-->');
$html .= $tmp[1];
2020-05-03 10:17:18 +00:00
}
2020-05-07 10:45:10 +00:00
while (strpos($html, '<!--GuestUploadStart-->')) {
$tmp = splitfirst($html, '<!--GuestUploadStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
$html .= $tmp[1];
2020-05-03 10:17:18 +00:00
}
2020-05-07 10:45:10 +00:00
while (strpos($html, '<!--EncryptedStart-->')) {
$tmp = splitfirst($html, '<!--EncryptedStart-->');
2020-05-03 10:17:18 +00:00
$html = $tmp[0];
2020-05-07 10:45:10 +00:00
$tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
2020-05-03 10:17:18 +00:00
$html .= $tmp[1];
2020-05-07 10:45:10 +00:00
}
}
if ($_SERVER['admin']) {
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--LoginStart-->');
2020-05-03 10:17:18 +00:00
$html = $tmp[0];
2020-05-07 10:45:10 +00:00
$tmp = splitfirst($tmp[1], '<!--LoginEnd-->');
$html .= $tmp[1];
}
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--GuestStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--GuestEnd-->');
$html .= $tmp[1];
}
2020-05-07 10:45:10 +00:00
while (strpos($html, '<!--AdminStart-->')) {
$html = str_replace('<!--AdminStart-->', '', $html);
$html = str_replace('<!--AdminEnd-->', '', $html);
}
while (strpos($html, '<!--constStr@Operate-->')) $html = str_replace('<!--constStr@Operate-->', getconstStr('Operate'), $html);
while (strpos($html, '<!--constStr@Create-->')) $html = str_replace('<!--constStr@Create-->', getconstStr('Create'), $html);
while (strpos($html, '<!--constStr@Encrypt-->')) $html = str_replace('<!--constStr@Encrypt-->', getconstStr('Encrypt'), $html);
while (strpos($html, '<!--constStr@RefreshCache-->')) $html = str_replace('<!--constStr@RefreshCache-->', getconstStr('RefreshCache'), $html);
while (strpos($html, '<!--constStr@Setup-->')) $html = str_replace('<!--constStr@Setup-->', getconstStr('Setup'), $html);
while (strpos($html, '<!--constStr@Logout-->')) $html = str_replace('<!--constStr@Logout-->', getconstStr('Logout'), $html);
while (strpos($html, '<!--constStr@Rename-->')) $html = str_replace('<!--constStr@Rename-->', getconstStr('Rename'), $html);
while (strpos($html, '<!--constStr@Submit-->')) $html = str_replace('<!--constStr@Submit-->', getconstStr('Submit'), $html);
while (strpos($html, '<!--constStr@Delete-->')) $html = str_replace('<!--constStr@Delete-->', getconstStr('Delete'), $html);
while (strpos($html, '<!--constStr@Copy-->')) $html = str_replace('<!--constStr@Copy-->', getconstStr('Copy'), $html);
while (strpos($html, '<!--constStr@Move-->')) $html = str_replace('<!--constStr@Move-->', getconstStr('Move'), $html);
while (strpos($html, '<!--constStr@Folder-->')) $html = str_replace('<!--constStr@Folder-->', getconstStr('Folder'), $html);
while (strpos($html, '<!--constStr@File-->')) $html = str_replace('<!--constStr@File-->', getconstStr('File'), $html);
while (strpos($html, '<!--constStr@Name-->')) $html = str_replace('<!--constStr@Name-->', getconstStr('Name'), $html);
while (strpos($html, '<!--constStr@Content-->')) $html = str_replace('<!--constStr@Content-->', getconstStr('Content'), $html);
} else {
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--AdminStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--AdminEnd-->');
$html .= $tmp[1];
}
if (getConfig('adminloginpage')=='') {
while (strpos($html, '<!--LoginStart-->')) $html = str_replace('<!--LoginStart-->', '', $html);
while (strpos($html, '<!--LoginEnd-->')) $html = str_replace('<!--LoginEnd-->', '', $html);
} else {
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--LoginStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--LoginEnd-->');
$html .= $tmp[1];
}
}
while (strpos($html, '<!--GuestStart-->')) $html = str_replace('<!--GuestStart-->', '', $html);
while (strpos($html, '<!--GuestEnd-->')) $html = str_replace('<!--GuestEnd-->', '', $html);
2020-05-07 10:45:10 +00:00
}
if ($_SERVER['ishidden']==4) {
// 加密状态
2021-08-09 04:27:25 +00:00
if (getConfig('useBasicAuth')) {
2021-01-17 03:33:05 +00:00
// use Basic Auth
return output('Need password.', 401, ['WWW-Authenticate'=>'Basic realm="Secure Area"']);
}
/*$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--ListStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ListEnd-->');
$html .= $tmp[1];
}*/
2020-05-07 10:45:10 +00:00
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFileStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
$html .= $tmp[1];
}
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFolderStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
$html .= $tmp[1];
}
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsNotHiddenStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsNotHiddenEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--EncryptedStart-->')) {
$html = str_replace('<!--EncryptedStart-->', '', $html);
$html = str_replace('<!--EncryptedEnd-->', '', $html);
2020-05-07 10:45:10 +00:00
}
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--GuestUploadStart-->');
2020-05-07 10:45:10 +00:00
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--IsNotHiddenStart-->')) {
$tmp = splitfirst($html, '<!--IsNotHiddenStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsNotHiddenEnd-->');
$html .= $tmp[1];
}
2021-01-17 05:13:37 +00:00
while (strpos($html, '<!--HeadomfStart-->')) {
$tmp = splitfirst($html, '<!--HeadomfStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--HeadomfEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--HeadmdStart-->')) {
$tmp = splitfirst($html, '<!--HeadmdStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--HeadmdEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--ReadmemdStart-->')) {
$tmp = splitfirst($html, '<!--ReadmemdStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ReadmemdEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--FootomfStart-->')) {
$tmp = splitfirst($html, '<!--FootomfStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--FootomfEnd-->');
$html .= $tmp[1];
}
} else {
while (strpos($html, '<!--EncryptedStart-->')) {
$tmp = splitfirst($html, '<!--EncryptedStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
2020-05-07 10:45:10 +00:00
$html .= $tmp[1];
}
while (strpos($html, '<!--IsNotHiddenStart-->')) {
$html = str_replace('<!--IsNotHiddenStart-->', '', $html);
$html = str_replace('<!--IsNotHiddenEnd-->', '', $html);
}
2020-05-07 10:45:10 +00:00
}
while (strpos($html, '<!--constStr@Download-->')) $html = str_replace('<!--constStr@Download-->', getconstStr('Download'), $html);
if ($_SERVER['is_guestup_path']&&!$_SERVER['admin']) {
2020-05-07 10:45:10 +00:00
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFileStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
$html .= $tmp[1];
}
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFolderStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--GuestUploadStart-->')) {
$html = str_replace('<!--GuestUploadStart-->', '', $html);
$html = str_replace('<!--GuestUploadEnd-->', '', $html);
}
while (strpos($html, '<!--IsNotHiddenStart-->')) {
2020-05-07 10:45:10 +00:00
$tmp = splitfirst($html, '<!--IsNotHiddenStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsNotHiddenEnd-->');
$html .= $tmp[1];
}
} else {
while (strpos($html, '<!--GuestUploadStart-->')) {
$tmp = splitfirst($html, '<!--GuestUploadStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--IsNotHiddenStart-->')) {
$html = str_replace('<!--IsNotHiddenStart-->', '', $html);
$html = str_replace('<!--IsNotHiddenEnd-->', '', $html);
}
}
2021-03-07 14:43:38 +00:00
$DriverFile = scandir(__DIR__ . $slash . 'disk');
$Driver_arr = null;
foreach ($DriverFile as $v1) {
if ($v1!='.' && $v1!='..') {
$v1 = splitlast($v1, '.php')[0];
$Driver_arr[] = $v1;
2021-01-15 03:10:08 +00:00
}
2021-03-07 14:43:38 +00:00
}
if ($_SERVER['is_guestup_path']||( $_SERVER['admin']&&$files['type']=='folder'&&$_SERVER['ishidden']<4 )) {
while (strpos($html, '<!--UploadJsStart-->')) $html = str_replace('<!--UploadJsStart-->', '', $html);
while (strpos($html, '<!--UploadJsEnd-->')) $html = str_replace('<!--UploadJsEnd-->', '', $html);
$now_driver = baseclassofdrive();
unset($Driver_arr[$now_driver]);
while (strpos($html, '<!--' . $now_driver . 'UploadJsStart-->')) $html = str_replace('<!--' . $now_driver . 'UploadJsStart-->', '', $html);
while (strpos($html, '<!--' . $now_driver . 'UploadJsEnd-->')) $html = str_replace('<!--' . $now_driver . 'UploadJsEnd-->', '', $html);
foreach ($Driver_arr as $driver) {
while (strpos($html, '<!--' . $driver . 'UploadJsStart-->')) {
$tmp = splitfirst($html, '<!--' . $driver . 'UploadJsStart-->');
2021-01-15 03:10:08 +00:00
$html = $tmp[0];
2021-03-07 14:43:38 +00:00
$tmp = splitfirst($tmp[1], '<!--' . $driver . 'UploadJsEnd-->');
2021-01-15 03:10:08 +00:00
$html .= $tmp[1];
}
}
while (strpos($html, '<!--constStr@Calculate-->')) $html = str_replace('<!--constStr@Calculate-->', getconstStr('Calculate'), $html);
} else {
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--UploadJsStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--UploadJsEnd-->');
$html .= $tmp[1];
}
2021-03-07 14:43:38 +00:00
foreach ($Driver_arr as $driver) {
while (strpos($html, '<!--' . $driver . 'UploadJsStart-->')) {
$tmp = splitfirst($html, '<!--' . $driver . 'UploadJsStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--' . $driver . 'UploadJsEnd-->');
$html .= $tmp[1];
}
2021-01-15 03:10:08 +00:00
}
2020-05-07 10:45:10 +00:00
}
2020-05-26 01:49:13 +00:00
2021-01-15 03:10:08 +00:00
if ($files['type']=='file') {
2020-07-13 09:33:47 +00:00
while (strpos($html, '<!--GuestUploadStart-->')) {
$tmp = splitfirst($html, '<!--GuestUploadStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
$html .= $tmp[1];
}
$tmp = splitfirst($html, '<!--EncryptedStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
$html .= $tmp[1];
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFolderStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--IsFileStart-->')) {
$html = str_replace('<!--IsFileStart-->', '', $html);
$html = str_replace('<!--IsFileEnd-->', '', $html);
}
2021-10-06 08:01:31 +00:00
$html = str_replace('<!--FileEncodeUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
$html = str_replace('<!--FileUrl-->', (path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
2021-05-16 12:12:17 +00:00
2020-07-13 09:33:47 +00:00
$ext = strtolower(substr($path, strrpos($path, '.') + 1));
if (in_array($ext, $exts['img'])) $ext = 'img';
elseif (in_array($ext, $exts['video'])) $ext = 'video';
elseif (in_array($ext, $exts['music'])) $ext = 'music';
//elseif (in_array($ext, $exts['pdf'])) $ext = 'pdf';
elseif ($ext=='pdf') $ext = 'pdf';
elseif (in_array($ext, $exts['office'])) $ext = 'office';
elseif (in_array($ext, $exts['txt'])) $ext = 'txt';
else $ext = 'Other';
$previewext = ['img', 'video', 'music', 'pdf', 'office', 'txt', 'Other'];
$previewext = array_diff($previewext, [ $ext ]);
foreach ($previewext as $ext1) {
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--Is'.$ext1.'FileStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--Is'.$ext1.'FileEnd-->');
$html .= $tmp[1];
}
}
while (strpos($html, '<!--Is'.$ext.'FileStart-->')) {
$html = str_replace('<!--Is'.$ext.'FileStart-->', '', $html);
$html = str_replace('<!--Is'.$ext.'FileEnd-->', '', $html);
}
2021-02-01 10:17:43 +00:00
//while (strpos($html, '<!--FileDownUrl-->')) $html = str_replace('<!--FileDownUrl-->', $files['url'], $html);
2021-10-06 08:01:31 +00:00
while (strpos($html, '<!--FileDownUrl-->')) $html = str_replace('<!--FileDownUrl-->', (path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
//echo $path . "<br>\n";
while (strpos($html, '<!--FileEncodeReplaceUrl-->')) $html = str_replace('<!--FileEncodeReplaceUrl-->', (path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path))), $html);
2020-07-13 09:33:47 +00:00
while (strpos($html, '<!--FileName-->')) $html = str_replace('<!--FileName-->', $files['name'], $html);
2021-04-09 02:44:56 +00:00
while (strpos($html, '<!--FileEncodeDownUrl-->')) $html = str_replace('<!--FileEncodeDownUrl-->', urlencode($files['url']), $html);
2021-10-06 08:01:31 +00:00
//while (strpos($html, '<!--FileEncodeDownUrl-->')) $html = str_replace('<!--FileEncodeDownUrl-->', urlencode($_SERVER['host'] . path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
2020-07-13 09:33:47 +00:00
$html = str_replace('<!--constStr@ClicktoEdit-->', getconstStr('ClicktoEdit'), $html);
$html = str_replace('<!--constStr@CancelEdit-->', getconstStr('CancelEdit'), $html);
$html = str_replace('<!--constStr@Save-->', getconstStr('Save'), $html);
2021-03-31 07:28:00 +00:00
//while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(curl('GET', $files['url'], '', [], 0, 1)['body']), $html);
while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(get_content(spurlencode(path_format(urldecode($path)), '/'))['content']['body']), $html);
2020-07-13 09:33:47 +00:00
$html = str_replace('<!--constStr@FileNotSupport-->', getconstStr('FileNotSupport'), $html);
//$html = str_replace('<!--constStr@File-->', getconstStr('File'), $html);
2021-01-15 03:10:08 +00:00
} elseif ($files['type']=='folder') {
2020-05-07 10:45:10 +00:00
while (strpos($html, '<!--GuestUploadStart-->')) {
$tmp = splitfirst($html, '<!--GuestUploadStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
$html .= $tmp[1];
}
$tmp = splitfirst($html, '<!--EncryptedStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
$html .= $tmp[1];
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--IsFileStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
$html .= $tmp[1];
}
while (strpos($html, '<!--IsFolderStart-->')) {
$html = str_replace('<!--IsFolderStart-->', '', $html);
$html = str_replace('<!--IsFolderEnd-->', '', $html);
}
$html = str_replace('<!--constStr@File-->', getconstStr('File'), $html);
$html = str_replace('<!--constStr@ShowThumbnails-->', getconstStr('ShowThumbnails'), $html);
$html = str_replace('<!--constStr@CopyAllDownloadUrl-->', getconstStr('CopyAllDownloadUrl'), $html);
$html = str_replace('<!--constStr@EditTime-->', getconstStr('EditTime'), $html);
$html = str_replace('<!--constStr@Size-->', getconstStr('Size'), $html);
$filenum = 0;
$tmp = splitfirst($html, '<!--FolderListStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--FolderListEnd-->');
$FolderList = $tmp[0];
2021-01-15 03:10:08 +00:00
foreach ($files['list'] as $file) {
if ($file['type']=='folder') {
2020-05-07 10:45:10 +00:00
if ($_SERVER['admin'] or !isHideFile($file['name'])) {
$filenum++;
2021-05-16 12:12:17 +00:00
$FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path) . '/' . $file['name'])), $FolderList);
2021-01-15 03:10:08 +00:00
$FolderListStr = str_replace('<!--FileId-->', $file['id'], $FolderListStr);
$FolderListStr = str_replace('<!--FileEncodeReplaceName-->', str_replace('&','&amp;', $file['showname']?$file['showname']:$file['name']), $FolderListStr);
2021-01-15 03:10:08 +00:00
$FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['time']), $FolderListStr);
2020-05-07 10:45:10 +00:00
$FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
$html .= $FolderListStr;
}
}
}
$html .= $tmp[1];
$tmp = splitfirst($html, '<!--FileListStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--FileListEnd-->');
$FolderList = $tmp[0];
2021-01-15 03:10:08 +00:00
foreach ($files['list'] as $file) {
if ($file['type']=='file') {
2020-05-07 10:45:10 +00:00
if ($_SERVER['admin'] or !isHideFile($file['name'])) {
$filenum++;
$ext = strtolower(substr($file['name'], strrpos($file['name'], '.') + 1));
2021-03-07 15:07:54 +00:00
$FolderListStr = $FolderList;
2021-05-16 12:12:17 +00:00
while (strpos($FolderListStr, '<!--FileEncodeReplaceUrl-->')) $FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path) . '/' . $file['name'])), $FolderListStr);
2020-05-26 01:49:13 +00:00
$FolderListStr = str_replace('<!--FileExt-->', $ext, $FolderListStr);
if (in_array($ext, $exts['music'])) $FolderListStr = str_replace('<!--FileExtType-->', 'audio', $FolderListStr);
elseif (in_array($ext, $exts['video'])) $FolderListStr = str_replace('<!--FileExtType-->', 'iframe', $FolderListStr);
else $FolderListStr = str_replace('<!--FileExtType-->', '', $FolderListStr);
2020-05-07 10:45:10 +00:00
$FolderListStr = str_replace('<!--FileEncodeReplaceName-->', str_replace('&','&amp;', $file['name']), $FolderListStr);
2021-01-15 03:10:08 +00:00
$FolderListStr = str_replace('<!--FileId-->', $file['id'], $FolderListStr);
2020-05-07 10:45:10 +00:00
//$FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . str_replace('&','&amp;', $file['name'])), $FolderListStr);
2021-01-15 03:10:08 +00:00
$FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['time']), $FolderListStr);
2020-05-07 10:45:10 +00:00
$FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
2020-05-24 07:07:56 +00:00
if (!!$IconValues) {
foreach ($IconValues as $key1 => $value1) {
if (isset($exts[$key1])&&in_array($ext, $exts[$key1])) {
$FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
}
if ($ext==$key1) {
$FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
}
//error_log1('file:'.$file['name'].':'.$key1);
2020-05-24 07:07:56 +00:00
if (!strpos($FolderListStr, '<!--IconValue-->')) break;
2020-05-07 10:45:10 +00:00
}
2020-05-24 07:07:56 +00:00
if (strpos($FolderListStr, '<!--IconValue-->')) $FolderListStr = str_replace('<!--IconValue-->', $IconValues['default'], $FolderListStr);
2020-05-07 10:45:10 +00:00
}
while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
$html .= $FolderListStr;
}
}
}
$html .= $tmp[1];
while (strpos($html, '<!--maxfilenum-->')) $html = str_replace('<!--maxfilenum-->', $filenum, $html);
2021-01-15 03:10:08 +00:00
if ($files['childcount']>200) {
2020-05-07 10:45:10 +00:00
while (strpos($html, '<!--MorePageStart-->')) $html = str_replace('<!--MorePageStart-->', '', $html);
while (strpos($html, '<!--MorePageEnd-->')) $html = str_replace('<!--MorePageEnd-->', '', $html);
2021-01-15 03:10:08 +00:00
$pagenum = $files['page'];
2020-05-07 10:45:10 +00:00
if ($pagenum=='') $pagenum = 1;
2021-01-15 03:10:08 +00:00
$maxpage = ceil($files['childcount']/200);
2020-05-07 10:45:10 +00:00
if ($pagenum!=1) {
$html = str_replace('<!--PrePageStart-->', '', $html);
$html = str_replace('<!--PrePageEnd-->', '', $html);
$html = str_replace('<!--constStr@PrePage-->', getconstStr('PrePage'), $html);
$html = str_replace('<!--PrePageNum-->', $pagenum-1, $html);
} else {
$tmp = splitfirst($html, '<!--PrePageStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--PrePageEnd-->');
$html .= $tmp[1];
}
//$html .= json_encode($files['folder']);
if ($pagenum!=$maxpage) {
$html = str_replace('<!--NextPageStart-->', '', $html);
$html = str_replace('<!--NextPageEnd-->', '', $html);
$html = str_replace('<!--constStr@NextPage-->', getconstStr('NextPage'), $html);
$html = str_replace('<!--NextPageNum-->', $pagenum+1, $html);
} else {
$tmp = splitfirst($html, '<!--NextPageStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--NextPageEnd-->');
$html .= $tmp[1];
}
$tmp = splitfirst($html, '<!--MorePageListNowStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MorePageListNowEnd-->');
$MorePageListNow = str_replace('<!--PageNum-->', $pagenum, $tmp[0]);
$html .= $tmp[1];
$tmp = splitfirst($html, '<!--MorePageListStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MorePageListEnd-->');
$MorePageList = $tmp[0];
2020-05-03 10:17:18 +00:00
for ($page=1;$page<=$maxpage;$page++) {
if ($page == $pagenum) {
$MorePageListStr = $MorePageListNow;
} else {
$MorePageListStr = str_replace('<!--PageNum-->', $page, $MorePageList);
$MorePageListStr = str_replace('<!--PageNum-->', $page, $MorePageListStr);
}
$html .= $MorePageListStr;
}
$html .= $tmp[1];
2020-05-24 10:15:31 +00:00
while (strpos($html, '<!--MaxPageNum-->')) $html = str_replace('<!--MaxPageNum-->', $maxpage, $html);
2020-05-03 10:17:18 +00:00
} else {
while (strpos($html, '<!--MorePageStart-->')) {
$tmp = splitfirst($html, '<!--MorePageStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MorePageEnd-->');
$html .= $tmp[1];
}
}
}
$html = str_replace('<!--constStr@language-->', $constStr['language'], $html);
$title = $pretitle;
if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) {
if (getConfig('diskname')!='') $diskname = getConfig('diskname');
else $diskname = $_SERVER['disktag'];
$title .= ' - ' . $diskname;
}
$title .= ' - ' . $_SERVER['sitename'];
$html = str_replace('<!--Title-->', $title, $html);
$keywords = $n_path;
2020-05-15 12:22:35 +00:00
if ($p_path!='') $keywords .= ', ' . $p_path;
if ($_SERVER['sitename']!='OneManager') $keywords .= ', ' . $_SERVER['sitename'] . ', OneManager';
else $keywords .= ', OneManager';
2020-05-03 10:17:18 +00:00
$html = str_replace('<!--Keywords-->', $keywords, $html);
2020-05-15 12:22:35 +00:00
if ($_GET['preview']) {
$description = $n_path.', '.getconstStr('Preview');//'Preview of '.
2021-01-15 03:10:08 +00:00
} elseif ($files['type']=='folder') {
2020-05-15 12:22:35 +00:00
$description = $n_path.', '.getconstStr('List');//'List of '.$n_path.'. ';
}
//$description .= 'In '.$_SERVER['sitename'];
2020-05-03 10:17:18 +00:00
$html = str_replace('<!--Description-->', $description, $html);
2020-05-30 07:05:23 +00:00
while (strpos($html, '<!--base_disk_path-->')) $html = str_replace('<!--base_disk_path-->', (substr($_SERVER['base_disk_path'],-1)=='/'?substr($_SERVER['base_disk_path'],0,-1):$_SERVER['base_disk_path']), $html);
2020-05-03 10:17:18 +00:00
while (strpos($html, '<!--base_path-->')) $html = str_replace('<!--base_path-->', $_SERVER['base_path'], $html);
while (strpos($html, '<!--Path-->')) $html = str_replace('<!--Path-->', str_replace('%23', '#', str_replace('&','&amp;', path_format($path.'/'))), $html);
2020-05-03 10:17:18 +00:00
while (strpos($html, '<!--constStr@Home-->')) $html = str_replace('<!--constStr@Home-->', getconstStr('Home'), $html);
2020-05-03 10:17:18 +00:00
$html = str_replace('<!--customCss-->', getConfig('customCss'), $html);
$html = str_replace('<!--customScript-->', getConfig('customScript'), $html);
2020-05-04 03:41:31 +00:00
while (strpos($html, '<!--constStr@Login-->')) $html = str_replace('<!--constStr@Login-->', getconstStr('Login'), $html);
while (strpos($html, '<!--constStr@Close-->')) $html = str_replace('<!--constStr@Close-->', getconstStr('Close'), $html);
while (strpos($html, '<!--constStr@InputPassword-->')) $html = str_replace('<!--constStr@InputPassword-->', getconstStr('InputPassword'), $html);
while (strpos($html, '<!--constStr@InputPasswordUWant-->')) $html = str_replace('<!--constStr@InputPasswordUWant-->', getconstStr('InputPasswordUWant'), $html);
while (strpos($html, '<!--constStr@Submit-->')) $html = str_replace('<!--constStr@Submit-->', getconstStr('Submit'), $html);
while (strpos($html, '<!--constStr@Success-->')) $html = str_replace('<!--constStr@Success-->', getconstStr('Success'), $html);
while (strpos($html, '<!--constStr@GetUploadLink-->')) $html = str_replace('<!--constStr@GetUploadLink-->', getconstStr('GetUploadLink'), $html);
while (strpos($html, '<!--constStr@UpFileTooLarge-->')) $html = str_replace('<!--constStr@UpFileTooLarge-->', getconstStr('UpFileTooLarge'), $html);
while (strpos($html, '<!--constStr@UploadStart-->')) $html = str_replace('<!--constStr@UploadStart-->', getconstStr('UploadStart'), $html);
while (strpos($html, '<!--constStr@UploadStartAt-->')) $html = str_replace('<!--constStr@UploadStartAt-->', getconstStr('UploadStartAt'), $html);
while (strpos($html, '<!--constStr@LastUpload-->')) $html = str_replace('<!--constStr@LastUpload-->', getconstStr('LastUpload'), $html);
while (strpos($html, '<!--constStr@ThisTime-->')) $html = str_replace('<!--constStr@ThisTime-->', getconstStr('ThisTime'), $html);
while (strpos($html, '<!--constStr@Upload-->')) $html = str_replace('<!--constStr@Upload-->', getconstStr('Upload'), $html);
while (strpos($html, '<!--constStr@AverageSpeed-->')) $html = str_replace('<!--constStr@AverageSpeed-->', getconstStr('AverageSpeed'), $html);
while (strpos($html, '<!--constStr@CurrentSpeed-->')) $html = str_replace('<!--constStr@CurrentSpeed-->', getconstStr('CurrentSpeed'), $html);
while (strpos($html, '<!--constStr@Expect-->')) $html = str_replace('<!--constStr@Expect-->', getconstStr('Expect'), $html);
while (strpos($html, '<!--constStr@UploadErrorUpAgain-->')) $html = str_replace('<!--constStr@UploadErrorUpAgain-->', getconstStr('UploadErrorUpAgain'), $html);
while (strpos($html, '<!--constStr@EndAt-->')) $html = str_replace('<!--constStr@EndAt-->', getconstStr('EndAt'), $html);
2020-05-03 10:17:18 +00:00
2020-05-04 03:41:31 +00:00
while (strpos($html, '<!--constStr@UploadComplete-->')) $html = str_replace('<!--constStr@UploadComplete-->', getconstStr('UploadComplete'), $html);
while (strpos($html, '<!--constStr@CopyUrl-->')) $html = str_replace('<!--constStr@CopyUrl-->', getconstStr('CopyUrl'), $html);
while (strpos($html, '<!--constStr@UploadFail23-->')) $html = str_replace('<!--constStr@UploadFail23-->', getconstStr('UploadFail23'), $html);
while (strpos($html, '<!--constStr@GetFileNameFail-->')) $html = str_replace('<!--constStr@GetFileNameFail-->', getconstStr('GetFileNameFail'), $html);
while (strpos($html, '<!--constStr@UploadFile-->')) $html = str_replace('<!--constStr@UploadFile-->', getconstStr('UploadFile'), $html);
while (strpos($html, '<!--constStr@UploadFolder-->')) $html = str_replace('<!--constStr@UploadFolder-->', getconstStr('UploadFolder'), $html);
2020-05-20 09:20:10 +00:00
while (strpos($html, '<!--constStr@FileSelected-->')) $html = str_replace('<!--constStr@FileSelected-->', getconstStr('FileSelected'), $html);
2020-05-04 03:41:31 +00:00
while (strpos($html, '<!--IsPreview?-->')) $html = str_replace('<!--IsPreview?-->', (isset($_GET['preview'])?'?preview&':'?'), $html);
2020-05-03 10:17:18 +00:00
$tmp = splitfirst($html, '<!--BackgroundStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--BackgroundEnd-->');
if (getConfig('background')) {
2020-08-16 04:14:13 +00:00
$html .= str_replace('<!--BackgroundUrl-->', getConfig('background'), $tmp[0]);
}
$html .= $tmp[1];
$tmp = splitfirst($html, '<!--BackgroundMStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--BackgroundMEnd-->');
if (getConfig('backgroundm')) {
$html .= str_replace('<!--BackgroundMUrl-->', getConfig('backgroundm'), $tmp[0]);
2020-05-03 10:17:18 +00:00
}
2020-08-16 04:14:13 +00:00
$html .= $tmp[1];
2020-05-22 08:05:12 +00:00
$tmp = splitfirst($html, '<!--PathArrayStart-->');
$html = $tmp[0];
if ($tmp[1]!='') {
$tmp = splitfirst($tmp[1], '<!--PathArrayEnd-->');
$PathArrayStr = $tmp[0];
$tmp_url = $_SERVER['base_disk_path'];
$tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
while ($tmp_path!='') {
$tmp1 = splitfirst($tmp_path, '/');
$folder1 = $tmp1[0];
if ($folder1!='') {
2021-05-16 12:12:17 +00:00
$tmp_url .= str_replace('&amp;', '&', $folder1) . '/';
2021-04-21 15:45:18 +00:00
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', encode_str_replace($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
$PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1);
$html .= $PathArrayStr1;
}
$tmp_path = $tmp1[1];
}
$html .= $tmp[1];
}
$tmp = splitfirst($html, '<!--DiskPathArrayStart-->');
$html = $tmp[0];
if ($tmp[1]!='') {
$tmp = splitfirst($tmp[1], '<!--DiskPathArrayEnd-->');
$PathArrayStr = $tmp[0];
$tmp_url = $_SERVER['base_path'];
$tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
while ($tmp_path!='') {
$tmp1 = splitfirst($tmp_path, '/');
$folder1 = $tmp1[0];
if ($folder1!='') {
2021-05-16 12:12:17 +00:00
$tmp_url .= str_replace('&amp;', '&', $folder1) . '/';
2021-04-21 15:45:18 +00:00
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', encode_str_replace($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
$PathArrayStr1 = str_replace('<!--PathArrayName-->', ($folder1==$_SERVER['disktag']?(getConfig('diskname')==''?$_SERVER['disktag']:getConfig('diskname')):$folder1), $PathArrayStr1);
$html .= $PathArrayStr1;
}
$tmp_path = $tmp1[1];
}
$html .= $tmp[1];
2020-05-22 08:05:12 +00:00
}
2020-05-03 10:17:18 +00:00
$tmp = splitfirst($html, '<!--SelectLanguageStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--SelectLanguageEnd-->');
$SelectLanguage = $tmp[0];
foreach ($constStr['languages'] as $key1 => $value1) {
$SelectLanguageStr = str_replace('<!--SelectLanguageKey-->', $key1, $SelectLanguage);
$SelectLanguageStr = str_replace('<!--SelectLanguageValue-->', $value1, $SelectLanguageStr);
$SelectLanguageStr = str_replace('<!--SelectLanguageSelected-->', ($key1==$constStr['language']?'selected="selected"':''), $SelectLanguageStr);
$html .= $SelectLanguageStr;
}
$html .= $tmp[1];
$tmp = splitfirst($html, '<!--NeedUpdateStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--NeedUpdateEnd-->');
$NeedUpdateStr = $tmp[0];
if (isset($_SERVER['needUpdate'])&&$_SERVER['needUpdate']) $NeedUpdateStr = str_replace('<!--constStr@NeedUpdate-->', getconstStr('NeedUpdate'), $NeedUpdateStr);
else $NeedUpdateStr ='';
$html .= $NeedUpdateStr . $tmp[1];
$tmp = splitfirst($html, '<!--BackArrowStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--BackArrowEnd-->');
$current_url = path_format($_SERVER['PHP_SELF'] . '/');
if ($current_url !== $_SERVER['base_path']) {
2020-05-03 10:17:18 +00:00
while (substr($current_url, -1) === '/') {
$current_url = substr($current_url, 0, -1);
}
if (strpos($current_url, '/') !== FALSE) {
$parent_url = substr($current_url, 0, strrpos($current_url, '/'));
} else {
$parent_url = $current_url;
}
$BackArrow = str_replace('<!--BackArrowUrl-->', $parent_url.'/', $tmp[0]);
}
$html .= $BackArrow . $tmp[1];
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--ShowThumbnailsStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ShowThumbnailsEnd-->');
2020-05-24 11:15:09 +00:00
//if (!(isset($_SERVER['USER'])&&$_SERVER['USER']=='qcloud')) {
if (!getConfig('disableShowThumb')) {
2020-05-15 12:22:35 +00:00
$html .= str_replace('<!--constStr@OriginalPic-->', getconstStr('OriginalPic'), $tmp[0]) . $tmp[1];
2020-05-03 10:17:18 +00:00
} else $html .= $tmp[1];
}
$imgextstr = '';
foreach ($exts['img'] as $imgext) $imgextstr .= '\''.$imgext.'\', ';
$html = str_replace('<!--ImgExts-->', $imgextstr, $html);
$html = str_replace('<!--Sitename-->', $_SERVER['sitename'], $html);
$tmp = splitfirst($html, '<!--MultiDiskAreaStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MultiDiskAreaEnd-->');
$disktags = explode("|",getConfig('disktag'));
if (count($disktags)>1) {
$tmp1 = $tmp[1];
$tmp = splitfirst($tmp[0], '<!--MultiDisksStart-->');
$MultiDiskArea = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MultiDisksEnd-->');
$MultiDisks = $tmp[0];
foreach ($disktags as $disk) {
$diskname = getConfig('diskname', $disk);
if ($diskname=='') $diskname = $disk;
$MultiDisksStr = str_replace('<!--MultiDisksUrl-->', path_format($_SERVER['base_path'].'/'.$disk.'/'), $MultiDisks);
$MultiDisksStr = str_replace('<!--MultiDisksNow-->', ($_SERVER['disktag']==$disk?' now':''), $MultiDisksStr);
$MultiDisksStr = str_replace('<!--MultiDisksName-->', $diskname, $MultiDisksStr);
$MultiDiskArea .= $MultiDisksStr;
}
$MultiDiskArea .= $tmp[1];
$tmp[1] = $tmp1;
}
$html .= $MultiDiskArea . $tmp[1];
2021-01-15 03:10:08 +00:00
$diskname = getConfig('diskname', $_SERVER['disktag']);
2020-05-20 09:20:10 +00:00
if ($diskname=='') $diskname = $_SERVER['disktag'];
2020-05-30 07:05:23 +00:00
//if (strlen($diskname)>15) $diskname = substr($diskname, 0, 12).'...';
2020-05-20 09:20:10 +00:00
while (strpos($html, '<!--DiskNameNow-->')) $html = str_replace('<!--DiskNameNow-->', $diskname, $html);
2020-05-03 10:17:18 +00:00
$tmp = splitfirst($html, '<!--HeadomfStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--HeadomfEnd-->');
2021-01-15 03:10:08 +00:00
if (isset($files['list']['head.omf'])) {
$headomf = str_replace('<!--HeadomfContent-->', get_content(spurlencode(path_format($path . '/' . $files['list']['head.omf']['name']), '/'))['content']['body'], $tmp[0]);
2020-05-03 10:17:18 +00:00
}
$html .= $headomf . $tmp[1];
$tmp = splitfirst($html, '<!--HeadmdStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--HeadmdEnd-->');
2021-01-15 03:10:08 +00:00
if (isset($files['list']['head.md'])) {
$headmd = str_replace('<!--HeadmdContent-->', get_content(spurlencode(path_format($path . '/' . $files['list']['head.md']['name']), '/'))['content']['body'], $tmp[0]);
2020-05-03 10:17:18 +00:00
$html .= $headmd . $tmp[1];
while (strpos($html, '<!--HeadmdStart-->')) {
$html = str_replace('<!--HeadmdStart-->', '', $html);
$html = str_replace('<!--HeadmdEnd-->', '', $html);
}
} else {
$html .= $tmp[1];
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--HeadmdStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--HeadmdEnd-->');
$html .= $tmp[1];
}
}
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--ListStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ListEnd-->');
$html_aft = $tmp[1];
if ($files) {
$listarea = $tmp[0];
}
$html .= $listarea . $html_aft;
}
$tmp = splitfirst($html, '<!--ReadmemdStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ReadmemdEnd-->');
2021-01-15 03:10:08 +00:00
if (isset($files['list']['readme.md'])) {
$Readmemd = str_replace('<!--ReadmemdContent-->', get_content(spurlencode(path_format($path . '/' . $files['list']['readme.md']['name']),'/'))['content']['body'], $tmp[0]);
2020-05-03 10:17:18 +00:00
$html .= $Readmemd . $tmp[1];
while (strpos($html, '<!--ReadmemdStart-->')) {
$html = str_replace('<!--ReadmemdStart-->', '', $html);
$html = str_replace('<!--ReadmemdEnd-->', '', $html);
}
} else {
$html .= $tmp[1];
$tmp[1] = 'a';
while ($tmp[1]!='') {
$tmp = splitfirst($html, '<!--ReadmemdStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ReadmemdEnd-->');
$html .= $tmp[1];
}
}
$tmp = splitfirst($html, '<!--FootomfStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--FootomfEnd-->');
2021-01-15 03:10:08 +00:00
if (isset($files['list']['foot.omf'])) {
$Footomf = str_replace('<!--FootomfContent-->', get_content(spurlencode(path_format($path . '/' . $files['list']['foot.omf']['name']),'/'))['content']['body'], $tmp[0]);
2020-05-03 10:17:18 +00:00
}
$html .= $Footomf . $tmp[1];
$tmp = splitfirst($html, '<!--MdRequireStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MdRequireEnd-->');
2021-01-15 03:10:08 +00:00
if (isset($files['list']['head.md'])||isset($files['list']['readme.md'])) {
2020-05-03 10:17:18 +00:00
$html .= $tmp[0] . $tmp[1];
} else $html .= $tmp[1];
if (getConfig('passfile')!='') {
$tmp = splitfirst($html, '<!--EncryptBtnStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptBtnEnd-->');
$html .= str_replace('<!--constStr@Encrypt-->', getconstStr('Encrypt'), $tmp[0]) . $tmp[1];
$tmp = splitfirst($html, '<!--EncryptAlertStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptAlertEnd-->');
$html .= $tmp[1];
} else {
$tmp = splitfirst($html, '<!--EncryptAlertStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptAlertEnd-->');
$html .= str_replace('<!--constStr@SetpassfileBfEncrypt-->', getconstStr('SetpassfileBfEncrypt'), $tmp[0]) . $tmp[1];
$tmp = splitfirst($html, '<!--EncryptBtnStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--EncryptBtnEnd-->');
$html .= $tmp[1];
}
$tmp = splitfirst($html, '<!--MoveRootStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MoveRootEnd-->');
if ($path != '/') {
$html .= str_replace('<!--constStr@ParentDir-->', getconstStr('ParentDir'), $tmp[0]) . $tmp[1];
} else $html .= $tmp[1];
$tmp = splitfirst($html, '<!--MoveDirsStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MoveDirsEnd-->');
$MoveDirs = $tmp[0];
2021-01-15 03:10:08 +00:00
if ($files['type']=='folder') {
foreach ($files['list'] as $file) {
if ($file['type']=='folder') {
2020-05-03 10:17:18 +00:00
$MoveDirsStr = str_replace('<!--MoveDirsValue-->', str_replace('&','&amp;', $file['name']), $MoveDirs);
$MoveDirsStr = str_replace('<!--MoveDirsValue-->', str_replace('&','&amp;', $file['name']), $MoveDirsStr);
$html .= $MoveDirsStr;
}
}
}
$html .= $tmp[1];
$tmp = splitfirst($html, '<!--WriteTimezoneStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--WriteTimezoneEnd-->');
if (!isset($_COOKIE['timezone'])) $html .= str_replace('<!--timezone-->', $_SERVER['timezone'], $tmp[0]);
$html .= $tmp[1];
while (strpos($html, '<!--timezone-->')) $html = str_replace('<!--timezone-->', $_SERVER['timezone'], $html);
2020-05-03 10:17:18 +00:00
2020-05-30 07:05:23 +00:00
while (strpos($html, '{{.RawData}}')) {
$str = '[';
$i = 0;
2021-01-15 03:10:08 +00:00
foreach ($files['list'] as $file) if ($_SERVER['admin'] or !isHideFile($file['name'])) {
2020-05-30 07:05:23 +00:00
$tmp = [];
$tmp['name'] = $file['name'];
$tmp['size'] = size_format($file['size']);
$tmp['date'] = time_format($file['lastModifiedDateTime']);
$tmp['@time'] = $file['date'];
2021-01-15 03:10:08 +00:00
$tmp['@type'] = ($file['type']=='folder')?'folder':'file';
2020-05-30 07:05:23 +00:00
$str .= json_encode($tmp).',';
}
if ($str == '[') {
$str = '';
} else $str = substr($str, 0, -1).']';
$html = str_replace('{{.RawData}}', base64_encode($str), $html);
}
2020-05-21 10:05:18 +00:00
// 最后清除换行
//while (strpos($html, "\r\n\r\n")) $html = str_replace("\r\n\r\n", "\r\n", $html);
//while (strpos($html, "\r\r")) $html = str_replace("\r\r", "\r", $html);
//while (strpos($html, "\n\n")) $html = str_replace("\n\n", "\n", $html);
2020-05-21 10:05:18 +00:00
//while (strpos($html, PHP_EOL.PHP_EOL)) $html = str_replace(PHP_EOL.PHP_EOL, PHP_EOL, $html);
$exetime = round(microtime(true)-$_SERVER['php_starttime'],3);
2021-01-15 03:10:08 +00:00
//$ip2city = json_decode(curl('GET', 'http://ip.taobao.com/outGetIpInfo?ip=' . $_SERVER['REMOTE_ADDR'] . '&accessKey=alibaba-inc')['body'], true);
//if ($ip2city['code']===0) $city = ' ' . $ip2city['data']['city'];
$html = str_replace('<!--FootStr-->', date("Y-m-d H:i:s") . " " . getconstStr('Week')[date("w")] . " " . $_SERVER['REMOTE_ADDR'] . $city . ' Runningtime:' . $exetime . 's Mem:' . size_format(memory_get_usage()), $html);
2020-05-21 10:05:18 +00:00
}
/*if ($_SERVER['admin']||!getConfig('disableChangeTheme')) {
2020-09-13 05:21:02 +00:00
$theme_arr = scandir(__DIR__ . $slash . 'theme');
2021-01-15 03:10:08 +00:00
$selecttheme = '
<div style="position: fixed;right: 10px;bottom: 10px;">
<select name="theme" onchange="changetheme(this.options[this.options.selectedIndex].value)">
<option value="">'.getconstStr('Theme').'</option>';
foreach ($theme_arr as $v1) {
2021-01-15 03:10:08 +00:00
if ($v1!='.' && $v1!='..') $selecttheme .= '
<option value="' . $v1 . '"' . ($v1==$theme?' selected="selected"':'') . '>' . $v1 . '</option>';
}
2021-01-15 03:10:08 +00:00
$selecttheme .= '
</select>
</div>
';
$selectthemescript ='
2020-05-21 09:56:45 +00:00
<script type="text/javascript">
function changetheme(str)
{
2020-05-24 11:15:09 +00:00
var expd = new Date();
expd.setTime(expd.getTime()+(2*60*60*1000));
var expires = "expires="+expd.toGMTString();
document.cookie=\'theme=\'+str+\'; path=/; \'+expires;
2020-05-21 09:56:45 +00:00
location.href = location.href;
}
</script>';
2021-01-15 03:10:08 +00:00
$tmp = splitfirst($html, '</body>');
$html = $tmp[0] . $selecttheme . '</body>' . $selectthemescript . $tmp[1];
}*/
2020-05-21 09:56:45 +00:00
2021-01-15 03:10:08 +00:00
$tmp = splitfirst($html, '</title>');
$html = $tmp[0] . '</title>' . $authinfo . $tmp[1];
2021-02-23 09:20:19 +00:00
//if (isset($_SERVER['Set-Cookie'])) return output($html, $statusCode, [ 'Set-Cookie' => $_SERVER['Set-Cookie'], 'Content-Type' => 'text/html' ]);
2021-01-15 03:10:08 +00:00
return output($html, $statusCode);
2020-01-18 12:12:21 +00:00
}