V1.8 20.06.2023 -> neue Parameter und devid darf keine Zeichen sondern nur Buchstaben und Zahlen enthalten

This commit is contained in:
2023-07-24 12:22:05 +02:00
parent 9e5a01d82c
commit 18a14e7436
2 changed files with 54 additions and 10 deletions

View File

@@ -1,7 +1,9 @@
<?php <?php
/* /*
Nenninger N-Tools.de Nenninger N-Tools.de
Version 1.7 Version 1.8
*20.06.2023 -> neue Parameter und devid darf keine Zeichen sondern nur Buchstaben und Zahlen enthalten
hermine@THW PHPConnector hermine@THW PHPConnector
inspiriert von https://gitlab.com/aeberhardt/stashcat-api-client inspiriert von https://gitlab.com/aeberhardt/stashcat-api-client
@@ -167,7 +169,7 @@ class UUID {
class hermineConnect{ class hermineConnect{
private $VERSION = '1.3'; private $VERSION = '1.8';
private $hermineServer = 'https://api.thw-messenger.de'; private $hermineServer = 'https://api.thw-messenger.de';
private $connectorID = ""; private $connectorID = "";
private $user = ""; private $user = "";
@@ -190,7 +192,11 @@ class hermineConnect{
$data = ''; $data = '';
$eol = "\r\n"; $eol = "\r\n";
$delimiter = '-------------' . $boundary; $delimiter = '-------------' . $boundary;
foreach ($fields as $name => $content) { foreach ($fields as $name => $content) {
/*echo "@@\n";
print_r($content);
echo "@@\n";*/
$data .= "--" . $delimiter . $eol $data .= "--" . $delimiter . $eol
. 'Content-Disposition: form-data; name="' . $name . "\"".$eol.$eol . 'Content-Disposition: form-data; name="' . $name . "\"".$eol.$eol
. $content . $eol . $content . $eol
@@ -221,7 +227,7 @@ class hermineConnect{
} }
$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 = base64_encode($cID); $this->connectorID =str_replace(['+','/','='], ['','',''],base64_encode($cID));
$this->user = $user; $this->user = $user;
$this->password = $password; $this->password = $password;
$this->passphrase = $passphrase; $this->passphrase = $passphrase;
@@ -254,7 +260,6 @@ class hermineConnect{
"Content-Length: " . strlen($_data), "Content-Length: " . strlen($_data),
'Expect:' 'Expect:'
)); ));
curl_setopt( $this->cURL, CURLOPT_COOKIESESSION, true ); curl_setopt( $this->cURL, CURLOPT_COOKIESESSION, true );
curl_setopt( $this->cURL, CURLOPT_COOKIEJAR, './hermineConnectCookie.txt' ); curl_setopt( $this->cURL, CURLOPT_COOKIEJAR, './hermineConnectCookie.txt' );
curl_setopt( $this->cURL, CURLOPT_COOKIEFILE, './hermineConnectCookie.txt' ); curl_setopt( $this->cURL, CURLOPT_COOKIEFILE, './hermineConnectCookie.txt' );
@@ -278,15 +283,32 @@ class hermineConnect{
return false; return false;
} }
} else { } else {
$this->lasterror = 'Curl error: ' . curl_error($cURL); $this->lasterror = 'Curl error: ' . curl_error($this->cURL);
return false; return false;
} }
} }
function _check(){
//Nenninger ab 20.06.2023 neue
$data = [
"app_name" => 'hermine@thw-PHP:'.$this->VERSION,
"encrypted" => true,
"callable" => false,
"key_transfer_support" => false
];
$response = $this->request($this->hermineServer."/auth/check",$data);
if($response !== false){
return true;
}else{
return false;
}
}
function _open_private_key(){ function _open_private_key(){
$data = []; //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); $response = $this->request($this->hermineServer."/security/get_private_key",$data);
$private_key = json_decode($response->keys->private_key); $private_key = json_decode($response->keys->private_key);
$privkey_decoded = openssl_pkey_get_private($private_key->private, $this->passphrase); $privkey_decoded = openssl_pkey_get_private($private_key->private, $this->passphrase);
@@ -497,6 +519,21 @@ class hermineConnect{
} }
} }
function _get_channel_infos($_id){
$data = [
"channel_id" => $_id,
"without_members" => false
];
$response = $this->request($this->hermineServer."/channels/info",$data);
if($response !== false){
return $response->channels;
}else{
return false;
}
}
/* /*
Öffentliche Funktionen Öffentliche Funktionen
*/ */
@@ -525,6 +562,7 @@ class hermineConnect{
$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;
$this->_check();
if($this->_open_private_key()){ if($this->_open_private_key()){
$this->companies = $this->get_companies(); $this->companies = $this->get_companies();
$this->channels = $this->get_channels($this->companies->companies[0]->id); $this->channels = $this->get_channels($this->companies->companies[0]->id);
@@ -538,13 +576,15 @@ class hermineConnect{
"password" => $this->password, "password" => $this->password,
"app_name" => 'hermine@thw-PHP:'.$this->VERSION, "app_name" => 'hermine@thw-PHP:'.$this->VERSION,
"encrypted" => true, "encrypted" => true,
"callable" => false "callable" => false,
"key_transfer_support" => false
]; ];
$response = $this->request($this->hermineServer."/auth/login",$data); $response = $this->request($this->hermineServer."/auth/login",$data);
if($response !== false){ if($response !== false){
$this->client_key = $response->client_key; $this->client_key = $response->client_key;
$this->user_id = $response->userinfo->id; $this->user_id = $response->userinfo->id;
$this->_check();
if($this->_open_private_key()){ if($this->_open_private_key()){
$this->companies = $this->get_companies(); $this->companies = $this->get_companies();
$this->channels = $this->get_channels($this->companies->companies[0]->id); $this->channels = $this->get_channels($this->companies->companies[0]->id);
@@ -611,15 +651,19 @@ class hermineConnect{
return $this->get_messages(array('channel',$_channel_id),$_limit,$_offset); return $this->get_messages(array('channel',$_channel_id),$_limit,$_offset);
} }
public function get_channel_infos($_channel_id){
return $this->_get_channel_infos($_channel_id);
}
public function search_user($_searchby, $_limit=50, $_offset=0){ public function search_user($_searchby, $_limit=50, $_offset=0){
$data = [ $data = [
"limit" => $_limit, "limit" => $_limit,
"offset" => $_offset, "offset" => $_offset,
"key_hashes" => false, "key_hashes" => false,
"search" => $_searchby, "search" => $_searchby,
"sorting" => ["first_name_asc", "last_name_asc"], "sorting" => '["first_name_asc", "last_name_asc"]',
"exclude_user_ids" => [], "exclude_user_ids" => '[]',
"group_ids" => [], "group_ids" => '[]',
]; ];
$response = $this->request($this->hermineServer."/users/listing",$data); $response = $this->request($this->hermineServer."/users/listing",$data);

Binary file not shown.