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