<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录界面</title>
</head>

<link rel="stylesheet" href="/js/jquery-clockpicker/assets/css/bootstrap.min_wev8.css">
<script src="/security/js/checkLogin.min.js"></script>
<script src="/js/jquery-clockpicker/assets/js/bootstrap.min_wev8.js"></script>
<script  type="text/javascript" src="/js/rsa/jsencrypt.js"></script>
<script  type="text/javascript" src="/js/rsa/rsa.js"></script>
<%--<script type="text/javascript" src="/js/ecology8/lang/weaver_lang_7_wev8.js"></script>--%>

<style type="text/css">
    .btnclass {
        margin-top:20px!important;
        margin-left:0px!important;
        margin-bottom:10px;
        width:200px;
        height:30px;
    }
    .btnclass {
        border:0px;cursor:pointer;
        background-color:#558ED5;
        color:white;
    }
    .updating {
        font-family:"Microsoft YaHei"!important;
        margin:0px 0 0 0!important;
    }
    #imagediv {
        float:left;
    }
    .updatingnew {
        font-family:"Microsoft YaHei"!important;
        border:1px solid #DBDBDB;
        margin:0px 0 0 0!important;
        width:49.7%;
        position:relative;
    }
    .divleft {
        float:left;
    }
    .divright{
        float:right;
    }
    .imagediv {
        text-align:center;
    }
    .divmargin {
        margin-top:20px!important;
    }
    .content {
        margin-left:15px;
        margin-right:15px;
        margin-top:10px;
    }
    #pro {
        float:left
    }
    .tips{
        width:100%;
        font-weight:bold;
        background-color:#FFFFE0;
        border-radius:15px;
        height:20px;
    }

    .operationmsg {
        background-color:rgb(255, 243, 220);
        border:1px solid;
        border-color:rgb(255, 204, 0);
        border-radius:3px;
        height:200px;
        overflow:auto;
        width:40%;
        margin: 0 auto;
        margin-top:20px;

    }
    .continuebtn{
        color:#FFFFFF;
        font-size: 14px;
        height: 40px;
        width: 170px;
        background-color:rgb(76, 177, 252);
        border: none;
        border-radius: 2px;
        cursor: pointer;
    }

    .continuebtn2{
        color:#FFFFFF;
        font-size: 14px;
        height: 40px;
        width: 170px;
        background-color:rgb(138, 182, 214);
        border: none;
        border-radius: 2px;
        cursor: pointer;
    }


    .sqlerrormsg {
        height:160px;
        width:40%;
        margin:0 auto;
        margin-top:10px;
    }
    .divmid {
        margin: 0 auto;
        text-align:center
    }
    .executesqlmsg {
        height:160px;
        width:40%;
        margin:0 auto;
        margin-top:10px;
    }
    .msgstyle1 {
        font-family: 微软雅黑;
        font-style: normal;
        font-size: 15px;
        text-align: center;
        line-height: normal;
        margin-top:20px;
    }
    .msgstyle2{
        color: #999999;
        text-align: center;
        font-family: 微软雅黑;
        font-style: normal;
        font-size: 12px;
        margin-top:10px;
    }
    .msgnote1 {
        color:#FF9200;
        margin-left:20px;

    }
    .msgnote2 {
        color:#868686;
        margin-left:20px;
        margin-top:0px;
        margin-bottom:0px;
    }
    .btnclass {
        margin-top:50px;
        margin-left:50px;
        widht:300px;
        height:30px;
    }




    .login_title{
        font-size: 17px;
        font-weight: bold;
        border-bottom: 1px solid rgb(185, 185, 185);
        letter-spacing:-1px;
        padding-bottom: 12px;
    }

    .sub_pre{
        margin-top: 35px;
        width: 100%;
        border-bottom: 1px solid rgb(185, 185, 185);
    }

    .login_sub{
        text-align: center;
        letter-spacing: 5px;
        text-indent: 5px;
        display: block;
        width: 80px;
        height: 40px;
        border-radius: 5px;
        margin-top: 20px;
        color: #fff;
        background-color: #428bca;
        text-decoration: none;
        border: none;
        font-size: 18px;
        margin-left: auto;
    }


    .login_box_msg{
        font-size: 14px;
        text-align: center;
        color: #fff;;
        border: 1px solid;
        border-color:rgb(255, 204, 0);
        border-style: dashed;
        border-radius: 5px;
        padding: 8px 50px;
        background-color: rgb(205, 133, 63);

    }

    .login_main{
        width: 470px;
        height: 320px;
        border-radius: 7px;
        justify-content: center;
        align-items: center;
    }

    .login_box{
        overflow: hidden;
    }

    .login_box input{
        width: 100%;
        margin-bottom: 20px;
        outline: none;
        border: 0;
        padding: 10px;
        border-bottom: 2px solid rgb(0, 0, 0);
        background-color: transparent;
        font: 800 15px '';
        color: black;
    }

    .captcha_image {
        width: 200px;
        padding-bottom: 20px;
    }

    .login_box_container{
        display: flex;
    }











    html,body{height:100%}

