]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/extrahd.cgi
Add acl support for samba and rsync.
[ipfire-2.x.git] / html / cgi-bin / extrahd.cgi
CommitLineData
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
22use strict;
23# enable only the following on debugging purpose
cb5e9c6c
CS
24#use warnings;
25#use CGI::Carp 'fatalsToBrowser';
aa2870e6
MT
26
27require '/var/ipfire/general-functions.pl';
28require "${General::swroot}/lang.pl";
29require "${General::swroot}/header.pl";
30
31my %extrahdsettings = ();
32my $message = "";
33my $errormessage = "";
34my $size = "";
35my $ok = "true";
36my @tmp = ();
37my @tmpline = ();
38my $tmpentry = "";
39my @devices = ();
40my @deviceline = ();
41my $deviceentry = "";
42my @scans = ();
43my @scanline = ();
44my $scanentry = "";
45my @partitions = ();
46my @partitionline = ();
47my $partitionentry = "";
48my $devicefile = "/var/ipfire/extrahd/devices";
49my $scanfile = "/var/ipfire/extrahd/scan";
50my $partitionsfile = "/var/ipfire/extrahd/partitions";
51system("/usr/local/bin/scanhd ide");
52system("/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'} = '';
784d72a2 61$extrahdsettings{'UUID'} = '';
aa2870e6
MT
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
72if ($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 = "You can't mount $extrahdsettings{'DEVICE'} to $extrahdsettings{'PATH'}, because there is already a device mounted.";
83 }
84 if ( "$extrahdsettings{'PATH'}" eq "/" ) {
85 $ok = "false";
86 $errormessage = "You can't mount $extrahdsettings{'DEVICE'} to root /.";
87 }
88 }
89
90 if ( "$ok" eq "true" ) {
91 open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile";
92 print FILE <<END
784d72a2 93UUID=$extrahdsettings{'UUID'};$extrahdsettings{'FS'};$extrahdsettings{'PATH'};
aa2870e6
MT
94END
95;
96 system("/usr/local/bin/extrahdctrl mount $extrahdsettings{'PATH'}");
97 }
98}
99elsif ($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 = "Can't umount $extrahdsettings{'PATH'}. Maybe the device is in use?";
117 }
118}
119
120if ($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
388ba7bc 130&Header::openbox('100%', 'center', $Lang::tr{'extrahd'});
aa2870e6
MT
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">
136END
137;
138 foreach $deviceentry (sort @devices)
139 {
140 @deviceline = split( /\;/, $deviceentry );
141 my $color="$Header::colourred";
784d72a2 142 if ( `/bin/mountpoint $deviceline[2]` ) {
aa2870e6
MT
143 $color=$Header::colourgreen;
144 }
145 print <<END
146 <tr><td colspan="5">&nbsp;
784d72a2 147 <tr><td align='center'><font color=$color><b>$deviceline[0]</b></font>
aa2870e6
MT
148 <td align='center'>$deviceline[1]
149 <td align='center'>$deviceline[2]
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>
158END
159;
160 }
161 print <<END
162 </table>
163END
164;
165
166&Header::closebox();
167
bfdd4688 168&Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'});
aa2870e6
MT
169 print <<END
170 <table border='0' width='600' cellspacing="0">
171END
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 print <<END
183 <tr><td colspan="5">&nbsp;
184 <tr><td align='center'><b>/dev/$scanline[0]</b>
185 <td align='center' colspan="2">$scanline[1]
186END
187;
188 foreach $partitionentry (sort @partitions)
189 {
190 @partitionline = split( /\;/, $partitionentry );
191 if ( "$partitionline[0]" eq "$scanline[0]" ) {
192 $size = int($partitionline[1] / 1024);
193 print <<END
194 <td align='center'>$Lang::tr{'size'} $size MB
195 <td>&nbsp;
196 <tr><td colspan="5">&nbsp;
197END
198;
199 }
200 }
201
202 foreach $partitionentry (sort @partitions)
203 {
204 @partitionline = split( /\;/, $partitionentry );
205 if (( "$partitionline[0]" =~ /^$scanline[0]/ ) && ! ( "$partitionline[0]" eq "$scanline[0]" )) {
206 $size = int($partitionline[1] / 1024);
207 print <<END
208 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
f2fdd0c1
CS
209 <tr><td align="center">/dev/$partitionline[0]
210 <td align="center">$Lang::tr{'size'} $size MB
211 <td align='center'><select name="FS">
aa2870e6
MT
212 <option value="auto">auto</option>
213 <option value="ext3">ext3</option>
214 <option value="reiserfs">reiserfs</option>
215 <option value="vfat">fat</option>
216 <option value="ntfs-3g">ntfs (experimental)</option>
217 </select>
f2fdd0c1 218 <td align="center"><input type='text' name='PATH' value=/mnt/harddisk />
aa2870e6
MT
219 <td align="center">
220 <input type='hidden' name='DEVICE' value='$partitionline[0]' />
784d72a2 221 <input type='hidden' name='UUID' value='$partitionline[2]' />
aa2870e6
MT
222 <input type='hidden' name='ACTION' value=$Lang::tr{'add'} />
223 <input type='image' alt=$Lang::tr{'add'} src='/images/add.gif' />
224 </form>
225
226END
227;
228 }
229 }
230 }
231
232 print <<END
233 <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.
234 </table>
235END
236;
237&Header::closebox();
238
239&Header::closebigbox();
240&Header::closepage();