b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 |
|
| 2 | (function($) {
|
| 3 |
|
| 4 | $.fn.objWifiPortMap = function() {
|
| 5 |
|
| 6 | this.onLoad = function(flag) {
|
| 7 | if(flag) {
|
| 8 | LoadWebPage("html/wifi/wifiPortMap.html");
|
| 9 |
|
| 10 | $("#lt_portMap_btnAddPortMap").click(function() {
|
| 11 | AddPortMapEntry();
|
| 12 | });
|
| 13 |
|
| 14 | $("#lt_portMap_btnDeletePortMap").click(function() {
|
| 15 | DelPortMapEntry();
|
| 16 | });
|
| 17 |
|
| 18 | } //end flag
|
| 19 |
|
| 20 | GetFWPortMapInfo();
|
| 21 | }
|
| 22 |
|
| 23 | function DelPortMapEntry() {
|
| 24 | var entryIdxList = "";
|
| 25 | $("tbody tr td :checked").each(function() {
|
| 26 | var entryIdx = $(this).parents("tr").prevAll("tr").length + 1;
|
| 27 | entryIdxList = entryIdxList + entryIdx + ",";
|
| 28 | });
|
| 29 |
|
| 30 | if(""==entryIdxList) {
|
| 31 | return;
|
| 32 | }
|
| 33 |
|
| 34 | var entryMap = new Map();
|
| 35 | entryMap.put("RGW/firewall/del_port_mapping_index",entryIdxList);
|
| 36 | var retXml = PostXml("firewall","delete_port_mapping_entry",entryMap);
|
| 37 | if("OK" == $(retXml).find("setting_response").text()) {
|
| 38 | GetFWPortMapInfo();
|
| 39 | } else {
|
| 40 | alert("delete port map entry failed.");
|
| 41 | }
|
| 42 | }
|
| 43 |
|
| 44 |
|
| 45 | function AddPortMapEntry() {
|
| 46 | ShowPortMapConfigDlg();
|
| 47 | var ipportMapIP_dest = $("#divportMapIP_dest").ip_address("divportMapIP_dest");
|
| 48 | $("#lt_btnSave").click(function() {
|
| 49 | var validateMsg = ValidatePortMapEntry(ipportMapIP_dest);
|
| 50 | if("ok" != validateMsg) {
|
| 51 | $("#lIpFilterSetError").show().text(validateMsg);
|
| 52 | return;
|
| 53 | }
|
| 54 |
|
| 55 | var entryId = $("tbody tr").size() + 1;
|
| 56 | var preTag = "RGW/firewall/port_mapping/entry_list/entry_" + entryId;
|
| 57 | var entryMap = new Map();
|
| 58 | entryMap.put(preTag+"/start_time",GetTimeFromElement("txtStartTime"));
|
| 59 | entryMap.put(preTag+"/stop_time",GetTimeFromElement("txtEndTime"));
|
| 60 | entryMap.put(preTag+"/dest_ip", ipportMapIP_dest.getIP());
|
| 61 | entryMap.put(preTag+"/src_dport", GetPortFromElement("txtDestPort"));
|
| 62 | entryMap.put(preTag+"/proto", $("#selPortMapProtocol").val());
|
| 63 | entryMap.put(preTag+"/enabled", $("#selPortMapStatus").val());
|
| 64 |
|
| 65 | CloseDlg();
|
| 66 | var retXml = PostXml("firewall","add_port_mapping_entry",entryMap);
|
| 67 | if("OK" == $(retXml).find("setting_response").text()) {
|
| 68 | GetFWPortMapInfo();
|
| 69 | } else {
|
| 70 | alert("add port map entry failed.");
|
| 71 | }
|
| 72 | });
|
| 73 | }
|
| 74 |
|
| 75 |
|
| 76 | function GetFWPortMapInfo() {
|
| 77 | $("#tbodyPortMap").empty();
|
| 78 | $("#DeleteAllIpEntry").attr("checked",false);
|
| 79 | $("#lt_portMap_btnDeletePortMap").hide();
|
| 80 |
|
| 81 | var retXml = PostXml("firewall","fw_get_port_mapping_info");
|
| 82 |
|
| 83 | var bFoundEntry = true;
|
| 84 | var idx = 1;
|
| 85 | while(bFoundEntry) {
|
| 86 | var entryIdx = "entry_" + idx;
|
| 87 | bFoundEntry = false;
|
| 88 | $(retXml).find(entryIdx).each(function() {
|
| 89 | bFoundEntry = true;
|
| 90 | var startTime = $(this).find("start_time").text();
|
| 91 | var stopTime = $(this).find("stop_time").text();
|
| 92 | var destPort = $(this).find("src_dport").text();
|
| 93 | var destIp = $(this).find("dest_ip").text();
|
| 94 | var proto = $(this).find("proto").text();
|
| 95 | var enabled = $(this).find("enabled").text();
|
| 96 | var portMapEntryInfo = startTime + ";" + stopTime + ";" + destIp + ";" + destPort + ";" + proto + ";" + enabled;
|
| 97 |
|
| 98 | var timeRange = startTime + "-" + stopTime;
|
| 99 | var statusString;
|
| 100 | if(0 == enabled) {
|
| 101 | statusString = jQuery.i18n.prop("lt_optDisabledSwitch");
|
| 102 | } else {
|
| 103 | statusString = jQuery.i18n.prop("lt_optEnableSwitch");
|
| 104 | }
|
| 105 |
|
| 106 | var htmlTxt = "<tr style='cursor: pointer;'name='" + portMapEntryInfo + "'><td>" + timeRange + "</td><td>"
|
| 107 | + destIp + "</td><td>" + destPort + "</td><td>" + proto + "</td><td>"
|
| 108 | + statusString + "</td> <td><input type='checkbox'></td></tr>";
|
| 109 | $("#tbodyPortMap").append(htmlTxt);
|
| 110 | });
|
| 111 | ++idx;
|
| 112 | $("tbody tr:last td:lt(5)").click(function() {
|
| 113 | var entryIdx = $(this).parents("tr").prevAll("tr").length;
|
| 114 | ModifyPortMapEntry(entryIdx);
|
| 115 | });
|
| 116 | }
|
| 117 |
|
| 118 | $("#DeleteAllIpEntry").click(function() {
|
| 119 | if($(this).attr("checked")) {
|
| 120 | $("tbody :checkbox").attr("checked",true);
|
| 121 | } else {
|
| 122 | $("tbody :checkbox").attr("checked",false);
|
| 123 | }
|
| 124 | if($("tbody :checked").length>0) {
|
| 125 | $("#lt_portMap_btnDeletePortMap").show();
|
| 126 | } else {
|
| 127 | $("#lt_portMap_btnDeletePortMap").hide();
|
| 128 | }
|
| 129 | });
|
| 130 |
|
| 131 | $("tbody :checkbox").click(function() {
|
| 132 | if($("tbody :checked").length == $("tbody tr").length) {
|
| 133 | $("#DeleteAllIpEntry").attr("checked",true);
|
| 134 | } else {
|
| 135 | $("#DeleteAllIpEntry").attr("checked",false);
|
| 136 | }
|
| 137 | if($("tbody :checked").length>0) {
|
| 138 | $("#lt_portMap_btnDeletePortMap").show();
|
| 139 | } else {
|
| 140 | $("#lt_portMap_btnDeletePortMap").hide();
|
| 141 | }
|
| 142 | });
|
| 143 | }
|
| 144 |
|
| 145 | function ModifyPortMapEntry(entryIdx) {
|
| 146 | ShowPortMapConfigDlg();
|
| 147 | var ipportMapIP_dest = $("#divportMapIP_dest").ip_address("divportMapIP_dest");
|
| 148 | var entryId = entryIdx + 1;
|
| 149 | var selector = "tbody tr:eq(" + entryIdx+ ")";
|
| 150 | var portMapEntryInfo = $(selector).attr("name").split(";");
|
| 151 |
|
| 152 | SetTimeToElement("txtStartTime",portMapEntryInfo[0]);
|
| 153 | SetTimeToElement("txtEndTime",portMapEntryInfo[1]);
|
| 154 |
|
| 155 | ipportMapIP_dest.setIP(portMapEntryInfo[2]);
|
| 156 | SetPortToElement("txtDestPort",portMapEntryInfo[3]);
|
| 157 |
|
| 158 | $("#selPortMapProtocol").val(portMapEntryInfo[4]);
|
| 159 | $("#selPortMapStatus").val(portMapEntryInfo[5]);
|
| 160 |
|
| 161 | $("#lt_btnSave").click(function() {
|
| 162 | var validateMsg = ValidatePortMapEntry(ipportMapIP_dest);
|
| 163 | if("ok" != validateMsg) {
|
| 164 | $("#lIpFilterSetError").show().text(validateMsg);
|
| 165 | return;
|
| 166 | }
|
| 167 |
|
| 168 | if(portMapEntryInfo[0] == GetTimeFromElement("txtStartTime") && portMapEntryInfo[1] == GetTimeFromElement("txtEndTime")
|
| 169 | && portMapEntryInfo[2] == ipportMapIP_dest.getIP()&& portMapEntryInfo[3] == GetPortFromElement("txtDestPort")
|
| 170 | && portMapEntryInfo[4] == $("#selPortMapProtocol").val() && portMapEntryInfo[5] == $("#selPortMapStatus").val()) {
|
| 171 | CloseDlg();
|
| 172 | return;
|
| 173 | }
|
| 174 |
|
| 175 | var preTag = "RGW/firewall/port_mapping/entry_list/entry_" + entryId;
|
| 176 | var entryMap = new Map();
|
| 177 | entryMap.put(preTag+"/start_time",GetTimeFromElement("txtStartTime"));
|
| 178 | entryMap.put(preTag+"/stop_time",GetTimeFromElement("txtEndTime"));
|
| 179 | entryMap.put(preTag+"/dest_ip",ipportMapIP_dest.getIP());
|
| 180 | entryMap.put(preTag+"/src_dport", GetPortFromElement("txtDestPort"));
|
| 181 |
|
| 182 | entryMap.put(preTag+"/proto", $("#selPortMapProtocol").val());
|
| 183 | entryMap.put(preTag+"/enabled", $("#selPortMapStatus").val());
|
| 184 |
|
| 185 | CloseDlg();
|
| 186 | var retXml = PostXml("firewall","edit_port_mapping_entry",entryMap);
|
| 187 | if("OK" == $(retXml).find("setting_response").text()) {
|
| 188 | GetFWPortMapInfo();
|
| 189 | } else {
|
| 190 | alert("edit port mapping entry failed.");
|
| 191 | }
|
| 192 | });//$("#lt_btnSave").click(function(){
|
| 193 | }
|
| 194 |
|
| 195 | function ShowPortMapConfigDlg() {
|
| 196 | ShowDlg("divPortMapSetDlg",300,100);
|
| 197 | $("[name='time']").keyup(function() {
|
| 198 | $("#lIpFilterSetError").hide();
|
| 199 | if($(this).val().length == 2) {
|
| 200 | $(this).nextAll(":eq(1)").focus();
|
| 201 | }
|
| 202 | });
|
| 203 |
|
| 204 | }
|
| 205 |
|
| 206 | function ValidatePortMapEntry(IPControl) {
|
| 207 | if(!IsTime(GetTimeFromElement("txtStartTime")) || !IsTime(GetTimeFromElement("txtEndTime"))) {
|
| 208 | return jQuery.i18n.prop("lt_TimeFormatError");
|
| 209 | }
|
| 210 | if(!IPControl.validIPV4()) {
|
| 211 | return jQuery.i18n.prop("lt_ipAddrFormatError");
|
| 212 | }
|
| 213 | if(!IsPort(GetPortFromElement("txtDestPort")))
|
| 214 | return jQuery.i18n.prop("lt_PortFormatError");
|
| 215 |
|
| 216 | return "ok";
|
| 217 | }
|
| 218 |
|
| 219 |
|
| 220 | return this;
|
| 221 | }
|
| 222 | })(jQuery);
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|