Anyone have a list of CGI Commands for Imporx / Hikvision Speed Domes?

SyconsciousAu

Getting comfortable
Joined
Sep 13, 2015
Messages
872
Reaction score
825
Ok so I am successfully calling presets/PTZ commands on my YC-HD785R-20X using Blue Iris, however I would like to go a bit further and access the CGI protocols in the camera so I can change settings in the camera via http commands.

In a perfect world I would like to set the auto tracking scene, and turn auto tracking on/off by CGI script.

Anyone have a list of CGI Commands?

 
Last edited by a moderator:

SyconsciousAu

Getting comfortable
Joined
Sep 13, 2015
Messages
872
Reaction score
825
Thanks and I may be doing something wrong but the Hikvision commands are not being recognised by the camera.
 

SyconsciousAu

Getting comfortable
Joined
Sep 13, 2015
Messages
872
Reaction score
825
So lets try and work out what the commands are.

So after that gave me no joy I decided to give a man in the middle attack a go and see if I could extrapolate the command protocols the camera was using.

I recorded what was being sent out from the web interface when I clicked the buttons. This is what I got.

POST /ipnc/ HTTP/1.1
Host: 192.168.***.***
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: */*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://192.168.***.***/preview.html
Content-Length: 298
Cookie: yummy_magical_cookie=/ipnc/; language=en; session_id=39636438616231302D643930342D3131; def_ip=192.168.0.99; showPlugin=no; checkPluginVersion=no; userName=admin; password=password; user_level=0; rtsp_port=554; deviceInfo=%7B%22dechannel_cnt%22%3A1%2C%22model%22%3A%22%22%2C%22serial%22%3A%22107D7F5697********%22%2C%22firmware_version%22%3A%22V1.0.2%20Build%20201512171147%22%2C%22software_version%22%3A%22ZoomCam_V1.0.2_build201512170917%22%2C%22alarm_input%22%3A1%2C%22alarm_output%22%3A1%2C%22audio%22%3A1%2C%22harddisk_cnt%22%3A0%2C%22focusType%22%3A0%2C%22rs232%22%3A1%2C%22rs485%22%3A1%2C%22track%22%3A1%2C%22product_type%22%3A2%7D; errCode=passwordError; page=preview.html
Connection: keep-alive

{"header":{"version":101,"seq":0,"peer_type":4001,"local_version":0,"peer_id":"ffffffffffffffff0000000000000001","session_id":"39636438616231302D643930342D3131","tt":"20160222124009","cc":"98a8ea175b7df8ce272d72c742ec35ac27cf9859"},"body":{"cmd":1029,"channel":0,"control":2,"number":1,"title":""}}
HTTP/1.0 200 OK
Via: 1.1 tinyproxy (tinyproxy/1.8.3)
Set-Cookie: yummy_magical_cookie=/ipnc/; path=/
Content-Type: text/plain
Connection: close

{ "body": { "channel": 0 }, "header": { "err_code": 0, "err_message": "", "version": 102 } }
That was when I clicked Preset 1. As you can see the password is sent in plain text, so I wouldnt be logging into these cameras from the wifi at starbucks. The yummy_magical_cookie sounds like something you could buy in a cafe in Amsterdam.

The results for presets two to five were exactly the same with one slight change

{"cmd":1029,"channel":0,"control":2,"number":2,"title":""}
{"cmd":1029,"channel":0,"control":2,"number":3,"title":""}
{"cmd":1029,"channel":0,"control":2,"number":4,"title":""}
{"cmd":1029,"channel":0,"control":2,"number":5,"title":""}
Clicking the PTZ UP control button gave this information in the body

{"cmd":1027,"channel":0,"control":1,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
followed by
{"cmd":1027,"channel":0,"control":0,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
The second one appears to be the stop command as it followed all the movement button clicks twice.

Up Right {"cmd":1027,"channel":0,"control":6,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Right {"cmd":1027,"channel":0,"control":4,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Down Right {"cmd":1027,"channel":0,"control":8,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Down {"cmd":1027,"channel":0,"control":2,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Down Left {"cmd":1027,"channel":0,"control":7,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Left {"cmd":1027,"channel":0,"control":3,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Up Left {"cmd":1027,"channel":0,"control":5,"pan_speed":50,"tilt_speed":50,"zoom_speed":30}
Now I have attempted to use Firefox and CURL to send these commands to the camera however so far, regardless of which method I use, all I get is the login screen.

I've tried the http://USER:PASSWORD@IP ADDRESS:pORT/ method without success.
I also tried http://IP ADDRESS:pORT/User=Admin&Password=Password method.

I am trying to create a URL that will bypass the log in screen, and execute the command in the body. I've probably got the syntax wrong but this is definitely not my area of expertise. If anyone has any ideas on the correct syntax I'm all ears.
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
the authorization credentials are in the cookie, its not using Basic HTTP Auth or you'd see an Authorization: header in there.

going to have to form the cookie and send it in w/the headers it looks like.

i dont think this is really a hikvision if the Hikvision API dont work
 

SyconsciousAu

Getting comfortable
Joined
Sep 13, 2015
Messages
872
Reaction score
825
i dont think this is really a hikvision if the Hikvision API dont work
I thought it might be using at least part of the Hikvision code because I set it to the PTZ protocols in blue iris to hikvision and that got things working.

Interestingly enough the source on the login page makes reference to Huisun which i thought used the Hikvision code as well. If blue iris is using the Hikvision protocol to move tha camera and that is working the Hikvision API should work I would have thought.

Im beginning to suspect my syntax is wrong. I've got a lot of learning to do here.
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
its likely using ONVIF interface and not the same one the webui uses... when I was researching Hunisun HTTP commands I read a report that the plugin does the auth and creates the session, they could not figure out how to create a new session.. I suspect you need to figure out how to auth, retrieve the cookie and then use that for any subsequent commands.

its going to be tricky to reverse engineer, the API is not documented and it looks like they purposely tried to make it difficult to integrate with, so you have a long road ahead..

I found an OnVif NodeJS module that could send in PTZ Commands, that would be the first place I started.. https://github.com/agsh/onvif

but I suspect the ONVIF interface is unlikely to get what you want, and thats changing settings for internal functions on demand.
 

SyconsciousAu

Getting comfortable
Joined
Sep 13, 2015
Messages
872
Reaction score
825
its likely using ONVIF interface and not the same one the webui uses... when I was researching Hunisun HTTP commands I read a report that the plugin does the auth and creates the session, they could not figure out how to create a new session.. I suspect you need to figure out how to auth, retrieve the cookie and then use that for any subsequent commands.

its going to be tricky to reverse engineer, the API is not documented and it looks like they purposely tried to make it difficult to integrate with, so you have a long road ahead..

I found an OnVif NodeJS module that could send in PTZ Commands, that would be the first place I started.. https://github.com/agsh/onvif

but I suspect the ONVIF interface is unlikely to get what you want, and thats changing settings for internal functions on demand.
This will probably mean more to you than it does to me at this point in time but it appears to be a full list of javascript commands for the camera, and, potentially, by the look of things all the Huisun/Imporx cameras.

GET /js/operation.js HTTP/1.1
Host: 192.168.***.***
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: */*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://192.168.***.***/
Cookie: yummy_magical_cookie=/
Connection: keep-alive


HTTP/1.0 200 OK
Via: 1.1 tinyproxy (tinyproxy/1.8.3)
Set-Cookie: yummy_magical_cookie=/; path=/
Content-Type: application/javascript
Server: Boa/0.94.13
Date: Tue, 23 Feb 2016 09:34:09 GMT
Last-Modified: Tue, 01 Dec 2015 06:19:24 GMT
Connection: close
Content-Length: 47879

var protocol_version = 101;
var peer_type = 4001;
var method_key = "cmd";
var operation_key = "operation";
var channel_key = "channel";
var stream_key = "stream";
var protocol_url = "/ipnc/";
var upgrade_config_url = "/uconfig/";
var callback_onkeepalive = null;

this.JSON3 = this.JSON;
this.JSON = false;

var CMD_TYPE_LOGIN = 1001;
var CMD_TYPE_LOGOUT = 1002;
var CMD_TYPE_CAPTURE_MJPEG = 1003;
var CMD_TYPE_FRAME_RATE = 1004;
var CMD_TYPE_NET_CONFIG = 1005;
var CMD_TYPE_KEEP_ALIVE = 1006;
var CMD_TYPE_VIDEO_MASK = 1007;
var CMD_TYPE_CAMERA_PARAMS = 1008;
var CMD_TYPE_USER_MANAGER = 1009;
var CMD_TYPE_SERVICE_PORT = 1010;
var CMD_TYPE_MAC_ADDRESS = 1011;
var CMD_TYPE_DDNS_CONFIG = 1012;
var CMD_TYPE_PPPOE_CONFIG = 1013;
var CMD_TYPE_FTP_CONFIG = 1014;
var CMD_TYPE_UPNP = 1015;
var CMD_TYPE_PORT_MAPPING = 1016;
var CMD_TYPE_REBOOT = 1017;
var CMD_TYPE_RESTORE_CONFIG = 1018;
var CMD_TYPE_DEVICE_NAME = 1019;
var CMD_TYPE_TIME_CONFIG = 1020;
var CMD_TYPE_IRIS_CONFIG = 1021;
var CMD_TYPE_DAYNIGHT_SWITCH = 1022;
var CMD_TYPE_MIRROR_SWITCH = 1023;
var CMD_TYPE_WDR = 1024;
var CMD_TYPE_WHITE_BALANCE = 1026;
var CMD_TYPE_PTZ_MOVE = 1027;
var CMD_TYPE_PTZ_SWITCH = 1028;
var CMD_TYPE_PTZ_PRESET = 1029;
var CMD_TYPE_PTZ_3D = 1030;
var CMD_TYPE_VA_CONFIG = 1031;
var CMD_TYPE_BITRATE_CONFIG = 1032;
var CMD_TYPE_VIDEO_QUALITY = 1033;
var CMD_TYPE_IFRAME_INTERVAL = 1034;
var CMD_TYPE_OSD = 1035;
var CMD_TYPE_PTZ_SCAN = 1036;
var CMD_TYPE_PTZ_SEQUENCE = 1037;
var CMD_TYPE_PTZ_PATTERN = 1038;
var CMD_TYPE_PTZ_GUARD = 1039;
var CMD_TYPE_MOTION_ALARM_CONFIG = 1040;
var CMD_TYPE_MOTION_ALARM_AREA = 1041;
var CMD_TYPE_ALARM_SCHEDULE = 1042;
var CMD_TYPE_ALARM_TRIGGER = 1043;
var CMD_TYPE_PORT_ALARM = 1044;
var CMD_TYPE_SEARCH_LOGS = 1045;
var CMD_TYPE_FORCE_IFRAME = 1046;
var CMD_TYPE_IP_FILTER = 1047;
var CMD_TYPE_IP_FILTER_ENABLE = 1048;
var CMD_TYPE_OUTPUT_DELAY = 1049;
var CMD_TYPE_ANONYMOUS_ACCESS = 1050;
var CMD_TYPE_UPGRADE_PROGRESS = 1051;
var CMD_TYPE_SEARCH_RECORDS = 1052;
var CMD_TYPE_NOISE_REDUCTION = 1053;
var CMD_TYPE_RTSP_AUTHENTICATION = 1054;
var CMD_TYPE_EMAIL_CONFIG = 1055;
var CMD_TYPE_RECORD_SCHEDULE = 1056;
var CMD_TYPE_RECORD_CONFIG = 1057;


var CMD_TYPE_AUDIO_ENCODER = 1059;
var CMD_TYPE_AUDIO_INPUT = 1060;
var CMD_TYPE_VIDEO_MASK_ALARM = 1061;
var CMD_TYPE_IR_LED = 1062;
var CMD_TYPE_SCHEDULE_CAPTURE = 1063;
var CMD_TYPE_STORAGE_QUOTA = 1064;
var CMD_TYPE_VIDEO_SYSTEM = 1065;
var CMD_TYPE_FOCUS_MODE = 1066;
var CMD_TYPE_LOCAL_OUTPUT = 1067;
var CMD_TYPE_RESTORE_CAMERA_PARAMS = 1068;
var CMD_TYPE_FORMAT_DEVICE = 1069;
var CMD_TYPE_EXPORT_CONFIG = 1070;
var CMD_TYPE_GET_STORAGE_DEVICES = 1071;
var CMD_TYPE_GET_DEVICE_VERSION = 1072;
var CMD_TYPE_WIRELESS_LIST = 1073;
var CMD_TYPE_WIFI_DEVICE_INFO = 1074;
var CMD_TYPE_WIRELESS_CONFIG = 1075;
var CMD_TYPE_ROI = 1076;
var CMD_TYPE_AISLE = 1077;
var CMD_TYPE_ZOOM_LIMIT = 1078;
var CMD_TYPE_RS485 = 1079;
var CMD_TYPE_RS232 = 1080;
var CMD_TYPE_TRACK_CONFIG = 1081;
var CMD_TYPE_TRACK_RET_SCENE = 1082;
var CMD_TYPE_TRACK_ENABLE = 1083;
var CMD_TYPE_TEST_FUNCTION = 1084;
var CMD_TYPE_SYS_MOBILE = 1085;
var CMD_TYPE_OSD_LANGUAGE = 1086;
var CMD_TYPE_DEFOG_MODE = 1087;
var CMD_TYPE_SNMP_CONFIG = 1088;
var CMD_TYPE_IDLE_ACTION_CONFIG = 1089;
var CMD_TYPE_IDLE_CAPTURE_SCHEDULE = 1090;

var CMD_TYPE_BIND_SESSION = 2001;
var CMD_TYPE_HEARTBEAT = 2002;
var CMD_TYPE_SERIAL_CONTROL = 2003;
var CMD_TYPE_OPEN_STREAM = 3001;
var CMD_TYPE_MEDIA_HEADER = 3002;
var CMD_TYPE_FRAME_HEADER = 3003;
var CMD_TYPE_SEARCH_DEVICE = 9990;
var CMD_TYPE_ONLINE = 9991;
var CMD_TYPE_OFFLINE = 9992;

var errCode = {
ERR_SUCCESS: 0,
ERR_USER_NOT_EXIST_ERROR: 1001,
ERR_USER_PASSWORD_ERROR: 1002,
ERR_USER_LENGTH_ERROR: 1003,
ERR_SESSION_INVALID: 1004,
ERR_SET_FAILED:1006,
ERR_INSUFFICIENT_PERMISSIONS: 1018,
ERR_IP_REFUSED: 1019,
ERR_USER_EXIST: 1021,
ERR_USER_LIMIT: 1022
};

var OP_TYPE_GET = 0;
var OP_TYPE_SET = 1;

var VEDIO_MASK_MAX = 4;
var MOTION_AREA_V_MAX = 18;

var ptzMove = {
NS_PTZ_MOVE_STOP: 0,
NS_PTZ_MOVE_UP: 1,
NS_PTZ_MOVE_DOWN: 2,
NS_PTZ_MOVE_LEFT: 3,
NS_PTZ_MOVE_RIGHT: 4,
NS_PTZ_MOVE_LEFT_UP: 5,
NS_PTZ_MOVE_RIGHT_UP: 6,
NS_PTZ_MOVE_LEFT_DOWN: 7,
NS_PTZ_MOVE_RIGHT_DOWN: 8,
NS_PTZ_MOVE_ZOOM_TELE: 20,
NS_PTZ_MOVE_ZOOM_WIDE: 21,
NS_PTZ_MOVE_FOCUS_NEAR: 22,
NS_PTZ_MOVE_FOCUS_FAR: 23,
NS_PTZ_MOVE_IRIS_CLOSE: 24,
NS_PTZ_MOVE_IRIS_OPEN: 25,
NS_PTZ_MOVE_RESET_CAMERA: 99
};

var ptzSwitchType = {
LIGHT: 0,
WIPER: 1,
POWER: 2,
AUXILIARY_FOCUS: 3,
HEAT: 4,
DEFOG: 5,
FAN: 6,
length: 7
};

var wifiSafeMode = { Encrypted: 0, WEP: 1, WPA_Personal: 2, WPA_Enterprise: 3, WPA2_Personal: 4, WPA2_Enterprise: 5 };
var storageDeviceType = { SD: 0, HD: 1 };
var storageStatus = { NOT_EXIST: 0, NOT_FORMAT: 1, IN_FORMATTING: 2, UNMOUNTED: 3, MOUNTED: 4, READY: 5 };
var dayNightMode = { DAY: 0, NIGHT: 1, AUTO: 2 };
var ptzPatternType = { SET_START: 1, SET_STOP: 2, DELETE: 3, START: 4, STOP: 5 };
var ptzScanType = { SET_LEFT: 1, SET_RIGHT: 2, SET_SPEED: 3, DELETE: 4, START: 5, STOP: 9999 };
var exposureType = { MANUAL: 0, AUTO: 1, IRIS_FIRST: 2, SHUTTER_FIRST: 3 };
var whiteBalanceType = { AUTO: 0, MANUAL: 1, LOCKED: 2, TEMPLATE: 3 };
var presetControl = { PRESET_ADD: 1, PRESET_CALL: 2, PRESET_DEL: 3 };
var sequenceControl = { ADD: 0, DELETE: 1, DELETE_PRESET: 2, COVER: 3, START: 4, STOP: 5 };
var upgradeStatus = { UPGRADE_NOACTIVE: 0, UPGRADE_STARTED: 1, UPGRADE_IN_PROGRESS: 2 };
var osdType = { OSD_DATETIME: 0, OSD_CHANNEL_NAME: 1, OSD_OVERLAY_TEXT: 2 };
var mirrorType = { MIRROR_NO: 0, MIRROR_UPDOWN: 1, MIRROR_LEFTRIGHT: 2, MIRROR_CENTER: 3 };
var userLevel = { LEVEL_ADMIN: 0, LEVEL_OPERATOR: 1, LEVEL_OBSERVER: 2 };
var alarmType = { ALARM_MOTION: 0, ALARM_MASK: 1, ALARM_PORTIN: 2, ALARM_PORTOUT: 3 };
var alarmPortType = { ALARMPORT_IN: 0, ALARMPORT_OUT: 1 };
var triggerType = { MOTION: 0, MASK: 1, ALARMIN: 2, DISK_FULL: 3, DISK_ERROR: 4, NET_DISCONNECT: 5, IP_CONFLICED: 6 };
var recordType = { SCHEDULE: 0, MOTION: 1, PORT: 2, MOTION_OR_PORT: 3, MOTION_AND_PORT: 4 };
var productType = { BULLET_CAM: 0, MINIPTZ: 1, ZOOM_CAM: 2, DOME: 3 };
var logsSubType = {
ALARM_INPUT_START: 0,
ALARM_INPUT_END: 1,
ALARM_OUTPUT: 2,
ALARM_MOTION_START: 3,
ALARM_MOTION_END: 4,
ALARM_OVERLAY_START: 5,
ALARM_OVERLAY_END: 6,
EXP_DISK_FULL: 100,
EXP_DISK_ERROR: 101,
EXP_NET_DISCONNECTED: 102,
EXP_IP_CONFLICTED: 103,
OP_BOOT: 200,
OP_SHUTDOWN: 201,
OP_REBOOT: 202,
OP_RESTORE: 203,
OP_LOGIN: 204,
OP_LOGOUT: 205,
OP_CONFIG: 206,
OP_UPGRADE: 207,
OP_PTZ: 208,
OP_DISK_FORMAT: 209,
OP_IMPORT_CONFIG: 210,
OP_EXPORT_CONFIG: 211,
OP_MODIFY_TIME: 212,
OP_MODIFY_IP: 213,
OP_FLIPMIRROR: 214,
OP_RESTORE_CAM: 215,
OP_RESTORE_MEDIA: 216,
OP_SET_RES: 217
};
var session_id = "";
var cpPlugin = null;
var keepAliveTimerId = null;

function cpplugin() {
return document.getElementById('plugin0');
}

var getCpPlugin = cpplugin;

function cpGenerate() {
var jsonObj2 = { "header": {}, "body": {} };
var jo_header = jsonObj2.header;
jo_header["version"] = protocol_version;
jo_header["seq"] = 0;
jo_header["peer_type"] = peer_type;
jo_header["local_version"] = 0;
jo_header["peer_id"] = "ffffffffffffffff0000000000000001";
var sid = $.cookie("session_id");
if (typeof (sid) == "undefined" || sid == null) {
session_id = "";
}
else {
session_id = sid;
}
jo_header["session_id"] = session_id;

tt = new Date().Format("yyyyMMddhhmmss");
jo_header["tt"] = tt;

if (getCpPlugin() != null && getCpPlugin().valid) {
jo_header["cc"] = getCpPlugin().nsstpGetCC(tt, session_id);
}
else {
jo_header["cc"] = "";
}

return jsonObj2;
}

function cpParseResponseHead(data) {
var response_obj = JSON3.parse(data);
var obj_body = response_obj.body;
var obj_header = response_obj.header;
if (typeof (response_obj) == "undefined") {
var jsonObj2 = { "header": {}, "body": {} };
var jo_header = jsonObj2.header;
jo_header["err_code"] = 101;
return jsonObj2;
}
return response_obj;
}

function cpLogin(user, password) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_LOGIN;
jbody["user"] = user;
jbody["password"] = $.md5(password);
return JSON3.stringify(jobj);
}

function cpLoginResponse(data) {
var response_obj = JSON3.parse(data);
var obj_body = response_obj.body;
var obj_header = response_obj.header;
if (obj_header["err_code"] == 0) {
session_id = obj_body["session"];
}
return response_obj;
}

function cpForceIFrame(channel, stream) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_FORCE_IFRAME;
jbody[channel_key] = channel;
jbody[stream_key] = stream;
return JSON3.stringify(jobj);
}

function cpSetFrameRate(channel, stream, framerate) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_FRAME_RATE;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = channel;
jbody[stream_key] = stream;
jbody["frame_rate"] = framerate;

return JSON3.stringify(jobj);
}

function cpKeepAlive() {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_KEEP_ALIVE;
return JSON3.stringify(jobj);
}

function cpSetNetConfig(net_config_obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_NET_CONFIG;
jbody[operation_key] = OP_TYPE_SET;

jbody["ipv4_enable"] = net_config_obj.ipv4_enable;
jbody["ipv4_address"] = net_config_obj.ipv4_address;
jbody["ipv4_mask"] = net_config_obj.ipv4_mask;
jbody["ipv4_gateway"] = net_config_obj.ipv4_gateway;
jbody["ipv4_dns_address"] = net_config_obj.ipv4_dns_address;
jbody["ipv4_dhcp_enable"] = net_config_obj.ipv4_dhcp_enable;

jbody["ipv6_enable"] = net_config_obj.ipv6_enable;
jbody["ipv6_address"] = net_config_obj.ipv6_address;
jbody["ipv6_mask"] = net_config_obj.ipv6_mask;
jbody["ipv6_gateway"] = net_config_obj.ipv6_gateway;
jbody["ipv6_dns_address"] = net_config_obj.ipv6_dns_address;
jbody["ipv6_mode"] = net_config_obj.ipv6_mode;

return JSON3.stringify(jobj);
}

function cpSetCameraParams(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_CAMERA_PARAMS;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = obj.channel;
jbody["brightness"] = obj.brightness;
jbody["contrast"] = obj.contrast;
jbody["saturation"] = obj.saturation;
jbody["sharpness"] = obj.sharpness;
jbody["hue"] = obj.hue;
return JSON3.stringify(jobj);
}

function cpSetPortConfig(http_port, rtsp_port, https_port, ns_port) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_SERVICE_PORT;
jbody[operation_key] = OP_TYPE_SET;
jbody["http_port"] = http_port;
jbody["https_port"] = https_port;
jbody["rtsp_port"] = rtsp_port;
jbody["ns_port"] = ns_port;
return JSON3.stringify(jobj);
}

function cpSetSNMPConfig(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
var base64 = new Base64();
jbody[method_key] = CMD_TYPE_SNMP_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable_v1"] = obj.enable_v1;
jbody["enable_v2"] = obj.enable_v2;
jbody["rcommunity"] = obj.rcommunity;
jbody["wcommunity"] = obj.wcommunity;
jbody["trap_host"] = obj.trap_host;
jbody["trap_port"] = parseInt(obj.tarp_port,10);
jbody["trap_community"] = obj.trap_community;
jbody["enable_v3"] = obj.enable_v3;
jbody["rsec_name"] = obj.rsec_name;
jbody["rsec_level"] = parseInt(obj.rsec_level,10);
jbody["rauth_mode"] = obj.rauth_mode;
jbody["rauth_pwd"] = base64.encode(obj.rauth_pwd);
jbody["rpriv_mode"] = obj.rpriv_mode;
jbody["rpriv_pwd"] = base64.encode(obj.rpriv_pwd);
jbody["wsec_name"] = obj.wsec_name;
jbody["wsec_level"] = parseInt(obj.wsec_level,10);
jbody["wauth_mode"] = obj.wauth_mode;
jbody["wauth_pwd"] = base64.encode(obj.wauth_pwd);
jbody["wpriv_mode"] = obj.wpriv_mode;
jbody["wpriv_pwd"] = base64.encode(obj.wpriv_pwd);
jbody["port"] = parseInt(obj.port,10);
return JSON3.stringify(jobj);
}

function cpSetFtpConfig(config_obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_FTP_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["svr_address"] = config_obj.svr_address;
jbody["svr_port"] = config_obj.svr_port;
jbody["user_name"] = config_obj.user_name;
jbody["user_password"] = config_obj.user_password;
jbody["dir_level_count"] = config_obj.dir_level_count;
jbody["dir_level_1"] = config_obj.dir_level_1;
jbody["dir_level_2"] = config_obj.dir_level_2;

return JSON3.stringify(jobj);
}

function cpSetUpnpConfig(enable, alias) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_UPNP;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
jbody["alias"] = alias;

return JSON3.stringify(jobj);
}

function cpGetUpgradeResponse(response_str) {
return parseInt(response_str, 10);
}

function cpRestoreConfig(type) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_RESTORE_CONFIG;
jbody["type"] = type;
return JSON3.stringify(jobj);
}

function cpSetDeviceName(name) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_DEVICE_NAME;
jbody[operation_key] = OP_TYPE_SET;
var base64tool = new Base64();
jbody["name"] = base64tool.encode(name);
return JSON3.stringify(jobj);
}

function cpGetOSD(channel, type) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_OSD;
jbody[operation_key] = OP_TYPE_GET;
jbody[channel_key] = channel;
jbody["type"] = type;
return JSON3.stringify(jobj);
}

function cpSetOSD(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_OSD;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = obj.channel;
jbody["type"] = obj.type;
jbody["enable"] = obj.enable;
jbody["language"] = obj.language;
jbody["pos_x"] = obj.pos_x;
jbody["pos_y"] = obj.pos_y;
if (0 == obj.type) {
jbody["date_format"] = obj.date_format;
jbody["time_format"] = obj.time_format;
}
else {
jbody["text"] = obj.text;
}

return JSON3.stringify(jobj);
}

function cpPTZMove(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_PTZ_MOVE;
jbody[channel_key] = obj.channel;
jbody["control"] = obj.control;
jbody["pan_speed"] = obj.pan_speed;
jbody["tilt_speed"] = obj.tilt_speed;
jbody["zoom_speed"] = obj.zoom_speed;
return JSON3.stringify(jobj);
}

function cpPTZPreset(channel, control, number, title) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_PTZ_PRESET;
jbody[channel_key] = channel;
jbody["control"] = control;
jbody["number"] = number;
jbody["title"] = title;
return JSON3.stringify(jobj);
}

function cpPTZSwitch(channel, type, status) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[operation_key] = OP_TYPE_SET;
jbody[method_key] = CMD_TYPE_PTZ_SWITCH;
jbody[channel_key] = channel;
jbody["type"] = type;
jbody["status"] = status;
return JSON3.stringify(jobj);
}

function cpSetVAConfig(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_VA_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = obj.channel;
jbody[stream_key] = obj.stream;
jbody["stream_type"] = obj.stream_type;
jbody["resolution_w"] = obj.resolution_w;
jbody["resolution_h"] = obj.resolution_h;
jbody["video_encoding"] = obj.video_encoding;

return JSON3.stringify(jobj);
}

function cpGetVAConfig(channel, stream) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_VA_CONFIG;
jbody[operation_key] = OP_TYPE_GET;
jbody[channel_key] = channel;
jbody[stream_key] = stream;
return JSON3.stringify(jobj);
}


function cpCmd(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = obj.method;
jbody[operation_key] = OP_TYPE_GET;
if (obj.channel != null) {
jbody[channel_key] = obj.channel;
}
if (obj.stream != null) {
jbody[stream_key] = obj.stream;
}
return JSON3.stringify(jobj);
}

function cpSetVideoMask(channel, obj, enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_VIDEO_MASK;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = channel;
var areas = { "area": [] };
for (var i = 0; i < obj.length; ++i) {
var area = { px: obj.x, py: obj.y, w: obj.w, h: obj.h, enable: obj.enable };
areas.area.push(area);
}
jbody["area"] = areas.area;
jbody["enable"] = enable;

return JSON3.stringify(jobj);
}

function cpSetMotionAlarmArea(channel, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_MOTION_ALARM_AREA;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = channel;
var areas = { "area": [] };
for (var i = 0; i < obj.length; ++i) {
var area = { v: obj };
areas.area.push(area);
}
jbody["area"] = areas.area;
return JSON3.stringify(jobj);
}

function cpSetMotionAlarmConfig(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_MOTION_ALARM_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = obj.channel;
jbody["enable"] = obj.enable;
jbody["sensitivity"] = obj.sensitivity;

return JSON3.stringify(jobj);
}

function cpSetMirror(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_MIRROR_SWITCH;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = obj.channel;
jbody["type"] = obj.type;

return JSON3.stringify(jobj);
}

function cpUserManager(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_USER_MANAGER;
jbody[operation_key] = OP_TYPE_SET;
jbody["control"] = obj.control;
jbody["user_name"] = obj.user_name;
jbody["new_name"] = obj.new_name;
var base64tool = new Base64();
jbody["user_password"] = base64tool.encode(obj.user_password); //$.md5(obj.user_password);
jbody["user_level"] = obj.user_level;
jbody["per_ch"] = obj.userch;
jbody["per_dev"] = obj.userdev;

return JSON3.stringify(jobj);
}

function cpSetAddUserSchedule() {
var per_ch = [{ video: "", ptz: "", manual_rec: "", playback: ""}];
var per_dev = { set_params: "", load_logs: "", upgrade: "", shutdown: "", alarm: "", vout: "", serial: "", talk: "" };
var usr_per = [per_ch, per_dev];

per_ch[0]["manual_rec"] = document.getElementById("RemoteManualRd").checked ? 1 : 0;
per_ch[0]["playback"] = document.getElementById("RemotePlayBack").checked ? 1 : 0;
per_ch[0]["video"] = document.getElementById("RemotePreview").checked ? 1 : 0;
per_ch[0]["ptz"] = document.getElementById("RemotePTZCtrl").checked ? 1 : 0;
per_dev.load_logs = document.getElementById("RemoteLog").checked ? 1 : 0;
per_dev.talk = document.getElementById("RemoteVtalk").checked ? 1 : 0;
per_dev.alarm = document.getElementById("RemoteAlarm").checked ? 1 : 0;
per_dev.serial = document.getElementById("RemoteRS485").checked ? 1 : 0;
per_dev.set_params = document.getElementById("RemoteSetPamar").checked ? 1 : 0;
per_dev.shutdown = document.getElementById("RemoteReboot").checked ? 1 : 0;
per_dev.upgrade = document.getElementById("RemoteUpgrade").checked ? 1 : 0;
per_dev.vout = document.getElementById("RemoteCtrlOut").checked ? 1 : 0;
return (usr_per);
}

function cpPTZ3D(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_PTZ_3D;
jbody[channel_key] = obj.channel;
jbody["ox"] = obj.ox;
jbody["oy"] = obj.oy;
jbody["width"] = obj.width;
jbody["height"] = obj.height;
jbody["speed"] = obj.speed;
jbody["direction"] = obj.direction;
return JSON3.stringify(jobj);
}

function cpSetIPFilter(control, ip, enable, type) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_IP_FILTER;
jbody[operation_key] = OP_TYPE_SET;
jbody["control"] = control;
var ip_arr = { "iplist": [] };
for (var i = 0; i < ip.length; ++i) {
var info = { ip: ip };
ip_arr.iplist.push(info);
}
jbody["iplist"] = ip_arr.iplist;

if (typeof (enable) != "undefined") {
jbody["enable"] = enable;
}
if (typeof (type) != "undefined") {
jbody["type"] = type;
}

return JSON3.stringify(jobj);
}

function cpSetAnonymous(enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_ANONYMOUS_ACCESS;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
return JSON3.stringify(jobj);
}
function cpSearchRecords(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_SEARCH_RECORDS;
jbody[channel_key] = obj.channel;
jbody["start_time"] = obj.start_time;
jbody["end_time"] = obj.end_time;
jbody["event_type"] = obj.event_type;
jbody["search_type"] = obj.search_type;
jbody["page_start"] = obj.page_start;
jbody["page_count"] = obj.page_count;
return JSON3.stringify(jobj);
}

function cpTimeConfig(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_TIME_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["timezone"] = obj.timezone;
jbody["ntp_enable"] = obj.ntp_enable;
jbody["ntp_address"] = obj.ntp_address;
jbody["ntp_port"] = obj.ntp_port;
jbody["ntp_interval"] = obj.ntp_interval;
jbody["sync_time"] = obj.sync_time;
jbody["apply_to_others"] = obj.apply_to_others;
return JSON3.stringify(jobj);
}

function jumpToMainPage() {
window.parent.location.href = "/index.html";
}
function sessionLogin(result, response_str) {
//alert(result + "-result--response_str-:" + response_str);
if (result == true) {
var login_response = cpLoginResponse(response_str);
var obj_body = login_response.body;
var obj_header = login_response.header;
var err_code = obj_header["err_code"];
if (err_code == 0) {
session_id = obj_body["session"];
$.cookie("session_id", session_id);
}
else {
//jumpToMainPage();
}
}
else {
//jumpToMainPage();
}
if (keepAliveTimerId == null) {
keepAliveTimerId = setInterval(OnTimerKeepAlive, 10 * 1000);
}
}

function sessionError(err_code) {
if (err_code != 0) {
if (err_code == errCode.ERR_SESSION_INVALID) {
if (keepAliveTimerId != null) {
clearInterval(keepAliveTimerId);
keepAliveTimerId = null;
}
session_id = "";
var userName = $.cookie("userName");
var password = $.cookie("password");
var post_content = cpLogin(userName, password);
nsstpHttpRequestPost(protocol_url, post_content, sessionLogin);
}
}
}
function CallbackDoNothing(result, response_str) {
if (result == true) {
var response = cpParseResponseHead(response_str);
var obj_body = response.body;
var obj_header = response.header;
var err_code = obj_header["err_code"];

sessionError(err_code);
}
else {
}
}

function OnKeepAlive(result, response_str) {
if (result == true) {
var response = cpParseResponseHead(response_str);
var obj_body = response.body;
var obj_header = response.header;
var err_code = obj_header["err_code"];
if (err_code == 0) {
var cpu_info = obj_body["cpu_info"];
var mem_total = obj_body["mem_total"];
var mem_free = obj_body["mem_free"];
var uptime = obj_body["uptime"];
var obj = { cpu: cpu_info, mem_total: mem_total, mem_free: mem_free, uptime: uptime };
if (callback_onkeepalive != null) {
callback_onkeepalive(obj);
}
}
sessionError(err_code);
}
else {
}
}

function OnTimerKeepAlive() {

if (session_id.length > 0) {
nsstpHttpRequestPost(protocol_url, cpKeepAlive(), OnKeepAlive);
}
}
//
function getVideoUrl(streamType, userName, password) {
var rv = "rtsp://" + userName + ":" + password + "@" + window.location.hostname + ":" + getRTSPPort();
if (streamType == 1) {
rv = rv + "/2";
}
return rv;
}
function getRecordUrl(userName, password, filename) {
var rv = "rtsp://" + userName + ":" + password + "@" + window.location.hostname + ":" + getRTSPPort() + "/playback/" + filename;
return rv;
}
function cpSetDDNS(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_DDNS_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = obj.enable;
jbody["type_name"] = obj.type_name;
jbody["svr_address"] = obj.svr_address;
jbody["device_domain"] = obj.device_domain;
jbody["svr_port"] = obj.svr_port;
jbody["user_name"] = obj.user_name;
jbody["user_password"] = obj.user_password;
return JSON3.stringify(jobj);
}

function cpSetPPPOE(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_PPPOE_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = obj.enable;
jbody["user_name"] = obj.user_name;
jbody["user_password"] = obj.user_password;
return JSON3.stringify(jobj);
}

function cpSetEmail(obj, mailto_list) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_EMAIL_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
var base64tool = new Base64();
jbody["sender_name"] = base64tool.encode(obj.sender_name);
jbody["sender_email"] = obj.sender_email;
jbody["smtp_server"] = obj.smtp_server;
jbody["smtp_port"] = obj.smtp_port;
jbody["use_ssl"] = obj.use_ssl;
jbody["auth_enable"] = obj.auth_enable;
jbody["auth_user"] = obj.auth_user;
jbody["auth_password"] = obj.auth_password;
var mailto_arr = { "mailto": [] };
for (var i = 0; i < 4; ++i) {
var info = { name: base64tool.encode(mailto_list.name), address: mailto_list.address };
mailto_arr.mailto.push(info);
}
jbody["mailto"] = mailto_arr.mailto;
return JSON3.stringify(jobj);
}
function cpRTSPAuth(mode) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_RTSP_AUTHENTICATION;
jbody[operation_key] = OP_TYPE_SET;
jbody["mode"] = mode;
return JSON3.stringify(jobj);
}

function cpNoiseReduction(channel, mode, level_2D, level_3D) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_NOISE_REDUCTION;
jbody[operation_key] = OP_TYPE_SET;
jbody["mode"] = mode;
jbody["level_2D"] = level_2D;
jbody["level_3D"] = level_3D;
return JSON3.stringify(jobj);
}

function cpSetEncoder(channel, encoder) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_AUDIO_ENCODER;
jbody[operation_key] = OP_TYPE_SET;
jbody["encoder"] = encoder;
return JSON3.stringify(jobj);
}

function cpSetAudioInput(channel, selected, volume) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_AUDIO_INPUT;
jbody[operation_key] = OP_TYPE_SET;
jbody["selected"] = selected;
jbody["volume"] = volume;
return JSON3.stringify(jobj);
}

function cpSetIFrameInterval(channel, stream, interval) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[stream_key] = stream;
jbody[method_key] = CMD_TYPE_IFRAME_INTERVAL;
jbody[operation_key] = OP_TYPE_SET;
jbody["iframe_interval"] = interval;
return JSON3.stringify(jobj);
}

function cpSetBitrate(channel, stream, type, max) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[stream_key] = stream;
jbody[method_key] = CMD_TYPE_BITRATE_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["bitrate_type"] = type;
jbody["bitrate_max"] = max;
return JSON3.stringify(jobj);
}
function cpSetVideoQuality(channel, stream, quality) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[stream_key] = stream;
jbody[method_key] = CMD_TYPE_VIDEO_QUALITY;
jbody[operation_key] = OP_TYPE_SET;
jbody["video_quality"] = quality;
return JSON3.stringify(jobj);
}
function cpGetAlarmTrigger(channel, type) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_ALARM_TRIGGER;
jbody[operation_key] = OP_TYPE_GET;
jbody["type"] = type;
return JSON3.stringify(jobj);
}

