]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/extrahd.cgi
"Update Booster" fertiggestellt und getestet.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / extrahd.cgi
CommitLineData
aa2870e6
MT
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8#
9
10use strict;
11# enable only the following on debugging purpose
12use warnings;
13use CGI::Carp 'fatalsToBrowser';
14
15require '/var/ipfire/general-functions.pl';
16require "${General::swroot}/lang.pl";
17require "${General::swroot}/header.pl";
18
19my %extrahdsettings = ();
20my $message = "";
21my $errormessage = "";
22my $size = "";
23my $ok = "true";
24my @tmp = ();
25my @tmpline = ();
26my $tmpentry = "";
27my @devices = ();
28my @deviceline = ();
29my $deviceentry = "";
30my @scans = ();
31my @scanline = ();
32my $scanentry = "";
33my @partitions = ();
34my @partitionline = ();
35my $partitionentry = "";
36my $devicefile = "/var/ipfire/extrahd/devices";
37my $scanfile = "/var/ipfire/extrahd/scan";
38my $partitionsfile = "/var/ipfire/extrahd/partitions";
39system("/usr/local/bin/scanhd ide");
40system("/usr/local/bin/scanhd partitions");
41
42&Header::showhttpheaders();
43
44### Values that have to be initialized
45$extrahdsettings{'PATH'} = '';
46$extrahdsettings{'FS'} = '';
47$extrahdsettings{'DEVICE'} = '';
48$extrahdsettings{'ACTION'} = '';
49
50&General::readhash("${General::swroot}/extrahd/settings", \%extrahdsettings);
51&Header::getcgihash(\%extrahdsettings);
52
53&Header::openpage('ExtraHD', 1, '');
54&Header::openbigbox('100%', 'left', '', $errormessage);
55
56############################################################################################################################
57############################################################################################################################
58
59if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'})
60{
61 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
62 @devices = <FILE>;
63 close FILE;
64 foreach $deviceentry (sort @devices)
65 {
66 @deviceline = split( /\;/, $deviceentry );
67 if ( "$extrahdsettings{'PATH'}" eq "$deviceline[2]" ) {
68 $ok = "false";
69 $errormessage = "You can't mount $extrahdsettings{'DEVICE'} to $extrahdsettings{'PATH'}, because there is already a device mounted.";
70 }
71 if ( "$extrahdsettings{'PATH'}" eq "/" ) {
72 $ok = "false";
73 $errormessage = "You can't mount $extrahdsettings{'DEVICE'} to root /.";
74 }
75 }
76
77 if ( "$ok" eq "true" ) {
78 open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile";
79 print FILE <<END
80$extrahdsettings{'DEVICE'};$extrahdsettings{'FS'};$extrahdsettings{'PATH'};
81END
82;
83 system("/usr/local/bin/extrahdctrl mount $extrahdsettings{'PATH'}");
84 }
85}
86elsif ($extrahdsettings{'ACTION'} eq $Lang::tr{'delete'})
87{
88 if ( `/usr/local/bin/extrahdctrl umount $extrahdsettings{'PATH'}` ) {
89 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
90 @tmp = <FILE>;
91 close FILE;
92 open( FILE, "> $devicefile" ) or die "Unable to write $devicefile";
93 foreach $deviceentry (sort @tmp)
94 {
95 @tmpline = split( /\;/, $deviceentry );
96 if ( $tmpline[2] ne $extrahdsettings{'PATH'} )
97 {
98 print FILE $deviceentry;
99 }
100 }
101 close FILE;
102 } else {
103 $errormessage = "Can't umount $extrahdsettings{'PATH'}. Maybe the device is in use?";
104 }
105}
106
107if ($errormessage) {
108 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
109 print "<class name='base'>$errormessage\n";
110 print "&nbsp;</class>\n";
111 &Header::closebox();
112}
113
114############################################################################################################################
115############################################################################################################################
116
117&Header::openbox('100%', 'center', 'ExtraHD');
118 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
119 @devices = <FILE>;
120 close FILE;
121 print <<END
122 <table border='0' width='600' cellspacing="0">
123END
124;
125 foreach $deviceentry (sort @devices)
126 {
127 @deviceline = split( /\;/, $deviceentry );
128 my $color="$Header::colourred";
129 if ( `/bin/mount | /bin/fgrep $deviceline[2] | /bin/fgrep /dev/$deviceline[0]` ) {
130 $color=$Header::colourgreen;
131 }
132 print <<END
133 <tr><td colspan="5">&nbsp;
134 <tr><td align='center'><font color=$color><b>/dev/$deviceline[0]</b></font>
135 <td align='center'>$deviceline[1]
136 <td align='center'>$deviceline[2]
137 <td align='center'>
138 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
139 <input type='hidden' name='DEVICE' value='$deviceline[0]' />
140 <input type='hidden' name='FS' value='$deviceline[1]' />
141 <input type='hidden' name='PATH' value='$deviceline[2]' />
142 <input type='hidden' name='ACTION' value=$Lang::tr{'delete'} />
143 <input type='image' alt=$Lang::tr{'delete'} src='/images/delete.gif' />
144 </form>
145END
146;
147 }
148 print <<END
149 </table>
150END
151;
152
153&Header::closebox();
154
155&Header::openbox('100%', 'center', 'Gefundene Laufwerke');
156 print <<END
157 <table border='0' width='600' cellspacing="0">
158END
159;
160 open( FILE, "< $scanfile" ) or die "Unable to read $scanfile";
161 @scans = <FILE>;
162 close FILE;
163 open( FILE, "< $partitionsfile" ) or die "Unable to read $partitionsfile";
164 @partitions = <FILE>;
165 close FILE;
166 foreach $scanentry (sort @scans)
167 {
168 @scanline = split( /\;/, $scanentry );
169 print <<END
170 <tr><td colspan="5">&nbsp;
171 <tr><td align='center'><b>/dev/$scanline[0]</b>
172 <td align='center' colspan="2">$scanline[1]
173END
174;
175 foreach $partitionentry (sort @partitions)
176 {
177 @partitionline = split( /\;/, $partitionentry );
178 if ( "$partitionline[0]" eq "$scanline[0]" ) {
179 $size = int($partitionline[1] / 1024);
180 print <<END
181 <td align='center'>$Lang::tr{'size'} $size MB
182 <td>&nbsp;
183 <tr><td colspan="5">&nbsp;
184END
185;
186 }
187 }
188
189 foreach $partitionentry (sort @partitions)
190 {
191 @partitionline = split( /\;/, $partitionentry );
192 if (( "$partitionline[0]" =~ /^$scanline[0]/ ) && ! ( "$partitionline[0]" eq "$scanline[0]" )) {
193 $size = int($partitionline[1] / 1024);
194 print <<END
195 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
196 <tr><td align="center" bgcolor='#EAEAEA'>/dev/$partitionline[0]
197 <td align="center" bgcolor='#EAEAEA'>$Lang::tr{'size'} $size MB
198 <td align='center' bgcolor='#EAEAEA'><select name="FS">
199 <option value="auto">auto</option>
200 <option value="ext3">ext3</option>
201 <option value="reiserfs">reiserfs</option>
202 <option value="vfat">fat</option>
203 <option value="ntfs-3g">ntfs (experimental)</option>
204 </select>
205 <td align="center" bgcolor='#EAEAEA'><input type='text' name='PATH' value=/mnt/harddisk />
206 <td align="center">
207 <input type='hidden' name='DEVICE' value='$partitionline[0]' />
208 <input type='hidden' name='ACTION' value=$Lang::tr{'add'} />
209 <input type='image' alt=$Lang::tr{'add'} src='/images/add.gif' />
210 </form>
211
212END
213;
214 }
215 }
216 }
217
218 print <<END
219 <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.
220 </table>
221END
222;
223&Header::closebox();
224
225&Header::closebigbox();
226&Header::closepage();