| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155 |
- <?php
- /**
- * WHMCS siteBuilder Provisioning Module
- *
- * Provisioning for User Account on the siteBuilder Server
- *
- * @see https://centos-webpanel.com/
- * @copyright Copyright (c) Thurdata GmbH 2022
- * @license GPL
- */
- use WHMCS\Database\Capsule;
- require_once 'Net/DNS2.php';
- require_once(__DIR__ . '/api/sitebuilder.php');
- if (!defined('WHMCS')) {
- die('This file cannot be accessed directly');
- }
- /**
- * Define siteBuilder product metadata parameters.
- *
- * @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
- *
- * @return array
- */
- function siteBuilder_MetaData() {
- return array(
- 'DisplayName' => 'ThurData SiteBuilder Provisioning',
- 'APIVersion' => '1.2',
- 'DefaultNonSSLPort' => '80',
- 'DefaultSSLPort' => '443',
- 'RequiresServer' => true,
- 'ServiceSingleSignOnLabel' => 'Login to siteBuilder',
- 'AdminSingleSignOnLabel' => 'Login to siteBuilder Admin'
- );
- }
- /**
- * Test connection to a siteBuilder server with the given server parameters.
- *
- * Allows an admin user to verify that an API connection can be
- * successfully made with the given configuration parameters for a
- * server.
- *
- * When defined in a module, a test connection button will appear
- * alongside the server type dropdown when adding or editing an
- * existing server.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return array
- */
- function siteBuilder_Testconnection($params) {
- $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
- $response = $siteBuilder->ping($params['serverusername'], $params['serverpassword']);
- if($response['response']['answer'] == 'pong') {
- return array(
- 'success' => true,
- 'error' => '',
- );
- }
- return array(
- 'success' => false,
- 'error' => $response,
- );
- }
- /**
- * Provision a new account of a siteBuilder server.
- *
- * Attempt to provision a new siteBuilder account. This is
- * called any time provisioning is requested inside of WHMCS. Depending upon the
- * configuration, this can be any of:
- * * When a new order is placed
- * * When an invoice for a new order is paid
- * * Upon manual request by an admin user
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string 'success' or an error message
- */
- function siteBuilder_CreateAccount($params) {
- $username = strtolower(substr($params['clientsdetails']['firstname'],0,2) . substr($params['clientsdetails']['lastname'],0,3)) . $params['serviceid'];
- $userdomain = $params['domain'];
- try {
- Capsule::table('tblhosting')
- ->where('id', '=', $params['serviceid'])
- ->update(
- array(
- 'username' => $username,
- 'domain' => $userdomain,
- )
- );
- } catch (\Exception $e) {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $params,
- 'Error: could save username & domain in database',
- $e->getMessage()
- );
- return 'Error: could save username & password in database';
- }
- if ($params["server"] == 1) {
- $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
- $response = $siteBuilder->deployDev($username, $domain, $params['serverusername'], $params['serverpassword']);
- }
- if($response['status'] != '200') {
- return 'Error: ' . $response['response'];
- }
- return 'success';
- }
- /**
- * Removes a siteBuilder account.
- *
- * Called when a termination is requested. This can be invoked automatically for
- * overdue products if enabled, or requested manually by an admin user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string 'success' or an error message
- */
- function siteBuilder_TerminateAccount($params) {
- $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
- $response = $siteBuilder->terminateAccount($params['username'], $params['serverusername'], $params['serverpassword']);
- if($response['status'] != '200') {
- return 'Error: ' . $response['response'];
- }
- return 'success';
- }
- /**
- * Set a siteBuilder account to status inactive.
- *
- * Called when a suspension is requested. This is invoked automatically by WHMCS
- * when a product becomes overdue on payment or can be called manually by admin
- * user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string 'success' or an error message
- */
- function siteBuilder_SuspendAccount($params) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->suspendAccount($params['username']);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Set a siteBuilder account to status active.
- *
- * Called when an un-suspension is requested. This is invoked
- * automatically upon payment of an overdue invoice for a product, or
- * can be called manually by admin user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string 'success' or an error message
- */
- function siteBuilder_UnsuspendAccount($params) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->unsuspendAccount($params['username']);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Client area output logic handling.
- *
- * This function is used to define module specific client area output. It should
- * return an array consisting of a template file and optional additional
- * template variables to make available to that template.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/client-area-output/
- *
- * @return array
- */
- function siteBuilder_ClientArea($params) {
- $clientInfo = array('moduleclientarea' => '1');
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->getAutoSSL($params['username']);
- if($response['status'] == 'OK') {
- $sslSites = array();
- foreach($response['msj'] as $sslSite) {
- $sslSites[$sslSite['ssl']] = array(
- 'auotssl' => $sslSite['autossl'],
- 'expire' => $sslSite['exp'],
- );
- }
- }
- $response = $siteBuilder->getAccount($params['username']);
- if($response['status'] != 'OK') {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $params,
- 'debug',
- $response
- );
- }
- if(siteBuilderCheckLimit($params,'domains')){
- $clientInfo['domainlimit'] = 1;
- } else {
- $clientInfo['domainlimit'] = 0;
- };
- if(siteBuilderCheckLimit($params,'subdomins')){
- $clientInfo['subdomainlimit'] = 1;
- } else {
- $clientInfo['subdomainlimit'] = 0;
- };
- $clientInfo['db_max'] = $response['result']['account_info']['db_max'];
- $clientInfo['db_used'] = $response['result']['account_info']['db_used'];
- $clientInfo['ftp_accounts'] = $response['result']['account_info']['ftp_accounts'];
- $clientInfo['ftp_accounts_used'] = $response['result']['account_info']['ftp_accounts_used'];
- $clientInfo['addons_domains'] = $response['result']['account_info']['addons_domains'];
- $clientInfo['addons_domains_used'] = $response['result']['account_info']['addons_domains_used'];
- $clientInfo['sub_domains'] = $response['result']['account_info']['sub_domains'];
- $clientInfo['sub_domains_used'] = $response['result']['account_info']['sub_domains_used'];
- $clientInfo['space_usage'] = $response['result']['account_info']['space_usage'];
- $clientInfo['space_disk'] = $response['result']['account_info']['space_disk'];
- $clientInfo['bandwidth_used'] = $response['result']['account_info']['bandwidth_used'];
- $clientInfo['bandwidth'] = $response['result']['account_info']['bandwidth'];
- $domains = $response['result']['domains'];
- $subDomains = $response['result']['subdomins'];
- $clientInfo['domains'] = array();
- foreach($domains as $domain) {
- if($domain['path'] == '/home/' . $params['username'] . '/public_html') {
- $clientInfo['mgmtDomain'] = $domain['domain'];
- $clientInfo['mgmtEmail'] = $domain['email'];
- } else {
- $domain['relpath'] = str_replace('/home/' . $params['username'], '~', $domain['path']);
- if(array_key_exists($domain['domain'], $sslSites)) {
- $domain['ssl'] = 1;
- $domain['sslexpire'] = $sslSites[$domain['domain']]['expire'];
- $domain['autossl'] = $sslSites[$domain['domain']]['auotssl'];
- }
- if(siteBuilderCheckA($domain['domain'],$params['serverip'],$params['configoption5']) == 1) {
- $domain['DNS'] = 1;
- }
- $domain['domainNS'] = siteBuilderCheckSOA($domain['domain'],$params['configoption5']);
- $domain['subdomains'] = array();
- foreach($subDomains as $subDomain) {
- if($subDomain['domain'] == $domain['domain']) {
- $subFQDN = $subDomain['subdomain'] . '.' . $subDomain['domain'];
- $subDomain['relpath'] = str_replace('/home/' . $params['username'], '~', $subDomain['path']);
- if(array_key_exists($subFQDN, $sslSites)) {
- $subDomain['ssl'] = 1;
- $subDomain['sslexpire'] = $sslSites[$subFQDN]['expire'];
- $subDomain['autossl'] = $sslSites[$subFQDN]['auotssl'];
- } else {
- unset($subDomain['ssl']);
- unset($subDomain['sslexpire']);
- unset($subDomain['autossl']);
- }
- if(siteBuilderCheckA($subFQDN,$params['serverip'],$params['configoption5']) == 1) {
- $subDomain['DNS'] = 1;
- } else {
- unset($subDomain['DNS']);
- }
- array_push($domain['subdomains'], $subDomain);
- }
- }
- array_push($clientInfo['domains'], $domain);
- }
- }
- return array(
- 'tabOverviewReplacementTemplate' => 'clientarea',
- 'vars' => $clientInfo,
- );
- }
- /**
- * Perform single sign-on for a siteBuilder account.
- *
- * When successful, returns a URL to which the user should be redirected.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/single-sign-on/
- *
- * @return array
- */
- function siteBuilder_ServiceSingleSignOn($params) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->getLoginLink($params['username']);
- if($response['status'] == 'OK') {
- $link = $response['msj']['details'];
- $linkautologin = $link[0]['url'];
- return array(
- 'success' => true,
- 'redirectTo' => $linkautologin,
- );
- } else {
- return array(
- 'success' => false,
- 'redirectTo' => '',
- );
- }
- }
- /**
- * Change the password for a siteBuilder account.
- *
- * Called when a password change is requested. This can occur either due to a
- * client requesting it via the client area or an admin requesting it from the
- * admin side.
- *
- * This option is only available to client end users when the product is in an
- * active status.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_ChangePassword($params) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->changePass(array('user' => $params['username'], 'password' => $params['password']));
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Upgrade or downgrade a siteBuilder account by package.
- *
- * Called to apply any change in product assignment or parameters. It
- * is called to provision upgrade or downgrade orders, as well as being
- * able to be invoked manually by an admin user.
- *
- * This same function is called for upgrades and downgrades of both
- * products and configurable options.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_ChangePackage($params) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $data = array(
- 'user' => $params['username'],
- 'email' => $params['clientsdetails']['email'],
- 'package' => $params['configoption1'],
- 'inode' => (int) $params["configoption2"],
- 'openfiles' => (int) $params["configoption3"],
- 'processes' => (int) $params["configoption4"],
- 'server_ips'=> $params["serverip"],
- );
- $response = $siteBuilder->modifyAccount($data);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Usage Update
- *
- * Important: Runs daily per server not per product
- * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/usage-update/
- */
- function siteBuilder_UsageUpdate($params) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->getAllAccounts();
- if($response['status'] == 'OK'){
- $results = $response['msj'];
- for($i = 0; $i < count($results); $i++){
- if($results[$i]['diskusage'] == '') {
- $diskusage = 0;
- } else {
- $diskusage = trim($results[$i]['diskusage']);
- }
- if($results[$i]['disklimit'] == '') {
- $disklimit = 0;
- } else {
- $disklimit = trim($results[$i]['disklimit']);
- }
- if($results[$i]['bandwidth'] == '') {
- $bandwidth = 0;
- } else {
- $bandwidth =trim($results[$i]['bandwidth']);
- }
- if($results[$i]['bwlimit'] == '') {
- $bwlimit = 0;
- } else {
- $bwlimit = trim($results[$i]['bwlimit']);
- }
- $domain = trim($results[$i]['domain']);
- try {
- \WHMCS\Database\Capsule::table('tblhosting')
- ->where('server', $params['serverid'])
- ->where('domain', $domain)
- ->update([
- 'diskusage' => $diskusage,
- 'disklimit' => $disklimit,
- 'bwusage' => $bandwidth,
- 'bwlimit' => $bwlimit,
- 'lastupdate' => date('Y-m-d H:i:S'),
- ]);
- } catch (\Exception $e) {
- logActivity('ERROR: Unable to update server usage: ' . $e->getMessage());
- }
- }
- }
- }
- /**
- * Additional actions a client user can invoke.
- *
- * Define additional actions a client user can perform for an instance of a
- * product/service.
- *
- * Any actions you define here will be automatically displayed in the available
- * list of actions within the client area.
- *
- * @return array
- */
- function siteBuilder_ClientAreaCustomButtonArray ($params) {
- if(siteBuilderCheckLimit($params, 'domains')) {
- return array();
- }
- return array(
- 'Neue Domain' => 'newDomain',
- );
- }
- /**
- * Additional actions a client user can invoke.
- *
- * Define additional actions a client user is allowed to perform for an instance of a
- * product/service.
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array
- */
- function siteBuilder_ClientAreaAllowedFunctions() {
- return array(
- "Enable SSL" => "enableSSL",
- "Renew SSL" => "renewSSL",
- "Set DNS" => "setDNS",
- "Unset DNS" => "unsetDNS",
- "Confirm Enable SSL" => "enableSSLConfirm",
- "Confirm Renew SSL" => "renewSSLConfirm",
- "Confirm Set DNS" => "setDNSConfirm",
- "Confirm Unset DNS" => "unsetDNSConfirm",
- "Info DNS" => "infoDNS",
- "Info SSL" => "infoSSL",
- "Add Domain" => "addDomain",
- "new Domain" => "newDomain",
- "Add Subdomain" => "addSubdomain",
- "New Subdomain" => "newSubdomain",
- "Confirm Delete Domain" => "delDomainConfirm",
- "Delete Domain" => "delDomain",
- "Confirm Delete Subdomain" => "delSubdomainConfirm",
- "Delete Subdomain" => "delSubdomain",
- );
- }
- /**
- * Opens a form to add a new domain.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_newDomain($params) {
- return array(
- 'breadcrumb' => array(
- 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newDomain' => 'Neue Domain',
- ),
- 'templatefile' => 'siteBuilder_add_domain',
- );
- }
- /**
- * Adds a new domain to a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_addDomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- if(siteBuilderCheckLimit($params, 'domains')) {
- return 'Error: domain limit exceeded';
- }
- $vars['user'] = $params['username'];
- $vars['name'] = $_POST['d'];
- $vars['type'] = 'domain';
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->addDomain($vars);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Opens a form to add a new subdomain to a domain.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_newSubdomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- return array(
- 'breadcrumb' => array(
- 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newSubdomain' => 'Neue Subdomain',
- ),
- 'templatefile' => 'siteBuilder_add_subdomain',
- 'vars' => array(
- 'domainselected' => $_POST['d'],
- ),
- );
- }
- /**
- * Adds a new subdomain to domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_addSubdomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid subdomain name';
- }
- if($_POST['s'] == 'www') {
- return 'Error: default Subdomain www wurde bereits automatisch erstellt' ;
- }
- if(siteBuilderCheckLimit($params, 'subdomins')) {
- return 'Error: subdomain limit exceeded';
- }
- $vars['user'] = $params['username'];
- $vars['name'] = $_POST['s'] . '.' . $_POST['d'];
- $vars['type'] = 'subdomain';
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->addDomain($vars);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Opens a form to delete a domain from a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_delDomainConfirm($params) {
- return array(
- 'templatefile' => 'siteBuilder_del_domain_confirm',
- 'vars' => array(
- 'deldomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Removes a domain from a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_delDomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->getAccount($params['username']);
- if($response['status'] != 'OK') {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $params,
- 'debug',
- $response
- );
- }
- $domains = $response['result']['domains'];
- $clientdomains = array();
- foreach($domains as $domain){
- if($domain['domain'] != $params['domain']) {
- array_push($clientdomains, $domain['domain']);
- }
- }
- if(!in_array($_POST['d'], $clientdomains)) {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $_POST,
- 'POST DATA VIOLATION',
- $params
- );
- return 'Error: ' . $_POST['d'] . ' not in client domains';
- }
- // do delete domain
- $vars['user'] = $params['username'];
- $vars['name'] = $_POST['d'];
- $vars['type'] = 'domain';
- $response = $siteBuilder->deleteDomain($vars);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Opens a form to delete a subdomain from domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_delSubdomainConfirm($params) {
- return array(
- 'templatefile' => 'siteBuilder_del_subdomain_confirm',
- 'vars' => array(
- 'delsubdomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Removes a subdomain from a domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_delSubdomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->getAccount($params['username']);
- if($response['status'] != 'OK') {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $params,
- 'debug',
- $response
- );
- }
- $subdomains = $response['result']['subdomins'];
- $clientsubdomains = array();
- foreach($subdomains as $subdomain){
- if($subdomain['domain'] != $params['domain']) {
- array_push($clientsubdomains, $subdomain['subdomain'] . "." . $subdomain['domain']);
- }
- }
- if(!in_array($_POST['d'], $clientsubdomains)) {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $_POST,
- 'POST DATA VIOLATION',
- $params
- );
- return 'Error: ' . $_POST['d'] . ' not in client subdomains';
- }
- // do delete subdomain
- $vars['user'] = $params['username'];
- $vars['name'] = $_POST['d'];
- $vars['type'] = 'subdomain';
- $response = $siteBuilder->deleteDomain($vars);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Opens a form to enable SSL for a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_enableSSLConfirm($params) {
- return array(
- 'templatefile' => 'siteBuilder_enable_SSL_confirm',
- 'vars' => array(
- 'SSLdomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Aktivate siteBuilder AutoSSL for a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_enableSSL($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $vars['user'] = $params['username'];
- $vars['name'] = $_POST['d'];
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->addAutoSSL($vars);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Opens a form to renew a SSL certificate for a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_renewSSLConfirm($params) {
- return array(
- 'templatefile' => 'siteBuilder_renew_SSL_confirm',
- 'vars' => array(
- 'SSLdomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Renews a SSL certificate for a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_renewSSL($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $vars['user'] = $params['username'];
- $vars['name'] = $_POST['d'];
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->updateAutoSSL($vars);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- return 'success';
- }
- /**
- * Opens a form to set a DNS record for a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_setDNSConfirm($params) {
- if(isset($_POST['s'])){
- return array(
- 'templatefile' => 'siteBuilder_set_DNS_confirm',
- 'vars' => array(
- 'DNSdomain' => $_POST['d'],
- 'DNSsubdomain' => $_POST['s'],
- ),
- );
- }
- return array(
- 'templatefile' => 'siteBuilder_set_DNS_confirm',
- 'vars' => array(
- 'DNSdomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Opens a form to unsset a DNS record for a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_unsetDNSConfirm($params) {
- if(isset($_POST['s'])){
- return array(
- 'templatefile' => 'siteBuilder_unset_DNS_confirm',
- 'vars' => array(
- 'DNSdomain' => $_POST['d'],
- 'DNSsubdomain' => $_POST['s'],
- ),
- );
- }
- return array(
- 'templatefile' => 'siteBuilder_unset_DNS_confirm',
- 'vars' => array(
- 'DNSdomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Update a DNS zone for a domain setting a new record for a domain or subdomain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_setDNS($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $domainName = $_POST['d'];
- $zoneRecords = array();
- if(isset($_POST['s'])){
- if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid subdomain name';
- }
- $hostName = $_POST['s'] . '.' . $domainName . '.';
- $newRecord = array(
- 'line' => $hostName.'|A|0',
- 'name' => $hostName,
- 'type' => 'A',
- 'class' => 'IN',
- 'data' => array(
- 'address' => $params['serverip'],
- ),
- );
- array_push($zoneRecords, $newRecord);
- } else {
- $hostName = $domainName . '.';
- $domainRecord = array(
- 'line' => $hostName.'|A|0',
- 'name' => $hostName,
- 'type' => 'A',
- 'class' => 'IN',
- 'data' => array(
- 'address' => $params['serverip'],
- ),
- );
- array_push($zoneRecords, $domainRecord);
- $wwwRecord = array(
- 'line' => 'www'.$hostName.'|A|0',
- 'name' => 'www'.$hostName,
- 'type' => 'A',
- 'class' => 'IN',
- 'data' => array(
- 'address' => $params['serverip'],
- ),
- );
- array_push($zoneRecords, $wwwRecord);
- }
- $zoneIDcollection = Capsule::table('dns_manager2_zone')
- ->select('id')
- ->where('name', '=', $domainName)
- ->where('clientid', '=', $params['userid'])
- ->get();
- $zoneIDobj = $zoneIDcollection[0];
- $zoneID = $zoneIDobj->{'id'};
- if(!isset($zoneID)) {
- return 'Error: Zone for domain ' . $domainName . ' or not owned by client';
- }
- $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
- foreach($dnsZone['data']->records as $record) {
- if(($record->name != $hostName) || ($record->type != 'A' && $record->type != 'CNAME')) {
- array_push($zoneRecords, $record);
- };
- }
- $result = localAPI('dnsmanager' ,
- array(
- 'dnsaction' => 'updateZone',
- 'zone_id' => $zoneID,
- 'records' => $zoneRecords,
- )
- );
- if($result['result'] != 'success') {
- return 'Error: ' . $result['message'];
- }
- return 'success';
- }
- /**
- * Removing a DNS record for a domain or subdomain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string "success" or an error message
- */
- function siteBuilder_unsetDNS($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $domainName = $_POST['d'];
- $zoneRecords = array();
- if(isset($_POST['s'])){
- if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid subdomain name';
- }
- $hostName = $_POST['s'] . '.' . $domainName . '.';
- } else {
- $hostName = $domainName . '.';
- }
- $zoneIDcollection = Capsule::table('dns_manager2_zone')
- ->select('id')
- ->where('name', '=', $domainName)
- ->where('clientid', '=', $params['userid'])
- ->get();
- $zoneIDobj = $zoneIDcollection[0];
- $zoneID = $zoneIDobj->{'id'};
- if(!isset($zoneID)) {
- return 'Error: Zone for domain ' . $domainName . ' or not owned by client';
- }
- $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
- foreach($dnsZone['data']->records as $record) {
- if(($record->name != $hostName) || ($record->type != 'A' && $record->type != 'CNAME')) {
- array_push($zoneRecords, $record);
- };
- }
- $result = localAPI('dnsmanager' ,
- array(
- 'dnsaction' => 'updateZone',
- 'zone_id' => $zoneID,
- 'records' => $zoneRecords,
- )
- );
- if($result['result'] != 'success') {
- return 'Error: ' . $result['message'];
- }
- return 'success';
- }
- /**
- * Opens a form to inform about the DNS status of a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_infoDNS($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $siteBuildernameserver = siteBuilderCheckSOA($_POST['d'],$params['configoption5']);
- return array(
- 'templatefile' => 'siteBuilder_help_dns',
- 'vars' => array(
- 'infodomain' => $_POST['d'],
- 'siteBuildernameserver' => $siteBuildernameserver,
- ),
- );
- }
- /**
- * Opens a form to inform about the SSL status of a subdomain or domain of a siteBuilder account.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return array template information
- */
- function siteBuilder_infoSSL($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- return array(
- 'templatefile' => 'siteBuilder_help_ssl',
- 'vars' => array(
- 'infodomain' => $_POST['d'],
- ),
- );
- }
- /**
- * Ask nameservers for a IP adress of a given host.
- *
- * @param string $host hostname
- * @param string $serverIP siteBuilder server IP
- * @param string $nameserverIP polled name server IP
- * @param int $recurse optional -> used to follow CNAME responses
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return bool
- */
- function siteBuilderCheckA($host, $serverIP, $nameserverIP, $recurse = 0) {
- if($recurse > 3) {
- return false;
- }
- $nameserver = array($nameserverIP);
- # try NS1
- $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
- try {
- $result = $resolver->query($host, 'A');
- } catch(Net_DNS2_Exception $e) {
- # try default nameserver
- $resolver = new Net_DNS2_Resolver();
- try {
- $result = $resolver->query($host, 'A');
- } catch(Net_DNS2_Exception $e) {
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $e,
- 'DNS lookup exception',
- $e->getMessage()
- );
- return false;
- }
- }
- $hostA = $result->answer;
- if($hostA[0]->type == 'CNAME') {
- if(siteBuilderCheckA($hostA[0]->cname, $serverIP, $nameserverIP, $recurse++)) {
- return true;
- }
- }
- if($hostA[0]->type == 'A') {
- if($hostA[0]->address == $serverIP){
- return true;
- }
- }
- return false;
- }
- /**
- * Ask nameservers for the authority of a domain.
- *
- * @param string $domain domain name
- * @param string $nameserverIP polled name server IP
- * @param string $nameserverName name of the own namesever
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return string 'none' -> not registered, 'self' -> registered at own or the name of an other responsible nameserver
- */
- function siteBuilderCheckSOA($domain, $nameserverIP) {
- $nameserver = array($nameserverIP);
- # try NS1
- $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
- try {
- $result = $resolver->query($domain, 'SOA');
- return 'self';
- } catch(Net_DNS2_Exception $e) {
- # try default NS
- $resolver = new Net_DNS2_Resolver();
- try {
- $result = $resolver->query($domain, 'SOA');
- } catch(Net_DNS2_Exception $e) {
- return 'none';
- }
- }
- return $result->answer[0]->mname;
- }
- /**
- * Check limits for a service of an account .
- *
- * @param array $params common module parameters
- * @param string $type domains|subdomins
- *
- * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
- *
- * @return bool true -> limit reached, false -> limit not reached
- */
- function siteBuilderCheckLimit($params, $type) {
- $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $siteBuilder->getQuota($params['username']);
- if($response[$type]['sw'] < 1) {
- return true;
- }
- return false;
- }
- /**
- * Returns API Url .
- *
- * @param string $params common module parameters
- * @param string $user
- * @param string $params common module parameters
- *
- * @return string $apiUrl
- */
- function getSiteBuilderApiURL($params) {
- $httpPrefix = $params['serversecure'] ? 'https://' : 'http://';
- $serverPort = $params['serverport'] ? ':' . $params['serverport'] . '/' : '/';
- return $httpPrefix . $params['serverhostname'] . $serverPort;
- }
|