diff options
author | Bill Marquette <bill.marquette@gmail.com> | 2009-02-06 19:18:00 -0600 |
---|---|---|
committer | Bill Marquette <bill.marquette@gmail.com> | 2009-02-06 19:18:00 -0600 |
commit | 55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1 (patch) | |
tree | ba4783bab1dd65f1ceef2dfac9fdbd515531d18b /config/freenas/pkg | |
parent | 67780cc9d469288742aea5bc378c29a54edd5ec5 (diff) | |
download | pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.tar.gz pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.tar.bz2 pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.zip |
mv packages to config dir to match web layout
Diffstat (limited to 'config/freenas/pkg')
-rw-r--r-- | config/freenas/pkg/freenas.inc | 297 | ||||
-rw-r--r-- | config/freenas/pkg/freenas.xml | 570 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_config.inc | 45 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_disks.inc | 1256 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_functions.inc | 49 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_guiconfig.inc | 288 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_services.inc | 2025 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_system.inc | 838 | ||||
-rw-r--r-- | config/freenas/pkg/freenas_utils.inc | 1049 | ||||
-rw-r--r-- | config/freenas/pkg/rc.freenas | 102 |
10 files changed, 6519 insertions, 0 deletions
diff --git a/config/freenas/pkg/freenas.inc b/config/freenas/pkg/freenas.inc new file mode 100644 index 00000000..b87ebfe6 --- /dev/null +++ b/config/freenas/pkg/freenas.inc @@ -0,0 +1,297 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + freenas.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. + */ +/* ========================================================================== */ + +require_once("freenas_config.inc"); + +function sync_package_freenas() { +} + +function oninstall_copy_kernel_binaries($action = "install") { + $binaries = array(); + $binaries[] = array("source" => "/usr/local/pkg/iscsi_initiator.ko", + "target" => "/boot/kernel/iscsi_initiator.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/ext2fs.ko", + "target" => "/boot/kernel/ext2fs.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/geom_concat.ko", + "target" => "/boot/kernel/geom_concat.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/geom_gpt.ko", + "target" => "/boot/kernel/geom_gpt.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/geom_mirror.ko", + "target" => "/boot/kernel/geom_mirror.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/geom_stripe.ko", + "target" => "/boot/kernel/geom_stripe.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/geom_vinum.ko", + "target" => "/boot/kernel/geom_vinum.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/ntfs.ko", + "target" => "/boot/kernel/ntfs.ko", + "backup" => false); + $binaries[] = array("source" => "/usr/local/pkg/kernel.gz", + "target" => "/boot/kernel/kernel.gz", + "backup" => true); + + if ($action == "install") { + while (list(, $val) = each($binaries)) { + $static_output .= "FreeNAS: Moving binary file... "; + update_output_window($static_output); + if ($val['backup'] && file_exists($val['target'])) + rename($val['target'], "{$val['target']}.org"); + rename($val['source'], $val['target']); + $static_output .= "done.\n"; + update_output_window($static_output); + } + } else if ($action == "deinstall") { + while (list($source, $target) = each($binaries)) { + $static_output .= "FreeNAS: Removing binary file... "; + update_output_window($static_output); + unlink($target); + $static_output .= "done.\n"; + update_output_window($static_output); + } + } +} + +function remove_package_contents($pkg = "") { + if ($pkg == "") { return; } + + $pd = popen("pkg_info -rf {$pkg}", "r"); + + if (! pd) { return; } + + while (! feof($pd)) { + $buffer = fgets($pd, 4096); + + if (strpos($buffer, "File:") !== false) { + $file = trim(str_replace("File:", "", $buffer)); + + if (strpos($file, "man/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "share/doc/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "share/aclocal/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "include/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "libdata/pkgconfig/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "info/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "etc/rc.d/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } else if (strpos($file, "etc/") !== false) { + if (strpos($file, ".dist") !== false || + strpos($file, ".sample") !== false || + strpos($file, ".example") !== false || + strpos($file, ".default") !== false || + strpos($file, ".sh") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } + } else if (strpos($file, "share/examples/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } + + /* What about locales? */ + /* + } else if (strpos($file, "share/local/") !== false) { + unlink_if_exists("/usr/local/{$file}"); + } + */ + } + } + + fclose ($pd); +} + +function adjust_package_contents() { + remove_package_contents("avahi+libdns-0.6.12"); + remove_package_contents("ataidle-0.9"); + remove_package_contents("perl-5.8.8"); + remove_package_contents("libiconv-1.9.2_2"); + remove_package_contents("libxml2-2.6.26"); + remove_package_contents("gettext-0.14.5_2"); + remove_package_contents("glib-2.10.3"); + remove_package_contents("expat-2.0.0_1"); + remove_package_contents("wzdftpd-0.7.2_1"); + remove_package_contents("e2fsprogs-1.39_1"); + remove_package_contents("smartmontools-5.36"); + remove_package_contents("aaccli-1.0"); + remove_package_contents("rsync-2.6.8_2"); + remove_package_contents("scponly-4.6_1"); + remove_package_contents("cracklib-2.7_2"); + remove_package_contents("samba-3.0.23,1"); + remove_package_contents("netatalk-2.0.3_3,1"); + remove_package_contents("pam_ldap-1.8.2"); +} + +function oninstall_copy_misc_binaries($action = "install") { + $binaries = array(); + $binaries[] = array("source" => "/usr/local/pkg/iscontrol", + "target" => "/usr/local/sbin/iscontrol"); + $binaries[] = array("source" => "/usr/local/pkg/nfsd", + "target" => "/usr/sbin/nfsd"); + $binaries[] = array("source" => "/usr/local/pkg/nfsd", + "target" => "/usr/sbin/mountd"); + $binaries[] = array("source" => "/usr/local/pkg/rpcbind", + "target" => "/usr/sbin/rpcbind"); + $binaries[] = array("source" => "/usr/local/pkg/rpc.lockd", + "target" => "/usr/sbin/rpc.lockd"); + $binaries[] = array("source" => "/usr/local/pkg/rpc.lockd", + "target" => "/usr/sbin/rpc.lockd"); + + if ($action == "install") { + while (list(, $val) = each($binaries)) { + $static_output .= "FreeNAS: Installing binary file... "; + update_output_window($static_output); + mwexec("install -s {$source} ${target}"); + $static_output .= "done.\n"; + update_output_window($static_output); + } + } else if ($action == "deinstall") { + while (list($val['source'], $val['target']) = each($binaries)) { + $static_output .= "FreeNAS: Removing binary file... "; + update_output_window($static_output); + unlink($target); + $static_output .= "done.\n"; + update_output_window($static_output); + } + } +} + +function oninstall_setup_config() { + global $config; + + $config['system']['zeroconf_disable'] = "yes"; + + $freenas_config =& $config['installedpackages']['freenas']['config'][0]; + + if (!is_array($freenas_config['disks'])) + $freenas_config['disks'] = array(); + if (!is_array($freenas_config['mounts'])) + $freenas_config['mounts'] = array(); + + if (!is_array($freenas_config['samba'])) + $freenas_config['samba'] = array(); + $freenas_config['samba']['netbiosname'] = "freenas"; + $freenas_config['samba']['workgroup'] = "WORKGROUP"; + $freenas_config['samba']['serverdesc'] = "pfSense Server"; + $freenas_config['samba']['security'] = "share"; + $freenas_config['samba']['localmaster'] = "yes"; + + if (!is_array($freenas_config['ftp'])) + $freenas_config['ftp'] = array(); + $freenas_config['ftp']['numberclients'] = "5"; + $freenas_config['ftp']['maxconperip'] = "2"; + $freenas_config['ftp']['timeout'] = "300"; + $freenas_config['ftp']['port'] = "21"; + $freenas_config['ftp']['anonymous'] = "yes"; + $freenas_config['ftp']['pasv_max_port'] = "0"; + $freenas_config['ftp']['pasv_min_port'] = "0"; + + if (!is_array($freenas_config['afp'])) + $freenas_config['afp'] = array(); + + if (!is_array($freenas_config['rsyncd'])) + $freenas_config['rsyncd'] = array(); + $freenas_config['rsyncd']['readonly'] = "no"; + $freenas_config['rsyncd']['port'] = "873"; + + if (!is_array($freenas_config['nfs'])) + $freenas_config['nfs'] = array(); +} + +function custom_php_install_command() { + global $g; + + oninstall_copy_kernel_binaries(); + oninstall_copy_misc_binaries(); + adjust_package_contents(); + oninstall_setup_config(); + + if (! file_exists("/usr/local/etc/rc.d")) + mwexec("mkdir -p /usr/local/etc/rc.d"); + + if (! file_exists("{$g['varrun_path']}/dbus")) + mkdir("{$g['varrun_path']}/dbus"); + + if (! file_exists("{$g['varrun_path']}/avahi-daemon")) + mkdir("{$g['varrun_path']}/avahi-daemon"); + + rename("/usr/local/pkg/rc.freenas", "/usr/local/etc/rc.d/freenas.sh"); + chmod ("/usr/local/etc/rc.d/freenas.sh", 0755); + + mwexec("ln -s /usr/local/etc/uams/uams_passwd.so /usr/local/etc/uams/uams_clrtxt.so"); + mwexec("ln -s /usr/local/etc/uams/uams_dhx_passwd.so /usr/local/etc/uams/uams_dhx.so"); + /* hack cause I linked netatalk against db44 instead of db42 */ + mwexec("ln -s /usr/local/lib/libdb-4.4.so.0 /usr/local/lib/libdb-4.2.so.2"); +} + +function custom_php_deinstall_command() { + global $config, $g; + + oninstall_copy_kernel_binaries("deinstall"); + oninstall_copy_misc_binaries("deinstall"); + + if (! file_exists("/usr/local/etc/rc.d")) + mwexec("rm -rf /usr/local/etc/rc.d"); + + if (! file_exists("{$g['varrun_path']}/dbus")) + mwexec("rm -rf {$g['varrun_path']}/dbus"); + + if (! file_exists("{$g['varrun_path']}/avahi-daemon")) + mwexec("rm -rf {$g['varrun_path']}/avahi-daemon"); + + unlink_if_exists("/usr/local/etc/uams/uams_clrtxt.so"); + unlink_if_exists("/usr/local/etc/uams/uams_dhx.so"); + unlink_if_exists("/usr/local/etc/rc.d/freenas.sh"); + unlink_if_exists("/usr/local/lib/libdb-4.2.so.2"); + + unset($config['installedpackages']['freenas']); + write_config(); + conf_mount_ro(); +} +?> diff --git a/config/freenas/pkg/freenas.xml b/config/freenas/pkg/freenas.xml new file mode 100644 index 00000000..edac8085 --- /dev/null +++ b/config/freenas/pkg/freenas.xml @@ -0,0 +1,570 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE packagegui SYSTEM "../../schema/packages.dtd"> +<?xml-stylesheet type="text/xsl" href="../../xsl/package.xsl"?> +<packagegui> + <copyright> + <![CDATA[ +/* $Id$ */ +/* ========================================================================== */ +/* + authng.xml + part of pfSense (http://www.pfSense.com) + Copyright (C) 2007 Daniel S. Haischt <me@daniel.stefan.haischt.name> + 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. + */ +/* ========================================================================== */ + ]]> + </copyright> + <description>Describe your package here</description> + <requirements>Describe your package requirements here</requirements> + <faq>Currently there are no FAQ items provided.</faq> + <name>freenas</name> + <version>1.0</version> + <title>System: Disks: Management</title> + <include_file>/usr/local/pkg/freenas.inc</include_file> + <!-- Menu is where this packages menu will appear --> + <menu> + <name>Disks</name> + <section>System</section> + <url>/disks_manage.php</url> + </menu> + <menu> + <name>RAID</name> + <section>System</section> + <url>/disks_raid_gmirror.php</url> + </menu> + <menu> + <name>Mounts</name> + <section>System</section> + <url>/disks_mount.php</url> + </menu> + <menu> + <name>FreeNAS Infos</name> + <section>Diagnostics</section> + <url>/diag_disk_infos.php</url> + </menu> + <menu> + <name>FreeNAS Logs</name> + <section>Diagnostics</section> + <url>/diag_fn_logs_samba.php</url> + </menu> + <menu> + <name>Disk Status</name> + <section>Status</section> + <url>/status_disks.php</url> + </menu> + <menu> + <name>AFP</name> + <section>Services</section> + <url>/services_afp.php</url> + </menu> + <menu> + <name>FTP</name> + <section>Services</section> + <url>/services_ftp.php</url> + </menu> + <menu> + <name>NFS</name> + <section>Services</section> + <url>/services_nfs.php</url> + </menu> + <menu> + <name>Rsync</name> + <section>Services</section> + <url>/services_rsyncd.php</url> + </menu> + <menu> + <name>Samba</name> + <section>Services</section> + <url>/services_samba.php</url> + </menu> + <menu> + <name>Unison</name> + <section>Services</section> + <url>/services_unison.php</url> + </menu> + <!-- + <service> + <name>dspam</name> + <rcfile>/usr/local/etc/rc.d/dspam.sh</rcfile> + </service> + --> + <tabs /> + <!-- + configpath gets expanded out automatically and config items + will be stored in that location + --> + <configpath>['installedpackages']['freenas']['config']</configpath> + <!-- PHP files (disk management) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_manage.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_manage_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_manage_init.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_manage_iscsi.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_manage_tools.php</item> + </additional_files_needed> + <!-- PHP files (RAID management) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_infos.php</item> + </additional_files_needed> + <!-- + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_init.php</item> + </additional_files_needed> + --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_tools.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_infos.php</item> + </additional_files_needed> + <!-- + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_init.php</item> + </additional_files_needed> + --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_tools.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat_tools.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe_tools.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5_tools.php</item> + </additional_files_needed> + <!-- PHP files (mount management) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_mount.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_mount_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/disks_mount_tools.php</item> + </additional_files_needed> + <!-- PHP files (diagnostics) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_ad_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_ataidle_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_disk_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_iscsi_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_mounts_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_part_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_raid_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_smart_infos.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_space_infos.php</item> + </additional_files_needed> + <!-- PHP files (logs) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_daemon.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_ftp.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_rsyncd.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_samba.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_settings.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_smartd.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_sshd.php</item> + </additional_files_needed> + <!-- PHP files (services) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_afp.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_ftp.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_nfs.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_nfs_export.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_nfs_export_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_rsyncd.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_rsyncd_client.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_rsyncd_local.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_samba.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_samba_share.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_samba_edit.php</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/services_unison.php</item> + </additional_files_needed> + <!-- PHP files (misc) --> + <additional_files_needed> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/www/status_disks.php</item> + </additional_files_needed> + <!-- package files --> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_disks.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_config.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_functions.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_guiconfig.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_services.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_utils.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/freenas_system.inc</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/pkg/rc.freenas</item> + </additional_files_needed> + <!-- kernel binaries --> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/iscsi_initiator.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/ext2fs.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/geom_concat.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/geom_gpt.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/geom_mirror.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/geom_stripe.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/geom_vinum.ko</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/kernel.gz</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/ntfs.ko</item> + </additional_files_needed> + <!-- misc binaries --> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/iscontrol</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/mountd</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/nfsd</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/rpcbind</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/rpc.lockd</item> + </additional_files_needed> + <additional_files_needed> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + <item>http://www.pfsense.com/packages/config/freenas/bin/rpc.statd</item> + </additional_files_needed> + <!-- + fields gets invoked when the user adds or edits a item. The following items + will be parsed and rendered for the user as a gui with input, and selectboxes. + --> + <!-- + Arbitrary PHP Code, that gets executed if a certain event gets triggered. + --> + <custom_php_resync_config_command> + sync_package_freenas(); + </custom_php_resync_config_command> + <custom_php_install_command> + custom_php_install_command(); + </custom_php_install_command> + <custom_php_deinstall_command> + custom_php_deinstall_command(); + </custom_php_deinstall_command> +</packagegui> diff --git a/config/freenas/pkg/freenas_config.inc b/config/freenas/pkg/freenas_config.inc new file mode 100644 index 00000000..fc139228 --- /dev/null +++ b/config/freenas/pkg/freenas_config.inc @@ -0,0 +1,45 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + freenas_config.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. + */ +/* ========================================================================== */ + +$GLOBALS['custom_listtags'] = array("disk", "mount", "vdisk"); + +?>
\ No newline at end of file diff --git a/config/freenas/pkg/freenas_disks.inc b/config/freenas/pkg/freenas_disks.inc new file mode 100644 index 00000000..0946164f --- /dev/null +++ b/config/freenas/pkg/freenas_disks.inc @@ -0,0 +1,1256 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + freenas_disks.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. + */ +/* ========================================================================== */ + +/* include all configuration functions */ +require_once("functions.inc"); +require_once("freenas_functions.inc"); + +$freenas_config =& $config['installedpackages']['freenas']['config'][0]; + +/* Mount all configured disks */ +function disks_mount_all() { + global $freenas_config, $g; + + if ($g['booting']) + echo "Mounting Partitions... "; + + /* For each device configured: */ + if (is_array($freenas_config['mounts']['mount'])) { + foreach ($freenas_config['mounts']['mount'] as $mountent) { + /* Advanced Umount filesystem if not booting mode (mount edition) */ + if (!$g['booting']) + disks_umount_adv($mountent); + + /* mount filesystem */ + disks_mount($mountent); + } // end foreach + } // end if + + if ($g['booting']) + echo "done\n"; + + return 0; +} + +/* Mount using the configured mount given in parameter + * Return 0 if sucessful, 1 if error + */ +function disks_mount($mount) { + global $freenas_config, $g; + + /* Create one directory for each device under mnt */ + + $mountname=escapeshellcmd($mount['sharename']); + + @mkdir ("/mnt/$mountname",0777); + + /* mount the filesystems */ + $devname=escapeshellcmd($mount['fullname']); + + /* check the fileystem only if there is a problem*/ + /* This part is too stupid: I must read the FreBSD + * start script for use the same intelligent method + * for checking hard drive + */ + switch ($mount['fstype']) { + case "ufs": + if (mwexec("/sbin/mount -t ufs -o acls $devname /mnt/$mountname") == 0) { + /* Change this directory into 777 mode */ + mwexec("/bin/chmod 777 /mnt/$mountname"); + $result = 0; + } else { + /* If it's NOK, Check filesystem and do a fsck, answer Yes to all question*/ + mwexec("/sbin/fsck -y -t ufs $devname"); + + /* Re-try to mount the partition */ + if (mwexec("/sbin/mount -t ufs -o acls $devname /mnt/$mountname") == 0) { + /* Change this directory into 777 mode */ + mwexec("/bin/chmod 777 /mnt/$mountname"); + $result = 0; + } else { + /* Not OK, remove the directory, prevent writing on RAM disk*/ + @rmdir ("/mnt/$mountname"); + $result = 1; + } // end if + } // end if + break; + case "msdosfs": + if (mwexec("/sbin/mount_msdosfs -u ftp -g ftp -m 777 $devname /mnt/$mountname") == 0) { + $result = 0; + } else { + exec("/sbin/fsck -y -t msdosfs {$devname}"); + + if (mwexec("/sbin/mount_msdosfs -u ftp -g ftp -m 777 $devname /mnt/$mountname") == 0) { + $result = 0; + } else { + /* Not OK, remove the directory, prevent writing on RAM disk*/ + @rmdir ("/mnt/$mountname"); + $result = 1; + } + } + break; + case "ntfs": + if (mwexec("/sbin/mount_ntfs -u ftp -g ftp -m 777 $devname /mnt/$mountname") == 0) { + $result = 0; + } else { + /* Not OK, remove the directory, prevent writing on RAM disk */ + @rmdir ("/mnt/$mountname"); + $result = 1; + } + break; + case "ext2fs": + if (mwexec("/sbin/mount_ext2fs $devname /mnt/$mountname") == 0) { + /* Change this directory into 777 mode */ + mwexec("/bin/chmod 777 /mnt/$mountname"); + $result = 0; + } else { + exec("/usr/local/sbin/e2fsck -f -p {$devname}"); + + if (mwexec("/sbin/mount_ext2fs $devname /mnt/$mountname") == 0) { + /* Change this directory into 777 mode */ + mwexec("/bin/chmod 777 /mnt/$mountname"); + $result = 0; + } else { + /* Not OK, remove the directory, prevent writing on RAM */ + @rmdir ("/mnt/$mountname"); + $result= 1; + } + } + break; + } // end switch + + return $result; +} + +/* Mount using fullname (/dev/ad0s1) given in parameter*/ +function disks_mount_fullname($fullname) { + global $freenas_config; + + if (is_array($freenas_config['mounts']['mount'])) { + /* Search the mount list for given disk and partition */ + foreach($freenas_config['mounts']['mount'] as $mountk => $mountv) { + if($mountv['fullname'] == $fullname) { + $mount = $mountv; + } + } + } + + if($mount) { + $result= disks_mount($mount); + } else { + $result=0; + } + + return $result; +} + +/* Umount the specified configured mount point + * Return 0 is successfull, 1 if error + */ +function disks_umount($mount) { + global $freenas_config, $g; + + /* Umout the specified mount point */ + /* The $mount variable is the all config table for the mount point*/ + $mountname=escapeshellcmd($mount['sharename']); + + if (mwexec("/sbin/umount /mnt/$mountname") == 0) { + if (@rmdir ("/mnt/$mountname")) { + return 0; + } else { + return 1; + } + } else { + return 1; + } +} + +/* Advanced unmount the specified mount point without using the sharename value + * Used when changing the 'sharename': Need to umount the old unknow sharename + * Return 0 if successful, 1 if error + */ +function disks_umount_fullname($fullname) { + global $freenas_config; + + /* Search the mount list for given fullname */ + foreach($freenas_config['mounts']['mount'] as $mountk => $mountv) { + if (strcmp($mountv['fullname'],$fullname) == 0) { + $mount = $mountv; + } + } + + if($mount) { + $result = disks_umount($mount); + } else { + $result= 1; + } + + return $result; +} + +/* Advanced unmount the specified mount point without using the sharename value + * Used when changing the 'sharename': Need to umount the old unknow sharename + * Return 0 if successful, 1 if error + */ +function disks_umount_adv($mount) +{ + $fulname="{$mount['fullname']}"; + + // get the mount list + $detmount = get_mounts_list(); + + //Look for the mount point in all mounted point + foreach ($detmount as $detmountk => $detmountv) { + // If we found the mount point on the device + if (strcmp($detmountv['fullname'],$fullname) == 0) { + $mountname="{$detmountv['mp']}"; + } + } + + if ($mountname) { + exec("/sbin/umount $mountname"); + @rmdir ("$mountname"); + return 0; + } else { + $result = 1; + } + + return $result; +} + +function disks_mount_status($mount) { + // This option check if the mount are mounted + global $freenas_config, $g; + $detmount = get_mounts_list(); + $status="ERROR"; + + // Recreate the full system name device+s+partition number + /* mount the filesystems */ + $mountpart="{$mount['partition']}"; + + if ((strcmp($mountpart,"gvinum") == 0) || (strcmp($mountpart,"gmirror") == 0)) { + $complete = "{$mount['mdisk']}"; + } else { + $complete = "{$mount['mdisk']}{$mount['partition']}"; + } + + //echo "debug, display complete: $complete <br>"; + + foreach ($detmount as $detmountk => $detmountv) { + //echo "debug, display detmountv[mdisk]: {$detmountv['mdisk']} <br>"; + + if (strcmp($detmountv['mdisk'],$complete) == 0) { + $status="OK"; + return $status; + } + } + + return $status; +} + +/* This option check if this fullname (/dev/ad0s1) is mounted + * Return 0 if not, 1 if yes + */ +function disks_check_mount_fullname($fullname) { + $detmount = get_mounts_list(); + $status=0; + //print_r($detmount); + + foreach ($detmount as $detmountk => $detmountv) { + if (strpos($detmountv['fullname'],$fullname) !== false) { + $status=1; + break; + } + } + + return $status; +} + +/* This option check if the configured mount is mounted. */ +function disks_check_mount($mount) +{ + return disks_check_mount_fullname($mount['fullname']); +} + +/* This function check if the disk is mounted + * Return 0 if not, 1 if yes + */ +function disks_check_mount_disk($disk) { + $detmount = get_mounts_list(); + $status=0; + + foreach ($detmount as $detmountk => $detmountv) { + /* Must found the $disk (ad0) in result $mdisk (ad0s1) */ + // strpos will return 0 (found at position 0) if found, must check the 'false' value + if (strpos($detmountv['mdisk'], $disk) !== false ) { + $status=1; + break; + } +} +return $status; +} + +/* This option check if the configured disk is online (detected by the system) + * Result: "MISSING", disk don't detected by OS + * Result: "ONLINE", disk is online + * Result: "CHANGED", disk have changed (be replaced ?) + */ +function disks_status($diskname) { + // This option check if the configured disk is online + global $freenas_config, $g; + $detectedlist = get_physical_disks_list(); + $status="MISSING"; + + foreach ($detectedlist as $detecteddisk => $detecteddiskv) { + if ($detecteddisk == $diskname['name']) { + $status="ONLINE"; + if (($detecteddiskv['size'] != $diskname['size']) || ($detecteddiskv['desc'] != $diskname['desc'])) { + $status="CHANGED"; + } + break; + } + } + + return $status; +} + +function disks_addfstab($cfgdev,$cfgtype) { + global $freenas_config, $g; + + /* Open or create fstab in RW */ + $fd = fopen("{$g['etc_path']}/fstab", "w"); + + if ( $fd ) { + /* check for the precence of dev */ + /* ADD (check if it's ADD line or replace) the line for the dev */ + $fstab = "/dev/$cfgdev /mnt/$cfgdev $cfgtype rw 1 1\n"; + + /* write out an fstab */ + fwrite($fd, $fstab); + + /* close file */ + fclose($fd); + } else { + die( "fopen failed for {$g['etc_path']}/fstab" ) ; + } +} + +function disks_umount_all() { + global $freenas_config, $g; + + /* Sync disks*/ + mwexec("/bin/sync"); + + if (is_array($freenas_config['mounts']['mount'])) { + foreach ($freenas_config['mounts']['mount'] as $mountent) { + /* Umount filesystem */ + disks_umount($mountent); + } + } + + return 0; +} + +/* Configure, create and start gvinum volume */ +function disks_raid_gvinum_configure() { + global $freenas_config, $g; + + /* Generate the raid.conf file */ + if ($freenas_config['gvinum']['vdisk']) { + + foreach ($freenas_config['gvinum']['vdisk'] as $a_raid_conf) { + if (file_exists($g['varrun_path'] . "/raid.conf.dirty") && + !in_array("{$a_raid_conf['name']}\n", file($g['varrun_path'] . "/raid.conf.dirty"))) { continue; } + + /* generate raid.conf */ + $fd = fopen("{$g['varetc_path']}/raid-{$a_raid_conf['name']}.conf", "w"); + if (!$fd) { + printf("Error: cannot open raid.conf in services_raid_configure().\n"); + return 1; + } + + $raidconf=""; + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $raidconf .= <<<EOD +drive disk_{$diskrv} device {$diskrv} + +EOD; + } // end foreach + + $raidconf .= <<<EOD +volume {$a_raid_conf['name']} + +EOD; + + switch ($a_raid_conf['type']) { + case "0": + $raidconf .= <<<EOD +plex org striped 256k + +EOD; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<<EOD +sd length {$disksize} drive disk_{$diskrv} + +EOD; +*/ + + $raidconf .= <<<EOD +sd length 0 drive disk_{$diskrv} + +EOD; + + } // end foreach + break; + case "1": + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $raidconf .= <<<EOD +plex org concat + +EOD; + + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<<EOD +sd length {$disksize} drive disk_{$diskrv} + +EOD; +*/ + $raidconf .= <<<EOD +sd length 0 drive disk_{$diskrv} + +EOD; + + } // end foreach + break; + case "5": + $raidconf .= <<<EOD +plex org raid5 256k + +EOD; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<<EOD +sd length {$disksize} drive disk_{$diskrv} + +EOD; +*/ + + $raidconf .= <<<EOD +sd length 0 drive disk_{$diskrv} + +EOD; + + } // end foreach + break; + } // end switch + + fwrite($fd, $raidconf); + fclose($fd); + + /* Create each volume */ + mwexec("/sbin/gvinum create {$g['varetc_path']}/raid-{$a_raid_conf['name']}.conf"); + } // end foreach + + + /* start each volume */ + + foreach ($freenas_config['gvinum']['vdisk'] as $a_raid_conf) { + exec("/sbin/gvinum lv $raidname",$rawdata); + + if (strpos($rawdata[0],"State: up")>=0) { continue; } + + mwexec("/sbin/gvinum start {$a_raid_conf['name']}"); + } + } // end if + + return 0; +} + +function disks_raid_configure() +{ + global $freenas_config, $g; + + /* Generate the raid.conf file */ + if ($freenas_config['raid']['vdisk']) { + foreach ($freenas_config['raid']['vdisk'] as $a_raid_conf) { + if (file_exists($g['varrun_path'] . "/raid.conf.dirty") && + ! in_array("{$a_raid_conf['name']}\n",file($g['varrun_path'] . "/raid.conf.dirty"))) { continue; } + + /* generate raid.conf */ + $fd = fopen("{$g['varetc_path']}/raid-{$a_raid_conf['name']}.conf", "w"); + + if (!$fd) { + printf("Error: cannot open raid.conf in services_raid_configure().\n"); + return 1; + } + + $raidconf=""; + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $raidconf .= <<<EOD +drive disk_{$diskrv} device /dev/{$diskrv}s1a + +EOD; + + } // end foreach + + $raidconf .= <<<EOD +volume {$a_raid_conf['name']} + +EOD; + + switch ($a_raid_conf['type']) { + case "0": + $raidconf .= <<<EOD +plex org striped 256k + +EOD; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<<EOD +sd length {$disksize} drive disk_{$diskrv} + +EOD; +*/ + +$raidconf .= <<<EOD +sd length 0 drive disk_{$diskrv} + +EOD; + + } // end foreach + break; + case "1": + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $raidconf .= <<<EOD +plex org concat + +EOD; + + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<<EOD +sd length {$disksize} drive disk_{$diskrv} + +EOD; +*/ + + $raidconf .= <<<EOD +sd length 0 drive disk_{$diskrv} + +EOD; + + } // end foreach + break; + case "5": + $raidconf .= <<<EOD +plex org raid5 256k + +EOD; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<<EOD +sd length {$disksize} drive disk_{$diskrv} + +EOD; +*/ + + $raidconf .= <<<EOD +sd length 0 drive disk_{$diskrv} + +EOD; + + } // end foreach + break; + } // end switch + + fwrite($fd, $raidconf); + fclose($fd); + + /* Create each volume */ + mwexec("/sbin/gvinum create {$g['varetc_path']}/raid-{$a_raid_conf['name']}.conf"); + } // end foreach + + /* start each volume */ + foreach ($freenas_config['raid']['vdisk'] as $a_raid_conf) { + exec("/sbin/gvinum lv $raidname",$rawdata); + if (strpos($rawdata[0],"State: up")>=0) { continue; } + mwexec("/sbin/gvinum start {$a_raid_conf['name']}"); + } + } // end if + + return 0; +} + +/* Configure, create and start gmirror volume */ +function disks_raid_gmirror_configure() { + global $freenas_config, $g; + + /* Create the gmirror device */ + if ($freenas_config['gmirror']['vdisk']) { + // Load gmirror + mwexec("/sbin/gmirror load"); + + foreach ($freenas_config['gmirror']['vdisk'] as $a_raid_conf) { + /* Create each volume */ + $cmd = "/sbin/gmirror label -b {$a_raid_conf['balance']} {$a_raid_conf['name']} "; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $cmd .= "{$diskrv} "; + } + + mwexec($cmd); + } + } + + return 0; +} + +/* Configure, create and start gconcat volume */ +function disks_raid_gconcat_configure() { + global $freenas_config, $g; + + if ($freenas_config['gconcat']['vdisk']) { + // Load gconcat + mwexec("/sbin/gconcat load"); + + foreach ($freenas_config['gconcat']['vdisk'] as $a_raid_conf) { + /* Create each volume */ + $cmd = "/sbin/gconcat label {$a_raid_conf['name']} "; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $cmd .= "{$diskrv} "; + } + + mwexec($cmd); + + } + } + + return 0; +} + +/* Configure, create and start gstripe volume */ +function disks_raid_gstripe_configure() { + global $freenas_config, $g; + + if ($freenas_config['gstripe']['vdisk']) { + // Load gstripe + mwexec("/sbin/gstripe load"); + + foreach ($freenas_config['gstripe']['vdisk'] as $a_raid_conf) { + /* Create each volume */ + $cmd = "/sbin/gstripe label {$a_raid_conf['name']} "; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $cmd .= "{$diskrv} "; + } + + mwexec($cmd); + } + } + + return 0; +} + +/* Configure, create and start graid5 volume */ + +function disks_raid_graid5_configure() +{ + global $freenas_config, $g; + + if ($freenas_config['graid5']['vdisk']) { + /* Load graid5 */ + mwexec("/sbin/graid5 load"); + + foreach ($freenas_config['graid5']['vdisk'] as $a_raid_conf) { + /* Create each volume */ + $cmd = "/sbin/graid5 label -s 131072 {$a_raid_conf['name']} "; + + foreach ($a_raid_conf['diskr'] as $diskrk => $diskrv) { + $cmd .= "{$diskrv} "; + } + + mwexec($cmd); + } + } + + return 0; +} + +function disks_raid_start() { + global $freenas_config, $g; + + /* WARNING: Must change this code for advanced RAID configuration ex: RAID1+0 + * Geom RAID volume must be started in 'intelligent' sort, for RAID1+0, gmirror must + * be started before gstripe, etc... + */ + disks_raid_gvinum_start(); + disks_raid_gmirror_start(); + disks_raid_gstripe_start(); + disks_raid_gconcat_start(); + disks_raid_graid5_start(); + + return 0; +} + + +function disks_raid_gvinum_start() { + global $freenas_config, $g; + + /* Generate the raid.conf file */ + if ($freenas_config['raid']['vdisk']) { + if ($g['booting']) + echo "Start gvinum raid... "; + + /* start each volume */ + foreach ($freenas_config['raid']['vdisk'] as $a_raid_conf) { + mwexec("/sbin/gvinum start {$a_raid_conf['name']}"); + } + + if ($g['booting']) + echo "done\n"; + } + + return 0; +} + +function disks_raid_gmirror_start() { + global $freenas_config, $g; + + /* Start Geom mirror */ + if ($freenas_config['gmirror']['vdisk']) { + if ($g['booting']) + echo "Start gmirror raid... "; + + // Load geom mirror module + mwexec("/sbin/gmirror load"); + + if ($g['booting']) + echo "done\n"; + } + + return 0; +} + +/* Start geom concat volumes */ +function disks_raid_gconcat_start() { + global $freenas_config, $g; + +/* Start Geom concat */ + if ($freenas_config['gconcat']['vdisk']) { + if ($g['booting']) + echo "Start gconcat raid... "; + + // Load geom concat module + mwexec("/sbin/gconcat load"); + + if ($g['booting']) + echo "done\n"; + } + + return 0; +} + +/* Start geom stripe volumes */ +function disks_raid_gstripe_start() { + global $freenas_config, $g; + + /* Start Geom stripe */ + if ($freenas_config['gstripe']['vdisk']) { + if ($g['booting']) + echo "Start gstripe raid... "; + + // Load geom stripe module + mwexec("/sbin/gstripe load"); + + if ($g['booting']) + echo "done\n"; + } + + return 0; +} + +/* Start geom raid5 volumes */ +function disks_raid_graid5_start() { + global $freenas_config, $g; + + /* Start Geom RAID5 */ + if ($freenas_config['graid5']['vdisk']) { + if ($g['booting']) + echo "Start graid5 raid... "; + + // Load geom raid5 module + mwexec("/sbin/graid5 load"); + + if ($g['booting']) + echo "done\n"; + } + + return 0; +} + +function disks_raid_stop() { + /* WARNING: Must change this code for advanced RAID configuration ex: RAID1+0 + * Geom RAID volume must be started in 'intelligent' sort, for RAID1+0, gmirror must + * be started before gstripe, etc... + */ + disks_raid_gvinum_stop(); + disks_raid_graid5_stop(); + disks_raid_gstripe_stop(); + disks_raid_gconcat_stop(); + disks_raid_gmirror_stop(); + + return 0; +} + +function disks_raid_gvinum_stop() { + global $freenas_config, $g; + + /* Generate the raid.conf file */ + if ($freenas_config['raid']['vdisk']) { + /* stop each volume */ + foreach ($freenas_config['raid']['vdisk'] as $a_raid_conf) { + mwexec("/sbin/gvinum stop {$a_raid_conf['name']}"); + } + } + + return 0; +} + +function disks_raid_gmirror_stop() { + global $freenas_config, $g; + + /* Generate the raid.conf file */ + if ($freenas_config['gmirror']['vdisk']) { + /* start each volume */ + foreach ($freenas_config['gmirror']['vdisk'] as $a_raid_conf) { + mwexec("/sbin/gmirror stop {$a_raid_conf['name']}"); + } + } + + return 0; +} + +/* Stop all geom concat volumes */ +function disks_raid_gconcat_stop() { + global $freenas_config, $g; + + /* Stop geom concat */ + if ($freenas_config['gconcat']['vdisk']) { + /* start each volume */ + foreach ($freenas_config['gconcat']['vdisk'] as $a_raid_conf) { + mwexec("/sbin/gconcat stop {$a_raid_conf['name']}"); + } + } + + return 0; +} + +/* Stop all geom stripe volumes */ +function disks_raid_gstripe_stop() { + global $freenas_config, $g; + + /* Stop geom stripe */ + if ($freenas_config['gstripe']['vdisk']) { + /* start each volume */ + foreach ($freenas_config['gstripe']['vdisk'] as $a_raid_conf) { + mwexec("/sbin/gstripe stop {$a_raid_conf['name']}"); + } + } + + return 0; +} + +/* Stop all geom raid5 volumes */ +function disks_raid_graid5_stop() { + global $freenas_config, $g; + + /* Generate the raid.conf file */ + if ($freenas_config['graid5']['vdisk']) { + /* start each volume */ + foreach ($freenas_config['graid5']['vdisk'] as $a_raid_conf) { + mwexec("/sbin/graid5 stop {$a_raid_conf['name']}"); + } + } + + return 0; +} + + +/* Delete geom gvinum volume given in parameter */ +function disks_raid_gvinum_delete($raidname) { + global $freenas_config, $g; + + exec("/sbin/gvinum lv $raidname",$rawdata); + + if (strpos($rawdata[0],"State: up") === false) { + return 0; + } + + mwexec("/sbin/gvinum rm -r $raidname"); + + foreach ($freenas_config['gvinum']['vdisk'] as $a_raid) { + if ($a_raid['name'] == $raidname) { + foreach ($a_raid['diskr'] as $disk) { + mwexec("/sbin/gvinum rm -r disk_{$disk}"); + } + } + } + + return 0; +} + +/* Delete geom mirror volume given in parameter */ +function disks_raid_gmirror_delete($raidname) { + global $freenas_config, $g; + + // Stop the volume + mwexec("/sbin/gmirror stop $raidname"); + + // Clear the gmirror information on the hard drive + foreach ($freenas_config['gmirror']['vdisk'] as $a_raid) { + if ($a_raid['name'] == $raidname) { + foreach ($a_raid['diskr'] as $disk) { + mwexec("/sbin/gmirror clear {$disk}"); + } + } + } + + return 0; +} + +/* Delete geom concat volume given in parameter */ +function disks_raid_gconcat_delete($raidname) { + global $freenas_config, $g; + + // Stop the volume + mwexec("/sbin/gconcat stop $raidname"); + + // Clear the gconcat information on the hard drive + foreach ($freenas_config['gconcat']['vdisk'] as $a_raid) { + if ($a_raid['name'] == $raidname) { + foreach ($a_raid['diskr'] as $disk) { + mwexec("/sbin/gconcat clear {$disk}"); + } + + mwexec("/sbin/gconcat destroy $raidname"); + } + } + + return 0; +} + +/* Delete geom stripe volume given in parameter */ +function disks_raid_gstripe_delete($raidname) { + global $freenas_config, $g; + + // Stop the volume + mwexec("/sbin/gstripe stop $raidname"); + + // Clear the gconcat information on the hard drive + foreach ($freenas_config['gstripe']['vdisk'] as $a_raid) { + if ($a_raid['name'] == $raidname) { + foreach ($a_raid['diskr'] as $disk) { + mwexec("/sbin/gstripe clear {$disk}"); + } + + mwexec("/sbin/gstripe destroy $raidname"); + } + } + + return 0; +} + +/* Delete geom raid5 volume given in parameter */ +function disks_raid_graid5_delete($raidname) { + global $freenas_config, $g; + + // Stop the volume + mwexec("/sbin/graid5 stop $raidname"); + + // The volume can disapear a few second after stop + sleep(2); + + // Clear the graid5 information on the hard drive + foreach ($freenas_config['graid5']['vdisk'] as $a_raid) { + if ($a_raid['name'] == $raidname) { + foreach ($a_raid['diskr'] as $disk) { + mwexec("/sbin/graid5 remove $raidname {$disk}"); + } + + mwexec("/sbin/graid5 destroy $raidname"); + } + } + + return 0; +} + +/* Initialise HARD DRIVE for installing FreeNAS (creating 2 partition) */ +function fdisk_hd_install($harddrive) { + global $freenas_config, $g; + + /* Initialise HARD DRIVE for installing FreeNAS (creating 2 partition) */ + + /* getting disk information */ + $fdisk_info=fdisk_get_info($harddrive); + + /* setting FreeNAS partition size to 32Mb */ + + $part_freenas_size=32; + + /* convert Mb to b */ + $part_freenas_size=$part_freenas_size * 1024 * 1024; + + $part1_size=$part_freenas_size / $fdisk_info['sec_size']; + $part2_size=$fdisk_info['total'] - $part1_size; + + /* Create fdisk config file */ + + /* generate fdisk.conf */ + $fd = fopen("{$g['varetc_path']}/fdisk.conf", "w"); + if (!$fd) { + printf("Error: cannot open fdisk.conf in fdisk_hd_install().\n"); + return 1; + } + +$fdiskconf .= <<<EOD +g c{$fdisk_info['cyl']} h{$fdisk_info['head']} s{$fdisk_info['sect']} +p 1 165 1 $part1_size +p 2 165 $part1_size $part2_size +p 3 0 0 0 +p 4 0 0 0 +a 1 + +EOD; + + fwrite($fd, $fdiskconf); + fclose($fd); + + /* Fdisk the disk */ + + /* Warning: Ask two questions to the user */ + mwexec("/sbin/fdisk -f {$g['varetc_path']}/fdisk.conf /dev/$harddrive"); + + return 0; +} + +function fdisk_get_info($harddrive) { + /* Return information about an harddrive + + $result['total'] : size + $result['cyl'] : cylinders + $result['head'] : heads + $result['sect'] : sectors/track + $result['sec_size'] : Media sector size + + */ + + global $freenas_config, $g; + + exec("/sbin/fdisk /dev/$harddrive",$rawdata); + + $result=array(); + + foreach ($rawdata as $line) { + /* separe the line by space or egal*/ + $aline= preg_split("/[\s,]+|=/", $line); + $first_word = chop($aline[0]); + + if ($aline[0] == "Media") { + $result['sec_size']=chop($aline[4]); + continue ; + } + + if ($aline[0] == "cylinders") { + $result['cyl']=chop($aline[1]); + $result['head']=chop($aline[3]); + $result['sect']=chop($aline[5]); + continue ; + } + } + + $result['total'] = $result['cyl'] * $result['head'] * $result['sect'] ; + + return $result; +} + +/* Is this function still used ??? */ +function disks_bsdlabel($harddrive,$partition,$type) { + global $freenas_config, $g; + + // Generating BSD Label table + passthru("/sbin/bsdlabel " . escapeshellarg($harddrive) ."$partition > {$g['tmp_path']}/label.tmp"); + + // put this file on a array + $tableau = file("{$g['tmp_path']}/label.tmp"); + + // Open this file in add mode + $handle = fopen("{$g['tmp_path']}/label.tmp", 'a'); + + while(list(,$val) = each($tableau)) { + // If the line contain the word "unused" + if (ereg ("unused",$val)) { + // Replacing c: by a: + // Why ??? Must found the web page where I see this method + $val = ereg_replace ("c:","a:", $val); + // Peplacing unused by $type + $val = ereg_replace ("unused",$type, $val); + // Adding this line add the end of the file + fwrite($handle, $val); + } + } + + // Closing file + fclose($handle); + + // Injecting this new partition table + passthru("/sbin/bsdlabel -R -B " . escapeshellarg($harddrive) ."$partition {$g['tmp_path']}/label.tmp"); +} + + +function disks_set_ataidle() { + global $g, $freenas_config; + + if (is_array($freenas_config['disks']['disk'])) { + foreach ($freenas_config['disks']['disk'] as $disk) { + if ($disk['type']=="IDE") { + /* If UDMA mode forced, launch atacontrol */ + if (isset($disk['udma']) && ($disk['udma'] != "auto")) { + mwexec("/sbin/atacontrol mode {$disk['name']} {$disk['udma']}"); + } + + /* Don't use ataidle if all is disabled */ + if (($disk['harddiskstandby'] == 0) && ($disk['apm'] == 0) && ($disk['acoustic'] == 0)) { continue; } + + /* Found the channel and device number from the /dev name */ + /* Divise the number by 2, the interger is the channel number, the rest is the device */ + + $value=trim($disk['name'],'ad'); + + $value=intval($value); + $channel = $value/2; + $device=$value % 2; + $channel=intval($channel); + $time=$disk['harddiskstandby']; + $apm=$disk['apm']; + $ac=$disk['acoustic']; + + $cmd = "/usr/local/sbin/ataidle "; + + if ($disk['acoustic'] != 0) { $cmd .= "-A $ac "; } + if ($disk['apm'] != 0) { $cmd .= "-P $apm "; } + if ($disk['harddiskstandby'] !=0) { $cmd .= "-S $time "; } + + $cmd .= "$channel $device"; + mwexec($cmd); + } // end if + } // end foreach + + return 1; + } // end if + + return 0; +} + +/* Is this function still used ??? +Get list of partition information from disk. +Result is in the form: +[1] => Array +( + [start] => 31 + [size] => 409169 + [type] => 0xa5 + [flags] => 0x80 +) + +Called in disks_manage_tools.php +*/ +function disks_get_partition_info($disk) { + exec("/sbin/fdisk -s {$disk}", $rawdata); + array_shift($rawdata); + array_shift($rawdata); + + $result = array(); + + foreach($rawdata as $partinfo) { + $apartinfo = preg_split("/\s+/", $partinfo); + $partid = chop($apartinfo[1],":"); + + $result[$partid] = array(); + $result[$partid]['start'] = chop($apartinfo[2]); + $result[$partid]['size'] = chop($apartinfo[3]); + $result[$partid]['type'] = chop($apartinfo[4]); + $result[$partid]['flags'] = chop($apartinfo[5]); + } + + return $result; +} + +?> diff --git a/config/freenas/pkg/freenas_functions.inc b/config/freenas/pkg/freenas_functions.inc new file mode 100644 index 00000000..fcea4478 --- /dev/null +++ b/config/freenas/pkg/freenas_functions.inc @@ -0,0 +1,49 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + freenas_functions.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. + */ +/* ========================================================================== */ + +/* include all configuration functions */ +require_once ("freenas_disks.inc"); +require_once ("freenas_utils.inc"); +require_once ("freenas_services.inc"); +require_once ("freenas_system.inc"); + +?>
\ No newline at end of file diff --git a/config/freenas/pkg/freenas_guiconfig.inc b/config/freenas/pkg/freenas_guiconfig.inc new file mode 100644 index 00000000..2dec5a42 --- /dev/null +++ b/config/freenas/pkg/freenas_guiconfig.inc @@ -0,0 +1,288 @@ +<?php +/* + guiconfig.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. +*/ + +$d_mountdirty_path = $g['varrun_path'] . "/mount.dirty"; +$d_diskdirty_path = $g['varrun_path'] . "/disk.dirty"; +$d_raidconfdirty_path = $g['varrun_path'] . "/raid.conf.dirty"; +$d_userconfdirty_path = $g['varrun_path'] . "/user.conf.dirty"; +$d_groupconfdirty_path = $g['varrun_path'] . "/group.conf.dirty"; +$d_smbshareconfdirty_path = $g['varrun_path'] . "/smbshare.conf.dirty"; +$d_nfsexportconfdirty_path = $g['varrun_path'] . "/nfsexport.conf.dirty"; +$d_upnpconfdirty_path = $g['varrun_path'] . "/upnp.conf.dirty"; + +/* ============================================================================= */ +/* == Constants used together with executing a UNIX command line tool == */ +/* ============================================================================= */ + +define("DONE_PARAGRAPH", " + <p> + <span class='red' style='font-family: Courier, monospace; font-size: small;'><strong>Done!</strong></span> + </p> + "); + +define("CMDOUT_PARA", " + <p style='font-size: small;'> + <strong>Command output</strong> (use the toggle icon to unveil detailed infos): + </p> + "); + +define("CMDOUT_PARA_WOHINT", " + <p style='font-size: small;'> + <strong>Command output:</strong> + </p> + "); + +define("CMDOUT_TOGGLE_FUNC", " +function toggle_cmdout(image, totoggle) { + var plusSrc = \"/themes/{$g['theme']}/images/misc/bullet_toggle_plus.png\"; + var minusSrc = \"/themes/{$g['theme']}/images/misc/bullet_toggle_minus.png\"; + var currentSrc = image.src; + var newSrc = (currentSrc.indexOf(\"plus\") >= 0) ? minusSrc : plusSrc; + + image.src = newSrc; + Effect.toggle(totoggle, 'appear', { duration: 0.75 }); +} +"); + +define("CMDOUT_AJAX_SCRIPT", " + <script type='text/javascript'> + function execCMD() { + var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='/themes/nervecenter/images/misc/loader_tab.gif' \/><\/div>\"; + new Insertion.Before('doCMDSubmit', to_insert); + + $('doCMDSubmit').style.visibility = 'hidden'; + $('loading').style.visibility = 'visible'; + $('cmdOutputTD').innerHTML = ''; + + new Ajax.Request( + \"{$_SERVER['SCRIPT_NAME']}\", { + method : 'post', + parameters : Form.serialize($('iform')), + onSuccess : execCMDComplete, + onFailure : execCMDFailure + } + ); + } + + function execCMDFailure(req) { + if($('doCMDSubmit')) $('doCMDSubmit').style.visibility = 'visible'; + if($('loading')) $('loading').style.visibility = 'hidden'; + if($('inputerrors')) window.scrollTo(0, 0); + if($('inputerrors')) new Effect.Shake($('inputerrors')); + if($('inputerrors')) $('inputerrors').innerHTML = req.responseText; + } + + function execCMDComplete(req) { + $('cmdOutputTD').innerHTML = req.responseText; + $('loading').style.visibility = 'hidden'; + $('doCMDSubmit').style.visibility = 'visible'; + $('cmdOutputTD').style.visibility = 'visible'; + } + </script> +"); + +$freenas_config =& $config['installedpackages']['freenas']['config'][0]; + +/* ============================================================================= */ +/* == Functions used together with executing a UNIX command line tool == */ +/* ============================================================================= */ + +function assemble_cmdout($button, $out, $done = false) { + $dopara = DONE_PARAGRAPH; + + $retvalue =<<<EOD +{$button} +{$out} + +EOD; + + if ($done) { $retvalue .= "{$dopara}\n"; } + return $retvalue; +} + +function create_cmdout_container($id = "", $cmd = "") { + $diskinit_str = ""; + + if (is_array($cmd)) { + foreach ($cmd as $cmdline) { + $a_out = exec_command_and_return_text_array($cmdline); + $diskinit_str .= implode("\n", $a_out); + } + } else { + $a_out = exec_command_and_return_text_array($cmd); + $diskinit_str = implode("\n", $a_out); + } + + $returnval =<<<EOD + <div id="{$id}" style="display: none; font-family: Courier, monospace; font-size: small;"> + <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre> + </div> + +EOD; + + return $returnval; +} + +function create_toggle_button($title, $totoggle) { + global $g; + + $returnval =<<<EOD + <table cellpadding="0" cellspacing="0" border="0" style="padding-bottom: 8px;"> + <tr> + <td align="left" valign="middle" style="padding-right: 5px;"> + <img src='/themes/{$g['theme']}/images/misc/bullet_toggle_plus.png' alt='' border='0' style='border: solid 1px silver; cursor: pointer;' onclick='toggle_cmdout(this, "{$totoggle}");' /> + </td> + <td align="left" valign="middle" style='font-family: Courier, monospace; font-size: small;'> + {$title}: + </td> + </tr> + </table> +EOD; + + return $returnval; +} + +function print_error_box_np($msg) { + global $g; + + echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n"; + echo "<tr><td bgcolor=\"#A12A2A\" width=\"36\" align=\"center\" valign=\"top\"><img src=\"/themes/{$g['theme']}/images/icons/icon_error.gif\" width=\"28\" height=\"32\"></td>\n"; + echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">"; + echo "<span class=\"errmsg\">"; + echo $msg; + echo "</span>"; + echo "</td></tr></table>"; +} + +function print_error_box($msg) { + echo "<p>"; + print_error_box_np($msg); + echo "</p>"; +} + +function mount_sort() { + global $g, $freenas_config; + + function mountcmp($a, $b) { + return strcmp($a['mdisk'], $b['mdisk']); + } + + usort($freenas_config['mounts']['mount'], "mountcmp"); +} + +function disks_sort() { + global $g, $freenas_config; + + function diskcmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($freenas_config['disks']['disk'], "diskcmp"); +} + +function gvinum_sort() { + global $g, $freenas_config; + + function gvinumcmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($freenas_config['gvinum']['vdisk'], "gvinumcmp"); + +} + +function gmirror_sort() { + global $g, $freenas_config; + + function gmirrorcmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($freenas_config['gmirror']['vdisk'], "gmirrorcmp"); + +} + +function gconcat_sort() { + global $g, $freenas_config; + + function gconcatcmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($freenas_config['gconcat']['vdisk'], "gconcatcmp"); + +} + +function gstripe_sort() { + global $g, $freenas_config; + + function gstripecmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($freenas_config['gstripe']['vdisk'], "gstripecmp"); + +} + +function graid5_sort() { + global $g, $freenas_config; + + function graid5cmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($freenas_config['graid5']['vdisk'], "graid5cmp"); + +} + +/* TODO: This needs to be changed */ +function users_sort() { + global $g, $config; + + function userscmp($a, $b) { + return strcmp($a['login'], $b['login']); + } + + usort($config['system']['user'], "userscmp"); +} + +/* TODO: This needs to be changed */ +function groups_sort() { + global $g, $config; + + function groupscmp($a, $b) { + return strcmp($a['name'], $b['name']); + } + + usort($config['system']['group'], "groupscmp"); +} +?>
\ No newline at end of file diff --git a/config/freenas/pkg/freenas_services.inc b/config/freenas/pkg/freenas_services.inc new file mode 100644 index 00000000..71401211 --- /dev/null +++ b/config/freenas/pkg/freenas_services.inc @@ -0,0 +1,2025 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + 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"); +define ("NFS_SERVICE_PORTS", "111 2049 4711"); + +$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; + + /* kill any running samba */ + killbyname("smbd"); + killbyname("winbindd"); + killbyname("nmbd"); + + 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")) { + mkdir("{$g['varetc_path']}/private"); + } + 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; } + + $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']} +workgroup = {$freenas_config['samba']['workgroup']} +server string = {$freenas_config['samba']['serverdesc']} +load printers = no +security = {$freenas_config['samba']['security']} +dns proxy = no +socket options = IPTOS_LOWDELAY TCP_NODELAY +EOD; + + if ($freenas_config['samba']['sndbuf']) { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD + SO_SNDBUF={$freenas_config['samba']['sndbuf']} +EOD; + } else { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD + SO_SNDBUF=16384 +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 { + /* below is a continuation of socket options! */ + $sambaconf .= <<<EOD + SO_RCVBUF=16384 +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 + +unix charset = {$freenas_config['samba']['unixcharset']} + +EOD; + } else { + $sambaconf .= <<<EOD + +unix charset = UTF-8 + +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 = 10 +syslog only = yes +syslog = {$config['samba']['loglevel']} +load printers = no +printing = bsd +printcap name = /dev/null +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 +private dir = {$g['varetc_path']}/private + +EOD; + + switch ($freenas_config['samba']['security']) { + case "share": + $sambaconf .= <<<EOD +create mask = 0666 +directory mask = 0777 +passdb backend = smbpasswd + +EOD; + + $guestmode = <<<EOD +guest ok = yes + +EOD; + + break; // end case "share" + case "domain": + $sambaconf .= <<<EOD +passdb backend = smbpasswd +allow trusted domains = No +dns proxy = No +ldap ssl = no +idmap backend = rid:{$freenas_config['samba']['workgroup']}=10000-20000 +idmap uid = 10000-20000 +idmap gid = 10000-20000 +winbind enum groups = yes +winbind enum users = yes +winbind use default domain = Yes +template homedir = /mnt +template shell = /bin/sh + +EOD; + + $guestmode = <<<EOD +guest ok = no + +EOD; + break; // end case "domain": + case "user": + $sambaconf .= <<<EOD +passdb backend = smbpasswd + +EOD; + + $guestmode = <<<EOD +guest ok = no + +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']} +path = /mnt/{$mountent['sharename']} +public = yes +writeable = yes +printable = no +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 +browseable = no + +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']}"); + } + + $result |= 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']}"); + } + + $result |= mwexec("/usr/local/sbin/smbd -D -s {$g['varetc_path']}/smb.conf"); + + /* TEST: Wait for samba starting */ + sleep(2); + + /* Generate the samba password file */ + $result |= system_user_samba(); + + 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; + + /* kill any running rsync daemon */ + sigkillbypid("{$g['varrun_path']}/rsyncd.pid", "TERM"); + + 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 +read only = {$freenas_config['rsyncd']['readonly']} +syslog facility = local4 +list = yes +port = {$freenas_config['rsyncd']['port']} +pid file = {$g['varrun_path']}/rsyncd.pid + +EOD; + + if (!empty($freenas_config['rsyncd']['maxcon'])) { + $rsyncdconf .= <<<EOD +max connections = {$freenas_config['rsyncd']['maxcon']} + +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 +uid = {$freenas_config['rsyncd']['rsyncd_user']} + +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 + +[{$mountent['sharename']}] +comment = {$mountent['desc']} +path = /mnt/{$mountent['sharename']} + +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); + } // end if + + /* run rsync Daemon */ + $result = mwexec("/usr/local/bin/rsync --daemon --config={$g['varetc_path']}/rsyncd.conf"); + + if ($g['booting']) { echo "done\n"; } + } // end if + + 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; + + /* 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... "; } + + $nfsconf = ""; + $a_nfsconf = array(); + + /* 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; + } + + $a_mount = &$freenas_config['mounts']['mount']; + $pfnetworks = array(); + + foreach ($a_mount as $mount) { + /* -mapall and -maproot mutually exclusive */ + $mapping = $mount['nfs']['mapall'] == "yes" ? "-mapall=root" : "-maproot=root"; + $networks = isset($mount['nfs']['networks']) ? $mount['nfs']['networks'] : ""; + + $nfsconf = "/mnt/{$mount['sharename']} -alldirs {$mapping}"; + + if ($networks <> "") { + foreach (explode(",", $networks) as $netel) { + list($network,$subnet) = + explode('/', $netel); + + $subnet = gen_subnet_mask($subnet); + $pfnetworks[] = $network; + + $tmp_nfsconf .= "{$nfsconf} -network {$network} -mask {$subnet}\n"; + } + + services_setup_transparency_for("nfs", implode(" ", $pfnetworks)); + $nfsconf = $tmp_nfsconf; + } else { + $nfsconf .= "\n"; + } + } + + fwrite($fd, $nfsconf); + fclose($fd); + + $nfsdbindto = $freenas_config['nfs']['bindto'] = "(ANY)" ? " -a" : " -h {$freenas_config['nfs']['bindto']}"; + $rpcbbindto = $freenas_config['nfs']['bindto'] = "(ANY)" ? "" : " -h {$freenas_config['nfs']['bindto']}"; + $servetcp = isset($freenas_config['nfs']['servetcp']) ? " -t" : ""; + $serveudp = isset($freenas_config['nfs']['serveudp']) ? " -u" : ""; + + /* run rpcbind, nfsd and mountd */ + mwexec("/usr/sbin/rpcbind{$rpcbbindto}"); + mwexec("/usr/sbin/nfsd{$nfsdbindto}{$serveudp}{$servetcp} -n 4"); + mwexec("/usr/sbin/mountd -p 4711 -r {$g['varetc_path']}/exports"); + mwexec("/usr/sbin/rpc.lockd"); + mwexec("/usr/sbin/rpc.statd"); + + if ($g['booting']) { echo "done\n"; } + } else { + services_remove_transparency_for("nfs"); + }// end if + + return 0; +} + +function services_remove_transparency_for($whom) { + global $g; + + $service_result = mwexec ("pfctl -a \"passin-package-freenas-{$whom}\" -F rules"); + if($service_result <> 0) { + file_notice("FREENAS", "There were error(s) flushing the exclude table", "FREENAS", ""); + } + + unlink_if_exists("{$g['pkg_path']}/pf/freenas-{$whom}.sh"); +} + +function services_setup_transparency_for($whom, $networks) { + global $g, $config, $freenas_config; + + if ($whom == "" || $networks == "") { return; } + + $generatedLANSubnet = gen_subnet($config['interfaces']['lan']['ipaddr'], + $config['interfaces']['lan']['subnet']); + $aliases = ""; + + /* stolen from filter.inc */ + $real_wanif = get_real_wan_interface(); + $wanip = find_interface_ip($real_wanif); + + $wan_aliases = " " . link_ip_to_carp_interface($wanip); + + if (link_int_to_bridge_interface("wan")) + $wan_aliases .= " " . link_int_to_bridge_interface("wan"); + + if ($config['interfaces']['wan']['ipaddr'] == "pppoe" or $config['interfaces']['wan']['ipaddr'] == "pptp") { + $aliases .= "ng0 = \"{ {$config['interfaces']['wan']['if']} {$real_wanif} }\" \n"; + $aliases .= "wan = \"{ {$config['interfaces']['wan']['if']} {$wan_aliases} ng0 }\"\n"; + } else { + $aliases .= "wan = \"{ {$real_wanif} {$wan_aliases} }\"\n"; + } + + $trans_file = fopen("/tmp/freenas-{$whom}.rules","w"); + fwrite($trans_file, "{$aliases}\n"); + + switch ($whom) { + case "nfs": + $nfs_ports = explode(" ", NFS_SERVICE_PORTS); + + foreach ($nfs_ports as $port) { + fwrite($trans_file, "pass in quick on \$wan proto { tcp udp } from { {$networks} } to {$freenas_config['nfs']['bindto']} port = {$port} keep state label \"FreeNAS related rule for {$whom}-{$port}\"\n"); + } + break; + } + fclose($trans_file); + $service_result = mwexec ("pfctl -a \"passin-package-freenas-{$whom}\" -f /tmp/freenas-{$whom}.rules"); + if($service_result <> 0) { + file_notice("FREENAS", "There were error(s) loading the transparency rules", "FREENAS", ""); + } + + /* create a shell script to make sure our filter rules + * are getting loaded upon each filter realod cycle. + */ + $scriptstr = "#!/bin/sh\n\n"; + $scriptstr .= "case $1 in\n"; + $scriptstr .= " start)\n"; + $scriptstr .= " if [ -f /tmp/freenas-nfs.rules ]; then\n"; + $scriptstr .= " /sbin/pfctl -a \"passin-package-freenas-{$whom}\" -f /tmp/freenas-{$whom}.rules\n"; + $scriptstr .= " fi\n"; + $scriptstr .= " ;;\n"; + $scriptstr .= " *)\n"; + $scriptstr .= " echo \"Usage: $0 (start|stop|restart|status|log)\"\n"; + $scriptstr .= " exit 1\n"; + $scriptstr .= "esac\n"; + + file_put_contents("{$g['pkg_path']}/pf/freenas-{$whom}.sh", $scriptstr); + chmod("{$g['pkg_path']}/pf/freenas-{$whom}.sh", 0700); +} + +function services_ftpd_configure() { + global $freenas_config, $g; + // services_vsftpd_configure(); + // services_pureftpd_configure(); + services_wzdftpd_configure(); +} + +function services_wzdftpd_configure() { + global $freenas_config, $config, $g; + + /* kill any WZDFTPD */ + killbyname("wzdftpd"); + + if (isset($freenas_config['ftp']['enable'])) { + if ($g['booting']) { echo "Starting FTP server... "; } + + /* 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"); } + + /* 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; + } + + $ftpconf = <<<EOD +[GLOBAL] +config version = 0.7.2 +backup config = true +port = {$freenas_config['ftp']['port']} + +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 + +pasv_ip = {$freenas_config['ftp']['pasv_address']} +dir_message = .message +logfile = /var/log/wzdftpd/wzd.log +xferlog = /var/log/wzdftpd/xferlog +logdir = /var/log/wzdftpd +max_threads = {$freenas_config['ftp']['numberclients']} + +backend = /usr/local/share/wzdftpd/backends/libwzd{$freenas_config['ftp']['authentication_backend']}.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 = * + +EOD; + + if (! empty($freenas_config['ftp']['timeout'])) { + $ftpconf .= "site_idle ={$freenas_config['ftp']['timeout']}\n"; + } else { + $ftpconf .= "site_idle = *\n"; + } + + $ftpconf .= <<<EOD +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] +/usr/local/share/wzdftpd/modules/libwzd_debug.so = deny +/usr/local/share/wzdftpd/modules/libwzd_test.so = deny +/usr/local/share/wzdftpd/modules/libwzd_sfv.so = allow +/usr/local/share/wzdftpd/modules/libwzd_tcl.so = deny +/usr/local/share/wzdftpd/modules/libwzd_perl.so = deny + +EOD; + + if (empty($config['system']['zeroconf_disable'])) { + $ftpconf .= <<<EOD +/usr/local/share/wzdftpd/modules/libwzd_zeroconf.so = allow + +[ZEROCONF] +zeroconf_port = {$freenas_config['ftp']['port']} +zeroconf_username = wzdftpd +zeroconf_password = wzdftpd +zeroconf_path = / + +EOD; + + } + + $ftpconf .= <<<EOD + +[sfv] +progressmeter = [WzD] - %3d%% Complete - [WzD] +del_progressmeter = \[.*] - ...% Complete - \[WzD] +incomplete_indicator = ../(incomplete)-%0 +other_completebar = [WzD] - ( %.0mM %fF - COMPLETE ) - [WzD] + +[plaintext] +param = /usr/local/etc/wzdftpd/users + +[sections] +ALL = /* ^([]\[A-Za-z0-9_.'() \\t+-])*\$ + +[cron] + +[events] + +[custom_commands] +site_rules = !/usr/local/etc/wzdftpd/file_rules.txt + +site_groups = !/usr/local/etc/wzdftpd/file_groups.txt +site_help = !/usr/local/etc/wzdftpd/file_help.txt +site_swho = !/usr/local/etc/wzdftpd/file_swho.txt +site_users = !/usr/local/etc/wzdftpd/file_users.txt +site_vfsls = !/usr/local/etc/wzdftpd/file_vfs.txt +site_who = !/usr/local/etc/wzdftpd/file_who.txt + +[vfs] + +[messages] + +EOD; + + 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); + + /* 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; + + $ftpusers .= <<<EOD + +privgroup {$group['name']} +gid={$gid} +default_home=/ + +EOD; + } // end foreach + + /* anonymous group */ + if (! empty($freenas_config['ftp']['anonymous'])) { + $ftpusers .= <<<EOD + +privgroup anonymous +max_idle_time=10 +gid=3 +default_home=/home + +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']} +home=/ +uid={$i} +groups={$user['groupname']} +rights=0xffffffff + +EOD; + } // end foreach + + /* anonymous user */ + if (! empty($freenas_config['ftp']['anonymous'])) { + $ftpusers .= <<<EOD + +name=guest +pass=% +home=/tmp +uid=200 +groups=anonymous +rights=0x10003 +ip_allowed=* +max_dl_speed=20480 +credits=0 +bytes_ul_total=0 +bytes_dl_total=1918812 +num_logins=2 + +EOD; + } // end if + + $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"; } + } // end if + + return 0; +} + +/* this function is currently not used */ +function services_vsftpd_configure() { + global $freenas_config, $g; + + /* 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 +# Standalone mode +listen=YES +background=YES +listen_port={$freenas_config['ftp']['port']} +max_clients={$freenas_config['ftp']['numberclients']} +max_per_ip={$freenas_config['ftp']['maxconperip']} +xferlog_enable=YES +#vsftpd_log_file=/var/log/ftp.log +syslog_enable=YES +# Access rights +anonymous_enable={$freenas_config['ftp']['anonymous']} +local_enable={$freenas_config['ftp']['localuser']} +write_enable=YES +hide_file=.snap +anon_other_write_enable=YES +anon_upload_enable=YES +anon_mkdir_write_enable=YES +chroot_local_user=YES +local_umask=066 +anon_umask=066 +chmod_enable=YES +pasv_address={$freenas_config['ftp']['pasv_address']} +# Features +ls_recurse_enable=YES +# Performance +idle_session_timeout={$freenas_config['ftp']['timeout']} + +EOD; + if (isset($freenas_config['ftp']['banner'])) { + $ftpconf .= <<<EOD +ftpd_banner={$freenas_config['ftp']['banner']} + +EOD; + } 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 +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 +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"); + + if ($g['booting']) { echo "done\n"; } + } + + return 0; +} + +function services_pureftpd_configure() { + global $freenas_config, $g; + + /* kill any Pure-FTPD */ + killbyname("pure-ftpd"); + + 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 pfSense FTP service + +EOD; + } else { + $banner = <<<EOD +{$freenas_config['ftp']['banner']} + +EOD; + } // 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"); + + if (isset($config['system']['smart'])) { + if ($g['booting']) { echo "Starting smartd... "; } + + /* run smartd */ + mwexec("/usr/local/sbin/smartd --logfacility=local5"); + + if ($g['booting']) { echo "done\n"; } + } + + 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"); + + /* ======================================================================= */ + /* = 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 + + /* 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 = "*"; + } + + $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; + + // 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 +exit +fi +/usr/bin/touch /var/run/rsync-running + +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; + } // 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"; } + } // end if + + return 0; +} + +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; + } + + $syncscript = <<<EOD +#!/bin/sh + +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 + -noslp -nozeroconf -uamlist +EOD; + } // end if + + 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 + uams_guest.so +EOD; + } else if (isset($freenas_config['afp']['local'])) { + $afpconf .= <<<EOD + uams_clrtxt.so,uams_dhx.so +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 +/mnt/{$mount['sharename']} "{$mount['sharename']}" + +EOD; + + } // end foreach + + fwrite($fd, $AppleVolumes); + fclose($fd); + + /* run afpdpd */ + mwexec("/usr/local/sbin/afpd -F {$g['varetc_path']}/afpd.conf"); + + if ($g['booting']) { echo "done\n"; } + } // end if + + return 0; +} + +function services_nis_configure() { + global $freenas_config, $g; + + 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(); + return services_avahi_configure(); +} + +function services_avahi_configure() { + global $freenas_config, $config, $g; + + $service_template = <<<EOD +<?xml version="1.0" standalone='no'?> +<!DOCTYPE service-group SYSTEM "avahi-service.dtd"> +<service-group> + + <name replace-wildcards="yes">@SERVICE_DESC@ on %h</name> + + <service> + <type>@TYPE@</type> + <port>@PORT@</port> + @TXT_RECORDS@ + </service> + +</service-group> + +EOD; + + /* 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 */ + mwexec("/usr/local/sbin/avahi-daemon -k"); + + /* 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 + + /* 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 + + /* add ntp service type */ + if ($config['ntpd']['mode'] == "server") { + $ntpdservice = str_replace("@PORT@", + "123", + $service_template); + $ntpdservice = str_replace("@TYPE@", + "_ntp._udp", + $ntpdservice); + $ntpdservice = str_replace("@SERVICE_DESC@", + "Network Time Daemon", + $ntpdservice); + $ntpdservice = str_replace("@TXT_RECORDS@", + "", + $ntpdservice); + + file_put_contents("/usr/local/etc/avahi/services/ntpd.service", $ntpdservice); + } // end if + + 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; +} + +/* 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 +"{$config['system']['hostname']} Web Admin" _http._tcp local. 80 + +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 +"{$config['system']['hostname']} RSYNC Server" _rsync._tcp. local. {$freenas_config['rsyncd']['port']} + +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 +"{$config['system']['hostname']} FTP Server" _ftp._tcp local. {$freenas_config['ftp']['port']} + +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 +"{$config['system']['hostname']} NFS: {$mount['sharename']}" _nfs._tcp local. 2049 path=/mnt/{$mount['sharename']} + +EOD; + } // end foreach + } // end if + + fwrite($fd, $mDNSResponder); + fclose($fd); + + + /* run mDNSResponder */ + mwexec("/usr/local/sbin/mDNSResponder -f {$g['varetc_path']}/mDNSResponder.conf"); + + if ($g['booting']) { echo "done\n"; } + + return 0; +} + +/* this function is currently not used */ +function services_mdnsresponder_configure() { + global $freenas_config, $config, $g; + + /* 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 +"{$config['system']['hostname']} Web Admin" +_http._tcp local. +80 + +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 + +"{$config['system']['hostname']} RSYNC Server" +_rsync._tcp. local. +{$freenas_config['rsyncd']['port']} + +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 + +"{$config['system']['hostname']} FTP Server" +_ftp._tcp local. +{$freenas_config['ftp']['port']} + +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 + +"{$config['system']['hostname']} NFS: {$mount['sharename']}" +_nfs._tcp local. +2049 path=/mnt/{$mount['sharename']} + +EOD; + } // 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; +} +?>
\ No newline at end of file diff --git a/config/freenas/pkg/freenas_system.inc b/config/freenas/pkg/freenas_system.inc new file mode 100644 index 00000000..2bd0a30a --- /dev/null +++ b/config/freenas/pkg/freenas_system.inc @@ -0,0 +1,838 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + freenas_system.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. + */ +/* ========================================================================== */ + +require_once("globals.inc"); + +$freenas_config =& $config['installedpackages']['freenas']['config'][0]; + +function system_do_extensions($early = false) { + global $config, $g; + + if (!is_dir("{$g['etc_path']}/inc/ext")) { return; } + + $dh = @opendir("{$g['etc_path']}/inc/ext"); + + if ($dh) { + while (($extd = readdir($dh)) !== false) { + if (($extd === ".") || ($extd === "..")) { continue; } + + $rcfile = "{$g['etc_path']}/inc/ext/" . $extd . "/" . ($early ? "rc.early" : "rc"); + + if (file_exists($rcfile)) { passthru($rcfile); } + } // end while + + closedir($dh); + } // end if +} + +function system_set_termcap() { + global $config; + + if (isset($config['diag']['ipfstatentries'])) { + $lines = $config['diag']['ipfstatentries'] + 6; + } else { + $lines = 306; + } + + /* do not remove the tabs below or replace them using whitespaces */ + $termcap = <<<EOD +cons25w|ansiw|ansi80x25-raw:\ + :am:bs:NP:ms:pt:AX:eo:bw:ut:km:\ + :co#80:li#25:pa#64:Co#8:it#8:\ + :al=\E[L:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:\ + :dc=\E[P:dl=\E[M:do=\E[B:bt=\E[Z:ho=\E[H:ic=\E[@:cb=\E[1K:\ + :nd=\E[C:rs=\Ec:so=\E[7m:se=\E[27m:up=\E[A:cr=^M:ta=^I:\ + :AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:sc=\E7:rc=\E8:\ + :k1=\E[M:k2=\E[N:k3=\E[O:k4=\E[P:k5=\E[Q:k6=\E[R:k7=\E[S:k8=\E[T:\ + :k9=\E[U:k;=\E[V:F1=\E[W:F2=\E[X:K2=\E[E:nw=\E[E:ec=\E[%dX:\ + :kb=^H:kh=\E[H:ku=\E[A:kd=\E[B:kl=\E[D:kr=\E[C:le=^H:sf=\E[S:sr=\E[T:\ + :kN=\E[G:kP=\E[I:@7=\E[F:kI=\E[L:kD=\\177:kB=\E[Z:\ + :IC=\E[%d@:DC=\E[%dP:SF=\E[%dS:SR=\E[%dT:AL=\E[%dL:DL=\E[%dM:\ + :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:cv=\E[%i%dd:ch=\E[%i%d`:\ + :mb=\E[5m:md=\E[1m:mr=\E[7m:me=\E[m:bl=^G:\ + :ve=\E[=S:vi=\E[=1S:vs=\E[=2S: +cons25|ansis|ansi80x25:\ + :ac=l\\332m\\300k\\277j\\331u\\264t\\303v\\301w\\302q\\304x\\263n\\305`^Da\\260f\\370g\\361~\\371.^Y-^Xh\\261i^U0\\333y\\363z\\362:\ + :tc=cons25w: +dumb|su|unknown:\ + :am:co#132:li#$lines:do=^J: +xterm-noapp|xterm with cursor keys in normal mode:\ + :kl=\E[D:kd=\E[B:kr=\E[C:ku=\E[A:ks=\E=:ke=\E>:ti@:te@:tc=xterm: +xterm|xterm-color|X11 terminal emulator:\ + :ti@:te@:tc=xterm-xfree86: +xterm-xfree86|XFree86 xterm:\ + :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\ + :k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:\ + :k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:\ + :kH=\EOF:@7=\EOF:kI=\E[2~:\ + :kh=\EOH:*6=\EOF:kP=\E[5~:kN=\E[6~:\ + :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:Km=\E[M:tc=xterm-basic: +xterm-basic|xterm common (XFree86):\ + :li#24:co#80:am:kn#12:km:mi:ms:xn:bl=^G:\ + :is=\E[!p\E[?3;4l\E[4l\E>:rs=\E[!p\E[?3;4l\E[4l\E>:le=^H:\ + :AL=\E[%dL:DL=\E[%dM:DC=\E[%dP:al=\E[L:dc=\E[P:dl=\E[M:\ + :UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:\ + :ho=\E[H:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:cs=\E[%i%d;%dr:\ + :im=\E[4h:ei=\E[4l:ks=\E[?1h\E=:ke=\E[?1l\E>:kD=\E[3~:kb=^H:\ + :sf=\n:sr=\EM:st=\EH:ct=\E[3g:sc=\E7:rc=\E8:\ + :eA=\E(B\E)0:as=^N:ae=^O:ml=\El:mu=\Em:up=\E[A:nd=\E[C:\ + :md=\E[1m:me=\E[m^O:mr=\E[7m:so=\E[7m:se=\E[27m:us=\E[4m:ue=\E[24m:\ + :ti=\E[?1049h:te=\E[?1049l:vi=\E[?25l:ve=\E[?25h:\ + :ut:Co#8:pa#64:op=\E[39;49m:AB=\E[4%dm:AF=\E[3%dm:\ + +EOD; + + if (!file_exists("/usr/share/misc")) { mkdir("/usr/share/misc"); } + + $fd = @fopen("/usr/share/misc/termcap", "w"); + + if (!$fd) { + printf("Error: cannot open termcap in system_set_termcap().\n"); + return 1; + } + + chmod("/usr/share/misc/termcap", 0644); + fwrite($fd, $termcap); + fclose($fd); + + return 0; +} + +/* TODO: Figure out whether this function can be removed cause + * implements its own user management framework. + */ +function system_users_create() { + /* Create All the passwd file */ + global $config, $g; + + if ($g['booting']) { echo "Generating user database... "; } + + system_user_masterpasswd(); + system_user_group(); + system_user_pwdmkdb(); + + if ($g['booting']) { echo "done\n"; } + + return 0; +} + +/* TODO: Figure out whether this function can be removed cause + * implements its own user management framework. + */ +function system_user_masterpasswd() { + /* Create the master.passwd file*/ + global $config, $g, $userindex, $groupindex; + $root = getUNIXRoot(); + + $masterpasswd = <<<EOD +root:{$root['password']}:0:0::0:0:Charlie &:/root:/bin/sh +toor:*:0:0::0:0:Bourne-again Superuser:/root: +daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin +operator:*:2:5::0:0:System &:/:/usr/sbin/nologin +bin:*:3:7::0:0:Binaries Commands and Source:/:/usr/sbin/nologin +tty:*:4:65533::0:0:Tty Sandbox:/:/usr/sbin/nologin +kmem:*:5:65533::0:0:KMem Sandbox:/:/usr/sbin/nologin +smmsp:*:25:25::0:0:Sendmail Submission User:/var/spool/clientmqueue:/usr/sbin/nologin +mailnull:*:26:26::0:0:Sendmail Default User:/var/spool/mqueue:/usr/sbin/nologin +proxy:*:62:62::0:0:Packet Filter pseudo-user:/nonexistent:/usr/sbin/nologin +_pflogd:*:64:64::0:0:pflogd privsep user:/var/empty:/usr/sbin/nologin +www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin +nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin +dhcpd:*:1002:1002::0:0:DHCP Daemon:/nonexistent:/sbin/nologin +_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin +_isakmpd:*:68:68::0:0:isakmpd privsep:/var/empty:/sbin/nologin +ftp:*:21:50::0:0:FTP user:/mnt:/sbin/nologin +sshd:*:22:22::0:0:Secure Shell Daemon:/var/empty:/usr/sbin/nologin + +EOD; + + if (is_array($config['system']['user'])) { + foreach ($config['system']['user'] as $user) { + $password= $user['password']; + $groupname = $user['groupname']; + $group =& $config['system']['group'][$groupindex[$groupname]]; + + if (empty($user['uid'])) { + $newuser = assignUID($user['name']); + $newgroup = assignGID($groupname); + if (! empty($newuser)) { $user = $newuser; } + if (! empty($newgroup)) { $group = $newgroup; } + } + + if (hasShellAccess($user['name'])) { + $masterpasswd .= <<<EOD +{$user['name']}:{$password}:{$user['uid']}:{$group['gid']}::0:0:{$user['fullname']}:/mnt:/etc/rc.initial + +EOD; + } else { + $masterpasswd .= <<<EOD +{$user['name']}:{$password}:{$user['uid']}:{$group['gid']}::0:0:{$user['fullname']}:/mnt:/usr/local/bin/scponly + +EOD; + } // end if + } // end foreach + } // end if + + $fd = fopen("/etc/master.passwd", "w"); + + if (!$fd) { + printf("Error: cannot open master.passwd in system_user_masterpasswd().\n"); + return 1; + } + + fwrite($fd, $masterpasswd); + fclose($fd); + +return 0; +} + +/* TODO: Figure out whether this function can be removed cause + * implements its own user management framework. + */ +function system_user_group() { + /* Create the group file*/ + global $config, $g; + + $groupfile = <<<EOD +wheel:*:0:root +EOD; + + /* If user exist with full shell, put them on the wheel group */ + if (is_array($config['system']['user'])) { + foreach ($config['system']['user'] as $user) { + if (hasShellAccess($user['name']) && isSystemAdmin($user['name'])) { + $groupfile .= <<<EOD +,{$user['name']} +EOD; + } // end if + } // end foreach + } // end if + + $groupfile .= <<<EOD + +daemon:*:1: +kmem:*:2: +sys:*:3: +tty:*:4: +operator:*:5:root +mail:*:6: +bin:*:7: +staff:*:20: +EOD; + + /* If user exist without full shell, put them on the staff group */ + if (is_array($config['system']['user'])) { + foreach ($config['system']['user'] as $user) { + if (hasShellAccess($user['name'])) { + $groupfile .= <<<EOD +{$user['name']}, +EOD; + } // end if + } // end foreach + } // end if + + $groupfile .= <<<EOD + +sshd:*:22: +smmsp:*:25: +mailnull:*:26: +guest:*:31: +proxy:*:62: +_pflogd:*:64: +_dhcp:*:65: +ftp:*:50: +authpf:*:63: +network:*:69: +www:*:80: +nogroup:*:65533: +nobody:*:65534: +admin:*:0: + +EOD; + + if (is_array($config['system']['group'])) { + foreach ($config['system']['group'] as $group) { + if (empty($group['gid'])) { + $newgroup = assignGID($group['name']); + if (! empty($newgroup)) { $group = $newgroup; } + } + + $groupfile .= <<<EOD +{$group['name']}:*:{$group['gid']}: + +EOD; + } // end foreach + } // end if + + $fd = fopen("/etc/group", "w"); + + if (!$fd) { + printf("Error: cannot open group in system_user_group().\n"); + return 1; + } + + fwrite($fd, $groupfile); + fclose($fd); + + return 0; +} + +function system_user_pwdmkdb() { + /* Generate the db of password */ + global $config, $g; + + mwexec("/usr/sbin/pwd_mkdb -p -d /etc /etc/master.passwd"); + + return 0; +} + +function system_user_samba() { + /* Generate the db of password */ + + // TODO: MUST FIND A WAY OF USING UNIX CRYPTED PASSWORD IN THE PLACE OF CLEAR TEXT PASSWORD FOR GENERATING SAMBA DB!!! + + global $config, $g; + + if (is_array($config['system']['user'])) { + foreach ($config['system']['user'] as $user) { + /* TODO: the password in config.xml is already encrypted */ + $password = escapeshellcmd($user['password']); + $login = escapeshellcmd($user['name']); + mwexec("(/bin/echo {$password}; /bin/echo {$password}) | /usr/local/bin/smbpasswd -s -a {$login}"); + //mwexec("(/bin/echo {$password}; /bin/echo {$password}) | /usr/local/bin/pdbedit -tau {$login}"); + } // end foreach + } // end if + + return 0; + +} + +function system_pam_configure() { + /* Create the pam configuration files*/ + global $config, $g; + + if (!file_exists("{$g['varetc_path']}/pam.d")) { + mkdir("{$g['varetc_path']}/pam.d", 0744); + } + + $system = <<<EOD +# System-wide defaults +# auth +auth sufficient pam_opie.so no_warn no_fake_prompts +auth requisite pam_opieaccess.so no_warn allow_local + +EOD; + + if (isset($config['ad']['enable'])) { + $system .= <<<EOD +#auth sufficient /usr/local/lib/pam_winbind.so debug try_first_pass + +EOD; + } + + $system .= <<<EOD +auth required pam_unix.so no_warn try_first_pass nullok + +# account + +EOD; + + if (isset($config['ad']['enable'])) { + $system .= <<<EOD +#account sufficient /usr/local/lib/pam_winbind.so + +EOD; + } + + $system .= <<<EOD +account required pam_login_access.so +account required pam_unix.so + +# session +session required pam_lastlog.so no_fail + +# password + +EOD; + + if (isset($config['ad']['enable'])) { + $system .= <<<EOD +#password sufficient /usr/local/lib/pam_winbind.so debug try_first_pass + +EOD; + } + + $system .= <<<EOD +password required pam_unix.so no_warn try_first_pass + +EOD; + + $fd = fopen("{$g['varetc_path']}/pam.d/system", "w"); + + if (!$fd) { + printf("Error: cannot open /pam.d/system in system_pam_configure().\n"); + return 1; + } + + fwrite($fd, $system); + fclose($fd); + + $sshd .= <<<EOD +# PAM configuration for the "sshd" service + +# auth +auth required pam_nologin.so no_warn +auth sufficient pam_opie.so no_warn no_fake_prompts +auth requisite pam_opieaccess.so no_warn allow_local + +EOD; + + if (isset($config['ad']['enable'])) { + $sshd .= <<<EOD +auth sufficient /usr/local/lib/pam_winbind.so debug try_first_pass + +EOD; + } + + $sshd .= <<<EOD +auth required pam_unix.so no_warn try_first_pass + +# account + +EOD; + + if (isset($config['ad']['enable'])) { + $sshd .= <<<EOD +account sufficient /usr/local/lib/pam_winbind.so + +EOD; + } + + $sshd .= <<<EOD +account required pam_unix.so + +# session +session required pam_permit.so + +# password + +EOD; + + if (isset($config['ad']['enable'])) { + $sshd .= <<<EOD +password sufficient /usr/local/lib/pam_winbind.so debug try_first_pass + +EOD; + } + + $sshd .= <<<EOD +password required pam_unix.so no_warn try_first_pass + +EOD; + + unset($fd); + $fd = fopen("{$g['varetc_path']}/pam.d/sshd", "w"); + + if (!$fd) { + printf("Error: cannot open /pam.d/sshd in system_pam_configure().\n"); + return 1; + } + + fwrite($fd, $sshd); + fclose($fd); + + $ftp = <<<EOD +# PAM configuration for the "ftpd" service + +# auth +auth required pam_nologin.so no_warn +auth sufficient pam_opie.so no_warn no_fake_prompts +auth requisite pam_opieaccess.so no_warn allow_local + +EOD; + + if (isset($config['ad']['enable'])) { + $ftp .= <<<EOD +auth sufficient /usr/local/lib/pam_winbind.so debug try_first_pass + +EOD; + } + + $ftp .= <<<EOD +auth required pam_unix.so no_warn try_first_pass + +# account + +EOD; + + if (isset($config['ad']['enable'])) { + $ftp .= <<<EOD +account sufficient /usr/local/lib/pam_winbind.so + +EOD; + } + + $ftp .= <<<EOD +account required pam_login_access.so +account required pam_unix.so + +# session +session required pam_permit.so + +EOD; + + unset($fd); + $fd = fopen("{$g['varetc_path']}/pam.d/ftp", "w"); + + if (!$fd) { + printf("Error: cannot open /pam.d/ftp in system_pam_configure().\n"); + return 1; + } + + fwrite($fd, $ftp); + fclose($fd); + + $login = <<<EOD +# PAM configuration for the "login" service +# + +# auth +auth required pam_nologin.so no_warn + +EOD; + + if (isset($config['ad']['enable'])) { + $login .= <<<EOD +auth sufficient /usr/local/lib/pam_winbind.so debug try_first_pass + +EOD; + } + + $login .= <<<EOD +auth sufficient pam_self.so no_warn +auth include system + +# account + +EOD; + + if (isset($config['ad']['enable'])) { + $login .= <<<EOD +account sufficient /usr/local/lib/pam_winbind.so + +EOD; + } + + $login .= <<<EOD +account requisite pam_securetty.so +account include system + +# session +session include system + +# password +password include system + +EOD; + + unset($fd); + $fd = fopen("{$g['varetc_path']}/pam.d/login", "w"); + + if (!$fd) { + printf("Error: cannot open /pam.d/login in system_pam_configure().\n"); + return 1; + } + + fwrite($fd, $login); + fclose($fd); + + unset($fd); + + /* Create the nsswitch.conf file*/ + if (isset($config['ad']['enable'])) { + $nsswitch = <<<EOD +group: files winbind +group_compat: nis +hosts: files dns wins +networks: files +passwd: files winbind +passwd_compat: nis +shells: files + +EOD; + } else { + $nsswitch = <<<EOD +group: compat +group_compat: nis +hosts: files dns +networks: files +passwd: compat +passwd_compat: nis +shells: files + +EOD; + } // end if + + $fd = fopen("{$g['varetc_path']}/nsswitch.conf", "w"); + + if (!$fd) { + printf("Error: cannot open /var/etc/nsswitch.conf in system_pam_configure().\n"); + return 1; + } + + fwrite($fd, $nsswitch); + fclose($fd); + + unset($fd); + + return 0; +} + +function system_tuning() { + /* fine tune kernel value */ + global $config, $g; + + if (isset($config['system']['tune'])) { + if ($g['booting']) { echo 'Tuning the system... '; } + + mwexec('/sbin/sysctl net.inet.tcp.delayed_ack=0'); + mwexec('/sbin/sysctl net.inet.tcp.sendspace=65536'); + mwexec('/sbin/sysctl net.inet.tcp.recvspace=65536'); + mwexec('/sbin/sysctl net.inet.udp.recvspace=65536'); + mwexec('/sbin/sysctl net.inet.udp.maxdgram=57344'); + mwexec('/sbin/sysctl net.local.stream.recvspace=65535'); + mwexec('/sbin/sysctl net.local.stream.sendspace=65535'); + mwexec('/sbin/sysctl kern.ipc.maxsockbuf=2097152'); + mwexec('/sbin/sysctl kern.ipc.somaxconn=8192'); + /* This variable can be set on the boot conf file only: */ + /* mwexec('/sbin/sysctl kern.ipc.maxsockets=16424'); */ + mwexec('/sbin/sysctl kern.ipc.nmbclusters=60000'); + mwexec('/sbin/sysctl kern.maxfiles=65536'); + mwexec('/sbin/sysctl kern.maxfilesperproc=32768'); + mwexec('/sbin/sysctl net.inet.tcp.inflight.enable=0'); + + if ($g['booting']) { echo "done\n"; } + return 0; + } else { + /* Set the default value (if previously changed) if not booting mode */ + if (!$g['booting']) { + mwexec('/sbin/sysctl net.inet.tcp.delayed_ack=1'); + mwexec('/sbin/sysctl net.inet.tcp.sendspace=32768'); + mwexec('/sbin/sysctl net.inet.tcp.recvspace=65536'); + mwexec('/sbin/sysctl net.inet.udp.recvspace=42080'); + mwexec('/sbin/sysctl net.inet.udp.maxdgram=9216'); + mwexec('/sbin/sysctl net.local.stream.recvspace=8192'); + mwexec('/sbin/sysctl net.local.stream.sendspace=8192'); + mwexec('/sbin/sysctl kern.ipc.maxsockbuf=262144'); + mwexec('/sbin/sysctl kern.ipc.somaxconn=128'); + /* mwexec('/sbin/sysctl kern.ipc.maxsockets=16424'); */ + mwexec('/sbin/sysctl kern.ipc.nmbclusters=3072'); + mwexec('/sbin/sysctl kern.maxfiles=1064'); + mwexec('/sbin/sysctl kern.maxfilesperproc=957'); + } // end if + + return 0; + } // end if +} + +/* TODO: Probably a function that is not needed */ +function system_install_mount_cd($cdrom) { + /* Part of install process: Mount the CDROM */ + global $config, $g; + + /* Creating tempo directory for cdrom*/ + echo "Creating Mount point for the CDROM:\n"; + if (mwexec("/bin/mkdir /mnt/cdrom_fr_0507")) { return 1; } + + /* Mounting the CDROM */ + echo "Mount CDROM:\n"; + if (mwexec("/sbin/mount_cd9660 /dev/$cdrom /mnt/cdrom_fr_0507")) { return 1; } + + return 0; +} + +/* TODO: Probably a function that is not needed */ +function system_install_init_fulldisk($harddrive) { + /* Part of install process: Initialize the destination disk with one partition */ + global $config, $g; + + echo "Erasing partitions:\n"; + if (mwexec("/bin/dd if=/dev/zero of=/dev/$harddrive bs=1k count=20")) { return 1; } + + echo "Creating the primary partition and install simple MBR:\n"; + if (mwexec("/sbin/fdisk -BI -b /boot/mbr $harddrive")) { return 1; } + + /* Must wait that the /dev is upatded with the new information */ + /* There should be a more intelligent code here than this stupid timer... */ + echo "Waiting for system update.."; + $devtotest="/dev/$harddrive". "s1"; + $i=0; + + while (!file_exists($devtotest)) { + sleep(1); + echo "."; + $i++; + + if ($i==20) { return 1; } + } + echo "\n"; + + echo "Erasing primary partition:\n"; + if (mwexec("/bin/dd if=/dev/zero of=/dev/" . escapeshellarg($harddrive) . "s1 bs=32k count=16")) { + return 1; + } + + echo "Creating FreeBSD partition:\n"; + if (mwexec("/sbin/bsdlabel -B -w -b /boot/boot " . escapeshellarg($harddrive) ."s1 auto")) { + return 1; + } + + echo "Setting BSDlabel:\n"; + + disks_bsdlabel($harddrive,"s1","4.2BSD"); + + echo "Creating UFS filesystem:\n"; + if (mwexec("/sbin/newfs -U /dev/" . escapeshellarg($harddrive) . "s1")) { return 1; } + + return 0; +} + +/* TODO: Probably a function that is not needed */ +function system_install_init_halfdisk($harddrive) { + /* Part of install process: Initialize the destination disk with 2 partitions */ + global $config, $g; + + /* Create the partitions */ + fdisk_hd_install($harddrive); + + if (mwexec("(/bin/echo y; /bin/echo y) | /sbin/fdisk -B -b /boot/mbr $harddrive")) { return 0; } + + /* Must wait that the /dev is upatded with the new information */ + echo "Waiting for system update.."; + + $devtotest="/dev/$harddrive". "s2"; + $i=0; + while (!file_exists($devtotest)) { + sleep(1); + echo "."; + $i++; + + if ($i==20) { return 1; } + } + echo "\n"; + + echo "Creating BSD Label:\n"; + if (mwexec("/sbin/bsdlabel -B -w -b /boot/boot " . escapeshellarg($harddrive) ."s1 auto")) { + return 1; + } + if (mwexec("/sbin/bsdlabel -w " . escapeshellarg($harddrive) ."s2 auto")) { + return 1; + } + + echo "Modify BSD Label information:\n"; + + disks_bsdlabel($harddrive,"s1","4.2BSD"); + disks_bsdlabel($harddrive,"s2","4.2BSD"); + + echo "Creating filesystem:\n"; + if (mwexec("/sbin/newfs -U /dev/" . escapeshellarg($harddrive) . "s1")) { + return 1; + } + if (mwexec("/sbin/newfs -U /dev/" . escapeshellarg($harddrive) . "s2")) { + return 1; + } + + return 0; +} + +/* TODO: Probably a function that is not needed */ +function system_install_mount_destdisk($harddrive) { + /* Part of install process: Mount the destination disk */ + global $config, $g; + + echo "Creation tempory mouting point:\n"; + if (mwexec("/bin/mkdir /mnt/install_fr_0507")) { return 1; } + + echo "Mount destination disk:\n"; + if (mwexec("/sbin/mount /dev/" . escapeshellarg($harddrive) . "s1 /mnt/install_fr_0507")) { + return 1; + } + + return 0; +} + +/* TODO: Probably a function that is not needed */ +function system_install_unmount() { + /* Part of install process: Unmounting the disk */ + global $config, $g; + + /* Unmounting disk */ + if (mwexec("/sbin/umount /mnt/install_fr_0507")) { return 1; } + if (mwexec("/sbin/umount /mnt/cdrom_fr_0507")) { return 1; } + + /* using 'rm -rf' for deleting the temp directory is too dangerous here... */ + /* + if (mwexec("/bin/rm -rf /mnt/cdrom_fr_0507")) { return 1; } + if (mwexec("/bin/rm -rf /mnt/install_fr_0507")) { return 1; } + */ + + /* Test: replace with PHP function rmdir */ + @rmdir ("/mnt/cdrom_fr_0507"); + @rmdir ("/mnt/install_fr_0507"); + + return 0; +} + +/* TODO: Probably a function that is not needed */ +function system_install_installation($harddrive) { + /* Part of install process: dd image file on the destination disk */ + global $config, $g; + + echo "Installation:\n"; + if (mwexec("/usr/bin/gunzip -S \"\" -c /mnt/cdrom_fr_0507/FreeNAS-generic-pc.gz | dd of=/dev/" . escapeshellarg($harddrive) . " bs=16k > /dev/null 2>&1")) { + return 1; + } + + return 0; +} + +?>
\ No newline at end of file diff --git a/config/freenas/pkg/freenas_utils.inc b/config/freenas/pkg/freenas_utils.inc new file mode 100644 index 00000000..6e5d8872 --- /dev/null +++ b/config/freenas/pkg/freenas_utils.inc @@ -0,0 +1,1049 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + freenas_utils.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. + */ +/* ========================================================================== */ + +/* returns true if $desc is a valid description (alphanum and space, _ , - , .)*/ +function is_validdesc($desc) { + if (!is_string($desc)) { return false; } + + if (preg_match("/^[A-Za-z0-9]([A-Za-z0-9_\-\.\s]*[A-Za-z0-9])*$/", $desc)) { + return true; + } else { + return false; + } +} + +/* returns true if $login is a valid login name (alphanum,dot, _ , -)*/ +function is_validlogin($login) { + if (!is_string($login)) { return false; } + + if (preg_match("/^[A-Za-z0-9]([A-Za-z0-9_\-\.\s]*[A-Za-z0-9])*$/", $login)) { + return true; + } else { + return false; + } +} + +/* returns true if $password is a valid password (not used of special : character)*/ +function is_validpassword($password) { + if (!is_string($password)) { return false; } + + if (strstr($password, ':')) { + return false; + } else { + return true; + } +} + +/* returns true if $login is a valid share name (alphanum,dot, _ , -)*/ +function is_validsharename($sharename) { + if (!is_string($sharename)) { return false; } + + if (preg_match("/^[A-Za-z0-9]([A-Za-z0-9_\-\.\s]*[A-Za-z0-9])*$/", $sharename)){ + return true; + } else { + return false; + } +} + +/* Returns true if $workgroup is a valid workgroup name */ +/* A workgroup name can contain up to 15 characters, including letters, numbers, */ +/* and the following characters: ! @ # $ % ^ & ( ) _ - ; : ' " , . */ +/* It cannot contain any spaces, and must begin with a letter or number. */ +function is_workgroup($workgroup) { + if (!is_string($workgroup)) { return false; } + + if (preg_match("/^[\w\d]+[\w\d\!\@\#\$\%\^\&\(\)\_\-\;\:\'\"\,\.]*$/", $workgroup)) { + return true; + } else { + return false; + } +} + +function get_mounts_list() +{ + // Return list of mounted disk + //example: Array + // [0] => Array + // ( + // [mp] => /mnt/ad0s1 + // [mdisk] => ad0s1 + // ) + global $g; + + exec("/sbin/mount",$rawdata); + + $mountlist = array(); + $i=0; + + foreach ($rawdata as $line) { + $aline = explode(" ", $line); + + if ((chop($aline[0]) == "/dev/md0") || (chop($aline[0]) == "devfs") || (chop($aline[0]) == "/dev/fd0")) { + continue; + } + + $mountlist[$i]['fullname'] = chop($aline[0]); + $mountlist[$i]['mp'] = chop($aline[2]); + + // Get the complete name /dev/devicename + $complete = explode("/",chop($aline[0])); + $devname = $complete[2]; + + // Test if it's a gvinum or gmirror device + if ((strcmp($devname,"gvinum") == 0) || (strcmp($devname,"mirror") == 0)) { + $devname = $complete[3]; + } + + $mountlist[$i]['mdisk']=$devname; + $i++; + } // end foreach + + return $mountlist; +} + +function get_mount_use() { + // Return list of mounted use + // example: Array + // [mount_point_name] => Array + // ( + // [capacity] => 48% + // [used] => 2.4G + // [avail] => 2.6G + // [size] => 5.4G + // ) + global $freenas_config, $g; + + exec("/bin/df -h",$rawdata); + + $result = array(); + + foreach ($rawdata as $line) { + /* separe the line by space*/ + $aline = preg_split("/[\s,]+/", $line); + $tmp = explode("/",chop($aline[5])); + $mounted_on = $tmp[2]; + $capacity = chop($aline[4]); + $avail = chop($aline[3]); + $used = chop($aline[2]); + $size = chop($aline[1]); + + if (is_array($freenas_config['mounts']['mount'])) { + foreach ($freenas_config['mounts']['mount'] as $mountcfg) { + if (strcmp($mounted_on,$mountcfg['sharename']) == 0) { + $result[$mounted_on] = array(); + $result[$mounted_on]['capacity'] = $capacity; + $result[$mounted_on]['avail'] = $avail; + $result[$mounted_on]['used'] = $used; + $result[$mounted_on]['size'] = $size; + } + } // end foreach + } else { + return 0; + } // end if + } // end foreach + + //print_r($result); + + return $result; +} + +function get_sraid_disks_list() { + /* Return list of ALL software volume: gvinum, gmirror */ + $disklist = array_merge((array)get_gvinum_disks_list(),(array)get_gmirror_disks_list(),(array)get_gconcat_disks_list(),(array)get_gstripe_disks_list(),(array)get_graid5_disks_list()); + return $disklist; +} + +function get_gvinum_disks_list() { + /* Get information about gvinum volume */ + global $g; + + /* Return list of Software RAID disk */ + //[volumename] => Array + // ( + // [type] => Software RAID - gvinum + // [desc] => UP + // [size] => 6149 MB + // ) + + /* on envoie la commande d'affichage de la liste des volumes*/ + exec("/sbin/gvinum list",$rawdata); + + foreach ($rawdata as $line) { + /* Split the line using the space as separator */ + $aline = preg_split("/\s+/", $line); + + /* Get the line that begin with the letter 'V' */ + if ($aline[0] != "V") { continue ; } + + $diskname = chop($aline[1]); + $disklist[$diskname] = array(); + + $disklist[$diskname]['name'] = $diskname; + $disklist[$diskname]['fullname'] = "/dev/gvinum/" . $diskname; + $disklist[$diskname]['type'] = "Software RAID - gvinum"; + $disklist[$diskname]['size'] = "$aline[7] $aline[8]" ; + $disklist[$diskname]['desc'] = $aline[3]; + } // end foreach + + return $disklist; +} + +function get_gmirror_disks_list() { + /* Get information about gmirror volume */ + global $g; + + //[volumename] => Array + // ( + // [type] => Software RAID - gmirror + // [desc] => COMPLETE + // [size] => 6149M + // ) + + /* Display all configured gmirror volume */ + exec("/sbin/gmirror list", $rawdata); + + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + foreach ($rawdata as $line) { + /* Use space for break the line */ + $aline = preg_split("/\s+/", $line); + + // First Step: Getting the array name + // look for this output: + // Geom name: pouet + if ( (strcmp($aline[0],"Geom") == 0) && (strcmp($aline[1],"name:") == 0) ) { + $diskname = $aline[2]; + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/mirror/" . $diskname; + $foundname = 1 ; + continue ; + } + + // Second Step: Getting the array status + // look for this output: + // State: COMPLETE + if ( (strcmp($aline[0],"State:") == 0) && $foundname) { + $desc = $aline[1]; + $disklist[$diskname]['desc'] = $desc; + $founddesc=1; + continue ; + } + + // Third Step: Getting the array Size + // look for this output: + // Name: mirror/pouet + // Mediasize: 107373568 (102M) + if (preg_match("/Name: mirror\/(.*)$/", $line, $matches)) { + if ($matches[1]=$diskname) { + $goodname=1; + continue ; + } + } + + if (($aline[0] = "Mediasize:") && $goodname) { + // extract the size between the ( ) + preg_match("/.*\\(([^\)]*)\).*/",$aline[3],$match); + $disklist[$diskname]['size'] = $match[1]; + $disklist[$diskname]['type'] = "Software RAID - gmirror"; + + // init the check variable for the next RAID volume + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + continue ; + + } + } // end foreach + + return $disklist; +} + +function get_gconcat_disks_list() { + /* Get information about gconcat volume */ + global $g; + + //[volumename] => Array + // ( + // [type] => Software RAID - gconcat + // [desc] => COMPLETE + // [size] => 6149M + // [name] => concat1 + // [fullname] => /dev/concat/concat1 + // ) + + /* Display all configured gconcat volume*/ + exec("/sbin/gconcat list",$rawdata); + + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + foreach ($rawdata as $line) { + /* Use space for break the line */ + $aline = preg_split("/\s+/", $line); + + // First Step: Getting the array name + // look for this output: + // Geom name: pouet + if ( (strcmp($aline[0],"Geom") == 0) && (strcmp($aline[1],"name:") == 0) ) { + $diskname = $aline[2]; + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/concat/" . $diskname; + $foundname = 1 ; + continue ; + } + + // Second Step: Getting the array status + // look for this output: + // State: UP + if ( (strcmp($aline[0],"State:") == 0) && $foundname) { + + $desc = $aline[1]; + $disklist[$diskname]['desc'] = $desc; + $founddesc=1; + continue ; + } + + // Third Step: Getting the array Size + // look for this output: + // Name: concat/pouet + // Mediasize: 107373568 (102M) + if (preg_match("/Name: concat\/(.*)$/", $line, $matches)) { + if ($matches[1]=$diskname) { + $goodname=1; + continue ; + } + + } + + if (($aline[0] = "Mediasize:") && $goodname) { + // extract the size between the ( ) + preg_match("/.*\\(([^\)]*)\).*/",$aline[3],$match); + $disklist[$diskname]['size'] = $match[1]; + $disklist[$diskname]['type'] = "Software RAID - gconcat"; + + // init the check variable for the next RAID volume + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + continue ; + } + } + + return $disklist; +} + +function get_gstripe_disks_list() { + /* Get information about gstripe volume */ + global $g; + + //[volumename] => Array + // ( + // [type] => Software RAID - gstripe + // [desc] => COMPLETE + // [size] => 6149M + // [name] => raid0 + // [fullname] => /dev/stripe/raid0 + // ) + + /* Display all configured gstripe volume*/ + exec("/sbin/gstripe list",$rawdata); + + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + foreach ($rawdata as $line) { + /* Use space for break the line */ + $aline = preg_split("/\s+/", $line); + + // First Step: Getting the array name + // look for this output: + // Geom name: pouet + if ( (strcmp($aline[0],"Geom") == 0) && (strcmp($aline[1],"name:") == 0) ) { + $diskname = $aline[2]; + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/stripe/" . $diskname; + $foundname = 1 ; + continue ; + } + + // Second Step: Getting the array status + // look for this output: + // State: UP + if ( (strcmp($aline[0],"State:") == 0) && $foundname) { + $desc = $aline[1]; + $disklist[$diskname]['desc'] = $desc; + $founddesc=1; + continue ; + } + + // Third Step: Getting the array Size + // look for this output: + // Name: stripe/pouet + // Mediasize: 107373568 (102M) + if (preg_match("/Name: stripe\/(.*)$/", $line, $matches)) { + if ($matches[1]=$diskname) { + $goodname=1; + continue ; + } + + } + + if (($aline[0] = "Mediasize:") && $goodname) { + // extract the size between the ( ) + preg_match("/.*\\(([^\)]*)\).*/",$aline[3],$match); + $disklist[$diskname]['size'] = $match[1]; + $disklist[$diskname]['type'] = "Software RAID - gstripe"; + + // init the check variable for the next RAID volume + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + continue ; + + } + } + + return $disklist; +} + +function get_graid5_disks_list() { + /* Get information about graid5 volume */ + global $g; + + //[volumename] => Array + // ( + // [type] => Software RAID - graid5 + // [desc] => COMPLETE + // [size] => 6149M + // [name] => BIG1 + // [fullname] => /dev/raid5/BIG1 + // ) + + /* Display all configured graid5 volume*/ + exec("/sbin/graid5 list",$rawdata); + + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + foreach ($rawdata as $line) { + /* Use space for break the line */ + $aline = preg_split("/\s+/", $line); + + // First Step: Getting the array name + // look for this output: + // Geom name: pouet + if ( (strcmp($aline[0],"Geom") == 0) && (strcmp($aline[1],"name:") == 0) ) { + $diskname = $aline[2]; + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/raid5/" . $diskname; + $foundname = 1 ; + continue ; + } + + // Second Step: Getting the array status + // look for this output: + // State: COMPLETE + if ( (strcmp($aline[0],"State:") == 0) && $foundname) { + $desc = $aline[1]; + $disklist[$diskname]['desc'] = $desc; + $founddesc=1; + continue ; + } + + // Third Step: Getting the array Size + // look for this output: + // Name: raid5/pouet + // Mediasize: 107373568 (102M) + if (preg_match("/Name: raid5\/(.*)$/", $line, $matches)) { + if ($matches[1]=$diskname) { + $goodname=1; + continue ; + } + } + + if (($aline[0] = "Mediasize:") && $goodname) { + // extract the size between the ( ) + preg_match("/.*\\(([^\)]*)\).*/",$aline[3],$match); + $disklist[$diskname]['size'] = $match[1]; + $disklist[$diskname]['type'] = "Software RAID - graid5"; + + // init the check variable for the next RAID volume + $foundname = 0 ; + $founddesc = 0 ; + $goodname = 0 ; + + continue ; + } + } + + return $disklist; +} + +function get_ata_disks_list() { + /* Return list of ATA disk */ + + //[ad0] => Array + // ( + // [type] => IDE + // [desc] => QUANTUM FIREBALL EX6.4A/A0A.0D00 + // [size] => 6149MB + // ) + + global $g; + + /* Recupere le dmesg */ + exec("/sbin/dmesg",$rawdmesg); + + $disklist = array(); + + /******* Getting IDE disk informations *******/ + exec("/sbin/atacontrol list",$rawdata); + + foreach ($rawdata as $line) { + /* Separe la ligne par les espace */ + $aline = preg_split("/\s+/", $line); + + /* Si ATA alors NEXT */ + if ($aline[0] == "ATA") { continue ; } + + $diskname = chop($aline[2]); + + /* Exlude CDROM (acdX) and Empty (no) */ + if (!preg_match("/^(acd)/", $diskname ) & $diskname != "no") { + $disklist[$diskname] = array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/" . $diskname; + + $disklist[$diskname]['type'] = "IDE"; + + /* Match the description witch is include between < and > */ + preg_match("/.*\<([^>]*)>.*/",$line,$match); + + $disklist[$diskname]['desc'] = $match[1]; + + /* Looking for the disk size */ + foreach ($rawdmesg as $dmesgline) { + /* Take only the first dmesg line */ + if (!$disklist[$diskname]['size']) { + /* Separe la ligne par les espace */ + $dmesgtab = explode(" ", $dmesgline); + $dmesgtab[0] = rtrim($dmesgtab[0],":"); + /* When there is a wrong DMA cable, the first line is: + * ad0: DMA limited to UDMA33, controller found non-ATA66 cable + */ + if ($dmesgtab[0]!="" && (strcasecmp($dmesgtab[0],$diskname) == 0) && + strcmp($dmesgtab[1],"DMA") !=0) { + $disklist[$diskname]['size'] = $dmesgtab[1]; + } + } // end if + } // end foreach + } // end if + } // end foreach + + return $disklist; +} + +function get_scsi_disks_list() { + /* Recupere la liste des disques SCSI */ + + //[ad0] => Array + // ( + // [type] => IDE + // [desc] => QUANTUM FIREBALL EX6.4A/A0A.0D00 + // [size] => 6149MB + // ) + + global $g; + + /* Recupere le dmesg */ + exec("/sbin/dmesg",$rawdmesg); + + /* on envoie la commande d'affichage de la liste des disques*/ + exec("/sbin/camcontrol devlist",$rawdata); + + foreach ($rawdata as $line) { + /* Get information include between parenthese: (pass0,da0) or (da0,pass0)*/ + preg_match("/.*\(([^>]*)\).*/",$line,$match); + + /* Sépare le resultat par la virgule */ + $temp = preg_split("/,/", $match[1]); + + // Check if diskname is the first (da0,pass0) or the second (pass0,da0) arguement + $diskname = $temp[1]; + + if ($diskname[0] == "p") { $diskname = $temp[0]; } + + /* On exlus les lecteurs cd */ + if (!preg_match("/^(cd)/", $diskname )) { + $disklist[$diskname] = array(); + $disklist[$diskname]['name'] = $diskname; + $disklist[$diskname]['fullname'] = "/dev/" . $diskname; + $disklist[$diskname]['type'] = "SCSI"; + /* Recupère la description: ce qu'il y a entre < et > */ + + preg_match("/.*\<([^>]*)>.*/",$line,$match); + + $disklist[$diskname]['desc'] = $match[1]; + + /* Looking for the disk size */ + foreach ($rawdmesg as $dmesgline) { + /* Separe la ligne par les espace */ + $dmesgtab = explode(" ", $dmesgline); + $dmesgtab[0] = rtrim($dmesgtab[0],":"); + if ($dmesgtab[0]!="" &&(strcasecmp($dmesgtab[0],$diskname) == 0)) { + $disklist[$diskname]['size'] = $dmesgtab[1]; + } + } // end foreach + } // end if + } // end foreach + + return $disklist; +} + +function get_hraid_disks_list() { + /* Recupere la liste des disques RAID */ + $kerneldisks = explode(" ", trim(preg_replace("/kern.disks: /", "", exec("/sbin/sysctl kern.disks")))); + + /* Recupere la liste des disques ATA et SCSI */ + $diskdetected = array_merge((array)get_ata_disks_list(),(array)get_scsi_disks_list()); + + /* Recupere le dmesg */ + exec("/sbin/dmesg",$rawdmesg); + + foreach ($kerneldisks as $diskname) { + $allready=1; + + // Check of this entry is IDE or SCSI (allready detected) + foreach ($diskdetected as $diskfoundk => $diskfoundv) { + if (strcasecmp($diskfoundk,$diskname) == 0) { + $allready = 0; + } + } + + if ($allready) { + /* If not an IDE and SCSI disk */ + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/" . $diskname; + + $disklist[$diskname]['type'] = "RAID"; + + /* Looking for the disk size in the dmesg */ + foreach ($rawdmesg as $dmesgline) { + /* Separe la ligne par les espace */ + $dmesgtab = explode(" ", $dmesgline); + $dmesgtab[0] = rtrim($dmesgtab[0],":"); + // si la ligne commence par le nom du disque: attention il y a 2 lignes + if ($dmesgtab[0]!="" &&(strcasecmp($dmesgtab[0],$diskname) == 0)) { + // the first line as this example "aacd0: <RAID 5> on aac0" + if (strcasecmp(substr($dmesgtab[1], 0, 1),"<") == 0) { + /* Match the description witch is include between < and > */ + preg_match("/.*\<([^>]*)>.*/",$dmesgline,$match); + $disklist[$diskname]['desc'] = $match[1]; + } else{ + // si c'est la deuxieme ligne, elle ressemble a "aacd0: 138850MB (284365824 sectors)" + $disklist[$diskname]['size'] = $dmesgtab[1]; + } // end if + } // end if + } // end foreach + } // end if + } // end foreach + + return $disklist; +} + +function get_physical_disks_list() { + /* Return list of ALL disk: physical, hardware RAID and Software RAID disk */ + $disklist = array_merge((array)get_ata_disks_list(),(array)get_scsi_disks_list(),(array)get_hraid_disks_list()); + return $disklist; +} + +function get_all_disks_list() { + /* Return list of ALL disk: physical, hardware RAID and Software RAID disk */ + $disklist = array_merge((array)get_ata_disks_list(),(array)get_scsi_disks_list(),(array)get_hraid_disks_list(), (array)get_sraid_disks_list()); + return $disklist; +} + +function get_disks_size($diskname) { + /* Return size of the disk */ + $disklist=get_physical_disks_list(); + $disksize=0; + + foreach ($disklist as $diskk => $diskv) { + if (strcmp($diskk,$diskname)==0) { + $disksize=$diskv['size']; + } + } + + return $disksize; +} + +function get_cdrom_list() { + /* Return list of IDE AND SCSI CDROM */ + // exemple: Array + // [acd0] => Array + // ( + // [type] => IDE + // [desc] => TDK CDRW241040B/57S2 + // ) + + global $g; + + /* Recupere la liste des disques IDE */ + exec("/sbin/atacontrol list",$rawdata); + + /* Recupere le dmesg */ + exec("/sbin/dmesg",$rawdmesg); + + $disklist = array(); + + /* Variable $i utilisé pour l'index du tableau */ + $i=0; + foreach ($rawdata as $line) { + /* Separe la ligne par les espace */ + $aline = preg_split("/\s+/", $line); + + /* Si ATA alors NEXT */ + if ($aline[0] == "ATA") { continue ; } + + $diskname = chop($aline[2]); + + /* Exlude disk (adX) and Empty (no) */ + if (!preg_match("/^(ad)/", $diskname ) & $diskname != "no") { + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/" . $diskname; + + $disklist[$diskname]['type'] = "IDE"; + + /* Match the description witch is include between < and > */ + preg_match("/.*\<([^>]*)>.*/",$line,$match); + + $disklist[$diskname]['desc'] = $match[1]; + + $i++; + } // end if + } // end foreach + + /* Get the SCSI disk list */ + + /* Cleaning used variable and initialize array */ + unset($rawdata); + unset($dmesgtab); + reset($rawdmesg); + + /* Get the result of the command camcontrol*/ + exec("/sbin/camcontrol devlist",$rawdata); + + foreach ($rawdata as $line) { + /* Get information include between parenthese: (pass0,da0) or (da0,pass0)*/ + preg_match("/.*\(([^>]*)\).*/",$line,$match); + + /* Sépare le resultat par la virgule */ + $temp = preg_split("/,/", $match[1]); + + // Check if diskname is the first (da0,pass0) or the second (pass0,da0) arguement + $diskname = $temp[1]; + if ($diskname[0] == "p") { $diskname = $temp[0]; } + + /* On exlus les lecteurs disque dur da */ + if (!preg_match("/^(da)/", $diskname )) { + $disklist[$diskname]=array(); + $disklist[$diskname]['name']=$diskname; + $disklist[$diskname]['fullname']= "/dev/" . $diskname; + $disklist[$diskname]['type'] = "SCSI"; + + /* Recupère la description: ce qu'il y a entre < et > */ + preg_match("/.*\<([^>]*)>.*/",$line,$match); + + $disklist[$diskname]['desc'] = $match[1]; + + $i++; + } // end if + } // end foreach + + return $disklist; +} + +/* Get list of disks from given type of filesystem. */ +function get_fstype_disks_list($fstype) { + global $freenas_config; + + $result = array(); + + /* Scan all physical disk */ + if (is_array($freenas_config['disks']['disk'])) { + foreach ($freenas_config['disks']['disk'] as $disk) { + if (strcmp($disk['fstype'],$fstype) == 0) { + $result[] = $disk; + } + } // end foreach + } // end if + + /* Scan all gmirror volume */ + if (is_array($freenas_config['gmirror']['vdisk'])) { + foreach ($freenas_config['gmirror']['vdisk'] as $disk) { + if (strcmp($disk['fstype'],$fstype) == 0) { + $result[] = $disk; + } + } // end foreach + } // end if + + /* Scan all gconcat volume */ + if (is_array($freenas_config['gconcat']['vdisk'])) { + foreach ($freenas_config['gconcat']['vdisk'] as $disk) { + if (strcmp($disk['fstype'],$fstype) == 0) { + $result[] = $disk; + } + } // end foreach + } // end if + + /* Scan all gstripe volume */ + if (is_array($freenas_config['gstripe']['vdisk'])) { + foreach ($freenas_config['gstripe']['vdisk'] as $disk) { + if (strcmp($disk['fstype'],$fstype) == 0) { + $result[] = $disk; + } + } // end foreach + } // end if + + /* Scan all gvinum volume */ + if (is_array($freenas_config['gvinum']['vdisk'])) { + foreach ($freenas_config['gvinum']['vdisk'] as $disk) { + if (strcmp($disk['fstype'],$fstype) == 0) { + $result[] = $disk; + } + } // end foreach + } // end if + + /* Scan all graid5 volume */ + if (is_array($freenas_config['graid5']['vdisk'])) { + foreach ($freenas_config['graid5']['vdisk'] as $disk) { + if (strcmp($disk['fstype'],$fstype) == 0) { + $result[] = $disk; + } + } // end foreach + } // end if + + return $result; +} + +/* Get list of supported filesystem types */ +function get_fstype_list() { + $fstlist = array( + ""=>"Unformated", + "ufs"=>"UFS with Soft Updates (use 8% space disk)", + "ufs_no_su"=>"UFS", + "ufsgpt"=>"UFS (EFI/GPT) with Soft Updates (use 8% space disk)", + "ufsgpt_no_su"=>"UFS (EFI/GPT)", + "msdos"=>"FAT32", + "ntfs"=>"NTFS", + "softraid"=>"Software RAID"); +/* + "gmirror"=>"Software RAID: gmirror", + "gconcat"=>"Software RAID: gconcat", + "gstripe"=>"Software RAID: gstripe", + "graid5"=>"Software RAID: graid5", + "gvinum"=>"Software RAID: gvinum"); +*/ + return $fstlist; +} + +function get_fstype_shortdesc($fstype) { + $shortdesc = ""; + + switch($fstype) { + case "": $shortdesc = "Unformated"; + break; + case "ufs": + case "ufs_no_su": + case "ufsgpt": + case "ufsgpt_no_su": $shortdesc = "UFS"; + break; + case "msdos": $shortdesc = "FAT32"; + break; + case "ntfs": $shortdesc = "NTFS"; + break; + case "gmirror": $shortdesc = "gmirror"; + break; + case "gconcat": $shortdesc = "gconcat"; + break; + case "gstripe": $shortdesc = "gstripe"; + break; + case "graid5": $shortdesc = "graid5"; + break; + case "gvinum": $shortdesc = "gvinum"; + break; + case "softraid": $shortdesc = "softraid"; + break; + } // end switch + + return $shortdesc; +} + +/* Search in a multidimensional array */ +function array_search_ex($needle, $haystack, $key) { + foreach($haystack as $haystackval => $value) { + $found = false; + + if (is_array($needle) && is_array($key)) { + foreach ($needle as $n => $needlev) { + $found = ($value[$key[$n]] == $needlev); + + if (false == $found) { break; } + } + } else { + $found = ($value[$key] == $needle); + } // end if + + if (true == $found) { return $haystackval; } + } // end foreach + + return false; +} + +/* TODO: This function is probably not needed. */ +function freenas_install($src,$dst) { + // Creating source directory + passthru("/bin/mkdir /mnt/src"); + + // Mount the source function is_cdrom must BE CREATED!!!! + + if (is_cdrom($src)) { + echo "Mount CDROM:\n"; + passthru("/sbin/mount_cd9660 /dev/$src /mnt/src"); + } else { + echo "Mount disk:\n"; + passthru("/sbin/mount -t ufs /dev/$src /mnt/src"); + } // end if + + echo "Erasing primary partitions:\n"; + passthru("/bin/dd if=/dev/zero of=/dev/$dst bs=1k count=20"); + + echo "Creation 1 booting primary parition:\n"; + passthru("/sbin/fdisk -BI -b /boot/boot0 $dst"); + + /* echo "Installing bootloader:\n"; + passthru("/usr/sbin/boot0cfg -B -b /boot/boot0 $dst"); */ + + echo "Erasing FreeBSD partition on the primary:\n"; + passthru("/bin/dd if=/dev/zero of=/dev/" . escapeshellarg($dst) . "s1 bs=32k count=16"); + + echo "Creating FreeBSD partition:\n"; + passthru("/sbin/bsdlabel -B -w -b /boot/boot " . escapeshellarg($dst) ."s1 auto"); + + echo "Modify partition information:\n"; + + /* Generation de la table des partitions dans un fichier temp */ + + passthru("/sbin/bsdlabel " . escapeshellarg($dst) ."s1 > label.tmp"); + + /* copie de ce fichier dans un tableau*/ + $tableau = file("label.tmp"); + + // Ouverture du fichier en mode ajout + $handle = fopen("label.tmp", 'a'); + + while(list(,$val) = each($tableau)) { + // Si la ligne contient le mot "unused" + + if (ereg ("unused",$val)) { + // On remplace c: par a: + $val = ereg_replace ("c:","a:", $val); + // On remplace unused par 4.2BSD + $val = ereg_replace ("unused","4.2BSD", $val); + // On ajoute cette ligne à la fin du fichier + fwrite($handle, $val); + } // end if + } // end while + + // Fermeture du fichier + fclose($handle); + + // On injecte la nouvelle table des paritions + passthru("/sbin/bsdlabel -R -B " . escapeshellarg($dst) ."s1 label.tmp"); + + echo "Creating filesystem:\n"; + passthru("/sbin/newfs /dev/" . escapeshellarg($dst) . "s1"); + + echo "Creation temp mouting point:\n"; + passthru("/bin/mkdir /mnt/src"); + + echo "Mount disk:\n"; + passthru("/sbin/mount /dev/" . escapeshellarg($dst) . "s1 /mnt/dst"); + + echo "Installation:\n"; + + passthru("/bin/cp -pr /mnt/src/boot /mnt/dst"); + passthru("/bin/cp /mnt/src/cf.gz /mnt/dst/mfsroot.gz"); + + if ($src == CDROM) { + passthru("/bin/rm -f /mnt/dst/boot/cdloader"); + } + + passthru("mkdir /mnt/dst/conf"); + passthru("/bin/cp /conf/config.xml /mnt/dst/conf/"); + + /* demontage des disques */ + passthru("/sbin/umount /mnt/dst"); + passthru("/sbin/umount /mnt/src"); + passthru("/bin/rm -rf /mnt/src"); + passthru("/bin/rm -rf /mnt/dst"); +} + +/* Force kill a process by name */ +function forcekillbyname($procname) { + return mwexec("/usr/bin/killall -9 " . escapeshellarg($procname)); +} +?>
\ No newline at end of file diff --git a/config/freenas/pkg/rc.freenas b/config/freenas/pkg/rc.freenas new file mode 100644 index 00000000..3b5c6c0c --- /dev/null +++ b/config/freenas/pkg/rc.freenas @@ -0,0 +1,102 @@ +#!/usr/local/bin/php -f +<?php +/* $Id$ */ +/* ========================================================================== */ + rc.freenas + part of pfSense (http://www.pfSense.com) + Copyright (C) 2006 Daniel S. Haischt + 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. + */ +/* ========================================================================== */ + +require_once("globals.inc"); + +/* parse the configuration and include all functions used below */ +require_once("config.inc"); +require_once("functions.inc"); +require_once("freenas_functions.inc"); + +/* Tune the system */ +system_tuning(); + +/* Generate local user base */ +system_users_create(); + +/* start iSCSI service */ +services_iscsi_configure(); + +/* start the S.M.A.R.T daemon */ +services_smart_configure(); + +/* ATA disk Idle configuration */ +disks_set_ataidle(); + +/* RAID configuration */ +disks_raid_start(); + +/* Mount the disks */ +disks_mount_all(); + +/* Generate the pam configuration file */ +system_pam_configure(); + +/* start NIS service */ +services_nis_configure(); + +/* start SAMBA service */ +services_samba_configure(); + +/* start Rsynd service */ +services_rsyncd_configure(); + +/* start FTP service */ +services_ftpd_configure(); + +/* start NFS service */ +services_nfs_configure(); + +/* configure Unison service */ +services_unison_configure(); + +/* start SSH service */ +/* services_sshd_configure(); */ + +/* start AFP service */ +services_afpd_configure(); + +/* start RSYNC client/slave mode service */ +services_rsyncclient_configure(); + +/* start RSYNC local service */ +services_rsync_local_configure(); + +/* Start cron */ +services_cron_configure(); + +/* Start mdnsresponder (Zeroconf/Bonjour) */ +services_zeroconf_configure(); + +?>
\ No newline at end of file |