1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Initial main commit

This commit is contained in:
Ylian Saint-Hilaire 2017-08-28 09:27:45 -07:00
parent 802cbecb3c
commit b831b7cb97
104 changed files with 62749 additions and 1 deletions

View file

@ -0,0 +1,591 @@
/**
* @description Remote Desktop
* @author Ylian Saint-Hilaire
* @version v0.0.2g
*/
// Construct a MeshServer object
var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
var obj = {}
obj.CanvasId = canvasid;
if (typeof canvasid === 'string') obj.CanvasId = Q(canvasid);
obj.Canvas = obj.CanvasId.getContext("2d");
obj.scrolldiv = scrolldiv;
obj.State = 0;
obj.PendingOperations = [];
obj.tilesReceived = 0;
obj.TilesDrawn = 0;
obj.KillDraw = 0;
obj.ipad = false;
obj.tabletKeyboardVisible = false;
obj.LastX = 0;
obj.LastY = 0;
obj.touchenabled = 0;
obj.submenuoffset = 0;
obj.touchtimer = null;
obj.TouchArray = {};
obj.connectmode = 0; // 0 = HTTP, 1 = WebSocket, 2 = WebRTC
obj.connectioncount = 0;
obj.rotation = 0;
obj.protocol = 2; // KVM
obj.sessionid = 0;
obj.username;
obj.oldie = false;
obj.CompressionLevel = 50;
obj.ScalingLevel = 1024;
obj.FrameRateTimer = 50;
obj.FirstDraw = false;
obj.ScreenWidth = 960;
obj.ScreenHeight = 700;
obj.width = 960;
obj.height = 960;
obj.onScreenResize = null;
obj.onMessage = null;
obj.onConnectCountChanged = null;
obj.onDebugMessage = null;
obj.onTouchEnabledChanged = null;
obj.Start = function () {
obj.State = 0;
}
obj.Stop = function () {
obj.setRotation(0);
obj.UnGrabKeyInput();
obj.UnGrabMouseInput();
obj.touchenabled = 0;
if (obj.onScreenResize != null) obj.onScreenResize(obj, obj.ScreenWidth, obj.ScreenHeight, obj.CanvasId);
obj.Canvas.clearRect(0, 0, obj.CanvasId.width, obj.CanvasId.height);
}
obj.xxStateChange = function (newstate) {
if (obj.State == newstate) return;
obj.State = newstate;
//console.log('xxStateChange', newstate);
switch (newstate) {
case 0: {
// Disconnect
obj.Stop();
break;
}
case 3: {
// Websocket connected
break;
}
}
}
obj.Send = function (x) {
//console.log("KSend(" + x.length + "): " + rstr2hex(x));
obj.parent.Send(x);
}
// KVM Control.
// Routines for processing incoming packets from the AJAX server, and handling individual messages.
obj.ProcessPictureMsg = function (str, X, Y) {
//if (obj.targetnode != null) obj.Debug("ProcessPictureMsg " + X + "," + Y + " - " + obj.targetnode.substring(0, 8));
var tile = new Image();
obj.tilesReceived++;
var r = obj.tilesReceived;
tile.src = "data:image/jpeg;base64," + btoa(str.substring(4, str.length));
tile.onload = function () {
if (obj.Canvas != null && obj.KillDraw < r && obj.State != 0) {
obj.PendingOperations.push([r, 2, tile, X, Y]);
while (obj.DoPendingOperations()) { }
}
}
}
obj.DoPendingOperations = function () {
if (obj.PendingOperations.length == 0) return false;
for (var i = 0; i < obj.PendingOperations.length; i++) { // && KillDraw < tilesDrawn
var Msg = obj.PendingOperations[i];
if (Msg[0] == (obj.TilesDrawn + 1)) {
if (Msg[1] == 1) { obj.ProcessCopyRectMsg(Msg[2]); }
else if (Msg[1] == 2) { obj.Canvas.drawImage(Msg[2], obj.rotX(Msg[3], Msg[4]), obj.rotY(Msg[3], Msg[4])); delete Msg[2]; }
obj.PendingOperations.splice(i, 1);
delete Msg;
obj.TilesDrawn++;
if (obj.TilesDrawn == obj.tilesReceived && obj.KillDraw < obj.TilesDrawn) { obj.KillDraw = obj.TilesDrawn = obj.tilesReceived = 0; }
return true;
}
}
if (obj.oldie && obj.PendingOperations.length > 0) { obj.TilesDrawn++; }
return false;
}
obj.ProcessCopyRectMsg = function (str) {
var SX = ((str.charCodeAt(0) & 0xFF) << 8) + (str.charCodeAt(1) & 0xFF);
var SY = ((str.charCodeAt(2) & 0xFF) << 8) + (str.charCodeAt(3) & 0xFF);
var DX = ((str.charCodeAt(4) & 0xFF) << 8) + (str.charCodeAt(5) & 0xFF);
var DY = ((str.charCodeAt(6) & 0xFF) << 8) + (str.charCodeAt(7) & 0xFF);
var WIDTH = ((str.charCodeAt(8) & 0xFF) << 8) + (str.charCodeAt(9) & 0xFF);
var HEIGHT = ((str.charCodeAt(10) & 0xFF) << 8) + (str.charCodeAt(11) & 0xFF);
obj.Canvas.drawImage(Canvas.canvas, SX, SY, WIDTH, HEIGHT, DX, DY, WIDTH, HEIGHT);
}
obj.SendUnPause = function () {
//obj.Debug("SendUnPause");
//obj.xxStateChange(3);
obj.Send(String.fromCharCode(0x00, 0x08, 0x00, 0x05, 0x00));
}
obj.SendPause = function () {
//obj.Debug("SendPause");
//obj.xxStateChange(2);
obj.Send(String.fromCharCode(0x00, 0x08, 0x00, 0x05, 0x01));
}
obj.SendCompressionLevel = function (type, level, scaling, frametimer) {
if (level) { obj.CompressionLevel = level; }
if (scaling) { obj.ScalingLevel = scaling; }
if (frametimer) { obj.FrameRateTimer = frametimer; }
obj.Send(String.fromCharCode(0x00, 0x05, 0x00, 0x0A, type, obj.CompressionLevel) + obj.shortToStr(obj.ScalingLevel) + obj.shortToStr(obj.FrameRateTimer));
}
obj.SendRefresh = function () {
obj.Send(String.fromCharCode(0x00, 0x06, 0x00, 0x04));
}
obj.ProcessScreenMsg = function (width, height) {
//obj.Debug("ProcessScreenMsg: " + width + " x " + height);
obj.Canvas.setTransform(1, 0, 0, 1, 0, 0);
obj.rotation = 0;
obj.FirstDraw = true;
obj.ScreenWidth = obj.width = width;
obj.ScreenHeight = obj.height = height;
obj.KillDraw = obj.tilesReceived;
while (obj.PendingOperations.length > 0) { obj.PendingOperations.shift(); }
obj.SendCompressionLevel(1);
obj.SendUnPause();
}
obj.ProcessData = function (str) {
if (str.length < 4) return;
var cmdmsg = null, X = 0, Y = 0, command = ReadShort(str, 0), cmdsize = ReadShort(str, 2);
if (command >= 18) { console.error("Invalid KVM command " + command + " of size " + cmdsize); obj.parent.Stop(); return; }
if (cmdsize > str.length) return;
//meshOnDebug("KVM Command: " + command + " Len:" + cmdsize);
if (command == 3 || command == 4 || command == 7) {
cmdmsg = str.substring(4, cmdsize);
X = ((cmdmsg.charCodeAt(0) & 0xFF) << 8) + (cmdmsg.charCodeAt(1) & 0xFF);
Y = ((cmdmsg.charCodeAt(2) & 0xFF) << 8) + (cmdmsg.charCodeAt(3) & 0xFF);
}
switch (command) {
case 3: // Tile
if (obj.FirstDraw) obj.onResize();
obj.ProcessPictureMsg(cmdmsg, X, Y);
break;
case 4: // Tile Copy
if (obj.FirstDraw) obj.onResize();
if (obj.TilesDrawn == obj.tilesReceived) {
obj.ProcessCopyRectMsg(cmdmsg);
} else {
obj.PendingOperations.push([ ++tilesReceived, 1, cmdmsg ]);
}
break;
case 7: // Screen size
obj.ProcessScreenMsg(X, Y);
obj.SendKeyMsgKC(obj.KeyAction.UP, 16); // Shift
obj.SendKeyMsgKC(obj.KeyAction.UP, 17); // Ctrl
obj.SendKeyMsgKC(obj.KeyAction.UP, 18); // Alt
obj.SendKeyMsgKC(obj.KeyAction.UP, 91); // Left-Windows
obj.SendKeyMsgKC(obj.KeyAction.UP, 92); // Right-Windows
obj.Send(String.fromCharCode(0x00, 0x0E, 0x00, 0x04));
break;
case 11: // GetDisplays
var dcount = ((str.charCodeAt(4) & 0xFF) << 8) + (str.charCodeAt(5) & 0xFF);
if (dcount == 0) {
// One display present
if (document.getElementById('termdisplays') != null) document.getElementById('termdisplays').style.display = 'none';
if (document.getElementById('termdisplays2') != null) document.getElementById('termdisplays2').style.display = 'none';
} else {
// Many displays present
var seldisp = ((str.charCodeAt(6 + (dcount * 2)) & 0xFF) << 8) + (str.charCodeAt(7 + (dcount * 2)) & 0xFF);
var selitem = 0;
var myOptions = [];
for (var i = 0; i < dcount; i++) {
var disp = ((str.charCodeAt(6 + (i * 2)) & 0xFF) << 8) + (str.charCodeAt(7 + (i * 2)) & 0xFF);
if (disp == 65535) {
myOptions.push('All Displays');
} else {
myOptions.push('Display ' + disp);
}
if (disp == seldisp) selitem = i;
}
}
// TODO
break;
case 12: // SetDisplay
break;
case 14: // KVM_INIT_TOUCH
obj.touchenabled = 1;
obj.TouchArray = {};
if (obj.onTouchEnabledChanged != null) obj.onTouchEnabledChanged(obj.touchenabled);
break;
case 15: // KVM_TOUCH
obj.TouchArray = {};
break;
case 16: // MNG_KVM_CONNECTCOUNT
obj.connectioncount = ReadInt(str, 4);
//obj.Debug("Got KVM Connect Count: " + obj.connectioncount);
if (obj.onConnectCountChanged != null) obj.onConnectCountChanged(obj.connectioncount, obj);
break;
case 17: // MNG_KVM_MESSAGE
//obj.Debug("Got KVM Message: " + str.substring(4, cmdsize));
if (obj.onMessage != null) obj.onMessage(str.substring(4, cmdsize), obj);
break;
}
}
// Keyboard and Mouse I/O.
obj.MouseButton = { "NONE": 0x00, "LEFT": 0x02, "RIGHT": 0x08, "MIDDLE": 0x20 };
obj.KeyAction = { "NONE": 0, "DOWN": 1, "UP": 2, "SCROLL": 3, "EXUP": 4, "EXDOWN": 5 };
obj.InputType = { "KEY": 1, "MOUSE": 2, "CTRLALTDEL": 10, "TOUCH": 15 };
obj.Alternate = 0;
obj.SendKeyMsg = function (action, event) {
if (action == null) return;
if (!event) { var event = window.event; }
var kc = event.keyCode;
if (kc == 0x3B) kc = 0xBA; // ';' key
obj.SendKeyMsgKC(action, kc);
}
obj.SendMessage = function (msg) {
if (obj.State == 3) obj.Send(String.fromCharCode(0x00, 0x11) + obj.shortToStr(4 + msg.length) + msg); // 0x11 = 17 MNG_KVM_MESSAGE
}
obj.SendKeyMsgKC = function (action, kc) {
if (obj.State == 3) obj.Send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, (action - 1), kc));
}
obj.sendcad = function() { obj.SendCtrlAltDelMsg(); }
obj.SendCtrlAltDelMsg = function () {
if (obj.State == 3) { obj.Send(String.fromCharCode(0x00, obj.InputType.CTRLALTDEL, 0x00, 0x04)); }
}
obj.SendEscKey = function () {
if (obj.State == 3) obj.Send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, 0x00, 0x1B, 0x00, obj.InputType.KEY, 0x00, 0x06, 0x01, 0x1B));
}
obj.SendStartMsg = function () {
obj.SendKeyMsgKC(obj.KeyAction.EXDOWN, 0x5B); // L-Windows
obj.SendKeyMsgKC(obj.KeyAction.EXUP, 0x5B); // L-Windows
}
obj.SendCharmsMsg = function () {
obj.SendKeyMsgKC(obj.KeyAction.EXDOWN, 0x5B); // L-Windows
obj.SendKeyMsgKC(obj.KeyAction.DOWN, 67); // C
obj.SendKeyMsgKC(obj.KeyAction.UP, 67); // C
obj.SendKeyMsgKC(obj.KeyAction.EXUP, 0x5B); // L-Windows
}
obj.SendTouchMsg1 = function (id, flags, x, y) {
if (obj.State == 3) obj.Send(String.fromCharCode(0x00, obj.InputType.TOUCH) + obj.shortToStr(14) + String.fromCharCode(0x01, id) + obj.intToStr(flags) + obj.shortToStr(x) + obj.shortToStr(y));
}
obj.SendTouchMsg2 = function (id, flags) {
var msg = '';
var flags2;
var str = "TOUCHSEND: ";
for (var k in obj.TouchArray) {
if (k == id) { flags2 = flags; } else {
if (obj.TouchArray[k].f == 1) { flags2 = 0x00010000 | 0x00000002 | 0x00000004; obj.TouchArray[k].f = 3; str += "START" + k; } // POINTER_FLAG_DOWN
else if (obj.TouchArray[k].f == 2) { flags2 = 0x00040000; str += "STOP" + k; } // POINTER_FLAG_UP
else flags2 = 0x00000002 | 0x00000004 | 0x00020000; // POINTER_FLAG_UPDATE
}
msg += String.fromCharCode(k) + obj.intToStr(flags2) + obj.shortToStr(obj.TouchArray[k].x) + obj.shortToStr(obj.TouchArray[k].y);
if (obj.TouchArray[k].f == 2) delete obj.TouchArray[k];
}
if (obj.State == 3) obj.Send(String.fromCharCode(0x00, obj.InputType.TOUCH) + obj.shortToStr(5 + msg.length) + String.fromCharCode(0x02) + msg);
if (Object.keys(obj.TouchArray).length == 0 && obj.touchtimer != null) { clearInterval(obj.touchtimer); obj.touchtimer = null; }
}
obj.SendMouseMsg = function (Action, event) {
if (obj.State != 3) return;
if (Action != null && obj.Canvas != null) {
if (!event) { var event = window.event; }
var ScaleFactorHeight = (obj.Canvas.canvas.height / obj.CanvasId.clientHeight);
var ScaleFactorWidth = (obj.Canvas.canvas.width / obj.CanvasId.clientWidth);
var Offsets = obj.GetPositionOfControl(obj.Canvas.canvas);
var X = ((event.pageX - Offsets[0]) * ScaleFactorWidth);
var Y = ((event.pageY - Offsets[1]) * ScaleFactorHeight);
if (X >= 0 && X <= obj.Canvas.canvas.width && Y >= 0 && Y <= obj.Canvas.canvas.height) {
var Button = 0;
var Delta = 0;
if (Action == obj.KeyAction.UP || Action == obj.KeyAction.DOWN) {
if (event.which) { ((event.which == 1) ? (Button = obj.MouseButton.LEFT) : ((event.which == 2) ? (Button = obj.MouseButton.MIDDLE) : (Button = obj.MouseButton.RIGHT))); }
else if (event.button) { ((event.button == 0) ? (Button = obj.MouseButton.LEFT) : ((event.button == 1) ? (Button = obj.MouseButton.MIDDLE) : (Button = obj.MouseButton.RIGHT))); }
}
else if (Action == obj.KeyAction.SCROLL) {
if (event.detail) { Delta = (-1 * (event.detail * 120)); } else if (event.wheelDelta) { Delta = (event.wheelDelta * 3); }
}
var MouseMsg = "";
if (Action == obj.KeyAction.SCROLL) MouseMsg = String.fromCharCode(0x00, obj.InputType.MOUSE, 0x00, 0x0C, 0x00, ((Action == obj.KeyAction.DOWN) ? Button : ((Button * 2) & 0xFF)), ((X / 256) & 0xFF), (X & 0xFF), ((Y / 256) & 0xFF), (Y & 0xFF), ((Delta / 256) & 0xFF), (Delta & 0xFF));
else MouseMsg = String.fromCharCode(0x00, obj.InputType.MOUSE, 0x00, 0x0A, 0x00, ((Action == obj.KeyAction.DOWN) ? Button : ((Button * 2) & 0xFF)), ((X / 256) & 0xFF), (X & 0xFF), ((Y / 256) & 0xFF), (Y & 0xFF));
if (obj.Action == obj.KeyAction.NONE) { if (obj.Alternate == 0 || obj.ipad) { obj.Send(MouseMsg); obj.Alternate = 1; } else { obj.Alternate = 0; } } else { obj.Send(MouseMsg); }
}
}
}
obj.GetDisplayNumbers = function () { obj.Send(String.fromCharCode(0x00, 0x0B, 0x00, 0x04)); } // Get Terminal display
obj.SetDisplay = function (number) { obj.Send(String.fromCharCode(0x00, 0x0C, 0x00, 0x06, number >> 8, number & 0xFF)); } // Set Terminal display
obj.intToStr = function (x) { return String.fromCharCode((x >> 24) & 0xFF, (x >> 16) & 0xFF, (x >> 8) & 0xFF, x & 0xFF); }
obj.shortToStr = function (x) { return String.fromCharCode((x >> 8) & 0xFF, x & 0xFF); }
obj.onResize = function () {
if (obj.ScreenWidth == 0 || obj.ScreenHeight == 0) return;
if (obj.Canvas.canvas.width == obj.ScreenWidth && obj.Canvas.canvas.height == obj.ScreenHeight) return;
if (obj.FirstDraw) {
obj.Canvas.canvas.width = obj.ScreenWidth;
obj.Canvas.canvas.height = obj.ScreenHeight;
obj.Canvas.fillRect(0, 0, obj.ScreenWidth, obj.ScreenHeight);
if (obj.onScreenResize != null) obj.onScreenResize(obj, obj.ScreenWidth, obj.ScreenHeight, obj.CanvasId);
}
obj.FirstDraw = false;
//obj.Debug("onResize: " + obj.ScreenWidth + " x " + obj.ScreenHeight);
}
obj.xxMouseInputGrab = false;
obj.xxKeyInputGrab = false;
obj.xxMouseMove = function (e) { if (obj.State == 3) obj.SendMouseMsg(obj.KeyAction.NONE, e); if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxMouseUp = function (e) { if (obj.State == 3) obj.SendMouseMsg(obj.KeyAction.UP, e); if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxMouseDown = function (e) { if (obj.State == 3) obj.SendMouseMsg(obj.KeyAction.DOWN, e); if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxDOMMouseScroll = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
obj.xxMouseWheel = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
obj.xxKeyUp = function (e) { if (obj.State == 3) { obj.SendKeyMsg(obj.KeyAction.UP, e); } if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxKeyDown = function (e) { if (obj.State == 3) { obj.SendKeyMsg(obj.KeyAction.DOWN, e); } if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxKeyPress = function (e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
// Key handlers
obj.handleKeys = function (e) { return obj.xxKeyPress(e); }
obj.handleKeyUp = function (e) { return obj.xxKeyUp(e); }
obj.handleKeyDown = function (e) { return obj.xxKeyDown(e); }
// Mouse handlers
obj.mousedown = function (e) { return obj.xxMouseDown(e); }
obj.mouseup = function (e) { return obj.xxMouseUp(e); }
obj.mousemove = function (e) { return obj.xxMouseMove(e); }
obj.xxMsTouchEvent = function (evt) {
if (evt.originalEvent.pointerType == 4) return; // If this is a mouse pointer, ignore this event. Touch & pen are ok.
if (evt.preventDefault) evt.preventDefault();
if (evt.stopPropagation) evt.stopPropagation();
if (evt.type == 'MSPointerDown' || evt.type == 'MSPointerMove' || evt.type == 'MSPointerUp') {
var flags = 0;
var id = evt.originalEvent.pointerId % 256;
var X = evt.offsetX * (Canvas.canvas.width / obj.CanvasId.clientWidth);
var Y = evt.offsetY * (Canvas.canvas.height / obj.CanvasId.clientHeight);
if (evt.type == 'MSPointerDown') flags = 0x00010000 | 0x00000002 | 0x00000004; // POINTER_FLAG_DOWN
else if (evt.type == 'MSPointerMove') {
//if (obj.TouchArray[id] && MuchTheSame(obj.TouchArray[id].x, X) && MuchTheSame(obj.TouchArray[id].y, Y)) return;
flags = 0x00020000 | 0x00000002 | 0x00000004; // POINTER_FLAG_UPDATE
}
else if (evt.type == 'MSPointerUp') flags = 0x00040000; // POINTER_FLAG_UP
if (!obj.TouchArray[id]) obj.TouchArray[id] = { x: X, y : Y };
obj.SendTouchMsg2(id, flags)
if (evt.type == 'MSPointerUp') delete obj.TouchArray[id];
} else {
alert(evt.type);
}
return true;
}
obj.xxTouchStart = function (e) {
if (obj.State != 3) return;
if (e.preventDefault) e.preventDefault();
if (obj.touchenabled == 0 || obj.touchenabled == 1) {
if (e.originalEvent.touches.length > 1) return;
var t = e.originalEvent.touches[0];
e.which = 1;
obj.LastX = e.pageX = t.pageX;
obj.LastY = e.pageY = t.pageY;
obj.SendMouseMsg(KeyAction.DOWN, e);
} else {
var Offsets = obj.GetPositionOfControl(Canvas.canvas);
for (var i in e.originalEvent.changedTouches) {
if (!e.originalEvent.changedTouches[i].identifier) continue;
var id = e.originalEvent.changedTouches[i].identifier % 256;
if (!obj.TouchArray[id]) { obj.TouchArray[id] = { x: (e.originalEvent.touches[i].pageX - Offsets[0]) * (Canvas.canvas.width / obj.CanvasId.clientWidth), y: (e.originalEvent.touches[i].pageY - Offsets[1]) * (Canvas.canvas.height / obj.CanvasId.clientHeight), f: 1 }; }
}
if (Object.keys(obj.TouchArray).length > 0 && touchtimer == null) { obj.touchtimer = setInterval(function () { obj.SendTouchMsg2(256, 0); }, 50); }
}
}
obj.xxTouchMove = function (e) {
if (obj.State != 3) return;
if (e.preventDefault) e.preventDefault();
if (obj.touchenabled == 0 || obj.touchenabled == 1) {
if (e.originalEvent.touches.length > 1) return;
var t = e.originalEvent.touches[0];
e.which = 1;
obj.LastX = e.pageX = t.pageX;
obj.LastY = e.pageY = t.pageY;
obj.SendMouseMsg(obj.KeyAction.NONE, e);
} else {
var Offsets = obj.GetPositionOfControl(Canvas.canvas);
for (var i in e.originalEvent.changedTouches) {
if (!e.originalEvent.changedTouches[i].identifier) continue;
var id = e.originalEvent.changedTouches[i].identifier % 256;
if (obj.TouchArray[id]) {
obj.TouchArray[id].x = (e.originalEvent.touches[i].pageX - Offsets[0]) * (obj.Canvas.canvas.width / obj.CanvasId.clientWidth);
obj.TouchArray[id].y = (e.originalEvent.touches[i].pageY - Offsets[1]) * (obj.Canvas.canvas.height / obj.CanvasId.clientHeight);
}
}
}
}
obj.xxTouchEnd = function (e) {
if (obj.State != 3) return;
if (e.preventDefault) e.preventDefault();
if (obj.touchenabled == 0 || obj.touchenabled == 1) {
if (e.originalEvent.touches.length > 1) return;
e.which = 1;
e.pageX = LastX;
e.pageY = LastY;
obj.SendMouseMsg(KeyAction.UP, e);
} else {
for (var i in e.originalEvent.changedTouches) {
if (!e.originalEvent.changedTouches[i].identifier) continue;
var id = e.originalEvent.changedTouches[i].identifier % 256;
if (obj.TouchArray[id]) obj.TouchArray[id].f = 2;
}
}
}
obj.GrabMouseInput = function () {
if (obj.xxMouseInputGrab == true) return;
var c = obj.CanvasId;
c.onmousemove = obj.xxMouseMove;
c.onmouseup = obj.xxMouseUp;
c.onmousedown = obj.xxMouseDown;
c.touchstart = obj.xxTouchStart;
c.touchmove = obj.xxTouchMove;
c.touchend = obj.xxTouchEnd;
c.MSPointerDown = obj.xxMsTouchEvent;
c.MSPointerMove = obj.xxMsTouchEvent;
c.MSPointerUp = obj.xxMsTouchEvent;
if (navigator.userAgent.match(/mozilla/i)) c.DOMMouseScroll = obj.xxDOMMouseScroll; else c.onmousewheel = obj.xxMouseWheel;
obj.xxMouseInputGrab = true;
}
obj.UnGrabMouseInput = function () {
if (obj.xxMouseInputGrab == false) return;
var c = obj.CanvasId;
c.onmousemove = null;
c.onmouseup = null;
c.onmousedown = null;
c.touchstart = null;
c.touchmove = null;
c.touchend = null;
c.MSPointerDown = null;
c.MSPointerMove = null;
c.MSPointerUp = null;
if (navigator.userAgent.match(/mozilla/i)) c.DOMMouseScroll = null; else c.onmousewheel = null;
obj.xxMouseInputGrab = false;
}
obj.GrabKeyInput = function () {
if (obj.xxKeyInputGrab == true) return;
document.onkeyup = obj.xxKeyUp;
document.onkeydown = obj.xxKeyDown;
document.onkeypress = obj.xxKeyPress;
obj.xxKeyInputGrab = true;
}
obj.UnGrabKeyInput = function () {
if (obj.xxKeyInputGrab == false) return;
document.onkeyup = null;
document.onkeydown = null;
document.onkeypress = null;
obj.xxKeyInputGrab = false;
}
obj.GetPositionOfControl = function (Control) {
var Position = Array(2);
Position[0] = Position[1] = 0;
while (Control) { Position[0] += Control.offsetLeft; Position[1] += Control.offsetTop; Control = Control.offsetParent; }
return Position;
}
obj.crotX = function (x, y) {
if (obj.rotation == 0) return x;
if (obj.rotation == 1) return y;
if (obj.rotation == 2) return obj.Canvas.canvas.width - x;
if (obj.rotation == 3) return obj.Canvas.canvas.height - y;
}
obj.crotY = function (x, y) {
if (obj.rotation == 0) return y;
if (obj.rotation == 1) return obj.Canvas.canvas.width - x;
if (obj.rotation == 2) return obj.Canvas.canvas.height - y;
if (obj.rotation == 3) return x;
}
obj.rotX = function (x, y) {
if (obj.rotation == 0 || obj.rotation == 1) return x;
if (obj.rotation == 2) return x - obj.Canvas.canvas.width;
if (obj.rotation == 3) return x - obj.Canvas.canvas.height;
}
obj.rotY = function (x, y) {
if (obj.rotation == 0 || obj.rotation == 3) return y;
if (obj.rotation == 1) return y - obj.Canvas.canvas.width;
if (obj.rotation == 2) return y - obj.Canvas.canvas.height;
}
obj.tcanvas = null;
obj.setRotation = function (x) {
while (x < 0) { x += 4; }
var newrotation = x % 4;
if (newrotation == obj.rotation) return true;
var rw = obj.Canvas.canvas.width;
var rh = obj.Canvas.canvas.height;
if (obj.rotation == 1 || obj.rotation == 3) { rw = obj.Canvas.canvas.height; rh = obj.Canvas.canvas.width; }
// Copy the canvas, put it back in the correct direction
if (obj.tcanvas == null) obj.tcanvas = document.createElement('canvas');
var tcanvasctx = obj.tcanvas.getContext('2d');
tcanvasctx.setTransform(1, 0, 0, 1, 0, 0);
tcanvasctx.canvas.width = rw;
tcanvasctx.canvas.height = rh;
tcanvasctx.rotate((obj.rotation * -90) * Math.PI / 180);
if (obj.rotation == 0) tcanvasctx.drawImage(obj.Canvas.canvas, 0, 0);
if (obj.rotation == 1) tcanvasctx.drawImage(obj.Canvas.canvas, -obj.Canvas.canvas.width, 0);
if (obj.rotation == 2) tcanvasctx.drawImage(obj.Canvas.canvas, -obj.Canvas.canvas.width, -obj.Canvas.canvas.height);
if (obj.rotation == 3) tcanvasctx.drawImage(obj.Canvas.canvas, 0, -obj.Canvas.canvas.height);
// Change the size and orientation and copy the canvas back into the rotation
if (obj.rotation == 0 || obj.rotation == 2) { obj.Canvas.canvas.height = rw; obj.Canvas.canvas.width = rh; }
if (obj.rotation == 1 || obj.rotation == 3) { obj.Canvas.canvas.height = rh; obj.Canvas.canvas.width = rw; }
obj.Canvas.setTransform(1, 0, 0, 1, 0, 0);
obj.Canvas.rotate((newrotation * 90) * Math.PI / 180);
obj.rotation = newrotation;
obj.Canvas.drawImage(obj.tcanvas, obj.rotX(0, 0), obj.rotY(0, 0));
obj.ScreenWidth = obj.Canvas.canvas.width;
obj.ScreenHeight = obj.Canvas.canvas.height;
if (obj.onScreenResize != null) obj.onScreenResize(obj, obj.ScreenWidth, obj.ScreenHeight, obj.CanvasId);
return true;
}
// Private method
obj.MuchTheSame = function (a, b) { return (Math.abs(a - b) < 4); }
obj.Debug = function (msg) { console.log(msg); }
obj.getIEVersion = function () { var r = -1; if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) r = parseFloat(RegExp.$1); } return r; }
obj.haltEvent = function (e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
return obj;
}

View file

@ -0,0 +1,120 @@
/**
* @description Mesh Agent Transport Module - using websocket relay
* @author Ylian Saint-Hilaire
* @version v0.0.1f
*/
// Construct a MeshServer agent direction object
var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort) {
var obj = {};
obj.m = module; // This is the inner module (Terminal or Desktop)
module.parent = obj;
obj.meshserver = meshserver;
obj.nodeid = null;
obj.State = 0;
obj.socket = null;
obj.connectstate = -1;
obj.tunnelid = Math.random().toString(36).substring(2); // Generate a random client tunnel id
obj.protocol = module.protocol; // 1 = SOL, 2 = KVM, 3 = IDER, 4 = Files, 5 = FileTransfer
obj.onStateChanged = null;
// Private method
//obj.debug = function (msg) { console.log(msg); }
obj.Start = function (nodeid) {
var url2, url = window.location.protocol.replace("http", "ws") + "//" + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/meshrelay.ashx?id=" + obj.tunnelid;
if (serverPublicNamePort) { url2 = window.location.protocol.replace("http", "ws") + "//" + serverPublicNamePort + "/meshrelay.ashx?id=" + obj.tunnelid; } else { url2 = url; }
obj.nodeid = nodeid;
obj.connectstate = 0;
obj.socket = new WebSocket(url);
obj.socket.onopen = obj.xxOnSocketConnected;
obj.socket.onmessage = obj.xxOnMessage;
obj.socket.onclose = obj.xxOnSocketClosed;
obj.xxStateChange(1);
obj.meshserver.Send({ action: 'msg', type: 'tunnel', nodeid: obj.nodeid, value: url2 });
//obj.debug("Agent Redir Start: " + url);
}
obj.xxOnSocketConnected = function () {
//obj.debug("Agent Redir Socket Connected");
obj.xxStateChange(2);
}
obj.xxOnMessage = function (e) {
if (obj.State < 3) { if (e.data == 'c') { obj.socket.send(obj.protocol); obj.xxStateChange(3); return; } }
if (typeof e.data == 'object') {
var f = new FileReader();
if (f.readAsBinaryString) {
// Chrome & Firefox (Draft)
f.onload = function (e) { obj.xxOnSocketData(e.target.result); }
f.readAsBinaryString(new Blob([e.data]));
} else if (f.readAsArrayBuffer) {
// Chrome & Firefox (Spec)
f.onloadend = function (e) { obj.xxOnSocketData(e.target.result); }
f.readAsArrayBuffer(e.data);
} else {
// IE10, readAsBinaryString does not exist, use an alternative.
var binary = "";
var bytes = new Uint8Array(e.data);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
obj.xxOnSocketData(binary);
}
} else {
// If we get a string object, it maybe the WebRTC confirm. Ignore it.
//obj.debug("Agent Redir Relay - OnData - " + typeof e.data + " - " + e.data.length);
obj.xxOnSocketData(e.data);
}
};
obj.xxOnSocketData = function (data) {
if (!data || obj.connectstate == -1) return;
if (typeof data === 'object') {
// This is an ArrayBuffer, convert it to a string array (used in IE)
var binary = "", bytes = new Uint8Array(data), length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
data = binary;
}
else if (typeof data !== 'string') return;
//console.log("xxOnSocketData", rstr2hex(data));
return obj.m.ProcessData(data);
}
obj.Send = function (x) {
//obj.debug("Agent Redir Send(" + x.length + "): " + rstr2hex(x));
if (obj.socket != null && obj.socket.readyState == WebSocket.OPEN) {
if (typeof x == 'string') {
var b = new Uint8Array(x.length);
for (var i = 0; i < x.length; ++i) { b[i] = x.charCodeAt(i); }
obj.socket.send(b.buffer);
} else {
obj.socket.send(x);
}
}
}
obj.xxOnSocketClosed = function () {
//obj.debug("Agent Redir Socket Closed");
obj.Stop();
}
obj.xxStateChange = function(newstate) {
if (obj.State == newstate) return;
obj.State = newstate;
obj.m.xxStateChange(obj.State);
if (obj.onStateChanged != null) obj.onStateChanged(obj, obj.State);
}
obj.Stop = function () {
//obj.debug("Agent Redir Socket Stopped");
obj.xxStateChange(0);
obj.connectstate = -1;
if (obj.socket != null) { obj.socket.close(); obj.socket = null; }
}
return obj;
}

976
public/scripts/amt-0.2.0.js Normal file
View file

@ -0,0 +1,976 @@
/**
* @fileoverview Intel(r) AMT Communication StackXX
* @author Ylian Saint-Hilaire
* @version v0.2.0b
*/
/**
* Construct a AmtStackCreateService object, this ia the main Intel AMT communication stack.
* @constructor
*/
function AmtStackCreateService(wsmanStack) {
var obj = new Object();
obj.wsman = wsmanStack;
obj.pfx = ["http://intel.com/wbem/wscim/1/amt-schema/1/", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/", "http://intel.com/wbem/wscim/1/ips-schema/1/"];
obj.PendingEnums = [];
obj.PendingBatchOperations = 0;
obj.ActiveEnumsCount = 0;
obj.MaxActiveEnumsCount = 1; // Maximum number of enumerations that can be done at the same time.
obj.onProcessChanged = null;
var _MaxProcess = 0;
var _LastProcess = 0;
// Return the number of pending actions
obj.GetPendingActions = function () { return (obj.PendingEnums.length * 2) + (obj.ActiveEnumsCount) + obj.wsman.comm.PendingAjax.length + obj.wsman.comm.ActiveAjaxCount + obj.PendingBatchOperations; }
// Private Method, Update the current processing status, this gives the application an idea of what progress is being done by the WSMAN stack
function _up() {
var x = obj.GetPendingActions();
if (_MaxProcess < x) _MaxProcess = x;
if (obj.onProcessChanged != null && _LastProcess != x) {
//console.log("Process Old=" + _LastProcess + ", New=" + x + ", PEnums=" + obj.PendingEnums.length + ", AEnums=" + obj.ActiveEnumsCount + ", PAjax=" + obj.wsman.comm.PendingAjax.length + ", AAjax=" + obj.wsman.comm.ActiveAjaxCount + ", PBatch=" + obj.PendingBatchOperations);
_LastProcess = x;
obj.onProcessChanged(x, _MaxProcess);
}
if (x == 0) _MaxProcess = 0;
}
// Perform a WSMAN "SUBSCRIBE" operation.
obj.Subscribe = function (name, delivery, url, callback, tag, pri, selectors, opaque, user, pass) { obj.wsman.ExecSubscribe(obj.CompleteName(name), delivery, url, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri, selectors, opaque, user, pass); _up(); }
// Perform a WSMAN "UNSUBSCRIBE" operation.
obj.UnSubscribe = function (name, callback, tag, pri, selectors) { obj.wsman.ExecUnSubscribe(obj.CompleteName(name), function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri, selectors); _up(); }
// Perform a WSMAN "GET" operation.
obj.Get = function (name, callback, tag, pri) { obj.wsman.ExecGet(obj.CompleteName(name), function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri); _up(); }
// Perform a WSMAN "PUT" operation.
obj.Put = function (name, putobj, callback, tag, pri, selectors) { obj.wsman.ExecPut(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri, selectors); _up(); }
// Perform a WSMAN "CREATE" operation.
obj.Create = function (name, putobj, callback, tag, pri) { obj.wsman.ExecCreate(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri); _up(); }
// Perform a WSMAN "DELETE" operation.
obj.Delete = function (name, putobj, callback, tag, pri) { obj.wsman.ExecDelete(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri); _up(); }
// Perform a WSMAN method call operation.
obj.Exec = function (name, method, args, callback, tag, pri, selectors) { obj.wsman.ExecMethod(obj.CompleteName(name), method, args, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, obj.CompleteExecResponse(response), xstatus, tag); }, 0, pri, selectors); _up(); }
// Perform a WSMAN method call operation.
obj.ExecWithXml = function (name, method, args, callback, tag, pri, selectors) { obj.wsman.ExecMethodXml(obj.CompleteName(name), method, execArgumentsToXml(args), function (ws, resuri, response, xstatus) { _up(); callback(obj, name, obj.CompleteExecResponse(response), xstatus, tag); }, 0, pri, selectors); _up(); }
// Perform a WSMAN "ENUMERATE" operation.
obj.Enum = function (name, callback, tag, pri) {
if (obj.ActiveEnumsCount < obj.MaxActiveEnumsCount) {
obj.ActiveEnumsCount++; obj.wsman.ExecEnum(obj.CompleteName(name), function (ws, resuri, response, xstatus, tag0) { _up(); _EnumStartSink(name, response, callback, resuri, xstatus, tag0); }, tag, pri);
} else {
obj.PendingEnums.push([name, callback, tag, pri]);
}
_up();
}
// Private method
function _EnumStartSink(name, response, callback, resuri, status, tag, pri) {
if (status != 200) { callback(obj, name, null, status, tag); _EnumDoNext(1); return; }
if (response == null || response.Header["Method"] != "EnumerateResponse" || !response.Body["EnumerationContext"]) { callback(obj, name, null, 603, tag); _EnumDoNext(1); return; }
var enumctx = response.Body["EnumerationContext"];
obj.wsman.ExecPull(resuri, enumctx, function (ws, resuri, response, xstatus) { _EnumContinueSink(name, response, callback, resuri, [], xstatus, tag, pri); });
}
// Private method
function _EnumContinueSink(name, response, callback, resuri, items, status, tag, pri) {
if (status != 200) { callback(obj, name, null, status, tag); _EnumDoNext(1); return; }
if (response == null || response.Header["Method"] != "PullResponse") { callback(obj, name, null, 604, tag); _EnumDoNext(1); return; }
for (var i in response.Body["Items"]) {
if (response.Body["Items"][i] instanceof Array) {
for (var j in response.Body["Items"][i]) { items.push(response.Body["Items"][i][j]); }
} else {
items.push(response.Body["Items"][i]);
}
}
if (response.Body["EnumerationContext"]) {
var enumctx = response.Body["EnumerationContext"];
obj.wsman.ExecPull(resuri, enumctx, function (ws, resuri, response, xstatus) { _EnumContinueSink(name, response, callback, resuri, items, xstatus, tag, 1); });
} else {
_EnumDoNext(1);
callback(obj, name, items, status, tag);
_up();
}
}
// Private method
function _EnumDoNext(dec) {
obj.ActiveEnumsCount -= dec;
if (obj.ActiveEnumsCount >= obj.MaxActiveEnumsCount || obj.PendingEnums.length == 0) return;
var x = obj.PendingEnums.shift();
obj.Enum(x[0], x[1], x[2]);
_EnumDoNext(0);
}
// Perform a batch of WSMAN "ENUM" operations.
obj.BatchEnum = function (batchname, names, callback, tag, continueOnError, pri) {
obj.PendingBatchOperations += (names.length * 2);
_BatchNextEnum(batchname, Clone(names), callback, tag, {}, continueOnError, pri); _up();
}
// Request each enum in the batch, stopping if something does not return status 200
function _BatchNextEnum(batchname, names, callback, tag, results, continueOnError, pri) {
obj.PendingBatchOperations -= 2;
var n = names.shift(), f = obj.Enum;
if (n[0] == '*') { f = obj.Get; n = n.substring(1); } // If the name starts with a star, do a GET instead of an ENUM. This will reduce round trips.
//console.log((f == obj.Get?'Get ':'Enum ') + n);
// Perform a GET/ENUM action
f(n, function (stack, name, responses, status, tag0) {
tag0[2][name] = { response: (responses==null?null:responses.Body), responses: responses, status: status };
if (tag0[1].length == 0 || status == 401 || (continueOnError != true && status != 200 && status != 400)) { obj.PendingBatchOperations -= (names.length * 2); _up(); callback(obj, batchname, tag0[2], status, tag); }
else { _up(); _BatchNextEnum(batchname, names, callback, tag, tag0[2], pri); }
}, [batchname, names, results], pri);
_up();
}
// Perform a batch of WSMAN "GET" operations.
obj.BatchGet = function (batchname, names, callback, tag, pri) {
_FetchNext({ name: batchname, names: names, callback: callback, current: 0, responses: {}, tag: tag, pri: pri }); _up();
}
// Private method
function _FetchNext(batch) {
if (batch.names.length <= batch.current) {
batch.callback(obj, batch.name, batch.responses, 200, batch.tag);
} else {
obj.wsman.ExecGet(obj.CompleteName(batch.names[batch.current]), function (ws, resuri, response, xstatus) { _Fetched(batch, response, xstatus); }, batch.pri);
batch.current++;
}
_up();
}
// Private method
function _Fetched(batch, response, status) {
if (response == null || status != 200) {
batch.callback(obj, batch.name, null, status, batch.tag);
} else {
batch.responses[response.Header["Method"]] = response;
_FetchNext(batch);
}
}
// Private method
obj.CompleteName = function(name) {
if (name.indexOf("AMT_") == 0) return obj.pfx[0] + name;
if (name.indexOf("CIM_") == 0) return obj.pfx[1] + name;
if (name.indexOf("IPS_") == 0) return obj.pfx[2] + name;
}
obj.CompleteExecResponse = function (resp) {
if (resp && resp != null && resp.Body && resp.Body["ReturnValue"]) resp.Body.ReturnValueStr = obj.AmtStatusToStr(resp.Body["ReturnValue"]);
return resp;
}
obj.RequestPowerStateChange = function (PowerState, callback_func) {
obj.CIM_PowerManagementService_RequestPowerStateChange(PowerState, "<Address xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">http://schemas.xmlsoap.org/ws/2004/08/addressing</Address><ReferenceParameters xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"><ResourceURI xmlns=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\">http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem</ResourceURI><SelectorSet xmlns=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\"><Selector Name=\"CreationClassName\">CIM_ComputerSystem</Selector><Selector Name=\"Name\">ManagedSystem</Selector></SelectorSet></ReferenceParameters>", null, null, callback_func);
}
obj.SetBootConfigRole = function (Role, callback_func) {
obj.CIM_BootService_SetBootConfigRole("<Address xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">http://schemas.xmlsoap.org/ws/2004/08/addressing</Address><ReferenceParameters xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"><ResourceURI xmlns=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\">http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootConfigSetting</ResourceURI><SelectorSet xmlns=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\"><Selector Name=\"InstanceID\">Intel(r) AMT: Boot Configuration 0</Selector></SelectorSet></ReferenceParameters>", Role, callback_func);
}
// Cancel all pending queries with given status
obj.CancelAllQueries = function (s) {
obj.wsman.CancelAllQueries(s);
}
// Auto generated methods
obj.AMT_AgentPresenceWatchdog_RegisterAgent = function (callback_func) { obj.Exec("AMT_AgentPresenceWatchdog", "RegisterAgent", {}, callback_func); }
obj.AMT_AgentPresenceWatchdog_AssertPresence = function (SequenceNumber, callback_func) { obj.Exec("AMT_AgentPresenceWatchdog", "AssertPresence", { "SequenceNumber": SequenceNumber }, callback_func); }
obj.AMT_AgentPresenceWatchdog_AssertShutdown = function (SequenceNumber, callback_func) { obj.Exec("AMT_AgentPresenceWatchdog", "AssertShutdown", { "SequenceNumber": SequenceNumber }, callback_func); }
obj.AMT_AgentPresenceWatchdog_AddAction = function (OldState, NewState, EventOnTransition, ActionSd, ActionEac, callback_func, tag, pri, selectors) { obj.Exec("AMT_AgentPresenceWatchdog", "AddAction", { "OldState": OldState, "NewState": NewState, "EventOnTransition": EventOnTransition, "ActionSd": ActionSd, "ActionEac": ActionEac }, callback_func, tag, pri, selectors); }
obj.AMT_AgentPresenceWatchdog_DeleteAllActions = function (callback_func, tag, pri, selectors) { obj.Exec("AMT_AgentPresenceWatchdog", "DeleteAllActions", {}, callback_func, tag, pri, selectors); }
obj.AMT_AgentPresenceWatchdogAction_GetActionEac = function (callback_func) { obj.Exec("AMT_AgentPresenceWatchdogAction", "GetActionEac", {}, callback_func); }
obj.AMT_AgentPresenceWatchdogVA_RegisterAgent = function (callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "RegisterAgent", {}, callback_func); }
obj.AMT_AgentPresenceWatchdogVA_AssertPresence = function (SequenceNumber, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "AssertPresence", { "SequenceNumber": SequenceNumber }, callback_func); }
obj.AMT_AgentPresenceWatchdogVA_AssertShutdown = function (SequenceNumber, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "AssertShutdown", { "SequenceNumber": SequenceNumber }, callback_func); }
obj.AMT_AgentPresenceWatchdogVA_AddAction = function (OldState, NewState, EventOnTransition, ActionSd, ActionEac, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "AddAction", { "OldState": OldState, "NewState": NewState, "EventOnTransition": EventOnTransition, "ActionSd": ActionSd, "ActionEac": ActionEac }, callback_func); }
obj.AMT_AgentPresenceWatchdogVA_DeleteAllActions = function (_method_dummy, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "DeleteAllActions", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_AuditLog_ClearLog = function (callback_func) { obj.Exec("AMT_AuditLog", "ClearLog", {}, callback_func); }
obj.AMT_AuditLog_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_AuditLog", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.AMT_AuditLog_ReadRecords = function (StartIndex, callback_func, tag) { obj.Exec("AMT_AuditLog", "ReadRecords", { "StartIndex": StartIndex }, callback_func, tag); }
obj.AMT_AuditLog_SetAuditLock = function (LockTimeoutInSeconds, Flag, Handle, callback_func) { obj.Exec("AMT_AuditLog", "SetAuditLock", { "LockTimeoutInSeconds": LockTimeoutInSeconds, "Flag": Flag, "Handle": Handle }, callback_func); }
obj.AMT_AuditLog_ExportAuditLogSignature = function (SigningMechanism, callback_func) { obj.Exec("AMT_AuditLog", "ExportAuditLogSignature", { "SigningMechanism": SigningMechanism }, callback_func); }
obj.AMT_AuditLog_SetSigningKeyMaterial = function (SigningMechanismType, SigningKey, LengthOfCertificates, Certificates, callback_func) { obj.Exec("AMT_AuditLog", "SetSigningKeyMaterial", { "SigningMechanismType": SigningMechanismType, "SigningKey": SigningKey, "LengthOfCertificates": LengthOfCertificates, "Certificates": Certificates }, callback_func); }
obj.AMT_AuditPolicyRule_SetAuditPolicy = function (Enable, AuditedAppID, EventID, PolicyType, callback_func) { obj.Exec("AMT_AuditPolicyRule", "SetAuditPolicy", { "Enable": Enable, "AuditedAppID": AuditedAppID, "EventID": EventID, "PolicyType": PolicyType }, callback_func); }
obj.AMT_AuditPolicyRule_SetAuditPolicyBulk = function (Enable, AuditedAppID, EventID, PolicyType, callback_func) { obj.Exec("AMT_AuditPolicyRule", "SetAuditPolicyBulk", { "Enable": Enable, "AuditedAppID": AuditedAppID, "EventID": EventID, "PolicyType": PolicyType }, callback_func); }
obj.AMT_AuthorizationService_AddUserAclEntryEx = function (DigestUsername, DigestPassword, KerberosUserSid, AccessPermission, Realms, callback_func) { obj.Exec("AMT_AuthorizationService", "AddUserAclEntryEx", { "DigestUsername": DigestUsername, "DigestPassword": DigestPassword, "KerberosUserSid": KerberosUserSid, "AccessPermission": AccessPermission, "Realms": Realms }, callback_func); }
obj.AMT_AuthorizationService_EnumerateUserAclEntries = function (StartIndex, callback_func) { obj.Exec("AMT_AuthorizationService", "EnumerateUserAclEntries", { "StartIndex": StartIndex }, callback_func); }
obj.AMT_AuthorizationService_GetUserAclEntryEx = function (Handle, callback_func, tag) { obj.Exec("AMT_AuthorizationService", "GetUserAclEntryEx", { "Handle": Handle }, callback_func, tag); }
obj.AMT_AuthorizationService_UpdateUserAclEntryEx = function (Handle, DigestUsername, DigestPassword, KerberosUserSid, AccessPermission, Realms, callback_func) { obj.Exec("AMT_AuthorizationService", "UpdateUserAclEntryEx", { "Handle": Handle, "DigestUsername": DigestUsername, "DigestPassword": DigestPassword, "KerberosUserSid": KerberosUserSid, "AccessPermission": AccessPermission, "Realms": Realms }, callback_func); }
obj.AMT_AuthorizationService_RemoveUserAclEntry = function (Handle, callback_func) { obj.Exec("AMT_AuthorizationService", "RemoveUserAclEntry", { "Handle": Handle }, callback_func); }
obj.AMT_AuthorizationService_SetAdminAclEntryEx = function (Username, DigestPassword, callback_func) { obj.Exec("AMT_AuthorizationService", "SetAdminAclEntryEx", { "Username": Username, "DigestPassword": DigestPassword }, callback_func); }
obj.AMT_AuthorizationService_GetAdminAclEntry = function (callback_func) { obj.Exec("AMT_AuthorizationService", "GetAdminAclEntry", {}, callback_func); }
obj.AMT_AuthorizationService_GetAdminAclEntryStatus = function (callback_func) { obj.Exec("AMT_AuthorizationService", "GetAdminAclEntryStatus", {}, callback_func); }
obj.AMT_AuthorizationService_GetAdminNetAclEntryStatus = function (callback_func) { obj.Exec("AMT_AuthorizationService", "GetAdminNetAclEntryStatus", {}, callback_func); }
obj.AMT_AuthorizationService_SetAclEnabledState = function (Handle, Enabled, callback_func, tag) { obj.Exec("AMT_AuthorizationService", "SetAclEnabledState", { "Handle": Handle, "Enabled": Enabled }, callback_func, tag); }
obj.AMT_AuthorizationService_GetAclEnabledState = function (Handle, callback_func, tag) { obj.Exec("AMT_AuthorizationService", "GetAclEnabledState", { "Handle": Handle }, callback_func, tag); }
obj.AMT_EndpointAccessControlService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_EndpointAccessControlService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.AMT_EndpointAccessControlService_GetPosture = function (PostureType, callback_func) { obj.Exec("AMT_EndpointAccessControlService", "GetPosture", { "PostureType": PostureType }, callback_func); }
obj.AMT_EndpointAccessControlService_GetPostureHash = function (PostureType, callback_func) { obj.Exec("AMT_EndpointAccessControlService", "GetPostureHash", { "PostureType": PostureType }, callback_func); }
obj.AMT_EndpointAccessControlService_UpdatePostureState = function (UpdateType, callback_func) { obj.Exec("AMT_EndpointAccessControlService", "UpdatePostureState", { "UpdateType": UpdateType }, callback_func); }
obj.AMT_EndpointAccessControlService_GetEacOptions = function (callback_func) { obj.Exec("AMT_EndpointAccessControlService", "GetEacOptions", {}, callback_func); }
obj.AMT_EndpointAccessControlService_SetEacOptions = function (EacVendors, PostureHashAlgorithm, callback_func) { obj.Exec("AMT_EndpointAccessControlService", "SetEacOptions", { "EacVendors": EacVendors, "PostureHashAlgorithm": PostureHashAlgorithm }, callback_func); }
obj.AMT_EnvironmentDetectionSettingData_SetSystemDefensePolicy = function (Policy, callback_func) { obj.Exec("AMT_EnvironmentDetectionSettingData", "SetSystemDefensePolicy", { "Policy": Policy }, callback_func); }
obj.AMT_EnvironmentDetectionSettingData_EnableVpnRouting = function (Enable, callback_func) { obj.Exec("AMT_EnvironmentDetectionSettingData", "EnableVpnRouting", { "Enable": Enable }, callback_func); }
obj.AMT_EthernetPortSettings_SetLinkPreference = function (LinkPreference, Timeout, callback_func) { obj.Exec("AMT_EthernetPortSettings", "SetLinkPreference", { "LinkPreference": LinkPreference, "Timeout": Timeout }, callback_func); }
obj.AMT_HeuristicPacketFilterStatistics_ResetSelectedStats = function (SelectedStatistics, callback_func) { obj.Exec("AMT_HeuristicPacketFilterStatistics", "ResetSelectedStats", { "SelectedStatistics": SelectedStatistics }, callback_func); }
obj.AMT_KerberosSettingData_GetCredentialCacheState = function (callback_func) { obj.Exec("AMT_KerberosSettingData", "GetCredentialCacheState", {}, callback_func); }
obj.AMT_KerberosSettingData_SetCredentialCacheState = function (Enable, callback_func) { obj.Exec("AMT_KerberosSettingData", "SetCredentialCacheState", { "Enable": Enable }, callback_func); }
obj.AMT_MessageLog_CancelIteration = function (IterationIdentifier, callback_func) { obj.Exec("AMT_MessageLog", "CancelIteration", { "IterationIdentifier": IterationIdentifier }, callback_func); }
obj.AMT_MessageLog_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_MessageLog", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.AMT_MessageLog_ClearLog = function (callback_func) { obj.Exec("AMT_MessageLog", "ClearLog", { }, callback_func); }
obj.AMT_MessageLog_GetRecords = function (IterationIdentifier, MaxReadRecords, callback_func, tag) { obj.Exec("AMT_MessageLog", "GetRecords", { "IterationIdentifier": IterationIdentifier, "MaxReadRecords": MaxReadRecords }, callback_func, tag); }
obj.AMT_MessageLog_GetRecord = function (IterationIdentifier, PositionToNext, callback_func) { obj.Exec("AMT_MessageLog", "GetRecord", { "IterationIdentifier": IterationIdentifier, "PositionToNext": PositionToNext }, callback_func); }
obj.AMT_MessageLog_PositionAtRecord = function (IterationIdentifier, MoveAbsolute, RecordNumber, callback_func) { obj.Exec("AMT_MessageLog", "PositionAtRecord", { "IterationIdentifier": IterationIdentifier, "MoveAbsolute": MoveAbsolute, "RecordNumber": RecordNumber }, callback_func); }
obj.AMT_MessageLog_PositionToFirstRecord = function (callback_func, tag) { obj.Exec("AMT_MessageLog", "PositionToFirstRecord", {}, callback_func, tag); }
obj.AMT_MessageLog_FreezeLog = function (Freeze, callback_func) { obj.Exec("AMT_MessageLog", "FreezeLog", { "Freeze": Freeze }, callback_func); }
obj.AMT_PublicKeyManagementService_AddCRL = function (Url, SerialNumbers, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "AddCRL", { "Url": Url, "SerialNumbers": SerialNumbers }, callback_func); }
obj.AMT_PublicKeyManagementService_ResetCRLList = function (_method_dummy, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "ResetCRLList", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_PublicKeyManagementService_AddCertificate = function (CertificateBlob, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "AddCertificate", { "CertificateBlob": CertificateBlob }, callback_func); }
obj.AMT_PublicKeyManagementService_AddTrustedRootCertificate = function (CertificateBlob, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "AddTrustedRootCertificate", { "CertificateBlob": CertificateBlob }, callback_func); }
obj.AMT_PublicKeyManagementService_AddKey = function (KeyBlob, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "AddKey", { "KeyBlob": KeyBlob }, callback_func); }
obj.AMT_PublicKeyManagementService_GeneratePKCS10Request = function (KeyPair, DNName, Usage, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "GeneratePKCS10Request", { "KeyPair": KeyPair, "DNName": DNName, "Usage": Usage }, callback_func); }
obj.AMT_PublicKeyManagementService_GeneratePKCS10RequestEx = function (KeyPair, SigningAlgorithm, NullSignedCertificateRequest, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "GeneratePKCS10RequestEx", { "KeyPair": KeyPair, "SigningAlgorithm": SigningAlgorithm, "NullSignedCertificateRequest": NullSignedCertificateRequest }, callback_func); }
obj.AMT_PublicKeyManagementService_GenerateKeyPair = function (KeyAlgorithm, KeyLength, callback_func) { obj.Exec("AMT_PublicKeyManagementService", "GenerateKeyPair", { "KeyAlgorithm": KeyAlgorithm, "KeyLength": KeyLength }, callback_func); }
obj.AMT_RedirectionService_RequestStateChange = function (RequestedState, callback_func) { obj.Exec("AMT_RedirectionService", "RequestStateChange", { "RequestedState": RequestedState }, callback_func); }
obj.AMT_RedirectionService_TerminateSession = function (SessionType, callback_func) { obj.Exec("AMT_RedirectionService", "TerminateSession", { "SessionType": SessionType }, callback_func); }
obj.AMT_RemoteAccessService_AddMpServer = function (AccessInfo, InfoFormat, Port, AuthMethod, Certificate, Username, Password, CN, callback_func) { obj.Exec("AMT_RemoteAccessService", "AddMpServer", { "AccessInfo": AccessInfo, "InfoFormat": InfoFormat, "Port": Port, "AuthMethod": AuthMethod, "Certificate": Certificate, "Username": Username, "Password": Password, "CN": CN }, callback_func); }
obj.AMT_RemoteAccessService_AddRemoteAccessPolicyRule = function (Trigger, TunnelLifeTime, ExtendedData, MpServer, callback_func) { obj.Exec("AMT_RemoteAccessService", "AddRemoteAccessPolicyRule", { "Trigger": Trigger, "TunnelLifeTime": TunnelLifeTime, "ExtendedData": ExtendedData, "MpServer": MpServer }, callback_func); }
obj.AMT_RemoteAccessService_CloseRemoteAccessConnection = function (_method_dummy, callback_func) { obj.Exec("AMT_RemoteAccessService", "CloseRemoteAccessConnection", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_SetupAndConfigurationService_CommitChanges = function (_method_dummy, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "CommitChanges", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_SetupAndConfigurationService_Unprovision = function (ProvisioningMode, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "Unprovision", { "ProvisioningMode": ProvisioningMode }, callback_func); }
obj.AMT_SetupAndConfigurationService_PartialUnprovision = function (_method_dummy, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "PartialUnprovision", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_SetupAndConfigurationService_ResetFlashWearOutProtection = function (_method_dummy, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "ResetFlashWearOutProtection", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_SetupAndConfigurationService_ExtendProvisioningPeriod = function (Duration, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "ExtendProvisioningPeriod", { "Duration": Duration }, callback_func); }
obj.AMT_SetupAndConfigurationService_SetMEBxPassword = function (Password, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "SetMEBxPassword", { "Password": Password }, callback_func); }
obj.AMT_SetupAndConfigurationService_SetTLSPSK = function (PID, PPS, callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "SetTLSPSK", { "PID": PID, "PPS": PPS }, callback_func); }
obj.AMT_SetupAndConfigurationService_GetProvisioningAuditRecord = function (callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "GetProvisioningAuditRecord", {}, callback_func); }
obj.AMT_SetupAndConfigurationService_GetUuid = function (callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "GetUuid", {}, callback_func); }
obj.AMT_SetupAndConfigurationService_GetUnprovisionBlockingComponents = function (callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "GetUnprovisionBlockingComponents", {}, callback_func); }
obj.AMT_SetupAndConfigurationService_GetProvisioningAuditRecordV2 = function (callback_func) { obj.Exec("AMT_SetupAndConfigurationService", "GetProvisioningAuditRecordV2", {}, callback_func); }
obj.AMT_SystemDefensePolicy_GetTimeout = function (callback_func) { obj.Exec("AMT_SystemDefensePolicy", "GetTimeout", {}, callback_func); }
obj.AMT_SystemDefensePolicy_SetTimeout = function (Timeout, callback_func) { obj.Exec("AMT_SystemDefensePolicy", "SetTimeout", { "Timeout": Timeout }, callback_func); }
obj.AMT_SystemDefensePolicy_UpdateStatistics = function (NetworkInterface, ResetOnRead, callback_func, tag, pri, selectors) { obj.Exec("AMT_SystemDefensePolicy", "UpdateStatistics", { "NetworkInterface": NetworkInterface, "ResetOnRead": ResetOnRead }, callback_func, tag, pri, selectors); }
obj.AMT_SystemPowerScheme_SetPowerScheme = function (callback_func, schemeInstanceId, tag) { obj.Exec("AMT_SystemPowerScheme", "SetPowerScheme", {}, callback_func, tag, 0, { "InstanceID": schemeInstanceId }); }
obj.AMT_TimeSynchronizationService_GetLowAccuracyTimeSynch = function (callback_func, tag) { obj.Exec("AMT_TimeSynchronizationService", "GetLowAccuracyTimeSynch", {}, callback_func, tag); }
obj.AMT_TimeSynchronizationService_SetHighAccuracyTimeSynch = function (Ta0, Tm1, Tm2, callback_func, tag) { obj.Exec("AMT_TimeSynchronizationService", "SetHighAccuracyTimeSynch", { "Ta0": Ta0, "Tm1": Tm1, "Tm2": Tm2 }, callback_func, tag); }
obj.AMT_UserInitiatedConnectionService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_UserInitiatedConnectionService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.AMT_WebUIService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_WebUIService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.AMT_WiFiPortConfigurationService_AddWiFiSettings = function (WiFiEndpoint, WiFiEndpointSettingsInput, IEEE8021xSettingsInput, ClientCredential, CACredential, callback_func) { obj.ExecWithXml("AMT_WiFiPortConfigurationService", "AddWiFiSettings", { "WiFiEndpoint": WiFiEndpoint, "WiFiEndpointSettingsInput": WiFiEndpointSettingsInput, "IEEE8021xSettingsInput": IEEE8021xSettingsInput, "ClientCredential": ClientCredential, "CACredential": CACredential }, callback_func); }
obj.AMT_WiFiPortConfigurationService_UpdateWiFiSettings = function (WiFiEndpointSettings, WiFiEndpointSettingsInput, IEEE8021xSettingsInput, ClientCredential, CACredential, callback_func) { obj.ExecWithXml("AMT_WiFiPortConfigurationService", "UpdateWiFiSettings", { "WiFiEndpointSettings": WiFiEndpointSettings, "WiFiEndpointSettingsInput": WiFiEndpointSettingsInput, "IEEE8021xSettingsInput": IEEE8021xSettingsInput, "ClientCredential": ClientCredential, "CACredential": CACredential }, callback_func); }
obj.AMT_WiFiPortConfigurationService_DeleteAllITProfiles = function (_method_dummy, callback_func) { obj.Exec("AMT_WiFiPortConfigurationService", "DeleteAllITProfiles", { "_method_dummy": _method_dummy }, callback_func); }
obj.AMT_WiFiPortConfigurationService_DeleteAllUserProfiles = function (_method_dummy, callback_func) { obj.Exec("AMT_WiFiPortConfigurationService", "DeleteAllUserProfiles", { "_method_dummy": _method_dummy }, callback_func); }
obj.CIM_Account_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_Account", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_AccountManagementService_CreateAccount = function (System, AccountTemplate, callback_func) { obj.Exec("CIM_AccountManagementService", "CreateAccount", { "System": System, "AccountTemplate": AccountTemplate }, callback_func); }
obj.CIM_BootConfigSetting_ChangeBootOrder = function (Source, callback_func) { obj.Exec("CIM_BootConfigSetting", "ChangeBootOrder", { "Source": Source }, callback_func); }
obj.CIM_BootService_SetBootConfigRole = function (BootConfigSetting, Role, callback_func) { obj.Exec("CIM_BootService", "SetBootConfigRole", { "BootConfigSetting": BootConfigSetting, "Role": Role }, callback_func, 0, 1); }
obj.CIM_Card_ConnectorPower = function (Connector, PoweredOn, callback_func) { obj.Exec("CIM_Card", "ConnectorPower", { "Connector": Connector, "PoweredOn": PoweredOn }, callback_func); }
obj.CIM_Card_IsCompatible = function (ElementToCheck, callback_func) { obj.Exec("CIM_Card", "IsCompatible", { "ElementToCheck": ElementToCheck }, callback_func); }
obj.CIM_Chassis_IsCompatible = function (ElementToCheck, callback_func) { obj.Exec("CIM_Chassis", "IsCompatible", { "ElementToCheck": ElementToCheck }, callback_func); }
obj.CIM_Fan_SetSpeed = function (DesiredSpeed, callback_func) { obj.Exec("CIM_Fan", "SetSpeed", { "DesiredSpeed": DesiredSpeed }, callback_func); }
obj.CIM_KVMRedirectionSAP_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_KVMRedirectionSAP", "RequestStateChange", { "RequestedState": RequestedState/*, "TimeoutPeriod": TimeoutPeriod */}, callback_func); }
obj.CIM_MediaAccessDevice_LockMedia = function (Lock, callback_func) { obj.Exec("CIM_MediaAccessDevice", "LockMedia", { "Lock": Lock }, callback_func); }
obj.CIM_MediaAccessDevice_SetPowerState = function (PowerState, Time, callback_func) { obj.Exec("CIM_MediaAccessDevice", "SetPowerState", { "PowerState": PowerState, "Time": Time }, callback_func); }
obj.CIM_MediaAccessDevice_Reset = function (callback_func) { obj.Exec("CIM_MediaAccessDevice", "Reset", {}, callback_func); }
obj.CIM_MediaAccessDevice_EnableDevice = function (Enabled, callback_func) { obj.Exec("CIM_MediaAccessDevice", "EnableDevice", { "Enabled": Enabled }, callback_func); }
obj.CIM_MediaAccessDevice_OnlineDevice = function (Online, callback_func) { obj.Exec("CIM_MediaAccessDevice", "OnlineDevice", { "Online": Online }, callback_func); }
obj.CIM_MediaAccessDevice_QuiesceDevice = function (Quiesce, callback_func) { obj.Exec("CIM_MediaAccessDevice", "QuiesceDevice", { "Quiesce": Quiesce }, callback_func); }
obj.CIM_MediaAccessDevice_SaveProperties = function (callback_func) { obj.Exec("CIM_MediaAccessDevice", "SaveProperties", {}, callback_func); }
obj.CIM_MediaAccessDevice_RestoreProperties = function (callback_func) { obj.Exec("CIM_MediaAccessDevice", "RestoreProperties", {}, callback_func); }
obj.CIM_MediaAccessDevice_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_MediaAccessDevice", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_PhysicalFrame_IsCompatible = function (ElementToCheck, callback_func) { obj.Exec("CIM_PhysicalFrame", "IsCompatible", { "ElementToCheck": ElementToCheck }, callback_func); }
obj.CIM_PhysicalPackage_IsCompatible = function (ElementToCheck, callback_func) { obj.Exec("CIM_PhysicalPackage", "IsCompatible", { "ElementToCheck": ElementToCheck }, callback_func); }
obj.CIM_PowerManagementService_RequestPowerStateChange = function (PowerState, ManagedElement, Time, TimeoutPeriod, callback_func) { obj.Exec("CIM_PowerManagementService", "RequestPowerStateChange", { "PowerState": PowerState, "ManagedElement": ManagedElement, "Time": Time, "TimeoutPeriod": TimeoutPeriod }, callback_func, 0, 1); }
obj.CIM_PowerSupply_SetPowerState = function (PowerState, Time, callback_func) { obj.Exec("CIM_PowerSupply", "SetPowerState", { "PowerState": PowerState, "Time": Time }, callback_func); }
obj.CIM_PowerSupply_Reset = function (callback_func) { obj.Exec("CIM_PowerSupply", "Reset", {}, callback_func); }
obj.CIM_PowerSupply_EnableDevice = function (Enabled, callback_func) { obj.Exec("CIM_PowerSupply", "EnableDevice", { "Enabled": Enabled }, callback_func); }
obj.CIM_PowerSupply_OnlineDevice = function (Online, callback_func) { obj.Exec("CIM_PowerSupply", "OnlineDevice", { "Online": Online }, callback_func); }
obj.CIM_PowerSupply_QuiesceDevice = function (Quiesce, callback_func) { obj.Exec("CIM_PowerSupply", "QuiesceDevice", { "Quiesce": Quiesce }, callback_func); }
obj.CIM_PowerSupply_SaveProperties = function (callback_func) { obj.Exec("CIM_PowerSupply", "SaveProperties", {}, callback_func); }
obj.CIM_PowerSupply_RestoreProperties = function (callback_func) { obj.Exec("CIM_PowerSupply", "RestoreProperties", {}, callback_func); }
obj.CIM_PowerSupply_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_PowerSupply", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_Processor_SetPowerState = function (PowerState, Time, callback_func) { obj.Exec("CIM_Processor", "SetPowerState", { "PowerState": PowerState, "Time": Time }, callback_func); }
obj.CIM_Processor_Reset = function (callback_func) { obj.Exec("CIM_Processor", "Reset", {}, callback_func); }
obj.CIM_Processor_EnableDevice = function (Enabled, callback_func) { obj.Exec("CIM_Processor", "EnableDevice", { "Enabled": Enabled }, callback_func); }
obj.CIM_Processor_OnlineDevice = function (Online, callback_func) { obj.Exec("CIM_Processor", "OnlineDevice", { "Online": Online }, callback_func); }
obj.CIM_Processor_QuiesceDevice = function (Quiesce, callback_func) { obj.Exec("CIM_Processor", "QuiesceDevice", { "Quiesce": Quiesce }, callback_func); }
obj.CIM_Processor_SaveProperties = function (callback_func) { obj.Exec("CIM_Processor", "SaveProperties", {}, callback_func); }
obj.CIM_Processor_RestoreProperties = function (callback_func) { obj.Exec("CIM_Processor", "RestoreProperties", {}, callback_func); }
obj.CIM_Processor_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_Processor", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_RecordLog_ClearLog = function (callback_func) { obj.Exec("CIM_RecordLog", "ClearLog", {}, callback_func); }
obj.CIM_RecordLog_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_RecordLog", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_RedirectionService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_RedirectionService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_Sensor_SetPowerState = function (PowerState, Time, callback_func) { obj.Exec("CIM_Sensor", "SetPowerState", { "PowerState": PowerState, "Time": Time }, callback_func); }
obj.CIM_Sensor_Reset = function (callback_func) { obj.Exec("CIM_Sensor", "Reset", {}, callback_func); }
obj.CIM_Sensor_EnableDevice = function (Enabled, callback_func) { obj.Exec("CIM_Sensor", "EnableDevice", { "Enabled": Enabled }, callback_func); }
obj.CIM_Sensor_OnlineDevice = function (Online, callback_func) { obj.Exec("CIM_Sensor", "OnlineDevice", { "Online": Online }, callback_func); }
obj.CIM_Sensor_QuiesceDevice = function (Quiesce, callback_func) { obj.Exec("CIM_Sensor", "QuiesceDevice", { "Quiesce": Quiesce }, callback_func); }
obj.CIM_Sensor_SaveProperties = function (callback_func) { obj.Exec("CIM_Sensor", "SaveProperties", {}, callback_func); }
obj.CIM_Sensor_RestoreProperties = function (callback_func) { obj.Exec("CIM_Sensor", "RestoreProperties", {}, callback_func); }
obj.CIM_Sensor_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_Sensor", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_StatisticalData_ResetSelectedStats = function (SelectedStatistics, callback_func) { obj.Exec("CIM_StatisticalData", "ResetSelectedStats", { "SelectedStatistics": SelectedStatistics }, callback_func); }
obj.CIM_Watchdog_KeepAlive = function (callback_func) { obj.Exec("CIM_Watchdog", "KeepAlive", {}, callback_func); }
obj.CIM_Watchdog_SetPowerState = function (PowerState, Time, callback_func) { obj.Exec("CIM_Watchdog", "SetPowerState", { "PowerState": PowerState, "Time": Time }, callback_func); }
obj.CIM_Watchdog_Reset = function (callback_func) { obj.Exec("CIM_Watchdog", "Reset", {}, callback_func); }
obj.CIM_Watchdog_EnableDevice = function (Enabled, callback_func) { obj.Exec("CIM_Watchdog", "EnableDevice", { "Enabled": Enabled }, callback_func); }
obj.CIM_Watchdog_OnlineDevice = function (Online, callback_func) { obj.Exec("CIM_Watchdog", "OnlineDevice", { "Online": Online }, callback_func); }
obj.CIM_Watchdog_QuiesceDevice = function (Quiesce, callback_func) { obj.Exec("CIM_Watchdog", "QuiesceDevice", { "Quiesce": Quiesce }, callback_func); }
obj.CIM_Watchdog_SaveProperties = function (callback_func) { obj.Exec("CIM_Watchdog", "SaveProperties", {}, callback_func); }
obj.CIM_Watchdog_RestoreProperties = function (callback_func) { obj.Exec("CIM_Watchdog", "RestoreProperties", {}, callback_func); }
obj.CIM_Watchdog_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_Watchdog", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.CIM_WiFiPort_SetPowerState = function (PowerState, Time, callback_func) { obj.Exec("CIM_WiFiPort", "SetPowerState", { "PowerState": PowerState, "Time": Time }, callback_func); }
obj.CIM_WiFiPort_Reset = function (callback_func) { obj.Exec("CIM_WiFiPort", "Reset", {}, callback_func); }
obj.CIM_WiFiPort_EnableDevice = function (Enabled, callback_func) { obj.Exec("CIM_WiFiPort", "EnableDevice", { "Enabled": Enabled }, callback_func); }
obj.CIM_WiFiPort_OnlineDevice = function (Online, callback_func) { obj.Exec("CIM_WiFiPort", "OnlineDevice", { "Online": Online }, callback_func); }
obj.CIM_WiFiPort_QuiesceDevice = function (Quiesce, callback_func) { obj.Exec("CIM_WiFiPort", "QuiesceDevice", { "Quiesce": Quiesce }, callback_func); }
obj.CIM_WiFiPort_SaveProperties = function (callback_func) { obj.Exec("CIM_WiFiPort", "SaveProperties", {}, callback_func); }
obj.CIM_WiFiPort_RestoreProperties = function (callback_func) { obj.Exec("CIM_WiFiPort", "RestoreProperties", {}, callback_func); }
obj.CIM_WiFiPort_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("CIM_WiFiPort", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.IPS_HostBasedSetupService_Setup = function (NetAdminPassEncryptionType, NetworkAdminPassword, McNonce, Certificate, SigningAlgorithm, DigitalSignature, callback_func) { obj.Exec("IPS_HostBasedSetupService", "Setup", { "NetAdminPassEncryptionType": NetAdminPassEncryptionType, "NetworkAdminPassword": NetworkAdminPassword, "McNonce": McNonce, "Certificate": Certificate, "SigningAlgorithm": SigningAlgorithm, "DigitalSignature": DigitalSignature }, callback_func); }
obj.IPS_HostBasedSetupService_AddNextCertInChain = function (NextCertificate, IsLeafCertificate, IsRootCertificate, callback_func) { obj.Exec("IPS_HostBasedSetupService", "AddNextCertInChain", { "NextCertificate": NextCertificate, "IsLeafCertificate": IsLeafCertificate, "IsRootCertificate": IsRootCertificate }, callback_func); }
obj.IPS_HostBasedSetupService_AdminSetup = function (NetAdminPassEncryptionType, NetworkAdminPassword, McNonce, SigningAlgorithm, DigitalSignature, callback_func) { obj.Exec("IPS_HostBasedSetupService", "AdminSetup", { "NetAdminPassEncryptionType": NetAdminPassEncryptionType, "NetworkAdminPassword": NetworkAdminPassword, "McNonce": McNonce, "SigningAlgorithm": SigningAlgorithm, "DigitalSignature": DigitalSignature }, callback_func); }
obj.IPS_HostBasedSetupService_UpgradeClientToAdmin = function (McNonce, SigningAlgorithm, DigitalSignature, callback_func) { obj.Exec("IPS_HostBasedSetupService", "UpgradeClientToAdmin", { "McNonce": McNonce, "SigningAlgorithm": SigningAlgorithm, "DigitalSignature": DigitalSignature }, callback_func); }
obj.IPS_HostBasedSetupService_DisableClientControlMode = function (_method_dummy, callback_func) { obj.Exec("IPS_HostBasedSetupService", "DisableClientControlMode", { "_method_dummy": _method_dummy }, callback_func); }
obj.IPS_KVMRedirectionSettingData_TerminateSession = function (callback_func) { obj.Exec("IPS_KVMRedirectionSettingData", "TerminateSession", {}, callback_func); }
obj.IPS_OptInService_StartOptIn = function (callback_func) { obj.Exec("IPS_OptInService", "StartOptIn", {}, callback_func); }
obj.IPS_OptInService_CancelOptIn = function (callback_func) { obj.Exec("IPS_OptInService", "CancelOptIn", {}, callback_func); }
obj.IPS_OptInService_SendOptInCode = function (OptInCode, callback_func) { obj.Exec("IPS_OptInService", "SendOptInCode", { "OptInCode": OptInCode }, callback_func); }
obj.IPS_OptInService_StartService = function (callback_func) { obj.Exec("IPS_OptInService", "StartService", {}, callback_func); }
obj.IPS_OptInService_StopService = function (callback_func) { obj.Exec("IPS_OptInService", "StopService", {}, callback_func); }
obj.IPS_OptInService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("IPS_OptInService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.IPS_ProvisioningRecordLog_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("IPS_ProvisioningRecordLog", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.IPS_ProvisioningRecordLog_ClearLog = function (_method_dummy, callback_func) { obj.Exec("IPS_ProvisioningRecordLog", "ClearLog", { "_method_dummy": _method_dummy }, callback_func); }
obj.IPS_SecIOService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("IPS_SecIOService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); }
obj.AmtStatusToStr = function (code) { if (obj.AmtStatusCodes[code]) return obj.AmtStatusCodes[code]; else return "UNKNOWN_ERROR" }
obj.AmtStatusCodes = {
0x0000: "SUCCESS",
0x0001: "INTERNAL_ERROR",
0x0002: "NOT_READY",
0x0003: "INVALID_PT_MODE",
0x0004: "INVALID_MESSAGE_LENGTH",
0x0005: "TABLE_FINGERPRINT_NOT_AVAILABLE",
0x0006: "INTEGRITY_CHECK_FAILED",
0x0007: "UNSUPPORTED_ISVS_VERSION",
0x0008: "APPLICATION_NOT_REGISTERED",
0x0009: "INVALID_REGISTRATION_DATA",
0x000A: "APPLICATION_DOES_NOT_EXIST",
0x000B: "NOT_ENOUGH_STORAGE",
0x000C: "INVALID_NAME",
0x000D: "BLOCK_DOES_NOT_EXIST",
0x000E: "INVALID_BYTE_OFFSET",
0x000F: "INVALID_BYTE_COUNT",
0x0010: "NOT_PERMITTED",
0x0011: "NOT_OWNER",
0x0012: "BLOCK_LOCKED_BY_OTHER",
0x0013: "BLOCK_NOT_LOCKED",
0x0014: "INVALID_GROUP_PERMISSIONS",
0x0015: "GROUP_DOES_NOT_EXIST",
0x0016: "INVALID_MEMBER_COUNT",
0x0017: "MAX_LIMIT_REACHED",
0x0018: "INVALID_AUTH_TYPE",
0x0019: "AUTHENTICATION_FAILED",
0x001A: "INVALID_DHCP_MODE",
0x001B: "INVALID_IP_ADDRESS",
0x001C: "INVALID_DOMAIN_NAME",
0x001D: "UNSUPPORTED_VERSION",
0x001E: "REQUEST_UNEXPECTED",
0x001F: "INVALID_TABLE_TYPE",
0x0020: "INVALID_PROVISIONING_STATE",
0x0021: "UNSUPPORTED_OBJECT",
0x0022: "INVALID_TIME",
0x0023: "INVALID_INDEX",
0x0024: "INVALID_PARAMETER",
0x0025: "INVALID_NETMASK",
0x0026: "FLASH_WRITE_LIMIT_EXCEEDED",
0x0027: "INVALID_IMAGE_LENGTH",
0x0028: "INVALID_IMAGE_SIGNATURE",
0x0029: "PROPOSE_ANOTHER_VERSION",
0x002A: "INVALID_PID_FORMAT",
0x002B: "INVALID_PPS_FORMAT",
0x002C: "BIST_COMMAND_BLOCKED",
0x002D: "CONNECTION_FAILED",
0x002E: "CONNECTION_TOO_MANY",
0x002F: "RNG_GENERATION_IN_PROGRESS",
0x0030: "RNG_NOT_READY",
0x0031: "CERTIFICATE_NOT_READY",
0x0400: "DISABLED_BY_POLICY",
0x0800: "NETWORK_IF_ERROR_BASE",
0x0801: "UNSUPPORTED_OEM_NUMBER",
0x0802: "UNSUPPORTED_BOOT_OPTION",
0x0803: "INVALID_COMMAND",
0x0804: "INVALID_SPECIAL_COMMAND",
0x0805: "INVALID_HANDLE",
0x0806: "INVALID_PASSWORD",
0x0807: "INVALID_REALM",
0x0808: "STORAGE_ACL_ENTRY_IN_USE",
0x0809: "DATA_MISSING",
0x080A: "DUPLICATE",
0x080B: "EVENTLOG_FROZEN",
0x080C: "PKI_MISSING_KEYS",
0x080D: "PKI_GENERATING_KEYS",
0x080E: "INVALID_KEY",
0x080F: "INVALID_CERT",
0x0810: "CERT_KEY_NOT_MATCH",
0x0811: "MAX_KERB_DOMAIN_REACHED",
0x0812: "UNSUPPORTED",
0x0813: "INVALID_PRIORITY",
0x0814: "NOT_FOUND",
0x0815: "INVALID_CREDENTIALS",
0x0816: "INVALID_PASSPHRASE",
0x0818: "NO_ASSOCIATION",
0x081B: "AUDIT_FAIL",
0x081C: "BLOCKING_COMPONENT",
0x0821: "USER_CONSENT_REQUIRED",
0x1000: "APP_INTERNAL_ERROR",
0x1001: "NOT_INITIALIZED",
0x1002: "LIB_VERSION_UNSUPPORTED",
0x1003: "INVALID_PARAM",
0x1004: "RESOURCES",
0x1005: "HARDWARE_ACCESS_ERROR",
0x1006: "REQUESTOR_NOT_REGISTERED",
0x1007: "NETWORK_ERROR",
0x1008: "PARAM_BUFFER_TOO_SHORT",
0x1009: "COM_NOT_INITIALIZED_IN_THREAD",
0x100A: "URL_REQUIRED"
}
//
// Methods used for getting the event log
//
obj.GetMessageLog = function (func, tag) {
obj.AMT_MessageLog_PositionToFirstRecord(_GetMessageLog0, [func, tag, []]);
}
function _GetMessageLog0(stack, name, responses, status, tag) {
if (status != 200 || responses.Body["ReturnValue"] != '0') { tag[0](obj, null, tag[2]); return; }
obj.AMT_MessageLog_GetRecords(responses.Body["IterationIdentifier"], 390, _GetMessageLog1, tag);
}
function _GetMessageLog1(stack, name, responses, status, tag) {
if (status != 200 || responses.Body["ReturnValue"] != '0') { tag[0](obj, null, tag[2]); return; }
var i, j, x, e, AmtMessages = tag[2], t = new Date(), TimeStamp, ra = responses.Body["RecordArray"];
if (typeof ra === 'string') { responses.Body["RecordArray"] = [responses.Body["RecordArray"]]; }
for (i in ra) {
e = null;
try { e = window.atob(ra[i]); } catch (ex) { }
if (e != null) {
TimeStamp = ReadIntX(e, 0);
if ((TimeStamp > 0) && (TimeStamp < 0xFFFFFFFF)) {
x = { 'DeviceAddress': e.charCodeAt(4), 'EventSensorType': e.charCodeAt(5), 'EventType': e.charCodeAt(6), 'EventOffset': e.charCodeAt(7), 'EventSourceType': e.charCodeAt(8), 'EventSeverity': e.charCodeAt(9), 'SensorNumber': e.charCodeAt(10), 'Entity': e.charCodeAt(11), 'EntityInstance': e.charCodeAt(12), 'EventData': [], 'Time': new Date((TimeStamp + (t.getTimezoneOffset() * 60)) * 1000) };
for (j = 13; j < 21; j++) { x['EventData'].push(e.charCodeAt(j)); }
x['EntityStr'] = _SystemEntityTypes[x['Entity']];
x['Desc'] = _GetEventDetailStr(x['EventSensorType'], x['EventOffset'], x['EventData'], x['Entity']);
if (!x['EntityStr']) x['EntityStr'] = "Unknown";
AmtMessages.push(x);
}
}
}
if (responses.Body["NoMoreRecords"] != true) { obj.AMT_MessageLog_GetRecords(responses.Body["IterationIdentifier"], 390, _GetMessageLog1, [tag[0], AmtMessages, tag[2]]); } else { tag[0](obj, AmtMessages, tag[2]); }
}
var _EventTrapSourceTypes = "Platform firmware (e.g. BIOS)|SMI handler|ISV system management software|Alert ASIC|IPMI|BIOS vendor|System board set vendor|System integrator|Third party add-in|OSV|NIC|System management card".split('|');
var _SystemFirmwareError = "Unspecified.|No system memory is physically installed in the system.|No usable system memory, all installed memory has experienced an unrecoverable failure.|Unrecoverable hard-disk/ATAPI/IDE device failure.|Unrecoverable system-board failure.|Unrecoverable diskette subsystem failure.|Unrecoverable hard-disk controller failure.|Unrecoverable PS/2 or USB keyboard failure.|Removable boot media not found.|Unrecoverable video controller failure.|No video device detected.|Firmware (BIOS) ROM corruption detected.|CPU voltage mismatch (processors that share same supply have mismatched voltage requirements)|CPU speed matching failure".split('|');
var _SystemFirmwareProgress = "Unspecified.|Memory initialization.|Starting hard-disk initialization and test|Secondary processor(s) initialization|User authentication|User-initiated system setup|USB resource configuration|PCI resource configuration|Option ROM initialization|Video initialization|Cache initialization|SM Bus initialization|Keyboard controller initialization|Embedded controller/management controller initialization|Docking station attachment|Enabling docking station|Docking station ejection|Disabling docking station|Calling operating system wake-up vector|Starting operating system boot process|Baseboard or motherboard initialization|reserved|Floppy initialization|Keyboard test|Pointing device test|Primary processor initialization".split('|');
var _SystemEntityTypes = "Unspecified|Other|Unknown|Processor|Disk|Peripheral|System management module|System board|Memory module|Processor module|Power supply|Add in card|Front panel board|Back panel board|Power system board|Drive backplane|System internal expansion board|Other system board|Processor board|Power unit|Power module|Power management board|Chassis back panel board|System chassis|Sub chassis|Other chassis board|Disk drive bay|Peripheral bay|Device bay|Fan cooling|Cooling unit|Cable interconnect|Memory device|System management software|BIOS|Intel(r) ME|System bus|Group|Intel(r) ME|External environment|Battery|Processing blade|Connectivity switch|Processor/memory module|I/O module|Processor I/O module|Management controller firmware|IPMI channel|PCI bus|PCI express bus|SCSI bus|SATA/SAS bus|Processor front side bus".split('|');
obj.RealmNames = "||Redirection|PT Administration|Hardware Asset|Remote Control|Storage|Event Manager|Storage Admin|Agent Presence Local|Agent Presence Remote|Circuit Breaker|Network Time|General Information|Firmware Update|EIT|LocalUN|Endpoint Access Control|Endpoint Access Control Admin|Event Log Reader|Audit Log|ACL Realm|||Local System".split('|');
obj.WatchdogCurrentStates = { 1: 'Not Started', 2: 'Stopped', 4: 'Running', 8: 'Expired', 16: 'Suspended' };
function _GetEventDetailStr(eventSensorType, eventOffset, eventDataField, entity) {
if (eventSensorType == 15)
{
if (eventDataField[0] == 235) return "Invalid Data";
if (eventOffset == 0) return _SystemFirmwareError[eventDataField[1]];
return _SystemFirmwareProgress[eventDataField[1]];
}
if (eventSensorType == 18 && eventDataField[0] == 170) // System watchdog event
{
return "Agent watchdog " + char2hex(eventDataField[4]) + char2hex(eventDataField[3]) + char2hex(eventDataField[2]) + char2hex(eventDataField[1]) + "-" + char2hex(eventDataField[6]) + char2hex(eventDataField[5]) + "-... changed to " + obj.WatchdogCurrentStates[eventDataField[7]];
}
/*
if (eventSensorType == 5 && eventOffset == 0) // System chassis
{
return "Case intrusion";
}
if (eventSensorType == 192 && eventOffset == 0 && eventDataField[0] == 170 && eventDataField[1] == 48)
{
if (eventDataField[2] == 0) return "A remote Serial Over LAN session was established.";
if (eventDataField[2] == 1) return "Remote Serial Over LAN session finished. User control was restored.";
if (eventDataField[2] == 2) return "A remote IDE-Redirection session was established.";
if (eventDataField[2] == 3) return "Remote IDE-Redirection session finished. User control was restored.";
}
if (eventSensorType == 36)
{
long handle = ((long)(eventDataField[1]) << 24) + ((long)(eventDataField[2]) << 16) + ((long)(eventDataField[3]) << 8) + (long)(eventDataField[4]);
string nic = string.Format("#{0}", eventDataField[0]);
if (eventDataField[0] == 0xAA) nic = "wired"; // TODO: Add wireless *****
//if (eventDataField[0] == 0xAA) nic = "wireless";
if (handle == 4294967293) { return string.Format("All received packet filter was matched on {0} interface.", nic); }
if (handle == 4294967292) { return string.Format("All outbound packet filter was matched on {0} interface.", nic); }
if (handle == 4294967290) { return string.Format("Spoofed packet filter was matched on {0} interface.", nic); }
return string.Format("Filter {0} was matched on {1} interface.", handle, nic);
}
if (eventSensorType == 192)
{
if (eventDataField[2] == 0) return "Security policy invoked. Some or all network traffic (TX) was stopped.";
if (eventDataField[2] == 2) return "Security policy invoked. Some or all network traffic (RX) was stopped.";
return "Security policy invoked.";
}
if (eventSensorType == 193)
{
if (eventDataField[0] == 0xAA && eventDataField[1] == 0x30 && eventDataField[2] == 0x00 && eventDataField[3] == 0x00) { return "User request for remote connection."; }
if (eventDataField[0] == 0xAA && eventDataField[1] == 0x20 && eventDataField[2] == 0x03 && eventDataField[3] == 0x01) { return "EAC error: attempt to get posture while NAC in Intel® AMT is disabled."; // eventDataField = 0xAA20030100000000 }
if (eventDataField[0] == 0xAA && eventDataField[1] == 0x20 && eventDataField[2] == 0x04 && eventDataField[3] == 0x00) { return "Certificate revoked. "; }
}
*/
if (eventSensorType == 6) return "Authentication failed " + (eventDataField[1] + (eventDataField[2] << 8)) + " times. The system may be under attack.";
if (eventSensorType == 30) return "No bootable media";
if (eventSensorType == 32) return "Operating system lockup or power interrupt";
if (eventSensorType == 35) return "System boot failure";
if (eventSensorType == 37) return "System firmware started (at least one CPU is properly executing).";
return "Unknown Sensor Type #" + eventSensorType;
}
// ###BEGIN###{AuditLog}
// Useful link: https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Fsecurityadminevents.htm
var _AmtAuditStringTable =
{
16: 'Security Admin',
17: 'RCO',
18: 'Redirection Manager',
19: 'Firmware Update Manager',
20: 'Security Audit Log',
21: 'Network Time',
22: 'Network Administration',
23: 'Storage Administration',
24: 'Event Manager',
25: 'Circuit Breaker Manager',
26: 'Agent Presence Manager',
27: 'Wireless Configuration',
28: 'EAC',
29: 'KVM',
30: 'User Opt-In Events',
32: 'Screen Blanking',
33: 'Watchdog Events',
1600: 'Provisioning Started',
1601: 'Provisioning Completed',
1602: 'ACL Entry Added',
1603: 'ACL Entry Modified',
1604: 'ACL Entry Removed',
1605: 'ACL Access with Invalid Credentials',
1606: 'ACL Entry State',
1607: 'TLS State Changed',
1608: 'TLS Server Certificate Set',
1609: 'TLS Server Certificate Remove',
1610: 'TLS Trusted Root Certificate Added',
1611: 'TLS Trusted Root Certificate Removed',
1612: 'TLS Preshared Key Set',
1613: 'Kerberos Settings Modified',
1614: 'Kerberos Master Key Modified',
1615: 'Flash Wear out Counters Reset',
1616: 'Power Package Modified',
1617: 'Set Realm Authentication Mode',
1618: 'Upgrade Client to Admin Control Mode',
1619: 'Unprovisioning Started',
1700: 'Performed Power Up',
1701: 'Performed Power Down',
1702: 'Performed Power Cycle',
1703: 'Performed Reset',
1704: 'Set Boot Options',
1800: 'IDER Session Opened',
1801: 'IDER Session Closed',
1802: 'IDER Enabled',
1803: 'IDER Disabled',
1804: 'SoL Session Opened',
1805: 'SoL Session Closed',
1806: 'SoL Enabled',
1807: 'SoL Disabled',
1808: 'KVM Session Started',
1809: 'KVM Session Ended',
1810: 'KVM Enabled',
1811: 'KVM Disabled',
1812: 'VNC Password Failed 3 Times',
1900: 'Firmware Updated',
1901: 'Firmware Update Failed',
2000: 'Security Audit Log Cleared',
2001: 'Security Audit Policy Modified',
2002: 'Security Audit Log Disabled',
2003: 'Security Audit Log Enabled',
2004: 'Security Audit Log Exported',
2005: 'Security Audit Log Recovered',
2100: 'Intel&reg; ME Time Set',
2200: 'TCPIP Parameters Set',
2201: 'Host Name Set',
2202: 'Domain Name Set',
2203: 'VLAN Parameters Set',
2204: 'Link Policy Set',
2205: 'IPv6 Parameters Set',
2300: 'Global Storage Attributes Set',
2301: 'Storage EACL Modified',
2302: 'Storage FPACL Modified',
2303: 'Storage Write Operation',
2400: 'Alert Subscribed',
2401: 'Alert Unsubscribed',
2402: 'Event Log Cleared',
2403: 'Event Log Frozen',
2500: 'CB Filter Added',
2501: 'CB Filter Removed',
2502: 'CB Policy Added',
2503: 'CB Policy Removed',
2504: 'CB Default Policy Set',
2505: 'CB Heuristics Option Set',
2506: 'CB Heuristics State Cleared',
2600: 'Agent Watchdog Added',
2601: 'Agent Watchdog Removed',
2602: 'Agent Watchdog Action Set',
2700: 'Wireless Profile Added',
2701: 'Wireless Profile Removed',
2702: 'Wireless Profile Updated',
2800: 'EAC Posture Signer SET',
2801: 'EAC Enabled',
2802: 'EAC Disabled',
2803: 'EAC Posture State',
2804: 'EAC Set Options',
2900: 'KVM Opt-in Enabled',
2901: 'KVM Opt-in Disabled',
2902: 'KVM Password Changed',
2903: 'KVM Consent Succeeded',
2904: 'KVM Consent Failed',
3000: 'Opt-In Policy Change',
3001: 'Send Consent Code Event',
3002: 'Start Opt-In Blocked Event'
}
// Return human readable extended audit log data
// TODO: Just put some of them here, but many more still need to be added, helpful link here:
// https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Fsecurityadminevents.htm
obj.GetAuditLogExtendedDataStr = function (id, data) {
if ((id == 1602 || id == 1604) && data.charCodeAt(0) == 0) { return data.substring(2, 2 + data.charCodeAt(1)); } // ACL Entry Added/Removed (Digest)
if (id == 1603) { if (data.charCodeAt(1) == 0) { return data.substring(3); } return null; } // ACL Entry Modified
if (id == 1605) { return ["Invalid ME access", "Invalid MEBx access"][data.charCodeAt(0)]; } // ACL Access with Invalid Credentials
if (id == 1606) { var r = ["Disabled", "Enabled"][data.charCodeAt(0)]; if (data.charCodeAt(1) == 0) { r += ", " + data.substring(3); } return r;} // ACL Entry State
if (id == 1607) { return "Remote " + ["NoAuth", "ServerAuth", "MutualAuth"][data.charCodeAt(0)] + ", Local " + ["NoAuth", "ServerAuth", "MutualAuth"][data.charCodeAt(1)]; } // TLS State Changed
if (id == 1617) { return obj.RealmNames[ReadInt(data, 0)] + ", " + ["NoAuth", "Auth", "Disabled"][data.charCodeAt(4)]; } // Set Realm Authentication Mode
if (id == 1619) { return ["BIOS", "MEBx", "Local MEI", "Local WSMAN", "Remote WSAMN"][data.charCodeAt(0)]; } // Intel AMT Unprovisioning Started
if (id == 1900) { return "From " + ReadShort(data, 0) + "." + ReadShort(data, 2) + "." + ReadShort(data, 4) + "." + ReadShort(data, 6) + " to " + ReadShort(data, 8) + "." + ReadShort(data, 10) + "." + ReadShort(data, 12) + "." + ReadShort(data, 14); } // Firmware Updated
if (id == 2100) { var t4 = new Date(); t4.setTime(ReadInt(data, 0) * 1000 + (new Date().getTimezoneOffset() * 60000)); return t4.toLocaleString(); } // Intel AMT Time Set
if (id == 3000) { return "From " + ["None", "KVM", "All"][data.charCodeAt(0)] + " to " + ["None", "KVM", "All"][data.charCodeAt(1)]; } // Opt-In Policy Change
if (id == 3001) { return ["Success", "Failed 3 times"][data.charCodeAt(0)]; } // Send Consent Code Event
return null;
}
obj.GetAuditLog = function (func) {
obj.AMT_AuditLog_ReadRecords(1, _GetAuditLog0, [func, []]);
}
function _GetAuditLog0(stack, name, responses, status, tag) {
if (status != 200) { tag[0](obj, [], status); return; }
var ptr, i, e, x, r = tag[1], t = new Date(), TimeStamp;
if (responses.Body['RecordsReturned'] > 0) {
responses.Body['EventRecords'] = MakeToArray(responses.Body['EventRecords']);
for (i in responses.Body['EventRecords']) {
e = null;
try {
e = window.atob(responses.Body['EventRecords'][i]);
} catch (e) {
console.log(e + " " + responses.Body['EventRecords'][i])
}
x = { 'AuditAppID': ReadShort(e, 0), 'EventID': ReadShort(e, 2), 'InitiatorType': e.charCodeAt(4) };
x['AuditApp'] = _AmtAuditStringTable[x['AuditAppID']];
x['Event'] = _AmtAuditStringTable[(x['AuditAppID'] * 100) + x['EventID']];
if (!x['Event']) x['Event'] = '#' + x['EventID'];
// Read and process the initiator
if (x['InitiatorType'] == 0) {
// HTTP digest
var userlen = e.charCodeAt(5);
x['Initiator'] = e.substring(6, 6 + userlen);
ptr = 6 + userlen;
}
if (x['InitiatorType'] == 1) {
// Kerberos
x['KerberosUserInDomain'] = ReadInt(e, 5);
var userlen = e.charCodeAt(9);
x['Initiator'] = GetSidString(e.substring(10, 10 + userlen));
ptr = 10 + userlen;
}
if (x['InitiatorType'] == 2) {
// Local
x['Initiator'] = '<i>Local</i>';
ptr = 5;
}
if (x['InitiatorType'] == 3) {
// KVM Default Port
x['Initiator'] = '<i>KVM Default Port</i>';
ptr = 5;
}
// Read timestamp
TimeStamp = ReadInt(e, ptr);
x['Time'] = new Date((TimeStamp + (t.getTimezoneOffset() * 60)) * 1000);
ptr += 4;
// Read network access
x['MCLocationType'] = e.charCodeAt(ptr++);
var netlen = e.charCodeAt(ptr++);
x['NetAddress'] = e.substring(ptr, ptr + netlen);
// Read extended data
ptr += netlen;
var exlen = e.charCodeAt(ptr++);
x['Ex'] = e.substring(ptr, ptr + exlen);
x['ExStr'] = obj.GetAuditLogExtendedDataStr((x['AuditAppID'] * 100) + x['EventID'], x['Ex']);
r.push(x);
}
}
if (responses.Body['TotalRecordCount'] > r.length) {
obj.AMT_AuditLog_ReadRecords(r.length + 1, _GetAuditLog0, [tag[0], r]);
} else {
tag[0](obj, r, status);
}
}
// ###END###{AuditLog}
return obj;
}
// ###BEGIN###{Certificates}
// Forge MD5
function hex_md5(str) { return forge.md.md5.create().update(str).digest().toHex(); }
// ###END###{Certificates}
// ###BEGIN###{!Certificates}
// TinyMD5 from https://github.com/jbt/js-crypto
// Perform MD5 setup
var md5_k = [];
for (var i = 0; i < 64;) { md5_k[i] = 0 | (Math.abs(Math.sin(++i)) * 4294967296); }
// Perform MD5 on raw string and return hex
function hex_md5(str) {
var b, c, d, j,
x = [],
str2 = unescape(encodeURI(str)),
a = str2.length,
h = [b = 1732584193, c = -271733879, ~b, ~c],
i = 0;
for (; i <= a;) x[i >> 2] |= (str2.charCodeAt(i) || 128) << 8 * (i++ % 4);
x[str = (a + 8 >> 6) * 16 + 14] = a * 8;
i = 0;
for (; i < str; i += 16) {
a = h; j = 0;
for (; j < 64;) {
a = [
d = a[3],
((b = a[1] | 0) +
((d = (
(a[0] +
[
b & (c = a[2]) | ~b & d,
d & b | ~d & c,
b ^ c ^ d,
c ^ (b | ~d)
][a = j >> 4]
) +
(md5_k[j] +
(x[[
j,
5 * j + 1,
3 * j + 5,
7 * j
][a] % 16 + i] | 0)
)
)) << (a = [
7, 12, 17, 22,
5, 9, 14, 20,
4, 11, 16, 23,
6, 10, 15, 21
][4 * a + j++ % 4]) | d >>> 32 - a)
),
b,
c
];
}
for (j = 4; j;) h[--j] = h[j] + a[j];
}
str = '';
for (; j < 32;) str += ((h[j >> 3] >> ((1 ^ j++ & 7) * 4)) & 15).toString(16);
return str;
}
// ###END###{!Certificates}
// Perform MD5 on raw string and return raw string result
function rstr_md5(str) { return hex2rstr(hex_md5(str)); }
/*
Convert arguments into selector set and body XML. Used by AMT_WiFiPortConfigurationService_UpdateWiFiSettings.
args = {
"WiFiEndpoint": {
__parameterType: 'reference',
__resourceUri: 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpoint',
Name: 'WiFi Endpoint 0'
},
"WiFiEndpointSettingsInput":
{
__parameterType: 'instance',
__namespace: 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpointSettings',
ElementName: document.querySelector('#editProfile-profileName').value,
InstanceID: 'Intel(r) AMT:WiFi Endpoint Settings ' + document.querySelector('#editProfile-profileName').value,
AuthenticationMethod: document.querySelector('#editProfile-networkAuthentication').value,
//BSSType: 3, // Intel(r) AMT supports only infrastructure networks
EncryptionMethod: document.querySelector('#editProfile-encryption').value,
SSID: document.querySelector('#editProfile-networkName').value,
Priority: 100,
PSKPassPhrase: document.querySelector('#editProfile-passPhrase').value
},
"IEEE8021xSettingsInput": null,
"ClientCredential": null,
"CACredential": null
},
*/
function execArgumentsToXml(args) {
if(args === undefined || args === null) return null;
var result = '';
for(var argName in args) {
var arg = args[argName];
if(!arg) continue;
if(arg['__parameterType'] === 'reference') result += referenceToXml(argName, arg);
else result += instanceToXml(argName, arg);
//if(arg['__isInstance']) result += instanceToXml(argName, arg);
}
return result;
}
/**
* Convert JavaScript object into XML
<r:WiFiEndpointSettingsInput xmlns:q="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpointSettings">
<q:ElementName>Wireless-Profile-Admin</q:ElementName>
<q:InstanceID>Intel(r) AMT:WiFi Endpoint Settings Wireless-Profile-Admin</q:InstanceID>
<q:AuthenticationMethod>6</q:AuthenticationMethod>
<q:EncryptionMethod>4</q:EncryptionMethod>
<q:Priority>100</q:Priority>
<q:PSKPassPhrase>P@ssw0rd</q:PSKPassPhrase>
</r:WiFiEndpointSettingsInput>
*/
function instanceToXml(instanceName, inInstance) {
if(inInstance === undefined || inInstance === null) return null;
var hasNamespace = !!inInstance['__namespace'];
var startTag = hasNamespace ? '<q:' : '<';
var endTag = hasNamespace ? '</q:' : '</';
var namespaceDef = hasNamespace ? (' xmlns:q="' + inInstance['__namespace'] + '"' ): '';
var result = '<r:' + instanceName + namespaceDef + '>';
for(var prop in inInstance) {
if (!inInstance.hasOwnProperty(prop) || prop.indexOf('__') === 0) continue;
if (typeof inInstance[prop] === 'function' || Array.isArray(inInstance[prop]) ) continue;
if (typeof inInstance[prop] === 'object') {
//result += startTag + prop +'>' + instanceToXml('prop', inInstance[prop]) + endTag + prop +'>';
console.error('only convert one level down...');
}
else {
result += startTag + prop +'>' + inInstance[prop].toString() + endTag + prop +'>';
}
}
result += '</r:' + instanceName + '>';
return result;
}
/**
* Convert a selector set into XML. Expect no nesting.
* {
* selectorName : selectorValue,
* selectorName : selectorValue,
* ... ...
* }
<r:WiFiEndpoint>
<a:Address>http://192.168.1.103:16992/wsman</a:Address>
<a:ReferenceParameters>
<w:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpoint</w:ResourceURI>
<w:SelectorSet>
<w:Selector Name="Name">WiFi Endpoint 0</w:Selector>
</w:SelectorSet>
</a:ReferenceParameters>
</r:WiFiEndpoint>
*/
function referenceToXml(referenceName, inReference) {
if(inReference === undefined || inReference === null ) return null;
var result = '<r:' + referenceName + '><a:Address>/wsman</a:Address><a:ReferenceParameters><w:ResourceURI>'+ inReference['__resourceUri']+'</w:ResourceURI><w:SelectorSet>';
for(var selectorName in inReference) {
if (!inReference.hasOwnProperty(selectorName) || selectorName.indexOf('__') === 0) continue;
if (typeof inReference[selectorName] === 'function' ||
typeof inReference[selectorName] === 'object' ||
Array.isArray(inReference[selectorName]) )
continue;
result += '<w:Selector Name="' + selectorName +'">' + inReference[selectorName].toString() + '</w:Selector>';
}
result += '</w:SelectorSet></a:ReferenceParameters></r:' + referenceName + '>';
return result;
}
// Convert a byte array of SID into string
function GetSidString(sid) {
var r = "S-" + sid.charCodeAt(0) + "-" + sid.charCodeAt(7);
for (var i = 2; i < (sid.length / 4) ; i++) r += "-" + ReadIntX(sid, i * 4);
return r;
}
// Convert a SID readable string into bytes
function GetSidByteArray(sidString) {
if (!sidString || sidString == null) return null;
var sidParts = sidString.split('-');
// Make sure the SID has at least 4 parts and starts with 'S'
if (sidParts.length < 4 || (sidParts[0] != 's' && sidParts[0] != 'S')) return null;
// Check that each part of the SID is really an integer
for (var i = 1; i < sidParts.length; i++) { var y = parseInt(sidParts[i]); if (y != sidParts[i]) return null; sidParts[i] = y; }
// Version (8 bit) + Id count (8 bit) + 48 bit in big endian -- DO NOT use bitwise right shift operator. JavaScript converts the number into a 32 bit integer before shifting. In real world, it's highly likely this part is always 0.
var r = String.fromCharCode(sidParts[1]) + String.fromCharCode(sidParts.length - 3) + ShortToStr(Math.floor(sidParts[2] / Math.pow(2, 32))) + IntToStr((sidParts[2]) & 0xFFFF);
// the rest are in 32 bit in little endian
for (var i = 3; i < sidParts.length; i++) r += IntToStrX(sidParts[i]);
return r;
}

View file

@ -0,0 +1,646 @@
/**
* @description Remote Desktop
* @author Ylian Saint-Hilaire
* @version v0.0.2g
*/
// Construct a MeshServer object
var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
var obj = {};
obj.canvasid = divid;
obj.scrolldiv = scrolldiv;
obj.canvas = Q(divid).getContext("2d");
obj.protocol = 2; // KVM
obj.state = 0;
obj.acc = "";
obj.ScreenWidth = 960;
obj.ScreenHeight = 700;
obj.width = 0;
obj.height = 0;
obj.rwidth = 0;
obj.rheight = 0;
obj.bpp = 2; // Bytes per pixel (1 or 2 supported)
obj.useZRLE = true;
obj.showmouse = true;
obj.buttonmask = 0;
obj.spare = null;
obj.sparew = 0;
obj.spareh = 0;
obj.sparew2 = 0;
obj.spareh2 = 0;
obj.sparecache = {};
obj.ZRLEfirst = 1;
obj.onScreenSizeChange = null;
obj.frameRateDelay = 0;
// ###BEGIN###{DesktopRotation}
obj.rotation = 0;
// ###END###{DesktopRotation}
// ###BEGIN###{DesktopFocus}
obj.mx = 0; // Last mouse x position
obj.my = 0; // Last mouse y position
obj.ox = -1; // Old mouse x position
obj.oy = -1; // Old mouse y position
obj.focusmode = 0;
// ###END###{DesktopFocus}
// Private method
obj.Debug = function (msg) { console.log(msg); }
obj.xxStateChange = function (newstate) {
if (newstate == 0) {
obj.canvas.fillStyle = '#000000';
obj.canvas.fillRect(0, 0, obj.width, obj.height);
obj.canvas.canvas.width = obj.rwidth = obj.width = 640;
obj.canvas.canvas.height = obj.rheight = obj.height = 400;
QS(obj.canvasid).cursor = 'auto';
} else {
if (!obj.showmouse) { QS(obj.canvasid).cursor = 'none'; }
}
}
obj.ProcessData = function (data) {
if (!data) return;
// obj.Debug("KRecv(" + data.length + "): " + rstr2hex(data));
obj.acc += data;
while (obj.acc.length > 0) {
//obj.Debug("KAcc(" + obj.acc.length + "): " + rstr2hex(obj.acc));
var cmdsize = 0;
if (obj.state == 0 && obj.acc.length >= 12) {
// Getting handshake & version
cmdsize = 12;
//if (obj.acc.substring(0, 4) != "RFB ") { return obj.Stop(); }
//var version = parseFloat(obj.acc.substring(4, 11));
//obj.Debug("KVersion: " + version);
obj.state = 1;
obj.Send("RFB 003.008\n");
}
else if (obj.state == 1 && obj.acc.length >= 1) {
// Getting security options
cmdsize = obj.acc.charCodeAt(0) + 1;
obj.Send(String.fromCharCode(1)); // Send the "None" security type. Since we already authenticated using redirection digest auth, we don't need to do this again.
obj.state = 2;
}
else if (obj.state == 2 && obj.acc.length >= 4) {
// Getting security response
cmdsize = 4;
if (ReadInt(obj.acc, 0) != 0) { return obj.Stop(); }
obj.Send(String.fromCharCode(1)); // Send share desktop flag
obj.state = 3;
}
else if (obj.state == 3 && obj.acc.length >= 24) {
// Getting server init
var namelen = ReadInt(obj.acc, 20);
if (obj.acc.length < 24 + namelen) return;
cmdsize = 24 + namelen;
obj.canvas.canvas.width = obj.rwidth = obj.width = obj.ScreenWidth = ReadShort(obj.acc, 0);
obj.canvas.canvas.height = obj.rheight = obj.height = obj.ScreenHeight = ReadShort(obj.acc, 2);
// These are all values we don't really need, we are going to only run in RGB565 or RGB332 and not use the flexibility provided by these settings.
// Makes the javascript code smaller and maybe a bit faster.
/*
obj.xbpp = obj.acc.charCodeAt(4);
obj.depth = obj.acc.charCodeAt(5);
obj.bigend = obj.acc.charCodeAt(6);
obj.truecolor = obj.acc.charCodeAt(7);
obj.rmax = ReadShort(obj.acc, 8);
obj.gmax = ReadShort(obj.acc, 10);
obj.bmax = ReadShort(obj.acc, 12);
obj.rsh = obj.acc.charCodeAt(14);
obj.gsh = obj.acc.charCodeAt(15);
obj.bsh = obj.acc.charCodeAt(16);
var name = obj.acc.substring(24, 24 + namelen);
obj.Debug("name: " + name);
obj.Debug("width: " + obj.width + ", height: " + obj.height);
obj.Debug("bits-per-pixel: " + obj.xbpp);
obj.Debug("depth: " + obj.depth);
obj.Debug("big-endian-flag: " + obj.bigend);
obj.Debug("true-colour-flag: " + obj.truecolor);
obj.Debug("rgb max: " + obj.rmax + "," + obj.gmax + "," + obj.bmax);
obj.Debug("rgb shift: " + obj.rsh + "," + obj.gsh + "," + obj.bsh);
*/
// SetEncodings, with AMT we can't omit RAW, must be specified.
// Intel AMT supports encodings: RAW (0), ZRLE (16), Desktop Size (0xFFFFFF21, -223)
var supportedEncodings = '';
if (obj.useZRLE) supportedEncodings += IntToStr(16);
supportedEncodings += IntToStr(0);
obj.Send(String.fromCharCode(2, 0) + ShortToStr((supportedEncodings.length / 4) + 1) + supportedEncodings + IntToStr(-223)); // Supported Encodings + Desktop Size
// Set the pixel encoding to something much smaller
// obj.Send(String.fromCharCode(0, 0, 0, 0, 16, 16, 0, 1) + ShortToStr(31) + ShortToStr(63) + ShortToStr(31) + String.fromCharCode(11, 5, 0, 0, 0, 0)); // Setup 16 bit color RGB565 (This is the default, so we don't need to set it)
if (obj.bpp == 1) obj.Send(String.fromCharCode(0, 0, 0, 0, 8, 8, 0, 1) + ShortToStr(7) + ShortToStr(7) + ShortToStr(3) + String.fromCharCode(5, 2, 0, 0, 0, 0)); // Setup 8 bit color RGB332
obj.state = 4;
obj.parent.xxStateChange(3);
_SendRefresh();
//obj.timer = setInterval(obj.xxOnTimer, 50);
// ###BEGIN###{DesktopFocus}
obj.ox = -1; // Old mouse x position
// ###END###{DesktopFocus}
if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); }
}
else if (obj.state == 4) {
var c = obj.acc.charCodeAt(0);
if (c == 2) {
cmdsize = 1; // This is the bell, do nothing.
} else if (c == 0) {
if (obj.acc.length < 4) return;
obj.state = 100 + ReadShort(obj.acc, 2); // Read the number of tiles that are going to be sent, add 100 and use that as our protocol state.
cmdsize = 4;
}
}
else if (obj.state > 100 && obj.acc.length >= 12) {
var x = ReadShort(obj.acc, 0),
y = ReadShort(obj.acc, 2),
width = ReadShort(obj.acc, 4),
height = ReadShort(obj.acc, 6),
s = width * height,
encoding = ReadInt(obj.acc, 8);
if (encoding < 17) {
if (width < 1 || width > 64 || height < 1 || height > 64) { console.log("Invalid tile size (" + width + "," + height + "), disconnecting."); return obj.Stop(); }
// Set the spare bitmap to the rigth size if it's not already. This allows us to recycle the spare most if not all the time.
if (obj.sparew != width || obj.spareh != height) {
obj.sparew = obj.sparew2 = width;
obj.spareh = obj.spareh2 = height;
// ###BEGIN###{DesktopRotation}
if (obj.rotation == 1 || obj.rotation == 3) { obj.sparew2 = height, obj.spareh2 = width; }
// ###END###{DesktopRotation}
var xspacecachename = obj.sparew2 + 'x' + obj.spareh2;
obj.spare = obj.sparecache[xspacecachename];
if (!obj.spare) { obj.sparecache[xspacecachename] = obj.spare = obj.canvas.createImageData(obj.sparew2, obj.spareh2); }
}
}
if (encoding == 0xFFFFFF21) {
// Desktop Size (0xFFFFFF21, -223)
obj.canvas.canvas.width = obj.rwidth = obj.width = width;
obj.canvas.canvas.height = obj.rheight = obj.height = height;
obj.Send(String.fromCharCode(3, 0, 0, 0, 0, 0) + ShortToStr(obj.width) + ShortToStr(obj.height)); // FramebufferUpdateRequest
cmdsize = 12;
if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); }
// obj.Debug("New desktop width: " + obj.width + ", height: " + obj.height);
}
else if (encoding == 0) {
// RAW encoding
var ptr = 12, cs = 12 + (s * obj.bpp);
if (obj.acc.length < cs) return; // Check we have all the data needed and we can only draw 64x64 tiles.
cmdsize = cs;
// CRITICAL LOOP, optimize this as much as possible
for (var i = 0; i < s; i++) { _setPixel(obj.acc.charCodeAt(ptr++) + ((obj.bpp == 2) ? (obj.acc.charCodeAt(ptr++) << 8) : 0), i); }
_putImage(obj.spare, x, y);
}
else if (encoding == 16) {
// ZRLE encoding
if (obj.acc.length < 16) return;
var datalen = ReadInt(obj.acc, 12);
if (obj.acc.length < (16 + datalen)) return;
//obj.Debug("RECT ZRLE (" + x + "," + y + "," + width + "," + height + ") LEN = " + datalen);
//obj.Debug("RECT ZRLE LEN: " + ReadShortX(obj.acc, 17) + ", DATA: " + rstr2hex(obj.acc.substring(16)));
// Process the ZLib header if this is the first block
var ptr = 16, delta = 5, dx = 0;
if (obj.ZRLEfirst == 1) { obj.ZRLEfirst = 0; ptr += 2; delta = 7; dx = 2; } // Skip the ZLib header
if (datalen > 5 && obj.acc.charCodeAt(ptr) == 0 && ReadShortX(obj.acc, ptr + 1) == (datalen - delta)) {
// This is an uncompressed ZLib data block
_decodeLRE(obj.acc, ptr + 5, x, y, width, height, s, datalen);
}
// ###BEGIN###{Inflate}
else {
// This is compressed ZLib data, decompress and process it.
var arr = inflate(obj.acc.substring(ptr, ptr + datalen - dx));
if (arr.length > 0) { _decodeLRE(String.fromCharCode.apply(null, new Uint8Array(arr)), 0, x, y, width, height, s, arr.length); } else { obj.Debug("Invalid deflate data"); }
}
// ###END###{Inflate}
cmdsize = 16 + datalen;
}
else {
obj.Debug("Unknown Encoding: " + encoding);
return obj.Stop();
}
if (--obj.state == 100) {
obj.state = 4;
if (obj.frameRateDelay == 0) {
_SendRefresh(); // Ask for new frame
} else {
setTimeout(_SendRefresh, obj.frameRateDelay); // Hold x miliseconds before asking for a new frame
}
}
}
if (cmdsize == 0) return;
obj.acc = obj.acc.substring(cmdsize);
}
}
function _decodeLRE(data, ptr, x, y, width, height, s, datalen) {
var subencoding = data.charCodeAt(ptr++), index, v, runlengthdecode, palette = {}, rlecount = 0, runlength = 0, i;
// obj.Debug("RECT RLE (" + (datalen - 5) + ", " + subencoding + "):" + rstr2hex(data.substring(21, 21 + (datalen - 5))));
if (subencoding == 0) {
// RAW encoding
for (i = 0; i < s; i++) { _setPixel(data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0), i); }
_putImage(obj.spare, x, y);
}
else if (subencoding == 1) {
// Solid color tile
v = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0);
obj.canvas.fillStyle = 'rgb(' + ((obj.bpp == 1) ? ((v & 224) + ',' + ((v & 28) << 3) + ',' + _fixColor((v & 3) << 6)) : (((v >> 8) & 248) + ',' + ((v >> 3) & 252) + ',' + ((v & 31) << 3))) + ')';
// ###BEGIN###{DesktopRotation}
var xx = _rotX(x, y);
y = _rotY(x, y);
x = xx;
// ###END###{DesktopRotation}
obj.canvas.fillRect(x, y, width, height);
}
else if (subencoding > 1 && subencoding < 17) { // Packed palette encoded tile
// Read the palette
var br = 4, bm = 15; // br is BitRead and bm is BitMask. By adjusting these two we can support all the variations in this encoding.
for (i = 0; i < subencoding; i++) { palette[i] = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0); }
// Compute bits to read & bit mark
if (subencoding == 2) { br = 1; bm = 1; } else if (subencoding <= 4) { br = 2; bm = 3; }
// Display all the bits
while (rlecount < s && ptr < data.length) { v = data.charCodeAt(ptr++); for (i = (8 - br) ; i >= 0; i -= br) { _setPixel(palette[(v >> i) & bm], rlecount++); } }
_putImage(obj.spare, x, y);
}
else if (subencoding == 128) { // RLE encoded tile
while (rlecount < s && ptr < data.length) {
// Get the run color
v = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0);
// Decode the run length. This is the fastest and most compact way I found to do this.
runlength = 1; do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255);
// Draw a run
while (--runlength >= 0) { _setPixel(v, rlecount++); }
}
_putImage(obj.spare, x, y);
}
else if (subencoding > 129) { // Palette RLE encoded tile
// Read the palette
for (i = 0; i < (subencoding - 128) ; i++) { palette[i] = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0); }
// Decode RLE on palette
while (rlecount < s && ptr < data.length) {
// Setup the run, get the color index and get the color from the palette.
runlength = 1; index = data.charCodeAt(ptr++); v = palette[index % 128];
// If the index starts with high order bit 1, this is a run and decode the run length.
if (index > 127) { do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255); }
// Draw a run
while (--runlength >= 0) { _setPixel(v, rlecount++); }
}
_putImage(obj.spare, x, y);
}
}
function _putImage(i, x, y) {
// ###BEGIN###{DesktopRotation}
var xx = _arotX(x, y);
y = _arotY(x, y);
x = xx;
// ###END###{DesktopRotation}
obj.canvas.putImageData(i, x, y);
}
function _setPixel(v, p) {
var pp = p * 4;
// ###BEGIN###{DesktopRotation}
if (obj.rotation > 0) {
if (obj.rotation == 1) {
var x = p % obj.sparew;
var y = Math.floor(p / obj.sparew);
p = (x * obj.sparew2) + (obj.sparew2 - 1 - y);
pp = p * 4;
}
else if (obj.rotation == 2) { pp = (obj.sparew * obj.spareh * 4) - 4 - pp; }
else if (obj.rotation == 3) {
var x = p % obj.sparew;
var y = Math.floor(p / obj.sparew);
p = ((obj.sparew2 - 1 - x) * obj.sparew2) + (y);
pp = p * 4;
}
}
// ###END###{DesktopRotation}
if (obj.bpp == 1) {
// Set 8bit color RGB332
obj.spare.data[pp++] = v & 224;
obj.spare.data[pp++] = (v & 28) << 3;
obj.spare.data[pp++] = _fixColor((v & 3) << 6);
} else {
// Set 16bit color RGB565
obj.spare.data[pp++] = (v >> 8) & 248;
obj.spare.data[pp++] = (v >> 3) & 252;
obj.spare.data[pp++] = (v & 31) << 3;
}
obj.spare.data[pp] = 0xFF; // Set alpha channel to opaque.
}
// ###BEGIN###{DesktopRotation}
function _arotX(x, y) {
if (obj.rotation == 0) return x;
if (obj.rotation == 1) return obj.canvas.canvas.width - obj.sparew2 - y;
if (obj.rotation == 2) return obj.canvas.canvas.width - obj.sparew2 - x;
if (obj.rotation == 3) return y;
return 0;
}
function _arotY(x, y) {
if (obj.rotation == 0) return y;
if (obj.rotation == 1) return x;
if (obj.rotation == 2) return obj.canvas.canvas.height - obj.spareh2 - y;
if (obj.rotation == 3) return obj.canvas.canvas.height - obj.spareh - x;
return 0;
}
function _crotX(x, y) {
if (obj.rotation == 0) return x;
if (obj.rotation == 1) return y;
if (obj.rotation == 2) return obj.canvas.canvas.width - x;
if (obj.rotation == 3) return obj.canvas.canvas.height - y;
return 0;
}
function _crotY(x, y) {
if (obj.rotation == 0) return y;
if (obj.rotation == 1) return obj.canvas.canvas.width - x;
if (obj.rotation == 2) return obj.canvas.canvas.height - y;
if (obj.rotation == 3) return x;
return 0;
}
function _rotX(x, y) {
if (obj.rotation == 0) return x;
if (obj.rotation == 1) return x;
if (obj.rotation == 2) return x - obj.canvas.canvas.width;
if (obj.rotation == 3) return x - obj.canvas.canvas.height;
return 0;
}
function _rotY(x, y) {
if (obj.rotation == 0) return y;
if (obj.rotation == 1) return y - obj.canvas.canvas.width;
if (obj.rotation == 2) return y - obj.canvas.canvas.height;
if (obj.rotation == 3) return y;
return 0;
}
obj.tcanvas = null;
obj.setRotation = function (x) {
while (x < 0) { x += 4; }
var newrotation = x % 4;
if (newrotation == obj.rotation) return true;
var rw = obj.canvas.canvas.width;
var rh = obj.canvas.canvas.height;
if (obj.rotation == 1 || obj.rotation == 3) { rw = obj.canvas.canvas.height; rh = obj.canvas.canvas.width; }
// Copy the canvas, put it back in the correct direction
if (obj.tcanvas == null) obj.tcanvas = document.createElement('canvas');
var tcanvasctx = obj.tcanvas.getContext('2d');
tcanvasctx.setTransform(1, 0, 0, 1, 0, 0);
tcanvasctx.canvas.width = rw;
tcanvasctx.canvas.height = rh;
tcanvasctx.rotate((obj.rotation * -90) * Math.PI / 180);
if (obj.rotation == 0) tcanvasctx.drawImage(obj.canvas.canvas, 0, 0);
if (obj.rotation == 1) tcanvasctx.drawImage(obj.canvas.canvas, -obj.canvas.canvas.width, 0);
if (obj.rotation == 2) tcanvasctx.drawImage(obj.canvas.canvas, -obj.canvas.canvas.width, -obj.canvas.canvas.height);
if (obj.rotation == 3) tcanvasctx.drawImage(obj.canvas.canvas, 0, -obj.canvas.canvas.height);
// Change the size and orientation and copy the canvas back into the rotation
if (obj.rotation == 0 || obj.rotation == 2) { obj.canvas.canvas.height = rw; obj.canvas.canvas.width = rh; }
if (obj.rotation == 1 || obj.rotation == 3) { obj.canvas.canvas.height = rh; obj.canvas.canvas.width = rw; }
obj.canvas.setTransform(1, 0, 0, 1, 0, 0);
obj.canvas.rotate((newrotation * 90) * Math.PI / 180);
obj.rotation = newrotation;
obj.canvas.drawImage(obj.tcanvas, _rotX(0, 0), _rotY(0, 0));
obj.width = obj.canvas.canvas.width;
obj.height = obj.canvas.canvas.height;
if (obj.onScreenResize != null) obj.onScreenResize(obj, obj.width, obj.height, obj.CanvasId);
return true;
}
// ###END###{DesktopRotation}
function _fixColor(c) { return (c > 127) ? (c + 32) : c; }
function _SendRefresh() {
// ###BEGIN###{DesktopFocus}
if (obj.focusmode > 0) {
// Request only pixels around the last mouse position
var df = obj.focusmode * 2;
obj.Send(String.fromCharCode(3, 1) + ShortToStr(Math.max(Math.min(obj.ox, obj.mx) - obj.focusmode, 0)) + ShortToStr(Math.max(Math.min(obj.oy, obj.my) - obj.focusmode, 0)) + ShortToStr(df + Math.abs(obj.ox - obj.mx)) + ShortToStr(df + Math.abs(obj.oy - obj.my))); // FramebufferUpdateRequest
obj.ox = obj.mx;
obj.oy = obj.my;
} else
// ###END###{DesktopFocus} {
// Request the entire screen
obj.Send(String.fromCharCode(3, 1, 0, 0, 0, 0) + ShortToStr(obj.rwidth) + ShortToStr(obj.rheight)); // FramebufferUpdateRequest
}
obj.Start = function () {
//obj.Debug("KVM-Start");
obj.state = 0;
obj.acc = "";
obj.ZRLEfirst = 1;
// ###BEGIN###{Inflate}
inflate_start();
// ###END###{Inflate}
for (var i in obj.sparecache) { delete obj.sparecache[i]; }
}
obj.Stop = function () {
obj.UnGrabMouseInput();
obj.UnGrabKeyInput();
obj.parent.Stop();
}
obj.Send = function (x) {
//obj.Debug("KSend(" + x.length + "): " + rstr2hex(x));
obj.parent.Send(x);
}
/*
Intel AMT only recognizes a small subset of keysym characters defined in the keysymdef.h so you dont need to
implement all the languages (this is taken care by the USB Scancode Extension in RFB4.0 protocol).
The only subset recognized by the FW is the defined by the following sets : XK_LATIN1 , XK_MISCELLANY, XK_3270, XK_XKB_KEYS, XK_KATAKANA.
In addition to keysymdef.h symbols there are 6 japanese extra keys that we do support:
#define XK_Intel_EU_102kbd_backslash_pipe_45 0x17170056 // European 102-key: 45 (backslash/pipe), usb Usage: 0x64
#define XK_Intel_JP_106kbd_yen_pipe 0x1717007d // Japanese 106-key: 14 (Yen/pipe), usb Usage: 0x89
#define XK_Intel_JP_106kbd_backslash_underbar 0x17170073 // Japanese 106-key: 56 (backslash/underbar), usb Usage: 0x87
#define XK_Intel_JP_106kbd_NoConvert 0x1717007b // Japanese 106-key: 131 (NoConvert), usb Usage: 0x8b
#define XK_Intel_JP_106kbd_Convert 0x17170079 // Japanese 106-key: 132 (Convert), usb Usage: 0x8a
#define XK_Intel_JP_106kbd_Hirigana_Katakana 0x17170070 // Japanese 106-key: 133 (Hirigana/Katakana), usb Usage: 0x88
*/
function _keyevent(d, e) {
if (!e) { e = window.event; }
var k = e.keyCode;
if (k == 173) k = 189; // '-' key (Firefox)
if (k == 61) k = 187; // '=' key (Firefox)
var kk = k;
if (e.shiftKey == false && k >= 65 && k <= 90) kk = k + 32;
if (k >= 112 && k <= 124) kk = k + 0xFF4E;
if (k == 8) kk = 0xff08; // Backspace
if (k == 9) kk = 0xff09; // Tab
if (k == 13) kk = 0xff0d; // Return
if (k == 16) kk = 0xffe1; // Shift (Left)
if (k == 17) kk = 0xffe3; // Ctrl (Left)
if (k == 18) kk = 0xffe9; // Alt (Left)
if (k == 27) kk = 0xff1b; // ESC
if (k == 33) kk = 0xff55; // PageUp
if (k == 34) kk = 0xff56; // PageDown
if (k == 35) kk = 0xff57; // End
if (k == 36) kk = 0xff50; // Home
if (k == 37) kk = 0xff51; // Left
if (k == 38) kk = 0xff52; // Up
if (k == 39) kk = 0xff53; // Right
if (k == 40) kk = 0xff54; // Down
if (k == 45) kk = 0xff63; // Insert
if (k == 46) kk = 0xffff; // Delete
if (k >= 96 && k <= 105) kk = k - 48; // Key pad numbers
if (k == 106) kk = 42; // Pad *
if (k == 107) kk = 43; // Pad +
if (k == 109) kk = 45; // Pad -
if (k == 110) kk = 46; // Pad .
if (k == 111) kk = 47; // Pad /
if (k == 186) kk = 59; // ;
if (k == 187) kk = 61; // =
if (k == 188) kk = 44; // ,
if (k == 189) kk = 45; // -
if (k == 190) kk = 46; // .
if (k == 191) kk = 47; // /
if (k == 192) kk = 96; // `
if (k == 219) kk = 91; // [
if (k == 220) kk = 92; // \
if (k == 221) kk = 93; // ]t
if (k == 222) kk = 39; // '
//console.log('Key' + d + ": " + k + " = " + kk);
obj.sendkey(kk, d);
return obj.haltEvent(e);
}
obj.sendkey = function (k, d) { obj.Send(String.fromCharCode(4, d, 0, 0) + IntToStr(k)); }
obj.SendCtrlAltDelMsg = function () { obj.sendcad(); }
obj.sendcad = function () {
obj.sendkey(0xFFE3, 1); // Control
obj.sendkey(0xFFE9, 1); // Alt
obj.sendkey(0xFFFF, 1); // Delete
obj.sendkey(0xFFFF, 0); // Delete
obj.sendkey(0xFFE9, 0); // Alt
obj.sendkey(0xFFE3, 0); // Control
}
var _MouseInputGrab = false;
var _KeyInputGrab = false;
obj.GrabMouseInput = function () {
if (_MouseInputGrab == true) return;
var c = obj.canvas.canvas;
c.onmouseup = obj.mouseup;
c.onmousedown = obj.mousedown;
c.onmousemove = obj.mousemove;
//if (navigator.userAgent.match(/mozilla/i)) c.DOMMouseScroll = obj.xxDOMMouseScroll; else c.onmousewheel = obj.xxMouseWheel;
_MouseInputGrab = true;
}
obj.UnGrabMouseInput = function () {
if (_MouseInputGrab == false) return;
var c = obj.canvas.canvas;
c.onmousemove = null;
c.onmouseup = null;
c.onmousedown = null;
//if (navigator.userAgent.match(/mozilla/i)) c.DOMMouseScroll = null; else c.onmousewheel = null;
_MouseInputGrab = false;
}
obj.GrabKeyInput = function () {
if (_KeyInputGrab == true) return;
document.onkeyup = obj.handleKeyUp;
document.onkeydown = obj.handleKeyDown;
document.onkeypress = obj.handleKeys;
_KeyInputGrab = true;
}
obj.UnGrabKeyInput = function () {
if (_KeyInputGrab == false) return;
document.onkeyup = null;
document.onkeydown = null;
document.onkeypress = null;
_KeyInputGrab = false;
}
obj.handleKeys = function (e) { return obj.haltEvent(e); }
obj.handleKeyUp = function (e) { return _keyevent(0, e); }
obj.handleKeyDown = function (e) { return _keyevent(1, e); }
obj.haltEvent = function (e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
// RFB "PointerEvent" and mouse handlers
obj.mousedown = function (e) { obj.buttonmask |= (1 << e.button); return obj.mousemove(e); }
obj.mouseup = function (e) { obj.buttonmask &= (0xFFFF - (1 << e.button)); return obj.mousemove(e); }
obj.mousemove = function (e) {
if (obj.state != 4) return true;
var pos = obj.getPositionOfControl(Q(obj.canvasid));
obj.mx = (e.pageX - pos[0]) * (obj.canvas.canvas.height / Q(obj.canvasid).offsetHeight);
obj.my = ((e.pageY - pos[1] + (scrolldiv ? scrolldiv.scrollTop : 0)) * (obj.canvas.canvas.width / Q(obj.canvasid).offsetWidth));
// ###BEGIN###{DesktopRotation}
obj.mx2 = _crotX(obj.mx, obj.my);
obj.my = _crotY(obj.mx, obj.my);
obj.mx = obj.mx2;
// ###END###{DesktopRotation}
obj.Send(String.fromCharCode(5, obj.buttonmask) + ShortToStr(obj.mx) + ShortToStr(obj.my));
// ###BEGIN###{DesktopFocus}
// Update focus area if we are in focus mode
QV('DeskFocus', obj.focusmode);
if (obj.focusmode != 0) {
var x = Math.min(obj.mx, obj.canvas.canvas.width - obj.focusmode),
y = Math.min(obj.my, obj.canvas.canvas.height - obj.focusmode),
df = obj.focusmode * 2,
c = Q(obj.canvasid),
qx = c.offsetHeight / obj.canvas.canvas.height,
qy = c.offsetWidth / obj.canvas.canvas.width,
q = QS('DeskFocus'),
ppos = obj.getPositionOfControl(Q(obj.canvasid).parentElement);
q.left = (Math.max(((x - obj.focusmode) * qx), 0) + (pos[0] - ppos[0])) + 'px';
q.top = (Math.max(((y - obj.focusmode) * qy), 0) + (pos[1] - ppos[1])) + 'px';
q.width = ((df * qx) - 6) + 'px';
q.height = ((df * qx) - 6) + 'px';
}
// ###END###{DesktopFocus}
return obj.haltEvent(e);
}
obj.getPositionOfControl = function (Control) {
var Position = Array(2);
Position[0] = Position[1] = 0;
while (Control) {
Position[0] += Control.offsetLeft;
Position[1] += Control.offsetTop;
Control = Control.offsetParent;
}
return Position;
}
return obj;
}

