Add files via upload
This commit is contained in:
parent
b6b04452ad
commit
491424e214
1 changed files with 493 additions and 0 deletions
493
KeyHelp.php
Normal file
493
KeyHelp.php
Normal file
|
@ -0,0 +1,493 @@
|
|||
<?php
|
||||
/**
|
||||
* FOSSBilling
|
||||
*
|
||||
* @copyright FOSSBilling (https://www.fossbilling.org)
|
||||
* @license Apache-2.0
|
||||
*
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
/**
|
||||
* KeyHelp API
|
||||
* Version: 2.4
|
||||
* @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')) {
|
||||
throw new Server_Exception('cURL extension is not enabled');
|
||||
}
|
||||
|
||||
if(empty($this->_config['ip'])) {
|
||||
throw new Server_Exception('Server manager "KeyHelp" is not configured properly. IP address is not set!');
|
||||
}
|
||||
|
||||
if(empty($this->_config['host'])) {
|
||||
throw new Server_Exception('Server manager "KeyHelp" is not configured properly. Hostname is not set!');
|
||||
}
|
||||
|
||||
if(empty($this->_config['accesshash'])) {
|
||||
throw new Server_Exception('Server manager "KeyHelp" is not configured properly. API Key / Access Hash is not set!');
|
||||
} else {
|
||||
$this->_config['accesshash'] = preg_replace("'(\r|\n)'","",$this->_config['accesshash']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getForm()
|
||||
{
|
||||
return [
|
||||
'label' => 'KeyHelp',
|
||||
'form' => [
|
||||
'credentials' => [
|
||||
'fields' => [
|
||||
[
|
||||
'name' => 'accesshash',
|
||||
'type' => 'text',
|
||||
'label' => 'API key',
|
||||
'placeholder' => 'API key you generated from within KeyHelp.',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
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.'';
|
||||
}
|
||||
public function getResellerLoginUrl()
|
||||
{
|
||||
$host = $this->_config['host'];
|
||||
return 'https://'.$host.'';
|
||||
}
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
if(isset($result)) {
|
||||
return true;
|
||||
var_dump($a);
|
||||
} else {
|
||||
throw new Server_Exception('Failed to connect to server');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
$new = clone $a;
|
||||
$new->setSuspended($result->is_suspended);
|
||||
$new->setUsername($result->username);
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Package name must match on both KeyHelp and FOSSBilling!
|
||||
*/
|
||||
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();
|
||||
|
||||
$data = array(
|
||||
"username"=> $a->getUsername(),
|
||||
"language"=> "de",
|
||||
"email"=> $client->getEmail(),
|
||||
"password"=> $a->getPassword(),
|
||||
"id_hosting_plan"=> $package,
|
||||
"is_suspended"=> false,
|
||||
"suspend_on"=> null,
|
||||
"delete_on"=> null,
|
||||
"send_login_credentials"=> true,
|
||||
"create_system_domain"=> false,
|
||||
);
|
||||
|
||||
$curl_session_b = curl_init();
|
||||
curl_setopt($curl_session_b ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session_b, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session_b, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($curl_session_b, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl_session_b, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl_session_b, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
curl_setopt($curl_session_b, CURLOPT_POST, 1);
|
||||
curl_setopt($curl_session_b, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$result_a = json_decode(curl_exec($curl_session_b));
|
||||
curl_close($curl_session_b );
|
||||
$keyhelp_user_id = $result_a->id;
|
||||
|
||||
$data = array(
|
||||
"id_user"=> $keyhelp_user_id,
|
||||
"domain"=> $a->getDomain()
|
||||
);
|
||||
$action = "domains";
|
||||
$actionapiUrl = $apiUrl . $action;
|
||||
$curl_session = curl_init();
|
||||
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($curl_session, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
curl_setopt($curl_session, CURLOPT_POST, 1);
|
||||
curl_setopt($curl_session, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$result_c = json_decode(curl_exec($curl_session));
|
||||
curl_close($curl_session );
|
||||
|
||||
if(isset($result_a)&&isset($result_c)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Server_Exception('Failed to create the hosting');
|
||||
}
|
||||
}
|
||||
|
||||
public function suspendAccount(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;
|
||||
|
||||
$data = array(
|
||||
"is_suspended"=> true,
|
||||
);
|
||||
$action = "clients/".$userID;
|
||||
$actionapiUrl = $apiUrl . $action;
|
||||
$curl_session = curl_init();
|
||||
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
curl_setopt($curl_session, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$result_c = json_decode(curl_exec($curl_session));
|
||||
curl_close($curl_session );
|
||||
|
||||
if(isset($result_c)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Server_Exception('Failed to suspend account!');
|
||||
}
|
||||
}
|
||||
|
||||
public function unsuspendAccount(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;
|
||||
|
||||
$data = array(
|
||||
"is_suspended"=> false,
|
||||
);
|
||||
$action = "clients/".$userID;
|
||||
$actionapiUrl = $apiUrl . $action;
|
||||
$curl_session = curl_init();
|
||||
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
curl_setopt($curl_session, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$result_c = json_decode(curl_exec($curl_session));
|
||||
curl_close($curl_session );
|
||||
|
||||
if(isset($result_c)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Server_Exception('Failed to suspend account!');
|
||||
}
|
||||
}
|
||||
|
||||
public function cancelAccount(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/".$userID;
|
||||
$actionapiUrl = $apiUrl . $action;
|
||||
$curl_session = curl_init();
|
||||
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
$result_c = json_decode(curl_exec($curl_session));
|
||||
curl_close($curl_session );
|
||||
|
||||
if(empty($result_c)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Server_Exception('Failed to cancel / delete account!');
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
$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;
|
||||
|
||||
$data = array(
|
||||
"id_hosting_plan"=> $p->getName(),
|
||||
);
|
||||
$action = "clients/".$userID;
|
||||
$actionapiUrl = $apiUrl . $action;
|
||||
$curl_session = curl_init();
|
||||
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
curl_setopt($curl_session, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$result_c = json_decode(curl_exec($curl_session));
|
||||
curl_close($curl_session );
|
||||
|
||||
if(isset($result_c)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Server_Exception('Failed to change the account password!');
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
$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;
|
||||
|
||||
$data = array(
|
||||
"password"=> $a->getPassword(),
|
||||
);
|
||||
$action = "clients/".$userID;
|
||||
$actionapiUrl = $apiUrl . $action;
|
||||
$curl_session = curl_init();
|
||||
curl_setopt($curl_session ,CURLOPT_URL,$actionapiUrl);
|
||||
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
|
||||
'X-API-Key: '.$apiKey,
|
||||
'accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
));
|
||||
curl_setopt($curl_session, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$result_c = json_decode(curl_exec($curl_session));
|
||||
curl_close($curl_session );
|
||||
|
||||
if(isset($result_c)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Server_Exception('Failed to change the account password!');
|
||||
}
|
||||
}
|
||||
/*#######################################
|
||||
### KEIN SUPPORT FÜR DIESE FUNKTIONEN ###
|
||||
#######################################*/
|
||||
|
||||
public function changeAccountUsername(Server_Account $a, $new)
|
||||
{
|
||||
throw new Server_Exception('KeyHelp does not support username changes');
|
||||
}
|
||||
public function changeAccountDomain(Server_Account $a, $new)
|
||||
{
|
||||
throw new Server_Exception('KeyHelp does not support changing the primary domain name');
|
||||
}
|
||||
public function changeAccountIp(Server_Account $a, $new)
|
||||
{
|
||||
throw new Server_Exception('KeyHelp does not support changing the IP');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue