<commit_before>#!/usr/local/bin/php
<?php
/* $Id$ */
/*
	interfaces_opt.php
	part of m0n0wall (http://m0n0.ch/wall)

	Copyright (C) 2003-2004 <NAME> <<EMAIL>>.
	All rights reserved.

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

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

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

require("guiconfig.inc");

unset($index);
if ($_GET['index'])
	$index = $_GET['index'];
else if ($_POST['index'])
	$index = $_POST['index'];

if (!$index)
	exit;

$optcfg = &$config['interfaces']['opt' . $index];
$optcfg['descr'] = str_replace(" ", "_", $optcfg['descr']);

$pconfig['descr'] = str_replace(" ", "_", $optcfg['descr']);
$pconfig['bridge'] = $optcfg['bridge'];

$pconfig['bandwidth'] = $optcfg['bandwidth'];
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];

$pconfig['enable'] = isset($optcfg['enable']);

$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
$pconfig['spoofmac'] = $optcfg['spoofmac'];
$pconfig['mtu'] = $optcfg['mtu'];

/* Wireless interface? */
if (isset($optcfg['wireless'])) {
	require("interfaces_wlan.inc");
	wireless_config_init();
}

if ($optcfg['ipaddr'] == "dhcp") {
	$pconfig['type'] = "DHCP";
} else {
	$pconfig['type'] = "Static";
	$pconfig['ipaddr'] = $optcfg['ipaddr'];
	$pconfig['subnet'] = $optcfg['subnet'];
	$pconfig['gateway'] = $optcfg['gateway'];
	$pconfig['pointtopoint'] = $optcfg['pointtopoint'];
}

if ($_POST) {

	unset($input_errors);

	/* filter out spaces from descriptions  */
	$POST['descr'] = str_replace(" ", "_", $POST['descr']);

	$pconfig = $_POST;

	/* input validation */
	if ($_POST['enable']) {

		/* description unique? */
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
			if ($i != $index) {
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
					$input_errors[] = "An interface with the specified description already exists.";
				}
			}
		}

		if ($_POST['bridge']) {
			/* double bridging? */
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
				if ($i != $index) {
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
						$input_errors[] = "Optional interface {$i} " .
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
							"the specified interface.";
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
						$input_errors[] = "Optional interface {$i} " .
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
							"this interface.";
					}
				}
			}
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
				$input_errors[] = "The specified interface is already bridged to " .
					"another interface.";
			}
			/* captive portal on? */
			if (isset($config['captiveportal']['enable'])) {
				$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
			}
		} else {
			$reqdfields = explode(" ", "descr");
			$reqdfieldsn = explode(",", "Description");

			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);

			if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
				$input_errors[] = "A valid IP address must be specified.";
			}
			if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
				$input_errors[] = "A valid subnet bit count must be specified.";
			}
		}
	}

	/* Wireless interface? */
	if (isset($optcfg['wireless'])) {
		$wi_input_errors = wireless_config_post();
		if ($wi_input_errors) {
			$input_errors = array_merge($input_errors, $wi_input_errors);
		}
	}

	if (!$input_errors) {

		$optcfg['descr'] = str_replace(" ", "_", $_POST['descr']);
		$optcfg['bridge'] = $_POST['bridge'];
		$optcfg['enable'] = $_POST['enable'] ? true : false;
		
		if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
			$optcfg['bandwidth'] = $_POST['bandwidth'];
			$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
		} else {
			unset($optcfg['bandwidth']);
			unset($optcfg['bandwidthtype']);
		}
<commit_msg>Remove non alpha characters from interface descriptions<commit_after>#!/usr/local/bin/php
<?php
/* $Id$ */
/*
	interfaces_opt.php
	part of m0n0wall (http://m0n0.ch/wall)

	Copyright (C) 2003-2004 <NAME> <<EMAIL>>.
	All rights reserved.

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

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

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

require("guiconfig.inc");

unset($index);
if ($_GET['index'])
	$index = $_GET['index'];
else if ($_POST['index'])
	$index = $_POST['index'];

if (!$index)
	exit;

function remove_bad_chars($string) {
	return preg_replace('/[^a-z]/i','',$string);
}

$optcfg = &$config['interfaces']['opt' . $index];
$optcfg['descr'] = remove_bad_chars($optcfg['descr']);

$pconfig['descr'] = $optcfg['descr'];
$pconfig['bridge'] = $optcfg['bridge'];

$pconfig['bandwidth'] = $optcfg['bandwidth'];
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];

$pconfig['enable'] = isset($optcfg['enable']);

$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
$pconfig['spoofmac'] = $optcfg['spoofmac'];
$pconfig['mtu'] = $optcfg['mtu'];

/* Wireless interface? */
if (isset($optcfg['wireless'])) {
	require("interfaces_wlan.inc");
	wireless_config_init();
}

if ($optcfg['ipaddr'] == "dhcp") {
	$pconfig['type'] = "DHCP";
} else {
	$pconfig['type'] = "Static";
	$pconfig['ipaddr'] = $optcfg['ipaddr'];
	$pconfig['subnet'] = $optcfg['subnet'];
	$pconfig['gateway'] = $optcfg['gateway'];
	$pconfig['pointtopoint'] = $optcfg['pointtopoint'];
}

if ($_POST) {

	unset($input_errors);

	/* filter out spaces from descriptions  */
	$POST['descr'] = remove_bad_chars($POST['descr']);

	$pconfig = $_POST;

	/* input validation */
	if ($_POST['enable']) {

		/* description unique? */
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
			if ($i != $index) {
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
					$input_errors[] = "An interface with the specified description already exists.";
				}
			}
		}

		if ($_POST['bridge']) {
			/* double bridging? */
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
				if ($i != $index) {
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
						$input_errors[] = "Optional interface {$i} " .
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
							"the specified interface.";
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
						$input_errors[] = "Optional interface {$i} " .
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
							"this interface.";
					}
				}
			}
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
				$input_errors[] = "The specified interface is already bridged to " .
					"another interface.";
			}
			/* captive portal on? */
			if (isset($config['captiveportal']['enable'])) {
				$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
			}
		} else {
			$reqdfields = explode(" ", "descr");
			$reqdfieldsn = explode(",", "Description");

			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);

			if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
				$input_errors[] = "A valid IP address must be specified.";
			}
			if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
				$input_errors[] = "A valid subnet bit count must be specified.";
			}
		}
	}

	/* Wireless interface? */
	if (isset($optcfg['wireless'])) {
		$wi_input_errors = wireless_config_post();
		if ($wi_input_errors) {
			$input_errors = array_merge($input_errors, $wi_input_errors);
		}
	}

	if (!$input_errors) {

		$optcfg['descr'] = remove_bad_chars($_POST['descr']);
		$optcfg['bridge'] = $_POST['bridge'];
		$optcfg['enable'] = $_POST['enable'] ? true : false;
		
		if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
			$optcfg['bandwidth'] = $_POST['bandwidth'];
			$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
		} else {
			unset($optcfg['bandwidth']);
			unset($optcfg['bandwidthtype']);
		}

{'fraction_non_alphanumeric': 0.18950749464668093, 'fraction_numerical': 0.003114658360911038, 'mean_word_length': 4.614754098360656, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607791', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3327, 'n_words': 878}