</style>

<body>

<center>
    <form method="post" action="" class="form-horizontal" role="form" id="form1_login">
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
            <div class="modal-dialog" style="width: 600px;">
                <div class="modal-content">
                    <%--<button type="button" class="close" style="padding:10px 10px 0px 0px;" data-dismiss="modal" aria-hidden="true" onclick="">
                        &times;
                    </button>--%>
                    <div class="modal-header text-left">
                        <span class="glyphicon glyphicon-cog"></span>系统管理员登录二次认证（更新缓存）
                    </div>
                    <div class="modal-body">

                        <div class="operationmsg" style="height:32px!important;font-size: 12px;color:#FF9200;width:400px;margin-top:0px!important;margin-bottom:20px!important;">
                            <img src="/wui/theme/ecologyBasic/skins/default/rightbox/userlog_warning_wev8.gif" style="width:20px;vertical-align:middle;line-height:30px!important;"></img>
                            <span style="color:#FF9200;line-height:30px!important;vertical-align:middle;" id="msg_show">
						请输入管理员密码二次验证，非管理员不可操作！
						</span><br>
                        </div>

                        <%--<div class="form-group">
                            <label class="col-xs-offset-1 col-xs-2 control-label" for="username">用户名</label>
                            <div class="col-xs-7"><input class="form-control" name="username" type="text" id="username"></div>
                        </div>--%>

                        <div class="form-group" style="display: none">
                            <label class="col-xs-offset-1 col-xs-2 control-label" for="token">token</label>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-offset-1 col-xs-2 control-label" for="password">密  码</label>
                            <div class="col-xs-7"><input class="form-control" name="password" autocomplete="new-password"  id="password" type="password" style="width:100%;" onkeydown="if(event.keyCode == 13){checkall();}"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-offset-1 col-xs-2 control-label" for="username">验证码</label>
                            <div class="col-xs-7">
                                <input class="form-control pull-left" name="username" type="text" id="captcha" style="width: 60%; margin-right: 0px">
                                <img border="0" style="cursor:pointer" class="pull-right" alt="点击刷新验证码" onclick="change()" src="/weaver/weaver.file.MakeValidateCode?notneedvalidate=1" id="captcha01" style="width: 0%;">
                            </div>

                            <%--<div class="col-sm-1">

                            </div>--%>


                            <%--<div class="login_main">
                                <div class="login_title">系统管理员登录二次认证</div>
                                <div class="login_box">
                                    <p class="login_box_msg">请输入管理员密码二次验证，非管理员不可操作！</p>
                                    <input id="userpassword" name="userpassword" type="password" placeholder="密码">
                                    <div class="login_box_container">
                                        <input id="captcha" style="" name="captcha" type="text" placeholder="验证码" style="width: 83px;">
                                        <img alt="" class="captcha_image" src="/weaver/weaver.file.MakeValidateCode?notneedvalidate=1" id="captcha01" onclick="change()">
                                    </div>
                                    <p class="sub_pre"></p>
                                    <button class="login_sub" onclick="submitData()">验证</button>
                                </div>
                            </div>--%>


                        </div>






                    </div>
                    <div class="modal-footer">
                        <button type="button" id="get_focus" class="btn btn-primary" onclick="checkall()">确 定</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    </form>
