]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/mac.cgi
Merge branch 'master' of ssh://arne_f@ipfire.org/pub/git/ipfire-2.x
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / mac.cgi
1 #!/usr/bin/perl
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 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31
32 my %macsettings=();
33 my $errormessage = '';
34
35 &Header::showhttpheaders();
36
37 &General::readhash("${General::swroot}/mac/settings", \%macsettings);
38
39 &Header::getcgihash(\%macsettings);
40
41 &Header::openpage($Lang::tr{'mac address title'}, 1, );
42
43 &Header::openbigbox('100%', 'left', '', $errormessage);
44
45 if ($macsettings{'ACTION'} eq $Lang::tr{'save'}) {
46 $macsettings{'MAC'} =~ s/\-/:/g;
47 my @mac = split(/:/,$macsettings{"MAC"});
48 if ($#mac == 5) {
49 if (($mac[0] eq "00")||($mac[0] eq "0")){
50 foreach (@mac) {
51 unless ($_ =~ /^[a-fA-F0-9]{1,2}$/) {
52 $errormessage = $Lang::tr{'mac address error not valid'};
53 last;
54 }
55 }
56 } else {
57 $errormessage = $Lang::tr{'mac address error not 00'};
58 }
59 if ($errormessage eq "") {
60 $macsettings{'MAC'} =~ s/\:/-/g;
61 &General::writehash("${General::swroot}/mac/settings", \%macsettings);
62 &Header::openbox('100%', 'left', $Lang::tr{'mac address saved'});
63 print "<font class='base'>$Lang::tr{'mac address saved txt'}</font>\n";
64 &Header::closebox();
65 }
66 } else {
67 $errormessage = $Lang::tr{'mac address error not valid'};
68 }
69 }
70 if ($macsettings{'ACTION'} eq $Lang::tr{'reconnect'}) {
71 system("/usr/local/bin/redctrl restart >/dev/null 2>&1 &");
72 &Header::openbox('100%', 'left', $Lang::tr{'mac address recon'} );
73 print "<font class='base'>$Lang::tr{'mac address done'}</font>\n";
74 &Header::closebox();
75 }
76 if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) {
77 system("cat /dev/null > ${General::swroot}/mac/settings &");
78 &Header::openbox('100%', 'left', $Lang::tr{'mac address deleted'} );
79 print "<font class='base'>$Lang::tr{'mac address deleted txt'}</font>\n";
80 &Header::closebox();
81 }
82 if ($macsettings{'ACTION'} eq $Lang::tr{'reboot'}) {
83 &General::log($Lang::tr{'rebooting ipfire'});
84 system("/usr/local/bin/ipfirereboot boot");
85 &Header::openbox('100%', 'left', $Lang::tr{'rebooting ipfire'} );
86 print "&nbsp;&nbsp;<img src='/images/indicator.gif' /><br /><br />";
87 print "<meta http-equiv='refresh' content='120;'>";
88 &Header::closebox();
89 }
90
91 # DPC move error message to top so it is seen!
92 if ($errormessage) {
93 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
94 print "<font class='base'>$errormessage&nbsp;</font>\n";
95 &Header::closebox();
96 }
97
98 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
99
100 &Header::openbox('100%', 'left', $Lang::tr{'mac address header'});
101 print <<END
102
103 <table border="0" width='100%'>
104 <tr>
105 <td><font class='base'>$Lang::tr{'mac desc'}</font></td>
106 </tr>
107 <tr>
108 <td>&nbsp;</td>
109 </tr>
110 <tr>
111 <td><font class='base'>$Lang::tr{'mac new'}&nbsp;</font>
112 END
113 ;
114 if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) {
115 print <<END
116 <input type="text" name="MAC" maxlength="17" value=''/></td>
117 END
118 ;
119 } else {
120 print <<END
121 <input type="text" name="MAC" maxlength="17" value='$macsettings{"MAC"}'/></td>
122 END
123 ;
124 }
125 print <<END
126 </tr>
127 <tr>
128 <td><hr /></td>
129 </tr>
130 <tr>
131 <td><div align="center">
132 END
133 ;
134 if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) {
135 print <<END
136 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
137 &nbsp;&nbsp;&nbsp;&nbsp;
138 <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' />
139 &nbsp;&nbsp;&nbsp;&nbsp;
140 <input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' />
141 END
142 ;
143 } elsif ($macsettings{'ACTION'} eq $Lang::tr{'save'} && $errormessage eq "") {
144 print <<END
145 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
146 &nbsp;&nbsp;&nbsp;&nbsp;
147 <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' />
148 &nbsp;&nbsp;&nbsp;&nbsp;
149 <input type='submit' name='ACTION' value='$Lang::tr{'reconnect'}' />
150 END
151 ;
152 } elsif ($macsettings{'ACTION'} eq $Lang::tr{'save'}) {
153 print <<END
154 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
155 END
156 ;
157 } else {
158 print <<END
159 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
160 &nbsp;&nbsp;&nbsp;&nbsp;
161 <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' />
162 END
163 ;
164 }
165 print <<END
166 </div></td>
167 </tr>
168
169
170
171 </table>
172
173 END
174 ;
175 &Header::closebox();
176
177 print "</form>\n";
178
179 &Header::closebigbox();
180
181 &Header::closepage();
182