diff --git a/conststr.php b/conststr.php
index 920aa3c..b0954f9 100644
--- a/conststr.php
+++ b/conststr.php
@@ -16,92 +16,64 @@ $constStr = [
'ja' => '日本語',
],
'Week' => [
- 0 => [
- 'en-us' => 'Sunday',
- 'zh-cn' => '星期日',
- 'ja' => '日曜日',
+ 'en-us' => [
+ 0 => 'Sunday',
+ 1 => 'Monday',
+ 2 => 'Tuesday',
+ 3 => 'Wednesday',
+ 4 => 'Thursday',
+ 5 => 'Friday',
+ 6 => 'Saturday',
],
- 1 => [
- 'en-us' => 'Monday',
- 'zh-cn' => '星期一',
- 'ja' => '月曜日',
+ 'zh-cn' => [
+ 0 => '星期日',
+ 1 => '星期一',
+ 2 => '星期二',
+ 3 => '星期三',
+ 4 => '星期四',
+ 5 => '星期五',
+ 6 => '星期六',
],
- 2 => [
- 'en-us' => 'Tuesday',
- 'zh-cn' => '星期二',
- 'ja' => '火曜日',
- ],
- 3 => [
- 'en-us' => 'Wednesday',
- 'zh-cn' => '星期三',
- 'ja' => '水曜日',
- ],
- 4 => [
- 'en-us' => 'Thursday',
- 'zh-cn' => '星期四',
- 'ja' => '木曜日',
- ],
- 5 => [
- 'en-us' => 'Friday',
- 'zh-cn' => '星期五',
- 'ja' => '金曜日',
- ],
- 6 => [
- 'en-us' => 'Saturday',
- 'zh-cn' => '星期六',
- 'ja' => '土曜日',
+ 'ja' => [
+ 0 => '日曜日',
+ 1 => '月曜日',
+ 2 => '火曜日',
+ 3 => '水曜日',
+ 4 => '木曜日',
+ 5 => '金曜日',
+ 6 => '土曜日',
],
],
'EnvironmentsDescription' => [
- 'admin' => [
- 'en-us' => 'The admin password, Login button will not show when empty',
- 'zh-cn' => '管理密码,不添加时不显示登录页面且无法登录。',
- 'ja' => 'パスワードを管理する、追加しない場合、ログインページは表示されず、ログインできません。',
+ 'en-us' => [
+ 'admin' => 'The admin password, Login button will not show when empty',
+ 'adminloginpage' => 'if set, the Login button will not display, and the login page no longer \'?admin\', it is \'?{this value}\'.',
+ 'domain_path' => 'more custom domain, format is a1.com:/dirto/path1|b2.com:/path2',
+ 'guestup_path' => 'Set guest upload dir, before set this, the files in this dir will show as normal.',
+ 'passfile' => 'The password of dir will save in this file.',
+ 'public_path' => 'Show this Onedrive dir when through the long url of API Gateway; public show files less than private.',
+ 'sitename' => 'sitename',
+ 'Onedrive_ver' => 'Onedrive version',
],
- 'adminloginpage' => [
- 'en-us' => 'if set, the Login button will not display, and the login page no longer \'?admin\', it is \'?{this value}\'.',
- 'zh-cn' => '如果设置,登录按钮及页面隐藏。管理登录的页面不再是\'?admin\',而是\'?此设置的值\'。',
- 'ja' => '設定すると、ログインボタンとページが非表示になります。ログインを管理するためのページは\'?admin \'ではなく、\'?この設定の値\'。',
+ 'zh-cn' => [
+ 'admin' => '管理密码,不添加时不显示登录页面且无法登录。',
+ 'adminloginpage' => '如果设置,登录按钮及页面隐藏。管理登录的页面不再是\'?admin\',而是\'?此设置的值\'。',
+ 'domain_path' => '使用多个自定义域名时,指定每个域名看到的目录。格式为a1.com:/dirto/path1|b1.com:/path2,比private_path优先。',
+ 'guestup_path' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。',
+ 'passfile' => '自定义密码文件的名字,可以是\'pppppp\',也可以是\'aaaa.txt\'等等;列目录时不会显示,只有知道密码才能查看或下载此文件。密码是这个文件的内容,可以空格、可以中文;',
+ 'public_path' => '使用API长链接访问时,显示网盘文件的路径,不设置时默认为根目录;不能是private_path的上级(public看到的不能比private多,要么看到的就不一样)。',
+ 'sitename' => '网站的名称',
+ 'Onedrive_ver' => 'Onedrive版本',
],
- 'domain_path' => [
- 'en-us' => 'more custom domain, format is a1.com:/dirto/path1|b2.com:/path2',
- 'zh-cn' => '使用多个自定义域名时,指定每个域名看到的目录。格式为a1.com:/dirto/path1|b1.com:/path2,比private_path优先。',
- 'ja' => '複数のカスタムドメイン名を使用する場合、各ドメイン名に表示されるディレクトリを指定します。形式はa1.com:/dirto/path1|b1.com:/path2で、private_pathよりも優先されます。',
- ],
- 'guestup_path' => [
- 'en-us' => 'Set guest upload dir, before set this, the files in this dir will show as normal.',
- 'zh-cn' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。',
- 'ja' => 'マップベッドのパスを設定します。この値が設定されていない場合、ディレクトリの内容は通常ファイルにリストされ、設定後はアップロードインターフェイスのみが表示されます。',
- ],
- 'passfile' => [
- 'en-us' => 'The password of dir will save in this file.',
- 'zh-cn' => '自定义密码文件的名字,可以是\'pppppp\',也可以是\'aaaa.txt\'等等;列目录时不会显示,只有知道密码才能查看或下载此文件。密码是这个文件的内容,可以空格、可以中文;',
- 'ja' => 'カスタムパスワードファイルの名前は、\'pppppp \'、\'aaaa.txt \'などの場合があります。ディレクトリをリストするときには表示されません。パスワードを知っている場合にのみ、このファイルを表示またはダウンロードできます。 パスワードはこのファイルの内容であり、スペースまたは漢字を使用できます。',
- ],
- 'private_path' => [
- 'en-us' => 'Show this Onedrive dir when through custom domain, default is \'/\'.',
- 'zh-cn' => '使用自定义域名访问时,显示网盘文件的路径,不设置时默认为根目录。',
- 'ja' => 'カスタムドメイン名を使用してアクセスする場合、ネットワークディスクファイルのパスが表示されます設定されていない場合は、デフォルトでルートディレクトリになります。',
- ],
- 'public_path' => [
- 'en-us' => 'Show this Onedrive dir when through the long url of API Gateway; public show files less than private.',
- 'zh-cn' => '使用API长链接访问时,显示网盘文件的路径,不设置时默认为根目录;不能是private_path的上级(public看到的不能比private多,要么看到的就不一样)。',
- 'ja' => 'APIのロングリンクアクセスを使用する場合、ネットワークディスクファイルのパスが表示されますが、設定されていない場合はデフォルトでルートディレクトリになり、private_pathの上位にはなりません(publicはprivate以上のものを見ることができません。それ以外は異なります。)。',
- ],
- 'sitename' => [
- 'en-us' => 'sitename',
- 'zh-cn' => '网站的名称',
- 'ja' => 'ウェブサイト名',
- ],
- 'language' => [
- 'en-us' => 'en-us',
- 'zh-cn' => '中文',
- 'ja' => '日本語',
- ],
- 'Onedrive_ver' => [
- 'en-us' => 'Onedrive version',
- 'zh-cn' => 'Onedrive版本',
- 'ja' => 'Onedriveバージョン',
+ 'ja' => [
+ 'admin' => 'パスワードを管理する、追加しない場合、ログインページは表示されず、ログインできません。',
+ 'adminloginpage' => '設定すると、ログインボタンとページが非表示になります。ログインを管理するためのページは\'?admin \'ではなく、\'?この設定の値\'。',
+ 'domain_path' => '複数のカスタムドメイン名を使用する場合、各ドメイン名に表示されるディレクトリを指定します。形式はa1.com:/dirto/path1|b1.com:/path2で、private_pathよりも優先されます。',
+ 'guestup_path' => 'マップベッドのパスを設定します。この値が設定されていない場合、ディレクトリの内容は通常ファイルにリストされ、設定後はアップロードインターフェイスのみが表示されます。',
+ 'passfile' => 'カスタムパスワードファイルの名前は、\'pppppp \'、\'aaaa.txt \'などの場合があります。ディレクトリをリストするときには表示されません。パスワードを知っている場合にのみ、このファイルを表示またはダウンロードできます。 パスワードはこのファイルの内容であり、スペースまたは漢字を使用できます。',
+ 'public_path' => 'APIのロングリンクアクセスを使用する場合、ネットワークディスクファイルのパスが表示されますが、設定されていない場合はデフォルトでルートディレクトリになり、private_pathの上位にはなりません(publicはprivate以上のものを見ることができません。それ以外は異なります。)。',
+ 'sitename' => 'ウェブサイト名',
+ 'Onedrive_ver' => 'Onedriveバージョン',
],
],
'SetSecretsFirst' => [
diff --git a/function/common.php b/function/common.php
index fe036ae..70f55f7 100644
--- a/function/common.php
+++ b/function/common.php
@@ -14,14 +14,21 @@ function savecache($key, $value, $exp = 3300)
$cache->save($key, $value, $exp);
}
-function config_oauth()
+function getconstStr($str)
{
global $constStr;
$constStr['language'] = $_COOKIE['language'];
if ($constStr['language']=='') $constStr['language'] = getConfig('language');
if ($constStr['language']=='') $constStr['language'] = 'en-us';
+ if ($constStr[$str][$constStr['language']]!='') return $constStr[$str][$constStr['language']];
+ return $constStr[$str]['en-us'];
+}
+
+function config_oauth()
+{
+ global $constStr;
$_SERVER['sitename'] = getConfig('sitename');
- if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = $constStr['defaultSitename'][$constStr['language']];
+ if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
$_SERVER['redirect_uri'] = 'https://scfonedrive.github.io';
if (getConfig('Onedrive_ver')=='MS') {
@@ -311,3 +318,546 @@ function get_thumbnails_url($path = '/')
if (isset($files['url'])) return output($files['url']);
return output('', 404);
}
+
+function bigfileupload($path)
+{
+ $path1 = path_format($_SERVER['list_path'] . path_format($path));
+ if (substr($path1,-1)=='/') $path1=substr($path1,0,-1);
+ if ($_GET['upbigfilename']!=''&&$_GET['filesize']>0) {
+ $fileinfo['name'] = $_GET['upbigfilename'];
+ $fileinfo['size'] = $_GET['filesize'];
+ $fileinfo['lastModified'] = $_GET['lastModified'];
+ $filename = spurlencode( $fileinfo['name'] );
+ $cachefilename = '.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $filename . '.tmp';
+ $getoldupinfo=fetch_files(path_format($path . '/' . $cachefilename));
+ //echo json_encode($getoldupinfo, JSON_PRETTY_PRINT);
+ if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) {
+ $getoldupinfo_j = curl_request($getoldupinfo['@microsoft.graph.downloadUrl']);
+ $getoldupinfo = json_decode($getoldupinfo_j , true);
+ if ( json_decode( curl_request($getoldupinfo['uploadUrl']), true)['@odata.context']!='' ) return output($getoldupinfo_j);
+ }
+ if (!$_SERVER['admin']) $filename = spurlencode( $fileinfo['name'] ) . '.scfupload';
+ $response=MSAPI('createUploadSession',path_format($path1 . '/' . $filename),'{"item": { "@microsoft.graph.conflictBehavior": "fail" }}',$_SERVER['access_token']);
+ $responsearry = json_decode($response['body'],true);
+ if (isset($responsearry['error'])) return output($response['body'], $response['stat']);
+ $fileinfo['uploadUrl'] = $responsearry['uploadUrl'];
+ MSAPI('PUT', path_format($path1 . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body'];
+ return output($response['body'], $response['stat']);
+ }
+ return output('error', 400);
+}
+
+function main($path)
+{
+ global $exts;
+ global $constStr;
+ config_oauth();
+ $_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
+ if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';
+ $_SERVER['is_guestup_path'] = is_guestup_path($path);
+ $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
+ $_SERVER['ajax']=0;
+ if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
+
+ $refresh_token = getConfig('refresh_token');
+ if (!$refresh_token) return get_refresh_token();
+
+ if (getConfig('adminloginpage')=='') {
+ $adminloginpage = 'admin';
+ } else {
+ $adminloginpage = getConfig('adminloginpage');
+ }
+ if ($_GET[$adminloginpage]) {
+ if ($_GET['preview']) {
+ $url = $_SERVER['PHP_SELF'] . '?preview';
+ } else {
+ $url = path_format($_SERVER['PHP_SELF'] . '/');
+ }
+ if (getConfig('admin')!='') {
+ if ($_POST['password1']==getConfig('admin')) {
+ return adminform($_SERVER['function_name'].'admin',md5($_POST['password1']),$url);
+ } else return adminform();
+ } else {
+ return output('', 302, [ 'Location' => $url ]);
+ }
+ }
+ if (getConfig('admin')!='')
+ if ( $_COOKIE['admin']==md5(getConfig('admin')) || $_POST['password1']==getConfig('admin') ) {
+ $_SERVER['admin']=1;
+ $_SERVER['needUpdate'] = needUpdate();
+ } else {
+ $_SERVER['admin']=0;
+ }
+ if ($_GET['setup'])
+ if ($_SERVER['admin']) {
+ // setup Environments. 设置,对环境变量操作
+ return EnvOpt($_SERVER['function_name'], $_SERVER['needUpdate']);
+ } else {
+ $url = path_format($_SERVER['PHP_SELF'] . '/');
+ return output('', 302, [ 'Location' => $url ]);
+ }
+ $_SERVER['retry'] = 0;
+
+ if (!($_SERVER['access_token'] = getcache('access_token'))) {
+ $ret = json_decode(curl_request(
+ $_SERVER['oauth_url'] . 'token',
+ 'client_id='. $_SERVER['client_id'] .'&client_secret='. $_SERVER['client_secret'] .'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . $refresh_token
+ )['body'], true);
+ if (!isset($ret['access_token'])) {
+ error_log('failed to get access_token. response' . json_encode($ret));
+ throw new Exception('failed to get access_token.');
+ }
+ $_SERVER['access_token'] = $ret['access_token'];
+ savecache('access_token', $_SERVER['access_token']);
+ }
+
+ if ($_SERVER['ajax']) {
+ if ($_GET['action']=='del_upload_cache'&&substr($_GET['filename'],-4)=='.tmp') {
+ // del '.tmp' without login. 无需登录即可删除.tmp后缀文件
+ $tmp = MSAPI('DELETE',path_format(path_format($_SERVER['list_path'] . path_format($path)) . '/' . spurlencode($_GET['filename']) ),'',$_SERVER['access_token']);
+ $path1 = path_format($_SERVER['list_path'] . path_format($path));
+ savecache('path_' . $path1, json_decode('{}',true), 1);
+ return output($tmp['body'],$tmp['stat']);
+ }
+ if ($_GET['action']=='uploaded_rename') {
+ // rename .scfupload file without login.
+ // 无需登录即可重命名.scfupload后缀文件,filemd5为用户提交,可被构造,问题不大,以后处理
+ $oldname = spurlencode($_GET['filename']);
+ $pos = strrpos($oldname, '.');
+ if ($pos>0) $ext = strtolower(substr($oldname, $pos));
+ $oldname = path_format(path_format($_SERVER['list_path'] . path_format($path)) . '/' . $oldname . '.scfupload' );
+ $data = '{"name":"' . $_GET['filemd5'] . $ext . '"}';
+ //echo $oldname .'
'. $data;
+ $tmp = MSAPI('PATCH',$oldname,$data,$_SERVER['access_token']);
+ if ($tmp['stat']==409) MSAPI('DELETE',$oldname,'',$_SERVER['access_token'])['body'];
+ $path1 = path_format($_SERVER['list_path'] . path_format($path));
+ savecache('path_' . $path1, json_decode('{}',true), 1);
+ return output($tmp['body'],$tmp['stat']);
+ }
+ if ($_GET['action']=='upbigfile') return bigfileupload($path);
+ }
+ if ($_SERVER['admin']) {
+ $tmp = adminoperate($path);
+ if ($tmp['statusCode'] > 0) {
+ $path1 = path_format($_SERVER['list_path'] . path_format($path));
+ savecache('path_' . $path1, json_decode('{}',true), 1);
+ return $tmp;
+ }
+ } else {
+ if ($_SERVER['ajax']) return output(getconstStr('RefleshtoLogin'),401);
+ }
+ $_SERVER['ishidden'] = passhidden($path);
+ if ($_GET['thumbnails']) {
+ if ($_SERVER['ishidden']<4) {
+ if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) {
+ return get_thumbnails_url($path);
+ } else return output(json_encode($exts['img']),400);
+ } else return output('',401);
+ }
+ $files = list_files($path);
+ if (isset($files['file']) && !$_GET['preview']) {
+ // is file && not preview mode
+ if ($_SERVER['ishidden']<4) return output('', 302, [ 'Location' => $files['@microsoft.graph.downloadUrl'] ]);
+ }
+ if ( isset($files['folder']) || isset($files['file']) ) {
+ return render_list($path, $files);
+ } else {
+ return message('