Skip to content
desaiuditd edited this page Dec 3, 2014 · 1 revision

We have following code running at http://hooks.rtcamp.com/docs.php

<?php
date_default_timezone_set('asia/kolkata');

if (!function_exists('getallheaders')) 
{ 
    function getallheaders() 
    { 
           $headers = ''; 
       foreach ($_SERVER as $name => $value) 
       { 
           if (substr($name, 0, 5) == 'HTTP_') 
           { 
               $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; 
           } 
       } 
       return $headers; 
    } 
} 

$secret = "GITHUB-WEBHOOK-SECRET";

$headers = getallheaders();
$hubSignature = $headers['X-Hub-Signature'];
 
list($algo, $hash) = explode('=', $hubSignature, 2);
 
$payload = file_get_contents('php://input');
$data    = json_decode($payload); 

$payloadHash = hash_hmac($algo, $payload, $secret);

 
if ($hash !== $payloadHash) {
//    die('Bad secret');
}
 
// Your code here.
$output = shell_exec('cd /path/to/repo/docs.rtcamp.com && git pull && jekyll build && rsync -avz --progress --rsh="sshpass -p PASSWORD ssh -l user_xceoobwr -o StrictHostKeyChecking=no" _site* USER@HOST:/www/
');
mail("[email protected],[email protected]", "docs.rtcamp.com updated on " . date("F j, Y, g:i a") , $output);
print_r($output);
?>
Clone this wiki locally