Entrance.jsp.bak 48.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="weaver.general.OutterMD5" %>
<%@ page import="weaver.general.SecurityHelper" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.integration.logging.Logger" %>
<%@ page import="weaver.integration.logging.LoggerFactory" %>
<%@ page import="weaver.interfaces.outter.CheckIpNetWork" %>
<%@ page import="weaver.interfaces.outter.OutterUtil" %>

<%@ include file="/systeminfo/init_wev8.jsp" %>

<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="RecordSet1" class="weaver.conn.RecordSet" scope="page" />

<%@ page import="weaver.outter.OutterDisplayHelper"%>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Map" %>
<%@ page import="sun.misc.BASE64Decoder" %>

<%
// 集成日志
Logger newlog = LoggerFactory.getLogger();

String operationType = "";
Enumeration paramList = request.getParameterNames();
if(paramList != null) {
    while(paramList.hasMoreElements()) {
        String tempName = Util.null2String((String) paramList.nextElement());
        if("operationType".equals(tempName)) {
            String tempValue = Util.null2String(request.getParameter(tempName));
            if("test".equals(tempValue)) {
                operationType = tempValue;
            }
        }
    }
}

String sysid = Util.null2String(request.getParameter("id"));// 系统标识
String gopage = Util.null2String(request.getParameter("gopage"));// 登陆后直接显示哪个页面
if("".equals(operationType)) {
    // 权限判断
    // 得到有权限查看的集成登录
    OutterDisplayHelper ohp = new OutterDisplayHelper();
    String sqlright = ohp.getShareOutterSql(user);
    String sql = "select sysid from outter_sys a where sysid='"+sysid+"' and EXISTS (select 1 from ("+sqlright+") b where a.sysid=b.sysid )";
    RecordSet.executeSql(sql);
    
    if(RecordSet.getCounts() < 1) {
        response.sendRedirect("/notice/noright.jsp");
        return;
    }
    
    String account = "";
    String password = "";
    String logintype = "1";// 访问类型,1内网、2外网
    String requesttype = "";// 请求方式,POSTGET
    String encrypttype = "";// 加密算法,0不加密、2自定义加密类、其他的为系统加密类
    
    String encryptclass = "";// 加密类全路径名
    String encryptmethod = "";// 加密方法
    String isneedpwd = "";// 加密类是否需要密钥
    String encryptpwd = "";// 加密密钥
    String isneediv = "";// 加密类是否需要向量
    String ivparam = "";// 加密向量
    
    Object object = null;
    Method methodEncode = null;// 加密方法
    Method methodSetpwd = null;// 设置密钥方法
    Method methodSetiv = null;// 设置向量方法
    
    String baseparam1 = "";// 账号参数名
    int basetype1 = 0;// 是否使用ecology账号
    String urlparaencrypt1 = "";// 是否加密账号参数名
    String encryptcode1 = "";// 账号参数名加密密钥
    String encryptiv1 = "";
    
    String baseparam2 = "";// 密码参数名
    int basetype2 = 0;// 是否使用ecology密码
    String urlparaencrypt2 = "";// 是否加密密码参数名
    String encryptcode2 = "";// 密码参数名加密密钥
    String encryptiv2 = "";
    
    String iurl = "";
    String ourl = "";
    String autologinflag = "";// 是否内外网自动登录
    
    String typename = "";// 集成登录类型
    String urlencodeflag = "";// 地址是否编码
    String encodeflag = "";// 登录系统编码方式,UTF-8GBK
    String entranceurl = "";
    String result = "";
    
    String serverurl = "AccountSetting.jsp?sysid=" + sysid;

    rs.executeSql("select encrypttype from outter_sys where sysid = '"+sysid+"' ");
    if (rs.next()) {
        String  tempEncrypttype = Util.null2String(rs.getString("encrypttype"));
        if("2".equals(tempEncrypttype)) {// 自定义加密类关联outter_encryptclass
            RecordSet.executeSql("select t1.*,t2.encryptclass as encryptclass1,t2.encryptmethod as encryptmethod1,t2.isneedpwd,t2.password,t2.isneediv,t2.ivparam from outter_sys t1 LEFT JOIN outter_encryptclass t2 on t1.encryptclassId = t2.id where sysid = '" + sysid + "' ");
        } else {// 系统加密类关联outter_encryptclass_sys
            RecordSet.executeSql("select t1.*,t2.encryptclass as encryptclass1,t2.encryptmethod as encryptmethod1,t2.isneedpwd,t2.password,t2.isneediv,t2.ivparam from outter_sys t1 LEFT JOIN outter_encryptclass_sys t2 on t1.encrypttype = t2.id where sysid = '" + sysid + "' ");
        }
    }
    if (RecordSet.next()) {
        requesttype = Util.null2String(RecordSet.getString("requesttype"));// 请求方式,POSTGET
        if(requesttype.equals("")) {
            requesttype = "POST";
        }
        encrypttype = Util.null2String(RecordSet.getString("encrypttype"));// 加密类型,0不加密、2自定义加密类、其他的为系统加密类
        
        encryptclass = Util.null2String(RecordSet.getString("encryptclass1"));// 加密类全路径名
        encryptmethod = Util.null2String(RecordSet.getString("encryptmethod1"));// 加密方法
        isneedpwd = Util.null2String(RecordSet.getString("isneedpwd"));
        encryptpwd = Util.null2String(RecordSet.getString("password"));
        if(!"".equals(encryptpwd)) {
            encryptpwd = SecurityHelper.decryptSimple(encryptpwd);
        }
        isneediv = Util.null2String(RecordSet.getString("isneediv"));
        ivparam = Util.null2String(RecordSet.getString("ivparam"));
        if(!"".equals(ivparam)) {
            ivparam = SecurityHelper.decryptSimple(ivparam);
        }
        
        baseparam1 = Util.null2String(RecordSet.getString("baseparam1"));// 账号参数名
        basetype1 = Util.getIntValue(RecordSet.getString("basetype1"),0);// 0用户录入、1使用ecology的账号密码
        urlparaencrypt1 = Util.null2String(RecordSet.getString("urlparaencrypt1"));// 账号参数名是否加密
        encryptcode1 = Util.null2String(RecordSet.getString("encryptcode1"));// 账号参数名加密密钥
        encryptiv1 = Util.null2String(RecordSet.getString("encryptiv1"));
        
        baseparam2 = Util.null2String(RecordSet.getString("baseparam2"));// 密码参数名
        basetype2 = Util.getIntValue(RecordSet.getString("basetype2"),0);// 0用户录入、1使用ecology的账号密码
        urlparaencrypt2 = Util.null2String(RecordSet.getString("urlparaencrypt2"));// 密码参数名是否加密
        encryptcode2 = Util.null2String(RecordSet.getString("encryptcode2"));// 密码参数名加密密钥
        encryptiv2 = Util.null2String(RecordSet.getString("encryptiv2"));
        
        iurl = Util.null2String(RecordSet.getString("iurl"));// 内网地址
        ourl = Util.null2String(RecordSet.getString("ourl"));// 外网地址
        autologinflag = Util.null2String(RecordSet.getString("autologin"));// 内外网自动登录
        
        typename = Util.null2String(RecordSet.getString("typename"));// 集成登录类型
        urlencodeflag = Util.null2String(RecordSet.getString("urlencodeflag"));// 地址是否编码
        encodeflag = Util.null2String(RecordSet.getString("encodeflag"));// 登录系统编码方式,0UTF-81GBK
        entranceurl = Util.null2String(RecordSet.getString("entranceurl"));
        result = Util.null2String(RecordSet.getString("result"));
    }
    
    // 集成登录日志
    String date = TimeUtil.getCurrentDateString();
    String time = TimeUtil.getOnlyCurrentTimeString();
    RecordSet.executeSql("insert into outter_entrance_log(userid,sysid,createdate,createtime) values("+user.getUID()+",'"+sysid+"','"+date+"','"+time+"')") ;
    
    //if("1".equals(typename)) {// NC单点登录
    //  response.sendRedirect("NcEntrance.jsp?id="+sysid);
    //  return;
    //}
    //if("5".equals(typename)) {// NC6单点登录
    //  response.sendRedirect("Nc6Entrance.jsp?id="+sysid);
    //  return;
    //}
    //if("6".equals(typename)) {// QQ邮箱
    //  response.sendRedirect("EntranceQQEmail.jsp?id="+sysid);
    //  return;
    //}
    //if("7".equals(typename)) {// 263邮箱
    //  response.sendRedirect("Entrance_email263.jsp?id="+sysid);
    //  return;
    //}
    
    if(!"".equals(encryptclass) && !"".equals(encryptmethod)) {
        try {
            Class clazz = Class.forName(encryptclass);
            object = clazz.newInstance();
            Class [] paramtype = new Class[1];
            paramtype[0] = java.lang.String.class;
            methodEncode = clazz.getMethod(encryptmethod, paramtype);
            methodSetpwd = clazz.getMethod("setPwd", paramtype);// 设置密钥方法固定为setPwd
            methodSetiv = clazz.getMethod("setIv", paramtype);// 设置向量方法固定为setIv
            
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    RecordSet.executeSql("select account,password,logintype from outter_account where sysid='"+ sysid + "' and userid=" + user.getUID());
    if (RecordSet.next()) {
        account = RecordSet.getString("account");
        password = RecordSet.getString("password");

        // 解密
        String password_new = "";
        if(!password.equals("")) {
            password_new = SecurityHelper.decryptSimple(password);
        }
        if(!password_new.equals("")) {
            password = password_new;
        }
        if (basetype1 == 1) {//使用ecology账号
              account = user.getLoginid();
            //RecordSet rs_loginid = new RecordSet();
            //rs_loginid.executeSql("select loginid from hrmresource where id='"+user.getUID()+"'");
            //rs_loginid.next();
            //account = Util.null2String(rs_loginid.getString(1));
        }
        if (basetype2 == 1) {// 使用ecology密码
            //password = (String) session.getAttribute("password");
            
            password = (String)user.getPwd();//未处理的密码
        }
        
        if(autologinflag.equals("1")) {// 开启内外网自动登录
            CheckIpNetWork checkipnetwork = new CheckIpNetWork();
            String clientIP = request.getRemoteAddr();
            boolean checktmp = checkipnetwork.checkIpSeg(clientIP,sysid);// true表示在网段之外,false表示在网段之内
            if(checktmp) {// true表示在网段之外
                serverurl = ourl;
            } else {
                serverurl = iurl;// false表示在网段之内
            }
        } else {
            logintype = RecordSet.getString("logintype");
            if (logintype.equals("1")) {
                serverurl = iurl;
            } else {
                serverurl = ourl;
            }
        }
    } else {// 对于使用ecology账号和使用ecology密码,自动在outter_account中加入数据,避免用户进入配置页面
        // 使用ecology账号、使用ecology密码,或者同时没有参数名
        if((basetype1 == 1 && basetype2 == 1 && !baseparam1.equals("") && !baseparam2.equals("")) 
            || (baseparam1.equals("") && baseparam2.equals(""))
            || (baseparam1.equals("") && basetype2 == 1 && !baseparam2.equals(""))
            || (baseparam2.equals("") && basetype1 == 1 && !baseparam1.equals(""))) 
        {
            // 参数明细表中参数类型为用户录入的参数数量为0,自动添加数据才可启用
            RecordSet.executeSql("select * from outter_sysparam where paramtype = 1 and sysid='"+ sysid + "' order by indexid");
            if(RecordSet.getCounts() == 0) {
                account = user.getLoginid();
                //password = (String) session.getAttribute("password");
            
                password = (String)user.getPwd();//未处理的密码

                // 插入数据
                RecordSet1.executeSql("insert into outter_account(sysid,userid,logintype,createdate,createtime,modifydate,modifytime) values('"+sysid+"',"+user.getUID()+","+logintype+",'"+date+"','"+time+"','"+date+"','"+time+"')") ;
                // 返回地址
                if(autologinflag.equals("1")) {// 开启内外网自动登录
                    CheckIpNetWork checkipnetwork = new CheckIpNetWork();
                    String clientIP = request.getRemoteAddr();
                    boolean checktmp = checkipnetwork.checkIpSeg(clientIP,sysid);// true表示在网段之外,false表示在网段之内
                    if(checktmp) {// true表示在网段之外
                        serverurl = ourl;
                    } else {
                        serverurl = iurl;// false表示在网段之内
                    }
                } else {
                    if (logintype.equals("1")) {
                        serverurl = iurl;
                    } else {
                        serverurl = ourl;
                    }
                }
            }
        }
    }
    if("6".equals(typename)) {
        response.sendRedirect("EntranceQQEmail.jsp?id="+sysid);
        return;
    }
    //[80][90][客户]集成登录-解决不设置账号、密码参数名选择用户录入单点登录会跳转到账号设置页面的问题
    if((!baseparam1.equals("")&&basetype1 == 0&&"".equals(account))||(!baseparam2.equals("")&&basetype2 == 0&&"".equals(password))){
         serverurl = "/spa/integration/static4engine/engine.html#/main/integration/accountSetting/" + sysid;
    }
    if (serverurl.indexOf("accountSetting") > -1) {// 账号设置页面
        String e9serverurl = "/spa/integration/static4engine/engine.html#/main/integration/accountSetting/"+sysid;
        response.sendRedirect(e9serverurl);
        //response.sendRedirect(serverurl);
        return;
    }
    if(encodeflag.equals("1")) {// 登录系统是GBK编码
        response.sendRedirect("/interface/Entrance_gbk.jsp?id="+sysid);
        return;
    }

    if("1".equals(typename)) {
        response.sendRedirect("NcEntrance.jsp?id="+sysid);
        return;
    }
    if("5".equals(typename)){//NC6系列单点登录
        response.sendRedirect("Nc6Entrance.jsp?id="+sysid);
        return;
    }

    if(!"0".equals(typename)) {
        response.sendRedirect(entranceurl+"?id="+sysid);
        return;
    } else {
        if(!"/interface/Entrance.jsp".equals(entranceurl)) {// 通用类型可以修改单点登录地址
            response.sendRedirect(entranceurl+"?id="+sysid);
            return;
        }
    }
    
    String requesttypestr = requesttype;
    // 自定义加密类以及系统加密类
    if(!"0".equals(encrypttype)) {
        // 账号加密
        if("1".equals(urlparaencrypt1) && !"".equals(account)) {
            if(null != object && null != methodEncode) {
                try {
                    encryptcode1 = "".equals(encryptcode1) ? encryptpwd : encryptcode1;
                    if(null != methodSetpwd && "1".equals(isneedpwd) && !"".equals(encryptcode1)) {
                        Object [] pwd = new Object[1];
                        pwd[0] = encryptcode1;
                        methodSetpwd.invoke(object, pwd);
                    }
                    
                    encryptiv1 = "".equals(encryptiv1) ? ivparam : encryptiv1;
                    if(null != methodSetiv && "1".equals(isneediv) && !"".equals(encryptiv1)) {
                        Object [] iv = new Object[1];
                        iv[0] = encryptiv1;
                        methodSetiv.invoke(object, iv);
                    }
                    
                    Object [] paramvalue = new Object[1];
                    paramvalue[0] = account;
                    account = (String) methodEncode.invoke(object, paramvalue);
                    
                    // 加密异常
                    if(account == null) {
%>                      
                        <script language=javascript >
                            top.Dialog.confirm("<%=SystemEnv.getHtmlLabelName(129643,user.getLanguage()) %>", function() {
                                window.close();
                            }, function() {
                                window.close();
                            }, 320, 90);
                        </script>
<%                      
                        return;
                    }
                    
                    if("-1".equals(result)) {// 加密后小写
                        account = account.toLowerCase();
                    } else if("1".equals(result)) {// 加密后大写
                        account = account.toUpperCase();
                    }
                } catch(Exception e) {
                    newlog.error(" - interface/Entrance.jsp:加密异常,请确认加密方法是否正确,密钥或向量长度是否符合要求", e);
                }
            }
        }
        
        // 密码加密
        if("1".equals(urlparaencrypt2) && !"".equals(password)) {
            if(null != object && null != methodEncode) {
                try {
                    encryptcode2 = "".equals(encryptcode2) ? encryptpwd : encryptcode2;
                    if(null != methodSetpwd && "1".equals(isneedpwd) && !"".equals(encryptcode2)) {
                        Object [] pwd = new Object[1];
                        pwd[0] = encryptcode2;
                        methodSetpwd.invoke(object, pwd);
                    }
                    
                    encryptiv2 = "".equals(encryptiv2) ? ivparam : encryptiv2;
                    if(null != methodSetiv && "1".equals(isneediv) && !"".equals(encryptiv2)) {
                        Object [] iv = new Object[1];
                        iv[0] = encryptiv2;
                        methodSetiv.invoke(object, iv);
                    }
                    
                    Object [] paramvalue = new Object[1];
                    paramvalue[0] = password;
                    password = (String) methodEncode.invoke(object, paramvalue);
                    
                    // 加密异常
                    if(password == null) {
%>                      
                        <script language=javascript >
                            top.Dialog.confirm("<%=SystemEnv.getHtmlLabelName(129643,user.getLanguage()) %>", function() {
                                window.close();
                            }, function() {
                                window.close();
                            }, 320, 90);
                        </script>
<%                      
                        return;
                    }
                    
                    if("-1".equals(result)) {// 加密后小写
                        password = password.toLowerCase();
                    } else if("1".equals(result)) {// 加密后大写
                        password = password.toUpperCase();
                    }
                } catch(Exception e) {
                    newlog.error(" - interface/Entrance.jsp:加密异常,请确认加密方法是否正确,密钥或向量长度是否符合要求", e);
                }
            }
        }
    }
    
    String param_get = "";
    if(serverurl.indexOf("ftp://") > -1) {
        String ftpurl = "ftp://" + account + ":" + password + "@" + serverurl.substring(6);
        response.sendRedirect(ftpurl);
        return;
    } else {
        String str = "<html><body>\n"
                + "<form name=Loginform action='"
                + serverurl
                + "' method="+requesttypestr+" target='_self'><INPUT type='hidden' NAME='gopage' VALUE='"
                + gopage + "'>";
        
        OutterUtil tu1=new OutterUtil();//qc344968 [80][90][客户]集成登录-解决表达式中采用时间戳参数时,每次均会有毫秒级误差的问题
        Map nametoValue =tu1.expressionValueMap(sysid,user,(String)session.getAttribute("password"));
        
        // 其他参数加密
        RecordSet.executeSql("select * from outter_sysparam where sysid='"+ sysid + "' order by indexid");
        while (RecordSet.next()) {
            int paramtype = Util.getIntValue(RecordSet.getString("paramtype"), 0);
            String paramname = RecordSet.getString("paramname");
            String paramvalue = RecordSet.getString("paramvalue");
            String dparaencrypt = RecordSet.getString("paraencrypt");// 是否加密
            String dencryptcode = RecordSet.getString("encryptcode");// 加密密钥
            String dencryptiv = RecordSet.getString("encryptiv");// 加密向量
            if (paramtype == 0) {// 固定值
                
            } else if (paramtype == 1) {// 用户输入
                RecordSet1.executeSql("select * from outter_params where sysid='"
                                + sysid
                                + "' and userid="
                                + user.getUID()
                                + " and paramname='" + paramname + "'");
                if (RecordSet1.next()) {
                    paramvalue = RecordSet1.getString("paramvalue");
                }
                
            } else if (paramtype == 2) {// 分部
                paramvalue = "" + user.getUserSubCompany1();
                
            } else if (paramtype == 3) {// 部门
                paramvalue = "" + user.getUserDepartment();
                
            } else if(paramtype == 4) {// 表达式
                OutterUtil tu = new OutterUtil();
                // paramvalue = tu.getExpressionValue(paramvalue,sysid,user,(String)session.getAttribute("password"));
                paramvalue = tu.getExpressionValue(paramvalue,sysid,user,(String)session.getAttribute("password"),nametoValue);//qc344968 [80][90][客户]集成登录-解决表达式中采用时间戳参数时,每次均会有毫秒级误差的问题
                
            } else if(paramtype == 5) {// 表达式参数
                continue;
            }
            
            // 自定义加密类以及系统加密类
            if(!"0".equals(encrypttype)) {
                if("1".equals(dparaencrypt) && !"".equals(paramvalue)) {
                    if(null != object && null != methodEncode) {
                        try {
                            dencryptcode = "".equals(dencryptcode) ? encryptpwd : dencryptcode;
                            if(null != methodSetpwd && "1".equals(isneedpwd) && !"".equals(dencryptcode)) {
                                Object [] pwd = new Object[1];
                                pwd[0] = dencryptcode;
                                methodSetpwd.invoke(object, pwd);
                            }
                            
                            dencryptiv = "".equals(dencryptiv) ? ivparam : dencryptiv;
                            if(null != methodSetiv && "1".equals(isneediv) && !"".equals(dencryptiv)) {
                                Object [] iv = new Object[1];
                                iv[0] = dencryptiv;
                                methodSetiv.invoke(object, iv);
                            }
                            
                            Object [] paramvalue1 = new Object[1];
                            paramvalue1[0] = paramvalue;
                            paramvalue = (String) methodEncode.invoke(object, paramvalue1);
                            
                            // 加密异常
                            if(paramvalue == null) {
%>                              
                                <script language=javascript >
                                    top.Dialog.confirm("<%=SystemEnv.getHtmlLabelName(129643,user.getLanguage()) %>", function() {
                                        window.close();
                                    }, function() {
                                        window.close();
                                    }, 320, 90);
                                </script>
<%                              
                                return;
                            }
                            
                            if("-1".equals(result)) {// 加密后小写
                                paramvalue = paramvalue.toLowerCase();
                            } else if("1".equals(result)) {// 加密后大写
                                paramvalue = paramvalue.toUpperCase();
                            }
                        } catch(Exception e) {
                            newlog.error(" - interface/Entrance.jsp:加密异常,请确认加密方法是否正确,密钥或向量长度是否符合要求", e);
                        }
                    }
                }
            }
            
            
            str += "<INPUT type='hidden' NAME='" + paramname + "' VALUE='"+  paramvalue+ "'>";
            param_get+=(param_get.length()==0?"":"&")+paramname+"="+encodestr(paramvalue,urlencodeflag);
        }
        
        if(!"".equals(baseparam1)) {
            str += "<INPUT type='hidden' NAME='" + baseparam1 + "' VALUE='" + account+ "'>" ;
            param_get+=(param_get.length()==0?"":"&")+baseparam1+"="+encodestr(account,urlencodeflag)+"";
        }
        if(!"".equals(baseparam2)) {
            str += "<INPUT type='hidden' NAME='" + baseparam2 + "' VALUE='" + password + "'>";
            param_get+=(param_get.length()==0?"":"&")+baseparam2+"="+encodestr(password,urlencodeflag)+"";
        }
        
        Enumeration em = request.getParameterNames();
        if(null != em) {
            while(em.hasMoreElements()) {
                String temppname = Util.null2String((String)em.nextElement());
                if(!"id".equals(temppname)&&!"gopage".equals(temppname)) {
                    String temppvalue = Util.null2String(request.getParameter(temppname));
                    str += "<INPUT type='hidden' NAME='" + temppname + "' VALUE='"+ temppvalue + "'>";
                    //param_get+=(param_get.length()==0?"":"&")+temppname+"="+encodestr(temppvalue,urlencodeflag)+"";
                }
            }
        }
        if (sysid.equals("1")) {
            //todo,add yourselves html fields
            str += "</form></body></html>"
                    + "<script>Loginform.submit();</script>";
            out.print(str);
        } else if (sysid.equals("2")) {
            //todo,add yourselves html fields
            str += "</form></body></html>"
                    + "<script>Loginform.submit();</script>";
            out.print(str);
        } else {
            if(requesttypestr.equalsIgnoreCase("POST")) {
                str += "</form></body></html>"
                    + "<script>Loginform.submit();</script>";
                
                //newlog.error("集成登录url_POST:"+str);
                //System.err.println("集成登录url_POST:"+str);
                out.print(str);
            }else if(requesttypestr.equalsIgnoreCase("GET")){
                if (typename.equals("9")) {
                    response.sendRedirect("K3CloudEntrance.jsp?id="+sysid+"&uid="+user.getUID());
                    return;
                }else if (typename.equals("10")) {
                    response.sendRedirect("K3CloudEntranceV2.jsp?id="+sysid+"&uid="+user.getUID());
                    return;
                }
                String url = "";
                if(serverurl.indexOf("?") > -1) {
                    url = serverurl+"&"+param_get;
                } else {
                    if(!"".equals(param_get)) {
                        url = serverurl+"?"+param_get;
                    } else {
                        url = serverurl;
                    }
                }
                
                //newlog.error("集成登录url_GET:"+url);
                //System.err.println("集成登录url_GET:"+url);
                
                out.println("<script language='javascript'>");
                /*QC348480 [80][90][客户]集成登录-解决单点登录选择get方式,选择编码后, 特殊字符出现两次编码的问题 start*/
                //if(urlencodeflag.equals("1")) {// 地址是否编码
                //  out.println("window.location.href=encodeURI('"+url+"')");
                //} else {
                    out.println("window.location.href='"+url+"'");
                //}
                /*QC348480 [80][90][客户]集成登录-解决单点登录选择get方式,选择编码后, 特殊字符出现两次编码的问题 end*/
                out.println("</script>");
            }
        }
    }
    
} else {
    String account = "";
    String password = "";
    
    Map map = new HashMap();
    String subcompanyid1 = "";
    String departmentid = "";
    
    String logintype = "1";// 访问类型,1内网、2外网
    String requesttype = "";// 请求方式,POST或GET
    String encrypttype = "";// 加密算法,0不加密、2自定义加密类、其他的为系统加密类
    
    String encryptclass = "";// 加密类全路径名
    String encryptmethod = "";// 加密方法
    String isneedpwd = "";// 加密类是否需要密钥
    String encryptpwd = "";// 加密密钥
    String isneediv = "";// 加密类是否需要向量
    String ivparam = "";// 加密向量
    
    Object object = null;
    Method methodEncode = null;// 加密方法
    Method methodSetpwd = null;// 设置密钥方法
    Method methodSetiv = null;// 设置向量方法
    
    String baseparam1 = "";// 账号参数名
    String urlparaencrypt1 = "";// 是否加密账号参数名
    String encryptcode1 = "";// 账号参数名加密密钥
    String encryptiv1 = "";
    
    String baseparam2 = "";// 密码参数名
    String urlparaencrypt2 = "";// 是否加密密码参数名
    String encryptcode2 = "";// 密码参数名加密密钥
    String encryptiv2 = "";
    
    String iurl = "";
    String ourl = "";
    String autologinflag = "";// 是否内外网自动登录
    
    String typename = "";// 集成登录类型
    String urlencodeflag = "";// 地址是否编码
    String entranceurl = "";
    String result = "";
    
    String serverurl = "";

    rs.executeSql("select encrypttype from outter_sys where sysid = '"+sysid+"' ");
    if (rs.next()) {
        String  tempEncrypttype = Util.null2String(rs.getString("encrypttype"));
        if("2".equals(tempEncrypttype)) {// 自定义加密类关联outter_encryptclass
            RecordSet.executeSql("select t1.*,t2.encryptclass as encryptclass1,t2.encryptmethod as encryptmethod1,t2.isneedpwd,t2.password,t2.isneediv,t2.ivparam from outter_sys t1 LEFT JOIN outter_encryptclass t2 on t1.encryptclassId = t2.id where sysid = '" + sysid + "' ");
        } else {// 系统加密类关联outter_encryptclass_sys
            RecordSet.executeSql("select t1.*,t2.encryptclass as encryptclass1,t2.encryptmethod as encryptmethod1,t2.isneedpwd,t2.password,t2.isneediv,t2.ivparam from outter_sys t1 LEFT JOIN outter_encryptclass_sys t2 on t1.encrypttype = t2.id where sysid = '" + sysid + "' ");
        }
    }
    if (RecordSet.next()) {
        requesttype = Util.null2String(RecordSet.getString("requesttype"));// 请求方式,POST或GET
        if(requesttype.equals("")) {
            requesttype = "POST";
        }
        encrypttype = Util.null2String(RecordSet.getString("encrypttype"));// 加密类型,0不加密、2自定义加密类、其他的为系统加密类
        
        encryptclass = Util.null2String(RecordSet.getString("encryptclass1"));// 加密类全路径名
        encryptmethod = Util.null2String(RecordSet.getString("encryptmethod1"));// 加密方法
        isneedpwd = Util.null2String(RecordSet.getString("isneedpwd"));
        encryptpwd = Util.null2String(RecordSet.getString("password"));
        if(!"".equals(encryptpwd)) {
            encryptpwd = SecurityHelper.decryptSimple(encryptpwd);
        }
        isneediv = Util.null2String(RecordSet.getString("isneediv"));
        ivparam = Util.null2String(RecordSet.getString("ivparam"));
        if(!"".equals(ivparam)) {
            ivparam = SecurityHelper.decryptSimple(ivparam);
        }
        
        baseparam1 = Util.null2String(RecordSet.getString("baseparam1"));// 账号参数名
        urlparaencrypt1 = Util.null2String(RecordSet.getString("urlparaencrypt1"));// 账号参数名是否加密
        encryptcode1 = Util.null2String(RecordSet.getString("encryptcode1"));// 账号参数名加密密钥
        encryptiv1 = Util.null2String(RecordSet.getString("encryptiv1"));
        
        baseparam2 = Util.null2String(RecordSet.getString("baseparam2"));// 密码参数名
        urlparaencrypt2 = Util.null2String(RecordSet.getString("urlparaencrypt2"));// 密码参数名是否加密
        encryptcode2 = Util.null2String(RecordSet.getString("encryptcode2"));// 密码参数名加密密钥
        encryptiv2 = Util.null2String(RecordSet.getString("encryptiv2"));
        
        iurl = Util.null2String(RecordSet.getString("iurl"));// 内网地址
        ourl = Util.null2String(RecordSet.getString("ourl"));// 外网地址
        autologinflag = Util.null2String(RecordSet.getString("autologin"));// 内外网自动登录
        
        typename = Util.null2String(RecordSet.getString("typename"));// 集成登录类型
        urlencodeflag = Util.null2String(RecordSet.getString("urlencodeflag"));// 地址是否编码
        entranceurl = Util.null2String(RecordSet.getString("entranceurl"));
        result = Util.null2String(RecordSet.getString("result"));
    }
    
    StringBuffer sb = new StringBuffer();
    String tempString = Util.null2String(request.getParameter("otherPageUrlString"));
    BASE64Decoder decoder = new BASE64Decoder();
    try {
        byte[] key = decoder.decodeBuffer(tempString);
        tempString = new String(key);
    } catch (Exception e) {
    }
    rs.executeSql("select * from outter_sysparam where paramtype in (0, 4, 5) and  sysid = '" + sysid + "' order by indexid");
    while(rs.next()) {
        String paramname = Util.null2String(rs.getString("paramname"));
        String paramvalue = Util.null2String(rs.getString("paramvalue"));
        map.put(paramname, paramvalue);
        sb.append(paramname).append("=").append(paramvalue).append("&");
    }
    sb.append(tempString);

    if(!"".equals(encryptclass) && !"".equals(encryptmethod)) {
        try {
            Class clazz = Class.forName(encryptclass);
            object = clazz.newInstance();
            Class [] paramtype = new Class[1];
            paramtype[0] = java.lang.String.class;
            methodEncode = clazz.getMethod(encryptmethod, paramtype);
            methodSetpwd = clazz.getMethod("setPwd", paramtype);// 设置密钥方法固定为setPwd
            methodSetiv = clazz.getMethod("setIv", paramtype);// 设置向量方法固定为setIv
            
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    // 集成登录测试传入参数
    Enumeration paramList1 = request.getParameterNames();
    while(paramList1.hasMoreElements()) {
        String tempName = Util.null2String((String) paramList1.nextElement());
        // 分部
        rs.executeSql("select * from outter_sysparam where paramtype = 2 and  sysid = '" + sysid + "' ");
        if(rs.next()) {
            String paramname = Util.null2String(rs.getString("paramname"));
            if(paramname.equals(tempName)) {
                subcompanyid1 = Util.null2String(request.getParameter(tempName));
            }
        }
        // 部门
        rs.executeSql("select * from outter_sysparam where paramtype = 3 and  sysid = '" + sysid + "' ");
        if(rs.next()) {
            String paramname = Util.null2String(rs.getString("paramname"));
            if(paramname.equals(tempName)) {
                departmentid = Util.null2String(request.getParameter(tempName));
            }
        }
        // 账号
        if(baseparam1.equals(tempName)) {
            account = Util.null2String(request.getParameter(tempName));
			account = URLDecoder.decode(account);
        }
        // 密码
        if(baseparam2.equals(tempName)) {
            password = Util.null2String(request.getParameter(tempName));
			password = URLDecoder.decode(password);
        }
        // 访问类型
        if("logintype_sysparam".equals(tempName)) {
            logintype = Util.null2String(request.getParameter(tempName));
        }
        
        if(!"logintype_sysparam".equals(tempName) && !"id".equals(tempName) 
                && !"operationType".equals(tempName) 
                && !"otherPageUrlString".equals(tempName)) {
            String tempValue = Util.null2String(request.getParameter(tempName));
            map.put(tempName, tempValue);
        }
    }
    
    if(autologinflag.equals("1")) {// 开启内外网自动登录
        CheckIpNetWork checkipnetwork = new CheckIpNetWork();
        String clientIP = request.getRemoteAddr();
        boolean checktmp = checkipnetwork.checkIpSeg(clientIP,sysid);// true表示在网段之外,false表示在网段之内
        if(checktmp) {// true表示在网段之外
            serverurl = ourl;
        } else {
            serverurl = iurl;// false表示在网段之内
        }
    } else {
        if (logintype.equals("1")) {
            serverurl = iurl;
        } else {
            serverurl = ourl;
        }
    }

    if(!"0".equals(typename)) {
        response.sendRedirect(entranceurl+"?id="+sysid+"&"+sb.toString());
        return;
    } else {
        if(!"/interface/Entrance.jsp".equals(entranceurl)) {// 通用类型可以修改单点登录地址
            response.sendRedirect(entranceurl+"?"+sb.toString());
            return;
        }
    }
    
    String requesttypestr = requesttype;
    // 自定义加密类以及系统加密类
    if(!"0".equals(encrypttype)) {
        // 账号加密
        if("1".equals(urlparaencrypt1) && !"".equals(account)) {
            if(null != object && null != methodEncode) {
                try {
                    encryptcode1 = "".equals(encryptcode1) ? encryptpwd : encryptcode1;
                    if(null != methodSetpwd && "1".equals(isneedpwd) && !"".equals(encryptcode1)) {
                        Object [] pwd = new Object[1];
                        pwd[0] = encryptcode1;
                        methodSetpwd.invoke(object, pwd);
                    }
                    
                    encryptiv1 = "".equals(encryptiv1) ? ivparam : encryptiv1;
                    if(null != methodSetiv && "1".equals(isneediv) && !"".equals(encryptiv1)) {
                        Object [] iv = new Object[1];
                        iv[0] = encryptiv1;
                        methodSetiv.invoke(object, iv);
                    }
                    
                    Object [] paramvalue = new Object[1];
                    paramvalue[0] = account;
                    account = (String) methodEncode.invoke(object, paramvalue);
                    
                    // 加密异常
                    if(account == null) {
%>                      
                        <script language=javascript >
                            top.Dialog.confirm("<%=SystemEnv.getHtmlLabelName(129643,user.getLanguage()) %>", function() {
                                window.close();
                            }, function() {
                                window.close();
                            }, 320, 90);
                        </script>
<%                      
                        return;
                    }
                    
                    if("-1".equals(result)) {// 加密后小写
                        account = account.toLowerCase();
                    } else if("1".equals(result)) {// 加密后大写
                        account = account.toUpperCase();
                    }
                } catch(Exception e) {
                    newlog.error(" - interface/Entrance.jsp:加密异常,请确认加密方法是否正确,密钥或向量长度是否符合要求", e);
                }
            }
        }
        
        // 密码加密
        if("1".equals(urlparaencrypt2) && !"".equals(password)) {
            if(null != object && null != methodEncode) {
                try {
                    encryptcode2 = "".equals(encryptcode2) ? encryptpwd : encryptcode2;
                    if(null != methodSetpwd && "1".equals(isneedpwd) && !"".equals(encryptcode2)) {
                        Object [] pwd = new Object[1];
                        pwd[0] = encryptcode2;
                        methodSetpwd.invoke(object, pwd);
                    }
                    
                    encryptiv2 = "".equals(encryptiv2) ? ivparam : encryptiv2;
                    if(null != methodSetiv && "1".equals(isneediv) && !"".equals(encryptiv2)) {
                        Object [] iv = new Object[1];
                        iv[0] = encryptiv2;
                        methodSetiv.invoke(object, iv);
                    }
                    
                    Object [] paramvalue = new Object[1];
                    paramvalue[0] = password;
                    password = (String) methodEncode.invoke(object, paramvalue);
                    
                    // 加密异常
                    if(password == null) {
%>                      
                        <script language=javascript >
                            top.Dialog.confirm("<%=SystemEnv.getHtmlLabelName(129643,user.getLanguage()) %>", function() {
                                window.close();
                            }, function() {
                                window.close();
                            }, 320, 90);
                        </script>
<%                      
                        return;
                    }
                    
                    if("-1".equals(result)) {// 加密后小写
                        password = password.toLowerCase();
                    } else if("1".equals(result)) {// 加密后大写
                        password = password.toUpperCase();
                    }
                } catch(Exception e) {
                    newlog.error(" - interface/Entrance.jsp:加密异常,请确认加密方法是否正确,密钥或向量长度是否符合要求", e);
                }
            }
        }
    }
    
    String param_get = "";
    if(serverurl.indexOf("ftp://") > -1) {
        String ftpurl = "ftp://" + account + ":" + password + "@" + serverurl.substring(6);
        response.sendRedirect(ftpurl);
        return;
    } else {
        String str = "<html><body>\n"
                + "<form name=Loginform action='"
                + serverurl
                + "' method="+requesttypestr+" target='_self'><INPUT type='hidden' NAME='gopage' VALUE='"
                + gopage + "'>";
        
        // 其他参数加密
        RecordSet.executeSql("select * from outter_sysparam where sysid='"+ sysid + "' order by indexid");
        while (RecordSet.next()) {
            int paramtype = Util.getIntValue(RecordSet.getString("paramtype"), 0);
            String paramname = RecordSet.getString("paramname");
            String paramvalue = RecordSet.getString("paramvalue");
            String dparaencrypt = RecordSet.getString("paraencrypt");// 是否加密
            String dencryptcode = RecordSet.getString("encryptcode");// 加密密钥
            String dencryptiv = RecordSet.getString("encryptiv");// 加密向量
            if (paramtype == 0) {// 固定值
                
            } else if (paramtype == 1) {// 用户输入
                paramvalue = Util.null2String(request.getParameter(paramname));
				 paramvalue = URLDecoder.decode(paramvalue);
                
            } else if (paramtype == 2) {// 分部
                paramvalue = subcompanyid1;
                
            } else if (paramtype == 3) {// 部门
                paramvalue = departmentid;
                
            } else if(paramtype == 4) {// 表达式
                OutterUtil outterUtil = new OutterUtil();
                paramvalue = outterUtil.getExpressionValue2(paramvalue, sysid, map, subcompanyid1, departmentid);
                
            } else if(paramtype == 5) {// 表达式参数
                continue;
            }
            
            // 自定义加密类以及系统加密类
            if(!"0".equals(encrypttype)) {
                if("1".equals(dparaencrypt) && !"".equals(paramvalue)) {
                    if(null != object && null != methodEncode) {
                        try {
                            dencryptcode = "".equals(dencryptcode) ? encryptpwd : dencryptcode;
                            if(null != methodSetpwd && "1".equals(isneedpwd) && !"".equals(dencryptcode)) {
                                Object [] pwd = new Object[1];
                                pwd[0] = dencryptcode;
                                methodSetpwd.invoke(object, pwd);
                            }
                            
                            dencryptiv = "".equals(dencryptiv) ? ivparam : dencryptiv;
                            if(null != methodSetiv && "1".equals(isneediv) && !"".equals(dencryptiv)) {
                                Object [] iv = new Object[1];
                                iv[0] = dencryptiv;
                                methodSetiv.invoke(object, iv);
                            }
                            
                            Object [] paramvalue1 = new Object[1];
                            paramvalue1[0] = paramvalue;
                            paramvalue = (String) methodEncode.invoke(object, paramvalue1);
                            
                            // 加密异常
                            if(paramvalue == null) {
%>                              
                                <script language=javascript >
                                    top.Dialog.confirm("<%=SystemEnv.getHtmlLabelName(129643,user.getLanguage()) %>", function() {
                                        window.close();
                                    }, function() {
                                        window.close();
                                    }, 320, 90);
                                </script>
<%                              
                                return;
                            }
                            
                            if("-1".equals(result)) {// 加密后小写
                                paramvalue = paramvalue.toLowerCase();
                            } else if("1".equals(result)) {// 加密后大写
                                paramvalue = paramvalue.toUpperCase();
                            }
                        } catch(Exception e) {
                            newlog.error(" - interface/Entrance.jsp:加密异常,请确认加密方法是否正确,密钥或向量长度是否符合要求", e);
                        }
                    }
                }
            }
            
            
            str += "<INPUT type='hidden' NAME='" + paramname + "' VALUE='"+  paramvalue+ "'>";
            param_get+=(param_get.length()==0?"":"&")+paramname+"="+encodestr(paramvalue,urlencodeflag);
        }
        
        if(!"".equals(baseparam1)) {
            str += "<INPUT type='hidden' NAME='" + baseparam1 + "' VALUE='" + account+ "'>" ;
            param_get+=(param_get.length()==0?"":"&")+baseparam1+"="+encodestr(account,urlencodeflag)+"";
        }
        if(!"".equals(baseparam2)) {
            str += "<INPUT type='hidden' NAME='" + baseparam2 + "' VALUE='" + password + "'>";
            param_get+=(param_get.length()==0?"":"&")+baseparam2+"="+encodestr(password,urlencodeflag)+"";
        }
        if(requesttypestr.equalsIgnoreCase("POST")) {
            str += "</form></body></html>"
                + "<script>Loginform.submit();</script>";
            
            //newlog.error("集成登录测试url_POST:"+str);
            //System.err.println("集成登录测试url_POST:"+str);
            out.print(str);
            
        } else if(requesttypestr.equalsIgnoreCase("GET")) {
            String url = "";
            if(serverurl.indexOf("?") > -1) {
                url = serverurl+"&"+param_get;
            } else {
                if(!"".equals(param_get)) {
                    url = serverurl+"?"+param_get;
                } else {
                    url = serverurl;
                }
            }
            
            //newlog.error("集成登录测试url_GET:"+url);
            //System.err.println("集成登录测试url_GET:"+url);
            
            out.println("<script language='javascript'>");
            /*QC348480 [80][90][客户]集成登录-解决单点登录选择get方式,选择编码后, 特殊字符出现两次编码的问题 start*/
            //if(urlencodeflag.equals("1")) {// 地址是否编码
            //  out.println("window.location.href=encodeURI('"+url+"')");
            //} else {
                out.println("window.location.href='"+url+"'");
            //}
            /*QC348480 [80][90][客户]集成登录-解决单点登录选择get方式,选择编码后, 特殊字符出现两次编码的问题 end*/
            out.println("</script>");
        }
    }
    
}

%>



<%!
public String encodestr(String str, String flag) {
    if(flag.equals("1")) {
        return java.net.URLEncoder.encode(str);
    } else {
        return str;
    }
}
 %>