forked from natxet/welovejs-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
70 lines (61 loc) · 2.16 KB
/
deploy.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
Configuration: just put here the filename in which the hash will be stored
It must be non readable from the public folder!
*/
$token_filename = '.gittoken';
$destinations = array('[email protected]');
if(!isset($_GET['token']) || !$_GET['token']) die('No token');
if(!file_exists($token_filename)) file_put_contents($token_filename, $_GET['token']);
$token = trim(file_get_contents($token_filename));
if($_GET['token'] != $token) die('Incorrect token. Delete $token_filename file for storing a new token');
// todo: estas son las ips de github 207.97.227.253, 50.57.128.197, 108.171.174.178
/**
* based on https://gist.github.com/1809044
*/
// The commands
$commands = array(
'echo $PWD',
'whoami',
// 'git reset --hard HEAD',
'git pull',
'git status',
'git submodule sync',
'git submodule update',
'git submodule status',
);
// Run the commands for output
$output = $commands_results = '';
foreach($commands AS $command){
// Run it
$tmp = shell_exec($command . " 2>&1");
// Output
$output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #729FCF;\">{$command}\n</span>";
$output .= htmlentities(trim($tmp)) . "\n";
$commands_results .= htmlentities(trim($tmp)) . "\n";
}
$author = $_POST['payload']['pusher']['email'];
if(!in_array($author, $destinations)) $destinations[] = $author;
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
foreach($destinations as $destination ) {
mail( $destination, 'Server deployed via github', "IP: $ip\n" . var_export($_POST, true) . "\n\n" . $commands_results );
}
// Make it pretty for manual user access (and why not?)
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>GIT DEPLOYMENT SCRIPT</title>
</head>
<body style="background-color: #000000; color: #FFFFFF; font-weight: bold; padding: 0 10px;">
<pre>
. ____ . ____________________________
|/ \| | |
[| <span style="color: #FF0000;">♥ ♥</span> |] | Git Deployment Script v0.1 |
|___==___| / © oodavid 2012 |
|____________________________|
<?php echo $output; ?>
</pre>
</body>
</html>