|
- <?php
-
- /**
- * WHMCS VPSManager Module
- *
- */
-
- if (!defined('WHMCS')) {
- http_response_code(403);
- exit;
- }
-
- require_once __DIR__ . '/lib/VPSManager.php';
- require_once __DIR__ . '/lib/ClientView.php';
- require_once __DIR__ . '/WhmcsHelpers/CustomField.php';
-
- use VPSManager\VPSManager;
- use WHMCS\Database\Capsule;
- use VPSManager\WhmcsHelpers\CustomField;
-
-
- function vpsmanager_Metadata() {
- return array(
- 'DisplayName' => 'o6h VPSManager Module',
- 'APIVersion' => '1.1',
- 'RequiresServer' => true,
- 'DefaultNonSSLPort' => '8080',
- 'DefaultSSLPort' => '8080',
- );
- }
-
- function vpsmanager_ConfigOptions( $params ) {
-
- $vpsmanager = new VPSManager();
-
- try {
- $nodes = $vpsmanager->apiCall('nodes');
- $packs = $vpsmanager->apiCall('packs');
- } catch (\Throwable $e) {
- $nodes = [];
- $packs = [];
- }
-
- return [
- 'VPSManager Remote Username' => [
- 'Type' => 'text',
- 'Size' => '16',
- 'Description' => 'Remote Username configured in VPSManager.'
- ],
- 'VPSManager Remote Password' => [
- 'Type' => 'password',
- 'Size' => '16',
- 'Description' => 'Remote Password configured in VPSManager.'
- ],
- 'VPSManager URL' => [
- 'Type' => 'text',
- 'Size' => '32',
- 'Description' => 'E.g. vpsmanager.example.tld:8080'
- ],
- 'VPSManager SSL' => [
- 'Type' => 'yesno',
- 'Description' => 'Tick if you enabled SSL on your VPSManager'
- . ' Controlpanel Web Interface.'
- ],
- 'Nodo' => [
- 'Type' => 'dropdown',
- 'Options' => $nodes,
- 'SimpleMode' => false,
- ],
- 'Pack' => [
- 'Type' => "dropdown", # Dropdown Choice of Options
- 'Options' => $packs
- ],
- ];
- }
-
- function vpsmanager_CreateAccount( $params ) {
- return 'success';
- }
-
- function vpsmanager_TerminateAccount( $params ) {
-
- }
-
- function vpsmanager_ChangePackage( $params ) {
-
- }
-
- function vpsmanager_SuspendAccount( $params )
- {
- return vpsmanager_m_suspend($params);
- }
-
- function vpsmanager_UnsuspendAccount( $params )
- {
- return vpsmanager_m_unsuspend($params);
- }
-
- function vpsmanager_ChangePassword( $params ) {
-
- }
-
- function vpsmanager_ClientAreaCustomButtonArray()
- {
- return array(
- "Reiniciar" => "Reiniciar",
- "Detener" => "Detener",
- "Iniciar" => "Iniciar",
- "Firewall" => "Firewall",
- "Snapshots" => "Snapshots",
- );
- }
-
-
-
- function vpsmanager_Firewall(array $params)
- {
- if (isset($_POST["a"])) {
- return vpsmanager_m_firewall($params);
- }
-
- return [
- 'templatefile' => 'templates/firewall',
- 'vars' => [
- 'action' => 'Firewall',
- 'selfip' => ($_SERVER['REMOTE_ADDR'] ?? '')
- ]
- ];
- }
-
- function vpsmanager_Reiniciar(array $params)
- {
- if (isset($_POST["a"])) {
- return vpsmanager_m_reboot($params);
- }
-
- return [
- 'templatefile' => 'templates/alert',
- 'vars' => [
- 'action' => 'Reiniciar',
- 'description' => 'reiniciar el servidor'
- ]
- ];
- }
-
- function vpsmanager_Detener(array $params)
- {
- if (isset($_POST["a"])) {
- return vpsmanager_m_shutdown($params);
- }
-
- return [
- 'templatefile' => 'templates/alert',
- 'vars' => [
- 'action' => 'Detener',
- 'description' => 'detener el servidor'
- ]
- ];
- }
-
- function vpsmanager_Iniciar(array $params)
- {
- if (isset($_POST["a"])) {
- return vpsmanager_m_boot($params);
- }
-
- return [
- 'templatefile' => 'templates/alert',
- 'vars' => [
- 'action' => 'Iniciar',
- 'description' => 'iniciar el servidor'
- ]
- ];
- }
-
- function vpsmanager_Snapshots(array $params)
- {
- // si recibimos un post lo procesamos en la otra funcion
- if (isset($_POST["a"])) {
- return vpsmanager_m_snapshots($params);
- }
-
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- $serverhostname = $params['domain'];
-
- // hacemos la llamada para popular la tabla de snapshots
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/getsnap';
-
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- $result = curl_exec($ch);
-
- //Decode Json
- $datos = json_decode($result,true);
-
- curl_close($ch);
-
- return [
- 'templatefile' => 'templates/snapshots',
- 'vars' => [
- 'action' => 'Snapshots',
- 'selfip' => ($_SERVER['REMOTE_ADDR'] ?? ''),
- 'uuid' => $uuid,
- 'serverhostname' => $serverhostname,
- 'size' => $datos['size'] ?? '',
- 'date' => $datos['date'] ?? ''
- ]
- ];
- }
-
- function vpsmanager_m_snapshots(array $params)
- {
- if (isset($_POST["abort"])) {
- return "operacion cancelada por el usuario";
- }
-
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/restoresnap';
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
-
- function vpsmanager_m_reboot(array $params)
- {
- if (isset($_POST["abort"])) {
- return "Operacion cancelada por el usuario";
- }
-
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/command/reboot';
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
- function vpsmanager_m_shutdown(array $params)
- {
- if (isset($_POST["abort"])) {
- return "operacion cancelada por el usuario";
- }
-
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/command/shutdown';
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
- function vpsmanager_m_firewall(array $params)
- {
- if (isset($_POST["abort"])) {
- return "operacion cancelada por el usuario";
- }
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
-
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
- $ip = $_POST["ip"] ?? '';
- if (!is_string($ip) || !filter_var($ip, FILTER_VALIDATE_IP)) {
- return 'Dirección IP no válida.';
- }
-
- if ( ($_POST["proceed"] ?? null) == "Desbloquear" ) {
- $url = $globalurl . '/unblock';
- } elseif ( ($_POST["proceed"] ?? null) == "Bloquear" ) {
- $url = $globalurl . '/block';
- } else {
- return 'Acción de firewall no válida.';
- }
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid,
- 'ip' => $ip
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
-
- function vpsmanager_m_boot(array $params)
- {
- if (isset($_POST["abort"])) {
- return "operacion cancelada por el usuario";
- }
-
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/command/boot';
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
- function vpsmanager_m_suspend(array $params)
- {
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/suspend';
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
- function vpsmanager_m_unsuspend(array $params)
- {
- $datos = $params['customfields'];
-
- $gzid = $datos['gzid'];
- $uuid = $datos['uuid'];
-
- try {
- $globalurl = \VPSManager\Config::url(\VPSManager\Config::load(), 'vpsmanager_api_url', false);
- if (!function_exists('curl_init')) {
- return 'Transporte del módulo no disponible.';
- }
- } catch (\Throwable $e) {
- return 'Configuración del módulo no disponible.';
- }
- $url = $globalurl . '/unsuspend';
-
- //create a new cURL resource
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-
- //setup request to send json via POST
- $data = array(
- 'gzid' => $gzid,
- 'uuid' => $uuid
- );
-
- $payload = json_encode($data);
-
- //attach encoded JSON string to the POST fields
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
-
- //set the content type to application/json
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
-
- //execute the POST request
- $result = curl_exec($ch);
-
- //close cURL resource
- curl_close($ch);
-
- return 'success';
- }
-
-
-
- function vpsmanager_ClientArea($params)
- {
- // WHMCS resolves and authorizes this service before calling the module.
- // Only a whitelisted range is read from the request, never uuid/vtype/id.
- return \VPSManager\ClientView::render($params, $_GET['metrics_range'] ?? '24h');
- }
-
- function vpsmanager_AdminServicesTabFields($params)
- {
- return ['' => \VPSManager\ClientView::links($params)];
- }
-
- function vpsmanager_LoginLink($params)
- {
- return [];
- }
|