From 03992a0a2acf5ea87eb3299cf158bcb4c1b84e56 Mon Sep 17 00:00:00 2001 From: "NTEN\\Nenninger" Date: Tue, 31 Oct 2023 15:17:08 +0100 Subject: [PATCH] =?UTF-8?q?*20.06.2023=20->=20neue=20Parameter=20und=20dev?= =?UTF-8?q?id=20darf=20keine=20Zeichen=20sondern=20nur=20Buchstaben=20und?= =?UTF-8?q?=20Zahlen=20enthalten=20=20*13.09.2023=20->=20cookie=20Datei=20?= =?UTF-8?q?und=20Login.dat=20umbenannt=20=20*19.09.2023=20->=20$=5FSERVER[?= =?UTF-8?q?'SERVER=5FNAME']=20wird=20wenn=20nicht=20da=20auf=20Hostname=20?= =?UTF-8?q?gesetzt=20=20*20.09.2023=20->=20get=5Fchannel=5Fmessages=20korr?= =?UTF-8?q?igiert=20(limit,=20offset)=20=20*26.09.2023=20->=20l=C3=B6schen?= =?UTF-8?q?=20von=20Dateien=20eingebaut;=20=20*31.10.2023=20->=20Fehler=20?= =?UTF-8?q?beim=20speichern=20der=20Logins=20gefixt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hermineConnect.php | 121 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 28 deletions(-) diff --git a/hermineConnect.php b/hermineConnect.php index 2f46e65..fb9b4db 100644 --- a/hermineConnect.php +++ b/hermineConnect.php @@ -1,9 +1,14 @@ neue Parameter und devid darf keine Zeichen sondern nur Buchstaben und Zahlen enthalten + *13.09.2023 -> cookie Datei und Login.dat umbenannt + *19.09.2023 -> $_SERVER['SERVER_NAME'] wird wenn nicht da auf Hostname gesetzt + *20.09.2023 -> get_channel_messages korrigiert (limit, offset) + *26.09.2023 -> löschen von Dateien eingebaut; + *31.10.2023 -> Fehler beim speichern der Logins gefixt hermine@THW PHPConnector inspiriert von https://gitlab.com/aeberhardt/stashcat-api-client @@ -169,7 +174,8 @@ class UUID { class hermineConnect{ - private $VERSION = '1.8'; + private $VERSION = '1.12'; + private $MACHINENAME = 'default'; private $hermineServer = 'https://api.thw-messenger.de'; private $connectorID = ""; private $user = ""; @@ -225,6 +231,10 @@ class hermineConnect{ } return $ret; } + if(!isset($_SERVER['SERVER_NAME'])){ //wenn php ohne Apache aufgerufen wird ... + exec("hostname",$ret); + $_SERVER['SERVER_NAME'] = implode(" ",$ret); + } $cID = array_map('hexdec', str_split('deadbeef'.sha1($_SERVER['SERVER_NAME']), 2)); $cID = intArrayToString($cID); $this->connectorID =str_replace(['+','/','='], ['','',''],base64_encode($cID)); @@ -232,6 +242,7 @@ class hermineConnect{ $this->password = $password; $this->passphrase = $passphrase; $this->cURL = curl_init(); + $this->MACHINENAME = $_SERVER['SERVER_NAME']; } function __destruct() { @@ -293,7 +304,7 @@ class hermineConnect{ function _check(){ //Nenninger ab 20.06.2023 neue $data = [ - "app_name" => 'hermine@thw-PHP:'.$this->VERSION, + "app_name" => 'hermine@'.$this->MACHINENAME.'-PHP:'.$this->VERSION, "encrypted" => true, "callable" => false, "key_transfer_support" => false @@ -310,14 +321,22 @@ class hermineConnect{ //Nenninger ab 20.06.2023 neue Parameter format=pem&type=encryption $data = ['format'=>'pem','type'=>'encryption']; $response = $this->request($this->hermineServer."/security/get_private_key",$data); - $private_key = json_decode($response->keys->private_key); - $privkey_decoded = openssl_pkey_get_private($private_key->private, $this->passphrase); - if($privkey_decoded !== false){ - $this->private_key = $privkey_decoded; - return true; - }else{ - return false; - } + if($response !== false){ + if(property_exists($response,'keys')){ + $private_key = json_decode($response->keys->private_key); + $privkey_decoded = openssl_pkey_get_private($private_key->private, $this->passphrase); + if($privkey_decoded !== false){ + $this->private_key = $privkey_decoded; + return true; + }else{ + return false; + } + }else{ + return false; + } + }else{ + return false; + } } function _get_conversation_key($_target){ @@ -492,11 +511,15 @@ class hermineConnect{ foreach($response->messages as $message){ if($message->kind == "message"){ if($message->encrypted){ - $encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->text)), $conversation_key, hex2bin($message->iv)); - if($encryptet !== false) - $message->text = $encryptet; - else - $message->text = '[!!decrypterror!!]'; + if($message->text != ''){ + $encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->text)), $conversation_key, hex2bin($message->iv)); + if($encryptet !== false) + $message->text = $encryptet; + else + $message->text = '[!!decrypterror!!]'; + }else{ + $message->text = '[Dieser Inhalt wurde gelöscht.]'; + } } if($message->location->encrypted){ $encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->location->latitude)), $conversation_key, hex2bin($message->location->iv)); @@ -533,7 +556,43 @@ class hermineConnect{ return false; } } - + + function list_uploaded_files($_type,$_search,$_offset,$_limit,$_sorting){ + /*type=chats& search=& offset=0& limit=75& sorting=created_desc*/ + $data = [ + "type" => $_type, + "search" => $_search, + "offset" => $_offset, + "limit" => $_limit, + "sorting" => $_sorting + ]; + + $response = $this->request($this->hermineServer."/folder/list_uploaded_files",$data); + + if($response !== false){ + //print_r($response); + return $response->files; + }else{ + return false; + } + } + + public function _delete_files($_ids=[]){ + /*file_ids=%5B8826184%5D ([8826184])*/ + $data = [ + "file_ids" => json_encode($_ids) + ]; + + $response = $this->request($this->hermineServer."/file/delete",$data); + + if($response !== false){ + //print_r($response); + return $response->success; + }else{ + return false; + } + } + /* Öffentliche Funktionen */ @@ -556,9 +615,10 @@ class hermineConnect{ Login, wenn $_saveLogin=true, dann wird device_id und client_key in login.dat gespeichert und es erfolgt keine Mitteilung in Hermine */ public function login($_saveLogin=false){ + $savelogin = new stdClass(); if($_saveLogin){ - if(file_exists('./login.dat')){ - $savelogin = json_decode(file_get_contents('./login.dat')); + if(file_exists('./hermineConnectLogin.dat')){ + $savelogin = json_decode(file_get_contents('./hermineConnectLogin.dat')); $this->client_key = $savelogin->ClientKey; $this->connectorID = $savelogin->DeviceId; $this->user_id = $savelogin->UserID; @@ -590,10 +650,11 @@ class hermineConnect{ $this->channels = $this->get_channels($this->companies->companies[0]->id); $this->conversations = $this->get_conversations(); if($_saveLogin){ - $savelogin['ClientKey'] = $this->client_key; - $savelogin['DeviceId'] = $this->connectorID; - $savelogin['UserID'] = $this->user_id; - file_put_contents('./login.dat',json_encode($savelogin)); + print_r($savelogin); + $savelogin->ClientKey = $this->client_key; + $savelogin->DeviceId = $this->connectorID; + $savelogin->UserID = $this->user_id; + file_put_contents('./hermineConnectLogin.dat',json_encode($savelogin)); } return true; } @@ -647,7 +708,7 @@ class hermineConnect{ return $this->get_messages(array('conversation',$_conversation_id),$_limit,$_offset); } - public function get_channel_messages($_channel_id){ + public function get_channel_messages($_channel_id,$_limit=50, $_offset=0){ return $this->get_messages(array('channel',$_channel_id),$_limit,$_offset); } @@ -674,8 +735,12 @@ class hermineConnect{ } } - - + public function list_uploaded_chat_files($_search){ + return $this->list_uploaded_files('chats',$_search,0,99999,'created_desc'); + } + + public function delete_files($_ids=[]){ + return $this->_delete_files($_ids); + } } -?> - +?> \ No newline at end of file