diff --git a/.replit b/.replit
new file mode 100644
index 0000000..1dbf6d9
--- /dev/null
+++ b/.replit
@@ -0,0 +1,3 @@
+language = "php74"
+run = "php -S 0.0.0.0:8000 index.php"
+entrypoint = "index.php"
diff --git a/common.php b/common.php
index 672438d..13f6278 100644
--- a/common.php
+++ b/common.php
@@ -21,7 +21,7 @@ $EnvConfigs = [
'admin' => 0b000,
'adminloginpage' => 0b010,
- 'autoJumpFirstDisk' => 0b010,
+ //'autoJumpFirstDisk' => 0b010,
'background' => 0b011,
'backgroundm' => 0b011,
'disableShowThumb' => 0b010,
@@ -38,6 +38,10 @@ $EnvConfigs = [
'useBasicAuth' => 0b010,
'referrer' => 0b011,
'forceHttps' => 0b010,
+ 'globalHeadOmfUrl' => 0b011,
+ 'globalHeadMdUrl' => 0b011,
+ 'globalReadmeMdUrl' => 0b011,
+ 'globalFootOmfUrl' => 0b011,
'Driver' => 0b100,
'client_id' => 0b100,
@@ -137,6 +141,7 @@ function main($path)
$_SERVER['php_starttime'] = microtime(true);
$path = path_format($path);
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
+ $_SERVER['base_disk_path'] = $_SERVER['base_path'];
if (getConfig('forceHttps')&&$_SERVER['REQUEST_SCHEME']=='http') {
if ($_GET) {
$tmp = '';
@@ -166,14 +171,23 @@ function main($path)
$_SERVER['timezone'] = getConfig('timezone');
if (isset($_COOKIE['timezone'])&&$_COOKIE['timezone']!='') $_SERVER['timezone'] = $_COOKIE['timezone'];
if ($_SERVER['timezone']=='') $_SERVER['timezone'] = 0;
+ $_SERVER['sitename'] = getConfig('sitename');
+ if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
+ if (isset($_GET['WaitFunction'])) {
+ $response = WaitFunction($_GET['WaitFunction']);
+ //var_dump($response);
+ if ($response===true) return output("ok", 200);
+ elseif ($response===false) return output("", 206);
+ else return $response;
+ }
if (getConfig('admin')=='') return install();
if (getConfig('adminloginpage')=='') {
$adminloginpage = 'admin';
} else {
$adminloginpage = getConfig('adminloginpage');
}
- if (isset($_GET[$adminloginpage])) {
+ if (isset($_GET['login'])&&$_GET['login']==$adminloginpage) {
/*if (isset($_GET['preview'])) {
$url = $_SERVER['PHP_SELF'] . '?preview';
} else {
@@ -204,63 +218,6 @@ function main($path)
$url = path_format($_SERVER['PHP_SELF'] . '/');
return output('', 302, [ 'Location' => $url ]);
}
- 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;
- }
-
- $_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) {
- if ($path=='/'||$path=='') {
- $files['type'] = 'folder';
- $files['childcount'] = count($disktags);
- $files['showname'] = 'root';
- foreach ($disktags as $disktag) {
- $files['list'][$disktag]['type'] = 'folder';
- $files['list'][$disktag]['name'] = $disktag;
- $files['list'][$disktag]['showname'] = getConfig('diskname', $disktag);
- }
- if ($_GET['json']) {
- // return a json
- return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
- }
- if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
- } 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 ' . $tmp . '.', 302, [ 'Location' => $tmp ]);
- //return message('Please visit from Home Page.', 'Error', 404);
- }
- $path = substr($path, strlen('/' . $_SERVER['disktag']));
- if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
- }
- } else $_SERVER['disktag'] = $disktags[0];
- // echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.'';
- $_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
- if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';
- $path1 = path_format($_SERVER['list_path'] . path_format($path));
- if ($path1!='/' && substr($path1,-1)=='/') $path1 = substr($path1, 0, -1);
- $_SERVER['is_guestup_path'] = is_guestup_path($path);
- $_SERVER['ajax']=0;
- if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
// Add disk
if (isset($_GET['AddDisk'])) {
@@ -269,9 +226,10 @@ function main($path)
return output('Please visit ' . $tmp . '.', 301, [ 'Location' => $tmp ]);
}
if ($_SERVER['admin']) {
+ if (!$_SERVER['disktag']) $_SERVER['disktag'] = '';
if (!class_exists($_GET['AddDisk'])) require 'disk' . $slash . $_GET['AddDisk'] . '.php';
- $drive = new $_GET['AddDisk']($_GET['disktag']);
- return $drive->AddDisk();
+ $drive = new $_GET['AddDisk']($_GET['disktag']);
+ return $drive->AddDisk();
} else {
$url = $_SERVER['PHP_SELF'];
/*if ($_GET) {
@@ -291,20 +249,67 @@ function main($path)
}
}
+ $disktags = explode("|", getConfig('disktag'));
+ // echo 'count$disk:'.count($disktags);
+ if (count($disktags)>1) {
+ if ($path=='/'||$path=='') {
+ $files['type'] = 'folder';
+ $files['childcount'] = count($disktags);
+ $files['showname'] = 'root';
+ foreach ($disktags as $disktag) {
+ $files['list'][$disktag]['type'] = 'folder';
+ $files['list'][$disktag]['name'] = $disktag;
+ $files['list'][$disktag]['showname'] = getConfig('diskname', $disktag);
+ }
+ if ($_GET['json']) {
+ // return a json
+ return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
+ }
+ //if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
+ } 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 ' . $tmp . '.', 302, [ 'Location' => $tmp ]);
+ //return message('Please visit from Home Page.', 'Error', 404);
+ }
+ //$path = substr($path, strlen('/' . $_SERVER['disktag']));
+ $path = splitfirst($path, $_SERVER['disktag'])[1];
+ if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
+ }
+ } 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'] = '/';
+ $path1 = path_format($_SERVER['list_path'] . path_format($path));
+ if ($path1!='/' && substr($path1,-1)=='/') $path1 = substr($path1, 0, -1);
+ $_SERVER['is_guestup_path'] = is_guestup_path($path);
+ $_SERVER['ajax']=0;
+ if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
+
if (!isreferhost()) return message('Must visit from designated host', 'NOT_ALLOWED', 403);
- // Show disks in root
- if ($files['showname'] == 'root') return render_list($path, $files);
-
- if (!driveisfine($_SERVER['disktag'], $drive)) return render_list();
-
// Operate
if ($_SERVER['ajax']) {
+ //error_log1($_SERVER['REQUEST_METHOD']);
if ($_GET['action']=='del_upload_cache') {
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件
+ if (!driveisfine($_SERVER['disktag'], $drive)) return output('Not in drive, or disk [' . $_SERVER['disktag'] . '] error.', 403);
+ savecache('path_' . $path1, '', $_SERVER['disktag'], 1); // clear cache.
return $drive->del_upload_cache($path);
}
if ($_GET['action']=='upbigfile') {
+ if (!driveisfine($_SERVER['disktag'], $drive)) return output('Not in drive, or disk [' . $_SERVER['disktag'] . '] error.', 403);
if (!$_SERVER['admin']) {
if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400);
if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400);
@@ -323,6 +328,12 @@ function main($path)
} else {
if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401);
}
+
+ // Show disks in root
+ if ($files['showname'] == 'root') return render_list($path, $files);
+
+ if (!driveisfine($_SERVER['disktag'], $drive)) return render_list();
+
$_SERVER['ishidden'] = passhidden($path);
if (isset($_GET['thumbnails'])) {
if ($_SERVER['ishidden']<4) {
@@ -350,7 +361,7 @@ function main($path)
$files = json_decode('{"type":"folder"}', true);
} elseif ($_SERVER['ishidden']==4) {
if (!getConfig('downloadencrypt', $_SERVER['disktag'])) {
- $files = json_decode('{"type":"folder"}', true);
+ $files = json_decode('{"type":"file"}', true);
} else {
$files = $drive->list_files($path1);
if ($files['type']=='folder') $files = json_decode('{"type":"folder"}', true);
@@ -358,7 +369,8 @@ function main($path)
} else {
$files = $drive->list_files($path1);
}
- if ($path!=='') if ( $files['type']=='folder' && substr($path, -1)!=='/' ) {
+ //if ($path!=='')
+ if ( $files['type']=='folder' && substr($path, -1)!=='/' ) {
$tmp = path_format($_SERVER['base_disk_path'] . $path . '/');
return output('
@@ -552,7 +564,7 @@ function compareadminsha1($adminsha1, $timestamp, $pass)
if (!is_numeric($timestamp)) return 'Timestamp not Number';
if (abs(time()-$timestamp) > 5*60) {
date_default_timezone_set('UTC');
- return 'The timestamp in server is ' . time() . ' (' . date("Y-m-d H:i:s") . ' UTC),
and your posted timestamp is ' . $timestamp . ' (' . date("Y-m-d H:i:s", $timestamp) . ' UTC)';
+ return 'The time in server is ' . time() . ' (' . date("Y-m-d H:i:s") . ' UTC),
and your time is ' . $timestamp . ' (' . date("Y-m-d H:i:s", $timestamp) . ' UTC)';
}
if ($adminsha1 == sha1($timestamp . $pass)) return '';
else return 'Error password';
@@ -618,7 +630,7 @@ function filecache($disktag)
if ( is_writable($tmp) ) $dir = $tmp;
} elseif ( mkdir($tmp) ) $dir = $tmp;
}
- $tag = __DIR__ . '/OneManager/' . $disktag;
+ $tag = $_SERVER['HTTP_HOST'] . '/OneManager/' . $disktag;
while (strpos($tag, '/')>-1) $tag = str_replace('/', '_', $tag);
if (strpos($tag, ':')>-1) {
$tag = str_replace(':', '_', $tag);
@@ -629,14 +641,52 @@ function filecache($disktag)
return $cache;
}
+function calcDownKey($filename, $key = '') {
+ if ($key) {
+ // check key
+ $tmp = splitfirst($key, '.');
+ if ($tmp[1]!='') {
+ $timestamp = $tmp[0];
+ if (time() > $timestamp) return false;
+ if (md5($timestamp . sha1($filename . getConfig('admin'))) == $tmp[1]) return true;
+ else return false;
+ } else return false;
+ } else {
+ // calc key
+ $timestamp = time() + 1*24*60*60;
+ return $timestamp . '.' . md5($timestamp . sha1($filename . getConfig('admin')));
+ }
+}
+
+function findIndexPath($rootpath, $path = '')
+{// find the path of the first 'index.php' that not in rootpath.
+ global $slash;
+ if (substr($rootpath,-1)==$slash) $rootpath = substr($rootpath, 0, -1);
+ if (substr($path,0,1)==$slash) $path = substr($path, 1);
+ $handler=opendir(path_format($rootpath.$slash.$path)); //打开当前文件夹
+ while($filename=readdir($handler)){
+ if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
+ $nowname = path_format($rootpath.$slash.$path.$slash.$filename);
+ if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
+ $res = findIndexPath($rootpath, $path.$slash.$filename);
+ if ($res!=='') return $res;
+ }else{
+ if ($filename==='index.php') if ($path!='') return $rootpath.$slash.$path;
+ }
+ }
+ }
+ @closedir($handler);
+ return '';
+}
+
function sortConfig(&$arr)
{
ksort($arr);
- $tags = explode('|', $arr['disktag']);
- unset($arr['disktag']);
- if ($tags[0]!='') {
- foreach($tags as $tag) {
+ if (isset($arr['disktag'])) {
+ $tags = explode('|', $arr['disktag']);
+ unset($arr['disktag']);
+ foreach($tags as $tag) if (isset($arr[$tag])) {
$disks[$tag] = $arr[$tag];
unset($arr[$tag]);
}
@@ -917,7 +967,7 @@ function message($message, $title = 'Message', $statusCode = 200, $wainstat = 0)
//setTimeout(function() { getStatus() }, 1000);
}
} else if (xhr.status==206) {
- errordiv.innerHTML = min + "
' . getconstStr('Wait') . '" + x;
+ errordiv.innerHTML = "' . getconstStr('Wait') . '" + x + "
" + min;
setTimeout(function() { getStatus() }, 1000);
} else {
errordiv.innerHTML = "ERROR
" + xhr.status + "
" + xhr.responseText;
@@ -949,7 +999,8 @@ function needUpdate()
$current_ver = explode(urldecode('%0D'),$current_ver)[0];
$split = splitfirst($current_version, '.' . $current_ver)[0] . '.' . $current_ver;
if (!($github_version = getcache('github_version'))) {
- $tmp = curl('GET', 'https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
+ //$tmp = curl('GET', 'https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
+ $tmp = curl('GET', 'https://git.hit.edu.cn/ysun/OneManager-php/-/raw/master/version');
if ($tmp['stat']==0) return 0;
$github_version = $tmp['body'];
savecache('github_version', $github_version);
@@ -1082,7 +1133,7 @@ function adminform($name = '', $pass = '', $storage = '', $path = '')
}
}
-';
+';
$html .= '';
return output($html, $statusCode);
}
@@ -1090,6 +1141,7 @@ function adminform($name = '', $pass = '', $storage = '', $path = '')
function adminoperate($path)
{
global $drive;
+ if ($_SERVER['REQUEST_METHOD']=='POST') if (!driveisfine($_SERVER['disktag'], $drive)) return output('Not in drive, or disk [' . $_SERVER['disktag'] . '] error.', 403);
$path1 = path_format($_SERVER['list_path'] . '/' . $path);
if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
$tmpget = $_GET;
@@ -1207,6 +1259,7 @@ function splitfirst($str, $split)
$tmp[0] = '';
$tmp[1] = substr($str, $len);
}
+ if ($tmp[1]===false) $tmp[1] = '';
return $tmp;
}
@@ -1224,6 +1277,7 @@ function splitlast($str, $split)
$tmp[0] = '';
$tmp[1] = substr($str, $len);
}
+ if ($tmp[1]===false) $tmp[1] = '';
return $tmp;
}
@@ -1251,7 +1305,7 @@ function EnvOpt($needUpdate = 0)
$html = 'OneManager '.getconstStr('Setup').'';
if (isset($_POST['updateProgram'])&&$_POST['updateProgram']==getconstStr('updateProgram')) if (compareadminmd5('admin', getConfig('admin'), $_COOKIE['admin'], $_POST['_admin'])) {
- $response = setConfigResponse(OnekeyUpate($_POST['auth'], $_POST['project'], $_POST['branch']));
+ $response = setConfigResponse(OnekeyUpate($_POST['GitSource'], $_POST['auth'], $_POST['project'], $_POST['branch']));
if (api_error($response)) {
$html = api_error_msg($response);
$title = 'Error';
@@ -1391,19 +1445,18 @@ function EnvOpt($needUpdate = 0)
}
} else return message('please login again', 'Need login', 403);
- if (isset($_GET['preview'])) {
- $preurl = $_SERVER['PHP_SELF'] . '?preview';
- } else {
- $preurl = path_format($_SERVER['PHP_SELF'] . '/');
- }
$html .= '
-' . getconstStr('Back') . '
+' . getconstStr('Back') . '
+
';
if ($_GET['setup']==='cmd') {
$statusCode = 200;
$html .= '
+OneManager DIR: ' . __DIR__ . '
';
if ($_POST['cmd']!='') {
@@ -1433,6 +1486,9 @@ output:
';
return message($html, 'Run cmd', $statusCode);
}
+ if ($_GET['setup']==='auth') {
+ return changeAuthKey();
+ }
if ($_GET['setup']==='platform') {
$frame .= '
@@ -1599,11 +1655,9 @@ output:
}
';
} else {
- //$_GET['disktag'] = '';
- $Driver_arr = scandir(__DIR__ . $slash . 'disk');
if (count($disktags)>1) {
$frame .= '
-
+
+' . getconstStr('DragSort') . ':
+
+
';
}
+ $Driver_arr = scandir(__DIR__ . $slash . 'disk');
$frame .= '