diff --git a/platform/HuaweiFG_file.php b/platform/HuaweiFG_file.php index abddc7f..353f7b1 100644 --- a/platform/HuaweiFG_file.php +++ b/platform/HuaweiFG_file.php @@ -80,10 +80,8 @@ function GetPathSetting($event, $context) function getConfig($str, $disktag = '') { - - global $slash; - $projectPath = splitlast(__DIR__, $slash)[0]; - $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; + $projectPath = splitlast(__DIR__, '/')[0]; + $configPath = $projectPath . '/.data/config.php'; $s = file_get_contents($configPath); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') { @@ -108,9 +106,8 @@ function setConfig($arr, $disktag = '') { if ($disktag=='') $disktag = $_SERVER['disktag']; - global $slash; - $projectPath = splitlast(__DIR__, $slash)[0]; - $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; + $projectPath = splitlast(__DIR__, '/')[0]; + $configPath = $projectPath . '/.data/config.php'; $s = file_get_contents($configPath); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') $envs = json_decode($configs, true); @@ -422,7 +419,6 @@ function updateEnvironment($Envs, $HW_urn, $HW_key, $HW_secret) function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret) { - global $slash; //echo json_encode($Envs,JSON_PRETTY_PRINT); if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' ); else { @@ -465,8 +461,8 @@ function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret) return $response; } - $projectPath = splitlast(__DIR__, $slash)[0]; - $configPath = $projectPath . $slash . '.data' . $slash . 'config.php'; + $projectPath = splitlast(__DIR__, '/')[0]; + $configPath = $projectPath . '/.data/config.php'; $s = file_get_contents($configPath); $configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}'; if ($configs!='') $tmp_env = json_decode($configs, true); @@ -521,39 +517,24 @@ function setConfigResponse($response) return json_decode( $response, true ); } -function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') +function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') { $source = '/tmp/code.zip'; $outPath = '/tmp/'; - // 从github下载对应tar.gz,并解压 - $url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; + if ($GitSource=='Github') { + // 从github下载对应tar.gz,并解压 + $url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; + } elseif ($GitSource=='HITGitlab') { + $url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz'; + } else return json_encode(['error_code'=>'Error', 'error_msg'=>'Git Source input Error!']); $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; - } - } + $outPath = findIndexPath($outPath); // 放入配置文件 file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/config.php')); @@ -588,7 +569,7 @@ function addFileToZip($zip, $rootpath, $path = '') } } } - @closedir($path); + @closedir($handler); } @@ -598,6 +579,7 @@ function addFileToZip($zip, $rootpath, $path = '') + define("BasicDateFormat", "Ymd\THis\Z"); define("Algorithm", "SDK-HMAC-SHA256"); define("HeaderXDate", "X-Sdk-Date");