]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/extrahd.cgi
vpn-statistic: change title of ovpn RW statistic page
[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 #
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
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";
e528205e
AF
51system("/usr/local/bin/extrahdctrl scanhd ide");
52system("/usr/local/bin/extrahdctrl scanhd partitions");
aa2870e6
MT
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";
20730a6f 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'}.";
aa2870e6
MT
83 }
84 if ( "$extrahdsettings{'PATH'}" eq "/" ) {
85 $ok = "false";
20730a6f 86 $errormessage = "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'DEVICE'} $Lang::tr{'extrahd to root'}.";
aa2870e6
MT
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 {
20730a6f 116 $errormessage = "$Lang::tr{'extrahd cant umount'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd maybe the device is in use'}?";
aa2870e6
MT
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
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">
135END
136;
137 foreach $deviceentry (sort @devices)
138 {
139 @deviceline = split( /\;/, $deviceentry );
140 my $color="$Header::colourred";
76d8ffc4 141 if ( ! `/bin/mountpoint $deviceline[2] | grep " not "` ) {
aa2870e6
MT
142 $color=$Header::colourgreen;
143 }
144 print <<END
20730a6f
JPT
145 <tr><td colspan="4">&nbsp;</td></tr>
146 <tr><td align='left'><font color=$color><b>$deviceline[0]</b></font></td>
147 <td align='left'>$deviceline[1]</td>
148 <td align='left'>$deviceline[2]</td>
aa2870e6
MT
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'} />
f8aa0679 155 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/delete.gif' />
20730a6f 156 </form></td></tr>
aa2870e6
MT
157END
158;
159 }
160 print <<END
161 </table>
162END
163;
bfdd4688 164&Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'});
aa2870e6
MT
165 print <<END
166 <table border='0' width='600' cellspacing="0">
167END
168;
169 open( FILE, "< $scanfile" ) or die "Unable to read $scanfile";
170 @scans = <FILE>;
171 close FILE;
172 open( FILE, "< $partitionsfile" ) or die "Unable to read $partitionsfile";
173 @partitions = <FILE>;
174 close FILE;
175 foreach $scanentry (sort @scans)
176 {
177 @scanline = split( /\;/, $scanentry );
20730a6f
JPT
178 # remove wrong entries like usb controller name
179 if ($scanline[1] ne "\n")
180 {
181 print <<END
182 <tr><td colspan="5">&nbsp;</td></tr>
183 <tr><td align='left' colspan="2"><b>/dev/$scanline[0]</b></td>
184 <td align='center' colspan="2">$scanline[1]</td>
aa2870e6
MT
185END
186;
20730a6f
JPT
187
188 }
aa2870e6
MT
189 foreach $partitionentry (sort @partitions)
190 {
191 @partitionline = split( /\;/, $partitionentry );
192 if ( "$partitionline[0]" eq "$scanline[0]" ) {
193 $size = int($partitionline[1] / 1024);
194 print <<END
20730a6f
JPT
195 <td align='center'>$Lang::tr{'size'} $size MB</td>
196 <td>&nbsp;</td></tr>
197 <tr><td colspan="5">&nbsp;</td></tr>
aa2870e6
MT
198END
199;
200 }
201 }
202
203 foreach $partitionentry (sort @partitions)
204 {
205 @partitionline = split( /\;/, $partitionentry );
1eaa29b1 206 if (( "$partitionline[0]" =~ /^$scanline[0]/ ) && !( "$partitionline[2]" eq "" )) {
aa2870e6
MT
207 $size = int($partitionline[1] / 1024);
208 print <<END
209 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
20730a6f 210 <tr><td align="left" colspan=5><strong>UUID=$partitionline[2]</strong></td></tr>
e528205e
AF
211 <tr>
212 <td align="list">/dev/$partitionline[0]</td>
20730a6f 213 <td align="center">$Lang::tr{'size'} $size MB</td>
e528205e 214 <td align="center"><select name="FS">
aa2870e6
MT
215 <option value="auto">auto</option>
216 <option value="ext3">ext3</option>
20730a6f 217 <option value="ext4">ext4</option>
aa2870e6
MT
218 <option value="reiserfs">reiserfs</option>
219 <option value="vfat">fat</option>
220 <option value="ntfs-3g">ntfs (experimental)</option>
20730a6f
JPT
221 </select></td>
222 <td align="center"><input type='text' name='PATH' value=/mnt/harddisk /></td>
aa2870e6
MT
223 <td align="center">
224 <input type='hidden' name='DEVICE' value='$partitionline[0]' />
784d72a2 225 <input type='hidden' name='UUID' value='$partitionline[2]' />
aa2870e6 226 <input type='hidden' name='ACTION' value=$Lang::tr{'add'} />
f8aa0679 227 <input type='image' alt='$Lang::tr{'add'}' title='$Lang::tr{'add'}' src='/images/add.gif' />
20730a6f
JPT
228 </form></td></tr>
229END
230;
aa2870e6
MT
231
232END
233;
234 }
235 }
236 }
237
238 print <<END
20730a6f
JPT
239 <tr><td align="center" colspan="5">&nbsp;</td></tr>
240 <tr><td align="center" colspan="5">&nbsp;</td></tr>
241 <tr><td align="center" colspan="5">$Lang::tr{'extrahd install or load driver'}</td></tr>
aa2870e6
MT
242 </table>
243END
244;
245&Header::closebox();
246
247&Header::closebigbox();
248&Header::closepage();