View file

@ -0,0 +1,127 @@
/**
* @description Remote Desktop
* @author Ylian Saint-Hilaire
* @version v0.0.2
*/
// Construct a Intel AMT IDER object
var CreateAmtRemoteIder = function (serverurl) {
var obj = {};
obj.protocol = 3; // IDER
obj.state = 0;
obj.socket = null;
obj.serverurl = serverurl;
obj.bytesToAmt = 0;
obj.bytesFromAmt = 0;
// Private method
obj.Debug = function (msg) { console.log(msg); }
// Private method, called by parent when it change state
obj.xxStateChange = function (newstate) {
//console.log("STATE: " + newstate);
if (newstate == 0) { obj.Stop(); } // Tell Storage Server to stop IDER
if (newstate == 3) { obj.StateChange(3); _Send('D'); } // Tell Storage Server to start IDER
}
// Private method
obj.StateChange = function (newstate) { obj.state = newstate; }
// Private method
obj.ProcessData = function (data) { _Send('F' + data); obj.bytesFromAmt += data.length; }
obj.Start = function (host, port, user, pass, tls) {
//obj.Debug("IDER-Start");
obj.host = host;
obj.port = port;
obj.user = user;
obj.pass = pass;
obj.tls = tls;
obj.bytesToAmt = 0;
obj.bytesFromAmt = 0;
obj.socket = new WebSocket(serverurl);
obj.socket.onopen = _OnSocketConnected;
obj.socket.onmessage = _OnMessage;
obj.socket.onclose = _OnSocketClosed;
obj.StateChange(1);
}
obj.Stop = function () {
if (obj.socket != null) { _Send('G'); obj.socket.close(); obj.socket = null; }
obj.StateChange(0);
obj.parent.Stop();
}
function _OnSocketConnected() {
obj.Debug("Socket Connected");
obj.StateChange(2);
_Send('C');
}
function _OnMessage(e) {
if (typeof e.data == 'object') {
var f = new FileReader();
if (f.readAsBinaryString) {
// Chrome & Firefox (Draft)
f.onload = function (e) { _OnSocketData(e.target.result); }
f.readAsBinaryString(new Blob([e.data]));
} else if (f.readAsArrayBuffer) {
// Chrome & Firefox (Spec)
f.onloadend = function (e) { _OnSocketData(e.target.result); }
f.readAsArrayBuffer(e.data);
} else {
// IE10, readAsBinaryString does not exist, use an alternative.
var binary = "";
var bytes = new Uint8Array(e.data);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
_OnSocketData(binary);
}
} else {
_OnSocketData(e.data);
}
};
function _OnSocketData(data) {
if (!data) return;
if (typeof data === 'object') {
// This is an ArrayBuffer, convert it to a string array (used in IE)
var binary = "";
var bytes = new Uint8Array(data);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
data = binary;
}
else if (typeof data !== 'string') { return; }
// console.log("CMD: " + data.substring(0, 1));
// Handle commands
switch (data.substring(0, 1)) {
case 'A': { data[0] = 'B'; _Send(data); break; } // Echo
case 'C': { obj.parent.Start(obj.host, obj.port, obj.user, obj.pass, obj.tls); break; } // Session Start
case 'E': { obj.Stop(); break; } // Stop IDER
case 'F': { obj.parent.xxSend(data.substring(1)); obj.bytesToAmt += (data.length - 1); break; } // IDER Data
case 'H': { if (obj.onDialogPrompt) obj.onDialogPrompt(obj, JSON.parse(data.substring(1))); } // IDER Dialog Prompt
}
}
function _OnSocketClosed() {
// obj.Debug("Socket Closed");
obj.Stop();
}
obj.dialogPrompt = function(x) { _Send('H' + JSON.stringify(x)); }
function _Send(x) {
// obj.Debug("Send(" + x.length + "): " + rstr2hex(x));
if (obj.socket != null && obj.socket.readyState == WebSocket.OPEN) {
var b = new Uint8Array(x.length);
for (var i = 0; i < x.length; ++i) { b[i] = x.charCodeAt(i); }
obj.socket.send(b.buffer);
}
}
return obj;
}

