// JavaScript Document document.charset = "utf-8"; var username=""; var password=""; var isSupportComplexd; var streamlist = [ {stream:str_vs_main, value :"1"}, {stream:str_vs_sub, value:"4"}, {stream:str_vs_mo, value:"5"} ]; // 修改密码 function confirmpwd() { if ($("#inpwd").val().length == 0) { $('#inpwd').focus(); errorMsg(str_if_pwd, "umsgpsw"); return false; }; if ($("#againpwd").val().length == 0) { $('#againpwd').focus(); errorMsg(str_if_pwd, "umsgpsw"); return false; }; if ($("#inpwd").val() !== $("#againpwd").val()) { errorMsg(str_if_unifiedpwd, "umsgpsw"); return false; }; var reg = /^(?![^A-z]+$)(?!\D+$)[A-z\d]{9,16}$/; var str = $("#againpwd").val() if (!reg.test(str)) { errorMsg(str_if_pwd_meg, "umsgpsw"); return false; }; var cyXml = "" + "" + "" + "" + $("#username").val() + "" + "" + $("#againpwd").val() + "" + "" + "Normal" + ""; $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/System/Users/1", type: "PUT", username: "admin", password: "", async: true, timeout: 15000, data: cyXml, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success: function (xmlDoc, textStatus, xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("401" ==state) { window.location.href = "/"; } if ("-13" == state) { errorMsg(str_if_unameer, "meg") } else { //errorMsg(str_pass_succ, "meg") $("#forgetpsw").hide(); $("#loginpic2").show(); } }, error: function (xhr, textStatus, errorThrown) { if ("401" == xhr.status) { window.location.href = "/"; } } }); } /********************************** 功能: 登陆 ***********************************/ function Login() { //用户名为空时提示 if ($('#username').val().length == 0) { $('#username').focus(); errorMsg(str_if_user,"umsg"); return false } if (JudgeTextLength($('#username').val()) > 32) { $('#username').focus(); $('#username').val(''); errorMsg(str_if_user_len,"umsg"); return false; } if (JudgeTextLength($('#passwd').val()) > 17) { $('#passwd').focus(); $('#passwd').val(''); errorMsg(str_if_pwd_len,"umsg"); return false; } var cyDate = 'Username=' + $('#username').val() + '&Password=' + $('#passwd').val(); username=$('#username').val(); password=$('#passwd').val(); $.ajax({ url:m_Http + m_HostName + ":" + m_HttpPort + "/Security/UserAuth", type:"PUT", timeout: 15000, data:cyDate, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success:function (xmlDoc, textStatus, xhr){ var statusflg = $(xmlDoc).find('ResponseStatus').eq(0).find('statusCode').eq(0).text(); if (0 == statusflg){//成功登陆 isSupportFaceReco();//是否支持人脸识别 IsFaceSnapshot();//是抓拍机还是识别机 loginLoad(); }else if(statusflg == "-25"){ $("#forgetpsw").show(); $("#inpwd,#againpwd").empty(); errorMsg(str_if_pwd_meg, "umsgpsw"); $("#loginpic2").hide(); } else if (-17 == statusflg){//密码出错 errorMsg(str_if_uperror,"umsg"); }else if ("401" != xhr.status){//其它异常 if ("timeout" == textStatus) {//连接超时 errorMsg(str_if_nouttime,"umsg"); } else {//网络异常 errorMsg(str_if_abnormal,"umsg"); } } }, error:function (xhr, textStatus, errorThrown) { if ("401" != xhr.status){ if ("timeout" == textStatus) { errorMsg(str_if_nouttime,"umsg"); } else { errorMsg(str_if_abnormal,"umsg"); } } } }); } /************************************************* Function: isSupportFaceReco Description: 是否支持人形检测 **************************************************/ function isSupportFaceReco(){ $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/FaceRecognition/Ability", type: "GET", username:username, password:password, async: true, timeout: 15000, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); xhr.setRequestHeader("Cache-Control:no-cache","must-revalidate"); xhr.setRequestHeader("keep-alive","timeout=0, max=1000"); }, success: function (xmlDoc, textStatus, xhr) { var st = $(xmlDoc).find('RecognitionAbility').eq(0).find('isSupportFaceReco').text(); $.cookie('isSupportFaceReco', st); }, error: function (xhr, textStatus, errorThrown) { if ("401" != xhr.status){ if ("timeout" == textStatus) { errorMsg(str_if_nouttime,"umsg"); } else { errorMsg(str_if_abnormal,"umsg"); } } else{ errorMsg(str_if_uperror,"umsg"); } } }); } function IsFaceSnapshot(){ $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/System/DeviceCap", dataType: 'XML', type: "GET", username:username, password:password, async: true, timeout: 15000, beforeSend: function(xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); xhr.setRequestHeader("Cache-Control:no-cache","must-revalidate"); xhr.setRequestHeader("keep-alive","timeout=0, max=1000"); }, success: function(xmlDoc) { var IsFaceSnapshot = $(xmlDoc).find('FaceFunction').eq(0).find('FaceSnapshot').text().toLowerCase(); //抓拍 var IsFaceReco = $(xmlDoc).find('FaceFunction').eq(0).find('FaceReco').text().toLowerCase(); //识别 // var streamcount=$(xmlDoc).find("StreamCount").text(); // $.cookie('streamcount', streamcount); $.cookie('IsFaceSnapshot', IsFaceSnapshot); $.cookie('IsFaceReco', IsFaceReco); }, error: function(xhr, textStatus, errorThrown) { } }); } function loginLoad(){ $.ajax({ url:m_Http + m_HostName + ":" + m_HttpPort + "/Network/Port", type:"GET", async:false, username:$('#username').val(), password:$('#passwd').val(), timeout: 15000, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); xhr.setRequestHeader("Cache-Control:no-cache","must-revalidate"); xhr.setRequestHeader("keep-alive","timeout=0, max=1000"); }, success:function (xmlDoc, textStatus, xhr) { m_cyUserPwdValue = Base64.encode($('#username').val() + ":" + $('#passwd').val()); $.cookie('userInfo', m_cyUserPwdValue); for(var i = 0;i < streamlist.length;i++){ if($("#streamlist").val() == streamlist[i].stream){ var streamvalue = streamlist[i].value; } } $.cookie('strem', streamvalue); $.cookie('commandPort',$(xmlDoc).find('Port').eq(0).find('Command').eq(0).text()); $.cookie('rtspPort',$(xmlDoc).find('Port').eq(0).find('RTP').eq(0).text()); $.cookie('Media', $(xmlDoc).find('Port').eq(0).find('Media').eq(0).text()); kk = "true" if (kk == "true") { // 此时判断密码是否为弱密 getDeviceCap() if (isSupportComplexd == "true") { if ($('#passwd').val() == "") { $("#usernamed").val($("#username").val()) $('#ruopwd').show() $('#loginpic2').hide() return } else { var testpwd = /^(?=.*?[A-Za-z]+)(?=.*?[0-9]+)(?=.*?[A-Z]).{8,16}$/ var flag = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]") var PWD = testpwd.test($('#passwd').val()) var pwds = flag.test($('#passwd').val()) if (PWD == false || pwds == true) { $("#usernamed").val($("#username").val()) $('#ruopwd').show() $('#loginpic2').hide() return } } } } window.location.href = "main.html"; }, error:function (xhr, textStatus, errorThrown) { if ("401" != xhr.status){ if ("timeout" == textStatus) { errorMsg(str_if_nouttime,"umsg"); } else { errorMsg(str_if_abnormal,"umsg"); } } else{ errorMsg(str_if_uperror,"umsg"); } } }); } /********************************** 功能: 计算字符串的长度 参数: szString: 输入的字符串 ***********************************/ function JudgeTextLength(szString) { var iLength = 0; for (var i = 0; i < szString.length; i++) { if (szString.charCodeAt(i) > 255) { iLength += 2; } else { iLength += 1; } } return iLength } /********************************** 功能: 按回车键登录 ***********************************/ document.onkeydown = function (event) { event = event ? event : (window.event ? window.event : null); if (event.keyCode == 13) { Login(); } } // 获取弱密码能力 function getDeviceCap() { $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/System/DeviceCap", type: "GET", async: false, timeout: 15000, beforeSend: function(xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success: function(xmlDoc) { isSupportComplexd = $(xmlDoc).find("RejectEmptyPassword").find("Complex").text().toLowerCase(); }, error: function(xhr) { } }) };