    <!-- 破解密码 -->
    <div class="modal fade" id="ModuleCrack" tabindex="-1" role="dialog" aria-labelledby="ModuleCrack" aria-hidden="false" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content panel panel-primary">
                <div id="modalModuleCrackHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">{$zjmf_layer_close}</span>
                    </button>
                    <h4 class="modal-title">{$zjmf_api_crackpass}</h4>
                </div>
                <div class="modal-body panel-body">
                    <div class="margin-top-bottom-20 text-center">
                        <div class="form-group row" style="width: 100%;float: left;">
                            <div class="col-xs-12 col-md-4">
                                <select name="password_type" class="form-control">
                                    <option value="0">{$zjmf_layer_content_password}</option>
                                    <option value="1">{$zjmf_ssh_key}</option>
                                </select> 
                            </div>
                            <div class="col-xs-12 col-md-8">
                                <div class="use_password">
                                    <input class="form-control" style="box-shadow:none" type="text" name="new_pass" value=""> 
                                    <img src="/modules/servers/zjmfcloud/templates/server_innerpage/image/random.svg" alt="" class="creakInputRandom" style="width: 18px; cursor: pointer;top: -25px;right: 10px;float: right;position: relative;">
                                </div>
                                <div class="use_ssh_key" style="display: none;">
                                    <select name="ssh_key_id" class="form-control">
                                        {$ssh_key_list}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>            
                    </div>
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary modal_confirm" style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                        {$zjmf_layer_confirm}
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                        {$zjmf_layer_cancel}
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!-- 重装系统 -->
    <div class="modal fade" id="ModuleReinstall" tabindex="-1" role="dialog" aria-labelledby="ModuleReinstall" aria-hidden="false" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content panel panel-primary">
                <div id="modalModuleReinstallHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">{$zjmf_layer_close}</span>
                    </button>
                    <h4 class="modal-title">{$zjmf_api_reinstall}</h4>
                </div>
                <div class="modal-body panel-body">
                    <div class="margin-top-bottom-20 text-center">
                        <div class="form-group row" style="width: 100%;float: left;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;"><span style="color:red;">*</span>{$zjmf_layer_content_os}</label>
                            <div class="col-xs-12 col-md-3" id="os_group">
                                <select name="os_group" class="form-control">
                                    {$os_group}
                                </select> 
                            </div>
							<div class="col-xs-12 col-md-6">
                                <select name="os" class="form-control">
                                    
                                </select> 
                            </div>
                        </div>
                        <div class="form-group row" style="width: 100%;float: left;">
                            <div class="col-xs-12 col-md-3 form-control-label">
                                <select name="password_type" class="form-control">
                                    <option value="0">{$zjmf_layer_content_password}</option>
                                    <option value="1">{$zjmf_ssh_key}</option>
                                </select> 
                            </div>
                            <div class="col-xs-12 col-md-9">
                                <div class="use_password">
                                    <input class="form-control" style="box-shadow:none" type="text" name="new_pass" value=""> 
								    <img src="/modules/servers/zjmfcloud/templates/server_innerpage/image/random.svg" alt="" class="creakInputRandom" style="width: 18px; cursor: pointer;top: -25px;right: 10px;float: right;position: relative;">
                                </div>
                                <div class="use_ssh_key" style="display: none;">
                                    <select name="ssh_key_id" class="form-control">
                                        {$ssh_key_list}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>            
                    </div>
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary modal_confirm" style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                        {$zjmf_layer_confirm}
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                        {$zjmf_layer_cancel}
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!-- 救援系统 -->
    <div class="modal fade" id="ModuleRescue" tabindex="-1" role="dialog" aria-labelledby="ModuleRescue" aria-hidden="false" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content panel panel-primary">
                <div id="modalModuleRescueHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">{$zjmf_layer_close}</span>
                    </button>
                    <h4 class="modal-title">{$zjmf_api_rescue}</h4>
                </div>
                <div class="modal-body panel-body">
                    <div class="margin-top-bottom-20 text-center">
                        <div class="form-group row" style="width: 100%;float: left;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;"><span style="color:red;">*</span>{$zjmf_layer_rescue_type}</label>
                            <div class="col-xs-12 col-md-9">
                                <select name="type" class="form-control">
                                    <option value="1">Windows(中文版)</option>
                                    <option value="2">Linux</option>
                                    <option value="3">Windows(English)</option>
                                </select> 
                            </div>
                        </div>
                        <div class="form-group row" style="width: 100%;float: left;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;"><span style="color:red;">*</span>{$zjmf_layer_temp_pass}</label>
                            <div class="col-xs-12 col-md-9">
                                <input class="form-control" style="box-shadow:none" type="text" name="new_pass" value=""> 
                                <img src="/modules/servers/zjmfcloud/templates/server_innerpage/image/random.svg" alt="" class="creakInputRandom" style="width: 18px; cursor: pointer;top: -25px;right: 10px;float: right;position: relative;">
                            </div>
                        </div>
                        <div class="form-group row" style="width: 100%;float: left;">
                            <div class="col-xs-12 col-md-3 form-control-label"></div>
                            <div class="col-xs-12 col-md-9" style="text-align: left;
                                color: #f56c6c;
                                margin-top: -20px;
                                background-color: #fef0f0;
                                border: 1px solid #fde2e2;
                                padding: 10px;">
                                <span>{$zjmf_onetime_password_please_save}</span>
                            </div>
                        </div>
                        <div class="form-group row" style="width: 100%;float: left;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;"><span style="color:red;">*</span>{$zjmf_clients_repassword_4}</label>
                            <div class="col-xs-12 col-md-9" style="text-align: left;line-height: 30px;">
                                <input type="checkbox" /> &nbsp;&nbsp;{$zjmf_clients_repassword_5}
                            </div>
                        </div>

                        <div class="clearfix"></div>            
                    </div>
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary modal_confirm" style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                        {$zjmf_layer_confirm}
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                        {$zjmf_layer_cancel}
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
    	var hostid = "{$hostid}";
    	var zjmfcloud_power_status = "{$zjmfcloud_power_status}";
        var vnc_window;
        var base_url = "clientsservices.php?userid={$user_id}&id={$serviceid}";
        var cloud_rescue_status = "{$cloud_rescue_status}"

        $(function(){
            if(hostid){
                $("#modcmdbtns").find("button").eq(0).hide();
            }
            var remote_image_group_id = "{$remote_image_group_id}"
            if(remote_image_group_id != 1){
                $('#ModuleRescue select[name="type"]').find('option').eq(1).attr('selected', 'selected');
            }

			//挂起状态
			if(zjmfcloud_power_status=="paused"){
				$("#modcmdbtns").find("button").eq(6).hide();
				$("#modcmdbtns").find("button").eq(7).hide();
				$("#modcmdbtns").find("button").eq(8).hide();
				$("#modcmdbtns").find("button").eq(10).hide();
				$("#modcmdbtns").find("button").eq(11).hide();
				$("#modcmdbtns").find("button").eq(12).hide();
                $("#modcmdbtns").find("button").eq(13).hide();
				$("#modcmdbtns").find("button").eq(14).hide();
			}
			//操作系统
			var os={$os};
			var os_group_id=$('select[name="os_group"]').val();
			$.each(os,function(i,v){
				if(!os_group_id){
					$('select[name="os"]').append('<option value='+v.id+'>'+v.name+'</option>');
				}else if(v.group==os_group_id){
					$('select[name="os"]').append('<option value='+v.id+'>'+v.name+'</option>');
				}
			});
			$('select[name="os_group"]').change(function(){
				var os_group_id=$('select[name="os_group"]').val();
				$('select[name="os"]').html("");
				$.each(os,function(i,v){
					if(v.group==os_group_id){
						$('select[name="os"]').append('<option value='+v.id+'>'+v.name+'</option>');
					}
				});
			}); 
			if(!os_group_id){
				$("#os_group").hide();
			}
            // 去掉默认点击事件
            $("#btnreinstall").html("{$zjmf_api_reinstall}").removeAttr("onclick")
            $("#btncrackpass").html("{$zjmf_api_crackpass}").removeAttr("onclick")

            if(cloud_rescue_status == 0){
                $("#btnrescue").html("{$zjmf_api_rescue}").removeAttr("onclick")
            }else{
                $("#btnrescue").html("{$zjmf_api_rescue_exit}").removeAttr("onclick")
            }
            $("#btnvnc").html("vnc").removeAttr("onclick")
            $('#btnpanel').html("{$zjmf_api_panel}").removeAttr("onclick");

            $('#btnreinstall').on('click', function(){
                $('#ModuleReinstall').modal('show');
				creatCode($('#ModuleReinstall .creakInputRandom'));
            })

            // 破解密码
            $('#btncrackpass').on('click', function(){
            	$('#ModuleCrack').modal('show')
            })
			//随机密码
			
			$(".creakInputRandom").click(function(){
				creatCode($(this));
			});
			function creatCode(obj){
				let crackRePwd = '' // 存放验证码
				const codeLength = parseInt(9) // 设置验证码长度为6
				const codeChars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
                // 大小写字母数字
                crackRePwd += codeChars[ Math.max(36, Math.floor(Math.random() * 61)) ]
                crackRePwd += codeChars[ Math.max(10, Math.floor(Math.random() * 35)) ]
                crackRePwd += codeChars[ Math.floor(Math.random() * 9) ]
				for (let i = 0; i < codeLength; i++) {
					const charIndex = Math.floor(Math.random() * 52)
					crackRePwd += codeChars[charIndex]
				}
				const codeReg = /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d).*$/
				var re = new RegExp(codeReg)
				obj.parent().find('input[name="new_pass"]').val(crackRePwd);
			}
            // vnc
            $("#btnvnc").on("click", function(){
	            var _this = $(this),
	                old_desc = $(this).text()
	            if(!_this.data('submit')){
	                $(this).html('{$zjmf_check_vnc_loading}');
	                $(this).data('submit', 'submit')
	                
	                $.post(base_url, {'zjmfcloud_method':'vnc'}, function(res){
	                	_this.data('submit', '')
	                	_this.html('vnc')
	                	if(res.status == 'success'){
							if(res.data.url){
								var vnc_url =res.data.url;
                            }else{
								var vnc_url = base_url + '&zjmfcloud_method=vnc_page&token=' + res.data.token + '&pass=' + res.data.vnc_pass;
                                if(typeof res.data.path != 'undefined'){
                                    vnc_url += '&path=' + res.data.path;
                                }
                            }
	                		vnc_window = window.open(vnc_url, '', 'height=800,width=1024,toolbar=no,location=no,scrollbars=yes,left=180,top=100');
	                	}else{
	                		alert(res.msg);
	                	}
	                }, 'json')
	            }
	        })

            // 管理面板
            $('#btnpanel').on('click', function(){
                var url = "{$api_url}/#/cloudsHome?id=" + hostid;
                window.open(url);
            })

            $('#ModuleCrack .modal_confirm').on('click', function(){
                var _this = $(this),
                    new_pass = $('#ModuleCrack input[name="new_pass"]').val();
                    password_type = $('#ModuleCrack select[name="password_type"]').val();
                    ssh_key_id = $('#ModuleCrack select[name="ssh_key_id"]').val();
                if(password_type == 0 && !new_pass){
                    alert('{$zjmf_check_password}')
                    return;
                }else if(password_type == 1 && !ssh_key_id){
                    alert('{$zjmf_please_select_ssh_key}')
                    return;
                }

                if(!_this.data('submit')){
                    $(this).data('submit', 'submit')
                    _this.text("{$zjmf_api_crackpass}...");
                    $.post(base_url, {'zjmfcloud_method':'crack_pass', 'new_pass': new_pass, 'password_type': password_type, 'ssh_key_id': ssh_key_id }, function(res){
                        _this.data('submit', '')
                        if(res.status == 'success'){
                            $('#ModuleCrack').modal('hide')
                            alert(res.msg)
                        }else{
                            alert(res.msg);
                        }
						_this.text("{$zjmf_layer_confirm}");
						window.location.reload();
                    }, 'json')
                }
            })

            $('#ModuleReinstall .modal_confirm').on('click', function(){
                var _this = $(this),
                    new_pass = $('#ModuleReinstall input[name="new_pass"]').val(),
                    password_type = $('#ModuleReinstall select[name="password_type"]').val(),
                    ssh_key_id = $('#ModuleReinstall select[name="ssh_key_id"]').val(),
                    os = $('#ModuleReinstall select[name="os"]').val();
                if(password_type == 0 && !new_pass){
                    alert('{$zjmf_check_password}')
                    return;
                }else if(password_type == 1 && !ssh_key_id){
                    alert('{$zjmf_please_select_ssh_key}')
                    return;
                }
                if(!os){
                    alert('{$zjmf_check_os}')
                    return;
                }
                if(!_this.data('submit')){
                    $(this).data('submit', 'submit')
                    
					_this.text("{$zjmf_api_reinstall}...");
                    $.post(base_url, {'zjmfcloud_method':'reinstall', 'os': os, 'new_pass': new_pass, 'password_type': password_type, 'ssh_key_id': ssh_key_id }, function(res){
                        _this.data('submit', '')
                        if(res.status == 'success'){
                            $('#ModuleReinstall').modal('hide')
                            alert(res.msg);
                        }else{
                            alert(res.msg);
                        }
						_this.text("{$zjmf_layer_confirm}");
						window.location.reload();
                    }, 'json')
                }
            })
			//获取电源状态
            var pre_status = '';
            var pre_task = '';
			var ajaxPowerStatus = setInterval(function() {
				get_cloud_status();
			},5000);

            get_cloud_status();
			setTimeout(function(){
				clearInterval(ajaxPowerStatus);
			},180000);	

            function get_cloud_status(){
                $.get(base_url, {'zjmfcloud_method':'powerStatus'}, function(res){
                    if(res.status == 'success'){
                        if(pre_status == 'process' && res.data.status != 'process'){
                            if(pre_task == 'rescue' || pre_task == 'close_rescue'){
                                window.location.reload()   
                            }
                        }
                        pre_status = res.data.status
                        pre_task = res.data.task
                        $("#powerStatus").html(res.data.des);
                    }else{
                        $("#powerStatus").html(res.msg);
                    }
                }, 'json');
            }

            // 救援系统
            $('#btnrescue').on('click', function(){
                if(pre_task == 'rescue' || pre_task == 'close_rescue'){
                    alert('{$zjmf_please_wait_act}');return;
                }
                if(cloud_rescue_status == 0){
                    creatCode($('#ModuleRescue .creakInputRandom'));
                    $('#ModuleRescue').modal('show')
                }else{
                    var _this = $(this);
                    if(!_this.data('submit')){
                        $(this).data('submit', 'submit')
                        _this.text("{$zjmf_api_rescue_exit}...");
                        $.post(base_url, {'zjmfcloud_method':'exit_rescue'}, function(res){
                            _this.data('submit', '')
                            if(res.status == 'success'){
                                // $('#ModuleRescue').modal('hide')
                                alert(res.msg)
                            }else{
                                alert(res.msg);
                            }
                            _this.text("{$zjmf_api_rescue_exit}");
                            window.location.reload();
                        }, 'json')
                    }
                }
            })
            
            $('#ModuleRescue .modal_confirm').on('click', function(){
                var _this = $(this),
                    new_pass = $('#ModuleRescue input[name="new_pass"]').val(),
                    type = $('#ModuleRescue select[name="type"]').val();
                if(!new_pass){
                    alert('{$zjmf_check_password}')
                    return;
                }
                if(!$('#ModuleRescue input[type=checkbox]').prop('checked')){
                    alert('{$zjmf_please_receive_hard_off}');return;
                }
                if(!_this.data('submit')){
                    $(this).data('submit', 'submit')
                    _this.text("{$zjmf_api_rescue}...");
                    $.post(base_url, {'zjmfcloud_method':'rescue', 'temp_pass': new_pass, 'type': type}, function(res){
                        _this.data('submit', '')
                        if(res.status == 'success'){
                            $('#ModuleRescue').modal('hide')
                            alert(res.msg)
                        }else{
                            alert(res.msg);
                        }
                        _this.text("{$zjmf_layer_confirm}");
                        window.location.reload();
                    }, 'json')
                }
            })

            $('select[name="password_type"]').on('change', function(){
                var password_type = $(this).val();
                if(password_type == 0){
                    $(this).parent().parent().find('.use_ssh_key').hide();
                    $(this).parent().parent().find('.use_password').show();
                }else{
                    $(this).parent().parent().find('.use_password').hide();
                    $(this).parent().parent().find('.use_ssh_key').show();
                }
            });
        })
    </script>