#!/usr/bin/perl
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see . #
# #
###############################################################################
use strict;
# enable only the following on debugging purpose
#use warnings;
#use CGI::Carp 'fatalsToBrowser';
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
require "${General::swroot}/header.pl";
my %extrahdsettings = ();
my $message = "";
my $errormessage = "";
my $size = "";
my $ok = "true";
my @tmp = ();
my @tmpline = ();
my $tmpentry = "";
my @devices = ();
my @deviceline = ();
my $deviceentry = "";
my @scans = ();
my @scanline = ();
my $scanentry = "";
my @partitions = ();
my @partitionline = ();
my $partitionentry = "";
my $devicefile = "/var/ipfire/extrahd/devices";
my $scanfile = "/var/ipfire/extrahd/scan";
my $partitionsfile = "/var/ipfire/extrahd/partitions";
system("/usr/local/bin/scanhd ide");
system("/usr/local/bin/scanhd partitions");
&Header::showhttpheaders();
### Values that have to be initialized
$extrahdsettings{'PATH'} = '';
$extrahdsettings{'FS'} = '';
$extrahdsettings{'DEVICE'} = '';
$extrahdsettings{'ACTION'} = '';
&General::readhash("${General::swroot}/extrahd/settings", \%extrahdsettings);
&Header::getcgihash(\%extrahdsettings);
&Header::openpage('ExtraHD', 1, '');
&Header::openbigbox('100%', 'left', '', $errormessage);
############################################################################################################################
############################################################################################################################
if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'})
{
open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
@devices = ;
close FILE;
foreach $deviceentry (sort @devices)
{
@deviceline = split( /\;/, $deviceentry );
if ( "$extrahdsettings{'PATH'}" eq "$deviceline[2]" ) {
$ok = "false";
$errormessage = "You can't mount $extrahdsettings{'DEVICE'} to $extrahdsettings{'PATH'}, because there is already a device mounted.";
}
if ( "$extrahdsettings{'PATH'}" eq "/" ) {
$ok = "false";
$errormessage = "You can't mount $extrahdsettings{'DEVICE'} to root /.";
}
}
if ( "$ok" eq "true" ) {
open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile";
print FILE <;
close FILE;
open( FILE, "> $devicefile" ) or die "Unable to write $devicefile";
foreach $deviceentry (sort @tmp)
{
@tmpline = split( /\;/, $deviceentry );
if ( $tmpline[2] ne $extrahdsettings{'PATH'} )
{
print FILE $deviceentry;
}
}
close FILE;
} else {
$errormessage = "Can't umount $extrahdsettings{'PATH'}. Maybe the device is in use?";
}
}
if ($errormessage) {
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
print "$errormessage\n";
print " \n";
&Header::closebox();
}
############################################################################################################################
############################################################################################################################
&Header::openbox('100%', 'center', 'ExtraHD');
open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
@devices = ;
close FILE;
print <
END
;
foreach $deviceentry (sort @devices)
{
@deviceline = split( /\;/, $deviceentry );
my $color="$Header::colourred";
if ( `/bin/mount | /bin/fgrep $deviceline[2] | /bin/fgrep /dev/$deviceline[0]` ) {
$color=$Header::colourgreen;
}
print <
/dev/$deviceline[0]
$deviceline[1]
$deviceline[2]
END
;
}
print <
END
;
&Header::closebox();
&Header::openbox('100%', 'center', 'Gefundene Laufwerke');
print <
END
;
open( FILE, "< $scanfile" ) or die "Unable to read $scanfile";
@scans = ;
close FILE;
open( FILE, "< $partitionsfile" ) or die "Unable to read $partitionsfile";
@partitions = ;
close FILE;
foreach $scanentry (sort @scans)
{
@scanline = split( /\;/, $scanentry );
print <
If your device isn't listed here, you need to install or load the driver. If you can see your device but no partitions you have to create them first.
END
;
&Header::closebox();
&Header::closebigbox();
&Header::closepage();