</center>

<script type="text/javascript">

    String.prototype.wec_replaceAll = function (f, e) {
        var reg = new RegExp(f, "g");
        return this.replace(reg, e);
    }

    var diag = null;
    var timeout = null;
    var counter = null;
    var countertime = 10;
    $(document).ready(function(){

    });
    adminLogDialog();
    function adminLogDialog() {
        if(timeout != null) {
            clearTimeout(timeout);
        }
        $("#myModal").modal({backdrop: 'static', keyboard: false});
    }

    function counterFun(id,backupFun){
        if(countertime > 0){
            var initVal = $("#"+id).val();
            var reg = new RegExp('\\(.*S\\)');
            if(initVal.match(reg)){
                initVal = initVal.replace(reg, "("+countertime+"S)");
                $("#"+id).val(initVal);
            } else {
                $("#"+id).val(initVal+"("+countertime+"S)");
            }
            $("#"+id).removeClass("continuebtn");
            $("#"+id).addClass("continuebtn2");
            countertime--;
        } else {

            $("#"+id).removeClass("continuebtn2");
            $("#"+id).addClass("continuebtn");
            //删除计数器
            clearInterval(counter);
            //重置计数器
            countertime = 10;
            //根据函数名得到函数类型
            var func=eval(backupFun);
            //创建函数对象，并调用
            new func();
        }
    };
    function isNormalKeycode(code) {
        if (code >= 48 && code <= 57) {//0-9数字
            return true;
        } else if (code == 110 || code == 190) {//数字点小键盘点
            return true;
        } else if (code >= 96 && code <= 105) {//0-9小键盘
            return true;//0-9 数字和小键盘
        } else if (code >= 65 && code <= 90) {//a-z字母
            return true;
        }
        return fals
    };
    //给input框绑定事件
    function bindinput(likeid) {
        var Regx = /^[A-Za-z0-9]*$/;
        console.log("-------111111111---------");
        var txts = $("input[id^='" + likeid + "']");
        for (var i = 0; i < txts.length; i++) {
            var t = txts[i];
            t.index = i;
            t.onkeyup = function (event) {
                this.value = this.value.replace(/^(.).*$/, '$1').trim();
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (this.value == '' || this.value == undefined) {
                    if(keycode!=8){
                        return;
                    }else{
                        var next = this.index - 1;
                        if (next <0) return;
                        txts[next].focus();
                        txts[next].select();
                        return;
                    }
                } else if ((!Regx.test(this.value) && this.value != '.')||!isNormalKeycode(keycode)) {
                    this.select();
                    return;
                }
                var next = this.index + 1;
                if (next > txts.length - 1) return;
                txts[next].focus();
                txts[next].select();
            }
        }
    };

    function checkall(){

        var RSA_CODE = "";
        var RSA_PUB = "";
        var RSA_FLAG = "";
        jQuery.ajax({
            url:(window.ecologyContentPath||"")+"/rsa/weaver.rsa.GetRsaInfo?ts="+new Date().getTime(),
            type:"get",
            dataType:"json",
            async : false,
            success:function(data){
                //console.log(data);
                RSA_CODE = data.rsa_code;
                RSA_PUB = data.rsa_pub;
                RSA_FLAG = data.rsa_flag;
            }
        });


        var captcha = $('#captcha').val();
        var pwd = $('#password').val();
        //console.log(captcha);
        //console.log(RSA_PUB);

        if (!isEmpty(RSA_PUB)) {
            pwd = replaceStr(__RSAEcrypt__.rsa_data_encrypt(pwd)) + "_check_";
        }
        //console.log(pwd);

        $.ajax({
            url:(window.ecologyContentPath||"")+'/security/login/secondLoginCheck.jsp',
            type: "POST",
            async : false,
            data:{
                userpassword:pwd,
                validatecode:captcha,
            },
            success(data){
                //console.log(data.trim());
                data = data.trim();
                if(data === "1"){
                    console.log("1");
                    location.reload();
                }else {
                    console.log("2");
                    $('#password').val('');
                    $('#captcha').val('');
                    //alert("1111");
                    if (data.indexOf('<html>') != -1) {
                        $('#msg_show').html("错误次数达到上限，凭证已注销，需重新到登录页面登录！");
                    } else {
                        $('#msg_show').html(data + "！");
                    }

                    change();
                }
            }
        })


    }

    function isEmpty(str) {
        return (!str || str.length === 0 );
    }

    function replaceStr(pwdStr) {

        if (pwdStr.indexOf("+") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("\\+", "_s-s_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("on") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("on", "_s-1_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("oN") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("oN", "_s-2_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("On") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("On", "_s-3_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("ON") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("ON", "_s-4_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("=") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("=", "_s-5_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("0X") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("0X", "_s-6_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("0x") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("0x", "_s-7_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("`") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("`", "_s-8_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("/") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("/", "_s-9_");//防止waf 针对特殊字符的拦截
        }

        if (pwdStr.indexOf("in") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("in", "_s-10_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("iN") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("iN", "_s-11_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("In") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("In", "_s-12_");//防止waf 针对特殊字符的拦截
        }
        if (pwdStr.indexOf("IN") !== -1) {
            pwdStr = pwdStr.wec_replaceAll("IN", "_s-13_");//防止waf 针对特殊字符的拦截
        }

        return pwdStr;
    }

    /*function checkall(){
        var i=0;
        var j=0;
        var errMessage="";
        if(form1_login.username.value=="") {
            errMessage=errMessage+'请输入用户名';
            i=i+1;
        }
        if(form1_login.password.value=="") {
            if(i <= 0) {
                if(errMessage != "") {
                    errMessage=errMessage+'密码';
                } else {
                    errMessage=errMessage+'请输入密码';
                }

            }
            j=j+1;
        }
        if(i>0) {
            $("#msg_show").html(errMessage);
            form1_login.username.focus();
            return false ;
        } else if(j>0){
            $("#msg_show").html(errMessage);
            form1_login.password.focus();
            return false ;
        }
        //提交
        var tusername = form1_login.username.value;
        var tpassword = form1_login.password.value;
        tpassword=__RSAEcrypt__.rsa_data_encrypt(tpassword);
        var timestamp=new Date().getTime();
        $("#msg_show").html('正在验证，请稍等.');
        $.ajax({
            url:"/login/UpgradeAdminLoginOperation.jsp?v="+timestamp,
            type:"post",
            datatype:"json",
            data:{
                username:tusername,
                password:tpassword
            },
            success:function(data){
                var obj=JSON.parse(data);
                var loginstatus=obj.loginstatus;
                var flag=obj.flag;
                var count=obj.count;
                var choices=obj.canloginchoice;
                if(choices>0){
                    canloginchoice=choices;
                }
                if(loginstatus==2){
                    checkall_callback(flag);
                }else{
                    checkall_callback1(flag,count);
                }
            }
        });
    }*/
    //ajax验证用户登录回调函数原先的逻辑
    function checkall_callback(databack){
        var message = databack;//后台返回的信息
        if(message == "0") {
            parent.window.location.reload();
        } else if(message == "2"){
            $("#msg_show").html('该账号无权限！%>');
        }else {//表示用户名或密码不正确
            $("#msg_show").html('账号或密码不正确！');
        }
    }

    function change(){
        var img = document.getElementById("captcha01");
        img.src = (window.ecologyContentPath||"") + "/weaver/weaver.file.MakeValidateCode?notneedvalidate=1&date=" + new Date().getTime();
    }
</script>

</body>
</html>
