Project

General

Profile

Download (18.3 KB) Statistics
| Branch: | Tag: | Revision:
1 d2cfb7a4 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_aliases_edit.php
5 2e9ab96b Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 d2cfb7a4 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 d2cfb7a4 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 d2cfb7a4 Scott Ullrich
18 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 d2cfb7a4 Scott Ullrich
22 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34 6b07c15a Matthew Grooms
##|+PRIV
35
##|*IDENT=page-firewall-alias-edit
36
##|*NAME=Firewall: Alias: Edit page
37
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
38
##|*MATCH=firewall_aliases_edit.php*
39
##|-PRIV
40
41
42 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Aliases","Edit");
43 5a1eebc7 Scott Ullrich
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45
46
if (!is_array($config['aliases']['alias']))
47
	$config['aliases']['alias'] = array();
48
49
aliases_sort();
50
$a_aliases = &$config['aliases']['alias'];
51
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55
56
if (isset($id) && $a_aliases[$id]) {
57
	$pconfig['name'] = $a_aliases[$id]['name'];
58 ba393f6c Scott Dale
	$pconfig['detail'] = $a_aliases[$id]['detail'];
59
	$pconfig['address'] = $a_aliases[$id]['address'];
60
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
61 e47c266d Scott Ullrich
62 cbe3ea96 Ermal Luçi
	/* optional if list */
63
	$iflist = get_configured_interface_with_descr(true, true);
64
	foreach ($iflist as $if => $ifdesc)
65
		if($ifdesc == $pconfig['descr']) 
66 e47c266d Scott Ullrich
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
67
68 ba393f6c Scott Dale
	$addresses = explode(' ', $pconfig['address']);
69
	$address = explode("/", $addresses[0]);
70
	if ($address[1])
71
		$addresssubnettest = true;
72 d89924da Bill Marquette
	else
73 ba393f6c Scott Dale
		$addresssubnettest = false;	
74
	
75
	if ($addresssubnettest)
76 5b237745 Scott Ullrich
		$pconfig['type'] = "network";
77
	else
78 ba393f6c Scott Dale
		if (is_ipaddr($address[0]))
79 d89924da Bill Marquette
			$pconfig['type'] = "host";
80
		else
81
			$pconfig['type'] = "port";
82 5a1eebc7 Scott Ullrich
83
	if($a_aliases[$id]['aliasurl'] <> "") {
84
		$pconfig['type'] = "url";
85
		if(is_array($a_aliases[$id]['aliasurl'])) {
86
			$isfirst = 0;
87
			$pconfig['address'] = "";
88
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
89
				if($isfirst == 1)
90
					$pconfig['address'] .= " ";
91
				$isfirst = 1;
92
				$pconfig['address'] .= $aa;
93
			}
94
		} else {
95
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
96
		}
97
	}
98 5b237745 Scott Ullrich
}
99
100
if ($_POST) {
101
102
	unset($input_errors);
103
	$pconfig = $_POST;
104
105
	/* input validation */
106 d27d8cdc Scott Ullrich
	if(strtolower($_POST['name']) == "pptp")
107 4fdff4ae Scott Ullrich
		$input_errors[] = gettext("Aliases may not be named PPTP.");
108 0cd7ed19 Scott Ullrich
109 0df6adf8 Bill Marquette
	$x = is_validaliasname($_POST['name']);
110
	if (!isset($x)) {
111
		$input_errors[] = "Reserved word used for alias name.";
112
	} else {
113
		if (is_validaliasname($_POST['name']) == false)
114 d87fc50b Seth Mos
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
115 beeef1f0 Bill Marquette
	}
116 5b237745 Scott Ullrich
	/* check for name conflicts */
117
	foreach ($a_aliases as $alias) {
118
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
119
			continue;
120
121
		if ($alias['name'] == $_POST['name']) {
122
			$input_errors[] = "An alias with this name already exists.";
123
			break;
124
		}
125
	}
126 5a1eebc7 Scott Ullrich
127 cfa466bb Scott Ullrich
	/* check for name interface description conflicts */
128
	foreach($config['interfaces'] as $interface) {
129
		if($interface['descr'] == $_POST['name']) {
130 5a1eebc7 Scott Ullrich
			$input_errors[] = "An interface description with this name already exists.";
131
			break;
132 cfa466bb Scott Ullrich
		}
133 5a1eebc7 Scott Ullrich
	}
134 ba393f6c Scott Dale
	
135
	$alias = array();
136
	$alias['name'] = $_POST['name'];
137
	if($_POST['type'] == "url") {
138
		$address = "";
139 d2cfb7a4 Scott Ullrich
		$isfirst = 0;
140 ba393f6c Scott Dale
		$address_count = 2;
141
142
		/* item is a url type */
143 d8898df4 Scott Ullrich
		for($x=0; isset($_POST['address'. $x]); $x++) {
144 ba393f6c Scott Dale
			if($_POST['address' . $x]) {
145
				/* fetch down and add in */
146
				$isfirst = 0;
147
				$temp_filename = tempnam("/tmp/", "alias_import");
148
				unlink($temp_filename);
149
				$fda = fopen("/tmp/tmpfetch","w");
150
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
151
				fclose($fda);
152
				mwexec("mkdir -p {$temp_filename}");
153
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
154
				/* if the item is tar gzipped then extract */
155
				if(stristr($_POST['address' . $x], ".tgz"))
156
					process_alias_tgz($temp_filename);
157
				if(file_exists("{$temp_filename}/aliases")) {
158
					$file_contents = file_get_contents("{$temp_filename}/aliases");
159
					$file_contents = str_replace("#", "\n#", $file_contents);
160
					$file_contents_split = split("\n", $file_contents);
161
					foreach($file_contents_split as $fc) {
162
						$tmp = trim($fc);
163
						if(stristr($fc, "#")) {
164
							$tmp_split = split("#", $tmp);
165
							$tmp = trim($tmp_split[0]);
166 5a1eebc7 Scott Ullrich
						}
167 ba393f6c Scott Dale
						if(trim($tmp) <> "") {
168
							if($isfirst == 1)
169
								$address .= " ";
170
							$address .= $tmp;
171
							$isfirst = 1;
172 5a1eebc7 Scott Ullrich
						}
173 ba393f6c Scott Dale
					}
174
					if($isfirst == 0) {
175
						/* nothing was found */
176
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
177 5a1eebc7 Scott Ullrich
						$dont_update = true;
178
						break;
179
					}
180 ba393f6c Scott Dale
					$alias['aliasurl'][] = $_POST['address' . $x];
181
					mwexec("/bin/rm -rf {$temp_filename}");
182
				} else {
183
					$input_errors[] = "You must provide a valid URL.";
184
					$dont_update = true;
185
					break;
186 5a1eebc7 Scott Ullrich
				}
187
			}
188 ba393f6c Scott Dale
		}
189
	} else {
190 b6f3005c Ermal Luçi
		$address = "";
191
		$isfirst = 0;
192 ba393f6c Scott Dale
		/* item is a normal alias type */
193 a2d8d3dd Ermal Luçi
		for($x=0; $x<4999; $x++) {
194 b6f3005c Ermal Luçi
			if($_POST["address{$x}"] <> "") {
195
				if ($isfirst > 0)
196
					$address .= " ";
197
				$address .= $_POST["address{$x}"];
198
				if($_POST["address_subnet{$x}"] <> "") 
199
					$address .= "/" . $_POST["address_subnet{$x}"];
200
201
	       			if($_POST["detail{$x}"] <> "") {
202
	       				$final_address_details .= $_POST["detail{$x}"];
203
	       			} else {
204
		       			$final_address_details .= "Entry added" . " ";
205
		       			$final_address_details .= date('r');
206
	       			}
207
	       			$final_address_details .= "||";
208
				$isfirst++;
209 d2cfb7a4 Scott Ullrich
			}
210
		}
211 ba393f6c Scott Dale
	}
212 d2cfb7a4 Scott Ullrich
213 ba393f6c Scott Dale
	if (!$input_errors) {
214
		$alias['address'] = $address;
215 ec3cedf7 Bill Marquette
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
216 ba393f6c Scott Dale
		$alias['type'] = $_POST['type'];
217
		$alias['detail'] = $final_address_details;
218 d2cfb7a4 Scott Ullrich
219 ba393f6c Scott Dale
		if (isset($id) && $a_aliases[$id])
220
			$a_aliases[$id] = $alias;
221
		else
222
			$a_aliases[] = $alias;
223 a18b6b97 Scott Ullrich
224 ba393f6c Scott Dale
		touch($d_aliasesdirty_path);
225 a18b6b97 Scott Ullrich
226 ba393f6c Scott Dale
		write_config();
227
		filter_configure();
228 d2cfb7a4 Scott Ullrich
229 ba393f6c Scott Dale
		header("Location: firewall_aliases.php");
230
		exit;		
231
	}
232
	//we received input errors, copy data to prevent retype
233
	else
234
	{
235 ec3cedf7 Bill Marquette
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
236 ba393f6c Scott Dale
		$pconfig['address'] = $address;
237
		$pconfig['type'] = $_POST['type'];
238 ec3cedf7 Bill Marquette
		$pconfig['detail'] = $final_address_details;
239 5b237745 Scott Ullrich
	}
240
}
241 da7ae7ef Bill Marquette
242
include("head.inc");
243
244 5a1eebc7 Scott Ullrich
$jscriptstr = <<<EOD
245 da7ae7ef Bill Marquette
246 5a1eebc7 Scott Ullrich
<script type="text/javascript">
247 5b237745 Scott Ullrich
function typesel_change() {
248
	switch (document.iform.type.selectedIndex) {
249
		case 0:	/* host */
250 d2cfb7a4 Scott Ullrich
			var cmd;
251 5a1eebc7 Scott Ullrich
252 b6f3005c Ermal Luçi
			newrows = totalrows;
253
			for(i=0; i<newrows; i++) {
254 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
255
				eval(comd);
256
				comd = 'document.iform.address_subnet' + i + '.value = "";';
257
				eval(comd);
258 d2cfb7a4 Scott Ullrich
			}
259 5b237745 Scott Ullrich
			break;
260
		case 1:	/* network */
261 d2cfb7a4 Scott Ullrich
			var cmd;
262 5a1eebc7 Scott Ullrich
263 b6f3005c Ermal Luçi
			newrows = totalrows;
264
			for(i=0; i<newrows; i++) {
265 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
266
				eval(comd);
267 d2cfb7a4 Scott Ullrich
			}
268 5b237745 Scott Ullrich
			break;
269 4d6b6263 Scott Ullrich
		case 2:	/* port */
270
			var cmd;
271 5a1eebc7 Scott Ullrich
272 b6f3005c Ermal Luçi
			newrows = totalrows;
273
			for(i=0; i<newrows; i++) {
274 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
275
				eval(comd);
276
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
277
				eval(comd);
278
			}
279
			break;
280 cd35a596 Scott Ullrich
		case 3:	/* OpenVPN Users */
281 5a1eebc7 Scott Ullrich
			var cmd;
282 cd35a596 Scott Ullrich
283 b6f3005c Ermal Luçi
			newrows = totalrows;
284
			for(i=0; i<newrows; i++) {
285 cd35a596 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
286
				eval(comd);
287
				comd = 'document.iform.address_subnet' + i + '.value = "";';
288 5a1eebc7 Scott Ullrich
				eval(comd);
289 4d6b6263 Scott Ullrich
			}
290
			break;
291 6e7e1814 Scott Ullrich
292 cd35a596 Scott Ullrich
		case 4:	/* url */
293 6e7e1814 Scott Ullrich
			var cmd;
294 b6f3005c Ermal Luçi
			newrows = totalrows;
295
			for(i=0; i<newrows; i++) {
296 6e7e1814 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
297
				eval(comd);
298
			}
299
			break;
300 5b237745 Scott Ullrich
	}
301
}
302 d2cfb7a4 Scott Ullrich
303 5a1eebc7 Scott Ullrich
EOD;
304
305
$network_str = gettext("Network");
306
$networks_str = gettext("Network(s)");
307
$cidr_str = gettext("CIDR");
308
$description_str = gettext("Description");
309
$hosts_str = gettext("Host(s)");
310
$ip_str = gettext("IP");
311
$ports_str = gettext("Port(s)");
312
$port_str = gettext("Port");
313
$url_str = gettext("URL");
314
$update_freq_str = gettext("Update Freq.");
315
316 974ff781 Chris Buechler
$networks_help = gettext("Networks are specified in CIDR format.  Select the CIDR mask that pertains to each entry. /32 specifies a single host, /24 specifies 255.255.255.0, etc. Hostnames (FQDNs) may also be specified, using a /32 mask.");
317
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
318 5a1eebc7 Scott Ullrich
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
319
$url_help = gettext("Enter as many urls as you wish.  Also set the time that you would like the url refreshed in days.  After saving {$g['product_name']} will download the URL and import the items into the alias.");
320
321 3ebd97eb Scott Ullrich
$openvpn_str = gettext("Username");
322
$openvpn_user_str = gettext("OpenVPN Users");
323
$openvpn_help = gettext("Enter as many usernames as you wish.");
324 4c743413 Scott Ullrich
$openvpn_freq = gettext("");
325 3ebd97eb Scott Ullrich
326 5a1eebc7 Scott Ullrich
$jscriptstr .= <<<EOD
327
328 d2cfb7a4 Scott Ullrich
function update_box_type() {
329
	var indexNum = document.forms[0].type.selectedIndex;
330
	var selected = document.forms[0].type.options[indexNum].text;
331 5a1eebc7 Scott Ullrich
	if(selected == '{$networks_str}') {
332
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
333
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
334
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
335
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
336
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
337
	} else if(selected == '{$hosts_str}') {
338
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
339
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
340
		document.getElementById ("twocolumn").firstChild.data = "";
341
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
342
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
343
	} else if(selected == '{$ports_str}') {
344
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
345
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
346
		document.getElementById ("twocolumn").firstChild.data = "";
347
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
348
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
349
	} else if(selected == '{$url_str}') {
350
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
351
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
352
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
353
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
354
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
355 6e7e1814 Scott Ullrich
	} else if(selected == '{$openvpn_user_str}') {
356
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
357 3ebd97eb Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
358 4c743413 Scott Ullrich
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
359 6e7e1814 Scott Ullrich
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
360 3ebd97eb Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
361 d2cfb7a4 Scott Ullrich
	}
362
}
363 5b237745 Scott Ullrich
</script>
364
365 66138bf6 Scott Dale
EOD;
366 d2cfb7a4 Scott Ullrich
367 5a1eebc7 Scott Ullrich
?>
368 d2cfb7a4 Scott Ullrich
369 5a1eebc7 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
370
<?php
371
	include("fbegin.inc");
