New in CWP Edge / LTSFree with every CWPpro licenceWebsites up to 300x faster

CWP now includes LSPHP, LSAPI-Cache and CWP Cage at no extra cost with all CWPpro licences. The LSAPI-Cache plugin is integrated into our WordPress and other script installers. Available now in the Edge-Latest and LTS-Stable versions. Discuss in the forum

LSPHP / Cache ›
CWP Secure KernelKernel-level protectionEvery site in its own sandbox

Every PHP site, cron job and SSH session runs in its own profile that the kernel enforces. A hacked WordPress cannot read other accounts’ files, and crypto miners and unexpected processes are stopped. Discuss in the forum

Secure Kernel ›
CWP DataCenter PanelFree for CWPpro serversAll your servers on one screen

Manage all your CWP servers from one panel: live health, every hosting account, CWP and OS updates on many servers at once, backups, SSL, firewall and Telegram alerts. Discuss in the forum

DataCenter Panel ›
CWP Backup ServerFree for CWPpro serversBackups that ransomware cannot reach

Protected backups of all your CWP servers on a separate machine. Snapshots a hosting server cannot delete, and restore of files, databases, mail and whole accounts in the admin and user panel. Discuss in the forum

Backup Server ›
WordPress ManagerIncluded & freeWordPress managed from the panel

Install, secure, update, back up and clone WordPress sites without FTP. Updates are tested on a staging clone first and applied to the live site only when they pass, with a backup taken first. Discuss in the forum

WordPress Manager ›
CWP CageIsolationEvery account in its own cage

Per-account isolation built from Linux namespaces and cgroups. A break-in or a runaway script on one site cannot reach another account, the panel or the rest of the server; resource limits per hosting package. Discuss in the forum

CWP Cage ›
Script InstallerOne-click appsWordPress, Joomla, Moodle and more in one click

CWP’s own script installer in the user panel: pick an app, choose the domain and folder, and it is live in seconds with its database and admin login created automatically. Ready for LSPHP and LSAPI-Cache. Discuss in the forum

Script Installer ›
DNS ClusterFor every control panelOne DNS cluster for all your servers

Your servers keep creating domains as usual; the zones are collected into one authoritative PowerDNS cluster you control, with DNSSEC, roles and a full activity trail. Accepts CWP, cPanel, Plesk, DirectAdmin and BIND. Discuss in the forum

DNS Cluster ›
CWP BillingFree to useBilling and support system for hosting providers

Clients, services, invoices, payments, domains, server provisioning and support tickets in one place. All gateways, server modules and registrars are free, with free migration from WHMCS, ClientExec and Blesta. Discuss in the forum

CWP Billing ›
CWPproFrom $1.49 per monthEvery CWP feature unlocked

CWPpro is the professional version of Control Web Panel: all features, unlimited accounts, the latest CWP version and security fixes first. $1.49 per month or $11.99 per year. Discuss in the forum

Get CWPpro ›

[module] WHMCS (Fix)

Started by IHOS, March 13, 2019, 04:17:46 AM

Previous topic - Next topic

IHOS

ihoscwp7
WHMCS Module (Fix) for Centos-WebPanel (CWP) by IHOS

Attention ! The module was created fixed for my private use, in case of error I will be happy to fix it as far as possible!

Credits

Based on Module http://wiki.centos-webpanel.com/whmcs-module-for-cwp-api

Tested on version
WHMCS: 7.7.1
CWPpro version: 0.9.8.779

Screenshot


Features:
Add Account - Working
Edit Account - Working
Suspend Account - Working
Unsuspend Account - Working
Delete Account - Working
Change Password - Working
Edit Packages - Working

Future Implementations:
#Admin Dashboard Widgets
Provide necessary and important information in your interface in the administrator's home page panel.

#Loader Functions
An example use case for this is for a Package or Plan name field, where the values need to be fetched via an API from the remote system where the Packages or Plans are defined. Without a loader function, the end user would have to manually enter the package or plan name for the product. With a loader being used, WHMCS will poll the remote API service for a list of possible values when the field is rendered to the end user and allow them to make a choice.

#Client Area Output
Product Details Page Output
Creating output to display on the same page as the product details in the client area is easy.

#Admin Services Tab
Admin Services Tab functions allow definition of extra fields to appear on the product details in the admin area. Used for informational output, or for settings and values stored in custom tables or outside WHMCS.

Installation:

[1]. Extract file ihoscwp7.zip in your WHMCS folder

WHMCS/modules/servers/

As extracted module file path will look like this WHMCS/modules/servers/ihoscwp7/ihoscwp7.php

[2]. In WHMCS

In Menu goto: Setup -> Products/Services -> Servers
Add New Server and under "Server Details"
Type = IHOS CWP7
Username: root
Password: (your server password)
Access Hash: copy your key from CWP API

[3]. Generate API Key on the CWP server

Goto Left-Menu -> CWP Settings -> API Manager

Use the following permissions:
-Add, Edit, Suspend, Unsuspend and Delete Accounts
-Edit Packages
-Change Password

Updates
Changelog

[INFO] Date: 13/03/2019
[INFO] Version Release: 1.0.0
  • Fix/Revised methods CreateAccount, SuspendAccount, UnsuspendAccount, TerminateAccount, ChangePassword, ChangePackage
  • Added detailed success and error logs in all methods
  • Added verification on file for not directly accessing
  • Added exception handling

    More Info and Download: https://bitbucket.org/vinicius_ihos/ihoscwp7

    ! IMPORTANT
    If there is any problem or you have suggestion to add or request please reply here on the forum.
    Please don't send me PM's.
    Any code fixes, improvements, etc. Bitbucket can be used.

IHOS

Update! - New version available | 1.0.1

* Date: 16/03/2019
* Version Release: 1.0.1
* + Added function ihoscwp7_LoaderFunction

List of Packages are now automatically loaded

ScreenShot




Jamshed Datori

Fantastic, I will check the module now.

Also, don't forget to submit your module to https://marketplace.whmcs.com/

Jamshed Datori

I have started testing your module and I am reporting first bug.

When I click on "Admin Control Panel" button, it takes me to CWP Admin login page but it does not automatically get me in.

Kindly fix it.



josemnunez

For now the auto login is not available for any of the environments!

Jamshed Datori

Quote from: josemnunez on March 21, 2019, 02:05:05 AM
For now the auto login is not available for any of the environments!

OK. Have not you any API command/access for the same?

moh.elzaiat

i'm using CWP with WHMCS 7.7.1 however Termination not working?
any advise?

pixelpadre

Quote from: altomarketing on September 22, 2019, 02:19:26 AM
Quote from: jamshed_206 on March 23, 2019, 06:40:10 AM
Quote from: josemnunez on March 21, 2019, 02:05:05 AM
For now the auto login is not available for any of the environments!

OK. Have not you any API command/access for the same?

you can download with AUTOLOGIN here: https://gitlab.com/whmcs-proyects/servers/centos-webpanel

Spammer.  Page has link for paid support

henrycoule

I really like your idea of fetching the packages from the server into WHMCS but I was missing the autologin from the other package so I combined yours and the other one to get both worlds. If anyone is interested I can share it.

Quote from: IHOS on March 16, 2019, 03:57:29 AM
Update! - New version available | 1.0.1

* Date: 16/03/2019
* Version Release: 1.0.1
* + Added function ihoscwp7_LoaderFunction

List of Packages are now automatically loaded

ScreenShot



Jamshed Datori

Quote from: henrycoule on November 06, 2019, 07:10:55 AM
I really like your idea of fetching the packages from the server into WHMCS but I was missing the autologin from the other package so I combined yours and the other one to get both worlds. If anyone is interested I can share it.

Quote from: IHOS on March 16, 2019, 03:57:29 AM
Update! - New version available | 1.0.1

* Date: 16/03/2019
* Version Release: 1.0.1
* + Added function ihoscwp7_LoaderFunction

List of Packages are now automatically loaded

ScreenShot



Yes. Please share the files.

prakash7610

#10
HI IHOS

i have added some code from github for auto login from client area for user panel

pls check this out
<?php
/**
 * Created by IntelliJ IDEA.
 * User: Vinicius Assis
 * E-mail: viniciusassisnascimento@gmail.com
 * Company: IHOS T.I.
 * Date: 10/03/2019
 * Time: 23:41
 *
 * Changelog
 * #############################
 * Date: 16/03/2019
 * Version Release: 1.0.1
 * + Added function ihoscwp7_LoaderFunction
 * #############################
 * Date: 13/03/2019
 * Version Release: 1.0.0
 * # Fix/Revised methods CreateAccount, SuspendAccount, UnsuspendAccount, TerminateAccount, ChangePassword, ChangePackage
 * + Added detailed success and error logs in all methods
 * + Added Verification on file for not directly accessing
 * + Added exception handling
 * #############################
 */

if (!defined("WHMCS")) {
    die(
"This file cannot be accessed directly");
}

/**
 * @return array
 */
function ihoscwp7_MetaData()
{
    return array(
        
'DisplayName' => 'IHOS CWP7',
        
'APIVersion' => '1.1', // Use API Version 1.1
        
'RequiresServer' => true,
        
'DefaultSSLPort' => '2304', // Default SSL Connection Port
        
'ServiceSingleSignOnLabel' => 'Login to Panel as User',
        
'AdminSingleSignOnLabel' => 'Login to Panel as Admin',
    );
}

/**
 * @return array
 */
function ihoscwp7_ConfigOptions()
{
    return array(
        
'PACKAGE-NUMBER' => array(
            
'Type' => 'text',
            
'Loader' => 'ihoscwp7_LoaderFunction',
            
'SimpleMode' => true,
            
'Description' => 'Package ID'
        
),
        
'Inode' => array(
            
'Type' => 'text',
            
'Default' => '0',
            
'SimpleMode' => true,
            
'Description' => 'Limit Inodes, 0 for unlimited'
        
),
        
'Nofile' => array(
            
'Type' => 'text',
            
'Default' => '100',
            
'SimpleMode' => true,
            
'Description' => 'Limit number of Open Files for account'
        
),
        
'Nproc' => array(
            
'Type' => 'text',
            
'Default' => '40',
            
'SimpleMode' => true,
            
'Description' => 'Limit number of Processes for account, don\'t use 0 as it will not allow any processes'
        
)
    );
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_CreateAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'package' => $params['configoption1'],
                
'domain' => $params['domain'],
                
'key' => $params['serveraccesshash'],
                
'action' => 'add',
                
'username' => $params['username'],
                
'user' => $params['username'],
                
'pass' => $params['password'],
                
'email' => $params['clientsdetails']['email'],
                
'inode' => $params['configoption2'],
                
'nofile' => $params['configoption3'],
                
'nproc' => $params['configoption4'],
                
'server_ips' => $params['serverip']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account');
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_SuspendAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'susp',
                
'user' => $params['username']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account');
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_UnsuspendAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'unsp',
                
'user' => $params['username']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account');
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_TerminateAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'del',
                
'user' => $params['username'],
                
'email' => $params['clientsdetails']['email']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_ChangePassword(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'udp',
                
'user' => $params['username'],
                
'pass' => $params['password']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/changepass';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_ChangePackage(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'udp',
                
'user' => $params['username'],
                
'package' => $params['configoption1']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/changepack';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return string
 */
function ihoscwp7_ClientArea(array $params)
{
      
$postvars = array('key' => $params["serveraccesshash"],'action' => 'list','user' => $params["username"],'timer'=>5);
    
$postdata = http_build_query($postvars);
    
$curl = curl_init();
    
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
    
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    
curl_setopt($curl, CURLOPT_POST, true);
    
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
    
$answer = curl_exec($curl);
    
$arry=(json_decode($answer,true)); //die;
    
$link=$arry['msj']['details'];
    
$linkautologin="https://{$params["serverhostname"]}:2083/{$link[0]['user']}/?user_session={$link[0]['token']}";
    
//logModuleCall('cwpwhmcs','centoswebpanel_LoginLink','https://' . $params["serverhostname"] . ':2304/v1/user_session'.$postdata,$answer);


    
$code = '<form action="'.$linkautologin.'" method="GET" target="_blank">
        <input type="submit" value="Login to Control Panel" />
        <input type="hidden" id="user_session" name="user_session" value="'
.$link[0]['token'].'" />
        <input type="button" value="Login to Webmail" onClick="window.open(\'https://'
.$params["serverhostname"].'/webmail\')" />
        </form>'
;
    return 
$code;
}

/**
 * @param $params
 * @return string
 */
function ihoscwp7_AdminLink($params)
{
    
$code = '<input type="button" value="Admin Control Panel" onClick="window.open(\'https://' . $params['serverhostname'] . ':2031/login/index.php\')" />';

    return 
$code;
}

/**
 * @param $params
 */
function ihoscwp7_LoginLink($params)
{
   
$postvars = array('key' => $params["serveraccesshash"],'action' => 'list','user' => $params["username"],'timer'=>5);
    
$postdata = http_build_query($postvars);
    
$curl = curl_init();
    
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
    
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    
curl_setopt($curl, CURLOPT_POST, true);
    
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
    
$answer = curl_exec($curl);
    
$arry=(json_decode($answer,true)); //die;
    
$link=$arry['msj']['details'];
    
$linkautologin="https://{$params["serverhostname"]}:2083/{$link[0]['user']}/?user_session={$link[0]['token']}";
    
logModuleCall('cwpwhmcs','centoswebpanel_LoginLink','https://' . $params["serverhostname"] . ':2304/v1/user_session'.$postdata,$answer);

    echo 
"<a href=\"{$linkautologin}\" target=\"_blank\" style=\"color:#cc0000\">Control Panel</a>";
}

function 
ihoscwp7_LoaderFunction($params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'list'
            
);

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/packages';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

        }

        if (
curl_error($curl)) {
            throw new 
Exception('Unable to connect: ' . curl_errno($curl) . ' - ' . curl_error($curl));
        } elseif (empty(
$response)) {
            throw new 
Exception('Empty response');
        }

        
curl_close($curl);

        
$packages = json_decode($response, true);

        
$packageNames = [];
        foreach (
$packages['msj'] as $key => $package) {
            
$packageNames[$package['id']] = ucfirst($package['package_name']);
        }

        if (
is_null($packageNames)) {
            throw new 
Exception('Invalid response format');
        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$packageNames;
}

vanthoi

Quote from: prakash7610 on May 22, 2020, 08:26:06 AM
HI IHOS

i have added some code from github for auto login from client area for user panel

pls check this out
<?php
/**
 * Created by IntelliJ IDEA.
 * User: Vinicius Assis
 * E-mail: viniciusassisnascimento@gmail.com
 * Company: IHOS T.I.
 * Date: 10/03/2019
 * Time: 23:41
 *
 * Changelog
 * #############################
 * Date: 16/03/2019
 * Version Release: 1.0.1
 * + Added function ihoscwp7_LoaderFunction
 * #############################
 * Date: 13/03/2019
 * Version Release: 1.0.0
 * # Fix/Revised methods CreateAccount, SuspendAccount, UnsuspendAccount, TerminateAccount, ChangePassword, ChangePackage
 * + Added detailed success and error logs in all methods
 * + Added Verification on file for not directly accessing
 * + Added exception handling
 * #############################
 */

if (!defined("WHMCS")) {
    die(
"This file cannot be accessed directly");
}

/**
 * @return array
 */
function ihoscwp7_MetaData()
{
    return array(
        
'DisplayName' => 'IHOS CWP7',
        
'APIVersion' => '1.1', // Use API Version 1.1
        
'RequiresServer' => true,
        
'DefaultSSLPort' => '2304', // Default SSL Connection Port
        
'ServiceSingleSignOnLabel' => 'Login to Panel as User',
        
'AdminSingleSignOnLabel' => 'Login to Panel as Admin',
    );
}

/**
 * @return array
 */
function ihoscwp7_ConfigOptions()
{
    return array(
        
'PACKAGE-NUMBER' => array(
            
'Type' => 'text',
            
'Loader' => 'ihoscwp7_LoaderFunction',
            
'SimpleMode' => true,
            
'Description' => 'Package ID'
        
),
        
'Inode' => array(
            
'Type' => 'text',
            
'Default' => '0',
            
'SimpleMode' => true,
            
'Description' => 'Limit Inodes, 0 for unlimited'
        
),
        
'Nofile' => array(
            
'Type' => 'text',
            
'Default' => '100',
            
'SimpleMode' => true,
            
'Description' => 'Limit number of Open Files for account'
        
),
        
'Nproc' => array(
            
'Type' => 'text',
            
'Default' => '40',
            
'SimpleMode' => true,
            
'Description' => 'Limit number of Processes for account, don\'t use 0 as it will not allow any processes'
        
)
    );
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_CreateAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'package' => $params['configoption1'],
                
'domain' => $params['domain'],
                
'key' => $params['serveraccesshash'],
                
'action' => 'add',
                
'username' => $params['username'],
                
'user' => $params['username'],
                
'pass' => $params['password'],
                
'email' => $params['clientsdetails']['email'],
                
'inode' => $params['configoption2'],
                
'nofile' => $params['configoption3'],
                
'nproc' => $params['configoption4'],
                
'server_ips' => $params['serverip']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account');
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_SuspendAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'susp',
                
'user' => $params['username']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account');
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_UnsuspendAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'unsp',
                
'user' => $params['username']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account');
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_TerminateAccount(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'del',
                
'user' => $params['username'],
                
'email' => $params['clientsdetails']['email']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/account';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_ChangePassword(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'udp',
                
'user' => $params['username'],
                
'pass' => $params['password']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/changepass';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return mixed|string
 */
function ihoscwp7_ChangePackage(array $params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'udp',
                
'user' => $params['username'],
                
'package' => $params['configoption1']
            );

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/changepack';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

            
$response = json_decode($response, true);
            if (
$response['status'] == 'OK') {
                
$result = 'success';
            } else {
                
$result = $response;
            }

        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$result;
}

/**
 * @param array $params
 * @return string
 */
function ihoscwp7_ClientArea(array $params)
{
      
$postvars = array('key' => $params["serveraccesshash"],'action' => 'list','user' => $params["username"],'timer'=>5);
    
$postdata = http_build_query($postvars);
    
$curl = curl_init();
    
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
    
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    
curl_setopt($curl, CURLOPT_POST, true);
    
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
    
$answer = curl_exec($curl);
    
$arry=(json_decode($answer,true)); //die;
    
$link=$arry['msj']['details'];
    
$linkautologin="https://{$params["serverhostname"]}:2083/{$link[0]['user']}/?user_session={$link[0]['token']}";
    
//logModuleCall('cwpwhmcs','centoswebpanel_LoginLink','https://' . $params["serverhostname"] . ':2304/v1/user_session'.$postdata,$answer);


    
$code = '<form action="'.$linkautologin.'" method="GET" target="_blank">
        <input type="submit" value="Login to Control Panel" />
        <input type="hidden" id="user_session" name="user_session" value="'
.$link[0]['token'].'" />
        <input type="button" value="Login to Webmail" onClick="window.open(\'https://'
.$params["serverhostname"].'/webmail\')" />
        </form>'
;
    return 
$code;
}

/**
 * @param $params
 * @return string
 */
function ihoscwp7_AdminLink($params)
{
    
$code = '<input type="button" value="Admin Control Panel" onClick="window.open(\'https://' . $params['serverhostname'] . ':2031/login/index.php\')" />';

    return 
$code;
}

/**
 * @param $params
 */
function ihoscwp7_LoginLink($params)
{
   
$postvars = array('key' => $params["serveraccesshash"],'action' => 'list','user' => $params["username"],'timer'=>5);
    
$postdata = http_build_query($postvars);
    
$curl = curl_init();
    
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
    
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    
curl_setopt($curl, CURLOPT_POST, true);
    
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
    
$answer = curl_exec($curl);
    
$arry=(json_decode($answer,true)); //die;
    
$link=$arry['msj']['details'];
    
$linkautologin="https://{$params["serverhostname"]}:2083/{$link[0]['user']}/?user_session={$link[0]['token']}";
    
logModuleCall('cwpwhmcs','centoswebpanel_LoginLink','https://' . $params["serverhostname"] . ':2304/v1/user_session'.$postdata,$answer);

    echo 
"<a href=\"{$linkautologin}\" target=\"_blank\" style=\"color:#cc0000\">Control Panel</a>";
}

function 
ihoscwp7_LoaderFunction($params)
{
    try {

        if (
$params['server'] == 1) {

            
$postvars = array(
                
'key' => $params['serveraccesshash'],
                
'action' => 'list'
            
);

            
$postdata = http_build_query($postvars);

            
$url = 'https://' . $params['serverhostname'] . ':' . $params['serverport'] . '/v1/packages';

            
$curl = curl_init();
            
curl_setopt($curl, CURLOPT_URL, $url);
            
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
            
curl_setopt($curl, CURLOPT_POST, true);
            
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            
$response = curl_exec($curl);

            
logModuleCall(
                
'ihoscwp7',
                
__FUNCTION__,
                
$url . '/?' . $postdata,
                
$response
            
);

        }

        if (
curl_error($curl)) {
            throw new 
Exception('Unable to connect: ' . curl_errno($curl) . ' - ' . curl_error($curl));
        } elseif (empty(
$response)) {
            throw new 
Exception('Empty response');
        }

        
curl_close($curl);

        
$packages = json_decode($response, true);

        
$packageNames = [];
        foreach (
$packages['msj'] as $key => $package) {
            
$packageNames[$package['id']] = ucfirst($package['package_name']);
        }

        if (
is_null($packageNames)) {
            throw new 
Exception('Invalid response format');
        }

    } catch (
Exception $e) {
        
logModuleCall(
            
'ihoscwp7',
            
__FUNCTION__,
            
$params,
            
$e->getMessage(),
            
$e->getTraceAsString()
        );

        return 
$e->getMessage();
    }

    return 
$packageNames;
}

Can you add this information to the User on CWP7?
Processor limits and file opening on missing CWP7 modules with WHMCS 7.10.2

jmshosting

Hi

You can change this two line

From

                'nofile' => $params['configoption3'],
                'nproc' => $params['configoption4'],


to

                'limit_nofile' => $params['configoption3'],
                'limit_nproc' => $params['configoption4'],


CWP have new name of nofile och nproc.

Same change can be done in CWP7.php. (https://wiki.centos-webpanel.com/whmcs-module-for-cwp-api).