From 94be140cc8597228b2b7e07fbb85027fd0993b92 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Haischt Date: Tue, 15 Aug 2006 15:06:54 +0000 Subject: initial version of a FreeNAS package --- packages/freenas/pkg/freenas.xml | 345 ++++++ packages/freenas/pkg/freenas_disks.inc | 899 ++++++++++++++++ packages/freenas/pkg/freenas_functions.inc | 38 + packages/freenas/pkg/freenas_guiconfig.inc | 104 ++ packages/freenas/pkg/freenas_services.inc | 1600 ++++++++++++++++++++++++++++ packages/freenas/pkg/freenas_utils.inc | 675 ++++++++++++ 6 files changed, 3661 insertions(+) create mode 100644 packages/freenas/pkg/freenas.xml create mode 100644 packages/freenas/pkg/freenas_disks.inc create mode 100644 packages/freenas/pkg/freenas_functions.inc create mode 100644 packages/freenas/pkg/freenas_guiconfig.inc create mode 100644 packages/freenas/pkg/freenas_services.inc create mode 100644 packages/freenas/pkg/freenas_utils.inc (limited to 'packages/freenas/pkg') diff --git a/packages/freenas/pkg/freenas.xml b/packages/freenas/pkg/freenas.xml new file mode 100644 index 00000000..ef90cf2b --- /dev/null +++ b/packages/freenas/pkg/freenas.xml @@ -0,0 +1,345 @@ + + + freenas + 1.0 + System: Disks: Management + /usr/local/pkg/freenas.inc + + + FreeNAS Disks +
System
+ freenas.xml + /disk_manage.php +
+ + FreeNAS RAID +
System
+ /disks_raid_gmirror.php +
+ + FreeNAS 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 +
+ + dspam + /usr/local/etc/rc.d/dspam.sh + + + + ['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_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_init.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_init.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_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/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_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_samba.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_disks.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/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 + + + + + sync_package_freenas(); + + + custom_php_install_command(); + + + custom_php_deinstall_command(); + +
diff --git a/packages/freenas/pkg/freenas_disks.inc b/packages/freenas/pkg/freenas_disks.inc new file mode 100644 index 00000000..4cc9f5c5 --- /dev/null +++ b/packages/freenas/pkg/freenas_disks.inc @@ -0,0 +1,899 @@ +. + 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"); + +$freenas_config =& $config['installedpackages']['freenas']['config'][0]; + +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); + + } + } + + if ($g['booting']) + echo "done\n"; + + return 0; + +} + +function disks_mount($mount) +{ + global $config, $g; + + /* mount the specified $mount partition */ + /* The $mount variable is the all config table for the mount point*/ + + /* Create one directory for each device under mnt */ + + $mountname=escapeshellcmd($mount['sharename']); + + @mkdir ("/mnt/$mountname",0777); + + /* mount the filesystems */ + + /* Must use a special dev name for software RAID volume */ + + if (strcmp($mount['partition'],"gvinum") == 0) + $devname="/dev/gvinum/{$mount['mdisk']}"; + else if (strcmp($mount['partition'],"gmirror") == 0) + $devname="/dev/mirror/{$mount['mdisk']}"; + else + $devname="/dev/{$mount['mdisk']}{$mount['partition']}"; + + /* check the fileystem only if there is a problem*/ + + 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"); + return 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"); + return 0; + } + else + { + /* Not OK, remove the directory, prevent writing on RAM */ + @rmdir ("/mnt/$mountname"); + return 1; + } + + } + break; + + case "msdosfs": + if (mwexec("/sbin/mount_msdosfs -u ftp -g ftp -m 777 {$devname} /mnt/$mountname") == 0) + return 0; + else + { + exec("/sbin/fsck_msdosfs -y {$devname}"); + if (mwexec("/sbin/mount_msdosfs -u ftp -g ftp -m 777 {$devname} /mnt/$mountname") == 0) + return 0; + else + { + /* Not OK, remove the directory, prevent writing on RAM */ + @rmdir ("/mnt/$mountname"); + return 1; + } + } + + break; + + case "ntfs": + if (mwexec("/sbin/mount_ntfs -u ftp -g ftp -m 777 {$devname} /mnt/$mountname") == 0) + return 0; + else + { + /* Not OK, remove the directory, prevent writing on RAM */ + @rmdir ("/mnt/$mountname"); + return 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"); + return 0; + } + else + { + exec("/usr/local/sbin/e2fsck -f -p -y {$devname}"); + if (mwexec("/sbin/mount_ext2fs {$devname} /mnt/$mountname") == 0) + { + /* Change this directory into 777 mode */ + mwexec("/bin/chmod 777 /mnt/$mountname"); + return 0; + } + else + { + /* Not OK, remove the directory, prevent writing on RAM */ + @rmdir ("/mnt/$mountname"); + return 1; + } + } + break; + } + +} + +function disks_umount($mount) +{ + global $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 $mountname") == 0) + { + if (@rmdir ("/mnt/$mountname")) + return 0; + else + return 1; + + } + + else + return 1; + +} + +function disks_umount_adv($mount) +{ + global $config, $g; + + /* Advanced unmout the specified mount point without using the sharename (changing it)*/ + /* The $mount variable is the all config table for the mount point*/ + + $mountpart="{$mount['partition']}"; + + if ((strcmp($mountpart,"gvinum") == 0) || (strcmp($mountpart,"gmirror") == 0)) + $complete = "{$mount['mdisk']}"; + else + $complete = "{$mount['mdisk']}{$mount['partition']}"; + + // get the mount list + $detmount = get_mounts_list(); + + foreach ($detmount as $detmountk => $detmountv) + { + + // If we found the mount point on the device + + if (strcmp($detmountv['mdisk'],$complete) == 0) + { + $mountname="{$detmountv['mp']}"; + } + + } + + if ($mountname) + { + exec("/sbin/umount $mountname"); + @rmdir ("$mountname"); + return 0; + } + else + return 1; +} + +function disks_mount_status($mount) +{ + // This option check if the mount are mounted + global $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; +} + +function disks_check_mount($disk) +{ + // This option check if the partition 1 of the disk is mounted + // Return 0 if not, 1 if yes + global $config, $g; + $detmount = get_mounts_list(); + $status=0; + + // Recreate the full system name device+s+partition number + /* mount the filesystems */ + + $complete = "{$disk}" . "s1"; + + foreach ($detmount as $detmountk => $detmountv) + { + + //echo "debug, display detmountv[mdisk]: {$detmountv['mdisk']}
"; + + if (strcmp($detmountv['mdisk'],$complete) == 0) + { + $status="1"; + return $status; + } + + } + return $status; +} + + + +function disks_status($diskname) +{ + // This option check if the configured disk is online + global $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 $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("/usr/bin/sync"); + + if (is_array($freenas_config['mounts']['mount'])) + { + foreach ($freenas_config['mounts']['mount'] as $mountent) + { + + /* Umount filesystem */ + disks_umount($mountent); + + } + } + + 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']}"); + } + + } + + return 0; +} + +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; +} + +function disks_raid_start() +{ + global $config, $g; + + /* Start software RAID */ + disks_raid_gvinum_start(); + disks_raid_gmirror_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; +} + +function disks_raid_stop() +{ + /* Stop software RAID */ + + disks_raid_gvinum_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; +} + +function disks_raid_gvinum_delete($raidname) +{ + global $freenas_config, $g; + + /* Delete a gvinum volume */ + + //echo "DEBUG: delete {$raidname}"; + + exec("/sbin/gvinum lv $raidname",$rawdata); + if (strpos($rawdata[0],"State: up") === false) { + return 0; + } + + mwexec("/sbin/gvinum rm -r $raidname"); + + foreach ($freenas_config['raid']['vdisk'] as $a_raid) { + if ($a_raid['name'] == $raidname) { + foreach ($a_raid['diskr'] as $disk) { + mwexec("/sbin/gvinum rm -r disk_{$disk}"); + } + } + } + + return 0; +} + +function disks_raid_gmirror_delete($raidname) +{ + global $freenas_config, $g; + + /* Delete a gmirror volume */ + + // 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; +} + +function fdisk_hd_install($harddrive) +{ + global $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: + $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']; + + /* mwexec("/usr/local/sbin/ataidle -A $ac -P $apm -S $time $channel $device"); */ + + $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); + + + } + + } + return 1; + } + + return 0; + +} + +?> diff --git a/packages/freenas/pkg/freenas_functions.inc b/packages/freenas/pkg/freenas_functions.inc new file mode 100644 index 00000000..02be42b5 --- /dev/null +++ b/packages/freenas/pkg/freenas_functions.inc @@ -0,0 +1,38 @@ +. + 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"); +?> \ No newline at end of file diff --git a/packages/freenas/pkg/freenas_guiconfig.inc b/packages/freenas/pkg/freenas_guiconfig.inc new file mode 100644 index 00000000..f46cf8df --- /dev/null +++ b/packages/freenas/pkg/freenas_guiconfig.inc @@ -0,0 +1,104 @@ +. + 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"; + +$freenas_config =& $config['installedpackages']['freenas']['config'][0]; + +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['raid']['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"); + +} + +/* TODO: This needs to be changed */ +function users_sort() { + global $g, $config; + + function userscmp($a, $b) { + return strcmp($a['login'], $b['login']); + } + + usort($config['access']['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['access']['group'], "groupscmp"); +} +?> \ No newline at end of file diff --git a/packages/freenas/pkg/freenas_services.inc b/packages/freenas/pkg/freenas_services.inc new file mode 100644 index 00000000..a2d8d531 --- /dev/null +++ b/packages/freenas/pkg/freenas_services.inc @@ -0,0 +1,1600 @@ +. + All rights reserved. + + Modified for FreeNAS (http://freenas.org) by Olivier Cochard + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +$freenas_config =& $config['installedpackages']['freenas']['config'][0]; + +function services_samba_configure() { + global $freenas_config, $g; + + /* kill any running samba */ + + killbyname("smbd"); + killbyname("winbindd"); + killbyname("nmbd"); + + if (isset($freenas_config['samba']['enable'])) + { + + if ($g['booting']) + echo "Starting Samba... "; + + /* generate smb.conf */ + $fd = fopen("{$g['varetc_path']}/smb.conf", "w"); + if (!$fd) { + printf("Error: cannot open smb.conf in services_samba_configure().\n"); + return 1; + } + + /* If no share configured, exit */ + if (!is_array($freenas_config['mounts']['mount'])) + return 0; + + + $sambaconf = << 124 +backend = ${datarootdir}/wzdftpd/backends/libwzdpam.so + +max_ul_speed = 0 +max_dl_speed = 0 +deny_access_files_uploaded = 1 + +tls_certificate = /usr/local/etc/wzdftpd/wzd.pem +sitefile_ginfo = /usr/local/etc/wzdftpd/file_ginfo.txt +sitefile_group = /usr/local/etc/wzdftpd/file_group.txt +sitefile_user = /usr/local/etc/wzdftpd/file_user.txt + +[pre_ip_check] +localhost = allow + +[perms] +site_addip = +O +G +site_adduser = +O +G +site_backend = +O +site_chacl = +O +site_change = +O +G +site_changegrp = +O +G +site_checkperm = +O +site_chgrp = +O +site_chmod = +O +site_chown = +O +site_chpass = * +site_chratio = +O +G +site_close = +O +site_color = !=guest * +site_delip = +O +G +site_deluser = +O +G +site_flags = -admin +site_free = * +site_ginfo = +O +G +site_give = * +site_group = +O +site_groups = +O +site_grpadd = +O +site_grpaddip = +O +site_grpchange = +O +site_grpdel = +O +site_grpdelip = +O +site_grpkill = +O +site_grpratio = +O +site_grpren = +O +site_gsinfo = +O +G +site_help = * +site_idle = * +site_invite = !=guest * +site_kick = +O +site_kill = +O +site_link = +O +site_msg = +O +site_perm = +O +site_purge = +O +G +site_readd = +O +G +site_reload = +O +site_reopen = +O +site_rules = * +site_rusage = +O +site_savecfg = +O +site_sections = +O +site_shutdown = +O +site_su = +O +site_swho = +O +site_tagline = !=guest * +site_take = +O +site_unlock = +O +site_uptime = * +site_user = +O +G +site_users = -admin +site_utime = * +site_vars = +O +site_vars_group = +O +site_vars_user = +O +site_version = +O +site_who = !=guest * +site_wipe = +O +site_vfsls = +O +site_vfsadd = +O +site_vfsdel = +O + +[modules] +${datarootdir}/wzdftpd/modules/libwzd_debug.so = deny +${datarootdir}/wzdftpd/modules/libwzd_test.so = deny +${datarootdir}/wzdftpd/modules/libwzd_sfv.so = allow +${datarootdir}/wzdftpd/modules/libwzd_tcl.so = deny +${datarootdir}/wzdftpd/modules/libwzd_perl.so = deny + +EOD; + + if (empty($config['system']['zeroconf_disable'])) { + $ftpconf .= << 0) + $cron_min = $cron_min . "," . $minutev; + else + $cron_min = $minutev; + } + } + else + $cron_min = "*"; + + + if ($freenas_config['rsyncclient']['all_hours'] == "0") { + foreach ($freenas_config['rsyncclient']['hour'] as $hourv) { + if (strlen($cron_hour) > 0) + $cron_hour = $cron_hour . "," . $hourv; + else + $cron_hour = $hourv; + } + } + else + $cron_hour = "*"; + + if ($freenas_config['rsyncclient']['all_days'] == "0") { + foreach ($freenas_config['rsyncclient']['day'] as $dayv) { + if (strlen($cron_day) > 0) + $cron_day = $cron_day . "," . $dayv; + else + $cron_day = $dayv; + } + } + else + $cron_day = "*"; + + if ($freenas_config['rsyncclient']['all_months'] == "0") { + foreach ($freenas_config['rsyncclient']['month'] as $monthv) { + if (strlen($cron_month) > 0) + $cron_month = $cron_month . "," . $monthv; + else + $cron_month = $monthv; + } + } + else + $cron_month = "*"; + + + if ($freenas_config['rsyncclient']['all_weekday'] == "0") { + foreach ($freenas_config['rsyncclient']['weekday'] as $weekdayv) { + if (strlen($cron_weekday) > 0) + $cron_weekday = $cron_weekday . "," . $weekdayv; + else + $cron_weekday = $weekdayv; + } + } + else + $cron_weekday = "*"; + + $crontabconf .= << 0) + $cron_min = $cron_min . "," . $minutev; + else + $cron_min = $minutev; + } + } + else + $cron_min = "*"; + + + if ($freenas_config['shutdown']['all_hours'] == "0") { + foreach ($freenas_config['shutdown']['hour'] as $hourv) { + if (strlen($cron_hour) > 0) + $cron_hour = $cron_hour . "," . $hourv; + else + $cron_hour = $hourv; + } + } + else + $cron_hour = "*"; + + if ($freenas_config['shutdown']['all_days'] == "0") { + foreach ($freenas_config['shutdown']['day'] as $dayv) { + if (strlen($cron_day) > 0) + $cron_day = $cron_day . "," . $dayv; + else + $cron_day = $dayv; + } + } + else + $cron_day = "*"; + + if ($freenas_config['shutdown']['all_months'] == "0") { + foreach ($freenas_config['shutdown']['month'] as $monthv) { + if (strlen($cron_month) > 0) + $cron_month = $cron_month . "," . $monthv; + else + $cron_month = $monthv; + } + } + else + $cron_month = "*"; + + + if ($freenas_config['shutdown']['all_weekday'] == "0") { + foreach ($freenas_config['shutdown']['weekday'] as $weekdayv) { + if (strlen($cron_weekday) > 0) + $cron_weekday = $cron_weekday . "," . $weekdayv; + else + $cron_weekday = $weekdayv; + } + } + else + $cron_weekday = "*"; + + $crontabconf .= << $sharev) + { + $syncscript .= << + + + + @SERVICE_DESC@ on %h + + + @TYPE@ + @PORT@ + @TXT_RECORDS@ + + + + +EOD; + + /* kill any running dbus daemon */ + sigkillbypid("{$g['varrun_path']}/dbus/dbus.pid"", "TERM"); + + /* kill any running avahi daemons */ + mwexec("/usr/local/sbin/avahi-daemon -k"); + + + if (isset($config['system']['zeroconf_disable'])) + return 0; + + if (! file_exists("/usr/local/etc/avahi/services")) + mwexec("mkdir -p /usr/local/etc/avahi/services"); + + if (isset($config['system']['webgui']['port'])) { + $webservice = str_replace("@PORT@", + "{$config['system']['webgui']['port']}", + $service_template); + $webservice = str_replace("@TYPE@", + "_http._tcp", + $webservice); + $webservice = str_replace("@SERVICE_DESC@", + "pfSense webGUI", + $webservice); + $webservice = str_replace("@TXT_RECORDS@", + "", + $webservice); + + file_put_contents("/usr/local/etc/avahi/services/http.service", $webservice); + } else { + $webservice = str_replace("@PORT@", + "80", + $service_template); + $webservice = str_replace("@TYPE@", + "_http._tcp", + $webservice); + $webservice = str_replace("@SERVICE_DESC@", + "pfSense webGUI", + $webservice); + $webservice = str_replace("@TXT_RECORDS@", + "", + $webservice); + + file_put_contents("/usr/local/etc/avahi/services/http.service", $webservice); + } + + + + if (isset($freenas_config['afp']['enable'])) { + /* NOP */ + } + + if (isset($freenas_config['rsyncd']['enable'])) { + $rsyncservice = str_replace("@PORT@", + "{$config['rsyncd']['port']}", + $service_template); + $rsyncservice = str_replace("@TYPE@", + "_rsync._tcp", + $rsyncservice); + $rsyncservice = str_replace("@SERVICE_DESC@", + "Remote Sync Daemon", + $rsyncservice); + $rsyncservice = str_replace("@TXT_RECORDS@", + "", + $rsyncservice); + + file_put_contents("/usr/local/etc/avahi/services/rsync.service", $rsyncservice); + } + + if (isset($config['sshd']['enable'])) { + $sshservice = str_replace("@PORT@", + "22", + $service_template); + $sshservice = str_replace("@TYPE@", + "_ssh._tcp", + $sshservice); + $sshservice = str_replace("@SERVICE_DESC@", + "Remote Terminal", + $sshservice); + $sshservice = str_replace("@TXT_RECORDS@", + "", + $sshservice); + + file_put_contents("/usr/local/etc/avahi/services/ssh.service", $sshservice); + } + + if (isset($freenas_config['ftp']['enable'])) { + /* NOP */ + } + + if (isset($freenas_config['samba']['enable'])) { + $cifsservice = str_replace("@PORT@", + "139", + $service_template); + $cifsservice = str_replace("@TYPE@", + "_smb._tcp", + $cifsservice); + $cifsservice = str_replace("@SERVICE_DESC@", + "Samba Server", + $cifsservice); + $cifsservice = str_replace("@TXT_RECORDS@", + "", + $cifsservice); + + file_put_contents("/usr/local/etc/avahi/services/cifs.service", $cifsservice); + } + + if (isset($freenas_config['nfs']['enable'])) { + + /* If no share configured, exit */ + if (!is_array($freenas_config['mounts']['mount'])) + break; + + $a_mount = &$freenas_config['mounts']['mount']; + + foreach ($a_mount as $mount) { + $sharename = str_replace(" ", "", $mount['sharename']); + $sharename = strtolower($sharename); + + $nfsservice = str_replace("@PORT@", + "2049", + $service_template); + $nfsservice = str_replace("@TYPE@", + "_nfs._tcp", + $nfsservice); + $nfsservice = str_replace("@SERVICE_DESC@", + "NFS Mount: {$mount['sharename']}", + $nfsservice); + $nfsservice = str_replace("@TXT_RECORDS@", + "path=/mnt/{$mount['sharename']}", + $nfsservice); + + file_put_contents("/usr/local/etc/avahi/services/{$sharename}_nfs.service", $nfsservice); + } + } + + + /* run dbus */ + mwexec("/usr/local/bin/dbus-daemon --system"); + + /* run avahi */ + mwexec("/usr/local/sbin/avahi-daemon -D"); + + if ($g['booting']) + echo "done\n"; + + return 0; +} + +function services_howl_configure() +{ + global $freenas_config, $config, $g; + + + /* kill any mDNSResponder */ + killbyname("mDNSResponder"); + + if (isset($config['system']['zeroconf_disable'])) + return 0; + + $fd = fopen("{$g['varetc_path']}/mDNSResponder.conf", "w"); + if (!$fd) + { + printf("Error: cannot open mDNSResponder.conf in services_howl_configure().\n"); + return 1; + } + + if ($config['system']['webgui']['port']) + { + $mDNSResponder = << \ No newline at end of file diff --git a/packages/freenas/pkg/freenas_utils.inc b/packages/freenas/pkg/freenas_utils.inc new file mode 100644 index 00000000..12c71a12 --- /dev/null +++ b/packages/freenas/pkg/freenas_utils.inc @@ -0,0 +1,675 @@ +. + 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. +*/ + +/* 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 $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; +} + +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]['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++; + } + + return $mountlist; +} + +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()); + 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) + { + + + /* Separe la ligne par les espace */ + $aline = preg_split("/\s+/", $line); + + /* Récupère la ligne commencant par 'V' */ + if ($aline[0] != "V") + { + continue ; + } + + $diskname = chop($aline[1]); + + $disklist[$diskname]=array(); + + $disklist[$diskname]['type'] = "Software RAID - gvinum"; + + $disklist[$diskname]['size'] = "$aline[7] $aline[8]" ; + + $disklist[$diskname]['desc'] = $aline[3]; + + } + + + 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(); + $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 ; + + } + + } + + 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]['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],":"); + if ($dmesgtab[0]!="" &&(strcasecmp($dmesgtab[0],$diskname) == 0)) + $disklist[$diskname]['size'] = $dmesgtab[1]; + } + } + + } + + } + 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]['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]; + + } + + } + } + 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]['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: 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]; + } + + } + } + } + + } + + 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[$i]['name'] = chop($aline[2]); + + + $disklist[$diskname]['type'] = "IDE"; + + /* Match the description witch is include between < and > */ + + preg_match("/.*\<([^>]*)>.*/",$line,$match); + + $disklist[$diskname]['desc'] = $match[1]; + + + $i++; + + } + + } + + /* 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]['type'] = "SCSI"; + /* Recupère la description: ce qu'il y a entre < et > */ + + preg_match("/.*\<([^>]*)>.*/",$line,$match); + + $disklist[$diskname]['desc'] = $match[1]; + + $i++; + + } + + } + + return $disklist; +} + +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"); + } + + + 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); + } + } + // 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"); + +} +?> \ No newline at end of file -- cgit v1.2.3