372
	echo $jscriptstr;
373
?>
374
375 625dcc40 Bill Marquette
<script type="text/javascript" src="/javascript/row_helper.js">
376 5a1eebc7 Scott Ullrich
</script>
377 d2cfb7a4 Scott Ullrich
378 5a1eebc7 Scott Ullrich
<input type='hidden' name='address_type' value='textbox' />
379
<input type='hidden' name='address_subnet_type' value='select' />
380 d2cfb7a4 Scott Ullrich
381 5a1eebc7 Scott Ullrich
<script type="text/javascript">
382
	rowname[0] = "address";
383
	rowtype[0] = "textbox";
384
	rowsize[0] = "30";
385 d2cfb7a4 Scott Ullrich
386 5a1eebc7 Scott Ullrich
	rowname[1] = "address_subnet";
387
	rowtype[1] = "select";
388
	rowsize[1] = "1";
389 d2cfb7a4 Scott Ullrich
390 5a1eebc7 Scott Ullrich
	rowname[2] = "detail";
391
	rowtype[2] = "textbox";
392 b6f3005c Ermal Luçi
	rowsize[2] = "50";
393 d2cfb7a4 Scott Ullrich
</script>
394
395 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
396 5a1eebc7 Scott Ullrich
<div id="inputerrors"></div>
397
398
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
399
<table width="100%" border="0" cellpadding="6" cellspacing="0">
400 c823d56b Scott Ullrich
  <tr>
