Add files via upload
This commit is contained in:
+147
-95
@@ -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()
|
||||
{
|
||||
global $constStr;
|
||||
$url = path_format($_SERVER['PHP_SELF'] . '/');
|
||||
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']);
|
||||
if ($tmp['stat']==200) $ret = json_decode($tmp['body'], true);
|
||||
if (isset($ret['refresh_token'])) {
|
||||
@@ -64,17 +128,21 @@ function get_refresh_token()
|
||||
texta[i].style.height = texta[i].scrollHeight + \'px\';
|
||||
}
|
||||
document.cookie=\'language=; path=/\';
|
||||
document.cookie=\'disktag=; path=/\';
|
||||
</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);
|
||||
$str .= '
|
||||
<meta http-equiv="refresh" content="5;URL=' . $url . '">';
|
||||
<meta http-equiv="refresh" content="2;URL=' . $url . '">';
|
||||
return message($str, getconstStr('WaitJumpIndex'));
|
||||
}
|
||||
return message('<pre>' . $tmp['body'] . '</pre>', $tmp['stat']);
|
||||
//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') {
|
||||
return message('
|
||||
<a href="" id="a1">'.getconstStr('JumptoOffice').'</a>
|
||||
@@ -88,17 +156,19 @@ function get_refresh_token()
|
||||
', getconstStr('Wait').' 1s', 201);
|
||||
}
|
||||
}
|
||||
if ($_GET['install2']) {
|
||||
// echo $_POST['Onedrive_ver'];
|
||||
if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') {
|
||||
if ($_GET['install0']) {
|
||||
if ($_POST['disktag_add']!='' && ($_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'];
|
||||
if ($_POST['Onedrive_ver']=='MSC') {
|
||||
$tmp['client_id'] = $_POST['client_id'];
|
||||
$tmp['client_secret'] = $_POST['client_secret'];
|
||||
}
|
||||
$response = setConfig($tmp);
|
||||
$response = setConfig($tmp, $_COOKIE['disktag']);
|
||||
$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) {
|
||||
$html = $response . '<br>
|
||||
Can not write config to file.<br>
|
||||
@@ -108,20 +178,17 @@ Can not write config to file.<br>
|
||||
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') {
|
||||
$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">
|
||||
|
||||
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>
|
||||
@@ -133,15 +200,45 @@ Can not write config to file.<br>
|
||||
</div>
|
||||
</label><br>
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>';
|
||||
$title = 'Install';
|
||||
} else {
|
||||
$html = $response . '<br>
|
||||
</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 ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
$tmp['language'] = $_POST['language'];
|
||||
$response = setConfig($tmp);
|
||||
if (!$response) {
|
||||
$html = $response . '<br>
|
||||
Can not write config to file.<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Reflesh').'</button>';
|
||||
$title = 'Error';
|
||||
}
|
||||
return message($html, $title, 201);
|
||||
$title = 'Error';
|
||||
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']) {
|
||||
@@ -157,14 +254,19 @@ run Writeable.sh.';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$html .= '
|
||||
<form action="?install1" method="post" onsubmit="return adminnotnull(this);">
|
||||
<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>';
|
||||
}
|
||||
$html .= '<br>
|
||||
<label>admin:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
||||
if (getConfig('SecretId')==''||getConfig('SecretKey')=='') $html .= '
|
||||
<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').'">
|
||||
</form>
|
||||
<script>
|
||||
@@ -173,19 +275,29 @@ language:<br>';
|
||||
document.cookie=\'language=\'+str+\'; path=/\';
|
||||
location.href = location.href;
|
||||
}
|
||||
function adminnotnull(t)
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.admin.value==\'\') {
|
||||
alert(\'input admin\');
|
||||
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;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
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';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
@@ -203,8 +315,7 @@ function ConfigWriteable()
|
||||
function RewriteEngineOn()
|
||||
{
|
||||
$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'];
|
||||
//if $_SERVER['SERVER_PORT']
|
||||
$tmpurl = $http_type . $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
|
||||
$tmpurl .= path_format($_SERVER['base_path'] . '/config.php');
|
||||
$tmp = curl_request($tmpurl);
|
||||
if ($tmp['stat']==200) return false;
|
||||
@@ -212,65 +323,6 @@ function RewriteEngineOn()
|
||||
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)
|
||||
{
|
||||
global $constStr;
|
||||
|
||||
Reference in New Issue
Block a user