Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return array(
'passwd' => 'change me'
'passwd' => 'change me'
);
20 changes: 12 additions & 8 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

require_once('inc.php');
header('Content-Type: text/plain');
if(file_exists('key.php')) {
$key = require('key.php');
if($key['current'] === $_SERVER['QUERY_STRING']) {
$pwd = getcwd();
chdir(dirname($pwd));
_exec('pwd');
_exec('git pull');
}
if (file_exists('key.php'))
{
$key = require('key.php');
if ($key['current'] === $_SERVER['QUERY_STRING'])
{
$submodule = getcwd();
$project = $submodule.'/../../../';
chdir(dirname($project));
_exec('pwd');
_exec('git pull');
_exec('git submodule update');
}
}

_log(var_export($_POST, true));
18 changes: 10 additions & 8 deletions inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

#error_reporting(0);

function _exec($cmd) {
$out = "$ ".$cmd."\n";
$out .= shell_exec($cmd.' 2>&1');
_log($out);
function _exec($cmd)
{
$out = "$ " . $cmd . "\n";
$out .= shell_exec($cmd . ' 2>&1');
_log($out);
}

function _log($str) {
$out = "\n".date('r')." ".$str;
echo $out;
error_log($out, 3, '.webhook.log');
function _log($str)
{
$out = "\n" . date('r') . " " . $str;
echo $out;
error_log($out, 3, '.webhook.log');
}
53 changes: 32 additions & 21 deletions link.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
require_once('inc.php');
$config = require('config.php');

if(file_exists('key.php')) {
$key = require('key.php');
if($key['current'] !== $_SERVER['QUERY_STRING']) {
if($key['previous'] === $_SERVER['QUERY_STRING']) {
header('Location: ?'.$key['current']);
} else if(!isset($_POST['passwd'])) {
echo '<form method="post"><input type="password" name="passwd" /></form>';
} else if($_POST['passwd'] !== $config['passwd']) {
echo 'Wrong';
} else {
header('Location: ?'.$key['current']);
if (file_exists('key.php'))
{
$key = require('key.php');
if ($key['current'] !== $_SERVER['QUERY_STRING'])
{
if ($key['previous'] === $_SERVER['QUERY_STRING'])
{
header('Location: ?' . $key['current']);
}
else if (!isset($_POST['passwd']))
{
echo '<form method="post"><input type="password" name="passwd" /></form>';
}
else if ($_POST['passwd'] !== $config['passwd'])
{
echo 'Wrong';
}
else
{
header('Location: ?' . $key['current']);
}
exit;
}
exit;
}
} else {
}
else
{
}

mt_srand(microtime(true)*1000);
$new = sha1(crypt(microtime(true).mt_rand().time().mt_rand()));
file_put_contents('key.php', '<?php return '.var_export(array(
'current' => $new,
'previous' => isset($key) ? $key['current'] : '',
), true).';');
mt_srand(microtime(true) * 1000);
$new = sha1(crypt(microtime(true) . mt_rand() . time() . mt_rand()));
file_put_contents('key.php', '<?php return ' . var_export(array(
'current' => $new,
'previous' => isset($key) ? $key['current'] : '',
), true) . ';');

echo '<label for="webhook">Webhook:</label> <input id="webhook" size="80" type="text" value="'.dirname($_SERVER['SCRIPT_URI']).'/hook.php?'.$new.'" />';
echo '<label for="webhook">Webhook:</label> <input id="webhook" size="80" type="text" value="' . dirname($_SERVER['SCRIPT_URI']) . '/hook.php?' . $new . '" />';
//print_r($_SERVER);