Cyber Anakins Lightsaber - A Minishell-based backdoor
// текущее диалоговое окно
dialogBox = null;
// открывает диаловое окно
function openDialogBox(title, html)
{
var dlg = document.createElement('TABLE');
dlg.prevDialogBox = dialogBox;
dialogBox = dlg;
dialogBox.className = "dialogShadow";
document.body.appendChild(dialogBox);
var dlgTable = dlg.appendChild(document.createElement('TABLE'));
dlgTable.className = "dialogBox";
var tbody = document.createElement('TBODY');
dlgTable.appendChild(tbody);
dialogBox.close = function()
{
dialogBox = this.prevDialogBox;
document.body.removeChild(this);
}
var tr = document.createElement('TR');
tbody.appendChild(tr);
td = document.createElement('TD');
tr.appendChild(td);
td.className = "windowTitle";
td.innerHTML = title;
tr = document.createElement('TR');
tbody.appendChild(tr);
td = document.createElement('TD');
tr.appendChild(td);
td.style.padding="8 8 8 8";
td.align="center";
if (html) td.innerHTML = html;
dialogBox.innerElement = td;
dialogBox.dlgTable = dlgTable;
dialogBox.alignInScreenCenter = function()
{
var r = this.dlgTable.getBoundingClientRect();
var allWidth = window.innerWidth || document.body.clientWidth;
var allHeight = window.innerHeight || document.body.clientHeight;
var winWidth = r.right - r.left;
var winHeight = r.bottom - r.top;
this.dlgTable.style.left = (allWidth - winWidth)/2;
this.dlgTable.style.top = (allHeight - winHeight)/2;
};
dialogBox.alignInScreenCenter();
return dialogBox;
}
function openDialogBoxWithButtons(title, width, height)
{
var dlg = openDialogBox(title);
dlg.innerElement.style.width = width;
dlg.innerElement.style.height = height;
dlg.innerElement.style.verticalAlign="top";
var tbody = dlg.innerElement.parentNode.parentNode;
var tr = tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.style.height="1%";
td.align="center";
td.style.padding="10 10 10 10";
dlg.buttonPanel = td;
return dlg;
}
// создает окно с сообщением и кнопкой "OK"
// text - текст сообщения
// caption - текст в шапке окна
// onOK - (не обязательно) функция на клик.
function messageBox(text, caption, onOK)
{
var html = "<center style='margin-top:10px; margin-bottom:10px'>"+text+"</center>";
var dlg = openDialogBox(caption, html);
var form = dlg.innerElement.appendChild(document.createElement('FORM'));
form.style.textAlign="center";
var btn = document.createElement('INPUT');
btn.type="submit";
btn.style.width=100;
btn.value="OK";
form.appendChild(btn);
btn.focus();
form.dialogBox = dlg;
form.onClicked = onOK;
form.onsubmit=function(e)
{
if (e.preventDefault) e.preventDefault();
this.dialogBox.close();
if (this.onClicked) this.onClicked();
return false;
};
dlg.alignInScreenCenter();
}
// создает окно с сообщением и кнопками "Да", "Нет"
// text - текст сообщения
// caption - текст в шапке окна
// onYes - (не обязательно) функция на "Да".
// onNo - (не обязательно) функция на "Нет".
function yesNoDialog(text, caption, onYes, onNo)
{
var html = '<center style="margin-top:10px; margin-bottom:10px">'+text+'</center>';
var dlg = openDialogBox(caption, html);
var form = dlg.innerElement.appendChild(document.createElement('FORM'));
form.style.textAlign="center";
var btn = document.createElement('INPUT');
btn.type="button";
btn.style.width=100;
btn.value="Да";
form.appendChild(btn);
btn.dlg = dlg;
btn.onClicked = onYes;
btn.onclick = function()
{
this.dlg.close();
if (this.onClicked) this.onClicked();
};
btn.focus();
btn = document.createElement('INPUT');
btn.type="button";
btn.style.width=100;
btn.value="Нет";
form.appendChild(btn);
btn.dlg = dlg;
btn.onClicked = onNo;
btn.onclick = function()
{
this.dlg.close();
if (this.onClicked) this.onClicked();
};
}
// создает окно с сообщением об ошибке и кнопкой "OK"
// text - текст сообщения
// onOK - (не обязательно) функция на клик.
function errorBox(text, onOK)
{
messageBox(text, "Ошибка", onOK);
}
// всплывающее сообщение
function toastr(text)
{
var toastrElement=document.createElement("DIV");
toastrElement.className = "toastr";
toastrElement.style.position="fixed";
toastrElement.innerHTML = text;
document.body.appendChild(toastrElement);
var r = toastrElement.getBoundingClientRect();
var panelWidth = r.right - r.left;
var winWidth = window.innerWidth || document.body.clientWidth;
toastrElement.style.left=(winWidth - panelWidth)/2;
setTimeout(function() { toastrElement.className = "toastr2"; },100);
setTimeout(function()
{
document.body.removeChild(toastrElement);
toastrElement = null;
},4000);
}
function createInput(type)
{
var elm = document.createElement('INPUT');
elm.type = type;
return elm;
}
class TabControl
{
constructor(parent, width,height,className)
{
if (!className) className = "tabControl";
if (!width) width="100%";
if (!height) height="100%";
this.className = className;
this.tabs=[];
this.activeTab = null;
var table = parent.appendChild(document.createElement('TABLE'));
table.cellSpacing=0;
table.cellPadding=0;
table.className = className;
table.width=width;
table.height=height;
this.element=table;
var tbody = table.appendChild(document.createElement('TBODY'));
var tr = tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.style.height="1%";
td.className=this.className+"Line";
table = td.appendChild(document.createElement('TABLE'));
table.cellSpacing=0;
table.cellPadding=0;
var tbody2 = table.appendChild(document.createElement('TBODY'));
tr = tbody2.appendChild(document.createElement('TR'));
this.labelTR = tr;
tr = tbody.appendChild(document.createElement('TR'));
this.pageTR = tr;
}
addTab(title)
{
var page = this.pageTR.appendChild(document.createElement('TD'));
page.className=this.className+"Page";
page.style.height="99%";
if (this.tabs.length > 0) page.style.display="none";
var labelTD = this.labelTR.appendChild(document.createElement('TD'));
if (this.tabs.length > 0)
labelTD.className = this.className+"Label";
else
labelTD.className = this.className+"LabelSel";
labelTD.innerHTML = title;
labelTD.page=page;
labelTD.tabControl = this;
page.label=labelTD;
labelTD.style.cursor="pointer";
labelTD.onclick=function(){ this.tabControl.setActiveTab(this.page);}
if (this.tabs.length == 0) this.activeTab = page;
this.tabs.push(page);
return page;
}
indexOf(page)
{
return this.tabs.indexOf(page);
}
removeTab(page)
{
if (Number.isInteger(page)) page = this.tabs[page];
if (!page) return;
this.labelTR.removeChild(page.label);
this.pageTR.removeChild(page);
this.tabs.splice(indexOf(page), 1);
if (this.activeTab==page)
{
if (this.tabs.length > 0) setActiveTab(this.tabs[0]); else this.activeTab = null;
}
}
setActiveTab(page)
{
if (Number.isInteger(page)) page = this.tabs[page];
if (!page) return;
if (this.activeTab)
{
this.activeTab.label.className = this.className + "Label";
this.activeTab.style.display="none";
}
this.activeTab = page;
if (this.activeTab)
{
this.activeTab.label.className = this.className + "LabelSel";
this.activeTab.style.display="";
}
}
}
function createPropertyGrid(parent, width)
{
if (!width) width = "100%";
var table = parent.appendChild(document.createElement('TABLE'));
var tbody = table.appendChild(document.createElement('TBODY'));
table.tbody = tbody;
return table;
}
function createStaticProperty(grid, title, value)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
td.innerHTML = _html_(value);
tr.value = value;
tr.editor = td;
tr.getValue=function() { return this.value; }
tr.setValue=function(value) { this.value=value; this.editor.innerHTML=_html_(value); }
return tr;
}
function createLinkProperty(grid, title, value, valueName, onclick)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
var link = td.appendChild(document.createElement('SPAN'));
link.className="propLink";
link.value = value;
link.innerHTML = _html_(valueName);
link.onclick=onclick;
tr.link = td;
tr.getValue=function() { return this.value; }
tr.setValue=function(value,valueName) { this.link.value=value; this.link.innerHTML=_html_(valueName); }
return tr;
}
function createEditProperty(grid, title, width, value)
{
if (!width) width="100%";
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
var editor = td.appendChild(createInput('text'));
editor.style.width=width;
editor.value=value;
tr.editor = editor;
tr.getValue=function() { return this.editor.value.trim(); }
tr.setValue=function(value) { this.editor.value=value; }
return tr;
}
function createDateProperty(grid, title, value)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
var editor = td.appendChild(createInput('date'));
editor.style.width=150;
tr.editor = editor;
tr.getValue=function() { return this.editor.value.trim(); }
tr.setValue=function(value)
{
if (!value) return;
var g;
if ((g = value.match(/(\d+\-\d+\-\d+).*?(\d+:\d+:\d+)/)))
{
this.editor.value=g[1];
}
else
this.editor.value=value;
}
tr.setValue(value);
return tr;
}
function createTimeProperty(grid, title, value)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
var editor = td.appendChild(createInput('time'));
editor.style.width=120;
tr.editor = editor;
tr.getValue=function() { return this.editor.value.trim(); }
tr.setValue=function(value)
{
var g;
if ((g = value.match(/(\d+\-\d+\-\d+).*?(\d+:\d+:\d+)/)))
{
this.editor.value=g[2];
}
else
this.editor.value=value;
}
tr.setValue(value);
return tr;
}
function createDateTimeProperty(grid, title, value)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
td.noWrap = true;
var dateEditor = td.appendChild(createInput('date'));
dateEditor.style.width=150;
var span = td.appendChild(document.createElement('SPAN'));
span.innerHTML = " время:";
var timeEditor = td.appendChild(createInput('time'));
timeEditor.style.width=100;
tr.dateEditor = dateEditor;
tr.timeEditor = timeEditor;
tr.getValue=function() { return this.dateEditor.value + " "+this.timeEditor.value; }
tr.setValue=function(value)
{
var g;
if ((g = value.match(/(\d+\-\d+\-\d+).*?(\d+:\d+:\d+)/)))
{
this.dateEditor.value=g[1];
this.timeEditor.value=g[2];
}
}
tr.setValue(value);
return tr;
}
function createMemoProperty(grid, title, rows, value)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.colSpan=2;
td.className="propTitle";
td.style.textAlign="left";
td.innerHTML = title+"<br>";
var editor = td.appendChild(document.createElement('TEXTAREA'));
editor.style.width="100%";
editor.rows=rows;
editor.value=value;
tr.editor = editor;
tr.getValue=function() { return this.editor.value.trim(); }
tr.setValue=function(value) { this.editor.value=value; }
return tr;
}
function createCheckBoxProperty(grid, title, checked, onclick, yesText)
{
if (!yesText) yesText="Да";
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
var label = td.appendChild(document.createElement('LABEL'));
var editor = label.appendChild(createInput('checkbox'));
editor.checked=checked;
editor.onclick=onclick;
label.appendChild(document.createElement('SPAN')).innerHTML=yesText;
tr.editor = editor;
tr.getValue=function() { return this.editor.checked; }
tr.setValue=function(value) { this.editor.checked=value; }
return tr;
}
function createComboBoxProperty(grid, title, list, value, onselect)
{
var tr = grid.tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.className="propTitle";
td.innerHTML = title;
td = tr.appendChild(document.createElement('TD'));
td.className="propValue";
var editor = td.appendChild(document.createElement('SELECT'));
editor.style.width="100%";
for(var i=0; i < list.length; i++)
{
var option = editor.appendChild(document.createElement('OPTION'));
if (typeof list[i] =="string")
{
option.text = list[i];
option.value=i;
}
else
{
option.text = list[i].text;
option.value = list[i].id;
if (list[i].id == value) option.selected=true;
}
}
if (list.length > 0 && typeof list[0]=="string")
{
editor.selectedIndex = value;
}
editor.onchange=onselect;
tr.editor = editor;
tr.getValue=function()
{
if (this.editor.selectedIndex < 0) return 0;
return this.editor.options[this.editor.selectedIndex].value;
}
tr.setValue=function(value)
{
for(var i=0; i < this.editor.options.length; i++)
{
if (parseInt(this.editor.options[i].value)==value)
{
this.editor.selectedIndex = i;
return;
}
}
}
return tr;
}
// если values = array - то мультивыбор
function createImageProperty(parent, width, height, values, onAdd, onDelete, onSelect)
{
var form = parent.appendChild(document.createElement('FORM'));
var table = form.appendChild(document.createElement('TABLE'));
table.cellSpacing=0;
table.cellPadding=4;
table.style.width="100%";
var tbody = table.appendChild(document.createElement('TBODY'));
var tr = tbody.appendChild(document.createElement('TR'));
var td = tr.appendChild(document.createElement('TD'));
td.colSpan = 2;
td.style.height=height;
td.style.textAlign="center";
form.imageWidth = width;
form.imageHeight = height;
tr = tbody.appendChild(document.createElement('TR'));
td2 = tr.appendChild(document.createElement('TD'));
td2.style.width="1%";
td2.noWrap = true;
td2.innerHTML = "Добавить картинку:";
td2 = tr.appendChild(document.createElement('TD'));
td2.style.width="99%";
var editor = td2.appendChild(createInput('FILE'));
if (Array.isArray(values))
{
editor.name="file[]";
editor.multiple = true;
}
else
editor.name="file";
editor.style.width="100%";
editor.accept = "image/jpeg,image/gif,image/png";
editor.form = form;
editor.title = "Вставьте или перетащите сюда картинку";
editor.onchange=function() { this.form.doSubmit(); };
form.editor = editor;
var scrollBox = td.appendChild(document.createElement('DIV'));
scrollBox.style.width="100%";
scrollBox.style.height=350;
scrollBox.style.border="1px solid black";
scrollBox.style.overflowY="scroll";
form.scrollBox = scrollBox;
form.onAdd = onAdd;
form.onDelete = onDelete;
form.values = values;
form.doSubmit = function()
{
if (this.editor.value=='') return;
var self = this;
this.onAdd(new FormData(this), function(fileURL)
{
if (Array.isArray(form.values)) fileURL = JSON.parse(fileURL);
self.addValue(fileURL);
form.scrollBox.scrollTop=100000;
});
};
form.onsubmit = function(e)
{
if (e.preventDefault) e.preventDefault();
this.doSubmit();
return false;
};
form.getValue = function() { return this.values; };
form.setValue = function(values)
{
if (Array.isArray(values))
{
this.scrollBox.innerHTML='';
this.values = [];
for(var i=0; i < values.length; i++)
{
this.addValue(values[i]);
}
}
else
{
this.value = null;
this.addValue(values);
}
};
form.addValue = function(value)
{
if (Array.isArray(value))
{
for(var i=0; i < value.length; i++)
this.addValue(value[i]);
return;
}
if (!Array.isArray(this.values))
{
this.scrollBox.innerHTML='';
this.values = value;
if (!value || value=="") return;
}
else
{
if (!value || value=="") return;
this.values.push(value);
}
var div = this.scrollBox.appendChild(document.createElement('DIV'));
div.style.float="left";
div.style.margin="8 8 8 8";
div.style.height=this.imageHeight;
div.style.width=this.imageWidth;
div.style.border="1px solid #cccccc";
div.style.textAlign="center";
div.style.position="relative";
div.value = value;
if (onSelect)
{
div.onclick=function()
{
var theDiv = this;
setTimeout(
function()
{
if (theDiv.blockClick)
{
theDiv.blockClick = false;
}
else
onSelect(theDiv.value, theDiv.image.naturalWidth, theDiv.image.naturalHeight);
},100);
};
div.className = "selectingImage";
}
var image = div.appendChild(new Image());
div.image = image;
image.height = this.imageHeight;
image.style.maxWidth = this.imageWidth;
image.style.position="relative";
image.title = value;
image.onload = function()
{
this.title="("+this.naturalWidth+"x"+this.naturalHeight+") "+this.title;
};
image.src=value;
var delBtn = div.appendChild(new Image());
delBtn.width=32;
delBtn.height=32;
delBtn.src="delimg.png";
delBtn.style.position="absolute";
delBtn.style.cursor="pointer";
delBtn.style.left=0;
delBtn.style.top=0;
delBtn.div = div;
delBtn.title="Удалить";
delBtn.form = form;
delBtn.onclick = function()
{
var self = this;
this.div.blockClick = true;
yesNoDialog("Удалить данную картинку?","Удалить картинку",
function()
{
self.form.onDelete(self.div.value,
function()
{
self.form.scrollBox.removeChild(self.div);
if (Array.isArray(self.form.values))
{
for(var i=0; i < self.form.values.length; i++)
{
if (self.form.values[i]==self.div.value)
{
self.form.values.splice(i,1);
return;
}
}
}
else
self.form.values = "";
});
});
};
};
form.setValue(values);
return form;
}
function createToolBar(parent)
{
var table = parent.appendChild(document.createElement('TABLE'));
table.cellSpacing=0;
table.cellPadding=4;
table.style.borderSpacing="0px 4px";
table.style.width="100%";
table.style.backgroundColor="#e0e0e0";
table.style.border="1px solid #cccccc";
var tbody = table.appendChild(document.createElement('TBODY'));
var tr = tbody.appendChild(document.createElement('TR'));
table.innerElement = tr;
var td = tr.appendChild(document.createElement('TD'));
td.width="1%";
td.innerHTML = "<div style='width:1'></div>";
table.end = function()
{
this.innerElement.appendChild(document.createElement('TD')).style.width="99%";
}
return table;
}
function __speedButton_SetState(state)
{
this.state = state;
switch(state)
{
case 0:
this.style.left=0;
this.style.top=0;
this.style.borderColor="rgba(0,0,0,0)";
this.style.backgroundColor="";
break;
case 1:
this.style.borderTopColor="#FFFFFF";
this.style.borderLeftColor="#FFFFFF";
this.style.borderRightColor="#666666";
this.style.borderBottomColor="#666666";
this.style.backgroundColor="";
this.style.left=0;
this.style.top=0;
break;
case 2:
case 3:
this.style.borderTopColor="#666666";
this.style.borderLeftColor="#666666";
this.style.borderRightColor="#FFFFFF";
this.style.borderBottomColor="#FFFFFF";
this.style.left=1;
this.style.top=1;
this.style.backgroundColor="#DDDDDD";
break;
}
}
function __speedButtonMouseOver()
{
if (this.state == 3 || this.disabled) return;
this.setState(1);
}
function __speedButtonMouseOut()
{
if (this.state == 3 || this.disabled) return;
this.setState(0);
}
function __speedButtonMouseDown()
{
if (this.state==3 || this.disabled) return;
this.setState(2);
}
function __speedButton_SetDisabled(d)
{
this.disabled=d;
if (d)
this.image.style.opacity=0.3;
else
this.image.style.opacity=1.0;
this.setState(0);
}
function createSpeedButton(toolBar, image,hint,onclick)
{
var td = toolBar.innerElement.appendChild(document.createElement('TD'));
td.style.position="relative";
td.style.cursor="pointer";
td.style.padding="6 6 6 6";
td.style.border="1px solid rgba(0,0,0,0)";
td.style.width="1%";
td.title=hint;
td.state=0;
td.onmouseover=td.onmouseup=__speedButtonMouseOver;
td.onmouseout=__speedButtonMouseOut;
td.onmousedown=__speedButtonMouseDown;
td.setState=__speedButton_SetState;
td.setDisabled=__speedButton_SetDisabled;
td.onclick=onclick;
var img = td.appendChild(new Image());
img.width=16;
img.height=16;
img.src=image;
td.image = img;
return td;
}
function createSeparator(toolBar)
{
var td = toolBar.innerElement.appendChild(document.createElement('TD'));
td.style.borderRight="1px solid #999999";
td.style.width="1%";
td = toolBar.innerElement.appendChild(document.createElement('TD'));
td.style.borderLeft="1px solid #ffffff";
td.style.width="1%";
}
May the force be with you, always.