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

Add Rebuild v-server to clientarea #42

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions modules/servers/solusvmpro/lang/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
$_LANG['solusvmpro_used'] = 'Used';
$_LANG['solusvmpro_free'] = 'Free';
$_LANG['solusvmpro_status'] = 'Status';
$_LANG['solusvmpro_rebuild'] = 'Rebuild Os';
$_LANG['solusvmpro_submit_rebuild'] = 'Submit Rebuild Os';
$_LANG['solusvmpro_ipAddress'] = 'IP Address';
$_LANG['solusvmpro_unavailable'] = 'Unavailable';
$_LANG['solusvmpro_VSC'] = 'Virtual Server Control';
Expand Down
73 changes: 73 additions & 0 deletions modules/servers/solusvmpro/solusvmpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,43 @@ function solusvmpro_Custom_ChangeVNCPassword( $params = '' ) {

}

function mf_solusvmpro_RebuildVirtualServer( $params, $os ) {
global $_LANG;

try {
$solusvm = new SolusVM( $params );
$customField = $solusvm->getParam( "customfields" );

## The call string for the connection fuction
$callArray = array(
"vserverid" => $customField["vserverid"],
"template" => $os,
);

$solusvm->apiCall( 'vserver-rebuild', $callArray );

if ( $solusvm->isSuccessResponse($solusvm->result) ) {
$result = "success";
} else {
$result = (string) $solusvm->result["statusmsg"];
}

return $result;
} catch ( Exception $e ) {
// Record the error in WHMCS's module log.
logModuleCall(
'rebuild',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);

return $e->getMessage();
}

}

function solusvmpro_ClientArea( $params ) {
$notCustomFuntions = [ 'reboot', 'shutdown', 'boot' ];
if ( isset( $_GET['modop'] ) && ( $_GET['modop'] == 'custom' ) ) {
Expand Down Expand Up @@ -1116,10 +1153,46 @@ function solusvmpro_ClientArea( $params ) {
}
}
} else {

$rebuild = false;
if (isset($_POST['change_os']) && isset($_POST['vserver_templates'])){
$os = $_POST['vserver_templates'];
$rebuild = mf_solusvmpro_RebuildVirtualServer($params, $os);
}

#--------------- get templates
$packageconfigoption = initConfigOption();
$vt = '';
if ( $packageconfigoption[5] == "OpenVZ" ) {
$vt = "openvz";
} elseif ( $packageconfigoption[5] == "Xen-PV" ) {
$vt = "xen";
} elseif ( $packageconfigoption[5] == "Xen-HVM" ) {
$vt = "xen hvm";
} elseif ( $packageconfigoption[5] == "KVM" ) {
$vt = "kvm";
}
$callArray = array( "type" => $vt );
## List templates
$solusvm->apiCall( 'listtemplates', $callArray );

if ( $solusvm->isSuccessResponse($solusvm->result) ) {
$default_template = $solusvm->result["templates"];
} else {
$default_template = $solusvm->rawResult;
}
$default_template = explode(',', $default_template);
#--------------- get templates

$data = array(
'vserverid' => $customField["vserverid"],
'templates' => $default_template,
);

if($rebuild !== false){
$data['rebuild_os'] = $rebuild;
}

return array(
'templatefile' => 'templates/clientareaBootstrap.tpl',
'vars' => array(
Expand Down
13 changes: 13 additions & 0 deletions modules/servers/solusvmpro/templates/clientareaBootstrap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@
<div class="col-md-9" id="displayState">
{$LANG.solusvmpro_loading}
</div>
<div class="col-md-3">
{$LANG.solusvmpro_rebuild}
</div>
<div class="col-md-9">
<form action="#" method="post">
<select name="vserver_templates">
{foreach $data.templates as $item}
<option value="{$item}">{$item}</option>
{/foreach}
<input type="submit" name="change_os" class="btn btn-primary margin-left-5" value="{$LANG.solusvmpro_submit_rebuild}">
</select>
</form>
</div>
<div class="col-md-9" id="displayStateUnavailable" style="display: none">
<strong>{$LANG.solusvmpro_unavailable}</strong>
</div>
Expand Down