function cpSetAlarmTrigger(channel, type, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_ALARM_TRIGGER;
jbody[operation_key] = OP_TYPE_SET;
jbody["type"] = type;
jbody["audio"] = obj.audio;
jbody["broadcast"] = obj.broadcast;
jbody["port"] = obj.port;
jbody["record"] = obj.record;
jbody["ptz_preset"] = obj.ptz_preset;
jbody["ptz_sequence"] = obj.ptz_sequence;
jbody["ptz_scan"] = obj.ptz_scan;
jbody["snapshot"] = { "enable": obj.snapshot_enable,
"ftp": obj.snapshot_ftp,
"email": obj.snapshot_email,
"sdcard": obj.snapshot_sdcard
};
return JSON3.stringify(jobj);
}

function cpGetAlarmSchedule(channel, type) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_ALARM_SCHEDULE;
jbody[operation_key] = OP_TYPE_GET;
jbody["type"] = type;
return JSON3.stringify(jobj);
}
function cpSetAlarmSchedule(channel, type, schedule) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_ALARM_SCHEDULE;
jbody[operation_key] = OP_TYPE_SET;
jbody["type"] = type;

for (var i = 0; i < 7; ++i) {
var day_key = "day" + i;
var day_obj = { day_key: [] };
for (var j = 0; j < 8; j++) {
var seg_obj = { "start": 0, "end": 0 };
seg_obj["start"] = schedule[j].start;
seg_obj["end"] = schedule[j].end;
day_obj.day_key.push(seg_obj);
}
jbody["day" + i] = day_obj.day_key;
}

return JSON3.stringify(jobj);
}


function cpSetVPicSchedule(channel, enable, schedule, id) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
if(id=="videoProgram"){
jbody[method_key] = CMD_TYPE_RECORD_SCHEDULE;
jbody["enable"] = enable;
}
if(id=="capture"){
jbody[method_key] = CMD_TYPE_IDLE_CAPTURE_SCHEDULE;
}
jbody[operation_key] = OP_TYPE_SET;

for (var i = 0; i < 7; ++i) {
var day_key = "day" + i;
var day_obj = { day_key: [] };
for (var j = 0; j < 8; j++) {
var seg_obj = { "start": 0, "end": 0 };
seg_obj["start"] = schedule[j].start;
seg_obj["end"] = schedule[j].end;
if(id!="capture"){
seg_obj["type"] = schedule[j].type;
}
day_obj.day_key.push(seg_obj);
}
jbody["day" + i] = day_obj.day_key;
}

return JSON3.stringify(jobj);
}

function cpSetRecordConfig(channel, pre, post, overwrite) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_RECORD_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["pre_record"] = pre;
jbody["post_record"] = post;
jbody["overwrite"] = overwrite;
return JSON3.stringify(jobj);
}

function cpGetPortAlarm(channel, type) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_PORT_ALARM;
jbody[operation_key] = OP_TYPE_GET;
jbody["type"] = type;
return JSON3.stringify(jobj);
}

function cpSetPortAlarm(channel, type, title, status, enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_PORT_ALARM;
jbody[operation_key] = OP_TYPE_SET;
jbody["type"] = type;
jbody["enable"] = enable;
var base64tool = new Base64();
jbody["title"] = base64tool.encode(title);
jbody["status"] = status;
return JSON3.stringify(jobj);
}

function cpSetAlarmOutDelay(channel, delay) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_OUTPUT_DELAY;
jbody[operation_key] = OP_TYPE_SET;
jbody["delay"] = delay;
return JSON3.stringify(jobj);
}
function cpGetLogs(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_SEARCH_LOGS;
jbody["main"] = obj.main_type;
jbody["sub"] = obj.sub_type;
jbody["start"] = obj.start_time;
jbody["end"] = obj.end_time;
jbody["page_start"] = obj.page_start;
jbody["page_count"] = obj.page_count;
return JSON3.stringify(jobj);
}

function cpSetMaskAlarm(channel, enable, sensitivity) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_VIDEO_MASK_ALARM;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
jbody["sensitivity"] = sensitivity;
return JSON3.stringify(jobj);
}

function cpSetPTZSequence(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = obj.channel;
jbody[method_key] = CMD_TYPE_PTZ_SEQUENCE;
jbody[operation_key] = OP_TYPE_SET;
jbody["index"] = obj.index;
jbody["control"] = obj.control;
if (obj.control == sequenceControl.COVER) {
var arr = { "presets": [] };
for (var i = 0; i < obj.presets.length; ++i) {
arr.presets.push(obj.presets);
}
jbody["presets"] = arr.presets;
}
else {
jbody["preset"] = obj.preset;
jbody["delay"] = obj.delay;
jbody["speed"] = obj.speed;
}
return JSON3.stringify(jobj);
}

function cpGetPTZSequence(channel, index) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_PTZ_SEQUENCE;
jbody[operation_key] = OP_TYPE_GET;
jbody["index"] = index;
return JSON3.stringify(jobj);
}

function cpSetExposureConfig(channel, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_IRIS_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["type"] = obj.type;
jbody["iris"] = obj.iris;
jbody["gain"] = obj.gain;
jbody["gain_limit"] = obj.gain_limit;
jbody["smart_ir_enable"] = obj.smart_ir_enable;
jbody["shutter_times"] = obj.shutter_times;
jbody["shutter_limit"] = obj.shutter_limit;
jbody["compensation_enable"] = obj.compensation_enable;
jbody["compensation_level"] = obj.compensation_level;

return JSON3.stringify(jobj);
}

function cpGetExposureConfig(channel) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_IRIS_CONFIG;
jbody[operation_key] = OP_TYPE_GET;

return JSON3.stringify(jobj);
}

function cpSetVideoSystem(channel, system) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_VIDEO_SYSTEM;
jbody[operation_key] = OP_TYPE_SET;
jbody["system"] = system;
return JSON3.stringify(jobj);
}

function cpSetWhiteBalance(channel, type, gain_r, gain_b) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_WHITE_BALANCE;
jbody[operation_key] = OP_TYPE_SET;
jbody["type"] = type;
jbody["gain_r"] = gain_r;
jbody["gain_b"] = gain_b;
jbody["template"] = 0;
return JSON3.stringify(jobj);
}

function cpPTZScan(channel, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_PTZ_SCAN;
jbody["index"] = obj.index;
jbody["control"] = obj.control;
jbody["value"] = obj.value;
return JSON3.stringify(jobj);
}

function cpPTZPattern(channel, control, index) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_PTZ_PATTERN;
jbody["index"] = index;
jbody["control"] = control;
return JSON3.stringify(jobj);
}

function cpSetDayNightSwitch(channel, type, sensitivity) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_DAYNIGHT_SWITCH;
jbody[operation_key] = OP_TYPE_SET;
jbody["type"] = type;
jbody["sensitivity"] = sensitivity;
jbody["switch_time"] = 0;
jbody["start_time"] = 0;
jbody["end_time"] = 0;
return JSON3.stringify(jobj);
}
function cpSetWDR(channel, enable, level) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_WDR;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
jbody["level"] = level;
return JSON3.stringify(jobj);
}
function cpSetFocusMode(channel, mode, min_distance) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_FOCUS_MODE;
jbody[operation_key] = OP_TYPE_SET;
jbody["mode"] = mode;
jbody["min_distance"] = min_distance;
return JSON3.stringify(jobj);
}
function cpSetLocalOutput(channel, enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_LOCAL_OUTPUT;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
return JSON3.stringify(jobj);
}

function cpSetIRLED(channel, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_IR_LED;
jbody[operation_key] = OP_TYPE_SET;
jbody["mode"] = obj.mode;
jbody["illuminance"] = obj.illuminance;
jbody["auto_dimming"] = obj.auto_dimming;
jbody["near_power"] = obj.near_power;
jbody["far_power"] = obj.far_power;
jbody["near_compensation"] = obj.near_compensation;
return JSON3.stringify(jobj);
}

function cpSetScheduleCapture(channel, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_SCHEDULE_CAPTURE;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = obj.enable;
jbody["format"] = 0;
jbody["quality"] = obj.quality;
jbody["interval_value"] = obj.interval_value;
jbody["interval_unit"] = obj.interval_unit;
jbody["trigger_ftp"] = obj.trigger_ftp;
jbody["trigger_email"] = obj.trigger_email;
jbody["trigger_sdcard"] = obj.trigger_sdcard;
return JSON3.stringify(jobj);
}

