Project

General

Profile

« Previous | Next » 

Revision 00bcbdd0

Added by Bill Marquette over 20 years ago

inbound nat can now be reordered

View differences:

usr/local/www/firewall_nat.php
37 37
	$config['nat']['rule'] = array();
38 38
	
39 39
$a_nat = &$config['nat']['rule'];
40
nat_rules_sort();
40
//nat_rules_sort();
41 41

  
42 42
if ($_POST) {
43 43

  
......
68 68
	}
69 69
}
70 70

  
71
if ($_GET['act'] == "del") {
72
	if ($a_nat[$_GET['id']]) {
73
		unset($a_nat[$_GET['id']]);
74
		write_config();
75
		touch($d_natconfdirty_path);
76
		header("Location: firewall_nat.php");
77
		exit;
78
	}
71
if (isset($_POST['del_x'])) {
72
        /* delete selected rules */
73
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
74
                foreach ($_POST['rule'] as $rulei) {
75
                        unset($a_nat[$rulei]);
76
                }
77
                write_config();
78
                touch($d_natconfdirty_path);
79
                header("Location: firewall_nat.php");
80
                exit;
81
        }
82

  
83
} else {
84
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
85
        unset($movebtn);
86
        foreach ($_POST as $pn => $pd) {
87
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
88
                        $movebtn = $matches[1];
89
                        break;
90
                }
91
        }
92
        /* move selected rules before this rule */
93
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
94
                $a_nat_new = array();
95

  
96
                /* copy all rules < $movebtn and not selected */
97
                for ($i = 0; $i < $movebtn; $i++) {
98
                        if (!in_array($i, $_POST['rule']))
99
                                $a_nat_new[] = $a_nat[$i];
100
                }
101

  
102
                /* copy all selected rules */
103
                for ($i = 0; $i < count($a_nat); $i++) {
104
                        if ($i == $movebtn)
105
                                continue;
106
                        if (in_array($i, $_POST['rule']))
107
                                $a_nat_new[] = $a_nat[$i];
108
                }
109

  
110
                /* copy $movebtn rule */
111
                if ($movebtn < count($a_nat))
112
                        $a_nat_new[] = $a_nat[$movebtn];
113

  
114
                /* copy all rules > $movebtn and not selected */
115
                for ($i = $movebtn+1; $i < count($a_nat); $i++) {
116
                        if (!in_array($i, $_POST['rule']))
117
                                $a_nat_new[] = $a_nat[$i];
118
                }
119
                $a_nat = $a_nat_new;
120
                write_config();
121
                touch($d_natconfdirty_path);
122
                header("Location: firewall_nat.php");
123
                exit;
124
        }
79 125
}
126

  
80 127
?>
81 128
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
82 129
<html>
......
89 136
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90 137
<?php include("fbegin.inc"); ?>
91 138
<p class="pgtitle">Firewall: NAT: Inbound</font></p>
92
<form action="firewall_nat.php" method="post">
139
<form action="firewall_nat.php" method="post" name="iform">
140
<script type="text/javascript" language="javascript" src="row_toggle.js">
141
</script>
93 142
<?php if ($savemsg) print_info_box($savemsg); ?>
94 143
<?php if (file_exists($d_natconfdirty_path)): ?><p>
95 144
<?php print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
......
108 157
  <tr>
109 158
    <td class="tabcont">
110 159
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
111
                <tr>
160
                <tr id="frheader">
161
		  <td width="3%" class="list">&nbsp;</td>
162
                  <td width="3%" class="list">&nbsp;</td>
112 163
                  <td width="5%" class="listhdrr">If</td>
113 164
                  <td width="5%" class="listhdrr">Proto</td>
114 165
                  <td width="20%" class="listhdrr">Ext. port range</td>
......
116 167
                  <td width="20%" class="listhdrr">Int. port range</td>
117 168
                  <td width="20%" class="listhdr">Description</td>
118 169
                  <td width="5%" class="list"></td>
119
				</tr>
120
			  <?php $i = 0; foreach ($a_nat as $natent): ?>
