From 53f88aa506f9beec678ba05ddd2e378121bfbe95 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Sun, 7 Jun 2020 18:43:47 +0800
Subject: [PATCH] Alifc (#73)
* Update index.php
* Update common.php
* Update and rename scf.php to tencentscf.php
* Create alifc.php
* Update common.php
* Update alifc.php
* Update alifc.php
* Update alifc.php
* Update normal.php
* Update common.php
* Update common.php
* Update conststr.php
* Update normal.php
* Update normal.php
* Update conststr.php
* Update index.php
* Update common.php
* Rename alifc.php to AliyunFC.php
* Rename heroku.php to Heroku.php
* Rename normal.php to Normal.php
* Rename tencentscf.php to TencentSCF.php
* Update common.php
* Update conststr.php
* Update common.php
* Update common.php
* Update common.php
---
common.php | 136 +++++++--
conststr.php | 10 +-
index.php | 65 ++++-
platform/AliyunFC.php | 397 +++++++++++++++++++++++++++
platform/{heroku.php => Heroku.php} | 0
platform/{normal.php => Normal.php} | 68 ++++-
platform/{scf.php => TencentSCF.php} | 2 +
7 files changed, 645 insertions(+), 33 deletions(-)
create mode 100644 platform/AliyunFC.php
rename platform/{heroku.php => Heroku.php} (100%)
rename platform/{normal.php => Normal.php} (79%)
rename platform/{scf.php => TencentSCF.php} (96%)
diff --git a/common.php b/common.php
index 61838da..de54a53 100644
--- a/common.php
+++ b/common.php
@@ -5,6 +5,8 @@ $Base64Env = [
//'Region', // used in SCF.
//'SecretId', // used in SCF.
//'SecretKey', // used in SCF.
+ //'AccessKeyID', // used in FC.
+ //'AccessKeySecret', // used in FC.
//'admin',
//'adminloginpage',
'background',
@@ -33,6 +35,7 @@ $Base64Env = [
//'sharecookie',
'shareapiurl',
//'siteid',
+ 'domainforproxy',
'public_path',
//'refresh_token',
//'token_expires',
@@ -43,6 +46,8 @@ $CommonEnv = [
'Region', // used in SCF.
'SecretId', // used in SCF.
'SecretKey', // used in SCF.
+ 'AccessKeyID', // used in FC.
+ 'AccessKeySecret', // used in FC.
'admin',
'adminloginpage',
'background',
@@ -64,6 +69,8 @@ $ShowedCommonEnv = [
//'Region', // used in SCF.
//'SecretId', // used in SCF.
//'SecretKey', // used in SCF.
+ //'AccessKeyID', // used in FC.
+ //'AccessKeySecret', // used in FC.
//'admin',
'adminloginpage',
'background',
@@ -95,6 +102,7 @@ $InnerEnv = [
'shareurl',
//'sharecookie',
'shareapiurl',
+ 'domainforproxy',
'public_path',
'refresh_token',
'token_expires',
@@ -115,6 +123,7 @@ $ShowedInnerEnv = [
//'shareurl',
//'sharecookie',
//'shareapiurl',
+ 'domainforproxy',
'public_path',
//'refresh_token',
//'token_expires',
@@ -317,6 +326,10 @@ function main($path)
$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 = [];
@@ -325,14 +338,29 @@ function main($path)
}
$tmp = array_values($tmp);
if (count($tmp)>0) {
- if (isset($_GET['url'])) return output($tmp[rand(0,count($tmp)-1)], 200);
- return output('', 302, [ 'Location' => $tmp[rand(0,count($tmp)-1)] ]);
+ $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);
+ }
+ return output('', 302, [ 'Location' => $url ]);
} else return output('',404);
} else return output('',401);
}
if (isset($files['file']) && !isset($_GET['preview'])) {
// is file && not preview mode
- if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt')&&$files['name']!=getConfig('passfile')) ) return output('', 302, [ 'Location' => $files[$_SERVER['DownurlStrName']] ]);
+ if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt')&&$files['name']!=getConfig('passfile')) ) {
+ $url = $files[$_SERVER['DownurlStrName']];
+ $domainforproxy = '';
+ $domainforproxy = getConfig('domainforproxy');
+ if ($domainforproxy!='') {
+ $url = proxy_replace_domain($url, $domainforproxy);
+ }
+ if ( strtolower(splitlast($files['name'],'.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']);
+ else return output('', 302, [ 'Location' => $url ]);
+ }
}
if ( isset($files['folder']) || isset($files['file']) ) {
return render_list($path, $files);
@@ -347,6 +375,54 @@ function main($path)
}
}
+function proxy_replace_domain($url, $domainforproxy)
+{
+ $tmp = splitfirst($url, '//');
+ $http = $tmp[0];
+ $tmp = splitfirst($tmp[1], '/');
+ $domain = $tmp[0];
+ $uri = $tmp[1];
+ if (substr($domainforproxy, 0, 7)=='http://' || substr($domainforproxy, 0, 8)=='https://') $aim = $domainforproxy;
+ else $aim = $http . '//' . $domainforproxy;
+ if (substr($aim, -1)=='/') $aim = substr($aim, 0, -1);
+ return $aim . '/' . $uri . '&Origindomain=' . $domain;
+ //$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('', 404);
+ return output(json_encode($tmp));
+}
+
function get_access_token($refresh_token)
{
if (getConfig('Drive_ver')=='shareurl') {
@@ -802,8 +878,15 @@ function get_thumbnails_url($path = '/', $location = 0)
}
}
if ($thumb_url!='') {
- if ($location) return output('', 302, [ 'Location' => $thumb_url ]);
- else return output($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);
}
@@ -1541,11 +1624,10 @@ function EnvOpt($needUpdate = 0)
}*/
$response = setConfigResponse( setConfig($tmp, $_SERVER['disk_oprating']) );
if (api_error($response)) {
- $html = api_error_msg($response);
- $title = 'Error';
- } else {
+ $html = api_error_msg($response);
+ $title = 'Error';
+ } else {
//WaitSCFStat();
- //sleep(3);
$html .= getconstStr('Success') . '!
';
$title = getconstStr('Setup');
@@ -1655,16 +1737,30 @@ function EnvOpt($needUpdate = 0)
}
$html .= '
'.getconstStr('AddDisk').'
';
- if (!((isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud')||(isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app'))) {
+
+ $canOneKeyUpate = 0;
+ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
+ $canOneKeyUpate = 1;
+ } elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
+ $canOneKeyUpate = 1;
+ } elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
+ $canOneKeyUpate = 1;
+ } else {
+ $tmp = time();
+ if ( mkdir(''.$tmp, 0777) ) {
+ rmdir(''.$tmp);
+ $canOneKeyUpate = 1;
+ }
+ }
+ if (!$canOneKeyUpate) {
$html .= '
-'.getconstStr('VPSnotupdate').'
';
+'.getconstStr('CannotOneKeyUpate').'
';
} else {
$html .= '