diff options
Diffstat (limited to 'packages/freenas/pkg/freenas_services.inc')
-rw-r--r-- | packages/freenas/pkg/freenas_services.inc | 2331 |
1 files changed, 1278 insertions, 1053 deletions
diff --git a/packages/freenas/pkg/freenas_services.inc b/packages/freenas/pkg/freenas_services.inc index 91f740e7..8d6f1940 100644 --- a/packages/freenas/pkg/freenas_services.inc +++ b/packages/freenas/pkg/freenas_services.inc @@ -1,75 +1,90 @@ <?php /* $Id$ */ +/* ========================================================================== */ /* - services.inc - part of m0n0wall (http://m0n0.ch/wall) - - Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>. - All rights reserved. - - Modified for FreeNAS (http://freenas.org) by Olivier Cochard <cochard@gmail.com> - - 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_services.inc + part of pfSense (http://www.pfSense.com) + Copyright (C) 2006 Daniel S. Haischt <me@daniel.stefan.haischt.name> + All rights reserved. + + Based on FreeNAS (http://www.freenas.org) + Copyright (C) 2005-2006 Olivier Cochard-Labbé <olivier@freenas.org>. + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>. + 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. + + 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. + */ +/* ========================================================================== */ define (FTP_BACKEND_PAM, "pam"); define (FTP_BACKEND_PLAINTEXT, "plaintext"); $freenas_config =& $config['installedpackages']['freenas']['config'][0]; +/* Stop samba, Generate the samba configuration + * file and start samba Return 0 if OK, 1 or + * error code if error + */ function services_samba_configure() { - global $freenas_config, $g; + global $freenas_config, $g; - /* kill any running samba */ - - killbyname("smbd"); - killbyname("winbindd"); - killbyname("nmbd"); + /* kill any running samba */ + killbyname("smbd"); + killbyname("winbindd"); + killbyname("nmbd"); - if (isset($freenas_config['samba']['enable'])) - { - - if ($g['booting']) - echo "Starting Samba... "; + if (isset($freenas_config['samba']['enable'])) { + if ($g['booting']) { echo "Starting Samba... "; } /* make sure any of the required dirs exist */ - if (! file_exists("{$g['varetc_path']}/private")) + if (! file_exists("{$g['varetc_path']}/private")) { mkdir("{$g['varetc_path']}/private"); - if (! file_exists("{$g['varlog_path']}/samba")) + } + if (! file_exists("{$g['varlog_path']}/samba")) { mkdir("{$g['varlog_path']}/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 = <<<EOD + /* 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; } + + $gen_date = date("F j, Y, g:i a"); + $sambaconf = <<<EOD +# +# smb.conf generated by pfSense +# Generated at: {$gen_date} +# [global] encrypt passwords = yes netbios name = {$freenas_config['samba']['netbiosname']} @@ -81,67 +96,70 @@ dns proxy = no socket options = IPTOS_LOWDELAY TCP_NODELAY EOD; - if ($freenas_config['samba']['sndbuf']) { - $sambaconf .= <<<EOD + if ($freenas_config['samba']['sndbuf']) { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD SO_SNDBUF={$freenas_config['samba']['sndbuf']} EOD; - } - else { - $sambaconf .= <<<EOD + } else { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD SO_SNDBUF=16384 EOD; - } - - if ($freenas_config['samba']['rcvbuf']) { - $sambaconf .= <<<EOD + } // end if + + if ($freenas_config['samba']['rcvbuf']) { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD SO_RCVBUF={$freenas_config['samba']['rcvbuf']} EOD; - } - else { - $sambaconf .= <<<EOD + } else { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD SO_RCVBUF=16384 EOD; - } - - if ($freenas_config['samba']['winssrv']) { - $sambaconf .= <<<EOD + } // end if + + if ($freenas_config['samba']['winssrv']) { + $sambaconf .= <<<EOD wins server = {$freenas_config['samba']['winssrv']} EOD; - } - - if (isset ($freenas_config['samba']['unixcharset'])) { - $sambaconf .= <<<EOD + } + + if (isset ($freenas_config['samba']['unixcharset'])) { + $sambaconf .= <<<EOD unix charset = {$freenas_config['samba']['unixcharset']} EOD; - } - else { - $sambaconf .= <<<EOD + } else { + $sambaconf .= <<<EOD unix charset = UTF-8 EOD; - - } - - - - $sambaconf .= <<<EOD + + } // end if + + $sambaconf .= <<<EOD local master = {$freenas_config['samba']['localmaster']} time server = {$freenas_config['samba']['timesrv']} guest account = ftp display charset = UTF-8 -max log size = 100 -#syslog only = yes -syslog = 3 +max log size = 10 +syslog only = yes +syslog = {$config['samba']['loglevel']} load printers = no printing = bsd printcap name = /dev/null -disable spoolss = Yes +disable spoolss = yes +#Test: Try to improve samba performance under FreeBSD: +use sendfile = yes +strict locking = no +#End of performance section log level = {$freenas_config['samba']['loglevel']} dos charset = {$freenas_config['samba']['doscharset']} smb passwd file = {$g['varetc_path']}/private/smbpasswd @@ -149,23 +167,23 @@ private dir = {$g['varetc_path']}/private EOD; - switch ($freenas_config['samba']['security']) { - case "share": - $sambaconf .= <<<EOD + switch ($freenas_config['samba']['security']) { + case "share": + $sambaconf .= <<<EOD create mask = 0666 directory mask = 0777 passdb backend = smbpasswd EOD; - - $guestmode = <<<EOD + + $guestmode = <<<EOD guest ok = yes EOD; - - break; - case "domain": - $sambaconf .= <<<EOD + + break; // end case "share" + case "domain": + $sambaconf .= <<<EOD passdb backend = smbpasswd allow trusted domains = No dns proxy = No @@ -180,30 +198,29 @@ template homedir = /mnt template shell = /bin/sh EOD; - - $guestmode = <<<EOD + + $guestmode = <<<EOD guest ok = no EOD; - break; - case "user": - $sambaconf .= <<<EOD + break; // end case "domain": + case "user": + $sambaconf .= <<<EOD passdb backend = smbpasswd EOD; - $guestmode = <<<EOD + + $guestmode = <<<EOD guest ok = no EOD; - break; - } - - - - foreach ($freenas_config['mounts']['mount'] as $mountent) { - /* Unmount filesystem if not booting mode*/ - - $sambaconf .= <<<EOD + + break; // end case "user": + } // end switch + + foreach ($freenas_config['mounts']['mount'] as $mountent) { + /* Unmount filesystem if not booting mode*/ + $sambaconf .= <<<EOD [{$mountent['sharename']}] comment = {$mountent['desc']} @@ -211,86 +228,84 @@ path = /mnt/{$mountent['sharename']} public = yes writeable = yes printable = no -veto files = /.snap/ +veto files = /Network Trash Folder/Icon?/:2e*/.AppleDesktop/.AppleDB/.AppleDouble/TheFindByContentFolder/TheVolumeSettingsFolder/Temporary Items/.snap/ +hide dot files = yes {$guestmode} EOD; - if ( (is_array($freenas_config['samba']['hidemount']) && in_array($mountent['sharename'],$freenas_config['samba']['hidemount']))) - - $sambaconf .= <<<EOD + if ( (is_array($freenas_config['samba']['hidemount']) && in_array($mountent['sharename'],$freenas_config['samba']['hidemount']))) { + $sambaconf .= <<<EOD browseable = no EOD; - } - - if (isset($freenas_config['samba']['recyclebin'])) { - $sambaconf .= <<<EOD + } // end if + + if (isset($freenas_config['samba']['recyclebin'])) { + $sambaconf .= <<<EOD vfs object = recycle recycle:repository = Recycle Bin recycle:keeptree = Yes recycle:versions = Yes EOD; - } + } // end if + } // end foreach + + fwrite($fd, $sambaconf); + fclose($fd); + + /* run nmbd and nmbd */ + if (isset($freenas_config['ad']['enable'])) { + mwexec("/usr/local/bin/net rpc join -S {$freenas_config['ad']['ad_srv_name']} -U {$freenas_config['ad']['admin_name']}%{$freenas_config['ad']['admin_pass']}"); + } - fwrite($fd, $sambaconf); - fclose($fd); + $result |= mwexec("/usr/local/sbin/nmbd -D -s {$g['varetc_path']}/smb.conf"); - /* run nmbd and nmbd */ - - if (isset($freenas_config['ad']['enable'])) { - mwexec("/usr/local/bin/net rpc join -S {$freenas_config['ad']['ad_srv_name']} -U {$freenas_config['ad']['admin_name']}%{$freenas_config['ad']['admin_pass']}"); - } + if (isset($freenas_config['ad']['enable'])) { + mwexec("/usr/local/sbin/winbindd -s {$g['varetc_path']}/smb.conf"); + //mwexec("/usr/local/sbin/wbinfo --set-auth-user {$freenas_config['ad']['admin_name']}%{$freenas_config['ad']['admin_pass']}"); + } - mwexec("/usr/local/sbin/nmbd -D -s {$g['varetc_path']}/smb.conf"); - - if (isset($freenas_config['ad']['enable'])) { - mwexec("/usr/local/sbin/winbindd -s {$g['varetc_path']}/smb.conf"); - //mwexec("/usr/local/sbin/wbinfo --set-auth-user {$freenas_config['ad']['admin_name']}%{$freenas_config['ad']['admin_pass']}"); - } - - mwexec("/usr/local/sbin/smbd -D -s {$g['varetc_path']}/smb.conf"); - - - /* TEST: Wait for samba starting */ - sleep(2); + $result |= mwexec("/usr/local/sbin/smbd -D -s {$g['varetc_path']}/smb.conf"); - /* Generate the samba password file */ - system_user_samba(); + /* TEST: Wait for samba starting */ + sleep(2); - if ($g['booting']) - echo "done\n"; - } + /* Generate the samba password file */ + $result |= system_user_samba(); - return 0; + if ($g['booting']) { echo "done\n"; } + }// end if + + return $result; } +/* Stop rsync, Generate the rsync configuration file and start + * rsync Return 0 if OK, 1 or error code if error + */ function services_rsyncd_configure() { - global $freenas_config, $g; + global $freenas_config, $g; - /* kill any running rsync daemon */ + /* kill any running rsync daemon */ + sigkillbypid("{$g['varrun_path']}/rsyncd.pid", "TERM"); - sigkillbypid("{$g['varrun_path']}/rsyncd.pid", "TERM"); + if (isset($freenas_config['rsyncd']['enable'])) { + if ($g['booting']) { echo "Starting RSYNC daemon... "; } - if (isset($freenas_config['rsyncd']['enable'])) { - - if ($g['booting']) - echo "Starting RSYNC daemon... "; - - /* If no share configured, exit */ - if (!is_array($freenas_config['mounts']['mount'])) - return 1; - - /* generate rsyncd.conf */ - $fd = fopen("{$g['varetc_path']}/rsyncd.conf", "w"); - if (!$fd) { - printf("Error: cannot open rsyncd.conf in services_rsyncd_configure().\n"); - return 1; - } - - $rsyncdconf = <<<EOD + /* If no share configured, exit */ + if (!is_array($freenas_config['mounts']['mount'])) { return 1; } + + /* generate rsyncd.conf */ + $fd = fopen("{$g['varetc_path']}/rsyncd.conf", "w"); + + if (!$fd) { + printf("Error: cannot open rsyncd.conf in services_rsyncd_configure().\n"); + return 1; + } + + $rsyncdconf = <<<EOD read only = {$freenas_config['rsyncd']['readonly']} syslog facility = local4 list = yes @@ -299,155 +314,141 @@ pid file = {$g['varrun_path']}/rsyncd.pid EOD; - if (!empty($freenas_config['rsyncd']['maxcon'])) { - $rsyncdconf .= <<<EOD + if (!empty($freenas_config['rsyncd']['maxcon'])) { + $rsyncdconf .= <<<EOD max connections = {$freenas_config['rsyncd']['maxcon']} EOD; - } - - if (!empty($freenas_config['rsyncd']['motd'])) { - $rsyncdconf .= <<<EOD + } + + if (!empty($freenas_config['rsyncd']['motd'])) { + $rsyncdconf .= <<<EOD motd file = {$g['varetc_path']}/rsyncd.motd EOD; - } - - if (isset($freenas_config['rsyncd']['rsyncd_user'])) { - $rsyncdconf .= <<<EOD + } + + if (isset($freenas_config['rsyncd']['rsyncd_user'])) { + $rsyncdconf .= <<<EOD uid = {$freenas_config['rsyncd']['rsyncd_user']} EOD; - } - else { - $rsyncdconf .= <<<EOD + } else { + $rsyncdconf .= <<<EOD uid = ftp gid = ftp EOD; - } + } // end if + foreach ($freenas_config['mounts']['mount'] as $mountent) { + /* Unmount filesystem if not booting mode*/ + $rsyncdconf .= <<<EOD - - foreach ($freenas_config['mounts']['mount'] as $mountent) { - /* Unmount filesystem if not booting mode*/ - - $rsyncdconf .= <<<EOD - [{$mountent['sharename']}] comment = {$mountent['desc']} path = /mnt/{$mountent['sharename']} EOD; - } - - fwrite($fd, $rsyncdconf); - fclose($fd); - - // Generate MOTD file if configured - - if (!empty($freenas_config['rsyncd']['motd'])) { - $fd = fopen("{$g['varetc_path']}/rsyncd.motd", "w"); - if (!$fd) { - printf("Error: cannot open rsyncd.motd in services_rsyncd_configure().\n"); - return 1; - } - - $motd = <<<EOD + } // end foreach + + fwrite($fd, $rsyncdconf); + fclose($fd); + + // Generate MOTD file if configured + if (!empty($freenas_config['rsyncd']['motd'])) { + $fd = fopen("{$g['varetc_path']}/rsyncd.motd", "w"); + + if (!$fd) { + printf("Error: cannot open rsyncd.motd in services_rsyncd_configure().\n"); + return 1; + } + + $motd = <<<EOD {$freenas_config['rsyncd']['motd']} EOD; - - fwrite($fd, $motd); - fclose($fd); - } - /* run rsync Daemon */ - mwexec("/usr/local/bin/rsync --daemon --config={$g['varetc_path']}/rsyncd.conf"); + fwrite($fd, $motd); + fclose($fd); + } // end if + /* run rsync Daemon */ + $result = mwexec("/usr/local/bin/rsync --daemon --config={$g['varetc_path']}/rsyncd.conf"); - if ($g['booting']) - echo "done\n"; - } + if ($g['booting']) { echo "done\n"; } + } // end if - return 0; + return $result; } +/* Stop nfs processes, Generate the nfs configuration file and + * start nfsd processes Return 0 if OK, 1 or error code if error + */ function services_nfs_configure() { - global $freenas_config, $g; + global $freenas_config, $g; - /* kill any running nfsd */ - - killbyname("rpc.statd"); - killbyname("rpc.lockd"); - killbypid("{$g['varrun_path']}/mountd.pid"); - forcekillbyname("nfsd"); - killbyname("rpcbind"); + /* kill any running nfsd */ + killbyname("rpc.statd"); + killbyname("rpc.lockd"); + killbypid("{$g['varrun_path']}/mountd.pid"); + forcekillbyname("nfsd"); + killbyname("rpcbind"); + + if (isset($freenas_config['nfs']['enable'])) { + if ($g['booting']) { echo "Starting NFS... "; } + + /* If no share configured, exit */ + if (!is_array($freenas_config['mounts']['mount'])) { return 1; } + + /* generate exports */ + $fd = fopen("{$g['varetc_path']}/exports", "w"); + + if (!$fd) { + printf("Error: cannot open exports in services_nfs_configure().\n"); + return 1; + } - - if (isset($freenas_config['nfs']['enable'])) - { - - if ($g['booting']) - echo "Starting NFS... "; - - /* If no share configured, exit */ - if (!is_array($freenas_config['mounts']['mount'])) - return 1; - - /* generate exports */ - $fd = fopen("{$g['varetc_path']}/exports", "w"); - if (!$fd) { - printf("Error: cannot open exports in services_nfs_configure().\n"); - return 1; - } - - list($network,$subnet) = - explode('/', $freenas_config['nfs']['nfsnetwork']); - - $subnet = gen_subnet_mask($subnet); - - $a_mount = &$freenas_config['mounts']['mount']; - - foreach ($a_mount as $mount) - { - $nfsconf .= <<<EOD + list($network,$subnet) = + explode('/', $freenas_config['nfs']['nfsnetwork']); + + $subnet = gen_subnet_mask($subnet); + $a_mount = &$freenas_config['mounts']['mount']; + + foreach ($a_mount as $mount) { + $nfsconf .= <<<EOD /mnt/{$mount['sharename']} -alldirs -maproot=root EOD; - if ($freenas_config['nfs']['mapall'] == "yes") - { - - $nfsconf .= <<<EOD + if ($freenas_config['nfs']['mapall'] == "yes") { + $nfsconf .= <<<EOD -mapall=root EOD; - - } - - $nfsconf .= <<<EOD --network {$network} -mask $subnet -EOD; - - } - fwrite($fd, $nfsconf); - fclose($fd); + } - /* run rpcbind, nfsd and mountd */ - mwexec("/usr/sbin/rpcbind"); - mwexec("/usr/sbin/nfsd -u -t -n 4"); - mwexec("/usr/sbin/mountd -r {$g['varetc_path']}/exports"); - mwexec("/usr/sbin/rpc.lockd"); - mwexec("/usr/sbin/rpc.statd"); + $nfsconf .= <<<EOD +-network {$network} -mask $subnet +EOD; - if ($g['booting']) - echo "done\n"; - } + } // end foreach + + fwrite($fd, $nfsconf); + fclose($fd); + + /* run rpcbind, nfsd and mountd */ + mwexec("/usr/sbin/rpcbind"); + mwexec("/usr/sbin/nfsd -u -t -n 4"); + mwexec("/usr/sbin/mountd -r {$g['varetc_path']}/exports"); + mwexec("/usr/sbin/rpc.lockd"); + mwexec("/usr/sbin/rpc.statd"); + + if ($g['booting']) { echo "done\n"; } + } // end if - return 0; - + return 0; } function services_ftpd_configure() { @@ -458,31 +459,28 @@ function services_ftpd_configure() { } function services_wzdftpd_configure() { - global $freenas_config, $config, $g; - - /* kill any WZDFTPD */ - killbyname("wzdftpd"); + global $freenas_config, $config, $g; - if (isset($freenas_config['ftp']['enable'])) { + /* kill any WZDFTPD */ + killbyname("wzdftpd"); - if ($g['booting']) - echo "Starting FTP server... "; + if (isset($freenas_config['ftp']['enable'])) { + if ($g['booting']) { echo "Starting FTP server... "; } - if (! file_exists("/var/log/wzdftpd")) - mkdir("/var/log/wzdftpd"); + /* create missing dirs if necessary */ + if (! file_exists("/var/log/wzdftpd")) { mkdir("/var/log/wzdftpd"); } + if (! file_exists("/usr/local/etc/wzdftpd")) { mkdir("/usr/local/etc/wzdftpd"); } - if (! file_exists("/usr/local/etc/wzdftpd")) - mkdir("/usr/local/etc/wzdftpd"); - - /* generate wzd.cfg */ + /* generate wzd.cfg */ chmod("/usr/local/etc/wzdftpd/wzd.cfg", 0600); - $fd = fopen("/usr/local/etc/wzdftpd/wzd.cfg", "w"); - if (!$fd) { - printf("Error: cannot open vsftpd.conf in services_vsftpd_configure().\n"); - return 1; - } + $fd = fopen("/usr/local/etc/wzdftpd/wzd.cfg", "w"); + + if (!$fd) { + printf("Error: cannot open vsftpd.conf in services_vsftpd_configure().\n"); + return 1; + } - $ftpconf = <<<EOD + $ftpconf = <<<EOD [GLOBAL] config version = 0.7.2 backup config = true @@ -490,15 +488,15 @@ port = {$freenas_config['ftp']['port']} EOD; - if ($freenas_config['ftp']['pasv_min_port'] && $freenas_config['ftp']['pasv_max_port']) { - $ftpconf .= <<<EOD + if ($freenas_config['ftp']['pasv_min_port'] && $freenas_config['ftp']['pasv_max_port']) { + $ftpconf .= <<<EOD pasv_low_range = {$freenas_config['ftp']['pasv_min_port']} pasv_high_range = {$freenas_config['ftp']['pasv_max_port']} EOD; - } + } - $ftpconf .= <<<EOD + $ftpconf .= <<<EOD pasv_ip = {$freenas_config['ftp']['pasv_address']} dir_message = .message @@ -557,13 +555,13 @@ site_help = * EOD; -if (! empty($freenas_config['ftp']['timeout'])) { -$ftpconf .= "site_idle ={$freenas_config['ftp']['timeout']}\n"; -} else { -$ftpconf .= "site_idle = *\n"; -} + if (! empty($freenas_config['ftp']['timeout'])) { + $ftpconf .= "site_idle ={$freenas_config['ftp']['timeout']}\n"; + } else { + $ftpconf .= "site_idle = *\n"; + } - $ftpconf .= <<<EOD + $ftpconf .= <<<EOD site_invite = !=guest * site_kick = +O site_kill = +O @@ -607,8 +605,8 @@ site_vfsdel = +O EOD; - if (empty($config['system']['zeroconf_disable'])) { - $ftpconf .= <<<EOD + if (empty($config['system']['zeroconf_disable'])) { + $ftpconf .= <<<EOD /usr/local/share/wzdftpd/modules/libwzd_zeroconf.so = allow [ZEROCONF] @@ -619,9 +617,9 @@ zeroconf_path = / EOD; - } + } - $ftpconf .= <<<EOD + $ftpconf .= <<<EOD [sfv] progressmeter = [WzD] - %3d%% Complete - [WzD] @@ -655,36 +653,38 @@ site_who = !/usr/local/etc/wzdftpd/file_who.txt EOD; - if (isset($freenas_config['ftp']['banner'])) { - $ftpconf .= "200 = {$freenas_config['ftp']['banner']}"; - } + if (isset($freenas_config['ftp']['banner'])) { + $ftpconf .= "200 = {$freenas_config['ftp']['banner']}"; + } else { + $ftpconf .= "200 = Welcome to pfSense FTP service"; + } - fwrite($fd, $ftpconf); - fclose($fd); - chmod("/usr/local/etc/wzdftpd/wzd.cfg", 0400); + fwrite($fd, $ftpconf); + fclose($fd); + chmod("/usr/local/etc/wzdftpd/wzd.cfg", 0400); - /* now generate the plaintext users file (if applicable) */ - if ($freenas_config['ftp']['authentication_backend'] == FTP_BACKEND_PLAINTEXT) { - $ftpusers = "[GROUPS]\n"; - $a_group =& $config['system']['group']; - $a_user =& $config['system']['user']; + /* now generate the plaintext users file (if applicable) */ + if ($freenas_config['ftp']['authentication_backend'] == FTP_BACKEND_PLAINTEXT) { + $ftpusers = "[GROUPS]\n"; + $a_group =& $config['system']['group']; + $a_user =& $config['system']['user']; - for ($i = 0; $i < count($a_group); $i++) { - $group = $a_group[$i]; - $gid = $i + 1; + for ($i = 0; $i < count($a_group); $i++) { + $group = $a_group[$i]; + $gid = $i + 1; - $ftpusers .= <<<EOD + $ftpusers .= <<<EOD privgroup {$group['name']} gid={$gid} default_home=/ EOD; - } // end foreach + } // end foreach - /* anonymous group */ - if (! empty($freenas_config['ftp']['anonymous'])) { - $ftpusers .= <<<EOD + /* anonymous group */ + if (! empty($freenas_config['ftp']['anonymous'])) { + $ftpusers .= <<<EOD privgroup anonymous max_idle_time=10 @@ -694,11 +694,11 @@ default_home=/home EOD; } - /* same for users */ - $ftpusers .= "[USERS]\n"; - for ($i = 0; $i < count($a_user); $i++) { - $user = $a_user[$i]; - $ftpusers .= <<<EOD + /* same for users */ + $ftpusers .= "[USERS]\n"; + for ($i = 0; $i < count($a_user); $i++) { + $user = $a_user[$i]; + $ftpusers .= <<<EOD name={$user['name']} pass={$user['password']} @@ -708,11 +708,11 @@ groups={$user['groupname']} rights=0xffffffff EOD; - } // end foreach + } // end foreach - /* anonymous user */ - if (! empty($freenas_config['ftp']['anonymous'])) { - $ftpusers .= <<<EOD + /* anonymous user */ + if (! empty($freenas_config['ftp']['anonymous'])) { + $ftpusers .= <<<EOD name=guest pass=% @@ -728,45 +728,42 @@ bytes_dl_total=1918812 num_logins=2 EOD; - } - - $ftpusers .= "[HOSTS]\nall = *\n"; - chmod("/usr/local/etc/wzdftpd/users", 0600); - file_put_contents("/usr/local/etc/wzdftpd/users", $ftpusers); - chmod("/usr/local/etc/wzdftpd/users", 0400); - - } // end if + } // end if - /* run vsftpd */ - mwexec("/usr/local/sbin/wzdftpd -f /usr/local/etc/wzdftpd/wzd.cfg"); + $ftpusers .= "[HOSTS]\nall = *\n"; + chmod("/usr/local/etc/wzdftpd/users", 0600); + file_put_contents("/usr/local/etc/wzdftpd/users", $ftpusers); + chmod("/usr/local/etc/wzdftpd/users", 0400); + } // end if + /* run vsftpd */ + mwexec("/usr/local/sbin/wzdftpd -f /usr/local/etc/wzdftpd/wzd.cfg"); - if ($g['booting']) - echo "done\n"; - } + if ($g['booting']) { echo "done\n"; } + } // end if - return 0; + return 0; } +/* this function is currently not used */ function services_vsftpd_configure() { - global $freenas_config, $g; + global $freenas_config, $g; - /* kill any VSFTPD */ - killbyname("vsftpd"); + /* kill any VSFTPD */ + killbyname("vsftpd"); - if (isset($freenas_config['ftp']['enable'])) { - - if ($g['booting']) - echo "Starting FTP server... "; - - /* generate vfstpd.conf */ - $fd = fopen("{$g['varetc_path']}/vsftpd.conf", "w"); - if (!$fd) { - printf("Error: cannot open vsftpd.conf in services_vsftpd_configure().\n"); - return 1; - } - - $ftpconf = <<<EOD + if (isset($freenas_config['ftp']['enable'])) { + if ($g['booting']) { echo "Starting FTP server... "; } + + /* generate vfstpd.conf */ + $fd = fopen("{$g['varetc_path']}/vsftpd.conf", "w"); + + if (!$fd) { + printf("Error: cannot open vsftpd.conf in services_vsftpd_configure().\n"); + return 1; + } + + $ftpconf = <<<EOD # Standalone mode listen=YES background=YES @@ -795,345 +792,504 @@ ls_recurse_enable=YES idle_session_timeout={$freenas_config['ftp']['timeout']} EOD; - if (isset($freenas_config['ftp']['banner'])) { - $ftpconf .= <<<EOD + if (isset($freenas_config['ftp']['banner'])) { + $ftpconf .= <<<EOD ftpd_banner={$freenas_config['ftp']['banner']} EOD; - } - else { - $ftpconf .= <<<EOD -ftpd_banner=Welcome to FreeNAS FTP service + } else { + $ftpconf .= <<<EOD +ftpd_banner=Welcome to pfSense FTP service EOD; - } - - if ($freenas_config['ftp']['pasv_min_port'] && $freenas_config['ftp']['pasv_max_port']) { - $ftpconf .= <<<EOD + } + + if ($freenas_config['ftp']['pasv_min_port'] && $freenas_config['ftp']['pasv_max_port']) { + $ftpconf .= <<<EOD pasv_max_port={$freenas_config['ftp']['pasv_max_port']} pasv_min_port={$freenas_config['ftp']['pasv_min_port']} EOD; - } - - if ($freenas_config['ftp']['pasv_address']) { - $ftpconf .= <<<EOD + } + + if ($freenas_config['ftp']['pasv_address']) { + $ftpconf .= <<<EOD pasv_address={$freenas_config['ftp']['pasv_address']} EOD; - } - - fwrite($fd, $ftpconf); - fclose($fd); + } - /* run vsftpd */ - mwexec("/usr/local/sbin/vsftpd {$g['varetc_path']}/vsftpd.conf"); + fwrite($fd, $ftpconf); + fclose($fd); + /* run vsftpd */ + mwexec("/usr/local/sbin/vsftpd {$g['varetc_path']}/vsftpd.conf"); - if ($g['booting']) - echo "done\n"; - } + if ($g['booting']) { echo "done\n"; } + } - return 0; + return 0; } function services_pureftpd_configure() { + global $freenas_config, $g; - // Stop the pure-ftpd process and re-start it - - global $freenas_config, $g; + /* kill any Pure-FTPD */ + killbyname("pure-ftpd"); - /* kill any Pure-FTPD */ - killbyname("pure-ftpd"); + if (isset($freenas_config['ftp']['enable'])) { + if ($g['booting']) { echo "Starting FTP server... "; } - if (isset($freenas_config['ftp']['enable'])) { - - if ($g['booting']) - echo "Starting FTP server... "; - - /* Generate the banner file */ - - $fd = fopen("/mnt/.banner", "w"); - if (!$fd) { - printf("Error: cannot open .banner in services_pureftpd_configure().\n"); - return 1; - } - - if (empty($freenas_config['ftp']['banner'])) { - $banner = <<<EOD -Welcome to FreeNAS FTP service + /* Generate the banner file */ + $fd = fopen("/mnt/.banner", "w"); + + if (!$fd) { + printf("Error: cannot open .banner in services_pureftpd_configure().\n"); + return 1; + } + + if (empty($freenas_config['ftp']['banner'])) { + $banner = <<<EOD +Welcome to pfSense FTP service EOD; - } else { - $banner = <<<EOD + } else { + $banner = <<<EOD {$freenas_config['ftp']['banner']} - + EOD; - } - - fwrite($fd, $banner); - fclose($fd); - - - /* run pure-ftpd */ - - $cmd = "/usr/local/sbin/pure-ftpd -S {$freenas_config['ftp']['port']} -c {$freenas_config['ftp']['numberclients']} -C {$freenas_config['ftp']['maxconperip']} -I {$freenas_config['ftp']['timeout']} -M U 077:077 -B -b "; - - if ( (isset($freenas_config['ftp']['anonymous'])) && (!isset($freenas_config['ftp']['localuser']))) - $cmd .= "-e "; - - if ( (!isset($freenas_config['ftp']['anonymous'])) && (isset($freenas_config['ftp']['localuser']))) - $cmd .= "-E "; - - if ($freenas_config['ftp']['pasv_min_port'] && $freenas_config['ftp']['pasv_max_port']) - $cmd .= "-p {$freenas_config['ftp']['pasv_min_port']}:{$freenas_config['ftp']['pasv_max_port']} "; - - if ($freenas_config['ftp']['pasv_address']) - $cmd .= "-P {$freenas_config['ftp']['pasv_address']} "; - - if ($freenas_config['ftp']['natmode']) - $cmd .= "-N "; - - if ($freenas_config['ftp']['passiveip']) - $cmd .= "-P {$freenas_config['ftp']['passiveip']} "; - - if ($freenas_config['ftp']['fxp']) - $cmd .= "-W "; - - - mwexec($cmd); - - - if ($g['booting']) - echo "done\n"; - } - - - return 0; + } // end if + + fwrite($fd, $banner); + fclose($fd); + + /* run pure-ftpd */ + $cmd = "/usr/local/sbin/pure-ftpd -S {$freenas_config['ftp']['port']} -c {$freenas_config['ftp']['numberclients']} -C {$freenas_config['ftp']['maxconperip']} -I {$freenas_config['ftp']['timeout']} -M U 077:077 -B -b "; + + if ( (isset($freenas_config['ftp']['anonymous'])) && (!isset($freenas_config['ftp']['localuser']))) { + $cmd .= "-e "; + } + + if ( (!isset($freenas_config['ftp']['anonymous'])) && (isset($freenas_config['ftp']['localuser']))) { + $cmd .= "-E "; + } + + if ($freenas_config['ftp']['pasv_min_port'] && $freenas_config['ftp']['pasv_max_port']) { + $cmd .= "-p {$freenas_config['ftp']['pasv_min_port']}:{$freenas_config['ftp']['pasv_max_port']} "; + } + + if ($freenas_config['ftp']['pasv_address']) { + $cmd .= "-P {$freenas_config['ftp']['pasv_address']} "; + } + + if ($freenas_config['ftp']['natmode']) { + $cmd .= "-N "; + } + + if ($freenas_config['ftp']['passiveip']) { + $cmd .= "-P {$freenas_config['ftp']['passiveip']} "; + } + + if ($freenas_config['ftp']['fxp']) { + $cmd .= "-W "; + } + + mwexec($cmd); + + if ($g['booting']) { echo "done\n"; } + } // end if + + return 0; } +/* Stop smartd, Generate the configuration file and start + * smartd Return 0 if OK, 1 or error code if error + */ function services_smart_configure() { - global $config, $g; - - /* kill any running smartd */ - killbyname("smartd"); + global $config, $g; - if (isset($config['system']['smart'])) { + /* kill any running smartd */ + killbyname("smartd"); - if ($g['booting']) - echo "Starting smartd... "; + if (isset($config['system']['smart'])) { + if ($g['booting']) { echo "Starting smartd... "; } - /* run smartd */ - mwexec("/usr/local/sbin/smartd --logfacility=local5"); + /* run smartd */ + mwexec("/usr/local/sbin/smartd --logfacility=local5"); - if ($g['booting']) - echo "done\n"; - } + if ($g['booting']) { echo "done\n"; } + } - return 0; + return 0; +} + +/* Generate the unison configuration + * Return 0 if OK, 1 or error code if error + */ +function services_unison_configure() { + global $freenas_config, $g; + $result = 0 ; + + if ($g['booting']) { echo "Configuring unison... \n"; } + + if (isset($freenas_config['unison']['enable'])) { + /* ensure unison workdir exists */ + $workdir = "/mnt/{$freenas_config['unison']['share']}/{$config['unison']['workdir']}"; + + if (isset($freenas_config['unison']['makedir']) && !file_exists($workdir)) { + if (!mkdir($workdir)) { + printf("Error: cannot mkdir $workdir in services_unison_configure().\n"); + } + + exec("/bin/chmod 775 $workdir"); + } + + if (!file_exists($workdir)) { + printf("Error: cannot open $workdir in services_unison_configure().\n"); + $result = 1 ; + } + + /* add workdir to login.conf UNISON environment variable */ + $logfile = "{$g['etc_path']}/login.conf"; + + if (!file_exists("$logfile")) { + printf("Error: $logfile doesn't exist, in services_unison_configure().\n"); + $result = 1 ; + } + + $tmp = file_get_contents("$logfile"); + $search = "/UNISON=.*?(?=[,:])/"; + + if (!preg_match($search, $tmp)) { + printf("Error: cannot find UNISON in $logfile, in services_unison_configure().\n"); + $result = 1 ; + } + + $tmp = preg_replace($search, "UNISON=$workdir", $tmp); + + if (!file_put_contents($logfile, $tmp)) { + printf("Error: couldn't write $logfile, in services_unison_configure().\n"); + $result = 1 ; + } + } // end if + + $tmp = ""; + + return $result; +} + +/* Stop and start ushare + * Return 0 if OK, 1 or error code if error + */ +function services_ushare_configure() { + global $freenas_config, $g; + + $result = 0 ; + + /* Kill any running uShare */ + killbyname("ushare"); + + /* Delete multicast route. */ + mwexec("/sbin/route delete -net 239.0.0.0"); + + if(isset($freenas_config['upnp']['enable'])) { + if($g['booting']) { echo "Starting UPnP server... "; } + + /* Setup a multicast route for UPnP messages. */ + // TODO: where to get the upnp iface? + $result = mwexec("/sbin/route add -net 239.0.0.0 -netmask 255.0.0.0 -interface " . escapeshellarg($freenas_config['upnp']['if'])); + + $content = ""; + foreach($freenas_config['upnp']['content'] as $contentv) { + $content .= " --content=$contentv"; + } + + /* Run uShare as daemon. */ + // TODO: where to get the upnp iface? + $result |= mwexec("/usr/local/bin/ushare --daemon --no-web --name={$freenas_config['upnp']['name']} --interface={$freenas_config['upnp']['if']} {$content}"); + } // end if + + return $result; } function services_cron_configure() { - global $freenas_config, $g; - - /* kill any running cron */ - killbyname("cron"); - - /* generate crontab */ - $fd = fopen("{$g['varetc_path']}/crontab", "w"); - - $crontabconf = <<<EOD -SHELL=/bin/sh -PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin -HOME=/var/log -# -#minute hour mday month wday who command -# + global $freenas_config, $g; + + /* kill any running cron */ + killbyname("cron"); + + /* ======================================================================= */ + /* = configure crontab item for rsyncclient = */ + /* ======================================================================= */ + if (isset($freenas_config['rsyncclient']['enable'])) { + if ($g['booting']) { echo "Configuring cron for rsync client... "; } + + if ($freenas_config['rsyncclient']['all_mins'] == "0") { + foreach ($freenas_config['rsyncclient']['minute'] as $minutev) { + if (strlen($cron_min) > 0) { + $cron_min = $cron_min . "," . $minutev; + } else { + $cron_min = $minutev; + } + } // end foreach + } else { + $cron_min = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_hour = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_day = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_month = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_weekday = "*"; + } // end if + + $cron_item = array(); + $cron_item['minute'] = "{$cron_min}"; + $cron_item['hour'] = "{$cron_hour}"; + $cron_item['mday'] = "{$cron_day}"; + $cron_item['month'] = "{$cron_month}"; + $cron_item['wday'] = "{$cron_weekday}"; + $cron_item['who'] = "root"; + $cron_item['command'] = "{$g['varrun_path']}/sync.sh"; + + $config['cron']['item'][] = $cron_item; + + if ($g['booting']) { echo "done\n"; } + } // end if -EOD; + /* Erase all variable used previously */ + unset ($cron_min, $cron_hour, $cron_day, $cron_month, $cron_weekday); + + /* ======================================================================= */ + /* = configure crontab item for rsync local part = */ + /* ======================================================================= */ + if (isset($freenas_config['rsync_local']['enable'])) { + if ($g['booting']) { echo "Configuring cron for local rsync... "; } + + if ($freenas_config['rsync_local']['all_mins'] == "0") { + foreach ($freenas_config['rsync_local']['minute'] as $minutev) { + if (strlen($cron_min) > 0) { + $cron_min = $cron_min . "," . $minutev; + } else { + $cron_min = $minutev; + } + } // end foreach + } else { + $cron_min = "*"; + } // end if + + if ($freenas_config['rsync_local']['all_hours'] == "0") { + foreach ($freenas_config['rsync_local']['hour'] as $hourv) { + if (strlen($cron_hour) > 0) { + $cron_hour = $cron_hour . "," . $hourv; + } else { + $cron_hour = $hourv; + } + } // end foreach + } else { + $cron_hour = "*"; + } // end if + + if ($freenas_config['rsync_local']['all_days'] == "0") { + foreach ($freenas_config['rsync_local']['day'] as $dayv) { + if (strlen($cron_day) > 0) { + $cron_day = $cron_day . "," . $dayv; + } else { + $cron_day = $dayv; + } + } // end foreach + } else { + $cron_day = "*"; + } // end if + + if ($freenas_config['rsync_local']['all_months'] == "0") { + foreach ($freenas_config['rsync_local']['month'] as $monthv) { + if (strlen($cron_month) > 0) { + $cron_month = $cron_month . "," . $monthv; + } else { + $cron_month = $monthv; + } + } // end foreach + } else { + $cron_month = "*"; + } // end if + + if ($freenas_config['rsync_local']['all_weekday'] == "0") { + foreach ($freenas_config['rsync_local']['weekday'] as $weekdayv) { + if (strlen($cron_weekday) > 0) { + $cron_weekday = $cron_weekday . "," . $weekdayv; + } else { + $cron_weekday = $weekdayv; + } + } // end foreach + } else { + $cron_weekday = "*"; + } - if (!$fd) { - printf("Error: cannot open crontab in services_cron_configure().\n"); - return 1; - } - - if (isset($freenas_config['rsyncclient']['enable'])) { - - if ($g['booting']) - echo "Configuring cron for rsync client... "; - - if ($freenas_config['rsyncclient']['all_mins'] == "0") { - foreach ($freenas_config['rsyncclient']['minute'] as $minutev) { - if (strlen($cron_min) > 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 .= <<<EOD -{$cron_min} {$cron_hour} {$cron_day} {$cron_month} {$cron_weekday} root {$g['varrun_path']}/sync.sh - -EOD; - - if ($g['booting']) - echo "done\n"; - } - - // Erase all variable used previously - unset ($cron_min, $cron_hour, $cron_day, $cron_month, $cron_weekday); - - if (isset($freenas_config['shutdown']['enable'])) { - - if ($g['booting']) - echo "Configuring cron for shutdown... "; - - if ($freenas_config['shutdown']['all_mins'] == "0") { - foreach ($freenas_config['shutdown']['minute'] as $minutev) { - if (strlen($cron_min) > 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 .= <<<EOD -{$cron_min} {$cron_hour} {$cron_day} {$cron_month} {$cron_weekday} root /etc/rc.shutdown - -EOD; - - if ($g['booting']) - echo "done\n"; - } - - fwrite($fd, $crontabconf); - fclose($fd); - - /* run cron */ - mwexec("/usr/sbin/cron -s"); - - return 0; - + $cron_item = array(); + $cron_item['minute'] = "{$cron_min}"; + $cron_item['hour'] = "{$cron_hour}"; + $cron_item['mday'] = "{$cron_day}"; + $cron_item['month'] = "{$cron_month}"; + $cron_item['wday'] = "{$cron_weekday}"; + $cron_item['who'] = "root"; + $cron_item['command'] = "{$g['varrun_path']}/sync.sh"; + + $config['cron']['item'][] = $cron_item; + + if ($g['booting']) { echo "done\n"; } + } + + /* Erase all variable used previously */ + unset ($cron_min, $cron_hour, $cron_day, $cron_month, $cron_weekday); + + /* ======================================================================= */ + /* = configure crontab item shutdown part = */ + /* ======================================================================= */ + if (isset($freenas_config['shutdown']['enable'])) { + if ($g['booting']) { echo "Configuring cron for shutdown... "; } + + if ($freenas_config['shutdown']['all_mins'] == "0") { + foreach ($freenas_config['shutdown']['minute'] as $minutev) { + if (strlen($cron_min) > 0) { + $cron_min = $cron_min . "," . $minutev; + } else { + $cron_min = $minutev; + } + } // end foreach + } else { + $cron_min = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_hour = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_day = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_month = "*"; + } // end if + + 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; + } + } // end foreach + } else { + $cron_weekday = "*"; + } // end if + + $cron_item = array(); + $cron_item['minute'] = "{$cron_min}"; + $cron_item['hour'] = "{$cron_hour}"; + $cron_item['mday'] = "{$cron_day}"; + $cron_item['month'] = "{$cron_month}"; + $cron_item['wday'] = "{$cron_weekday}"; + $cron_item['who'] = "root"; + $cron_item['command'] = "{$g['varrun_path']}/sync.sh"; + + $config['cron']['item'][] = $cron_item; + + if ($g['booting']) { echo "done\n"; } + } // end if + + /* call the pfSense configure_cron function */ + configure_cron(); + + /* run cron */ + mwexec("/usr/sbin/cron -s"); + + return 0; } -function services_rsyncclient_configure() -{ - global $freenas_config, $g; +function services_rsyncclient_configure() { + global $freenas_config, $g; - // Generate a shell script that is used by cron - // Generate crontab works - - if (isset($freenas_config['rsyncclient']['enable'])) - { - - if ($g['booting']) - echo "Generating synchronizing cron script... "; - - /* generate /var/run/sync.sh script */ - $fd = fopen("{$g['varrun_path']}/sync.sh", "w"); - if (!$fd) - { - printf("Error: cannot open /var/run/sync.sh in services_rsyncclient_configure().\n"); - return 1; - } - - $syncscript = <<<EOD + // Generate a shell script that is used by cron + // Generate crontab works + if (isset($freenas_config['rsyncclient']['enable'])) { + if ($g['booting']) { echo "Generating synchronizing cron script... "; } + + /* generate /var/run/sync.sh script */ + $fd = fopen("{$g['varrun_path']}/sync.sh", "w"); + + if (!$fd) { + printf("Error: cannot open /var/run/sync.sh in services_rsyncclient_configure().\n"); + return 1; + } + + $syncscript = <<<EOD #!/bin/sh if [ -r /var/run/rsync-running ]; then @@ -1143,167 +1299,243 @@ fi EOD; - $opt_delete=""; - if (isset($freenas_config['rsyncclient']['opt_delete'])) - $opt_delete = "--delete --delete-after "; - - foreach ($freenas_config['rsyncclient']['sharetosync'] as $sharek => $sharev) - { - $syncscript .= <<<EOD + $opt_delete=""; + if (isset($freenas_config['rsyncclient']['opt_delete'])) { + $opt_delete = "--delete --delete-after "; + } + + foreach ($freenas_config['rsyncclient']['sharetosync'] as $sharek => $sharev) { + $syncscript .= <<<EOD /usr/local/bin/rsync -rtz {$opt_delete}rsync://{$freenas_config['rsyncclient']['rsyncserverip']}/{$sharev} /mnt/{$sharev} EOD; - } - - $syncscript .= <<<EOD + } // end foreach + + $syncscript .= <<<EOD /bin/rm -f /var/run/rsync-running EOD; - fwrite($fd,$syncscript); - fclose($fd); - - /* Add exectutive right to the script */ - exec("/bin/chmod 770 {$g['varrun_path']}/sync.sh"); - - if ($g['booting']) - echo "done\n"; - return 0; - } - - return 0; + fwrite($fd,$syncscript); + fclose($fd); + + /* Add exectutive right to the script */ + exec("/bin/chmod 770 {$g['varrun_path']}/sync.sh"); + + if ($g['booting']) { echo "done\n"; } + } // end if + + return 0; } -function services_afpd_configure() -{ - global $freenas_config, $config, $g; +function services_rsync_local_configure() { + global $freenas_config, $g; + + // Generate a shell script that is used by cron + // Generate crontab works + if (isset($freenas_config['rsync_local']['enable'])) { + if ($g['booting']) { echo "Generating local rsync cron script... "; } + + /* generate /var/run/sync_local.sh script */ + $fd = fopen("{$g['varrun_path']}/sync_local.sh", "w"); + + if (!$fd) { + printf("Error: cannot open /var/run/sync_local.sh in services_rsync_local_configure().\n"); + return 1; + } - /* kill any VSFTPD */ - killbyname("afpd"); + $syncscript = <<<EOD +#!/bin/sh - if (isset($freenas_config['afp']['enable'])) { - - /* If no share configured, exit */ - if (!is_array($freenas_config['mounts']['mount'])) - return 1; - - if ($g['booting']) - echo "Starting AFP server... "; - - if (empty($freenas_config['afp']['afpname'])) - $afpname="-"; - else - $afpname=$freenas_config['afp']['afpname']; - - /* generate afpd.conf */ - $fd = fopen("{$g['varetc_path']}/afpd.conf", "w"); - if (!$fd) { - printf("Error: cannot open afpd.conf in services_afpd_configure().\n"); - return 1; - } - - $afpconf = <<<EOD -{$afpname} -transall -EOD; - - if (empty($config['system']['zeroconf_disable'])) { - $afpconf .= <<<EOD +if [ -r /var/run/rsync_local-running ]; then +exit +fi +/usr/bin/touch /var/run/rsync_local-running + +EOD; + + $opt_delete=""; + if (isset($freenas_config['rsync_local']['opt_delete'])) { + $opt_delete = "--delete --delete-after "; + } + + $syncscript .= <<<EOD +/usr/local/bin/rsync -a {$opt_delete} /mnt/{$freenas_config['rsync_local']['source']} /mnt/{$freenas_config['rsync_local']['destination']} + +EOD; + + $syncscript .= <<<EOD +/bin/rm -f /var/run/rsync_local-running + +EOD; + + fwrite($fd,$syncscript); + fclose($fd); + + /* Add exectutive right to the script */ + exec("/bin/chmod 770 {$g['varrun_path']}/sync_local.sh"); + + if ($g['booting']) { echo "done\n"; } + } // end if + + return 0; +} + +function services_radius_configure() { + global $freenas_config, $g; + + if (isset($config['radius']['enable'])) { + /* generate radius.conf */ + $fd = fopen("{$g['varetc_path']}/radius.conf", "w"); + + if (!$fd) { + printf("Error: cannot open radius.conf in services_radius_configure().\n"); + return 1; + } + + $radiusconf = <<<EOD +auth {$config['radius']['radiusip']}:{$config['radius']['port']} {$config['radius']['secret']} {$config['radius']['timeout']} {$config['radius']['maxretry']} + +EOD; + + fwrite($fd, $radiusconf); + fclose($fd); + } // end if + + return 0; +} + +/* Stop, Generate the config file and start + * AFP Return 0 if OK, 1 or error code if error + */ +function services_afpd_configure() { + global $freenas_config, $config, $g; + + /* kill any afpd */ + killbyname("afpd"); + + if (isset($freenas_config['afp']['enable'])) { + /* If no share configured, exit */ + if (!is_array($freenas_config['mounts']['mount'])) { return 1; } + if ($g['booting']) { echo "Starting AFP server... "; } + + if (empty($freenas_config['afp']['afpname'])) { + $afpname="-"; + } else { + $afpname=$freenas_config['afp']['afpname']; + } + + /* generate afpd.conf */ + $fd = fopen("{$g['varetc_path']}/afpd.conf", "w"); + + if (!$fd) { + printf("Error: cannot open afpd.conf in services_afpd_configure().\n"); + return 1; + } + + $afpconf = <<<EOD +{$afpname} -transall -uamlist +EOD; + + if (empty($config['system']['zeroconf_disable'])) { + $afpconf .= <<<EOD -noslp -fqdn {$config['system']['hostname']}.{$config['system']['domain']} -uamlist EOD; - } else { - $afpconf .= <<<EOD + } else { + $afpconf .= <<<EOD -noslp -nozeroconf -uamlist EOD; - } + } // end if - if (isset($freenas_config['afp']['guest']) && isset($freenas_config['afp']['local']) ) - $afpconf .= <<<EOD + if (isset($freenas_config['afp']['guest']) && isset($freenas_config['afp']['local']) ) { + $afpconf .= <<<EOD uams_guest.so,uams_clrtxt.so,uams_dhx.so EOD; - else if (isset($freenas_config['afp']['guest'])) - $afpconf .= <<<EOD + } else if (isset($freenas_config['afp']['guest'])) { + $afpconf .= <<<EOD uams_guest.so EOD; - else if (isset($freenas_config['afp']['local'])) - $afpconf .= <<<EOD + } else if (isset($freenas_config['afp']['local'])) { + $afpconf .= <<<EOD uams_clrtxt.so,uams_dhx.so EOD; - - $afpconf .= <<<EOD + } + + $afpconf .= <<<EOD -nosavepassword -defaultvol {$g['varetc_path']}/AppleVolumes.default -systemvol {$g['varetc_path']}/AppleVolumes.system -uampath /etc/uams -guestname ftp EOD; - fwrite($fd, $afpconf); - fclose($fd); - - /* generate AppleVolumes.default */ - $fd = fopen("{$g['varetc_path']}/AppleVolumes.default", "w"); - if (!$fd) - { - printf("Error: cannot open AppleVolumes.default in services_afpd_configure().\n"); - return 1; - } - - $a_mount = &$freenas_config['mounts']['mount']; - foreach ($a_mount as $mount) - { - $AppleVolumes .= <<<EOD + + fwrite($fd, $afpconf); + fclose($fd); + + /* generate AppleVolumes.default */ + $fd = fopen("{$g['varetc_path']}/AppleVolumes.default", "w"); + + if (!$fd) { + printf("Error: cannot open AppleVolumes.default in services_afpd_configure().\n"); + return 1; + } + + $a_mount = &$freenas_config['mounts']['mount']; + + foreach ($a_mount as $mount) { + $AppleVolumes .= <<<EOD /mnt/{$mount['sharename']} "{$mount['sharename']}" EOD; - } - - fwrite($fd, $AppleVolumes); - fclose($fd); + } // end foreach + + fwrite($fd, $AppleVolumes); + fclose($fd); - /* run afpdpd */ - mwexec("/usr/local/sbin/afpd -F {$g['varetc_path']}/afpd.conf"); + /* run afpdpd */ + mwexec("/usr/local/sbin/afpd -F {$g['varetc_path']}/afpd.conf"); - if ($g['booting']) - echo "done\n"; - } + if ($g['booting']) { echo "done\n"; } + } // end if - return 0; + return 0; } -function services_nis_configure() -{ - global $freenas_config, $g; +function services_nis_configure() { + global $freenas_config, $g; - return 0; + return 0; } -function services_iscsi_configure() -{ - global $freenas_config, $g; - - if (isset($freenas_config['iscsi']['enable'])) - { - if ($g['booting']) - echo "Starting iSCSI driver... "; - - mwexec("/sbin/kldload kdload /boot/kernel/iscsi_initiator.ko"); - mwexec("/sbin/sysctl debug.iscsi=0"); - mwexec("/usr/local/sbin/iscontrol targetaddress={$freenas_config['iscsi']['targetaddress']} TargetName={$freenas_config['iscsi']['targetname']}"); - - if ($g['booting']) - echo "done\n"; - } - - return 0; +/* Start iscsi initiator + * Return 0 if Ok, 1 or error code if problem + */ +/* TODO: NEED TO STOP IT TOO ??? */ +function services_iscsi_configure() { + global $freenas_config, $g; + + if (isset($freenas_config['iscsi']['enable'])) { + if ($g['booting']) { echo "Starting iSCSI driver... "; } + + $result = mwexec("/sbin/kldload kdload /boot/kernel/iscsi_initiator.ko"); + $result |= mwexec("/sbin/sysctl debug.iscsi=0"); + $result |= mwexec("/usr/local/sbin/iscontrol targetaddress={$freenas_config['iscsi']['targetaddress']} TargetName={$freenas_config['iscsi']['targetname']}"); + + if ($g['booting']) { echo "done\n"; } + } + + if (isset($result)) { return $result; } + return 0; } function services_zeroconf_configure() { - //services_mdnsresponder_configure(); - //services_howl_configure(); - services_avahi_configure(); + //services_mdnsresponder_configure(); + //services_howl_configure(); + return services_avahi_configure(); } function services_avahi_configure() { - global $freenas_config, $config, $g; - - $service_template = <<<EOD + global $freenas_config, $config, $g; + + $service_template = <<<EOD <?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> @@ -1320,376 +1552,369 @@ function services_avahi_configure() { EOD; - /* kill any running dbus daemon */ + /* kill any running dbus daemon */ sigkillbypid("{$g['varrun_path']}/dbus/dbus.pid", "TERM"); unlink_if_exists("{$g['varrun_path']}/dbus/dbus.pid"); - /* kill any running avahi daemons */ + /* 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@", - "", + /* simply return if zeroconf isn't enabled */ + if (isset($config['system']['zeroconf_disable'])) { return 0; } + + /* configure Avahi and it's dependencies */ + if (! file_exists("/usr/local/etc/avahi/services")) { + mwexec("mkdir -p /usr/local/etc/avahi/services"); + } + + /* add HTTP service type */ + $webproto = $config['system']['webgui']['protocol']; + + if (isset($config['system']['webgui']['port'])) { + $webservice = str_replace("@PORT@", + $config['system']['webgui']['port'], + $service_template); + $webservice = str_replace("@TYPE@", + "_{$webproto}._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@", + "_{$webproto}._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); + } // end if - file_put_contents("/usr/local/etc/avahi/services/http.service", $webservice); - } - + /* afp is announcing itself */ + if (isset($freenas_config['afp']['enable'])) { + /* NOP */ + } + + /* add rsync service type */ + if (isset($freenas_config['rsyncd']['enable'])) { + $rsyncservice = str_replace("@PORT@", + $freenas_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); + } // end if - - 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['system']['ssh']['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); - } - } + if (isset($config['system']['ssh']['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); + + /* do the same for sftp, cause we do enable it by dfeault */ + $sftpservice = str_replace("@PORT@", + "22", + $service_template); + $sftpservice = str_replace("@TYPE@", + "_ssh._tcp", + $sftpservice); + $sftpservice = str_replace("@SERVICE_DESC@", + "Remote Terminal", + $sftpservice); + $sftpservice = str_replace("@TXT_RECORDS@", + "", + $sftpservice); + + file_put_contents("/usr/local/etc/avahi/services/ssh-sftp.service", $sftpservice); + } // end if + /* we are using wzdftpd, which has the ability to announce itself */ + 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); + } // end foreach + } // end if /* 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; + 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 = <<<EOD +/* this function is currently not used */ +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 = <<<EOD "{$config['system']['hostname']} Web Admin" _http._tcp local. {$config['system']['webgui']['port']} EOD; - } - else - { - $mDNSResponder = <<<EOD + } else { + $mDNSResponder = <<<EOD "{$config['system']['hostname']} Web Admin" _http._tcp local. 80 EOD; - } - - - if (isset($freenas_config['afp']['enable'])) - { - $mDNSResponder .= <<<EOD + } // end if + + if (isset($freenas_config['afp']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} AFP Server" _afpovertcp._tcp local. 548 EOD; - } - - if (isset($freenas_config['rsyncd']['enable'])) - { - $mDNSResponder .= <<<EOD + } + + if (isset($freenas_config['rsyncd']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} RSYNC Server" _rsync._tcp. local. {$freenas_config['rsyncd']['port']} EOD; - } - - if (isset($config['sshd']['enable'])) - { - $mDNSResponder .= <<<EOD + } + + if (isset($config['sshd']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} SSH Server" _ssh._tcp local. {$config['sshd']['port']} EOD; - } - - if (isset($freenas_config['ftp']['enable'])) - { - $mDNSResponder .= <<<EOD + } + + if (isset($freenas_config['ftp']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} FTP Server" _ftp._tcp local. {$freenas_config['ftp']['port']} EOD; - } - - if (isset($freenas_config['samba']['enable'])) - { - $mDNSResponder .= <<<EOD + } + + if (isset($freenas_config['samba']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} Samba Server" _smb._tcp local. 139 EOD; - } - - 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) - { - $mDNSResponder .= <<<EOD + } + + 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) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} NFS: {$mount['sharename']}" _nfs._tcp local. 2049 path=/mnt/{$mount['sharename']} EOD; - } - } - - fwrite($fd, $mDNSResponder); - fclose($fd); + } // end foreach + } // end if + + fwrite($fd, $mDNSResponder); + fclose($fd); - /* run mDNSResponder */ - mwexec("/usr/local/sbin/mDNSResponder -f {$g['varetc_path']}/mDNSResponder.conf"); + /* run mDNSResponder */ + mwexec("/usr/local/sbin/mDNSResponder -f {$g['varetc_path']}/mDNSResponder.conf"); - if ($g['booting']) - echo "done\n"; - - return 0; + if ($g['booting']) { echo "done\n"; } + + return 0; } -function services_mdnsresponder_configure() -{ - global $freenas_config, $config, $g; - - - /* kill any running snmpd */ - sigkillbypid("{$g['varrun_path']}/mDNSResponder.pid", "TERM"); +/* this function is currently not used */ +function services_mdnsresponder_configure() { + global $freenas_config, $config, $g; - - 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_bonjour_configure().\n"); - return 1; - } - - if ($config['system']['webgui']['port']) { - $mDNSResponder = <<<EOD + /* kill any running snmpd */ + sigkillbypid("{$g['varrun_path']}/mDNSResponder.pid", "TERM"); + + 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_bonjour_configure().\n"); + return 1; + } + + if ($config['system']['webgui']['port']) { + $mDNSResponder = <<<EOD "{$config['system']['hostname']} Web Admin" _http._tcp local. {$config['system']['webgui']['port']} EOD; - } - else { - $mDNSResponder = <<<EOD + } else { + $mDNSResponder = <<<EOD "{$config['system']['hostname']} Web Admin" _http._tcp local. 80 EOD; - } - - - if (isset($freenas_config['afp']['enable'])) { - $mDNSResponder .= <<<EOD + } // end if + + if (isset($freenas_config['afp']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} AFP Server" _afpovertcp._tcp local. 548 EOD; - } - - if (isset($freenas_config['rsyncd']['enable'])) { - $mDNSResponder .= <<<EOD + } + + if (isset($freenas_config['rsyncd']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} RSYNC Server" _rsync._tcp. local. {$freenas_config['rsyncd']['port']} EOD; - } - - if (isset($config['sshd']['enable'])) { - $mDNSResponder .= <<<EOD + } + + if (isset($config['sshd']['enable'])) { + $mDNSResponder .= <<<EOD "{$freenas_config['system']['hostname']} SSH Server" _ssh._tcp local. {$config['sshd']['port']} EOD; - } - - if (isset($freenas_config['ftp']['enable'])) { - $mDNSResponder .= <<<EOD + } + + if (isset($freenas_config['ftp']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} FTP Server" _ftp._tcp local. {$freenas_config['ftp']['port']} EOD; - } - - if (isset($freenas_config['samba']['enable'])) { - $mDNSResponder .= <<<EOD + } + + if (isset($freenas_config['samba']['enable'])) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} Samba Server" -_smb._tcp local. +_smb._tcp local. 139 EOD; - } - - 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) { - $mDNSResponder .= <<<EOD + } + + 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) { + $mDNSResponder .= <<<EOD "{$config['system']['hostname']} NFS: {$mount['sharename']}" _nfs._tcp local. 2049 path=/mnt/{$mount['sharename']} EOD; - } - } - - fwrite($fd, $mDNSResponder); - fclose($fd); + } // end foreach + } + fwrite($fd, $mDNSResponder); + fclose($fd); - /* run mDNSResponder */ - mwexec("/usr/local/sbin/mDNSResponderPosix -b -f {$g['varetc_path']}/mDNSResponder.conf"); - if ($g['booting']) - echo "done\n"; - - return 0; + /* run mDNSResponder */ + mwexec("/usr/local/sbin/mDNSResponderPosix -b -f {$g['varetc_path']}/mDNSResponder.conf"); + + if ($g['booting']) { echo "done\n"; } + + return 0; } ?>
\ No newline at end of file |