未验证 提交 9cc257f7 编写于 作者: Q qkqpttgf 提交者: GitHub

refresh token expires in 90 day

上级 db569853
...@@ -17,9 +17,6 @@ function savecache($key, $value, $exp = 3300) ...@@ -17,9 +17,6 @@ function savecache($key, $value, $exp = 3300)
function getconstStr($str) function getconstStr($str)
{ {
global $constStr; global $constStr;
$constStr['language'] = $_COOKIE['language'];
if ($constStr['language']=='') $constStr['language'] = getConfig('language');
if ($constStr['language']=='') $constStr['language'] = 'en-us';
if ($constStr[$str][$constStr['language']]!='') return $constStr[$str][$constStr['language']]; if ($constStr[$str][$constStr['language']]!='') return $constStr[$str][$constStr['language']];
return $constStr[$str]['en-us']; return $constStr[$str]['en-us'];
} }
...@@ -353,7 +350,11 @@ function bigfileupload($path) ...@@ -353,7 +350,11 @@ function bigfileupload($path)
function main($path) function main($path)
{ {
global $exts; global $exts;
global $constStr;
config_oauth(); config_oauth();
$constStr['language'] = $_COOKIE['language'];
if ($constStr['language']=='') $constStr['language'] = getConfig('language');
if ($constStr['language']=='') $constStr['language'] = 'en-us';
$_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);
...@@ -364,6 +365,19 @@ function main($path) ...@@ -364,6 +365,19 @@ function main($path)
$refresh_token = getConfig('refresh_token'); $refresh_token = getConfig('refresh_token');
if (!$refresh_token) return get_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']);
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 {
...@@ -400,19 +414,6 @@ function main($path) ...@@ -400,19 +414,6 @@ function main($path)
} }
$_SERVER['retry'] = 0; $_SERVER['retry'] = 0;
if (!($_SERVER['access_token'] = getcache('access_token'))) {
$ret = json_decode(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
)['body'], true);
if (!isset($ret['access_token'])) {
error_log('failed to get access_token. response' . json_encode($ret));
throw new Exception('failed to get access_token.');
}
$_SERVER['access_token'] = $ret['access_token'];
savecache('access_token', $_SERVER['access_token']);
}
if ($_SERVER['ajax']) { if ($_SERVER['ajax']) {
if ($_GET['action']=='del_upload_cache'&&substr($_GET['filename'],-4)=='.tmp') { if ($_GET['action']=='del_upload_cache'&&substr($_GET['filename'],-4)=='.tmp') {
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件 // del '.tmp' without login. 无需登录即可删除.tmp后缀文件
......
...@@ -66,7 +66,7 @@ function get_refresh_token() ...@@ -66,7 +66,7 @@ function get_refresh_token()
} }
document.cookie=\'language=; path=/\'; document.cookie=\'language=; path=/\';
</script>'; </script>';
setConfig([ 'refresh_token' => $tmptoken ]); setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]);
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="5;URL=' . $url . '">';
......
...@@ -65,7 +65,7 @@ function get_refresh_token() ...@@ -65,7 +65,7 @@ function get_refresh_token()
} }
document.cookie=\'language=; path=/\'; document.cookie=\'language=; path=/\';
</script>'; </script>';
setConfig([ 'refresh_token' => $tmptoken ]); setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]);
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="5;URL=' . $url . '">';
......
...@@ -23,6 +23,7 @@ function GetGlobalVariable($event) ...@@ -23,6 +23,7 @@ function GetGlobalVariable($event)
$pos = strpos($cookievalues,"="); $pos = strpos($cookievalues,"=");
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1)); $_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
} }
$_SERVER['USER'] = 'qcloud';
} }
function GetPathSetting($event, $context) function GetPathSetting($event, $context)
...@@ -100,7 +101,7 @@ function get_refresh_token() ...@@ -100,7 +101,7 @@ function get_refresh_token()
} }
document.cookie=\'language=; path=/\'; document.cookie=\'language=; path=/\';
</script>'; </script>';
setConfig([ 'refresh_token' => $tmptoken ]); setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]);
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 '
......
...@@ -55,17 +55,17 @@ ...@@ -55,17 +55,17 @@
<?php <?php
if (getConfig('admin')!='') if (!$_SERVER['admin']) { if (getConfig('admin')!='') if (!$_SERVER['admin']) {
if (getConfig('adminloginpage')=='') { ?> if (getConfig('adminloginpage')=='') { ?>
<a onclick="login();"><?php echo getconstStr('Login'); ?></a> <a onclick="login();"><ion-icon name="log-in"></ion-icon><?php echo getconstStr('Login'); ?></a>
<?php } <?php }
} else { ?> } else { ?>
<li class="operate"><?php echo getconstStr('Operate'); ?><ul> <li class="operate"><ion-icon name="construct"></ion-icon><?php echo getconstStr('Operate'); ?><ul>
<?php if (isset($files['folder'])) { ?> <?php if (isset($files['folder'])) { ?>
<li><a onclick="showdiv(event,'create','');"><?php echo getconstStr('Create'); ?></a></li> <li><a onclick="showdiv(event,'create','');"><ion-icon name="add-circle"></ion-icon><?php echo getconstStr('Create'); ?></a></li>
<li><a onclick="showdiv(event,'encrypt','');"><?php echo getconstStr('encrypt'); ?></a></li> <li><a onclick="showdiv(event,'encrypt','');"><ion-icon name="lock"></ion-icon><?php echo getconstStr('encrypt'); ?></a></li>
<li><a href="?RefreshCache"><?php echo getconstStr('RefreshCache'); ?></a></li> <li><a href="?RefreshCache"><ion-icon name="refresh"></ion-icon><?php echo getconstStr('RefreshCache'); ?></a></li>
<?php } ?> <?php } ?>
<li><a href="<?php echo $_GET['preview']?'?preview&':'?';?>setup"><?php echo getconstStr('Setup'); ?></a></li> <li><a href="<?php echo $_GET['preview']?'?preview&':'?';?>setup"><ion-icon name="settings"></ion-icon><?php echo getconstStr('Setup'); ?></a></li>
<li><a onclick="logout()"><?php echo getconstStr('Logout'); ?></a></li> <li><a onclick="logout()"><ion-icon name="log-out"></ion-icon><?php echo getconstStr('Logout'); ?></a></li>
</ul></li> </ul></li>
<?php <?php
} ?> } ?>
...@@ -158,8 +158,9 @@ ...@@ -158,8 +158,9 @@
<div id="txt"> <div id="txt">
<?php if ($_SERVER['admin']) { ?> <?php if ($_SERVER['admin']) { ?>
<form id="txt-form" action="" method="POST"> <form id="txt-form" action="" method="POST">
<a onclick="enableedit(this);" id="txt-editbutton"><?php echo getconstStr('ClicktoEdit'); ?></a> <a onclick="document.getElementById('txt-a').readOnly='';document.getElementById('txt-save').style.display='';document.getElementById('txt-editbutton').style.display='none';document.getElementById('txt-cancelbutton').style.display='';" id="txt-editbutton"><ion-icon name="create"></ion-icon><?php echo getconstStr('ClicktoEdit'); ?></a>
<a id="txt-save" style="display:none"><?php echo getconstStr('Save'); ?></a> <a onclick="document.getElementById('txt-a').readOnly='readonly';document.getElementById('txt-save').style.display='none';document.getElementById('txt-editbutton').style.display='';document.getElementById('txt-cancelbutton').style.display='none';" id="txt-cancelbutton" style="display:none"><ion-icon name="close"></ion-icon><?php echo getconstStr('CancelEdit'); ?></a>&nbsp;&nbsp;&nbsp;
<a id="txt-save" style="display:none"><ion-icon name="save"></ion-icon><?php echo getconstStr('Save'); ?></a>
<?php } ?> <?php } ?>
<textarea id="txt-a" name="editfile" readonly style="width: 100%; margin-top: 2px;" <?php if ($_SERVER['admin']) echo 'onchange="document.getElementById(\'txt-save\').onclick=function(){document.getElementById(\'txt-form\').submit();}"';?> ><?php echo $txtstr;?></textarea> <textarea id="txt-a" name="editfile" readonly style="width: 100%; margin-top: 2px;" <?php if ($_SERVER['admin']) echo 'onchange="document.getElementById(\'txt-save\').onclick=function(){document.getElementById(\'txt-form\').submit();}"';?> ><?php echo $txtstr;?></textarea>
<?php if ($_SERVER['admin']) echo '</form>'; ?> <?php if ($_SERVER['admin']) echo '</form>'; ?>
...@@ -180,7 +181,7 @@ ...@@ -180,7 +181,7 @@
$readme = false; ?> $readme = false; ?>
<table class="list-table" id="list-table"> <table class="list-table" id="list-table">
<tr id="tr0"> <tr id="tr0">
<th class="file" onclick="sortby('a');"><?php echo getconstStr('File'); ?>&nbsp;&nbsp;&nbsp;<button onclick="showthumbnails(this);"><?php echo getconstStr('ShowThumbnails'); ?></button></th> <th class="file" onclick="sortby('a');"><?php echo getconstStr('File'); if ($_SERVER['USER']!='qcloud') { ?>&nbsp;&nbsp;&nbsp;<button onclick="showthumbnails(this);"><?php echo getconstStr('ShowThumbnails'); ?></button><?php } ?></th>
<th class="updated_at" width="25%" onclick="sortby('time');"><?php echo getconstStr('EditTime'); ?></th> <th class="updated_at" width="25%" onclick="sortby('time');"><?php echo getconstStr('EditTime'); ?></th>
<th class="size" width="15%" onclick="sortby('size');"><?php echo getconstStr('Size'); ?></th> <th class="size" width="15%" onclick="sortby('size');"><?php echo getconstStr('Size'); ?></th>
</tr> </tr>
...@@ -193,12 +194,12 @@ ...@@ -193,12 +194,12 @@
<tr data-to id="tr<?php echo $filenum;?>"> <tr data-to id="tr<?php echo $filenum;?>">
<td class="file"> <td class="file">
<?php if ($_SERVER['admin']) { ?> <?php if ($_SERVER['admin']) { ?>
<li class="operate"><?php echo getconstStr('Operate'); ?> <li class="operate"><ion-icon name="construct"></ion-icon><?php echo getconstStr('Operate'); ?>
<ul> <ul>
<li><a onclick="showdiv(event,'encrypt',<?php echo $filenum;?>);"><?php echo getconstStr('encrypt'); ?></a></li> <li><a onclick="showdiv(event,'encrypt',<?php echo $filenum;?>);"><ion-icon name="lock"></ion-icon><?php echo getconstStr('encrypt'); ?></a></li>
<li><a onclick="showdiv(event, 'rename',<?php echo $filenum;?>);"><?php echo getconstStr('Rename'); ?></a></li> <li><a onclick="showdiv(event, 'rename',<?php echo $filenum;?>);"><ion-icon name="create"></ion-icon><?php echo getconstStr('Rename'); ?></a></li>
<li><a onclick="showdiv(event, 'move',<?php echo $filenum;?>);"><?php echo getconstStr('Move'); ?></a></li> <li><a onclick="showdiv(event, 'move',<?php echo $filenum;?>);"><ion-icon name="move"></ion-icon><?php echo getconstStr('Move'); ?></a></li>
<li><a onclick="showdiv(event, 'delete',<?php echo $filenum;?>);"><?php echo getconstStr('Delete'); ?></a></li> <li><a onclick="showdiv(event, 'delete',<?php echo $filenum;?>);"><ion-icon name="trash"></ion-icon><?php echo getconstStr('Delete'); ?></a></li>
</ul> </ul>
</li>&nbsp;&nbsp;&nbsp; </li>&nbsp;&nbsp;&nbsp;
<?php } ?> <?php } ?>
...@@ -224,11 +225,11 @@ ...@@ -224,11 +225,11 @@
<tr data-to id="tr<?php echo $filenum;?>"> <tr data-to id="tr<?php echo $filenum;?>">
<td class="file"> <td class="file">
<?php if ($_SERVER['admin']) { ?> <?php if ($_SERVER['admin']) { ?>
<li class="operate"><?php echo getconstStr('Operate'); ?> <li class="operate"><ion-icon name="construct"></ion-icon><?php echo getconstStr('Operate'); ?>
<ul> <ul>
<li><a onclick="showdiv(event, 'rename',<?php echo $filenum;?>);"><?php echo getconstStr('Rename'); ?></a></li> <li><a onclick="showdiv(event, 'rename',<?php echo $filenum;?>);"><ion-icon name="create"></ion-icon><?php echo getconstStr('Rename'); ?></a></li>
<li><a onclick="showdiv(event, 'move',<?php echo $filenum;?>);"><?php echo getconstStr('Move'); ?></a></li> <li><a onclick="showdiv(event, 'move',<?php echo $filenum;?>);"><ion-icon name="move"></ion-icon><?php echo getconstStr('Move'); ?></a></li>
<li><a onclick="showdiv(event, 'delete',<?php echo $filenum;?>);"><?php echo getconstStr('Delete'); ?></a></li> <li><a onclick="showdiv(event, 'delete',<?php echo $filenum;?>);"><ion-icon name="trash"></ion-icon><?php echo getconstStr('Delete'); ?></a></li>
</ul> </ul>
</li>&nbsp;&nbsp;&nbsp; </li>&nbsp;&nbsp;&nbsp;
<?php } <?php }
...@@ -980,12 +981,6 @@ ...@@ -980,12 +981,6 @@
document.cookie = "admin=; path=/"; document.cookie = "admin=; path=/";
location.href = location.href; location.href = location.href;
} }
function enableedit(obj) {
document.getElementById('txt-a').readOnly=!document.getElementById('txt-a').readOnly;
//document.getElementById('txt-editbutton').innerHTML=(document.getElementById('txt-editbutton').innerHTML=='取消编辑')?'点击后编辑':'取消编辑';
obj.innerHTML=(obj.innerHTML=='<?php echo getconstStr('CancelEdit'); ?>')?'<?php echo getconstStr('ClicktoEdit'); ?>':'<?php echo getconstStr('CancelEdit'); ?>';
document.getElementById('txt-save').style.display=document.getElementById('txt-save').style.display==''?'none':'';
}
<?php if (!$_GET['preview']) {?> <?php if (!$_GET['preview']) {?>
function showdiv(event,action,num) { function showdiv(event,action,num) {
var $operatediv=document.getElementsByName('operatediv'); var $operatediv=document.getElementsByName('operatediv');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册