*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
|
<?php
|
||||||
/*
|
/*
|
||||||
Nenninger N-Tools.de
|
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
|
*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
|
hermine@THW PHPConnector
|
||||||
inspiriert von https://gitlab.com/aeberhardt/stashcat-api-client
|
inspiriert von https://gitlab.com/aeberhardt/stashcat-api-client
|
||||||
@@ -169,7 +174,8 @@ class UUID {
|
|||||||
|
|
||||||
|
|
||||||
class hermineConnect{
|
class hermineConnect{
|
||||||
private $VERSION = '1.8';
|
private $VERSION = '1.12';
|
||||||
|
private $MACHINENAME = 'default';
|
||||||
private $hermineServer = 'https://api.thw-messenger.de';
|
private $hermineServer = 'https://api.thw-messenger.de';
|
||||||
private $connectorID = "";
|
private $connectorID = "";
|
||||||
private $user = "";
|
private $user = "";
|
||||||
@@ -225,6 +231,10 @@ class hermineConnect{
|
|||||||
}
|
}
|
||||||
return $ret;
|
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 = array_map('hexdec', str_split('deadbeef'.sha1($_SERVER['SERVER_NAME']), 2));
|
||||||
$cID = intArrayToString($cID);
|
$cID = intArrayToString($cID);
|
||||||
$this->connectorID =str_replace(['+','/','='], ['','',''],base64_encode($cID));
|
$this->connectorID =str_replace(['+','/','='], ['','',''],base64_encode($cID));
|
||||||
@@ -232,6 +242,7 @@ class hermineConnect{
|
|||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
$this->passphrase = $passphrase;
|
$this->passphrase = $passphrase;
|
||||||
$this->cURL = curl_init();
|
$this->cURL = curl_init();
|
||||||
|
$this->MACHINENAME = $_SERVER['SERVER_NAME'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function __destruct() {
|
function __destruct() {
|
||||||
@@ -293,7 +304,7 @@ class hermineConnect{
|
|||||||
function _check(){
|
function _check(){
|
||||||
//Nenninger ab 20.06.2023 neue
|
//Nenninger ab 20.06.2023 neue
|
||||||
$data = [
|
$data = [
|
||||||
"app_name" => 'hermine@thw-PHP:'.$this->VERSION,
|
"app_name" => 'hermine@'.$this->MACHINENAME.'-PHP:'.$this->VERSION,
|
||||||
"encrypted" => true,
|
"encrypted" => true,
|
||||||
"callable" => false,
|
"callable" => false,
|
||||||
"key_transfer_support" => false
|
"key_transfer_support" => false
|
||||||
@@ -310,14 +321,22 @@ class hermineConnect{
|
|||||||
//Nenninger ab 20.06.2023 neue Parameter format=pem&type=encryption
|
//Nenninger ab 20.06.2023 neue Parameter format=pem&type=encryption
|
||||||
$data = ['format'=>'pem','type'=>'encryption'];
|
$data = ['format'=>'pem','type'=>'encryption'];
|
||||||
$response = $this->request($this->hermineServer."/security/get_private_key",$data);
|
$response = $this->request($this->hermineServer."/security/get_private_key",$data);
|
||||||
$private_key = json_decode($response->keys->private_key);
|
if($response !== false){
|
||||||
$privkey_decoded = openssl_pkey_get_private($private_key->private, $this->passphrase);
|
if(property_exists($response,'keys')){
|
||||||
if($privkey_decoded !== false){
|
$private_key = json_decode($response->keys->private_key);
|
||||||
$this->private_key = $privkey_decoded;
|
$privkey_decoded = openssl_pkey_get_private($private_key->private, $this->passphrase);
|
||||||
return true;
|
if($privkey_decoded !== false){
|
||||||
}else{
|
$this->private_key = $privkey_decoded;
|
||||||
return false;
|
return true;
|
||||||
}
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _get_conversation_key($_target){
|
function _get_conversation_key($_target){
|
||||||
@@ -492,11 +511,15 @@ class hermineConnect{
|
|||||||
foreach($response->messages as $message){
|
foreach($response->messages as $message){
|
||||||
if($message->kind == "message"){
|
if($message->kind == "message"){
|
||||||
if($message->encrypted){
|
if($message->encrypted){
|
||||||
$encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->text)), $conversation_key, hex2bin($message->iv));
|
if($message->text != ''){
|
||||||
if($encryptet !== false)
|
$encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->text)), $conversation_key, hex2bin($message->iv));
|
||||||
$message->text = $encryptet;
|
if($encryptet !== false)
|
||||||
else
|
$message->text = $encryptet;
|
||||||
$message->text = '[!!decrypterror!!]';
|
else
|
||||||
|
$message->text = '[!!decrypterror!!]';
|
||||||
|
}else{
|
||||||
|
$message->text = '[Dieser Inhalt wurde gelöscht.]';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if($message->location->encrypted){
|
if($message->location->encrypted){
|
||||||
$encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->location->latitude)), $conversation_key, hex2bin($message->location->iv));
|
$encryptet = $this->_decrypt_aes(base64_encode(hex2bin($message->location->latitude)), $conversation_key, hex2bin($message->location->iv));
|
||||||
@@ -533,7 +556,43 @@ class hermineConnect{
|
|||||||
return false;
|
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
|
Ö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
|
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){
|
public function login($_saveLogin=false){
|
||||||
|
$savelogin = new stdClass();
|
||||||
if($_saveLogin){
|
if($_saveLogin){
|
||||||
if(file_exists('./login.dat')){
|
if(file_exists('./hermineConnectLogin.dat')){
|
||||||
$savelogin = json_decode(file_get_contents('./login.dat'));
|
$savelogin = json_decode(file_get_contents('./hermineConnectLogin.dat'));
|
||||||
$this->client_key = $savelogin->ClientKey;
|
$this->client_key = $savelogin->ClientKey;
|
||||||
$this->connectorID = $savelogin->DeviceId;
|
$this->connectorID = $savelogin->DeviceId;
|
||||||
$this->user_id = $savelogin->UserID;
|
$this->user_id = $savelogin->UserID;
|
||||||
@@ -590,10 +650,11 @@ class hermineConnect{
|
|||||||
$this->channels = $this->get_channels($this->companies->companies[0]->id);
|
$this->channels = $this->get_channels($this->companies->companies[0]->id);
|
||||||
$this->conversations = $this->get_conversations();
|
$this->conversations = $this->get_conversations();
|
||||||
if($_saveLogin){
|
if($_saveLogin){
|
||||||
$savelogin['ClientKey'] = $this->client_key;
|
print_r($savelogin);
|
||||||
$savelogin['DeviceId'] = $this->connectorID;
|
$savelogin->ClientKey = $this->client_key;
|
||||||
$savelogin['UserID'] = $this->user_id;
|
$savelogin->DeviceId = $this->connectorID;
|
||||||
file_put_contents('./login.dat',json_encode($savelogin));
|
$savelogin->UserID = $this->user_id;
|
||||||
|
file_put_contents('./hermineConnectLogin.dat',json_encode($savelogin));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -647,7 +708,7 @@ class hermineConnect{
|
|||||||
return $this->get_messages(array('conversation',$_conversation_id),$_limit,$_offset);
|
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);
|
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