<?php 

# 输出到页面的JS
function ipmi_AdminAreaPageJS($params){
	global $_LANG;
    $userid = $params['userid'];
    $serviceid = $params['serviceid'];
    $ipmi_id = $params['ipmi_id'];
    $disk_num = $params['disk_num'];	
    return <<<HTML
    <script type="text/javascript">
        var ipmi_id = "{$ipmi_id}";
        var vnc_window;
        var base_url = "clientsservices.php?userid={$userid}&id={$serviceid}";

        $(function(){
            if(ipmi_id){
                $("#modcmdbtns").find("button").eq(0).hide();
            }
            if($('.ipmi_serverFlow').length>0){
                $.getJSON("clientsservices.php?userid={$userid}&id={$serviceid}&ipmi_serverFlow=true&startDate={$params['startDate']}&endDate={$params['endDate']}", function(res){
                    $(".ipmi_serverFlow").html(res.msg);
                });
            }
            $("#btnKVM").removeAttr("onclick")
            $("#btnIKVM").removeAttr("onclick")
            $("#btnVNC").removeAttr("onclick")
            $("#btnReinstall").html("{$_LANG['ipmi_layer_content_os_reos']}").removeAttr("onclick")
            $("#btnRescue").html("{$_LANG['ipmi_layer_content_rescue']}").removeAttr("onclick")
            $("#btnCrack").html("{$_LANG['ipmi_admin_area_reinstall_getinfo2']}").removeAttr("onclick")
            $('#btnIdcim').html("{$_LANG['ipmi_layer_content_system']}").removeAttr("onclick");
            $('#btnIdcim').click(function(){
                var url = "https://{$params['api_url']}/index.php?m=server&a=detailed&id=" + ipmi_id;
                window.open(url);
            })
            if(!ipmi_id){
                $("#btnKVM").hide();
                $("#btnIKVM").hide();
                $("#btnVNC").hide();
                $("#btnReinstall").hide();
                $("#btnRescue").hide();
                $("#btnCrack").hide();
            }

            $('#port_random').click(function(){
                var num = 10000 + Math.ceil(Math.random() * 10000)                              
                $('#port_imput').val(num)
            })
        })

        function get_traffic_usage(){
            var start = $('#ipmi_traffic_usage .start').val() || '';
            var end = $('#ipmi_traffic_usage .end').val() || '';
            $.post(base_url, {'ipmi_traffic_usage':1, 'start':start,'end':end}, function(res){
                if(res.status == 'error'){
                    alert(res.msg);
                    return;
                }
                var dom = document.getElementById('ipmi_traffic_usage_chart');
                var myChart = echarts.init(dom);
                var app = {};
                option = null;
                option = {
                    tooltip: {
                        trigger: 'axis',
                        formatter: function(params) { 
                            var res = params[0].name+'<br/>';  
                            for (var i = 0; i < params.length; i++) {  
                                res+= params[i].seriesName+':'+params[i].value+'MB<br/>';   
                            }
                            return res;  
                        }
                    },
                    title: {
                        text: "{$_LANG['ipmi_layer_content_usage_info']}"
                    },
                    legend: {
                        data:['{$_LANG['ipmi_admin_area_field_flow']}']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },

                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: res.x,
                    },
                    yAxis: {
                        type: 'value',
                        //msz
                        splitLine:{
                            lineStyle:{
                                color:['#eee']
                            }
                        },
                        
                        axisTick: {
                            
                            lineStyle: {
                                color: '#333',
                            }
                        },
                        axisLine:{
                            lineStyle:{
                                color:'#333'
                            }
                        }
                        //msz over
                    },
                    series: [
                        {
                            name: "{$_LANG['ipmi_admin_area_field_flow']}",
                            type: 'line',
                            stack: "{$_LANG['ipmi_admin_area_field_flow']}",
                            areaStyle: {normal: {}},
                            label: {
                                normal: {
                                show: true,
                                position: 'top',
                                backgroundColor: 'rgba(0,0,0,0.5)',
                                color:'#fff',
                                borderRadius: 4,
                                padding:[5,8]
                                }
                            },
                            data: res.data,
                            itemStyle: {normal: {color:'#50c5ab'}},
                        }
                    ]
                };;
                if (option && typeof option === "object") {
                    myChart.setOption(option, true);
                }
            }, 'json')
        }

        $(function(){
            if($('#ipmi_traffic_usage').length > 0){
                get_traffic_usage();

                $('#ipmi_traffic_usage .start').change(function(){
                    get_traffic_usage();
                })

                $('#ipmi_traffic_usage .end').change(function(){
                    get_traffic_usage();
                })
            }
        })

        $("#btnVNC").on("click", function(){
            var _this = $(this),
                old_desc = $(this).text()
            if(!_this.data('submit')){
                $(this).html('{$_LANG['ipmi_layer_content_vnc_loading']}');
                $(this).data('submit', 'submit')
                if(vnc_window && typeof vnc_window.location !== 'undefined' && typeof vnc_window.location.href == 'string' && vnc_window.location.href != ''){
                    vnc_window.location.reload();
                    _this.data('submit', '')
                    _this.html(old_desc);
                    return ;
                }
                _this.removeData('submit')
                vnc_window = window.open("clientsservices.php?userid={$userid}&id={$serviceid}&vnc=true", '', 'height=800,width=1024,toolbar=no,location=no,scrollbars=yes,left=180,top=100');
                _this.html(old_desc);
            }
        })
        
        //KVM
        $("#btnKVM").on("click", function(){
            var _this = $(this);
            var _name = $(this).html()
            
            if($(this).data("submit") == "submit"){
                _this.removeData("submit");
                return false;
            }else{
                _this.html(_name + '...')
                $(this).data("submit","submit");
                $.post(base_url, {adminipmiac: 'kvm'}, function(res){
                    if("success" == res.status){
                        var filename = res.filename;
                        var url = location.href + '&download=true&java=true&name='+filename;
                        window.open(url, '_parent', 'width=200,height=100,menubar=no,toolbar=no');
                    }else{
                        alert(res.msg)
                    }
                    _this.html(_name)
                    _this.removeData("submit");
                }, 'json')
            }
        })
        
        // IKVM
        $("#btnIKVM").on("click", function(){
            var _this = $(this);
            var _name = $(this).html()
            
            if($(this).data("submit") == "submit"){
                _this.removeData("submit");
                return false;
            }else{
                _this.html(_name + '...')
                $(this).data("submit","submit");
                $.post(base_url, {adminipmiac: 'ikvm'}, function(res){
                    if("success" == res.status){
                        var filename = res.filename;
                        var url = location.href + '&download=true&java=true&name='+filename;
                        window.open(url, '_parent', 'width=200,height=100,menubar=no,toolbar=no');
                    }else{
                        alert(res.msg)
                    }
                    _this.html(_name)
                    _this.removeData("submit");
                }, 'json')  
            }
        })

        $(document).on('click', ".unsuspendReload", function(){
            if($(this).data("submit")=='submit'){ 
                alert('{$_LANG['ipmi_layer_content_unsuspendReload']}');
            }else{
                $("#windows_disk_error").modal("hide");
                var unsuspend=$(this);
                unsuspend.data("submit","submit");
                var url=base_url;
                var disk_part = $('#windows_disk_error input[name="disk_part"]').val()
                var mirror_task_id = $(this).data('id')
                $.ajax({
                    url:url,
                    type:'post',
                    dataType:'json',
                    data:{
                        disk_part: disk_part,
                        adminipmiac: 'unsuspendReload',
                        mirror_task_id: mirror_task_id
                    },
                    success:function(data){
                        if(data.msg){
                            alert(data.msg)
                        }
                        unsuspend.data("submit", '');
                    }
                });
            }
        });

        $(document).on("click", "#btnReinstall", function(){
            if($("#mos").find("option:selected").text().toLowerCase().indexOf("win") != -1){
                $("#port_imput").val(3389)
            }else{
                $("#port_imput").val(22)
            }
            $("#ipmi_msg").html("");
            $("#ipmi_msg").hide();
            $("#provisionHostNew").show();
            $(".reinstall").text("{$_LANG['ipmi_layer_content_os_confirm']}");
            $("#ModuleReinstall").modal({backdrop: 'static', show:true});
            $("#provisionHostNew").find(".wltag").text($("input[name='wltag']").val());
            $("#provisionHostNew").find(".mainIP").text($("input[name='dedicatedip']").val());
            $("#provisionHostNew input[name='zhuip']").val($("input[name='dedicatedip']").val());
            $("#provisionHostNew input[name='passwords']").val(randomString());
        });

        function osconfig(){
            var mos=""; 
            if(os_config){
                $.each(os_config, function(i,v){
                    if(v.osname == $("#mos").val()){
                        mos +='<option value="'+v.id+'">'+v.name+'</option>'; 
                    }
                })
            }
            if(mos=="") mos='<option value="0">{$_LANG['ipmi_layer_content_attach_no']}</option>'; 
            $("#mcon select").html(mos);
        }
        $(document).on("click",".partition label",function(){
            var label=$(this).find("input").val();
            if(label==1){
                osconfig();
                $("#mcon").show();
                $('.diy_partition_add').hide();
                $('.diy_partition_content').hide();
                $('.diy_partition_content .error-text').html('');
            }else if(label == 2){
                $("#mcon").hide();
                if($('#mos').val()>0){
                    if($('#mos').find('option:selected').text().indexOf('Win') == -1){
                        if(/freebsd/i.test($('#mos').find('option:selected').text())){
                            $('.diy_partition_content').html($('#reload_freebsd_default_part').html())
                        }else{
                            $('.diy_partition_content').html($('#reload_linux_default_part').html())
                        }
                    }else{
                        $('.diy_partition_content').html($('#reload_windows_default_part').html())
                    }
                    $('.diy_partition_add').show();
                    $('.diy_partition_content').show();
                }
            }else{                  
                $("#mcon").hide();
                $('.diy_partition_add').hide();
                $('.diy_partition_content').hide();
                $('.diy_partition_content .error-text').html('');
            }
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0 ){
                    $(".reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $(".reinstall").removeClass("error-btn-color");
                }
            })
        });

        $(document).on("change", ".partition input[name=ipmiaction]", function(){
            var label = $(this).val()
            var is_win = $("#mos").find("option:selected").text().toLowerCase().indexOf("win") != -1;
            if(label==1){
                $("#provisionHostNew input[name=highgrade]").parent().parent().hide();
                $("#select_disk").hide();
            }else{
                if(is_win){
                    $("#provisionHostNew input[name=highgrade]").parent().parent().show();
                    if($("#provisionHostNew input[name=highgrade]").is(":checked")){
                        $("#select_disk").show();
                    }else{
                        $("#select_disk").hide();
                    }
                }
            }
        })

        $(document).on("change","#mos",function(){
            var label = $(".partition input[name='ipmiaction']:checked").val();
            if(label==1){
                $("#provisionHostNew input[name=highgrade]").parent().parent().hide();
                $("#select_disk").hide();
                osconfig();
                $("#mcon").show();
                $('.diy_partition_add').hide();
                $('.diy_partition_content').hide();
                $('.diy_partition_content .error-text').html('');
            }else if(label == 2){
                $("#mcon").hide();
                if($('#mos').val()>0){
                    if($('#mos').find('option:selected').text().toLowerCase().indexOf('win') == -1){
                        if(/freebsd/i.test($('#mos').find('option:selected').text())){
                            $('.diy_partition_content').html($('#reload_freebsd_default_part').html())
                        }else{
                            $('.diy_partition_content').html($('#reload_linux_default_part').html())
                        }
                    }else{
                        $('.diy_partition_content').html($('#reload_windows_default_part').html())
                    }
                    $('.diy_partition_add').show();
                    $('.diy_partition_content').show();
                }else{
                    $('.diy_partition_add').hide();
                    $('.diy_partition_content').hide();
                }
            }else{                  
                $("#mcon").hide();
                $('.diy_partition_add').hide();
                $('.diy_partition_content').hide();
                $('.diy_partition_content .error-text').html('');
            }
            var is_win = $(this).find("option:selected").text().toLowerCase().indexOf("win") != -1;
            if(is_win){
                $("#ModuleReinstall .part_type").show();
                $("#ModuleReinstall input[name='port']").val(3389);
                $("#ModuleReinstall .part_type").find("input").eq(0).click();
                $("#ModuleReinstall .part_info").show();
                $("#ModuleReinstall input[name='highgrade']").removeAttr("checked");
                getReloadSelectDisk();
            }else{
                $("#ModuleReinstall .part_type").hide();
                $("#ModuleReinstall .part_type").find("input").eq(1).click();
                $("#ModuleReinstall input[name='port']").val(22);
                $("#ModuleReinstall .part_info").show();
                $("#ModuleReinstall input[name='highgrade']").removeAttr("checked");
                getReloadSelectDisk();
            }
            getMirrorScripts();
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0 ){
                    $(".reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $(".reinstall").removeClass("error-btn-color");
                }
            })
        });

        $(document).on('change', "#ModuleReinstall input[name='part_type']", function() {
            var label = $(".partition input[name='ipmiaction']:checked").val();
            var is_win = $('#mos').find("option:selected").text().toLowerCase().indexOf("win") != -1;
            if ($("#ModuleReinstall input[name='part_type']:checked").val() == 1) {
                $("#ModuleReinstall .part_info").hide();
                $("#mcon").hide();
                $('.diy_partition_add').hide();
                $('.diy_partition_content').hide();
                $('.diy_partition_content .error-text').html('')
            } else{
                $("#ModuleReinstall .part_info").show();
                if (label == 1) {
                    $("#mcon").show();
                    $('.diy_partition_add').hide();
                    $('.diy_partition_content').hide();
                    $('.diy_partition_content .error-text').html('')
                } else if(label == 2){
                    $("#mcon").hide();
                    if($('#mos').val()){
                        if(!is_win){
                            if(/freebsd/i.test($('#mos').find('option:selected').text())){
                                $('.diy_partition_content').html($('#reload_freebsd_default_part').html())
                            }else{
                                $('.diy_partition_content').html($('#reload_linux_default_part').html())
                            }
                        }else{
                            $('.diy_partition_content').html($('#reload_windows_default_part').html())
                        }
                        $('.diy_partition_add').show();
                        $('.diy_partition_content').show();
                    }
                }else{
                    $("#mcon").hide();
                    $('.diy_partition_add').hide();
                    $('.diy_partition_content').hide();
                    $('.diy_partition_content .error-text').html('')
                }
            }
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0 ){
                    $("#ModuleReinstall .reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $("#ModuleReinstall .reinstall").removeClass("error-btn-color");
                }
            })
        });

        $(document).on("change", "#ModuleReinstall input[name='highgrade']", function(){
            getReloadSelectDisk();
        });

        function getReloadSelectDisk(){
            if($("#ModuleReinstall input[name='highgrade']").is(":checked")){
                var id = $("#ModuleReinstall input[name='id']").val();
                var disk_num = {$disk_num};
                var _html='';
                for(let i=0; i<disk_num; i++){
                    _html+='<option value="'+i+'">disk'+i+'</option>';
                }
                $("#select_disk").find("select").html(_html);
                $("#select_disk").show();
            }else{
                $("#select_disk").find("select").html('<option value="0">disk0</option>');
                $("#select_disk").hide();
            }
        }

        function getMirrorScripts(){
            // 是否已经获取过了
            var select_option = $("#mos").find("option:selected");
            var cache = select_option.data('mscripts');
            if(cache){
                $('#mscripts select[name="mscripts"]').html(cache);
            }else{
                $('#mscripts select[name="mscripts"]').html('<option value="0">{$_LANG["ipmi_action_get_reinstall_boot_script"]}</option>');
                var mos = $('#mos').val();
                var mscripts_selected = false;
                var _html = '';
                $.post(base_url, {"mos":mos,'adminipmiac':"getMirrorScripts"}, function(res) {
                    if(res.status == 'success' && res.data.length > 0){
                        var data = res.data;
                        for(let i=0; i<data.length; i++){
                            if(data[i].auto_install==1 && mscripts_selected==false){
                                _html+='<option value="'+ data[i].id +'" selected>' + data[i].name + '</option>';
                                mscripts_selected = true
                            }else{
                                _html+='<option value="'+ data[i].id +'">' + data[i].name + '</option>';
                            }
                        }
                        if(!_html){
                            _html = '<option value="0">{$_LANG["ipmi_action_no_enable_script"]}</option>';
                        }else{
                            _html = "<option value='0'>{$_LANG['ipmi_layer_content_select']}</option>" + _html;
                        }
                        select_option.data('mscripts', _html);

                        $('#mscripts select[name="mscripts"]').html(_html);
                    }else{
                        $('#mscripts select[name="mscripts"]').html('<option value="0">{$_LANG["ipmi_action_no_enable_script"]}</option>');
                    }
                }, "json");
            }
        }

        $(document).on('click', '.reload_add_part', function(){
            var is_win = $('#mos').find('option:selected').text().toLowerCase().indexOf('win') != -1;
            var len = 0;
            if(is_win){
                //获取下个分区
                len = $('.diy_partition_content .diy_partition').length;
            }
            var win_part = '<div class="diy_partition 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;"></label>'+
                                    '<div class="col-xs-12 col-md-3" style="position: relative;">'+
                                        '<div class="diy_part form-control">{$_LANG['ipmi_layer_content_os_partition']}'+ len +'</div>'+
                                    '</div>'+
                                    '<div class="col-xs-12 col-md-3" style="position: relative;">'+
                                        '<select class="diy_fs form-control">'+
                                            '<option value="NTFS">NTFS</option>'+
                                        '</select>'+
                                    '</div>'+
                                    '<div class="col-xs-12 col-md-2">'+
                                        '<input type="text" class="diy_size form-control" value="剩余全部" placeholder="{$_LANG['ipmi_layer_content_capacity'] }">'+
                                    '</div>'+
                                    '<div class="col-md-1 col-xs-1 p-r-5">'+
                                        '<button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">'+
                                            '<span class="text">-</span>'+
                                        '</button>'+
                                    '</div>'+
                                '</div>';
            var lin_part = '<div class="diy_partition 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;"></label>'+
                                '<div class="col-xs-12 col-md-3">'+
                                    '<input type="text" class="diy_part form-control" value="/">'+
                                    '<span class="error-text" style="display: none;"></span>'+
                                '</div>'+
                                '<div class="col-xs-12 col-md-3">'+
                                    '<select class="diy_fs form-control">'+
                                        '<option value="ext4">ext4</option>'+
                                        '<option value="ext3">ext3</option>'+
                                        '<option value="ext2">ext2</option>'+
                                        '<option value="swap">swap</option>'+
                                        '<option value="xfs">xfs</option>'+
                                    '</select>'+
                                    '<span class="error-text" style="display: none;"></span>'+
                                '</div>'+
                                '<div class="col-xs-12 col-md-2">'+
                                    '<input type="text" class="diy_size form-control" value="剩余全部" placeholder="{$_LANG['ipmi_layer_content_capacity'] }">'+
                                    '<span class="error-text" style="display: none;"></span>'+
                                '</div>'+
                                '<div class="col-md-1 col-xs-1 p-r-5">'+
                                    '<button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">'+
                                        '<span class="text">-</span>'+
                                    '</button>'+
                                '</div>'+
                            '</div>';
            var freebsd_part = '<div class="diy_partition 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;"></label>'+
                                '<div class="col-xs-12 col-md-3">'+
                                    '<input type="text" class="diy_part form-control" value="/">'+
                                    '<span class="error-text" style="display: none;"></span>'+
                                '</div>'+
                                '<div class="col-xs-12 col-md-3">'+
                                    '<input type="text" class="diy_fs form-control" value="ufs" disabled="" style="cursor: not-allowed;">'+
                                    '<span class="error-text" style="display: none;"></span>'+
                                '</div>'+
                                '<div class="col-xs-12 col-md-2">'+
                                    '<input type="text" class="diy_size form-control" value="剩余全部" placeholder="{$_LANG['ipmi_layer_content_capacity'] }">'+
                                    '<span class="error-text" style="display: none;"></span>'+
                                '</div>'+
                                '<div class="col-md-1 col-xs-1 p-r-5">'+
                                    '<button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">'+
                                        '<span class="text">-</span>'+
                                    '</button>'+
                                '</div>'+
                            '</div>';
            if(is_win){
                $('.diy_partition_content').append(win_part);
            }else{
                if(/freebsd/i.test($('#mos').find('option:selected').text())){
                    $('.diy_partition_content').append(freebsd_part);
                }else{
                    $('.diy_partition_content').append(lin_part);
                }
            }
        })
        
        $(document).on('click', '.reload_remove_part', function(){
            var is_win = $('#mos').find('option:selected').text().toLowerCase().indexOf('win') != -1;
            $(this).parents('.diy_partition').remove();
            if(is_win){
                //重新设置分区
                $('.diy_partition_content .diy_part').each(function(i, v){
                    $(this).html('{$_LANG['ipmi_layer_content_os_partition']}'+i);
                })
            }
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0 ){
                    $(".reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $(".reinstall").removeClass("error-btn-color");
                }
            })
        })

        $(document).on('change', '.diy_partition_content .diy_size', function(){
            var val = $(this).val()
            if(!val){
                $(this).val('剩余全部')
            }
        })

        $(document).on('click', '#ModuleCrack .show_other_user', function(){
            if($(this).find('input').is(':checked')){
                $('#ModuleCrack .other_user').show();
            }else{
                $('#ModuleCrack .other_user').hide();
            }
        })

        function getReloadDiy(){
            var obj = [];
            var length = $('.diy_partition_content .diy_partition').length
            var parts = []
            var left = null;
            var is_win = $('#mos').find('option:selected').text().toLowerCase().indexOf('win') != -1;
            for(let i = 0; i<length; i++){
                let one = {
                    part: $('.diy_partition_content .diy_part').eq(i).val().trim(),
                    fs: $('.diy_partition_content .diy_fs').eq(i).val(),
                    size: +$('.diy_partition_content .diy_size').eq(i).val().trim(),
                }
                if(isNaN(one.size)){
                    one.size = 0;
                }
                if(is_win){
                    one.part = i+1;
                }
                if(!one.part){
                    return {status: 0, msg: '{$_LANG['ipmi_layer_content_partition_error1']}'}
                }
                if(/[^\d]/.test(one.size)){
                    return {status: 0, msg: '{$_LANG['ipmi_layer_content_partition_error2']}'}
                }
                if(parts.indexOf(one.part) != -1){
                    return {status: 0, msg: '{$_LANG['ipmi_layer_content_partition_error3']}'}
                }
                if(one.size == 0){
                    if(!left){
                        left = one;
                    }else{
                        return {status: 0, msg: '{$_LANG['ipmi_layer_content_partition_error4']}'}
                    }
                }else{
                    parts.push(one.part);
                    obj.push(one);
                }   
            }
            if(left){
                obj.push(left)
            }
            return {status: 1, obj: obj};
        }

        $(document).on('change', '.diy_partition_content .diy_fs', function(){
            var val = $(this).val()
            var input = $(this).parents('.diy_partition').find('.diy_part')
            var real_os_name = $('#mos').find('option:selected').text()
            if(val == 'swap'){
                input.val('swap').trigger('change')
            }else{
                if(input.val() == 'swap'){
                    input.val('').trigger('change')
                }
            }
            if(/centos-?5/i.test(real_os_name)){  //centos5 不支持xfs,/boot不支持ext4
                if(val == 'xfs'){
                    $(this).siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error1'] }').removeData('check')
                }else if(val == 'ext4'){
                    if(input.val() == '/boot'){
                        $(this).siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error2'] }').removeData('check')
                    }else{
                        $(this).siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error3']}').data('check', 1)
                    }
                }else{
                    $(this).siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                }
            }else if(/centos-?6/i.test(real_os_name)){  //centos6 /不支持xfs,/boot不支持ext4,xfs
                if(input.val() == '/'){
                    if(val == 'xfs'){
                        $(this).siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error1'] }').removeData('check')
                    }else{
                        $(this).siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                    }
                }else if(input.val() == '/boot'){
                    if(val == 'xfs'){
                        $(this).siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error1'] }').removeData('check')
                    }else if(val == 'ext4'){
                        $(this).siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error2']}').removeData('check')
                    }else{
                        $(this).siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                    }
                }else{
                    $(this).siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                }
            }else{
                $(this).siblings('.error-text').css({'display':'none'}).text('').removeData('check')
            }
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0){
                    $("#ModuleReinstall .reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $("#ModuleReinstall .reinstall").removeClass("error-btn-color");
                }
            })
        })

        $(document).on('change input propertychange', '.diy_partition_content input.diy_part', function(){
            var val = $(this).val()
            var select = $(this).parents('.diy_partition').find('select.diy_fs')
            var size = $(this).parents('.diy_partition').find('.diy_size')
            var real_os_name = $('#mos').find('option:selected').text()
            if(val == 'swap'){
                select.val('swap')
                $(this).siblings('.error-text').css({'display':'none'})
                $(this).siblings('.error-text').text('')
            }else{
                if(val == '' || val.indexOf('/') != 0){
                    $(this).siblings('.error-text').css({'display':'inline-block'})
                    $(this).siblings('.error-text').text('{$_LANG['ipmi_layer_content_propertychange_error1']}')
                }else{
                    $(this).siblings('.error-text').css({'display':'none'})
                    $(this).siblings('.error-text').text('')
                }
                if(select.val() == 'swap'){
                    select.val('ext4')
                }
                if(val == '/'){
                    if(size.val() != 0 && size.val() < 500){
                        size.siblings('.error-text').css({'display':'inline-block'})
                        size.siblings('.error-text').text('{$_LANG['ipmi_layer_content_propertychange_error2']}')
                    }else{
                        size.siblings('.error-text').css({'display':'none'})
                        size.siblings('.error-text').text('')
                    }
                }else if(val == '/boot'){
                    if(size.val() != 0 && size.val() < 100){
                        size.siblings('.error-text').css({'display':'inline-block'})
                        size.siblings('.error-text').text('{$_LANG['ipmi_layer_content_propertychange_error3']}')
                    }else{
                        size.siblings('.error-text').css({'display':'none'})
                        size.siblings('.error-text').text('')
                    }
                }else{
                    size.siblings('.error-text').css({'display':'none'})
                    size.siblings('.error-text').text('')
                }
            }
            if(/centos-?5/i.test(real_os_name)){  //centos5 不支持xfs,/boot不支持ext4
                if(select.val() == 'xfs'){
                    select.siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error1']}').removeData('check')
                }else if(select.val() == 'ext4'){
                    if(val == '/boot'){
                        select.siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error2']}').removeData('check')
                    }else{
                        select.siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error3']}').data('check', 1)
                    }
                }else{
                    select.siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                }
            }else if(/centos-?6/i.test(real_os_name)){  //centos6 /不支持xfs,/boot不支持ext4,xfs
                if(val == '/'){
                    if(select.val() == 'xfs'){
                        select.siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error1']}').removeData('check')
                    }else{
                        select.siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                    }   
                }else if(val == '/boot'){
                    if(select.val() == 'xfs'){
                        select.siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error1']}').removeData('check')
                    }else if(select.val() == 'ext4'){
                        select.siblings('.error-text').css({'display':'inline-block'}).text('{$_LANG['ipmi_layer_content_os_error2']}').removeData('check')
                    }else{
                        select.siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                    }
                }else{
                    select.siblings('.error-text').css({'display':'none'}).text('').removeData('check')
                }
            }else{
                select.siblings('.error-text').css({'display':'none'}).text('').removeData('check')
            }
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0 ){
                    $(".reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $(".reinstall").removeClass("error-btn-color");
                }
            })
        })

        $(document).on('input propertychange', '.diy_partition_content .diy_size', function(){
            var part = $(this).parents('.diy_partition').find('.diy_part').val()
            var val = $(this).val();
            if($(this).hasClass('windows_start_part')){
                if(val != 0 && val <= 16000){
                    $(this).siblings('.error-text').css({'display':'inline-block'})
                    $(this).siblings('.error-text').text('{$_LANG['ipmi_layer_content_propertychange_error4']}')
                }else{
                    $(this).siblings('.error-text').css({'display':'none'})
                    $(this).siblings('.error-text').text('')
                }
            }else{
                if(part == '/'){
                    if(val != 0 && val < 500){
                        $(this).siblings('.error-text').css({'display':'inline-block'})
                        $(this).siblings('.error-text').text('{$_LANG['ipmi_layer_content_propertychange_error2']}')
                    }else{
                        $(this).siblings('.error-text').css({'display':'none'})
                        $(this).siblings('.error-text').text('')
                    }
                }else if(part == '/boot'){
                    if(val != 0 && val < 100){
                        $(this).siblings('.error-text').css({'display':'inline-block'})
                        $(this).siblings('.error-text').text('{$_LANG['ipmi_layer_content_propertychange_error3']}')
                    }else{
                        $(this).siblings('.error-text').css({'display':'none'})
                        $(this).siblings('.error-text').text('')
                    }
                }else{
                    $(this).siblings('.error-text').css({'display':'none'})
                    $(this).siblings('.error-text').text('')
                }
            }
            $('#ModuleReinstall .error-text').each(function(){
                if($(this).data('check')){
                    return true;
                }
                var l = $(this).text()
                if(l.length > 0 ){
                    $(".reinstall").addClass("error-btn-color");
                    return false;
                }else{
                    $(".reinstall").removeClass("error-btn-color");
                }
            })
        })
    
        $(document).on("click",".reinstall",function(){   
            var ipmiaction=$("input[name=ipmiaction]:checked").val();
            var passwords=$("input[name=passwords]").val();    
            var mos=$("select[name=mos]").val();
            var mcon=$("select[name=mcon]").val();
            var wltag=$("input[name=wltag]").val();
            var port = $("#port_imput").val();
            var part_type = $("#ModuleReinstall input[name='part_type']:checked").val()
            var disk = $("#ModuleReinstall select[name='disk']").val()
            var mscripts = $("#ModuleReinstall select[name='mscripts']").val()
            if($(this).hasClass('error-btn-color')){
                return;
            }
            if(!checkOsPass(passwords)){
                alert('{$_LANG['ipmi_layer_content_os_error4']}');
                return ;
            }
            if(mos<=0){
                $("#ipmi_msg").show();
                $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_os_error5']}');
                return ;
            }
            var xml = ''
            if(!$(".partition input[name='ipmiaction']").is(':hidden') && $(".partition input[name='ipmiaction']:checked").val() == 2){
                var part_obj = getReloadDiy();
                var option = $('#mos').find('option:selected')
                if(part_obj.status == 0){
                    $("#ipmi_msg").show();
                    $("#ipmi_msg").html(part_obj.msg);
                    return ;
                }
                if(option.text().toLowerCase().indexOf('win') != -1){ //windows
                    var partition = [
                        {
                            CreatePartitions: [],
                            DiskID: "0",
                            ModifyPartitions: [],
                            WillWipeDisk: "true",
                        }
                    ];
                    if(part_obj.obj[0].size != 0 && part_obj.obj[0].size <= 16000){
                        msgTop('{$_LANG['ipmi_layer_content_propertychange_error4']}', 'error');
                        return ;
                    }
                    for(let i = 0; i<part_obj.obj.length; i++){
                        if(part_obj.obj[i].size>0){
                            partition[0].CreatePartitions.push({Order: i+1, Size: part_obj.obj[i].size, Type: "Primary"});
                        }else{
                            partition[0].CreatePartitions.push({Order: i+1, Extend: "true", Type: "Primary"});
                        }
                        partition[0].ModifyPartitions.push({Order: i+1, Format: part_obj.obj[i].fs, Label: '', Type: "Primary"}); 
                    }
                    var partition_obj = new Windows_Partition('');
                }else{
                    if(option.text().toLowerCase().indexOf('ubuntu') != -1 || option.text().toLowerCase().indexOf('debian') != -1){  //Ubuntu
                        var partition = [];
                        if(option.text().toLowerCase().indexOf('debian') != -1){
                            var partition_obj = new Ubuntu_Partition('', 'BIOS', 'debian');
                        }else{
                            var partition_obj = new Ubuntu_Partition('');
                            if(option.text().toLowerCase().indexOf('-20') != -1 || option.text().toLowerCase().indexOf('_20') != -1){
                                partition_obj.setVersion(20)
                            }
                        }
                        for(let i = 0; i<part_obj.obj.length; i++){
                            let t = {
                                bootable: false,
                                format: true,
                                fs: part_obj.obj[i].fs,
                                method: "format",
                                min_size: part_obj.obj[i].size == 0 ? 100 : part_obj.obj[i].size,
                                mountpoint: part_obj.obj[i].part,
                                part: part_obj.obj[i].part,
                                primary: true,
                                priority: 50 + i*10,
                                size: part_obj.obj[i].size,
                                use_filesystem: true,
                            }
                            if(part_obj.obj[i].part == 'swap'){
                                t.method = 'swap';
                            }else if(part_obj.obj[i].part == '/boot'){
                                t.bootable = true;
                                if(t.size != 0 && t.size < 100){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error3'] }');
                                    return ;
                                }
                            }else if(part_obj.obj[i].part == '/'){
                                if(t.size != 0 && t.size < 500){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error2']}');
                                    return ;
                                }
                            }
                            partition.push(t)
                        }
                    }else if(option.text().toLowerCase().indexOf('freebsd') != -1){
                        var partition = [];
                        var partition_obj = new FreeBSD_Partition('');
                        for(let i = 0; i<part_obj.obj.length; i++){
                            let t = {
                                fs: "ufs",
                                part: part_obj.obj[i].part,
                                size: part_obj.obj[i].size,
                            }
                            if(part_obj.obj[i].part == 'swap'){
                                t.fs = 'swap';
                            }else if(part_obj.obj[i].part == '/boot'){
                                if(t.size != 0 && t.size < 100){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error3']}');
                                    return ;
                                }
                            }else if(part_obj.obj[i].part == '/'){
                                if(t.size != 0 && t.size < 500){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error2']}');
                                    return ;
                                }
                            }
                            if(partition.length>0 && t.size != 0 && partition[partition.length-1].size == 0){
                                partition.splice(partition.length-1, 0, t)
                            }else{
                                partition.push(t)
                            }
                        }
                    }else{
                        var partition = [];
                        for(let i = 0; i<part_obj.obj.length; i++){
                            if(part_obj.obj[i].part == '/boot'){
                                if(part_obj.obj[i].size != 0 && part_obj.obj[i].size < 100){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error3']}');
                                    return ;
                                }
                            }else if(part_obj.obj[i].part == '/'){
                                if(part_obj.obj[i].size != 0 && part_obj.obj[i].size < 500){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error2']}');
                                    return ;
                                }
                            }
                            if(part_obj.obj[i].size>0){
                                partition.push({part: part_obj.obj[i].part, fs: part_obj.obj[i].fs, size: part_obj.obj[i].size, grow: false, left: ""});
                            }else{
                                partition.push({part: part_obj.obj[i].part, fs: part_obj.obj[i].fs, size: 0, grow: true, left: ""});
                            }
                        }
                        var partition_obj = new Centos_Partition('');
                    }
                }
                partition_obj.obj = partition
                partition_obj.refreshXml();
                xml = partition_obj.xml;
            }
            $(".cancellReinstall").removeData("reinstall");
            if($(".reinstall").data("reinstall")) return false;
            $("#ipmi_msg").html("");
            $(".reinstall").text("{$_LANG['ipmi_layer_content_os_submit']}");
            $("#ipmi_msg").hide();
            $("#ipmi_msg").html('');
            $(".reinstall").data("reinstall",true);
            $.post(base_url,{"ipmi_reinstall":"true","ipmiaction":ipmiaction,"passwords":passwords,"mos":mos,"mcon":mcon,"wltag":wltag,"port":port,"xml":xml,"part_type":part_type,disk:disk,"check_disk_size":1,"mscripts":mscripts},function(data){
                if(data.status=="error"){                           
                    $(".reinstall").removeData("reinstall");
                    $(".reinstall").text("{$_LANG['ipmi_layer_content_os_confirm']}");
                    $("#ipmi_msg").show();
                    $("#ipmi_msg").html(data.msg);
                }else if(data.status == 'confirm'){
                    $('#ModuleReinstall').modal('hide');
                    $(".reinstall").removeData("reinstall");
                    $(".reinstall").text("{$_LANG['ipmi_layer_content_os_confirm']}");
                    $("#ipmi_msg").html('');
                    $("#disk_size_error .modal-body").html(data.msg);
                    $("#disk_size_error").modal("show");
                }else{
                    alert(data.msg);
                    //$("#provisionHostNew").hide();
                    $(".reinstall").text("{$_LANG['ipmi_layer_confirm']}"); 
                    //$(".reinstallcal").hide();
                    $(".reinstall").hide();
                    location.reload(); 
                }                               
            },"json");
        });
        $(".reinstallStatus").hide();
        if($(".reinstallStatus").html()){
            var reinstallStatus='<div class="reinstallStatus">'+$(".reinstallStatus").html()+"</div>";
            $(".ipmi_status").before(reinstallStatus);      
        }

        $(document).on('click', ".disk_size_edit_btn", function() {
            $("#disk_size_error").modal("hide");
            $("#ModuleReinstall").modal("show");
        });

        $(document).on('click', '.reload_continue_btn', function(){
            $("#disk_size_error").modal("hide");
            var ipmiaction=$("input[name=ipmiaction]:checked").val();
            var passwords=$("input[name=passwords]").val();    
            var mos=$("select[name=mos]").val();
            var mcon=$("select[name=mcon]").val();
            var wltag=$("input[name=wltag]").val();
            var port = $("#port_imput").val();
            var part_type = $("#ModuleReinstall input[name='part_type']:checked").val()
            var disk = $("#ModuleReinstall select[name='disk']").val()
            var xml = ''
            if($("#ModuleReinstall input[name='part_type']:checked").val() == 0 && $(".partition input[name='ipmiaction']:checked").val() == 2){
                var part_obj = getReloadDiy();
                var option = $('#mos').find('option:selected')
                if(part_obj.status == 0){
                    $("#ipmi_msg").show();
                    $("#ipmi_msg").html(part_obj.msg);
                    return ;
                }
                if(option.text().toLowerCase().indexOf('win') != -1){ //windows
                    var partition = [
                        {
                            CreatePartitions: [],
                            DiskID: "0",
                            ModifyPartitions: [],
                            WillWipeDisk: "true",
                        }
                    ];
                    if(part_obj.obj[0].size != 0 && part_obj.obj[0].size <= 16000){
                        msgTop('{$_LANG['ipmi_layer_content_propertychange_error4']}', 'error');
                        return ;
                    }
                    for(let i = 0; i<part_obj.obj.length; i++){
                        if(part_obj.obj[i].size>0){
                            partition[0].CreatePartitions.push({Order: i+1, Size: part_obj.obj[i].size, Type: "Primary"});
                        }else{
                            partition[0].CreatePartitions.push({Order: i+1, Extend: "true", Type: "Primary"});
                        }
                        partition[0].ModifyPartitions.push({Order: i+1, Format: part_obj.obj[i].fs, Label: '', Type: "Primary"}); 
                    }
                    var partition_obj = new Windows_Partition('');
                }else{
                    if(option.text().toLowerCase().indexOf('ubuntu') != -1 || option.text().toLowerCase().indexOf('debian') != -1){  //Ubuntu
                        var partition = [];
                        var partition_obj = new Ubuntu_Partition('');
                        for(let i = 0; i<part_obj.obj.length; i++){
                            let t = {
                                bootable: false,
                                format: true,
                                fs: part_obj.obj[i].fs,
                                method: "format",
                                min_size: part_obj.obj[i].size == 0 ? 100 : part_obj.obj[i].size,
                                mountpoint: part_obj.obj[i].part,
                                part: part_obj.obj[i].part,
                                primary: true,
                                priority: 50 + i*10,
                                size: part_obj.obj[i].size == 0 ? partition_obj.left : part_obj.obj[i].size,
                                use_filesystem: true,
                            }
                            if(part_obj.obj[i].part == 'swap'){
                                t.method = 'swap';
                            }else if(part_obj.obj[i].part == '/boot'){
                                t.bootable = true;
                                if(t.size != 0 && t.size < 100){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error3']}');
                                    return ;
                                }
                            }else if(part_obj.obj[i].part == '/'){
                                if(t.size != 0 && t.size < 500){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error2']}');
                                    return ;
                                }
                            }
                            partition.push(t)
                        }
                    }else if(option.text().toLowerCase().indexOf('freebsd') != -1){
                        var partition = [];
                        var partition_obj = new FreeBSD_Partition('');
                        for(let i = 0; i<part_obj.obj.length; i++){
                            let t = {
                                fs: "ufs",
                                part: part_obj.obj[i].part,
                                size: part_obj.obj[i].size,
                            }
                            if(part_obj.obj[i].part == 'swap'){
                                t.fs = 'swap';
                            }else if(part_obj.obj[i].part == '/boot'){
                                if(t.size != 0 && t.size < 100){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error3']}');
                                    return ;
                                }
                            }else if(part_obj.obj[i].part == '/'){
                                if(t.size != 0 && t.size < 500){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error2']}');
                                    return ;
                                }
                            }
                            if(partition.length>0 && t.size != 0 && partition[partition.length-1].size == 0){
                                partition.splice(partition.length-1, 0, t)
                            }else{
                                partition.push(t)
                            }
                        }
                    }else{
                        var partition = [];
                        for(let i = 0; i<part_obj.obj.length; i++){
                            if(part_obj.obj[i].part == '/boot'){
                                if(part_obj.obj[i].size != 0 && part_obj.obj[i].size < 100){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error3']}');
                                    return ;
                                }
                            }else if(part_obj.obj[i].part == '/'){
                                if(part_obj.obj[i].size != 0 && part_obj.obj[i].size < 500){
                                    $("#ipmi_msg").show();
                                    $("#ipmi_msg").html('{$_LANG['ipmi_layer_content_propertychange_error2']}');
                                    return ;
                                }
                            }
                            if(part_obj.obj[i].size>0){
                                partition.push({part: part_obj.obj[i].part, fs: part_obj.obj[i].fs, size: part_obj.obj[i].size, grow: false, left: ""});
                            }else{
                                partition.push({part: part_obj.obj[i].part, fs: part_obj.obj[i].fs, size: 0, grow: true, left: ""});
                            }
                        }
                        var partition_obj = new Centos_Partition('');
                    }
                }
                partition_obj.obj = partition
                partition_obj.refreshXml();
                xml = partition_obj.xml;
            }
            $.post(base_url,{"ipmi_reinstall":"true","ipmiaction":ipmiaction,"passwords":passwords,"mos":mos,"mcon":mcon,"wltag":wltag,"port":port,"xml":xml,"part_type":part_type,disk:disk},function(data){
                if(data.status=="error"){                           
                    alert(data.msg);
                }else{
                    alert(data.msg);
                    location.reload(); 
                }                               
            },"json");
        })

        $(document).on("click", ".stopReload",function(){ 
            var _html = $(this).html();
            $(".cancellReinstall").text("{$_LANG['ipmi_layer_yes']}");
            $("#modalcancellReinstallBody").html("{$_LANG['ipmi_layer_confirm_y']}" + _html +"?");
            $("#cancellReinstall").modal({backdrop: 'static', show:true});
            var mirror_task_id = $(this).data("id");
            $(".cancellReinstall").click(function(){
                $("#modalcancellReinstallBody").html("{$_LANG['ipmi_layer_confirm_y']}"+ _html +"?");
                if($(".cancellReinstall").data("reinstall")) return false;
                $(".cancellReinstall").text(_html + "...");
                $(".cancellReinstall").data("reinstall",true);
                $.post(base_url, {"ipmi_cancellReinstall":"true", "mirror_task_id":mirror_task_id}, function(result){
                    if(result.status == "success"){                     
                        window.location.reload();
                    }else{
                        $(".cancellReinstall").removeData("reinstall");
                    }
                    $(".cancellReinstall").text("{$_LANG['ipmi_layer_yes']}");
                    $("#modalcancellReinstallBody").html(result.msg);
                }, "json");
            });
        });
        if($(".reload_status").length>0){
            var show_time = 0;
            var reload_status_interval = setInterval(function () {
                $.post(base_url, {"adminipmiac": "reload_status"}, function (data) {
                    if (data.status == "success") {
                        $(".reload_status").html(data.msg);

                        if(data.crackPwd){
                            if($('#ModuleChooseUser').is(':hidden')){
                                var _html="";
                                $.each(data.crackPwd.user,function(i,v){
                                    _html+='<option value="'+v+'">'+v+'</option>';
                                });
                                $("#crackPwdUser").html(_html);
                                $("#ModuleChooseUser input[name='crack_password']").val(data.crackPwd.password);
                                $("#ModuleChooseUser").modal({backdrop: 'static', show:true});
                            }
                        }else{
                            if($("#ModuleChooseUser").length>0){
                                $("#ModuleChooseUser").modal("hide");
                            }
                        }
                        // windows_disk_error
                        if(data.error_type > 0){
                            if(data.progress <= 20){
                                if(show_time == 0 && $("#windows_disk_error").is(':hidden')){
                                    if(data.error_type==1){
                                        $("#windows_disk_error .modal-title").html('{$_LANG['ipmi_layer_content_os_error6'] }');
                                        $("#windows_disk_error .modal-body").html('<div class="form-group row"><div class="col-xs-12 col-md-12">'+data.error_msg+'</div></div>');
                                        $("#windows_disk_error .stopReload").html('{$_LANG['ipmi_layer_content_os_error8'] }');
                                        $("#windows_disk_error .stopReload").addClass("red-700");
                                        $("#windows_disk_error .unsuspendReload").hide();
                                    }else if(data.error_type==2){
                                        $("#windows_disk_error .modal-title").html('{$_LANG['ipmi_layer_content_os_error7'] }');
                                        var _html='<div class="form-group row"><div class="col-xs-12 col-md-12">'+data.error_msg+'</div></div>';
                                        $.each(data.disk_info, function(i,v){
                                            _html+='<div class="form-group row"><div class="col-xs-2 col-md-2">'+v.disk+'</div><div class="col-xs-2 col-md-2">'+v.part+'</div><div class="col-xs-2 col-md-2">'+v.size+'</div><div class="col-xs-2 col-md-2">'+v.type+'</div><div class="col-xs-4 col-md-4">'+v.windows+'</div></div>';
                                        });
                                        $.each(data.disk_check,function(i,v){
                                            if(v.checked==1){
                                                _html+='<div class="form-group row"><div class="col-xs-12 col-md-12"><label><input type="radio" name="disk_part" value="'+v.value+'" checked>'+v.description+'</label></div></div>';
                                            }else{
                                                _html+='<div class="form-group row"><div class="col-xs-12 col-md-12"><label><input type="radio" name="disk_part" value="'+v.value+'">'+v.description+'</label></div></div>';
                                            }
                                        });
                                        _html+='<div class="clearfix"></div>';
                                        $("#windows_disk_error .modal-body").html(_html);
                                        $("#windows_disk_error .unsuspendReload").show();
                                        $("#windows_disk_error .unsuspendReload").html('{$_LANG['ipmi_layer_content_os_format_all'] }');
                                        $("#windows_disk_error .stopReload").html('{$_LANG['ipmi_layer_content_os_cancel2'] }');
                                        $("#windows_disk_error .stopReload").removeClass("red-700");
                                    }else{
                                        $("#windows_disk_error .modal-title").html('{$_LANG['ipmi_layer_content_os_error9']}');
                                        var _html='<div class="form-group row"><div class="col-xs-12 col-md-12">'+data.error_msg+'</div></div>';
                                        $.each(data.disk_info,function(i,v){
                                            _html+='<div class="form-group row"><div class="col-xs-2 col-md-2">'+v.disk+'</div><div class="col-xs-2 col-md-2">'+v.part+'</div><div class="col-xs-2 col-md-2">'+v.size+'</div><div class="col-xs-2 col-md-2">'+v.type+'</div><div class="col-xs-4 col-md-4">'+v.windows+'</div></div>';
                                        });
                                        $.each(data.disk_check,function(i,v){
                                            if(v.checked==1){
                                                _html+='<div class="form-group row"><div class="col-xs-12 col-md-12"><label><input type="radio" name="disk_part" value="'+v.value+'" checked>'+v.description+'</label></div></div>';
                                            }else{
                                                _html+='<div class="form-group row"><div class="col-xs-12 col-md-12"><label><input type="radio" name="disk_part" value="'+v.value+'">'+v.description+'</label></div></div>';
                                            }
                                        });
                                        _html+='<div class="clearfix"></div>';
                                        $("#windows_disk_error .modal-body").html(_html);
                                        $("#windows_disk_error .unsuspendReload").show();
                                        $("#windows_disk_error .unsuspendReload").html('{$_LANG['ipmi_layer_content_os_error10'] }');
                                        $("#windows_disk_error .stopReload").html('{$_LANG['ipmi_layer_content_os_cancel2'] }');
                                        $("#windows_disk_error .stopReload").removeClass("red-700");
                                    }
                                    $("#windows_disk_error .stopReload").data('id', data.id)
                                    $("#windows_disk_error .unsuspendReload").data('id', data.id)
                                    $("#windows_disk_error").modal("show");
                                    show_time++;
                                }
                            }else{
                                if(show_time == 1){
                                    $("#windows_disk_error").modal("hide");
                                    $("#windows_disk_error input[name='id']").val('');
                                    $("#windows_disk_error .modal-body").html('');
                                    show_time = 0
                                }
                            }
                        }else{
                            if(show_time == 1){
                                $("#windows_disk_error").modal("hide");
                                $("#windows_disk_error input[name='id']").val('');
                                $("#windows_disk_error .modal-body").html('');
                                show_time = 0
                            }
                        }
                    }else{
                        if($("#ModuleChooseUser").length>0){
                            $("#ModuleChooseUser").modal("hide");
                        }
                        $(".reload_status").remove();
                        clearInterval(reload_status_interval);
                    }
                },"json");
            }, 5000);
        }

        $('#btnRescue').click(function(){
            $("#ModuleRescue").modal({backdrop: 'static', show:true});
        })

        $(document).on('click', '.rescue', function(){
            var rescue = $("#ModuleRescue").find("select[name=rescue]").val();
            var system = $("#ModuleRescue").find("select[name=system]").val();
            var _this = $(this)
            
            if(_this.data('submit')){
                return;
            }
            _this.data('submit', 'submit').html('{$_LANG['ipmi_layer_content_os_operation']}');
            $.post(base_url, {rescue: rescue, system: system, ipmi_rescue: 'true'}, function(data){
                _this.removeData("submit");
                _this.text("{$_LANG['ipmi_layer_confirm']}");
                if(data.status == "error"){      
                    $("#ModuleRescue .error_text").show();
                    $("#ModuleRescue .error_text").html(data.msg);
                }else{
                    alert(data.msg);
                    $("#ModuleRescue .error_text").hide();
                    $("#ModuleRescue").hide();
                    location.reload(); 
                }                               
            },"json");
        })

        $('#btnCrack').click(function(){
            $("#ModuleCrack").find('input[name="crack_password"]').val(randomString());
            $("#ModuleCrack").modal({backdrop: 'static', show:true});
        })
        
        $(document).on('click', '#ModuleCrack .crack', function(){
            var _this = $(this)
            var crack_password = $('#ModuleCrack').find('input[name="crack_password"]').val()
            var other_user = $('#ModuleCrack').find('input[name="other_user"]').is(":checked") ? 1 : 0;
            var user = $('#ModuleCrack').find('input[name="user"]').val()
            if(_this.data('submit')){
                return;
            }
            if(other_user == 1 && !!user && !/^[^@\s\u4e00-\u9fa5]+$/.test(user)){
                alert('{$_LANG['ipmi_layer_content_os_error12'] }');return;
            }
            _this.data('submit', 'submit').html('{$_LANG['ipmi_layer_content_os_operation']}');
            $.post(base_url, {ipmi_crack: 'true', password: crack_password, other_user: other_user, user: user}, function(data){
                _this.removeData("submit");
                _this.text("{$_LANG['ipmi_layer_confirm']}");
                if(data.status == "error"){      
                    alert(data.msg);
                }else{
                    alert(data.msg);
                    location.reload();
                }               
            },"json");
        })

        $(document).on('click', '#ModuleChooseUser .choose_user', function(){
            var user = $('#ModuleChooseUser').find('select[name=user]').val();
            var password = $('#ModuleChooseUser').find('input[name=crack_password]').val();
            var _this = $(this)

            if(!user){
                alert('{$_LANG['ipmi_layer_content_os_error11'] }');
                return;
            }
            
            if(_this.data('submit')){
                return;
            }
            _this.data('submit', 'submit').html('{$_LANG['ipmi_layer_content_os_operation']}');
            $.post(base_url, {user: user, password: password, action: 'chooseUser', ipmi_crack: 'true'}, function(data){
                _this.removeData("submit");
                _this.text("{$_LANG['ipmi_layer_confirm']}");
                if(data.status == "error"){      
                    alert(data.msg);
                }else{
                    alert(data.msg);
                }  
                location.reload();             
            },"json");
        })

        function randomString() {
        　　var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var maxPos = chars.length;
            var pwd = '';
            for (i = 0; i < 3; i++) {
                pwd += chars.charAt(Math.floor(Math.random() * maxPos));
            }
            var chars = "abcdefghijklmnopqrstuvwxyz";
            var maxPos = chars.length;
            for (i = 0; i < 3; i++) {
                pwd += chars.charAt(Math.floor(Math.random() * maxPos));
            }
            var chars = "123456789";
            var maxPos = chars.length;
            for (i = 0; i < 2; i++) {
                pwd += chars.charAt(Math.floor(Math.random() * maxPos));
            }
            return pwd;
        }

        function checkOsPass(str){
            var preg = /[^0-9A-Za-z`~!@#$%^&*()\-_=+\[\]{}|\:;'",.<>?/]/;
            if(preg.test(str) || str.length<6){
                return false;
            }else{
                var strength=0;
                preg = /[0-9]/;
                if(preg.test(str)){
                    strength++;
                }
                preg = /[A-Z]/;
                if(preg.test(str)){
                    strength++;
                }
                preg = /[a-z]/;
                if(preg.test(str)){
                    strength++;
                }

                preg = /[`~!@#$%^&*()\-_=+\[\]{}|\:;'",.<>?/]/;
                if(preg.test(str)){
                    strength++;
                }

                if(strength<3){
                    return false;
                }
            }
            return true;
        }
    </script>
