diff --git a/common.php b/common.php index 48af4a8..cd3ed6e 100644 --- a/common.php +++ b/common.php @@ -1,155 +1,59 @@ 0b000, // used in heroku. + 'SecretId' => 0b000, // used in SCF. + 'SecretKey' => 0b000, // used in SCF. + 'AccessKeyID' => 0b000, // used in FC. + 'AccessKeySecret' => 0b000, // used in FC. + 'HW_urn' => 0b000, // used in FG. + 'HW_key' => 0b000, // used in FG. + 'HW_secret' => 0b000, // used in FG. + 'function_name' => 0b000, // used in heroku. -$CommonEnv = [ - 'APIKey', // used in heroku. - 'SecretId', // used in SCF. - 'SecretKey', // used in SCF. - 'AccessKeyID', // used in FC. - 'AccessKeySecret', // used in FC. - 'HW_urn', // used in FG. - 'HW_key', // used in FG. - 'HW_secret', // used in FG. - 'admin', - 'adminloginpage', - 'autoJumpFirstDisk', - 'background', - 'backgroundm', - 'disktag', - 'disableShowThumb', - 'disableChangeTheme', - 'function_name', // used in heroku. - 'hideFunctionalityFile', - 'timezone', - 'passfile', - 'sitename', - 'customScript', - 'customCss', - 'customTheme', - 'theme', -]; + 'admin' => 0b001, + 'adminloginpage' => 0b010, + 'autoJumpFirstDisk' => 0b010, + 'background' => 0b011, + 'backgroundm' => 0b011, + 'disableShowThumb' => 0b010, + 'disableChangeTheme'=> 0b010, + 'disktag' => 0b000, + 'hideFunctionalityFile'=> 0b010, + 'timezone' => 0b010, + 'passfile' => 0b011, + 'sitename' => 0b011, + 'customScript' => 0b011, + 'customCss' => 0b011, + 'customTheme' => 0b011, + 'theme' => 0b010, -$ShowedCommonEnv = [ - //'APIKey', // used in heroku. - //'SecretId', // used in SCF. - //'SecretKey', // used in SCF. - //'AccessKeyID', // used in FC. - //'AccessKeySecret', // used in FC. - //'HW_urn', // used in FG. - //'HW_key', // used in FG. - //'HW_secret', // used in FG. - //'admin', - 'adminloginpage', - 'autoJumpFirstDisk', - 'background', - 'backgroundm', - //'disktag', - 'disableShowThumb', - 'disableChangeTheme', - //'function_name', // used in heroku. - 'hideFunctionalityFile', - 'timezone', - 'passfile', - 'sitename', - 'customScript', - 'customCss', - 'customTheme', - 'theme', -]; - -$InnerEnv = [ - 'Drive_ver', - 'Drive_custom', - 'client_id', - 'client_secret', - 'diskname', - 'domain_path', - 'downloadencrypt', - 'guestup_path', - 'usesharepoint', - 'sharepointSiteAddress', - 'siteid', - 'shareurl', - //'sharecookie', - 'shareapiurl', - 'domainforproxy', - 'public_path', - 'refresh_token', - 'token_expires', -]; - -$ShowedInnerEnv = [ - //'Drive_ver', - //'Drive_custom', - //'client_id', - //'client_secret', - 'diskname', - 'domain_path', - 'downloadencrypt', - 'guestup_path', - //'usesharepoint', - //'sharepointSiteAddress', - //'siteid', - //'shareurl', - //'sharecookie', - //'shareapiurl', - 'domainforproxy', - 'public_path', - //'refresh_token', - //'token_expires', + 'Driver' => 0b100, + 'client_id' => 0b100, + 'client_secret' => 0b101, + 'diskname' => 0b111, + 'domain_path' => 0b111, + 'downloadencrypt' => 0b110, + 'guestup_path' => 0b111, + 'sharepointSite' => 0b101, + 'shareurl' => 0b101, + //'sharecookie' => 0b101, + 'shareapiurl' => 0b101, + 'siteid' => 0b100, + 'domainforproxy' => 0b111, + 'public_path' => 0b111, + 'refresh_token' => 0b100, + 'token_expires' => 0b100, + 'default_drive_id' => 0b100, + 'default_sbox_drive_id'=> 0b100, ]; $timezones = array( @@ -186,11 +90,43 @@ $timezones = array( '12'=>'Asia/Kamchatka' ); +function isCommonEnv($str) +{ + global $EnvConfigs; + if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b100 ) ? false : true; + else return null; +} + +function isInnerEnv($str) +{ + global $EnvConfigs; + if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b100 ) ? true : false; + else return null; +} + +function isShowedEnv($str) +{ + global $EnvConfigs; + if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b010 ) ? true : false; + else return null; +} + +function isBase64Env($str) +{ + global $EnvConfigs; + if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b001 ) ? true : false; + else return null; +} + function main($path) { global $exts; global $constStr; + global $slash; + global $drive; + $slash = '/'; + if (strpos(__DIR__, ':')) $slash = '\\'; $_SERVER['php_starttime'] = microtime(true); $path = path_format($path); if (in_array($_SERVER['firstacceptlanguage'], array_keys($constStr['languages']))) { @@ -211,6 +147,7 @@ function main($path) if (isset($_COOKIE['timezone'])&&$_COOKIE['timezone']!='') $_SERVER['timezone'] = $_COOKIE['timezone']; if ($_SERVER['timezone']=='') $_SERVER['timezone'] = 0; $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path); + if (getConfig('admin')=='') return install(); if (getConfig('adminloginpage')=='') { @@ -255,16 +192,17 @@ function main($path) if (count($disktags)>1) { if ($path=='/'||$path=='') { if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]); + $files['type'] = 'folder'; + $files['childcount'] = count($disktags); $files['showname'] = 'root'; - $files['folder']['childCount'] = count($disktags); foreach ($disktags as $disktag) { - $files['children'][$disktag]['folder'] = 1; - $files['children'][$disktag]['name'] = $disktag; - $files['children'][$disktag]['showname'] = getConfig('diskname', $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 files_json($files); + return output(json_encode($files)); } } else { $_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0]; @@ -295,133 +233,188 @@ function main($path) $_SERVER['ajax']=0; if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1; - if ($_SERVER['admin']) if (isset($_GET['AddDisk'])) return get_refresh_token(); - - if ($files['showname'] == 'root') return render_list($path, $files); - config_oauth(); - $refresh_token = getConfig('refresh_token'); - if (!$refresh_token) { - return render_list(); - } else { - if (!($_SERVER['access_token'] = getcache('access_token', $_SERVER['disktag']))) { - $response = get_access_token($refresh_token); - if (isset($response['stat'])) return message($response['body'], 'Error', $response['stat']); - } - - if ($_SERVER['ajax']) { - if ($_GET['action']=='del_upload_cache') { - // del '.tmp' without login. 无需登录即可删除.tmp后缀文件 - error_log('del.tmp:GET,'.json_encode($_GET,JSON_PRETTY_PRINT)); - $tmp = splitlast($_GET['filename'], '/'); - if ($tmp[1]!='') { - $filename = $tmp[0] . '/.' . $_GET['filelastModified'] . '_' . $_GET['filesize'] . '_' . $tmp[1] . '.tmp'; - } else { - $filename = '.' . $_GET['filelastModified'] . '_' . $_GET['filesize'] . '_' . $_GET['filename'] . '.tmp'; - } - $filename = path_format( path_format($_SERVER['list_path'] . path_format($path)) . '/' . spurlencode($filename, '/') ); - $tmp = MSAPI('DELETE', $filename, '', $_SERVER['access_token']); - $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); - savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 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' ); - $oldname = path_format(path_format($_SERVER['list_path'] . path_format($path)) . '/' . $oldname); - $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']); - $tmpbody = json_decode($tmp['body'], true); - $tmpbody['name'] = $_GET['filemd5'] . $ext; - $tmp['body'] = json_encode($tmpbody); - } - $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); - savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - return output($tmp['body'],$tmp['stat']); - } - if ($_GET['action']=='upbigfile') return bigfileupload($path); - } + // Add disk + if (isset($_GET['AddDisk'])) { if ($_SERVER['admin']) { - $tmp = adminoperate($path); - if ($tmp['statusCode'] > 0) { - $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); - savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - return $tmp; - } + if (!class_exists($_GET['AddDisk'])) require 'disk' . $slash . $_GET['AddDisk'] . '.php'; + $drive = new $_GET['AddDisk']($_COOKIE['disktag']); + return $drive->AddDisk(); } else { - if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401); - } - $_SERVER['ishidden'] = passhidden($path); - if (isset($_GET['thumbnails'])) { - if ($_SERVER['ishidden']<4) { - if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) { - return get_thumbnails_url($path, $_GET['location']); - } else return output(json_encode($exts['img']),400); - } else return output('',401); - } - - $files = list_files($path); - //echo json_encode(array_keys($files['children']), JSON_PRETTY_PRINT); - if ($_GET['json']) { - // return a json - return files_json($files); - } - if (isset($_GET['random'])&&$_GET['random']!=='') { - if ($_SERVER['ishidden']<4) { - $tmp = []; - foreach (array_keys($files['children']) as $filename) { - if (strtolower(splitlast($filename,'.')[1])==strtolower($_GET['random'])) $tmp[$filename] = $files['children'][$filename][$_SERVER['DownurlStrName']]; - } - $tmp = array_values($tmp); - if (count($tmp)>0) { - $url = $tmp[rand(0,count($tmp)-1)]; - if (isset($_GET['url'])) return output($url, 200); - $domainforproxy = ''; - $domainforproxy = getConfig('domainforproxy'); - if ($domainforproxy!='') { - $url = proxy_replace_domain($url, $domainforproxy); + $url = $_SERVER['PHP_SELF']; + if ($_GET) { + $tmp = null; + $tmp = ''; + foreach ($_GET as $k => $v) { + if ($k!='setup') { + if ($v===true) $tmp .= '&' . $k; + else $tmp .= '&' . $k . '=' . $v; } - return output('', 302, [ 'Location' => $url ]); - } else return output('',404); - } else return output('',401); + } + $tmp = substr($tmp, 1); + if ($tmp!='') $url .= '?' . $tmp; + } + return output('', 302, [ 'Location' => $url ]); } - if (isset($files['file']) && !isset($_GET['preview'])) { - // is file && not preview mode - if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt')&&$files['name']!=getConfig('passfile')) ) { - $url = $files[$_SERVER['DownurlStrName']]; + } + + // Show disks in root + if ($files['showname'] == 'root') return render_list($path, $files); + + $disktype = getConfig('Driver', $_SERVER['disktag']); + if ($disktype=='') return render_list(); + + if (!class_exists($disktype)) require 'disk' . $slash . $disktype . '.php'; + $drive = new $disktype($_SERVER['disktag']); + if (!driveisfine($_SERVER['disktag'])) return render_list(); + + // Operate + if ($_SERVER['ajax']) { + if ($_GET['action']=='del_upload_cache') { + // del '.tmp' without login. 无需登录即可删除.tmp后缀文件 + return $drive->del_upload_cache(); + } + if ($_GET['action']=='upbigfile') { + if (!$_SERVER['admin']) { + if (!is_guestup_path($path)) return output('Not_Guest_Upload_Folder', 400); + if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); + } + $path1 = path_format($_SERVER['list_path'] . path_format($path)); + if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1); + return $drive->bigfileupload($path1); + } + } + 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), $_SERVER['disktag'], 1); + if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); + savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); + return $tmp; + } + } else { + if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401); + } + $_SERVER['ishidden'] = passhidden($path); + if (isset($_GET['thumbnails'])) { + if ($_SERVER['ishidden']<4) { + if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) { + $path1 = path_format($_SERVER['list_path'] . path_format($path)); + if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1); + $thumb_url = $drive->get_thumbnails_url($path1); + if ($thumb_url!='') { + if ($_GET['location']) { + $url = $thumb_url; + $domainforproxy = ''; + $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']); + if ($domainforproxy!='') { + $url = proxy_replace_domain($url, $domainforproxy); + } + return output('', 302, [ 'Location' => $url ]); + } else return output($thumb_url); + } + return output('', 404); + } else return output(json_encode($exts['img']), 400); + } else return output('', 401); + } + + // list folder + if ($_SERVER['is_guestup_path'] && !$_SERVER['admin']) { + $files = json_decode('{"type":"folder"}', true); + } elseif (!getConfig('downloadencrypt', $_SERVER['disktag'])) { + if ($_SERVER['ishidden']==4) $files = json_decode('{"type":"folder"}', true); + else { + $path1 = path_format($_SERVER['list_path'] . path_format($path)); + if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1); + $files = $drive->list_files($path1); + } + } else { + $path1 = path_format($_SERVER['list_path'] . path_format($path)); + if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1); + $files = $drive->list_files($path1); + } + + if ($_GET['json']) { + // return a json + return output(json_encode($files)); + } + // random file + if (isset($_GET['random'])&&$_GET['random']!=='') { + if ($_SERVER['ishidden']<4) { + $tmp = []; + foreach (array_keys($files['list']) as $filename) { + if (strtolower(splitlast($filename, '.')[1])==strtolower($_GET['random'])) $tmp[$filename] = $files['list'][$filename]['url']; + } + $tmp = array_values($tmp); + if (count($tmp)>0) { + $url = $tmp[rand(0, count($tmp)-1)]; + if (isset($_GET['url'])) return output($url, 200); $domainforproxy = ''; - $domainforproxy = getConfig('domainforproxy'); + $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']); if ($domainforproxy!='') { $url = proxy_replace_domain($url, $domainforproxy); } - if ( strtolower(splitlast($files['name'],'.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']); - else { - if ($_SERVER['HTTP_RANGE']!='') $header['Range'] = $_SERVER['HTTP_RANGE']; - $header['Location'] = $url; - return output('', 302, $header); - } + return output('', 302, [ 'Location' => $url ]); + } else return output('No ' . $_GET['random'] . 'file', 404); + } else return output('Hidden', 401); + } + // is file && not preview mode, download file + if ($files['type']=='file' && !isset($_GET['preview'])) { + if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt', $_SERVER['disktag'])&&$files['name']!=getConfig('passfile')) ) { + $url = $files['url']; + $domainforproxy = ''; + $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']); + if ($domainforproxy!='') { + $url = proxy_replace_domain($url, $domainforproxy); } - } - if ( isset($files['folder']) || isset($files['file']) ) { - return render_list($path, $files); - } else { - if (!isset($files['error'])) { - $files['error']['message'] = json_encode($files, JSON_PRETTY_PRINT); - $files['error']['code'] = 'unknownError'; - $files['error']['stat'] = 500; + if ( strtolower(splitlast($files['name'], '.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']); + else { + if ($_SERVER['HTTP_RANGE']!='') $header['Range'] = $_SERVER['HTTP_RANGE']; + $header['Location'] = $url; + return output('', 302, $header); } - return message(''.getconstStr('Back').getconstStr('Home').'
' . $files['error']['message'] . '
'.getconstStr('Back').'', $files['error']['code'], $files['error']['stat']); } } + // Show folder + if ( $files['type']=='folder' || $files['type']=='file' ) { + return render_list($path, $files); + } else { + if (!isset($files['error'])) { + if (is_array($files)) $files['error']['message'] = json_encode($files, JSON_PRETTY_PRINT); + else $files['error']['message'] = $files; + $files['error']['code'] = 'unknownError'; + $files['error']['stat'] = 500; + } + return message(''.getconstStr('Back').getconstStr('Home').'
' . $files['error']['message'] . '
'.getconstStr('Back').'', $files['error']['code'], $files['error']['stat']); + } +} + +function get_content($path) +{ + global $drive; + $path1 = path_format($_SERVER['list_path'] . path_format($path)); + if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1); + $file = $drive->list_files($path1); + //var_dump($file); + return $file; +} + +function driveisfine($tag) +{ + global $slash; + $disktype = getConfig('Driver', $tag); + if (!$disktype) return false; + if (!class_exists($disktype)) require 'disk' . $slash . $disktype . '.php'; + $drive = new $disktype($tag); + if ($drive->isfine()) return true; + else return false; +} + +function baseclassofdrive() +{ + global $drive; + if (!$drive) return false; + return $drive->show_base_class(); } function pass2cookie($name, $pass) @@ -443,110 +436,6 @@ function proxy_replace_domain($url, $domainforproxy) //$url = str_replace($tmp, $domainforproxy, $url).'&Origindomain='.$tmp; } -function files_json($files) -{ - //$tmp = ''; - if (isset($files['file'])) { - $tmp['file']['type'] = 0; - $tmp['file']['id'] = $files['id']; - $tmp['file']['name'] = $files['name']; - $tmp['file']['time'] = $files['lastModifiedDateTime']; - $tmp['file']['size'] = $files['size']; - $tmp['file']['mime'] = $files['file']['mimeType']; - $tmp['file']['url'] = $files[$_SERVER['DownurlStrName']]; - $tmp['url'] = $files[$_SERVER['DownurlStrName']]; - } elseif (isset($files['folder'])) { - $tmp['list'] = []; - foreach ($files['children'] as $file) { - $tmp1 = null; - $tmp1 = []; - if (isset($file['file'])) { - $tmp1['type'] = 0; - $tmp1['url'] = $file[$_SERVER['DownurlStrName']]; - } elseif (isset($file['folder'])) { - $tmp1['type'] = 1; - } - $tmp1['id'] = $file['id']; - $tmp1['name'] = $file['name']; - $tmp1['time'] = $file['lastModifiedDateTime']; - $tmp1['size'] = $file['size']; - $tmp1['mime'] = $file['file']['mimeType']; - array_push($tmp['list'], $tmp1); - } - } else return output(var_dump($files), 404); - return output(json_encode($tmp), 200, ['Content-Type' => 'application/json']); -} - -function get_access_token($refresh_token) -{ - if (getConfig('Drive_ver')=='shareurl') { - $shareurl = getConfig('shareurl'); - $tmp1 = splitlast($shareurl, '/')[0]; - $account = splitlast($tmp1, '/')[1]; - $tmp1 = splitlast($shareurl, ':')[0]; - $domain = splitlast($tmp1, '/')[0]; - if (!isset($_SERVER['sharecookie'])||$_SERVER['sharecookie']=='') $_SERVER['sharecookie'] = curl_request($shareurl,false, [],1)['returnhead']['Set-Cookie']; - $response = curl_request( - $domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE", - '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}', - [ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => $domain, 'Cookie' => $_SERVER['sharecookie'] ] - ); - if ($response['stat']==200) $ret = json_decode($response['body'], true); - $_SERVER['access_token'] = splitlast($ret['ListSchema']['.driveAccessToken'],'=')[1]; - $_SERVER['api_url'] = $ret['ListSchema']['.driveUrl'].'/root'; - if (!$_SERVER['access_token']) { - error_log($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE"); - error_log('failed to get share access_token. response' . json_encode($ret)); - $response['body'] .= '\nfailed to get shareurl access_token.'; - return $response; - //throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']); - } - $tmp = $ret; - $tmp['access_token'] = '******'; - error_log('['.$_SERVER['disktag'].'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT)); - savecache('access_token', $_SERVER['access_token'], $_SERVER['disktag']); - $tmp1 = []; - $tmp1['shareapiurl'] = $_SERVER['api_url']; - if (getConfig('shareapiurl')=='') setConfig($tmp1); - } else { - $p=0; - while ($response['stat']==0&&$p<3) { - $response = 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 ); - $p++; - } - if ($response['stat']==200) $ret = json_decode($response['body'], true); - if (!isset($ret['access_token'])) { - error_log($_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=' . substr($refresh_token, 0, 20) . '******' . substr($refresh_token, -20)); - error_log('failed to get ['.$_SERVER['disktag'].'] access_token. response' . json_encode($ret)); - $response['body'] .= '\nfailed to get ['.$_SERVER['disktag'].'] access_token.'; - return $response; - //throw new Exception($response['stat'].', failed to get ['.$_SERVER['disktag'].'] access_token.'.$response['body']); - } - $tmp = $ret; - $tmp['access_token'] = '******'; - $tmp['refresh_token'] = '******'; - error_log('['.$_SERVER['disktag'].'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT)); - $_SERVER['access_token'] = $ret['access_token']; - savecache('access_token', $_SERVER['access_token'], $_SERVER['disktag'], $ret['expires_in'] - 300); - if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]); - } - return 0; -} - -function list_files($path) -{ - $path = path_format($path); - if ($_SERVER['is_guestup_path']&&!$_SERVER['admin']) { - $files = json_decode('{"folder":{}}', true); - } elseif (!getConfig('downloadencrypt')) { - if ($_SERVER['ishidden']==4) $files = json_decode('{"folder":{}}', true); - else $files = fetch_files($path); - } else { - $files = fetch_files($path); - } - return $files; -} - function isHideFile($name) { $FunctionalityFile = [ @@ -596,6 +485,26 @@ function filecache($disktag) return $cache; } +function sortConfig(&$arr) +{ + ksort($arr); + + $tags = explode('|', $arr['disktag']); + unset($arr['disktag']); + if ($tags[0]!='') { + foreach($tags as $tag) { + $disks[$tag] = $arr[$tag]; + unset($arr[$tag]); + } + $arr['disktag'] = implode('|', $tags); + foreach($disks as $k => $v) { + $arr[$k] = $v; + } + } + + return $arr; +} + function getconstStr($str) { global $constStr; @@ -603,78 +512,10 @@ function getconstStr($str) return $constStr[$str]['en-us']; } -function config_oauth() -{ - $_SERVER['redirect_uri'] = 'https://scfonedrive.github.io'; - if (getConfig('Drive_ver')=='shareurl') { - $_SERVER['api_url'] = getConfig('shareapiurl'); - $_SERVER['sharecookie'] = getConfig('sharecookie'); - $_SERVER['DownurlStrName'] = '@content.downloadUrl'; - return 0; - } - if (getConfig('Drive_ver')=='MS') { - // MS - // https://portal.azure.com - //$_SERVER['client_id'] = '4da3e7f2-bf6d-467c-aaf0-578078f0bf7c'; - //$_SERVER['client_secret'] = '7/+ykq2xkfx:.DWjacuIRojIaaWL0QI6'; - $_SERVER['client_id'] = '734ef928-d74c-4555-8d1b-d942fa0a1a41'; - $_SERVER['client_secret'] = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW'; - $_SERVER['oauth_url'] = 'https://login.microsoftonline.com/common/oauth2/v2.0/'; - $_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/me/drive/root'; - $_SERVER['scope'] = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access'; - if (getConfig('usesharepoint')=='on') $_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/sites/' . getConfig('siteid') . '/drive/root'; - } - if (getConfig('Drive_ver')=='CN') { - // CN 21Vianet - // https://portal.azure.cn - $_SERVER['client_id'] = '31f3bed5-b9d9-4173-86a4-72c73d278617'; - $_SERVER['client_secret'] = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y'; - $_SERVER['oauth_url'] = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/'; - $_SERVER['api_url'] = 'https://microsoftgraph.chinacloudapi.cn/v1.0/me/drive/root'; - $_SERVER['scope'] = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access'; - if (getConfig('usesharepoint')=='on') $_SERVER['api_url'] = 'https://microsoftgraph.chinacloudapi.cn/v1.0/sites/' . getConfig('siteid') . '/drive/root'; - } - - if (getConfig('Drive_custom')=='on') { - // Customer - $_SERVER['client_id'] = getConfig('client_id'); - $_SERVER['client_secret'] = getConfig('client_secret'); - } - $_SERVER['client_secret'] = urlencode($_SERVER['client_secret']); - $_SERVER['scope'] = urlencode($_SERVER['scope']); - $_SERVER['DownurlStrName'] = '@microsoft.graph.downloadUrl'; -} - -function get_siteid($access_token) -{ - $sharepointSiteAddress = getConfig('sharepointSiteAddress'); - while (substr($sharepointSiteAddress, -1)=='/') $sharepointSiteAddress = substr($sharepointSiteAddress, 0, -1); - $tmp = splitlast($sharepointSiteAddress, '/'); - $sharepointname = urlencode($tmp[1]); - $tmp = splitlast($tmp[0], '/'); - $sharepointname = $tmp[1] . '/' . $sharepointname; - if (getConfig('Drive_ver')=='MS') $url = 'https://graph.microsoft.com/v1.0/sites/root:/'.$sharepointname; - if (getConfig('Drive_ver')=='CN') $url = 'https://microsoftgraph.chinacloudapi.cn/v1.0/sites/root:/'.$sharepointname; - - $i=0; - $response = []; - while ($url!=''&&$response['stat']!=200&&$i<4) { - $response = curl_request($url, false, ['Authorization' => 'Bearer ' . $access_token]); - $i++; - } - if ($response['stat']!=200) { - error_log('failed to get siteid. response' . json_encode($response)); - $response['body'] .= '\nfailed to get siteid.'; - return $response; - //throw new Exception($response['stat'].', failed to get siteid.'.$response['body']); - } - return json_decode($response['body'],true)['id']; -} - function getListpath($domain) { - $domain_path1 = getConfig('domain_path'); - $public_path = getConfig('public_path'); + $domain_path1 = getConfig('domain_path', $_SERVER['disktag']); + $public_path = getConfig('public_path', $_SERVER['disktag']); $tmp_path=''; if ($domain_path1!='') { $tmp = explode("|",$domain_path1); @@ -704,19 +545,19 @@ function path_format($path) function spurlencode($str, $split='') { - $str = str_replace(' ', '%20',$str); + $str = str_replace(' ', '%20', $str); $tmp=''; if ($split!='') { $tmparr=explode($split, $str); foreach ($tmparr as $str1) { $tmp .= urlencode($str1) . $split; } - $tmp = substr($tmp, 0, -strlen($split)); + $tmp = substr($tmp, 0, strlen($tmp)-strlen($split)); } else { $tmp = urlencode($str); } - $tmp = str_replace('%2520', '%20',$tmp); - $tmp = str_replace('%26amp%3B', '&',$tmp); + $tmp = str_replace('%2520', '%20', $tmp); + $tmp = str_replace('%26amp%3B', '&', $tmp); return $tmp; } @@ -735,27 +576,17 @@ function base64y_decode($str) while (strpos($str, '-')!==false) $str = str_replace('-', '+', $str); while (strlen($str)%4) $str .= '='; $str = base64_decode($str); - if (strpos($str, '%')!==false) $str = urldecode($str); - return $str; -} - -function equal_replace($str, $add = false) -{ - if ($add) { - while(strlen($str)%4) $str .= '='; - $str = urldecode(base64_decode($str)); - } else { - $str = base64_encode(urlencode($str)); - while(substr($str,-1)=='=') $str=substr($str,0,-1); - } + //if (strpos($str, '%')!==false) $str = urldecode($str); return $str; } function is_guestup_path($path) { - $a1 = path_format(path_format(urldecode($_SERVER['list_path'].path_format($path))).'/'); - $a2 = path_format(path_format(getConfig('guestup_path')).'/'); - if (getConfig('guestup_path')!=''&&strtolower($a1)==strtolower($a2)) return 1; + if (getConfig('guestup_path', $_SERVER['disktag'])!='') { + $a1 = path_format(path_format(urldecode($_SERVER['list_path'].path_format($path))).'/'); + $a2 = path_format(path_format(getConfig('guestup_path', $_SERVER['disktag'])).'/'); + if (strtolower($a1)==strtolower($a2)) return 1; + } return 0; } @@ -769,6 +600,7 @@ function curl($method, $url, $data = '', $headers = [], $returnheader = 0) //if (!isset($headers['Accept'])) $headers['Accept'] = '*/*'; //if (!isset($headers['Referer'])) $headers['Referer'] = $url; //if (!isset($headers['Content-Type'])) $headers['Content-Type'] = 'application/x-www-form-urlencoded'; + if (!isset($headers['Content-Type'])) $headers['Content-Type'] = ''; $sendHeaders = array(); foreach ($headers as $headerName => $headerVal) { $sendHeaders[] = $headerName . ': ' . $headerVal; @@ -804,7 +636,7 @@ function curl_request($url, $data = false, $headers = [], $returnheader = 0) { if (!isset($headers['Accept'])) $headers['Accept'] = '*/*'; //if (!isset($headers['Referer'])) $headers['Referer'] = $url; - if (!isset($headers['Content-Type'])) $headers['Content-Type'] = 'application/x-www-form-urlencoded'; + //if (!isset($headers['Content-Type'])) $headers['Content-Type'] = 'application/x-www-form-urlencoded'; $sendHeaders = array(); foreach ($headers as $headerName => $headerVal) { $sendHeaders[] = $headerName . ': ' . $headerVal; @@ -833,7 +665,7 @@ function curl_request($url, $data = false, $headers = [], $returnheader = 0) } else { $response['body'] = curl_exec($ch); } - $response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE); + $response['stat'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $response; } @@ -873,10 +705,10 @@ function gethiddenpass($path,$passfile) if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); $password=getcache('path_' . $path1 . '/?password', $_SERVER['disktag']); if ($password=='') { - $ispassfile = fetch_files(path_format($path . '/' . urlencode($passfile))); + $ispassfile = get_content(path_format($path . '/' . urlencode($passfile))); //echo $path . '
' . json_encode($ispassfile, JSON_PRETTY_PRINT) . '
'; - if (isset($ispassfile['file'])) { - $arr = curl_request($ispassfile[$_SERVER['DownurlStrName']]); + if ($ispassfile['type']=='file') { + $arr = curl('GET', $ispassfile['url']); if ($arr['stat']==200) { $passwordf=explode("\n",$arr['body']); $password=$passwordf[0]; @@ -935,17 +767,18 @@ function message($message, $title = 'Message', $statusCode = 200) function needUpdate() { - $slash = '/'; - if (strpos(__DIR__, ':')) $slash = '\\'; + global $slash; $current_version = file_get_contents(__DIR__ . $slash . 'version'); $current_ver = substr($current_version, strpos($current_version, '.')+1); $current_ver = explode(urldecode('%0A'),$current_ver)[0]; $current_ver = explode(urldecode('%0D'),$current_ver)[0]; $split = splitfirst($current_version, '.' . $current_ver)[0] . '.' . $current_ver; - //$github_version = file_get_contents('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version'); - $tmp = curl_request('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version'); - if ($tmp['stat']==0) return 0; - $github_version = $tmp['body']; + if (!($github_version = getcache('github_version'))) { + $tmp = curl('GET', 'https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version'); + if ($tmp['stat']==0) return 0; + $github_version = $tmp['body']; + savecache('github_version', $github_version); + } $github_ver = substr($github_version, strpos($github_version, '.')+1); $github_ver = explode(urldecode('%0A'),$github_ver)[0]; $github_ver = explode(urldecode('%0D'),$github_ver)[0]; @@ -976,7 +809,7 @@ function passhidden($path) if (getConfig('passfile') != '') { $path = spurlencode($path,'/'); if (substr($path,-1)=='/') $path=substr($path,0,-1); - $hiddenpass=gethiddenpass($path,getConfig('passfile')); + $hiddenpass=gethiddenpass($path, getConfig('passfile')); if ($hiddenpass != '') { return comppass($hiddenpass); } else { @@ -1009,86 +842,13 @@ function time_format($ISO) return date('Y-m-d H:i:s',strtotime($ISO . " UTC")); } -function get_thumbnails_url($path = '/', $location = 0) -{ - $path1 = path_format($path); - $path = path_format($_SERVER['list_path'] . path_format($path)); - if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1); - $thumb_url = getcache('thumb_'.$path, $_SERVER['disktag']); - if ($thumb_url=='') { - $url = $_SERVER['api_url']; - if ($path !== '/') { - $url .= ':' . $path; - if (substr($url,-1)=='/') $url=substr($url,0,-1); - } - $url .= ':/thumbnails/0/medium'; - $files = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true); - if (isset($files['url'])) { - savecache('thumb_'.$path, $files['url'], $_SERVER['disktag']); - $thumb_url = $files['url']; - } - } - if ($thumb_url!='') { - if ($location) { - $url = $thumb_url; - $domainforproxy = ''; - $domainforproxy = getConfig('domainforproxy'); - if ($domainforproxy!='') { - $url = proxy_replace_domain($url, $domainforproxy); - } - return output('', 302, [ 'Location' => $url ]); - } else return output($thumb_url); - } - return output('', 404); -} - -function bigfileupload($path) -{ - if (!$_SERVER['admin']) { - if (!is_guestup_path($path)) return output('Not_Guest_Upload_Folder', 400); - if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); - } - $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if (substr($path1,-1)=='/') $path1=substr($path1,0,-1); - if ($_GET['upbigfilename']!=''&&$_GET['filesize']>0) { - $tmp = splitlast($_GET['upbigfilename'], '/'); - if ($tmp[1]!='') { - $fileinfo['name'] = $tmp[1]; - $fileinfo['path'] = $tmp[0]; - } else { - $fileinfo['name'] = $_GET['upbigfilename']; - } - $fileinfo['size'] = $_GET['filesize']; - $fileinfo['lastModified'] = $_GET['lastModified']; - $filename = spurlencode($_GET['upbigfilename'],'/'); - if ($fileinfo['size']>10*1024*1024) { - $cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.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[$_SERVER['DownurlStrName']]); - $getoldupinfo = json_decode($getoldupinfo_j['body'], true); - if ( json_decode( curl_request($getoldupinfo['uploadUrl'])['body'], true)['@odata.context']!='' ) return output($getoldupinfo_j['body'], $getoldupinfo_j['stat']); - } - } - //if (!$_SERVER['admin']) $filename = spurlencode( $fileinfo['name'] ) . '.scfupload'; - $response = MSAPI('createUploadSession', path_format($path1 . '/' . $filename), '{"item": { "@microsoft.graph.conflictBehavior": "fail" }}', $_SERVER['access_token']); - if ($response['stat']<500) { - $responsearry = json_decode($response['body'],true); - if (isset($responsearry['error'])) return output($response['body'], $response['stat']); - $fileinfo['uploadUrl'] = $responsearry['uploadUrl']; - if ($fileinfo['size']>10*1024*1024) MSAPI('PUT', path_format($path1 . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $_SERVER['access_token']); - } - return output($response['body'], $response['stat']); - } - return output('error', 400); -} - function adminform($name = '', $pass = '', $path = '') { $html = '' . getconstStr('AdminLogin') . ''; if ($name!=''&&$pass!='') { - $html .= '' . getconstStr('LoginSuccess') . ''; + $html .= ' + + ' . getconstStr('LoginSuccess') . ''; $statusCode = 201; date_default_timezone_set('UTC'); $header = [ @@ -1100,26 +860,38 @@ function adminform($name = '', $pass = '', $path = '') } $statusCode = 401; $html .= ' - -
-

