From 4bfa257b02da56c8892ee44a0b714474f8f75108 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 22 Sep 2019 23:15:29 +0900 Subject: [PATCH] =?UTF-8?q?git=5Fpull=EC=9D=B4=20CLI=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8F=84=20=EB=8F=99=EC=9E=91=ED=95=98=EA=B2=8C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hook/git_pull.php | 57 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/hook/git_pull.php b/hook/git_pull.php index 916422e..5137be9 100644 --- a/hook/git_pull.php +++ b/hook/git_pull.php @@ -24,10 +24,14 @@ function getVersion($target=null){ } +function isCommandLineInterface() +{ + return (php_sapi_name() === 'cli'); +} + header('Content-Type: application/json'); -$req_hash = $_REQUEST['req']??''; -$req_time = $_REQUEST['time']??0; + $json_response = [ 'result'=>false, @@ -35,33 +39,38 @@ $json_response = [ 'version'=>null, ]; -if(!$req_hash){ - $json_response['reason'] = 'no req'; - die(json_encode($json_response)); -} -if(!$req_time || !is_numeric($req_time)){ - $json_response['reason'] = 'invalid time'; - die(json_encode($json_response)); -} +if (!isCommandLineInterface()) { + $req_hash = $_REQUEST['req']??''; + $req_time = $_REQUEST['time']??0; -$key = HashKey::KEY; -if(strlen($key)<16){ - $json_response['reason'] = 'key is too short'; - die(json_encode($json_response)); -} + if (!$req_hash) { + $json_response['reason'] = 'no req'; + die(json_encode($json_response)); + } + if (!$req_time || !is_numeric($req_time)) { + $json_response['reason'] = 'invalid time'; + die(json_encode($json_response)); + } -$timestamp = time(); + $key = HashKey::KEY; + if (strlen($key)<16) { + $json_response['reason'] = 'key is too short'; + die(json_encode($json_response)); + } -if(abs($timestamp - $req_time) > 300){ - $json_response['reason'] = 'time difference'; - die(json_encode($json_response)); -} + $timestamp = time(); -$ans_hash = hashPassword(sprintf("%016x", $req_time), $key); + if (abs($timestamp - $req_time) > 300) { + $json_response['reason'] = 'time difference'; + die(json_encode($json_response)); + } -if($ans_hash != $req_hash){ - $json_response['reason'] = 'hash mismatch'; - die(json_encode($json_response)); + $ans_hash = hashPassword(sprintf("%016x", $req_time), $key); + + if ($ans_hash != $req_hash) { + $json_response['reason'] = 'hash mismatch'; + die(json_encode($json_response)); + } } exec("git pull -q 2>&1", $output);