Advertisement
Serafim

Untitled

Dec 16th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. header('Content-Type: application/json');
  3.  
  4. /**
  5.  * Check config files
  6.  */
  7. if (!file_exists(__DIR__ . '/../app/config/app.php')) {
  8.     die(json_encode(['error' => 'Can not find configuration file']));
  9. }
  10.  
  11. /**
  12.  * Check deploy key
  13.  */
  14. $config = require __DIR__ . '/../app/config/app.php';
  15. if (!isset($config['deploykey'])) {
  16.     die(json_encode(['error' => 'Deploy key not exists']));
  17. }
  18.  
  19. /**
  20.  * User Agent must be a GitHub-Hookshot/****
  21.  * @return bool
  22.  */
  23. $validateUserAgent = function()
  24. {
  25.     return isset($_SERVER['HTTP_USER_AGENT']) &&
  26.         preg_match('/GitHub\-Hookshot\/[0-9]+/is', $_SERVER['HTTP_USER_AGENT']);
  27. };
  28.  
  29. /**
  30.  * Signature must be sha1 of raw content and key
  31.  * @return bool
  32.  */
  33. $validateSig = function() use ($config)
  34. {
  35.     $input  = file_get_contents('php://input');
  36.     $data   = json_decode($input);
  37.  
  38.     return isset($_SERVER['HTTP_X_HUB_SIGNATURE']) &&
  39.         hash_hmac('sha1', $data, $config['deploykey']) === $_SERVER['HTTP_X_HUB_SIGNATURE'];
  40. };
  41.  
  42. /**
  43.  * Execute script
  44.  * @param array $commands
  45.  */
  46. $exec = function(array $commands)
  47. {
  48.     system(implode('&&', $commands));
  49.     die(json_encode(['success' => 'Forum updated']));
  50. };
  51.  
  52.  
  53. /**
  54.  * Validate
  55.  */
  56. if ($validateUserAgent() && $validateSig()) {
  57.  
  58.     $exec([
  59.         'cd ../',
  60.         'git checkout -f',
  61.         'composer update'
  62.     ]);
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement