From 55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1 Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Fri, 6 Feb 2009 19:18:00 -0600 Subject: mv packages to config dir to match web layout --- config/freenas/pkg/freenas.inc | 297 +++++ config/freenas/pkg/freenas.xml | 570 +++++++++ config/freenas/pkg/freenas_config.inc | 45 + config/freenas/pkg/freenas_disks.inc | 1256 ++++++++++++++++++ config/freenas/pkg/freenas_functions.inc | 49 + config/freenas/pkg/freenas_guiconfig.inc | 288 +++++ config/freenas/pkg/freenas_services.inc | 2025 ++++++++++++++++++++++++++++++ config/freenas/pkg/freenas_system.inc | 838 +++++++++++++ config/freenas/pkg/freenas_utils.inc | 1049 ++++++++++++++++ config/freenas/pkg/rc.freenas | 102 ++ 10 files changed, 6519 insertions(+) create mode 100644 config/freenas/pkg/freenas.inc create mode 100644 config/freenas/pkg/freenas.xml create mode 100644 config/freenas/pkg/freenas_config.inc create mode 100644 config/freenas/pkg/freenas_disks.inc create mode 100644 config/freenas/pkg/freenas_functions.inc create mode 100644 config/freenas/pkg/freenas_guiconfig.inc create mode 100644 config/freenas/pkg/freenas_services.inc create mode 100644 config/freenas/pkg/freenas_system.inc create mode 100644 config/freenas/pkg/freenas_utils.inc create mode 100644 config/freenas/pkg/rc.freenas (limited to 'config/freenas/pkg') 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 @@ + + All rights reserved. + + Based on FreeNAS (http://www.freenas.org) + Copyright (C) 2005-2006 Olivier Cochard-Labbé . + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper . + 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 @@ + + + + + + + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper . + 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. + */ +/* ========================================================================== */ + ]]> + + Describe your package here + Describe your package requirements here + Currently there are no FAQ items provided. + freenas + 1.0 + System: Disks: Management + /usr/local/pkg/freenas.inc + + + Disks +
System
+ /disks_manage.php +
+ + RAID +
System
+ /disks_raid_gmirror.php +
+ + Mounts +
System
+ /disks_mount.php +
+ + FreeNAS Infos +
Diagnostics
+ /diag_disk_infos.php +
+ + FreeNAS Logs +
Diagnostics
+ /diag_fn_logs_samba.php +
+ + Disk Status +
Status
+ /status_disks.php +
+ + AFP +
Services
+ /services_afp.php +
+ + FTP +
Services
+ /services_ftp.php +
+ + NFS +
Services
+ /services_nfs.php +
+ + Rsync +
Services
+ /services_rsyncd.php +
+ + Samba +
Services
+ /services_samba.php +
+ + Unison +
Services
+ /services_unison.php +
+ + + + ['installedpackages']['freenas']['config'] + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_manage.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_manage_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_manage_init.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_manage_iscsi.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_manage_tools.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_infos.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gmirror_tools.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_infos.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gvinum_tools.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gconcat_tools.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_gstripe_tools.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_raid_graid5_tools.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_mount.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_mount_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/disks_mount_tools.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_ad_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_ataidle_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_disk_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_iscsi_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_mounts_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_part_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_raid_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_smart_infos.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_space_infos.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_daemon.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_ftp.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_rsyncd.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_samba.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_settings.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_smartd.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/diag_fn_logs_sshd.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_afp.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_ftp.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_nfs.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_nfs_export.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_nfs_export_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_rsyncd.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_rsyncd_client.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_rsyncd_local.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_samba.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_samba_share.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_samba_edit.php + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/services_unison.php + + + + /usr/local/www/ + 0755 + http://www.pfsense.com/packages/config/freenas/www/status_disks.php + + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_disks.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_config.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_functions.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_guiconfig.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_services.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_utils.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/freenas_system.inc + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/pkg/rc.freenas + + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/iscsi_initiator.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/ext2fs.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/geom_concat.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/geom_gpt.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/geom_mirror.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/geom_stripe.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/geom_vinum.ko + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/kernel.gz + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/ntfs.ko + + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/iscontrol + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/mountd + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/nfsd + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/rpcbind + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/rpc.lockd + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/freenas/bin/rpc.statd + + + + + sync_package_freenas(); + + + custom_php_install_command(); + + + custom_php_deinstall_command(); + +
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 @@ + + All rights reserved. + + Based on FreeNAS (http://www.freenas.org) + Copyright (C) 2005-2006 Olivier Cochard-Labbé . + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper . + 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 @@ + + All rights reserved. + + Based on FreeNAS (http://www.freenas.org) + Copyright (C) 2005-2006 Olivier Cochard-Labbé . + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper . + 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
"; + + foreach ($detmount as $detmountk => $detmountv) { + //echo "debug, display detmountv[mdisk]: {$detmountv['mdisk']}
"; + + 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 .= << $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= << $diskrv) { + $raidconf .= << $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<=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 .= << $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= << $diskrv) { + $raidconf .= << $diskrv) { + /* Get the disksize */ + $disksize=get_disks_size($diskrv); + /* Remove the ending 'B' in 'MB' */ + $disksize=rtrim($disksize, 'B'); + /* + $raidconf .= <<=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 .= << {$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 @@ + + All rights reserved. + + Based on FreeNAS (http://www.freenas.org) + Copyright (C) 2005-2006 Olivier Cochard-Labbé . + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper . + 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 @@ +. + All rights reserved. + + Modified for FreeNAS (http://freenas.org) by Olivier Cochard + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +$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", " +

+ Done! +

+ "); + +define("CMDOUT_PARA", " +

+ Command output (use the toggle icon to unveil detailed infos): +

+ "); + +define("CMDOUT_PARA_WOHINT", " +

+ Command output: +

+ "); + +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", " + +"); + +$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 =<<