Update KeyHelp.php

New:
- Adding getCURL()
- Replaced tabs with spaces

Still not working:
- synchronizeAccount() waiting for FOSSBilling
This commit is contained in:
Syltmedia 2023-01-12 18:12:21 +01:00 committed by GitHub
parent 6eec3339cb
commit 359a1211e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,10 +15,6 @@
* @see https://app.swaggerhub.com/apis-docs/keyhelp/api/2.4 * @see https://app.swaggerhub.com/apis-docs/keyhelp/api/2.4
*/ */
class Server_Manager_KeyHelp extends Server_Manager { class Server_Manager_KeyHelp extends Server_Manager {
/**
* Method is called just after obejct contruct is complete.
* Add required parameters checks here.
*/
public function init() public function init()
{ {
if (!extension_loaded('curl')) { if (!extension_loaded('curl')) {
@ -60,52 +56,36 @@ class Server_Manager_KeyHelp extends Server_Manager {
]; ];
} }
/**
* curl GET
*/
public function getCURL($action, $actionEx)
{
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = $action . $actionEx;
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash'];
$curl_session = curl_init();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
return $result;
}
/**
* Later: Custom login url for User ;) Waiting for FOSSBilling
*/
public function getLoginUrl() public function getLoginUrl()
{ {
/*
###############################
### VORBEREITUNG FÜR SPÄTER ###
###############################
$username = "rokkcloud";
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$username;
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash'];
$curl_session = curl_init();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id;
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "login/".$userID;
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash'];
$curl_session = curl_init();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userLogin = $result->url;
return $userLogin; */
$host = $this->_config['host']; $host = $this->_config['host'];
return 'https://'.$host.''; return 'https://'.$host.'';
} }
@ -115,27 +95,14 @@ class Server_Manager_KeyHelp extends Server_Manager {
return 'https://'.$host.''; return 'https://'.$host.'';
} }
/**
* Here we check if the API is working ;)
*/
public function testConnection() public function testConnection()
{ {
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "ping"; $action = "ping";
$actionapiUrl = $apiUrl . $action; $actionEx = "";
$apiKey = $this->_config['accesshash']; $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$curl_session = curl_init();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
if(isset($result)) { if(isset($result)) {
return true; return true;
@ -145,31 +112,21 @@ class Server_Manager_KeyHelp extends Server_Manager {
} }
} }
/**
* Not working, because of FOSSBilling
*/
public function synchronizeAccount(Server_Account $a) public function synchronizeAccount(Server_Account $a)
{ {
$host = $this->_config['host']; $action = "clients/name/";
$apiUrl = "https://".$host."/api/v2/"; $actionEx = $a->getUsername();
$action = "clients/name/".$a->getUsername(); $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash'];
$curl_session = curl_init();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id;
$new = clone $a; $new = clone $a;
$new->setSuspended($result->is_suspended); if(empty($result->is_suspended)) {
$new->setUsername($result->username); $new->setSuspended(false);
} else {
$new->setSuspended(true);
}
return $new; return $new;
} }
@ -180,27 +137,31 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function createAccount(Server_Account $a) public function createAccount(Server_Account $a)
{ {
$apiUrl = "https://".$this->_config['host']."/api/v2/"; $apiUrl = "https://".$this->_config['host']."/api/v2/";
$action = "clients/";
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash']; $apiKey = $this->_config['accesshash'];
$this->getLog()->info('Creating account '.$a->getUsername()); $this->getLog()->info('Creating account '.$a->getUsername());
$client = $a->getClient(); $client = $a->getClient();
$package = $a->getPackage()->getName(); $package = $a->getPackage()->getName();
$action = "hosting-plans/name/";
$actionEx = preg_replace("/\s+/", "%20", $package);
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$packageID = $result->id;
$data = array( $data = array(
"username"=> $a->getUsername(), "username"=> $a->getUsername(),
"language"=> "de", "language"=> "de",
"email"=> $client->getEmail(), "email"=> $client->getEmail(),
"password"=> $a->getPassword(), "password"=> $a->getPassword(),
"id_hosting_plan"=> $package, "id_hosting_plan"=> $packageID,
"is_suspended"=> false, "is_suspended"=> false,
"suspend_on"=> null, "suspend_on"=> null,
"delete_on"=> null, "delete_on"=> null,
"send_login_credentials"=> true, "send_login_credentials"=> true,
"create_system_domain"=> false, "create_system_domain"=> false,
); );
$action = "clients/";
$actionapiUrl = $apiUrl . $action;
$curl_session_b = curl_init(); $curl_session_b = curl_init();
curl_setopt($curl_session_b ,CURLOPT_URL,$actionapiUrl); curl_setopt($curl_session_b ,CURLOPT_URL,$actionapiUrl);
curl_setopt($curl_session_b, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_session_b, CURLOPT_RETURNTRANSFER, true);
@ -249,23 +210,12 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function suspendAccount(Server_Account $a) public function suspendAccount(Server_Account $a)
{ {
$host = $this->_config['host']; $apiUrl = "https://".$this->_config['host']."/api/v2/";
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash']; $apiKey = $this->_config['accesshash'];
$action = "clients/name/";
$curl_session = curl_init(); $actionEx = $a->getUsername();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl); $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id; $userID = $result->id;
$data = array( $data = array(
@ -295,23 +245,12 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function unsuspendAccount(Server_Account $a) public function unsuspendAccount(Server_Account $a)
{ {
$host = $this->_config['host']; $apiUrl = "https://".$this->_config['host']."/api/v2/";
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash']; $apiKey = $this->_config['accesshash'];
$action = "clients/name/";
$curl_session = curl_init(); $actionEx = $a->getUsername();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl); $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id; $userID = $result->id;
$data = array( $data = array(
@ -341,23 +280,13 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function cancelAccount(Server_Account $a) public function cancelAccount(Server_Account $a)
{ {
$host = $this->_config['host']; $apiUrl = "https://".$this->_config['host']."/api/v2/";
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash']; $apiKey = $this->_config['accesshash'];
$curl_session = curl_init(); $action = "clients/name/";
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl); $actionEx = $a->getUsername();
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true); $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id; $userID = $result->id;
$action = "clients/".$userID; $action = "clients/".$userID;
@ -384,27 +313,17 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function changeAccountPackage(Server_Account $a, Server_Package $p) public function changeAccountPackage(Server_Account $a, Server_Package $p)
{ {
$this->getLog()->info('Changing password on account '.$a->getUsername()); $this->getLog()->info('Changing password on account '.$a->getUsername());
$host = $this->_config['host']; $apiUrl = "https://".$this->_config['host']."/api/v2/";
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash']; $apiKey = $this->_config['accesshash'];
$action = "clients/name/";
$curl_session = curl_init(); $actionEx = $a->getUsername();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl); $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id; $userID = $result->id;
$package = preg_replace("/\s+/", "%20", $p->getName());
$data = array( $data = array(
"id_hosting_plan"=> $p->getName(), "id_hosting_plan"=> $package,
); );
$action = "clients/".$userID; $action = "clients/".$userID;
$actionapiUrl = $apiUrl . $action; $actionapiUrl = $apiUrl . $action;
@ -431,23 +350,12 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function changeAccountPassword(Server_Account $a, $new) public function changeAccountPassword(Server_Account $a, $new)
{ {
$this->getLog()->info('Changing password on account '.$a->getUsername()); $this->getLog()->info('Changing password on account '.$a->getUsername());
$host = $this->_config['host']; $apiUrl = "https://".$this->_config['host']."/api/v2/";
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash']; $apiKey = $this->_config['accesshash'];
$action = "clients/name/";
$curl_session = curl_init(); $actionEx = $a->getUsername();
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl); $result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
'X-API-Key: '.$apiKey,
'accept: application/json',
'Content-Type: application/json',
));
$result = json_decode(curl_exec($curl_session));
curl_close($curl_session );
$userID = $result->id; $userID = $result->id;
$data = array( $data = array(
@ -474,10 +382,10 @@ class Server_Manager_KeyHelp extends Server_Manager {
throw new Server_Exception('Failed to change the account password!'); throw new Server_Exception('Failed to change the account password!');
} }
} }
/*#######################################
### KEIN SUPPORT FÜR DIESE FUNKTIONEN ###
#######################################*/
/*
Maybe upcoming - maybe not....
*/
public function changeAccountUsername(Server_Account $a, $new) public function changeAccountUsername(Server_Account $a, $new)
{ {
throw new Server_Exception('KeyHelp does not support username changes'); throw new Server_Exception('KeyHelp does not support username changes');