change login page, rm JumpFirstDisk, 403 in operating root, change sorting disk, remake disktags tab, add global md config

change login page, rm JumpFirstDisk, 403 in operating root, change sorting disk, remake disktags tab, add global md config
pull/525/head
qkqpttgf 2022-01-27 11:48:01 +08:00 committed by GitHub
parent be58a17328
commit bc86e38c71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 91 additions and 36 deletions

View File

@ -21,7 +21,7 @@ $EnvConfigs = [
'admin' => 0b000, 'admin' => 0b000,
'adminloginpage' => 0b010, 'adminloginpage' => 0b010,
'autoJumpFirstDisk' => 0b010, //'autoJumpFirstDisk' => 0b010,
'background' => 0b011, 'background' => 0b011,
'backgroundm' => 0b011, 'backgroundm' => 0b011,
'disableShowThumb' => 0b010, 'disableShowThumb' => 0b010,
@ -38,6 +38,10 @@ $EnvConfigs = [
'useBasicAuth' => 0b010, 'useBasicAuth' => 0b010,
'referrer' => 0b011, 'referrer' => 0b011,
'forceHttps' => 0b010, 'forceHttps' => 0b010,
'globalHeadOmfUrl' => 0b011,
'globalHeadMdUrl' => 0b011,
'globalReadmeMdUrl' => 0b011,
'globalFootOmfUrl' => 0b011,
'Driver' => 0b100, 'Driver' => 0b100,
'client_id' => 0b100, 'client_id' => 0b100,
@ -183,7 +187,7 @@ function main($path)
} else { } else {
$adminloginpage = getConfig('adminloginpage'); $adminloginpage = getConfig('adminloginpage');
} }
if (isset($_GET[$adminloginpage])) { if (isset($_GET['login'])&&$_GET['login']==$adminloginpage) {
/*if (isset($_GET['preview'])) { /*if (isset($_GET['preview'])) {
$url = $_SERVER['PHP_SELF'] . '?preview'; $url = $_SERVER['PHP_SELF'] . '?preview';
} else { } else {
@ -222,7 +226,6 @@ function main($path)
return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 301, [ 'Location' => $tmp ]); return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 301, [ 'Location' => $tmp ]);
} }
if ($_SERVER['admin']) { if ($_SERVER['admin']) {
$_SERVER['disktag'] = '';
if (!class_exists($_GET['AddDisk'])) require 'disk' . $slash . $_GET['AddDisk'] . '.php'; if (!class_exists($_GET['AddDisk'])) require 'disk' . $slash . $_GET['AddDisk'] . '.php';
$drive = new $_GET['AddDisk']($_GET['disktag']); $drive = new $_GET['AddDisk']($_GET['disktag']);
return $drive->AddDisk(); return $drive->AddDisk();
@ -261,7 +264,7 @@ function main($path)
// return a json // return a json
return output(json_encode($files), 200, ['Content-Type' => 'application/json']); return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
} }
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]); //if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
} else { } else {
$_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0]; $_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
//$pos = strpos($path, '/'); //$pos = strpos($path, '/');
@ -295,19 +298,17 @@ function main($path)
if (!isreferhost()) return message('Must visit from designated host', 'NOT_ALLOWED', 403); 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 // Operate
if ($_SERVER['ajax']) { if ($_SERVER['ajax']) {
//error_log1($_SERVER['REQUEST_METHOD']);
if ($_GET['action']=='del_upload_cache') { if ($_GET['action']=='del_upload_cache') {
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件 // 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. savecache('path_' . $path1, '', $_SERVER['disktag'], 1); // clear cache.
return $drive->del_upload_cache($path); return $drive->del_upload_cache($path);
} }
if ($_GET['action']=='upbigfile') { 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['admin']) {
if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400); if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400);
if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400);
@ -326,6 +327,12 @@ function main($path)
} else { } else {
if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401); 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); $_SERVER['ishidden'] = passhidden($path);
if (isset($_GET['thumbnails'])) { if (isset($_GET['thumbnails'])) {
if ($_SERVER['ishidden']<4) { if ($_SERVER['ishidden']<4) {
@ -1133,6 +1140,7 @@ function adminform($name = '', $pass = '', $storage = '', $path = '')
function adminoperate($path) function adminoperate($path)
{ {
global $drive; 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); $path1 = path_format($_SERVER['list_path'] . '/' . $path);
if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1); if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
$tmpget = $_GET; $tmpget = $_GET;
@ -1646,11 +1654,9 @@ output:
} }
</script>'; </script>';
} else { } else {
//$_GET['disktag'] = '';
$Driver_arr = scandir(__DIR__ . $slash . 'disk');
if (count($disktags)>1) { if (count($disktags)>1) {
$frame .= ' $frame .= '
<script src="//cdn.bootcss.com/Sortable/1.8.3/Sortable.js"></script> <script src="http://sortablejs.github.io/Sortable/Sortable.js"></script>
<style> <style>
.sortable-ghost { .sortable-ghost {
opacity: 0.4; opacity: 0.4;
@ -1661,24 +1667,26 @@ output:
cursor: move; cursor: move;
} }
</style> </style>
' . getconstStr('DragSort') . ':
<form id="sortdisks_form" action="" method="post" style="margin: 0" onsubmit="return dragsort(this);">
<table border=1> <table border=1>
<form id="sortdisks_form" action="" method="post" style="margin: 0" onsubmit="return dragsort(this);"> <tbody id="sortdisks">
<tr id="sortdisks">
<input type="hidden" name="disktag_sort" value="">'; <input type="hidden" name="disktag_sort" value="">';
$num = 0; $num = 0;
foreach ($disktags as $disktag) { foreach ($disktags as $disktag) {
if ($disktag!='') { if ($disktag!='') {
$num++; $num++;
$frame .= ' $frame .= '
<td>' . $disktag . '</td>'; <tr class="sorthandle"><td>' . $num . '</td><td> ' . $disktag . '</td></tr>';
} }
} }
$frame .= ' $frame .= '
</tbody>
<input name="_admin" type="hidden" value=""> <input name="_admin" type="hidden" value="">
</tr>
<tr><td colspan="' . $num . '">' . getconstStr('DragSort') . '<input type="submit" name="submit1" value="' . getconstStr('SubmitSortdisks') . '"></td></tr>
</form>
</table> </table>
<input type="submit" name="submit1" value="' . getconstStr('SubmitSortdisks') . '">
</form>
<script> <script>
var disks=' . json_encode($disktags) . '; var disks=' . json_encode($disktags) . ';
function change(arr, oldindex, newindex) { function change(arr, oldindex, newindex) {
@ -1711,7 +1719,8 @@ output:
} }
return true; return true;
} }
Sortable.create(document.getElementById(\'sortdisks\'), { new Sortable(document.getElementById(\'sortdisks\'), {
handle: \'.sorthandle\',
animation: 150, animation: 150,
onEnd: function (evt) { //拖拽完毕之后发生该事件 onEnd: function (evt) { //拖拽完毕之后发生该事件
//console.log(evt.oldIndex); //console.log(evt.oldIndex);
@ -1724,6 +1733,7 @@ output:
}); });
</script><br>'; </script><br>';
} }
$Driver_arr = scandir(__DIR__ . $slash . 'disk');
$frame .= ' $frame .= '
<select name="DriveType" onchange="changedrivetype(this.options[this.options.selectedIndex].value)">'; <select name="DriveType" onchange="changedrivetype(this.options[this.options.selectedIndex].value)">';
foreach ($Driver_arr as $v1) { foreach ($Driver_arr as $v1) {
@ -2013,31 +2023,30 @@ output:
} }
$html .= ' $html .= '
<style type="text/css"> <style type="text/css">
.tabs td { padding: 5px; } .tabs { padding: 10px; white-space: nowrap; overflow-x: auto;}
.tabs a { margin:0 10px; }
</style> </style>
<table border=0> <div class="tabs">';
<tr class="tabs">';
if ($_GET['disktag']==''||$_GET['disktag']===true||!in_array($_GET['disktag'], $disktags)) { if ($_GET['disktag']==''||$_GET['disktag']===true||!in_array($_GET['disktag'], $disktags)) {
if ($_GET['setup']==='platform') $html .= ' if ($_GET['setup']==='platform') $html .= '
<td><a href="?setup">' . getconstStr('Home') . '</a></td> <a href="?setup">' . getconstStr('Home') . '</a>
<td>' . getconstStr('PlatformConfig') . '</td>'; ' . getconstStr('PlatformConfig') . '';
else $html .= ' else $html .= '
<td>' . getconstStr('Home') . '</td> ' . getconstStr('Home') . '
<td><a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a></td>'; <a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a>';
} else $html .= ' } else $html .= '
<td><a href="?setup">' . getconstStr('Home') . '</a></td> <a href="?setup">' . getconstStr('Home') . '</a>
<td><a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a></td>'; <a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a>';
foreach ($disktags as $disktag) { foreach ($disktags as $disktag) {
if ($disktag!='') { if ($disktag!='') {
if ($_GET['disktag']===$disktag) $html .= ' if ($_GET['disktag']===$disktag) $html .= '
<td>' . $disktag . '</td>'; ' . $disktag . '';
else $html .= ' else $html .= '
<td><a href="?setup&disktag=' . $disktag . '">' . $disktag . '</a></td>'; <a href="?setup&disktag=' . $disktag . '">' . $disktag . '</a>';
} }
} }
$html .= ' $html .= '
</tr> </div><br>';
</table><br>';
$html .= $frame; $html .= $frame;
$html .= '<script> $html .= '<script>
var inputAdminStorage = document.getElementsByName("_admin"); var inputAdminStorage = document.getElementsByName("_admin");
@ -2848,6 +2857,15 @@ function render_list($path = '', $files = [])
$tmp = splitfirst($tmp[1], '<!--HeadomfEnd-->'); $tmp = splitfirst($tmp[1], '<!--HeadomfEnd-->');
if (isset($files['list']['head.omf'])) { if (isset($files['list']['head.omf'])) {
$headomf = str_replace('<!--HeadomfContent-->', get_content(path_format($path . '/' . $files['list']['head.omf']['name']))['content']['body'], $tmp[0]); $headomf = str_replace('<!--HeadomfContent-->', get_content(path_format($path . '/' . $files['list']['head.omf']['name']))['content']['body'], $tmp[0]);
} elseif (getConfig('globalHeadOmfUrl')) {
if (!$headomfcontent = getcache('HeadomfContent')) {
$headomfres = curl('GET', getConfig('globalHeadOmfUrl'), '', [], 0, 1);
if ($headomfres['stat']==200) {
$headomfcontent = $headomfres['body'];
savecache('HeadomfContent', $headomfcontent);
} else $headomfcontent = $headomfres['stat'];
}
$headomf = str_replace('<!--HeadomfContent-->', $headomfcontent, $tmp[0]);
} }
$html .= $headomf . $tmp[1]; $html .= $headomf . $tmp[1];
@ -2861,6 +2879,20 @@ function render_list($path = '', $files = [])
$html = str_replace('<!--HeadmdStart-->', '', $html); $html = str_replace('<!--HeadmdStart-->', '', $html);
$html = str_replace('<!--HeadmdEnd-->', '', $html); $html = str_replace('<!--HeadmdEnd-->', '', $html);
} }
} elseif (getConfig('globalHeadMdUrl')) {
if (!$headmdcontent = getcache('HeadmdContent')) {
$headmdres = curl('GET', getConfig('globalHeadMdUrl'), '', [], 0, 1);
if ($headmdres['stat']==200) {
$headmdcontent = $headmdres['body'];
savecache('HeadmdContent', $headmdcontent);
} else $headmdcontent = $headmdres['stat'];
}
$headmd = str_replace('<!--HeadmdContent-->', $headmdcontent, $tmp[0]);
$html .= $headmd . $tmp[1];
while (strpos($html, '<!--HeadmdStart-->')) {
$html = str_replace('<!--HeadmdStart-->', '', $html);
$html = str_replace('<!--HeadmdEnd-->', '', $html);
}
} else { } else {
$html .= $tmp[1]; $html .= $tmp[1];
$tmp[1] = 'a'; $tmp[1] = 'a';
@ -2895,6 +2927,20 @@ function render_list($path = '', $files = [])
$html = str_replace('<!--ReadmemdStart-->', '', $html); $html = str_replace('<!--ReadmemdStart-->', '', $html);
$html = str_replace('<!--ReadmemdEnd-->', '', $html); $html = str_replace('<!--ReadmemdEnd-->', '', $html);
} }
} elseif (getConfig('globalReadmeMdUrl')) {
if (!$readmemdcontent = getcache('ReadmemdContent')) {
$readmemdres = curl('GET', getConfig('globalReadmeMdUrl'), '', [], 0, 1);
if ($readmemdres['stat']==200) {
$readmemdcontent = $readmemdres['body'];
savecache('ReadmemdContent', $readmemdcontent);
} else $readmemdcontent = $readmemdres['stat'];
}
$Readmemd = str_replace('<!--ReadmemdContent-->', $readmemdcontent, $tmp[0]);
$html .= $Readmemd . $tmp[1];
while (strpos($html, '<!--ReadmemdStart-->')) {
$html = str_replace('<!--ReadmemdStart-->', '', $html);
$html = str_replace('<!--ReadmemdEnd-->', '', $html);
}
} else { } else {
$html .= $tmp[1]; $html .= $tmp[1];
$tmp[1] = 'a'; $tmp[1] = 'a';
@ -2912,6 +2958,15 @@ function render_list($path = '', $files = [])
$tmp = splitfirst($tmp[1], '<!--FootomfEnd-->'); $tmp = splitfirst($tmp[1], '<!--FootomfEnd-->');
if (isset($files['list']['foot.omf'])) { if (isset($files['list']['foot.omf'])) {
$Footomf = str_replace('<!--FootomfContent-->', get_content(path_format($path . '/' . $files['list']['foot.omf']['name']))['content']['body'], $tmp[0]); $Footomf = str_replace('<!--FootomfContent-->', get_content(path_format($path . '/' . $files['list']['foot.omf']['name']))['content']['body'], $tmp[0]);
} elseif (getConfig('globalFootOmfUrl')) {
if (!$footomfcontent = getcache('FootomfContent')) {
$footres = curl('GET', getConfig('globalFootOmfUrl'), '', [], 0, 1);
if ($footres['stat']==200) {
$footomfcontent = $footres['body'];
savecache('FootomfContent', $footomfcontent);
} else $footomfcontent = $footres['stat'];
}
$Footomf = str_replace('<!--FootomfContent-->', $footomfcontent, $tmp[0]);
} }
$html .= $Footomf . $tmp[1]; $html .= $Footomf . $tmp[1];
@ -2919,7 +2974,7 @@ function render_list($path = '', $files = [])
$tmp = splitfirst($html, '<!--MdRequireStart-->'); $tmp = splitfirst($html, '<!--MdRequireStart-->');
$html = $tmp[0]; $html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--MdRequireEnd-->'); $tmp = splitfirst($tmp[1], '<!--MdRequireEnd-->');
if (isset($files['list']['head.md'])||isset($files['list']['readme.md'])) { if (isset($files['list']['head.md'])||isset($files['list']['readme.md'])||getConfig('globalHeadMdUrl')||getConfig('globalReadmeMdUrl')) {
$html .= $tmp[0] . $tmp[1]; $html .= $tmp[0] . $tmp[1];
} else $html .= $tmp[1]; } else $html .= $tmp[1];