From 0ae6daf8342d8a07d33bf6677ce9a228530defac Mon Sep 17 00:00:00 2001 From: Ermal Date: Tue, 7 Sep 2010 19:36:53 +0000 Subject: Use the new events mechanisms to dispatch events. --- etc/devd.conf | 4 ++-- etc/inc/filter.inc | 3 +-- etc/inc/globals.inc | 1 + etc/inc/gwlb.inc | 4 ++-- etc/inc/interfaces.inc | 2 +- etc/inc/openvpn.inc | 2 +- etc/inc/pfsense-utils.inc | 6 +++--- etc/inc/util.inc | 34 ++++++++++++++++++++++++++++++--- etc/rc | 2 -- etc/rc.bootup | 2 +- etc/rc.newwanip | 2 +- sbin/dhclient-script | 7 ++----- usr/local/sbin/ovpn-linkdown | 2 +- usr/local/sbin/ovpn-linkup | 4 ++-- usr/local/sbin/ppp-linkdown | 2 +- usr/local/sbin/ppp-linkup | 2 +- usr/local/www/system_advanced_admin.php | 2 +- 17 files changed, 52 insertions(+), 29 deletions(-) diff --git a/etc/devd.conf b/etc/devd.conf index da1f611..647de43 100644 --- a/etc/devd.conf +++ b/etc/devd.conf @@ -30,7 +30,7 @@ notify 100 { #notify 0 { # match "type" "LINK_DOWN"; # media-type "ethernet"; -# action "/bin/echo -n '$subsystem stop ' >>/tmp/rc.linkup"; +# action "/usr/local/sbin/pfSctl -c 'interface linkup stop $subsystem'"; #}; # When a USB keyboard arrives, attach it as the console keyboard. @@ -54,7 +54,7 @@ notify 0 { match "system" "IFNET"; match "type" "LINK_UP"; media-type "ethernet"; - action "/bin/echo -n '$subsystem start ' >>/tmp/rc.linkup"; + action "/usr/local/sbin/pfSctl -c 'interface linkup start $subsystem'"; }; # Notify all users before beginning emergency shutdown when we get diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index 076a828..89a3d49 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -136,8 +136,7 @@ function filter_configure() { $mt = microtime(); echo "filter_configure() being called $mt\n"; } - global $g; - touch($g['tmp_path'] . "/filter_dirty"); + send_event("filter reload"); } function filter_delete_states_for_down_gateways() { diff --git a/etc/inc/globals.inc b/etc/inc/globals.inc index a0b9f31..1b786bd 100644 --- a/etc/inc/globals.inc +++ b/etc/inc/globals.inc @@ -58,6 +58,7 @@ function get_nics_with_capabilities($CAPABILITIES) { $g = array( "base_packages" => "siproxd", + "event_address" => "unix:///var/run/check_reload_status", "factory_shipped_username" => "admin", "factory_shipped_password" => "pfsense", "upload_path" => "/root", diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index 848a62c..4235145 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -82,8 +82,8 @@ rrd interval 60s; ## These parameters can be overriden in a specific alarm configuration alarm default { - command on "/usr/bin/touch /tmp/filter_dirty" - command off "/usr/bin/touch /tmp/filter_dirty" + command on "/usr/local/sbin/pfSctl -c 'filter reload'" + command off "/usr/local/sbin/pfSctl -c 'filter reload'" combine 10s } diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 6705a52..94903ce 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -848,7 +848,7 @@ function interface_bring_down($interface = "wan", $destroy = false) { } unlink_if_exists("{$g['varetc_path']}/mpd_{$interface}.conf"); if (isset($ppp['ondemand']) && !$destroy) - file_put_contents("{$g['tmp_path']}/interface_configure", $interface); + send_event("interface reconfigure {$interface}"); break; } } diff --git a/etc/inc/openvpn.inc b/etc/inc/openvpn.inc index f7765b1..6d400db 100644 --- a/etc/inc/openvpn.inc +++ b/etc/inc/openvpn.inc @@ -573,7 +573,7 @@ function openvpn_restart($mode, & $settings) { /* start the new process */ $fpath = $g['varetc_path']."/openvpn/{$mode_id}.conf"; mwexec_bg("nohup openvpn --config {$fpath}"); - touch("{$g['tmp_path']}/filter_dirty"); + send_event("filter reload"); } function openvpn_delete($mode, & $settings) { diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index a7e25ca..0498b2e 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -852,7 +852,7 @@ function reload_interfaces_sync() { ******/ function reload_all() { global $g; - touch("{$g['tmp_path']}/reload_all"); + send_event("service reload all"); } /****f* pfsense-utils/reload_interfaces @@ -925,10 +925,10 @@ function reload_all_sync() { conf_mount_ro(); /* restart sshd */ - @touch("{$g['tmp_path']}/start_sshd"); + send_event("service restart sshd"); /* restart webConfigurator if needed */ - touch("{$g['tmp_path']}/restart_webgui"); + send_event("service restart webgui"); mwexec("/bin/rm {$g['tmp_path']}/reload*"); } diff --git a/etc/inc/util.inc b/etc/inc/util.inc index 96d10f5..30f4566 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -137,6 +137,36 @@ function unlock($cfglckkey = 0) { return; } +function send_event($cmd) { + global $g; + + $fd = fsockopen($g['event_address']); + if ($fd) { + fwrite($fd, $cmd); + $resp = fread($fd, 4096); + if ($resp != "OK\n") + log_error("send_event: sent {$cmd} got {$resp}"); + fclose($fd); + } +} + +function send_multiple_events($cmds) { + global $g; + + if (!is_array($cmds)) + return; + $fd = fsockopen($g['event_address']); + if ($fd) { + foreach ($cmds as $cmd) { + fwrite($fd, $cmd); + $resp = fread($fd, 4096); + if ($resp != "OK\n") + log_error("send_event: sent {$cmd} got {$resp}"); + } + fclose($fd); + } +} + function refcount_init($reference) { $shmid = shmop_open($reference, "c", 0644, 10); shmop_write($shmid, 0, 0); @@ -1176,8 +1206,6 @@ function start_devd() { exec("/sbin/devd"); sleep(1); - if(file_exists("{$g['tmp_path']}/rc.linkup")) - unlink("{$g['tmp_path']}/rc.linkup"); } function is_interface_mismatch() { @@ -1207,7 +1235,7 @@ function is_interface_mismatch() { /* sync carp entries to other firewalls */ function carp_sync_client() { global $g; - touch($g['tmp_path'] . "/filter_sync"); + send_event("filter sync"); } /****f* util/isAjax diff --git a/etc/rc b/etc/rc index 99ae96c..54fb6a2 100755 --- a/etc/rc +++ b/etc/rc @@ -360,8 +360,6 @@ rm -rf /usr/local/pkg/pf/CVS # Remove stale files that have already been processed by bootup # scripts -rm -f /tmp/filter_dirty -rm -f /tmp/rc.linkup nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null & # Start ping handler every 240 seconds diff --git a/etc/rc.bootup b/etc/rc.bootup index 38310b4..3e5647b 100755 --- a/etc/rc.bootup +++ b/etc/rc.bootup @@ -305,7 +305,7 @@ services_dnsmasq_configure(); system_dhcpleases_configure(); /* start dyndns service */ -@touch("{$g['tmp_path']}/update_dyndns"); +send_event("service reload dyndnsall"); /* start DHCP relay */ services_dhcrelay_configure(); diff --git a/etc/rc.newwanip b/etc/rc.newwanip index a6b1bcb..d06c493 100755 --- a/etc/rc.newwanip +++ b/etc/rc.newwanip @@ -85,7 +85,7 @@ if (is_ipaddr($oldip) && $curwanip == $oldip) services_dnsupdate_process($interface); /* signal dyndns update */ -file_put_contents("{$g['tmp_path']}/update_dyndns", $interface); +send_event("service reload dyndns {$interface}"); /* reconfigure IPsec tunnels */ vpn_ipsec_force_reload(); diff --git a/sbin/dhclient-script b/sbin/dhclient-script index 132946d..7f1862e 100755 --- a/sbin/dhclient-script +++ b/sbin/dhclient-script @@ -81,10 +81,7 @@ add_new_address() { echo $new_routers > /tmp/${interface}_router cp /var/db/${interface}_ip /tmp/rc.newwanip_oldip 2>/dev/null -# echo $new_ip_address > /var/db/${interface}_ip - - echo $interface > /tmp/rc.newwanip -# echo $new_ip_address >> /tmp/rc.newwanip + /usr/local/sbin/pfSctl -c "'interface reload $interface'" } @@ -186,7 +183,7 @@ add_new_resolv_conf() { echo $new_domain_name >/var/etc/defaultdomain.conf fi - echo $interface > /tmp/rc.newwanip + /usr/local/sbin/pfSctl -c "'interface reload $interface'" return 0 } diff --git a/usr/local/sbin/ovpn-linkdown b/usr/local/sbin/ovpn-linkdown index e3c7400..112317f 100755 --- a/usr/local/sbin/ovpn-linkdown +++ b/usr/local/sbin/ovpn-linkdown @@ -4,4 +4,4 @@ /bin/rm -f /var/etc/nameserver_$1 /bin/rm -f /tmp/$1_router /bin/rm -f /tmp/$1up -/usr/bin/touch /tmp/filter_dirty +/usr/local/sbin/pfSctl -c 'filter reload' diff --git a/usr/local/sbin/ovpn-linkup b/usr/local/sbin/ovpn-linkup index 2ade032..354623e 100755 --- a/usr/local/sbin/ovpn-linkup +++ b/usr/local/sbin/ovpn-linkup @@ -3,9 +3,9 @@ # write nameservers to file needs dns fidnings?! # let the configuration system know that the ip has changed. -#/bin/echo $1 > /tmp/rc.newwanip +#/usr/local/sbin/pfSctl -c "'interface reload $interface'" /bin/echo $4 > /tmp/$1_router /usr/bin/touch /tmp/$1up # reload filter -/usr/bin/touch /tmp/filter_dirty +/usr/local/sbin/pfSctl -c 'filter reload' exit 0 diff --git a/usr/local/sbin/ppp-linkdown b/usr/local/sbin/ppp-linkdown index 06e24fa..59b2ce0 100755 --- a/usr/local/sbin/ppp-linkdown +++ b/usr/local/sbin/ppp-linkdown @@ -10,4 +10,4 @@ fi # Do not remove gateway used during filter reload. # /bin/rm -f /tmp/$1_router /bin/rm -f /tmp/$1up -/usr/bin/touch /tmp/resolv_conf_generate +/usr/local/sbin/pfSctl -c 'service reload dns' diff --git a/usr/local/sbin/ppp-linkup b/usr/local/sbin/ppp-linkup index 4002e42..67b0832 100755 --- a/usr/local/sbin/ppp-linkup +++ b/usr/local/sbin/ppp-linkup @@ -14,7 +14,7 @@ if [ $8 = "dns2" ]; then fi # let the configuration system know that the ip has changed. -/bin/echo $1 > /tmp/rc.newwanip +/usr/local/sbin/pfSctl -c "'interface reload $1'" /bin/echo $4 > /tmp/$1_router /usr/bin/touch /tmp/$1up exit 0 diff --git a/usr/local/www/system_advanced_admin.php b/usr/local/www/system_advanced_admin.php index c53cc7c..e7c217b 100644 --- a/usr/local/www/system_advanced_admin.php +++ b/usr/local/www/system_advanced_admin.php @@ -461,7 +461,7 @@ if ($restart_sshd) { if ($config['system']['enablesshd']) { log_error(gettext("secure shell configuration has changed. Restarting sshd.")); - touch("{$g['tmp_path']}/start_sshd"); + send_event("service restart sshd"); } } if ($restart_webgui) { -- cgit v1.1