未验证 提交 6bf9e7e8 编写于 作者: Q qkqpttgf 提交者: GitHub

no throw error, show it. in uploading, little file will not cache.

上级 86a083e1
...@@ -205,9 +205,6 @@ function main($path) ...@@ -205,9 +205,6 @@ function main($path)
} }
} }
if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language']; if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language'];
//if (!$constStr['language']) $constStr['language'] = getConfig('language');
/*echo 'firstacceptlanguage:'.$_SERVER['firstacceptlanguage'].'
'.'lan:'.$constStr['language'];*/
if ($constStr['language']=='') $constStr['language'] = 'en-us'; if ($constStr['language']=='') $constStr['language'] = 'en-us';
$_SERVER['language'] = $constStr['language']; $_SERVER['language'] = $constStr['language'];
$_SERVER['timezone'] = getConfig('timezone'); $_SERVER['timezone'] = getConfig('timezone');
...@@ -235,13 +232,12 @@ function main($path) ...@@ -235,13 +232,12 @@ function main($path)
return output('', 302, [ 'Location' => $url ]); return output('', 302, [ 'Location' => $url ]);
} }
} }
if (getConfig('admin')!='') if ( isset($_COOKIE['admin'])&&$_COOKIE['admin']==pass2cookie('admin', getConfig('admin')) ) {
if ( isset($_COOKIE['admin'])&&$_COOKIE['admin']==pass2cookie('admin', getConfig('admin')) ) { $_SERVER['admin']=1;
$_SERVER['admin']=1; $_SERVER['needUpdate'] = needUpdate();
$_SERVER['needUpdate'] = needUpdate(); } else {
} else { $_SERVER['admin']=0;
$_SERVER['admin']=0; }
}
if (isset($_GET['setup'])) if (isset($_GET['setup']))
if ($_SERVER['admin']) { if ($_SERVER['admin']) {
// setup Environments. 设置,对环境变量操作 // setup Environments. 设置,对环境变量操作
...@@ -250,15 +246,16 @@ function main($path) ...@@ -250,15 +246,16 @@ function main($path)
$url = path_format($_SERVER['PHP_SELF'] . '/'); $url = path_format($_SERVER['PHP_SELF'] . '/');
return output('<script>alert(\''.getconstStr('SetSecretsFirst').'\');</script>', 302, [ 'Location' => $url ]); return output('<script>alert(\''.getconstStr('SetSecretsFirst').'\');</script>', 302, [ 'Location' => $url ]);
} }
if ($_SERVER['admin']) if (isset($_GET['AddDisk'])||isset($_GET['authorization_code'])) return get_refresh_token();
$_SERVER['sitename'] = getConfig('sitename'); $_SERVER['sitename'] = getConfig('sitename');
if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename'); if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
$_SERVER['base_disk_path'] = $_SERVER['base_path']; $_SERVER['base_disk_path'] = $_SERVER['base_path'];
$disktags = explode("|",getConfig('disktag')); $disktags = explode("|", getConfig('disktag'));
// echo 'count$disk:'.count($disktags); // echo 'count$disk:'.count($disktags);
if (count($disktags)>1) { if (count($disktags)>1) {
if ($path=='/'||$path=='') { if ($path=='/'||$path=='') {
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
$files['showname'] = 'root';
$files['folder']['childCount'] = count($disktags); $files['folder']['childCount'] = count($disktags);
foreach ($disktags as $disktag) { foreach ($disktags as $disktag) {
$files['children'][$disktag]['folder'] = 1; $files['children'][$disktag]['folder'] = 1;
...@@ -269,19 +266,26 @@ function main($path) ...@@ -269,19 +266,26 @@ function main($path)
// return a json // return a json
return files_json($files); return files_json($files);
} }
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]); } else {
return render_list($path, $files); $_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
} //$pos = strpos($path, '/');
$_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0]; //if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
//$pos = strpos($path, '/'); if (!in_array($_SERVER['disktag'], $disktags)) {
//if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos); $tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path);
if (!in_array($_SERVER['disktag'], $disktags)) { if (!!$_GET) {
$tmp = path_format($_SERVER['base_path'].'/'.$disktags[0].'/'.$path); $tmp .= '?';
return output('Please visit <a href="'.$tmp.'">'.$tmp.'</a>.', 302, [ 'Location' => $tmp ]); foreach ($_GET as $k => $v) {
//return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404); if ($v === true) $tmp .= $k . '&';
else $tmp .= $k . '=' . $v . '&';
}
$tmp = substr($tmp, 0, -1);
}
return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 302, [ 'Location' => $tmp ]);
//return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404);
}
$path = substr($path, strlen('/' . $_SERVER['disktag']));
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
} }
$path = substr($path, strlen('/'.$_SERVER['disktag']));
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path']. '/' . $_SERVER['disktag'] . '/');
} else $_SERVER['disktag'] = $disktags[0]; } else $_SERVER['disktag'] = $disktags[0];
// echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.' // echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.'
//'; //';
...@@ -291,14 +295,17 @@ function main($path) ...@@ -291,14 +295,17 @@ function main($path)
$_SERVER['ajax']=0; $_SERVER['ajax']=0;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1; 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(); config_oauth();
$refresh_token = getConfig('refresh_token'); $refresh_token = getConfig('refresh_token');
//if (!$refresh_token) return get_refresh_token();
if (!$refresh_token) { if (!$refresh_token) {
return render_list(); return render_list();
} else { } else {
if (!($_SERVER['access_token'] = getcache('access_token'))) { if (!($_SERVER['access_token'] = getcache('access_token'))) {
get_access_token($refresh_token); $response = get_access_token($refresh_token);
if (isset($response['stat'])) return message($response['body'], 'Error', $response['stat']);
} }
if ($_SERVER['ajax']) { if ($_SERVER['ajax']) {
...@@ -466,7 +473,7 @@ function files_json($files) ...@@ -466,7 +473,7 @@ function files_json($files)
$tmp1['mime'] = $file['file']['mimeType']; $tmp1['mime'] = $file['file']['mimeType'];
array_push($tmp['list'], $tmp1); array_push($tmp['list'], $tmp1);
} }
} else return output('', 404); } else return output(var_dump($files), 404);
return output(json_encode($tmp), 200, ['Content-Type' => 'application/json']); return output(json_encode($tmp), 200, ['Content-Type' => 'application/json']);
} }
...@@ -490,7 +497,9 @@ function get_access_token($refresh_token) ...@@ -490,7 +497,9 @@ function get_access_token($refresh_token)
if (!$_SERVER['access_token']) { 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($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)); error_log('failed to get share access_token. response' . json_encode($ret));
throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']); $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 = $ret;
$tmp['access_token'] = '******'; $tmp['access_token'] = '******';
...@@ -509,7 +518,9 @@ function get_access_token($refresh_token) ...@@ -509,7 +518,9 @@ function get_access_token($refresh_token)
if (!isset($ret['access_token'])) { 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($_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)); error_log('failed to get ['.$_SERVER['disktag'].'] access_token. response' . json_encode($ret));
throw new Exception($response['stat'].', failed to get ['.$_SERVER['disktag'].'] access_token.'.$response['body']); $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 = $ret;
$tmp['access_token'] = '******'; $tmp['access_token'] = '******';
...@@ -519,6 +530,7 @@ function get_access_token($refresh_token) ...@@ -519,6 +530,7 @@ function get_access_token($refresh_token)
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300); savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]); if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]);
} }
return 0;
} }
function list_files($path) function list_files($path)
...@@ -654,7 +666,9 @@ function get_siteid($access_token) ...@@ -654,7 +666,9 @@ function get_siteid($access_token)
} }
if ($response['stat']!=200) { if ($response['stat']!=200) {
error_log('failed to get siteid. response' . json_encode($response)); error_log('failed to get siteid. response' . json_encode($response));
throw new Exception($response['stat'].', failed to get siteid.'.$response['body']); $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']; return json_decode($response['body'],true)['id'];
} }
...@@ -690,15 +704,16 @@ function path_format($path) ...@@ -690,15 +704,16 @@ function path_format($path)
return $path; return $path;
} }
function spurlencode($str,$split='') function spurlencode($str, $split='')
{ {
$str = str_replace(' ', '%20',$str); $str = str_replace(' ', '%20',$str);
$tmp=''; $tmp='';
if ($split!='') { if ($split!='') {
$tmparr=explode($split,$str); $tmparr=explode($split, $str);
for($x=0;$x<count($tmparr);$x++) { foreach ($tmparr as $str1) {
if ($tmparr[$x]!='') $tmp .= $split . urlencode($tmparr[$x]); $tmp .= urlencode($str1) . $split;
} }
$tmp = substr($tmp, 0, -strlen($split));
} else { } else {
$tmp = urlencode($str); $tmp = urlencode($str);
} }
...@@ -910,9 +925,7 @@ function message($message, $title = 'Message', $statusCode = 200) ...@@ -910,9 +925,7 @@ function message($message, $title = 'Message', $statusCode = 200)
<body> <body>
<h1>' . $title . '</h1> <h1>' . $title . '</h1>
<p> <p>
' . $message . ' ' . $message . '
</p> </p>
</body> </body>
</html> </html>
...@@ -1040,20 +1053,24 @@ function bigfileupload($path) ...@@ -1040,20 +1053,24 @@ function bigfileupload($path)
$fileinfo['size'] = $_GET['filesize']; $fileinfo['size'] = $_GET['filesize'];
$fileinfo['lastModified'] = $_GET['lastModified']; $fileinfo['lastModified'] = $_GET['lastModified'];
$filename = spurlencode($_GET['upbigfilename'],'/'); $filename = spurlencode($_GET['upbigfilename'],'/');
$cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.tmp', '/'); if ($fileinfo['size']>10*1024*1024) {
$getoldupinfo=fetch_files(path_format($path . '/' . $cachefilename)); $cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.tmp', '/');
//echo json_encode($getoldupinfo, JSON_PRETTY_PRINT); $getoldupinfo=fetch_files(path_format($path . '/' . $cachefilename));
if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) { //echo json_encode($getoldupinfo, JSON_PRETTY_PRINT);
$getoldupinfo_j = curl_request($getoldupinfo[$_SERVER['DownurlStrName']]); if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) {
$getoldupinfo = json_decode($getoldupinfo_j['body'], true); $getoldupinfo_j = curl_request($getoldupinfo[$_SERVER['DownurlStrName']]);
if ( json_decode( curl_request($getoldupinfo['uploadUrl'])['body'], true)['@odata.context']!='' ) return output($getoldupinfo_j['body'], $getoldupinfo_j['stat']); $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'; //if (!$_SERVER['admin']) $filename = spurlencode( $fileinfo['name'] ) . '.scfupload';
$response=MSAPI('createUploadSession',path_format($path1 . '/' . $filename),'{"item": { "@microsoft.graph.conflictBehavior": "fail" }}',$_SERVER['access_token']); $response = MSAPI('createUploadSession', path_format($path1 . '/' . $filename), '{"item": { "@microsoft.graph.conflictBehavior": "fail" }}', $_SERVER['access_token']);
$responsearry = json_decode($response['body'],true); if ($response['stat']<500) {
if (isset($responsearry['error'])) return output($response['body'], $response['stat']); $responsearry = json_decode($response['body'],true);
$fileinfo['uploadUrl'] = $responsearry['uploadUrl']; if (isset($responsearry['error'])) return output($response['body'], $response['stat']);
MSAPI('PUT', path_format($path1 . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body']; $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($response['body'], $response['stat']);
} }
return output('error', 400); return output('error', 400);
...@@ -1541,7 +1558,7 @@ function get_refresh_token() ...@@ -1541,7 +1558,7 @@ function get_refresh_token()
$envs = ''; $envs = '';
foreach ($CommonEnv as $env) $envs .= '\'' . $env . '\', '; foreach ($CommonEnv as $env) $envs .= '\'' . $env . '\', ';
$url = path_format($_SERVER['PHP_SELF'] . '/'); $url = path_format($_SERVER['PHP_SELF'] . '/');
if (isset($_GET['authorization_code']) && isset($_GET['code'])) { if (isset($_GET['install2']) && isset($_GET['code'])) {
$_SERVER['disktag'] = $_COOKIE['disktag']; $_SERVER['disktag'] = $_COOKIE['disktag'];
config_oauth(); 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']); $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']);
...@@ -1563,7 +1580,11 @@ function get_refresh_token() ...@@ -1563,7 +1580,11 @@ function get_refresh_token()
</script>'; </script>';
$tmptoken['refresh_token'] = $refresh_token; $tmptoken['refresh_token'] = $refresh_token;
$tmptoken['token_expires'] = time()+7*24*60*60; $tmptoken['token_expires'] = time()+7*24*60*60;
if (getConfig('usesharepoint')=='on') $tmptoken['siteid'] = get_siteid($ret['access_token']); 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']) ); $response = setConfigResponse( setConfig($tmptoken, $_COOKIE['disktag']) );
if (api_error($response)) { if (api_error($response)) {
$html = api_error_msg($response); $html = api_error_msg($response);
...@@ -2557,22 +2578,45 @@ function render_list($path = '', $files = '') ...@@ -2557,22 +2578,45 @@ function render_list($path = '', $files = '')
$tmp = splitfirst($html, '<!--PathArrayStart-->'); $tmp = splitfirst($html, '<!--PathArrayStart-->');
$html = $tmp[0]; $html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--PathArrayEnd-->'); if ($tmp[1]!='') {
$PathArrayStr = $tmp[0]; $tmp = splitfirst($tmp[1], '<!--PathArrayEnd-->');
$tmp_url = $_SERVER['base_path']; $PathArrayStr = $tmp[0];
$tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url))); $tmp_url = $_SERVER['base_disk_path'];
while ($tmp_path!='') { $tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
$tmp1 = splitfirst($tmp_path, '/'); while ($tmp_path!='') {
$folder1 = $tmp1[0]; $tmp1 = splitfirst($tmp_path, '/');
if ($folder1!='') { $folder1 = $tmp1[0];
$tmp_url .= $folder1 . '/'; if ($folder1!='') {
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr); $tmp_url .= $folder1 . '/';
$PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1); $PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
$html .= $PathArrayStr1; $PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1);
} $html .= $PathArrayStr1;
$tmp_path = $tmp1[1]; }
$tmp_path = $tmp1[1];
}
$html .= $tmp[1];
}
$tmp = splitfirst($html, '<!--DiskPathArrayStart-->');
$html = $tmp[0];
if ($tmp[1]!='') {
$tmp = splitfirst($tmp[1], '<!--DiskPathArrayEnd-->');
$PathArrayStr = $tmp[0];
$tmp_url = $_SERVER['base_path'];
$tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
while ($tmp_path!='') {
$tmp1 = splitfirst($tmp_path, '/');
$folder1 = $tmp1[0];
if ($folder1!='') {
$tmp_url .= $folder1 . '/';
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
$PathArrayStr1 = str_replace('<!--PathArrayName-->', ($folder1==$_SERVER['disktag']?(getConfig('diskname')==''?$_SERVER['disktag']:getConfig('diskname')):$folder1), $PathArrayStr1);
$html .= $PathArrayStr1;
}
$tmp_path = $tmp1[1];
}
$html .= $tmp[1];
} }
$html .= $tmp[1];
$tmp = splitfirst($html, '<!--SelectLanguageStart-->'); $tmp = splitfirst($html, '<!--SelectLanguageStart-->');
$html = $tmp[0]; $html = $tmp[0];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册