Skip to content

Instantly share code, notes, and snippets.

@rabehasy
Last active August 13, 2019 21:36
Show Gist options
  • Save rabehasy/04710fc30cc058e62748302aa6c26f9c to your computer and use it in GitHub Desktop.
Save rabehasy/04710fc30cc058e62748302aa6c26f9c to your computer and use it in GitHub Desktop.
<?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);
// mail
$to = 'me@gmail.com';
$s = 'Webhooks ';
$m = print_r($json, 1);
$h = 'From:from@me.com';
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