<?php

//////////////////////////////////////////////////////////////
//===========================================================
// Rebuild_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.7
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       May 2011
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function rebuild_theme(){

global $theme, $globals, $kernel, $user, $l, $error, $cluster, $servers, $oslist, $done, $vpses, $ostemplates;
global $servers, $isos, $virt, $hvm, $newvs, $vps, $vnc;
global $flag_rebuildvps, $actid, $done_data, $recipes, $webuzo_apps, $allowed_scripts, $webuzo_templates, $custom_cp;

if($flag_rebuildvps){
	echo $actid;
	$flag_rebuildvps = 0;
	
	return false;
}

if(optGET('done')){
		
		$done = $done_data['newvs']['vpsid'];
		$newvs = $done_data['newvs'];
		$vpsname = $done_data['vps']['vps_name'];
		$vnc = $done_data['vnc'];
		$ips = $done_data['vps']['ips'];
		$ipsv6 = $done_data['vps']['ips6'];
		$ipsv6_subnet = $done_data['vps']['ips6_subnet'];
		
		show_alert(__('The Virtual Server has been created. Return to <a href="index.php?act=vs">Virtual Server Overview</a>'));
	echo '<div class="notice mx-3"><b>'.__('Note').' : </b> &nbsp; '.__('The Virtual Server has been created. Return to <a href="index.php?act=vs">Virtual Server Overview</a>').'</div>';
	echo '<div class="card mt-3 mx-3">
	<div class="row mx-auto w-100 my-2">
		<div class="col-sm-12 p-2">
			<div class="row mx-auto w-100">
				<div class="col-sm-4">
					<span class="fhead">'.__('VPS ID').'</span>
				</div>
				<div class="col-sm-8">'.$done.'</div>
			</div>
		</div>
	</div>
	<div class="row mx-auto w-100 my-2">
		<div class="col-sm-12 p-2">
			<div class="row mx-auto w-100">
				<div class="col-sm-4">
					<span class="fhead">'.__('VPS Name').'</span>
				</div>
				<div class="col-sm-8">'.$vpsname.'</div>
			</div>
		</div>
	</div>
	<div class="row mx-auto w-100 my-2">
		<div class="col-sm-12 p-2">
			<div class="row mx-auto w-100">
				<div class="col-sm-4">
					<span class="fhead">'.__('Root Password').'</span>
				</div>
				<div class="col-sm-8" id="newvs_rootpass">'.htmlentities($newvs['pass']).'</div>
			</div>
		</div>
	</div>';

	if(!empty($vnc)){

		echo '<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-2">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('VNC Details').'</span>
					</div>
					<div class="col-sm-8">'.$vnc['ip'].':'.$vnc['port'].'</div>
				</div>
			</div>
		</div>';
	
		if(!empty($vnc['password'])){
			echo '
			<div class="row mx-auto w-100 my-2">
				<div class="col-sm-12 p-2">
					<div class="row mx-auto w-100">
						<div class="col-sm-4">
							<span class="fhead">'.__('VNC Password').'</span>
						</div>
						<div class="col-sm-8">'.$vnc['password'].'</div>
					</div>
				</div>
			</div>';
		}
	}

	echo '
	<div class="row mx-auto w-100 my-2">
		<div class="col-sm-12 p-2">
			<div class="row mx-auto w-100">
				<div class="col-sm-4">
					<span class="fhead">'.__('VPS IPs').'</span>
				</div>
				<div class="col-sm-8">'.implode(', ', $ips).'</div>
			</div>
		</div>
	</div>';

	if(!empty($ipsv6)){

		echo '<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-2">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('VPS IPV6').'</span>
					</div>
					<div class="col-sm-8">'.implode(', ', $ipsv6).'</div>
				</div>
			</div>
		</div>';
	}

	if(!empty($ipsv6_subnet)){
		echo '
		<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-2">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('VPS IPv6 Subnet(s)').'</span>
					</div>
					<div class="col-sm-8">'.implode(', ', $ipsv6_subnet).'</div>
				</div>
			</div>
		</div>';
	}

	echo '</div></div>';
		return true;
}
	
softheader($l['<title>']);

$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_vs', 'lms_rebuild');
					
// page header
echo page_header(__('Rebuild Virtual Server'), 'fas fa-server', '', 0, 0);

error_handle($error);

// Is it offline ?
$hypervisor_status = $cluster->statewise($globals['server']);
if($hypervisor_status == 0 || $hypervisor_status == 2){
	show_alert($globals['hypervisor_status'][$hypervisor_status], "1");

}else{

	if(!empty($done)){
		show_alert(__('The Virtual Server has been created. Return to <a href="index.php?act=vs">Virtual Server Overview</a>'));
	
		echo '<div>
		<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-3">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('VPS ID').'</span>
					</div>
					<div class="col-sm-4">'.$done.'</div>
				</div>
			</div>
		</div>
		<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-3">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('VPS Name').'</span>
					</div>
					<div class="col-sm-4">'.$vps['vps_name'].'</div>
				</div>
			</div>
		</div>
		<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-3">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('Root Password').'</span>
					</div>
					<div class="col-sm-4">'.$vps['pass'].'</div>
				</div>
			</div>
		</div>';
	
		if(!empty($vnc)){
	
			echo '<div class="row mx-auto w-100 my-2">
				<div class="col-sm-12 p-3">
					<div class="row mx-auto w-100">
						<div class="col-sm-4">
							<span class="fhead">'.__('VNC Details').'</span>
						</div>
						<div class="col-sm-4">'.$vnc['ip'].':'.$vnc['port'].'</div>
					</div>
				</div>
			</div>';
		
			if(!empty($vnc['password'])){
				echo '
				<div class="row mx-auto w-100 my-2">
					<div class="col-sm-12 p-3">
						<div class="row mx-auto w-100">
							<div class="col-sm-4">
								<span class="fhead">'.__('VNC Password').'</span>
							</div>
							<div class="col-sm-4">'.$vnc['password'].'</div>
						</div>
					</div>
				</div>';
			}
		}
	
		echo '
		<div class="row mx-auto w-100 my-2">
			<div class="col-sm-12 p-3">
				<div class="row mx-auto w-100">
					<div class="col-sm-4">
						<span class="fhead">'.__('VPS IPs').'</span>
					</div>
					<div class="col-sm-4">'.implode(', ', $vps['ips']).'</div>
				</div>
			</div>
		</div>';
	
		if(!empty($vps['ipv6'])){
	
			echo '<div class="row mx-auto w-100 my-2">
				<div class="col-sm-12 p-3">
					<div class="row mx-auto w-100">
						<div class="col-sm-4">
							<span class="fhead">'.__('VPS IPV6').'</span>
						</div>
						<div class="col-sm-4">'.implode(', ', $vps['ipv6']).'</div>
					</div>
				</div>
			</div>';
	
		}
	
		echo '</div>';	
		
	}else{
		
			echo '<script language="javascript" type="text/javascript">
			
var actid = null;
var progress = 0;
var progress_update = "";
var timer = null;
var newvs_rootpass="";

function copy_password(){
	
	showalert("'.__J('Please copy the password to a safe place').'<br><a id=\"a_newpass_txt\" href=\"javascript:copy($(\'#a_newpass_txt\'),\'a_newpass_txt\')\"><span class=\"copyflare\" style=\"font-size:14px\">"+$("#newpass").val()+"</span></a>" ,"2");
	$("#alert-modal").on("hidden.bs.modal", function (e) {
		return false;
	});
};

function check(){
	var cp = $("#control_panel").val();
	show_webuzo(cp);
};

function show_webuzo(cp){
	if(cp != "webuzo"){
		$("#show_webuzo_tr").hide();
		$("#show_webuzo_tr input[name=webuzo_os]").prop("disabled", true);
		return false;
	}
	
	$("#show_webuzo_tr").show();
	$("#show_webuzo_tr input[name=webuzo_os]").prop("disabled", false);
	ishvm();
}

function webuzo_apps(stack){
	stack = stack || 0;
	
	if($("#stack1").data("demo") === "1"){
		$("#webuzo_stack_tr").hide();
		return;
	}
	$("#webuzo_stack_tr").slideDown("slow");	
	if(stack == \'lamp\'){
		$("#webuzo_webserver_tr").show();
	}else{
		$("#webuzo_webserver_tr").hide();
	}
}

function script_req(sid){
	
	if(sid == 0 || $("#script_isfree").val() > 0){
		return;
	}
	$("#stack1, #stack2, #stack3").prop("checked", false);
	
	processing_symb(1);
	
	if(AJAX("'.$globals['index'].'act=rebuild&api=json&scriptreqid="+sid, "scriptdetails(re, true)")){
		return false;
	}else{
		return true;
	}
};

function scriptdetails(re, scriptreq){
	
	processing_symb();
	var re = $.parseJSON(re);
	scriptreq = scriptreq || false;
	
	if("error" in re){
		showalert(re["error"],"1");
		$("#webuzo_operation").hide();
		$("#webuzo_unsupport").show().text(re["error"]);
	}else{
		$("#webuzo_operation").show();
		$("#webuzo_unsupport").hide().text("");
	}
		
	if("webuzo_apps" in re["webuzo_done"]){
		for(x in re["webuzo_done"]["webuzo_apps"]){
			var id = "webuzo_"+x;
			var str = "";
			var val = re["webuzo_done"]["webuzo_apps"][x];
			str += \'<div class="row mx-auto w-100 my-2 my-0">\';
			for(k in val){
				str += \'<div class="col-4 p-0">\
				<label class="custom-control custom-radio">\
					<input type="radio" class="custom-control-input" name="\'+x+\'" id="serverver_\'+k+\'" value="\'+val[k][\'softname\']+\'">\
					<span class="custom-control-label" for="serverver_\'+k+\'">\'+val[k][\'fullname\']+\'</span>\
				</label></div>\';
			}
			str += \'</div>\';
			
			$("#"+id).html(str);
		}
	}
	
	if("isfree" in re["webuzo_done"]){
		$("#stack2_tr, #stack3_tr").hide();
		$("#stack1").prop("checked", true).data("demo", "1");
		$("#script_isfree").val(1);
	}else{
		$("#stack2_tr, #stack3_tr").show();
		$("#stack1").data("demo", "0");
	}
	
	if(scriptreq == true){
		return;
	}
	
	var options = \'<option value="0">'.__J('None').'</option>\';
	if("allowed_scripts" in re["webuzo_done"]){	
		for(x in re["webuzo_done"][\'allowed_scripts\']){
			options += \'<optgroup label="\'+x+\'">\';
			var val = re["webuzo_done"][\'allowed_scripts\'][x];
			for(k in val){
				options += \'<option value="\'+k+\'">\'+val[k][\'name\']+\'</option>\';
			}
			options += \'</optgroup>\';
		}
	}
}

$(document).ready(function(){
	progress_onload();
	
	$("#vpsid").on("change", function(){
		showtemplates();
		var formatprimary = $("#vpsid").find(":selected").attr("data-format-primary");
		if(formatprimary == 1){
			$("#format_primary_div").show();
		}

		var virt = $("#vpsid").find(":selected").attr("virt");
		
		if(virt == "docker") {
			$(".non-container").hide();
		} else {
			$(".non-container").show();
		}

	});
	
	$("#reos").click(function(){
		showalert("'.__J('Are you sure you want to rebuild VPS ? Warning : Existing data on VPS will be lost permanently.').'" ,"3" ,function(confirm){
			if(confirm == false){
				return false;		
			}else{
				progress = 0;
				var params = $("#rebuildform").serialize();
				newvs_rootpass = $("#newpass").val();
				$.ajax({type: "POST",
					url: "'.$globals['index'].'jsnohf=1&act=rebuild",
					data:params+"&reos=1",
					success:function(response){
						if(!isNaN(response)){
							animate_task("'.__J('Rebuild VPS task started').'");
							gettaskscount();
							actid = response;
							timer = setTimeout("get_progress(\'rebuild\')", 500);
							
						}else{
							gettaskscount();
							setTimeout(function(){
								var parsed_HTML = $(response);
								var error_box = parsed_HTML.filter("#error_box").add(parsed_HTML.find("#error_box"));
								showalert(error_box.html(),"1");
								$("#form-container").show();
								$("#progress-cont").hide();
								error_box.html("");
							} ,200);
						}
					}
				});
				
				$("#error_box").remove();
				$("#form-container").hide();
				$("#progress-cont").show();
				$("#pbar").html("'.__J('Checking submitted data...').'" + " ( 0% ) ");
				window.scrollTo(0, 0);
				$("#progressbar").progressbar({value: 0});
				return false;
			}
		});
	});
});
function setpwd(size){
	var pwd = rand_pass(size);
	$("#newpass").val(pwd);
	$("#conf").val(pwd);
}

function ishvm(){
	
	/*var current_virt = "'.$virt.'";	
	//alert(current_virt)		
	if(current_virt != "xen" && current_virt != "xcp"){
		return false;
	}*/
	
	var vpsid = $_("vpsid").value;
	if(!vpsid){
		return false;
	}
	
	//var hvm = getAttributeByName($_("vps"+vpsid), "hvm");
	var hvm = $("#vps" + vpsid).attr("hvm");
	//alert(vpsid + " -- " + hvm)
	
	for(var i=0; i<$_("osid").options.length; i++){
		if($_("osid").options[i].value < 1) continue;
		
		if(getAttributeByName($_("osid").options[i], "hvm") == 1 && hvm == true){
			$_("osid").options[i].disabled = false;
		}else if(getAttributeByName($_("osid").options[i], "hvm") != 1 && hvm == false){
			$_("osid").options[i].style.display = "";
		}else{
			$_("osid").options[i].style.display = "none";
		}
	}
	return false;
};

var lang = Array();
lang["bad"] = "'.__J('Bad').'";
lang["good"] = "'.__J('Good').'";
lang["strong"] = "'.__J('Strong').'";
lang["short"] = "'.__J('Short').'";
lang["strength_indicator"] = "'.__J('Strength Indicator').'";

// Match the passwords
function pass_match(){
	var newpass = $("#newpass").val();
	var conf = $("#conf").val();
	if(newpass != conf){
		$("#message").text("'.__J('Passwords do not match').'");
		$("#message").css("color", "red");
	}else{
		$("#message").text("");
	}
}

// Show the templates
function showtemplates(){
	
	var vpsid= $("#vpsid").val();
	var Virt = $("#vps"+vpsid).attr("virt");
	
	$("#osid").select2("destroy");
	$("#osid").select2({
		width:"100%",
		templateResult: function(option) {
			var myOption = $("#osid").find("option[value=\"" + option.id + "\"]");
			if ((myOption.attr("virt") != "undefined") && (myOption.attr("virt") == Virt)) {
				return option.text;
			}
		}
	});
}

function toggle_opts(ele){
	var nav = $(ele);
	var role = nav.attr("role");
	//alert(role);
	
	$("[show]").each(function(i, e){
		if($(e).is("[show="+role+"]")){
			$(e).show();
		}else{
			$(e).hide();
		}
	});	
}

addonload("check_pass_strength();");					
</script>
	<div id="form-container" class="form-horizontal">
		<form id="rebuildform" accept-charset="'.$globals['charset'].'" action="" method="post" name="rebuild" class="form-horizontal">

			<div class="row mx-auto w-100 my-3">

				<!--------------- General Settings ----------------->
				<div id="general_settings1" class="col-sm-12 col-md-12 col-lg-6">

					<div class="roundheader cursor-pointer">
						'.__('General').'
					</div>

					<div id="general_options" class="bgaddv w-100">

						<div class="w-100 mb-3 px-2">
							<label class="control-label">'.__('Server').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Change the current server to change the server').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							<select id="server-select" class="form-select server-select">';	
								foreach($servers as $k => $v) {
									echo '<option value="'.$k.'" data-icon="'.$theme['images'].'admin/'.$v['virt'].'_28.png" '.($k == $globals['server'] ? 'selected' : '').'><span><img src="'.$theme['images'].'admin/'.$v['virt'].'_28.png" class="mb-1"/>'.$v['server_name'].' ('.$v['ip'].')'.($v['locked'] == 0 ? '' : ' (Locked)').'</span></option>';
								}
							
							echo '</select>
						</div>

						';

						if(count($servers[$globals['server']]['virts']) < 1){
							echo '
							<div class="w-100 mb-3 px-2">
								<label class="control-label">'.__('Select Virtualization').'<a class="info" data-placement="right" tooltip="'.__('The Virtualizationn technology of the VPS to be created.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<select class="form-select" name="virt" onchange="loadvirt(this.value)">';
									foreach($servers[$globals['server']]['virts'] as $k => $v){		 
										echo '<option value="'.$v.'" '.(REQval('virt') == $v ? 'selected="selected"' : '').'>'.$globals['virt_names'][$v].'</option>';
									}
								
								echo '
								</select>
							</div>';	
						}

						echo'

						<div class="w-100 mb-3 px-2">
							<label class="control-label">'.__('VPS ID').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Select an existing VPS ID').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							<select name="vpsid" id="vpsid" class="form-select virt-select">
									<option value="0" '.(POSTval('vpsid')== 0 ? 'selected="selected"' :($vps['vps_name'] == 0 ? 'selected="selected"' : '')).'>'.__('Select VPS').'</option>';	
										
								foreach($vpses as $k => $v){
									$format_primary = $kernel->features('format_primary', $v['virt']);
									$format_primary = 'data-format-primary="'.((!empty($format_primary) && $v['virt'] != 'docker') ? 1 : 0).'"';
									echo '<option value="'.$k.'" '.(POSTval('vpsid') == $k ? 'selected="selected"' : ($vps['vpsid'] == $k ? 'selected="selected"' : '')).' hvm="'.$v['hvm'].'" id="vps'.$k.'" virt="'.$v['virt'].(!empty($v['hvm']) ? 'hvm' : '').'" '.$format_primary.'>'.$v['vps_name'].'  -  '.$v['hostname'].'</option>';
								}
								
							echo '</select>
						</div>

						<div class="w-100 mb-3 px-2 non-container">
							<label class="control-label">'.__('Operating System').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Select the Operating System for the VPS').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							<select class="form-select virt-select" id="osid" name="osid">
									<option value="0" '.(POSTval('osid')== 0 ?  'selected="selected"' :($vps['osid']== 0 ? 'selected="selected"' : '')).'>'.__('Select OS').'</option>';
									if(!empty($ostemplates)){
										foreach($ostemplates as $k => $v){
											// Does this server support this $_virt ?
											if(server_virt($globals['server'], $v['type']) != $v['type']){
												continue;
											}							
											echo '<option value="'.$k.'" '.(POSTval('osid') == $k ? 'selected="selected"' : ($vps['osid'] == $k ? 'selected="selected"' : '')).' '.(!empty($v['hvm']) ? 'hvm="1"' : '').' virt="'.$v['type'].(!empty($v['hvm']) ? 'hvm' : '').'">'.(!empty($v['hvm']) ? 'HVM - ' : '').''.$v['name'].is_custom_os($k).'</option>';
										}
									}
							echo'
							</select>
						</div>
						
						<div class="w-100 mb-3 px-2 non-container">
							<label class="control-label">'.__('New Password').'&nbsp;</label>
							<div class="input-group ">
								<input type="password" class="form-control" name="newpass" onkeyup="check_pass_strength(this.id);" id="newpass" size="30" value="" />
								<div class="input-group-append">
									<a href="javascript:void(0);" onclick="setpwd(12);check_pass_strength(\'newpass\');pass_match();copy_password();return false;" title="'.__('Make another Random Password').'" class="btn-primary rounded-right"><i class="fas fa-key p-2"></i></a>
								</div>
							</div>
							<div id="newpass_pass-strength-result" class="w-100">'.__('Strength Indicator').'</div>
						</div>

						<div class="w-100 mb-3 px-2 non-container">
							<label class="control-label">'.__('Retype Password').'&nbsp;</label>
							<input type="password" class="form-control" onblur="pass_match();" name="conf" id="conf" size="30" value="" /><div id="message"></div>
						</div>


					</div>

				</div>

				<!--------------- Advanced Settings ----------------->

				<div id="advanced_settings1" class="col-sm-12 col-md-12 col-lg-6">

					<div class="roundheader cursor-pointer">
						'.__('Advanced').'
					</div>

					<div id="advanced_options" class="bgaddv w-100">

						<div class="w-100 mb-3 px-2 non-container">
							<label class="control-label">'.__('Recipe').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Select the recipe to be executed inside the VPS after creation').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							<select class="form-select virt-select" name="recipe[]" id="recipe" multiple="multiple">
								<option value="0" '.POSTselect('recipe', 'none').'>None</option>';
								
								foreach($recipes as $k => $v){
									echo '<option value="'.$k.'" '.POSTselect('recipe', $k).'>'.$v['name'].'</option>';
								}
								
							echo '
							</select>
						</div>

						<div class="w-100 mb-3 px-2 non-container">
							<label class="control-label">'.__('Web Control Panel').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('This option will install selected web control panel in the VPS').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							<select class="custom-select" name="control_panel" id="control_panel" onchange="show_webuzo(this.value); check();">
								<option value="0" '.POSTselect('control_panel', 'none').'>None</option>
								<option value="webuzo" '.POSTselect('control_panel', 'webuzo').'>Webuzo</option>
								<option value="plesk" '.POSTselect('control_panel', 'plesk').'>Plesk</option>
								<option value="cpanel" '.POSTselect('control_panel', 'cpanel').'>cPanel</option>
								<option value="webmin" '.POSTselect('control_panel', 'webmin').'>Webmin</option>
								<option value="interworx" '.POSTselect('control_panel', 'interworx').'>Interworx</option>
								<option value="ispconfig" '.POSTselect('control_panel', 'ispconfig').'>ISPConfig</option>
								<option value="cwp" '.POSTselect('control_panel', 'cwp').'>CentOS Web Panel</option>
								<option value="vesta" '.POSTselect('control_panel', 'vesta').'>VestaCP</option>';
								if(!empty($custom_cp)){
									foreach($custom_cp as $k => $v){
										echo '<option value="virt_'.$v.'" '.POSTselect('control_panel', 'virt_'.$v).'>'.$v.'</option>';
									}
								}
								echo ';
							</select>
						</div>

						<div class="w-100 mb-3 px-2" id="show_webuzo_tr" style="display:none;">
							<div class="col-sm-12 p-2 border rounded">
								<div id="webuzo_content" class="py-2 px-1">
									<span class="help-block">'.__('Rebuild VPS with Applications').'</span><br />

									<div class="row mx-auto w-100 my-3">
										<label class="control-label">'.__('Primary Domain').'</label><br />
										<input class="form-control" type="textbox" name="webuzo_pd" id="webuzo_pd" placeholder="'.__('example.com').'" value="'.POSTval('webuzo_pd', '').'">	
									</div>

									<div class="row mx-auto w-100 my-3">
										<label class="control-label">'.__('Root Password').'</label><br />
										<div class="input-group ">
											<input class="form-control" type="text" name="webuzo_spasswd" id="webuzo_spasswd" onkeyup="check_pass_strength(\'webuzo_spasswd\');"  placeholder="'.__('Enter Root Password').'" 
											value="'.POSTval('webuzo_spasswd', '').'" autocomplete="off">
											<div class="input-group-append">
												<a href="javascript: void(0);" onclick="$_(\'webuzo_spasswd\').value=randstr(12, 1, '.(!empty($globals['pass_strength']) ? $globals['pass_strength'] : 0).');check_pass_strength(\'webuzo_spasswd\');return false;" class="btn-primary rounded-right" title="'.__('Make another Random Password').'"><i class="fas fa-key p-2"></i></a>
											</div>
										</div>
										<div id="webuzo_spasswd_pass-strength-result" class="w-100">
											'.__('Strength Indicator').'
										</div>
									</div>

									<div class="row mx-auto w-100 my-3">
										<label class="control-label">'.__('Select a script').'</label><br />';
										echo'
										<select id="webuzo_scriptlist" class="custom-select virt-select" onchange="script_req(this.value);" name="webuzo_script">
										<option value="0">'.__('None').'</option>';
										foreach($allowed_scripts as $k => $v){
											echo '<optgroup label="'.$k.'">';
											$val = $v;
											foreach($val as $vk => $vv){
												echo '<option value="'.$vk.'">'.$vv['name'].'</option>';
											}
											echo '</optgroup>';
										}
										echo ';
										</select>
									</div>

									<div class="row mx-auto w-100 my-3">
										<div class="col-sm-12 px-2">
											<label class="control-label">'.__('Select OS').'</label><br />
											<div class="row mx-auto w-100 form-group r-pill r-pill-bg">
												';foreach($webuzo_templates as $k => $v){
													echo '
													<div class="col-lg-6 col-md-4 col-12 px-2 my-1">
														<span class="r-pill__item">
															<input for="input radio" type="radio" class="custom-control-input" name="webuzo_os" id="webuzoos_'.$k.'" value="'.$k.'" '.(!empty($v['hvm']) ? 'hvm="1"' : '').' distro="'.$v['distro'].'">
															<label for="freq" class="m-0" for="webuzoos_'.$k.'">'.$v['name'].'</label>
														</span>
													</div>
													';
												}echo '
											</div>
										</div>
									</div>

									<div class="row mx-auto w-100 my-3">
										<div class="col-sm-12 px-2">
											<label class="control-label">'.__('Choose Stack').'</label><br />
											<div class="row mx-auto w-100 form-group r-pill r-pill-bg">
												<div class="col-3 px-2 my-1" id="stack1_tr">
													<span class="r-pill__item">
														<input type="radio" class="custom-control-input" name="webuzo_stack" id="stack1" value="lamp" onclick="webuzo_apps(this.value);" checked="checked">
														<label for="freq" class="m-0" for="stack1">LAMP</label>
													</span>
												</div>
												<div class="col-3 px-2 my-1" id="stack2_tr" style="display:'.(!empty($webuzo_done['isfree']) ? 'none' : '').';"> 
													<span class="r-pill__item">
														<input type="radio" class="custom-control-input" name="webuzo_stack" id="stack2" value="lemp" onclick="webuzo_apps(this.value);">
														<label for="freq" class="m-0" for="stack2">LEMP</label>
													</span>
												</div>
												<div class="col-3 px-2 my-1" id="stack3_tr" style="display:'.(!empty($webuzo_done['isfree']) ? 'none' : '').';">
													<span class="r-pill__item">
														<input type="radio" class="custom-control-input" name="webuzo_stack" id="stack3" value="llmp" onclick="webuzo_apps(this.value);">
														<label for="freq" class="m-0" for="stack3">LLMP</label>
													</span>
												</div>
											</div>
										</div>
									</div>

									<div id="webuzo_stack_tr" style="display:'.(!empty($webuzo_done['isfree']) ? 'none' : '').';">
										<input type="hidden" id="script_isfree" value="0" />
										<div class="row mx-auto w-100 my-3" id="webuzo_webserver_tr">
											<div class="col-sm-12 px-2">
												<label class="control-label">'.__('Select Apache Verison').'</label><br />
												<div id="webuzo_webserver">
													<div class="row mx-auto w-100 form-group r-pill r-pill-bg">';
													foreach($webuzo_apps['webserver'] as $wk => $wv){
													echo '
														<div class="col-lg-3 col-md-3 col-6 px-2 my-1">	
															<span class="r-pill__item">
																<input type="radio" class="custom-control-input" name="webserver" id="serverver_'.$wk.'" value="'.$wv['softname'].'">
																<label for="freq" class="m-0" for="serverver_'.$wk.'">'.$wv['fullname'].'</label>
															</span>				
														</div>';
													}
												echo '</div>
												</div>
											</div>
										</div>

										<div class="row mx-auto w-100 my-3">
											<div class="col-sm-12 px-2">
												<label class="control-label">'.__('Select MYSQL Version').'</label>
												<div id="webuzo_mysql">
													<div class="row mx-auto w-100 form-group r-pill r-pill-bg">';
													foreach($webuzo_apps['mysql'] as $wk => $wv){
														echo '
													<div class="col-lg-3 col-md-3 col-6 px-2 my-1">	
														<span class="r-pill__item">
															<input type="radio" class="custom-control-input" name="mysql" id="serverver_'.$wk.'" value="'.$wv['softname'].'">
															<label for="freq" class="m-0" for="serverver_'.$wk.'">'.$wv['fullname'].'</label>
														</span>			
													</div>';
													}
												echo '</div>
												</div>	
											</div>	
										</div>

										<div class="row mx-auto w-100 my-3">
											<div class="col-sm-12 px-2">
												<label class="control-label">'.__('Select PHP Version').'</label>
												<div id="webuzo_php">
													<div class="row mx-auto w-100 form-group r-pill r-pill-bg">';
													foreach($webuzo_apps['php'] as $wk => $wv){
														echo '
														<div class="col-lg-3 col-md-3 col-6 px-2 my-1">
															<span class="r-pill__item">
																<input type="radio" class="custom-control-input" name="php" id="serverver_'.$wk.'" value="'.$wv['softname'].'">
																<label for="freq" class="m-0" for="serverver_'.$wk.'">'.$wv['fullname'].'</label>
															</span>			
														</div>';
													}
												echo '</div>
												</div>
											</div>	
										</div>

									</div>
								</div>
							</div>
						</div>

						<div class="row w-100 mx-0 mb-3 px-2 format_primary_div" id="format_primary_div" style="display:none">
							<div class="col-8 px-0">
								<label class="control-label">'.__('Format only Primary Disk').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If this box is checked then only primary disk will be formatted of the OS. Other disks remains as it is.(Supported only for VPS(s) on KVM, PROXMOX KVM and XEN HVM)').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							</div>
							<div class="col-4">
								'.get_checkbox('format_primary', '', 'format_primary').'
							</div>
						</div>

						<div class="row w-100 mx-0 mb-3 px-2 non-container">
							<div class="col-8 px-0">
								<label class="control-label">'.__('Remove old SSH Keys').'&nbsp;
									<a class="info" data-placement="right" tooltip="'.__('If checked then old ssh-keys will be removed from the VPS').'">
										<i class="fas text-primary fa-info-circle"></i>
									</a>
								</label>
							</div>
							<div class="col-4">
								'.get_checkbox('remove_old_ssh_keys', '', 'remove_old_ssh_keys').'
							</div>
						</div>

						<div class="row w-100 mx-0 mb-3 px-2">
							<div class="col-8 px-0">
								<label class="control-label">'.__('Notify user').'&nbsp;
									<a class="info" data-placement="right" tooltip="'.__('If checked, an email will be sent to the VPS user after the VPS is rebuilt').'">
										<i class="fas text-primary fa-info-circle"></i>
									</a>
								</label>
							</div>
							<div class="col-4">
								'.get_checkbox('eu_send_rebuild_email', '', 'eu_send_rebuild_email', array('chk_it' => 1, 'val' => 1)).'
							</div>
						</div>

						<div class="w-100 mb-3 px-2 non-container">
							<label class="control-label">'.__('Add SSH key').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Add public key in VPS.<br>NOTE : This key will not be saved.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
							<textarea class="form-control font-monospace w-100" name="sshkey" rows="8">'.POSTval('sshkey', '').'</textarea>
						</div>

						<div class="notice" align="left">
							<b>'.__('Note').' : </b> &nbsp; '.__('Primary disk formatting is supported only for VPS(s) on KVM, PROXMOX KVM and XEN HVM Host nodes').'
						</div>

					</div>
				</div>

			</div>
			
			<center>
				<input type="button" class="go_btn mt-3" name="reos"  id="reos" value="'.__('Reinstall').'"/>
			</center>';
			echo 
			'
		</form>
	</div>';
	}

}// End of Server Offline if	


echo '<div id="processing_symb">
		<div class="loader-lg"></div></div><div id="progress_onload">
		</div>
	</div>';

softfooter();

}

?>