401
	<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
402
  </tr>
403 a18b6b97 Scott Ullrich
<?php if(is_alias_inuse($pconfig['name']) == true): ?>
404 5a1eebc7 Scott Ullrich
  <tr>
405
    <td valign="top" class="vncellreq">Name</td>
406
    <td class="vtable"> <input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
407 a18b6b97 Scott Ullrich
		  <?php echo $pconfig['name']; ?>
408 5a1eebc7 Scott Ullrich
      <p>
409
        <span class="vexpl">NOTE: This alias is in use so the name may not be modified!</span>
410
      </p>
411
    </td>
412
  </tr>
413 a18b6b97 Scott Ullrich
<?php else: ?>
414 5a1eebc7 Scott Ullrich
  <tr>
415
    <td valign="top" class="vncellreq">Name</td>
416
    <td class="vtable">
417 b5c78501 Seth Mos
      <input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
418 5a1eebc7 Scott Ullrich
      <br />
419
      <span class="vexpl">
420
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
421
      </span>
422
    </td>
423
  </tr>
424 a18b6b97 Scott Ullrich
<?php endif; ?>
425 5a1eebc7 Scott Ullrich
  <tr>
426
    <td width="22%" valign="top" class="vncell">Description</td>
427
    <td width="78%" class="vtable">
428 b5c78501 Seth Mos
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
429 5a1eebc7 Scott Ullrich
      <br />
430
      <span class="vexpl">
431
        You may enter a description here for your reference (not parsed).
432
      </span>
