]>
Commit | Line | Data |
---|---|---|
aa2870e6 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
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"; | |
51 | system("/usr/local/bin/scanhd ide"); | |
52 | system("/usr/local/bin/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 | ||
62 | &General::readhash("${General::swroot}/extrahd/settings", \%extrahdsettings); | |
63 | &Header::getcgihash(\%extrahdsettings); | |
64 | ||
65 | &Header::openpage('ExtraHD', 1, ''); | |
66 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
67 | ||
68 | ############################################################################################################################ | |
69 | ############################################################################################################################ | |
70 | ||
71 | if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) | |
72 | { | |
73 | open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; | |
74 | @devices = <FILE>; | |
75 | close FILE; | |
76 | foreach $deviceentry (sort @devices) | |
77 | { | |
78 | @deviceline = split( /\;/, $deviceentry ); | |
79 | if ( "$extrahdsettings{'PATH'}" eq "$deviceline[2]" ) { | |
80 | $ok = "false"; | |
81 | $errormessage = "You can't mount $extrahdsettings{'DEVICE'} to $extrahdsettings{'PATH'}, because there is already a device mounted."; | |
82 | } | |
83 | if ( "$extrahdsettings{'PATH'}" eq "/" ) { | |
84 | $ok = "false"; | |
85 | $errormessage = "You can't mount $extrahdsettings{'DEVICE'} to root /."; | |
86 | } | |
87 | } | |
88 | ||
89 | if ( "$ok" eq "true" ) { | |
90 | open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile"; | |
91 | print FILE <<END | |
92 | $extrahdsettings{'DEVICE'};$extrahdsettings{'FS'};$extrahdsettings{'PATH'}; | |
93 | END | |
94 | ; | |
95 | system("/usr/local/bin/extrahdctrl mount $extrahdsettings{'PATH'}"); | |
96 | } | |
97 | } | |
98 | elsif ($extrahdsettings{'ACTION'} eq $Lang::tr{'delete'}) | |
99 | { | |
100 | if ( `/usr/local/bin/extrahdctrl umount $extrahdsettings{'PATH'}` ) { | |
101 | open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; | |
102 | @tmp = <FILE>; | |
103 | close FILE; | |
104 | open( FILE, "> $devicefile" ) or die "Unable to write $devicefile"; | |
105 | foreach $deviceentry (sort @tmp) | |
106 | { | |
107 | @tmpline = split( /\;/, $deviceentry ); | |
108 | if ( $tmpline[2] ne $extrahdsettings{'PATH'} ) | |
109 | { | |
110 | print FILE $deviceentry; | |
111 | } | |
112 | } | |
113 | close FILE; | |
114 | } else { | |
115 | $errormessage = "Can't umount $extrahdsettings{'PATH'}. Maybe the device is in use?"; | |
116 | } | |
117 | } | |
118 | ||
119 | if ($errormessage) { | |
120 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
121 | print "<class name='base'>$errormessage\n"; | |
122 | print " </class>\n"; | |
123 | &Header::closebox(); | |
124 | } | |
125 | ||
126 | ############################################################################################################################ | |
127 | ############################################################################################################################ | |
128 | ||
388ba7bc | 129 | &Header::openbox('100%', 'center', $Lang::tr{'extrahd'}); |
aa2870e6 MT |
130 | open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; |
131 | @devices = <FILE>; | |
132 | close FILE; | |
133 | print <<END | |
134 | <table border='0' width='600' cellspacing="0"> | |
135 | END | |
136 | ; | |
137 | foreach $deviceentry (sort @devices) | |
138 | { | |
139 | @deviceline = split( /\;/, $deviceentry ); | |
140 | my $color="$Header::colourred"; | |
141 | if ( `/bin/mount | /bin/fgrep $deviceline[2] | /bin/fgrep /dev/$deviceline[0]` ) { | |
142 | $color=$Header::colourgreen; | |
143 | } | |
144 | print <<END | |
145 | <tr><td colspan="5"> | |
146 | <tr><td align='center'><font color=$color><b>/dev/$deviceline[0]</b></font> | |
147 | <td align='center'>$deviceline[1] | |
148 | <td align='center'>$deviceline[2] | |
149 | <td align='center'> | |
150 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
151 | <input type='hidden' name='DEVICE' value='$deviceline[0]' /> | |
152 | <input type='hidden' name='FS' value='$deviceline[1]' /> | |
153 | <input type='hidden' name='PATH' value='$deviceline[2]' /> | |
154 | <input type='hidden' name='ACTION' value=$Lang::tr{'delete'} /> | |
155 | <input type='image' alt=$Lang::tr{'delete'} src='/images/delete.gif' /> | |
156 | </form> | |
157 | END | |
158 | ; | |
159 | } | |
160 | print <<END | |
161 | </table> | |
162 | END | |
163 | ; | |
164 | ||
165 | &Header::closebox(); | |
166 | ||
388ba7bc | 167 | &Header::openbox('100%', 'center', $Lang::tr{'extrahd founded drives'}); |
aa2870e6 MT |
168 | print <<END |
169 | <table border='0' width='600' cellspacing="0"> | |
170 | END | |
171 | ; | |
172 | open( FILE, "< $scanfile" ) or die "Unable to read $scanfile"; | |
173 | @scans = <FILE>; | |
174 | close FILE; | |
175 | open( FILE, "< $partitionsfile" ) or die "Unable to read $partitionsfile"; | |
176 | @partitions = <FILE>; | |
177 | close FILE; | |
178 | foreach $scanentry (sort @scans) | |
179 | { | |
180 | @scanline = split( /\;/, $scanentry ); | |
181 | print <<END | |
182 | <tr><td colspan="5"> | |
183 | <tr><td align='center'><b>/dev/$scanline[0]</b> | |
184 | <td align='center' colspan="2">$scanline[1] | |
185 | END | |
186 | ; | |
187 | foreach $partitionentry (sort @partitions) | |
188 | { | |
189 | @partitionline = split( /\;/, $partitionentry ); | |
190 | if ( "$partitionline[0]" eq "$scanline[0]" ) { | |
191 | $size = int($partitionline[1] / 1024); | |
192 | print <<END | |
193 | <td align='center'>$Lang::tr{'size'} $size MB | |
194 | <td> | |
195 | <tr><td colspan="5"> | |
196 | END | |
197 | ; | |
198 | } | |
199 | } | |
200 | ||
201 | foreach $partitionentry (sort @partitions) | |
202 | { | |
203 | @partitionline = split( /\;/, $partitionentry ); | |
204 | if (( "$partitionline[0]" =~ /^$scanline[0]/ ) && ! ( "$partitionline[0]" eq "$scanline[0]" )) { | |
205 | $size = int($partitionline[1] / 1024); | |
206 | print <<END | |
207 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
f2fdd0c1 CS |
208 | <tr><td align="center">/dev/$partitionline[0] |
209 | <td align="center">$Lang::tr{'size'} $size MB | |
210 | <td align='center'><select name="FS"> | |
aa2870e6 MT |
211 | <option value="auto">auto</option> |
212 | <option value="ext3">ext3</option> | |
213 | <option value="reiserfs">reiserfs</option> | |
214 | <option value="vfat">fat</option> | |
215 | <option value="ntfs-3g">ntfs (experimental)</option> | |
216 | </select> | |
f2fdd0c1 | 217 | <td align="center"><input type='text' name='PATH' value=/mnt/harddisk /> |
aa2870e6 MT |
218 | <td align="center"> |
219 | <input type='hidden' name='DEVICE' value='$partitionline[0]' /> | |
220 | <input type='hidden' name='ACTION' value=$Lang::tr{'add'} /> | |
221 | <input type='image' alt=$Lang::tr{'add'} src='/images/add.gif' /> | |
222 | </form> | |
223 | ||
224 | END | |
225 | ; | |
226 | } | |
227 | } | |
228 | } | |
229 | ||
230 | print <<END | |
231 | <tr><td align="center" colspan="5">If your device isn't listed here, you need to install or load the driver.<br />If you can see your device but no partitions you have to create them first. | |
232 | </table> | |
233 | END | |
234 | ; | |
235 | &Header::closebox(); | |
236 | ||
237 | &Header::closebigbox(); | |
238 | &Header::closepage(); |