]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/extrahd.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2011 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
23 # enable only the following on debugging purpose
25 #use CGI::Carp 'fatalsToBrowser';
27 require '/var/ipfire/general-functions.pl' ;
28 require "${General::swroot}/lang.pl" ;
29 require "${General::swroot}/header.pl" ;
31 my %extrahdsettings = ();
33 my $errormessage = "" ;
46 my @partitionline = ();
47 my $partitionentry = "" ;
48 my $devicefile = "/var/ipfire/extrahd/devices" ;
49 my $scanfile = "/var/ipfire/extrahd/scan" ;
50 my $partitionsfile = "/var/ipfire/extrahd/partitions" ;
52 #workaround to suppress a warning when a variable is used only once
53 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourred
} );
56 & General
:: system ( "/usr/local/bin/extrahdctrl" , "scanhd" , "ide" );
57 & General
:: system ( "/usr/local/bin/extrahdctrl" , "scanhd" , "partitions" );
59 & Header
:: showhttpheaders
();
61 ### Values that have to be initialized
62 $extrahdsettings { 'PATH' } = '' ;
63 $extrahdsettings { 'FS' } = '' ;
64 $extrahdsettings { 'DEVICE' } = '' ;
65 $extrahdsettings { 'ACTION' } = '' ;
66 $extrahdsettings { 'UUID' } = '' ;
68 & General
:: readhash
( "${General::swroot}/extrahd/settings" , \
%extrahdsettings );
69 & Header
:: getcgihash
( \
%extrahdsettings );
71 & Header
:: openpage
( 'ExtraHD' , 1 , '' );
72 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
74 ############################################################################################################################
75 ############################################################################################################################
77 if ( $extrahdsettings { 'ACTION' } eq $Lang :: tr
{ 'add' })
79 open ( FILE
, "< $devicefile " ) or die "Unable to read $devicefile " ;
82 foreach $deviceentry ( sort @devices )
84 @deviceline = split ( /\;/ , $deviceentry );
85 if ( " $extrahdsettings {'PATH'}" eq " $deviceline [2]" ) {
87 $errormessage = " $Lang ::tr{'extrahd you cant mount'} $extrahdsettings {'DEVICE'} $Lang ::tr{'extrahd to'} $extrahdsettings {'PATH'} $Lang ::tr{'extrahd because there is already a device mounted'}." ;
89 if ( " $extrahdsettings {'PATH'}" eq "/" ) {
91 $errormessage = " $Lang ::tr{'extrahd you cant mount'} $extrahdsettings {'DEVICE'} $Lang ::tr{'extrahd to root'}." ;
95 if ( " $ok " eq "true" ) {
96 open ( FILE
, ">> $devicefile " ) or die "Unable to write $devicefile " ;
98 UUID= $extrahdsettings {'UUID'}; $extrahdsettings {'FS'}; $extrahdsettings {'PATH'};
101 & General
:: system ( "/usr/local/bin/extrahdctrl" , "mount" , " $extrahdsettings {'PATH'}" );
104 elsif ( $extrahdsettings { 'ACTION' } eq $Lang :: tr
{ 'delete' })
106 if ( & General
:: system ( "/usr/local/bin/extrahdctrl" , "umount" , " $extrahdsettings {'PATH'}" )) {
107 open ( FILE
, "< $devicefile " ) or die "Unable to read $devicefile " ;
110 open ( FILE
, "> $devicefile " ) or die "Unable to write $devicefile " ;
111 foreach $deviceentry ( sort @tmp )
113 @tmpline = split ( /\;/ , $deviceentry );
114 if ( $tmpline [ 2 ] ne $extrahdsettings { 'PATH' } )
116 print FILE
$deviceentry ;
121 $errormessage = " $Lang ::tr{'extrahd cant umount'} $extrahdsettings {'PATH'} $Lang ::tr{'extrahd maybe the device is in use'}?" ;
126 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
127 print "<class name='base'> $errormessage \n " ;
128 print " </class> \n " ;
132 ############################################################################################################################
133 ############################################################################################################################
135 open ( FILE
, "< $devicefile " ) or die "Unable to read $devicefile " ;
139 <table border='0' width='600' cellspacing="0">
142 foreach $deviceentry ( sort @devices )
144 @deviceline = split ( /\;/ , $deviceentry );
145 my $color = " $Header ::colourred" ;
147 # Use safe system_output to get mountpoint details.
148 my @mountpoint = & General
:: system_output
( "/bin/mountpoint" , " $deviceline [2]" );
150 if ( ! grep ( /not/ , @mountpoint )) {
151 $color = $Header :: colourgreen
;
154 <tr><td colspan="4"> </td></tr>
155 <tr><td align='left'><font color= $color ><b> $deviceline [0]</b></font></td>
156 <td align='left'> $deviceline [1]</td>
157 <td align='left'> $deviceline [2]</td>
159 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
160 <input type='hidden' name='DEVICE' value=' $deviceline [0]' />
161 <input type='hidden' name='FS' value=' $deviceline [1]' />
162 <input type='hidden' name='PATH' value=' $deviceline [2]' />
163 <input type='hidden' name='ACTION' value=' $Lang ::tr{'delete'}' />
164 <input type='image' alt=' $Lang ::tr{'delete'}' title=' $Lang ::tr{'delete'}' src='/images/delete.gif' />
173 & Header
:: openbox
( '100%' , 'center' , $Lang :: tr
{ 'extrahd detected drives' });
175 <table border='0' width='600' cellspacing="0">
178 open ( FILE
, "< $scanfile " ) or die "Unable to read $scanfile " ;
181 open ( FILE
, "< $partitionsfile " ) or die "Unable to read $partitionsfile " ;
182 @partitions = < FILE
>;
184 foreach $scanentry ( sort @scans )
186 @scanline = split ( /\;/ , $scanentry );
187 # remove wrong entries like usb controller name
188 if ( $scanline [ 1 ] ne " \n " )
191 <tr><td colspan="5"> </td></tr>
192 <tr><td align='left' colspan="2"><b>/dev/ $scanline [0]</b></td>
193 <td align='center' colspan="2"> $scanline [1]</td>
198 foreach $partitionentry ( sort @partitions )
200 @partitionline = split ( /\;/ , $partitionentry );
201 if ( " $partitionline [0]" eq " $scanline [0]" ) {
202 $size = int ( $partitionline [ 1 ] / 1024 );
204 <td align='center'> $Lang ::tr{'size'} $size MB</td>
206 <tr><td colspan="5"> </td></tr>
212 foreach $partitionentry ( sort @partitions )
214 @partitionline = split ( /\;/ , $partitionentry );
215 if (( " $partitionline [0]" =~ /^$scanline[0]/ ) && !( " $partitionline [2]" eq "" )) {
216 $size = int ( $partitionline [ 1 ] / 1024 );
218 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
219 <tr><td align="left" colspan=5><strong>UUID= $partitionline [2]</strong></td></tr>
221 <td align="list">/dev/ $partitionline [0]</td>
222 <td align="center"> $Lang ::tr{'size'} $size MB</td>
223 <td align="center"><select name="FS">
224 <option value="auto">auto</option>
225 <option value="ext3">ext3</option>
226 <option value="ext4">ext4</option>
227 <option value="reiserfs">reiserfs</option>
228 <option value="vfat">fat</option>
229 <option value="ntfs-3g">ntfs (experimental)</option>
231 <td align="center"><input type='text' name='PATH' value=/mnt/harddisk /></td>
233 <input type='hidden' name='DEVICE' value=' $partitionline [0]' />
234 <input type='hidden' name='UUID' value=' $partitionline [2]' />
235 <input type='hidden' name='ACTION' value=' $Lang ::tr{'add'}' />
236 <input type='image' alt=' $Lang ::tr{'add'}' title=' $Lang ::tr{'add'}' src='/images/add.gif' />
248 <tr><td align="center" colspan="5"> </td></tr>
249 <tr><td align="center" colspan="5"> </td></tr>
250 <tr><td align="center" colspan="5"> $Lang ::tr{'extrahd install or load driver'}</td></tr>
256 & Header
:: closebigbox
();
257 & Header
:: closepage
();