diff --git a/secret.php.example b/secret.php.example index 1077fb5..5f2227b 100644 --- a/secret.php.example +++ b/secret.php.example @@ -8,6 +8,8 @@ $_m['data'] = ''; $_m['pre'] = ''; $_m['salt'] = ''; +$_m['issuedata'] = ['domain'=>'','secret'=>'']; + $_sendermail = 'noreply@.de'; $_smtp['srv'] = 'mail.seemsleg.it'; $_smtp['user'] = 'noreply@.de'; diff --git a/sql.php b/sql.php index e0ae57e..f6e8d29 100644 --- a/sql.php +++ b/sql.php @@ -4,6 +4,7 @@ class SQL { private $res = false; private $m; public $salt; + public $issuedata; public $pre; public $cnt_get = 0; public $cnt_set = 0; @@ -11,6 +12,7 @@ class SQL { require_once ('secret.php'); $this->m = $_m; + $this->issuedata = $_m['issuedata']; $this->pre = $_m ['pre']; $this->salt = $_m ['salt']; if (SQL_LOG) diff --git a/troy-api.php b/troy-api.php index 56ca06b..01517cc 100644 --- a/troy-api.php +++ b/troy-api.php @@ -1,16 +1,50 @@ array ( - 'method' => 'POST', - 'header' => array ( - 'Content-Type: application/json' - ), - 'content' => json_encode ( $data ) - ) - ); - $context = stream_context_create ( $options ); - return file_get_contents ( $url, false, $context ); + $url = 'https://troy-grunt.de/api.php'; + $options = array ( + 'http' => array ( + 'method' => 'POST', + 'header' => array ( + 'Content-Type: application/json' + ), + 'content' => json_encode ( $data ) + ) + ); + $context = stream_context_create ( $options ); + return file_get_contents ( $url, false, $context ); +} + +function troysIssue($ident, $typ, $text = null, $data = [], $reaction = [], $wait_til = null) { + global $sql; + $url = "https://issues.troy-grunt.de/api/input"; + + $payload = [ + "domain" => $sql->issuedata['domain'], + "secret" => $sql->issuedata['secret'], + "ident" => $ident, + "typ" => $typ, + "text" => $text, + "data" => $data, + "reaction" => $reaction + ]; + + // Entferne null-Werte aus dem Array + $payload = array_filter($payload, function ($value) { + return $value !== null; + }); + + $options = [ + "http" => [ + "header" => "Content-Type: application/json\r\n", + "method" => "POST", + "content" => json_encode($payload), + "ignore_errors" => true + ] + ]; + + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); + + return json_decode($result, true); } ?> \ No newline at end of file