Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable TUN-TAP device feature #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/servers/solusvmpro/js/get_user_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ $(function () {
$("#controlpanellink").attr("onclick", "window.open('" + data.controlpanellink + "','_blank')");
}

var optionsIds = ["displayreboot", "displayshutdown", "displayboot", "displayconsole", "displayhtml5console", "displayvnc", "displayrootpassword", "displayhostname", "displayvncpassword", "displayrescuemode", "displaypanelbutton", "displayclientkeyauth"];
var optionsIds = ["displayreboot", "displayshutdown", "displayboot", "displayconsole", "displayhtml5console", "displayvnc", "displayrootpassword", "displayhostname", "displayvncpassword", "displayrescuemode", "displaypanelbutton", "displayclientkeyauth", "displaytunenable", "displaytundisable"];

var showOptions = false;
optionsIds.forEach(function (v) {
if (data.hasOwnProperty(v)) {
Expand Down
4 changes: 2 additions & 2 deletions modules/servers/solusvmpro/lang/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
die( "This file cannot be accessed directly" );
}


$_LANG['solusvmpro_reboot'] = 'Reboot';
$_LANG['solusvmpro_boot'] = 'Boot';
$_LANG['solusvmpro_shutdown'] = 'Shutdown';
Expand Down Expand Up @@ -103,4 +102,5 @@
$_LANG['solusvmpro_port'] = 'Port';
$_LANG['solusvmpro_rescueenabled'] = 'Enabled - Rescue mode can take several minutes before it becomes accessible on the network';
$_LANG['solusvmpro_rescuedisabled'] = 'Disabled - The server is now rebooting into the original system';

$_LANG['solusvmpro_tuntap_enable'] = 'Enable TUN/TAP';
$_LANG['solusvmpro_tuntap_disable'] = 'Disable TUN/TAP';
8 changes: 8 additions & 0 deletions modules/servers/solusvmpro/lib/SolusVM.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,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;
}
Expand Down
74 changes: 74 additions & 0 deletions modules/servers/solusvmpro/solusvmpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,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",
);
}

Expand All @@ -547,6 +549,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",
);
}

Expand Down Expand Up @@ -655,6 +659,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 ###
Expand Down
12 changes: 12 additions & 0 deletions modules/servers/solusvmpro/templates/clientareaBootstrap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@
value="{$LANG.solusvmpro_manage}">
</form>
</span><br/>
<span id="displaytunenable" style="display: none">
<button class="btn btn-default"
onclick="window.location='clientarea.php?action=productdetails&id={$serviceid}&serveraction=custom&a=tuntap_enable'">
{$LANG.solusvmpro_tuntap_enable}
</button>
</span>
<span id="displaytundisable" style="display: none">
<button class="btn btn-default"
onclick="window.location='clientarea.php?action=productdetails&id={$serviceid}&serveraction=custom&a=tuntap_disable'">
{$LANG.solusvmpro_tuntap_disable}
</button>
</span>
</div>
</div>
<div class="row">
Expand Down