. All rights reserved. Modified for FreeNAS (http://freenas.org) by Olivier Cochard 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. 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 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ $freenas_config =& $config['installedpackages']['freenas']['config'][0]; function services_samba_configure() { global $freenas_config, $g; /* kill any running samba */ killbyname("smbd"); killbyname("winbindd"); killbyname("nmbd"); if (isset($freenas_config['samba']['enable'])) { if ($g['booting']) echo "Starting Samba... "; /* generate smb.conf */ $fd = fopen("{$g['varetc_path']}/smb.conf", "w"); if (!$fd) { printf("Error: cannot open smb.conf in services_samba_configure().\n"); return 1; } /* If no share configured, exit */ if (!is_array($freenas_config['mounts']['mount'])) return 0; $sambaconf = << 124 backend = ${datarootdir}/wzdftpd/backends/libwzdpam.so max_ul_speed = 0 max_dl_speed = 0 deny_access_files_uploaded = 1 tls_certificate = /usr/local/etc/wzdftpd/wzd.pem sitefile_ginfo = /usr/local/etc/wzdftpd/file_ginfo.txt sitefile_group = /usr/local/etc/wzdftpd/file_group.txt sitefile_user = /usr/local/etc/wzdftpd/file_user.txt [pre_ip_check] localhost = allow [perms] site_addip = +O +G site_adduser = +O +G site_backend = +O site_chacl = +O site_change = +O +G site_changegrp = +O +G site_checkperm = +O site_chgrp = +O site_chmod = +O site_chown = +O site_chpass = * site_chratio = +O +G site_close = +O site_color = !=guest * site_delip = +O +G site_deluser = +O +G site_flags = -admin site_free = * site_ginfo = +O +G site_give = * site_group = +O site_groups = +O site_grpadd = +O site_grpaddip = +O site_grpchange = +O site_grpdel = +O site_grpdelip = +O site_grpkill = +O site_grpratio = +O site_grpren = +O site_gsinfo = +O +G site_help = * site_idle = * site_invite = !=guest * site_kick = +O site_kill = +O site_link = +O site_msg = +O site_perm = +O site_purge = +O +G site_readd = +O +G site_reload = +O site_reopen = +O site_rules = * site_rusage = +O site_savecfg = +O site_sections = +O site_shutdown = +O site_su = +O site_swho = +O site_tagline = !=guest * site_take = +O site_unlock = +O site_uptime = * site_user = +O +G site_users = -admin site_utime = * site_vars = +O site_vars_group = +O site_vars_user = +O site_version = +O site_who = !=guest * site_wipe = +O site_vfsls = +O site_vfsadd = +O site_vfsdel = +O [modules] ${datarootdir}/wzdftpd/modules/libwzd_debug.so = deny ${datarootdir}/wzdftpd/modules/libwzd_test.so = deny ${datarootdir}/wzdftpd/modules/libwzd_sfv.so = allow ${datarootdir}/wzdftpd/modules/libwzd_tcl.so = deny ${datarootdir}/wzdftpd/modules/libwzd_perl.so = deny EOD; if (empty($config['system']['zeroconf_disable'])) { $ftpconf .= << 0) $cron_min = $cron_min . "," . $minutev; else $cron_min = $minutev; } } else $cron_min = "*"; if ($freenas_config['rsyncclient']['all_hours'] == "0") { foreach ($freenas_config['rsyncclient']['hour'] as $hourv) { if (strlen($cron_hour) > 0) $cron_hour = $cron_hour . "," . $hourv; else $cron_hour = $hourv; } } else $cron_hour = "*"; if ($freenas_config['rsyncclient']['all_days'] == "0") { foreach ($freenas_config['rsyncclient']['day'] as $dayv) { if (strlen($cron_day) > 0) $cron_day = $cron_day . "," . $dayv; else $cron_day = $dayv; } } else $cron_day = "*"; if ($freenas_config['rsyncclient']['all_months'] == "0") { foreach ($freenas_config['rsyncclient']['month'] as $monthv) { if (strlen($cron_month) > 0) $cron_month = $cron_month . "," . $monthv; else $cron_month = $monthv; } } else $cron_month = "*"; if ($freenas_config['rsyncclient']['all_weekday'] == "0") { foreach ($freenas_config['rsyncclient']['weekday'] as $weekdayv) { if (strlen($cron_weekday) > 0) $cron_weekday = $cron_weekday . "," . $weekdayv; else $cron_weekday = $weekdayv; } } else $cron_weekday = "*"; $crontabconf .= << 0) $cron_min = $cron_min . "," . $minutev; else $cron_min = $minutev; } } else $cron_min = "*"; if ($freenas_config['shutdown']['all_hours'] == "0") { foreach ($freenas_config['shutdown']['hour'] as $hourv) { if (strlen($cron_hour) > 0) $cron_hour = $cron_hour . "," . $hourv; else $cron_hour = $hourv; } } else $cron_hour = "*"; if ($freenas_config['shutdown']['all_days'] == "0") { foreach ($freenas_config['shutdown']['day'] as $dayv) { if (strlen($cron_day) > 0) $cron_day = $cron_day . "," . $dayv; else $cron_day = $dayv; } } else $cron_day = "*"; if ($freenas_config['shutdown']['all_months'] == "0") { foreach ($freenas_config['shutdown']['month'] as $monthv) { if (strlen($cron_month) > 0) $cron_month = $cron_month . "," . $monthv; else $cron_month = $monthv; } } else $cron_month = "*"; if ($freenas_config['shutdown']['all_weekday'] == "0") { foreach ($freenas_config['shutdown']['weekday'] as $weekdayv) { if (strlen($cron_weekday) > 0) $cron_weekday = $cron_weekday . "," . $weekdayv; else $cron_weekday = $weekdayv; } } else $cron_weekday = "*"; $crontabconf .= << $sharev) { $syncscript .= << @SERVICE_DESC@ on %h @TYPE@ @PORT@ @TXT_RECORDS@ EOD; /* kill any running dbus daemon */ sigkillbypid("{$g['varrun_path']}/dbus/dbus.pid", "TERM"); /* kill any running avahi daemons */ mwexec("/usr/local/sbin/avahi-daemon -k"); if (isset($config['system']['zeroconf_disable'])) return 0; if (! file_exists("/usr/local/etc/avahi/services")) mwexec("mkdir -p /usr/local/etc/avahi/services"); if (isset($config['system']['webgui']['port'])) { $webservice = str_replace("@PORT@", $config['system']['webgui']['port'], $service_template); $webservice = str_replace("@TYPE@", "_http._tcp", $webservice); $webservice = str_replace("@SERVICE_DESC@", "pfSense webGUI", $webservice); $webservice = str_replace("@TXT_RECORDS@", "", $webservice); file_put_contents("/usr/local/etc/avahi/services/http.service", $webservice); } else { $webservice = str_replace("@PORT@", "80", $service_template); $webservice = str_replace("@TYPE@", "_http._tcp", $webservice); $webservice = str_replace("@SERVICE_DESC@", "pfSense webGUI", $webservice); $webservice = str_replace("@TXT_RECORDS@", "", $webservice); file_put_contents("/usr/local/etc/avahi/services/http.service", $webservice); } if (isset($freenas_config['afp']['enable'])) { /* NOP */ } if (isset($freenas_config['rsyncd']['enable'])) { $rsyncservice = str_replace("@PORT@", $config['rsyncd']['port'], $service_template); $rsyncservice = str_replace("@TYPE@", "_rsync._tcp", $rsyncservice); $rsyncservice = str_replace("@SERVICE_DESC@", "Remote Sync Daemon", $rsyncservice); $rsyncservice = str_replace("@TXT_RECORDS@", "", $rsyncservice); file_put_contents("/usr/local/etc/avahi/services/rsync.service", $rsyncservice); } if (isset($config['sshd']['enable'])) { $sshservice = str_replace("@PORT@", "22", $service_template); $sshservice = str_replace("@TYPE@", "_ssh._tcp", $sshservice); $sshservice = str_replace("@SERVICE_DESC@", "Remote Terminal", $sshservice); $sshservice = str_replace("@TXT_RECORDS@", "", $sshservice); file_put_contents("/usr/local/etc/avahi/services/ssh.service", $sshservice); } if (isset($freenas_config['ftp']['enable'])) { /* NOP */ } if (isset($freenas_config['samba']['enable'])) { $cifsservice = str_replace("@PORT@", "139", $service_template); $cifsservice = str_replace("@TYPE@", "_smb._tcp", $cifsservice); $cifsservice = str_replace("@SERVICE_DESC@", "Samba Server", $cifsservice); $cifsservice = str_replace("@TXT_RECORDS@", "", $cifsservice); file_put_contents("/usr/local/etc/avahi/services/cifs.service", $cifsservice); } if (isset($freenas_config['nfs']['enable'])) { /* If no share configured, exit */ if (!is_array($freenas_config['mounts']['mount'])) break; $a_mount = &$freenas_config['mounts']['mount']; foreach ($a_mount as $mount) { $sharename = str_replace(" ", "", $mount['sharename']); $sharename = strtolower($sharename); $nfsservice = str_replace("@PORT@", "2049", $service_template); $nfsservice = str_replace("@TYPE@", "_nfs._tcp", $nfsservice); $nfsservice = str_replace("@SERVICE_DESC@", "NFS Mount: {$mount['sharename']}", $nfsservice); $nfsservice = str_replace("@TXT_RECORDS@", "path=/mnt/{$mount['sharename']}", $nfsservice); file_put_contents("/usr/local/etc/avahi/services/{$sharename}_nfs.service", $nfsservice); } } /* run dbus */ mwexec("/usr/local/bin/dbus-daemon --system"); /* run avahi */ mwexec("/usr/local/sbin/avahi-daemon -D"); if ($g['booting']) echo "done\n"; return 0; } function services_howl_configure() { global $freenas_config, $config, $g; /* kill any mDNSResponder */ killbyname("mDNSResponder"); if (isset($config['system']['zeroconf_disable'])) return 0; $fd = fopen("{$g['varetc_path']}/mDNSResponder.conf", "w"); if (!$fd) { printf("Error: cannot open mDNSResponder.conf in services_howl_configure().\n"); return 1; } if ($config['system']['webgui']['port']) { $mDNSResponder = <<