Skip to content

Commit

Permalink
www: more cleanups possible for #1733
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Jul 22, 2017
1 parent 8ad27fb commit b0aa1be
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 180 deletions.
4 changes: 0 additions & 4 deletions src/www/carp_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 8 additions & 24 deletions src/www/diag_logs_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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();
Expand Down Expand Up @@ -157,22 +153,15 @@ 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, "[]");
if (!is_ipaddr($host) && !is_subnet($host)) {
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 */
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions src/www/firewall_aliases_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
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();

Expand Down
7 changes: 0 additions & 7 deletions src/www/interfaces_bridge_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
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
Expand Down
13 changes: 1 addition & 12 deletions src/www/services_dhcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ function reconfigure_dhcpd()
}
}

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'])) {
Expand Down Expand Up @@ -179,12 +173,7 @@ function reconfigure_dhcpd()
$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'])) {
Expand Down
11 changes: 2 additions & 9 deletions src/www/services_dhcp_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,15 @@ function staticmapcmp($a, $b)
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;

// handle identifiers and actions
if (!empty($pconfig['if']) && !empty($config['interfaces'][$pconfig['if']])) {
$if = $pconfig['if'];
}
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();

Expand Down
7 changes: 1 addition & 6 deletions src/www/services_dhcpv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,8 @@ function reconfigure_dhcpd()
}

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',
Expand Down
13 changes: 4 additions & 9 deletions src/www/services_dhcpv6_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,17 @@ function staticmapcmp($a, $b)
} 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'];
}
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"));
Expand Down
9 changes: 2 additions & 7 deletions src/www/services_dnsmasq.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@
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();
Expand Down
4 changes: 1 addition & 3 deletions src/www/services_ntpd_gps.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
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');
Expand Down
7 changes: 1 addition & 6 deletions src/www/services_ntpd_pps.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@
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') {
Expand Down
4 changes: 1 addition & 3 deletions src/www/services_opendns.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
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']);
Expand Down
4 changes: 1 addition & 3 deletions src/www/services_router_advertisements.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@
}

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'];
Expand Down
4 changes: 1 addition & 3 deletions src/www/services_unbound_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
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',
Expand Down
6 changes: 2 additions & 4 deletions src/www/services_unbound_overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@
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'])) {
$a_hosts[$i]['rr'] = is_ipaddrv6($hostent['ip']) ? 'AAAA' : 'A';
}
}

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'])) {
Expand Down
10 changes: 3 additions & 7 deletions src/www/system_authservers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 0 additions & 6 deletions src/www/system_gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ function delete_gateway_item($id, $a_gateways)
} 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'])) {
Expand Down
7 changes: 0 additions & 7 deletions src/www/system_gateways_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,6 @@
}

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']) ) {
Expand Down
11 changes: 2 additions & 9 deletions src/www/vpn_ipsec_keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@
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") {
Expand Down
11 changes: 2 additions & 9 deletions src/www/vpn_ipsec_keys_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@
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();
Expand Down
Loading

0 comments on commit b0aa1be

Please sign in to comment.