* Update index.php

* Update common.php

* Update and rename scf.php to tencentscf.php

* Create alifc.php

* Update common.php

* Update alifc.php

* Update alifc.php

* Update alifc.php

* Update normal.php

* Update common.php

* Update common.php

* Update conststr.php

* Update normal.php

* Update normal.php

* Update conststr.php

* Update index.php

* Update common.php

* Rename alifc.php to AliyunFC.php

* Rename heroku.php to Heroku.php

* Rename normal.php to Normal.php

* Rename tencentscf.php to TencentSCF.php

* Update common.php

* Update conststr.php

* Update common.php

* Update common.php

* Update common.php
pull/77/head
qkqpttgf 2020-06-07 18:43:47 +08:00 committed by GitHub
parent 7f07ab1b38
commit 53f88aa506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 645 additions and 33 deletions

View File

@ -5,6 +5,8 @@ $Base64Env = [
//'Region', // used in SCF.
//'SecretId', // used in SCF.
//'SecretKey', // used in SCF.
//'AccessKeyID', // used in FC.
//'AccessKeySecret', // used in FC.
//'admin',
//'adminloginpage',
'background',
@ -33,6 +35,7 @@ $Base64Env = [
//'sharecookie',
'shareapiurl',
//'siteid',
'domainforproxy',
'public_path',
//'refresh_token',
//'token_expires',
@ -43,6 +46,8 @@ $CommonEnv = [
'Region', // used in SCF.
'SecretId', // used in SCF.
'SecretKey', // used in SCF.
'AccessKeyID', // used in FC.
'AccessKeySecret', // used in FC.
'admin',
'adminloginpage',
'background',
@ -64,6 +69,8 @@ $ShowedCommonEnv = [
//'Region', // used in SCF.
//'SecretId', // used in SCF.
//'SecretKey', // used in SCF.
//'AccessKeyID', // used in FC.
//'AccessKeySecret', // used in FC.
//'admin',
'adminloginpage',
'background',
@ -95,6 +102,7 @@ $InnerEnv = [
'shareurl',
//'sharecookie',
'shareapiurl',
'domainforproxy',
'public_path',
'refresh_token',
'token_expires',
@ -115,6 +123,7 @@ $ShowedInnerEnv = [
//'shareurl',
//'sharecookie',
//'shareapiurl',
'domainforproxy',
'public_path',
//'refresh_token',
//'token_expires',
@ -317,6 +326,10 @@ function main($path)
$files = list_files($path);
//echo json_encode(array_keys($files['children']), JSON_PRETTY_PRINT);
if ($_GET['json']) {
// return a json
return files_json($files);
}
if (isset($_GET['random'])&&$_GET['random']!=='') {
if ($_SERVER['ishidden']<4) {
$tmp = [];
@ -325,14 +338,29 @@ function main($path)
}
$tmp = array_values($tmp);
if (count($tmp)>0) {
if (isset($_GET['url'])) return output($tmp[rand(0,count($tmp)-1)], 200);
return output('', 302, [ 'Location' => $tmp[rand(0,count($tmp)-1)] ]);
$url = $tmp[rand(0,count($tmp)-1)];
if (isset($_GET['url'])) return output($url, 200);
$domainforproxy = '';
$domainforproxy = getConfig('domainforproxy');
if ($domainforproxy!='') {
$url = proxy_replace_domain($url, $domainforproxy);
}
return output('', 302, [ 'Location' => $url ]);
} else return output('',404);
} else return output('',401);
}
if (isset($files['file']) && !isset($_GET['preview'])) {
// is file && not preview mode
if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt')&&$files['name']!=getConfig('passfile')) ) return output('', 302, [ 'Location' => $files[$_SERVER['DownurlStrName']] ]);
if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt')&&$files['name']!=getConfig('passfile')) ) {
$url = $files[$_SERVER['DownurlStrName']];
$domainforproxy = '';
$domainforproxy = getConfig('domainforproxy');
if ($domainforproxy!='') {
$url = proxy_replace_domain($url, $domainforproxy);
}
if ( strtolower(splitlast($files['name'],'.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']);
else return output('', 302, [ 'Location' => $url ]);
}
}
if ( isset($files['folder']) || isset($files['file']) ) {
return render_list($path, $files);
@ -347,6 +375,54 @@ function main($path)
}
}
function proxy_replace_domain($url, $domainforproxy)
{
$tmp = splitfirst($url, '//');
$http = $tmp[0];
$tmp = splitfirst($tmp[1], '/');
$domain = $tmp[0];
$uri = $tmp[1];
if (substr($domainforproxy, 0, 7)=='http://' || substr($domainforproxy, 0, 8)=='https://') $aim = $domainforproxy;
else $aim = $http . '//' . $domainforproxy;
if (substr($aim, -1)=='/') $aim = substr($aim, 0, -1);
return $aim . '/' . $uri . '&Origindomain=' . $domain;
//$url = str_replace($tmp, $domainforproxy, $url).'&Origindomain='.$tmp;
}
function files_json($files)
{
//$tmp = '';
if (isset($files['file'])) {
$tmp['file']['type'] = 0;
$tmp['file']['id'] = $files['id'];
$tmp['file']['name'] = $files['name'];
$tmp['file']['time'] = $files['lastModifiedDateTime'];
$tmp['file']['size'] = $files['size'];
$tmp['file']['mime'] = $files['file']['mimeType'];
$tmp['file']['url'] = $files[$_SERVER['DownurlStrName']];
$tmp['url'] = $files[$_SERVER['DownurlStrName']];
} elseif (isset($files['folder'])) {
$tmp['list'] = [];
foreach ($files['children'] as $file) {
$tmp1 = null;
$tmp1 = [];
if (isset($file['file'])) {
$tmp1['type'] = 0;
$tmp1['url'] = $file[$_SERVER['DownurlStrName']];
} elseif (isset($file['folder'])) {
$tmp1['type'] = 1;
}
$tmp1['id'] = $file['id'];
$tmp1['name'] = $file['name'];
$tmp1['time'] = $file['lastModifiedDateTime'];
$tmp1['size'] = $file['size'];
$tmp1['mime'] = $file['file']['mimeType'];
array_push($tmp['list'], $tmp1);
}
} else return output('', 404);
return output(json_encode($tmp));
}
function get_access_token($refresh_token)
{
if (getConfig('Drive_ver')=='shareurl') {
@ -802,8 +878,15 @@ function get_thumbnails_url($path = '/', $location = 0)
}
}
if ($thumb_url!='') {
if ($location) return output('', 302, [ 'Location' => $thumb_url ]);
else return output($thumb_url);
if ($location) {
$url = $thumb_url;
$domainforproxy = '';
$domainforproxy = getConfig('domainforproxy');
if ($domainforproxy!='') {
$url = proxy_replace_domain($url, $domainforproxy);
}
return output('', 302, [ 'Location' => $url ]);
} else return output($thumb_url);
}
return output('', 404);
}
@ -1541,11 +1624,10 @@ function EnvOpt($needUpdate = 0)
}*/
$response = setConfigResponse( setConfig($tmp, $_SERVER['disk_oprating']) );
if (api_error($response)) {
$html = api_error_msg($response);
$title = 'Error';
} else {
$html = api_error_msg($response);
$title = 'Error';
} else {
//WaitSCFStat();
//sleep(3);
$html .= getconstStr('Success') . '!<br>
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
$title = getconstStr('Setup');
@ -1655,16 +1737,30 @@ function EnvOpt($needUpdate = 0)
}
$html .= '
<a href="?AddDisk">'.getconstStr('AddDisk').'</a><br><br>';
if (!((isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud')||(isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app'))) {
$canOneKeyUpate = 0;
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
$canOneKeyUpate = 1;
} else {
$tmp = time();
if ( mkdir(''.$tmp, 0777) ) {
rmdir(''.$tmp);
$canOneKeyUpate = 1;
}
}
if (!$canOneKeyUpate) {
$html .= '
'.getconstStr('VPSnotupdate').'<br>';
'.getconstStr('CannotOneKeyUpate').'<br>';
} else {
$html .= '
<form name="updateform" action="" method="post">
<input type="text" name="auth" placeholder="auth" value="qkqpttgf">
<input type="text" name="project" placeholder="project" value="OneManager-php">
<button onclick="querybranchs();return false">'.getconstStr('QueryBranchs').'</button>
<!--<input type="text" name="branch" placeholder="branch" value="master">-->
<input type="text" name="auth" size="6" placeholder="auth" value="qkqpttgf">
<input type="text" name="project" size="12" placeholder="project" value="OneManager-php">
<button name="QueryBranchs" onclick="querybranchs();return false">'.getconstStr('QueryBranchs').'</button>
<select name="branch">
<option value="master">master</option>
</select>
@ -1673,7 +1769,6 @@ function EnvOpt($needUpdate = 0)
<script>
function querybranchs()
{
//alert(document.updateform.auth.value);
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.github.com/repos/"+document.updateform.auth.value+"/"+document.updateform.project.value+"/branches");
//xhr.setRequestHeader("User-Agent","qkqpttgf/OneManager");
@ -1683,10 +1778,10 @@ function EnvOpt($needUpdate = 0)
if (xhr.status==200) {
document.updateform.branch.options.length=0;
JSON.parse(xhr.responseText).forEach( function (e) {
//alert(e.name);
document.updateform.branch.options.add(new Option(e.name,e.name));
if ("master"==e.name) document.updateform.branch.options[document.updateform.branch.options.length-1].selected = true;
});
document.updateform.QueryBranchs.style.display="none";
} else {
alert(xhr.responseText+"\n"+xhr.status);
}
@ -1702,9 +1797,9 @@ function EnvOpt($needUpdate = 0)
$html .= '<div style="position:relative;word-wrap: break-word;">
' . str_replace("\r", '<br>',$_SERVER['github_version']) . '
</div>';
} else {
}/* else {
$html .= getconstStr('NotNeedUpdate');
}
}*/
return message($html, getconstStr('Setup'));
}
@ -1762,6 +1857,7 @@ function render_list($path = '', $files = '')
OneManager: An index & manager of Onedrive auth by ysun.
Github: https://github.com/qkqpttgf/OneManager-php
-->';
//$authinfo = $path . '<br><pre>' . json_encode($files, JSON_PRETTY_PRINT) . '</pre>';
if (isset($_COOKIE['theme'])&&$_COOKIE['theme']!='') $theme = $_COOKIE['theme'];
@ -2226,7 +2322,7 @@ function render_list($path = '', $files = '')
while (strpos($html, '<!--base_disk_path-->')) $html = str_replace('<!--base_disk_path-->', (substr($_SERVER['base_disk_path'],-1)=='/'?substr($_SERVER['base_disk_path'],0,-1):$_SERVER['base_disk_path']), $html);
while (strpos($html, '<!--base_path-->')) $html = str_replace('<!--base_path-->', $_SERVER['base_path'], $html);
while (strpos($html, '<!--Path-->')) $html = str_replace('<!--Path-->', str_replace('%23', '#', str_replace('&','&amp;', $path)), $html);
while (strpos($html, '<!--Path-->')) $html = str_replace('<!--Path-->', str_replace('%23', '#', str_replace('&','&amp;', path_format($path.'/'))), $html);
while (strpos($html, '<!--constStr@Home-->')) $html = str_replace('<!--constStr@Home-->', getconstStr('Home'), $html);
$html = str_replace('<!--customCss-->', getConfig('customCss'), $html);

View File

@ -79,7 +79,8 @@ $constStr = [
'timezone' => 'Set default timezone.',
'guestup_path' => 'Set guest upload dir, before set this, the files in this dir will show as normal.',
'hideFunctionalityFile' => '0 or 1. if 1, some file will not show in list to guest, like readme.md',
'passfile' => 'The password of dir will save in this file.',
'passfile' => 'The password of folder(& its childrens) will save in this file.',
'domainforproxy' => 'Will replace the https://xxxxx-my.sharepoint.com with this value.Add &Origindomain=xxxxx-my.sharepoint.com at last',
'public_path' => 'Show this Onedrive dir when through the long url of API Gateway; public show files less than private.',
'sitename' => 'sitename',
'Onedrive_ver' => 'Onedrive version',
@ -101,6 +102,7 @@ $constStr = [
'guestup_path' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。',
'hideFunctionalityFile' => '0 或 1。如果 1, 某些文件不列表给游客看但它的功能正常比如readme.md',
'passfile' => '自定义密码文件的名字,可以是\'pppppp\',也可以是\'aaaa.txt\'等等;列目录时不会显示,只有知道密码才能查看或下载此文件。密码是这个文件的内容,可以空格、可以中文;',
'domainforproxy' => '会将https://xxxxx-my.sharepoint.com替换成这个值在目标需要自己设置反代。会加上&Origindomain=原域名',
'public_path' => '使用API长链接访问时显示网盘文件的路径不设置时默认为根目录不能是private_path的上级public看到的不能比private多要么看到的就不一样。',
'sitename' => '网站的名称',
'Onedrive_ver' => 'Onedrive版本',
@ -777,9 +779,9 @@ $constStr = [
'ko-kr' => '캐시 플러시',
'fa' => 'رفرش cache',
],
'VPSnotupdate' => [
'en-us' => 'In VPS can not update by a click! run update.sh',
'zh-cn' => '在VPS中不能一键更新可以运行update.sh',
'CannotOneKeyUpate' => [
'en-us' => 'Can not update by a click! run update.sh',
'zh-cn' => '不能一键更新可以运行update.sh',
],
'QueryBranchs' => [
'en-us' => 'Query Branchs',

View File

@ -1,14 +1,17 @@
<?php
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL & ~E_NOTICE);
include 'vendor/autoload.php';
include 'conststr.php';
include 'common.php';
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
include 'platform/scf.php';
include 'platform/TencentSCF.php';
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
include 'platform/AliyunFC.php';
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
include 'platform/heroku.php';
include 'platform/Heroku.php';
$path = getpath();
//echo 'path:'. $path;
$_GET = getGET();
@ -21,7 +24,7 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
http_response_code($re['statusCode']);
echo $re['body'];
} else {
include 'platform/normal.php';
include 'platform/Normal.php';
$path = getpath();
//echo 'path:'. $path;
$_GET = getGET();
@ -36,6 +39,7 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
echo $re['body'];
}
// Tencent SCF
function main_handler($event, $context)
{
$event = json_decode(json_encode($event), true);
@ -51,3 +55,56 @@ function main_handler($event, $context)
return main($path);
}
// Aliyun FC
function handler($request, $context)
{
set_error_handler("myErrorHandler");
$event = array(
'method' => $request->getMethod(),
'clientIP' => $request->getAttribute("clientIP"),
'requestURI' => $request->getAttribute("requestURI"),
'path' => spurlencode($request->getAttribute("path"), '/'),
'queryString' => $request->getQueryParams(),
'headers' => $request->getHeaders(),
'body' => $request->getBody()->getContents(),
);
$context = json_decode(json_encode($context), true);
printInput($event, $context);
unset($_POST);
unset($_GET);
unset($_COOKIE);
unset($_SERVER);
GetGlobalVariable($event);
$path = GetPathSetting($event, $context);
$re = main($path);
return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], $re['body']);
}
// used by Aliyun FC
function myErrorHandler($errno, $errstr, $errfile, $errline) {
if (!(error_reporting() & $errno)) {
return false;
}
switch ($errno) {
case E_USER_ERROR:
$errInfo = array(
"errorMessage" => $errstr,
"errorType" => \ServerlessFC\friendly_error_type($errno),
"stackTrace" => array(
"file" => $errfile,
"line" => $errline,
),
);
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
break;
default: // E_USER_WARNING | E_USER_NOTICE
break;
}
/* Don't execute PHP internal error handler */
return true;
}

397
platform/AliyunFC.php Normal file
View File

@ -0,0 +1,397 @@
<?php
// https://help.aliyun.com/document_detail/53252.html
// https://github.com/aliyun/fc-php-sdk/blob/master/src/AliyunFC/Client.php
use AliyunFC\Client;
function printInput($event, $context)
{
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
' . urldecode(json_encode($context, JSON_PRETTY_PRINT)) . '
';
}
function GetGlobalVariable($event)
{
$_GET = $event['queryString'];
foreach ($_GET as $k => $v) {
if ($v=='') $_GET[$k] = true;
}
$postbody = explode("&",$event['body']);
foreach ($postbody as $postvalues) {
$pos = strpos($postvalues,"=");
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
}
$cookiebody = explode("; ",$event['headers']['Cookie'][0]);
foreach ($cookiebody as $cookievalues) {
$pos = strpos($cookievalues,"=");
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
}
$_SERVER['FC_SERVER_PATH'] = '/var/fc/runtime/php7.2';
}
function GetPathSetting($event, $context)
{
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['Accept-Language'][0],';')[0],',')[0]);
$_SERVER['accountId'] = $context['accountId'];
$_SERVER['region'] = $context['region'];
$_SERVER['service_name'] = $context['service']['name'];
$_SERVER['function_name'] = $context['function']['name'];
$_SERVER['base_path'] = '/';
$path = $event['path'];
//$path = spurlencode($path, '/');
if (substr($path,-1)=='/') $path=substr($path,0,-1);
$_SERVER['is_guestup_path'] = is_guestup_path($path);
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
$_SERVER['REMOTE_ADDR'] = $event['clientIP'];
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['X-Requested-With'][0];
return $path;
}
function getConfig($str, $disktag = '')
{
global $InnerEnv;
global $Base64Env;
if (in_array($str, $InnerEnv)) {
if ($disktag=='') $disktag = $_SERVER['disktag'];
$env = json_decode(getenv($disktag), true);
if (isset($env[$str])) {
if (in_array($str, $Base64Env)) return equal_replace($env[$str],1);
else return $env[$str];
}
} else {
if (in_array($str, $Base64Env)) return equal_replace(getenv($str),1);
else return getenv($str);
}
return '';
}
function setConfig($arr, $disktag = '')
{
global $InnerEnv;
global $Base64Env;
if ($disktag=='') $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)) {
if (in_array($k, $Base64Env)) $diskconfig[$k] = equal_replace($v);
else $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 {
if (in_array($k, $Base64Env)) $tmp[$k] = equal_replace($v);
else $tmp[$k] = $v;
}
}
if ($indisk) {
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
ksort($diskconfig);
$tmp[$disktag] = json_encode($diskconfig);
}
if ($oparetdisk) {
$disktags = array_unique($disktags);
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
else $tmp['disktag'] = '';
}
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
//';
$response = updateEnvironment($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], getConfig('AccessKeyID'), getConfig('AccessKeySecret'));
//WaitSCFStat();
return $response;
}
function install()
{
global $constStr;
if ($_GET['install2']) {
$tmp['admin'] = $_POST['admin'];
setConfig($tmp);
if (needUpdate()) {
OnekeyUpate();
return message('update to github version, reinstall.<script>document.cookie=\'language=; path=/\';</script><meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
}
return output('Jump<script>document.cookie=\'language=; path=/\';</script><meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
}
if ($_GET['install1']) {
//if ($_POST['admin']!='') {
$tmp['timezone'] = $_COOKIE['timezone'];
$AccessKeyID = getConfig('AccessKeyID');
if ($AccessKeyID=='') {
$AccessKeyID = $_POST['AccessKeyID'];
$tmp['AccessKeyID'] = $AccessKeyID;
}
$AccessKeySecret = getConfig('AccessKeySecret');
if ($AccessKeySecret=='') {
$AccessKeySecret = $_POST['AccessKeySecret'];
$tmp['AccessKeySecret'] = $AccessKeySecret;
}
$response = json_decode(SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $AccessKeyID, $AccessKeySecret), true);
if (api_error($response)) {
$html = api_error_msg($response);
$title = 'Error';
return message($html, $title, 201);
} else {
$html .= '
<form action="?install2" method="post" onsubmit="return notnull(this);">
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
<input type="submit" value="'.getconstStr('Submit').'">
</form>
<script>
function notnull(t)
{
if (t.admin.value==\'\') {
alert(\''.getconstStr('SetAdminPassword').'\');
return false;
}
return true;
}
</script>';
$title = getconstStr('SetAdminPassword');
return message($html, $title, 201);
}
//}
}
if ($_GET['install0']) {
$html .= '
<form action="?install1" method="post" onsubmit="return notnull(this);">
language:<br>';
foreach ($constStr['languages'] as $key1 => $value1) {
$html .= '
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
}
if (getConfig('AccessKeyID')==''||getConfig('AccessKeySecret')=='') $html .= '
<a href="https://usercenter.console.aliyun.com/?#/manage/ak" target="_blank">'.getconstStr('Create').' AccessKeyID & AccessKeySecret</a><br>
<label>AccessKeyID:<input name="AccessKeyID" type="text" placeholder="" size=""></label><br>
<label>AccessKeySecret:<input name="AccessKeySecret" type="text" placeholder="" size=""></label><br>';
$html .= '
<input type="submit" value="'.getconstStr('Submit').'">
</form>
<script>
var nowtime= new Date();
var timezone = 0-nowtime.getTimezoneOffset()/60;
var expd = new Date();
expd.setTime(expd.getTime()+(2*60*60*1000));
var expires = "expires="+expd.toGMTString();
document.cookie="timezone="+timezone+"; path=/; "+expires;
function changelanguage(str)
{
document.cookie=\'language=\'+str+\'; path=/\';
location.href = location.href;
}
function notnull(t)
{';
if (getConfig('AccessKeyID')==''||getConfig('AccessKeySecret')=='') $html .= '
if (t.AccessKeyID.value==\'\') {
alert(\'input AccessKeyID\');
return false;
}
if (t.AccessKeySecret.value==\'\') {
alert(\'input SecretKey\');
return false;
}';
$html .= '
return true;
}
</script>';
$title = getconstStr('SelectLanguage');
return message($html, $title, 201);
}
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
$title = 'Error';
return message($html, $title, 201);
}
function getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
{
$fcClient = new Client([
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
"accessKeyID" => $AccessKeyID,
"accessKeySecret" => $AccessKeySecret
]);
return $fcClient->getFunction($service_name, $function_name);
}
function updateEnvironment($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
{
//print_r($Envs);
$fcClient = new Client([
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
"accessKeyID" => $AccessKeyID,
"accessKeySecret" => $AccessKeySecret
]);
$tmp = $fcClient->getFunction($service_name, $function_name)['data'];
//$tmp = getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)['data'];
foreach ($tmp['environmentVariables'] as $key => $value ) {
$tmp_env[$key] = $value;
}
foreach ($Envs as $key1 => $value1) {
$tmp_env[$key1] = $value1;
}
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
ksort($tmp_env);
$tmpdata['functionName'] = $tmp['functionName'];
$tmpdata['description'] = $tmp['description'];
$tmpdata['memorySize'] = $tmp['memorySize'];
$tmpdata['timeout'] = $tmp['timeout'];
$tmpdata['runtime'] = $tmp['runtime'];
$tmpdata['handler'] = $tmp['handler'];
$tmpdata['environmentVariables'] = $tmp_env;
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($fcClient->getFunctionCode($service_name, $function_name)['data']['url']) );
return $fcClient->updateFunction($service_name, $function_name, $tmpdata);
}
function SetbaseConfig($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
{
//echo json_encode($Envs,JSON_PRETTY_PRINT);
$fcClient = new Client([
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
"accessKeyID" => $AccessKeyID,
"accessKeySecret" => $AccessKeySecret
]);
$tmp = $fcClient->getFunction($service_name, $function_name)['data'];
// $tmp = getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)['data'];
foreach ($tmp['environmentVariables'] as $key => $value ) {
$tmp_env[$key] = $value;
}
foreach ($Envs as $key1 => $value1) {
$tmp_env[$key1] = $value1;
}
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
ksort($tmp_env);
$tmpdata['functionName'] = $function_name;
$tmpdata['description'] = 'Onedrive index and manager in Ali FC.';
$tmpdata['memorySize'] = 128;
$tmpdata['timeout'] = 30;
$tmpdata['runtime'] = 'php7.2';
$tmpdata['handler'] = 'index.handler';
$tmpdata['environmentVariables'] = $tmp_env;
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($fcClient->getFunctionCode($service_name, $function_name)['data']['url']) );
return $fcClient->updateFunction($service_name, $function_name, $tmpdata);
}
function updateProgram($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret, $source)
{
//WaitSCFStat();
$fcClient = new Client([
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
"accessKeyID" => $AccessKeyID,
"accessKeySecret" => $AccessKeySecret
]);
$tmp = $fcClient->getFunction($service_name, $function_name)['data'];
//$tmp = getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)['data'];
$tmpdata['functionName'] = $tmp['functionName'];
$tmpdata['description'] = $tmp['description'];
$tmpdata['memorySize'] = $tmp['memorySize'];
$tmpdata['timeout'] = $tmp['timeout'];
$tmpdata['runtime'] = $tmp['runtime'];
$tmpdata['handler'] = $tmp['handler'];
$tmpdata['environmentVariables'] = $tmp['environmentVariables'];
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($source) );
return $fcClient->updateFunction($service_name, $function_name, $tmpdata);
}
function api_error($response)
{
return !isset($response['data']);
}
function api_error_msg($response)
{
return $response;
return $response['Error']['Code'] . '<br>
' . $response['Error']['Message'] . '<br><br>
function_name:' . $_SERVER['function_name'] . '<br>
Region:' . $_SERVER['Region'] . '<br>
namespace:' . $_SERVER['namespace'] . '<br>
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
}
function setConfigResponse($response)
{
return $response;
}
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{
$source = '/tmp/code.zip';
$outPath = '/tmp/';
// 从github下载对应tar.gz并解压
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . $branch . '/';
$tarfile = '/tmp/github.tar.gz';
file_put_contents($tarfile, file_get_contents($url));
$phar = new PharData($tarfile);
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
// 获取解压出的目录名
/*
@ob_start();
passthru('ls /tmp | grep '.$auth.'-'.$project.'',$stat);
$html.='状态:' . $stat . '
结果:
';
$archivefolder = ob_get_clean();
if (substr($archivefolder,-1)==PHP_EOL) $archivefolder = substr($archivefolder, 0, -1);
$outPath .= $archivefolder;
$html.=htmlspecialchars($archivefolder);
//return $html;
*/
$tmp = scandir($outPath);
$name = $auth.'-'.$project;
foreach ($tmp as $f) {
if ( substr($f, 0, strlen($name)) == $name) {
$outPath .= $f;
break;
}
}
// 将目录中文件打包成zip
$zip=new ZipArchive();
if($zip->open($source, ZipArchive::CREATE)){
addFileToZip($zip, $outPath); //调用方法对要打包的根目录进行操作并将ZipArchive的对象传递给方法
$zip->close(); //关闭处理的zip文件
}
return updateProgram($_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], getConfig('AccessKeyID'), getConfig('AccessKeySecret'), $source);
}
function addFileToZip($zip, $rootpath, $path = '')
{
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
if (substr($path,0,1)=='/') $path = substr($path, 1);
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
while($filename=readdir($handler)){
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
$nowname = path_format($rootpath.'/'.$path."/".$filename);
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
addFileToZip($zip, $rootpath, $path."/".$filename);
}else{ //将文件加入zip对象
$zip->addFile($nowname);
$newname = $path."/".$filename;
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
$zip->renameName($nowname, $newname);
}
}
}
@closedir($path);
}

View File

@ -252,12 +252,70 @@ Can not write config to file.<br>
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
}
function OnekeyUpate()
{
return json_decode(updateHerokuapp(getConfig('function_name'), getConfig('APIKey'))['body'], true);
}
function setConfigResponse($response)
{
return $response;
}
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{
// __DIR__ is xxx/platform
$projectPath = splitlast(__DIR__, '/')[0];
// 从github下载对应tar.gz并解压
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . $branch . '/';
$tarfile = $projectPath.'/github.tar.gz';
$githubfile = file_get_contents($url);
if (!$githubfile) return 0;
file_put_contents($tarfile, $githubfile);
if (splitfirst(PHP_VERSION, '.')[0] == '7') {
$phar = new PharData($tarfile); // need php7
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
} else {
ob_start();
passthru('tar -xzvf '.$tarfile,$stat);
ob_get_clean();
}
unlink($tarfile);
$outPath = '';
$tmp = scandir($projectPath);
$name = $auth.'-'.$project;
foreach ($tmp as $f) {
if ( substr($f, 0, strlen($name)) == $name) {
$outPath = $projectPath . '/' . $f;
break;
}
}
//error_log($outPath);
if ($outPath=='') return 0;
//unlink($outPath.'/config.php');
rename($projectPath.'/config.php', $outPath.'/config.php');
return moveFolder($outPath, $projectPath);
}
function moveFolder($from, $to)
{
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
if (!file_exists($to)) mkdir($to, 0777);
$handler=opendir($from);
while($filename=readdir($handler)) {
if($filename != '.' && $filename != '..'){
$fromfile = $from.'/'.$filename;
$tofile = $to.'/'.$filename;
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
moveFolder($fromfile, $tofile);
}else{
//if (file_exists($tofile)) unlink($tofile);
rename($fromfile, $tofile);
if (file_exists($fromfile)) unlink($fromfile);
}
}
}
closedir($handler);
rmdir($from);
return 1;
}

View File

@ -23,6 +23,8 @@ function GetGlobalVariable($event)
$pos = strpos($cookievalues,"=");
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
}
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
$_SERVER['HTTP_TRANSLATE']==$event['headers']['translate'];//'f'
$_SERVER['USER'] = 'qcloud';
}