Commit f0c9c1ca authored by Franco Fichtner's avatar Franco Fichtner

src: some cleanups

parent 73a66c85
...@@ -31,7 +31,6 @@ function set_networking_interfaces_ports() ...@@ -31,7 +31,6 @@ function set_networking_interfaces_ports()
{ {
global $noreboot; global $noreboot;
global $config; global $config;
global $g;
global $fp; global $fp;
$yes_no_prompt = '[y|n]? '; $yes_no_prompt = '[y|n]? ';
...@@ -430,7 +429,7 @@ EOD; ...@@ -430,7 +429,7 @@ EOD;
function vlan_setup() function vlan_setup()
{ {
global $iflist, $config, $g, $fp; global $iflist, $config, $fp;
$yes_no_prompt = '[y|n]? '; $yes_no_prompt = '[y|n]? ';
......
...@@ -143,7 +143,7 @@ function convert_config() { ...@@ -143,7 +143,7 @@ function convert_config() {
/* save the system configuration */ /* save the system configuration */
function write_config($desc = 'Unknown', $backup = true) function write_config($desc = 'Unknown', $backup = true)
{ {
global $config, $g; global $config;
if (!empty($_SERVER['REMOTE_ADDR'])) { if (!empty($_SERVER['REMOTE_ADDR'])) {
if (session_status() == PHP_SESSION_NONE) { if (session_status() == PHP_SESSION_NONE) {
...@@ -219,7 +219,7 @@ function reset_factory_defaults($sync = true) ...@@ -219,7 +219,7 @@ function reset_factory_defaults($sync = true)
function config_restore($conffile) function config_restore($conffile)
{ {
global $config, $g; global $config;
if (!file_exists($conffile)) if (!file_exists($conffile))
return 1; return 1;
...@@ -265,8 +265,9 @@ function security_checks_disabled() ...@@ -265,8 +265,9 @@ function security_checks_disabled()
/** /**
* remove old backups * remove old backups
*/ */
function cleanup_backups() { function cleanup_backups()
global $g, $config; {
global $config;
$i = false; $i = false;
if (isset($config['system']['backupcount']) && is_numeric($config['system']['backupcount']) && ($config['system']['backupcount'] >= 0)) { if (isset($config['system']['backupcount']) && is_numeric($config['system']['backupcount']) && ($config['system']['backupcount'] >= 0)) {
......
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '', $dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
$dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) { $dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
global $config, $g; global $config;
$this->_cacheFile = "/conf/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache"; $this->_cacheFile = "/conf/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache";
$this->_cacheFile_v6 = "/conf/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}_v6.cache"; $this->_cacheFile_v6 = "/conf/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}_v6.cache";
......
...@@ -35,8 +35,9 @@ $buffer_rules_rdr = array(); ...@@ -35,8 +35,9 @@ $buffer_rules_rdr = array();
$buffer_rules_normal = array(); $buffer_rules_normal = array();
/* format filter logs */ /* format filter logs */
function conv_log_filter($logfile, $nentries, $tail = 50, $filtertext = "", $filterinterface = null) { function conv_log_filter($logfile, $nentries, $tail = 50, $filtertext = '', $filterinterface = null)
global $config, $g; {
global $config;
/* Make sure this is a number before using it in a system call */ /* Make sure this is a number before using it in a system call */
if (!(is_numeric($tail))) if (!(is_numeric($tail)))
...@@ -279,9 +280,8 @@ function get_port_with_service($port, $proto) { ...@@ -279,9 +280,8 @@ function get_port_with_service($port, $proto) {
return ':' . $portstr; return ':' . $portstr;
} }
function find_rule_by_number($rulenum, $type="block") { function find_rule_by_number($rulenum, $type = 'block')
global $g; {
/* Passing arbitrary input to grep could be a Very Bad Thing(tm) */ /* Passing arbitrary input to grep could be a Very Bad Thing(tm) */
if (!is_numeric($rulenum) || !in_array($type, array('pass', 'block', 'match', 'rdr'))) if (!is_numeric($rulenum) || !in_array($type, array('pass', 'block', 'match', 'rdr')))
return; return;
...@@ -305,8 +305,9 @@ function find_rule_by_number($rulenum, $type="block") { ...@@ -305,8 +305,9 @@ function find_rule_by_number($rulenum, $type="block") {
return ""; return "";
} }
function buffer_rules_load() { function buffer_rules_load()
global $g, $buffer_rules_rdr, $buffer_rules_normal; {
global $buffer_rules_rdr, $buffer_rules_normal;
unset($buffer, $buffer_rules_rdr, $buffer_rules_normal); unset($buffer, $buffer_rules_rdr, $buffer_rules_normal);
/* Redeclare globals after unset to work around PHP */ /* Redeclare globals after unset to work around PHP */
global $buffer_rules_rdr, $buffer_rules_normal; global $buffer_rules_rdr, $buffer_rules_normal;
...@@ -340,13 +341,15 @@ function buffer_rules_load() { ...@@ -340,13 +341,15 @@ function buffer_rules_load() {
unset($_gb, $buffer); unset($_gb, $buffer);
} }
function buffer_rules_clear() { function buffer_rules_clear()
{
unset($GLOBALS['buffer_rules_normal']); unset($GLOBALS['buffer_rules_normal']);
unset($GLOBALS['buffer_rules_rdr']); unset($GLOBALS['buffer_rules_rdr']);
} }
function find_rule_by_number_buffer($rulenum, $type){ function find_rule_by_number_buffer($rulenum, $type)
global $g, $buffer_rules_rdr, $buffer_rules_normal; {
global $buffer_rules_rdr, $buffer_rules_normal;
$lookup_key = "@{$rulenum}"; $lookup_key = "@{$rulenum}";
...@@ -362,15 +365,17 @@ function find_rule_by_number_buffer($rulenum, $type){ ...@@ -362,15 +365,17 @@ function find_rule_by_number_buffer($rulenum, $type){
return "{$rulename} ({$lookup_key})"; return "{$rulename} ({$lookup_key})";
} }
function find_action_image($action) { function find_action_image($action)
// This function will now return a glyphicon class {
global $g; if ((strstr(strtolower($action), 'p')) || (strtolower($action) == 'rdr')) {
if ((strstr(strtolower($action), "p")) || (strtolower($action) == "rdr")) return 'glyphicon glyphicon-play text-success';
return "glyphicon glyphicon-play text-success"; }
else if(strstr(strtolower($action), "r"))
return "glyphicon glyphicon-remove text-warning"; if (strstr(strtolower($action), 'r')) {
else return 'glyphicon glyphicon-remove text-warning';
return "glyphicon glyphicon-remove text-danger"; }
return 'glyphicon glyphicon-remove text-danger';
} }
/* AJAX specific handlers */ /* AJAX specific handlers */
......
...@@ -50,7 +50,7 @@ function return_apinger_defaults() { ...@@ -50,7 +50,7 @@ function return_apinger_defaults() {
*/ */
function setup_gateways_monitor() function setup_gateways_monitor()
{ {
global $config, $g; global $config;
@mkdir('/var/db/rrd', 0775); @mkdir('/var/db/rrd', 0775);
@chown('/var/db/rrd', 'nobody'); @chown('/var/db/rrd', 'nobody');
...@@ -425,8 +425,9 @@ function return_gateways_status($byname = false) ...@@ -425,8 +425,9 @@ function return_gateways_status($byname = false)
} }
/* Return all configured gateways on the system */ /* Return all configured gateways on the system */
function return_gateways_array($disabled = false, $localhost = false, $inactive = false) { function return_gateways_array($disabled = false, $localhost = false, $inactive = false)
global $config, $g; {
global $config;
$gateways_arr = array(); $gateways_arr = array();
...@@ -722,8 +723,9 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive ...@@ -722,8 +723,9 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
return($gateways_arr); return($gateways_arr);
} }
function fixup_default_gateway($ipprotocol, $gateways_status, $gateways_arr) { function fixup_default_gateway($ipprotocol, $gateways_status, $gateways_arr)
global $config, $g; {
global $config;
/* /*
* NOTE: The code below is meant to replace the default gateway when it goes down. * NOTE: The code below is meant to replace the default gateway when it goes down.
* This facilitates services running on OPNsense itself and are not handled by a PBR to continue working. * This facilitates services running on OPNsense itself and are not handled by a PBR to continue working.
...@@ -781,8 +783,9 @@ function fixup_default_gateway($ipprotocol, $gateways_status, $gateways_arr) { ...@@ -781,8 +783,9 @@ function fixup_default_gateway($ipprotocol, $gateways_status, $gateways_arr) {
* Return an array with all gateway groups with name as key * Return an array with all gateway groups with name as key
* All gateway groups will be processed before returning the array. * All gateway groups will be processed before returning the array.
*/ */
function return_gateway_groups_array() { function return_gateway_groups_array()
global $config, $g; {
global $config;
/* fetch the current gateways status */ /* fetch the current gateways status */
$gateways_status = return_gateways_status(true); $gateways_status = return_gateways_status(true);
...@@ -934,8 +937,9 @@ function lookup_gateway_interface_by_name($name) { ...@@ -934,8 +937,9 @@ function lookup_gateway_interface_by_name($name) {
return (false); return (false);
} }
function get_interface_gateway($interface, &$dynamic = false) { function get_interface_gateway($interface, &$dynamic = false)
global $config, $g; {
global $config;
$gw = NULL; $gw = NULL;
...@@ -965,8 +969,9 @@ function get_interface_gateway($interface, &$dynamic = false) { ...@@ -965,8 +969,9 @@ function get_interface_gateway($interface, &$dynamic = false) {
return ($gw); return ($gw);
} }
function get_interface_gateway_v6($interface, &$dynamic = false) { function get_interface_gateway_v6($interface, &$dynamic = false)
global $config, $g; {
global $config;
$gw = NULL; $gw = NULL;
$gwcfg = $config['interfaces'][$interface]; $gwcfg = $config['interfaces'][$interface];
......
...@@ -2375,8 +2375,9 @@ function interface_sync_wireless_clones(&$ifcfg, $sync_changes = false) ...@@ -2375,8 +2375,9 @@ function interface_sync_wireless_clones(&$ifcfg, $sync_changes = false)
} }
} }
function interface_wireless_configure($if, &$wl, &$wlcfg) { function interface_wireless_configure($if, &$wl, &$wlcfg)
global $config, $g; {
global $config;
/* open up a shell script that will be used to output the commands. /* open up a shell script that will be used to output the commands.
* since wireless is changing a lot, these series of commands are fragile * since wireless is changing a lot, these series of commands are fragile
...@@ -2396,7 +2397,7 @@ function interface_wireless_configure($if, &$wl, &$wlcfg) { ...@@ -2396,7 +2397,7 @@ function interface_wireless_configure($if, &$wl, &$wlcfg) {
$fd_set = fopen("/tmp/{$if}_setup.sh","w"); $fd_set = fopen("/tmp/{$if}_setup.sh","w");
fwrite($fd_set, "#!/bin/sh\n"); fwrite($fd_set, "#!/bin/sh\n");
fwrite($fd_set, "# {$g['product_name']} wireless configuration script.\n\n"); fwrite($fd_set, "# wireless configuration script.\n\n");
/* set values for /path/program */ /* set values for /path/program */
$hostapd = "/usr/sbin/hostapd"; $hostapd = "/usr/sbin/hostapd";
...@@ -4289,8 +4290,9 @@ function interface_get_wireless_clone($wlif) { ...@@ -4289,8 +4290,9 @@ function interface_get_wireless_clone($wlif) {
} }
} }
function get_real_interface($interface = "wan", $family = "all", $realv6iface = false, $flush = true) { function get_real_interface($interface = "wan", $family = "all", $realv6iface = false, $flush = true)
global $config, $g; {
global $config;
$wanif = NULL; $wanif = NULL;
...@@ -5058,7 +5060,7 @@ function is_altq_capable($int) ...@@ -5058,7 +5060,7 @@ function is_altq_capable($int)
******/ ******/
function is_interface_wireless($interface) function is_interface_wireless($interface)
{ {
global $config, $g; global $config;
$friendly = convert_real_interface_to_friendly_interface_name($interface); $friendly = convert_real_interface_to_friendly_interface_name($interface);
if (!isset($config['interfaces'][$friendly]['wireless'])) { if (!isset($config['interfaces'][$friendly]['wireless'])) {
......
...@@ -43,7 +43,7 @@ function dump_rrd_to_xml($rrddatabase, $xmldumpfile) ...@@ -43,7 +43,7 @@ function dump_rrd_to_xml($rrddatabase, $xmldumpfile)
function restore_rrd() function restore_rrd()
{ {
global $g, $config; global $config;
$rrddbpath = '/var/db/rrd/'; $rrddbpath = '/var/db/rrd/';
$rrdtool = '/usr/local/bin/rrdtool'; $rrdtool = '/usr/local/bin/rrdtool';
...@@ -190,7 +190,7 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) { ...@@ -190,7 +190,7 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
} }
function enable_rrd_graphing() { function enable_rrd_graphing() {
global $config, $g, $altq_list_queues; global $config, $altq_list_queues;
if(file_exists("/var/run/booting")) if(file_exists("/var/run/booting"))
echo gettext("Generating RRD graphs..."); echo gettext("Generating RRD graphs...");
...@@ -888,9 +888,8 @@ function enable_rrd_graphing() { ...@@ -888,9 +888,8 @@ function enable_rrd_graphing() {
} }
# Create gateway quality RRD with settings suitable for OPNsense graph set. function create_gateway_quality_rrd($rrd_file)
function create_gateway_quality_rrd($rrd_file) { {
global $g;
$rrdinterval = 60; $rrdinterval = 60;
$valid = $rrdinterval * 2; $valid = $rrdinterval * 2;
$rrdtool = "/usr/local/bin/rrdtool"; $rrdtool = "/usr/local/bin/rrdtool";
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
function activate_powerd() function activate_powerd()
{ {
global $config, $g; global $config;
if (is_process_running('powerd')) { if (is_process_running('powerd')) {
exec('/usr/bin/killall powerd'); exec('/usr/bin/killall powerd');
...@@ -60,7 +60,7 @@ function get_default_sysctl_value($id) { ...@@ -60,7 +60,7 @@ function get_default_sysctl_value($id) {
function activate_sysctls() function activate_sysctls()
{ {
global $config, $g; global $config;
$sysctls = array( $sysctls = array(
"net.enc.out.ipsec_bpf_mask" => "0x0001", "net.enc.out.ipsec_bpf_mask" => "0x0001",
...@@ -85,7 +85,7 @@ function activate_sysctls() ...@@ -85,7 +85,7 @@ function activate_sysctls()
function system_resolvconf_generate($dynupdate = false) function system_resolvconf_generate($dynupdate = false)
{ {
global $config, $g; global $config;
$syscfg = $config['system']; $syscfg = $config['system'];
...@@ -170,8 +170,9 @@ function system_resolvconf_generate($dynupdate = false) ...@@ -170,8 +170,9 @@ function system_resolvconf_generate($dynupdate = false)
return 0; return 0;
} }
function get_searchdomains() { function get_searchdomains()
global $config, $g; {
global $config;
$master_list = array(); $master_list = array();
...@@ -192,8 +193,9 @@ function get_searchdomains() { ...@@ -192,8 +193,9 @@ function get_searchdomains() {
return $master_list; return $master_list;
} }
function get_nameservers() { function get_nameservers()
global $config, $g; {
global $config;
$master_list = array(); $master_list = array();
// Read in dhclient nameservers // Read in dhclient nameservers
...@@ -225,7 +227,7 @@ function get_nameservers() { ...@@ -225,7 +227,7 @@ function get_nameservers() {
function system_hosts_generate() function system_hosts_generate()
{ {
global $config, $g; global $config;
$syscfg = $config['system']; $syscfg = $config['system'];
$dnsmasqcfg = $config['dnsmasq']; $dnsmasqcfg = $config['dnsmasq'];
...@@ -362,7 +364,7 @@ function system_dhcpleases_configure() ...@@ -362,7 +364,7 @@ function system_dhcpleases_configure()
function system_hostname_configure() function system_hostname_configure()
{ {
global $config, $g; global $config;
$syscfg = $config['system']; $syscfg = $config['system'];
...@@ -378,7 +380,7 @@ function system_hostname_configure() ...@@ -378,7 +380,7 @@ function system_hostname_configure()
function system_routing_configure($interface = '') function system_routing_configure($interface = '')
{ {
global $config, $g; global $config;
$gatewayip = ""; $gatewayip = "";
$interfacegw = ""; $interfacegw = "";
...@@ -459,8 +461,9 @@ function system_routing_configure($interface = '') ...@@ -459,8 +461,9 @@ function system_routing_configure($interface = '')
return 0; return 0;
} }
function system_staticroutes_configure($interface = "", $update_dns = false) { function system_staticroutes_configure($interface = '', $update_dns = false)
global $config, $g, $aliastable; {
global $config, $aliastable;
$filterdns_list = array(); $filterdns_list = array();
...@@ -568,7 +571,7 @@ function system_staticroutes_configure($interface = "", $update_dns = false) { ...@@ -568,7 +571,7 @@ function system_staticroutes_configure($interface = "", $update_dns = false) {
function system_routing_enable() function system_routing_enable()
{ {
global $config, $g; global $config;
set_sysctl(array( set_sysctl(array(
"net.inet.ip.forwarding" => "1", "net.inet.ip.forwarding" => "1",
...@@ -911,7 +914,7 @@ function system_generate_lighty_config( ...@@ -911,7 +914,7 @@ function system_generate_lighty_config(
$ca_location = 'ca.pem', $ca_location = 'ca.pem',
$captive_portal = false) $captive_portal = false)
{ {
global $config, $g; global $config;
@mkdir('/tmp/lighttpdcompress'); @mkdir('/tmp/lighttpdcompress');
...@@ -940,7 +943,7 @@ url.rewrite-if-not-file = ( "^/ui/(.*)$" => "/ui/index.php?_url=/$1" , ...@@ -940,7 +943,7 @@ url.rewrite-if-not-file = ( "^/ui/(.*)$" => "/ui/index.php?_url=/$1" ,
EOD; EOD;
$captive_portal_mod_evasive = ""; $captive_portal_mod_evasive = "";
$server_upload_dirs = "server.upload-dirs = ( \"{$g['upload_path']}/\", \"/tmp/\", \"/var/\" )\n"; $server_upload_dirs = "server.upload-dirs = ( \"/root/\", \"/tmp/\", \"/var/\" )\n";
$server_max_request_size = "server.max-request-size = 2097152"; $server_max_request_size = "server.max-request-size = 2097152";
$cgi_config = "cgi.assign = ( \".cgi\" => \"\" )"; $cgi_config = "cgi.assign = ( \".cgi\" => \"\" )";
} }
...@@ -1248,7 +1251,7 @@ EOD; ...@@ -1248,7 +1251,7 @@ EOD;
function system_timezone_configure() function system_timezone_configure()
{ {
global $config, $g; global $config;
$syscfg = $config['system']; $syscfg = $config['system'];
...@@ -1276,8 +1279,9 @@ function system_timezone_configure() ...@@ -1276,8 +1279,9 @@ function system_timezone_configure()
echo gettext("done.") . "\n"; echo gettext("done.") . "\n";
} }
function system_ntp_setup_gps($serialport) { function system_ntp_setup_gps($serialport)
global $config, $g; {
global $config;
$gps_device = '/dev/gps0'; $gps_device = '/dev/gps0';
$serialport = '/dev/'.$serialport; $serialport = '/dev/'.$serialport;
...@@ -1345,7 +1349,7 @@ function system_ntp_setup_pps($serialport) ...@@ -1345,7 +1349,7 @@ function system_ntp_setup_pps($serialport)
function system_ntp_configure($start_ntpd = true) function system_ntp_configure($start_ntpd = true)
{ {
global $config, $g; global $config;
$driftfile = '/var/db/ntpd.drift'; $driftfile = '/var/db/ntpd.drift';
$statsdir = '/var/log/ntp'; $statsdir = '/var/log/ntp';
...@@ -1645,7 +1649,7 @@ function system_console_configure() ...@@ -1645,7 +1649,7 @@ function system_console_configure()
function system_set_harddisk_standby() function system_set_harddisk_standby()
{ {
global $g, $config; global $config;
if (isset($config['system']['harddiskstandby'])) { if (isset($config['system']['harddiskstandby'])) {
if (file_exists("/var/run/booting")) { if (file_exists("/var/run/booting")) {
......
...@@ -60,5 +60,3 @@ if __name__ == '__main__': ...@@ -60,5 +60,3 @@ if __name__ == '__main__':
result=rc.search(**parameters) result=rc.search(**parameters)
result['parameters'] = parameters result['parameters'] = parameters
print (json.dumps(result)) print (json.dumps(result))
...@@ -3,4 +3,3 @@ command:/usr/local/opnsense/scripts/suricata/getRuleJSON.py ...@@ -3,4 +3,3 @@ command:/usr/local/opnsense/scripts/suricata/getRuleJSON.py
parameters:/limit %s /offset %s /filter %s /filter_fields %s /sort_by %s parameters:/limit %s /offset %s /filter %s /filter_fields %s /sort_by %s
type:script_output type:script_output
message:request installed suricata rules message:request installed suricata rules
...@@ -108,4 +108,3 @@ else: ...@@ -108,4 +108,3 @@ else:
if result is None: if result is None:
sys.exit(-1) sys.exit(-1)
print('%s'%(result)) print('%s'%(result))
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