export&import config

pull/234/head
root 2021-03-01 04:38:15 -05:00
parent c234dd62d1
commit e9ed4dc7f1
12 changed files with 282 additions and 86 deletions

View File

@ -10,14 +10,14 @@ $EnvConfigs = [
// 1 showed/enableEdit, 0 hidden/disableEdit // 1 showed/enableEdit, 0 hidden/disableEdit
// 1 base64 to save, 0 not base64 // 1 base64 to save, 0 not base64
'APIKey' => 0b000, // used in heroku. 'APIKey' => 0b000, // used in heroku.
'SecretId' => 0b000, // used in SCF. 'SecretId' => 0b000, // used in SCF/CFC.
'SecretKey' => 0b000, // used in SCF. 'SecretKey' => 0b000, // used in SCF/CFC.
'AccessKeyID' => 0b000, // used in FC. 'AccessKeyID' => 0b000, // used in FC.
'AccessKeySecret' => 0b000, // used in FC. 'AccessKeySecret' => 0b000, // used in FC.
'HW_urn' => 0b000, // used in FG. 'HW_urn' => 0b000, // used in FG.
'HW_key' => 0b000, // used in FG. 'HW_key' => 0b000, // used in FG.
'HW_secret' => 0b000, // used in FG. 'HW_secret' => 0b000, // used in FG.
'function_name' => 0b000, // used in heroku. 'HerokuappId' => 0b000, // used in heroku.
'admin' => 0b000, 'admin' => 0b000,
'adminloginpage' => 0b010, 'adminloginpage' => 0b010,
@ -52,6 +52,7 @@ $EnvConfigs = [
'default_sbox_drive_id'=> 0b100, 'default_sbox_drive_id'=> 0b100,
'diskname' => 0b111, 'diskname' => 0b111,
'diskDescription' => 0b111,
'domain_path' => 0b111, 'domain_path' => 0b111,
'downloadencrypt' => 0b110, 'downloadencrypt' => 0b110,
'guestup_path' => 0b111, '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; if (substr($domainforproxy, 0, 7)=='http://' || substr($domainforproxy, 0, 8)=='https://') $aim = $domainforproxy;
else $aim = $http . '//' . $domainforproxy; else $aim = $http . '//' . $domainforproxy;
if (substr($aim, -1)=='/') $aim = substr($aim, 0, -1); 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; //$url = str_replace($tmp, $domainforproxy, $url).'&Origindomain='.$tmp;
} }
@ -617,12 +620,12 @@ function array_value_isnot_null($arr)
return $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['Accept'])) $headers['Accept'] = '*/*';
//if (!isset($headers['Referer'])) $headers['Referer'] = $url; //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';
if (!isset($headers['Content-Type'])) $headers['Content-Type'] = ''; if (!isset($headers['Content-Type'])&&!isset($headers['content-type'])) $headers['Content-Type'] = '';
$sendHeaders = array(); $sendHeaders = array();
foreach ($headers as $headerName => $headerVal) { foreach ($headers as $headerName => $headerVal) {
$sendHeaders[] = $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_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders); curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
if ($location) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//$response['body'] = curl_exec($ch); //$response['body'] = curl_exec($ch);
if ($returnheader) { if ($returnheader) {
list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch)); list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch));
@ -1033,6 +1037,7 @@ function EnvOpt($needUpdate = 0)
global $slash; global $slash;
global $drive; global $drive;
ksort($EnvConfigs); ksort($EnvConfigs);
$disktags = explode('|', getConfig('disktag'));
$envs = ''; $envs = '';
//foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', '; //foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', ';
$envs = substr(json_encode(array_keys ($EnvConfigs)), 1, -1); $envs = substr(json_encode(array_keys ($EnvConfigs)), 1, -1);
@ -1097,6 +1102,62 @@ function EnvOpt($needUpdate = 0)
} }
return message($html, $title); 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'])) { if (isset($_GET['preview'])) {
$preurl = $_SERVER['PHP_SELF'] . '?preview'; $preurl = $_SERVER['PHP_SELF'] . '?preview';
} else { } else {
@ -1161,7 +1222,7 @@ function EnvOpt($needUpdate = 0)
<tr><td><input type="submit" name="submit1" value="' . getconstStr('Setup') . '"></td></tr> <tr><td><input type="submit" name="submit1" value="' . getconstStr('Setup') . '"></td></tr>
</form> </form>
</table><br>'; </table><br>';
$disktags = explode('|', getConfig('disktag'));
if (count($disktags)>1) { if (count($disktags)>1) {
$html .= ' $html .= '
<script src="//cdn.bootcss.com/Sortable/1.8.3/Sortable.js"></script> <script src="//cdn.bootcss.com/Sortable/1.8.3/Sortable.js"></script>
@ -1265,16 +1326,15 @@ function EnvOpt($needUpdate = 0)
<tr> <tr>
<td>Driver</td> <td>Driver</td>
<td>' . getConfig('Driver', $disktag); <td>' . getConfig('Driver', $disktag);
if ($diskok && baseclassofdrive($disk_tmp)=='Onedrive') $html .= ' <a href="?AddDisk=' . get_class($disk_tmp) . '&disktag=' . $disktag . '&SelectDrive">' . getconstStr('ChangeOnedrivetype') . '</a>'; if ($diskok && baseclassofdrive($disk_tmp)!='Aliyundrive') $html .= ' <a href="?AddDisk=' . get_class($disk_tmp) . '&disktag=' . $disktag . '&SelectDrive">' . getconstStr('ChangeDrivetype') . '</a>';
$html .= '</td> $html .= '</td>
</tr> </tr>
'; ';
if ($diskok) {
foreach (extendShow_diskenv($disk_tmp) as $ext_env) { foreach (extendShow_diskenv($disk_tmp) as $ext_env) {
$html .= '<tr><td>' . $ext_env . '</td><td>' . getConfig($ext_env, $disktag) . '</td></tr> $html .= '<tr><td>' . $ext_env . '</td><td>' . getConfig($ext_env, $disktag) . '</td></tr>
'; ';
} }
if ($diskok) {
$html .= ' $html .= '
<form name="' . $disktag . '" action="" method="post"> <form name="' . $disktag . '" action="" method="post">
<input type="hidden" name="disk" value="' . $disktag . '">'; <input type="hidden" name="disk" value="' . $disktag . '">';
@ -1291,13 +1351,87 @@ function EnvOpt($needUpdate = 0)
} else { } else {
$html .= ' $html .= '
<tr> <tr>
<td colspan="2">' . $disk_tmp->error['body'] . '</td> <td colspan="2">' . ($disk_tmp->error['body']?$disk_tmp->error['stat'] . '<br>' . $disk_tmp->error['body']:'Add this disk again.') . '</td>
</tr>'; </tr>';
} }
$html .= ' $html .= '
</table><br>'; </table><br>';
} }
} }
$html .= '
<table>
<form id="config_f" name="config" action="" method="POST" onsubmit="return false;">
<tr>
<td>admin pass:<input type="password" name="pass"></td>
<td><button name="config_b" value="export" onclick="exportConfig(this);">export</button></td>
</tr>
<tr>
<td>config:<textarea name="config_t"></textarea></td>
<td><button name="config_b" value="import" onclick="importConfig(this);">import</button></td>
</tr>
</form>
</table>
<script>
var config_f = document.getElementById("config_f");
function exportConfig(b) {
if (config_f.pass.value=="") {
alert("admin pass");
return false;
}
var xhr = new XMLHttpRequest();
xhr.open("POST", "");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
xhr.onload = function(e){
console.log(xhr.responseText+","+xhr.status);
if (xhr.status==200) {
var res = JSON.parse(xhr.responseText);
config_f.config_t.value = xhr.responseText;
config_f.parentNode.style = "width: 100%";
config_f.config_t.style = "width: 100%";
config_f.config_t.style.height = config_f.config_t.scrollHeight + "px";
} else {
alert(xhr.status+"\n"+xhr.responseText);
}
}
xhr.onerror = function(e){
alert("Network Error "+xhr.status);
}
xhr.send("pass=" + config_f.pass.value + "&config_b=" + b.value);
}
function importConfig(b) {
if (config_f.pass.value=="") {
alert("admin pass");
return false;
}
if (config_f.config_t.value=="") {
alert("input config");
return false;
} else {
try {
var tmp = JSON.parse(config_f.config_t.value);
} catch(e) {
alert("config error!");
return false;
}
}
var xhr = new XMLHttpRequest();
xhr.open("POST", "");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
xhr.onload = function(e){
console.log(xhr.responseText+","+xhr.status);
if (xhr.status==200) {
//var res = JSON.parse(xhr.responseText);
alert("Import success");
} else {
alert(xhr.status+"\n"+xhr.responseText);
}
}
xhr.onerror = function(e){
alert("Network Error "+xhr.status);
}
xhr.send("pass=" + config_f.pass.value + "&config_t=" + encodeURIComponent(config_f.config_t.value) + "&config_b=" + b.value);
}
</script><br>';
$Diver_arr = scandir(__DIR__ . $slash . 'disk'); $Diver_arr = scandir(__DIR__ . $slash . 'disk');
$html .= ' $html .= '
<select name="DriveType" onchange="changedrivetype(this.options[this.options.selectedIndex].value)">'; <select name="DriveType" onchange="changedrivetype(this.options[this.options.selectedIndex].value)">';
@ -1842,11 +1976,13 @@ function render_list($path = '', $files = [])
while (strpos($html, '<!--FileDownUrl-->')) $html = str_replace('<!--FileDownUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path), $html); while (strpos($html, '<!--FileDownUrl-->')) $html = str_replace('<!--FileDownUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path), $html);
while (strpos($html, '<!--FileEncodeReplaceUrl-->')) $html = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path), $html); while (strpos($html, '<!--FileEncodeReplaceUrl-->')) $html = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path), $html);
while (strpos($html, '<!--FileName-->')) $html = str_replace('<!--FileName-->', $files['name'], $html); while (strpos($html, '<!--FileName-->')) $html = str_replace('<!--FileName-->', $files['name'], $html);
$html = str_replace('<!--FileEncodeDownUrl-->', urlencode($files['url']), $html); //$html = str_replace('<!--FileEncodeDownUrl-->', urlencode($files['url']), $html);
while (strpos($html, '<!--FileEncodeDownUrl-->')) $html = str_replace('<!--FileEncodeDownUrl-->', urlencode(path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
$html = str_replace('<!--constStr@ClicktoEdit-->', getconstStr('ClicktoEdit'), $html); $html = str_replace('<!--constStr@ClicktoEdit-->', getconstStr('ClicktoEdit'), $html);
$html = str_replace('<!--constStr@CancelEdit-->', getconstStr('CancelEdit'), $html); $html = str_replace('<!--constStr@CancelEdit-->', getconstStr('CancelEdit'), $html);
$html = str_replace('<!--constStr@Save-->', getconstStr('Save'), $html); $html = str_replace('<!--constStr@Save-->', getconstStr('Save'), $html);
while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(curl('GET', $files['url'])['body']), $html); while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(curl('GET', $files['url'], '', '', 0, 1)['body']), $html);
//while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(get_content(spurlencode(path_format(urldecode($path) . '/' . $files['name']), '/'))['content']['body']), $html);
$html = str_replace('<!--constStr@FileNotSupport-->', getconstStr('FileNotSupport'), $html); $html = str_replace('<!--constStr@FileNotSupport-->', getconstStr('FileNotSupport'), $html);

