Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: application/json');
- /**
- * Check config files
- */
- if (!file_exists(__DIR__ . '/../app/config/app.php')) {
- die(json_encode(['error' => 'Can not find configuration file']));
- }
- /**
- * Check deploy key
- */
- $config = require __DIR__ . '/../app/config/app.php';
- if (!isset($config['deploykey'])) {
- die(json_encode(['error' => 'Deploy key not exists']));
- }
- /**
- * User Agent must be a GitHub-Hookshot/****
- * @return bool
- */
- $validateUserAgent = function()
- {
- return isset($_SERVER['HTTP_USER_AGENT']) &&
- preg_match('/GitHub\-Hookshot\/[0-9]+/is', $_SERVER['HTTP_USER_AGENT']);
- };
- /**
- * Signature must be sha1 of raw content and key
- * @return bool
- */
- $validateSig = function() use ($config)
- {
- $input = file_get_contents('php://input');
- $data = json_decode($input);
- return isset($_SERVER['HTTP_X_HUB_SIGNATURE']) &&
- hash_hmac('sha1', $data, $config['deploykey']) === $_SERVER['HTTP_X_HUB_SIGNATURE'];
- };
- /**
- * Execute script
- * @param array $commands
- */
- $exec = function(array $commands)
- {
- system(implode('&&', $commands));
- die(json_encode(['success' => 'Forum updated']));
- };
- /**
- * Validate
- */
- if ($validateUserAgent() && $validateSig()) {
- $exec([
- 'cd ../',
- 'git checkout -f',
- 'composer update'
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement