From f50125b67433af437e6371b8dbe7a53dbe33258b Mon Sep 17 00:00:00 2001 From: Jordan Schelew Date: Wed, 21 Jun 2017 15:42:36 -0300 Subject: [PATCH] Enable/Disable TUN-TAP device feature --- .../servers/solusvmpro/js/get_user_data.js | 2 +- modules/servers/solusvmpro/lang/english.php | 5 +- modules/servers/solusvmpro/lib/SolusVM.php | 8 ++ modules/servers/solusvmpro/solusvmpro.php | 74 +++++++++++++++++++ .../templates/clientareaBootstrap.tpl | 12 +++ 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/modules/servers/solusvmpro/js/get_user_data.js b/modules/servers/solusvmpro/js/get_user_data.js index ceb05ef..b91ed06 100644 --- a/modules/servers/solusvmpro/js/get_user_data.js +++ b/modules/servers/solusvmpro/js/get_user_data.js @@ -47,7 +47,7 @@ $(function () { $("#controlpanellink").attr("onclick", "window.open('" + data.controlpanellink + "','_blank')"); } - var optionsIds = ["displayreboot", "displayshutdown", "displayboot", "displayconsole", "displayhtml5console", "displayvnc", "displayrootpassword", "displayhostname", "displayvncpassword", "displaypanelbutton", "displayclientkeyauth"]; + var optionsIds = ["displayreboot", "displayshutdown", "displayboot", "displayconsole", "displayhtml5console", "displayvnc", "displayrootpassword", "displayhostname", "displayvncpassword", "displaypanelbutton", "displayclientkeyauth", "displaytunenable", "displaytundisable"]; var showOptions = false; optionsIds.forEach(function (v) { if (data.hasOwnProperty(v)) { diff --git a/modules/servers/solusvmpro/lang/english.php b/modules/servers/solusvmpro/lang/english.php index 4ae19a0..d4fcaff 100644 --- a/modules/servers/solusvmpro/lang/english.php +++ b/modules/servers/solusvmpro/lang/english.php @@ -4,7 +4,6 @@ die( "This file cannot be accessed directly" ); } - $_LANG['solusvmpro_reboot'] = 'Reboot'; $_LANG['solusvmpro_boot'] = 'Boot'; $_LANG['solusvmpro_shutdown'] = 'Shutdown'; @@ -93,4 +92,6 @@ $_LANG['solusvmpro_shutdown_confirm_label'] = 'Confirm Shutdown'; $_LANG['solusvmpro_cancel'] = 'Cancel'; $_LANG['solusvmpro_shutdown_confirm'] = 'Are you sure you wish to power off this server?'; -$_LANG['solusvmpro_reboot_confirm'] = 'Are you sure you wish to restart this server?'; \ No newline at end of file +$_LANG['solusvmpro_reboot_confirm'] = 'Are you sure you wish to restart this server?'; +$_LANG['solusvmpro_tuntap_enable'] = 'Enable TUN/TAP'; +$_LANG['solusvmpro_tuntap_disable'] = 'Disable TUN/TAP'; \ No newline at end of file diff --git a/modules/servers/solusvmpro/lib/SolusVM.php b/modules/servers/solusvmpro/lib/SolusVM.php index 8d5b495..319fbd8 100644 --- a/modules/servers/solusvmpro/lib/SolusVM.php +++ b/modules/servers/solusvmpro/lib/SolusVM.php @@ -790,6 +790,14 @@ public function clientAreaCalculations( $result ) { } $cparams["displaygraphs"] = 1; } + + if ( $this->getExtData( "tun-enable" ) != "disable" ) { + $cparams["displaytunenable"] = 1; + } + + if ( $this->getExtData( "tun-disable" ) != "disable" ) { + $cparams["displaytundisable"] = 1; + } return $cparams; } diff --git a/modules/servers/solusvmpro/solusvmpro.php b/modules/servers/solusvmpro/solusvmpro.php index 21c4a5a..6b6f13a 100644 --- a/modules/servers/solusvmpro/solusvmpro.php +++ b/modules/servers/solusvmpro/solusvmpro.php @@ -535,6 +535,8 @@ function solusvmpro_AdminCustomButtonArray() { $_LANG["solusvmpro_reboot"] => "reboot", $_LANG["solusvmpro_shutdown"] => "shutdown", $_LANG["solusvmpro_boot"] => "boot", + $_LANG["solusvmpro_tuntap_enable"] => "tuntap_enable", + $_LANG["solusvmpro_tuntap_disable"] => "tuntap_disable", ); } @@ -545,6 +547,8 @@ function solusvmpro_ClientAreaCustomButtonArray() { $_LANG["solusvmpro_reboot"] => "reboot", $_LANG["solusvmpro_shutdown"] => "shutdown", $_LANG["solusvmpro_boot"] => "boot", + $_LANG["solusvmpro_tuntap_enable"] => "tuntap_enable", + $_LANG["solusvmpro_tuntap_disable"] => "tuntap_disable", ); } @@ -653,6 +657,76 @@ function solusvmpro_shutdown( $params ) { } } +################################################################################ +### TUN/TAP Enable function ### +################################################################################ + +function solusvmpro_tuntap_enable( $params ) { + try { + $solusvm = new SolusVM( $params ); + $customField = $solusvm->getParam( "customfields" ); + + ## The call string for the connection fuction + $callArray = array( "vserverid" => $customField["vserverid"] ); + + $solusvm->apiCall( 'vserver-tun-enable', $callArray ); + + if ( $solusvm->result["status"] == "success" ) { + $result = "success"; + } else { + $result = (string) $solusvm->result["statusmsg"]; + } + + return $result; + } catch ( Exception $e ) { + // Record the error in WHMCS's module log. + logModuleCall( + 'shutdown', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } +} + +################################################################################ +### TUN/TAP Disable function ### +################################################################################ + +function solusvmpro_tuntap_disable( $params ) { + try { + $solusvm = new SolusVM( $params ); + $customField = $solusvm->getParam( "customfields" ); + + ## The call string for the connection fuction + $callArray = array( "vserverid" => $customField["vserverid"] ); + + $solusvm->apiCall( 'vserver-tun-disable', $callArray ); + + if ( $solusvm->result["status"] == "success" ) { + $result = "success"; + } else { + $result = (string) $solusvm->result["statusmsg"]; + } + + return $result; + } catch ( Exception $e ) { + // Record the error in WHMCS's module log. + logModuleCall( + 'shutdown', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } +} + ################################################################################ ### Upgrade / Downgrade account function ### diff --git a/modules/servers/solusvmpro/templates/clientareaBootstrap.tpl b/modules/servers/solusvmpro/templates/clientareaBootstrap.tpl index f6b398a..087d635 100644 --- a/modules/servers/solusvmpro/templates/clientareaBootstrap.tpl +++ b/modules/servers/solusvmpro/templates/clientareaBootstrap.tpl @@ -180,6 +180,18 @@
+ +