Project

General

Profile

Download (19.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_aliases_edit.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
##|+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
$pgtitle = array("Firewall","Aliases","Edit");
43

    
44
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
	$pconfig['detail'] = $a_aliases[$id]['detail'];
59
	$pconfig['address'] = $a_aliases[$id]['address'];
60
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
61

    
62
	/* optional if list */
63
	$iflist = get_configured_interface_with_descr(true, true);
64
	foreach ($iflist as $if => $ifdesc)
65
		if($ifdesc == $pconfig['descr']) 
66
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
67

    
68
	$addresses = explode(' ', $pconfig['address']);
69
	$address = explode("/", $addresses[0]);
70
	if ($address[1])
71
		$addresssubnettest = true;
72
	else
73
		$addresssubnettest = false;	
74
	
75
	if ($addresssubnettest)
76
		$pconfig['type'] = "network";
77
	else
78
		if (is_ipaddr($address[0]))
79
			$pconfig['type'] = "host";
80
		else
81
			$pconfig['type'] = "port";
82

    
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
}
99

    
100
if ($_POST) {
101

    
102
	unset($input_errors);
103
	$pconfig = $_POST;
104

    
105
	/* input validation */
106
	if(strtolower($_POST['name']) == "pptp")
107
		$input_errors[] = gettext("Aliases may not be named PPTP.");
108

    
109
	$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
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
115
	}
116
	/* 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

    
127
	/* check for name interface description conflicts */
128
	foreach($config['interfaces'] as $interface) {
129
		if($interface['descr'] == $_POST['name']) {
130
			$input_errors[] = "An interface description with this name already exists.";
131
			break;
132
		}
133
	}
134
	
135
	$alias = array();
136
	$alias['name'] = $_POST['name'];
137
	if($_POST['type'] == "url") {
138
		$address = "";
139
		$isfirst = 0;
140
		$address_count = 2;
141

    
142
		/* item is a url type */
143
		for($x=0; isset($_POST['address'. $x]); $x++) {
144
			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
						}
167
						if(trim($tmp) <> "") {
168
							if($isfirst == 1)
169
								$address .= " ";
170
							$address .= $tmp;
171
							$isfirst = 1;
172
						}
173
					}
174
					if($isfirst == 0) {
175
						/* nothing was found */
176
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
177
						$dont_update = true;
178
						break;
179
					}
180
					$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
				}
187
			}
188
		}
189
	} else {
190
		$address = "";
191
		$isfirst = 0;
192
		/* item is a normal alias type */
193
		for($x=0; $x<4999; $x++) {
194
			if($_POST["address{$x}"] <> "") {
195
				if ($isfirst > 0)
196
					$address .= " ";
197
				$address .= $_POST["address{$x}"];
198
				if(is_ipaddr($_POST["address{$x}"]) && $_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
			}
210
		}
211
	}
212

    
213
	if (!$input_errors) {
214
		$alias['address'] = $address;
215
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
216
		$alias['type'] = $_POST['type'];
217
		$alias['detail'] = $final_address_details;
218

    
219
		if (isset($id) && $a_aliases[$id])
220
			$a_aliases[$id] = $alias;
221
		else
222
			$a_aliases[] = $alias;
223

    
224
		mark_subsystem_dirty('aliases');
225

    
226
		write_config();
227
		filter_configure();
228

    
229
		header("Location: firewall_aliases.php");
230
		exit;		
231
	}
232
	//we received input errors, copy data to prevent retype
233
	else
234
	{
235
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
236
		$pconfig['address'] = $address;
237
		$pconfig['type'] = $_POST['type'];
238
		$pconfig['detail'] = $final_address_details;
239
	}
240
}
241

    
242
include("head.inc");
243

    
244
$jscriptstr = <<<EOD
245

    
246
<script type="text/javascript">
247

    
248
var objAlias = new Array(4999);
249
function typesel_change() {
250
	switch (document.iform.type.selectedIndex) {
251
		case 0:	/* host */
252
			var cmd;
253

    
254
			newrows = totalrows;
255
			for(i=0; i<newrows; i++) {
256
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
257
				eval(comd);
258
				comd = 'document.iform.address_subnet' + i + '.value = "";';
259
				eval(comd);
260
			}
261
			break;
262
		case 1:	/* network */
263
			var cmd;
264

    
265
			newrows = totalrows;
266
			for(i=0; i<newrows; i++) {
267
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
268
				eval(comd);
269
			}
270
			break;
271
		case 2:	/* port */
272
			var cmd;
273

    
274
			newrows = totalrows;
275
			for(i=0; i<newrows; i++) {
276
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
277
				eval(comd);
278
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
279
				eval(comd);
280
			}
281
			break;
282
		case 3:	/* OpenVPN Users */
283
			var cmd;
284

    
285
			newrows = totalrows;
286
			for(i=0; i<newrows; i++) {
287
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
288
				eval(comd);
289
				comd = 'document.iform.address_subnet' + i + '.value = "";';
290
				eval(comd);
291
			}
292
			break;
293

    
294
		case 4:	/* url */
295
			var cmd;
296
			newrows = totalrows;
297
			for(i=0; i<newrows; i++) {
298
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
299
				eval(comd);
300
			}
301
			break;
302
	}
303
}
304

    
305
function add_alias_control() {
306
	var name = "address" + (totalrows - 1);
307
	obj = document.getElementById(name);
308
	obj.setAttribute('class', 'formfldalias');
309
	obj.setAttribute('autocomplete', 'off');
310
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
311
}
312
EOD;
313

    
314
$network_str = gettext("Network");
315
$networks_str = gettext("Network(s)");
316
$cidr_str = gettext("CIDR");
317
$description_str = gettext("Description");
318
$hosts_str = gettext("Host(s)");
319
$ip_str = gettext("IP");
320
$ports_str = gettext("Port(s)");
321
$port_str = gettext("Port");
322
$url_str = gettext("URL");
323
$update_freq_str = gettext("Update Freq.");
324

    
325
$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.");
326
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
327
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
328
$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.");
329

    
330
$openvpn_str = gettext("Username");
331
$openvpn_user_str = gettext("OpenVPN Users");
332
$openvpn_help = gettext("Enter as many usernames as you wish.");
333
$openvpn_freq = gettext("");
334

    
335
$jscriptstr .= <<<EOD
336

    
337
function update_box_type() {
338
	var indexNum = document.forms[0].type.selectedIndex;
339
	var selected = document.forms[0].type.options[indexNum].text;
340
	if(selected == '{$networks_str}') {
341
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
342
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
343
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
344
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
345
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
346
	} else if(selected == '{$hosts_str}') {
347
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
348
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
349
		document.getElementById ("twocolumn").firstChild.data = "";
350
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
351
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
352
	} else if(selected == '{$ports_str}') {
353
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
354
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
355
		document.getElementById ("twocolumn").firstChild.data = "";
356
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
357
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
358
	} else if(selected == '{$url_str}') {
359
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
360
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
361
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
362
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
363
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
364
	} else if(selected == '{$openvpn_user_str}') {
365
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
366
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
367
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
368
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
369
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
370
	}
371
}
372
</script>
373

    
374
EOD;
375

    
376
?>
377

    
378
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
379
<?php
380
	include("fbegin.inc");
381
	echo $jscriptstr;
382
?>
383

    
384
<script type="text/javascript" src="/javascript/row_helper.js">
385
</script>
386
<script type="text/javascript" src="/javascript/autosuggest.js">
387
</script>
388
<script type="text/javascript" src="/javascript/suggestions.js">
389
</script>
390

    
391
<input type='hidden' name='address_type' value='textbox' />
392
<input type='hidden' name='address_subnet_type' value='select' />
393

    
394
<script type="text/javascript">
395
	rowname[0] = "address";
396
	rowtype[0] = "textbox";
397
	rowsize[0] = "30";
398

    
399
	rowname[1] = "address_subnet";
400
	rowtype[1] = "select";
401
	rowsize[1] = "1";
402

    
403
	rowname[2] = "detail";
404
	rowtype[2] = "textbox";
405
	rowsize[2] = "50";
406
</script>
407

    
408
<?php if ($input_errors) print_input_errors($input_errors); ?>
409
<div id="inputerrors"></div>
410

    
411
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
412
<table width="100%" border="0" cellpadding="6" cellspacing="0">
413
  <tr>
414
	<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
415
  </tr>
416
<?php if(is_alias_inuse($pconfig['name']) == true): ?>
417
  <tr>
418
    <td valign="top" class="vncellreq">Name</td>
419
    <td class="vtable"> <input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
420
		  <?php echo $pconfig['name']; ?>
421
      <p>
422
        <span class="vexpl">NOTE: This alias is in use so the name may not be modified!</span>
423
      </p>
424
    </td>
425
  </tr>
426
<?php else: ?>
427
  <tr>
428
    <td valign="top" class="vncellreq">Name</td>
429
    <td class="vtable">
430
      <input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
431
      <br />
432
      <span class="vexpl">
433
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
434
      </span>
435
    </td>
436
  </tr>
437
<?php endif; ?>
438
  <tr>
439
    <td width="22%" valign="top" class="vncell">Description</td>
440
    <td width="78%" class="vtable">
441
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
442
      <br />
443
      <span class="vexpl">
444
        You may enter a description here for your reference (not parsed).
445
      </span>
446
    </td>
447
  </tr>
448
  <tr>
449
    <td valign="top" class="vncellreq">Type</td>
450
    <td class="vtable">
451
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
452
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
453
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
454
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
455
        <option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
456
      </select>
457
    </td>
458
  </tr>
459
  <tr>
460
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
461
    <td width="78%" class="vtable">
462
      <table id="maintable">
463
        <tbody>
464
          <tr>
465
            <td colspan="4">
466
      		    <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>
467
            </td>
468
          </tr>
469
          <tr>
470
            <td><div id="onecolumn">Network</div></td>
471
            <td><div id="twocolumn">CIDR</div></td>
472
           <td><div id="threecolumn">Description</div></td>
473
          </tr>
474

    
475
	<?php
476
	$counter = 0;
477
	$address = $pconfig['address'];
478
	if ($address <> "") {
479
		$item = explode(" ", $address);
480
		$item3 = explode("||", $pconfig['detail']);
481
		foreach($item as $ww) {
482
			$address = $item[$counter];
483
			$address_subnet = "";
484
			$item2 = explode("/", $address);
485
			foreach($item2 as $current) {
486
				if($item2[1] <> "") {
487
					$address = $item2[0];
488
					$address_subnet = $item2[1];
489
				}
490
			}
491
			$item4 = $item3[$counter];
492
			$tracker = $counter;
493
	?>
494
          <tr>
495
            <td>
496
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
497
            </td>
498
            <td>
499
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
500
			          <option></option>
501
			          <?php for ($i = 32; $i >= 1; $i--): ?>
502
			          <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
503
			          <?php endfor; ?>
504
			        </select>
505
			      </td>
506
            <td>
507
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
508
            </td>
509
            <td>
510
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
511
	      </td>
512
          </tr>
513
<?php
514
        	$counter++;
515

    
516
       		} // end foreach
517
	} // end if
518
?>
519
        </tbody>
520
        <tfoot>
521

    
522
        </tfoot>
523
		  </table>
524
			<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
525
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
526
      </a>
527
		</td>
528
  </tr>
529
  <tr>
530
    <td width="22%" valign="top">&nbsp;</td>
531
    <td width="78%">
532
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
533
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
534
      <?php if (isset($id) && $a_aliases[$id]): ?>
535
      <input name="id" type="hidden" value="<?=$id;?>" />
536
      <?php endif; ?>
537
    </td>
538
  </tr>
539
</table>
540
</form>
541

    
542
<script type="text/javascript">
543
	field_counter_js = 3;
544
	rows = 1;
545
	totalrows = <?php echo $counter; ?>;
546
	loaded = <?php echo $counter; ?>;
547
	typesel_change();
548
	update_box_type();
549

    
550
<?php
551
        $isfirst = 0;
552
        $aliases = "";
553
        $addrisfirst = 0;
554
        $aliasesaddr = "";
555
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
556
                foreach($config['aliases']['alias'] as $alias_name) {
557
			if($addrisfirst == 1) $aliasesaddr .= ",";
558
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
559
			$addrisfirst = 1;
560
                }
561
?>
562

    
563
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
564
        var customarray=new Array(<?php echo $aliases; ?>);
565

    
566
<?php  
567
	for ($jv = 0; $jv < $counter; $jv++)
568
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
569
?>
570

    
571

    
572
</script>
573

    
574
<?php include("fend.inc"); ?>
575
</body>
576
</html>
577

    
578
<?php
579
function process_alias_tgz($temp_filename) {
580
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
581
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
582
	unlink("{$temp_filename}/aliases.tgz");
583
	$files_to_process = return_dir_as_array("{$temp_filename}/");
584
	/* foreach through all extracted files and build up aliases file */
585
	$fd = fopen("{$temp_filename}/aliases", "a");
586
	foreach($files_to_process as $f2p) {
587
		$file_contents = file_get_contents($f2p);
588
		fwrite($fd, $file_contents);
589
		unlink($f2p);
590
	}
591
	fclose($fd);
592
}
593
?>
(47-47/218)