diff options
author | Chris Buechler <cmb@pfsense.org> | 2015-08-16 00:09:13 -0500 |
---|---|---|
committer | Chris Buechler <cmb@pfsense.org> | 2015-08-16 00:09:13 -0500 |
commit | 809e29cad9be0b5bbd9afde0193ca628f92503ef (patch) | |
tree | 18cc7bb845aca142a95e2f3c9ff84d89056fd481 /config/avahi/avahi.inc | |
parent | a86d8fab789d8d519ae089e90d04a258e792d141 (diff) | |
parent | e4370bba8fd5849751b3411e218c50c076b4d9a3 (diff) | |
download | pfsense-packages-809e29cad9be0b5bbd9afde0193ca628f92503ef.tar.gz pfsense-packages-809e29cad9be0b5bbd9afde0193ca628f92503ef.tar.bz2 pfsense-packages-809e29cad9be0b5bbd9afde0193ca628f92503ef.zip |
Merge pull request #983 from doktornotor/patch-25
Diffstat (limited to 'config/avahi/avahi.inc')
-rw-r--r-- | config/avahi/avahi.inc | 145 |
1 files changed, 84 insertions, 61 deletions
diff --git a/config/avahi/avahi.inc b/config/avahi/avahi.inc index 6d46df59..7d69af78 100644 --- a/config/avahi/avahi.inc +++ b/config/avahi/avahi.inc @@ -1,21 +1,21 @@ <?php - /* - $Id$ avahi.inc - part of pfSense (http://www.pfSense.com) - Copyright (C) 2009-2012 Scott Ullrich, Jim Pingle + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2009 Scott Ullrich + Copyright (C) 2009-2013 Jim Pingle + Copyright (C) 2015 ESF, LLC 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. + 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. + 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 @@ -28,40 +28,57 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -$pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); -if ($pfs_version == "2.1" || $pfs_version == "2.2") +$pfs_version = substr(trim(file_get_contents("/etc/version")), 0, 3); +if ($pfs_version == "2.1" || $pfs_version == "2.2") { define('AVAHI_BASE', '/usr/pbi/avahi-' . php_uname("m")); -else +} else { define('AVAHI_BASE', '/usr/local'); - -function avahi_start() { - mwexec_bg("/usr/local/etc/rc.d/avahi-daemon.sh start"); -} - -function avahi_stop() { - mwexec_bg("/usr/local/etc/rc.d/avahi-daemon.sh stop"); } function avahi_install() { - global $g, $config; conf_mount_rw(); if (!file_exists('/usr/local/etc/gnome.subr')) { @symlink(AVAHI_BASE . '/etc/gnome.subr', '/usr/local/etc/gnome.subr'); } - // Add needed users and groups - exec("/usr/sbin/pw useradd avahi -u 558"); - exec("/usr/sbin/pw groupadd avahi -g 558"); + // Add needed users and groups if they don't exist + if (!exec("/usr/sbin/pw usershow avahi")) { + exec("/usr/sbin/pw useradd avahi -u 558"); + } + if (!exec("/usr/sbin/pw groupshow avahi")) { + exec("/usr/sbin/pw groupadd avahi -g 558"); + } + + conf_mount_ro(); +} + +function avahi_deinstall() { + conf_mount_rw(); + + // Stop services and remove created rc script and symlink + if (is_process_running("avahi-daemon")) { + exec("/usr/bin/killall -9 avahi-daemon"); + } + if (is_process_running("dbus-daemon")) { + exec("/usr/bin/killall -9 dbus-daemon"); + } + unlink_if_exists("/usr/local/etc/rc.d/avahi-daemon.sh"); + unlink_if_exists("/usr/local/etc/gnome.subr"); + + // Remove created users and groups if they exist + if (exec("/usr/sbin/pw groupshow avahi")) { + exec("/usr/sbin/pw groupdel avahi"); + } + if (exec("/usr/sbin/pw usershow avahi")) { + exec("/usr/sbin/pw userdel avahi"); + } - // Make image RO conf_mount_ro(); } function avahi_write_config() { - global $g, $config; - // Make image RW + global $config; conf_mount_rw(); // Pull some various values out of config.xml @@ -72,29 +89,32 @@ function avahi_write_config() { $denyif = $config['installedpackages']['avahi']['config'][0]['denyinterfaces']; $useipv4 = ($config['installedpackages']['avahi']['config'][0]['disable_ipv4']) ? "no" : "yes"; $useipv6 = ($config['installedpackages']['avahi']['config'][0]['disable_ipv6']) ? "no" : "yes"; + $usedbus = ($config['installedpackages']['avahi']['config'][0]['disable_dbus']) ? "no" : "yes"; - // No supplied domains? Use the defaults. - if(!$browsedomains) + // No supplied domains? Use the defaults. + if (!$browsedomains) { $browsedomains = "local, 0pointer.de, zeroconf.org"; + } - // Never pass along WAN. Bad. + // Never pass along WAN. Bad. $denyinterfaces = $config['interfaces']['wan']['if']; // Process interfaces defined by user to deny. - if($denyif) { + if ($denyif) { $if = explode(",", $denyif); - foreach($if as $i) { + foreach ($if as $i) { $ifreal = convert_friendly_interface_to_real_interface_name($i); - if($ifreal) + if ($ifreal) { $denyinterfaces .= ", " . $ifreal; + } } } // Construct the avahi configuration - $avahiconfig = <<<EOF + $avahiconfig = <<<EOF # avahi.conf - This file was automatically generated by the pfSense pacakge -# manager. Do not edit this file, it will be overwritten automatically. +# manager. Do not edit this file, it will be overwritten automatically. # See /usr/local/pkg/avahi.inc to make changes to this file! [server] @@ -104,7 +124,7 @@ browse-domains={$browsedomains} deny-interfaces={$denyinterfaces} use-ipv4={$useipv4} use-ipv6={$useipv6} -enable-dbus=yes +enable-dbus={$usedbus} #check-response-ttl=no #use-iff-running=no #disallow-other-stacks=no @@ -146,57 +166,60 @@ EOF; $fd = fopen(AVAHI_BASE . "/etc/avahi/avahi-daemon.conf", "w"); fwrite($fd, $avahiconfig); fclose($fd); + /* Write out rc.d startup file */ $start = "/etc/rc.conf_mount_rw\n"; $start .= "if [ ! -d /proc/0 ]; then\n"; - $start .= " mkdir -p /proc\n"; - $start .= " mount -t procfs procfs /proc\n"; + $start .= " /bin/mkdir -p /proc\n"; + $start .= " /sbin/mount -t procfs procfs /proc\n"; $start .= "fi\n"; $start .= "if [ ! -f /usr/local/etc/gnome.subr ]; then\n"; - $start .= " ln -sf " . AVAHI_BASE . "/etc/gnome.subr /usr/local/etc/gnome.subr\n"; - $start .= "fi\n"; - $start .= "if [ ! -d /var/run/dbus ]; then\n"; - $start .= " mkdir /var/run/dbus\n"; - $start .= " chown messagebus:messagebus /var/run/dbus\n"; + $start .= " /bin/ln -sf " . AVAHI_BASE . "/etc/gnome.subr /usr/local/etc/gnome.subr\n"; $start .= "fi\n"; $start .= "/usr/bin/killall avahi-daemon >/dev/null 2>&1\n"; - if (file_exists(AVAHI_BASE . "/etc/rc.d/dbus")) { - $start .= AVAHI_BASE . "/etc/rc.d/dbus onestop\n"; - $start .= "rm /var/run/dbus/dbus.pid >/dev/null 2>&1\n"; - $start .= AVAHI_BASE . "/etc/rc.d/dbus onestart\n"; + if (!$config['installedpackages']['avahi']['config'][0]['disable_dbus']) { + $start .= "if [ ! -d /var/run/dbus ]; then\n"; + $start .= " /bin/mkdir /var/run/dbus\n"; + $start .= " /usr/sbin/chown messagebus:messagebus /var/run/dbus\n"; + $start .= "fi\n"; + if (file_exists(AVAHI_BASE . "/etc/rc.d/dbus")) { + $start .= AVAHI_BASE . "/etc/rc.d/dbus onestop\n"; + $start .= "/bin/rm /var/run/dbus/dbus.pid >/dev/null 2>&1\n"; + $start .= AVAHI_BASE . "/etc/rc.d/dbus onestart\n"; + $start .= "sleep 5\n"; + } } - $start .= "sleep 5\n"; $start .= AVAHI_BASE . "/sbin/avahi-daemon -D\n"; $start .= "/etc/rc.conf_mount_ro\n"; $stop = "/usr/bin/killall avahi-daemon >/dev/null 2>&1\n"; - if (file_exists(AVAHI_BASE . "/etc/rc.d/dbus")) { - $stop .= AVAHI_BASE . "/etc/rc.d/dbus onestop\n"; - $stop .= "rm /var/run/dbus/dbus.pid >/dev/null 2>&1\n"; + if (!$config['installedpackages']['avahi']['config'][0]['disable_dbus']) { + if (file_exists(AVAHI_BASE . "/etc/rc.d/dbus")) { + $stop .= AVAHI_BASE . "/etc/rc.d/dbus onestop\n"; + $stop .= "/bin/rm /var/run/dbus/dbus.pid >/dev/null 2>&1\n"; + } } write_rcfile(array( "file" => "avahi-daemon.sh", "start" => $start, - "stop" => $stop + "stop" => $stop ) ); - // Make image RO - conf_mount_ro(); + conf_mount_ro(); } function avahi_sync() { - global $g, $config; - - avahi_stop(); + global $config; + if (is_service_running("avahi")) { + stop_service("avahi"); + } avahi_write_config(); - // Is package enabled? - if (($config['installedpackages']['avahi']['config'][0]['enable']) - && file_exists("/usr/local/etc/rc.d/avahi-daemon.sh")) { - avahi_start(); + if (($config['installedpackages']['avahi']['config'][0]['enable']) && file_exists("/usr/local/etc/rc.d/avahi-daemon.sh")) { + start_service("avahi"); } } |