erster Wurf -> funktioniert noch nicht!

This commit is contained in:
2022-08-08 15:21:04 +02:00
commit ba6959ce21
2 changed files with 135 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
_login response.txt

134
hermineConnect.php Normal file
View File

@@ -0,0 +1,134 @@
<?php
/*
Nenninger N-Tools.de
Version 1.1
hermine@THW PHPConnector
inspiriert von https://gitlab.com/aeberhardt/stashcat-api-client
*/
class hermineConnect{
private $hermineServer = 'https://api.thw-messenger.de';
//private $hermineServer = 'https://thw.n-tools.de';
private $connectorID = "";
private $user = "";
private $password = "";
private $passphrase = "";
private $cURL;
private $client_key = "";
private $user_id = "";
function __construct($user,$password,$passphrase) {
$this->connectorID = base64_encode('deadbeef'.sha1($_SERVER['SERVER_NAME']));
$this->user = $user;
$this->password = $password;
$this->passphrase = $passphrase;
$this->cURL = curl_init();
}
function __destruct() {
curl_close($this->cURL);
}
function request($_url,$_data){
$_data['device_id'] = $this->connectorID;
if($this->client_key != '')
$_data['client_key'] = $this->client_key;
print_r($_data);
curl_setopt($this->cURL, CURLOPT_URL, $_url);
//curl_setopt($this->cURL, CURLOPT_PORT , 443);
curl_setopt($this->cURL, CURLOPT_VERBOSE, 0);
//curl_setopt($this->cURL, CURLOPT_HEADER, 0);
//curl_setopt($this->cURL, CURLOPT_SSLVERSION, 3);
//curl_setopt($this->cURL, CURLOPT_SSLCERT, getcwd() . "/client.pem");
//curl_setopt($this->cURL, CURLOPT_SSLKEY, getcwd() . "/keyout.pem");
//curl_setopt($this->cURL, CURLOPT_CAINFO, getcwd() . "/ca.pem");
curl_setopt($this->cURL, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($this->cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->cURL, CURLOPT_POST, true);
//curl_setopt($this->cURL, CURLOPT_BINARYTRANSFER, true);
curl_setopt($this->cURL, CURLOPT_POSTFIELDS,$_data);
curl_setopt($this->cURL, CURLOPT_HTTPHEADER, array("Accept: application/json, text/plain, */*","Connection: keep-alive","Keep-Alive: timeout=5, max=100"));
curl_setopt( $this->cURL, CURLOPT_COOKIESESSION, true );
curl_setopt( $this->cURL, CURLOPT_COOKIEJAR, './hermineConnectCookie.txt' );
curl_setopt( $this->cURL, CURLOPT_COOKIEFILE, './hermineConnectCookie.txt' );
$data = curl_exec($this->cURL);
if(!curl_errno($this->cURL)){
$data = json_decode($data);
if($data->status->value != "OK")
print_r($data);
$info = curl_getinfo($this->cURL);
return $data->payload;// 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
} else {
return false; //echo 'Curl error: ' . curl_error($cURL);
}
}
function open_private_key(){
$data = [];
$response = $this->request($this->hermineServer."/security/get_private_key",$data);
print_r($response->keys->private_key);
//$privkey_decoded = @openssl_pkey_get_private($private_key, $this->passphrase);
}
/*open_private_key(self, encryption_password):
data = self._post("security/get_private_key", data={})
private_key_field = json.loads(data["keys"]["private_key"])
# there might be an unescaping bug here....
self.private_key = Crypto.PublicKey.RSA.import_key(
private_key_field["private"], passphrase=encryption_password
) */
public function getID(){
return $this->connectorID;
}
public function login(){
$data = [
"email" => $this->user,
"password" => $this->password,
"app_name" => 'hermine@thw-php:1.1-browser-0',
"encrypted" => true,
"callable" => true
];
$response = $this->request($this->hermineServer."/auth/login",$data);
if($response !== false){
$this->client_key = $response->client_key;
$this->user_id = $response->userinfo->id;
$this->open_private_key();
return $response;
}
}
public function get_companies(){
$data = [
"no_cache" => true
];
$response = $this->request($this->hermineServer."/company/member",$data);
if($response !== false){
return $response;
}else{
return false;
}
}
}
$test = new hermineConnect('xxx@n4h.de','xxx','xxxx');
echo $test->getID();
$test->login();
print_r($test);
//print_r($test->get_companies());
?>