Last active
August 13, 2019 21:36
-
-
Save rabehasy/04710fc30cc058e62748302aa6c26f9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* add crontab -- * * * * * php /home/web/githooks.php | |
*/ | |
$folder = __DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; | |
// Go to miaryrabs; pull and remove files inside tmp | |
$cmd = 'cd /home/web/miaryrabs/; git pull gitlab master; rm -rf ' . $folder . '*'; | |
// if calling from php cli | |
if (isset($argv)) { | |
// file exists inside tmp folder | |
$files = glob($folder . "*"); | |
if (!empty($files)) { | |
shell_exec($cmd); | |
exit; | |
} | |
} | |
// if calling from webhooks | |
$sInput = 'php://input'; | |
$json_str = file_get_contents($sInput); | |
if ($json_str != '') { | |
$json = json_decode($json_str, true); | |
// print_r($json) | |
// if json >> save inside tmp folder | |
if (is_array($json)) { | |
// save request_payload inside txt | |
$f = $folder . uniqid() . '.txt'; | |
// print_r($f); | |
file_put_contents($f, $json_str); | |
$to = '[email protected]'; | |
$s = 'Webhooks '; | |
$m = print_r($json, 1); | |
$h = 'From:[email protected]'; | |
mail($to, $s, $m, $h); | |
exit; | |
} | |
} | |
// if calling from GET | |
echo "Hello"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment