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
*/
class Server_Manager_KeyHelp extends Server_Manager {
/**
* Method is called just after obejct contruct is complete.
* Add required parameters checks here.
*/
public function init()
{
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()
{
/*
###############################
### 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'];
return 'https://'.$host.'';
}
@ -115,27 +95,14 @@ class Server_Manager_KeyHelp extends Server_Manager {
return 'https://'.$host.'';
}
/**
* Here we check if the API is working ;)
*/
public function testConnection()
{
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "ping";
$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 );
$actionEx = "";
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
if(isset($result)) {
return true;
@ -145,31 +112,21 @@ class Server_Manager_KeyHelp extends Server_Manager {
}
}
/**
* Not working, because of FOSSBilling
*/
public function synchronizeAccount(Server_Account $a)
{
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$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;
$action = "clients/name/";
$actionEx = $a->getUsername();
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$new = clone $a;
$new->setSuspended($result->is_suspended);
$new->setUsername($result->username);
if(empty($result->is_suspended)) {
$new->setSuspended(false);
} else {
$new->setSuspended(true);
}
return $new;
}
@ -180,27 +137,31 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function createAccount(Server_Account $a)
{
$apiUrl = "https://".$this->_config['host']."/api/v2/";
$action = "clients/";
$actionapiUrl = $apiUrl . $action;
$apiKey = $this->_config['accesshash'];
$this->getLog()->info('Creating account '.$a->getUsername());
$client = $a->getClient();
$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(
"username"=> $a->getUsername(),
"language"=> "de",
"email"=> $client->getEmail(),
"password"=> $a->getPassword(),
"id_hosting_plan"=> $package,
"id_hosting_plan"=> $packageID,
"is_suspended"=> false,
"suspend_on"=> null,
"delete_on"=> null,
"send_login_credentials"=> true,
"create_system_domain"=> false,
);
$action = "clients/";
$actionapiUrl = $apiUrl . $action;
$curl_session_b = curl_init();
curl_setopt($curl_session_b ,CURLOPT_URL,$actionapiUrl);
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)
{
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiUrl = "https://".$this->_config['host']."/api/v2/";
$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 );
$action = "clients/name/";
$actionEx = $a->getUsername();
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$userID = $result->id;
$data = array(
@ -295,23 +245,12 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function unsuspendAccount(Server_Account $a)
{
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiUrl = "https://".$this->_config['host']."/api/v2/";
$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 );
$action = "clients/name/";
$actionEx = $a->getUsername();
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$userID = $result->id;
$data = array(
@ -341,23 +280,13 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function cancelAccount(Server_Account $a)
{
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiUrl = "https://".$this->_config['host']."/api/v2/";
$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 );
$action = "clients/name/";
$actionEx = $a->getUsername();
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$userID = $result->id;
$action = "clients/".$userID;
@ -384,27 +313,17 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function changeAccountPackage(Server_Account $a, Server_Package $p)
{
$this->getLog()->info('Changing password on account '.$a->getUsername());
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiUrl = "https://".$this->_config['host']."/api/v2/";
$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 );
$action = "clients/name/";
$actionEx = $a->getUsername();
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$userID = $result->id;
$package = preg_replace("/\s+/", "%20", $p->getName());
$data = array(
"id_hosting_plan"=> $p->getName(),
"id_hosting_plan"=> $package,
);
$action = "clients/".$userID;
$actionapiUrl = $apiUrl . $action;
@ -431,23 +350,12 @@ class Server_Manager_KeyHelp extends Server_Manager {
public function changeAccountPassword(Server_Account $a, $new)
{
$this->getLog()->info('Changing password on account '.$a->getUsername());
$host = $this->_config['host'];
$apiUrl = "https://".$host."/api/v2/";
$action = "clients/name/".$a->getUsername();
$actionapiUrl = $apiUrl . $action;
$apiUrl = "https://".$this->_config['host']."/api/v2/";
$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 );
$action = "clients/name/";
$actionEx = $a->getUsername();
$result = Server_Manager_KeyHelp::getCURL($action, $actionEx);
$userID = $result->id;
$data = array(
@ -474,10 +382,10 @@ class Server_Manager_KeyHelp extends Server_Manager {
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)
{
throw new Server_Exception('KeyHelp does not support username changes');