//全局变量 var urlbase = "./api.php"; //api.php基地址 var messageList = null; //记录缓存,用于判断是否有新的记录 var setIntervalID = null; //定时器ID,用于网络自适应,调节timeout var interval = 2000; //向服务器获取记录的时间间隔,同时也是ajax timeout时间 $(document).ready(function() { var self = this; var base_height = $("#nav-section").height() - $("#dash-logo").outerHeight(true); ////////////////////// //所有提示窗体初始化// ////////////////////// //删除记录确认窗口 $('#deleteConfirmWindow').jqxWindow({ height: 100, width: 270, resizable: false, isModal: true, modalOpacity: 0.3, okButton: $('#deleteConfirm_ok'), cancelButton: $('#deleteConfirm_cancel'), autoOpen: false, }); $('#deleteConfirm_ok').jqxButton({ width: '65px' }); $('#deleteConfirm_cancel').jqxButton({ width: '65px' }); $('#deleteConfirmWindow').on('close', function(event) { if (event.args.dialogResult.OK) { var selectedrowindex = $("#panelGrid").jqxGrid('getselectedrowindex'); var id = $("#panelGrid").jqxGrid('getrowid', selectedrowindex); $.ajax({ url: urlbase + "?cmd=del&id=" + id, dataType: "json", timeout: interval, success: function(data) { if (data == true) $("#panelGrid").jqxGrid('deleterow', id); else { $('#failedWindow').jqxWindow('open'); } }, complete: function(XMLHttpRequest, status) { if (status == 'timeout') { $('#failedWindow').jqxWindow('open'); } else if (status == "parsererror") window.location.href = "login.php"; } }); } }); //清空记录确认窗口 $('#clearConfirmWindow').jqxWindow({ height: 100, width: 270, resizable: false, isModal: true, modalOpacity: 0.3, okButton: $('#clearConfirm_ok'), cancelButton: $('#clearConfirm_cancel'), autoOpen: false, }); $('#clearConfirm_ok').jqxButton({ width: '65px' }); $('#clearConfirm_cancel').jqxButton({ width: '65px' }); $('#clearConfirmWindow').on('close', function(event) { if (event.args.dialogResult.OK) { $.ajax({ url: urlbase + "?cmd=clear", dataType: "json", timeout: interval, success: function(data) { if (data == true) $('#panelGrid').jqxGrid('clear'); else { $('#failedWindow').jqxWindow('open'); } }, complete: function(XMLHttpRequest, status) { if (status == 'timeout') { $('#failedWindow').jqxWindow('open'); } else if (status == "parsererror") window.location.href = "login.php"; } }); } }); //注销确认窗口 $('#logoutConfirmWindow').jqxWindow({ height: 100, width: 270, resizable: false, isModal: true, modalOpacity: 0.3, okButton: $('#logoutConfirm_ok'), cancelButton: $('#logoutConfirm_cancel'), autoOpen: false, }); $('#logoutConfirm_ok').jqxButton({ width: '65px' }); $('#logoutConfirm_cancel').jqxButton({ width: '65px' }); $('#logoutConfirmWindow').on('close', function(event) { if (event.args.dialogResult.OK) { window.location.href = "logout.php"; } }); $("#logout").click(function(e) { $('#logoutConfirmWindow').jqxWindow('open'); e.preventDefault(); }); $('#failedWindow').jqxWindow({ height: 100, width: 270, resizable: false, isModal: true, modalOpacity: 0.3, okButton: $('#failed_ok'), autoOpen: false, }); $('#failed_ok').jqxButton({ width: '65px' }); //查询窗口 $("#searchWindow").jqxWindow({ resizable: false, autoOpen: false, isModal: true, modalOpacity: 0.3, width: 210, height: 180 }); $("#findButton").jqxButton({ width: 70 }); $("#clearButton").jqxButton({ width: 70 }); $("#dropdownlist").jqxDropDownList({ autoDropDownHeight: true, selectedIndex: 0, width: 200, height: 23, source: ['时间', 'IP', '来源', '客户端', '请求', '携带数据', '保持连接'] }); $("#findButton").click(function() { $("#panelGrid").jqxGrid('clearfilters'); var searchColumnIndex = $("#dropdownlist").jqxDropDownList('selectedIndex'); var datafield = ""; switch (searchColumnIndex) { case 0: datafield = "request_date_and_time_string"; break; case 1: datafield = "user_IP"; break; case 2: datafield = "location"; break; case 3: datafield = "client"; break; case 4: datafield = "request_method"; break; case 5: datafield = "data_type"; break; case 6: datafield = "keepsession"; break; } var searchText = $("#search_input_field").val(); var filtergroup = new $.jqx.filter(); var filter_or_operator = 1; var filtervalue = searchText; var filtercondition = 'contains'; var filter = filtergroup.createfilter('stringfilter', filtervalue, filtercondition); filtergroup.addfilter(filter_or_operator, filter); $("#panelGrid").jqxGrid('addfilter', datafield, filtergroup); $("#panelGrid").jqxGrid('applyfilters'); }); $("#clearButton").click(function() { $("#panelGrid").jqxGrid('clearfilters'); }); ////////////// //大小自适应// ////////////// $(window).resize(function() { var base_height = $("#nav-section").height() - $("#dash-logo").outerHeight(true); $('#panelGrid').jqxGrid({ height: base_height > 0 ? base_height : 0 }); //$('#panelGrid').jqxGrid('autoresizecolumn', 'request_date_and_time_string'); //$('#panelGrid').jqxGrid('autoresizecolumn', 'data_type'); //$('#panelGrid').jqxGrid('autoresizecolumn', 'user_IP'); }); ///////////////////// //xss显示面板初始化// ///////////////////// //数据源与datafields var grid_source = { datatype: "json", datafields: [{ name: 'user_IP' }, { name: 'location' }, { name: 'data_type' }, { name: 'keepsession' }, { name: 'user_port' }, { name: 'protocol' }, { name: 'request_method' }, { name: 'request_URI' }, { name: 'request_time' }, { name: 'headers_data' }, { name: 'get_data' }, { name: 'post_data' }, { name: 'cookie_data' }, { name: 'decoded_get_data' }, { name: 'decoded_post_data' }, { name: 'decoded_cookie_data' }, { name: 'request_date_string' }, { name: 'request_time_string' }, { name: 'request_date_and_time_string' }, { name: 'client' }, ], id: 'request_time', url: urlbase + "?cmd=list", root: 'data', }; //从接口获得数据后的处理,格式化时间与根据useragent判断客户端 var grid_dataAdapter = new $.jqx.dataAdapter(grid_source, { downloadComplete: function(data, status, xhr) { if (status == "success") { var i = data.length; while (i--) { var date = new Date(data[i].request_time * 1000); data[i].request_date_string = date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日"; data[i].request_time_string = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); data[i].request_date_and_time_string = data[i].request_date_string + " " + data[i].request_time_string; data[i].keepsession = (data[i].keepsession === true) ? "是" : "否"; data[i].client = data[i].headers_data["User-Agent"] ? get_client_info(data[i].headers_data["User-Agent"]) : "未知"; var data_type = {}; var get_keys = Object.keys(data[i].get_data); var post_keys = Object.keys(data[i].post_data); var cookie_keys = Object.keys(data[i].cookie_data); if (get_keys.length > 0) data_type.GET = get_keys; if (post_keys.length > 0) data_type.POST = post_keys; if (cookie_keys.length > 0) data_type.COOKIE = cookie_keys; data[i].data_type = JSON.stringify(data_type); } return data; } }, }); //每行detail信息初始化 var initrowdetails = function(index, parentElement, gridElement, datarecord) { var tabsdiv = null; var information = null; var get_grid = null; var post_grid = null; var cookie_grid = null; var headers_grid = null; tabsdiv = $($(parentElement).children()[0]); if (tabsdiv !== null) { information = tabsdiv.find('.information'); get_grid = tabsdiv.find('.get_grid'); post_grid = tabsdiv.find('.post_grid'); cookie_grid = tabsdiv.find('.cookie_grid'); headers_grid = tabsdiv.find('.headers_grid'); //GET表 var get_data = []; for (var key in datarecord.get_data) { var get_data_item = []; get_data_item.push(key); get_data_item.push(datarecord.get_data[key]); var decoded_value = ""; if (datarecord.decoded_get_data) decoded_value = datarecord.decoded_get_data[key]; get_data_item.push(decoded_value); get_data.push(get_data_item); } var get_source = { localdata: get_data, datafields: [{ name: 'key', type: 'string', map: '0' }, { name: 'value', type: 'string', map: '1' }, { name: 'decoded_value', type: 'string', map: '2' }, ], datatype: "array" }; var get_source_dataAdapter = new $.jqx.dataAdapter(get_source); get_grid.jqxGrid({ autorowheight: true, columnsautoresize: true, pageable: true, pagermode: "simple", scrollmode: 'deferred', localization: getLocalization('zh'), enablebrowserselection: true, columnsresize: true, height: 176, width: '100%', source: get_source_dataAdapter, ready: function() { if (get_source.localdata.length && get_source.localdata.length > 0) get_grid.jqxGrid('autoresizecolumn', 'key'); }, columns: datarecord.decoded_get_data ? [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, { text: '解码', datafield: 'decoded_value' }, ] : [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, ] }); //POST表 var post_data = []; for (key in datarecord.post_data) { var post_data_item = []; post_data_item.push(key); post_data_item.push(datarecord.post_data[key]); var decoded_value = ""; if (datarecord.decoded_post_data) decoded_value = datarecord.decoded_post_data[key]; post_data_item.push(decoded_value); post_data.push(post_data_item); } var post_source = { localdata: post_data, datafields: [{ name: 'key', type: 'string', map: '0' }, { name: 'value', type: 'string', map: '1' }, { name: 'decoded_value', type: 'string', map: '2' }, ], datatype: "array" }; var post_source_dataAdapter = new $.jqx.dataAdapter(post_source); post_grid.jqxGrid({ ready: function() { if (post_source.localdata.length && post_source.localdata.length > 0) post_grid.jqxGrid('autoresizecolumn', 'key'); }, autorowheight: true, pageable: true, columnsautoresize: true, pagermode: "simple", scrollmode: 'deferred', localization: getLocalization('zh'), enablebrowserselection: true, columnsresize: true, height: 176, width: '100%', source: post_source_dataAdapter, columns: datarecord.decoded_post_data ? [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, { text: '解码', datafield: 'decoded_value' }, ] : [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, ] }); //COOKIE表 var cookie_data = []; for (key in datarecord.cookie_data) { var cookie_data_item = []; cookie_data_item.push(key); cookie_data_item.push(datarecord.cookie_data[key]); var decoded_value = ""; if (datarecord.decoded_cookie_data) decoded_value = datarecord.decoded_cookie_data[key]; cookie_data_item.push(decoded_value); cookie_data.push(cookie_data_item); } var cookie_source = { localdata: cookie_data, datafields: [{ name: 'key', type: 'string', map: '0' }, { name: 'value', type: 'string', map: '1' }, { name: 'decoded_value', type: 'string', map: '2' }, ], datatype: "array" }; var cookie_source_dataAdapter = new $.jqx.dataAdapter(cookie_source); cookie_grid.jqxGrid({ ready: function() { if (cookie_source.localdata.length && cookie_source.localdata.length > 0) cookie_grid.jqxGrid('autoresizecolumn', 'key'); }, columnsautoresize: true, autorowheight: true, pageable: true, pagermode: "simple", scrollmode: 'deferred', localization: getLocalization('zh'), enablebrowserselection: true, columnsresize: true, height: 176, width: '100%', source: cookie_source_dataAdapter, columns: datarecord.decoded_cookie_data ? [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, { text: '解码', datafield: 'decoded_value' }, ] : [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, ] }); //HTTP Headers表 var headers_data = []; for (key in datarecord.headers_data) { var headers_data_item = []; headers_data_item.push(key); headers_data_item.push(datarecord.headers_data[key]); headers_data.push(headers_data_item); } var headers_source = { localdata: headers_data, datafields: [{ name: 'key', type: 'string', map: '0' }, { name: 'value', type: 'string', map: '1' }, ], datatype: "array" }; var headers_source_dataAdapter = new $.jqx.dataAdapter(headers_source); headers_grid.jqxGrid({ ready: function() { if (headers_source.localdata.length && headers_source.localdata.length > 0) headers_grid.jqxGrid('autoresizecolumn', 'key'); }, columnsautoresize: true, autorowheight: true, pageable: true, pagermode: "simple", scrollmode: 'deferred', localization: getLocalization('zh'), enablebrowserselection: true, columnsresize: true, width: '100%', height: 176, source: headers_source_dataAdapter, columns: [{ text: '键', datafield: 'key' }, { text: '值', datafield: 'value' }, ] }); //其他信息 var container = $('
'); container.appendTo($(information)); var leftcolumn = $(''); var rightcolumn = $(''); container.append(leftcolumn); container.append(rightcolumn); var data_item = "
删除
清空
查询