From c1af030bce64edd04f2ebed72c6ce569a68b2dde Mon Sep 17 00:00:00 2001 From: v3 <59884249+742481030@users.noreply.github.com> Date: Sun, 10 May 2020 21:17:55 +0800 Subject: [PATCH 01/34] =?UTF-8?q?=E4=B8=8D=E7=94=A8=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 404.html | 26 +++++ controller/AdminController.php | 17 +-- controller/IndexController.php | 38 ++++++- index.php | 3 +- lib/member.php | 28 +++++ lib/onedrive.php | 1 + lib/oneindex.php | 1 + login.php | 92 ++++++++++++++++ view/admin/install/install_1.php | 6 +- view/classic/404.php | 19 +--- view/classic/images/index.php | 29 +++++ view/classic/images/layout.php | 82 ++++++++++++++ view/classic/layout.php | 53 +++++++-- view/classic/list.php | 180 ++++++++++++++++++++++++------- view/classic/password.php | 24 +++++ view/classic/show/audio.php | 36 +++++++ view/classic/show/code.php | 53 +++++++++ view/classic/show/doc.php | 9 ++ view/classic/show/image.php | 24 +++++ view/classic/show/pdf.php | 30 ++++++ view/classic/show/stream.php | 105 ++++++++++++++++++ view/classic/show/video.php | 35 ++++++ view/classic/show/video2.php | 42 ++++++++ view/classic/show/video5.php | 25 +++++ view/material/list.php | 2 + 25 files changed, 881 insertions(+), 79 deletions(-) create mode 100644 404.html create mode 100644 lib/member.php create mode 100644 login.php create mode 100644 view/classic/images/index.php create mode 100644 view/classic/images/layout.php create mode 100644 view/classic/password.php create mode 100644 view/classic/show/audio.php create mode 100644 view/classic/show/code.php create mode 100644 view/classic/show/doc.php create mode 100644 view/classic/show/image.php create mode 100644 view/classic/show/pdf.php create mode 100644 view/classic/show/stream.php create mode 100644 view/classic/show/video.php create mode 100644 view/classic/show/video2.php create mode 100644 view/classic/show/video5.php diff --git a/404.html b/404.html new file mode 100644 index 0000000..99ff94f --- /dev/null +++ b/404.html @@ -0,0 +1,26 @@ + + + + + + +404 + + + + +

404,您请求的文件不存在!

