Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
czkbai2 authored Nov 12, 2024
1 parent d1eaef2 commit d1010ce
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

require './czkdir/inc.php';

$c = isset($_GET['p'])?trim($_GET['p']):'home';

$x = new DirList();

switch($c){
case 'hash':
if(!checkRefererHost())exit('{"code":403}');
if($conf['file_hash'] != '1')echo_json(['code'=>-1,'msg'=>'没有开启文件hash功能']);
$path = isset($_POST['path'])?trim($_POST['path']):'';
try{
$r = $x->get_file_hash($path);
}catch(Exception $e){
$r = ['code'=>-1, 'msg'=>$e->getMessage()];
}
echo_json($r);
break;
case 'video':
case 'audio':
case 'markdown':
case 'text':
if(!checkRefererHost())exit('Access Denied');
$path = isset($_GET['path'])?trim($_GET['path']):'';
try{
$path = './'.$x->set_dir_path($path, true);
}catch(Exception $e){
$errmsg = $e->getMessage();
sysmsg($errmsg);
}
$name = basename($path);
$ext = $x->get_file_ext($path);
$url = implode('/', array_map('rawurlencode', explode('/', $path)));
include PAGE_ROOT.$c.'.php';
break;
case 'search':
$s = isset($_GET['s'])?trim($_GET['s']):'';
if($s == '') exit("<script language='javascript'>window.location.href='./';</script>");
try{
$list = $x->search_files($s);
$r = ['list'=>$list];
}catch(Exception $e){
$errmsg = $e->getMessage();
}
$s = htmlspecialchars($s);
include PAGE_ROOT.'home.php';
break;
case 'home':
$dir = isset($_GET['dir'])?trim($_GET['dir']):'';
try{
$r = $x->list_dir($dir);
}catch(Exception $e){
$errmsg = $e->getMessage();
$r = $x->list_dir();
}
if(!empty($r['passwd']) && isset($_POST['passwd'])){
if($errmsg) echo_json(['code'=>-1, 'msg'=>$errmsg]);
if(password_verify($_POST['passwd'], $r['passwd'])){
setcookie('dir_passwd', md5($r['passwd']));
echo_json(['code'=>0]);
}else{
echo_json(['code'=>-1, 'msg'=>'出错了,请检查目录密码重试']);
}
}
include PAGE_ROOT.'home.php';
break;
case 'admin':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
include PAGE_ROOT.'admin.php';
break;
case 'upload':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
$path = isset($_GET['path'])?trim($_GET['path']):'';
try{
$path = $x->set_dir_path($path);
}catch(Exception $e){
sysmsg($e->getMessage());
}
include PAGE_ROOT.'upload.php';
break;
case 'filemgr':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
$path = isset($_POST['path'])?trim($_POST['path']):'';
$do = isset($_POST['do'])?trim($_POST['do']):echo_json(['code'=>-1, 'msg'=>'param error']);
try{
$path = $x->set_dir_path($path);
}catch(Exception $e){
echo_json(['code'=>-1, 'msg'=>$e->getMessage()]);
}
$mgr = new FileMgr($path);
if(!method_exists($mgr, $do))echo_json(['code'=>-1, 'msg'=>'action error']);
try{
$result = $mgr->$do();
echo_json(['code'=>0, 'data'=>$result]);
}catch(Exception $e){
echo_json(['code'=>-1, 'msg'=>$e->getMessage()]);
}
break;
case 'editor':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
$path = isset($_GET['path'])?trim($_GET['path']):'';
try{
$path = $x->set_dir_path($path, true);
}catch(Exception $e){
$errmsg = $e->getMessage();
sysmsg($errmsg);
}
include PAGE_ROOT.'editor.php';
break;
case 'login':
include PAGE_ROOT.'login.php';
break;
default:
break;
}

0 comments on commit d1010ce

Please sign in to comment.