]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/extrahd.cgi
qos: Remove advanced settings.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / extrahd.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2011 IPFire Team <info@ipfire.org> #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23 # enable only the following on debugging purpose
24 #use warnings;
25 #use CGI::Carp 'fatalsToBrowser';
26
27 require '/var/ipfire/general-functions.pl';
28 require "${General::swroot}/lang.pl";
29 require "${General::swroot}/header.pl";
30
31 my %extrahdsettings = ();
32 my $message = "";
33 my $errormessage = "";
34 my $size = "";
35 my $ok = "true";
36 my @tmp = ();
37 my @tmpline = ();
38 my $tmpentry = "";
39 my @devices = ();
40 my @deviceline = ();
41 my $deviceentry = "";
42 my @scans = ();
43 my @scanline = ();
44 my $scanentry = "";
45 my @partitions = ();
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";
51 system("/usr/local/bin/extrahdctrl scanhd ide");
52 system("/usr/local/bin/extrahdctrl scanhd partitions");
53
54 &Header::showhttpheaders();
55
56 ### Values that have to be initialized
57 $extrahdsettings{'PATH'} = '';
58 $extrahdsettings{'FS'} = '';
59 $extrahdsettings{'DEVICE'} = '';
60 $extrahdsettings{'ACTION'} = '';
61 $extrahdsettings{'UUID'} = '';
62
63 &General::readhash("${General::swroot}/extrahd/settings", \%extrahdsettings);
64 &Header::getcgihash(\%extrahdsettings);
65
66 &Header::openpage('ExtraHD', 1, '');
67 &Header::openbigbox('100%', 'left', '', $errormessage);
68
69 ############################################################################################################################
70 ############################################################################################################################
71
72 if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'})
73 {
74 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
75 @devices = <FILE>;
76 close FILE;
77 foreach $deviceentry (sort @devices)
78 {
79 @deviceline = split( /\;/, $deviceentry );
80 if ( "$extrahdsettings{'PATH'}" eq "$deviceline[2]" ) {
81 $ok = "false";
82 $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'}.";
83 }
84 if ( "$extrahdsettings{'PATH'}" eq "/" ) {
85 $ok = "false";
86 $errormessage = "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'DEVICE'} $Lang::tr{'extrahd to root'}.";
87 }
88 }
89
90 if ( "$ok" eq "true" ) {
91 open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile";
92 print FILE <<END
93 UUID=$extrahdsettings{'UUID'};$extrahdsettings{'FS'};$extrahdsettings{'PATH'};
94 END
95 ;
96 system("/usr/local/bin/extrahdctrl mount $extrahdsettings{'PATH'}");
97 }
98 }
99 elsif ($extrahdsettings{'ACTION'} eq $Lang::tr{'delete'})
100 {
101 if ( `/usr/local/bin/extrahdctrl umount $extrahdsettings{'PATH'}` ) {
102 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
103 @tmp = <FILE>;
104 close FILE;
105 open( FILE, "> $devicefile" ) or die "Unable to write $devicefile";
106 foreach $deviceentry (sort @tmp)
107 {
108 @tmpline = split( /\;/, $deviceentry );
109 if ( $tmpline[2] ne $extrahdsettings{'PATH'} )
110 {
111 print FILE $deviceentry;
112 }
113 }
114 close FILE;
115 } else {
116 $errormessage = "$Lang::tr{'extrahd cant umount'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd maybe the device is in use'}?";
117 }
118 }
119
120 if ($errormessage) {
121 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
122 print "<class name='base'>$errormessage\n";
123 print "&nbsp;</class>\n";
124 &Header::closebox();
125 }
126
127 ############################################################################################################################
128 ############################################################################################################################
129
130 &Header::openbox('100%', 'center', $Lang::tr{'extrahd'});
131 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
132 @devices = <FILE>;
133 close FILE;
134 print <<END
135 <table border='0' width='600' cellspacing="0">
136 END
137 ;
138 foreach $deviceentry (sort @devices)
139 {
140 @deviceline = split( /\;/, $deviceentry );
141 my $color="$Header::colourred";
142 if ( ! `/bin/mountpoint $deviceline[2] | grep " not "` ) {
143 $color=$Header::colourgreen;
144 }
145 print <<END
146 <tr><td colspan="4">&nbsp;</td></tr>
147 <tr><td align='left'><font color=$color><b>$deviceline[0]</b></font></td>
148 <td align='left'>$deviceline[1]</td>
149 <td align='left'>$deviceline[2]</td>
150 <td align='center'>
151 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
152 <input type='hidden' name='DEVICE' value='$deviceline[0]' />
153 <input type='hidden' name='FS' value='$deviceline[1]' />
154 <input type='hidden' name='PATH' value='$deviceline[2]' />
155 <input type='hidden' name='ACTION' value=$Lang::tr{'delete'} />
156 <input type='image' alt=$Lang::tr{'delete'} src='/images/delete.gif' />
157 </form></td></tr>
158 END
159 ;
160 }
161 print <<END
162 </table>
163 END
164 ;
165
166 &Header::closebox();
167
168 &Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'});
169 print <<END
170 <table border='0' width='600' cellspacing="0">
171 END
172 ;
173 open( FILE, "< $scanfile" ) or die "Unable to read $scanfile";
174 @scans = <FILE>;
175 close FILE;
176 open( FILE, "< $partitionsfile" ) or die "Unable to read $partitionsfile";
177 @partitions = <FILE>;
178 close FILE;
179 foreach $scanentry (sort @scans)
180 {
181 @scanline = split( /\;/, $scanentry );
182 # remove wrong entries like usb controller name
183 if ($scanline[1] ne "\n")
184 {
185 print <<END
186 <tr><td colspan="5">&nbsp;</td></tr>
187 <tr><td align='left' colspan="2"><b>/dev/$scanline[0]</b></td>
188 <td align='center' colspan="2">$scanline[1]</td>
189 END
190 ;
191
192 }
193 foreach $partitionentry (sort @partitions)
194 {
195 @partitionline = split( /\;/, $partitionentry );
196 if ( "$partitionline[0]" eq "$scanline[0]" ) {
197 $size = int($partitionline[1] / 1024);
198 print <<END
199 <td align='center'>$Lang::tr{'size'} $size MB</td>
200 <td>&nbsp;</td></tr>
201 <tr><td colspan="5">&nbsp;</td></tr>
202 END
203 ;
204 }
205 }
206
207 foreach $partitionentry (sort @partitions)
208 {
209 @partitionline = split( /\;/, $partitionentry );
210 if (( "$partitionline[0]" =~ /^$scanline[0]/ ) && !( "$partitionline[2]" eq "" )) {
211 $size = int($partitionline[1] / 1024);
212 print <<END
213 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
214 <tr><td align="left" colspan=5><strong>UUID=$partitionline[2]</strong></td></tr>
215 <tr>
216 <td align="list">/dev/$partitionline[0]</td>
217 <td align="center">$Lang::tr{'size'} $size MB</td>
218 <td align="center"><select name="FS">
219 <option value="auto">auto</option>
220 <option value="ext3">ext3</option>
221 <option value="ext4">ext4</option>
222 <option value="reiserfs">reiserfs</option>
223 <option value="vfat">fat</option>
224 <option value="ntfs-3g">ntfs (experimental)</option>
225 </select></td>
226 <td align="center"><input type='text' name='PATH' value=/mnt/harddisk /></td>
227 <td align="center">
228 <input type='hidden' name='DEVICE' value='$partitionline[0]' />
229 <input type='hidden' name='UUID' value='$partitionline[2]' />
230 <input type='hidden' name='ACTION' value=$Lang::tr{'add'} />
231 <input type='image' alt=$Lang::tr{'add'} src='/images/add.gif' />
232 </form></td></tr>
233 END
234 ;
235
236 END
237 ;
238 }
239 }
240 }
241
242 print <<END
243 <tr><td align="center" colspan="5">&nbsp;</td></tr>
244 <tr><td align="center" colspan="5">&nbsp;</td></tr>
245 <tr><td align="center" colspan="5">$Lang::tr{'extrahd install or load driver'}</td></tr>
246 </table>
247 END
248 ;
249 &Header::closebox();
250
251 &Header::closebigbox();
252 &Header::closepage();