diff --git a/config.dist.php b/config.dist.php index fc984b5..74c2171 100644 --- a/config.dist.php +++ b/config.dist.php @@ -1,5 +1,5 @@ 'change me' + 'passwd' => 'change me' ); diff --git a/hook.php b/hook.php index ac7104e..37a9114 100644 --- a/hook.php +++ b/hook.php @@ -2,14 +2,18 @@ require_once('inc.php'); header('Content-Type: text/plain'); -if(file_exists('key.php')) { - $key = require('key.php'); - if($key['current'] === $_SERVER['QUERY_STRING']) { - $pwd = getcwd(); - chdir(dirname($pwd)); - _exec('pwd'); - _exec('git pull'); - } +if (file_exists('key.php')) +{ + $key = require('key.php'); + if ($key['current'] === $_SERVER['QUERY_STRING']) + { + $submodule = getcwd(); + $project = $submodule.'/../../../'; + chdir(dirname($project)); + _exec('pwd'); + _exec('git pull'); + _exec('git submodule update'); + } } _log(var_export($_POST, true)); \ No newline at end of file diff --git a/inc.php b/inc.php index e743533..d900d50 100644 --- a/inc.php +++ b/inc.php @@ -2,14 +2,16 @@ #error_reporting(0); -function _exec($cmd) { - $out = "$ ".$cmd."\n"; - $out .= shell_exec($cmd.' 2>&1'); - _log($out); +function _exec($cmd) +{ + $out = "$ " . $cmd . "\n"; + $out .= shell_exec($cmd . ' 2>&1'); + _log($out); } -function _log($str) { - $out = "\n".date('r')." ".$str; - echo $out; - error_log($out, 3, '.webhook.log'); +function _log($str) +{ + $out = "\n" . date('r') . " " . $str; + echo $out; + error_log($out, 3, '.webhook.log'); } diff --git a/link.php b/link.php index 54f635a..6ed274b 100644 --- a/link.php +++ b/link.php @@ -3,29 +3,40 @@ require_once('inc.php'); $config = require('config.php'); -if(file_exists('key.php')) { - $key = require('key.php'); - if($key['current'] !== $_SERVER['QUERY_STRING']) { - if($key['previous'] === $_SERVER['QUERY_STRING']) { - header('Location: ?'.$key['current']); - } else if(!isset($_POST['passwd'])) { - echo '
'; - } else if($_POST['passwd'] !== $config['passwd']) { - echo 'Wrong'; - } else { - header('Location: ?'.$key['current']); +if (file_exists('key.php')) +{ + $key = require('key.php'); + if ($key['current'] !== $_SERVER['QUERY_STRING']) + { + if ($key['previous'] === $_SERVER['QUERY_STRING']) + { + header('Location: ?' . $key['current']); + } + else if (!isset($_POST['passwd'])) + { + echo '
'; + } + else if ($_POST['passwd'] !== $config['passwd']) + { + echo 'Wrong'; + } + else + { + header('Location: ?' . $key['current']); + } + exit; } - exit; - } -} else { +} +else +{ } -mt_srand(microtime(true)*1000); -$new = sha1(crypt(microtime(true).mt_rand().time().mt_rand())); -file_put_contents('key.php', ' $new, - 'previous' => isset($key) ? $key['current'] : '', -), true).';'); +mt_srand(microtime(true) * 1000); +$new = sha1(crypt(microtime(true) . mt_rand() . time() . mt_rand())); +file_put_contents('key.php', ' $new, + 'previous' => isset($key) ? $key['current'] : '', +), true) . ';'); -echo ' '; +echo ' '; //print_r($_SERVER);