You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
6.5 KiB
275 lines
6.5 KiB
var myport = "80"; |
|
var g_check_if_airelay = 1; |
|
|
|
/* |
|
var mymirror = "0"; |
|
var myflip = "0"; |
|
var myrotate = "0"; |
|
*/ |
|
/* |
|
window.addEventListener("mousewheel", (e) => { |
|
if (e.deltaY === 1) { |
|
e.preventDefault(); |
|
} |
|
})*/ |
|
|
|
getIPCamSettings(); |
|
// Restricts input for the given textbox to the given inputFilter. |
|
|
|
function getIPCamSettings() { |
|
var urlStr; |
|
if (g_check_if_airelay == 1) { |
|
urlStr = '/airelay/getipcamsettings'; |
|
} |
|
else { |
|
urlStr = '/getipcamsettings'; |
|
} |
|
|
|
if (localStorage.getItem('IPCAM_PORT') == null) { |
|
$.ajax({ |
|
//url: "/airelay/getipcamsettings", |
|
url: urlStr, |
|
type: "GET", |
|
async: false, |
|
// timeout: 0, |
|
beforeSend: function (xmlHttp) { |
|
xmlHttp.setRequestHeader("If-Modified-Since", "0"); |
|
xmlHttp.setRequestHeader("Cache-Control", "no-cache"); |
|
//xmlHttp.setRequestHeader("Authorization", "Basic " + btoa("username:password")); |
|
}, |
|
success: function (retdata) { |
|
var jsonbuf = JSON.parse(retdata); |
|
|
|
myport = jsonbuf["IPCAM_PORT"]; |
|
localStorage.setItem("IPCAM_PORT", myport); |
|
|
|
/*mymirror = jsonbuf["IPCAM_MIRROR"]; |
|
myflip = jsonbuf["IPCAM_FLIP"]; |
|
myrotate = jsonbuf["IPCAM_ROTATE"]; |
|
*/ |
|
//console.info(retdata); |
|
}, |
|
error: function (retdata) { |
|
console.warn(retdata); |
|
/* |
|
if (localStorage.getItem('IPCAM_PORT') != null) { |
|
myport = localStorage.getItem('IPCAM_PORT'); |
|
}*/ |
|
} |
|
}); |
|
} |
|
else { |
|
myport = localStorage.getItem('IPCAM_PORT'); |
|
} |
|
} |
|
|
|
|
|
get_cgi = function () |
|
{ |
|
if (arguments.length == 0) |
|
{ |
|
return; |
|
} |
|
var ajax = new Array; |
|
var _timeout; |
|
if(window.location.protocol == "http:") |
|
{ |
|
ajax["port"] = myport; |
|
if(arguments[0].port != null) |
|
{ |
|
ajax["port"] = arguments[0].port; |
|
if (ajax["port"] == myport) |
|
ajax["url"] = "http://"+ (document.URL.split('//')[1]).split('/')[0].split(':')[0] + arguments[0].cmd; |
|
else |
|
ajax["url"] = "http://"+ (document.URL.split('//')[1]).split('/')[0].split(':')[0] + ":" + ajax["port"] + arguments[0].cmd; |
|
}else{ |
|
ajax["url"] = "http://"+ (document.URL.split('//')[1]).split('/')[0] + arguments[0].cmd; |
|
} |
|
|
|
} |
|
else |
|
{ |
|
ajax["url"] = "https://"+ (document.URL.split('//')[1]).split('/')[0] + arguments[0].cmd; |
|
} |
|
|
|
//console.log(ajax["url"]); |
|
|
|
ajax["async"] = true; |
|
if (typeof arguments[0].async == "boolean") |
|
{ |
|
ajax["async"] = arguments[0].async; |
|
} |
|
if(arguments[0].timeout != null) |
|
{ |
|
_timeout = arguments[0].timeout; |
|
}else{ |
|
_timeout = 30000; |
|
} |
|
ajax["get_parser"] = arguments[0].get_parser; |
|
ajax["get_response"] = arguments[0].get_response; |
|
if(arguments[0].parameter != null) |
|
{ |
|
ajax["parameter"] = arguments[0].parameter; |
|
} |
|
$.ajax({ |
|
url: ajax["url"], |
|
type: 'GET', |
|
async: ajax["async"], |
|
timeout: _timeout, |
|
cache: false, |
|
error: function (xhr) |
|
{ |
|
if (typeof ajax["get_parser"] == "function") |
|
{ |
|
ajax["get_parser"]("cgi_error"); |
|
} |
|
else if (typeof ajax["get_response"] == "function") |
|
{ |
|
ajax["get_response"]("cgi_error"); |
|
} |
|
}, |
|
success: function (response) |
|
{ |
|
//console.info(response); |
|
if (typeof ajax["get_parser"] == "function") |
|
{ |
|
if(ajax["parameter"] != null) |
|
{ |
|
ajax["get_parser"](parse_key_array_content(response),ajax["parameter"]); |
|
} |
|
else |
|
{ |
|
ajax["get_parser"](parse_key_array_content(response)); |
|
} |
|
} |
|
else if (typeof ajax["get_response"] == "function") |
|
{ |
|
ajax["get_response"](response); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
post_cgi = function() |
|
{ |
|
if (arguments.length == 0) |
|
{ |
|
return; |
|
} |
|
var ajax = new Array; |
|
var _timeout; |
|
|
|
if(window.location.protocol == "http:") |
|
{ |
|
ajax["url"] = "http://"+ (document.URL.split('//')[1]).split('/')[0] + arguments[0].cmd; |
|
} |
|
else |
|
{ |
|
ajax["url"] = "https://"+ (document.URL.split('//')[1]).split('/')[0] + arguments[0].cmd; |
|
} |
|
//console.log(ajax["url"]); |
|
ajax["async"] = true; |
|
if (typeof arguments[0].async == "boolean") |
|
{ |
|
ajax["async"] = arguments[0].async; |
|
} |
|
if(arguments[0].timeout != null) |
|
{ |
|
_timeout = arguments[0].timeout; |
|
}else{ |
|
_timeout = 1900; |
|
} |
|
|
|
ajax["get_parser"] = arguments[0].get_parser; |
|
ajax["post_data"] = arguments[0].post_data; |
|
ajax["get_response"] = arguments[0].get_response; |
|
|
|
$.ajax({ |
|
url: ajax["url"], |
|
data: ajax["post_data"], |
|
dataType: 'text', |
|
type: 'POST', |
|
async: ajax["async"], |
|
timeout: _timeout, |
|
cache: false, |
|
error: function (xhr) |
|
{ |
|
if (typeof ajax["get_parser"] == "function") |
|
{ |
|
ajax["get_parser"]("cgi_error"); |
|
} |
|
else if (typeof ajax["get_response"] == "function") |
|
{ |
|
ajax["get_response"]("cgi_error"); |
|
} |
|
}, |
|
success: function (response) |
|
{ |
|
if (typeof ajax["get_parser"] == "function") |
|
{ |
|
ajax["get_parser"](parse_key_array_content(response)); |
|
} |
|
else if (typeof ajax["get_response"] == "function") |
|
{ |
|
ajax["get_response"](response); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
parse_key_array_content = function(content,options) |
|
{ |
|
var options = $.extend({spliter1: '=', spliter2: '\n'},options); |
|
var result = { all: content }; |
|
var place = content.split(options.spliter2); |
|
var info=new Array; |
|
for (var i=0;i<place.length;i++) |
|
{ |
|
var sepSite = place[i].search(options.spliter1); |
|
if (sepSite!=-1) |
|
{ |
|
var endSite = place[i].search(options.spliter2); |
|
info[2*i] = place[i].slice(0,sepSite); |
|
info[2*i+1] = place[i].slice(sepSite+1,endSite); |
|
} |
|
} |
|
|
|
var key, value, _i, _len; |
|
for (var i = _i = 0, _len = info.length; _i < _len; i = _i += 2) |
|
{ |
|
key = $.trim(info[i]); |
|
value = info[i + 1];//$.trim(info[i + 1]); |
|
if (key !== '') |
|
{ |
|
result[key] = value; |
|
} |
|
} |
|
return result; |
|
} |
|
//common |
|
/*function my_sleep(delay) |
|
{ |
|
var start = new Date().getTime(); |
|
while (new Date().getTime() < start + delay); |
|
};*/ |
|
function TranTextQuoteGV(v) |
|
{ |
|
var Sq_length=v.length; |
|
var o=''; |
|
for(var i=0;i < Sq_length;i++) |
|
{ |
|
if(v.charCodeAt(i)==0x2B)//+ |
|
o+='%2B'; |
|
else if(v.charCodeAt(i)==0x3B)//->; |
|
o+='%3B'; |
|
else if(v.charCodeAt(i)==0x5C)//-> \ |
|
o+='%5C'; |
|
else if(v.charCodeAt(i)==0x2F)// ->/ |
|
o+='%2F'; |
|
else if(v.charCodeAt(i)==0x26)//->& |
|
o+='%26'; |
|
else |
|
o+=v.charAt(i); |
|
} |
|
return o; |
|
}; |