function cpSetStorageQuota(channel, capture, record) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_STORAGE_QUOTA;
jbody[operation_key] = OP_TYPE_SET;
jbody["capture"] = capture;
jbody["record"] = record;
return JSON3.stringify(jobj);
}

function cpFormatStorageDevice(index) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_FORMAT_DEVICE;
jbody["index"] = index;
return JSON3.stringify(jobj);
}

function cpSetPortMapping(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_PORT_MAPPING;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = obj.enable;
jbody["type"] = obj.type;
jbody["http_o"] = obj.http_o;
jbody["https_o"] = obj.https_o;
jbody["rtsp_o"] = obj.rtsp_o;
jbody["cmd_o"] = obj.cmd_o;
return JSON3.stringify(jobj);
}

function cpSetWirelessDeviceInfo(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_WIFI_DEVICE_INFO;
jbody[operation_key] = OP_TYPE_SET;
jbody["net_mode"] = obj.net_mode;
jbody["safe_mode"] = obj.safe_mode;
jbody["encrypt_type"] = obj.encrypt_type;
var base64tool = new Base64();
jbody["password"] = base64tool.encode(obj.password);
jbody["ssid"] = base64tool.encode(obj.ssid);
return JSON3.stringify(jobj);
}

function cpSetWirelessConfig(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_WIRELESS_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody["dhcp"] = obj.dhcp;
jbody["ipv4_address"] = obj.ipv4_address;
jbody["ipv4_mask"] = obj.ipv4_mask;
jbody["ipv4_gateway"] = obj.ipv4_gateway;
jbody["multi_address"] = obj.multi_address;
jbody["dns_server1"] = obj.dns_server1;
jbody["dns_server2"] = obj.dns_server2;
return JSON3.stringify(jobj);
}

function cpSetROI(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = obj.channel;
jbody[method_key] = CMD_TYPE_ROI;
jbody[operation_key] = OP_TYPE_SET;
jbody["region"] = obj.region;
jbody["ox"] = obj.ox;
jbody["oy"] = obj.oy;
jbody["width"] = obj.width;
jbody["height"] = obj.height;
jbody["enable"] = obj.enable;
jbody["quality"] = obj.quality;
return JSON3.stringify(jobj);
}

function cpGetROI(channel, region) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_ROI;
jbody[operation_key] = OP_TYPE_GET;
jbody["region"] = region;
return JSON3.stringify(jobj);
}

function cpSetAisle(channel, mode) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_AISLE;
jbody[operation_key] = OP_TYPE_SET;
jbody["aisle_mode"] = mode;
return JSON3.stringify(jobj);
}

function cpSetZoomLimit(channel, limit) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_ZOOM_LIMIT;
jbody[operation_key] = OP_TYPE_SET;
jbody["limit"] = limit;
return JSON3.stringify(jobj);
}

function cpSetRS485(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_RS485;
jbody[operation_key] = OP_TYPE_SET;
jbody["baudrate"] = obj.baudrate;
jbody["datebit"] = obj.datebit;
jbody["stopbit"] = obj.stopbit;
jbody["parity"] = obj.parity;
jbody["flow"] = obj.flow;
jbody["cprotocol"] = 0;
jbody["caddr"] = obj.caddr;

return JSON3.stringify(jobj);
}

function cpSetRS232(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_RS232;
jbody[operation_key] = OP_TYPE_SET;
jbody["baudrate"] = obj.baudrate;
jbody["datebit"] = obj.datebit;
jbody["stopbit"] = obj.stopbit;
jbody["parity"] = obj.parity;
jbody["flow"] = obj.flow;
jbody["cmode"] = 0;

return JSON3.stringify(jobj);
}

function cpSetTrackConfig(channel, obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_TRACK_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = channel;
jbody["sensitivity"] = obj.sensitivity;
jbody["zoom"] = obj.zoom;
jbody["ret_secs"] = obj.ret_secs;
jbody["aux"] = obj.aux;

return JSON3.stringify(jobj);
}

function cpSetTrackEnable(channel, enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_TRACK_ENABLE;
jbody[channel_key] = channel;
jbody["enable"] = enable;

return JSON3.stringify(jobj);
}

function cpSetTrackScene(channel) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_TRACK_RET_SCENE;
jbody[channel_key] = channel;
return JSON3.stringify(jobj);
}

function cpTestNtp(type, server, port) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_TEST_FUNCTION;
jbody["type"] = type;
jbody["server"] = server;
jbody["port"] = port;
return JSON3.stringify(jobj);
}

function cpSetSysMobile(enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_SYS_MOBILE;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
return JSON3.stringify(jobj);
}

function cpDefogMode(channel, enable) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[channel_key] = channel;
jbody[method_key] = CMD_TYPE_DEFOG_MODE;
jbody[operation_key] = OP_TYPE_SET;
jbody["enable"] = enable;
return JSON3.stringify(jobj);
}

function cpSetidleAction(obj) {
var jobj = cpGenerate();
var jbody = jobj.body;
jbody[method_key] = CMD_TYPE_IDLE_ACTION_CONFIG;
jbody[operation_key] = OP_TYPE_SET;
jbody[channel_key] = obj.channel;
jbody["idle_time"] = obj.parktime;
jbody["mode"] = obj.actType;
jbody["index"] = obj.index;

return JSON3.stringify(jobj);
}


This appears to be something about Cookie Generation

GET /third_party/jquerycookie.js HTTP/1.1
Host: 192.168.1.116
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: */*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://192.168..***.***/
Cookie: yummy_magical_cookie=/
Connection: keep-alive


HTTP/1.0 200 OK
Via: 1.1 tinyproxy (tinyproxy/1.8.3)
Set-Cookie: yummy_magical_cookie=/; path=/
Content-Type: application/javascript
Server: Boa/0.94.13
Date: Tue, 23 Feb 2016 09:34:09 GMT
Last-Modified: Tue, 23 Jun 2015 01:13:05 GMT
Connection: close
Content-Length: 3752

/*jslint browser: true */ /*global jQuery: true */

/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

// TODO JsDoc

/**
* Create a cookie with the given key and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String key The key of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/

/**
* Get the value of a cookie with the given key.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String key The key of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function (key, value, options) {

// key and value given, set cookie...
if (arguments.length > 1 && (value === null || typeof value !== "object")) {
options = jQuery.extend({}, options);

if (value === null) {
options.expires = -1;
}

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? String(value) : encodeURIComponent(String(value)),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '; path=/',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
And it looks like it Hashes the password at some stage

GET /third_party/jquery.md5.js HTTP/1.1
Host: 192.168.***.***
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: */*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://192.168.***.***/
Cookie: yummy_magical_cookie=/
Connection: keep-alive


HTTP/1.0 200 OK
Via: 1.1 tinyproxy (tinyproxy/1.8.3)
Set-Cookie: yummy_magical_cookie=/; path=/
Content-Type: application/javascript
Server: Boa/0.94.13
Date: Tue, 23 Feb 2016 09:34:09 GMT
Last-Modified: Tue, 23 Jun 2015 01:13:05 GMT
Connection: close
Content-Length: 9284

/**
* jQuery MD5 hash algorithm function
*
* <code>
* Calculate the md5 hash of a String
* String $.md5 ( String str )
* </code>
*
* Calculates the MD5 hash of str using the » RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash.
* MD5 (Message-Digest algorithm 5) is a widely-used cryptographic hash function with a 128-bit hash value. MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of data. The generated hash is also non-reversable. Data cannot be retrieved from the message digest, the digest uniquely identifies the data.
* MD5 was developed by Professor Ronald L. Rivest in 1994. Its 128 bit (16 byte) message digest makes it a faster implementation than SHA-1.
* This script is used to process a variable length message into a fixed-length output of 128 bits using the MD5 algorithm. It is fully compatible with UTF-8 encoding. It is very useful when u want to transfer encrypted passwords over the internet. If you plan using UTF-8 encoding in your project don't forget to set the page encoding to UTF-8 (Content-Type meta tag).
* This function orginally get from the WebToolkit and rewrite for using as the jQuery plugin.
*
* Example
* Code
* <code>
* $.md5("I'm Persian.");
* </code>
* Result
* <code>
* "b8c901d0f02223f9761016cfff9d68df"
* </code>
*
* @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com >
* @link http://www.semnanweb.com/jquery-plugin/md5.html
* @see http://www.webtoolkit.info/
* @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
* @param {jQuery} {md5:function(string))
* @return string
*/

(function($){

var rotateLeft = function(lValue, iShiftBits) {
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
}

var addUnsigned = function(lX, lY) {
var lX4, lY4, lX8, lY8, lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
lX4 = (lX & 0x40000000);
lY4 = (lY & 0x40000000);
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
if (lX4 | lY4) {
if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
} else {
return (lResult ^ lX8 ^ lY8);
}
}

var F = function(x, y, z) {
return (x & y) | ((~ x) & z);
}

var G = function(x, y, z) {
return (x & z) | (y & (~ z));
}

var H = function(x, y, z) {
return (x ^ y ^ z);
}

var I = function(x, y, z) {
return (y ^ (x | (~ z)));
}

var FF = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};

var GG = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};

var HH = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};

var II = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};

var convertToWordArray = function(string) {
var lWordCount;
var lMessageLength = string.length;
var lNumberOfWordsTempOne = lMessageLength + 8;
var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64;
var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16;
var lWordArray = Array(lNumberOfWords - 1);
var lBytePosition = 0;
var lByteCount = 0;
while (lByteCount < lMessageLength) {
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
lByteCount++;
}
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
return lWordArray;
};

var wordToHex = function(lValue) {
var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount;
for (lCount = 0; lCount <= 3; lCount++) {
lByte = (lValue >>> (lCount * 8)) & 255;
WordToHexValueTemp = "0" + lByte.toString(16);
WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2);
}
return WordToHexValue;
};

var uTF8Encode = function(string) {
string = string.replace(/\x0d\x0a/g, "\x0a");
var output = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
output += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
output += String.fromCharCode((c >> 6) | 192);
output += String.fromCharCode((c & 63) | 128);
} else {
output += String.fromCharCode((c >> 12) | 224);
output += String.fromCharCode(((c >> 6) & 63) | 128);
output += String.fromCharCode((c & 63) | 128);
}
}
return output;
};

$.extend({
md5: function(string) {
var x = Array();
var k, AA, BB, CC, DD, a, b, c, d;
var S11=7, S12=12, S13=17, S14=22;
var S21=5, S22=9 , S23=14, S24=20;
var S31=4, S32=11, S33=16, S34=23;
var S41=6, S42=10, S43=15, S44=21;
string = uTF8Encode(string);
x = convertToWordArray(string);
a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
for (k = 0; k < x.length; k += 16) {
AA = a; BB = b; CC = c; DD = d;
a = FF(a, b, c, d, x[k+0], S11, 0xD76AA478);
d = FF(d, a, b, c, x[k+1], S12, 0xE8C7B756);
c = FF(c, d, a, b, x[k+2], S13, 0x242070DB);
b = FF(b, c, d, a, x[k+3], S14, 0xC1BDCEEE);
a = FF(a, b, c, d, x[k+4], S11, 0xF57C0FAF);
d = FF(d, a, b, c, x[k+5], S12, 0x4787C62A);
c = FF(c, d, a, b, x[k+6], S13, 0xA8304613);
b = FF(b, c, d, a, x[k+7], S14, 0xFD469501);
a = FF(a, b, c, d, x[k+8], S11, 0x698098D8);
d = FF(d, a, b, c, x[k+9], S12, 0x8B44F7AF);
c = FF(c, d, a, b, x[k+10], S13, 0xFFFF5BB1);
b = FF(b, c, d, a, x[k+11], S14, 0x895CD7BE);
a = FF(a, b, c, d, x[k+12], S11, 0x6B901122);
d = FF(d, a, b, c, x[k+13], S12, 0xFD987193);
c = FF(c, d, a, b, x[k+14], S13, 0xA679438E);
b = FF(b, c, d, a, x[k+15], S14, 0x49B40821);
a = GG(a, b, c, d, x[k+1], S21, 0xF61E2562);
d = GG(d, a, b, c, x[k+6], S22, 0xC040B340);
c = GG(c, d, a, b, x[k+11], S23, 0x265E5A51);
b = GG(b, c, d, a, x[k+0], S24, 0xE9B6C7AA);
a = GG(a, b, c, d, x[k+5], S21, 0xD62F105D);
d = GG(d, a, b, c, x[k+10], S22, 0x2441453);
c = GG(c, d, a, b, x[k+15], S23, 0xD8A1E681);
b = GG(b, c, d, a, x[k+4], S24, 0xE7D3FBC8);
a = GG(a, b, c, d, x[k+9], S21, 0x21E1CDE6);
d = GG(d, a, b, c, x[k+14], S22, 0xC33707D6);
c = GG(c, d, a, b, x[k+3], S23, 0xF4D50D87);
b = GG(b, c, d, a, x[k+8], S24, 0x455A14ED);
a = GG(a, b, c, d, x[k+13], S21, 0xA9E3E905);
d = GG(d, a, b, c, x[k+2], S22, 0xFCEFA3F8);
c = GG(c, d, a, b, x[k+7], S23, 0x676F02D9);
b = GG(b, c, d, a, x[k+12], S24, 0x8D2A4C8A);
a = HH(a, b, c, d, x[k+5], S31, 0xFFFA3942);
d = HH(d, a, b, c, x[k+8], S32, 0x8771F681);
c = HH(c, d, a, b, x[k+11], S33, 0x6D9D6122);
b = HH(b, c, d, a, x[k+14], S34, 0xFDE5380C);
a = HH(a, b, c, d, x[k+1], S31, 0xA4BEEA44);
d = HH(d, a, b, c, x[k+4], S32, 0x4BDECFA9);
c = HH(c, d, a, b, x[k+7], S33, 0xF6BB4B60);
b = HH(b, c, d, a, x[k+10], S34, 0xBEBFBC70);
a = HH(a, b, c, d, x[k+13], S31, 0x289B7EC6);
d = HH(d, a, b, c, x[k+0], S32, 0xEAA127FA);
c = HH(c, d, a, b, x[k+3], S33, 0xD4EF3085);
b = HH(b, c, d, a, x[k+6], S34, 0x4881D05);
a = HH(a, b, c, d, x[k+9], S31, 0xD9D4D039);
d = HH(d, a, b, c, x[k+12], S32, 0xE6DB99E5);
c = HH(c, d, a, b, x[k+15], S33, 0x1FA27CF8);
b = HH(b, c, d, a, x[k+2], S34, 0xC4AC5665);
a = II(a, b, c, d, x[k+0], S41, 0xF4292244);
d = II(d, a, b, c, x[k+7], S42, 0x432AFF97);
c = II(c, d, a, b, x[k+14], S43, 0xAB9423A7);
b = II(b, c, d, a, x[k+5], S44, 0xFC93A039);
a = II(a, b, c, d, x[k+12], S41, 0x655B59C3);
d = II(d, a, b, c, x[k+3], S42, 0x8F0CCC92);
c = II(c, d, a, b, x[k+10], S43, 0xFFEFF47D);
b = II(b, c, d, a, x[k+1], S44, 0x85845DD1);
a = II(a, b, c, d, x[k+8], S41, 0x6FA87E4F);
d = II(d, a, b, c, x[k+15], S42, 0xFE2CE6E0);
c = II(c, d, a, b, x[k+6], S43, 0xA3014314);
b = II(b, c, d, a, x[k+13], S44, 0x4E0811A1);
a = II(a, b, c, d, x[k+4], S41, 0xF7537E82);
d = II(d, a, b, c, x[k+11], S42, 0xBD3AF235);
c = II(c, d, a, b, x[k+2], S43, 0x2AD7D2BB);
b = II(b, c, d, a, x[k+9], S44, 0xEB86D391);
a = addUnsigned(a, AA);
b = addUnsigned(b, BB);
c = addUnsigned(c, CC);
d = addUnsigned(d, DD);
}
var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
return tempValue.toLowerCase();
}
});
})(jQuery);
I think I can officially say I'm well out of my depth. Time to do some reading.
 
Top