View file

@ -0,0 +1,291 @@
/**
* @description Intel AMT Redirection Transport Module - using websocket relay
* @author Ylian Saint-Hilaire
* @version v0.0.1f
*/
// Construct a MeshServer object
var CreateAmtRedirect = function (module) {
var obj = {};
obj.m = module; // This is the inner module (Terminal or Desktop)
module.parent = obj;
obj.State = 0;
obj.socket = null;
// ###BEGIN###{!Mode-Firmware}
obj.host = null;
obj.port = 0;
obj.user = null;
obj.pass = null;
obj.authuri = "/RedirectionService";
// ###END###{!Mode-Firmware}
obj.connectstate = 0;
obj.protocol = module.protocol; // 1 = SOL, 2 = KVM, 3 = IDER
obj.amtaccumulator = "";
obj.amtsequence = 1;
obj.amtkeepalivetimer = null;
obj.onStateChanged = null;
// Private method
//obj.Debug = function (msg) { console.log(msg); }
obj.Start = function (host, port, user, pass, tls) {
obj.host = host;
obj.port = port;
obj.user = user;
obj.pass = pass;
obj.connectstate = 0;
obj.socket = new WebSocket(window.location.protocol.replace("http", "ws") + "//" + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/webrelay.ashx?p=2&host=" + host + "&port=" + port + "&tls=" + tls + ((user == '*') ? "&serverauth=1" : "") + ((typeof pass === "undefined") ? ("&serverauth=1&user=" + user) : "")); // The "p=2" indicates to the relay that this is a REDIRECTION session
obj.socket.onopen = obj.xxOnSocketConnected;
obj.socket.onmessage = obj.xxOnMessage;
obj.socket.onclose = obj.xxOnSocketClosed;
obj.xxStateChange(1);
}
obj.xxOnSocketConnected = function () {
//obj.Debug("Redir Socket Connected");
obj.xxStateChange(2);
if (obj.protocol == 1) obj.xxSend(obj.RedirectStartSol); // TODO: Put these strings in higher level module to tighten code
if (obj.protocol == 2) obj.xxSend(obj.RedirectStartKvm); // Don't need these is the feature is not compiled-in.
if (obj.protocol == 3) obj.xxSend(obj.RedirectStartIder);
}
obj.xxOnMessage = function (e) {
if (typeof e.data == 'object') {
var f = new FileReader();
if (f.readAsBinaryString) {
// Chrome & Firefox (Draft)
f.onload = function (e) { obj.xxOnSocketData(e.target.result); }
f.readAsBinaryString(new Blob([e.data]));
} else if (f.readAsArrayBuffer) {
// Chrome & Firefox (Spec)
f.onloadend = function (e) { obj.xxOnSocketData(e.target.result); }
f.readAsArrayBuffer(e.data);
} else {
// IE10, readAsBinaryString does not exist, use an alternative.
var binary = "";
var bytes = new Uint8Array(e.data);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
obj.xxOnSocketData(binary);
}
} else {
// If we get a string object, it maybe the WebRTC confirm. Ignore it.
// obj.debug("MeshDataChannel - OnData - " + typeof e.data + " - " + e.data.length);
obj.xxOnSocketData(e.data);
}
};
obj.xxOnSocketData = function (data) {
if (!data || obj.connectstate == -1) return;
if (typeof data === 'object') {
// This is an ArrayBuffer, convert it to a string array (used in IE)
var binary = "";
var bytes = new Uint8Array(data);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
data = binary;
}
else if (typeof data !== 'string') { return; }
if ((obj.protocol == 2 || obj.protocol == 3) && obj.connectstate == 1) { return obj.m.ProcessData(data); } // KVM traffic, forward it directly.
obj.amtaccumulator += data;
//obj.Debug("Redir Recv(" + obj.amtaccumulator.length + "): " + rstr2hex(obj.amtaccumulator));
while (obj.amtaccumulator.length >= 1) {
var cmdsize = 0;
switch (obj.amtaccumulator.charCodeAt(0)) {
case 0x11: // StartRedirectionSessionReply (17)
if (obj.amtaccumulator.length < 4) return;
var statuscode = obj.amtaccumulator.charCodeAt(1);
switch (statuscode) {
case 0: // STATUS_SUCCESS
if (obj.amtaccumulator.length < 13) return;
var oemlen = obj.amtaccumulator.charCodeAt(12);
if (obj.amtaccumulator.length < 13 + oemlen) return;
// Query for available authentication
obj.xxSend(String.fromCharCode(0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); // Query authentication support
cmdsize = (13 + oemlen);
break;
default:
obj.Stop();
break;
}
break;
case 0x14: // AuthenticateSessionReply (20)
if (obj.amtaccumulator.length < 9) return;
var authDataLen = ReadIntX(obj.amtaccumulator, 5);
if (obj.amtaccumulator.length < 9 + authDataLen) return;
var status = obj.amtaccumulator.charCodeAt(1);
var authType = obj.amtaccumulator.charCodeAt(4);
var authData = [];
for (i = 0; i < authDataLen; i++) { authData.push(obj.amtaccumulator.charCodeAt(9 + i)); }
var authDataBuf = obj.amtaccumulator.substring(9, 9 + authDataLen);
cmdsize = 9 + authDataLen;
if (authType == 0) {
// Query
if (authData.indexOf(4) >= 0) {
// Good Digest Auth (With cnonce and all)
obj.xxSend(String.fromCharCode(0x13, 0x00, 0x00, 0x00, 0x04) + IntToStrX(obj.user.length + obj.authuri.length + 8) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(0x00, 0x00) + String.fromCharCode(obj.authuri.length) + obj.authuri + String.fromCharCode(0x00, 0x00, 0x00, 0x00));
}
else if (authData.indexOf(3) >= 0) {
// Bad Digest Auth (Not sure why this is supported, cnonce is not used!)
obj.xxSend(String.fromCharCode(0x13, 0x00, 0x00, 0x00, 0x03) + IntToStrX(obj.user.length + obj.authuri.length + 7) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(0x00, 0x00) + String.fromCharCode(obj.authuri.length) + obj.authuri + String.fromCharCode(0x00, 0x00, 0x00));
}
else if (authData.indexOf(1) >= 0) {
// Basic Auth (Probably a good idea to not support this unless this is an old version of Intel AMT)
obj.xxSend(String.fromCharCode(0x13, 0x00, 0x00, 0x00, 0x01) + IntToStrX(obj.user.length + obj.pass.length + 2) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(obj.pass.length) + obj.pass);
}
else obj.Stop();
}
else if ((authType == 3 || authType == 4) && status == 1) {
var curptr = 0;
// Realm
var realmlen = authDataBuf.charCodeAt(curptr);
var realm = authDataBuf.substring(curptr + 1, curptr + 1 + realmlen);
curptr += (realmlen + 1);
// Nonce
var noncelen = authDataBuf.charCodeAt(curptr);
var nonce = authDataBuf.substring(curptr + 1, curptr + 1 + noncelen);
curptr += (noncelen + 1);
// QOP
var qoplen = 0;
var qop = null;
var cnonce = obj.xxRandomNonce(32);
var snc = '00000002';
var extra = '';
if (authType == 4) {
qoplen = authDataBuf.charCodeAt(curptr);
qop = authDataBuf.substring(curptr + 1, curptr + 1 + qoplen);
curptr += (qoplen + 1);
extra = snc + ":" + cnonce + ":" + qop + ":";
}
var digest = hex_md5(hex_md5(obj.user + ":" + realm + ":" + obj.pass) + ":" + nonce + ":" + extra + hex_md5("POST:" + obj.authuri));
var totallen = obj.user.length + realm.length + nonce.length + obj.authuri.length + cnonce.length + snc.length + digest.length + 7;
if (authType == 4) totallen += (qop.length + 1);
var buf = String.fromCharCode(0x13, 0x00, 0x00, 0x00, authType) + IntToStrX(totallen) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(realm.length) + realm + String.fromCharCode(nonce.length) + nonce + String.fromCharCode(obj.authuri.length) + obj.authuri + String.fromCharCode(cnonce.length) + cnonce + String.fromCharCode(snc.length) + snc + String.fromCharCode(digest.length) + digest;
if (authType == 4) buf += (String.fromCharCode(qop.length) + qop);
obj.xxSend(buf);
}
else
if (status == 0) { // Success
if (obj.protocol == 1) {
// Serial-over-LAN: Send Intel AMT serial settings...
var MaxTxBuffer = 10000;
var TxTimeout = 100;
var TxOverflowTimeout = 0;
var RxTimeout = 10000;
var RxFlushTimeout = 100;
var Heartbeat = 0;//5000;
obj.xxSend(String.fromCharCode(0x20, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + ShortToStrX(MaxTxBuffer) + ShortToStrX(TxTimeout) + ShortToStrX(TxOverflowTimeout) + ShortToStrX(RxTimeout) + ShortToStrX(RxFlushTimeout) + ShortToStrX(Heartbeat) + IntToStrX(0));
}
if (obj.protocol == 2) {
// Remote Desktop: Send traffic directly...
obj.xxSend(String.fromCharCode(0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
}
if (obj.protocol == 3) {
// Remote IDER: Send traffic directly...
obj.connectstate = 1;
obj.xxStateChange(3);
}
} else obj.Stop();
break;
case 0x21: // Response to settings (33)
if (obj.amtaccumulator.length < 23) break;
cmdsize = 23;
obj.xxSend(String.fromCharCode(0x27, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + String.fromCharCode(0x00, 0x00, 0x1B, 0x00, 0x00, 0x00));
if (obj.protocol == 1) { obj.amtkeepalivetimer = setInterval(obj.xxSendAmtKeepAlive, 2000); }
obj.connectstate = 1;
obj.xxStateChange(3);
break;
case 0x29: // Serial Settings (41)
if (obj.amtaccumulator.length < 10) break;
cmdsize = 10;
break;
case 0x2A: // Incoming display data (42)
if (obj.amtaccumulator.length < 10) break;
var cs = (10 + ((obj.amtaccumulator.charCodeAt(9) & 0xFF) << 8) + (obj.amtaccumulator.charCodeAt(8) & 0xFF));
if (obj.amtaccumulator.length < cs) break;
obj.m.ProcessData(obj.amtaccumulator.substring(10, cs));
cmdsize = cs;
break;
case 0x2B: // Keep alive message (43)
if (obj.amtaccumulator.length < 8) break;
cmdsize = 8;
break;
case 0x41:
if (obj.amtaccumulator.length < 8) break;
obj.connectstate = 1;
obj.m.Start();
// KVM traffic, forward rest of accumulator directly.
if (obj.amtaccumulator.length > 8) { obj.m.ProcessData(obj.amtaccumulator.substring(8)); }
cmdsize = obj.amtaccumulator.length;
break;
default:
console.log("Unknown Intel AMT command: " + obj.amtaccumulator.charCodeAt(0) + " acclen=" + obj.amtaccumulator.length);
obj.Stop();
return;
}
if (cmdsize == 0) return;
obj.amtaccumulator = obj.amtaccumulator.substring(cmdsize);
}
}
obj.xxSend = function (x) {
//obj.Debug("Redir Send(" + x.length + "): " + rstr2hex(x));
if (obj.socket != null && obj.socket.readyState == WebSocket.OPEN) {
var b = new Uint8Array(x.length);
for (var i = 0; i < x.length; ++i) { b[i] = x.charCodeAt(i); }
obj.socket.send(b.buffer);
}
}
obj.Send = function (x) {
if (obj.socket == null || obj.connectstate != 1) return;
if (obj.protocol == 1) { obj.xxSend(String.fromCharCode(0x28, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + ShortToStrX(x.length) + x); } else { obj.xxSend(x); }
}
obj.xxSendAmtKeepAlive = function () {
if (obj.socket == null) return;
obj.xxSend(String.fromCharCode(0x2B, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++));
}
obj.xxRandomNonceX = "abcdef0123456789";
obj.xxRandomNonce = function (length) {
var r = "";
for (var i = 0; i < length; i++) { r += obj.xxRandomNonceX.charAt(Math.floor(Math.random() * obj.xxRandomNonceX.length)); }
return r;
}
obj.xxOnSocketClosed = function () {
//obj.Debug("Redir Socket Closed");
obj.Stop();
}
obj.xxStateChange = function(newstate) {
if (obj.State == newstate) return;
obj.State = newstate;
obj.m.xxStateChange(obj.State);
if (obj.onStateChanged != null) obj.onStateChanged(obj, obj.State);
}
obj.Stop = function () {
//obj.Debug("Redir Socket Stopped");
obj.xxStateChange(0);
obj.connectstate = -1;
obj.amtaccumulator = "";
if (obj.socket != null) { obj.socket.close(); obj.socket = null; }
if (obj.amtkeepalivetimer != null) { clearInterval(obj.amtkeepalivetimer); obj.amtkeepalivetimer = null; }
}
obj.RedirectStartSol = String.fromCharCode(0x10, 0x00, 0x00, 0x00, 0x53, 0x4F, 0x4C, 0x20);
obj.RedirectStartKvm = String.fromCharCode(0x10, 0x01, 0x00, 0x00, 0x4b, 0x56, 0x4d, 0x52);
obj.RedirectStartIder = String.fromCharCode(0x10, 0x00, 0x00, 0x00, 0x49, 0x44, 0x45, 0x52);
return obj;
}

View file

@ -0,0 +1,436 @@
/**
* @fileoverview Script Compiler / Decompiler / Runner
* @author Ylian Saint-Hilaire
* @version v0.1.0e
*/
// Core functions
script_functionTable1 = ['nop', 'jump', 'set', 'print', 'dialog', 'getitem', 'substr', 'indexof', 'split', 'join', 'length', 'jsonparse', 'jsonstr', 'add', 'substract', 'parseint', 'wsbatchenum', 'wsput', 'wscreate', 'wsdelete', 'wsexec', 'scriptspeed', 'wssubscribe', 'wsunsubscribe', 'readchar', 'signwithdummyca'];
// functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
script_functionTable2 = ['encodeuri', 'decodeuri', 'passwordcheck', 'atob', 'btoa', 'hex2str', 'str2hex', 'random', 'md5', 'maketoarray', 'readshort', 'readshortx', 'readint', 'readsint', 'readintx', 'shorttostr', 'shorttostrx', 'inttostr', 'inttostrx'];
// functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
script_functionTableX2 = [encodeURI, decodeURI, passwordcheck, window.atob.bind(window), window.btoa.bind(window), hex2rstr, rstr2hex, random, rstr_md5, MakeToArray, ReadShort, ReadShortX, ReadInt, ReadSInt, ReadIntX, ShortToStr, ShortToStrX, IntToStr, IntToStrX];
// Optional functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
script_functionTable3 = ['pullsystemstatus', 'pulleventlog', 'pullauditlog', 'pullcertificates', 'pullwatchdog', 'pullsystemdefense', 'pullhardware', 'pulluserinfo', 'pullremoteaccess', 'highlightblock', 'disconnect', 'getsidstring', 'getsidbytearray'];
// Optional functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
script_functionTableX3 = [
PullSystemStatus
,
// ###BEGIN###{EventLog}
PullEventLog
// ###END###{EventLog}
,
// ###BEGIN###{AuditLog}
PullAuditLog
// ###END###{AuditLog}
,
// ###BEGIN###{Certificates}
PullCertificates
// ###END###{Certificates}
,
// ###BEGIN###{AgentPresence}
PullWatchdog
// ###END###{AgentPresence}
,
// ###BEGIN###{SystemDefense}
PullSystemDefense
// ###END###{SystemDefense}
,
// ###BEGIN###{HardwareInfo}
PullHardware
// ###END###{HardwareInfo}
,
PullUserInfo
,
// ###BEGIN###{RemoteAccess}
PullRemoteAccess
// ###END###{RemoteAccess}
,
// ###BEGIN###{Scripting-Editor}
script_HighlightBlock
// ###END###{Scripting-Editor}
,
// ###BEGIN###{ComputerSelector}
disconnect
// ###END###{ComputerSelector}
,
function (runner, x) { return GetSidString(x); }
,
function (runner, x) { return GetSidByteArray(x); }
];
// Setup the script state
function script_setup(binary, startvars) {
var obj = { startvars:startvars };
if (binary.length < 6) { console.error('Invalid script length'); return null; } // Script must have at least 6 byte header
if (ReadInt(binary, 0) != 0x247D2945) { console.error('Invalid binary script'); return null; } // Check the script magic header
if (ReadShort(binary, 4) > 1) { console.error('Unsupported script version'); return null; } // Check the script version
obj.script = binary.substring(6);
// obj.onStep;
// obj.onConsole;
// Reset the script to the start
obj.reset = function (stepspeed) {
obj.stop();
obj.ip = 0;
obj.variables = startvars;
obj.state = 1;
}
// Start the script
obj.start = function (stepspeed) {
obj.stop();
obj.stepspeed = stepspeed;
if (stepspeed > 0) { obj.timer = setInterval(function () { obj.step() }, stepspeed); }
}
// Stop the script
obj.stop = function () {
if (obj.timer != null) { clearInterval(obj.timer); }
obj.timer = null;
obj.stepspeed = 0;
}
// function used to load and store variable values
obj.getVar = function (name) { if (name == undefined) return undefined; return obj.getVarEx(name.split('.'), obj.variables); }
obj.getVarEx = function (name, val) { try { if (name == undefined) return undefined; if (name.length == 0) return val; return obj.getVarEx(name.slice(1), val[name[0]]); } catch (e) { return null; } }
obj.setVar = function (name, val) { obj.setVarEx(name.split('.'), obj.variables, val); }
obj.setVarEx = function (name, vars, val) { if (name.length == 1) { vars[name[0]] = val; } else { obj.setVarEx(name.slice(1), vars[name[0]], val); } }
// Run the script one step forward
obj.step = function () {
if (obj.state != 1) return;
if (obj.ip < obj.script.length) {
var cmdid = ReadShort(obj.script, obj.ip);
var cmdlen = ReadShort(obj.script, obj.ip + 2);
var argcount = ReadShort(obj.script, obj.ip + 4);
var argptr = obj.ip + 6;
var args = [];
// Clear all temp variables (This is optional)
for (var i in obj.variables) { if (i.startsWith('__')) { delete obj.variables[i]; } }
// Loop on each argument, moving forward by the argument length each time
for (var i = 0; i < argcount; i++) {
var arglen = ReadShort(obj.script, argptr);
var argval = obj.script.substring(argptr + 2, argptr + 2 + arglen);
var argtyp = argval.charCodeAt(0);
argval = argval.substring(1);
if (argtyp < 2) {
// Get the value and replace all {var} with variable values
while (argval.split("{").length > 1) { var t = argval.split("{").pop().split("}").shift(); argval = argval.replace('{' + t + '}', obj.getVar(t)); }
if (argtyp == 1) { obj.variables['__' + i] = decodeURI(argval); argval = '__' + i; } // If argtyp is 1, this is a literal. Store in temp variable.
args.push(argval);
}
if (argtyp == 2 || argtyp == 3) {
obj.variables['__' + i] = ReadSInt(argval, 0);
args.push('__' + i);
}
argptr += (2 + arglen);
}
// Move instruction pointer forward by command size
obj.ip += cmdlen;
// Get all variable values
var argsval = [];
for (var i = 0; i < 10; i++) { argsval.push(obj.getVar(args[i])); }
var storeInArg0;
try {
if (cmdid < 10000) {
// Lets run the actual command
switch (cmdid) {
case 0: // nop
break;
case 1: // jump(label) or jump(label, a, compare, b)
if (argsval[2]) {
if (
(argsval[2] == '<' && argsval[1] < argsval[3]) ||
(argsval[2] == '<=' && argsval[1] <= argsval[3]) ||
(argsval[2] == '!=' && argsval[1] != argsval[3]) ||
(argsval[2] == '=' && argsval[1] == argsval[3]) ||
(argsval[2] == '>=' && argsval[1] >= argsval[3]) ||
(argsval[2] == '>' && argsval[1] > argsval[3])
) { obj.ip = argsval[0]; }
} else {
obj.ip = argsval[0]; // Set the instruction pointer to the new location in the script
}
break;
case 2: // set(variable, value)
if (args[1] == undefined) delete obj.variables[args[0]]; else obj.setVar(args[0], argsval[1]);
break;
case 3: // print(message)
if (obj.onConsole) { obj.onConsole(obj.toString(argsval[0]), obj); } else { console.log(obj.toString(argsval[0])); }
// Q(obj.consoleid).value += () + '\n'); Q(obj.console).scrollTop = Q(obj.console).scrollHeight;
break;
case 4: // dialog(title, content, buttons)
obj.state = 2;
obj.dialog = true;
setDialogMode(11, argsval[0], argsval[2], obj.xxStepDialogOk, argsval[1], obj);
break;
case 5: // getitem(a, b, c)
for (var i in argsval[1]) { if (argsval[1][i][argsval[2]] == argsval[3]) { storeInArg0 = i; } };
break;
case 6: // substr(variable_dest, variable_src, index, len)
storeInArg0 = argsval[1].substr(argsval[2], argsval[3]);
break;
case 7: // indexOf(variable_dest, variable_src, index, len)
storeInArg0 = argsval[1].indexOf(argsval[2]);
break;
case 8: // split(variable_dest, variable_src, separator)
storeInArg0 = argsval[1].split(argsval[2]);
break;
case 9: // join(variable_dest, variable_src, separator)
storeInArg0 = argsval[1].join(argsval[2]);
break;
case 10: // length(variable_dest, variable_src)
storeInArg0 = argsval[1].length;
break;
case 11: // jsonparse(variable_dest, json)
storeInArg0 = JSON.parse(argsval[1]);
break;
case 12: // jsonstr(variable_dest, variable_src)
storeInArg0 = JSON.stringify(argsval[1]);
break;
case 13: // add(variable_dest, variable_src, value)
storeInArg0 = (argsval[1] + argsval[2]);
break;
case 14: // substract(variable_dest, variable_src, value)
storeInArg0 = (argsval[1] - argsval[2]);
break;
case 15: // parseInt(variable_dest, variable_src)
storeInArg0 = parseInt(argsval[1]);
break;
case 16: // wsbatchenum(name, objectList)
obj.state = 2;
obj.amtstack.BatchEnum(argsval[0], argsval[1], obj.xxWsmanReturn, obj);
break;
case 17: // wsput(name, args)
obj.state = 2;
obj.amtstack.Put(argsval[0], argsval[1], obj.xxWsmanReturn, obj);
break;
case 18: // wscreate(name, args)
obj.state = 2;
obj.amtstack.Create(argsval[0], argsval[1], obj.xxWsmanReturn, obj);
break;
case 19: // wsdelete(name, args)
obj.state = 2;
obj.amtstack.Delete(argsval[0], argsval[1], obj.xxWsmanReturn, obj);
break;
case 20: // wsexec(name, method, args, selectors)
obj.state = 2;
obj.amtstack.Exec(argsval[0], argsval[1], argsval[2], obj.xxWsmanReturn, obj, 0, argsval[3]);
break;
case 21: // Script Speed
obj.stepspeed = argsval[0];
if (obj.timer != null) { clearInterval(obj.timer); obj.timer = setInterval(function () { obj.step() }, obj.stepspeed); }
break;
case 22: // wssubscribe(name, delivery, url, selectors, opaque, user, pass)
obj.state = 2;
obj.amtstack.Subscribe(argsval[0], argsval[1], argsval[2], obj.xxWsmanReturn, obj, 0, argsval[3], argsval[4], argsval[5], argsval[6]);
break;
case 23: // wsunsubscribe(name, selectors)
obj.state = 2;
obj.amtstack.UnSubscribe(argsval[0], obj.xxWsmanReturn, obj, 0, argsval[1]);
break;
case 24: // readchar(str, pos)
console.log(argsval[1], argsval[2], argsval[1].charCodeAt(argsval[2]));
storeInArg0 = argsval[1].charCodeAt(argsval[2]);
break;
case 25: // signWithDummyCa
// ###BEGIN###{Certificates}
obj.state = 2;
// DERKey, xxCaPrivateKey, certattributes, issuerattributes
amtcert_signWithCaKey(argsval[0], null, argsval[1], { 'CN': 'Untrusted Root Certificate' }, obj.xxSignWithDummyCaReturn);
// ###END###{Certificates}
break;
default: {
obj.state = 9;
console.error("Script Error, unknown command: " + cmdid);
}
}
} else {
if (cmdid < 20000) {
// functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
storeInArg0 = script_functionTableX2[cmdid - 10000](argsval[1], argsval[2], argsval[3], argsval[4], argsval[5], argsval[6]);
} else {
// Optional functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
if (script_functionTableX3 && script_functionTableX3[cmdid - 20000]) {
storeInArg0 = script_functionTableX3[cmdid - 20000](obj, argsval[1], argsval[2], argsval[3], argsval[4], argsval[5], argsval[6]); // Note that optional calls start with "obj" as first argument.
}
}
}
if (storeInArg0 != undefined) obj.setVar(args[0], storeInArg0);
} catch (e) {
if (typeof e == 'object') { e = e.message; }
obj.setVar('_exception', e);
}
}
if (obj.state == 1 && obj.ip >= obj.script.length) { obj.state = 0; obj.stop(); }
if (obj.onStep) obj.onStep(obj);
return obj;
}
obj.xxStepDialogOk = function (button) {
obj.variables['DialogSelect'] = button;
obj.state = 1;
obj.dialog = false;
if (obj.onStep) obj.onStep(obj);
}
// ###BEGIN###{**ClosureAdvancedMode}
obj.xxWsmanReturnFix = function (x) {
if (!x || x == null) return;
if (x.Header) { x['Header'] = x.Header; delete x.Header; }
if (x.Body) { x['Body'] = x.Body; delete x.Body; }
if (x.Responses) { x['Responses'] = x.Responses; delete x.Responses; }
if (x.Response) { x['Response'] = x.Response; delete x.Response; }
if (x.ReturnValueStr) { x['ReturnValueStr'] = x.ReturnValueStr; delete x.ReturnValueStr; }
}
// ###END###{**ClosureAdvancedMode}
obj.xxWsmanReturn = function (stack, name, responses, status) {
// ###BEGIN###{**ClosureAdvancedMode}
// This is required when Google Closure is used
if (responses) {
obj.xxWsmanReturnFix(responses);
for (var i in responses) {
obj.xxWsmanReturnFix(responses[i]);
for (var j in responses[i]) { obj.xxWsmanReturnFix(responses[i][j]); }
}
}
// ###END###{**ClosureAdvancedMode}
obj.setVar(name, responses);
obj.setVar('wsman_result', status);
obj.setVar('wsman_result_str', ((httpErrorTable[status]) ? (httpErrorTable[status]) : ('Error #' + status)));
obj.state = 1;
if (obj.onStep) obj.onStep(obj);
}
// ###BEGIN###{Certificates}
obj.xxSignWithDummyCaReturn = function (cert) {
obj.setVar('signed_cert', btoa(_arrayBufferToString(cert)));
obj.state = 1;
if (obj.onStep) obj.onStep(obj);
}
// ###END###{Certificates}
obj.toString = function (x) { if (typeof x == 'object') return JSON.stringify(x); return x; }
obj.reset();
return obj;
}
// Argument types: 0 = Variable, 1 = String, 2 = Integer, 3 = Label
function script_compile(script, onmsg) {
var r = '', scriptlines = script.split('\n'), labels = {}, labelswap = [], swaps = [];
// Go thru each script line and encode it
for (var i in scriptlines) {
var scriptline = scriptlines[i];
if (scriptline.startsWith('##SWAP ')) { var x = scriptline.split(' '); if (x.length == 3) { swaps[x[1]] = x[2]; } } // Add a swap instance
if (scriptline[0] == '#' || scriptline.length == 0) continue; // Skip comments & blank lines
for (var x in swaps) { scriptline = scriptline.split(x).join(swaps[x]); } // Apply all swaps
var keywords = scriptline.match(/"[^"]*"|[^\s"]+/g);
if (keywords.length == 0) continue; // Skip blank lines
if (scriptline[0] == ':') { labels[keywords[0].toUpperCase()] = r.length; continue; } // Mark a label position
var funcIndex = script_functionTable1.indexOf(keywords[0].toLowerCase());
if (funcIndex == -1) { funcIndex = script_functionTable2.indexOf(keywords[0].toLowerCase()); if (funcIndex >= 0) funcIndex += 10000; }
if (funcIndex == -1) { funcIndex = script_functionTable3.indexOf(keywords[0].toLowerCase()); if (funcIndex >= 0) funcIndex += 20000; } // Optional methods
if (funcIndex == -1) { if (onmsg) { onmsg("Unabled to compile, unknown command: " + keywords[0]); } return ''; }
// Encode CommandId, CmdSize, ArgCount, Arg1Len, Arg1, Arg2Len, Arg2...
var cmd = ShortToStr(keywords.length - 1);
for (var j in keywords) {
if (j == 0) continue;
if (keywords[j][0] == ':') {
labelswap.push([keywords[j], r.length + cmd.length + 7]); // Add a label swap
cmd += ShortToStr(5) + String.fromCharCode(3) + IntToStr(0xFFFFFFFF); // Put an empty label
} else {
var argint = parseInt(keywords[j]);
if (argint == keywords[j]) {
cmd += ShortToStr(5) + String.fromCharCode(2) + IntToStr(argint);
} else {
if (keywords[j][0] == '"' && keywords[j][keywords[j].length - 1] == '"') {
cmd += ShortToStr(keywords[j].length - 1) + String.fromCharCode(1) + keywords[j].substring(1, keywords[j].length - 1);
} else {
cmd += ShortToStr(keywords[j].length + 1) + String.fromCharCode(0) + keywords[j];
}
}
}
}
cmd = ShortToStr(funcIndex) + ShortToStr(cmd.length + 4) + cmd;
r += cmd;
}
// Perform all the needed label swaps
for (i in labelswap) {
var label = labelswap[i][0].toUpperCase(), position = labelswap[i][1], target = labels[label];
if (target == undefined) { if (onmsg) { onmsg("Unabled to compile, unknown label: " + label); } return ''; }
r = r.substr(0, position) + IntToStr(target) + r.substr(position + 4);
}
return IntToStr(0x247D2945) + ShortToStr(1) + r;
}
// Decompile the script, intended for debugging only
function script_decompile(binary, onecmd) {
var r = '', ptr = 6, labelcount = 0, labels = {};
if (onecmd >= 0) {
ptr = onecmd; // If we are decompiling just one command, set the ptr to that command.
} else {
if (binary.length < 6) { return '# Invalid script length'; }
var magic = ReadInt(binary, 0);
var version = ReadShort(binary, 4);
if (magic != 0x247D2945) { return '# Invalid binary script: ' + magic; }
if (version != 1) { return '# Invalid script version'; }
}
// Loop on each command, moving forward by the command length each time.
while (ptr < binary.length) {
var cmdid = ReadShort(binary, ptr);
var cmdlen = ReadShort(binary, ptr + 2);
var argcount = ReadShort(binary, ptr + 4);
var argptr = ptr + 6;
var argstr = '';
if (!(onecmd >= 0)) r += ":label" + (ptr - 6) + "\n";
// Loop on each argument, moving forward by the argument length each time
for (var i = 0; i < argcount; i++) {
var arglen = ReadShort(binary, argptr);
var argval = binary.substring(argptr + 2, argptr + 2 + arglen);
var argtyp = argval.charCodeAt(0);
if (argtyp == 0) { argstr += ' ' + argval.substring(1); } // Variable
else if (argtyp == 1) { argstr += ' \"' + argval.substring(1) + '\"'; } // String
else if (argtyp == 2) { argstr += ' ' + ReadInt(argval, 1); } // Integer
else if (argtyp == 3) { // Label
var target = ReadInt(argval, 1);
var label = labels[target];
if (!label) { label = ":label" + target; labels[label] = target; }
argstr += ' ' + label;
}
argptr += (2 + arglen);
}
// Go in the script function table to decode the function
if (cmdid < 10000) {
r += script_functionTable1[cmdid] + argstr + "\n";
} else {
if (cmdid >= 20000) {
r += script_functionTable3[cmdid - 20000] + argstr + "\n"; // Optional methods
} else {
r += script_functionTable2[cmdid - 10000] + argstr + "\n";
}
}
ptr += cmdlen;
if (onecmd >= 0) return r; // If we are decompiling just one command, exit now
}
// Remove all unused labels
var scriptlines = r.split('\n');
r = '';
for (var i in scriptlines) {
var line = scriptlines[i];
if (line[0] != ':') { r += line + '\n'; } else { if (labels[line]) { r += line + '\n'; } }
}
return r;
}

View file

@ -0,0 +1,267 @@
/**
* @description Intel(R) AMT Setup.bin Parser
* @author Ylian Saint-Hilaire
* @version v0.1.0
*/
// Intel(R) AMT Setup.bin GUID's
var AmtSetupBinSetupGuids = [
"\xb5\x16\xfb\x71\x87\xcb\xf9\x4a\xb4\x41\xca\x7b\x38\x35\x78\xf9", // Version 1
"\x96\xb2\x81\x58\xcf\x6b\x72\x4c\x8b\x91\xa1\x5e\x51\x2e\x99\xc4", // Version 2
"\xa7\xf7\xf6\xc6\x89\xc4\xf6\x47\x93\xed\xe2\xe5\x02\x0d\xa5\x1d", // Version 3
"\xaa\xa9\x34\x52\xe1\x29\xa9\x44\x8d\x4d\x08\x1c\x07\xb9\x63\x53" // Version 4
];
// Notes about version 2 of setup.bin:
// - Default "admin" must be followed by a new MEBx password
// - ME_VARIABLE_IDENTIFIER_MANAGEABILITY_FEATURE_SELECTION may not appear after any CM settings
// - CM_VARIABLE_IDENTIFIER_USER_DEFINED_CERT_ADD must be preceded by setting CM_VARIABLE_IDENTIFIER_USER_DEFINED_CERTS_CONFIG to (TODO!)
// General notes:
// - Setup.bin should always start with "CurrentMEBx Pwd", "newMebx Pwd", "manageability selection" (if present).
// Intel(R) AMT variable identifiers
// Type: 0 = Binar Stringy, 1 = Char, 2 = Short, 3 = Int
var AmtSetupBinVarIds =
{
1: {
1: [0, "Current MEBx Password"],
2: [0, "New MEBx Password"],
3: [1, "Manageability Feature Selection"],
4: [1, "Firmware Local Update", // 0 = Disabled, 1 = Enabled, 2 = Password Protected
{ 0: "Disabled", 1: "Enabled", 2: "Password Protected" }],
5: [1, "Firmware Update Qualifier", // 0 = Always, 1 = Never, 2 = Restricted
{ 0: "Always", 1: "Never", 2: "Restricted" }],
6: [0, "Power Package"] // GUID Length (16 bytes), Intel AMT version 2.1, 3 and 4
},
2: {
1: [0, "Provisioning Preshared Key ID (PID)"],
2: [0, "Provisioning Preshared Key (PPS)"],
3: [0, "PKI DNS Suffix"], // 255 bytes max length
4: [0, "Configuration Server FQDN"], // 255 bytes max length
5: [1, "Remote Configuration Enabled (RCFG)", // 0 = Off, 1 = On
{ 0: "Off", 1: "On" }],
6: [1, "Pre-Installed Certificates Enabled", // 0 = Off, 1 = On
{ 0: "Off", 1: "On" }],
7: [1, "User Defined Certificate Configuration", // 0 = Disabled, 1 = Enabled, 2 = Delete
{ 0: "Disabled", 1: "Enabled", 2: "Delete" }],
8: [0, "User Defined Certificate Addition"], // 1 byte hash algo, 20 to 48 bytes hash, 1 byte name length, up to 32 bytes friendly name, 1 = SHA1 (20 bytes), 2 = SHA256 (32 bytes), 3 = SHA384 (48 bytes). Algo 2 & 3 are for version 3 and up.
10: [1, "SOL/IDER Redirection Configuration"],
11: [0, "Hostname"], // 63 bytes max length
12: [0, "Domain Name"], // 255 bytes max length
13: [0, "DHCP"],
14: [1, "Secure Firmware Update (SFWU)", // 0 = Disabled, 1 = Enabled
{ 0: "Disabled", 1: "Enabled" }],
15: [0, "ITO"],
16: [1, "Provisioning Mode (PM)", // 1 = Enterprise, 2 = Small Buisness (SMB)
{ 0: "Enterprise", 1: "Small Buisness"}],
17: [0, "Provisioning Server Address"],
18: [2, "Provision Server Port Number (PSPO)"],
19: [0, "Static PV4 Parameters"],
20: [0, "VLAN"],
21: [0, "PASS Policy Flag"],
22: [0, "IPv6"], // Length is 204 bytes old format, 84 bytes new format, Version 3+ only
23: [1, "Shared/Dedicated FQDN", // 0 = Dedicated, 1 = Shared. This option is valid only if configuring the hostname as well
{ 0: "Dedicated", 1: "Shared" }],
24: [1, "Dynamic DNS Update", // 0 = Disabled, 1 = Enabled
{ 0: "Disabled", 1: "Enabled" }],
25: [1, "Remote Desktop (KVM) State", // 0 = Disabled, 1 = Enabled
{ 0: "Disabled", 1: "Enabled" }],
26: [1, "Opt-in User Consent Option", // 0 = Disabled, 1 = KVM, 0xFF = ALL
{ 0 : "Disabled", 1 : "KVM", 255 : "All" }],
27: [1, "Opt-in Remote IT Consent Policy", // 0 = Disabled, 1 = Enabled. Allows user consent to be configured remotely.
{ 0 : "Disabled", 1 : "Enabled"} ],
28: [1, "ME Provision Halt Active", // 0 = Stop, 1 = Start. The "ME provisioning Halt/Activate" command must appear in the file only after "PKIDNSSuffix", "ConfigServerFQDN" and "Provisioning Server Address"
{ 0 : "Stop", 1 : "Start"}],
29: [1, "Manual Setup and Configuration", // 0 = Automated, 1 = Manual
{ 0 : "Automated", 1 : "Manual"}],
30: [3, "Support Channel Identifier"], // 4 bytes length. Support channel identifier (valid values: 1-65535)
31: [0, "Support Channel Description"], // 60 bytes max. Friendly name used to describe the party representedby the support channel identifier.
32: [0, "Service Account Number"], // 32 bytes max. Unique string identifier given to the end user by the service provider.
33: [0, "Enrollement Passcode"], // 32 bytes max
34: [3, "Service Type"], // 4 bytes length. 1 = Reactive, 2 = Proactive, 4 = One Time Session
35: [0, "Service Provider Identifier"] // GUID Length (16 bytes)
}
}
// Parse the Setup.bin file
var AmtSetupBinCreate = function (version, flags) {
var obj = {};
obj.fileType = version;
obj.recordChunkCount = 0;
obj.recordHeaderByteCount = 0;
obj.recordNumber = 0;
obj.majorVersion = version;
obj.minorVersion = 0;
obj.flags = flags;
obj.dataRecordsConsumed = 0;
obj.dataRecordChunkCount = 0;
obj.records = [];
return obj;
}
// Parse the Setup.bin file
var AmtSetupBinDecode = function (file) {
// Format of the setup file header:
// FileTypeUUID(16) - uniquely identifies the file type. This identifier will remain valid and constant across all versions of the file type.
// RecordChunkCount(2) - indicates the number of 512-byte chunks occupied by this record, including all header, body, and reserved fields.
// RecordHeaderBytes(2) - indicates the length of the record header in bytes.
// RecordNumber(4) - uniquely identifies the record among all records in the file. The field contains a non-negative ordinal value. The value of this field is always zero in the Local Provisioning File Header Record.
// MajorVersion(1) - identifies the major version of the file format specification. This is a positive integer that is greater than or equal to 1. The Major Version number is incremented to indicate that changes have been introduced that will cause code written against a lower Major Version number to fail.
// MinorVersion(1) - identifies the minor version of the file format specification. This is an integer that is greater than or equal to 0. The Minor Version number is incremented to indicate that changes have been introduced that will not cause code written against the same Major Version and a lower Minor Version number to fail. The purpose of this behavior is to allow a single local provisioning file to be used for multiple generations of Intel® AMT platform.
// DataRecordCount(4) - indicates the total number of data records written in the file when it was created.
// DataRecordsConsumed(4) - is a counter value that begins at 0 and is incremented by 1 by each platform BIOS when it consumes a data record from the file. This value is used to determine the offset of the next data record in the file.
// DataRecordChunkCount(2) - contains the number of 512-byte chunks in each data record. All data records are the same length.
// ModuleList - contains a list of module identifiers. A modules identifier appears in the list if and only if the data records contain entries for that module. Each module identifier is two bytes in length. The list is terminated by an identifier value of 0.
var obj = {}, UUID = file.substring(0, 16);
obj.fileType = 0;
for (var i in AmtSetupBinSetupGuids) { if (UUID == AmtSetupBinSetupGuids[i]) obj.fileType = (+i + 1); }
if (obj.fileType == 0) return; // Bad header
obj.recordChunkCount = ReadShortX(file, 16);
obj.recordHeaderByteCount = ReadShortX(file, 18);
obj.recordNumber = ReadIntX(file, 20);
obj.majorVersion = file.charCodeAt(24);
obj.minorVersion = file.charCodeAt(25);
obj.flags = ReadShortX(file, 26); // Flags: 1 = Do not consume records
var dataRecordCount = ReadIntX(file, 28);
obj.dataRecordsConsumed = ReadIntX(file, 32);
obj.dataRecordChunkCount = ReadShortX(file, 36);
obj.records = [];
var ptr = 512;
while (ptr + 512 <= file.length) {
// Format of a data record header:
// RecordTypeIdentifier(4) - identifies the type of record (in this case a data record). Record Identifiers: Invalid - 0, Data Record - 1
// RecordFlags(4) - contains a set of bit flags that characterize the record.
// RecordChunkCount(2) - contains the number of 512-byte chunks occupied by the record including all header, body, and reserved fields.
// RecordHeaderByteCount(2) - indicates the length of the record header in bytes.
// RecordNumber(4) - uniquely identifies the record among all records in the file, including invalid as well as valid records. The identifier is a non-negative integer.
var r = {};
r.typeIdentifier = ReadIntX(file, ptr);
r.flags = ReadIntX(file, ptr + 4); // Flags: 1 = Valid, 2 = Scrambled
r.chunkCount = ReadShortX(file, ptr + 8);
r.headerByteCount = ReadShortX(file, ptr + 10);
r.number = ReadIntX(file, ptr + 12);
r.variables = [];
var ptr2 = 0, recbin = file.substring(ptr + 24, ptr + 512);
if ((r.flags & 2) != 0) { recbin = AmtSetupBinDescrambleRecordData(recbin); } // De-Scramble the record
while (1) {
// Format of a data record entry:
// ModuleIdentifier(2) - identifies the target ME module for the entry.
// VariableIdentifier(2) - an enumeration value that identifies the variable. Variable identifiers are unique to each ModuleIdentifier.
// VariableLength(2) - is the length of the variable value in bytes.
// VariableValue - is the value to be assigned to the variable.
var v = {};
v.moduleid = ReadShortX(recbin, ptr2);
v.varid = ReadShortX(recbin, ptr2 + 2);
if (v.moduleid == 0 || v.varid == 0) break;
if (AmtSetupBinVarIds[v.moduleid][v.varid]) {
v.length = ReadShortX(recbin, ptr2 + 4);
v.type = AmtSetupBinVarIds[v.moduleid][v.varid][0];
v.desc = AmtSetupBinVarIds[v.moduleid][v.varid][1];
v.value = recbin.substring(ptr2 + 8, ptr2 + 8 + v.length);
if (v.type == 1 && v.length == 1) v.value = v.value.charCodeAt(0);
else if (v.type == 2 && v.length == 2) v.value = ReadShortX(v.value, 0);
else if (v.type == 3 && v.length == 4) v.value = ReadIntX(v.value, 0);
r.variables.push(v);
}
ptr2 += (8 + (Math.floor((v.length + 3) / 4) * 4));
}
// Sort the variables
r.variables.sort(AmtSetupBinVariableCompare);
obj.records.push(r);
ptr += 512;
}
if (dataRecordCount != obj.records.length) return; // Mismatch record count
return obj;
}
// Construct a Setup.bin file
var AmtSetupBinEncode = function (obj) {
if (obj.fileType < 1 && obj.fileType > AmtSetupBinSetupGuids.length) return null;
var out = [], r = AmtSetupBinSetupGuids[obj.fileType - 1], reccount = 0;
r += ShortToStrX(obj.recordChunkCount);
r += ShortToStrX(obj.recordHeaderByteCount);
r += IntToStrX(obj.recordNumber);
r += String.fromCharCode(obj.majorVersion, obj.minorVersion);
r += ShortToStrX(obj.flags); // Flags: 1 = Do not consume records
r += IntToStrX(obj.records.length);
r += IntToStrX(obj.dataRecordsConsumed);
r += ShortToStrX(obj.dataRecordChunkCount);
while (r.length < 512) { r += "\0"; } // Pad the header
out.push(r);
// Write each record
for (var i in obj.records) {
var r2 = "", rec = obj.records[i];
r2 += IntToStrX(rec.typeIdentifier);
r2 += IntToStrX(rec.flags);
r2 += IntToStrX(0); // Reserved
r2 += IntToStrX(0); // Reserved
r2 += ShortToStrX(1); // rec.chunkCount
r2 += ShortToStrX(24); // rec.headerByteCount
r2 += IntToStrX(++reccount);
// Sort the variables
rec.variables.sort(AmtSetupBinVariableCompare);
/*
// Change variable priority
AmtSetupBinMoveToTop(r.variables, 1, 3); // Manageability Feature Selection
AmtSetupBinMoveToTop(r.variables, 1, 2); // New MEBx password
AmtSetupBinMoveToTop(r.variables, 1, 1); // Current MEBx password
*/
// Write each variable
for (var j in rec.variables) {
var r3 = "", v = rec.variables[j], data = v.value;
v.type = AmtSetupBinVarIds[v.moduleid][v.varid][0]; // Set the correct type if not alreay connect
if (v.type > 0) { // If this is a numeric value, encode it correctly
data = parseInt(data);
if (v.type == 1) data = String.fromCharCode(data);
if (v.type == 2) data = ShortToStrX(data);
if (v.type == 3) data = IntToStrX(data);
}
r3 += ShortToStrX(v.moduleid); // Module Identifier
r3 += ShortToStrX(v.varid); // Variable Identifier
r3 += ShortToStrX(data.length); // Variable Length
r3 += ShortToStrX(0); // Reserved
r3 += data; // Variable Data
while (r3.length % 4 != 0) { r3 += "\0"; } // Pad the variable
r2 += r3;
}
while (r2.length < 512) { r2 += "\0"; } // Pad the record
if ((rec.flags & 2) != 0) { r2 = r2.substring(0, 24) + AmtSetupBinScrambleRecordData(r2.substring(24)); } // Scramble the record starting at byte 24, after the header
out.push(r2);
}
return out.join('');
}
// Used to sort variables
function AmtSetupBinVariableCompare(a, b) {
if (a.moduleid > b.moduleid) return 1;
if (a.moduleid < b.moduleid) return -1;
if (a.varid > b.varid) return 1;
if (a.varid < b.varid) return -1;
return 0;
}
// Scramble and un-scramble records
function AmtSetupBinScrambleRecordData(data) { var out = ""; for (var i = 0; i < data.length; i++) { out += String.fromCharCode((data.charCodeAt(i) + 17) & 0xFF); } return out; }
function AmtSetupBinDescrambleRecordData(data) { var out = ""; for (var i = 0; i < data.length; i++) { out += String.fromCharCode((data.charCodeAt(i) + 0xEF) & 0xFF); } return out; }
// Find a moduleid/varid in the variable list, if found, move it to the top
//function AmtSetupBinMoveToTop(variables, moduleid, varid) { var i = -1; for (var j in variables) { if ((variables[j].moduleid == moduleid) && (variables[j].varid == varid)) { i = j; } } if (i > 1) { ArrayElementMove(variables, i, 0); } }

View file

@ -0,0 +1,679 @@
/**
* @description Remote Terminal
* @author Ylian Saint-Hilaire
* @version v0.0.2c
*/
// Construct a MeshServer object
var CreateAmtRemoteTerminal = function (divid) {
var obj = {};
obj.DivId = divid;
obj.DivElement = document.getElementById(divid);
obj.protocol = 1; // SOL
// ###BEGIN###{Terminal-Enumation-All}
obj.terminalEmulation = 1;
// ###END###{Terminal-Enumation-All}
obj.fxEmulation = 0;
obj.width = 80; // 80 or 100
obj.height = 25; // 25 or 30
var _Terminal_CellHeight = 21;
var _Terminal_CellWidth = 13;
var _TermColors = ['000000', 'BB0000', '00BB00', 'BBBB00', '0000BB', 'BB00BB', '00BBBB', 'BBBBBB', '555555', 'FF5555', '55FF55', 'FFFF55', '5555FF', 'FF55FF', '55FFFF', 'FFFFFF'];
var _TermCurrentReverse = 0;
var _TermCurrentFColor = 7;
var _TermCurrentBColor = 0;
var _TermLineWrap = true;
var _termx = 0;
var _termy = 0;
var _termstate = 0;
var _escNumber = [];
var _escNumberPtr = 0;
var _scratt = [];
var _tscreen = [];
var _VTUNDERLINE = 1;
var _VTREVERSE = 2;
// ###BEGIN###{Terminal-Enumation-All}
var _utf8accumulator = 0;
var _utf8accumulatorCount = 0;
// ###END###{Terminal-Enumation-All}
// ###BEGIN###{Terminal-Enumation-UTF8}
var _utf8accumulator = 0;
var _utf8accumulatorCount = 0;
// ###END###{Terminal-Enumation-UTF8}
obj.Start = function () { }
obj.Init = function (width, height) {
obj.width = width ? width : 80;
obj.height = height ? height : 25;
for (var y = 0; y < obj.height; y++) {
_tscreen[y] = [];
_scratt[y] = [];
for (var x = 0; x < obj.width; x++) { _tscreen[y][x] = ' '; _scratt[y][x] = (7 << 6); }
}
obj.TermInit();
obj.TermDraw();
}
obj.xxStateChange = function(newstate) { }
obj.ProcessData = function (str) { if (obj.capture != null) obj.capture += str; _ProcessVt100EscString(str); obj.TermDraw(); }
function _ProcessVt100EscString(str) { for (var i = 0; i < str.length; i++) _ProcessVt100EscChar(String.fromCharCode(str.charCodeAt(i)), str.charCodeAt(i)); }
function _ProcessVt100EscChar(b, c) {
switch (_termstate) {
case 0: // Normal Term State
switch (c) {
case 27: // ESC
_termstate = 1;
break;
default:
// Process a single char
_ProcessVt100Char(b);
break;
}
break;
case 1:
switch (b) {
case '[':
_escNumberPtr = 0;
_escNumber = [];
_termstate = 2;
break;
case '(':
_termstate = 4;
break;
case ')':
_termstate = 5;
break;
default:
_termstate = 0;
break;
}
break;
case 2:
if (b >= '0' && b <= '9') {
// This is a number
if (!_escNumber[_escNumberPtr]) {
_escNumber[_escNumberPtr] = (b - '0');
}
else {
_escNumber[_escNumberPtr] = ((_escNumber[_escNumberPtr] * 10) + (b - '0'));
}
break;
}
else if (b == ';') {
// New number
_escNumberPtr++;
break;
}
else {
// Process Escape Sequence
if (!_escNumber[0]) _escNumber[0] = 0;
_ProcessEscapeHandler(b, _escNumber, _escNumberPtr + 1);
_termstate = 0;
}
break;
case 4: // '(' Code
_termstate = 0;
break;
case 5: // ')' Code
_termstate = 0;
break;
}
}
function _ProcessEscapeHandler(code, args, argslen) {
var i;
switch (code) {
case 'c': // ResetDevice
// Reset
obj.TermResetScreen();
break;
case 'A': // Move cursor up n lines
if (argslen == 1) {
_termy -= args[0];
if (_termy < 0) _termy = 0;
}
break;
case 'B': // Move cursor down n lines
if (argslen == 1) {
_termy += args[0];
if (_termy > obj.height) _termy = obj.height;
}
break;
case 'C': // Move cursor right n lines
if (argslen == 1) {
_termx += args[0];
if (_termx > obj.width) _termx = obj.width;
}
break;
case 'D': // Move cursor left n lines
if (argslen == 1) {
_termx -= args[0];
if (_termx < 0) _termx = 0;
}
break;
case 'd': // Set cursor to line n
if (argslen == 1) {
_termy = args[0] - 1;
if (_termy > obj.height) _termy = obj.height;
if (_termy < 0) _termy = 0;
}
break;
case 'G': // Set cursor to col n
if (argslen == 1) {
_termx = args[0] - 1;
if (_termx < 0) _termx = 0;
if (_termx > 79) _termx = 79;
}
break;
case 'J': // ClearScreen:
if (argslen == 1 && args[0] == 2) {
obj.TermClear((_TermCurrentBColor << 12) + (_TermCurrentFColor << 6)); // Erase entire screen
_termx = 0;
_termy = 0;
}
else if (argslen == 0 || argslen == 1 && args[0] == 0) // Erase cursor down
{
_EraseCursorToEol();
for (i = _termy + 1; i < obj.height; i++) _EraseLine(i);
}
else if (argslen == 1 && args[0] == 1) // Erase cursor up
{
_EraseCursorToEol();
for (i = 0; i < _termy - 1; i++) _EraseLine(i);
}
break;
case 'H': // MoveCursor:
if (argslen == 2) {
if (args[0] < 1) args[0] = 1;
if (args[1] < 1) args[1] = 1;
if (args[0] > obj.height) args[0] = obj.height;
if (args[1] > obj.width) args[1] = obj.width;
_termy = args[0] - 1;
_termx = args[1] - 1;
}
else {
_termy = 0;
_termx = 0;
}
break;
case 'm': // ScreenAttribs:
// Change attributes
for (i = 0; i < argslen; i++) {
if (!args[i] || args[i] == 0) {
// Reset Attributes
_TermCurrentBColor = 0;
_TermCurrentFColor = 7;
_TermCurrentReverse = 0;
}
else if (args[i] == 1) {
// Bright
if (_TermCurrentFColor < 8) _TermCurrentFColor += 8;
}
else if (args[i] == 2 || args[i] == 22) {
// Dim
if (_TermCurrentFColor >= 8) _TermCurrentFColor -= 8;
}
else if (args[i] == 7) {
// Set Reverse attribute true
_TermCurrentReverse = 2;
}
else if (args[i] == 27) {
// Set Reverse attribute false
_TermCurrentReverse = 0;
}
else if (args[i] >= 30 && args[i] <= 37) {
// Set Foreground Color
var bright = (_TermCurrentFColor >= 8);
_TermCurrentFColor = (args[i] - 30);
if (bright && _TermCurrentFColor <= 8) _TermCurrentFColor += 8;
}
else if (args[i] >= 40 && args[i] <= 47) {
// Set Background Color
_TermCurrentBColor = (args[i] - 40);
}
else if (args[i] >= 90 && args[i] <= 99) {
// Set Bright Foreground Color
_TermCurrentFColor = (args[i] - 82);
}
else if (args[i] >= 100 && args[i] <= 109) {
// Set Bright Background Color
_TermCurrentBColor = (args[i] - 92);
}
}
break;
case 'K': // EraseLine:
if (argslen == 0 || (argslen == 1 && (!args[0] || args[0] == 0))) {
_EraseCursorToEol(); // Erase from the cursor to the end of the line
}
else if (argslen == 1) {
if (args[0] == 1) // Erase from the beginning of the line to the cursor
{
_EraseBolToCursor();
}
else if (args[0] == 2) // Erase the line with the cursor
{
_EraseLine(_termy);
}
}
break;
case 'h': // EnableLineWrap:
_TermLineWrap = true;
break;
case 'l': // DisableLineWrap:
_TermLineWrap = false;
break;
default:
//if (code != '@') alert(code);
break;
}
}
obj.ProcessVt100String = function (str) {
for (var i = 0; i < str.length; i++) _ProcessVt100Char(String.fromCharCode(str.charCodeAt(i)));
}
// ###BEGIN###{Terminal-Enumation-All}
var AsciiToUnicode = [
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00da,
0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
0x2593, 0x2592, 0x2591, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
0x2568, 0x2564, 0x2565, 0x2568, 0x2558, 0x2552, 0x2553, 0x256b,
0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258b, 0x2590, 0x2580,
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
0x03c6, 0x03b8, 0x2126, 0x03b4, 0x221e, 0x00f8, 0x03b5, 0x220f,
0x2261, 0x00b1, 0x2265, 0x2266, 0x2320, 0x2321, 0x00f7, 0x2248,
0x00b0, 0x2022, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x220e, 0x00a0
];
var AsciiToUnicodeIntel = [
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00da,
0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ae, 0x00bb,
0x2593, 0x2592, 0x2591, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
0x2568, 0x2564, 0x2565, 0x2568, 0x2558, 0x2552, 0x2553, 0x256b,
0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258b, 0x2590, 0x2580,
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
0x03c6, 0x03b8, 0x2126, 0x03b4, 0x221e, 0x00f8, 0x03b5, 0x220f,
0x2261, 0x00b1, 0x2265, 0x2266, 0x2320, 0x2321, 0x00f7, 0x2248,
0x00b0, 0x2022, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x220e, 0x00a0
];
// ###END###{Terminal-Enumation-All}
// ###BEGIN###{Terminal-Enumation-ASCII}
var AsciiToUnicode = [
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00da,
0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
0x2593, 0x2592, 0x2591, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
0x2568, 0x2564, 0x2565, 0x2568, 0x2558, 0x2552, 0x2553, 0x256b,
0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258b, 0x2590, 0x2580,
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
0x03c6, 0x03b8, 0x2126, 0x03b4, 0x221e, 0x00f8, 0x03b5, 0x220f,
0x2261, 0x00b1, 0x2265, 0x2266, 0x2320, 0x2321, 0x00f7, 0x2248,
0x00b0, 0x2022, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x220e, 0x00a0
];
// ###END###{Terminal-Enumation-ASCII}
// ###BEGIN###{Terminal-Enumation-Intel}
var AsciiToUnicodeIntel = [
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00da,
0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ae, 0x00bb,
0x2593, 0x2592, 0x2591, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
0x2568, 0x2564, 0x2565, 0x2568, 0x2558, 0x2552, 0x2553, 0x256b,
0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258b, 0x2590, 0x2580,
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
0x03c6, 0x03b8, 0x2126, 0x03b4, 0x221e, 0x00f8, 0x03b5, 0x220f,
0x2261, 0x00b1, 0x2265, 0x2266, 0x2320, 0x2321, 0x00f7, 0x2248,
0x00b0, 0x2022, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x220e, 0x00a0
];
// ###END###{Terminal-Enumation-Intel}
function _ProcessVt100Char(c) {
if (c == '\0' || c.charCodeAt() == 7) return; // Ignore null & bell
var ch = c.charCodeAt();
// ###BEGIN###{Terminal-Enumation-All}
// UTF8 Terminal
if (obj.terminalEmulation == 0) {
// VT100 - UTF-8 emulation
var fallout = true;
if ((ch & 0x80) == 0) {
// Sub 127 char.
_utf8accumulator = ch;
_utf8accumulatorCount = 0;
fallout = false;
}
else if ((ch & 0xE0) == 0xC0) {
// 2 byte char
_utf8accumulator = (ch & 0x1F);
_utf8accumulatorCount = 1;
fallout = true;
}
else if ((ch & 0xF0) == 0xE0) {
// 3 byte char
_utf8accumulator = (ch & 0x0F);
_utf8accumulatorCount = 2;
fallout = true;
}
else if ((ch & 0xC0) == 0x80) {
if (_utf8accumulatorCount > 0) {
_utf8accumulator = (_utf8accumulator << 6);
_utf8accumulator += (ch & 0x3F);
_utf8accumulatorCount--;
fallout = (_utf8accumulatorCount != 0);
}
else {
_utf8accumulator = 0;
_utf8accumulatorCount = 0;
fallout = true;
}
}
if (fallout == true) return;
c = String.fromCharCode(_utf8accumulator);
} else if (obj.terminalEmulation == 1) {
// ANSI - Extended ASCII emulation.
if ((ch & 0x80) != 0) { c = String.fromCharCode(AsciiToUnicode[ch & 0x7F]); }
} else if (obj.terminalEmulation == 2) {
// ANSI - Intel Extended ASCII emulation.
if ((ch & 0x80) != 0) { c = String.fromCharCode(AsciiToUnicodeIntel[ch & 0x7F]); }
}
// ###END###{Terminal-Enumation-All}
// ###BEGIN###{Terminal-Enumation-UTF8}
// VT100 - UTF-8 emulation
var fallout = true;
if ((ch & 0x80) == 0) {
// Sub 127 char.
_utf8accumulator = ch;
_utf8accumulatorCount = 0;
fallout = false;
}
else if ((ch & 0xE0) == 0xC0) {
// 2 byte char
_utf8accumulator = (ch & 0x1F);
_utf8accumulatorCount = 1;
fallout = true;
}
else if ((ch & 0xF0) == 0xE0) {
// 3 byte char
_utf8accumulator = (ch & 0x0F);
_utf8accumulatorCount = 2;
fallout = true;
}
else if ((ch & 0xC0) == 0x80) {
if (_utf8accumulatorCount > 0) {
_utf8accumulator = (_utf8accumulator << 6);
_utf8accumulator += (ch & 0x3F);
_utf8accumulatorCount--;
fallout = (_utf8accumulatorCount != 0);
}
else {
_utf8accumulator = 0;
_utf8accumulatorCount = 0;
fallout = true;
}
}
if (fallout == true) return;
c = String.fromCharCode(_utf8accumulator);
// ###END###{Terminal-Enumation-UTF8}
// ###BEGIN###{Terminal-Enumation-ASCII}
// ANSI - Extended ASCII emulation.
if ((ch & 0x80) != 0) { c = String.fromCharCode(AsciiToUnicode[ch & 0x7F]); }
// ###END###{Terminal-Enumation-ASCII}
// ###BEGIN###{Terminal-Enumation-Intel}
// ANSI - Intel Extended ASCII emulation.
if ((ch & 0x80) != 0) { c = String.fromCharCode(AsciiToUnicodeIntel[ch & 0x7F]); }
// ###END###{Terminal-Enumation-Intel}
//if (ch < 32 && ch != 10 && ch != 13) alert(ch);
switch (ch) {
case 16: { c = ' '; break; } // This is an odd char that show up on Intel BIOS's.
case 24: { c = '↑'; break; }
case 25: { c = '↓'; break; }
}
if (_termx > obj.width) _termx = obj.width;
if (_termy > (obj.height - 1)) _termy = (obj.height - 1);
switch (c) {
case '\b': // Backspace
if (_termx > 0) {
_termx = _termx - 1;
_TermDrawChar(' ');
}
break;
case '\t': // tab
var tab = 8 - (_termx % 8)
for (var x = 0; x < tab; x++) _ProcessVt100Char(" ");
break;
case '\n': // Linefeed
_termy++;
if (_termy > (obj.height - 1)) {
// Move everything up one line
_TermMoveUp(1);
_termy = (obj.height - 1);
}
break;
case '\r': // Carriage Return
_termx = 0;
break;
default:
if (_termx >= obj.width) {
_termx = 0;
if (_TermLineWrap) { _termy++; }
if (_termy >= (obj.height - 1)) { _TermMoveUp(1); _termy = (obj.height - 1); }
}
_TermDrawChar(c);
_termx++;
break;
}
}
function _TermDrawChar(c) {
_tscreen[_termy][_termx] = c;
_scratt[_termy][_termx] = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse;
}
obj.TermClear = function(TermColor) {
for (var y = 0; y < obj.height; y++) {
for (var x = 0; x < obj.width; x++) {
_tscreen[y][x] = ' ';
_scratt[y][x] = TermColor;
}
}
}
obj.TermResetScreen = function () {
_TermCurrentReverse = 0;
_TermCurrentFColor = 7;
_TermCurrentBColor = 0;
_TermLineWrap = true;
_termx = 0;
_termy = 0;
obj.TermClear(7 << 6);
}
function _EraseCursorToEol() {
var t = (_TermCurrentBColor << 12);
for (var x = _termx; x < obj.width; x++) {
_tscreen[_termy][x] = ' ';
_scratt[_termy][x] = t;
}
}
function _EraseBolToCursor() {
var t = (_TermCurrentBColor << 12);
for (var x = 0; x < _termx; x++) {
_tscreen[_termy][x] = ' ';
_scratt[_termy][x] = t;
}
}
function _EraseLine(line) {
var t = (_TermCurrentBColor << 12);
for (var x = 0; x < obj.width; x++) {
_tscreen[line][x] = ' ';
_scratt[line][x] = t;
}
}
obj.TermSendKeys = function(keys) { obj.parent.Send(keys); }
obj.TermSendKey = function(key) { obj.parent.Send(String.fromCharCode(key)); }
function _TermMoveUp(linecount) {
var x, y;
for (y = 0; y < obj.height - linecount; y++) {
_tscreen[y] = _tscreen[y + linecount];
_scratt[y] = _scratt[y + linecount];
}
for (y = obj.height - linecount; y < obj.height; y++) {
_tscreen[y] = [];
_scratt[y] = [];
for (x = 0; x < obj.width; x++) {
_tscreen[y][x] = ' ';
_scratt[y][x] = (7 << 6);
}
}
}
obj.TermHandleKeys = function (e) {
if (!e.ctrlKey) {
if (e.which == 127) obj.TermSendKey(8);
else if (e.which == 13) obj.TermSendKeys("\r\n");
else if (e.which != 0) obj.TermSendKey(e.which);
return false;
}
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
}
obj.TermHandleKeyUp = function (e) {
if ((e.which != 8) && (e.which != 32) && (e.which != 9)) return true;
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
return false;
}
obj.TermHandleKeyDown = function (e) {
if ((e.which >= 65) && (e.which <= 90) && (e.ctrlKey == true)) {
obj.TermSendKey(e.which - 64);
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
return;
}
if (e.which == 27) { obj.TermSendKeys(String.fromCharCode(27)); return true; }; // ESC
if (e.which == 37) { obj.TermSendKeys(String.fromCharCode(27, 91, 68)); return true; }; // Left
if (e.which == 38) { obj.TermSendKeys(String.fromCharCode(27, 91, 65)); return true; }; // Up
if (e.which == 39) { obj.TermSendKeys(String.fromCharCode(27, 91, 67)); return true; }; // Right
if (e.which == 40) { obj.TermSendKeys(String.fromCharCode(27, 91, 66)); return true; }; // Down
if (e.which == 9) { obj.TermSendKeys("\t"); if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return true; }; // TAB
// F1 to F12 keys
// ###BEGIN###{Terminal-FxEnumation-All}
var fx0 = [80, 81, 119, 120, 116, 117, 113, 114, 112, 77];
var fx1 = [49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 33, 64];
var fx2 = [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91];
if (e.which > 111 & e.which < 124 && e.repeat == false) { // F1 to F12 keys
if (obj.fxEmulation == 0 && e.which < 122) { obj.TermSendKeys(String.fromCharCode(27, 91, 79, fx0[e.which - 112])); return true; } // 'Intel (F10 = ESC+[OM)'
if (obj.fxEmulation == 1) { obj.TermSendKeys(String.fromCharCode(27, fx1[e.which - 112])); return true; } // 'Alternate (F10 = ESC+0)'
if (obj.fxEmulation == 2) { obj.TermSendKeys(String.fromCharCode(27, 79, fx2[e.which - 112])); return true; } // 'VT100+ (F10 = ESC+[OY)'
}
// ###END###{Terminal-FxEnumation-All}
// ###BEGIN###{Terminal-FxEnumation-Intel}
var fx0 = [80, 81, 119, 120, 116, 117, 113, 114, 112, 77];
if (e.which > 111 & e.which < 122 && e.repeat == false) { obj.TermSendKeys(String.fromCharCode(27, 91, 79, fx0[e.which - 112])); return true; } // 'Intel (F10 = ESC+[OM)'
// ###END###{Terminal-FxEnumation-Intel}
// ###BEGIN###{Terminal-FxEnumation-Alternate}
var fx1 = [49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 33, 64];
if (e.which > 111 & e.which < 124 && e.repeat == false) { obj.TermSendKeys(String.fromCharCode(27, fx1[e.which - 112])); return true; } // 'Alternate (F10 = ESC+0)'
// ###END###{Terminal-FxEnumation-Alternate}
// ###BEGIN###{Terminal-FxEnumation-VT100Plus}
var fx2 = [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91];
if (e.which > 111 & e.which < 124 && e.repeat == false) { obj.TermSendKeys(String.fromCharCode(27, 79, fx2[e.which - 112])); return true; } // 'VT100+ (F10 = ESC+[OY)'
// ###END###{Terminal-FxEnumation-VT100Plus}
if (e.which != 8 && e.which != 32 && e.which != 9) return true;
obj.TermSendKey(e.which);
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
return false;
}
obj.TermDraw = function() {
var c, buf = '', closetag = '', newat, oldat = 1, x1, x2;
for (var y = 0; y < obj.height; ++y) {
for (var x = 0; x < obj.width; ++x) {
newat = _scratt[y][x];
if (_termx == x && _termy == y) { newat |= _VTREVERSE; } // If this is the cursor location, reverse the color.
if (newat != oldat) {
buf += closetag;
closetag = '';
x1 = 6; x2 = 12;
if (newat & _VTREVERSE) { x1 = 12; x2 = 6;}
buf += '<span style="color:#' + _TermColors[(newat >> x1) & 0x3F] + ';background-color:#' + _TermColors[(newat >> x2) & 0x3F];
if (newat & _VTUNDERLINE) buf += ';text-decoration:underline';
buf += ';">';
closetag = "</span>" + closetag;
oldat = newat;
}
c = _tscreen[y][x];
switch (c) {
case '&':
buf += '&amp;'; break;
case '<':
buf += '&lt;'; break;
case '>':
buf += '&gt;'; break;
case ' ':
buf += '&nbsp;'; break;
default:
buf += c;
break;
}
}
if (y != (obj.height - 1)) buf += '<br>';
}
obj.DivElement.innerHTML = "<font size='4'><b>" + buf + closetag + "</b></font>";
}
obj.TermInit = function () { obj.TermResetScreen(); }
obj.Init();
return obj;
}

View file

@ -0,0 +1,251 @@
/**
* @description Intel(r) AMT WSMAN Stack
* @author Ylian Saint-Hilaire
* @version v0.2.0
*/
// Construct a MeshServer object
var WsmanStackCreateService = function (host, port, user, pass, tls, extra) {
var obj = {};
//obj.onDebugMessage = null; // Set to a function if you want to get debug messages.
obj.NextMessageId = 1; // Next message number, used to label WSMAN calls.
obj.Address = '/wsman';
obj.comm = CreateWsmanComm(host, port, user, pass, tls, extra);
obj.PerformAjax = function (postdata, callback, tag, pri, namespaces) {
if (namespaces == undefined) namespaces = '';
obj.comm.PerformAjax('<?xml version=\"1.0\" encoding=\"utf-8\"?><Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns=\"http://www.w3.org/2003/05/soap-envelope\" ' + namespaces + '><Header><a:Action>' + postdata, function (data, status, tag) {
if (status != 200) { callback(obj, null, { Header: { HttpError: status } }, status, tag); return; }
var wsresponse = obj.ParseWsman(data);
if (!wsresponse || wsresponse == null) { callback(obj, null, { Header: { HttpError: status } }, 601, tag); } else { callback(obj, wsresponse.Header["ResourceURI"], wsresponse, 200, tag); }
}, tag, pri);
}
// Private method
//obj.Debug = function (msg) { /*console.log(msg);*/ }
// Cancel all pending queries with given status
obj.CancelAllQueries = function (s) { obj.comm.CancelAllQueries(s); }
// Get the last element of a URI string
obj.GetNameFromUrl = function (resuri) {
var x = resuri.lastIndexOf("/");
return (x == -1)?resuri:resuri.substring(x + 1);
}
// Perform a WSMAN Subscribe operation
obj.ExecSubscribe = function (resuri, delivery, url, callback, tag, pri, selectors, opaque, user, pass) {
var digest = "", digest2 = "";
if (user != undefined && pass != undefined) { digest = '<t:IssuedTokens><t:RequestSecurityTokenResponse><t:TokenType>http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken</t:TokenType><t:RequestedSecurityToken><se:UsernameToken><se:Username>' + user + '</se:Username><se:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd#PasswordText">' + pass + '</se:Password></se:UsernameToken></t:RequestedSecurityToken></t:RequestSecurityTokenResponse></t:IssuedTokens>'; digest2 = '<Auth Profile="http://schemas.xmlsoap.org/ws/2004/08/eventing/DeliveryModes/secprofile/http/digest"/>'; }
if (opaque != undefined && opaque != null) { opaque = '<a:ReferenceParameters>' + opaque + '</a:ReferenceParameters>'; } else { opaque = ""; }
var data = "http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo>" + _PutObjToSelectorsXml(selectors) + digest + '</Header><Body><e:Subscribe><e:Delivery Mode="http://schemas.dmtf.org/wbem/wsman/1/wsman/' + delivery + '"><e:NotifyTo><a:Address>' + url + '</a:Address></e:NotifyTo>' + digest2 + '</e:Delivery><e:Expires>PT0.000000S</e:Expires></e:Subscribe>';
obj.PerformAjax(data + "</Body></Envelope>", callback, tag, pri, 'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:se="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:m="http://x.com"');
}
// Perform a WSMAN UnSubscribe operation
obj.ExecUnSubscribe = function (resuri, callback, tag, pri, selectors) {
var data = "http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo>" + _PutObjToSelectorsXml(selectors) + '</Header><Body><e:Unsubscribe/>';
obj.PerformAjax(data + "</Body></Envelope>", callback, tag, pri, 'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing"');
}
// Perform a WSMAN PUT operation
obj.ExecPut = function (resuri, putobj, callback, tag, pri, selectors) {
var data = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Put</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60.000S</w:OperationTimeout>" + _PutObjToSelectorsXml(selectors) + '</Header><Body>' + _PutObjToBodyXml(resuri, putobj);
obj.PerformAjax(data + "</Body></Envelope>", callback, tag, pri);
}
// Perform a WSMAN CREATE operation
obj.ExecCreate = function (resuri, putobj, callback, tag, pri, selectors) {
var objname = obj.GetNameFromUrl(resuri);
var data = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Create</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout>" + _PutObjToSelectorsXml(selectors) + "</Header><Body><g:" + objname + " xmlns:g=\"" + resuri + "\">";
for (var n in putobj) { data += "<g:" + n + ">" + putobj[n] + "</g:" + n + ">" }
obj.PerformAjax(data + "</g:" + objname + "></Body></Envelope>", callback, tag, pri);
}
// Perform a WSMAN CREATE operation
obj.ExecCreateXml = function (resuri, argsxml, callback, tag, pri) {
var objname = obj.GetNameFromUrl(resuri), selector = "";
obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Create</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60.000S</w:OperationTimeout></Header><Body><r:" + objname + " xmlns:r=\"" + resuri + "\">" + argsxml + "</r:" + objname + "></Body></Envelope>", callback, tag, pri);
}
// Perform a WSMAN DELETE operation
obj.ExecDelete = function (resuri, putobj, callback, tag, pri) {
var data = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout>" + _PutObjToSelectorsXml(putobj) + "</Header><Body /></Envelope>";
obj.PerformAjax(data, callback, tag, pri);
}
// Perform a WSMAN GET operation
obj.ExecGet = function (resuri, callback, tag, pri) {
obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout></Header><Body /></Envelope>", callback, tag, pri);
}
// Perform a WSMAN method call operation
obj.ExecMethod = function (resuri, method, args, callback, tag, pri, selectors) {
var argsxml = "";
for (var i in args) { if (args[i] != null) { if (Array.isArray(args[i])) { for (var x in args[i]) { argsxml += "<r:" + i + ">" + args[i][x] + "</r:" + i + ">"; } } else { argsxml += "<r:" + i + ">" + args[i] + "</r:" + i + ">"; } } }
obj.ExecMethodXml(resuri, method, argsxml, callback, tag, pri, selectors);
}
// Perform a WSMAN method call operation. The arguments are already formatted in XML.
obj.ExecMethodXml = function (resuri, method, argsxml, callback, tag, pri, selectors) {
obj.PerformAjax(resuri + "/" + method + "</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout>" + _PutObjToSelectorsXml(selectors) + "</Header><Body><r:" + method + '_INPUT' + " xmlns:r=\"" + resuri + "\">" + argsxml + "</r:" + method + "_INPUT></Body></Envelope>", callback, tag, pri);
}
// Perform a WSMAN ENUM operation
obj.ExecEnum = function (resuri, callback, tag, pri) {
obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout></Header><Body><Enumerate xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" /></Body></Envelope>", callback, tag, pri);
}
// Perform a WSMAN PULL operation
obj.ExecPull = function (resuri, enumctx, callback, tag, pri) {
obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout></Header><Body><Pull xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\"><EnumerationContext>" + enumctx + "</EnumerationContext><MaxElements>999</MaxElements><MaxCharacters>99999</MaxCharacters></Pull></Body></Envelope>", callback, tag, pri);
}
// Private method
obj.ParseWsman = function (xml) {
try {
if (!xml.childNodes) xml = _turnToXml(xml);
var r = { Header:{} }, header = xml.getElementsByTagName("Header")[0], t;
if (!header) header = xml.getElementsByTagName("a:Header")[0];
if (!header) return null;
for (var i = 0; i < header.childNodes.length; i++) {
var child = header.childNodes[i];
r.Header[child.localName] = child.textContent;
}
var body = xml.getElementsByTagName("Body")[0];
if (!body) body = xml.getElementsByTagName("a:Body")[0];
if (!body) return null;
if (body.childNodes.length > 0) {
t = body.childNodes[0].localName;
if (t.indexOf("_OUTPUT") == t.length - 7) { t = t.substring(0, t.length - 7); }
r.Header['Method'] = t;
r.Body = _ParseWsmanRec(body.childNodes[0]);
}
return r;
} catch (e) {
console.log("Unable to parse XML: " + xml);
return null;
}
}
// Private method
function _ParseWsmanRec(node) {
var data, r = {};
for (var i = 0; i < node.childNodes.length; i++) {
var child = node.childNodes[i];
if (child.childElementCount == 0) { data = child.textContent; } else { data = _ParseWsmanRec(child); }
if (data == 'true') data = true; // Convert 'true' into true
if (data == 'false') data = false; // Convert 'false' into false
var childObj = data;
if (child.attributes.length > 0) {
childObj = {'Value': data };
for(var j = 0; j < child.attributes.length; j++) {
childObj['@' + child.attributes[j].name] = child.attributes[j].value;
}
}
if (r[child.localName] instanceof Array) { r[child.localName].push(childObj); }
else if (r[child.localName] == undefined) { r[child.localName] = childObj; }
else { r[child.localName] = [r[child.localName], childObj]; }
}
return r;
}
function _PutObjToBodyXml(resuri, putObj) {
if(!resuri || putObj === undefined || putObj === null) return '';
var objname = obj.GetNameFromUrl(resuri);
var result = '<r:' + objname + ' xmlns:r="' + resuri + '">';
for (var prop in putObj) {
if (!putObj.hasOwnProperty(prop) || prop.indexOf('__') === 0 || prop.indexOf('@') === 0) continue;
if (putObj[prop] === undefined || putObj[prop] === null || typeof putObj[prop] === 'function') continue;
if (typeof putObj[prop] === 'object' && putObj[prop]['ReferenceParameters']) {
result += '<r:' + prop + '><a:Address>' + putObj[prop].Address + '</a:Address><a:ReferenceParameters><w:ResourceURI>' + putObj[prop]['ReferenceParameters']["ResourceURI"] + '</w:ResourceURI><w:SelectorSet>';
var selectorArray = putObj[prop]['ReferenceParameters']['SelectorSet']['Selector'];
if (Array.isArray(selectorArray)) {
for (var i=0; i< selectorArray.length; i++) {
result += '<w:Selector' + _ObjectToXmlAttributes(selectorArray[i]) + '>' + selectorArray[i]['Value'] + '</w:Selector>';
}
}
else {
result += '<w:Selector' + _ObjectToXmlAttributes(selectorArray) + '>' + selectorArray['Value'] + '</w:Selector>';
}
result += '</w:SelectorSet></a:ReferenceParameters></r:' + prop + '>';
}
else {
if (Array.isArray(putObj[prop])) {
for (var i = 0; i < putObj[prop].length; i++) {
result += '<r:' + prop + '>' + putObj[prop][i].toString() + '</r:' + prop + '>';
}
} else {
result += '<r:' + prop + '>' + putObj[prop].toString() + '</r:' + prop + '>';
}
}
}
result += '</r:' + objname + '>';
return result;
}
/*
convert
{ @Name: 'InstanceID', @AttrName: 'Attribute Value'}
into
' Name="InstanceID" AttrName="Attribute Value" '
*/
function _ObjectToXmlAttributes(objWithAttributes) {
if(!objWithAttributes) return '';
var result = ' ';
for (var propName in objWithAttributes) {
if (!objWithAttributes.hasOwnProperty(propName) || propName.indexOf('@') !== 0) continue;
result += propName.substring(1) + '="' + objWithAttributes[propName] + '" ';
}
return result;
}
function _PutObjToSelectorsXml(selectorSet) {
if (!selectorSet) return '';
if (typeof selectorSet == 'string') return selectorSet;
if (selectorSet['InstanceID']) return "<w:SelectorSet><w:Selector Name=\"InstanceID\">" + selectorSet['InstanceID'] + "</w:Selector></w:SelectorSet>";
var result = '<w:SelectorSet>';
for(var propName in selectorSet) {
if (!selectorSet.hasOwnProperty(propName)) continue;
result += '<w:Selector Name="' + propName + '">';
if (selectorSet[propName]['ReferenceParameters']) {
result += '<a:EndpointReference>';
result += '<a:Address>' + selectorSet[propName]['Address'] + '</a:Address><a:ReferenceParameters><w:ResourceURI>' + selectorSet[propName]['ReferenceParameters']['ResourceURI'] + '</w:ResourceURI><w:SelectorSet>';
var selectorArray = selectorSet[propName]['ReferenceParameters']['SelectorSet']['Selector'];
if (Array.isArray(selectorArray)) {
for (var i = 0; i < selectorArray.length; i++) {
result += '<w:Selector' + _ObjectToXmlAttributes(selectorArray[i]) + '>' + selectorArray[i]['Value'] + '</w:Selector>';
}
}
else {
result += '<w:Selector' + _ObjectToXmlAttributes(selectorArray) + '>' + selectorArray['Value'] + '</w:Selector>';
}
result += '</w:SelectorSet></a:ReferenceParameters></a:EndpointReference>';
} else {
result += selectorSet[propName];
}
result += '</w:Selector>';
}
result += '</w:SelectorSet>';
return result;
}
function _turnToXml(text) {
if (window.DOMParser) {
return new DOMParser().parseFromString(text, "text/xml");
}
else // Internet Explorer
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(text);
return xmlDoc;
}
}
return obj;
}

View file

@ -0,0 +1,287 @@
/**
* @description WSMAN communication using websocket
* @author Ylian Saint-Hilaire
* @version v0.2.0c
*/
// Construct a WSMAN communication object
var CreateWsmanComm = function (host, port, user, pass, tls) {
var obj = {};
obj.PendingAjax = []; // List of pending AJAX calls. When one frees up, another will start.
obj.ActiveAjaxCount = 0; // Number of currently active AJAX calls
obj.MaxActiveAjaxCount = 1; // Maximum number of activate AJAX calls at the same time.
obj.FailAllError = 0; // Set this to non-zero to fail all AJAX calls with that error status, 999 causes responses to be silent.
obj.challengeParams = null;
obj.noncecounter = 1;
obj.authcounter = 0;
obj.socket = null;
obj.socketState = 0;
obj.host = host;
obj.port = port;
obj.user = user;
obj.pass = pass;
obj.tls = tls;
obj.cnonce = Math.random().toString(36).substring(7); // Generate a random client nonce
// Private method
//obj.Debug = function (msg) { console.log(msg); }
// Private method
// pri = priority, if set to 1, the call is high priority and put on top of the stack.
obj.PerformAjax = function (postdata, callback, tag, pri, url, action) {
if (obj.ActiveAjaxCount < obj.MaxActiveAjaxCount && obj.PendingAjax.length == 0) {
// There are no pending AJAX calls, perform the call now.
obj.PerformAjaxEx(postdata, callback, tag, url, action);
} else {
// If this is a high priority call, put this call in front of the array, otherwise put it in the back.
if (pri == 1) { obj.PendingAjax.unshift([postdata, callback, tag, url, action]); } else { obj.PendingAjax.push([postdata, callback, tag, url, action]); }
}
}
// Private method
obj.PerformNextAjax = function () {
if (obj.ActiveAjaxCount >= obj.MaxActiveAjaxCount || obj.PendingAjax.length == 0) return;
var x = obj.PendingAjax.shift();
obj.PerformAjaxEx(x[0], x[1], x[2], x[3], x[4]);
obj.PerformNextAjax();
}
// Private method
obj.PerformAjaxEx = function (postdata, callback, tag, url, action) {
if (obj.FailAllError != 0) { obj.gotNextMessagesError({ status: obj.FailAllError }, 'error', null, [postdata, callback, tag, url, action]); return; }
if (!postdata) postdata = "";
//console.log("SEND: " + postdata); // DEBUG
// We are in a websocket relay environment
obj.ActiveAjaxCount++;
return obj.PerformAjaxExNodeJS(postdata, callback, tag, url, action);
}
// Websocket relay specific private method
obj.pendingAjaxCall = [];
// Websocket relay specific private method
obj.PerformAjaxExNodeJS = function (postdata, callback, tag, url, action) { obj.PerformAjaxExNodeJS2(postdata, callback, tag, url, action, 3); }
// Websocket relay specific private method
obj.PerformAjaxExNodeJS2 = function (postdata, callback, tag, url, action, retry) {
if (retry <= 0 || obj.FailAllError != 0) {
// Too many retry, fail here.
obj.ActiveAjaxCount--;
if (obj.FailAllError != 999) obj.gotNextMessages(null, 'error', { status: ((obj.FailAllError == 0) ? 408 : obj.FailAllError) }, [postdata, callback, tag, url, action]); // 408 is timeout error
obj.PerformNextAjax();
return;
}
obj.pendingAjaxCall.push([postdata, callback, tag, url, action, retry]);
if (obj.socketState == 0) { obj.xxConnectHttpSocket(); }
else if (obj.socketState == 2) { obj.sendRequest(postdata, url, action); }
}
// Websocket relay specific private method (Content Length Encoding)
obj.sendRequest = function (postdata, url, action) {
url = url ? url : "/wsman";
action = action ? action : "POST";
var h = action + " " + url + " HTTP/1.1\r\n";
if (obj.challengeParams != null) {
var response = hex_md5(hex_md5(obj.user + ':' + obj.challengeParams["realm"] + ':' + obj.pass) + ':' + obj.challengeParams["nonce"] + ':' + obj.noncecounter + ':' + obj.cnonce + ':' + obj.challengeParams["qop"] + ':' + hex_md5(action + ':' + url));
h += 'Authorization: ' + obj.renderDigest({ "username": obj.user, "realm": obj.challengeParams["realm"], "nonce": obj.challengeParams["nonce"], "uri": url, "qop": obj.challengeParams["qop"], "response": response, "nc": obj.noncecounter++, "cnonce": obj.cnonce }) + '\r\n';
}
//h += 'Host: ' + obj.host + ':' + obj.port + '\r\nContent-Length: ' + postdata.length + '\r\n\r\n' + postdata; // Use Content-Length
h += 'Host: ' + obj.host + ':' + obj.port + '\r\nTransfer-Encoding: chunked\r\n\r\n' + postdata.length.toString(16).toUpperCase() + '\r\n' + postdata + '\r\n0\r\n\r\n'; // Use Chunked-Encoding
_Send(h);
//obj.Debug("SEND: " + h); // Display send packet
}
// Websocket relay specific private method
obj.parseDigest = function (header) {
var t = header.substring(7).split(',');
for (i in t) t[i] = t[i].trim();
return t.reduce(function (obj, s) { var parts = s.split('='); obj[parts[0]] = parts[1].replace(/"/g, ''); return obj; }, {})
}
// Websocket relay specific private method
obj.renderDigest = function (params) {
var paramsnames = [];
for (i in params) { paramsnames.push(i); }
return 'Digest ' + paramsnames.reduce(function (s1, ii) { return s1 + ',' + ii + '="' + params[ii] + '"' }, '').substring(1);
}
// Websocket relay specific private method
obj.xxConnectHttpSocket = function () {
//obj.Debug("xxConnectHttpSocket");
obj.socketParseState = 0;
obj.socketAccumulator = '';
obj.socketHeader = null;
obj.socketData = '';
obj.socketState = 1;
obj.socket = new WebSocket(window.location.protocol.replace("http", "ws") + "//" + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/webrelay.ashx?p=1&host=" + obj.host + "&port=" + obj.port + "&tls=" + obj.tls + ((user == '*') ? "&serverauth=1" : "") + ((typeof pass === "undefined") ? ("&serverauth=1&user=" + user) : "")); // The "p=1" indicates to the relay that this is a WSMAN session
obj.socket.onopen = _OnSocketConnected;
obj.socket.onmessage = _OnMessage;
obj.socket.onclose = _OnSocketClosed;
}
// Websocket relay specific private method
function _OnSocketConnected() {
//obj.Debug("xxOnSocketConnected");
obj.socketState = 2;
for (i in obj.pendingAjaxCall) { obj.sendRequest(obj.pendingAjaxCall[i][0], obj.pendingAjaxCall[i][3], obj.pendingAjaxCall[i][4]); }
}
function _OnMessage(e) {
if (typeof e.data == 'object') {
var f = new FileReader();
if (f.readAsBinaryString) {
// Chrome & Firefox (Draft)
f.onload = function (e) { _OnSocketData(e.target.result); }
f.readAsBinaryString(new Blob([e.data]));
} else if (f.readAsArrayBuffer) {
// Chrome & Firefox (Spec)
f.onloadend = function (e) { _OnSocketData(e.target.result); }
f.readAsArrayBuffer(e.data);
} else {
// IE10, readAsBinaryString does not exist, use an alternative.
var binary = "";
var bytes = new Uint8Array(e.data);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
_OnSocketData(binary);
}
} else if (typeof e.data == 'string') {
// We got a string object
_OnSocketData(e.data);
}
};
// Websocket relay specific private method
function _OnSocketData(data) {
//obj.Debug("_OnSocketData (" + data.length + "): " + data);
if (typeof data === 'object') {
// This is an ArrayBuffer, convert it to a string array (used in IE)
var binary = "", bytes = new Uint8Array(data), length = bytes.byteLength;
for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
data = binary;
}
else if (typeof data !== 'string') return;
//console.log("RECV: " + data); // DEBUG
obj.socketAccumulator += data;
while (true) {
if (obj.socketParseState == 0) {
var headersize = obj.socketAccumulator.indexOf("\r\n\r\n");
if (headersize < 0) return;
//obj.Debug(obj.socketAccumulator.substring(0, headersize)); // Display received HTTP header
obj.socketHeader = obj.socketAccumulator.substring(0, headersize).split("\r\n");
obj.socketAccumulator = obj.socketAccumulator.substring(headersize + 4);
obj.socketParseState = 1;
obj.socketData = '';
obj.socketXHeader = { Directive: obj.socketHeader[0].split(' ') };
for (i in obj.socketHeader) {
if (i != 0) {
var x2 = obj.socketHeader[i].indexOf(':');
obj.socketXHeader[obj.socketHeader[i].substring(0, x2).toLowerCase()] = obj.socketHeader[i].substring(x2 + 2);
}
}
}
if (obj.socketParseState == 1) {
var csize = -1;
if ((obj.socketXHeader["connection"] != undefined) && (obj.socketXHeader["connection"].toLowerCase() == 'close') && ((obj.socketXHeader["transfer-encoding"] == undefined) || (obj.socketXHeader["transfer-encoding"].toLowerCase() != 'chunked'))) {
// The body ends with a close, in this case, we will only process the header
csize = 0;
} else if (obj.socketXHeader["content-length"] != undefined) {
// The body length is specified by the content-length
csize = parseInt(obj.socketXHeader["content-length"]);
if (obj.socketAccumulator.length < csize) return;
var data = obj.socketAccumulator.substring(0, csize);
obj.socketAccumulator = obj.socketAccumulator.substring(csize);
obj.socketData = data;
csize = 0;
} else {
// The body is chunked
var clen = obj.socketAccumulator.indexOf("\r\n");
if (clen < 0) return; // Chunk length not found, exit now and get more data.
// Chunk length if found, lets see if we can get the data.
csize = parseInt(obj.socketAccumulator.substring(0, clen), 16);
if (isNaN(csize)) { if (obj.websocket) { obj.websocket.close(); } return; } // Critical error, close the socket and exit.
if (obj.socketAccumulator.length < clen + 2 + csize + 2) return;
// We got a chunk with all of the data, handle the chunck now.
var data = obj.socketAccumulator.substring(clen + 2, clen + 2 + csize);
obj.socketAccumulator = obj.socketAccumulator.substring(clen + 2 + csize + 2);
obj.socketData += data;
}
if (csize == 0) {
//obj.Debug("_OnSocketData DONE: (" + obj.socketData.length + "): " + obj.socketData);
_ProcessHttpResponse(obj.socketXHeader, obj.socketData);
obj.socketParseState = 0;
obj.socketHeader = null;
}
}
}
}
// Websocket relay specific private method
function _ProcessHttpResponse(header, data) {
//obj.Debug("_ProcessHttpResponse: " + header.Directive[1]);
var s = parseInt(header.Directive[1]);
if (isNaN(s)) s = 602;
if (s == 401 && ++(obj.authcounter) < 3) {
obj.challengeParams = obj.parseDigest(header['www-authenticate']); // Set the digest parameters, after this, the socket will close and we will auto-retry
} else {
var r = obj.pendingAjaxCall.shift();
// if (s != 200) { obj.Debug("Error, status=" + s + "\r\n\r\nreq=" + r[0] + "\r\n\r\nresp=" + data); } // Debug: Display the request & response if something did not work.
obj.authcounter = 0;
obj.ActiveAjaxCount--;
obj.gotNextMessages(data, 'success', { status: s }, r);
obj.PerformNextAjax();
}
}
// Websocket relay specific private method
function _OnSocketClosed(data) {
//obj.Debug("_OnSocketClosed");
obj.socketState = 0;
if (obj.socket != null) { obj.socket.close(); obj.socket = null; }
if (obj.pendingAjaxCall.length > 0) {
var r = obj.pendingAjaxCall.shift();
var retry = r[5];
obj.PerformAjaxExNodeJS2(r[0], r[1], r[2], r[3], r[4], --retry);
}
}
// Websocket relay specific private method
function _Send(x) {
//console.log("SEND: " + x); // DEBUG
if (obj.socketState == 2 && obj.socket != null && obj.socket.readyState == WebSocket.OPEN) {
var b = new Uint8Array(x.length);
for (var i = 0; i < x.length; ++i) { b[i] = x.charCodeAt(i); }
try { obj.socket.send(b.buffer); } catch (e) { }
}
}
// Private method
obj.gotNextMessages = function (data, status, request, callArgs) {
if (obj.FailAllError == 999) return;
if (obj.FailAllError != 0) { callArgs[1](null, obj.FailAllError, callArgs[2]); return; }
if (request.status != 200) { callArgs[1](null, request.status, callArgs[2]); return; }
callArgs[1](data, 200, callArgs[2]);
}
// Private method
obj.gotNextMessagesError = function (request, status, errorThrown, callArgs) {
if (obj.FailAllError == 999) return;
if (obj.FailAllError != 0) { callArgs[1](null, obj.FailAllError, callArgs[2]); return; }
callArgs[1](obj, null, { Header: { HttpError: request.status } }, request.status, callArgs[2]);
}
// Cancel all pending queries with given status
obj.CancelAllQueries = function (s) {
while (obj.PendingAjax.length > 0) { var x = obj.PendingAjax.shift(); x[1](null, s, x[2]); }
if (obj.websocket != null) { obj.websocket.close(); obj.websocket = null; obj.socketState = 0; }
}
return obj;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,104 @@
/**
* @description Set of short commonly used methods for handling HTML elements
* @author Ylian Saint-Hilaire
* @version v0.0.1b
*/
// Add startsWith for IE browser
if (!String.prototype.startsWith) { String.prototype.startsWith = function (str) { return this.lastIndexOf(str, 0) === 0; }; }
if (!String.prototype.endsWith) { String.prototype.endsWith = function (str) { return this.indexOf(str, this.length - str.length) !== -1; }; }
// Quick UI functions, a bit of a replacement for jQuery
//function Q(x) { if (document.getElementById(x) == null) { console.log('Invalid element: ' + x); } return document.getElementById(x); } // "Q"
function Q(x) { return document.getElementById(x); } // "Q"
function QS(x) { try { return Q(x).style; } catch (x) { } } // "Q" style
function QE(x, y) { try { Q(x).disabled = !y; } catch (x) { } } // "Q" enable
function QV(x, y) { try { QS(x).display = (y ? '' : 'none'); } catch (x) { } } // "Q" visible
function QA(x, y) { Q(x).innerHTML += y; } // "Q" append
function QH(x, y) { Q(x).innerHTML = y; } // "Q" html
// Move cursor to end of input box
function inputBoxFocus(x) { Q(x).focus(); var v = Q(x).value; Q(x).value = ''; Q(x).value = v; }
// Binary encoding and decoding functions
function ReadShort(v, p) { return (v.charCodeAt(p) << 8) + v.charCodeAt(p + 1); }
function ReadShortX(v, p) { return (v.charCodeAt(p + 1) << 8) + v.charCodeAt(p); }
function ReadInt(v, p) { return (v.charCodeAt(p) * 0x1000000) + (v.charCodeAt(p + 1) << 16) + (v.charCodeAt(p + 2) << 8) + v.charCodeAt(p + 3); } // We use "*0x1000000" instead of "<<24" because the shift converts the number to signed int32.
function ReadSInt(v, p) { return (v.charCodeAt(p) << 24) + (v.charCodeAt(p + 1) << 16) + (v.charCodeAt(p + 2) << 8) + v.charCodeAt(p + 3); }
function ReadIntX(v, p) { return (v.charCodeAt(p + 3) * 0x1000000) + (v.charCodeAt(p + 2) << 16) + (v.charCodeAt(p + 1) << 8) + v.charCodeAt(p); }
function ShortToStr(v) { return String.fromCharCode((v >> 8) & 0xFF, v & 0xFF); }
function ShortToStrX(v) { return String.fromCharCode(v & 0xFF, (v >> 8) & 0xFF); }
function IntToStr(v) { return String.fromCharCode((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF); }
function IntToStrX(v) { return String.fromCharCode(v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF, (v >> 24) & 0xFF); }
function MakeToArray(v) { if (!v || v == null || typeof v == 'object') return v; return [v]; }
function SplitArray(v) { return v.split(','); }
function Clone(v) { return JSON.parse(JSON.stringify(v)); }
function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
function EscapeHtmlBreaks(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;').replace(/\r/g, '<br />').replace(/\n/g, '').replace(/\t/g, '&nbsp;&nbsp;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
// Move an element from one position in an array to a new position
function ArrayElementMove(arr, from, to) { arr.splice(to, 0, arr.splice(from, 1)[0]); };
// Print object for HTML
function ObjectToStringEx(x, c) {
var r = "";
if (x != 0 && (!x || x == null)) return "(Null)";
if (x instanceof Array) { for (var i in x) { r += '<br />' + gap(c) + "Item #" + i + ": " + ObjectToStringEx(x[i], c + 1); } }
else if (x instanceof Object) { for (var i in x) { r += '<br />' + gap(c) + i + " = " + ObjectToStringEx(x[i], c + 1); } }
else { r += EscapeHtml(x); }
return r;
}
// Print object for console
function ObjectToStringEx2(x, c) {
var r = "";
if (x != 0 && (!x || x == null)) return "(Null)";
if (x instanceof Array) { for (var i in x) { r += '\r\n' + gap2(c) + "Item #" + i + ": " + ObjectToStringEx2(x[i], c + 1); } }
else if (x instanceof Object) { for (var i in x) { r += '\r\n' + gap2(c) + i + " = " + ObjectToStringEx2(x[i], c + 1); } }
else { r += EscapeHtml(x); }
return r;
}
// Create an ident gap
function gap(c) { var x = ''; for (var i = 0; i < (c * 4) ; i++) { x += '&nbsp;'; } return x; }
function gap2(c) { var x = ''; for (var i = 0; i < (c * 4) ; i++) { x += ' '; } return x; }
// Print an object in html
function ObjectToString(x) { return ObjectToStringEx(x, 0); }
function ObjectToString2(x) { return ObjectToStringEx2(x, 0); }
// Convert a hex string to a raw string
function hex2rstr(d) {
if (typeof d != "string" || d.length == 0) return '';
var r = '', m = ('' + d).match(/../g), t;
while (t = m.shift()) r += String.fromCharCode('0x' + t);
return r
}
// Convert decimal to hex
function char2hex(i) { return (i + 0x100).toString(16).substr(-2).toUpperCase(); }
// Convert a raw string to a hex string
function rstr2hex(input) {
var r = '', i;
for (i = 0; i < input.length; i++) { r += char2hex(input.charCodeAt(i)); }
return r;
}
// UTF-8 encoding & decoding functions
function encode_utf8(s) { return unescape(encodeURIComponent(s)); }
function decode_utf8(s) { return decodeURIComponent(escape(s)); }
// Convert a string into a blob
function data2blob(data) {
var bytes = new Array(data.length);
for (var i = 0; i < data.length; i++) bytes[i] = data.charCodeAt(i);
var blob = new Blob([new Uint8Array(bytes)]);
return blob;
}
// Generate random numbers
function random(max) { return Math.floor(Math.random() * max); }
// Trademarks
function trademarks(x) { return x.replace(/\(R\)/g, '&reg;').replace(/\(TM\)/g, '&trade;'); }

View file

@ -0,0 +1,270 @@
/* FileSaver.js
* A saveAs() FileSaver implementation.
* 1.1.20151003
*
* By Eli Grey, http://eligrey.com
* License: MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/
/*global self */
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs = saveAs || (function (view) {
"use strict";
// IE <10 is explicitly unsupported
if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
return;
}
var
doc = view.document
// only get URL when necessary in case Blob.js hasn't overridden it yet
, get_URL = function () {
return view.URL || view.webkitURL || view;
}
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
, click = function (node) {
var event = new MouseEvent("click");
node.dispatchEvent(event);
}
, is_safari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent)
, webkit_req_fs = view.webkitRequestFileSystem
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
, throw_outside = function (ex) {
(view.setImmediate || view.setTimeout)(function () {
throw ex;
}, 0);
}
, force_saveable_type = "application/octet-stream"
, fs_min_size = 0
// See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
// https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
// for the reasoning behind the timeout and revocation flow
, arbitrary_revoke_timeout = 500 // in ms
, revoke = function (file) {
var revoker = function () {
if (typeof file === "string") { // file is an object URL
get_URL().revokeObjectURL(file);
} else { // file is a File
file.remove();
}
};
if (view.chrome) {
revoker();
} else {
setTimeout(revoker, arbitrary_revoke_timeout);
}
}
, dispatch = function (filesaver, event_types, event) {
event_types = [].concat(event_types);
var i = event_types.length;
while (i--) {
var listener = filesaver["on" + event_types[i]];
if (typeof listener === "function") {
try {
listener.call(filesaver, event || filesaver);
} catch (ex) {
throw_outside(ex);
}
}
}
}
, auto_bom = function (blob) {
// prepend BOM for UTF-8 XML and text types (including HTML)
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob(["\ufeff", blob], { type: blob.type });
}
return blob;
}
, FileSaver = function (blob, name, no_auto_bom) {
if (!no_auto_bom) {
blob = auto_bom(blob);
}
// First try a.download, then web filesystem, then object URLs
var
filesaver = this
, type = blob.type
, blob_changed = false
, object_url
, target_view
, dispatch_all = function () {
dispatch(filesaver, "writestart progress write writeend".split(" "));
}
// on any filesys errors revert to saving with object URLs
, fs_error = function () {
if (target_view && is_safari && typeof FileReader !== "undefined") {
// Safari doesn't allow downloading of blob urls
var reader = new FileReader();
reader.onloadend = function () {
var base64Data = reader.result;
target_view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/));
filesaver.readyState = filesaver.DONE;
dispatch_all();
};
reader.readAsDataURL(blob);
filesaver.readyState = filesaver.INIT;
return;
}
// don't create more object URLs than needed
if (blob_changed || !object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (target_view) {
target_view.location.href = object_url;
} else {
var new_tab = view.open(object_url, "_blank");
if (new_tab == undefined && is_safari) {
//Apple do not allow window.open, see http://bit.ly/1kZffRI
view.location.href = object_url
}
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}
, abortable = function (func) {
return function () {
if (filesaver.readyState !== filesaver.DONE) {
return func.apply(this, arguments);
}
};
}
, create_if_not_found = { create: true, exclusive: false }
, slice
;
filesaver.readyState = filesaver.INIT;
if (!name) {
name = "download";
}
if (can_use_save_link) {
object_url = get_URL().createObjectURL(blob);
save_link.href = object_url;
save_link.download = name;
setTimeout(function () {
click(save_link);
dispatch_all();
revoke(object_url);
filesaver.readyState = filesaver.DONE;
});
return;
}
// Object and web filesystem URLs have a problem saving in Google Chrome when
// viewed in a tab, so I force save with application/octet-stream
// http://code.google.com/p/chromium/issues/detail?id=91158
// Update: Google errantly closed 91158, I submitted it again:
// https://code.google.com/p/chromium/issues/detail?id=389642
if (view.chrome && type && type !== force_saveable_type) {
slice = blob.slice || blob.webkitSlice;
blob = slice.call(blob, 0, blob.size, force_saveable_type);
blob_changed = true;
}
// Since I can't be sure that the guessed media type will trigger a download
// in WebKit, I append .download to the filename.
// https://bugs.webkit.org/show_bug.cgi?id=65440
if (webkit_req_fs && name !== "download") {
name += ".download";
}
if (type === force_saveable_type || webkit_req_fs) {
target_view = view;
}
if (!req_fs) {
fs_error();
return;
}
fs_min_size += blob.size;
req_fs(view.TEMPORARY, fs_min_size, abortable(function (fs) {
fs.root.getDirectory("saved", create_if_not_found, abortable(function (dir) {
var save = function () {
dir.getFile(name, create_if_not_found, abortable(function (file) {
file.createWriter(abortable(function (writer) {
writer.onwriteend = function (event) {
target_view.location.href = file.toURL();
filesaver.readyState = filesaver.DONE;
dispatch(filesaver, "writeend", event);
revoke(file);
};
writer.onerror = function () {
var error = writer.error;
if (error.code !== error.ABORT_ERR) {
fs_error();
}
};
"writestart progress write abort".split(" ").forEach(function (event) {
writer["on" + event] = filesaver["on" + event];
});
writer.write(blob);
filesaver.abort = function () {
writer.abort();
filesaver.readyState = filesaver.DONE;
};
filesaver.readyState = filesaver.WRITING;
}), fs_error);
}), fs_error);
};
dir.getFile(name, { create: false }, abortable(function (file) {
// delete file if it already exists
file.remove();
save();
}), abortable(function (ex) {
if (ex.code === ex.NOT_FOUND_ERR) {
save();
} else {
fs_error();
}
}));
}), fs_error);
}), fs_error);
}
, FS_proto = FileSaver.prototype
, saveAs = function (blob, name, no_auto_bom) {
return new FileSaver(blob, name, no_auto_bom);
}
;
// IE 10+ (native saveAs)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
return function (blob, name, no_auto_bom) {
if (!no_auto_bom) {
blob = auto_bom(blob);
}
return navigator.msSaveOrOpenBlob(blob, name || "download");
};
}
FS_proto.abort = function () {
var filesaver = this;
filesaver.readyState = filesaver.DONE;
dispatch(filesaver, "abort");
};
FS_proto.readyState = FS_proto.INIT = 0;
FS_proto.WRITING = 1;
FS_proto.DONE = 2;
FS_proto.error =
FS_proto.onwritestart =
FS_proto.onprogress =
FS_proto.onwrite =
FS_proto.onabort =
FS_proto.onerror =
FS_proto.onwriteend =
null;
return saveAs;
}(
typeof self !== "undefined" && self
|| typeof window !== "undefined" && window
|| this.content
));
// `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
if (typeof module !== "undefined" && module.exports) {
module.exports.saveAs = saveAs;
} else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
define([], function () {
return saveAs;
});
}

732
public/scripts/inflate.js Normal file
View file

@ -0,0 +1,732 @@
/*
* Port of script by Masanao Izumo.
*
* Wrapped all the variables in a function, created a
* constructor for interacting with the lib. Everything
* else was written by M. Izumo.
*
* Original code can be found here: http://www.onicos.com/staff/iz/amuse/javascript/expert/inflate.txt
*
*/
var zip_WSIZE = 32768; // Sliding Window size
var zip_STORED_BLOCK = 0;
var zip_STATIC_TREES = 1;
var zip_DYN_TREES = 2;
/* for inflate */
var zip_lbits = 9; // bits in base literal/length lookup table
var zip_dbits = 6; // bits in base distance lookup table
var zip_INBUFSIZ = 32768; // Input buffer size
var zip_INBUF_EXTRA = 64; // Extra buffer
/* variables (inflate) */
var zip_slide;
var zip_wp; // current position in slide
var zip_fixed_tl = null; // inflate static
var zip_fixed_td; // inflate static
var zip_fixed_bl, fixed_bd; // inflate static
var zip_bit_buf; // bit buffer
var zip_bit_len; // bits in bit buffer
var zip_method;
var zip_eof;
var zip_copy_leng;
var zip_copy_dist;
var zip_tl, zip_td; // literal/length and distance decoder tables
var zip_bl, zip_bd; // number of bits decoded by tl and td
var zip_inflate_data;
var zip_inflate_pos;
/* constant tables (inflate) */
var zip_MASK_BITS = new Array(
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff);
// Tables for deflate from PKZIP's appnote.txt.
var zip_cplens = new Array( // Copy lengths for literal codes 257..285
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);
/* note: see note #13 above about the 258 in this list. */
var zip_cplext = new Array( // Extra bits for literal codes 257..285
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99); // 99==invalid
var zip_cpdist = new Array( // Copy offsets for distance codes 0..29
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577);
var zip_cpdext = new Array( // Extra bits for distance codes
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13);
var zip_border = new Array( // Order of the bit length code lengths
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
/* objects (inflate) */
function zip_HuftList() {
this.next = null;
this.list = null;
}
function zip_HuftNode() {
this.e = 0; // number of extra bits or operation
this.b = 0; // number of bits in this code or subcode
// union
this.n = 0; // literal, length base, or distance base
this.t = null; // (zip_HuftNode) pointer to next level of table
}
function zip_HuftBuild(b, // code lengths in bits (all assumed <= BMAX)
n, // number of codes (assumed <= N_MAX)
s, // number of simple-valued codes (0..s-1)
d, // list of base values for non-simple codes
e, // list of extra bits for non-simple codes
mm // maximum lookup bits
) {
this.BMAX = 16; // maximum bit length of any code
this.N_MAX = 288; // maximum number of codes in any set
this.status = 0; // 0: success, 1: incomplete table, 2: bad input
this.root = null; // (zip_HuftList) starting table
this.m = 0; // maximum lookup bits, returns actual
/* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return zero on success, one if
the given code set is incomplete (the tables are still built in this
case), two if the input is invalid (all zero length codes or an
oversubscribed set of lengths), and three if not enough memory.
The code with value 256 is special, and the tables are constructed
so that no bits beyond that code are fetched when that code is
decoded. */
{
var a; // counter for codes of length k
var c = new Array(this.BMAX + 1); // bit length count table
var el; // length of EOB code (value 256)
var f; // i repeats in table every f entries
var g; // maximum code length
var h; // table level
var i; // counter, current code
var j; // counter
var k; // number of bits in current code
var lx = new Array(this.BMAX + 1); // stack of bits per table
var p; // pointer into c[], b[], or v[]
var pidx; // index of p
var q; // (zip_HuftNode) points to current table
var r = new zip_HuftNode(); // table entry for structure assignment
var u = new Array(this.BMAX); // zip_HuftNode[BMAX][] table stack
var v = new Array(this.N_MAX); // values in order of bit length
var w;
var x = new Array(this.BMAX + 1);// bit offsets, then code stack
var xp; // pointer into x or c
var y; // number of dummy codes added
var z; // number of entries in current table
var o;
var tail; // (zip_HuftList)
tail = this.root = null;
for (i = 0; i < c.length; i++)
c[i] = 0;
for (i = 0; i < lx.length; i++)
lx[i] = 0;
for (i = 0; i < u.length; i++)
u[i] = null;
for (i = 0; i < v.length; i++)
v[i] = 0;
for (i = 0; i < x.length; i++)
x[i] = 0;
// Generate counts for each bit length
el = n > 256 ? b[256] : this.BMAX; // set length of EOB code, if any
p = b; pidx = 0;
i = n;
do {
c[p[pidx]]++; // assume all entries <= BMAX
pidx++;
} while (--i > 0);
if (c[0] == n) { // null input--all zero length codes
this.root = null;
this.m = 0;
this.status = 0;
return;
}
// Find minimum and maximum length, bound *m by those
for (j = 1; j <= this.BMAX; j++)
if (c[j] != 0)
break;
k = j; // minimum code length
if (mm < j)
mm = j;
for (i = this.BMAX; i != 0; i--)
if (c[i] != 0)
break;
g = i; // maximum code length
if (mm > i)
mm = i;
// Adjust last length count to fill out codes, if needed
for (y = 1 << j; j < i; j++, y <<= 1)
if ((y -= c[j]) < 0) {
this.status = 2; // bad input: more codes than bits
this.m = mm;
return;
}
if ((y -= c[i]) < 0) {
this.status = 2;
this.m = mm;
return;
}
c[i] += y;
// Generate starting offsets into the value table for each length
x[1] = j = 0;
p = c;
pidx = 1;
xp = 2;
while (--i > 0) // note that i == g from above
x[xp++] = (j += p[pidx++]);
// Make a table of values in order of bit lengths
p = b; pidx = 0;
i = 0;
do {
if ((j = p[pidx++]) != 0)
v[x[j]++] = i;
} while (++i < n);
n = x[g]; // set n to length of v
// Generate the Huffman codes and for each, make the table entries
x[0] = i = 0; // first Huffman code is zero
p = v; pidx = 0; // grab values in bit order
h = -1; // no tables yet--level -1
w = lx[0] = 0; // no bits decoded yet
q = null; // ditto
z = 0; // ditto
// go through the bit lengths (k already is bits in shortest code)
for (; k <= g; k++) {
a = c[k];
while (a-- > 0) {
// here i is the Huffman code of length k bits for value p[pidx]
// make tables up to required level
while (k > w + lx[1 + h]) {
w += lx[1 + h]; // add bits already decoded
h++;
// compute minimum size table less than or equal to *m bits
z = (z = g - w) > mm ? mm : z; // upper limit
if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
// too few codes for k-w bit table
f -= a + 1; // deduct codes from patterns left
xp = k;
while (++j < z) { // try smaller tables up to z bits
if ((f <<= 1) <= c[++xp])
break; // enough codes to use up j bits
f -= c[xp]; // else deduct codes from patterns
}
}
if (w + j > el && w < el)
j = el - w; // make EOB code end at table
z = 1 << j; // table entries for j-bit table
lx[1 + h] = j; // set table size in stack
// allocate and link in new table
q = new Array(z);
for (o = 0; o < z; o++) {
q[o] = new zip_HuftNode();
}
if (tail == null)
tail = this.root = new zip_HuftList();
else
tail = tail.next = new zip_HuftList();
tail.next = null;
tail.list = q;
u[h] = q; // table starts after link
/* connect to last table, if there is one */
if (h > 0) {
x[h] = i; // save pattern for backing up
r.b = lx[h]; // bits to dump before this table
r.e = 16 + j; // bits in this table
r.t = q; // pointer to this table
j = (i & ((1 << w) - 1)) >> (w - lx[h]);
u[h - 1][j].e = r.e;
u[h - 1][j].b = r.b;
u[h - 1][j].n = r.n;
u[h - 1][j].t = r.t;
}
}
// set up table entry in r
r.b = k - w;
if (pidx >= n)
r.e = 99; // out of values--invalid code
else if (p[pidx] < s) {
r.e = (p[pidx] < 256 ? 16 : 15); // 256 is end-of-block code
r.n = p[pidx++]; // simple code is just the value
} else {
r.e = e[p[pidx] - s]; // non-simple--look up in lists
r.n = d[p[pidx++] - s];
}
// fill code-like entries with r //
f = 1 << (k - w);
for (j = i >> w; j < z; j += f) {
q[j].e = r.e;
q[j].b = r.b;
q[j].n = r.n;
q[j].t = r.t;
}
// backwards increment the k-bit code i
for (j = 1 << (k - 1) ; (i & j) != 0; j >>= 1)
i ^= j;
i ^= j;
// backup over finished tables
while ((i & ((1 << w) - 1)) != x[h]) {
w -= lx[h]; // don't need to update q
h--;
}
}
}
/* return actual size of base table */
this.m = lx[1];
/* Return true (1) if we were given an incomplete table */
this.status = ((y != 0 && g != 1) ? 1 : 0);
} /* end of constructor */
}
/* routines (inflate) */
function zip_GET_BYTE() {
if (zip_inflate_data.length == zip_inflate_pos)
return -1;
return zip_inflate_data.charCodeAt(zip_inflate_pos++) & 0xff;
}
function zip_NEEDBITS(n) {
while (zip_bit_len < n) {
zip_bit_buf |= zip_GET_BYTE() << zip_bit_len;
zip_bit_len += 8;
}
}
function zip_GETBITS(n) {
return zip_bit_buf & zip_MASK_BITS[n];
}
function zip_DUMPBITS(n) {
zip_bit_buf >>= n;
zip_bit_len -= n;
}
function zip_inflate_codes(buff, off, size) {
/* inflate (decompress) the codes in a deflated (compressed) block.
Return an error code or zero if it all goes ok. */
var e; // table entry flag/number of extra bits
var t; // (zip_HuftNode) pointer to table entry
var n;
if (size == 0)
return 0;
// inflate the coded data
n = 0;
for (; ;) { // do until end of block
zip_NEEDBITS(zip_bl);
t = zip_tl.list[zip_GETBITS(zip_bl)];
e = t.e;
while (e > 16) {
if (e == 99)
return -1;
zip_DUMPBITS(t.b);
e -= 16;
zip_NEEDBITS(e);
t = t.t[zip_GETBITS(e)];
e = t.e;
}
zip_DUMPBITS(t.b);
if (e == 16) { // then it's a literal
zip_wp &= zip_WSIZE - 1;
buff[off + n++] = zip_slide[zip_wp++] = t.n;
if (n == size)
return size;
continue;
}
// exit if end of block
if (e == 15)
break;
// it's an EOB or a length
// get length of block to copy
zip_NEEDBITS(e);
zip_copy_leng = t.n + zip_GETBITS(e);
zip_DUMPBITS(e);
// decode distance of block to copy
zip_NEEDBITS(zip_bd);
t = zip_td.list[zip_GETBITS(zip_bd)];
e = t.e;
while (e > 16) {
if (e == 99)
return -1;
zip_DUMPBITS(t.b);
e -= 16;
zip_NEEDBITS(e);
t = t.t[zip_GETBITS(e)];
e = t.e;
}
zip_DUMPBITS(t.b);
zip_NEEDBITS(e);
zip_copy_dist = zip_wp - t.n - zip_GETBITS(e);
zip_DUMPBITS(e);
// do the copy
while (zip_copy_leng > 0 && n < size) {
zip_copy_leng--;
zip_copy_dist &= zip_WSIZE - 1;
zip_wp &= zip_WSIZE - 1;
buff[off + n++] = zip_slide[zip_wp++]
= zip_slide[zip_copy_dist++];
}
if (n == size)
return size;
}
zip_method = -1; // done
return n;
}
function zip_inflate_stored(buff, off, size) {
/* "decompress" an inflated type 0 (stored) block. */
var n;
// go to byte boundary
n = zip_bit_len & 7;
zip_DUMPBITS(n);
// get the length and its complement
zip_NEEDBITS(16);
n = zip_GETBITS(16);
zip_DUMPBITS(16);
zip_NEEDBITS(16);
if (n != ((~zip_bit_buf) & 0xffff))
return -1; // error in compressed data
zip_DUMPBITS(16);
// read and output the compressed data
zip_copy_leng = n;
n = 0;
while (zip_copy_leng > 0 && n < size) {
zip_copy_leng--;
zip_wp &= zip_WSIZE - 1;
zip_NEEDBITS(8);
buff[off + n++] = zip_slide[zip_wp++] =
zip_GETBITS(8);
zip_DUMPBITS(8);
}
if (zip_copy_leng == 0)
zip_method = -1; // done
return n;
}
function zip_inflate_fixed(buff, off, size) {
/* decompress an inflated type 1 (fixed Huffman codes) block. We should
either replace this with a custom decoder, or at least precompute the
Huffman tables. */
// if first time, set up tables for fixed blocks
if (zip_fixed_tl == null) {
var i; // temporary variable
var l = new Array(288); // length list for huft_build
var h; // zip_HuftBuild
// literal table
for (i = 0; i < 144; i++)
l[i] = 8;
for (; i < 256; i++)
l[i] = 9;
for (; i < 280; i++)
l[i] = 7;
for (; i < 288; i++) // make a complete, but wrong code set
l[i] = 8;
zip_fixed_bl = 7;
h = new zip_HuftBuild(l, 288, 257, zip_cplens, zip_cplext,
zip_fixed_bl);
if (h.status != 0) {
alert("HufBuild error: " + h.status);
return -1;
}
zip_fixed_tl = h.root;
zip_fixed_bl = h.m;
// distance table
for (i = 0; i < 30; i++) // make an incomplete code set
l[i] = 5;
zip_fixed_bd = 5;
h = new zip_HuftBuild(l, 30, 0, zip_cpdist, zip_cpdext, zip_fixed_bd);
if (h.status > 1) {
zip_fixed_tl = null;
alert("HufBuild error: " + h.status);
return -1;
}
zip_fixed_td = h.root;
zip_fixed_bd = h.m;
}
zip_tl = zip_fixed_tl;
zip_td = zip_fixed_td;
zip_bl = zip_fixed_bl;
zip_bd = zip_fixed_bd;
return zip_inflate_codes(buff, off, size);
}
function zip_inflate_dynamic(buff, off, size) {
// decompress an inflated type 2 (dynamic Huffman codes) block.
var i; // temporary variables
var j;
var l; // last length
var n; // number of lengths to get
var t; // (zip_HuftNode) literal/length code table
var nb; // number of bit length codes
var nl; // number of literal/length codes
var nd; // number of distance codes
var ll = new Array(286 + 30); // literal/length and distance code lengths
var h; // (zip_HuftBuild)
for (i = 0; i < ll.length; i++)
ll[i] = 0;
// read in table lengths
zip_NEEDBITS(5);
nl = 257 + zip_GETBITS(5); // number of literal/length codes
zip_DUMPBITS(5);
zip_NEEDBITS(5);
nd = 1 + zip_GETBITS(5); // number of distance codes
zip_DUMPBITS(5);
zip_NEEDBITS(4);
nb = 4 + zip_GETBITS(4); // number of bit length codes
zip_DUMPBITS(4);
if (nl > 286 || nd > 30)
return -1; // bad lengths
// read in bit-length-code lengths
for (j = 0; j < nb; j++) {
zip_NEEDBITS(3);
ll[zip_border[j]] = zip_GETBITS(3);
zip_DUMPBITS(3);
}
for (; j < 19; j++)
ll[zip_border[j]] = 0;
// build decoding table for trees--single level, 7 bit lookup
zip_bl = 7;
h = new zip_HuftBuild(ll, 19, 19, null, null, zip_bl);
if (h.status != 0)
return -1; // incomplete code set
zip_tl = h.root;
zip_bl = h.m;
// read in literal and distance code lengths
n = nl + nd;
i = l = 0;
while (i < n) {
zip_NEEDBITS(zip_bl);
t = zip_tl.list[zip_GETBITS(zip_bl)];
j = t.b;
zip_DUMPBITS(j);
j = t.n;
if (j < 16) // length of code in bits (0..15)
ll[i++] = l = j; // save last length in l
else if (j == 16) { // repeat last length 3 to 6 times
zip_NEEDBITS(2);
j = 3 + zip_GETBITS(2);
zip_DUMPBITS(2);
if (i + j > n)
return -1;
while (j-- > 0)
ll[i++] = l;
} else if (j == 17) { // 3 to 10 zero length codes
zip_NEEDBITS(3);
j = 3 + zip_GETBITS(3);
zip_DUMPBITS(3);
if (i + j > n)
return -1;
while (j-- > 0)
ll[i++] = 0;
l = 0;
} else { // j == 18: 11 to 138 zero length codes
zip_NEEDBITS(7);
j = 11 + zip_GETBITS(7);
zip_DUMPBITS(7);
if (i + j > n)
return -1;
while (j-- > 0)
ll[i++] = 0;
l = 0;
}
}
// build the decoding tables for literal/length and distance codes
zip_bl = zip_lbits;
h = new zip_HuftBuild(ll, nl, 257, zip_cplens, zip_cplext, zip_bl);
if (zip_bl == 0) // no literals or lengths
h.status = 1;
if (h.status != 0) {
if (h.status == 1)
;// **incomplete literal tree**
return -1; // incomplete code set
}
zip_tl = h.root;
zip_bl = h.m;
for (i = 0; i < nd; i++)
ll[i] = ll[i + nl];
zip_bd = zip_dbits;
h = new zip_HuftBuild(ll, nd, 0, zip_cpdist, zip_cpdext, zip_bd);
zip_td = h.root;
zip_bd = h.m;
if (zip_bd == 0 && nl > 257) { // lengths but no distances
// **incomplete distance tree**
return -1;
}
if (h.status == 1) {
;// **incomplete distance tree**
}
if (h.status != 0)
return -1;
// decompress until an end-of-block code
return zip_inflate_codes(buff, off, size);
}
function zip_inflate_internal(buff, off, size) {
// decompress an inflated entry
var n, i;
n = 0;
while (n < size) {
if (zip_eof && zip_method == -1)
return n;
if (zip_copy_leng > 0) {
if (zip_method != zip_STORED_BLOCK) {
// STATIC_TREES or DYN_TREES
while (zip_copy_leng > 0 && n < size) {
zip_copy_leng--;
zip_copy_dist &= zip_WSIZE - 1;
zip_wp &= zip_WSIZE - 1;
buff[off + n++] = zip_slide[zip_wp++] =
zip_slide[zip_copy_dist++];
}
} else {
while (zip_copy_leng > 0 && n < size) {
zip_copy_leng--;
zip_wp &= zip_WSIZE - 1;
zip_NEEDBITS(8);
buff[off + n++] = zip_slide[zip_wp++] = zip_GETBITS(8);
zip_DUMPBITS(8);
}
if (zip_copy_leng == 0)
zip_method = -1; // done
}
if (n == size)
return n;
}
if (zip_method == -1) {
if (zip_eof)
break;
// read in last block bit
zip_NEEDBITS(1);
if (zip_GETBITS(1) != 0)
zip_eof = true;
zip_DUMPBITS(1);
// read in block type
zip_NEEDBITS(2);
zip_method = zip_GETBITS(2);
zip_DUMPBITS(2);
zip_tl = null;
zip_copy_leng = 0;
}
switch (zip_method) {
case 0: // zip_STORED_BLOCK
i = zip_inflate_stored(buff, off + n, size - n);
break;
case 1: // zip_STATIC_TREES
if (zip_tl != null)
i = zip_inflate_codes(buff, off + n, size - n);
else
i = zip_inflate_fixed(buff, off + n, size - n);
break;
case 2: // zip_DYN_TREES
if (zip_tl != null)
i = zip_inflate_codes(buff, off + n, size - n);
else
i = zip_inflate_dynamic(buff, off + n, size - n);
break;
default: // error
i = -1;
break;
}
if (i == -1) {
if (zip_eof)
return 0;
return -1;
}
n += i;
}
return n;
}
function zip_inflate_start() {
if (zip_slide == null) zip_slide = new Array(2 * zip_WSIZE);
zip_wp = 0;
zip_bit_buf = 0;
zip_bit_len = 0;
zip_method = -1;
zip_eof = false;
zip_copy_leng = zip_copy_dist = 0;
zip_tl = null;
}
inflate_start = function () { zip_inflate_start(); };
inflate = function (data) {
var out = "", buff = [], i, j;
zip_bit_buf = 0;
zip_bit_len = 0;
zip_method = -1;
zip_eof = false;
zip_inflate_data = data;
zip_inflate_pos = 0;
do { i = zip_inflate_internal(buff, buff.length, 1024); } while (i > 0);
zip_inflate_data = null; // G.C.
return buff;
};

View file

@ -0,0 +1,43 @@
/**
* @fileoverview Meshcentral.js
* @author Ylian Saint-Hilaire
* @version v0.0.1
*/
var MeshServerCreateControl = function (domain) {
var obj = {};
obj.State = 0;
obj.connectstate = 0;
obj.xxStateChange = function (newstate) {
if (obj.State == newstate) return;
obj.State = newstate;
if (obj.onStateChanged) obj.onStateChanged(obj, obj.State);
}
obj.Start = function () {
obj.connectstate = 0;
obj.socket = new WebSocket(window.location.protocol.replace("http", "ws") + "//" + window.location.host + domain + "control.ashx");
obj.socket.onopen = function () { obj.connectstate = 1; obj.xxStateChange(2); }
obj.socket.onmessage = obj.xxOnMessage;
obj.socket.onclose = function () { obj.Stop(); }
obj.xxStateChange(1);
}
obj.Stop = function () {
obj.connectstate = 0;
if (obj.socket) { obj.socket.close(); delete obj.socket; }
obj.xxStateChange(0);
}
obj.xxOnMessage = function (e) {
// console.log('xxOnMessage', e.data);
var message;
try { message = JSON.parse(e.data); } catch (e) { return; }
if (obj.onMessage) obj.onMessage(obj, message);
};
obj.Send = function (x) { if (obj.socket != null && obj.connectstate == 1) { obj.socket.send(JSON.stringify(x)); } }
return obj;
}