aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/avahi/avahi.inc122
1 files changed, 70 insertions, 52 deletions
diff --git a/config/avahi/avahi.inc b/config/avahi/avahi.inc
index 6d46df59..d180178d 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
@@ -73,28 +90,30 @@ function avahi_write_config() {
$useipv4 = ($config['installedpackages']['avahi']['config'][0]['disable_ipv4']) ? "no" : "yes";
$useipv6 = ($config['installedpackages']['avahi']['config'][0]['disable_ipv6']) ? "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]
@@ -146,23 +165,24 @@ 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 .= " /bin/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/mkdir /var/run/dbus\n";
+ $start .= " /usr/sbin/chown messagebus:messagebus /var/run/dbus\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 .= "/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";
@@ -172,31 +192,29 @@ EOF;
$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";
+ $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")) {
+ service_stop("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")) {
+ service_start("avahi");
}
}