|
|
@@ -0,0 +1,1211 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * WHMCS cwp7 Provisioning Module
|
|
|
+ *
|
|
|
+ * Provisioning for User Account on the cwp7 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/cwp7/Admin.php');
|
|
|
+
|
|
|
+if (!defined('WHMCS')) {
|
|
|
+ die('This file cannot be accessed directly');
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Define CWP7 product metadata parameters.
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+function cwp7_MetaData() {
|
|
|
+ return array(
|
|
|
+ 'DisplayName' => 'CentOS Web Panel Provisioning',
|
|
|
+ 'APIVersion' => '1.2',
|
|
|
+ 'DefaultNonSSLPort' => '2031',
|
|
|
+ 'DefaultSSLPort' => '2031',
|
|
|
+ 'RequiresServer' => true,
|
|
|
+ 'ServiceSingleSignOnLabel' => 'Login to CWP7',
|
|
|
+ 'AdminSingleSignOnLabel' => 'Login to CWP7 Admin'
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test connection to a CWP7 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 cwp7_Testconnection($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->getServerType();
|
|
|
+ if($response['status'] == 'OK') {
|
|
|
+ return array(
|
|
|
+ 'success' => true,
|
|
|
+ 'error' => '',
|
|
|
+ );
|
|
|
+ }
|
|
|
+ logModuleCall(
|
|
|
+ 'cwp7',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ 'debug',
|
|
|
+ $response
|
|
|
+ );
|
|
|
+ return array(
|
|
|
+ 'success' => false,
|
|
|
+ 'error' => $response['error_msg'] ? $response['error_msg'] : $response['msj'],
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Define CWP7 product configuration options.
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/config-options/
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+function cwp7_ConfigOptions() {
|
|
|
+ $whmcs = App::self();
|
|
|
+ $serverGroupID = $whmcs->get_req_var('servergroup');
|
|
|
+ $serverIDObj = Capsule::table('tblservergroupsrel')
|
|
|
+ ->select('serverid')
|
|
|
+ ->where('groupid', '=', $serverGroupID)
|
|
|
+ ->get();
|
|
|
+ $serverIDs = array();
|
|
|
+ foreach($serverIDObj as $serverID) {
|
|
|
+ array_push($serverIDs, $serverID->serverid);
|
|
|
+ }
|
|
|
+ $server = Capsule::table('tblservers')
|
|
|
+ ->select('hostname', 'accesshash')
|
|
|
+ ->where('id', $serverIDs)
|
|
|
+ ->where('active', '=', 1)
|
|
|
+ ->first();
|
|
|
+ $cwp7 = new cwp7_Admin($server->hostname, $server->accesshash);
|
|
|
+ $cwp7Packages = $cwp7->getPackages();
|
|
|
+ if($cwp7Packages['status'] != 'OK') {
|
|
|
+ logModuleCall(
|
|
|
+ 'cwp7',
|
|
|
+ __FUNCTION__,
|
|
|
+ $cwp7Packages['status'],
|
|
|
+ 'Could not fetch packages',
|
|
|
+ $cwp7Packages['error_msg']
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $cwp7PackageNames = array();
|
|
|
+ foreach($cwp7Packages['msj'] as $cwp7Package) {
|
|
|
+ array_push($cwp7PackageNames, $cwp7Package['package_name']);
|
|
|
+ }
|
|
|
+ $configOptions = array();
|
|
|
+ $configOptions['package'] = array(
|
|
|
+ 'FriendlyName' => 'CWP7 Package',
|
|
|
+ 'Type' => 'dropdown',
|
|
|
+ 'Options' => implode(',', $cwp7PackageNames),
|
|
|
+ 'Description' => 'Select CWP7 Package',
|
|
|
+ );
|
|
|
+ $configOptions['inode'] = array( "Type" => "text" , "Description" => "Max of inode", "Default" => "0",);
|
|
|
+ $configOptions['nofile'] = array( "Type" => "text", "Description" => "Max of nofile", "Default" => "100",);
|
|
|
+ $configOptions['nproc'] = array( "Type" => "text" , "Description" => "Nproc limit - 40 suggested", "Default" => "40",);
|
|
|
+ $configOptions['Own Nameserver IP'] = array( "Type" => "text" , "Description" => "Own Name Server IP", "Default" => "185.163.51.142",);
|
|
|
+ return $configOptions;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Provision a new account of a CWP7 server.
|
|
|
+ *
|
|
|
+ * Attempt to provision a new CWP7 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 cwp7_CreateAccount($params) {
|
|
|
+ $username = strtolower(substr($params['clientsdetails']['firstname'],0,2) . substr($params['clientsdetails']['lastname'],0,3)) . $params['serviceid'];
|
|
|
+ $userdomain = $username . '.local';
|
|
|
+ try {
|
|
|
+ Capsule::table('tblhosting')
|
|
|
+ ->where('id', '=', $params['serviceid'])
|
|
|
+ ->update(
|
|
|
+ array(
|
|
|
+ 'username' => $username,
|
|
|
+ 'domain' => $userdomain,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ logModuleCall(
|
|
|
+ 'cwp7',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ 'Error: could save username & domain in database',
|
|
|
+ $e->getMessage()
|
|
|
+ );
|
|
|
+ return 'Error: could save username & password in database';
|
|
|
+ }
|
|
|
+ if ($params["server"] == 1) {
|
|
|
+ $data = array(
|
|
|
+ 'package' => $params['configoption1'],
|
|
|
+ 'domain' => $userdomain,
|
|
|
+ 'user' => $username,
|
|
|
+ 'pass' => $params['password'],
|
|
|
+ 'email' => $params['clientsdetails']['email'],
|
|
|
+ 'inode' => (int) $params["configoption2"],
|
|
|
+ 'nofile' => (int) $params["configoption3"],
|
|
|
+ 'nproc' => (int) $params["configoption4"],
|
|
|
+ 'server_ips'=>$params["serverip"],
|
|
|
+ );
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->createAccount($data);
|
|
|
+ }
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ return 'Error: ' . $response['error_msg'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Removes a CWP7 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 cwp7_TerminateAccount($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->deleteAccount(array('user' => $params['username'], 'email' => $params['clientsdetails']['email']));
|
|
|
+ if($response['status'] == 'Error') {
|
|
|
+ return 'Error: ' . $response['msj'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Set a CWP7 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 cwp7_SuspendAccount($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->suspendAccount($params['username']);
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ return 'Error: ' . $response['error_msg'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Set a CWP7 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 cwp7_UnsuspendAccount($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 cwp7_ClientArea($params) {
|
|
|
+ $clientInfo = array('moduleclientarea' => '1');
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 = $cwp7->getAccount($params['username']);
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ logModuleCall(
|
|
|
+ 'cwp7',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ 'debug',
|
|
|
+ $response
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if(cwp7CheckLimit($params,'domains')){
|
|
|
+ $clientInfo['domainlimit'] = 1;
|
|
|
+ } else {
|
|
|
+ $clientInfo['domainlimit'] = 0;
|
|
|
+ };
|
|
|
+ if(cwp7CheckLimit($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(cwp7CheckA($domain['domain'],$params['serverip'],$params['configoption5']) == 1) {
|
|
|
+ $domain['DNS'] = 1;
|
|
|
+ }
|
|
|
+ $domain['domainNS'] = cwp7CheckSOA($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(cwp7CheckA($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 CWP7 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 cwp7_ServiceSingleSignOn($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 CWP7 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 cwp7_ChangePassword($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->changePass(array('user' => $params['username'], 'password' => $params['password']));
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ return 'Error: ' . $response['error_msg'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Upgrade or downgrade a CWP7 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 cwp7_ChangePackage($params) {
|
|
|
+ $cwp7 = new cwp7_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 = $cwp7->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 cwp7_UsageUpdate($params) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 cwp7_ClientAreaCustomButtonArray ($params) {
|
|
|
+ if(cwp7CheckLimit($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 cwp7_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 cwp7_newDomain($params) {
|
|
|
+ return array(
|
|
|
+ 'breadcrumb' => array(
|
|
|
+ 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newDomain' => 'Neue Domain',
|
|
|
+ ),
|
|
|
+ 'templatefile' => 'cwp7_add_domain',
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Adds a new domain to a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_addDomain($params) {
|
|
|
+ if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
|
|
|
+ return 'Error: invalid domain name';
|
|
|
+ }
|
|
|
+ if(cwp7CheckLimit($params, 'domains')) {
|
|
|
+ return 'Error: domain limit exceeded';
|
|
|
+ }
|
|
|
+ $vars['user'] = $params['username'];
|
|
|
+ $vars['name'] = $_POST['d'];
|
|
|
+ $vars['type'] = 'domain';
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 cwp7_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' => 'cwp7_add_subdomain',
|
|
|
+ 'vars' => array(
|
|
|
+ 'domainselected' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Adds a new subdomain to domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_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(cwp7CheckLimit($params, 'subdomins')) {
|
|
|
+ return 'Error: subdomain limit exceeded';
|
|
|
+ }
|
|
|
+ $vars['user'] = $params['username'];
|
|
|
+ $vars['name'] = $_POST['s'] . '.' . $_POST['d'];
|
|
|
+ $vars['type'] = 'subdomain';
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->addDomain($vars);
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ return 'Error: ' . $response['error_msg'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Opens a form to delete a domain from a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_delDomainConfirm($params) {
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_del_domain_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'deldomain' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Removes a domain from a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_delDomain($params) {
|
|
|
+ if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
|
|
|
+ return 'Error: invalid domain name';
|
|
|
+ }
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->getAccount($params['username']);
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ logModuleCall(
|
|
|
+ 'cwp7',
|
|
|
+ __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(
|
|
|
+ 'cwp7',
|
|
|
+ __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 = $cwp7->deleteDomain($vars);
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ return 'Error: ' . $response['error_msg'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Opens a form to delete a subdomain from domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_delSubdomainConfirm($params) {
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_del_subdomain_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'delsubdomain' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Removes a subdomain from a domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_delSubdomain($params) {
|
|
|
+ if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
|
|
|
+ return 'Error: invalid domain name';
|
|
|
+ }
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->getAccount($params['username']);
|
|
|
+ if($response['status'] != 'OK') {
|
|
|
+ logModuleCall(
|
|
|
+ 'cwp7',
|
|
|
+ __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(
|
|
|
+ 'cwp7',
|
|
|
+ __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 = $cwp7->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 CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_enableSSLConfirm($params) {
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_enable_SSL_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'SSLdomain' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Aktivate CWP7 AutoSSL for a subdomain or domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_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'];
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_renewSSLConfirm($params) {
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_renew_SSL_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'SSLdomain' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Renews a SSL certificate for a subdomain or domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_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'];
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->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 CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_setDNSConfirm($params) {
|
|
|
+ if(isset($_POST['s'])){
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_set_DNS_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'DNSdomain' => $_POST['d'],
|
|
|
+ 'DNSsubdomain' => $_POST['s'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_set_DNS_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'DNSdomain' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Opens a form to unsset a DNS record for a subdomain or domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_unsetDNSConfirm($params) {
|
|
|
+ if(isset($_POST['s'])){
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_unset_DNS_confirm',
|
|
|
+ 'vars' => array(
|
|
|
+ 'DNSdomain' => $_POST['d'],
|
|
|
+ 'DNSsubdomain' => $_POST['s'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_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 CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_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 CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function cwp7_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 CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_infoDNS($params) {
|
|
|
+ if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
|
|
|
+ return 'Error: invalid domain name';
|
|
|
+ }
|
|
|
+ $cwp7nameserver = cwp7CheckSOA($_POST['d'],$params['configoption5']);
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_help_dns',
|
|
|
+ 'vars' => array(
|
|
|
+ 'infodomain' => $_POST['d'],
|
|
|
+ 'cwp7nameserver' => $cwp7nameserver,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Opens a form to inform about the SSL status of a subdomain or domain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return array template information
|
|
|
+ */
|
|
|
+function cwp7_infoSSL($params) {
|
|
|
+ if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
|
|
|
+ return 'Error: invalid domain name';
|
|
|
+ }
|
|
|
+ return array(
|
|
|
+ 'templatefile' => 'cwp7_help_ssl',
|
|
|
+ 'vars' => array(
|
|
|
+ 'infodomain' => $_POST['d'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Ask nameservers for a IP adress of a given host.
|
|
|
+ *
|
|
|
+ * @param string $host hostname
|
|
|
+ * @param string $serverIP CWP7 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 cwp7CheckA($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(
|
|
|
+ 'cwp7',
|
|
|
+ __FUNCTION__,
|
|
|
+ $e,
|
|
|
+ 'DNS lookup exception',
|
|
|
+ $e->getMessage()
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $hostA = $result->answer;
|
|
|
+ if($hostA[0]->type == 'CNAME') {
|
|
|
+ if(cwp7CheckA($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 cwp7CheckSOA($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 cwp7CheckLimit($params, $type) {
|
|
|
+ $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
|
|
|
+ $response = $cwp7->getQuota($params['username']);
|
|
|
+ if($response[$type]['sw'] < 1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|