1
0

update via webhook

This commit is contained in:
Mike Schwörer 2018-02-03 14:42:51 +01:00
parent fd893db541
commit fe5f066621
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 29 additions and 0 deletions

View File

@ -40,6 +40,7 @@ $URL_RULES =
[ 'url' => ['api', 'test'], 'target' => 'pages/api_test.php', 'options' => [ '_opt' => 'http', ], ], [ 'url' => ['api', 'test'], 'target' => 'pages/api_test.php', 'options' => [ '_opt' => 'http', ], ],
[ 'url' => ['api', 'setselfadress'], 'target' => 'pages/api_setselfadress.php', 'options' => [ '_opt' => 'http', ], ], [ 'url' => ['api', 'setselfadress'], 'target' => 'pages/api_setselfadress.php', 'options' => [ '_opt' => 'http', ], ],
[ 'url' => ['api', 'statsping'], 'target' => 'pages/api_stats.php', 'options' => [ '_opt' => 'http', 'Name' => '%GET%', 'ClientID' => '%GET%', 'Version' => '%GET%', 'ProviderStr' => '%GET%', 'ProviderID' => '%GET%', 'NoteCount' => '%GET%', ], ], [ 'url' => ['api', 'statsping'], 'target' => 'pages/api_stats.php', 'options' => [ '_opt' => 'http', 'Name' => '%GET%', 'ClientID' => '%GET%', 'Version' => '%GET%', 'ProviderStr' => '%GET%', 'ProviderID' => '%GET%', 'NoteCount' => '%GET%', ], ],
[ 'url' => ['api', 'webhook', '${target}'], 'target' => 'pages/api_webhook.php', 'options' => [ '_opt' => 'http', 'target' => '%URL%', 'secret' => '%GET%', ],],
[ 'url' => ['admin'], 'target' => 'pages/admin.php', 'options' => [ '_opt' => 'password'], ], [ 'url' => ['admin'], 'target' => 'pages/admin.php', 'options' => [ '_opt' => 'password'], ],
[ 'url' => ['admin', 'cmd', '?{cmd}'], 'target' => 'pages/admin_cmd.php', 'options' => [ '_opt' => 'password', 'cmd' => '%URL%'], ], [ 'url' => ['admin', 'cmd', '?{cmd}'], 'target' => 'pages/admin_cmd.php', 'options' => [ '_opt' => 'password', 'cmd' => '%URL%'], ],

28
www/pages/api_webhook.php Normal file
View File

@ -0,0 +1,28 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
$hook = $OPTIONS['target'];
$secret = $OPTIONS['secret'];
$uri = $OPTIONS['uri'];
if ($secret !== $CONFIG['webhook_secret']) die('Unauthorized.');
$cmd = "";
if ($hook == 'website_mikescher') $cmd = 'git pull';
else if ($hook == 'griddominance') $cmd = 'update-gdapi';
else throw new Exception("Unknown webhook: $hook");
$std = shell_exec($cmd);
$content = "REQUEST: " . $uri . "\r\n\r\n" .
"IP: " . get_client_ip() . "\r\n\r\n" .
"TARGET: " . $hook . "\r\n\r\n" .
"OUTPUT: " . $std . "\r\n\r\n";
sendMail("Webhook '$hook' triggered", $content, 'virtualadmin@mikescher.de', 'webserver-error@mikescher.com');