View File

@ -96,6 +96,7 @@ $constStr = [
'referrer' => 'only these domains can refer resourse in this site, format is a1.com|b2.com', 'referrer' => 'only these domains can refer resourse in this site, format is a1.com|b2.com',
'domain_path' => 'more custom domain, format is a1.com:/dirto/path1|b2.com:/path2', 'domain_path' => 'more custom domain, format is a1.com:/dirto/path1|b2.com:/path2',
'diskname' => 'The disk name you want show.', 'diskname' => 'The disk name you want show.',
'diskDescription' => ' Some tips of this disk, not used in code.',
'disktag' => 'A tag used in store config and url.', 'disktag' => 'A tag used in store config and url.',
'disableShowThumb' => 'if 1, the ShowThumbnail button will not display', 'disableShowThumb' => 'if 1, the ShowThumbnail button will not display',
'disableChangeTheme' => 'if 1, the Theme selection button will not display', 'disableChangeTheme' => 'if 1, the Theme selection button will not display',
@ -123,6 +124,7 @@ $constStr = [
'referrer' => '只有这些域名能引用本站资源。格式为a1.com|b1.com', 'referrer' => '只有这些域名能引用本站资源。格式为a1.com|b1.com',
'domain_path' => '使用多个自定义域名时指定每个域名看到的目录。格式为a1.com:/dirto/path1|b1.com:/path2比private_path优先。', 'domain_path' => '使用多个自定义域名时指定每个域名看到的目录。格式为a1.com:/dirto/path1|b1.com:/path2比private_path优先。',
'diskname' => '这个盘你想显示什么名称。', 'diskname' => '这个盘你想显示什么名称。',
'diskDescription' => '对这个盘的一些描述,随便写,代码不引用这个。',
'disktag' => '一个标签用于保存配置多盘时会显示在url中。', 'disktag' => '一个标签用于保存配置多盘时会显示在url中。',
'disableShowThumb' => '如果填 1, ‘显示缩略’按钮将被隐藏。', 'disableShowThumb' => '如果填 1, ‘显示缩略’按钮将被隐藏。',
'disableChangeTheme' => '如果为 1则不会显示主题选择按钮', 'disableChangeTheme' => '如果为 1则不会显示主题选择按钮',
@ -325,9 +327,9 @@ $constStr = [
], ],
'SetpassfileBfEncrypt' => [ 'SetpassfileBfEncrypt' => [
'en-us' => 'Set \'passfile\' in Environments before encrypt', 'en-us' => 'Set \'passfile\' in Environments before encrypt',
'zh-cn' => '先在环境变量设置passfile才能加密', 'zh-cn' => '先设置passfile才能加密',
'zh-tw' => '先在環境變數設定passfile才能加密', 'zh-tw' => '先設定passfile才能加密',
'ja' => '最初に暗号化する環境変数にパスファイルを設定します', 'ja' => '最初に暗号化する変数にパスファイルを設定します',
'ko-kr' => '암호화하기 전에 환경 변수에 패스 파일을 설정하십시오', 'ko-kr' => '암호화하기 전에 환경 변수에 패스 파일을 설정하십시오',
'fa' => 'قبل از رمزگذاری \"passfile \" را در محیط تنظیم کنید', 'fa' => 'قبل از رمزگذاری \"passfile \" را در محیط تنظیم کنید',
'ar-sa' => 'أولا تعيين متغير البيئة passfile لتشفير', 'ar-sa' => 'أولا تعيين متغير البيئة passfile لتشفير',
@ -424,9 +426,9 @@ $constStr = [
'zh-tw' => '修改標籤', 'zh-tw' => '修改標籤',
'ar-sa' => 'تغيير التسمية', 'ar-sa' => 'تغيير التسمية',
], ],
'ChangeOnedrivetype' => [ 'ChangeDrivetype' => [
'en-us' => 'Change Onedrive/Sharepoint', 'en-us' => 'Change',
'zh-cn' => '切换Onedrive/Sharepoint', 'zh-cn' => '切换',
], ],
'AddDisk' => [ 'AddDisk' => [
'en-us' => 'Add Disk', 'en-us' => 'Add Disk',

View File

@ -27,18 +27,14 @@ class Aliyundrive {
public function ext_show_innerenv() public function ext_show_innerenv()
{ {
return []; return ['default_drive_id'];
} }
public function list_files($path = '/') public function list_files($path = '/')
{ {
$files = $this->list_path($path); $files = $this->list_path($path);
return $this->files_format($files); return $this->files_format($files);
} }
@ -129,6 +125,7 @@ class Aliyundrive {
$files['content'] = $content1; $files['content'] = $content1;
savecache('path_' . $path, $files, $this->disktag); savecache('path_' . $path, $files, $this->disktag);
} }
error_log1($files['name'] . ' : ' . json_encode($files['content']) . PHP_EOL);
} }
} }
if (!$files) { if (!$files) {
@ -254,9 +251,7 @@ class Aliyundrive {
$upload_id = $res['upload_id']; $upload_id = $res['upload_id'];
$result = curl('PUT', $url, $pass, [], 1); $result = curl('PUT', $url, $pass, [], 1);
if ($result['stat']==200) { // 块1传好 if ($result['stat']==200) { // 块1传好
$tmp1['part_number'] = 1; $result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
$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']); return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
} }
} }
@ -332,7 +327,7 @@ class Aliyundrive {
$result = curl('PUT', $url, $content, [], 1); $result = curl('PUT', $url, $content, [], 1);
if ($result['stat']==200) { // 块1传好 if ($result['stat']==200) { // 块1传好
$etag = $result['returnhead']['ETag']; $etag = $result['returnhead']['ETag'];
$result = $this->fileComplete($file_id, $upload_id, $etag); $result = $this->fileComplete($file_id, $upload_id, [ $etag ]);
if ($result['stat']!=200) return output($result['body'], $result['stat']); if ($result['stat']!=200) return output($result['body'], $result['stat']);
else return output('success', 0); else return output('success', 0);
}*/ }*/
@ -364,9 +359,7 @@ class Aliyundrive {
$upload_id = $res['upload_id']; $upload_id = $res['upload_id'];
$result = curl('PUT', $url, $content, [], 1); $result = curl('PUT', $url, $content, [], 1);
if ($result['stat']==200) { // 块1传好 if ($result['stat']==200) { // 块1传好
$tmp2['part_number'] = 1; $result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
$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']); if ($result['stat']!=200) return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
else return output('success', 0); else return output('success', 0);
} }
@ -410,9 +403,7 @@ class Aliyundrive {
$result = curl('PUT', $url, $content, [], 1); $result = curl('PUT', $url, $content, [], 1);
//error_log1('2,url:' . $url .' res:' . json_encode($result)); //error_log1('2,url:' . $url .' res:' . json_encode($result));
if ($result['stat']==200) { // 块1传好 if ($result['stat']==200) { // 块1传好
$tmp1['part_number'] = 1; $result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
$tmp1['etag'] = $result['returnhead']['ETag'];
$result = $this->fileComplete($file_id, $upload_id, [ $tmp1 ]);
//error_log1('3,url:' . $url .' res:' . json_encode($result)); //error_log1('3,url:' . $url .' res:' . json_encode($result));
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
} }
@ -702,6 +693,12 @@ class Aliyundrive {
return message($html, $title, 201); return message($html, $title, 201);
} }
protected function get_access_token($refresh_token) { protected function get_access_token($refresh_token) {
if (!$refresh_token) {
$tmp['stat'] = 0;
$tmp['body'] = 'No refresh_token';
$this->error = $tmp;
return false;
}
if (!($this->access_token = getcache('access_token', $this->disktag))) { if (!($this->access_token = getcache('access_token', $this->disktag))) {
$p=0; $p=0;
$tmp1['refresh_token'] = $refresh_token; $tmp1['refresh_token'] = $refresh_token;
@ -709,7 +706,7 @@ class Aliyundrive {
$response = curl('POST', $this->auth_url, json_encode($tmp1), ["content-type"=>"application/json; charset=utf-8"]); $response = curl('POST', $this->auth_url, json_encode($tmp1), ["content-type"=>"application/json; charset=utf-8"]);
$p++; $p++;
} }
error_log1(json_encode($response)); //error_log1(json_encode($response));
if ($response['stat']==200) $ret = json_decode($response['body'], true); if ($response['stat']==200) $ret = json_decode($response['body'], true);
if (!isset($ret['access_token'])) { if (!isset($ret['access_token'])) {
error_log1('failed to get [' . $this->disktag . '] access_token. response: ' . $response['stat'] . $response['body']); error_log1('failed to get [' . $this->disktag . '] access_token. response: ' . $response['stat'] . $response['body']);
@ -719,8 +716,8 @@ class Aliyundrive {
return false; return false;
} }
$tmp = $ret; $tmp = $ret;
$tmp['access_token'] = '******'; $tmp['access_token'] = substr($tmp['access_token'], 0, 10) . '******';
$tmp['refresh_token'] = '******'; $tmp['refresh_token'] = substr($tmp['refresh_token'], 0, 10) . '******';
error_log1('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT)); error_log1('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT));
$this->access_token = $ret['access_token']; $this->access_token = $ret['access_token'];
savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300); savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300);

View File

@ -767,6 +767,12 @@ class Onedrive {
} }
protected function get_access_token($refresh_token) { protected function get_access_token($refresh_token) {
if (!$refresh_token) {
$tmp['stat'] = 0;
$tmp['body'] = 'No refresh_token';
$this->error = $tmp;
return false;
}
if (!($this->access_token = getcache('access_token', $this->disktag))) { if (!($this->access_token = getcache('access_token', $this->disktag))) {
$p=0; $p=0;
while ($response['stat']==0&&$p<3) { while ($response['stat']==0&&$p<3) {
@ -784,8 +790,8 @@ class Onedrive {
//throw new Exception($response['stat'].', failed to get ['.$this->disktag.'] access_token.'.$response['body']); //throw new Exception($response['stat'].', failed to get ['.$this->disktag.'] access_token.'.$response['body']);
} }
$tmp = $ret; $tmp = $ret;
$tmp['access_token'] = '******'; $tmp['access_token'] = substr($tmp['access_token'], 0, 10) . '******';
$tmp['refresh_token'] = '******'; $tmp['refresh_token'] = substr($tmp['refresh_token'], 0, 10) . '******';
error_log1('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT)); error_log1('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT));
$this->access_token = $ret['access_token']; $this->access_token = $ret['access_token'];
savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300); savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300);

View File

@ -90,7 +90,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
else $tmp[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
else $diskconfig[$k] = $v; else $diskconfig[$k] = $v;
$indisk = 1; $indisk = 1;
@ -109,8 +112,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); $tmp[$k] = json_encode($v);
else $tmp[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {

View File

@ -80,7 +80,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
else $tmp[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
else $diskconfig[$k] = $v; else $diskconfig[$k] = $v;
$indisk = 1; $indisk = 1;
@ -99,8 +102,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); $tmp[$k] = json_encode($v);
else $tmp[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {

View File

@ -2,6 +2,30 @@
function getpath() function getpath()
{ {
if (getConfig('function_name') && getConfig('APIKey')) {
$APIKey = getConfig('APIKey');
$res = HerokuAPI('GET', 'https://api.heroku.com/apps/' . getConfig('function_name'), '', $APIKey);
$response = json_decode($res['body'], true);
if (isset($response['build_stack'])) {
$tmp['HerokuappId'] = $response['id'];
$tmp['function_name'] = null;
} else {
error_log1('Something error' . 'Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT));
//return message('Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT), 'Something error', 500);
}
$response = json_decode(setHerokuConfig($tmp, $tmp['HerokuappId'], $APIKey)['body'], true);
$title = 'Change function_name to HerokuappId';
if (api_error($response)) {
$html = api_error_msg($response);
$stat = 500;
error_log1('Change function_name to HerokuappId' . $html);
} else {
$html = getconstStr('Wait') . ' 5s, jump to index.
<meta http-equiv="refresh" content="5;URL=/">';
$stat = 201;
}
//return message($html, $title, $stat);
}
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]); $_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
$_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_X_FORWARDED_PROTO']; $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_X_FORWARDED_PROTO'];
@ -84,7 +108,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
else $tmp[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
else $diskconfig[$k] = $v; else $diskconfig[$k] = $v;
$indisk = 1; $indisk = 1;
@ -103,8 +130,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); $tmp[$k] = json_encode($v);
else $tmp[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {
@ -131,7 +157,7 @@ function setConfig($arr, $disktag = '')
} }
foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null; foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null;
return setHerokuConfig($tmp, getConfig('function_name'), getConfig('APIKey')); return setHerokuConfig($tmp, getConfig('HerokuappId'), getConfig('APIKey'));
error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp' . json_encode($tmp, JSON_PRETTY_PRINT)); error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp' . json_encode($tmp, JSON_PRETTY_PRINT));
} }
@ -148,15 +174,25 @@ function install()
$APIKey = $_POST['APIKey']; $APIKey = $_POST['APIKey'];
$tmp['APIKey'] = $APIKey; $tmp['APIKey'] = $APIKey;
} }
$HerokuappId = getConfig('HerokuappId');
if ($HerokuappId=='') {
$function_name = getConfig('function_name'); $function_name = getConfig('function_name');
if ($function_name=='') { if ($function_name=='') {
$tmp1 = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.')); $tmp1 = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.'));
$maindomain = substr($tmp1, strrpos($tmp1, '.')+1); $maindomain = substr($tmp1, strrpos($tmp1, '.')+1);
if ($maindomain=='herokuapp') $function_name = substr($tmp1, 0, strrpos($tmp1, '.')); if ($maindomain=='herokuapp') $function_name = substr($tmp1, 0, strrpos($tmp1, '.'));
else $function_name = 'visit from xxxx.herokuapp.com'; else return message('Please visit from xxxx.herokuapp.com', '', 500);
$tmp['function_name'] = $function_name; $res = HerokuAPI('GET', 'https://api.heroku.com/apps/' . $function_name, '', $APIKey);
$response = json_decode($res['body'], true);
if (isset($response['build_stack'])) {
$HerokuappId = $response['id'];
} else {
return message('Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT), 'Something error', 500);
} }
$response = json_decode(setHerokuConfig($tmp, $function_name, $APIKey)['body'], true); }
}
$tmp['HerokuappId'] = $HerokuappId;
$response = json_decode(setHerokuConfig($tmp, $HerokuappId, $APIKey)['body'], true);
if (api_error($response)) { if (api_error($response)) {
$html = api_error_msg($response); $html = api_error_msg($response);
$title = 'Error'; $title = 'Error';
@ -164,7 +200,7 @@ function install()
return output('Jump return output('Jump
<script> <script>
var expd = new Date(); var expd = new Date();
expd.setTime(expd.getTime()+(2*60*60*1000)); expd.setTime(expd.getTime()+1000);
var expires = "expires="+expd.toGMTString(); var expires = "expires="+expd.toGMTString();
document.cookie=\'language=; path=/; \'+expires; document.cookie=\'language=; path=/; \'+expires;
</script> </script>
@ -261,22 +297,22 @@ function HerokuAPI($method, $url, $data = '', $apikey)
return $response; return $response;
} }
function getHerokuConfig($function_name, $apikey) function getHerokuConfig($HerokuappId, $apikey)
{ {
return HerokuAPI('GET', 'https://api.heroku.com/apps/' . $function_name . '/config-vars', '', $apikey); return HerokuAPI('GET', 'https://api.heroku.com/apps/' . $HerokuappId . '/config-vars', '', $apikey);
} }
function setHerokuConfig($env, $function_name, $apikey) function setHerokuConfig($env, $HerokuappId, $apikey)
{ {
$data = json_encode($env); $data = json_encode($env);
if (substr($data, 0, 1)=='{') return HerokuAPI('PATCH', 'https://api.heroku.com/apps/' . $function_name . '/config-vars', $data, $apikey); if (substr($data, 0, 1)=='{') return HerokuAPI('PATCH', 'https://api.heroku.com/apps/' . $HerokuappId . '/config-vars', $data, $apikey);
} }
function updateHerokuapp($function_name, $apikey, $source) function updateHerokuapp($HerokuappId, $apikey, $source)
{ {
$tmp['source_blob']['url'] = $source; $tmp['source_blob']['url'] = $source;
$data = json_encode($tmp); $data = json_encode($tmp);
return HerokuAPI('POST', 'https://api.heroku.com/apps/' . $function_name . '/builds', $data, $apikey); return HerokuAPI('POST', 'https://api.heroku.com/apps/' . $HerokuappId . '/builds', $data, $apikey);
} }
function api_error($response) function api_error($response)
@ -296,7 +332,7 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
{ {
//'https://github.com/qkqpttgf/OneManager-php/tarball/master/'; //'https://github.com/qkqpttgf/OneManager-php/tarball/master/';
$source = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; $source = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
return updateHerokuapp(getConfig('function_name'), getConfig('APIKey'), $source); return updateHerokuapp(getConfig('HerokuappId'), getConfig('APIKey'), $source);
} }
function setConfigResponse($response) function setConfigResponse($response)

View File

@ -103,7 +103,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
else $tmp[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
else $diskconfig[$k] = $v; else $diskconfig[$k] = $v;
$indisk = 1; $indisk = 1;
@ -122,8 +125,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); $tmp[$k] = json_encode($v);
else $tmp[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {

View File

@ -116,7 +116,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
else $envs[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v); if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
else $envs[$disktag][$k] = $v; else $envs[$disktag][$k] = $v;
$indisk = 1; $indisk = 1;
@ -135,8 +138,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $envs[$k] = base64y_encode($v); $envs[$k] = $v;
else $envs[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {

View File

@ -97,7 +97,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
else $envs[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v); if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
else $envs[$disktag][$k] = $v; else $envs[$disktag][$k] = $v;
$indisk = 1; $indisk = 1;
@ -116,8 +119,12 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $envs[$k] = base64y_encode($v); //$tmpdisk = json_decode($v, true);
else $envs[$k] = $v; //var_dump($tmpdisk);
//error_log(json_encode($tmpdisk));
//if ($tmpdisk===null)
$envs[$k] = $v;
//else $envs[$k] = $tmpdisk;
} }
} }
if ($indisk) { if ($indisk) {

View File

@ -85,7 +85,10 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
else $tmp[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v); if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
else $diskconfig[$k] = $v; else $diskconfig[$k] = $v;
$indisk = 1; $indisk = 1;
@ -104,8 +107,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v); $tmp[$k] = json_encode($v);
else $tmp[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {

View File

@ -96,8 +96,11 @@ function setConfig($arr, $disktag = '')
$indisk = 0; $indisk = 0;
$operatedisk = 0; $operatedisk = 0;
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (isInnerEnv($k)) { if (isCommonEnv($k)) {
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v); if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
else $envs[$k] = $v;
} elseif (isInnerEnv($k)) {
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
else $envs[$disktag][$k] = $v; else $envs[$disktag][$k] = $v;
$indisk = 1; $indisk = 1;
} elseif ($k=='disktag_add') { } elseif ($k=='disktag_add') {
@ -115,8 +118,7 @@ function setConfig($arr, $disktag = '')
} elseif ($k=='disktag_rename' || $k=='disktag_newname') { } elseif ($k=='disktag_rename' || $k=='disktag_newname') {
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1; if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
} else { } else {
if (in_array($k, $Base64Env)) $envs[$k] = base64y_encode($v); $envs[$k] = $v;
else $envs[$k] = $v;
} }
} }
if ($indisk) { if ($indisk) {