From e9ed4dc7f1ffeef61a37a184dc60ea3ebf867e36 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 1 Mar 2021 04:38:15 -0500 Subject: [PATCH] export&import config --- common.php | 168 +++++++++++++++++++++++++++++++---- conststr.php | 16 ++-- disk/Aliyundrive.php | 33 ++++--- disk/Onedrive.php | 10 ++- platform/AliyunFC.php | 8 +- platform/BaiduCFC.php | 8 +- platform/Heroku.php | 78 +++++++++++----- platform/HuaweiFG_env.php | 8 +- platform/HuaweiFG_file.php | 8 +- platform/Normal.php | 13 ++- platform/TencentSCF_env.php | 8 +- platform/TencentSCF_file.php | 10 ++- 12 files changed, 282 insertions(+), 86 deletions(-) diff --git a/common.php b/common.php index 5e60564..3c3c760 100644 --- a/common.php +++ b/common.php @@ -10,14 +10,14 @@ $EnvConfigs = [ // 1 showed/enableEdit, 0 hidden/disableEdit // 1 base64 to save, 0 not base64 'APIKey' => 0b000, // used in heroku. - 'SecretId' => 0b000, // used in SCF. - 'SecretKey' => 0b000, // used in SCF. + 'SecretId' => 0b000, // used in SCF/CFC. + 'SecretKey' => 0b000, // used in SCF/CFC. '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. + 'HerokuappId' => 0b000, // used in heroku. 'admin' => 0b000, 'adminloginpage' => 0b010, @@ -52,6 +52,7 @@ $EnvConfigs = [ 'default_sbox_drive_id'=> 0b100, 'diskname' => 0b111, + 'diskDescription' => 0b111, 'domain_path' => 0b111, 'downloadencrypt' => 0b110, 'guestup_path' => 0b111, @@ -449,7 +450,9 @@ function proxy_replace_domain($url, $domainforproxy) 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; + if (strpos($url, '?')>0) $sp = '&'; + else $sp = '?'; + return $aim . '/' . $uri . $sp . 'Origindomain=' . $domain; //$url = str_replace($tmp, $domainforproxy, $url).'&Origindomain='.$tmp; } @@ -617,12 +620,12 @@ function array_value_isnot_null($arr) return $arr!==''; } -function curl($method, $url, $data = '', $headers = [], $returnheader = 0) +function curl($method, $url, $data = '', $headers = [], $returnheader = 0, $location = 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'] = ''; + if (!isset($headers['Content-Type'])&&!isset($headers['content-type'])) $headers['Content-Type'] = ''; $sendHeaders = array(); foreach ($headers as $headerName => $headerVal) { $sendHeaders[] = $headerName . ': ' . $headerVal; @@ -638,6 +641,7 @@ function curl($method, $url, $data = '', $headers = [], $returnheader = 0) curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders); + if ($location) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //$response['body'] = curl_exec($ch); if ($returnheader) { list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch)); @@ -1033,6 +1037,7 @@ function EnvOpt($needUpdate = 0) global $slash; global $drive; ksort($EnvConfigs); + $disktags = explode('|', getConfig('disktag')); $envs = ''; //foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', '; $envs = substr(json_encode(array_keys ($EnvConfigs)), 1, -1); @@ -1097,6 +1102,62 @@ function EnvOpt($needUpdate = 0) } return message($html, $title); } + if (isset($_POST['config_b'])) { + //return output(json_encode($_POST)); + if ($_POST['pass']!=''&&$_POST['pass']==getConfig('admin')) { + if ($_POST['config_b'] == 'export') { + foreach ($EnvConfigs as $env => $v) { + if (isCommonEnv($env)) { + $value = getConfig($env); + if ($value) $tmp[$env] = $value; + } + } + foreach ($disktags as $disktag) { + $d = getConfig($disktag); + if ($d === '') { + $d = ''; + } elseif (gettype($d)=='array') { + $tmp[$disktag] = $d; + } else { + $tmp[$disktag] = json_decode($d, true); + } + } + unset($tmp['admin']); + return output(json_encode($tmp, JSON_PRETTY_PRINT)); + } + if ($_POST['config_b'] == 'import') { + if (!$_POST['config_t']) return output("{\"Error\": \"Empty config.\"}", 403); + $c = '{' . splitfirst($_POST['config_t'], '{')[1]; + $c = splitlast($c, '}')[0] . '}'; + $tmp = json_decode($c, true); + if (!!!$tmp) return output("{\"Error\": \"Config input error. " . $c . "\"}", 403); + $tmptag = $tmp['disktag']; + foreach ($EnvConfigs as $env => $v) { + if (isCommonEnv($env)) { + if (isShowedEnv($env)) { + if (getConfig($env)!=''&&!isset($tmp[$env])) $tmp[$env] = ''; + } else { + unset($tmp[$env]); + } + } + } + foreach ($disktags as $disktag) { + if (!isset($tmp[$disktag])) $tmp[$disktag] = ''; + } + $tmp['disktag'] = $tmptag; + $response = setConfigResponse( setConfig($tmp, $_SERVER['disk_oprating']) ); + if (api_error($response)) { + return output("{\"Error\": \"" . api_error_msg($response) . "\"}", 500); + } else { + return output("{\"Success\": \"Success\"}", 200); + } + } + return output(json_encode($_POST), 500); + } else { + return output("{\"Error\": \"Error admin pass\"}", 403); + } + } + if (isset($_GET['preview'])) { $preurl = $_SERVER['PHP_SELF'] . '?preview'; } else { @@ -1161,7 +1222,7 @@ function EnvOpt($needUpdate = 0)
'; - $disktags = explode('|', getConfig('disktag')); + if (count($disktags)>1) { $html .= ' @@ -1265,16 +1326,15 @@ function EnvOpt($needUpdate = 0) Driver ' . getConfig('Driver', $disktag); - if ($diskok && baseclassofdrive($disk_tmp)=='Onedrive') $html .= ' ' . getconstStr('ChangeOnedrivetype') . ''; + if ($diskok && baseclassofdrive($disk_tmp)!='Aliyundrive') $html .= ' ' . getconstStr('ChangeDrivetype') . ''; $html .= ' '; - foreach (extendShow_diskenv($disk_tmp) as $ext_env) { - $html .= '' . $ext_env . '' . getConfig($ext_env, $disktag) . ' - '; - } - if ($diskok) { + foreach (extendShow_diskenv($disk_tmp) as $ext_env) { + $html .= '' . $ext_env . '' . getConfig($ext_env, $disktag) . ' + '; + } $html .= '
'; @@ -1291,13 +1351,87 @@ function EnvOpt($needUpdate = 0) } else { $html .= ' - ' . $disk_tmp->error['body'] . ' + ' . ($disk_tmp->error['body']?$disk_tmp->error['stat'] . '
' . $disk_tmp->error['body']:'Add this disk again.') . ' '; } $html .= '
'; } } + $html .= ' + + + + + + + + + + + +
admin pass:
config:
+
'; $Diver_arr = scandir(__DIR__ . $slash . 'disk'); $html .= '