+ + diff --git a/controller/AdminController.php b/controller/AdminController.php index 5f6222e..f17728c 100644 --- a/controller/AdminController.php +++ b/controller/AdminController.php @@ -4,10 +4,10 @@ class AdminController{ static $default_config = array( 'site_name' =>'OneIndex', 'password' => 'oneindex', - 'style'=>'nexmoe', + 'style'=>'material', 'onedrive_root' =>'', 'cache_type'=>'filecache', - 'cache_expire_time' => 3600, + 'cache_expire_time' => 3580, 'cache_refresh_time' => 600, 'root_path' => '', 'show'=> array ( @@ -130,7 +130,7 @@ function show(){ $show = config('show'); return view::load('show')->with('names', $names)->with('show', $show); } - +/* function setpass(){ if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_POST['old_pass'] == config('password')){ @@ -146,6 +146,7 @@ function setpass(){ } return view::load('setpass')->with('message', $message); } + */ function install(){ if(!empty($_GET['code'])){ @@ -179,12 +180,12 @@ function install_1(){ config('redirect_uri',$_POST['redirect_uri']); return view::direct('?step=2'); } - if($_SERVER['HTTP_HOST'] == 'localhost'){ - $redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].get_absolute_path(dirname($_SERVER['PHP_SELF'])); - }else{ + // if($_SERVER['HTTP_HOST'] == 'localhost'){ + // $redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].get_absolute_path(dirname($_SERVER['PHP_SELF'])); + // }else{ // 非https,调用ju.tn中转 - $redirect_uri = 'https://pan.layne666.cn/'; - } + $redirect_uri = 'https://742481030.github.io/onedriverapi.html'; + // } $ru = "https://developer.microsoft.com/en-us/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl={$redirect_uri}&platform=option-php"; $deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=oneindex&redirectUrl={$redirect_uri}&allowImplicitFlow=false&ru=".urlencode($ru); diff --git a/controller/IndexController.php b/controller/IndexController.php index 048b68f..30a63e8 100644 --- a/controller/IndexController.php +++ b/controller/IndexController.php @@ -1,11 +1,21 @@ + alert('请您先登陆以后访问'); + "); +} + } function index(){ //是否404 + $this->is404(); + // $this->islogin(); $this->is_password(); @@ -66,8 +89,9 @@ function password($password){ exit(); } - //文件 + function file(){ + $item = $this->items[$this->name]; if ($item['folder']) {//是文件夹 $url = $_SERVER['REQUEST_URI'].'/'; @@ -76,8 +100,15 @@ function file(){ }elseif($_SERVER['REQUEST_METHOD'] == 'POST' || !is_null($_GET['s']) ){ return $this->show($item); }else{//返回下载链接 - $url = $item['downloadUrl']; - } + + // if (!isset($_COOKIE['openid'])) { + // $go='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + // $url='/login.php?goto='.$go; + // }else{ + + $url = $item['downloadUrl'];} + + // } header('Location: '.$url); } @@ -141,6 +172,7 @@ function show($item){ return view::load('show/'.$n)->with($data); } } + header('Location: '.$item['downloadUrl']); } diff --git a/index.php b/index.php index 54a37de..76154a4 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,8 @@ = "0"){ + + echo "用户在线"; + echo $_SESSION["userid"]; +} + + +} + + + + + + + + + + +} \ No newline at end of file diff --git a/lib/onedrive.php b/lib/onedrive.php index 56610d9..075fcf5 100644 --- a/lib/onedrive.php +++ b/lib/onedrive.php @@ -73,6 +73,7 @@ static function request($path="/", $query=""){ $token = self::access_token(); $request['headers'] = "Authorization: bearer {$token}".PHP_EOL."Content-Type: application/json".PHP_EOL; $request['url'] = self::$api_url."/me/drive/root".$path.$query; + // $request['url'] = self::$api_url."/sites/universitytongji.sharepoint.cn,9bb20ecf-c4c1-48c0-851f-64a56ae1d5d2,522cede1-cb84-4052-b180-7c012a3c03ba/drive/root".$path.$query; return $request; } diff --git a/lib/oneindex.php b/lib/oneindex.php index 92d848e..c941606 100644 --- a/lib/oneindex.php +++ b/lib/oneindex.php @@ -97,6 +97,7 @@ static function download_url($path){ $item = self::file($path); if(!empty($item['downloadUrl'])){ return $item['downloadUrl']; + } return false; } diff --git a/login.php b/login.php new file mode 100644 index 0000000..5193b41 --- /dev/null +++ b/login.php @@ -0,0 +1,92 @@ + top.location.href='" . $dialog_url . "'"); + } + //Step2:通过Authorization Code获取Access Token + if($_REQUEST['state'] == $_SESSION['state']) + { + //拼接URL + $token_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&" + . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) + . "&client_secret=" . $app_secret . "&code=" . $code; + $response = file_get_contents($token_url); + if (strpos($response, "callback") !== false) + { + $lpos = strpos($response, "("); + $rpos = strrpos($response, ")"); + $response = substr($response, $lpos + 1, $rpos - $lpos -1); + $msg = json_decode($response); + if (isset($msg->error)) + { + echo "

error:

" . $msg->error; + echo "

msg :

" . $msg->error_description; + exit; + } + } + //Step3:使用Access Token来获取用户的OpenID + $params = array(); + parse_str($response, $params); + $graph_url = "https://graph.qq.com/oauth2.0/me?access_token=".$params['access_token']; + $str = file_get_contents($graph_url); + if (strpos($str, "callback") !== false) + { + $lpos = strpos($str, "("); + $rpos = strrpos($str, ")"); + $str = substr($str, $lpos + 1, $rpos - $lpos -1); + } + $user = json_decode($str); + if (isset($user->error)) + { + echo "

error:

" . $user->error; + echo "

msg :

" . $user->error_description; + exit; + } + echo("Hello " . $user->openid); + + + // echo("Hello " . $user->openid); + setcookie("openid",$user->openid); + $goto=$_COOKIE["goto"]; + echo ' + + + + 返回上一页 + '; + + } + else + { + echo("The state does not match. You may be a victim of CSRF."); + } + + + + + + // header('Location: '.$goto); + + \ No newline at end of file diff --git a/view/admin/install/install_1.php b/view/admin/install/install_1.php index 74f259e..654a57b 100644 --- a/view/admin/install/install_1.php +++ b/view/admin/install/install_1.php @@ -18,14 +18,14 @@
https - +
应用机密不能为空

- +
应用 ID不能为空

@@ -36,7 +36,7 @@ - +
重定向URL不能为空
diff --git a/view/classic/404.php b/view/classic/404.php index 9c283ac..c2a8717 100644 --- a/view/classic/404.php +++ b/view/classic/404.php @@ -1,14 +1,5 @@ - - - - - 404 Not Found - - - - -

is not found.

- - \ No newline at end of file + + + +
404 not found.
+ \ No newline at end of file diff --git a/view/classic/images/index.php b/view/classic/images/index.php new file mode 100644 index 0000000..b763a75 --- /dev/null +++ b/view/classic/images/index.php @@ -0,0 +1,29 @@ + + + + +
+ +
+
OneImages
+
+ + +
+
+ + + +
+
+
+ +
+
+ +
+
+ +
+ + \ No newline at end of file diff --git a/view/classic/images/layout.php b/view/classic/images/layout.php new file mode 100644 index 0000000..feb1922 --- /dev/null +++ b/view/classic/images/layout.php @@ -0,0 +1,82 @@ + + + + + + <?php e($title.' - '.config('site_name'));?> + + + + + +
+
+ + $l):?> + chevron_right + + + +
+
+ +
+ +
+ + \ No newline at end of file diff --git a/view/classic/layout.php b/view/classic/layout.php index 5d762da..ffc81d2 100644 --- a/view/classic/layout.php +++ b/view/classic/layout.php @@ -2,16 +2,17 @@ - <?php _($title);?> + + <?php e($title.' - '.config('site_name'));?>
- oneindex + + $l):?> chevron_right - admin - chevron_right - setpass -
- refresh + + +
- - \ No newline at end of file diff --git a/view/classic/list.php b/view/classic/list.php index 444ab1b..6e168ed 100644 --- a/view/classic/list.php +++ b/view/classic/list.php @@ -1,40 +1,142 @@ - - - - Index of <?php echo urldecode($path);?> - - - - -

Index of

- - - - - - - - + + + + + +
+ + +
+ +
+ + + +
+
- - - - - - - - - - - - -
NameSizeDate CreatedDate Modified
- .. -
/
- - \ No newline at end of file + + + + +
+
+ face + README.md +
+ +
+ + + + + + \ No newline at end of file diff --git a/view/classic/password.php b/view/classic/password.php new file mode 100644 index 0000000..c421419 --- /dev/null +++ b/view/classic/password.php @@ -0,0 +1,24 @@ + + + + +
+
+

这是一个受保护的文件夹,您需要提供访问密码才能查看。

+
+
+ https + + +
+
+ +
+
+ +
+ + \ No newline at end of file diff --git a/view/classic/show/audio.php b/view/classic/show/audio.php new file mode 100644 index 0000000..8ade9a1 --- /dev/null +++ b/view/classic/show/audio.php @@ -0,0 +1,36 @@ + + + + +
+
+
+
+ +
+
+ +
+ + +
+
+ + +
+
+file_download + + + + diff --git a/view/classic/show/code.php b/view/classic/show/code.php new file mode 100644 index 0000000..8cc5f0b --- /dev/null +++ b/view/classic/show/code.php @@ -0,0 +1,53 @@ + + + + +
+
+
+
+ + +
+file_download + + + + + \ No newline at end of file diff --git a/view/classic/show/doc.php b/view/classic/show/doc.php new file mode 100644 index 0000000..abe38a6 --- /dev/null +++ b/view/classic/show/doc.php @@ -0,0 +1,9 @@ + diff --git a/view/classic/show/image.php b/view/classic/show/image.php new file mode 100644 index 0000000..6a3ca7c --- /dev/null +++ b/view/classic/show/image.php @@ -0,0 +1,24 @@ + + + + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+file_download + diff --git a/view/classic/show/pdf.php b/view/classic/show/pdf.php new file mode 100644 index 0000000..5d5d5a6 --- /dev/null +++ b/view/classic/show/pdf.php @@ -0,0 +1,30 @@ + + + + +file_download + + \ No newline at end of file diff --git a/view/classic/show/stream.php b/view/classic/show/stream.php new file mode 100644 index 0000000..ec3193e --- /dev/null +++ b/view/classic/show/stream.php @@ -0,0 +1,105 @@ +'application/octet-stream', + 'ppt'=>'application/vnd.ms-powerpoint', + 'xls'=>'application/vnd.ms-excel', + 'doc'=>'application/msword', + 'exe'=>'application/octet-stream', + 'rar'=>'application/octet-stream', + 'js'=>"javascrīpt/js", + 'css'=>"text/css", + 'hqx'=>"application/mac-binhex40", + 'bin'=>"application/octet-stream", + 'oda'=>"application/oda", + 'pdf'=>"application/pdf", + 'ai'=>"application/postsrcipt", + 'eps'=>"application/postsrcipt", + 'es'=>"application/postsrcipt", + 'rtf'=>"application/rtf", + 'mif'=>"application/x-mif", + 'csh'=>"application/x-csh", + 'dvi'=>"application/x-dvi", + 'hdf'=>"application/x-hdf", + 'nc'=>"application/x-netcdf", + 'cdf'=>"application/x-netcdf", + 'latex'=>"application/x-latex", + 'ts'=>"application/x-troll-ts", + 'src'=>"application/x-wais-source", + 'zip'=>"application/zip", + 'bcpio'=>"application/x-bcpio", + 'cpio'=>"application/x-cpio", + 'gtar'=>"application/x-gtar", + 'shar'=>"application/x-shar", + 'sv4cpio'=>"application/x-sv4cpio", + 'sv4crc'=>"application/x-sv4crc", + 'tar'=>"application/x-tar", + 'ustar'=>"application/x-ustar", + 'man'=>"application/x-troff-man", + 'sh'=>"application/x-sh", + 'tcl'=>"application/x-tcl", + 'tex'=>"application/x-tex", + 'texi'=>"application/x-texinfo", + 'texinfo'=>"application/x-texinfo", + 't'=>"application/x-troff", + 'tr'=>"application/x-troff", + 'roff'=>"application/x-troff", + 'shar'=>"application/x-shar", + 'me'=>"application/x-troll-me", + 'ts'=>"application/x-troll-ts", + 'gif'=>"image/gif", + 'jpeg'=>"image/pjpeg", + 'jpg'=>"image/pjpeg", + 'jpe'=>"image/pjpeg", + 'ras'=>"image/x-cmu-raster", + 'pbm'=>"image/x-portable-bitmap", + 'ppm'=>"image/x-portable-pixmap", + 'xbm'=>"image/x-xbitmap", + 'xwd'=>"image/x-xwindowdump", + 'ief'=>"image/ief", + 'tif'=>"image/tiff", + 'tiff'=>"image/tiff", + 'pnm'=>"image/x-portable-anymap", + 'pgm'=>"image/x-portable-graymap", + 'rgb'=>"image/x-rgb", + 'xpm'=>"image/x-xpixmap", + 'txt'=>"text/plain", + 'c'=>"text/plain", + 'cc'=>"text/plain", + 'h'=>"text/plain", + 'html'=>"text/html", + 'htm'=>"text/html", + 'htl'=>"text/html", + 'txt'=>"text/html", + 'php'=>"text/html", + 'rtx'=>"text/richtext", + 'etx'=>"text/x-setext", + 'tsv'=>"text/tab-separated-values", + 'mpeg'=>"video/mpeg", + 'mpg'=>"video/mpeg", + 'mpe'=>"video/mpeg", + 'avi'=>"video/x-msvideo", + 'qt'=>"video/quicktime", + 'mov'=>"video/quicktime", + 'moov'=>"video/quicktime", + 'movie'=>"video/x-sgi-movie", + 'au'=>"audio/basic", + 'snd'=>"audio/basic", + 'wav'=>"audio/x-wav", + 'aif'=>"audio/x-aiff", + 'aiff'=>"audio/x-aiff", + 'aifc'=>"audio/x-aiff", + 'swf'=>"application/x-shockwave-flash", + 'myz'=>"application/myz" +]; +//大于 5M 跳转为直连下载 +if($item['size'] > 5242880){ + header('Location: '.$item['downloadUrl']);exit(); +} +$type = empty($types[$ext])?"application/octet-stream":$types[$ext]; +$content = IndexController::get_content($item); + +header('Content-type: '.$type); +echo $content; +exit(); +?> diff --git a/view/classic/show/video.php b/view/classic/show/video.php new file mode 100644 index 0000000..9a8f888 --- /dev/null +++ b/view/classic/show/video.php @@ -0,0 +1,35 @@ + + + + +
+
+
+
+ +
+ + +
+
+ + +
+
+'); } ?> + + +file_download + diff --git a/view/classic/show/video2.php b/view/classic/show/video2.php new file mode 100644 index 0000000..cfb1d08 --- /dev/null +++ b/view/classic/show/video2.php @@ -0,0 +1,42 @@ + + + + + + + + +
+
+
+
+ +
+ + +
+
+ + +
+
+ +file_download + \ No newline at end of file diff --git a/view/classic/show/video5.php b/view/classic/show/video5.php new file mode 100644 index 0000000..69f5e4d --- /dev/null +++ b/view/classic/show/video5.php @@ -0,0 +1,25 @@ + + + + + +
+
+ +
+ +
+ + +
+
+ + +
+
+file_download + \ No newline at end of file diff --git a/view/material/list.php b/view/material/list.php index 8c78e9b..6e168ed 100644 --- a/view/material/list.php +++ b/view/material/list.php @@ -84,6 +84,7 @@ function file_ico($item){ + + \ No newline at end of file From d7be86888519c7be853a4ee74ef66e2c0f727094 Mon Sep 17 00:00:00 2001 From: v3 <59884249+742481030@users.noreply.github.com> Date: Mon, 11 May 2020 15:08:59 +0800 Subject: [PATCH 02/34] =?UTF-8?q?=E6=B7=BB=E5=8A=A0sharepoint=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加sharepoint自动配置 --- README.md | 8 ----- index.html | 40 ++++++++++++++++++++++ index.php | 1 + lib/onedrive.php | 22 +++++++++--- sharepoint.php | 57 ++++++++++++++++++++++++++++++++ view/admin/install/install_1.php | 6 ++-- view/admin/install/install_3.php | 1 + view/material/list.php | 3 +- 8 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 index.html create mode 100644 sharepoint.php diff --git a/README.md b/README.md index e4909cf..99e2f2d 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,3 @@ if ($rule_0 = "21"){ rewrite ^/(.*)$ /index.php?/$1 last; } ``` - -## 预览图 - -![](http://file.layne666.cn/img/20191125233913.png) - -![](http://file.layne666.cn/img/20200211210637.png) - -![](http://file.layne666.cn/img/20200211210644.png) \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..c9f1e2c --- /dev/null +++ b/index.html @@ -0,0 +1,40 @@ + + + + + 恭喜,站点创建成功! + + + +
+

恭喜, 站点创建成功!

+

这是默认index.html,本页面由系统自动生成

+ +
+ + \ No newline at end of file diff --git a/index.php b/index.php index 76154a4..4d14939 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ require __DIR__.'/init.php'; + //世纪互联 onedrive::$api_url = "https://microsoftgraph.chinacloudapi.cn/v1.0"; onedrive::$oauth_url = "https://login.partner.microsoftonline.cn/common/oauth2/v2.0"; diff --git a/lib/onedrive.php b/lib/onedrive.php index 075fcf5..e91e32d 100644 --- a/lib/onedrive.php +++ b/lib/onedrive.php @@ -5,7 +5,7 @@ class onedrive{ static $redirect_uri; static $api_url = 'https://graph.microsoft.com/v1.0'; static $oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0'; - +static $typeurl; //验证URL,浏览器访问、授权 static function authorize_url(){ $client_id = self::$client_id; @@ -70,11 +70,25 @@ static function access_token(){ static function request($path="/", $query=""){ $path = self::urlencode($path); $path = empty($path)?'/':":/{$path}:/"; + $token = self::access_token(); $request['headers'] = "Authorization: bearer {$token}".PHP_EOL."Content-Type: application/json".PHP_EOL; - $request['url'] = self::$api_url."/me/drive/root".$path.$query; - // $request['url'] = self::$api_url."/sites/universitytongji.sharepoint.cn,9bb20ecf-c4c1-48c0-851f-64a56ae1d5d2,522cede1-cb84-4052-b180-7c012a3c03ba/drive/root".$path.$query; - return $request; + $filess = ROOT . 'config/sharepoint.php'; + if (file_exists($filess)){ + $se=include($filess); + onedrive::$typeurl=$se["0"]; + + + }else{ + onedrive::$typeurl="https://microsoftgraph.chinacloudapi.cn/v1.0/me/drive/root".$path.$query;; + } + + $request['url'] =self::$typeurl; + // $request['url'] = self::$api_url."/me/drive/root".$path.$query; + + //$request['url'] = self::$api_url."/sites/alphaone.sharepoint.cn,a0031d38-3ee4-4e22-87e3-c5ca1825419a,eda2d4bf-9dd2-4703-a606-5ff84bbd1c5b/drive/root".$path.$query; + + return $request; } diff --git a/sharepoint.php b/sharepoint.php new file mode 100644 index 0000000..304defe --- /dev/null +++ b/sharepoint.php @@ -0,0 +1,57 @@ + +   +   +'; +exit; + + + +} + $request['headers'] = "Authorization: bearer {$config["access_token"]}".PHP_EOL."Content-Type: application/json".PHP_EOL; + $request["url"]='https://microsoftgraph.chinacloudapi.cn/v1.0/sites/root'; + $resp=fetch::get($request) ; + $data = json_decode($resp->content, true); + $hostname= $data["siteCollection"]["hostname"]; + + $getsiteid='https://microsoftgraph.chinacloudapi.cn/v1.0/sites/'.$hostname.':'.$_GET["site"]; + $request["url"]=$getsiteid; + $respp=fetch::get($request) ; + $datass = json_decode($respp->content, true); + +echo $siteidurl=($datass["id"]); +if (($datass["id"])==""){echo "获取站点id失败刷新重试试"; + + echo '站点名称填写/sites/名称或者/teams/名称'; + echo '
+   +   +
'; + +exit;} +$b = ' +进入后台刷新缓存生效 默认密码oneindex'; diff --git a/view/admin/install/install_1.php b/view/admin/install/install_1.php index 654a57b..277a9f3 100644 --- a/view/admin/install/install_1.php +++ b/view/admin/install/install_1.php @@ -10,7 +10,7 @@

填入client_idclient_secret, - 获取应用ID和机密(分两个页面显示,请注意保存) + 不支持国际版,世纪互联无需填写或者点此注册

@@ -19,14 +19,14 @@ https -
应用机密不能为空
+

-
应用 ID不能为空
+

diff --git a/view/admin/install/install_3.php b/view/admin/install/install_3.php index c81de70..e750b6a 100644 --- a/view/admin/install/install_3.php +++ b/view/admin/install/install_3.php @@ -11,6 +11,7 @@

程序安装成功!



管理后台(初始密码:oneindex) + 是否启用Sharepoint 不使用onedriver点次配置sharepoint 访问网站

程序安装失败!

diff --git a/view/material/list.php b/view/material/list.php index 6e168ed..8f847ab 100644 --- a/view/material/list.php +++ b/view/material/list.php @@ -138,5 +138,4 @@ function file_ico($item){ }); - - \ No newline at end of file + \ No newline at end of file From 2db0b6d7a39ddbc9f96287105a489c5165de26c2 Mon Sep 17 00:00:00 2001 From: v3 <59884249+742481030@users.noreply.github.com> Date: Thu, 14 May 2020 04:57:46 +0800 Subject: [PATCH 03/34] cdn --- README.md | 2 +- controller/AdminController.php | 20 ++- controller/IndexController.php | 79 +++++---- controller/IndexController.php.bak | 249 +++++++++++++++++++++++++++++ index.php | 3 +- lib/cache/filecache_.php | 3 + lib/onedrive.php | 13 +- lib/sharepoint.php | 57 +++++++ page.html | 22 +++ view/admin/settings.php | 41 +++-- view/admin/settings.php.bak | 83 ++++++++++ view/classic/404.php | 19 ++- view/classic/layout.php | 53 ++---- view/classic/list.php | 180 +++++---------------- view/material/list.php | 3 +- view/nexmoe/404.php | 2 +- view/nexmoe/layout.php | 152 ++++++++++++++---- view/nexmoe/list.php | 215 +++++++++++++++++++++---- view/nexmoe/password.php | 10 +- view/nexmoe/show/audio.php | 26 ++- view/nexmoe/show/code.php | 28 +++- view/nexmoe/show/doc.php | 10 +- view/nexmoe/show/doc2pdf.php | 32 ++++ view/nexmoe/show/image.php | 43 +++-- view/nexmoe/show/pdf.php | 46 +++--- view/nexmoe/show/stream.php | 2 + view/nexmoe/show/video.php | 57 +++++-- view/nexmoe/show/video2.php | 31 ++-- view/nexmoe/show/video5.php | 48 +++++- 29 files changed, 1115 insertions(+), 414 deletions(-) create mode 100644 controller/IndexController.php.bak create mode 100644 lib/sharepoint.php create mode 100644 page.html create mode 100644 view/admin/settings.php.bak create mode 100644 view/nexmoe/show/doc2pdf.php diff --git a/README.md b/README.md index 99e2f2d..7789442 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

OneIndex

+ > Onedrive Directory Index diff --git a/controller/AdminController.php b/controller/AdminController.php index f17728c..edf346a 100644 --- a/controller/AdminController.php +++ b/controller/AdminController.php @@ -4,11 +4,12 @@ class AdminController{ static $default_config = array( 'site_name' =>'OneIndex', 'password' => 'oneindex', - 'style'=>'material', + 'style'=>'nexmoe', 'onedrive_root' =>'', 'cache_type'=>'filecache', - 'cache_expire_time' => 3580, + 'cache_expire_time' => 3600, 'cache_refresh_time' => 600, + 'page_item' => 50, 'root_path' => '', 'show'=> array ( 'stream'=>['txt'], @@ -53,6 +54,13 @@ function settings(){ } config('site_name', $_POST['site_name']); + // + config('title_name',$_POST['title_name']); + config('drawer',$_POST['drawer']); + config('main_domain',$_POST['main_domain']); + config('proxy_domain',$_POST['proxy_domain']); + + config('page_item',intval($_POST['page_item'])); config('style', $_POST['style']); config('onedrive_root', get_absolute_path($_POST['onedrive_root'])); config('onedrive_hide', $_POST['onedrive_hide']); @@ -60,6 +68,7 @@ function settings(){ config('cache_expire_time', intval($_POST['cache_expire_time'])); $_POST['root_path'] = empty($_POST['root_path'])?'?':''; config('root_path', $_POST['root_path']); + } $config = config('@base'); @@ -180,11 +189,12 @@ function install_1(){ config('redirect_uri',$_POST['redirect_uri']); return view::direct('?step=2'); } - // if($_SERVER['HTTP_HOST'] == 'localhost'){ + //if($_SERVER['HTTP_HOST'] == 'localhost'){ // $redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].get_absolute_path(dirname($_SERVER['PHP_SELF'])); - // }else{ + //}else{ // 非https,调用ju.tn中转 - $redirect_uri = 'https://742481030.github.io/onedriverapi.html'; + // $redirect_uri = 'https://pan.mxin.ltd/'; + $redirect_uri = 'https://coding.mxin.ltd/api/onedrive.html'; // } $ru = "https://developer.microsoft.com/en-us/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl={$redirect_uri}&platform=option-php"; diff --git a/controller/IndexController.php b/controller/IndexController.php index 30a63e8..3cbf85b 100644 --- a/controller/IndexController.php +++ b/controller/IndexController.php @@ -1,50 +1,39 @@ z_page = config('page_item'); + //获取路径和文件名 $paths = explode('/', rawurldecode($_GET['path'])); if(substr($_SERVER['REQUEST_URI'], -1) != '/'){ $this->name = array_pop($paths); } - $this->url_path = get_absolute_path(join('/', $paths)); + + preg_match_all("(\.page\-([0-9]*)/$)",get_absolute_path(join('/', $paths)),$mat); + if(empty($mat[1][0])){ + $this->page = 1; + } else { + $this->page = $mat[1][0]; + } + + $this->url_path = preg_replace("(\.page\-[0-9]*/$)","",get_absolute_path(join('/', $paths))); + $this->path = get_absolute_path(config('onedrive_root').$this->url_path); //获取文件夹下所有元素 $this->items = $this->items($this->path); } - function islogin(){ - - - - - if (!isset($_COOKIE['username'])) { - exit(""); -} - } function index(){ //是否404 - $this->is404(); - // $this->islogin(); $this->is_password(); @@ -89,9 +78,8 @@ function password($password){ exit(); } - + //文件 function file(){ - $item = $this->items[$this->name]; if ($item['folder']) {//是文件夹 $url = $_SERVER['REQUEST_URI'].'/'; @@ -100,15 +88,12 @@ function file(){ }elseif($_SERVER['REQUEST_METHOD'] == 'POST' || !is_null($_GET['s']) ){ return $this->show($item); }else{//返回下载链接 - - // if (!isset($_COOKIE['openid'])) { - // $go='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; - // $url='/login.php?goto='.$go; - // }else{ - - $url = $item['downloadUrl'];} - - // } + if (config('proxy_domain') != ""){ + $url = str_replace(config('main_domain'),config('proxy_domain'),$item['downloadUrl']); + }else { + $url = $item['downloadUrl']; + } + } header('Location: '.$url); } @@ -144,13 +129,21 @@ function dir(){ //不在列表中展示 unset($this->items['HEAD.md']); } - return view::load('list')->with('title', 'index of '. urldecode($this->url_path)) + + $this->totalpage = ceil(count($this->items) / $this->z_page); + + if($this->page*$this->z_page >= count($this->items)) + $this->page = $this->totalpage; + + return view::load('list')->with('title', config('title_name')) ->with('navs', $navs) - ->with('path',join("/", array_map("rawurlencode", explode("/", $this->url_path))) ) + ->with('path',join("/", array_map("rawurlencode", explode("/", $this->url_path)))) ->with('root', $root) - ->with('items', $this->items) + ->with('items', array_slice($this->items,$this->z_page*($this->page-1),$this->z_page)) ->with('head',$head) - ->with('readme',$readme); + ->with('readme',$readme) + ->with('page',$this->page) + ->with('totalpage',$this->totalpage); } function show($item){ @@ -168,11 +161,13 @@ function show($item){ $show = config('show'); foreach($show as $n=>$exts){ - if(in_array($ext,$exts)){ + if ($ext == 'pdf'){ + return view::load('show/pdf')->with($data); + } + elseif(in_array($ext,$exts)){ return view::load('show/'.$n)->with($data); } } - header('Location: '.$item['downloadUrl']); } @@ -224,7 +219,7 @@ static function get_content($item){ return $content; } - //时候404 + //404 function is404(){ if(!empty($this->items[$this->name]) || (empty($this->name) && is_array($this->items)) ){ return false; diff --git a/controller/IndexController.php.bak b/controller/IndexController.php.bak new file mode 100644 index 0000000..93a1192 --- /dev/null +++ b/controller/IndexController.php.bak @@ -0,0 +1,249 @@ +name = array_pop($paths); + } + $this->url_path = get_absolute_path(join('/', $paths)); + $this->path = get_absolute_path(config('onedrive_root').$this->url_path); + //获取文件夹下所有元素 + $this->items = $this->items($this->path); + } + + + function islogin(){ + + + + + if (!isset($_COOKIE['username'])) { + exit(""); +} + } + function index(){ + //是否404 + + $this->is404(); + // $this->islogin(); + + $this->is_password(); + + header("Expires:-1"); + header("Cache-Control:no_cache"); + header("Pragma:no-cache"); + + if(!empty($this->name)){//file + return $this->file(); + }else{//dir + return $this->dir(); + } + } + + //判断是否加密 + function is_password(){ + if(empty($this->items['.password'])){ + return false; + }else{ + $this->items['.password']['path'] = get_absolute_path($this->path).'.password'; + } + + $password = $this->get_content($this->items['.password']); + list($password) = explode("\n",$password); + $password = trim($password); + unset($this->items['.password']); + if(!empty($password) && strcmp($password, $_COOKIE[md5($this->path)]) === 0){ + return true; + } + + $this->password($password); + + } + + function password($password){ + if(!empty($_POST['password']) && strcmp($password, $_POST['password']) === 0){ + setcookie(md5($this->path), $_POST['password']); + return true; + } + $navs = $this->navs(); + echo view::load('password')->with('navs',$navs); + exit(); + } + + + function file(){ + + $item = $this->items[$this->name]; + if ($item['folder']) {//是文件夹 + $url = $_SERVER['REQUEST_URI'].'/'; + }elseif(!is_null($_GET['t']) ){//缩略图 + $url = $this->thumbnail($item); + }elseif($_SERVER['REQUEST_METHOD'] == 'POST' || !is_null($_GET['s']) ){ + return $this->show($item); + }else{//返回下载链接 + + // if (!isset($_COOKIE['openid'])) { + // $go='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + // $url='/login.php?goto='.$go; + // }else{ + + $url = $item['downloadUrl'];} + + // } + header('Location: '.$url); + } + + + + //文件夹 + function dir(){ + $root = get_absolute_path(dirname($_SERVER['SCRIPT_NAME'])).config('root_path'); + $navs = $this->navs(); + + if($this->items['index.html']){ + $this->items['index.html']['path'] = get_absolute_path($this->path).'index.html'; + $index = $this->get_content($this->items['index.html']); + header('Content-type: text/html'); + echo $index; + exit(); + } + + if($this->items['README.md']){ + $this->items['README.md']['path'] = get_absolute_path($this->path).'README.md'; + $readme = $this->get_content($this->items['README.md']); + $Parsedown = new Parsedown(); + $readme = $Parsedown->text($readme); + //不在列表中展示 + unset($this->items['README.md']); + } + + if($this->items['HEAD.md']){ + $this->items['HEAD.md']['path'] = get_absolute_path($this->path).'HEAD.md'; + $head = $this->get_content($this->items['HEAD.md']); + $Parsedown = new Parsedown(); + $head = $Parsedown->text($head); + //不在列表中展示 + unset($this->items['HEAD.md']); + } + return view::load('list')->with('title', 'index of '. urldecode($this->url_path)) + ->with('navs', $navs) + ->with('path',join("/", array_map("rawurlencode", explode("/", $this->url_path))) ) + ->with('root', $root) + ->with('items', $this->items) + ->with('head',$head) + ->with('readme',$readme); + } + + function show($item){ + $root = get_absolute_path(dirname($_SERVER['SCRIPT_NAME'])).(config('root_path')?'?/':''); + $ext = strtolower(pathinfo($item['name'], PATHINFO_EXTENSION)); + $data['title'] = $item['name']; + $data['navs'] = $this->navs(); + $data['item'] = $item; + $data['ext'] = $ext; + $data['item']['path'] = get_absolute_path($this->path).$this->name; + $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; + $uri = onedrive::urlencode(get_absolute_path($this->url_path.'/'.$this->name)); + $data['url'] = $http_type.$_SERVER['HTTP_HOST'].$root.$uri; + + + $show = config('show'); + foreach($show as $n=>$exts){ + if(in_array($ext,$exts)){ + return view::load('show/'.$n)->with($data); + } + } + + + header('Location: '.$item['downloadUrl']); + } + //缩略图 + function thumbnail($item){ + if(!empty($_GET['t'])){ + list($width, $height) = explode('|', $_GET['t']); + }else{ + //800 176 96 + $width = $height = 800; + } + $item['thumb'] = onedrive::thumbnail($this->path.$this->name); + list($item['thumb'],$tmp) = explode('&width=', $item['thumb']); + $item['thumb'] .= strpos($item['thumb'], '?')?'&':'?'; + return $item['thumb']."width={$width}&height={$height}"; + } + + //文件夹下元素 + function items($path, $fetch=false){ + $items = cache::get('dir_'.$this->path, function(){ + return onedrive::dir($this->path); + }, config('cache_expire_time')); + return $items; + } + + function navs(){ + $root = get_absolute_path(dirname($_SERVER['SCRIPT_NAME'])).config('root_path'); + $navs['/'] = get_absolute_path($root.'/'); + foreach(explode('/',$this->url_path) as $v){ + if(empty($v)){ + continue; + } + $navs[rawurldecode($v)] = end($navs).$v.'/'; + } + if(!empty($this->name)){ + $navs[$this->name] = end($navs).urlencode($this->name); + } + + return $navs; + } + + static function get_content($item){ + $content = cache::get('content_'.$item['path'], function() use ($item){ + $resp = fetch::get($item['downloadUrl']); + if($resp->http_code == 200){ + return $resp->content; + } + }, config('cache_expire_time') ); + return $content; + } + + //时候404 + function is404(){ + if(!empty($this->items[$this->name]) || (empty($this->name) && is_array($this->items)) ){ + return false; + } + + http_response_code(404); + view::load('404')->show(); + die(); + } + + function __destruct(){ + if (!function_exists("fastcgi_finish_request")) { + return; + } + } +} diff --git a/index.php b/index.php index 4d14939..e321de5 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,6 @@ require __DIR__.'/init.php'; - //世纪互联 onedrive::$api_url = "https://microsoftgraph.chinacloudapi.cn/v1.0"; onedrive::$oauth_url = "https://login.partner.microsoftonline.cn/common/oauth2/v2.0"; @@ -96,3 +95,5 @@ }, function() { route::any('{path:#all}','IndexController@index'); }); + + diff --git a/lib/cache/filecache_.php b/lib/cache/filecache_.php index 6b3e0d3..bb21d1d 100644 --- a/lib/cache/filecache_.php +++ b/lib/cache/filecache_.php @@ -11,6 +11,7 @@ function __construct($cache_path= null){ function get($key){ $file = $this->cache_path . md5($key) . '.php'; + $data = @include $file; if( is_array($data) && $data['expire'] > time() && !is_null($data['data']) ){ return $data['data']; @@ -21,6 +22,8 @@ function get($key){ function set($key, $value=null, $expire=99999999){ $file = $this->cache_path . md5($key) . '.php'; + + $data['expire'] = time() + $expire; $data['data'] = $value; return @file_put_contents($file, " time()+600){ + //$token = config('@token')["drive"][$_GET["path"]["0"]]; + if($token['expires_on'] > time()+600){ return $token['access_token']; }else{ $refresh_token = config('refresh_token'); @@ -70,9 +72,9 @@ static function access_token(){ static function request($path="/", $query=""){ $path = self::urlencode($path); $path = empty($path)?'/':":/{$path}:/"; - $token = self::access_token(); $request['headers'] = "Authorization: bearer {$token}".PHP_EOL."Content-Type: application/json".PHP_EOL; + $filess = ROOT . 'config/sharepoint.php'; if (file_exists($filess)){ $se=include($filess); @@ -84,11 +86,8 @@ static function request($path="/", $query=""){ } $request['url'] =self::$typeurl; - // $request['url'] = self::$api_url."/me/drive/root".$path.$query; - - //$request['url'] = self::$api_url."/sites/alphaone.sharepoint.cn,a0031d38-3ee4-4e22-87e3-c5ca1825419a,eda2d4bf-9dd2-4703-a606-5ff84bbd1c5b/drive/root".$path.$query; + return $request; - return $request; } diff --git a/lib/sharepoint.php b/lib/sharepoint.php new file mode 100644 index 0000000..304defe --- /dev/null +++ b/lib/sharepoint.php @@ -0,0 +1,57 @@ + +   +   +'; +exit; + + + +} + $request['headers'] = "Authorization: bearer {$config["access_token"]}".PHP_EOL."Content-Type: application/json".PHP_EOL; + $request["url"]='https://microsoftgraph.chinacloudapi.cn/v1.0/sites/root'; + $resp=fetch::get($request) ; + $data = json_decode($resp->content, true); + $hostname= $data["siteCollection"]["hostname"]; + + $getsiteid='https://microsoftgraph.chinacloudapi.cn/v1.0/sites/'.$hostname.':'.$_GET["site"]; + $request["url"]=$getsiteid; + $respp=fetch::get($request) ; + $datass = json_decode($respp->content, true); + +echo $siteidurl=($datass["id"]); +if (($datass["id"])==""){echo "获取站点id失败刷新重试试"; + + echo '站点名称填写/sites/名称或者/teams/名称'; + echo '
+   +   +
'; + +exit;} +$b = ' +进入后台刷新缓存生效 默认密码oneindex'; diff --git a/page.html b/page.html new file mode 100644 index 0000000..24c12b0 --- /dev/null +++ b/page.html @@ -0,0 +1,22 @@ + + + + +Untitled Document + + + + + + + + diff --git a/view/admin/settings.php b/view/admin/settings.php index 0496b4f..a363cde 100644 --- a/view/admin/settings.php +++ b/view/admin/settings.php @@ -4,7 +4,7 @@
-

基本设置 设置OneIndex基本参数

+

基本设置 设置基本参数

@@ -12,8 +12,25 @@
+
+

副标题

+ +
+
+

sharepoint域名

+ +
+
+

sharepoint CDN 域名-留空不使用该功能

+ +
+
+

侧边栏代码

+ +
+
-

网站主题

+

网站风格

+
+

项目数量

+ +
+
-

OneDrive起始目录(空为根目录)例:仅共享share目录 /share

+

起始目录 (空为根目录)

-

需要隐藏的目录 不需要列出的目录(一行一个) 清空缓存后生效

- - 这里是通配识别,就是存在以上字符文件夹一律会隐藏 -
- -
-

防盗链(白名单) 不填写则不启用, 多个用英文 ; 分割

- - 支持通配符 例: *.domain.com +

需要隐藏的目录 (每行一项,通配识别,清空缓存后生效)

+
@@ -64,7 +79,7 @@
-

去掉地址栏中的/?/ (需配合伪静态使用!!)

+

去掉/?/ (需配合伪静态使用!!)