| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600 |
- <?php
- /**
- * WHMCS cwp7 Provisioning Module
- *
- * Provisioning for User Account on the cwp7 Server
- *
- * @see https://centos-webpanel.com/
- * @copyright Copyright (c) Thurdata GmbH 2020
- * @license GPL
- */
- use WHMCS\Database\Capsule;
- require_once 'Net/DNS2.php';
- require_once 'Net/Whois.php';
- require_once(__DIR__ . '/api/cwp7/Admin.php');
- if (!defined('WHMCS')) {
- die('This file cannot be accessed directly');
- }
- const NS1 = '10.200.22.100';
- const NSTHURDATA = 'ns1.thurdata.ch';
- 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'
- );
- }
- 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['msj'],
- );
- }
- 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['msj']
- );
- 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",);
- return $configOptions;
- }
- 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' => $params["configoption2"],
- 'nofile' => $params["configoption3"],
- 'nproc' => $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['msj'];
- }
- return 'success';
- }
- 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'] != 'OK') {
- return 'Error: ' . $response['msj'];
- }
- return 'success';
- }
- function cwp7_SuspendAccount($params) {
- $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $cwp7->suspendAccount($params['username']);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['msj'];
- }
- return 'success';
- }
- function cwp7_UnsuspendAccount($params) {
- $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $cwp7->unsuspendAccount($params['username']);
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['msj'];
- }
- return 'success';
- }
- 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 {
- 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']) == 1) {
- $domain['DNS'] = 1;
- }
- $clientInfo['domainNS'] = cwp7CheckSOA($domain['domain']);
- $domain['subdomains'] = array();
- foreach($subDomains as $subDomain) {
- if($subDomain['domain'] == $domain['domain']) {
- $subFQDN = $subDomain['subdomain'] . '.' . $subDomain['domain'];
- 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']) == 1) {
- $subDomain['DNS'] = 1;
- } else {
- unset($subDomain['DNS']);
- }
- array_push($domain['subdomains'], $subDomain);
- }
- }
- array_push($clientInfo['domains'], $domain);
- }
- }
- return array(
- 'tabOverviewReplacementTemplate' => 'clientarea',
- 'vars' => $clientInfo,
- );
- }
- 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' => '',
- );
- }
- }
- 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['msj'];
- }
- return 'success';
- }
- function cwp7_ChangePackage($params){
- $cwp7 = new cwp7_Admin($params['serverhostname'], $params['serveraccesshash']);
- $response = $cwp7->modifyAccount(array('user' => $params['username'], 'email' => $params['clientdetails']['email'], 'package' => $params['configoption1']));
- if($response['status'] != 'OK') {
- return 'Error: ' . $response['msj'];
- }
- return 'success';
- }
- 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());
- }
- }
- }
- }
- function cwp7_ClientAreaCustomButtonArray ($params)
- {
- return array(
- 'Neue Domaine' => 'newDomain',
- 'Neue Subdomaine' => 'newSubdomain',
- );
- }
- function cwp7_ClientAreaAllowedFunctions() {
- return array(
- "Enable SSL" => "enableSSL",
- "Set DNS" => "setDNS",
- "Info DNS" => "infoDNS",
- "Add Domain" => "addDomain",
- "Confirm Delete Domain" => "delDomainConfirm",
- "Delete Domain" => "delDomain",
- "Confirm Delete Subdomain" => "delSubdomainConfirm",
- "Delete Subdomain" => "delSubdomain",
- );
- }
- function cwp7_newDomain($params) {
- return array(
- 'breadcrumb' => array(
- 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newDomain' => 'Neue Domaine',
- ),
- 'templatefile' => 'cwp7_add_domain',
- );
- }
- function cwp7_addDomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $_POST,
- 'debug addDomain',
- filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
- );
- return 'success';
- }
- function cwp7_newSubdomain($params) {
- $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']);
- }
- }
- return array(
- 'breadcrumb' => array(
- 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newSubdomain' => 'Neue Subdomaine',
- ),
- 'templatefile' => 'cwp7_add_subdomain',
- 'vars' => array(
- 'domains' => $clientdomains,
- ),
- );
- }
- function cwp7_addSubdomain($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $_POST,
- 'debug addSubdomain',
- filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
- );
- return 'success';
- }
- function cwp7_delDomainConfirm($params) {
- return array(
- 'templatefile' => 'cwp7_del_domain_confirm',
- 'vars' => array(
- 'deldomain' => $_POST['d'],
- ),
- );
- }
- 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
- return 'success';
- }
- function cwp7_delSubdomainConfirm($params) {
- return array(
- 'templatefile' => 'cwp7_del_subdomain_confirm',
- 'vars' => array(
- 'delsubdomain' => $_POST['d'],
- ),
- );
- }
- 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
- return 'success';
- }
- function cwp7_enableSSL($params) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $_POST,
- 'debug custom',
- $params
- );
- return 'success';
- }
- function cwp7_renewSSL($params) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $_POST,
- 'debug custom',
- $params
- );
- return 'success';
- }
- function cwp7_setDNS($params) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $_POST,
- 'debug custom',
- $params
- );
- return 'success';
- }
- function cwp7_infoDNS($params) {
- if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
- return 'Error: invalid domain name';
- }
- $cwp7nameserver = cwp7CheckSOA($_POST['d']);
- return array(
- 'templatefile' => 'cwp7_help_dns',
- 'vars' => array(
- 'infodomain' => $_POST['d'],
- 'cwp7nameserver' => $cwp7nameserver,
- ),
- );
- }
- function cwp7CheckA($domain, $serverIP, $recurse = 0) {
- if($recurse > 3) {
- return false;
- }
- $nameserver = array(NS1);
- $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
- try {
- $result = $resolver->query($domain, 'A');
-
- } catch(Net_DNS2_Exception $e) {
- logModuleCall(
- 'cwp7',
- __FUNCTION__,
- $e,
- 'DNS lookup exception',
- $e->getMessage()
- );
- }
- $domainA = $result->answer;
- if($domainA[0]->type == 'CNAME') {
- if(cwp7CheckA($domainA[0]->cname, $serverIP, $recurse++)) {
- return true;
- }
- }
- if($domainA[0]->type == 'A') {
- if($domainA[0]->address == $serverIP){
- return true;
- }
- }
- }
- function cwp7CheckSOA($domain) {
- $nameserver = array(NS1);
- $domain='seecure.ch';
- $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 == NSTHURDATA) {
- return 'self';
- }
- return $result->answer[0]->mname;
- }
|