433
    </td>
434
  </tr>
435
  <tr>
436
    <td valign="top" class="vncellreq">Type</td>
437
    <td class="vtable">
438
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
439
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
440
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
441
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
442 b6f3005c Ermal Luçi
        <option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
443 5a1eebc7 Scott Ullrich
      </select>
444
    </td>
445
  </tr>
446
  <tr>
447
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
448
    <td width="78%" class="vtable">
449
      <table id="maintable">
450
        <tbody>
451
          <tr>
452
            <td colspan="4">
453
      		    <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">Item information</div>
454
            </td>
455
          </tr>
456
          <tr>
457
            <td><div id="onecolumn">Network</div></td>
458
            <td><div id="twocolumn">CIDR</div></td>
459
           <td><div id="threecolumn">Description</div></td>
460
          </tr>
461 d2cfb7a4 Scott Ullrich
462 0d3f3e90 Ermal Luçi
	<?php
463
	$counter = 0;
464
	$address = $pconfig['address'];
465
	if ($address <> "") {
466
		$item = explode(" ", $address);
467
		$item3 = explode("||", $pconfig['detail']);
468
		foreach($item as $ww) {
469
			$address = $item[$counter];
470
			$address_subnet = "";
471
			$item2 = explode("/", $address);
472
			foreach($item2 as $current) {
473
				if($item2[1] <> "") {
474
					$address = $item2[0];
475
					$address_subnet = $item2[1];
476 d2cfb7a4 Scott Ullrich
				}
477 0d3f3e90 Ermal Luçi
			}
478
			$item4 = $item3[$counter];
479
			$tracker = $counter;
480
	?>
481 5a1eebc7 Scott Ullrich
          <tr>
482
            <td>
483 b5c78501 Seth Mos
              <input name="address<?php echo $tracker; ?>" type="text" class="formfld unknown" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
484 5a1eebc7 Scott Ullrich
            </td>
485
            <td>
486
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
487
			          <option></option>
488
			          <?php for ($i = 32; $i >= 1; $i--): ?>
489
			          <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
490
			          <?php endfor; ?>
491
			        </select>
492
			      </td>
493
            <td>
494 b5c78501 Seth Mos
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
495 5a1eebc7 Scott Ullrich
            </td>
496
            <td>
497 b6f3005c Ermal Luçi
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
498
	      </td>
499 5a1eebc7 Scott Ullrich
          </tr>
500 0d3f3e90 Ermal Luçi
<?php
501
        	$counter++;
502 5a1eebc7 Scott Ullrich
503 0d3f3e90 Ermal Luçi
       		} // end foreach
504
	} // end if
505
?>
506 5a1eebc7 Scott Ullrich
        </tbody>
507
        <tfoot>
508
509
        </tfoot>
510
		  </table>
511
			<a onclick="javascript:addRowTo('maintable'); typesel_change(); return false;" href="#">
512
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
513
      </a>
514
		</td>
515
  </tr>
516
  <tr>
517
    <td width="22%" valign="top">&nbsp;</td>
518
    <td width="78%">
519
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
520 b6f3005c Ermal Luçi
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
521 5a1eebc7 Scott Ullrich
      <?php if (isset($id) && $a_aliases[$id]): ?>
522
      <input name="id" type="hidden" value="<?=$id;?>" />
523
      <?php endif; ?>
524
    </td>
525
  </tr>
526
</table>
527 5b237745 Scott Ullrich
</form>
528 5a1eebc7 Scott Ullrich
529
<script type="text/javascript">
530
	field_counter_js = 3;
531
	rows = 1;
532
	totalrows = <?php echo $counter; ?>;
533
	loaded = <?php echo $counter; ?>;
534
	typesel_change();
535
	update_box_type();
536 5b237745 Scott Ullrich
</script>
537 5a1eebc7 Scott Ullrich
538 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
539
</body>
540
</html>
541 5a1eebc7 Scott Ullrich
542
<?php
543
function process_alias_tgz($temp_filename) {
544
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
545
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
546
	unlink("{$temp_filename}/aliases.tgz");
547
	$files_to_process = return_dir_as_array("{$temp_filename}/");
548
	/* foreach through all extracted files and build up aliases file */
549
	$fd = fopen("{$temp_filename}/aliases", "a");
550
	foreach($files_to_process as $f2p) {
551
		$file_contents = file_get_contents($f2p);
552
		fwrite($fd, $file_contents);
553
		unlink($f2p);
554
	}
555
	fclose($fd);
556
}
557
?>