-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-from-github.php
40 lines (37 loc) · 1.66 KB
/
update-from-github.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once __DIR__ . '/vendor/autoload.php';
session_start();
date_default_timezone_set('Europe/Paris');
if (isset($_POST['payload']) or true){
$db = MyApp\Utility\Db::getPDO();
try {
$reponse = $db->query ('SELECT data_value FROM platform_data WHERE data_name = "github_key"');
$github_key = $reponse->fetch()['data_value'];
$reponse->closeCursor();
} catch (Throwable $e){
die ("platform_data.github_key is missing from the database, platform can't be updated");
}
$hash = hash_hmac('sha1', file_get_contents('php://input'), $github_key);
if (isset($_SERVER['HTTP_X_HUB_SIGNATURE']) && $_SERVER['HTTP_X_HUB_SIGNATURE'] === ('sha1=' . $hash)) {
$result = [];
$output = '';
exec("git pull", $result);
foreach ($result as $line) $output .= $line."\n";
exec("rm -rf " . __DIR__ . "/src/templates/twig_cache/*");
exec("touch " . __DIR__ . "/src/templates/twig_cache/.gitkeep");
exec("php composer.phar update -o");
$version = ($_SERVER["SERVER_NAME"] != 'tifod.com') ? json_decode($_POST['payload'])->after : json_decode($_POST['payload'])->release->tag_name;
$reponse = $db->prepare ('UPDATE platform_data SET data_value = :version WHERE data_name = "version"');
try {
$reponse->execute([ 'version' => $version ]);
$reponse->closeCursor();
} catch (Throwable $e){
die ("platform_data.version is missing in database, can't be updated!");
}
echo "<pre>" . $output . "</pre>";
} else {
echo "Signature not matching";
}
} else {
echo "Method to update not allowed";
}