git_pull이 CLI에서도 동작하게 변경

This commit is contained in:
2019-09-22 23:15:29 +09:00
parent 0b4ef0e333
commit 4bfa257b02
+23 -14
View File
@@ -24,10 +24,14 @@ function getVersion($target=null){
} }
function isCommandLineInterface()
{
return (php_sapi_name() === 'cli');
}
header('Content-Type: application/json'); header('Content-Type: application/json');
$req_hash = $_REQUEST['req']??'';
$req_time = $_REQUEST['time']??0;
$json_response = [ $json_response = [
'result'=>false, 'result'=>false,
@@ -35,33 +39,38 @@ $json_response = [
'version'=>null, 'version'=>null,
]; ];
if(!$req_hash){ if (!isCommandLineInterface()) {
$req_hash = $_REQUEST['req']??'';
$req_time = $_REQUEST['time']??0;
if (!$req_hash) {
$json_response['reason'] = 'no req'; $json_response['reason'] = 'no req';
die(json_encode($json_response)); die(json_encode($json_response));
} }
if(!$req_time || !is_numeric($req_time)){ if (!$req_time || !is_numeric($req_time)) {
$json_response['reason'] = 'invalid time'; $json_response['reason'] = 'invalid time';
die(json_encode($json_response)); die(json_encode($json_response));
} }
$key = HashKey::KEY; $key = HashKey::KEY;
if(strlen($key)<16){ if (strlen($key)<16) {
$json_response['reason'] = 'key is too short'; $json_response['reason'] = 'key is too short';
die(json_encode($json_response)); die(json_encode($json_response));
} }
$timestamp = time(); $timestamp = time();
if(abs($timestamp - $req_time) > 300){ if (abs($timestamp - $req_time) > 300) {
$json_response['reason'] = 'time difference'; $json_response['reason'] = 'time difference';
die(json_encode($json_response)); die(json_encode($json_response));
} }
$ans_hash = hashPassword(sprintf("%016x", $req_time), $key); $ans_hash = hashPassword(sprintf("%016x", $req_time), $key);
if($ans_hash != $req_hash){ if ($ans_hash != $req_hash) {
$json_response['reason'] = 'hash mismatch'; $json_response['reason'] = 'hash mismatch';
die(json_encode($json_response)); die(json_encode($json_response));
}
} }
exec("git pull -q 2>&1", $output); exec("git pull -q 2>&1", $output);