(function($) { | |
$.fn.objWifiPortMap = function() { | |
this.onLoad = function(flag) { | |
if(flag) { | |
LoadWebPage("html/wifi/wifiPortMap.html"); | |
$("#lt_portMap_btnAddPortMap").click(function() { | |
AddPortMapEntry(); | |
}); | |
$("#lt_portMap_btnDeletePortMap").click(function() { | |
DelPortMapEntry(); | |
}); | |
} //end flag | |
GetFWPortMapInfo(); | |
} | |
function DelPortMapEntry() { | |
var entryIdxList = ""; | |
$("tbody tr td :checked").each(function() { | |
var entryIdx = $(this).parents("tr").prevAll("tr").length + 1; | |
entryIdxList = entryIdxList + entryIdx + ","; | |
}); | |
if(""==entryIdxList) { | |
return; | |
} | |
var entryMap = new Map(); | |
entryMap.put("RGW/firewall/del_port_mapping_index",entryIdxList); | |
var retXml = PostXml("firewall","delete_port_mapping_entry",entryMap); | |
if("OK" == $(retXml).find("setting_response").text()) { | |
GetFWPortMapInfo(); | |
} else { | |
alert("delete port map entry failed."); | |
} | |
} | |
function AddPortMapEntry() { | |
ShowPortMapConfigDlg(); | |
var ipportMapIP_dest = $("#divportMapIP_dest").ip_address("divportMapIP_dest"); | |
$("#lt_btnSave").click(function() { | |
var validateMsg = ValidatePortMapEntry(ipportMapIP_dest); | |
if("ok" != validateMsg) { | |
$("#lIpFilterSetError").show().text(validateMsg); | |
return; | |
} | |
var entryId = $("tbody tr").size() + 1; | |
var preTag = "RGW/firewall/port_mapping/entry_list/entry_" + entryId; | |
var entryMap = new Map(); | |
entryMap.put(preTag+"/start_time",GetTimeFromElement("txtStartTime")); | |
entryMap.put(preTag+"/stop_time",GetTimeFromElement("txtEndTime")); | |
entryMap.put(preTag+"/dest_ip", ipportMapIP_dest.getIP()); | |
entryMap.put(preTag+"/src_dport", GetPortFromElement("txtDestPort")); | |
entryMap.put(preTag+"/proto", $("#selPortMapProtocol").val()); | |
entryMap.put(preTag+"/enabled", $("#selPortMapStatus").val()); | |
CloseDlg(); | |
var retXml = PostXml("firewall","add_port_mapping_entry",entryMap); | |
if("OK" == $(retXml).find("setting_response").text()) { | |
GetFWPortMapInfo(); | |
} else { | |
alert("add port map entry failed."); | |
} | |
}); | |
} | |
function GetFWPortMapInfo() { | |
$("#tbodyPortMap").empty(); | |
$("#DeleteAllIpEntry").attr("checked",false); | |
$("#lt_portMap_btnDeletePortMap").hide(); | |
var retXml = PostXml("firewall","fw_get_port_mapping_info"); | |
var bFoundEntry = true; | |
var idx = 1; | |
while(bFoundEntry) { | |
var entryIdx = "entry_" + idx; | |
bFoundEntry = false; | |
$(retXml).find(entryIdx).each(function() { | |
bFoundEntry = true; | |
var startTime = $(this).find("start_time").text(); | |
var stopTime = $(this).find("stop_time").text(); | |
var destPort = $(this).find("src_dport").text(); | |
var destIp = $(this).find("dest_ip").text(); | |
var proto = $(this).find("proto").text(); | |
var enabled = $(this).find("enabled").text(); | |
var portMapEntryInfo = startTime + ";" + stopTime + ";" + destIp + ";" + destPort + ";" + proto + ";" + enabled; | |
var timeRange = startTime + "-" + stopTime; | |
var statusString; | |
if(0 == enabled) { | |
statusString = jQuery.i18n.prop("lt_optDisabledSwitch"); | |
} else { | |
statusString = jQuery.i18n.prop("lt_optEnableSwitch"); | |
} | |
var htmlTxt = "<tr style='cursor: pointer;'name='" + portMapEntryInfo + "'><td>" + timeRange + "</td><td>" | |
+ destIp + "</td><td>" + destPort + "</td><td>" + proto + "</td><td>" | |
+ statusString + "</td> <td><input type='checkbox'></td></tr>"; | |
$("#tbodyPortMap").append(htmlTxt); | |
}); | |
++idx; | |
$("tbody tr:last td:lt(5)").click(function() { | |
var entryIdx = $(this).parents("tr").prevAll("tr").length; | |
ModifyPortMapEntry(entryIdx); | |
}); | |
} | |
$("#DeleteAllIpEntry").click(function() { | |
if($(this).attr("checked")) { | |
$("tbody :checkbox").attr("checked",true); | |
} else { | |
$("tbody :checkbox").attr("checked",false); | |
} | |
if($("tbody :checked").length>0) { | |
$("#lt_portMap_btnDeletePortMap").show(); | |
} else { | |
$("#lt_portMap_btnDeletePortMap").hide(); | |
} | |
}); | |
$("tbody :checkbox").click(function() { | |
if($("tbody :checked").length == $("tbody tr").length) { | |
$("#DeleteAllIpEntry").attr("checked",true); | |
} else { | |
$("#DeleteAllIpEntry").attr("checked",false); | |
} | |
if($("tbody :checked").length>0) { | |
$("#lt_portMap_btnDeletePortMap").show(); | |
} else { | |
$("#lt_portMap_btnDeletePortMap").hide(); | |
} | |
}); | |
} | |
function ModifyPortMapEntry(entryIdx) { | |
ShowPortMapConfigDlg(); | |
var ipportMapIP_dest = $("#divportMapIP_dest").ip_address("divportMapIP_dest"); | |
var entryId = entryIdx + 1; | |
var selector = "tbody tr:eq(" + entryIdx+ ")"; | |
var portMapEntryInfo = $(selector).attr("name").split(";"); | |
SetTimeToElement("txtStartTime",portMapEntryInfo[0]); | |
SetTimeToElement("txtEndTime",portMapEntryInfo[1]); | |
ipportMapIP_dest.setIP(portMapEntryInfo[2]); | |
SetPortToElement("txtDestPort",portMapEntryInfo[3]); | |
$("#selPortMapProtocol").val(portMapEntryInfo[4]); | |
$("#selPortMapStatus").val(portMapEntryInfo[5]); | |
$("#lt_btnSave").click(function() { | |
var validateMsg = ValidatePortMapEntry(ipportMapIP_dest); | |
if("ok" != validateMsg) { | |
$("#lIpFilterSetError").show().text(validateMsg); | |
return; | |
} | |
if(portMapEntryInfo[0] == GetTimeFromElement("txtStartTime") && portMapEntryInfo[1] == GetTimeFromElement("txtEndTime") | |
&& portMapEntryInfo[2] == ipportMapIP_dest.getIP()&& portMapEntryInfo[3] == GetPortFromElement("txtDestPort") | |
&& portMapEntryInfo[4] == $("#selPortMapProtocol").val() && portMapEntryInfo[5] == $("#selPortMapStatus").val()) { | |
CloseDlg(); | |
return; | |
} | |
var preTag = "RGW/firewall/port_mapping/entry_list/entry_" + entryId; | |
var entryMap = new Map(); | |
entryMap.put(preTag+"/start_time",GetTimeFromElement("txtStartTime")); | |
entryMap.put(preTag+"/stop_time",GetTimeFromElement("txtEndTime")); | |
entryMap.put(preTag+"/dest_ip",ipportMapIP_dest.getIP()); | |
entryMap.put(preTag+"/src_dport", GetPortFromElement("txtDestPort")); | |
entryMap.put(preTag+"/proto", $("#selPortMapProtocol").val()); | |
entryMap.put(preTag+"/enabled", $("#selPortMapStatus").val()); | |
CloseDlg(); | |
var retXml = PostXml("firewall","edit_port_mapping_entry",entryMap); | |
if("OK" == $(retXml).find("setting_response").text()) { | |
GetFWPortMapInfo(); | |
} else { | |
alert("edit port mapping entry failed."); | |
} | |
});//$("#lt_btnSave").click(function(){ | |
} | |
function ShowPortMapConfigDlg() { | |
ShowDlg("divPortMapSetDlg",300,100); | |
$("[name='time']").keyup(function() { | |
$("#lIpFilterSetError").hide(); | |
if($(this).val().length == 2) { | |
$(this).nextAll(":eq(1)").focus(); | |
} | |
}); | |
} | |
function ValidatePortMapEntry(IPControl) { | |
if(!IsTime(GetTimeFromElement("txtStartTime")) || !IsTime(GetTimeFromElement("txtEndTime"))) { | |
return jQuery.i18n.prop("lt_TimeFormatError"); | |
} | |
if(!IPControl.validIPV4()) { | |
return jQuery.i18n.prop("lt_ipAddrFormatError"); | |
} | |
if(!IsPort(GetPortFromElement("txtDestPort"))) | |
return jQuery.i18n.prop("lt_PortFormatError"); | |
return "ok"; | |
} | |
return this; | |
} | |
})(jQuery); | |