| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165 |
- <?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' => '',
- );
- }
- return array(
- 'success' => false,
- 'error' => $response['error_msg'],
- );
- }
- /**
- * 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['Nameserver IP for lookups'] = array( "Type" => "text" , "Description" => "Name Server IP", "Default" => "185.163.51.142",);
- $configOptions['Name of own Nameserver'] = array( "Type" => "text" , "Description" => "Name Server Name", "Default" => "ns1.thurdata.ch",);
- 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']));
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $params,
- 'debug',
- $response
- );
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['error_msg'];
- }
- 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
- );
- }
- $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'],$params['configoption6']);
- $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"],
- );
- $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) {
- 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",
- "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';
- }
- $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) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $_POST,
- 'debug 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';
- }
- $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'],$params['configoption6']);
- 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);
- $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
- try {
- $result = $resolver->query($host, 'A');
-
- } catch(Net_DNS2_Exception $e) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $e,
- 'DNS lookup exception',
- $e->getMessage()
- );
- }
- $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, $nameserverName ) {
- $nameserver = array($nameserverIP);
- $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
- try {
- $result = $resolver->query($domain, 'SOA');
-
- } catch(Net_DNS2_Exception $e) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $e,
- 'DNS lookup exception',
- $e->getMessage()
- );
- return 'none';
- }
- if($result->answer[0]->mname == $nameserverName) {
- return 'self';
- }
- return $result->answer[0]->mname;
- }
|