HTML;
}
//管理区信息输出
function ipmi_admin_area($params){
	global $_LANG;
    $ipmiType = $params['configoption1'];
    $serviceid = $params['serviceid'];
    $customData = ipmi_GetCustomIpmi($serviceid);
    $ipmi_id = $customData['ipmi_id'];
    $params['ipmi_id'] = $ipmi_id;
    $hosting = getHosting($serviceid);
    $accesshash = serverAccessHash($hosting['server'], $hosting['accesshash']);
    $params['configoption1'] = $hosting['configoption1'];
    if(empty($ipmi_id) || "机柜租用" ==  $ipmiType) {
        $fieldsarray[$_LANG['ipmi_admin_area_field_serverid']] = '<input type="text" name="ipmi_id" size="30" value="'. $ipmi_id .'" />';
        if(!empty($ipmi_id)){
            if($accesshash['adminoutip'] == "on"){
                $assignedips = $hosting['assignedips'];
                if (!empty($assignedips)) {
                    $assignedips = explode("\r\n", $assignedips); 
                    $ip_output = '';
                    foreach ($assignedips as $v) {
                        if (preg_match('/\//', $v)) {    //ip段
                            $ip_output .= '<span>'.$v.'</span><br>';
                        } else {
                            $ip_output .= '<a class="ipmi_assignedips" href="javascript:;">'.$v.'</a><br>';
                        }
                    }
                }
                $fieldsarray[$_LANG['ipmi_admin_area_field_cabinetip']] = $ip_output.'<textarea style="display:none;" name="assignedips">'.$hosting['assignedips'].'</textarea>';
            }
            $fieldsarray[$_LANG['ipmi_admin_area_field_chart']] .= '<iframe id="flowchart_traffic_iframe" src="clientsservices.php?userid='.$_GET["userid"].'&traffic=true&id='.$serviceid.'" style="width: 100%;border: none;"></iframe>';
        }
        return $fieldsarray;
    } 
    $responses = ipmi_get_adminAreaData($params);

    // 电源状态
    $power_status = $responses['ipmiPowerSync']; //ipmi_GetPowerStatus($params);
    $status_msg = $power_status['msg'];
    if (empty($ipmi_id)) {
        $ipmi_id = '';
        $status_msg = $_LANG['ipmi_admin_area_status_msg'];  
    } 
    $params["url"] = '?userid='.$hosting["userid"].'&id='.$hosting["id"]."&ipmi_cancellReinstall=true";
    $reinstallStatus = $responses['reinstallStatus']; //ipmi_reinstallStatus($params);
    if (!empty($reinstallStatus['data'])) {
        if($reinstallStatus['data']['windows_finish']){
            $status_msg .= "<span class='reload_status'> ".$_LANG['ipmi_admin_area_reinstall_windows_finish']."</span>";
        }else{
            if($reinstallStatus['data']['task_type'] == 3){
                $info = $_LANG['ipmi_admin_area_reinstall_getinfo1'] ;
                $cancel = $_LANG['ipmi_admin_area_reinstall_cancelinfo1'];
                $span = '';
            }else if($reinstallStatus['data']['task_type'] == 2){
                $info = $_LANG['ipmi_admin_area_reinstall_getinfo2'] ;
                $cancel = $_LANG['ipmi_admin_area_reinstall_cancelinfo2'] ;
                $span = '';
            }else if($reinstallStatus['data']['task_type'] == 1){
                $info = $_LANG['ipmi_admin_area_reinstall_getinfo3'];
                $cancel = $_LANG['ipmi_admin_area_reinstall_cancelinfo3'] ;
                $span = '';
            }else{
                $info = $_LANG['ipmi_admin_area_reinstall_getinfo4'];
                $cancel = $_LANG['ipmi_admin_area_reinstall_cancelinfo4'] ;
                $part_info = [$_LANG['ipmi_admin_area_reinstall_part_info1'] , $_LANG['ipmi_admin_area_reinstall_part_info2'] ];
                $span = $reinstallStatus['data']['name'].','.$_LANG['ipmi_admin_area_reinstall_info1'] .'：disk'.$reinstallStatus['data']['disk'].','.$_LANG['ipmi_admin_area_reinstall_info2'].':'.$part_info[$reinstallStatus['data']['part_type']];
            }
            $status_msg .= "<span class='reload_status'><span style='color:red;'> {$info}：</span>".$span."  ".$_LANG['ipmi_admin_area_reinstall_info3']."：".$reinstallStatus['data']['progress']."% ".$reinstallStatus['data']['step']."  ".$_LANG['ipmi_admin_area_reinstall_info4']."：".$reinstallStatus['data']['time']."  <a href=\"javascript:;\" data-id=\"".$reinstallStatus['data']['id']."\" class=\"stopReload\">{$cancel}</a></span>";
        }
    } 
    $server_detail = $responses['detail'];  //ipmi_Detail($params);
    $detail = $server_detail['server'];
    if(!empty($detail['crack_success_info'])){
        $fieldsarray[$_LANG['ipmi_admin_area_field_crack'] ] = $detail['crack_success_info'];
    }
    $fieldsarray[$_LANG['ipmi_admin_area_field_power_status'] ] = $status_msg;
    $fieldsarray[$_LANG['ipmi_admin_area_field_serverid']] = '<input type="text" name="ipmi_id" size="30" value="' .  $ipmi_id . '" />';
    $fieldsarray[$_LANG['ipmi_admin_area_field_tag']] = '<span>' . $customData['value2'] . '</span>';
    $fieldsarray[$_LANG['ipmi_admin_area_field_panel_password']] = '<input type="text" name="ipmi_panel_pass" size="30" value="'.$customData['value3'].'" />';
    $fieldsarray[$_LANG['ipmi_admin_area_field_port']] = '<span>' . $detail['port'] . '</span>';

    // ip输出
    if($accesshash['adminoutip'] == "on"){
        $dedicatedip = trim($hosting['dedicatedip']);
        $assignedips = $hosting['assignedips'];
        if (!empty($assignedips)) {
            $assignedips = explode("\r\n", $assignedips); 
            $assignedips = array_filter($assignedips); 
            array_unshift($assignedips, $dedicatedip); 
            $ip_output = '<a class="ipmi_assignedips" href="javascript:;" style="color:red;">'.$dedicatedip.'</a><br>';
            foreach ($assignedips as $v) {
                if ($v != $dedicatedip) {
                    if (preg_match('/\//', $v)) {    //ip段
                        $ip_output .= '<span>'.$v.'</span><br>';
                    } else {
                        $ip_output .= '<a class="ipmi_assignedips" href="javascript:;">'.$v.'</a><br>';
                    }
                }
            }
        }
        if($ip_output) $fieldsarray[$_LANG['ipmi_admin_area_field_serverip']] = $ip_output;
    }
    $regdate = ipmi_regdate($hosting['regdate']);
    $params['startDate'] = $regdate['startDate'];
    $params['endDate'] = $regdate['endDate'];
    $host = $params['serverhostname'] ? $params['serverhostname'] : $params['serverip'];
    $params['api_url'] = !empty($hosting['serverport']) ? $host.':'.$hosting['serverport'] : $host;
    $params['disk_num'] = $detail['disk_num'] ?: 1;
    $js = ipmi_AdminAreaPageJS($params);
    if(!empty($server_detail['switch'])){
        $fieldsarray[$_LANG['ipmi_admin_area_field_flow']] = '<span class="ipmi_serverFlow">'.$_LANG['ipmi_admin_area_field_getflow'].'</span>'.$js;
    }else{
        $fieldsarray[$_LANG['ipmi_admin_area_field_port']] .= $js;
    }
    $os = ipmi_os($params);
    $os_option = '<option value="0">'.$_LANG['ipmi_layer_content_select'].'</option>';
    foreach ($os['os'] as $o) {
        if(strpos($o['name'],"救援系统")===false) $os_option .= '<option value="'.$o['id'].'">'.$o['name'].'</option>';
    }
    $rescue_option = '<option value="0">'.$_LANG['ipmi_layer_content_select_rescue'] .'</option>';
    foreach($os['rescue'] as $v){
        $rescue_option .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
    }
    $os_config = (is_array($os['config']) && count($os['config']) > 0) ? json_encode($os['config']) : '""';
    $_html .= '
    <script src="../modules/servers/ipmi/templates/assets/js/partition.js?v=200902"></script>
    <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 class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">'.$_LANG['ipmi_layer_close'].'</span>
                    </button>
                    <h4 class="modal-title" id="ModuleSuspendLabel">'.$_LANG['ipmi_layer_content_os_reos'].'</h4>
                </div>
                <div class="modal-body panel-body">
                    <div class="margin-top-bottom-20" id="provisionHostNew">
                        <div class="form-group  row" style="width: 100%;float: left;">
                            <div class="col-xs-12 col-md-9" style="margin-left: 30px;text-align:left;margin-bottom:10px">
                                <span>'.$_LANG['ipmi_layer_content_os_wltag'].'<font class="wltag" style="color: green;"></font></span>&nbsp;&nbsp;&nbsp;&nbsp;<span>主IP<font class="mainIP" style="color:green;"></font></span>
                            </div>
                        </div>
                        <div class="form-group  row" style="width: 100%;float: left;box-shadow:none">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_os'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <select id="mos" name="mos" class="form-control" style="box-shadow:none">
                                '.$os_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;">'.$_LANG['ipmi_layer_content_os_root_password'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <input type="text" name="passwords" class="form-control" placeholder="" value="xx" autocomplete="off" style="box-shadow:none">
                            </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;">'.$_LANG['ipmi_layer_content_os_port'].'</label>
                            <div class="col-xs-12 col-md-6">
                                <input id="port_imput" type="text" name="port" class="form-control" placeholder="" value="22" maxlength="5" autocomplete="off" style="box-shadow:none">
                            </div>
                            <div class="col-xs-12 col-md-3">
                                <a id="port_random" href="javascript:void(0);" class="btn green btn-primary" style="padding-right: 38px;padding-left: 38px;">'.$_LANG['ipmi_layer_content_os_random'] .'</a>
                            </div>
                        </div>
                        <div class="form-group row part_type" style="width: 100%;float: left;display:none;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_os_partition_type'].'</label>
                            <div class="col-xs-12 col-md-6" style="text-align: left;">
                                <label><input class="radeo" type="radio" name="part_type" value="0">'.$_LANG['ipmi_admin_area_reinstall_part_info1'].'</label>&nbsp;&nbsp;&nbsp;
                                <label><input class="radeo" type="radio" checked="checked" name="part_type" value="1">'.$_LANG['ipmi_admin_area_reinstall_part_info2'].'</label>&nbsp;&nbsp;&nbsp;
                            </div>
                            <div class="col-xs-12 col-md-3">
                                <label>
                                    <input class="check_box" type="checkbox" name="highgrade" value="1">'.$_LANG['ipmi_layer_content_os_senior'].'
                                </label>
                            </div>
                        </div>
                        <div id="select_disk" class="form-group row" style="width: 100%; float: left;display: none;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_os_disk'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <select name="disk" class="form-control">
                                </select>
                            </div>
                        </div>
                        <div class="form-group row part_type_error" style="width: 100%;float: left;display: none;">
                            <label class="col-xs-12 col-md-3 form-control-label"></label>
                            <div class="col-xs-12 col-md-9">
                                <span class="red-700" style="color:red;"></span>
                            </div>
                        </div>
                        <div class="form-group row part_info" 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;">'.$_LANG['ipmi_layer_content_os_partition'].'</label>
                            <div class="col-xs-12 col-md-9 partition" style="text-align: left;">
                                <label>'.$_LANG['ipmi_layer_content_os_partition_default'].'<input type="radio" checked="checked" name="ipmiaction" value="0"></label>&nbsp;&nbsp;&nbsp;
                                <label>'.$_LANG['ipmi_layer_content_os_partition_attach'].'<input type="radio" name="ipmiaction" value="1"></label>&nbsp;&nbsp;&nbsp;
                                <label>'.$_LANG['ipmi_layer_content_os_partition_field'].'<input type="radio" name="ipmiaction" value="2"></label>
                            </div>
                        </div>
                        <div id="mcon" class="form-group row" style="width: 100%;float: left;display:none;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;"></label>
                            <div class="col-xs-12 col-md-9">
                                <select name="mcon" class="form-control" style="box-shadow:none">
                                </select>
                            </div>
                        </div>
                        <div id="mscripts" 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;">'.$_LANG["ipmi_boot_script"].'</label>
                            <div class="col-xs-12 col-md-9">
                                <select name="mscripts" class="form-control">
                                    <option>'.$_LANG['ipmi_layer_content_select'].'</option>
                                </select>
                            </div>
                        </div>
                        <div class="diy_partition_content">
                        
                        </div>
                        <div class="diy_partition_add form-group row" style="width: 100%;float: left;display:none;">
                            <label class="col-xs-12 col-md-3 form-control-label"></label>
                            <div class="col-xs-12 col-md-3" >
                                <button type="button" class="reload_add_part btn btn-sm btn-primary m-b-0">
                                    <span class="text">+</span>
                                </button>
                            </div>
                        </div>
                        <div class="clearfix"></div>            
                    </div>
                    <div id="ipmi_msg" style="padding:0 30px;color:red;"></div>
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary reinstall" style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                            '.$_LANG['ipmi_layer_content_os_confirm'].'
                    </button><button type="button" class="btn btn-default reinstallcal" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                            '.$_LANG['ipmi_layer_cancel'].'
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="cancellReinstall" tabindex="-1" role="dialog" aria-labelledby="cancellReinstall" aria-hidden="false" style="display: none;">
        <div class="modal-dialog">  
            <div class="modal-content panel panel-primary">
                <div id="modalcancellReinstallHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">'.$_LANG['ipmi_layer_close'] .'</span>
                    </button>
                    <h4 class="modal-title" id="cancellReinstallLabel">'.$_LANG['ipmi_layer_confirm2'].'</h4>
                </div>
                <div id="modalcancellReinstallBody" class="modal-body panel-body">
                    '.$_LANG['ipmi_layer_content_os_confirm_cancel'].'
                </div>
                <div id="modalModuleTerminateFooter" class="modal-footer panel-footer">
                    <button type="button"  class="btn btn-primary cancellReinstall" >
                        '.$_LANG['ipmi_layer_yes'] .'
                    </button><button type="button"  class="btn btn-default" data-dismiss="modal">
                        '.$_LANG['ipmi_layer_no'].'
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!-- 重装错误 -->
    <div class="modal fade" id="windows_disk_error" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header clear w100">
                    <h5 class="modal-title"></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <form class="data-form">
                    <div class="modal-body">

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="stopReload btn btn-secondary" data-dismiss="modal">'.$_LANG['ipmi_layer_content_os_cancel'].'</button>
                        <button type="button" class="unsuspendReload btn green btn-primary">'.$_LANG['ipmi_layer_content_os_change'] .'</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="modal fade" id="modalModuleRemind" tabindex="-1" role="dialog" aria-labelledby="ModuleCreateLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content panel panel-primary">
                <div id="modalModuleCreateHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">'.$_LANG['ipmi_layer_close'] .'</span>
                    </button>
                    <h4 class="modal-title">'.$_LANG['ipmi_layer_confirm2'] .'</h4>
                </div>
                <div id="modalModuleRemindBody" class="modal-body panel-body">
                    '.$_LANG['ipmi_layer_content_confirm_info'].'
                </div>
                <div id="modalModuleCreateFooter" class="modal-footer panel-footer">
                    <button type=\'button\' id=\'ModuleRemindConfirm\' class=\'btn btn-primary\' >'.$_LANG['ipmi_layer_yes'].'</button>
                    <button type=\'button\' class=\'btn btn-default\' data-dismiss="modal">'.$_LANG['ipmi_layer_no'].'</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="ModuleRescue" 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="modalModuleRescueHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">'.$_LANG['ipmi_layer_close'] .'</span>
                    </button>
                    <h4 class="modal-title">'.$_LANG['ipmi_layer_content_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;box-shadow:none;display:none;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_rescue_script'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <select name="rescue" class="form-control" style="box-shadow:none">
                                '.$rescue_option.'
                                </select>  
                            </div>
                        </div>
                        <div class="form-group row" style="width: 100%;float: left;box-shadow:none">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_os'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <select name="system" class="form-control" style="box-shadow:none">
                                    <option value="1">Linux</option>
                                    <option value="2">Windows</option>
                                </select>  
                            </div>
                        </div>
                        <div class="clearfix"></div>            
                    </div>
                    <div class="error_text" style="padding:0 30px;"></div>   
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary rescue"      style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                        '.$_LANG['ipmi_layer_confirm'].'
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                        '.$_LANG['ipmi_layer_cancel'].'
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="ModuleCrack" 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="modalModuleCrackHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">'.$_LANG['ipmi_layer_close'] .'</span>
                    </button>
                    <h4 class="modal-title">'.$_LANG['ipmi_admin_area_reinstall_getinfo2'].'</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;text-align:left;">
                            <div class="col-xs-12 col-md-12">'.$_LANG['ipmi_layer_content_crack'].'</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>'.$_LANG['ipmi_layer_content_password'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <input class="form-control" style="box-shadow:none" type="text" name="crack_password" value=""> 
                            </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;">'.$_LANG['ipmi_layer_content_crack_other'].'</label>
                            <div class="col-xs-12 col-md-9" style="text-align:left;">
                                <label class="show_other_user">
                                    <input class="check_box" type="checkbox" name="other_user" value="1">
                                    '.$_LANG['ipmi_layer_content_crack_field'].'
                                </label>
                            </div>
                        </div>
                        <div class="form-group row other_user" style="width: 100%;float: left;display:none;">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_crack_field_user'] .'</label>
                            <div class="col-xs-12 col-md-9">
                                <input type="text" name="user" class="form-control">
                            </div>
                        </div>
                        <div class="clearfix"></div>            
                    </div>
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary crack"      style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                        '.$_LANG['ipmi_layer_confirm'].'
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                        '.$_LANG['ipmi_layer_cancel'] .'
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="ModuleChooseUser" 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="modalModuleRescueHeading" class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                        <span class="sr-only">'.$_LANG['ipmi_layer_close'] .'</span>
                    </button>
                    <h4 class="modal-title">'.$_LANG['ipmi_admin_area_reinstall_getinfo2'] .'</h4>
                </div>
                <input type="hidden" name="crack_password">
                <div class="modal-body panel-body">
                    <div class="margin-top-bottom-20 text-center">
                        <div class="form-group  row" style="width: 100%;float: left;box-shadow:none">
                            <label class="col-xs-12 col-md-3 form-control-label" style="line-height:30px;height:30px;text-align:center;">'.$_LANG['ipmi_layer_content_select_user'].'</label>
                            <div class="col-xs-12 col-md-9">
                                <select id="crackPwdUser" name="user" class="form-control" style="box-shadow:none">
                                </select>  
                            </div>
                        </div>
                        <div class="clearfix"></div>            
                    </div>
                    <div class="error_text" style="padding:0 30px;"></div>   
                </div>
                <div class="modal-footer panel-footer">
                    <button type="button" class="btn btn-primary choose_user"      style="background:#3979f1;border-color:#3979f1;outline:none;box-shadow:none;font-family: “Microsoft YaHei”">
                        '.$_LANG['ipmi_layer_confirm'] .'
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="font-family: “Microsoft YaHei”">
                        '.$_LANG['ipmi_layer_cancel'] .'
                    </button>
                </div>
            </div>
        </div>
    </div>
    <style>
        .error-text {
            left: 100%;
            top: 3px;
            color: #f15533;
            width: 100%;
        }

        .error-btn-color {
            background: #ddd !important;
            border: 1px #ddd solid !important;
            cursor: not-allowed !important;
        }
    </style>
    <div id="reload_windows_default_part" style="display: none;">
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <div class="diy_part form-control">'.$_LANG['ipmi_layer_content_os_partition'] .'0</div>
            </div>
            <div class="col-xs-12 col-md-3">
                <select class="diy_fs form-control">
                    <option value="NTFS">NTFS</option>
                </select>
            </div>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="windows_start_part diy_size form-control" value="51200" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
        </div>
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <div class="diy_part form-control">'.$_LANG['ipmi_layer_content_os_partition'] .'1</div>
            </div>
            <div class="col-xs-12 col-md-3">
                <select class="diy_fs form-control">
                    <option value="NTFS">NTFS</option>
                </select>
            </div>
            <div class="col-xs-12 col-md-2">
                <input type="text" class="diy_size form-control" value="剩余全部" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
            </div>
            <div class="col-md-1 col-xs-1 p-r-5">
                <button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">
                    <span class="text">-</span>
                </button>
            </div>
        </div>
    </div>
    <div id="reload_linux_default_part" style="display: none;">
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="/" disabled style="cursor: not-allowed;">
            </div>
            <div class="col-xs-12 col-md-3">
                <select class="diy_fs form-control">
                    <option value="ext4">ext4</option>
                    <option value="ext3" selected>ext3</option>
                    <option value="ext2">ext2</option>
                    <option value="xfs">xfs</option>
                </select>
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_size form-control" value="51200" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
        </div>
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="/boot">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <select class="diy_fs form-control">
                    <option value="ext4">ext4</option>
                    <option value="ext3" selected>ext3</option>
                    <option value="ext2">ext2</option>
                    <option value="swap">swap</option>
                    <option value="xfs">xfs</option>
                </select>
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-2">
                <input type="text" class="diy_size form-control" value="200" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-md-1 col-xs-1 p-r-5">
                <button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">
                    <span class="text">-</span>
                </button>
            </div>
        </div>
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="swap">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <select class="diy_fs form-control">
                    <option value="ext4">ext4</option>
                    <option value="ext3">ext3</option>
                    <option value="ext2">ext2</option>
                    <option value="swap" selected>swap</option>
                    <option value="xfs">xfs</option>
                </select>
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-2">
                <input type="text" class="diy_size form-control" value="8192" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-md-1 col-xs-1 p-r-5">
                <button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">
                    <span class="text">-</span>
                </button>
            </div>
        </div>
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="/home">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <select class="diy_fs form-control">
                    <option value="ext4">ext4</option>
                    <option value="ext3" selected>ext3</option>
                    <option value="ext2">ext2</option>
                    <option value="swap">swap</option>
                    <option value="xfs">xfs</option>
                </select>
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-2">
                <input type="text" class="diy_size form-control" value="剩余全部" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-md-1 col-xs-1 p-r-5">
                <button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">
                    <span class="text">-</span>
                </button>
            </div>
        </div>
    </div>
    <div id="reload_freebsd_default_part" style="display: none;">
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="/" disabled style="cursor: not-allowed;">
            </div>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_fs form-control" value="ufs" disabled style="cursor: not-allowed;">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_size form-control" value="51200" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
        </div>
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="swap">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_fs form-control" value="ufs" disabled style="cursor: not-allowed;">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-2">
                <input type="text" class="diy_size form-control" value="8192" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-md-1 col-xs-1 p-r-5">
                <button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">
                    <span class="text">-</span>
                </button>
            </div>
        </div>
        <div class="diy_partition 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;"></label>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_part form-control" value="/home">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-3">
                <input type="text" class="diy_fs form-control" value="ufs" disabled style="cursor: not-allowed;">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-xs-12 col-md-2">
                <input type="text" class="diy_size form-control" value="剩余全部" placeholder="'.$_LANG['ipmi_layer_content_capacity'].'">
                <span class="error-text" style="display: none;"></span>
            </div>
            <div class="col-md-1 col-xs-1 p-r-5">
                <button type="button" class="reload_remove_part btn btn-sm btn-primary m-b-0">
                    <span class="text">-</span>
                </button>
            </div>
        </div>
    </div>
    <!-- 分区大小错误 -->
    <div class="modal fade" id="disk_size_error" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header clear w100">
                    <h5 class="modal-title" id="exampleModalLabel">'.$_LANG['ipmi_layer_content_error'] .'</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">   
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary disk_size_edit_btn">'.$_LANG['ipmi_layer_content_capacity_edit'].'</button>
                    <button type="button" class="btn green btn-primary reload_continue_btn">'.$_LANG['ipmi_layer_content_install_go'].'</button>
                </div>
            </div>
        </div>
    </div>';
    $_html .= '
    <script>
        var os_config='.$os_config.';
    </script>';
    if(!empty($server_detail['switch'])){
        $fieldsarray[$_LANG['ipmi_admin_area_field_chart']] .= $_html.'<iframe id="flowchart_traffic_iframe" src="clientsservices.php?userid='.$_GET["userid"].'&traffic=true&id='.$serviceid.'" style="width: 100%;border: none;"></iframe>';
        if(ipmi_showTrafficUsage()){
            $fieldsarray[$_LANG['ipmi_admin_area_field_chart_usage']] = '<script src="../modules/servers/ipmi/templates/assets/js/echarts.min.js?v=200214"></script>
                                <div id="ipmi_traffic_usage">
                                    <div>
                                        <input type="text" value="" class="start form-control date-picker" />
                                        <input type="text" value="" class="end form-control date-picker" />
                                    </div>
                                    <div id="ipmi_traffic_usage_chart" style="min-height:400px;"></div>
                                </div>';
        }
    }else{
        $fieldsarray[$_LANG['ipmi_admin_area_field_port'] ] .= $_html;
    }
    return $fieldsarray;
	
}