121
                <tr valign="top">
122
				  <td class="listlr">
123
                  <?php
124
						if (!$natent['interface'] || ($natent['interface'] == "wan"))
125
							echo "WAN";
126
						else
127
							echo "<font color=\"#FFFFFF\">" . htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
128
				  ?>
170
		</tr>
171
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
172
                <tr valign="top" id="fr<?=$nnats;?>">
173
                  <td class="listt"><input type="checkbox" id="frc<?=$nnats;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nnats;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
174
                  <td class="listt" align="center"></td>
175
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>">
176
                    <?php
177
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
178
				echo "WAN";
179
			else
180
				echo "<font color=\"#FFFFFF\">" . htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
181
		    ?>
129 182
                  </td>
130
                  <td class="listr">
183
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>">
131 184
                    <?=strtoupper($natent['protocol']);?>
132 185
                  </td>
133
                  <td class="listr">
186
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>">
134 187
                    <?php
135 188
						list($beginport, $endport) = split("-", $natent['external-port']);
136 189
						if ((!$endport) || ($beginport == $endport)) {
......
141 194
							echo $beginport . " - " . $endport;
142 195
				  ?>
143 196
                  </td>
144
                  <td class="listr">
197
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>">
145 198
                    <?=$natent['target'];?>
146 199
					<?php if ($natent['external-address'])
147 200
						echo "<br>(ext.: " . $natent['external-address'] . ")";
148 201
					?>
149 202
                  </td>
150
                  <td class="listr">
203
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>">
151 204
                    <?php if ((!$endport) || ($beginport == $endport)) {
152 205
				  			echo $natent['local-port'];
153 206
							if ($wkports[$natent['local-port']])
......
160 213
                  <td class="listbg"><font color="#FFFFFFF">
161 214
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
162 215
                  </td>
163
                  <td valign="middle" class="list" nowrap> <a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
164
                     &nbsp;<a href="firewall_nat.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this rule?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
165
				</tr>
166
			  <?php $i++; endforeach; ?>
216
                  <td valign="middle" class="list" nowrap>
217
                    <table border="0" cellspacing="0" cellpadding="1">
218
                      <tr>
219
                        <td><a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
220
                      </tr>
221
                      <tr>
222
                        <td><input onmouseover="fr_insline(<?=$nnats;?>, true)" onmouseout="fr_insline(<?=$nnats;?>, false)" name="move_<?=$i;?>" src="left.gif" title="move selected rules before this rule" height="17" type="image" width="17" border="0"></td>
223
                        <!-- <billm><td><a href="firewall_nat_out_edit.php?dup=<?=$i;?>"><img src="plus.gif" title="add a new nat based on this one" width="17" height="17" border="0"></a></td><billm> -->
224
                      </tr>
225
                    </table>
226
		</tr>
227
  	     <?php $i++; $nnats++; endforeach; ?>
167 228
                <tr>
168
                  <td class="list" colspan="6"></td>
169
                  <td class="list"> <a href="firewall_nat_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
170
				</tr>
171
              </table>
229
                  <td class="list" colspan="8"></td>
230
                  <td class="list" valign="middle" nowrap>
231
                    <table border="0" cellspacing="0" cellpadding="1">
232
                      <tr>
233
                        <td><?php if ($nnats == 0): ?><img src="left_d.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="left.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php endif; ?></td>
234
                        <td><a href="firewall_nat_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
235
                      </tr>
236
                      <tr>
237
                        <td><?php if ($nnats == 0): ?><img src="x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="x.gif" width="17" height="17" title="delete selected mappings" onclick="return confirm('Do you really want to delete the selected mappings?')"><?php endif; ?></td>
238
                      </tr>
239
                    </table></td>
240
                </tr>              </table>
172 241
                    <p><span class="vexpl"><span class="red"><strong>Note:<br>
173 242
                      </strong></span>It is not possible to access NATed services
174 243
                      using the WAN IP address from within LAN (or an optional

Also available in: Unified diff