Add files via upload

pull/15/head
qkqpttgf 2020-02-17 02:59:03 -06:00 committed by GitHub
parent 21b966b437
commit 84b8ab523e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 456 additions and 207 deletions

View File

@ -3,14 +3,14 @@
function getcache($str) function getcache($str)
{ {
$cache = null; $cache = null;
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'Onedrive'); $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
return $cache->fetch($str); return $cache->fetch($str);
} }
function savecache($key, $value, $exp = 3300) function savecache($key, $value, $exp = 3300)
{ {
$cache = null; $cache = null;
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'Onedrive'); $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
$cache->save($key, $value, $exp); $cache->save($key, $value, $exp);
} }
@ -375,33 +375,31 @@ function main($path)
{ {
global $exts; global $exts;
global $constStr; global $constStr;
config_oauth(); echo 'main.enterpath:'.$path.'
';
$constStr['language'] = $_COOKIE['language']; $constStr['language'] = $_COOKIE['language'];
if ($constStr['language']=='') $constStr['language'] = getConfig('language'); if ($constStr['language']=='') $constStr['language'] = getConfig('language');
if ($constStr['language']=='') $constStr['language'] = 'en-us'; if ($constStr['language']=='') $constStr['language'] = 'en-us';
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
$disktags = explode("|",getConfig('disktag'));
echo 'count$disk:'.count($disktags);
if (count($disktags)>1) {
if ($path=='/') return output('', 302, [ 'Location' => path_format($_SERVER['PHP_SELF'].'/'.$disktags[0]) ]);
$_SERVER['disktag'] = $path;
$pos = strpos($path, '/');
if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
$path = substr($path, strlen('/'.$_SERVER['disktag']));
} else $_SERVER['disktag'] = $disktags[0];
echo 'main.disktag:'.$_SERVER['disktag'].'path:'.$path.'
';
$_SERVER['base_disk_path'] = $_SERVER['base_path'];
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] .= '/' . $_SERVER['disktag'];
$_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']); $_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/'; if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';
$_SERVER['is_guestup_path'] = is_guestup_path($path); $_SERVER['is_guestup_path'] = is_guestup_path($path);
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $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;
$refresh_token = getConfig('refresh_token');
if (!$refresh_token) return get_refresh_token();
if (!($_SERVER['access_token'] = getcache('access_token'))) {
$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 );
if ($response['stat']==200) $ret = json_decode($response['body'], true);
if (!isset($ret['access_token'])) {
error_log('failed to get access_token. response' . json_encode($ret));
throw new Exception($response['stat'].'failed to get access_token.'.$response['body']);
}
error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
$_SERVER['access_token'] = $ret['access_token'];
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+30*24*60*60 ]);
}
if (getConfig('adminloginpage')=='') { if (getConfig('adminloginpage')=='') {
$adminloginpage = 'admin'; $adminloginpage = 'admin';
} else { } else {
@ -436,6 +434,28 @@ 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 (getConfig('admin')=='') return install();
config_oauth();
if ($_SERVER['admin']) if ($_GET['AddDisk']||$_GET['authorization_code']) return get_refresh_token();
$refresh_token = getConfig('refresh_token');
//if (!$refresh_token) return get_refresh_token();
if (!$refresh_token) {
return render_list();
} else {
if (!($_SERVER['access_token'] = getcache('access_token'))) {
$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 );
if ($response['stat']==200) $ret = json_decode($response['body'], true);
if (!isset($ret['access_token'])) {
error_log('failed to get access_token. response' . json_encode($ret));
throw new Exception($response['stat'].'failed to get access_token.'.$response['body']);
}
error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
$_SERVER['access_token'] = $ret['access_token'];
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+30*24*60*60 ]);
}
$_SERVER['retry'] = 0; $_SERVER['retry'] = 0;
if ($_SERVER['ajax']) { if ($_SERVER['ajax']) {
@ -489,7 +509,8 @@ function main($path)
if ( isset($files['folder']) || isset($files['file']) ) { if ( isset($files['folder']) || isset($files['file']) ) {
return render_list($path, $files); return render_list($path, $files);
} else { } else {
return message('<div style="margin:8px;">' . $files['error']['message'] . '</div><a href="javascript:history.back(-1)">'.getconstStr('Back').'</a>', $files['error']['code'], $files['error']['stat']); return message('<a href="'.$_SERVER['base_path'].'">'.getconstStr('Back').getconstStr('Home').'</a><div style="margin:8px;">' . $files['error']['message'] . '</div><a href="javascript:history.back(-1)">'.getconstStr('Back').'</a>', $files['error']['code'], $files['error']['stat']);
}
} }
} }
@ -842,7 +863,7 @@ function fetch_files_children($files, $path, $page)
return $files; return $files;
} }
function render_list($path, $files) function render_list($path = '', $files = '')
{ {
global $exts; global $exts;
global $constStr; global $constStr;

View File

@ -36,11 +36,75 @@ function getGET()
} }
} }
function getConfig($str, $disktag = '')
{
global $innerEnv;
//include 'config.php';
if ($disktag=='') $disktag = $_SERVER['disktag'];
$s = file_get_contents('config.php');
$configs = substr($s, 18, -2);
if ($configs!='') {
$envs = json_decode($configs, true);
if (in_array($str, $innerEnv)) {
if (isset($envs[$disktag][$str])) return $envs[$disktag][$str];
} else if (isset($envs[$str])) return $envs[$str];
}
return '';
}
function setConfig($arr, $disktag = '')
{
global $innerEnv;
if ($disktag=='') $disktag = $_SERVER['disktag'];
//include 'config.php';
$s = file_get_contents('config.php');
$configs = substr($s, 18, -2);
if ($configs!='') $envs = json_decode($configs, true);
$disktags = explode("|",getConfig('disktag'));
//$indisk = 0;
$oparetdisk = 0;
foreach ($arr as $k => $v) {
if (in_array($k, $innerEnv)) {
$envs[$disktag][$k] = $v;
/*$diskconfig[$k] = $v;
$indisk = 1;*/
} elseif ($k=='disktag_add') {
array_push($disktags, $v);
$oparetdisk = 1;
} elseif ($k=='disktag_del') {
$disktags = array_diff($disktags, [ $v ]);
$envs[$v] = '';
$oparetdisk = 1;
} else {
$envs[$k] = $v;
}
}
/*if ($indisk) {
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
ksort($diskconfig);
$tmp[$disktag] = json_encode($diskconfig);
}*/
if ($oparetdisk) {
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
$envs['disktag'] = substr($disktag_s, 0, -1);
}
$envs = array_filter($envs, 'array_value_isnot_null');
ksort($envs);
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
$prestr = '<?php $configs = \'
';
$aftstr = '
\';';
return file_put_contents('config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
}
function get_refresh_token() function get_refresh_token()
{ {
global $constStr; global $constStr;
$url = path_format($_SERVER['PHP_SELF'] . '/'); $url = path_format($_SERVER['PHP_SELF'] . '/');
if ($_GET['authorization_code'] && isset($_GET['code'])) { if ($_GET['authorization_code'] && 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']); $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 ($tmp['stat']==200) $ret = json_decode($tmp['body'], true);
if (isset($ret['refresh_token'])) { if (isset($ret['refresh_token'])) {
@ -64,17 +128,21 @@ function get_refresh_token()
texta[i].style.height = texta[i].scrollHeight + \'px\'; texta[i].style.height = texta[i].scrollHeight + \'px\';
} }
document.cookie=\'language=; path=/\'; document.cookie=\'language=; path=/\';
document.cookie=\'disktag=; path=/\';
</script>'; </script>';
setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]); setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ], $_COOKIE['disktag']);
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60); savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
$str .= ' $str .= '
<meta http-equiv="refresh" content="5;URL=' . $url . '">'; <meta http-equiv="refresh" content="2;URL=' . $url . '">';
return message($str, getconstStr('WaitJumpIndex')); return message($str, getconstStr('WaitJumpIndex'));
} }
return message('<pre>' . $tmp['body'] . '</pre>', $tmp['stat']); return message('<pre>' . $tmp['body'] . '</pre>', $tmp['stat']);
//return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500); //return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500);
} }
if ($_GET['install3']) { if ($_GET['install1']) {
$_SERVER['disk_oprating'] = $_COOKIE['disktag'];
$_SERVER['disktag'] = $_COOKIE['disktag'];
config_oauth();
if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') { if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') {
return message(' return message('
<a href="" id="a1">'.getconstStr('JumptoOffice').'</a> <a href="" id="a1">'.getconstStr('JumptoOffice').'</a>
@ -88,17 +156,19 @@ function get_refresh_token()
', getconstStr('Wait').' 1s', 201); ', getconstStr('Wait').' 1s', 201);
} }
} }
if ($_GET['install2']) { if ($_GET['install0']) {
// echo $_POST['Onedrive_ver']; if ($_POST['disktag_add']!='' && ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC')) {
if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') { $_SERVER['disktag'] = $_COOKIE['disktag'];
$tmp['disktag_add'] = $_POST['disktag_add'];
$tmp['diskname'] = $_POST['diskname'];
$tmp['Onedrive_ver'] = $_POST['Onedrive_ver']; $tmp['Onedrive_ver'] = $_POST['Onedrive_ver'];
if ($_POST['Onedrive_ver']=='MSC') { if ($_POST['Onedrive_ver']=='MSC') {
$tmp['client_id'] = $_POST['client_id']; $tmp['client_id'] = $_POST['client_id'];
$tmp['client_secret'] = $_POST['client_secret']; $tmp['client_secret'] = $_POST['client_secret'];
} }
$response = setConfig($tmp); $response = setConfig($tmp, $_COOKIE['disktag']);
$title = getconstStr('MayinEnv'); $title = getconstStr('MayinEnv');
$html = getconstStr('Wait') . ' 3s<meta http-equiv="refresh" content="3;URL=' . $url . '?install3">'; $html = getconstStr('Wait') . ' 3s<meta http-equiv="refresh" content="3;URL=' . $url . '?AddDisk&install1">';
if (!$response) { if (!$response) {
$html = $response . '<br> $html = $response . '<br>
Can not write config to file.<br> Can not write config to file.<br>
@ -108,12 +178,7 @@ Can not write config to file.<br>
return message($html, $title, 201); return message($html, $title, 201);
} }
} }
if ($_GET['install1']) {
if ($_POST['admin']!='') {
$tmp['admin'] = $_POST['admin'];
$tmp['language'] = $_POST['language'];
$response = setConfig($tmp);
if ($response) {
if ($constStr['language']!='zh-cn') { if ($constStr['language']!='zh-cn') {
$linklang='en-us'; $linklang='en-us';
} else $linklang='zh-cn'; } else $linklang='zh-cn';
@ -121,7 +186,9 @@ Can not write config to file.<br>
$deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=OneManager&redirectUrl=".$_SERVER['redirect_uri']."&allowImplicitFlow=false&ru=".urlencode($ru); $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); $app_url = "https://apps.dev.microsoft.com/?deepLink=".urlencode($deepLink);
$html = ' $html = '
<form action="?install2" method="post"> <form action="?AddDisk&install0" method="post" onsubmit="return notnull(this);">
Onedrive Disk Tag:<input type="text" name="disktag_add"><br>
Onedrive Disk Name:<input type="text" name="diskname"><br>
Onedrive_Ver<br> Onedrive_Ver<br>
<label><input type="radio" name="Onedrive_ver" value="MS" checked>MS: '.getconstStr('OndriveVerMS').'</label><br> <label><input type="radio" name="Onedrive_ver" value="MS" checked>MS: '.getconstStr('OndriveVerMS').'</label><br>
<label><input type="radio" name="Onedrive_ver" value="CN">CN: '.getconstStr('OndriveVerCN').'</label><br> <label><input type="radio" name="Onedrive_ver" value="CN">CN: '.getconstStr('OndriveVerCN').'</label><br>
@ -133,15 +200,45 @@ Can not write config to file.<br>
</div> </div>
</label><br> </label><br>
<input type="submit" value="'.getconstStr('Submit').'"> <input type="submit" value="'.getconstStr('Submit').'">
</form>'; </form>
$title = 'Install'; <script>
} else { function notnull(t)
{
if (t.disktag_add.value==\'\') {
alert(\'input Disk Tag\');
return false;
}
//t.disktag_add.value=encodeURIComponent(t.disktag_add.value);
var reg = /^[a-zA-Z]([-_a-zA-Z0-9]{2,20})$/;
if (!reg.test(t.disktag_add.value)) {
alert(\'Tag Only letters and numbers, must start with letters!\');
return false;
}
document.cookie=\'disktag=\'+t.disktag_add.value+\'; path=/\';
return true;
}
</script>';
$title = 'Bind Onedrive';
return message($html, $title, 201);
}
function install()
{
global $constStr;
if ($_GET['install1']) {
if ($_POST['admin']!='') {
$tmp['admin'] = $_POST['admin'];
$tmp['language'] = $_POST['language'];
$response = setConfig($tmp);
if (!$response) {
$html = $response . '<br> $html = $response . '<br>
Can not write config to file.<br> Can not write config to file.<br>
<button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>'; <button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>';
$title = 'Error'; $title = 'Error';
}
return message($html, $title, 201); return message($html, $title, 201);
} else {
return output('Jump<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
}
} }
} }
if ($_GET['install0']) { if ($_GET['install0']) {
@ -157,14 +254,19 @@ run Writeable.sh.';
return message($html, $title, 201); return message($html, $title, 201);
} }
$html .= ' $html .= '
<form action="?install1" method="post" onsubmit="return adminnotnull(this);"> <form action="?install1" method="post" onsubmit="return notnull(this);">
language:<br>'; language:<br>';
foreach ($constStr['languages'] as $key1 => $value1) { foreach ($constStr['languages'] as $key1 => $value1) {
$html .= ' $html .= '
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>'; <label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
} }
$html .= '<br> if (getConfig('SecretId')==''||getConfig('SecretKey')=='') $html .= '
<label>admin:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br> <a href="https://console.cloud.tencent.com/cam/capi" target="_blank">'.getconstStr('Create').' SecretId & SecretKey</a><br>
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
$html .= '
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
$html .= '
<input type="submit" value="'.getconstStr('Submit').'"> <input type="submit" value="'.getconstStr('Submit').'">
</form> </form>
<script> <script>
@ -173,19 +275,29 @@ language:<br>';
document.cookie=\'language=\'+str+\'; path=/\'; document.cookie=\'language=\'+str+\'; path=/\';
location.href = location.href; location.href = location.href;
} }
function adminnotnull(t) function notnull(t)
{ {
if (t.admin.value==\'\') { if (t.admin.value==\'\') {
alert(\'input admin\'); alert(\'input admin\');
return false; return false;
}';
if (getConfig('SecretId')==''||getConfig('SecretKey')=='') $html .= '
if (t.SecretId.value==\'\') {
alert(\'input SecretId\');
return false;
} }
if (t.SecretKey.value==\'\') {
alert(\'input SecretKey\');
return false;
}';
$html .= '
return true; return true;
} }
</script>'; </script>';
$title = getconstStr('SelectLanguage'); $title = getconstStr('SelectLanguage');
return message($html, $title, 201); return message($html, $title, 201);
} }
$html .= 'refresh_token not exist, <a href="?install0">click to install.</a>'; $html .= '<a href="?install0">Click to install the project</a>, then login and bind your onedrive.';
$title = 'Error'; $title = 'Error';
return message($html, $title, 201); return message($html, $title, 201);
} }
@ -203,8 +315,7 @@ function ConfigWriteable()
function RewriteEngineOn() function RewriteEngineOn()
{ {
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$tmpurl = $http_type . $_SERVER['SERVER_NAME']; $tmpurl = $http_type . $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
//if $_SERVER['SERVER_PORT']
$tmpurl .= path_format($_SERVER['base_path'] . '/config.php'); $tmpurl .= path_format($_SERVER['base_path'] . '/config.php');
$tmp = curl_request($tmpurl); $tmp = curl_request($tmpurl);
if ($tmp['stat']==200) return false; if ($tmp['stat']==200) return false;
@ -212,65 +323,6 @@ function RewriteEngineOn()
return false; return false;
} }
function getConfig($str)
{
//include 'config.php';
$s = file_get_contents('config.php');
$configs = substr($s, 18, -2);
if ($configs!='') {
$envs = json_decode($configs, true);
if (isset($envs[$str])) return $envs[$str];
}
return '';
/*
if (!class_exists('mydbreader')) {
class mydbreader extends SQLite3
{
function __construct()
{
$this->open( __DIR__ .'/.ht.db');
}
}
}
$db = new mydbreader();
if(!$db){
echo $db->lastErrorMsg();
} else {
//echo "Opened database successfully<br>\n";
$id=rand(1,309);
$sql="select * from config where id=".$str.";";
$ret = $db->query($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {
$row = $ret->fetchArray(SQLITE3_ASSOC);
$value1 = $row['value'];
}
$db->close();
}
return $value1;
*/
}
function setConfig($arr)
{
//include 'config.php';
$s = file_get_contents('config.php');
$configs = substr($s, 18, -2);
if ($configs!='') $envs = json_decode($configs, true);
foreach ($arr as $k1 => $v1) {
$envs[$k1] = $v1;
}
$envs = array_filter($envs, 'array_value_isnot_null');
ksort($envs);
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
$prestr = '<?php $configs = \'
';
$aftstr = '
\';';
return file_put_contents('config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
}
function EnvOpt($function_name, $needUpdate = 0) function EnvOpt($function_name, $needUpdate = 0)
{ {
global $constStr; global $constStr;

View File

@ -1,4 +1,27 @@
<?php <?php
$commonEnv = [
//'Region',
//'SecretId',
//'SecretKey',
//'admin',
'adminloginpage',
//'disktag',
'language',
'passfile',
'sitename',
'theme',
];
$innerEnv = [
'Onedrive_ver',
'client_id',
'client_secret',
'domain_path',
'guestup_path',
'diskname',
'public_path',
'refresh_token',
'token_expires',
];
function printInput($event, $context) function printInput($event, $context)
{ {
@ -51,20 +74,70 @@ function GetPathSetting($event, $context)
return $path; return $path;
} }
function getConfig($str) function getConfig($str, $disktag = '')
{ {
global $innerEnv;
if ($disktag=='') $disktag = $_SERVER['disktag'];
if (in_array($str, $innerEnv)) {
return json_decode(getenv($disktag), true)[$str];
$a=getenv($_SERVER['disktag']);
echo $str.''.$a.'';
$b = json_decode($a, true);
echo json_encode($b[$str], JSON_PRETTY_PRINT).'
';
return $b[$str];
}
return getenv($str); return getenv($str);
} }
function setConfig($arr) function setConfig($arr, $disktag = '')
{ {
//$function_name, $Region, $Namespace, $SecretId, $SecretKey echo '进入设置:'.json_encode($arr,JSON_PRETTY_PRINT).'
$function_name = $_SERVER['function_name']; ';
$Region = $_SERVER['Region']; global $innerEnv;
$Namespace = $_SERVER['namespace']; if ($disktag=='') $disktag = $_SERVER['disktag'];
$SecretId = getConfig('SecretId'); //$disktags = json_decode(getConfig('disktag'), true);
$SecretKey = getConfig('SecretKey'); //if ($_SERVER['disk_oprating']) $disktag = $_SERVER['disk_oprating'];
return updateEnvironment($arr, $function_name, $Region, $Namespace, $SecretId, $SecretKey); //else $disktag = $_SERVER['disktag'];
$disktags = explode("|",getConfig('disktag'));
$diskconfig = json_decode(getenv($disktag), true);
$tmp = [];
$indisk = 0;
$oparetdisk = 0;
foreach ($arr as $k => $v) {
if (in_array($k, $innerEnv)) {
$diskconfig[$k] = $v;
$indisk = 1;
} elseif ($k=='disktag_add') {
array_push($disktags, $v);
$oparetdisk = 1;
} elseif ($k=='disktag_del') {
$disktags = array_diff($disktags, [ $v ]);
$tmp[$v] = '';
$oparetdisk = 1;
} else {
$tmp[$k] = $v;
}
}
if ($indisk) {
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
ksort($diskconfig);
$tmp[$disktag] = json_encode($diskconfig);
}
if ($oparetdisk) {
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
$tmp['disktag'] = substr($disktag_s, 0, -1);
}
echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
';
return updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
}
function WaitSCFStat()
{
$trynum = 0;
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
'.++$trynum;
} }
function get_refresh_token() function get_refresh_token()
@ -72,6 +145,8 @@ function get_refresh_token()
global $constStr; global $constStr;
$url = path_format($_SERVER['PHP_SELF'] . '/'); $url = path_format($_SERVER['PHP_SELF'] . '/');
if ($_GET['authorization_code'] && isset($_GET['code'])) { if ($_GET['authorization_code'] && 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']); $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 ($tmp['stat']==200) $ret = json_decode($tmp['body'], true);
if (isset($ret['refresh_token'])) { if (isset($ret['refresh_token'])) {
@ -95,8 +170,9 @@ function get_refresh_token()
texta[i].style.height = texta[i].scrollHeight + \'px\'; texta[i].style.height = texta[i].scrollHeight + \'px\';
} }
document.cookie=\'language=; path=/\'; document.cookie=\'language=; path=/\';
document.cookie=\'disktag=; path=/\';
</script>'; </script>';
setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]); setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ], $_COOKIE['disktag']);
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60); savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
$trynum = 0; $trynum = 0;
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo ' while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
@ -108,7 +184,10 @@ function get_refresh_token()
return message('<pre>' . $tmp['body'] . '</pre>', $tmp['stat']); return message('<pre>' . $tmp['body'] . '</pre>', $tmp['stat']);
//return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500); //return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500);
} }
if ($_GET['install3']) { if ($_GET['install1']) {
$_SERVER['disk_oprating'] = $_COOKIE['disktag'];
$_SERVER['disktag'] = $_COOKIE['disktag'];
config_oauth();
if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') { if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') {
return message(' return message('
<a href="" id="a1">'.getconstStr('JumptoOffice').'</a> <a href="" id="a1">'.getconstStr('JumptoOffice').'</a>
@ -122,17 +201,19 @@ function get_refresh_token()
', getconstStr('Wait').' 1s', 201); ', getconstStr('Wait').' 1s', 201);
} }
} }
if ($_GET['install2']) { if ($_GET['install0']) {
// echo $_POST['Onedrive_ver']; if ($_POST['disktag_add']!='' && ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC')) {
if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') { $_SERVER['disktag'] = $_COOKIE['disktag'];
$tmp['disktag_add'] = $_POST['disktag_add'];
$tmp['diskname'] = $_POST['diskname'];
$tmp['Onedrive_ver'] = $_POST['Onedrive_ver']; $tmp['Onedrive_ver'] = $_POST['Onedrive_ver'];
if ($_POST['Onedrive_ver']=='MSC') { if ($_POST['Onedrive_ver']=='MSC') {
$tmp['client_id'] = $_POST['client_id']; $tmp['client_id'] = $_POST['client_id'];
$tmp['client_secret'] = $_POST['client_secret']; $tmp['client_secret'] = $_POST['client_secret'];
} }
$response = json_decode( setConfig($tmp), true )['Response']; $response = json_decode( setConfig($tmp, $_COOKIE['disktag']), true )['Response'];
$title = getconstStr('MayinEnv'); $title = getconstStr('MayinEnv');
$html = getconstStr('Wait') . ' 3s<meta http-equiv="refresh" content="3;URL=' . $url . '?install3">'; $html = getconstStr('Wait') . ' 3s<meta http-equiv="refresh" content="3;URL=' . $url . '?AddDisk&install1">';
if (isset($response['Error'])) { if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '<br> $html = $response['Error']['Code'] . '<br>
' . $response['Error']['Message'] . '<br><br> ' . $response['Error']['Message'] . '<br><br>
@ -145,6 +226,53 @@ namespace:' . $_SERVER['namespace'] . '<br>
return message($html, $title, 201); 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 = '
<form action="?AddDisk&install0" method="post" onsubmit="return notnull(this);">
Onedrive Disk Tag:<input type="text" name="disktag_add"><br>
Onedrive Disk Name:<input type="text" name="diskname"><br>
Onedrive_Ver<br>
<label><input type="radio" name="Onedrive_ver" value="MS" checked>MS: '.getconstStr('OndriveVerMS').'</label><br>
<label><input type="radio" name="Onedrive_ver" value="CN">CN: '.getconstStr('OndriveVerCN').'</label><br>
<label><input type="radio" name="Onedrive_ver" value="MSC" onclick="document.getElementById(\'secret\').style.display=\'\';">MSC: '.getconstStr('OndriveVerMSC').'
<div id="secret" style="display:none">
<a href="'.$app_url.'" target="_blank">'.getconstStr('GetSecretIDandKEY').'</a><br>
client_secret:<input type="text" name="client_secret"><br>
client_id(12345678-90ab-cdef-ghij-klmnopqrstuv):<input type="text" name="client_id"><br>
</div>
</label><br>
<input type="submit" value="'.getconstStr('Submit').'">
</form>
<script>
function notnull(t)
{
if (t.disktag_add.value==\'\') {
alert(\'input Disk Tag\');
return false;
}
//t.disktag_add.value=encodeURIComponent(t.disktag_add.value);
var reg = /^[a-zA-Z]([-_a-zA-Z0-9]{2,20})$/;
if (!reg.test(t.disktag_add.value)) {
alert(\'Tag Only letters and numbers, must start with letters!\');
return false;
}
document.cookie=\'disktag=\'+t.disktag_add.value+\'; path=/\';
return true;
}
</script>';
$title = 'Bind Onedrive';
return message($html, $title, 201);
}
function install()
{
global $constStr;
if ($_GET['install1']) { if ($_GET['install1']) {
if ($_POST['admin']!='') { if ($_POST['admin']!='') {
$tmp['admin'] = $_POST['admin']; $tmp['admin'] = $_POST['admin'];
@ -159,8 +287,7 @@ namespace:' . $_SERVER['namespace'] . '<br>
$SecretKey = $_POST['SecretKey']; $SecretKey = $_POST['SecretKey'];
$tmp['SecretKey'] = $SecretKey; $tmp['SecretKey'] = $SecretKey;
} }
echo SetbaseConfig($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey); $response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
$response = json_decode( updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
if (isset($response['Error'])) { if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '<br> $html = $response['Error']['Code'] . '<br>
' . $response['Error']['Message'] . '<br><br> ' . $response['Error']['Message'] . '<br><br>
@ -170,34 +297,15 @@ namespace:' . $_SERVER['namespace'] . '<br>
<button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>'; <button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>';
$title = 'Error'; $title = 'Error';
} else { } else {
if (needUpdate()) {
$trynum = 0; $trynum = 0;
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo ' while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
'.++$trynum; '.++$trynum;
//$response = json_decode( updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
if (needUpdate()) {
updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey); updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey);
return message('update to github version, reinstall.<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201); return message('update to github version, reinstall.<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
} }
if ($constStr['language']!='zh-cn') { return output('Jump<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
$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 = '
<form action="?install2" method="post">
Onedrive_Ver<br>
<label><input type="radio" name="Onedrive_ver" value="MS" checked>MS: '.getconstStr('OndriveVerMS').'</label><br>
<label><input type="radio" name="Onedrive_ver" value="CN">CN: '.getconstStr('OndriveVerCN').'</label><br>
<label><input type="radio" name="Onedrive_ver" value="MSC" onclick="document.getElementById(\'secret\').style.display=\'\';">MSC: '.getconstStr('OndriveVerMSC').'
<div id="secret" style="display:none">
<a href="'.$app_url.'" target="_blank">'.getconstStr('GetSecretIDandKEY').'</a><br>
client_secret:<input type="text" name="client_secret"><br>
client_id(12345678-90ab-cdef-ghij-klmnopqrstuv):<input type="text" name="client_id"><br>
</div>
</label><br>
<input type="submit" value="'.getconstStr('Submit').'">
</form>';
$title = 'Install';
} }
return message($html, $title, 201); return message($html, $title, 201);
} }
@ -215,7 +323,7 @@ language:<br>';
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br> <label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>'; <label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
$html .= ' $html .= '
<label>admin:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>'; <label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
$html .= ' $html .= '
<input type="submit" value="'.getconstStr('Submit').'"> <input type="submit" value="'.getconstStr('Submit').'">
</form> </form>
@ -247,7 +355,7 @@ language:<br>';
$title = getconstStr('SelectLanguage'); $title = getconstStr('SelectLanguage');
return message($html, $title, 201); return message($html, $title, 201);
} }
$html .= 'refresh_token not exist, <a href="?install0">click to install.</a>'; $html .= '<a href="?install0">Click to install the project</a>, then login and bind your onedrive.';
$title = 'Error'; $title = 'Error';
return message($html, $title, 201); return message($html, $title, 201);
} }
@ -305,9 +413,7 @@ function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $Secret
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey) function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
{ {
//print_r($Envs); //print_r($Envs);
$trynum = 0; WaitSCFStat();
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
'.++$trynum;
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key'] //json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables']; $tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
foreach ($tmp as $tmp1) { foreach ($tmp as $tmp1) {
@ -343,15 +449,34 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr)); return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
} }
function SetbaseConfig($function_name, $Region, $Namespace, $SecretId, $SecretKey) function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
{ {
echo json_encode($Envs,JSON_PRETTY_PRINT);
$trynum = 0;
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
'.++$trynum;
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
foreach ($tmp as $tmp1) {
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
}
foreach ($Envs as $key1 => $value1) {
$tmp_env[$key1] = $value1;
}
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
$tmp_env['Region'] = $Region;
ksort($tmp_env);
$i = 0;
foreach ($tmp_env as $key1 => $value1) {
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
$i++;
}
$meth = 'POST'; $meth = 'POST';
$host = 'scf.tencentcloudapi.com'; $host = 'scf.tencentcloudapi.com';
$tmpdata['Action'] = 'UpdateFunctionConfiguration'; $tmpdata['Action'] = 'UpdateFunctionConfiguration';
$tmpdata['FunctionName'] = $function_name; $tmpdata['FunctionName'] = $function_name;
$tmpdata['Description'] = 'Onedrive index & manager in SCF.';
$tmpdata['MemorySize'] = 64;
$tmpdata['Timeout'] = 30;
$tmpdata['Namespace'] = $Namespace; $tmpdata['Namespace'] = $Namespace;
$tmpdata['Nonce'] = time(); $tmpdata['Nonce'] = time();
$tmpdata['Region'] = $Region; $tmpdata['Region'] = $Region;
@ -359,7 +484,11 @@ function SetbaseConfig($function_name, $Region, $Namespace, $SecretId, $SecretKe
$tmpdata['Timestamp'] = time(); $tmpdata['Timestamp'] = time();
$tmpdata['Token'] = ''; $tmpdata['Token'] = '';
$tmpdata['Version'] = '2018-04-16'; $tmpdata['Version'] = '2018-04-16';
$tmpdata['Description'] = 'Onedrive index and manager in SCF.';
$tmpdata['MemorySize'] = 64;
$tmpdata['Timeout'] = 30;
$data = ReorganizeDate($tmpdata); $data = ReorganizeDate($tmpdata);
echo $data;
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true)); $signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
//echo urlencode($signStr); //echo urlencode($signStr);
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr)); return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
@ -367,6 +496,7 @@ function SetbaseConfig($function_name, $Region, $Namespace, $SecretId, $SecretKe
function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey) function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey)
{ {
WaitSCFStat();
$meth = 'POST'; $meth = 'POST';
$host = 'scf.tencentcloudapi.com'; $host = 'scf.tencentcloudapi.com';
$tmpdata['Action'] = 'UpdateFunctionCode'; $tmpdata['Action'] = 'UpdateFunctionCode';
@ -391,13 +521,10 @@ function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKe
function EnvOpt($function_name, $needUpdate = 0) function EnvOpt($function_name, $needUpdate = 0)
{ {
global $constStr; global $constStr;
$constEnv = [ global $commonEnv;
//'admin', global $innerEnv;
'adminloginpage', 'domain_path', 'guestup_path', 'passfile', asort($commonEnv);
//'private_path', asort($innerEnv);
'public_path', 'sitename', 'language', 'theme'
];
asort($constEnv);
$html = '<title>OneManager '.getconstStr('Setup').'</title>'; $html = '<title>OneManager '.getconstStr('Setup').'</title>';
if ($_POST['updateProgram']==getconstStr('updateProgram')) { if ($_POST['updateProgram']==getconstStr('updateProgram')) {
$response = json_decode(updateProgram($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')), true)['Response']; $response = json_decode(updateProgram($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')), true)['Response'];
@ -410,9 +537,7 @@ namespace:' . $namespace . '<br>
<button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>'; <button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>';
$title = 'Error'; $title = 'Error';
} else { } else {
$trynum = 0; WaitSCFStat();
while( json_decode(getfunctioninfo($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
'.++$trynum;
$html .= getconstStr('UpdateSuccess') . '<br> $html .= getconstStr('UpdateSuccess') . '<br>
<button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>'; <button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>';
$title = getconstStr('Setup'); $title = getconstStr('Setup');
@ -420,11 +545,12 @@ namespace:' . $namespace . '<br>
return message($html, $title); return message($html, $title);
} }
if ($_POST['submit1']) { if ($_POST['submit1']) {
$_SERVER['disk_oprating'] = '';
foreach ($_POST as $k => $v) { foreach ($_POST as $k => $v) {
if (in_array($k, $constEnv)) { if (in_array($k, $commonEnv)||in_array($k, $innerEnv)||$k=='disktag_del' || $k=='disktag_add') {
//if (!(getConfig($k)==''&&$v==''))
$tmp[$k] = $v; $tmp[$k] = $v;
} }
if ($k == 'disk') $_SERVER['disk_oprating'] = $v;
} }
/*if ($tmp['domain_path']!='') { /*if ($tmp['domain_path']!='') {
$tmp1 = explode("|",$tmp['domain_path']); $tmp1 = explode("|",$tmp['domain_path']);
@ -435,7 +561,7 @@ namespace:' . $namespace . '<br>
} }
$tmp['domain_path'] = $tmparr; $tmp['domain_path'] = $tmparr;
}*/ }*/
$response = json_decode( setConfig($tmp), true )['Response']; $response = json_decode( setConfig($tmp, $_SERVER['disk_oprating']), true )['Response'];
if (isset($response['Error'])) { if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '<br> $html = $response['Error']['Code'] . '<br>
' . $response['Error']['Message'] . '<br><br> ' . $response['Error']['Message'] . '<br><br>
@ -445,11 +571,9 @@ namespace:' . $_SERVER['namespace'] . '<br>
<button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>'; <button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>';
$title = 'Error'; $title = 'Error';
} else { } else {
$trynum = 0; WaitSCFStat();
while( json_decode(getfunctioninfo($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
'.++$trynum;
//sleep(3); //sleep(3);
$html .= '<script>location.href=location.href</script>'; $html .= json_encode($response,JSON_PRETTY_PRINT).'<script>location.href=location.href</script>';
$title = getconstStr('Setup'); $title = getconstStr('Setup');
} }
return message($html, $title); return message($html, $title);
@ -471,9 +595,12 @@ namespace:' . $_SERVER['namespace'] . '<br>
$html .= getconstStr('NotNeedUpdate'); $html .= getconstStr('NotNeedUpdate');
} }
$html .= ' $html .= '
<form action="" method="post"> <form name="common" action="" method="post">
<table border=1 width=100%>'; <table border=1 width=100%>
foreach ($constEnv as $key) { <tr>
<td colspan="2">平台变量:</td>
</tr>';
foreach ($commonEnv as $key) {
if ($key=='language') { if ($key=='language') {
$html .= ' $html .= '
<tr> <tr>
@ -522,8 +649,38 @@ namespace:' . $_SERVER['namespace'] . '<br>
<td width=100%><input type="text" name="' . $key .'" value="' . getConfig($key) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td> <td width=100%><input type="text" name="' . $key .'" value="' . getConfig($key) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td>
</tr>'; </tr>';
} }
$html .= '</table> $html .= '
<input type="submit" name="submit1" value="'.getconstStr('Setup').'"> <tr><td><input type="submit" name="submit1" value="'.getconstStr('Setup').'"></td></tr>
</table>
</form>'; </form>';
foreach (explode("|",getConfig('disktag')) as $disktag) {
if ($disktag!='') {
$html .= '
<table border=1 width=100%>
<form action="" method="post">
<tr>
<td colspan="2">'.$disktag.'
<input type="hidden" name="disktag_del" value="'.$disktag.'">
<input type="submit" name="submit1" value="Del disk">
</td>
</tr>
</form>
<form name="'.$disktag.'" action="" method="post">
<input type="hidden" name="disk" value="'.$disktag.'">';
foreach ($innerEnv as $key) {
$html .= '
<tr>
<td><label>' . $key . '</label></td>
<td width=100%><input type="text" name="' . $key .'" value="' . getConfig($key, $disktag) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td>
</tr>';
}
$html .= '
<tr><td><input type="submit" name="submit1" value="'.getconstStr('Setup').'"></td></tr>
</form>
</table>';
}
}
$html .= '
<a href="?AddDisk">Add Disk</a>';
return message($html, getconstStr('Setup')); return message($html, getconstStr('Setup'));
} }

View File

@ -46,7 +46,7 @@ function main_handler($event, $context)
unset($_SERVER); unset($_SERVER);
GetGlobalVariable($event); GetGlobalVariable($event);
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
config_oauth();
$path = GetPathSetting($event, $context); $path = GetPathSetting($event, $context);
return main($path); return main($path);
} }

View File

@ -7,8 +7,8 @@
<meta http-equiv=X-UA-Compatible content="IE=edge"> <meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1"> <meta name=viewport content="width=device-width,initial-scale=1">
<meta name="keywords" content="<?php echo $n_path;?>,<?php if ($p_path!='') echo $p_path.','; echo $_SERVER['sitename'];?>,OneManager,auth_by_逸笙"> <meta name="keywords" content="<?php echo $n_path;?>,<?php if ($p_path!='') echo $p_path.','; echo $_SERVER['sitename'];?>,OneManager,auth_by_逸笙">
<link rel="icon" href="<?php echo $_SERVER['base_path'];?>favicon.ico" type="image/x-icon" /> <link rel="icon" href="<?php echo $_SERVER['base_disk_path'];?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $_SERVER['base_path'];?>favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="<?php echo $_SERVER['base_disk_path'];?>favicon.ico" type="image/x-icon" />
<style type="text/css"> <style type="text/css">
body{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:1em;background-color:#f7f7f9;color:#000} body{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:1em;background-color:#f7f7f9;color:#000}
a{color:#24292e;cursor:pointer;text-decoration:none} a{color:#24292e;cursor:pointer;text-decoration:none}
@ -53,7 +53,7 @@
} }
</style> </style>
</head> </head>
<?php //echo '<pre>'.json_encode($files, JSON_PRETTY_PRINT).'</pre>'; ?>
<body> <body>
<div style="padding:1px"> <div style="padding:1px">
<?php <?php
@ -90,6 +90,21 @@
<h1 class="title"> <h1 class="title">
<a href="<?php echo $_SERVER['base_path']; ?>"><?php echo $_SERVER['sitename']; ?></a> <a href="<?php echo $_SERVER['base_path']; ?>"><?php echo $_SERVER['sitename']; ?></a>
</h1> </h1>
<?php $disktags = explode("|",getConfig('disktag'));
if (count($disktags)>1) { ?>
<div class="list-wrapper" id="list-div">
<div class="list-container">
<div class="list-header-container">
<?php foreach ($disktags as $disk) {
$diskname = getConfig('diskname', $disk);
if ($diskname=='') $diskname = $disk;
echo '<a href="'.path_format($_SERVER['base_path'].'/'.$disk).'">'.$diskname.'</a>&nbsp&nbsp';
} ?>
</div>
</div>
</div>
<?php }
if ($files) { ?>
<div class="list-wrapper" id="list-div"> <div class="list-wrapper" id="list-div">
<div class="list-container"> <div class="list-container">
<div class="list-header-container"> <div class="list-header-container">
@ -130,8 +145,8 @@
?> ?>
<div style="margin: 12px 4px 4px; text-align: center"> <div style="margin: 12px 4px 4px; text-align: center">
<div style="margin: 24px"> <div style="margin: 24px">
<textarea id="url" title="url" rows="1" style="width: 100%; margin-top: 2px;" readonly><?php echo str_replace('%2523', '%23', str_replace('%26amp%3B','&amp;',spurlencode(path_format($_SERVER['base_path'] . '/' . $path), '/'))); ?></textarea> <textarea id="url" title="url" rows="1" style="width: 100%; margin-top: 2px;" readonly><?php echo str_replace('%2523', '%23', str_replace('%26amp%3B','&amp;',spurlencode(path_format($_SERVER['base_disk_path'] . '/' . $path), '/'))); ?></textarea>
<a href="<?php echo path_format($_SERVER['base_path'] . '/' . $path);//$files['@microsoft.graph.downloadUrl'] ?>"><ion-icon name="download" style="line-height: 16px;vertical-align: middle;"></ion-icon>&nbsp;<?php echo getconstStr('Download'); ?></a> <a href="<?php echo path_format($_SERVER['base_disk_path'] . '/' . $path);//$files['@microsoft.graph.downloadUrl'] ?>"><ion-icon name="download" style="line-height: 16px;vertical-align: middle;"></ion-icon>&nbsp;<?php echo getconstStr('Download'); ?></a>
</div> </div>
<div style="margin: 24px"> <div style="margin: 24px">
<?php $ext = strtolower(substr($path, strrpos($path, '.') + 1)); <?php $ext = strtolower(substr($path, strrpos($path, '.') + 1));
@ -210,7 +225,7 @@
</li>&nbsp;&nbsp;&nbsp; </li>&nbsp;&nbsp;&nbsp;
<?php } ?> <?php } ?>
<ion-icon name="folder"></ion-icon> <ion-icon name="folder"></ion-icon>
<a id="file_a<?php echo $filenum;?>" href="<?php echo path_format($_SERVER['base_path'] . '/' . $path . '/' . encode_str_replace($file['name']) . '/'); ?>"><?php echo str_replace('&','&amp;', $file['name']);?></a> <a id="file_a<?php echo $filenum;?>" href="<?php echo path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . encode_str_replace($file['name']) . '/'); ?>"><?php echo str_replace('&','&amp;', $file['name']);?></a>
</td> </td>
<td class="updated_at" id="folder_time<?php echo $filenum;?>"><?php echo time_format($file['lastModifiedDateTime']); ?></td> <td class="updated_at" id="folder_time<?php echo $filenum;?>"><?php echo time_format($file['lastModifiedDateTime']); ?></td>
<td class="size" id="folder_size<?php echo $filenum;?>"><?php echo size_format($file['size']); ?></td> <td class="size" id="folder_size<?php echo $filenum;?>"><?php echo size_format($file['size']); ?></td>
@ -262,8 +277,8 @@
<?php } else { ?> <?php } else { ?>
<ion-icon name="document"></ion-icon> <ion-icon name="document"></ion-icon>
<?php } ?> <?php } ?>
<a id="file_a<?php echo $filenum;?>" name="filelist" href="<?php echo path_format($_SERVER['base_path'] . '/' . $path . '/' . encode_str_replace($file['name'])); ?>?preview" target=_blank><?php echo str_replace('&','&amp;', $file['name']); ?></a> <a id="file_a<?php echo $filenum;?>" name="filelist" href="<?php echo path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . encode_str_replace($file['name'])); ?>?preview" target=_blank><?php echo str_replace('&','&amp;', $file['name']); ?></a>
<a href="<?php echo path_format($_SERVER['base_path'] . '/' . $path . '/' . str_replace('&','&amp;', $file['name']));?>"><ion-icon name="download"></ion-icon></a> <a href="<?php echo path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . str_replace('&','&amp;', $file['name']));?>"><ion-icon name="download"></ion-icon></a>
</td> </td>
<td class="updated_at" id="file_time<?php echo $filenum;?>"><?php echo time_format($file['lastModifiedDateTime']); ?></td> <td class="updated_at" id="file_time<?php echo $filenum;?>"><?php echo time_format($file['lastModifiedDateTime']); ?></td>
<td class="size" id="file_size<?php echo $filenum;?>"><?php echo size_format($file['size']); ?></td> <td class="size" id="file_size<?php echo $filenum;?>"><?php echo size_format($file['size']); ?></td>
@ -380,6 +395,7 @@
</div> </div>
</div> </div>
</div> </div>
<?php } ?>
<div id="mask" class="mask" style="display:none;"></div> <div id="mask" class="mask" style="display:none;"></div>
<?php <?php
if ($_SERVER['admin']) { if ($_SERVER['admin']) {
@ -492,13 +508,15 @@
} ?> } ?>
<font color="#f7f7f9"><?php echo date("Y-m-d H:i:s")." ".getconstStr('Week')[date("w")]." ".$_SERVER['REMOTE_ADDR'];?></font> <font color="#f7f7f9"><?php echo date("Y-m-d H:i:s")." ".getconstStr('Week')[date("w")]." ".$_SERVER['REMOTE_ADDR'];?></font>
</body> </body>
<?php if ($files) { ?>
<?php if ($head||$readme) { ?><link rel="stylesheet" href="//unpkg.zhimg.com/github-markdown-css@3.0.1/github-markdown.css"> <?php if ($head||$readme) { ?><link rel="stylesheet" href="//unpkg.zhimg.com/github-markdown-css@3.0.1/github-markdown.css">
<script type="text/javascript" src="//unpkg.zhimg.com/marked@0.6.2/marked.min.js"></script><?php } ?> <script type="text/javascript" src="//unpkg.zhimg.com/marked@0.6.2/marked.min.js"></script><?php } ?>
<?php if (isset($files['folder']) && $_SERVER['is_guestup_path'] && !$_SERVER['admin']) { ?><script type="text/javascript" src="//cdn.bootcss.com/spark-md5/3.0.0/spark-md5.min.js"></script><?php } ?> <?php if (isset($files['folder']) && $_SERVER['is_guestup_path'] && !$_SERVER['admin']) { ?><script type="text/javascript" src="//cdn.bootcss.com/spark-md5/3.0.0/spark-md5.min.js"></script><?php } ?>
<?php if ($pdfurl!='') { ?><script src="//cdn.bootcss.com/pdf.js/2.3.200/pdf.min.js"></script><?php } ?> <?php if ($pdfurl!='') { ?><script src="//cdn.bootcss.com/pdf.js/2.3.200/pdf.min.js"></script><?php } ?>
<?php } ?>
<script type="text/javascript"> <script type="text/javascript">
var root = '<?php echo $_SERVER["base_path"]; ?>'; <?php if ($files) { ?>
var root = '<?php echo $_SERVER["base_disk_path"]; ?>';
function path_format(path) { function path_format(path) {
path = '/' + path + '/'; path = '/' + path + '/';
while (path.indexOf('//') !== -1) { while (path.indexOf('//') !== -1) {
@ -777,12 +795,6 @@
document.getElementById('pagenum').value=num; document.getElementById('pagenum').value=num;
document.getElementById('nextpageform').submit(); document.getElementById('nextpageform').submit();
} }
<?php }
if (getConfig('admin')!='') { // close div. 有登录或操作需要关闭DIV时 ?>
function operatediv_close(operate) {
document.getElementById(operate+'_div').style.display='none';
document.getElementById('mask').style.display='none';
}
<?php } <?php }
if (isset($files['folder']) && ($_SERVER['is_guestup_path'] || $_SERVER['admin'])) { // is folder and is admin or guest upload path. 当前是admin登录或图床目录时 ?> if (isset($files['folder']) && ($_SERVER['is_guestup_path'] || $_SERVER['admin'])) { // is folder and is admin or guest upload path. 当前是admin登录或图床目录时 ?>
function uploadbuttonhide() { function uploadbuttonhide() {
@ -1006,6 +1018,13 @@
} }
} }
} }
<?php }
}
if (getConfig('admin')!='') { // close div. 有登录或操作需要关闭DIV时 ?>
function operatediv_close(operate) {
document.getElementById(operate+'_div').style.display='none';
document.getElementById('mask').style.display='none';
}
<?php } <?php }
if ($_SERVER['admin']) { // admin login. 管理登录后 ?> if ($_SERVER['admin']) { // admin login. 管理登录后 ?>
function logout() { function logout() {