try fix: suddenly can not save config in glitch

pull/171/head
qkqpttgf 2020-12-08 14:53:25 +08:00 committed by GitHub
parent 07cd427066
commit 4add1167db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 16 deletions

View File

@ -46,8 +46,12 @@ function getConfig($str, $disktag = '')
{ {
global $InnerEnv; global $InnerEnv;
global $Base64Env; global $Base64Env;
//include 'config.php';
$s = file_get_contents('.data/config.php'); $slash = '/';
if (strpos(__DIR__, ':')) $slash = '\\';
$projectPath = splitlast(__DIR__, $slash)[0];
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
$s = file_get_contents($configPath);
//$configs = substr($s, 18, -2); //$configs = substr($s, 18, -2);
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
if ($configs!='') { if ($configs!='') {
@ -73,8 +77,11 @@ function setConfig($arr, $disktag = '')
global $InnerEnv; global $InnerEnv;
global $Base64Env; global $Base64Env;
if ($disktag=='') $disktag = $_SERVER['disktag']; if ($disktag=='') $disktag = $_SERVER['disktag'];
//include 'config.php'; $slash = '/';
$s = file_get_contents('.data/config.php'); if (strpos(__DIR__, ':')) $slash = '\\';
$projectPath = splitlast(__DIR__, $slash)[0];
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
$s = file_get_contents($configPath);
//$configs = substr($s, 18, -2); //$configs = substr($s, 18, -2);
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
if ($configs!='') $envs = json_decode($configs, true); if ($configs!='') $envs = json_decode($configs, true);
@ -115,7 +122,7 @@ function setConfig($arr, $disktag = '')
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
$prestr = '<?php $configs = \'' . PHP_EOL; $prestr = '<?php $configs = \'' . PHP_EOL;
$aftstr = PHP_EOL . '\';'; $aftstr = PHP_EOL . '\';';
$response = file_put_contents('.data/config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr); $response = file_put_contents($configPath, $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
if ($response>0) return json_encode( [ 'response' => 'success' ] ); if ($response>0) return json_encode( [ 'response' => 'success' ] );
return json_encode( [ 'message' => 'Failed to write config.', 'code' => 'failed' ] ); return json_encode( [ 'message' => 'Failed to write config.', 'code' => 'failed' ] );
} }
@ -245,17 +252,6 @@ function ConfigWriteable()
return false; return false;
} }
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'].':'.$_SERVER['SERVER_PORT'];
$tmpurl .= path_format($_SERVER['base_path'] . '/.data/config.php');
$tmp = curl_request($tmpurl);
if ($tmp['stat']==200) return false;
if ($tmp['stat']==201) return true; //when install return 201, after installed return 404 or 200;
return false;
}
function api_error($response) function api_error($response)
{ {
return isset($response['message']); return isset($response['message']);