aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/avahi/avahi.inc118
1 files changed, 91 insertions, 27 deletions
diff --git a/config/avahi/avahi.inc b/config/avahi/avahi.inc
index 4c824e71..ba89676f 100644
--- a/config/avahi/avahi.inc
+++ b/config/avahi/avahi.inc
@@ -63,23 +63,36 @@ function avahi_deinstall() {
}
function avahi_write_config() {
- global $config;
+ global $config, $avahi_config;
conf_mount_rw();
// Pull some various values out of config.xml
+ if (isset($config['installedpackages']['avahi']['config'][0])) {
+ $avahi_config = $config['installedpackages']['avahi']['config'][0];
+ }
+ // Server Options
$hostname = $config['system']['hostname'];
$domain = $config['system']['domain'];
- $enable = $config['installedpackages']['avahi']['config'][0]['enable'];
- $browsedomains = $config['installedpackages']['avahi']['config'][0]['browsedomains'];
- $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) {
- $browsedomains = "local, 0pointer.de, zeroconf.org";
- }
+ $enable = $avahi_config['enable'];
+ $browsedomains = $avahi_config['browsedomains'] ?: "local";
+ $denyif = $avahi_config['denyinterfaces'];
+ $useipv4 = ($avahi_config['enable_ipv4']) ? "yes" : "no";
+ $useipv6 = ($avahi_config['enable_ipv6']) ? "yes" : "no";
+ $usedbus = ($avahi_config['disable_dbus']) ? "no" : "yes";
+ // Wide Area
+ $widearea = ($avahi_config['enable_wide_area']) ? "yes" : "no";
+ // Publishing Options
+ $publish = ($avahi_config['disable_publishing']) ? "no" : "yes";
+ $userpublish = ($avahi_config['disable_user_service_publishing']) ? "no" : "yes";
+ $addresspublish = ($avahi_config['publish_addresses']) ? "yes" : "no";
+ $cookie = ($avahi_config['add_service_cookie']) ? "yes" : "no";
+ $hinfopublish = ($avahi_config['publish_hinfo']) ? "yes" : "no";
+ $wspublish = ($avahi_config['publish_workstation']) ? "yes" : "no";
+ $aaaaonv4 = ($avahi_config['publish_aaaa_on_ipv4']) ? "yes" : "no";
+ $aonv6 = ($avahi_config['publish_a_on_ipv6']) ? "yes" : "no";
+ // Reflector Options
+ $reflect = ($avahi_config['enable_reflector']) ? "yes" : "no";
+ $reflectipv = ($avahi_config['reflect_ipv']) ? "yes" : "no";
// Never pass along WAN. Bad.
$denyinterfaces = $config['interfaces']['wan']['if'];
@@ -94,6 +107,15 @@ function avahi_write_config() {
}
}
}
+
+ // Process DNS servers and omit localhost if present in /etc/resolv.conf
+ $publishdns = '';
+ $dns = implode(" ", get_dns_servers());
+ $dns = trim(str_replace('127.0.0.1', '', $dns));
+ $dns = str_replace(' ', ', ', $dns);
+ if ($dns) {
+ $publishdns = "publish-dns-servers={$dns}";
+ }
// Construct the avahi configuration
$avahiconfig = <<<EOF
@@ -116,24 +138,24 @@ enable-dbus={$usedbus}
allow-point-to-point=yes
[wide-area]
-enable-wide-area=yes
+enable-wide-area={$widearea}
[publish]
-#disable-publishing=no
-#disable-user-service-publishing=no
-#add-service-cookie=no
-#publish-addresses=yes
-#publish-hinfo=yes
-#publish-workstation=yes
+disable-publishing={$publish}
+disable-user-service-publishing={$userpublish}
+add-service-cookie={$cookie}
+publish-addresses={$addresspublish}
+publish-hinfo={$hinfopublish}
+publish-workstation={$wspublish}
#publish-domain=yes
-#publish-dns-servers=192.168.50.1, 192.168.50.2
+{$publishdns}
#publish-resolv-conf-dns-servers=yes
-#publish-aaaa-on-ipv4=yes
-#publish-a-on-ipv6=no
+publish-aaaa-on-ipv4={$aaaaonv4}
+publish-a-on-ipv6={$aonv6}
[reflector]
-enable-reflector=yes
-#reflect-ipv=no
+enable-reflector={$reflect}
+reflect-ipv={$reflectipv}
[rlimits]
rlimit-core=0
@@ -162,7 +184,7 @@ EOF;
$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 (!$config['installedpackages']['avahi']['config'][0]['disable_dbus']) {
+ if (!$avahi_config['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";
@@ -178,7 +200,7 @@ EOF;
$start .= "/etc/rc.conf_mount_ro\n";
$stop = "/usr/bin/killall avahi-daemon >/dev/null 2>&1\n";
- if (!$config['installedpackages']['avahi']['config'][0]['disable_dbus']) {
+ if (!$avahi_config['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";
@@ -203,9 +225,51 @@ function avahi_sync() {
}
avahi_write_config();
// Is package enabled?
- if (($config['installedpackages']['avahi']['config'][0]['enable']) && file_exists("/usr/local/etc/rc.d/avahi-daemon.sh")) {
+ if ($config['installedpackages']['avahi']['config'][0]['enable']) {
start_service("avahi");
}
}
+function avahi_upgrade_config() {
+ global $config, $avahi_config;
+
+ $avahi_config =& $config['installedpackages']['avahi']['config'][0];
+ if (!is_array($avahi_config)) {
+ $avahi_config = array();
+ }
+ $changes = 0;
+ // Convert previous disable values to enable ones
+ // If broken settings were configured due to lack of validation, just set to defaults
+ if (isset($avahi_config['disable_ipv4']) && isset($avahi_config['disable_ipv6']) && $avahi_config['disable_ipv4'] == "on" && $avahi_config['disable_ipv6'] == "on") {
+ $avahi_config['enable_ipv4'] = "on";
+ $avahi_config['enable_ipv6'] = "on";
+ unset($avahi_config['disable_ipv4']);
+ unset($avahi_config['disable_ipv6']);
+ $changes++;
+ } elseif (isset($avahi_config['disable_ipv4']) && $avahi_config['disable_ipv4'] != "on") {
+ $avahi_config['enable_ipv4'] = "on";
+ unset($avahi_config['disable_ipv4']);
+ $changes++;
+ } elseif (isset($avahi_config['disable_ipv6']) && $avahi_config['disable_ipv6'] != "on") {
+ $avahi_config['enable_ipv6'] = "on";
+ unset($avahi_config['disable_ipv6']);
+ $changes++;
+ }
+ if ($changes > 0 ) {
+ write_config("[avahi] Upgraded old package configuration.");
+ }
+}
+
+function avahi_validate_input($post, &$input_errors) {
+ if (($post['enable_ipv4'] != "on" ) && ($post['enable_ipv6'] != "on" )) {
+ $input_errors[] = gettext("You cannot disable both IPv4 and IPv6!");
+ }
+ if (($post['enable_ipv4'] != "on" ) && ($post['publish_aaaa_on_ipv4'] == "on" )) {
+ $input_errors[] = gettext("'Publish AAAA records on IPv4' makes no sense with IPv4 disabled.");
+ }
+ if (($post['enable_ipv6'] != "on" ) && ($post['publish_a_on_ipv6'] == "on" )) {
+ $input_errors[] = gettext("'Publish A records on IPv6' makes no sense with IPv6 disabled.");
+ }
+}
+
?>