' . getconstStr('InputPassword') . '

-
-
- - -
-
-
-
-'; - $html .= ''; + + +
+

' . getconstStr('InputPassword') . '

+
+
+ + + +
+
+
+
+'; + $html .= ' +'; + $html .= ''; return output($html, $statusCode); } function adminoperate($path) { + global $drive; $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if (substr($path1,-1)=='/') $path1=substr($path1,0,-1); + if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1); $tmpget = $_GET; $tmppost = $_POST; $tmparr['statusCode'] = 0; @@ -1127,24 +899,19 @@ function adminoperate($path) if (isset($tmppost['rename_newname'])) $VAR = 'tmppost'; else $VAR = 'tmpget'; // rename 重命名 - $oldname = spurlencode(${$VAR}['rename_oldname']); - $oldname = path_format($path1 . '/' . $oldname); - $data = '{"name":"' . ${$VAR}['rename_newname'] . '"}'; - //echo $oldname; - $result = MSAPI('PATCH',$oldname,$data,$_SERVER['access_token']); - //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - return output($result['body'], $result['stat']); + $file['path'] = $path1; + $file['name'] = ${$VAR}['rename_oldname']; + $file['id'] = ${$VAR}['rename_fileid']; + return $drive->Rename($file, ${$VAR}['rename_newname']); } if (isset($tmpget['delete_name']) || isset($tmppost['delete_name'])) { if (isset($tmppost['delete_name'])) $VAR = 'tmppost'; else $VAR = 'tmpget'; // delete 删除 - $filename = spurlencode(${$VAR}['delete_name']); - $filename = path_format($path1 . '/' . $filename); - //echo $filename; - $result = MSAPI('DELETE', $filename, '', $_SERVER['access_token']); - //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - return output($result['body'], $result['stat']); + $file['path'] = $path1; + $file['name'] = ${$VAR}['delete_name']; + $file['id'] = ${$VAR}['delete_fileid']; + return $drive->Delete($file); } if ( (isset($tmpget['operate_action'])&&$tmpget['operate_action']==getconstStr('Encrypt')) || (isset($tmppost['operate_action'])&&$tmppost['operate_action']==getconstStr('Encrypt')) ) { if (isset($tmppost['operate_action'])) $VAR = 'tmppost'; @@ -1152,14 +919,10 @@ function adminoperate($path) // encrypt 加密 if (getConfig('passfile')=='') return message(getconstStr('SetpassfileBfEncrypt'),'',403); if (${$VAR}['encrypt_folder']=='/') ${$VAR}['encrypt_folder']==''; - $foldername = spurlencode(${$VAR}['encrypt_folder']); - $filename = path_format($path1 . '/' . $foldername . '/' . urlencode(getConfig('passfile'))); - //echo $foldername; - $result = MSAPI('PUT', $filename, ${$VAR}['encrypt_newpass'], $_SERVER['access_token']); - $path1 = path_format($path1 . '/' . $foldername ); - if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); - savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1); - return output($result['body'], $result['stat']); + $folder['path'] = path_format($path1 . '/' . spurlencode(${$VAR}['encrypt_folder'], '/')); + $folder['name'] = ${$VAR}['encrypt_folder']; + $folder['id'] = ${$VAR}['id']; + return $drive->Encrypt($folder, getConfig('passfile'), ${$VAR}['encrypt_newpass']); } if (isset($tmpget['move_folder']) || isset($tmppost['move_folder'])) { if (isset($tmppost['move_folder'])) $VAR = 'tmppost'; @@ -1169,98 +932,54 @@ function adminoperate($path) if ($path == '/' && ${$VAR}['move_folder'] == '/../') $moveable=0; if (${$VAR}['move_folder'] == ${$VAR}['move_name']) $moveable=0; if ($moveable) { - $filename = spurlencode(${$VAR}['move_name']); - $filename = path_format($path1 . '/' . $filename); + $file['path'] = $path1; + $file['name'] = ${$VAR}['move_name']; + $file['id'] = ${$VAR}['move_fileid']; if (${$VAR}['move_folder'] == '/../') { - $foldername = path_format('/' . urldecode($path1) . '/'); + $foldername = path_format('/' . urldecode($path1 . '/')); $foldername = substr($foldername, 0, -1); $foldername = splitlast($foldername, '/')[0]; } else $foldername = path_format('/' . urldecode($path1) . '/' . ${$VAR}['move_folder']); - $data = '{"parentReference":{"path": "/drive/root:'.$foldername.'"}}'; - $result = MSAPI('PATCH', $filename, $data, $_SERVER['access_token']); - //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - if (${$VAR}['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' ); - else $path2 = path_format( $path1 . '/' . ${$VAR}['move_folder'] . '/' ); - if ($path2!='/'&&substr($path2,-1)=='/') $path2=substr($path2,0,-1); - savecache('path_' . $path2, json_decode('{}',true), $_SERVER['disktag'], 1); - return output($result['body'], $result['stat']); + $folder['path'] = $foldername; + $folder['name'] = ${$VAR}['move_folder']; + $folder['id'] = ''; + return $drive->Move($file, $folder); } else { - return output('{"error":"'.getconstStr('CannotMove').'"}', 403); + return output('{"error":"' . getconstStr('CannotMove') . '"}', 403); } } if (isset($tmpget['copy_name']) || isset($tmppost['copy_name'])) { if (isset($tmppost['copy_name'])) $VAR = 'tmppost'; else $VAR = 'tmpget'; // copy 复制 - $filename = spurlencode(${$VAR}['copy_name']); - $filename = path_format($path1 . '/' . $filename); - $namearr = splitlast(${$VAR}['copy_name'], '.'); - if ($namearr[0]!='') { - $newname = $namearr[0] . ' (' . getconstStr('Copy') . ')'; - if ($namearr[1]!='') $newname .= '.' . $namearr[1]; - } else { - $newname = '.' . $namearr[1] . ' (' . getconstStr('Copy') . ')'; - } - //$newname = spurlencode($newname); - //$foldername = path_format('/'.urldecode($path1).'/./'); - //$data = '{"parentReference":{"path": "/drive/root:'.$foldername.'"}}'; - $data = '{ "name": "' . $newname . '" }'; - $result = MSAPI('copy', $filename, $data, $_SERVER['access_token']); - $num = 0; - while ($result['stat']==409 && json_decode($result['body'], true)['error']['code']=='nameAlreadyExists') { - $num++; - if ($namearr[0]!='') { - $newname = $namearr[0] . ' (' . getconstStr('Copy') . ' ' . $num . ')'; - if ($namearr[1]!='') $newname .= '.' . $namearr[1]; - } else { - $newname = '.' . $namearr[1] . ' ('.getconstStr('Copy'). ' ' . $num .')'; - } - //$newname = spurlencode($newname); - $data = '{ "name": "' . $newname . '" }'; - $result = MSAPI('copy', $filename, $data, $_SERVER['access_token']); - } - //echo $result['stat'].$result['body']; - //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - //if ($tmpget['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' ); - //else $path2 = path_format( $path1 . '/' . $tmpget['move_folder'] . '/' ); - //savecache('path_' . $path2, json_decode('{}',true), $_SERVER['disktag'], 1); - return output($result['body'], $result['stat']); + $file['path'] = $path1; + $file['name'] = ${$VAR}['copy_name']; + $file['id'] = ${$VAR}['copy_fileid']; + return $drive->Copy($file); } if (isset($tmppost['editfile'])) { // edit 编辑 - $data = $tmppost['editfile']; - /*TXT一般不会超过4M,不用二段上传 - $filename = $path1 . ':/createUploadSession'; - $response=MSAPI('POST',$filename,'{"item": { "@microsoft.graph.conflictBehavior": "replace" }}',$_SERVER['access_token']); - $uploadurl=json_decode($response,true)['uploadUrl']; - echo MSAPI('PUT',$uploadurl,$data,$_SERVER['access_token']);*/ - $result = MSAPI('PUT', $path1, $data, $_SERVER['access_token'])['body']; - //echo $result; - $resultarry = json_decode($result,true); - if (isset($resultarry['error'])) return message($resultarry['error']['message']. '
'.getconstStr('Back').'','Error',403); + $file['path'] = $path1; + $file['name'] = ''; + $file['id'] = ''; + return $drive->Edit($file, $tmppost['editfile']); } if (isset($tmpget['create_name']) || isset($tmppost['create_name'])) { if (isset($tmppost['create_name'])) $VAR = 'tmppost'; else $VAR = 'tmpget'; // create 新建 - if (${$VAR}['create_type']=='file') { - $filename = spurlencode(${$VAR}['create_name']); - $filename = path_format($path1 . '/' . $filename); - $result = MSAPI('PUT', $filename, ${$VAR}['create_text'], $_SERVER['access_token']); - } - if (${$VAR}['create_type']=='folder') { - $data = '{ "name": "' . ${$VAR}['create_name'] . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }'; - $result = MSAPI('children', $path1, $data, $_SERVER['access_token']); - } - //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); - return output($result['body'], $result['stat']); + $parent['path'] = $path1; + $parent['name'] = ''; + $parent['id'] = ${$VAR}['create_fileid']; + return $drive->Create($parent, ${$VAR}['create_type'], ${$VAR}['create_name'], ${$VAR}['create_text']); } if (isset($tmpget['RefreshCache'])) { - $path1 = path_format($_SERVER['list_path'] . path_format($path)); - if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); + //$path1 = path_format($_SERVER['list_path'] . path_format($path)); + //if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1); savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1); savecache('customTheme', '', '', 1); - return message('', getconstStr('RefreshCache'), 302); + return message(' + ', getconstStr('RefreshCache'), 202); } return $tmparr; } @@ -1299,170 +1018,6 @@ function splitlast($str, $split) return $tmp; } -function MSAPI($method, $path, $data = '', $access_token) -{ - if (substr($path,0,7) == 'http://' or substr($path,0,8) == 'https://') { - $url=$path; - $lenth=strlen($data); - $headers['Content-Length'] = $lenth; - $lenth--; - $headers['Content-Range'] = 'bytes 0-' . $lenth . '/' . $headers['Content-Length']; - } else { - $url = $_SERVER['api_url']; - if ($path=='' or $path=='/') { - $url .= '/'; - } else { - $url .= ':' . $path; - if (substr($url,-1)=='/') $url=substr($url,0,-1); - } - if ($method=='PUT') { - if ($path=='' or $path=='/') { - $url .= 'content'; - } else { - $url .= ':/content'; - } - $headers['Content-Type'] = 'text/plain'; - } elseif ($method=='PATCH') { - $headers['Content-Type'] = 'application/json'; - } elseif ($method=='POST') { - $headers['Content-Type'] = 'application/json'; - } elseif ($method=='DELETE') { - $headers['Content-Type'] = 'application/json'; - } else { - if ($path=='' or $path=='/') { - $url .= $method; - } else { - $url .= ':/' . $method; - } - $method='POST'; - $headers['Content-Type'] = 'application/json'; - } - } - $headers['Authorization'] = 'Bearer ' . $access_token; - if (!isset($headers['Accept'])) $headers['Accept'] = '*/*'; - //if (!isset($headers['Referer'])) $headers['Referer'] = $url;* - $sendHeaders = array(); - foreach ($headers as $headerName => $headerVal) { - $sendHeaders[] = $headerName . ': ' . $headerVal; - } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method); - curl_setopt($ch, CURLOPT_POSTFIELDS,$data); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders); - $response['body'] = curl_exec($ch); - $response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE); - //$response['Location'] = curl_getinfo($ch); - curl_close($ch); - error_log($response['stat'].' -'.$response['body'].' -'); - return $response; -} - -function fetch_files($path = '/') -{ - global $exts; - $path1 = path_format($path); - $path = path_format($_SERVER['list_path'] . path_format($path)); - if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1); - if (!($files = getcache('path_' . $path, $_SERVER['disktag']))) { - // https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0 - // https://docs.microsoft.com/zh-cn/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http - // https://developer.microsoft.com/zh-cn/graph/graph-explorer - $pos = splitlast($path, '/'); - $parentpath = $pos[0]; - if ($parentpath=='') $parentpath = '/'; - $filename = $pos[1]; - if ($parentfiles = getcache('path_' . $parentpath, $_SERVER['disktag'])) { - if (isset($parentfiles['children'][$filename][$_SERVER['DownurlStrName']])) { - if (in_array(splitlast($filename,'.')[1], $exts['txt'])) { - if (!(isset($parentfiles['children'][$filename]['content'])&&$parentfiles['children'][$filename]['content']['stat']==200)) { - $content1 = curl_request($parentfiles['children'][$filename][$_SERVER['DownurlStrName']]); - $parentfiles['children'][$filename]['content'] = $content1; - savecache('path_' . $parentpath, $parentfiles, $_SERVER['disktag']); - } - } - return $parentfiles['children'][$filename]; - } - } - - $url = $_SERVER['api_url']; - if ($path !== '/') { - $url .= ':' . $path; - if (substr($url,-1)=='/') $url=substr($url,0,-1); - } - $url .= '?expand=children(select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$_SERVER['DownurlStrName'].')'; - $retry = 0; - $arr = []; - while ($retry<3&&!$arr['stat']) { - $arr = curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']],1); - $retry++; - } - if ($arr['stat']<500) { - $files = json_decode($arr['body'], true); - //echo $path . '
' . json_encode($arr, JSON_PRETTY_PRINT) . '
'; - if (isset($files['folder'])) { - if ($files['folder']['childCount']>200) { - // files num > 200 , then get nextlink - $page = $_POST['pagenum']==''?1:$_POST['pagenum']; - if ($page>1) $files=fetch_files_children($files, $path1, $page); - $files['children'] = children_name($files['children']); - /*$url = $_SERVER['api_url']; - if ($path !== '/') { - $url .= ':' . $path; - if (substr($url,-1)=='/') $url=substr($url,0,-1); - $url .= ':/children?$top=9999&$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$_SERVER['DownurlStrName']; - } else { - $url .= '/children?$top=9999&$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$_SERVER['DownurlStrName']; - } - $children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true); - $files['children'] = $children['value'];*/ - } else { - // files num < 200 , then cache - //if (isset($files['children'])) { - $files['children'] = children_name($files['children']); - //} - savecache('path_' . $path, $files, $_SERVER['disktag']); - } - } - if (isset($files['file'])) { - if (in_array(splitlast($files['name'],'.')[1], $exts['txt'])) { - if (!(isset($files['content'])&&$files['content']['stat']==200)) { - $content1 = curl_request($files[$_SERVER['DownurlStrName']]); - $files['content'] = $content1; - savecache('path_' . $path, $files, $_SERVER['disktag']); - } - } - } - if (isset($files['error'])) { - $files['error']['stat'] = $arr['stat']; - } - } else { - //error_log($arr['body']); - $files = json_decode($arr['body'], true); - if (isset($files['error'])) { - $files['error']['stat'] = $arr['stat']; - } else { - $files['error']['stat'] = 503; - $files['error']['code'] = 'unknownError'; - $files['error']['message'] = 'unknownError'; - } - //$files = json_decode( '{"unknownError":{ "stat":'.$arr['stat'].',"message":"'.$arr['body'].'"}}', true); - //error_log(json_encode($files, JSON_PRETTY_PRINT)); - } - } - - return $files; -} - function children_name($children) { $tmp = []; @@ -1472,317 +1027,16 @@ function children_name($children) return $tmp; } -function fetch_files_children($files, $path, $page) -{ - $path1 = path_format($path); - $path = path_format($_SERVER['list_path'] . path_format($path)); - if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1); - $cachefilename = '.SCFcache_'.$_SERVER['function_name']; - $maxpage = ceil($files['folder']['childCount']/200); - if (!($files['children'] = getcache('files_' . $path . '_page_' . $page, $_SERVER['disktag']))) { - // down cache file get jump info. 下载cache文件获取跳页链接 - $cachefile = fetch_files(path_format($path1 . '/' .$cachefilename)); - if ($cachefile['size']>0) { - $pageinfo = curl_request($cachefile[$_SERVER['DownurlStrName']])['body']; - $pageinfo = json_decode($pageinfo,true); - for ($page4=1;$page4<$maxpage;$page4++) { - savecache('nextlink_' . $path . '_page_' . $page4, $pageinfo['nextlink_' . $path . '_page_' . $page4], $_SERVER['disktag']); - $pageinfocache['nextlink_' . $path . '_page_' . $page4] = $pageinfo['nextlink_' . $path . '_page_' . $page4]; - } - } - $pageinfochange=0; - for ($page1=$page;$page1>=1;$page1--) { - $page3=$page1-1; - $url = getcache('nextlink_' . $path . '_page_' . $page3, $_SERVER['disktag']); - if ($url == '') { - if ($page1==1) { - $url = $_SERVER['api_url']; - if ($path !== '/') { - $url .= ':' . $path; - if (substr($url,-1)=='/') $url=substr($url,0,-1); - $url .= ':/children?$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$_SERVER['DownurlStrName']; - } else { - $url .= '/children?$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$_SERVER['DownurlStrName']; - } - $children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true); - // echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; - savecache('files_' . $path . '_page_' . $page1, $children['value'], $_SERVER['disktag']); - $nextlink=getcache('nextlink_' . $path . '_page_' . $page1, $_SERVER['disktag']); - if ($nextlink!=$children['@odata.nextLink']) { - savecache('nextlink_' . $path . '_page_' . $page1, $children['@odata.nextLink'], $_SERVER['disktag']); - $pageinfocache['nextlink_' . $path . '_page_' . $page1] = $children['@odata.nextLink']; - $pageinfocache = clearbehindvalue($path,$page1,$maxpage,$pageinfocache); - $pageinfochange = 1; - } - $url = $children['@odata.nextLink']; - for ($page2=$page1+1;$page2<=$page;$page2++) { - sleep(1); - $children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true); - savecache('files_' . $path . '_page_' . $page2, $children['value'], $_SERVER['disktag']); - $nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $_SERVER['disktag']); - if ($nextlink!=$children['@odata.nextLink']) { - savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], $_SERVER['disktag']); - $pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink']; - $pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache); - $pageinfochange = 1; - } - $url = $children['@odata.nextLink']; - } - //echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; - $files['children'] = $children['value']; - $files['folder']['page']=$page; - $pageinfocache['filenum'] = $files['folder']['childCount']; - $pageinfocache['dirsize'] = $files['size']; - $pageinfocache['cachesize'] = $cachefile['size']; - $pageinfocache['size'] = $files['size']-$cachefile['size']; - if ($pageinfochange == 1) MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body']; - return $files; - } - } else { - for ($page2=$page3+1;$page2<=$page;$page2++) { - sleep(1); - $children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true); - savecache('files_' . $path . '_page_' . $page2, $children['value'], $_SERVER['disktag'], 3300); - $nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $_SERVER['disktag']); - if ($nextlink!=$children['@odata.nextLink']) { - savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], $_SERVER['disktag'], 3300); - $pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink']; - $pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache); - $pageinfochange = 1; - } - $url = $children['@odata.nextLink']; - } - //echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; - $files['children'] = $children['value']; - $files['folder']['page']=$page; - $pageinfocache['filenum'] = $files['folder']['childCount']; - $pageinfocache['dirsize'] = $files['size']; - $pageinfocache['cachesize'] = $cachefile['size']; - $pageinfocache['size'] = $files['size']-$cachefile['size']; - if ($pageinfochange == 1) MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body']; - return $files; - } - } - } else { - $files['folder']['page']=$page; - for ($page4=1;$page4<=$maxpage;$page4++) { - if (!($url = getcache('nextlink_' . $path . '_page_' . $page4, $_SERVER['disktag']))) { - if ($files['folder'][$path.'_'.$page4]!='') savecache('nextlink_' . $path . '_page_' . $page4, $files['folder'][$path.'_'.$page4], $_SERVER['disktag']); - } else { - $files['folder'][$path.'_'.$page4] = $url; - } - } - } - return $files; -} - -function get_refresh_token() -{ - global $constStr; - global $CommonEnv; - config_oauth(); - $envs = ''; - foreach ($CommonEnv as $env) $envs .= '\'' . $env . '\', '; - $url = path_format($_SERVER['PHP_SELF'] . '/'); - if (isset($_GET['install2']) && isset($_GET['code'])) { - $_SERVER['disktag'] = $_COOKIE['disktag']; - config_oauth(); - $tmp = curl_request($_SERVER['oauth_url'] . 'token', 'client_id=' . $_SERVER['client_id'] .'&client_secret=' . $_SERVER['client_secret'] . '&grant_type=authorization_code&requested_token_use=on_behalf_of&redirect_uri=' . $_SERVER['redirect_uri'] .'&code=' . $_GET['code']); - if ($tmp['stat']==200) $ret = json_decode($tmp['body'], true); - if (isset($ret['refresh_token'])) { - $refresh_token = $ret['refresh_token']; - $str = ' - refresh_token :
'; - $str .= ' -

- '.getconstStr('SavingToken').' - '; - $tmptoken['refresh_token'] = $refresh_token; - $tmptoken['token_expires'] = time()+7*24*60*60; - if (getConfig('usesharepoint')=='on') { - $tmp1 = get_siteid($ret['access_token']); - if (isset($tmp1['stat'])) return message($tmp1['body'], 'Error', $tmp1['stat']); - $tmptoken['siteid'] = $tmp1; - } - $response = setConfigResponse( setConfig($tmptoken, $_COOKIE['disktag']) ); - if (api_error($response)) { - $html = api_error_msg($response); - $title = 'Error'; - return message($html, $title, 201); - } else { - savecache('access_token', $ret['access_token'], $_SERVER['disktag'], $ret['expires_in'] - 60); - $str .= ' - '; - return message($str, getconstStr('WaitJumpIndex')); - } - } - return message('
' . json_encode(json_decode($tmp['body']), JSON_PRETTY_PRINT) . '
', $tmp['stat']); - //return message('
' . json_encode($ret, JSON_PRETTY_PRINT) . '
', 500); - } - if (isset($_GET['install1'])) { - $_SERVER['disktag'] = $_COOKIE['disktag']; - config_oauth(); - if (getConfig('Drive_ver')=='MS' || getConfig('Drive_ver')=='CN') { - return message(' - '.getconstStr('JumptoOffice').' - - ', getconstStr('Wait').' 1s', 201); - } else { - return message('Something error, retry after a few seconds.', 'retry', 201); - } - } - if (isset($_GET['install0'])) { - if ($_POST['disktag_add']!='') { - if (in_array($_COOKIE['disktag'], $CommonEnv)) { - return message('Do not input ' . $envs . '
', 'Error', 201); - } - $_SERVER['disktag'] = $_COOKIE['disktag']; - $tmp['disktag_add'] = $_POST['disktag_add']; - $tmp['diskname'] = $_POST['diskname']; - $tmp['Drive_ver'] = $_POST['Drive_ver']; - if ($_POST['Drive_ver']=='shareurl') { - $tmp['shareurl'] = $_POST['shareurl']; - $tmp['refresh_token'] = 1; - } else { - if ($_POST['Drive_custom']=='on') { - $tmp['Drive_custom'] = $_POST['Drive_custom']; - $tmp['client_id'] = $_POST['client_id']; - $tmp['client_secret'] = $_POST['client_secret']; - } else { - $tmp['Drive_custom'] = ''; - $tmp['client_id'] = ''; - $tmp['client_secret'] = ''; - } - if ($_POST['usesharepoint']=='on') { - $tmp['usesharepoint'] = $_POST['usesharepoint']; - $tmp['sharepointSiteAddress'] = $_POST['sharepointSiteAddress']; - } else { - $tmp['usesharepoint'] = ''; - $tmp['sharepointSiteAddress'] = ''; - } - } - $response = setConfigResponse( setConfig($tmp, $_COOKIE['disktag']) ); - if (api_error($response)) { - $html = api_error_msg($response); - $title = 'Error'; - } else { - $title = getconstStr('MayinEnv'); - $html = getconstStr('Wait') . ' 3s'; - if ($_POST['Drive_ver']=='shareurl') $html = getconstStr('Wait') . ' 3s'; - } - return message($html, $title, 201); - } - } - - //if ($constStr['language']!='zh-cn') { - // $linklang='en-us'; - //} else $linklang='zh-cn'; - //$ru = "https://developer.microsoft.com/".$linklang."/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl=".$_SERVER['redirect_uri']."&platform=option-php"; - //$deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=OneManager&redirectUrl=".$_SERVER['redirect_uri']."&allowImplicitFlow=false&ru=".urlencode($ru); - //$app_url = "https://apps.dev.microsoft.com/?deepLink=".urlencode($deepLink); - $html = ' -
-
- '.getconstStr('OnedriveDiskTag').': ('.getConfig('disktag').')
- '.getconstStr('OnedriveDiskName').':
-
-
-
-
-
-
-
- - -
- -
-
- '; - $title = 'Bind Disk'; - return message($html, $title, 201); -} - function EnvOpt($needUpdate = 0) { global $constStr; - global $CommonEnv; - global $ShowedCommonEnv; - global $ShowedInnerEnv; + global $EnvConfigs; global $timezones; - asort($ShowedCommonEnv); - asort($ShowedInnerEnv); + global $slash; + global $drive; + ksort($EnvConfigs); $envs = ''; - foreach ($CommonEnv as $env) $envs .= '\'' . $env . '\', '; + foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', '; $html = 'OneManager '.getconstStr('Setup').''; if (isset($_POST['updateProgram'])&&$_POST['updateProgram']==getconstStr('updateProgram')) { @@ -1801,14 +1055,15 @@ function EnvOpt($needUpdate = 0) if (isset($_POST['submit1'])) { $_SERVER['disk_oprating'] = ''; foreach ($_POST as $k => $v) { - if (in_array($k, $ShowedCommonEnv) || in_array($k, $ShowedInnerEnv) || $k=='disktag_del' || $k=='disktag_add' || $k=='disktag_rename') { + if (isShowedEnv($k) || $k=='disktag_del' || $k=='disktag_add' || $k=='disktag_rename') { $tmp[$k] = $v; } if ($k=='disktag_newname') { $v = preg_replace('/[^0-9a-zA-Z|_]/i', '', $v); $f = substr($v, 0, 1); if (strlen($v)==1) $v .= '_'; - if (in_array($v, $CommonEnv)) { + //if (in_array($v, $CommonEnv)) { + if (isCommonEnv($v)) { return message('Do not input ' . $envs . '
', 'Error', 201); } elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) { return message('Please start with letters'); @@ -1858,7 +1113,7 @@ function EnvOpt($needUpdate = 0) '.getconstStr('PlatformConfig').' '; - foreach ($ShowedCommonEnv as $key) { + foreach ($EnvConfigs as $key => $val) if (isCommonEnv($key) && isShowedEnv($key)) { if ($key=='timezone') { $html .= ' @@ -1875,8 +1130,6 @@ function EnvOpt($needUpdate = 0) '; } elseif ($key=='theme') { - $slash = '/'; - if (strpos(__DIR__, ':')) $slash = '\\'; $theme_arr = scandir(__DIR__ . $slash . 'theme'); $html .= ' @@ -1995,27 +1248,39 @@ function EnvOpt($needUpdate = 0) if ($disktag!='') { $html .= ' - - - - + + + + + + + + '; - if (getConfig('refresh_token', $disktag)!='') { + $tmp = getConfig('shareurl', $disktag); + if ($tmp!='') $html .= ''; + $tmp = getConfig('siteid', $disktag); + if ($tmp!='') { + $html .= ''; + $html .= ''; + } + + if (driveisfine($disktag)) { $html .= ' '; - foreach ($ShowedInnerEnv as $key) { + foreach ($EnvConfigs as $key => $val) if (isInnerEnv($key) && isShowedEnv($key)) { $html .= ' @@ -2035,8 +1300,26 @@ function EnvOpt($needUpdate = 0)
-
- - -
-
-
- - - -
-
+
+ + +
+
+
+ + + +
+
Driver' . getConfig('Driver', $disktag) . '
shareurl' . $tmp . '
Site' . getConfig('sharepointSite', $disktag) . '
siteid' . $tmp . '

'; } } + $Diver_arr = scandir(__DIR__ . $slash . 'disk'); $html .= ' -'.getconstStr('AddDisk').'

'; + +' . getconstStr('AddDisk') . ' + +

'; $canOneKeyUpate = 0; if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { @@ -2073,7 +1356,7 @@ function EnvOpt($needUpdate = 0) '; + $tmp = splitfirst($html, ''); + $html = $tmp[0] . $selecttheme . '' . $selectthemescript . $tmp[1]; } - $html = $authinfo . $html; + $tmp = splitfirst($html, ''); + $html = $tmp[0] . '' . $authinfo . $tmp[1]; if (isset($_SERVER['Set-Cookie'])) return output($html, $statusCode, [ 'Set-Cookie' => $_SERVER['Set-Cookie'], 'Content-Type' => 'text/html' ]); - return output($html,$statusCode); + return output($html, $statusCode); } diff --git a/conststr.php b/conststr.php index a8726ef..b09a275 100644 --- a/conststr.php +++ b/conststr.php @@ -335,12 +335,12 @@ $constStr = [ 'zh-tw' => '修改標籤', ], 'AddDisk' => [ - 'en-us' => 'Add Onedrive Disk', - 'zh-cn' => '添加Onedrive盘', - 'zh-tw' => '新增Onedrive盤', - 'ja' => 'Onedriveを追加', - 'ko-kr' => 'Onedrive 추가', - 'fa' => 'اضافه کردن دیسک Onedrive', + 'en-us' => 'Add Disk', + 'zh-cn' => '添加盘', + 'zh-tw' => '新增盤', + 'ja' => 'を追加', + 'ko-kr' => '추가', + 'fa' => 'اضافه کردن دیسک ', ], 'Home' => [ 'en-us' => 'Home', @@ -788,21 +788,21 @@ $constStr = [ 'ko-kr' => '사무실로 이동하여 로그인하여 refresh_token을 받으십시오.', 'fa' => 'وارد Office شوید و یک refresh_token دریافت کنید', ], - 'OnedriveDiskTag' => [ - 'en-us' => 'Onedrive Disk Tag', - 'zh-cn' => 'Onedrive 标签', - 'zh-tw' => 'Onedrive 標籤', - 'ja' => 'Onedriveタグ', - 'ko-kr' => 'Onedrive 태그', - 'fa' => 'برچسب دیسک Onedrive', + 'DiskTag' => [ + 'en-us' => 'Disk Tag', + 'zh-cn' => '标签', + 'zh-tw' => '標籤', + 'ja' => 'タグ', + 'ko-kr' => '태그', + 'fa' => 'برچسب دیسک ', ], - 'OnedriveDiskName' => [ - 'en-us' => 'Onedrive Showed Name', - 'zh-cn' => 'Onedrive 显示名称', - 'zh-tw' => 'Onedrive 顯示名稱', - 'ja' => 'Onedrive表示名', - 'ko-kr' => 'Onedrive 표시 이름', - 'fa' => 'نام نشان داده شده Onedrive', + 'DiskName' => [ + 'en-us' => 'Showed Name', + 'zh-cn' => '显示名称', + 'zh-tw' => '顯示名稱', + 'ja' => '表示名', + 'ko-kr' => '표시 이름', + 'fa' => 'نام نشان داده شده ', ], 'DriveVerMS' => [ 'en-us' => 'Onedrive, Onedrive for business', @@ -824,13 +824,13 @@ $constStr = [ ], 'UseShareLink' => [ 'en-us' => 'Share a folder in Onedrive (enable EDIT for everyone), input the link url below.', - 'zh-cn' => '对一个Onedrive文件夹共享,允许所有人编辑,然后将共享链接填在下方', + 'zh-cn' => '只有国际版能用,对一个Onedrive文件夹共享,允许所有人编辑,然后将共享链接填在下方', 'zh-tw' => '對一個Onedrive資料夾共享,允許所有人編輯,然後將共享連結填在下方', ], 'CustomIdSecret' => [ 'en-us' => 'Use custom client id & secret instead of OneManager default', - 'zh-cn' => '自己申请应用ID与机密,不用OneManager默认的', - 'zh-tw' => '自己申請應用ID與機密,不用OneManager預設的', + 'zh-cn' => '用自己申请的应用ID与机密,不用OneManager默认的', + 'zh-tw' => '用自己申請的應用ID與機密,不用OneManager預設的', 'ja' => 'アプリケーションIDとシークレットを自分で申請する', 'ko-kr' => '응용 프로그램 ID 및 비밀 신청', 'fa' => 'به طور پیش فرض اما از شناسه برنامه و سکرت استفاده کنید', diff --git a/disk/Aliyundrive.php b/disk/Aliyundrive.php new file mode 100644 index 0000000..e491bed --- /dev/null +++ b/disk/Aliyundrive.php @@ -0,0 +1,715 @@ +disktag = $tag; + $this->auth_url = 'https://websv.aliyundrive.com/token/refresh'; + $this->api_url = 'https://api.aliyundrive.com/v2'; + $this->access_token = $this->get_access_token(getConfig('refresh_token', $tag)); + $this->default_drive_id = getConfig('default_drive_id', $tag); + } + + public function isfine() + { + if (!$this->access_token) return false; + else return true; + } + public function show_base_class() + { + return get_class(); + //$tmp[0] = get_class(); + //$tmp[1] = get_class($this); + //return $tmp; + } + + public function list_files($path = '/') + { + + + + $files = $this->list_path($path); + + + + return $this->files_format($files); + } + + protected function files_format($files) + { + //return $files; + if ($files['type']=='file') { + $tmp['type'] = 'file'; + $tmp['id'] = $files['file_id']; + if (isset($files['name'])) $tmp['name'] = $files['name']; + elseif (isset($files['file_name'])) $tmp['name'] = $files['file_name']; + $tmp['time'] = $files['updated_at']; + $tmp['size'] = $files['size']; + $tmp['mime'] = $files['file']['mimeType']; + $tmp['url'] = $files['download_url']; + $tmp['content'] = $files['content']; + if (isset($files['exist'])) $tmp['exist'] = $files['exist']; + if (isset($files['rapid_upload'])) $tmp['rapid_upload'] = $files['rapid_upload']; + } elseif ($files['type']=='folder'||isset($files['items'])) { + $tmp['type'] = 'folder'; + $tmp['id'] = $files['file_id']; + if (isset($files['name'])) $tmp['name'] = $files['name']; + elseif (isset($files['file_name'])) $tmp['name'] = $files['file_name']; + $tmp['time'] = $files['updated_at']; + $tmp['size'] = $files['size']; + //$tmp['page'] = $files['folder']['page']; + foreach ($files['items'] as $file) { + if ($file['type']=='file') { + $tmp['list'][$file['name']]['type'] = 'file'; + $tmp['list'][$file['name']]['url'] = $file['download_url']; + $tmp['list'][$file['name']]['mime'] = $file['file']['content_type']; + } elseif ($file['type']=='folder') { + $tmp['list'][$file['name']]['type'] = 'folder'; + } + //$tmp['id'] = $file['parent_file_id']; + $tmp['list'][$file['name']]['id'] = $file['file_id']; + $tmp['list'][$file['name']]['name'] = $file['name']; + $tmp['list'][$file['name']]['time'] = $file['updated_at']; + $tmp['list'][$file['name']]['size'] = $file['size']; + $tmp['childcount']++; + } + } elseif (isset($files['code'])) { + return $files; + } + //error_log(json_encode($tmp)); + return $tmp; + } + + protected function list_path($path = '/') + { + global $exts; + while (substr($path, -1)=='/') $path = substr($path, 0, -1); + //$files = getcache('path_' . $path, $this->disktag); + //if (!$files) { + //if (!($files = getcache('path_' . $path, $this->disktag))) { + if ($path == '/' || $path == '') { + $files = $this->fileList('root'); + //error_log('root_id' . $files['id']); + $files['file_id'] = 'root'; + $files['type'] = 'folder'; + } else { + $tmp = splitlast($path, '/'); + $parent_path = $tmp[0]; + $filename = urldecode($tmp[1]); + $parent_folder = $this->list_path($parent_path); + foreach ($parent_folder['items'] as $item) { + if ($item['name']==$filename) { + if ($item['type']=='folder') { + $files = $this->fileList($item['file_id']); + $files['type'] = 'folder'; + $files['file_id'] = $item['file_id']; + $files['name'] = $item['name']; + $files['time'] = $item['updated_at']; + $files['size'] = $item['size']; + } else $files = $item; + + } + + } + //echo $files['name']; + } + if ($files['type']=='file') { + if (in_array(splitlast($files['name'],'.')[1], $exts['txt'])) { + if (!(isset($files['content'])&&$files['content']['stat']==200)) { + $content1 = curl('GET', $files['download_url']); + $files['content'] = $content1; + savecache('path_' . $path, $files, $this->disktag); + } + } + } + if (!$files) { + $files['error']['code'] = 'Not Found'; + $files['error']['message'] = 'Not Found'; + $files['error']['stat'] = 404; + } elseif (isset($files['stat'])) { + $tmp['error']['stat'] = $files['stat']; + $files['error']['code'] = 'Error'; + $files['error']['message'] = $files['body']; + } else { + savecache('path_' . $path, $files, $this->disktag, 600); + } + //} + //error_log('path:' . $path . ', files:' . json_encode($files)); + return $files; + } + + protected function fileGet($file_id) + { + $url = $this->api_url . '/file/get'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['drive_id'] = $this->default_drive_id; + $data['file_id'] = $file_id; + + $res = curl('POST', $url, json_encode($data), $header); + if ($res['stat']==200) return json_decode($res['body'], true); + else return $res; + } + protected function fileList($parent_file_id) + { + $url = $this->api_url . '/file/list'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['limit'] = 50; + $data['marker'] = NULL; + $data['drive_id'] = $this->default_drive_id; + $data['parent_file_id'] = $parent_file_id; + $data['image_thumbnail_process'] = 'image/resize,w_160/format,jpeg'; + $data['image_url_process'] = 'image/resize,w_1920/format,jpeg'; + $data['video_thumbnail_process'] = 'video/snapshot,t_0,f_jpg,w_300'; + $data['fields'] = '*'; + $data['order_by'] = 'updated_at'; + $data['order_direction'] = 'DESC'; + + $res = curl('POST', $url, json_encode($data), $header); + if ($res['stat']==200) return json_decode($res['body'], true); + else return $res; + } + + public function Rename($file, $newname) { + $url = $this->api_url . '/file/update'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['check_name_mode'] = 'refuse'; + $data['drive_id'] = $this->default_drive_id; + $data['file_id'] = $file['id']; + $data['name'] = $newname; + //$data['parent_file_id'] = 'root'; + + $result = curl('POST', $url, json_encode($data), $header); + //savecache('path_' . $file['path'], json_decode('{}',true), $this->disktag, 1); + //error_log('decode:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + //return output($result['body'], $result['stat']); + } + public function Delete($file) { + $url = $this->api_url . '/batch'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['resource'] = 'file'; + $data['requests'][0]['url'] = '/file/delete'; + $data['requests'][0]['method'] = 'DELETE'; + $data['requests'][0]['id'] = $file['id']; + $data['requests'][0]['headers']['Content-Type'] = 'application/json'; + $data['requests'][0]['body']['drive_id'] = $this->default_drive_id; + $data['requests'][0]['body']['file_id'] = $file['id']; + + $result = curl('POST', $url, json_encode($data), $header); + //savecache('path_' . $file['path'], json_decode('{}',true), $this->disktag, 1); + //error_log('result:' . json_encode($result)); + //return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + $res = json_decode($result['body'], true)['responses'][0]; + if (isset($res['status'])) return output($res['id'], $res['status']); + else return output($result['body'], $result['stat']); + } + public function Encrypt($folder, $passfilename, $pass) { + $existfile = $this->list_path($folder['path'] . '/' . $passfilename); + if (isset($existfile['type'])) { // 删掉原文件 + $this->Delete(['id'=>$existfile['file_id']]); + } + if (!$folder['id']) { + $res = $this->list_path($folder['path']); + //error_log('res:' . json_encode($res)); + $folder['id'] = $res['file_id']; + } + $tmp = '/tmp/' . $passfilename; + file_put_contents($tmp, $pass); + + $result = $this->tmpfileCreate($folder['id'], $tmp, $passfilename); + + if ($result['stat']==201) { + //error_log('1,url:' . $url .' res:' . json_encode($result)); + $res = json_decode($result['body'], true); + $url = $res['part_info_list'][0]['upload_url']; + if (!$url) { // 无url,应该算秒传 + return output('no up url', 200); + } + $file_id = $res['file_id']; + $upload_id = $res['upload_id']; + $result = curl('PUT', $url, $pass, [], 1); + if ($result['stat']==200) { // 块1传好 + $tmp1['part_number'] = 1; + $tmp1['etag'] = $result['returnhead']['ETag']; + $result = $this->fileComplete($file_id, $upload_id, [ $tmp1 ]); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + } + //error_log('2,url:' . $url .' res:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + public function Move($file, $folder) { + if (!$folder['id']) { + $res = $this->list_path($folder['path']); + //error_log('res:' . json_encode($res)); + $folder['id'] = $res['file_id']; + } + + $url = $this->api_url . '/batch'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['resource'] = 'file'; + $data['requests'][0]['url'] = '/file/move'; + $data['requests'][0]['method'] = 'POST'; + $data['requests'][0]['id'] = $file['id']; + $data['requests'][0]['headers']['Content-Type'] = 'application/json'; + $data['requests'][0]['body']['drive_id'] = $this->default_drive_id; + $data['requests'][0]['body']['file_id'] = $file['id']; + $data['requests'][0]['body']['auto_rename'] = true; + $data['requests'][0]['body']['to_parent_file_id'] = $folder['id']; + + $result = curl('POST', $url, json_encode($data), $header); + //savecache('path_' . $file['path'], json_decode('{}',true), $this->disktag, 1); + //error_log('result:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + public function Copy($file) { + if (!$file['id']) { + $oldfile = $this->list_path($file['path'] . '/' . $file['name']); + //error_log('res:' . json_encode($res)); + //$file['id'] = $res['file_id']; + } else { + $oldfile = $this->fileGet($file['id']); + } + + $url = $this->api_url . '/file/create'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['check_name_mode'] = 'auto_rename'; // ignore, auto_rename, refuse. + $data['content_hash'] = $oldfile['content_hash']; + $data['content_hash_name'] = 'sha1'; + $data['content_type'] = $oldfile['content_type']; + $data['drive_id'] = $this->default_drive_id; + $data['ignoreError'] = false; + $data['name'] = $oldfile['name']; + $data['parent_file_id'] = $oldfile['parent_file_id']; + $data['part_info_list'][0]['part_number'] = 1; + $data['size'] = $oldfile['size']; + $data['type'] = 'file'; + + $result = curl('POST', $url, json_encode($data), $header); + + if ($result['stat']==201) { + //error_log('1,url:' . $url .' res:' . json_encode($result)); + $res = json_decode($result['body'], true); + $url = $res['part_info_list'][0]['upload_url']; + if (!$url) { // 无url,应该算秒传 + return output('no up url', 200); + } else { + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + /*$file_id = $res['file_id']; + $upload_id = $res['upload_id']; + $result = curl('PUT', $url, $content, [], 1); + if ($result['stat']==200) { // 块1传好 + $etag = $result['returnhead']['ETag']; + $result = $this->fileComplete($file_id, $upload_id, $etag); + if ($result['stat']!=200) return output($result['body'], $result['stat']); + else return output('success', 0); + }*/ + } + //error_log('2,url:' . $url .' res:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + public function Edit($file, $content) { + $tmp = splitlast($file['path'], '/'); + $folderpath = $tmp[0]; + $filename = $tmp[1]; + $existfile = $this->list_path($file['path']); + if (isset($existfile['type'])) { // 删掉原文件 + $this->Delete(['id'=>$existfile['file_id']]); + } + $tmp1 = '/tmp/' . $filename; + file_put_contents($tmp1, $content); + + $result = $this->tmpfileCreate($this->list_path($folderpath)['file_id'], $tmp1, $filename); + + if ($result['stat']==201) { + //error_log('1,url:' . $url .' res:' . json_encode($result)); + $res = json_decode($result['body'], true); + $url = $res['part_info_list'][0]['upload_url']; + if (!$url) { // 无url,应该算秒传 + return output('no up url', 0); + } + $file_id = $res['file_id']; + $upload_id = $res['upload_id']; + $result = curl('PUT', $url, $content, [], 1); + if ($result['stat']==200) { // 块1传好 + $tmp2['part_number'] = 1; + $tmp2['etag'] = $result['returnhead']['ETag']; + $result = $this->fileComplete($file_id, $upload_id, [ $tmp2 ]); + if ($result['stat']!=200) return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + else return output('success', 0); + } + } + //error_log('2,url:' . $url .' res:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + public function Create($folder, $type, $name, $content = '') { + if (!$folder['id']) { + $res = $this->list_path($folder['path']); + //error_log('res:' . json_encode($res)); + $folder['id'] = $res['file_id']; + } + if ($type=='folder') { + $result = $this->folderCreate($folder['id'], $name); + //error_log('res:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + if ($type=='file') { + $tmp = '/tmp/' . $name; + file_put_contents($tmp, $content); + + $result = $this->tmpfileCreate($folder['id'], $tmp, $name); + + if ($result['stat']==201) { + //error_log('1,url:' . $url .' res:' . json_encode($result)); + $res = json_decode($result['body'], true); + if (isset($res['exist'])&&$res['exist']!=false) { + // 已经有 + //error_log('exist:' . json_encode($res)); + return output('{"type":"file","name":"' . $name . '", "exist":true}', 200); + } + if (isset($res['rapid_upload'])&&$res['rapid_upload']!=false) { + // 秒传 + //error_log('rapid up:' . json_encode($res)); + return output('{"type":"file","name":"' . $name . '", "rapid_upload":true}', 200); + } + $url = $res['part_info_list'][0]['upload_url']; + $file_id = $res['file_id']; + $upload_id = $res['upload_id']; + $result = curl('PUT', $url, $content, [], 1); + //error_log('2,url:' . $url .' res:' . json_encode($result)); + if ($result['stat']==200) { // 块1传好 + $tmp1['part_number'] = 1; + $tmp1['etag'] = $result['returnhead']['ETag']; + $result = $this->fileComplete($file_id, $upload_id, [ $tmp1 ]); + //error_log('3,url:' . $url .' res:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + } + //error_log('4,url:' . $url .' res:' . json_encode($result)); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + return output('Type not folder or file.', 500); + } + + protected function folderCreate($parentId, $folderName) { + if (strrpos($folderName, '/')) { + $tmp = splitlast($folderName, '/'); + $parentId = json_decode($this->folderCreate($parentId, $tmp[0])['body'], true)['file_id']; + $folderName = $tmp[1]; + } + $url = $this->api_url . '/file/create'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse. + $data['drive_id'] = $this->default_drive_id; + $data['name'] = $folderName; + $data['parent_file_id'] = $parentId; + $data['type'] = 'folder'; + + return curl('POST', $url, json_encode($data), $header); + } + protected function fileCreate($parentId, $fileName, $sha1, $size) { + $url = $this->api_url . '/file/create'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse. + $data['content_hash'] = $sha1; + $data['content_hash_name'] = 'sha1'; + $data['content_type'] = ''; + $data['drive_id'] = $this->default_drive_id; + $data['ignoreError'] = false; + $data['name'] = $fileName; + $data['parent_file_id'] = $parentId; + $data['part_info_list'][0]['part_number'] = 1; + $data['size'] = (int)$size; + $data['type'] = 'file'; + + return curl('POST', $url, json_encode($data), $header); + } + protected function tmpfileCreate($parentId, $tmpFilePath, $tofileName = '') { + $sha1 = sha1_file($tmpFilePath); + if ($tofileName == '') $tofileName = splitlast($tmpFilePath, '/')[1]; + $url = $this->api_url . '/file/create'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse. + $data['content_hash'] = $sha1; + $data['content_hash_name'] = 'sha1'; + $data['content_type'] = 'text/plain'; // now only txt + $data['drive_id'] = $this->default_drive_id; + $data['ignoreError'] = false; + $data['name'] = $tofileName; + $data['parent_file_id'] = $parentId; + $data['part_info_list'][0]['part_number'] = 1; // now only txt + $data['size'] = filesize($tmpFilePath); + $data['type'] = 'file'; + + return curl('POST', $url, json_encode($data), $header); + } + protected function fileComplete($file_id, $upload_id, $etags) { + $url = $this->api_url . '/file/complete'; + + $header["content-type"] = "application/json; charset=utf-8"; + $header['authorization'] = 'Bearer ' . $this->access_token; + + $data['drive_id'] = $this->default_drive_id; + $data['file_id'] = $file_id; + $data['ignoreError'] = false; + foreach ($etags as $etag) { + $data['part_info_list'][$etag['part_number'] - 1]['part_number'] = $etag['part_number']; + $data['part_info_list'][$etag['part_number'] - 1]['etag'] = $etag['etag']; + } + $data['upload_id'] = $upload_id; + + return curl('POST', $url, json_encode($data), $header); + } + + public function get_thumbnails_url($path = '/') + { + $res = $this->list_path($path); + $thumb_url = $res['thumbnail']; + return $thumb_url; + } + public function bigfileupload($path) + { + if (isset($_POST['uploadid'])) { + // Complete + $result = $this->fileComplete($_POST['fileid'], $_POST['uploadid'], $_POST['etag']); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } else { + if ($_POST['upbigfilename']=='') return output('error: no file name', 400); + if (!is_numeric($_POST['filesize'])) return output('error: no file size', 400); + if (!isset($_POST['filesha1'])) return output('error: no file sha1', 400); + + $tmp = splitlast($_POST['upbigfilename'], '/'); + if ($tmp[1]!='') { + $fileinfo['name'] = $tmp[1]; + if ($_SERVER['admin']) $fileinfo['path'] = $tmp[0]; + } else { + $fileinfo['name'] = $_POST['upbigfilename']; + } + $fileinfo['size'] = $_POST['filesize']; + $fileinfo['filelastModified'] = $_POST['filelastModified']; + if ($_SERVER['admin']) { + $filename = $fileinfo['name']; + } else { + $tmp1 = splitlast($fileinfo['name'], '.'); + if ($tmp1[0]==''||$tmp1[1]=='') $filename = $_POST['filesha1']; + else $filename = $_POST['filesha1'] . '.' . $tmp1[1]; + } + /*if ($fileinfo['size']>10*1024*1024) { + $cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['filelastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.tmp', '/'); + $getoldupinfo=$this->list_path(path_format($path . '/' . $cachefilename)); + //echo json_encode($getoldupinfo, JSON_PRETTY_PRINT); + if ($getoldupinfo['type']=='file'&&$getoldupinfo['size']<5120) { + $getoldupinfo_j = curl('GET', $getoldupinfo['url']); + $getoldupinfo = json_decode($getoldupinfo_j['body'], true); + //if ( json_decode( curl('GET', $getoldupinfo['uploadUrl'])['body'], true)['@odata.context']!='' ) return output($getoldupinfo_j['body'], $getoldupinfo_j['stat']); + } + }*/ + $parent = $this->list_path($path . '/' . $fileinfo['path']); + if (isset($parent['file_id'])) { + $parent_file_id = $parent['file_id']; + } else { + $res = $this->folderCreate($this->list_path($path)['file_id'], $fileinfo['path']); + //error_log($res['body']); + $parent_file_id = json_decode($res['body'], true)['file_id']; + } + $response = $this->fileCreate($parent_file_id, $filename, $_POST['filesha1'], $fileinfo['size']); + $res = json_decode($response['body'], true); + if (isset($res['exist'])) { + // 已经有 + //error_log('exist:' . json_encode($res)); + return output(json_encode($this->files_format(json_decode($response['body'], true))), $response['stat']); + //return output('{"type":"file","name":"' . $_POST['upbigfilename'] . '", "exist":true}', 200); + } + if (isset($res['rapid_upload'])&&$res['rapid_upload']!=false) { + // 秒传 + //error_log('rapid up:' . json_encode($res)); + return output(json_encode($this->files_format(json_decode($response['body'], true))), $response['stat']); + //return output('{"type":"file","name":"' . $_POST['upbigfilename'] . '", "rapid upload":true}', 200); + } + //if ($response['stat']<500) { + // $responsearry = json_decode($response['body'], true); + // if (isset($responsearry['error'])) return output($response['body'], $response['stat']); + // $fileinfo['uploadUrl'] = $responsearry['uploadUrl']; + // if ($fileinfo['size']>10*1024*1024) $this->MSAPI('PUT', path_format($path . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $this->access_token); + //} + return output($response['body'], $response['stat']); + } + } + + public function AddDisk() { + global $constStr; + global $EnvConfigs; + + $envs = ''; + foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', '; + $url = path_format($_SERVER['PHP_SELF'] . '/'); + + if (isset($_GET['install0']) && $_POST['disktag_add']!='') { + $_POST['disktag_add'] = preg_replace('/[^0-9a-zA-Z|_]/i', '', $_POST['disktag_add']); + $f = substr($_POST['disktag_add'], 0, 1); + if (strlen($_POST['disktag_add'])==1) $_POST['disktag_add'] .= '_'; + if (isCommonEnv($_POST['disktag_add'])) { + return message('Do not input ' . $envs . '
+ ', 'Error', 201); + } elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) { + return message('Please start with letters
+ ', 'Error', 201); + } + $tmp['refresh_token'] = $_POST['refresh_token']; + $res = curl('POST', $this->auth_url, json_encode($tmp), ["content-type"=>"application/json; charset=utf-8"]); + //return output($res['body']); + if ($res['stat']!=200) { + return message($res['body'], $res['stat'], $res['stat']); + } + //var_dump($res['body']); + $result = json_decode($res['body'], true); + + $tmp = null; + foreach ($EnvConfigs as $env => $v) if (isInnerEnv($env)) $tmp[$env] = ''; + + $tmp['refresh_token'] = $result['refresh_token']; + $tmp['default_drive_id'] = $result['default_drive_id']; + $tmp['default_sbox_drive_id'] = $result['default_sbox_drive_id']; + $tmp['token_expires'] = time()+7*24*60*60; + $tmp['Driver'] = 'Aliyundrive'; + $tmp['disktag_add'] = $_POST['disktag_add']; + $tmp['diskname'] = $_POST['diskname']; + + $response = setConfigResponse( setConfig($tmp, $this->disktag) ); + if (api_error($response)) { + $html = api_error_msg($response); + $title = 'Error'; + return message($html, $title, 201); + } else { + savecache('access_token', $result['access_token'], $this->disktag, $result['expires_in'] - 60); + $str .= ' + '; + return message($str, getconstStr('WaitJumpIndex'), 201); + } + + /*$api = $this->api_url . '/user/get'; + $header['authorization'] = 'Bearer ' . $this->access_token; + return json_encode(curl('GET', $api, '', $header));*/ + } + + $html = ' +
+ + ' . getconstStr('DiskTag') . ': (' . getConfig('disktag') . ') +
+ ' . getconstStr('DiskName') . ': +
+
+
填入refresh_token: +
+
+
+ + + +
+ '; + $title = 'Select Account Type'; + return message($html, $title, 201); + } + protected function get_access_token($refresh_token) { + if (!($this->access_token = getcache('access_token', $this->disktag))) { + $p=0; + $tmp1['refresh_token'] = $refresh_token; + while ($response['stat']==0&&$p<3) { + $response = curl('POST', $this->auth_url, json_encode($tmp1), ["content-type"=>"application/json; charset=utf-8"]); + $p++; + } + error_log(json_encode($response)); + if ($response['stat']==200) $ret = json_decode($response['body'], true); + if (!isset($ret['access_token'])) { + error_log('failed to get [' . $this->disktag . '] access_token. response' . json_encode($ret)); + $response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT); + $response['body'] .= '\nfailed to get [' . $this->disktag . '] access_token.'; + return $response; + } + $tmp = $ret; + $tmp['access_token'] = '******'; + $tmp['refresh_token'] = '******'; + error_log('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT)); + $this->access_token = $ret['access_token']; + savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300); + if (time()>getConfig('token_expires', $this->disktag)) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ], $this->disktag); + } + return $this->access_token; + } +} \ No newline at end of file diff --git a/disk/Onedrive.php b/disk/Onedrive.php new file mode 100644 index 0000000..e793a20 --- /dev/null +++ b/disk/Onedrive.php @@ -0,0 +1,915 @@ +disktag = $tag; + $this->redirect_uri = 'https://scfonedrive.github.io'; + if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) { + $this->client_id = getConfig('client_id', $tag); + $this->client_secret = getConfig('client_secret', $tag); + } else { + $this->client_id = '734ef928-d74c-4555-8d1b-d942fa0a1a41'; + $this->client_secret = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW'; + } + $this->oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/'; + $this->api_url = 'https://graph.microsoft.com/v1.0'; + $this->scope = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access'; + $this->access_token = $this->get_access_token(getConfig('refresh_token', $tag)); + + $this->client_secret = urlencode($this->client_secret); + $this->scope = urlencode($this->scope); + $this->DownurlStrName = '@microsoft.graph.downloadUrl'; + $this->ext_api_url = '/me/drive/root'; + } + + public function isfine() + { + if (!$this->access_token) return false; + else return true; + } + public function show_base_class() + { + return get_class(); + //$tmp[0] = get_class(); + //$tmp[1] = get_class($this); + //return $tmp; + } + + public function list_files($path = '/') + { + global $exts; + if (!($files = getcache('path_' . $path, $this->disktag))) { + // https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0 + // https://docs.microsoft.com/zh-cn/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http + // https://developer.microsoft.com/zh-cn/graph/graph-explorer + $pos = splitlast($path, '/'); + $parentpath = $pos[0]; + if ($parentpath=='') $parentpath = '/'; + $filename = $pos[1]; + if ($parentfiles = getcache('path_' . $parentpath, $this->disktag)) { + if (isset($parentfiles['children'][$filename][$this->DownurlStrName])) { + if (in_array(splitlast($filename,'.')[1], $exts['txt'])) { + if (!(isset($parentfiles['children'][$filename]['content'])&&$parentfiles['children'][$filename]['content']['stat']==200)) { + $content1 = curl('GET', $parentfiles['children'][$filename][$this->DownurlStrName]); + $parentfiles['children'][$filename]['content'] = $content1; + savecache('path_' . $parentpath, $parentfiles, $this->disktag); + } + } + return $this->files_format($parentfiles['children'][$filename]); + } + } + + $url = $this->api_url . $this->ext_api_url; + if ($path !== '/') { + $url .= ':' . $path; + if (substr($url,-1)=='/') $url=substr($url,0,-1); + } + $url .= '?expand=children(select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$this->DownurlStrName.')'; + $retry = 0; + $arr = []; + while ($retry<3&&!$arr['stat']) { + $arr = curl('GET', $url, '', ['Authorization' => 'Bearer ' . $this->access_token], 1); + $retry++; + } + //echo $url . '
' . json_encode($arr, JSON_PRETTY_PRINT) . '
'; + if ($arr['stat']<500) { + $files = json_decode($arr['body'], true); + //echo '
' . json_encode($files, JSON_PRETTY_PRINT) . '
'; + if (isset($files['folder'])) { + if ($files['folder']['childCount']>200) { + // files num > 200 , then get nextlink + $page = $_POST['pagenum']==''?1:$_POST['pagenum']; + if ($page>1) if (!($files = getcache('path_' . $path . '_' . $page, $this->disktag))) { + $files = $this->fetch_files_children($files, $path, $page); + //$files['children'] = children_name($files['children']); + /*$url = $_SERVER['api_url']; + if ($path !== '/') { + $url .= ':' . $path; + if (substr($url,-1)=='/') $url=substr($url,0,-1); + $url .= ':/children?$top=9999&$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$this->DownurlStrName; + } else { + $url .= '/children?$top=9999&$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$this->DownurlStrName; + } + $children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + $files['children'] = $children['value'];*/ + savecache('path_' . $path . '_' . $page, $files, $this->disktag); + } + } else { + // files num < 200 , then cache + //if (isset($files['children'])) { + //$files['children'] = children_name($files['children']); + //} + savecache('path_' . $path, $files, $this->disktag); + } + } + if (isset($files['file'])) { + if (in_array(splitlast($files['name'],'.')[1], $exts['txt'])) { + if (!(isset($files['content'])&&$files['content']['stat']==200)) { + $content1 = curl('GET', $files[$this->DownurlStrName]); + $files['content'] = $content1; + savecache('path_' . $path, $files, $this->disktag); + } + } + } + if (isset($files['error'])) { + $files['error']['stat'] = $arr['stat']; + } + } else { + //error_log($arr['body']); + $files = json_decode($arr['body'], true); + if (isset($files['error'])) { + $files['error']['stat'] = $arr['stat']; + } else { + $files['error']['stat'] = 503; + $files['error']['code'] = 'unknownError'; + $files['error']['message'] = 'unknownError'; + } + //$files = json_decode( '{"unknownError":{ "stat":'.$arr['stat'].',"message":"'.$arr['body'].'"}}', true); + //error_log(json_encode($files, JSON_PRETTY_PRINT)); + } + } + //echo '
' . json_encode($files, JSON_PRETTY_PRINT) . '
'; + return $this->files_format($files); + } + + protected function files_format($files) + { + if (isset($files['file'])) { + $tmp['type'] = 'file'; + $tmp['id'] = $files['id']; + $tmp['name'] = $files['name']; + $tmp['time'] = $files['lastModifiedDateTime']; + $tmp['size'] = $files['size']; + $tmp['mime'] = $files['file']['mimeType']; + $tmp['url'] = $files[$this->DownurlStrName]; + $tmp['content'] = $files['content']; + } elseif (isset($files['folder'])) { + $tmp['type'] = 'folder'; + $tmp['id'] = $files['id']; + $tmp['name'] = $files['name']; + $tmp['time'] = $files['lastModifiedDateTime']; + $tmp['size'] = $files['size']; + $tmp['childcount'] = $files['folder']['childCount']; + $tmp['page'] = $files['folder']['page']; + foreach ($files['children'] as $file) { + if (isset($file['file'])) { + $tmp['list'][$file['name']]['type'] = 'file'; + //var_dump($file); + //echo $file['name'] . ':' . $this->DownurlStrName . ':' . $file[$this->DownurlStrName] . PHP_EOL; + $tmp['list'][$file['name']]['url'] = $file[$this->DownurlStrName]; + $tmp['list'][$file['name']]['mime'] = $file['file']['mimeType']; + } elseif (isset($file['folder'])) { + $tmp['list'][$file['name']]['type'] = 'folder'; + } + $tmp['list'][$file['name']]['id'] = $file['id']; + $tmp['list'][$file['name']]['name'] = $file['name']; + $tmp['list'][$file['name']]['time'] = $file['lastModifiedDateTime']; + $tmp['list'][$file['name']]['size'] = $file['size']; + } + } elseif (isset($files['error'])) { + return $files; + } + //error_log(json_encode($tmp)); + return $tmp; + } + + protected function fetch_files_children($files, $path, $page) + { + $cachefilename = '.SCFcache_'.$_SERVER['function_name']; + $maxpage = ceil($files['folder']['childCount']/200); + if (!($files['children'] = getcache('files_' . $path . '_page_' . $page, $this->disktag))) { + // down cache file get jump info. 下载cache文件获取跳页链接 + $cachefile = $this->list_files(path_format($path . '/' .$cachefilename)); + if ($cachefile['size']>0) { + $pageinfo = curl('GET', $cachefile[$this->DownurlStrName])['body']; + $pageinfo = json_decode($pageinfo,true); + for ($page4=1;$page4<$maxpage;$page4++) { + savecache('nextlink_' . $path . '_page_' . $page4, $pageinfo['nextlink_' . $path . '_page_' . $page4], $this->disktag); + $pageinfocache['nextlink_' . $path . '_page_' . $page4] = $pageinfo['nextlink_' . $path . '_page_' . $page4]; + } + } + $pageinfochange=0; + for ($page1=$page;$page1>=1;$page1--) { + $page3=$page1-1; + $url = getcache('nextlink_' . $path . '_page_' . $page3, $this->disktag); + if ($url == '') { + if ($page1==1) { + $url = $this->api_url . $this->ext_api_url; + if ($path !== '/') { + $url .= ':' . $path; + if (substr($url,-1)=='/') $url=substr($url,0,-1); + $url .= ':'; + } + $url .= '/children?$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$this->DownurlStrName; + $children = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + // echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; + savecache('files_' . $path . '_page_' . $page1, $children['value'], $this->disktag); + $nextlink=getcache('nextlink_' . $path . '_page_' . $page1, $this->disktag); + if ($nextlink!=$children['@odata.nextLink']) { + savecache('nextlink_' . $path . '_page_' . $page1, $children['@odata.nextLink'], $this->disktag); + $pageinfocache['nextlink_' . $path . '_page_' . $page1] = $children['@odata.nextLink']; + $pageinfocache = clearbehindvalue($path,$page1,$maxpage,$pageinfocache); + $pageinfochange = 1; + } + $url = $children['@odata.nextLink']; + for ($page2=$page1+1;$page2<=$page;$page2++) { + sleep(1); + $children = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + savecache('files_' . $path . '_page_' . $page2, $children['value'], $this->disktag); + $nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $this->disktag); + if ($nextlink!=$children['@odata.nextLink']) { + savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], $this->disktag); + $pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink']; + $pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache); + $pageinfochange = 1; + } + $url = $children['@odata.nextLink']; + } + //echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; + $files['children'] = $children['value']; + $files['folder']['page']=$page; + $pageinfocache['filenum'] = $files['folder']['childCount']; + $pageinfocache['dirsize'] = $files['size']; + $pageinfocache['cachesize'] = $cachefile['size']; + $pageinfocache['size'] = $files['size']-$cachefile['size']; + if ($pageinfochange == 1) $this->MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $this->access_token)['body']; + return $files; + } + } else { + for ($page2=$page3+1;$page2<=$page;$page2++) { + sleep(1); + $children = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + savecache('files_' . $path . '_page_' . $page2, $children['value'], $this->disktag, 3300); + $nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $this->disktag); + if ($nextlink!=$children['@odata.nextLink']) { + savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], $this->disktag, 3300); + $pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink']; + $pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache); + $pageinfochange = 1; + } + $url = $children['@odata.nextLink']; + } + //echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; + $files['children'] = $children['value']; + $files['folder']['page']=$page; + $pageinfocache['filenum'] = $files['folder']['childCount']; + $pageinfocache['dirsize'] = $files['size']; + $pageinfocache['cachesize'] = $cachefile['size']; + $pageinfocache['size'] = $files['size']-$cachefile['size']; + if ($pageinfochange == 1) $this->MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $this->access_token)['body']; + return $files; + } + } + } else { + $files['folder']['page']=$page; + for ($page4=1;$page4<=$maxpage;$page4++) { + if (!($url = getcache('nextlink_' . $path . '_page_' . $page4, $this->disktag))) { + if ($files['folder'][$path.'_'.$page4]!='') savecache('nextlink_' . $path . '_page_' . $page4, $files['folder'][$path.'_'.$page4], $this->disktag); + } else { + $files['folder'][$path.'_'.$page4] = $url; + } + } + } + return $files; + } + + public function Rename($file, $newname) { + $oldname = spurlencode($file['name']); + $oldname = path_format($file['path'] . '/' . $oldname); + $data = '{"name":"' . $newname . '"}'; + //echo $oldname; + $result = $this->MSAPI('PATCH', $oldname, $data, $this->access_token); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + } + public function Delete($file) { + $filename = spurlencode($file['name']); + $filename = path_format($file['path'] . '/' . $filename); + //echo $filename; + $result = $this->MSAPI('DELETE', $filename, '', $this->access_token); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + return output($result['body'], $result['stat']); + } + public function Encrypt($folder, $passfilename, $pass) { + $filename = path_format($folder['path'] . '/' . urlencode($passfilename)); + $result = $this->MSAPI('PUT', $filename, $pass, $this->access_token); + $path1 = $folder['path']; + if ($path1!='/'&&substr($path1, -1)=='/') $path1 = substr($path1, 0, -1); + savecache('path_' . $path1 . '/?password', '', $this->disktag, 1); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + return output($result['body'], $result['stat']); + } + public function Move($file, $folder) { + $filename = spurlencode($file['name']); + $filename = path_format($file['path'] . '/' . $filename); + $data = '{"parentReference":{"path": "/drive/root:' . $folder['path'] . '"}}'; + $result = $this->MSAPI('PATCH', $filename, $data, $this->access_token); + $path2 = spurlencode($folder['path'], '/'); + if ($path2!='/'&&substr($path2, -1)=='/') $path2 = substr($path2, 0, -1); + savecache('path_' . $path2, json_decode('{}', true), $this->disktag, 1); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + return output($result['body'], $result['stat']); + } + public function Copy($file) { + $filename = spurlencode($file['name']); + $filename = path_format($file['path'] . '/' . $filename); + $namearr = splitlast($file['name'], '.'); + date_default_timezone_set('UTC'); + if ($namearr[0]!='') { + $newname = $namearr[0] . ' (' . date("Ymd\THis\Z") . ')'; + if ($namearr[1]!='') $newname .= '.' . $namearr[1]; + } else { + $newname = '.' . $namearr[1] . ' (' . date("Ymd\THis\Z") . ')'; + } + $data = '{ "name": "' . $newname . '" }'; + $result = $this->MSAPI('copy', $filename, $data, $this->access_token); + /*$num = 0; + while ($result['stat']==409 && json_decode($result['body'], true)['error']['code']=='nameAlreadyExists') { + $num++; + if ($namearr[0]!='') { + $newname = $namearr[0] . ' (' . getconstStr('Copy') . ' ' . $num . ')'; + if ($namearr[1]!='') $newname .= '.' . $namearr[1]; + } else { + $newname = '.' . $namearr[1] . ' ('.getconstStr('Copy'). ' ' . $num .')'; + } + //$newname = spurlencode($newname); + $data = '{ "name": "' . $newname . '" }'; + $result = $this->MSAPI('copy', $filename, $data, $this->access_token); + }*/ + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + return output($result['body'], $result['stat']); + } + public function Edit($file, $content) { + /*TXT一般不会超过4M,不用二段上传 + $filename = $path1 . ':/createUploadSession'; + $response=MSAPI('POST',$filename,'{"item": { "@microsoft.graph.conflictBehavior": "replace" }}',$_SERVER['access_token']); + $uploadurl=json_decode($response,true)['uploadUrl']; + echo MSAPI('PUT',$uploadurl,$data,$_SERVER['access_token']);*/ + $result = $this->MSAPI('PUT', $file['path'], $content, $this->access_token); + //return output($result['body'], $result['stat']); + //echo $result; + $resultarry = json_decode($result['body'],true); + if (isset($resultarry['error'])) return message($resultarry['error']['message']. '
'.getconstStr('Back').'','Error', 403); + else return output('success', 0); + } + public function Create($parent, $type, $name, $content = '') { + if ($type=='file') { + $filename = spurlencode($name); + $filename = path_format($parent['path'] . '/' . $filename); + $result = $this->MSAPI('PUT', $filename, $content, $this->access_token); + } + if ($type=='folder') { + $data = '{ "name": "' . $name . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }'; + $result = $this->MSAPI('children', $parent['path'], $data, $this->access_token); + } + //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); + return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); + return output($result['body'], $result['stat']); + } + + public function AddDisk() { + global $constStr; + global $EnvConfigs; + + $envs = ''; + foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', '; + $url = path_format($_SERVER['PHP_SELF'] . '/'); + //$this->api_url = splitfirst($_SERVER['api_url'], '/v1.0')[0] . '/v1.0'; + + if (isset($_GET['install4'])) { + if ($this->access_token == '') { + $refresh_token = getConfig('refresh_token', $this->disktag); + if (!$refresh_token) { + $html = 'No refresh_token config, please AddDisk again or wait minutes.
' . $this->disktag; + $title = 'Error'; + return message($html, $title, 201); + } + $response = $this->get_access_token($refresh_token); + if (isset($response['stat'])) return message($response['body'], 'Error', $response['stat']); + } + + $tmp = null; + if ($_POST['DriveType']=='Onedrive') { + $api = $this->api_url . '/me'; + $arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ], 1); + if ($arr['stat']==200) { + $userid = json_decode($arr['body'], true)['id']; + $api = $this->api_url . '/users/' . $userid . '/drive'; + $arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ], 1); + if ($arr['stat']!=200) return message($arr['stat'] . '
' . $api . '
' . $arr['body'], 'Get User Drive ID', $arr['stat']); + $tmp['DriveId'] = json_decode($arr['body'], true)['id']; + } elseif ($arr['stat']==403||$arr['stat']==401) { + // 403:世纪不让列me,401:个人也不给拿 + $api = $this->api_url . '/me/drive'; + } else { + return message($arr['stat'] . $arr['body'], 'Get User ID', $arr['stat']); + } + } elseif ($_POST['DriveType']=='Custom') { + // sitename计算siteid + $tmp1 = $this->get_siteid($_POST['sharepointSite']); + if (isset($tmp1['stat'])) return message($arr['stat'] . $tmp1['body'], 'Get Sharepoint Site ID ' . $_POST['sharepointSite'], $tmp1['stat']); + $siteid = $tmp1; + //$api = $this->api_url . '/sites/' . $siteid . '/drive/'; + //$arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ], 1); + //if ($arr['stat']!=200) return message($arr['stat'] . $arr['body'], 'Get Sharepoint Drive ID ' . $_POST['DriveType'], $arr['stat']); + $tmp['siteid'] = $siteid; + $tmp['sharepointSite'] = $_POST['sharepointSite']; + //$tmp['DriveId'] = json_decode($arr['body'], true)['id']; + if (get_class($this)=='Onedrive') $tmp['Driver'] = 'Sharepoint'; + elseif (get_class($this)=='OnedriveCN') $tmp['Driver'] = 'SharepointCN'; + } else { + // 直接是siteid + //$api = $this->api_url . '/sites/' . $_POST['DriveType'] . '/drive/'; + //$arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ], 1); + //if ($arr['stat']!=200) return message($arr['stat'] . $arr['body'], 'Get Sharepoint Drive ID ' . $_POST['DriveType'], $arr['stat']); + $tmp['siteid'] = $_POST['DriveType']; + $tmp['sharepointSite'] = $_POST['sharepointSiteUrl']; + //$tmp['DriveId'] = json_decode($arr['body'], true)['id']; + if (get_class($this)=='Onedrive') $tmp['Driver'] = 'Sharepoint'; + elseif (get_class($this)=='OnedriveCN') $tmp['Driver'] = 'SharepointCN'; + } + + $response = setConfigResponse( setConfig($tmp, $this->disktag) ); + if (api_error($response)) { + $html = api_error_msg($response); + $title = 'Error'; + return message($html, $title, 201); + } else { + $str .= ' + '; + return message($str, getconstStr('WaitJumpIndex'), 201); + } + } + + if (isset($_GET['install3'])) { + if ($this->access_token == '') { + $refresh_token = getConfig('refresh_token', $this->disktag); + if (!$refresh_token) { + $html = 'No refresh_token config, please AddDisk again or wait minutes.
' . $this->disktag; + $title = 'Error'; + return message($html, $title, 201); + } + $response = $this->get_access_token($refresh_token); + if (isset($response['stat'])) return message($response['body'], 'Error', $response['stat']); + } + + $api = $this->api_url . '/sites/root'; + $arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ]); + $Tenant = json_decode($arr['body'], true)['webUrl']; + + $api = $this->api_url . '/me/followedSites'; + $arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ]); + if (!($arr['stat']==200||$arr['stat']==403||$arr['stat']==400)) return message($arr['stat'] . json_encode(json_decode($arr['body']), JSON_PRETTY_PRINT), 'Get followedSites', $arr['stat']); + error_log($arr['body']); + $sites = json_decode($arr['body'], true)['value']; + + $title = 'Select Disk'; + $html = ' +
+
+
'; + if ($sites[0]!='') foreach ($sites as $k => $v) { + $html .= ' + '; + } + $html .= ' + +
+ '; + $html .= ' + +
+
+ + '; + return message($html, $title, 201); + } + + if (isset($_GET['install2']) && isset($_GET['code'])) { + $tmp = curl('POST', $this->oauth_url . 'token', 'client_id=' . $this->client_id .'&client_secret=' . $this->client_secret . '&grant_type=authorization_code&requested_token_use=on_behalf_of&redirect_uri=' . $this->redirect_uri . '&code=' . $_GET['code']); + if ($tmp['stat']==200) $ret = json_decode($tmp['body'], true); + if (isset($ret['refresh_token'])) { + $refresh_token = $ret['refresh_token']; + $str = ' + refresh_token :
'; + $str .= ' +

+ ' . getconstStr('SavingToken') . ' + '; + $tmptoken['refresh_token'] = $refresh_token; + $tmptoken['token_expires'] = time()+7*24*60*60; + $response = setConfigResponse( setConfig($tmptoken, $this->disktag) ); + if (api_error($response)) { + $html = api_error_msg($response); + $title = 'Error'; + return message($html, $title, 201); + } else { + savecache('access_token', $ret['access_token'], $this->disktag, $ret['expires_in'] - 60); + $str .= ' + '; + return message($str, getconstStr('Wait') . ' 3s', 201); + } + } + return message('
' . json_encode(json_decode($tmp['body']), JSON_PRETTY_PRINT) . '
', $tmp['stat']); + //return message('
' . json_encode($ret, JSON_PRETTY_PRINT) . '
', 500); + } + + if (isset($_GET['install1'])) { + if (get_class($this)=='Onedrive' || get_class($this)=='OnedriveCN') { + return message(' + ' . getconstStr('JumptoOffice') . ' + + ', getconstStr('Wait') . ' 1s', 201); + } else { + return message('Something error, retry after a few seconds.', 'Retry', 201); + } + } + + if (isset($_GET['install0'])) { + if ($_POST['disktag_add']!='') { + $_POST['disktag_add'] = preg_replace('/[^0-9a-zA-Z|_]/i', '', $_POST['disktag_add']); + $f = substr($_POST['disktag_add'], 0, 1); + if (strlen($_POST['disktag_add'])==1) $_POST['disktag_add'] .= '_'; + if (isCommonEnv($_POST['disktag_add'])) { + return message('Do not input ' . $envs . '
+ ', 'Error', 201); + } elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) { + return message('Please start with letters
+ ', 'Error', 201); + } + + $tmp = null; + foreach ($EnvConfigs as $env => $v) if (isInnerEnv($env)) $tmp[$env] = ''; + + //$this->disktag = $_POST['disktag_add']; + $tmp['disktag_add'] = $_POST['disktag_add']; + $tmp['diskname'] = $_POST['diskname']; + $tmp['Driver'] = $_POST['Drive_ver']; + if ($_POST['Drive_ver']=='Sharelink') { + $tmp['shareurl'] = $_POST['shareurl']; + } else { + if ($_POST['Drive_ver']=='Onedrive' && $_POST['NT_Drive_custom']=='on') { + $tmp['client_id'] = $_POST['NT_client_id']; + $tmp['client_secret'] = $_POST['NT_client_secret']; + } elseif ($_POST['Drive_ver']=='OnedriveCN' && $_POST['CN_Drive_custom']=='on') { + $tmp['client_id'] = $_POST['CN_client_id']; + $tmp['client_secret'] = $_POST['CN_client_secret']; + } + } + $response = setConfigResponse( setConfig($tmp, $this->disktag) ); + if (api_error($response)) { + $html = api_error_msg($response); + $title = 'Error'; + } else { + $title = getconstStr('MayinEnv'); + $html = getconstStr('Wait') . ' 3s'; + if ($_POST['Drive_ver']=='Sharelink') $html = getconstStr('Wait') . ' 3s'; + } + return message($html, $title, 201); + } + } + + $html = ' +
+
+ ' . getconstStr('DiskTag') . ': (' . getConfig('disktag') . ') +
+ ' . getconstStr('DiskName') . ': +
+
+
+
+
+
+
+
+ +
+
'; + if ($_SERVER['language']=='zh-cn') $html .= '你要理解 scfonedrive.github.io 是github上的静态网站,
除非github真的挂掉了,
不然,稍后你如果连不上,请检查你的运营商或其它“你懂的”问题!
'; + $html .=' + +
+
+ '; + $title = 'Select Account Type'; + return message($html, $title, 201); + } + + protected function get_access_token($refresh_token) { + if (!($this->access_token = getcache('access_token', $this->disktag))) { + $p=0; + while ($response['stat']==0&&$p<3) { + $response = curl('POST', $this->oauth_url . 'token', 'client_id=' . $this->client_id . '&client_secret=' . $this->client_secret . '&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . $refresh_token ); + $p++; + } + if ($response['stat']==200) $ret = json_decode($response['body'], true); + if (!isset($ret['access_token'])) { + error_log($this->oauth_url . 'token' . '?client_id=' . $this->client_id . '&client_secret=' . $this->client_secret . '&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . substr($refresh_token, 0, 20) . '******' . substr($refresh_token, -20)); + error_log('failed to get [' . $this->disktag . '] access_token. response' . json_encode($ret)); + $response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT); + $response['body'] .= '\nfailed to get [' . $this->disktag . '] access_token.'; + return $response; + //throw new Exception($response['stat'].', failed to get ['.$this->disktag.'] access_token.'.$response['body']); + } + $tmp = $ret; + $tmp['access_token'] = '******'; + $tmp['refresh_token'] = '******'; + error_log('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT)); + $this->access_token = $ret['access_token']; + savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300); + if (time()>getConfig('token_expires', $this->disktag)) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ], $this->disktag); + } + return $this->access_token; + } + + protected function get_siteid($sharepointSite) + { + //$sharepointSite = getConfig('sharepointSite', $this->disktag); + while (substr($sharepointSite, -1)=='/') $sharepointSite = substr($sharepointSite, 0, -1); + $tmp = splitlast($sharepointSite, '/'); + $sharepointname = urlencode($tmp[1]); + $tmp = splitlast($tmp[0], '/'); + $sharepointname = $tmp[1] . '/' . $sharepointname; + if (getConfig('Driver', $this->disktag)=='Onedrive') $url = 'https://graph.microsoft.com/v1.0/sites/root:/' . $sharepointname; + if (getConfig('Driver', $this->disktag)=='OnedriveCN') $url = 'https://microsoftgraph.chinacloudapi.cn/v1.0/sites/root:/' . $sharepointname; + + $i=0; + $response = []; + while ($url!=''&&$response['stat']!=200&&$i<4) { + $response = curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token]); + $i++; + } + if ($response['stat']!=200) { + error_log('failed to get siteid. response' . json_encode($response)); + $response['body'] .= '\nfailed to get siteid.'; + return $response; + //throw new Exception($response['stat'].', failed to get siteid.'.$response['body']); + } + return json_decode($response['body'],true)['id']; + } + + public function del_upload_cache() + { + error_log('del.tmp:GET,'.json_encode($_GET,JSON_PRETTY_PRINT)); + $tmp = splitlast($_GET['filename'], '/'); + if ($tmp[1]!='') { + $filename = $tmp[0] . '/.' . $_GET['filelastModified'] . '_' . $_GET['filesize'] . '_' . $tmp[1] . '.tmp'; + } else { + $filename = '.' . $_GET['filelastModified'] . '_' . $_GET['filesize'] . '_' . $_GET['filename'] . '.tmp'; + } + $filename = path_format( path_format($_SERVER['list_path'] . path_format($path)) . '/' . spurlencode($filename, '/') ); + $tmp = $this->MSAPI('DELETE', $filename, '', $this->access_token); + $path1 = path_format($_SERVER['list_path'] . path_format($path)); + if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1); + savecache('path_' . $path1, json_decode('{}',true), $this->disktag, 1); + return output($tmp['body'],$tmp['stat']); + } + + public function get_thumbnails_url($path = '/') + { + $thumb_url = getcache('thumb_'.$path, $this->disktag); + if ($thumb_url=='') { + $url = $this->api_url . $this->ext_api_url; + if ($path !== '/') { + $url .= ':' . $path; + if (substr($url,-1)=='/') $url=substr($url,0,-1); + } + $url .= ':/thumbnails/0/medium'; + $files = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + if (isset($files['url'])) { + savecache('thumb_' . $path, $files['url'], $this->disktag); + $thumb_url = $files['url']; + } + } + return $thumb_url; + } + + public function bigfileupload($path) + { + if ($_POST['upbigfilename']=='') return output('error: no file name', 400); + if (!is_numeric($_POST['filesize'])) return output('error: no file size', 400); + if (!$_SERVER['admin']) if (!isset($_POST['filemd5'])) return output('error: no file md5', 400); + + $tmp = splitlast($_POST['upbigfilename'], '/'); + if ($tmp[1]!='') { + $fileinfo['name'] = $tmp[1]; + if ($_SERVER['admin']) $fileinfo['path'] = $tmp[0]; + } else { + $fileinfo['name'] = $_POST['upbigfilename']; + } + $fileinfo['size'] = $_POST['filesize']; + $fileinfo['filelastModified'] = $_POST['filelastModified']; + if ($_SERVER['admin']) { + $filename = spurlencode($_POST['upbigfilename'], '/'); + } else { + $tmp1 = splitlast($fileinfo['name'], '.'); + if ($tmp1[0]==''||$tmp1[1]=='') $filename = $_POST['filemd5']; + else $filename = $_POST['filemd5'] . '.' . $tmp1[1]; + } + if ($fileinfo['size']>10*1024*1024) { + $cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['filelastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.tmp', '/'); + $getoldupinfo=$this->list_files(path_format($path . '/' . $cachefilename)); + //echo json_encode($getoldupinfo, JSON_PRETTY_PRINT); + if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) { + $getoldupinfo_j = curl('GET', $getoldupinfo['url']); + $getoldupinfo = json_decode($getoldupinfo_j['body'], true); + if ( json_decode( curl('GET', $getoldupinfo['uploadUrl'])['body'], true)['@odata.context']!='' ) return output($getoldupinfo_j['body'], $getoldupinfo_j['stat']); + } + } + $response = $this->MSAPI('createUploadSession', path_format($path . '/' . $filename), '{"item": { "@microsoft.graph.conflictBehavior": "fail" }}', $this->access_token); + if ($response['stat']<500) { + $responsearry = json_decode($response['body'],true); + if (isset($responsearry['error'])) return output($response['body'], $response['stat']); + $fileinfo['uploadUrl'] = $responsearry['uploadUrl']; + if ($fileinfo['size']>10*1024*1024) $this->MSAPI('PUT', path_format($path . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $this->access_token); + } + return output($response['body'], $response['stat']); + } + + protected function MSAPI($method, $path, $data = '', $access_token) + { + if (substr($path,0,7) == 'http://' or substr($path,0,8) == 'https://') { + $url=$path; + $lenth=strlen($data); + $headers['Content-Length'] = $lenth; + $lenth--; + $headers['Content-Range'] = 'bytes 0-' . $lenth . '/' . $headers['Content-Length']; + } else { + $url = $this->api_url . $this->ext_api_url; + if ($path=='' or $path=='/') { + $url .= '/'; + } else { + $url .= ':' . $path; + if (substr($url,-1)=='/') $url=substr($url,0,-1); + } + if ($method=='PUT') { + if ($path=='' or $path=='/') { + $url .= 'content'; + } else { + $url .= ':/content'; + } + $headers['Content-Type'] = 'text/plain'; + } elseif ($method=='PATCH') { + $headers['Content-Type'] = 'application/json'; + } elseif ($method=='POST') { + $headers['Content-Type'] = 'application/json'; + } elseif ($method=='DELETE') { + $headers['Content-Type'] = 'application/json'; + } else { + if ($path=='' or $path=='/') { + $url .= $method; + } else { + $url .= ':/' . $method; + } + $method='POST'; + $headers['Content-Type'] = 'application/json'; + } + } + $headers['Authorization'] = 'Bearer ' . $access_token; + if (!isset($headers['Accept'])) $headers['Accept'] = '*/*'; + //if (!isset($headers['Referer'])) $headers['Referer'] = $url;* + $sendHeaders = array(); + foreach ($headers as $headerName => $headerVal) { + $sendHeaders[] = $headerName . ': ' . $headerVal; + } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders); + $response['body'] = curl_exec($ch); + $response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE); + //$response['Location'] = curl_getinfo($ch); + curl_close($ch); + error_log($response['stat'].' + '.$response['body'].' + '.$url.' + '); + return $response; + } + +} \ No newline at end of file diff --git a/disk/OnedriveCN.php b/disk/OnedriveCN.php new file mode 100644 index 0000000..ecba9f7 --- /dev/null +++ b/disk/OnedriveCN.php @@ -0,0 +1,27 @@ +disktag = $tag; + $this->redirect_uri = 'https://scfonedrive.github.io'; + if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) { + $this->client_id = getConfig('client_id', $tag); + $this->client_secret = getConfig('client_secret', $tag); + } else { + $this->client_id = '31f3bed5-b9d9-4173-86a4-72c73d278617'; + $this->client_secret = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y'; + } + $this->oauth_url = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/'; + $this->api_url = 'https://microsoftgraph.chinacloudapi.cn/v1.0'; + $this->scope = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access'; + $this->access_token = getcache('access_token', $tag); + if (!$this->access_token) $this->access_token = $this->get_access_token(getConfig('refresh_token', $tag)); + + $this->client_secret = urlencode($this->client_secret); + $this->scope = urlencode($this->scope); + $this->DownurlStrName = '@microsoft.graph.downloadUrl'; + $this->ext_api_url = '/me/drive/root'; + } +} \ No newline at end of file diff --git a/disk/Sharelink.php b/disk/Sharelink.php new file mode 100644 index 0000000..e86fa79 --- /dev/null +++ b/disk/Sharelink.php @@ -0,0 +1,60 @@ +disktag = $tag; + $this->redirect_uri = 'https://scfonedrive.github.io'; + $this->api_url = getConfig('shareapiurl', $tag); + + $this->access_token = $this->get_access_token(1); + + //$this->ext_api_url = '/me/drive/root'; + $this->DownurlStrName = '@content.downloadUrl'; + } + + protected function get_access_token($refresh_token) { + if (!($this->access_token = getcache('access_token', $this->disktag))) { + $shareurl = getConfig('shareurl', $this->disktag); + if (!($this->sharecookie = getcache('sharecookie', $this->disktag))) { + $this->sharecookie = curl('GET', $shareurl, false, [], 1)['returnhead']['Set-Cookie']; + //$tmp = curl_request($shareurl, false, [], 1); + //$tmp['body'] .= json_encode($tmp['returnhead'],JSON_PRETTY_PRINT); + //return $tmp; + //$_SERVER['sharecookie'] = $tmp['returnhead']['Set-Cookie']; + //if ($tmp['stat']==302) $url = $tmp['returnhead']['Location']; + //return curl('GET', $url, [ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'Cookie' => $_SERVER['sharecookie'] ]); + savecache('sharecookie', $this->sharecookie, $this->disktag); + } + $tmp1 = splitlast($shareurl, '/')[0]; + $account = splitlast($tmp1, '/')[1]; + $domain = splitlast($shareurl, '/:')[0]; + $response = curl('POST', + $domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE", + '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}', + [ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => $domain, 'Cookie' => $this->sharecookie ] + ); + if ($response['stat']==200) $ret = json_decode($response['body'], true); + $this->access_token = splitlast($ret['ListSchema']['.driveAccessToken'],'=')[1]; + $this->api_url = $ret['ListSchema']['.driveUrl'].'/root'; + if (!$this->access_token) { + error_log($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE"); + error_log('failed to get share access_token. response' . json_encode($ret)); + $response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT); + $response['body'] .= '\nfailed to get shareurl access_token.'; + return $response; + //throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']); + } + //$tmp = $ret; + //$tmp['access_token'] = '******'; + //error_log('['.$this->disktag.'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT)); + savecache('access_token', $this->access_token, $this->disktag); + $tmp1 = null; + if (getConfig('shareapiurl', $this->disktag)!=$this->api_url) $tmp1['shareapiurl'] = $this->api_url; + //if (getConfig('sharecookie', $this->disktag)!=$this->sharecookie) $tmp1['sharecookie'] = $this->sharecookie; + if (!!$tmp1) setConfig($tmp1); + } + return $this->access_token; + } +} \ No newline at end of file diff --git a/disk/Sharepoint.php b/disk/Sharepoint.php new file mode 100644 index 0000000..f2d939d --- /dev/null +++ b/disk/Sharepoint.php @@ -0,0 +1,27 @@ +disktag = $tag; + $this->redirect_uri = 'https://scfonedrive.github.io'; + if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) { + $this->client_id = getConfig('client_id', $tag); + $this->client_secret = getConfig('client_secret', $tag); + } else { + $this->client_id = '734ef928-d74c-4555-8d1b-d942fa0a1a41'; + $this->client_secret = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW'; + } + $this->oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/'; + $this->api_url = 'https://graph.microsoft.com/v1.0'; + $this->scope = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access'; + $this->access_token = getcache('access_token', $tag); + if (!$this->access_token) $this->access_token = $this->get_access_token(getConfig('refresh_token', $tag)); + + $this->client_secret = urlencode($this->client_secret); + $this->scope = urlencode($this->scope); + $this->DownurlStrName = '@microsoft.graph.downloadUrl'; + $this->ext_api_url = '/sites/' . getConfig('siteid', $tag) . '/drive/root'; + } +} \ No newline at end of file diff --git a/disk/SharepointCN.php b/disk/SharepointCN.php new file mode 100644 index 0000000..7ab2a8b --- /dev/null +++ b/disk/SharepointCN.php @@ -0,0 +1,27 @@ +disktag = $tag; + $this->redirect_uri = 'https://scfonedrive.github.io'; + if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) { + $this->client_id = getConfig('client_id', $tag); + $this->client_secret = getConfig('client_secret', $tag); + } else { + $this->client_id = '31f3bed5-b9d9-4173-86a4-72c73d278617'; + $this->client_secret = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y'; + } + $this->oauth_url = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/'; + $this->api_url = 'https://microsoftgraph.chinacloudapi.cn/v1.0'; + $this->scope = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access'; + $this->access_token = getcache('access_token', $tag); + if (!$this->access_token) $this->access_token = $this->get_access_token(getConfig('refresh_token', $tag)); + + $this->client_secret = urlencode($this->client_secret); + $this->scope = urlencode($this->scope); + $this->DownurlStrName = '@microsoft.graph.downloadUrl'; + $this->ext_api_url = '/sites/' . getConfig('siteid', $tag) . '/drive/root'; + } +} \ No newline at end of file diff --git a/platform/AliyunFC.php b/platform/AliyunFC.php index 0ad210e..470f147 100644 --- a/platform/AliyunFC.php +++ b/platform/AliyunFC.php @@ -57,17 +57,15 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; $env = json_decode(getenv($disktag), true); if (isset($env[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($env[$str]); + if (isBase64Env($str)) return base64y_decode($env[$str]); else return $env[$str]; } } else { - if (in_array($str, $Base64Env)) return base64y_decode(getenv($str)); + if (isBase64Env($str)) return base64y_decode(getenv($str)); else return getenv($str); } return ''; @@ -75,8 +73,6 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; if ($disktag=='') $disktag = $_SERVER['disktag']; $disktags = explode("|", getConfig('disktag')); $diskconfig = json_decode(getenv($disktag), true); @@ -84,8 +80,8 @@ function setConfig($arr, $disktag = '') $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); else $diskconfig[$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -98,7 +94,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v); + if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); else $tmp[$k] = $v; } } @@ -245,7 +241,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -321,7 +317,8 @@ function updateEnvironment($Envs, $accountId, $region, $service_name, $function_ $tmp_env[$key1] = $value1; } $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值 - ksort($tmp_env); + //ksort($tmp_env); + sortConfig($tmp_env); $tmpdata['environmentVariables'] = $tmp_env; return FCAPI2016($config, 'PUT', json_encode($tmpdata)); diff --git a/platform/BaiduCFC.php b/platform/BaiduCFC.php index 4a81908..3262076 100644 --- a/platform/BaiduCFC.php +++ b/platform/BaiduCFC.php @@ -47,17 +47,15 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; $env = json_decode(getenv($disktag), true); if (isset($env[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($env[$str]); + if (isBase64Env($str)) return base64y_decode($env[$str]); else return $env[$str]; } } else { - if (in_array($str, $Base64Env)) return base64y_decode(getenv($str)); + if (isBase64Env($str)) return base64y_decode(getenv($str)); else return getenv($str); } return ''; @@ -65,8 +63,6 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; if ($disktag=='') $disktag = $_SERVER['disktag']; $disktags = explode("|",getConfig('disktag')); $diskconfig = json_decode(getenv($disktag), true); @@ -74,8 +70,8 @@ function setConfig($arr, $disktag = '') $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); else $diskconfig[$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -88,7 +84,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v); + if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); else $tmp[$k] = $v; } } @@ -232,7 +228,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -302,7 +298,8 @@ function updateEnvironment($Envs, $SecretId, $SecretKey) $tmp_env[$key1] = $value1; } $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值 - ksort($tmp_env); + //ksort($tmp_env); + sortConfig($tmp_env); $tmp['Environment']['Variables'] = $tmp_env; $data = json_encode($tmp); diff --git a/platform/Heroku.php b/platform/Heroku.php index c72994c..4a584e1 100644 --- a/platform/Heroku.php +++ b/platform/Heroku.php @@ -58,17 +58,15 @@ function getGET() function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; $env = json_decode(getenv($disktag), true); if (isset($env[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($env[$str]); + if (isBase64Env($str)) return base64y_decode($env[$str]); else return $env[$str]; } } else { - if (in_array($str, $Base64Env)) return base64y_decode(getenv($str)); + if (isBase64Env($str)) return base64y_decode(getenv($str)); else return getenv($str); } return ''; @@ -76,8 +74,6 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; if ($disktag=='') $disktag = $_SERVER['disktag']; $disktags = explode("|",getConfig('disktag')); $diskconfig = json_decode(getenv($disktag), true); @@ -85,8 +81,8 @@ function setConfig($arr, $disktag = '') $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); else $diskconfig[$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -99,7 +95,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v); + if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); else $tmp[$k] = $v; } } @@ -214,7 +210,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -259,6 +255,7 @@ function getHerokuConfig($function_name, $apikey) function setHerokuConfig($env, $function_name, $apikey) { + sortConfig($env); $data = json_encode($env); return HerokuAPI('PATCH', 'https://api.heroku.com/apps/' . $function_name . '/config-vars', $data, $apikey); } diff --git a/platform/HuaweiFG_env.php b/platform/HuaweiFG_env.php index e71d3d7..a9dc5f6 100644 --- a/platform/HuaweiFG_env.php +++ b/platform/HuaweiFG_env.php @@ -69,18 +69,16 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; global $contextUserData; - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; $env = json_decode($contextUserData->getUserData($disktag), true); if (isset($env[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($env[$str]); + if (isBase64Env($str)) return base64y_decode($env[$str]); else return $env[$str]; } } else { - if (in_array($str, $Base64Env)) return base64y_decode($contextUserData->getUserData($str)); + if (isBase64Env($str)) return base64y_decode($contextUserData->getUserData($str)); else return $contextUserData->getUserData($str); } return ''; @@ -88,8 +86,6 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; global $contextUserData; if ($disktag=='') $disktag = $_SERVER['disktag']; $disktags = explode("|",getConfig('disktag')); @@ -98,8 +94,8 @@ function setConfig($arr, $disktag = '') $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); else $diskconfig[$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -112,7 +108,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v); + if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); else $tmp[$k] = $v; } } @@ -278,7 +274,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -357,7 +353,8 @@ function updateEnvironment($Envs, $HW_urn, $HW_key, $HW_secret) $tmp_env[$key1] = $value1; } $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值 - ksort($tmp_env); + //ksort($tmp_env); + sortConfig($tmp_env); $tmpdata['handler'] = 'index.handler'; $tmpdata['memory_size'] = $contextUserData->getMemorySize()+1-1; diff --git a/platform/HuaweiFG_file.php b/platform/HuaweiFG_file.php index f684e94..4e07a53 100644 --- a/platform/HuaweiFG_file.php +++ b/platform/HuaweiFG_file.php @@ -69,23 +69,23 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; - //include 'config.php'; - $s = file_get_contents(__DIR__ . '/../config.php'); - //$configs = substr($s, 18, -2); + + global $slash; + $projectPath = splitlast(__DIR__, $slash)[0]; + $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; + $s = file_get_contents($configPath); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') { $envs = json_decode($configs, true); - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; if (isset($envs[$disktag][$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($envs[$disktag][$str]); + if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]); else return $envs[$disktag][$str]; } } else { if (isset($envs[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($envs[$str]); + if (isBase64Env($str)) return base64y_decode($envs[$str]); else return $envs[$str]; } } @@ -95,20 +95,20 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; + if ($disktag=='') $disktag = $_SERVER['disktag']; - //include 'config.php'; - $s = file_get_contents(__DIR__ . '/../config.php'); - //$configs = substr($s, 18, -2); + global $slash; + $projectPath = splitlast(__DIR__, $slash)[0]; + $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; + $s = file_get_contents($configPath); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') $envs = json_decode($configs, true); $disktags = explode("|",getConfig('disktag')); $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v); else $envs[$disktag][$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -121,7 +121,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $envs[$k] = base64y_encode($v); + if (isBase64Env($k)) $envs[$k] = base64y_encode($v); else $envs[$k] = $v; } } @@ -144,7 +144,7 @@ function setConfig($arr, $disktag = '') } } $envs = array_filter($envs, 'array_value_isnot_null'); - ksort($envs); + //ksort($envs); $response = updateEnvironment($envs, getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret')); return $response; } @@ -288,7 +288,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -377,9 +377,8 @@ function copyFolder($from, $to) function updateEnvironment($Envs, $HW_urn, $HW_key, $HW_secret) { - + sortConfig($Envs); //echo json_encode($Envs,JSON_PRETTY_PRINT); - global $contextUserData; $source = '/tmp/code.zip'; $outPath = '/tmp/code/'; $oldcode = '/tmp/oldcode.zip'; @@ -392,7 +391,7 @@ function updateEnvironment($Envs, $HW_urn, $HW_key, $HW_secret) // 将配置写入 $prestr = ' 'file' ); else { @@ -448,15 +448,17 @@ function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret) if (api_error(setConfigResponse($response))) { return $response; } - $s = file_get_contents(__DIR__ . '/../config.php'); - //$configs = substr($s, 18, -2); + + $projectPath = splitlast(__DIR__, $slash)[0]; + $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; + $s = file_get_contents($configPath); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') $tmp_env = json_decode($configs, true); foreach ($Envs as $k => $v) { $tmp_env[$k] = $v; } $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); - ksort($tmp_env); + //ksort($tmp_env); $response = updateEnvironment($tmp_env, $HW_urn, $HW_key, $HW_secret); return $response; } @@ -538,7 +540,7 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = } // 放入配置文件 - file_put_contents($outPath . '/config.php', file_get_contents(__DIR__.'/../config.php')); + file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/config.php')); // 将目录中文件打包成zip //$zip=new ZipArchive(); diff --git a/platform/Normal.php b/platform/Normal.php index ad55294..9c4ceb1 100644 --- a/platform/Normal.php +++ b/platform/Normal.php @@ -58,27 +58,22 @@ function getGET() function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; - - $slash = '/'; - if (strpos(__DIR__, ':')) $slash = '\\'; + global $slash; $projectPath = splitlast(__DIR__, $slash)[0]; $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; $s = file_get_contents($configPath); - //$configs = substr($s, 18, -2); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') { $envs = json_decode($configs, true); - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; if (isset($envs[$disktag][$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($envs[$disktag][$str]); + if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]); else return $envs[$disktag][$str]; } } else { if (isset($envs[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($envs[$str]); + if (isBase64Env($str)) return base64y_decode($envs[$str]); else return $envs[$str]; } } @@ -88,23 +83,19 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; + global $slash; if ($disktag=='') $disktag = $_SERVER['disktag']; - $slash = '/'; - if (strpos(__DIR__, ':')) $slash = '\\'; $projectPath = splitlast(__DIR__, $slash)[0]; $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; $s = file_get_contents($configPath); - //$configs = substr($s, 18, -2); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') $envs = json_decode($configs, true); $disktags = explode("|", getConfig('disktag')); $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v); else $envs[$disktag][$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -117,7 +108,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $envs[$k] = base64y_encode($v); + if (isBase64Env($k)) $envs[$k] = base64y_encode($v); else $envs[$k] = $v; } } @@ -140,7 +131,8 @@ function setConfig($arr, $disktag = '') } } $envs = array_filter($envs, 'array_value_isnot_null'); - ksort($envs); + //ksort($envs); + sortConfig($envs); //echo '
'. json_encode($envs, JSON_PRETTY_PRINT).'
'; $prestr = ''; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } diff --git a/platform/TencentSCF_env.php b/platform/TencentSCF_env.php index 2f4ab80..bbde711 100644 --- a/platform/TencentSCF_env.php +++ b/platform/TencentSCF_env.php @@ -54,17 +54,15 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; $env = json_decode(getenv($disktag), true); if (isset($env[$str])) { - if (in_array($str, $Base64Env)) return base64y_decode($env[$str]); + if (isBase64Env($str)) return base64y_decode($env[$str]); else return $env[$str]; } } else { - if (in_array($str, $Base64Env)) return base64y_decode(getenv($str)); + if (isBase64Env($str)) return base64y_decode(getenv($str)); else return getenv($str); } return ''; @@ -72,8 +70,6 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; if ($disktag=='') $disktag = $_SERVER['disktag']; $disktags = explode("|",getConfig('disktag')); $diskconfig = json_decode(getenv($disktag), true); @@ -81,8 +77,8 @@ function setConfig($arr, $disktag = '') $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { - if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v); + if (isInnerEnv($k)) { + if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); else $diskconfig[$k] = $v; $indisk = 1; } elseif ($k=='disktag_add') { @@ -95,7 +91,7 @@ function setConfig($arr, $disktag = '') } elseif ($k=='disktag_rename' || $k=='disktag_newname') { if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; } else { - if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v); + if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); else $tmp[$k] = $v; } } @@ -256,7 +252,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -324,7 +320,8 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId } $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值 //$tmp_env['Region'] = $Region; - ksort($tmp_env); + //ksort($tmp_env); + sortConfig($tmp_env); $i = 0; foreach ($tmp_env as $key1 => $value1) { diff --git a/platform/TencentSCF_file.php b/platform/TencentSCF_file.php index 2252316..3279ffb 100644 --- a/platform/TencentSCF_file.php +++ b/platform/TencentSCF_file.php @@ -54,15 +54,13 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - global $InnerEnv; - global $Base64Env; //include 'config.php'; - $s = file_get_contents('config.php'); + $s = file_get_contents('.data/config.php'); //$configs = substr($s, 18, -2); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') { $envs = json_decode($configs, true); - if (in_array($str, $InnerEnv)) { + if (isInnerEnv($str)) { if ($disktag=='') $disktag = $_SERVER['disktag']; if (isset($envs[$disktag][$str])) { if (in_array($str, $Base64Env)) return base64y_decode($envs[$disktag][$str]); @@ -80,11 +78,9 @@ function getConfig($str, $disktag = '') function setConfig($arr, $disktag = '') { - global $InnerEnv; - global $Base64Env; if ($disktag=='') $disktag = $_SERVER['disktag']; //include 'config.php'; - $s = file_get_contents('config.php'); + $s = file_get_contents('.data/config.php'); //$configs = substr($s, 18, -2); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') $envs = json_decode($configs, true); @@ -92,7 +88,7 @@ function setConfig($arr, $disktag = '') $indisk = 0; $operatedisk = 0; foreach ($arr as $k => $v) { - if (in_array($k, $InnerEnv)) { + if (isInnerEnv($k)) { if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v); else $envs[$disktag][$k] = $v; $indisk = 1; @@ -129,7 +125,7 @@ function setConfig($arr, $disktag = '') } } $envs = array_filter($envs, 'array_value_isnot_null'); - ksort($envs); + //ksort($envs); $response = updateEnvironment($envs, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')); WaitSCFStat($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')); return $response; @@ -268,7 +264,7 @@ language:
'; return message($html, $title, 201); } $html .= ''.getconstStr('ClickInstall').', '.getconstStr('LogintoBind'); - $title = 'Error'; + $title = 'Install'; return message($html, $title, 201); } @@ -366,6 +362,7 @@ function copyFolder($from, $to) function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey) { + sortConfig($Envs); // 获取当前代码并解压 //$codeurl = json_decode(getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey), true)['Response']['Url']; //$codezip = '/tmp/oldcode.zip'; @@ -382,7 +379,7 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId // 将配置写入 $prestr = ' - + @@ -269,7 +269,7 @@ - + @@ -357,6 +357,7 @@

+ @@ -370,6 +371,7 @@ +
@@ -380,6 +382,7 @@

+
@@ -391,6 +394,7 @@

+ @@ -402,6 +406,7 @@

+ + @@ -472,6 +478,7 @@ + - -"日)", - "1"=>"一)", - "2"=>"二)", - "3"=>"三)", - "4"=>"四)", - "5"=>"五)", - "6"=>"六)" -); -echo '(星期'.$week[$w]; -?> - - -
- - -
-  - - - - - - - - - - diff --git a/theme/lybwb.php b/theme/lybwb.php deleted file mode 100644 index a273a94..0000000 --- a/theme/lybwb.php +++ /dev/null @@ -1,1283 +0,0 @@ - - - - - <?php echo $pretitle;?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -
- - - -
    • - -
    • -
    • -
    • - -
    • -
    • -
  • - -   - -
    - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -'.$diskname.' -'; - } ?> -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    -
    - - -
    -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files['@microsoft.graph.downloadUrl'])['body']); -?> -
    - - - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - -
    - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or (substr($file['name'],0,1) !== '.' and $file['name'] !== getConfig('passfile') ) ) { - if (strtolower($file['name']) === 'head.md') $head = $file; - if (strtolower($file['name']) === 'readme.md') $readme = $file; - if (strtolower($file['name']) === 'index.html' && !$_SERVER['admin']) { - $html = curl_request(fetch_files(spurlencode(path_format($path . '/' .$file['name']),'/'))['@microsoft.graph.downloadUrl'])['body']; - return output($html,200); - } - $filenum++; ?> - - - - - - -
       
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    -
    '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    -
    - - -
    -
    - - - -
    -
    -
    -
    - - -
    -'; - } - if ($readme) { - echo ' -
    -
    -
    -
    -
    -
    -
    - -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    - - - - -
    - - - - - - - - - - diff --git a/theme/minus.php b/theme/minus.php deleted file mode 100644 index 491601e..0000000 --- a/theme/minus.php +++ /dev/null @@ -1,1544 +0,0 @@ - - - - <?php echo $pretitle; if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) { if (getConfig('diskname')!='') $diskname = getConfig('diskname'); else $diskname = $_SERVER['disktag']; echo ' - ' . $diskname; } ?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - - - - - - -
    - - - - - - -
  • - -   - -
    - - -
    - - -1) { ?> -
    -
    -
    -
    -'.$diskname.' -'; - } ?> -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    - - -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files['@microsoft.graph.downloadUrl'])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - -      - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or !isHideFile($file['name'])) { - $filenum++; ?> - - - - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    - - - -
    - -
    - -
    -
    -
    -
    -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    -
    Theme minus by Crazy白茫茫
    - - - - - - - - - - - - diff --git a/theme/purenice.php b/theme/purenice.php deleted file mode 100644 index 9501f1c..0000000 --- a/theme/purenice.php +++ /dev/null @@ -1,1272 +0,0 @@ - - - - - - <?php echo $pretitle; if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) { if (getConfig('diskname')!='') $diskname = getConfig('diskname'); else $diskname = $_SERVER['disktag']; echo ' - ' . $diskname; } ?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -
    - - - -
  • - -   - -
    - - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -'.$diskname.' -'; - } ?> -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    - - -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files['@microsoft.graph.downloadUrl'])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or !isHideFile($file['name'])) { - $filenum++; ?> - - - - - - -
        
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    - - - -
    - -
    - -
    -
    -
    -
    -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    - - - - - - - - - - diff --git a/theme/ruoli_blue.php b/theme/ruoli_blue.php deleted file mode 100644 index 92c4659..0000000 --- a/theme/ruoli_blue.php +++ /dev/null @@ -1,1240 +0,0 @@ - - - - - <?php echo $pretitle;?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -
    - - 登陆 - -
  • - -   - -
    - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -'.$diskname.''; - } ?> -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    -
    - - -
    -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files['@microsoft.graph.downloadUrl'])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or (substr($file['name'],0,1) !== '.' and $file['name'] !== getConfig('passfile') ) ) { - if (strtolower($file['name']) === 'head.md') $head = $file; - if (strtolower($file['name']) === 'readme.md') $readme = $file; - if (strtolower($file['name']) === 'index.html' && !$_SERVER['admin']) { - $html = curl_request(fetch_files(spurlencode(path_format($path . '/' .$file['name']),'/'))['@microsoft.graph.downloadUrl'])['body']; - return output($html,200); - } - $filenum++; ?> - - - - - - -
       
    - -
  • - -
  •     - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  •     - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    -
    - - -
    -
    - -
    - -
    -
    -
    -
    - - -
    -'; - } - if ($readme) { - echo ' -
    -
    -
    -
    -
    -
    -
    - -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    OneManager by 逸笙 theme by 若离
    - - - - - - - - - - - diff --git a/theme/ruoli_violet.php b/theme/ruoli_violet.php deleted file mode 100644 index ce71dfc..0000000 --- a/theme/ruoli_violet.php +++ /dev/null @@ -1,1259 +0,0 @@ - - - - - <?php echo $pretitle;?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -
    - - - -
  • - - -
    - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -=strlen(path_format($_SERVER['base_path'].'/'.$disk))){ - if(substr($_SERVER['REQUEST_URI'],0,strlen(path_format($_SERVER['base_path'].'/'.$disk)))===path_format($_SERVER['base_path'].'/'.$disk)) - echo ''.$diskname.''; - else - echo ''.$diskname.''; - } - else - echo ''.$diskname.''; - - } ?> -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    -
    - - -
    -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files['@microsoft.graph.downloadUrl']; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files['@microsoft.graph.downloadUrl'])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or (substr($file['name'],0,1) !== '.' and $file['name'] !== getConfig('passfile') ) ) { - if (strtolower($file['name']) === 'head.md') $head = $file; - if (strtolower($file['name']) === 'readme.md') $readme = $file; - if (strtolower($file['name']) === 'index.html' && !$_SERVER['admin']) { - $html = curl_request(fetch_files(spurlencode(path_format($path . '/' .$file['name']),'/'))['@microsoft.graph.downloadUrl'])['body']; - return output($html,200); - } - $filenum++; ?> - - - - - - - -
       
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    -
    - - -
    -
    - -
    - -
    -
    -
    -
    - - -
    -'; - } - if ($readme) { - echo ' -
    -
    -
    -
    -
    -
    -
    - -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    -
    Powred by 逸笙 | Theme by 若离
    - - - - - - - - - - diff --git a/theme/tfo_md.php b/theme/tfo_md.php deleted file mode 100644 index 9e8cdc2..0000000 --- a/theme/tfo_md.php +++ /dev/null @@ -1,1296 +0,0 @@ - - - - <?php echo $pretitle; if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) { if (getConfig('diskname')!='') $diskname = getConfig('diskname'); else $diskname = $_SERVER['disktag']; echo ' - ' . $diskname; } ?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -'; -?> - -'; -?> -
    -
    - - - -
  • - -   - -
    - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -'.$diskname.' -'; - } ?> -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    -
    - - -
    -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files[$_SERVER['DownurlStrName']]; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files[$_SERVER['DownurlStrName']]; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files[$_SERVER['DownurlStrName']])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or !isHideFile($file['name'])) { - $filenum++; ?> - - - - - - -
        
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    -
    - - -
    -
    - -
    - -
    -
    -
    -
    -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    Power byTfo's Theme for OneManager-php
    -
    - - - - - - - - - - - diff --git a/theme/tfo_mdtr.php b/theme/tfo_mdtr.php deleted file mode 100644 index e286954..0000000 --- a/theme/tfo_mdtr.php +++ /dev/null @@ -1,1296 +0,0 @@ - - - - <?php echo $pretitle; if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) { if (getConfig('diskname')!='') $diskname = getConfig('diskname'); else $diskname = $_SERVER['disktag']; echo ' - ' . $diskname; } ?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -'; -?> - -'; -?> -
    -
    - - - -
  • - -   - -
    - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -'.$diskname.' -'; - } ?> -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    -
    - - -
    -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files[$_SERVER['DownurlStrName']]; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files[$_SERVER['DownurlStrName']]; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files[$_SERVER['DownurlStrName']])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or !isHideFile($file['name'])) { - $filenum++; ?> - - - - - - -
        
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    -
    - - -
    -
    - -
    - -
    -
    -
    -
    -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    Power byTfo's Theme for OneManager-php
    -
    - - - - - - - - - - - diff --git a/theme/tfo_mdtrbaw.php b/theme/tfo_mdtrbaw.php deleted file mode 100644 index b3d5248..0000000 --- a/theme/tfo_mdtrbaw.php +++ /dev/null @@ -1,1297 +0,0 @@ - - - - <?php echo $pretitle; if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) { if (getConfig('diskname')!='') $diskname = getConfig('diskname'); else $diskname = $_SERVER['disktag']; echo ' - ' . $diskname; } ?> - <?php echo $_SERVER['sitename'];?> - - - - - - - - - - -'; -?> - -'; -?> -
    -
    - - - -
  • - -   - -
    - -
    - -

    - -

    -1) { ?> -
    -
    -
    -
    -'.$diskname.' -'; - } ?> -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    - - - - - -

    -
    -
    - -
    -
    - - -
    -
    -' . $files['error']['message'] . '
    '; - $statusCode=404; - } else { - if (isset($files['file'])) { -?> -
    -
    - -   -
    -
    -document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" /> -'; - } elseif (in_array($ext, $exts['video'])) { - //echo ''; - $DPvideo=$files[$_SERVER['DownurlStrName']]; - echo '
    -'; - } elseif (in_array($ext, $exts['music'])) { - echo ' -'; - } elseif (in_array($ext, ['pdf'])) { - /*echo ' - -';*/ - $pdfurl = $files[$_SERVER['DownurlStrName']]; - echo '
    -'; - } elseif (in_array($ext, $exts['office'])) { - echo ' -'; - } elseif (in_array($ext, $exts['txt'])) { - $txtstr = htmlspecialchars(curl_request($files[$_SERVER['DownurlStrName']])['body']); -?> -
    - -
    - -     - - - -'; ?> -
    - - -
    -'; - }*/ else { - echo ''.getconstStr('FileNotSupport').''; - } ?> -
    -
    - - - - - - - - - - - - - - -'; - foreach ($files['children'] as $file) { - // Files - if (isset($file['file'])) { - if ($_SERVER['admin'] or !isHideFile($file['name'])) { - $filenum++; ?> - - - - - - -
        
    - -
  • -
      -
    • -
    • -
    • -
    • -
    • -
    -
  • - - - -
    - -
  • -
      -
    • -
    • -
    • -
    • -
    -
  • - - - - - - - - - - - - - - - - - - - - - - - -
    -200) { - $pagenum = $files['folder']['page']; - $maxpage = ceil($files['folder']['childCount']/200); - $prepagenext = ' - - - - - - - - -
    '; - if ($pagenum!=1) { - $prepagenum = $pagenum-1; - $prepagenext .= ' - '.getconstStr('PrePage').''; - } - $prepagenext .= ' - '; - for ($page=1;$page<=$maxpage;$page++) { - if ($page == $pagenum) { - $prepagenext .= ' - ' . $page . ' '; - } else { - $prepagenext .= ' - ' . $page . ' '; - } - } - $prepagenext = substr($prepagenext,0,-1); - $prepagenext .= ' - '; - if ($pagenum!=$maxpage) { - $nextpagenum = $pagenum+1; - $prepagenext .= ' - '.getconstStr('NextPage').''; - } - $prepagenext .= ' -
    - '; - echo $prepagenext; - } - if ($_SERVER['admin']) { ?> -
    -
    - - -
    -
    - -
    - -
    -
    -
    -
    -
    - -
    -
    -'; - } - } - } else { - echo ' -
    -
    -
    - - -
    -
    -
    '; - $statusCode = 401; - } - } ?> -
    -
    -
    - - - -
    - - - - - - -
    - - - -
    Power byTfo's Theme for OneManager-php
    -
    - - - - - - - - - - -