HTML; // Option for the product $configarray = array( "package_name" => array( "FriendlyName" => "Package Name", "Type" => "text", "Size" => "25", "Description" => "The name of the package in Sentora" ), "reseller" => array( "FriendlyName" => "Reseller", "Type" => "yesno", "Description" => "Yes, is a reseller (can be ignored if you've set the product type to reseller).
This will give the people who buy this package reseller access to sentora.
Leave this unticked if you're unsure.", "Default" => "off" ), "autocreate_dns" => array( "FriendlyName" => "Auto-Create DNS Records", "Type" => "yesno", "Description" => "Yes, automatically create default domain records.
(This is required if you want your clients to be able to use your nameservers without them manually creating the default records)", "Default" => "on" ), "custom_username" => array( "FriendlyName" => "Custom Username Generation", "Type" => "text", "Description" => "Leave empty to disable, click HERE for more info." . $custom_username_help ), "disable_domain" => array( "FriendlyName" => "Disable domain", "Type" => "yesno", "Default" => "off", "Description" => "When suspending, disable the domain rather than the account (will allow the Sentora default 'Domain Disabled' page to show)" ) ); return $configarray; } function getProtocol($params) { return ($params["serversecure"] ? "https://" : "http://"); } function getServerHostname($params){ return empty($params['serverhostname']) ? $params['serverip'] : $params['serverhostname']; } function getAddress($params){ return getProtocol($params) . getServerHostname($params); } function getUserID($params){ $response = sendSenitorRequest($params, "whmcs", "GetUserId", array("username" => $params["username"])); if(!empty($response)){ $resp_arr = $response->asArray(); return $resp_arr["uid"]; } else{ return 0; } } function getDomainID($params, $userid, $domain){ $response = sendSenitorRequest($params, "whmcs", "GetDomainId", array("uid" => $userid, "domain" => $domain)); if(!empty($response)){ $resp_arr = $response->asArray(); return $resp_arr["domainid"]; } else{ return 0; } } function sendSenitorRequest($params, $module, $endpoint, $array_data = array(), $debug = true){ global $xmws; global $default_modules; $serveraccesshash = explode(",", $params["serveraccesshash"]); $server_apikey = $serveraccesshash[1]; # Get the API Key if($debug){ $replacevars = array(); # The array should ONLY be empty when debugging very thoroughly. } else{ $replacevars = array($server_apikey, $params["serveraccesshash"], $params["serverusername"], $params["serverpassword"], $params["password"], $params["clientsdetails"]["phonenumber"]); } $serverHostname = getServerHostname($params); if(empty($params["server"]) || empty($serverHostname)){ $logOutput = $params["server"] ? ( "The server has no IP or hostname configured." . "\nServer ID:" . $params["serverid"] . "\nServer Secure: " . $params["serversecure"] . "\nServer Hostname: " . $params["serverhostname"] . "\nServer IP: " . $paramas["serverip"] . "\nProtocol: " . getProtocol($params) . "\nAddress: " . getAddress($params) ) : "There's no server associated with this order." . ( "\nServer ID:" . $params["serverid"] . "\nServer Secure: " . $params["serversecure"] . "\nServer Hostname: " . $params["serverhostname"] . "\nServer IP: " . $paramas["serverip"] . "\nProtocol: " . getProtocol($params) . "\nAddress: " . getAddress($params) ); logModuleCall("Sentora", $module . "." . $endpoint, $array_data, $logOutput, "", $replacevars); return null; } if($xmws == null){ $xmws = SenitorFactory::create(getAddress($params), $server_apikey, $params["serverusername"], $params["serverpassword"], array('verify' => false)); } try{ // Workaround for an exception caused by having multiple Senitor requests per PHP page. MessageBag::getInstance()->reset(); } catch(Exception $e){ $str_error = "Caught exception: " . $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n"; logModuleCall("Sentora", $module . "." . $endpoint, $array_data, $str_error, "", $replacevars); return null; } $use_default_modules = $params["configoption3"] === "on" || $params["configoption3"] === "yes"; if($use_default_modules && !empty($default_modules[$module . "." . $endpoint])){ $module = $default_modules[$module . "." . $endpoint]; } if($debug){ # Even more debugging, enables verbose output of the Senitor library $xmws->debugMode(); ob_start(); } $resp = null; try{ $xmws->setModule($module); $xmws->setEndpoint($endpoint); $xmws->SetRequestData($array_data); $resp = $xmws->send(); } catch(Exception $e){ $str_error = "Caught exception: " . $e->getMessage() . "\n\n" . $e->getTraceAsString(); if($debug){ $str_error .= PHP_EOL . "Debug string from Senitor: " . ob_get_clean(); } #$str_error .= PHP_EOL . " " . print_r(expression); # No clue what I was planning to do here... logModuleCall("Sentora", $module . "." . $endpoint, var_export($array_data, true), $str_error, "", $replacevars); return null; } logModuleCall("Sentora", $module . "." . $endpoint, var_export($array_data, true), var_export($resp->asArray(), true) . ($debug ? "\nDebug from senitor: " . ob_get_clean() : ""), "", $replacevars); return $resp; } function sendVersionToSentora($params) { $array_data = array("whmcs_version" => getModuleVersion()); $response = sendSenitorRequest($params, "whmcs", "CheckVersion", $array_data); if($response != null){ return $response->asString() == "true"; } else{ return false; } //logModuleCall("Sentora", $response->asString(), "", $response->asString(), $response->asString(), ""); } function sentora_CreateAccount($params) { if(empty($params["server"])){ return "There's no server assigned to the order..."; } $serverHostname = getServerHostname($params); if(empty($serverHostname)){ return "There's no hostname or IP assigned to the server (ID: " . $params["serverid"] . ")"; } // Create account, used by the automation system and manual button // Account details $producttype = $params["producttype"]; # Product Type: hostingaccount, reselleraccount, server or other $domain = $params["domain"]; # Domain defined in the product $username = empty($params["username"]) ? substr(str_replace(".", "", $domain), 0, 49) : $params["username"]; # Username defined in the product, default to domainname if no username is defined. $password = $params["password"]; # Password defined in the product $clientsdetails = $params["clientsdetails"]; # Array of clients details - firstname, lastname, email, country, etc... // Product option $groupid = "3"; # Default to Client no need to have an else statement for this. if ($params["configoption2"] === "on" || stripos($producttype, "reseller") !== false){ $groupid = "2"; } if(empty($username)){ return "No username is defined for '" . $clientsdetails['firstname'] . " " . $clientsdetails['lastname'] . "'."; } $uniqueEmailResponse = sendSenitorRequest($params, "whmcs", "CheckUserEmailIsUnique", array( "email" => $clientsdetails["email"] )); if($uniqueEmailResponse == null){ return "Account couldn't be created, couldn't verify that email '" . $clientsdetails["email"] . "' is unique"; } $uniqueEmailRespStr = $uniqueEmailResponse->asString(); if($uniqueEmailRespStr != "true"){ return "Account couldn't be created, a user with the email '" . $clientsdetails["email"] . "' already exists! (NOTE: This includes deleted users, please use the 'Deleted Records Manager' module to remove such users)"; } // Server details $serveraccesshash = explode(",", $params["serveraccesshash"]); $server_reseller = $serveraccesshash[0]; # Get the Reseller ID $packageResponse = sendSenitorRequest($params, "whmcs", "GetPackageId", array( "packagename" => $params["configoption1"] )); if($packageResponse == null){ return "Account couldn't be created, invalid package " . $params["configoption1"]; } $pkgRespArray = $packageResponse->asArray(); $packageid = $pkgRespArray["packageid"]; if(empty($packageid)){ return "Account couldn't be created, invalid package " . $params["configoption1"]; } //CreateClient Checks if that username exists and creates it, otherwise returns a failure $data = array( "resellerid" => $server_reseller, "username" => $username, "packageid" => $packageid, "groupid" => $groupid, "fullname" => $clientsdetails['firstname'] . " " . $clientsdetails['lastname'], "email" => $clientsdetails["email"], "address" => $clientsdetails["address1"], "postcode" => $clientsdetails["postcode"], "phone" => $clientsdetails["phonenumber"], "password" => $password, "sendemail" => false, "emailsubject" => "", "emailbody" => "" ); $response = null; #$response = sendSenitorRequest($params, "whmcs", "CreateClient", $data); $response = sendSenitorRequest($params, "whmcs", "CreateClient", $data); // If it returns anything except 'success' then the user already exists if ($response == null) { return "Account couldn't be created, the API Request failed."; } $stringResponse = $response->asString(); if (!empty($stringResponse) && ($stringResponse != 'success' && $stringResponse != 'true')) { if ($stringResponse == "false" || empty($stringResponse) || empty($response->asArray())) { $usernameExists = sendSenitorRequest($params, "manage_clients", "UsernameExists", array("username" => $username)); if (!empty($usernameExists) && $usernameExists->asString() == "true") { return "Account couldn't be created, an account with that username already exists."; } else{ return "Account couldn't be created. Could be one of the following issues: Invalid username, invalid package, invalid email, invalid password."; } } else{ return $response->asString(); } } $response = null; // Now add the domain (if setup in WHMCS) if(!empty($domain)) { $uid = getUserID($params); if(empty($uid)) { return "Account Created? Error getting user id for domain setup."; } $domainResponse = sendSenitorRequest($params, "domains", "CreateDomain", array( "uid" => $uid, "domain" => $domain, "destination" => " ", "autohome" => 1 ) ); $content = $domainResponse->asArray(); if ($content['created'] == "false") { return "Account created, but couldn't add the domain (FQDN Must not already exist on the Sentora server)."; } if($params["configoption3"] === "on"){ $domainid = getDomainID($params, $uid, $params["domain"]); if(empty($domainid)){ return "Account and domain created? Error getting domain id for DNS setup."; } $dnsRecordsResponse = sendSenitorRequest($params, "whmcs", "CreateDefaultRecords", array( "uid" => $uid, "domainid" => $domainid ) ); } } return "success"; } function sentora_TerminateAccount($params) { //Get the UID $uid = getUserID($params); if (empty($uid)) { return "Error getting the UID"; } // Server details $serveraccesshash = explode(",", $params["serveraccesshash"]); $server_reseller = $serveraccesshash[0]; # Get the Reseller ID // Starting to Terminate the user to Sentora /* Moved DeleteClient to our own until error with the manage_clients DeleteClient is added to Sentora */ //$response = sendSenitorRequest($params, "manage_clients", "DeleteClient", array("uid" => $uid, "moveid" => $server_reseller)); $response = sendSenitorRequest($params, "whmcs", "DeleteClient", array("uid" => $uid, "moveid" => $server_reseller)); if(empty($response)){ $result = "Failed to delete the client."; } else{ $content = $response->asArray(); // If deleted return true, is done! if ($content['deleted'] == "true") { $result = "success"; } else { $result = "Failed to delete the client."; } } return $result; } function sentora_SuspendAccount($params) { $content = array(); //Get the UID $uid = getUserID($params); if (empty($uid)) { return "Error getting the UID"; } $type = "account"; if($params["configoption5"] === "on"){ $domainid = getDomainID($params, $uid, $params["domain"]); $type = "domain"; if(empty($domainid)){ return "Error getting the Domain ID"; } $response = sendSenitorRequest($params, "whmcs", "UpdateDomainStatus", array("uid" => $uid, "domainid" => $domainid, "enable" => 0)); $content = $response->asArray(); } else{ #UpdateDomainStatus // Starting to Suspend the user to Sentora $response = sendSenitorRequest($params, "manage_clients", "DisableClient", array("uid" => $uid)); $content = $response->asArray(); } // If disabled return true, is done! if ($content['disabled'] == "true") { $result = "success"; } else { $result = "User " . $type . " is not suspended."; } return $result; } function sentora_UnsuspendAccount($params) { $content = array(); //Get the UID $uid = getUserID($params); if (empty($uid)) { return "Error getting the UID"; } $type = "account"; if($params["configoption5"] === "on"){ $domainid = getDomainID($params, $uid, $params["domain"]); $type = "domain"; if(empty($domainid)){ return "Error getting the Domain ID"; } $response = sendSenitorRequest($params, "whmcs", "UpdateDomainStatus", array("uid" => $uid, "domainid" => $domainid, "enable" => 1)); $content = $response->asArray(); } else{ #UpdateDomainStatus // Starting to Suspend the user to Sentora $response = sendSenitorRequest($params, "manage_clients", "EnableClient", array("uid" => $uid)); $content = $response->asArray(); } // If enabled return true, is done! if ($content['enabled'] == "true" || $content['disabled'] == "false") { $result = "success"; } else { $result = "User " . $type . " is not unsuspended."; } return $result; } function sentora_ChangePassword($params) { // sendVersionToSentora($params); $uid = getUserID($params); if (empty($uid)) { return "Error getting the UID"; } // Reset the password $response = sendSenitorRequest($params, "password_assistant", "ResetUserPassword", array( "uid" => $uid, "newpassword" => $params["password"] )); $content = $response->asArray(); // If reset returns true, is a success if ($content['reset'] == "true") { $result = "success"; } else { $result = "Can't change the password for the user."; } return $result; } function sentora_ChangePackage($params) { // sendVersionToSentora($params); // Create account, used by the automation system and manual button // Account details $producttype = $params["producttype"]; # Product Type: hostingaccount, reselleraccount, server or other $domain = $params["domain"]; # Domain defined in the product $username = $params["username"]; # Username defined in the product $password = $params["password"]; # Password defined in the product $clientsdetails = $params["clientsdetails"]; # Array of clients details - firstname, lastname, email, country, etc... // Product option $groupid = "3"; # Default to Client no need to have an else statement for this. if ($params["configoption2"] === "on" || stripos($producttype, "reseller") !== false){ $groupid = "2"; } //Get the UID $uid = getUserID($params); if (empty($uid)) { return "Error getting the UID"; } // Starting to update account on Sentora $data = array( "packageid" => $params["configoption1"], "groupid" => $groupid, "uid" => $uid, "fullname" => empty(trim($clientsdetails['firstname'] . " " . $clientsdetails['lastname'])) ? "" : $clientsdetails['firstname'] . " " . $clientsdetails['lastname'], "email" => $clientsdetails['email'], "address" => $clientsdetails['address1'], "postcode" => $clientsdetails['postcode'], "password" => empty($password) ? "" : $password, "phone" => $clientsdetails['phonenumber'] ); $response = sendSenitorRequest($params, "whmcs", "UpdateClient", $data); $content = $response->asString(); return $content; } function sentora_ClientArea($params) { sendVersionToSentora($params); $code = '
'; return $code; } function sentora_AdminLink($params) { $code = '
'; return $code; } function sentora_LoginLink($params) { echo 'Login to Control Panel'; } function sentora_reboot($params) { // Is not a VPS or dedicated control panel return "Not available with Sentora"; } function sentora_shutdown($params) { // Is not a VPS or dedicated control panel return "Not available with Sentora"; } function sentora_ClientAreaCustomButtonArray() { return "Not available with Sentora"; } function sentora_AdminCustomButtonArray() { return "Not available with Sentora"; } function sentora_extrapage($params) { return "Not available with Sentora"; } function sentora_UsageUpdate($params) { sendVersionToSentora($params); // Server details $response = sendSenitorRequest($params, "manage_clients", "GetAllClients", array()); // $xmws->XMLDataToArray($xmws->Request($xmws->BuildRequest()), 0); if(!empty($response)){ $xmws_values = $response->asArray(); $xmws_clients = $xmws_values['client']; /* * NOTICE In the whmcs api doc disklimit is shown as dislimit in mysql it is really disklimit * also diskused is really diskusage * also bwused is really bwusage * * not sure if these are changes from another whmcs version * but i'm using the latest whmcs and thats what they are now * * All values should be in MB */ foreach ($xmws_clients as $xmws_client) { update_query("tblhosting", array( "diskusage" => (int)convertToMBytes($xmws_client['diskspacereadable']), "disklimit" => (int)convertToMBytes($xmws_client['diskspacequotareadable']), "bwusage" => (int)convertToMBytes($xmws_client['bandwidthreadable']), "bwlimit" => (int)convertToMBytes($xmws_client['bandwidthquotareadable']), "lastupdate" => "now()", ), array("server" => $serverid, "username" => $xmws_client['username'])); } } } function convertToMBytes($from) { $number = substr($from, 0, -2); switch (strtoupper(substr($from, -2))) { case "KB": return (float)($number / 1024); case "MB": return $number; case "GB": return $number * 1024; case "TB": return $number * pow(1024, 2); case "PB": return $number * pow(1024, 3); default: return $from; } } function sentora_AdminServicesTabFields($params) { return "Not available with Sentora"; } function sentora_AdminServicesTabFieldsSave($params) { return "Not available with Sentora"; }