Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Very basic webhook.

  • Loading branch information...
commit 71cb931fb4b8e41c78047ef3b368a3369fd6ce8f 1 parent 5a5c6da
@oleics authored
Showing with 67 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +5 −0 config.dist.php
  3. +15 −0 hook.php
  4. +15 −0 inc.php
  5. +31 −0 link.php
View
1  .gitignore
@@ -0,0 +1 @@
+config.php
View
5 config.dist.php
@@ -0,0 +1,5 @@
+<?php
+
+return array(
+ 'passwd' => 'change me'
+);
View
15 hook.php
@@ -0,0 +1,15 @@
+<?php
+
+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');
+ }
+}
+
+_log(var_export($_POST, true));
View
15 inc.php
@@ -0,0 +1,15 @@
+<?php
+
+#error_reporting(0);
+
+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');
+}
View
31 link.php
@@ -0,0 +1,31 @@
+<?php
+
+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']);
+ }
+ exit;
+ }
+} 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).';');
+
+echo '<label for="webhook">Webhook:</label> <input id="webhook" size="80" type="text" value="'.dirname($_SERVER['SCRIPT_URI']).'/hook.php?'.$new.'" />';
+//print_r($_SERVER);
Please sign in to comment.
Something went wrong with that request. Please try again.