// JavaScript Document document.charset = "utf-8"; $(document).ready(function () { var lang = $.cookie("language"); if(!lang){ lang = (navigator.language || navigator.browserLanguage).toLowerCase(); } if(lang.indexOf("zh") > -1){ $("#language").val(lang); }else{ lang = lang.split("-")[0]; $("#language").val(lang); } execI18n(lang); getStreamCount(); $("#language").change(function(){ execI18n($(this).val()); }) }); /********************************** 功能: 登陆 对于空密码的设备,UserAuth接口校验存在问题 ***********************************/ function Login() { //用户名为空时提示 if ($('#username').val().length == 0) { $('#username').focus(); showMsg($.i18n.prop('i18n-username-null'), "loginMSG"); return false } var cyDate = 'Username=' + $('#username').val() + '&Password=' + $('#password').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) { var LoginStatus = $(xmlDoc).find('ResponseStatus').eq(0).find('statusCode').eq(0).text(); if ("0" === LoginStatus) { //验证成功 loginLoad(); }else if(LoginStatus === "-17"){ //验证失败,用户名或密码错误 statusCode = 17 showMsg($.i18n.prop('i18n-login-failed'), "loginMSG"); }else{ } }, error: function (xhr, textStatus) { if ("401" != xhr.status) { if ("timeout" == textStatus) { showMsg($.i18n.prop('i18n-link-timeout'), "loginMSG"); } else { showMsg($.i18n.prop('i18n-network-issue'), "loginMSG"); } } } }); } /********************************** 功能: 重置 ***********************************/ function Reset() { $("#username").val("admin"); $("#password").val(""); $("#password").focus(); } /************************************************* Function: loginLoad Description: 初始化登陆数据 **************************************************/ function loginLoad() { $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/Network/Port", type: "GET", username: $('#username').val(), password: $('#password').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) { m_cyUserPwdValue = Base64.encode($('#username').val() + ":" + $('#password').val()); $.cookie('userInfo', m_cyUserPwdValue); $.cookie('stream', $("#streamList").val()); $.cookie('language',$("#language").val()); $.cookie('commandPort', $(xmlDoc).find('Port').eq(0).find('Command').eq(0).text()); $.cookie('rtspPort', $(xmlDoc).find('Port').eq(0).find('RTP').eq(0).text()); window.location.href = "main.html"; }, error: function (xhr, textStatus) { if ("401" != xhr.status){ if ("timeout" == textStatus) { showMsg($.i18n.prop('i18n-link-timeout'), "loginMSG"); }else { showMsg($.i18n.prop('i18n-network-issue'), "loginMSG"); } }else{ showMsg($.i18n.prop('i18n-login-failed'), "loginMSG"); } } }); } /********************************** 功能: 按回车键登录 ***********************************/ $(document).keydown(function(event) { if (event.keyCode === 13) { Login(); } }); var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function (string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } };