Commit b0aa1be3 authored by Franco Fichtner's avatar Franco Fichtner

www: more cleanups possible for #1733

parent 8ad27fbe
......@@ -30,10 +30,6 @@
require_once("guiconfig.inc");
require_once("interfaces.inc");
// init $config['virtualip']['vip']
if ( !isset($config['virtualip']['vip']) || !is_array($config['virtualip']['vip'])) {
$config['virtualip']['vip'] = array();
}
$a_vip = &config_read_array('virtualip', 'vip');
$act = null;
......
......@@ -100,8 +100,8 @@ function easyrule_block_rule_exists($int = 'wan', $ipproto = "inet") {
return false;
}
function easyrule_block_rule_create($int = 'wan', $ipproto = "inet") {
global $config;
function easyrule_block_rule_create($int = 'wan', $ipproto = "inet")
{
$blockaliasname = 'EasyRuleBlockHosts';
/* If the alias doesn't exist, exit.
* Can't create an empty alias, and we don't know a host */
......@@ -114,13 +114,9 @@ function easyrule_block_rule_create($int = 'wan', $ipproto = "inet") {
return true;
}
/* No rules, start a new array */
if (!is_array($config['filter']['rule'])) {
$config['filter']['rule'] = array();
}
$a_filter = &config_read_array('filter', 'rule');
filter_rules_sort();
$a_filter = &config_read_array('filter', 'rule');
/* Make up a new rule */
$filterent = array();
......@@ -157,8 +153,8 @@ function easyrule_block_alias_getid($int = 'wan')
return false;
}
function easyrule_block_alias_add($host, $int = 'wan') {
global $config;
function easyrule_block_alias_add($host, $int = 'wan')
{
$blockaliasname = 'EasyRuleBlockHosts';
/* If the host isn't a valid IP address, bail */
$host = trim($host, "[]");
......@@ -166,13 +162,6 @@ function easyrule_block_alias_add($host, $int = 'wan') {
return false;
}
/* If there are no aliases, start an array */
if (!isset($config['aliases']) || !is_array($config['aliases'])) {
$config['aliases'] = array();
}
if (!isset($config['aliases']['alias'])) {
$config['aliases']['alias'] = array();
}
$a_aliases = &config_read_array('aliases', 'alias');
/* Try to get the ID if the alias already exists */
......@@ -269,16 +258,11 @@ function easyrule_block_host_add($host, $int = 'wan', $ipproto = "inet") {
}
}
function easyrule_pass_rule_add($int, $proto, $srchost, $dsthost, $dstport, $ipproto) {
global $config;
/* No rules, start a new array */
if (!isset($config['filter']['rule'])) {
$config['filter']['rule'] = array();
}
function easyrule_pass_rule_add($int, $proto, $srchost, $dsthost, $dstport, $ipproto)
{
$a_filter = &config_read_array('filter', 'rule');
filter_rules_sort();
$a_filter = &config_read_array('filter', 'rule');
/* Make up a new rule */
$filterent = array();
......
......@@ -29,12 +29,7 @@
require_once("guiconfig.inc");
if (!isset($config['aliases']) || !is_array($config['aliases'])) {
$config['aliases'] = array();
}
if (!isset($config['aliases']['alias'])) {
$config['aliases']['alias'] = array();
}
config_read_array('aliases', 'alias');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// initialize form vars
......
......@@ -37,10 +37,8 @@ if (isset($_REQUEST['closenotice'])) {
exit;
}
##if no config entry found, initialize config entry
if (empty($config['widgets']) || !is_array($config['widgets'])) {
$config['widgets'] = array();
}
// if no config entry found, initialize config entry
config_read_array('widgets');
$widgetCollection = array();
......
......@@ -32,13 +32,6 @@ require_once("system.inc");
require_once("interfaces.inc");
require_once("services.inc");
if (!isset($config['bridges']) || !is_array($config['bridges'])) {
$config['bridges'] = array();
}
if (!isset($config['bridges']['bridged']) || !is_array($config['bridges']['bridged'])) {
$config['bridges']['bridged'] = array();
}
$a_bridges = &config_read_array('bridges', 'bridged');
// interface list
......
......@@ -121,12 +121,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
}
if (empty($config['dhcpd'][$if])) {
$config['dhcpd'][$if] = array();
}
if (empty($config['dhcpd'][$if]['pool'])) {
$config['dhcpd'][$if]['pool'] = array();
}
$a_pools = &config_read_array('dhcpd', $if, 'pool');
if (!empty($_GET['act'])) {
......@@ -179,12 +173,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pool = $_POST['pool'];
}
}
if (empty($config['dhcpd'][$if])) {
$config['dhcpd'][$if] = array();
}
if (empty($config['dhcpd'][$if]['pool'])) {
$config['dhcpd'][$if]['pool'] = array();
}
$a_pools = &config_read_array('dhcpd', $if, 'pool');
if (!empty($_POST['act'])) {
......
......@@ -86,6 +86,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
// handle identifiers and actions
if (!empty($pconfig['if']) && !empty($config['interfaces'][$pconfig['if']])) {
$if = $pconfig['if'];
......@@ -93,15 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!empty($config['dhcpd'][$if]['staticmap'][$pconfig['id']])) {
$id = $pconfig['id'];
}
if (empty($config['dhcpd'])) {
$config['dhcpd'] = array();
}
if (empty($config['dhcpd'][$if])) {
$config['dhcpd'][$if] = array();
}
if (empty($config['dhcpd'][$if]['staticmap'])) {
$config['dhcpd'][$if]['staticmap'] = array();
}
$a_maps = &config_read_array('dhcpd', $if, 'staticmap');
$input_errors = array();
......
......@@ -237,13 +237,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
if (count($input_errors) == 0) {
config_read_array('dhcpdv6', $if);
$dhcpdconf = array();
if (empty($config['dhcpdv6']) || !is_array($config['dhcpdv6'])) {
$config['dhcpdv6'] = array();
}
if (empty($config['dhcpdv6'][$if]) || !is_array($config['dhcpdv6'][$if])) {
$config['dhcpdv6'][$if] = array();
}
// simple 1-on-1 copy
$config_copy_fieldsnames = array('defaultleasetime', 'maxleasetime', 'netmask', 'domain', 'domainsearchlist',
......
......@@ -64,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input_errors = array();
$pconfig = $_POST;
// handle identifiers and actions
if (!empty($pconfig['if']) && !empty($config['interfaces'][$pconfig['if']])) {
$if = $pconfig['if'];
......@@ -71,15 +72,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!empty($config['dhcpdv6'][$if]['staticmap'][$pconfig['id']])) {
$id = $pconfig['id'];
}
if (empty($config['dhcpdv6']) || !is_array($config['dhcpdv6'])) {
$config['dhcpdv6'] = array();
}
if (empty($config['dhcpdv6'][$if]) || !is_array($config['dhcpdv6'][$if])) {
$config['dhcpdv6'][$if] = array();
}
if (empty($config['dhcpdv6'][$if]['staticmap']) || !is_array($config['dhcpdv6'][$if]['staticmap'])) {
$config['dhcpdv6'][$if]['staticmap'] = array();
}
config_read_array('dhcpdv6', $if, 'staticmap');
/* input validation */
$reqdfields = explode(" ", "duid");
$reqdfieldsn = array(gettext("DUID Identifier"));
......
......@@ -33,13 +33,8 @@ require_once("filter.inc");
require_once("services.inc");
require_once("system.inc");
if (empty($config['dnsmasq']['hosts']) || !is_array($config['dnsmasq']['hosts'])) {
$config['dnsmasq']['hosts'] = array();
}
if (empty($config['dnsmasq']['domainoverrides']) || !is_array($config['dnsmasq']['domainoverrides'])) {
$config['dnsmasq']['domainoverrides'] = array();
}
config_read_array('dnsmasq', 'hosts');
config_read_array('dnsmasq', 'domainoverrides');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
......
......@@ -34,9 +34,7 @@ require_once("system.inc");
require_once("interfaces.inc");
require_once("plugins.inc.d/ntpd.inc");
if (!isset($config['ntpd']['gps'])) {
$config['ntpd']['gps'] = array();
}
config_read_array('ntpd', 'gps');
$copy_fields = array('port', 'type', 'speed', 'nmea', 'fudge1', 'fudge2', 'stratum', 'prefer', 'noselect',
'flag1', 'flag2', 'flag3', 'flag4', 'subsec', 'refid', 'initcmd');
......
......@@ -33,12 +33,7 @@ require_once("system.inc");
require_once("interfaces.inc");
require_once("plugins.inc.d/ntpd.inc");
if (!isset($config['ntpd']) || !is_array($config['ntpd'])) {
$config['ntpd'] = array();
}
if (!isset($config['ntpd']['pps'])) {
$config['ntpd']['pps'] = array();
}
config_read_array('ntpd', 'pps');
$copy_fields = array('port', 'fudge1', 'stratum', 'flag2', 'flag3', 'flag4', 'refid');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
......
......@@ -32,9 +32,7 @@ require_once("system.inc");
require_once("services.inc");
require_once("interfaces.inc");
if (empty($config['opendns']) || !is_array($config['opendns'])) {
$config['opendns'] = array();
}
config_read_array('opendns');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig['enable'] = isset($config['opendns']['enable']);
......
......@@ -120,9 +120,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
if (count($input_errors) == 0) {
if (!is_array($config['dhcpdv6'][$if])) {
$config['dhcpdv6'][$if] = array();
}
config_read_array('dhcpdv6', $if);
$config['dhcpdv6'][$if]['ramode'] = $pconfig['ramode'];
$config['dhcpdv6'][$if]['rapriority'] = $pconfig['rapriority'];
......
......@@ -31,9 +31,7 @@ require_once("guiconfig.inc");
require_once("system.inc");
require_once("services.inc");
if(empty($config['unbound']) || !is_array($config['unbound'])) {
$config['unbound'] = array();
}
config_read_array('unbound');
$copy_fields = array(
'cache_max_ttl',
......
......@@ -34,6 +34,8 @@ require_once("system.inc");
require_once("interfaces.inc");
$a_hosts = &config_read_array('unbound', 'hosts');
config_read_array('unbound', 'domainoverrides');
/* Backwards compatibility for records created before introducing RR types. */
foreach ($a_hosts as $i => $hostent) {
if (!isset($hostent['rr'])) {
......@@ -41,10 +43,6 @@ foreach ($a_hosts as $i => $hostent) {
}
}
if (empty($config['unbound']['domainoverrides']) || !is_array($config['unbound']['domainoverrides'])) {
$config['unbound']['domainoverrides'] = array();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
if (!empty($pconfig['apply'])) {
......
......@@ -27,19 +27,15 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("auth.inc");
$authFactory = new \OPNsense\Auth\AuthenticationFactory();
$authCNFOptions = $authFactory->listConfigOptions();
if (!isset($config['system']['authserver'])) {
$config['system']['authserver'] = array();
}
if (empty($config['ca']) || !is_array($config['ca'])) {
$config['ca'] = array();
}
config_read_array('system', 'authserver');
config_read_array('ca');
$a_servers = auth_get_authserver_list();
$a_server = array();
......
......@@ -150,12 +150,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} elseif (isset($id) && isset($pconfig['act']) && $pconfig['act'] == "toggle") {
// Toggle active/in-active
$realid = $a_gateways[$id]['attribute'];
if (!is_array($config['gateways'])) {
$config['gateways'] = array();
}
if (!is_array($config['gateways']['gateway_item'])) {
$config['gateways']['gateway_item'] = array();
}
$a_gateway_item = &config_read_array('gateways', 'gateway_item');
if (isset($a_gateway_item[$realid]['disabled'])) {
......
......@@ -321,13 +321,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
if (count($input_errors) == 0) {
if (!isset($config['gateways']) || !is_array($config['gateways'])) {
$config['gateways'] = array();
}
if (!isset($config['gateways']['gateway_item']) || !is_array($config['gateways']['gateway_item'])) {
$config['gateways']['gateway_item'] = array();
}
// A result of obfuscating the list of gateways is that over here we need to map things back that should
// be aligned with the configuration. Not going to fix this now.
if (isset($a_gateways[$id]['attribute']) && is_numeric($a_gateways[$id]['attribute']) ) {
......
......@@ -33,15 +33,8 @@ require_once("filter.inc");
require_once("services.inc");
require_once("interfaces.inc");
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
$config['ipsec'] = array();
}
if (!is_array($config['ipsec']['mobilekey'])) {
$config['ipsec']['mobilekey'] = array();
} else {
ipsec_mobilekey_sort();
}
config_read_array('ipsec', 'mobilekey');
ipsec_mobilekey_sort();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['act']) && isset($_POST['id']) && is_numericint($_POST['id']) && $_POST['act'] == "del") {
......
......@@ -32,15 +32,8 @@ require_once("interfaces.inc");
require_once("services.inc");
require_once("plugins.inc.d/ipsec.inc");
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
$config['ipsec'] = array();
}
if (!isset($config['ipsec']['mobilekey'])) {
$config['ipsec']['mobilekey'] = array();
} else {
ipsec_mobilekey_sort();
}
config_read_aray('ipsec', 'mobilekey');
ipsec_mobilekey_sort();
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
......
......@@ -33,17 +33,8 @@ require_once("filter.inc");
require_once("services.inc");
require_once("plugins.inc.d/ipsec.inc");
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
$config['ipsec'] = array();
}
if (!isset($config['ipsec']['phase1'])) {
$config['ipsec']['phase1'] = array();
}
if (!isset($config['ipsec']['client'])) {
$config['ipsec']['client'] = array();
}
config_read_array('ipsec', 'client');
config_read_array('ipsec', 'phase1');
// define formfields
$form_fields = "user_source,group_source,pool_address,pool_netbits,net_list
......
......@@ -130,17 +130,8 @@ function getIndexByUniqueId($uniqid)
return $p2index;
}
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
$config['ipsec'] = array();
}
if (!isset($config['ipsec']['client'])) {
$config['ipsec']['client'] = array();
}
if (!isset($config['ipsec']['phase2'])) {
$config['ipsec']['phase2'] = array();
}
config_read_array('ipsec', 'client');
config_read_array('ipsec', 'phase2');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// lookup p2index
......
......@@ -33,9 +33,7 @@ require_once("plugins.inc.d/ipsec.inc");
require_once("services.inc");
require_once("interfaces.inc");
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
$config['ipsec'] = array();
}
config_read_array('ipsec');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// fetch form data
......
......@@ -31,9 +31,7 @@
require_once("guiconfig.inc");
require_once("interfaces.inc");
if (!isset($config['virtualip']['vip'])) {
$config['virtualip']['vip'] = array();
}
config_read_array('virtualip', 'vip');
?>
<table class="table table-striped table-condensed">
......
......@@ -27,6 +27,8 @@
require_once("guiconfig.inc");
config_read_array('widgets', 'thermal_sensors_widget');
function validate_temp_value($value)
{
if (is_numeric($value) && (int)$value == $value && $value >= 0 and $value <= 100) {
......@@ -45,10 +47,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig[$fieldname] = !empty($config['widgets']['thermal_sensors_widget'][$fieldname]) ? $config['widgets']['thermal_sensors_widget'][$fieldname] : $defaultValue;
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
// save widget config
if (empty($config['widgets']['thermal_sensors_widget']) || !is_array($config['widgets']['thermal_sensors_widget'])) {
$config['widgets']['thermal_sensors_widget'] = array();
}
foreach ($fieldnames as $fieldname) {
$defaultValue = strpos($fieldname, 'critical') !== false ? 80 : 70;
$newValue = !empty($_POST[$fieldname]) ? $_POST[$fieldname] : "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment