From 1f81c383eb789eeb3281ba6df44aa7a9e5bb2371 Mon Sep 17 00:00:00 2001 From: damage Date: Tue, 20 Oct 2026 20:18:57 +0200 Subject: [PATCH] init ci --- config.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ message.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 config.php create mode 100644 message.php diff --git a/config.php b/config.php new file mode 100644 index 0000000..3481f8f --- /dev/null +++ b/config.php @@ -0,0 +1,45 @@ +nextCloudBaseUrl = $this->getRequired($config, Config::NEXTCLOUD_BASE_URL); + $this->secret = $this->getRequired($config, Config::SECRET); + $this->username = $this->getRequired($config, Config::BASIC_AUTH_USERNAME); + $this->password = $this->getRequired($config, Config::BASIC_AUTH_PASSWORD); + } + + private function getRequired($config, $key) { + if (array_key_exists($key, $config)) { + return $config[$key]; + } else { + throw new Exception("missing configuration " . $key); + } + } + + public function getSecret() { + return $this->secret; + } + + public function getUrl() { + return $this->nextCloudBaseUrl . '/ocs/v2.php/apps/spreed/api/v1'; + } + + public function getUsername() { + return $this->username; + } + + public function getPassword() { + return $this->password; + } +} + diff --git a/message.php b/message.php new file mode 100644 index 0000000..6fb38e4 --- /dev/null +++ b/message.php @@ -0,0 +1,53 @@ +getUsername() == $_SERVER['PHP_AUTH_USER'] + || !$config->getPassword() == $_SERVER['PHP_AUTH_PW']) { + die('invalid credentials'); +} + +if (!array_key_exists('action', $_GET) + || !array_key_exists('token', $_GET)) { + die("required parameters not given"); +} + +//$message = file_get_contents('php://stdin'); +$message = file_get_contents('php://input'); +$token = $_GET['token']; +$url = $config->getUrl() . '/bot/' . $token . '/message'; +$random = bin2hex(random_bytes(32)); + +$digest = hash_hmac('sha256', $random . $message, $config->getSecret()); + +$data = json_encode( + array( + 'message' => $message + ) +); + +$opts = array('http' => + array( + 'method' => 'POST', + 'header' => array( + 'X-Nextcloud-Talk-Bot-Random: ' . $random, + 'X-Nextcloud-Talk-Bot-Signature: ' . $digest, + 'OCS-APIRequest: true', + 'Content-Type: application/json' + ), + 'content' => $data + ) +); + +$context = stream_context_create($opts); + +$result = file_get_contents($url, false, $context); +var_dump($result); \ No newline at end of file