*20.06.2023 -> 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
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
Nenninger N-Tools.de
|
||||
Version 1.8
|
||||
Version 1.12
|
||||
|
||||
*20.06.2023 -> 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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user