]>
Commit | Line | Data |
---|---|---|
ed7079a4 JPT |
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 | |
d4ca4a03 AF |
25 | use warnings; |
26 | use CGI::Carp 'fatalsToBrowser'; | |
ed7079a4 JPT |
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) { | |
d4ca4a03 AF |
49 | foreach (@mac) { |
50 | unless ($_ =~ /^[a-fA-F0-9]{1,2}$/) { | |
51 | $errormessage = $Lang::tr{'mac address error not valid'}; | |
52 | last; | |
ed7079a4 | 53 | } |
ed7079a4 | 54 | } |
d4ca4a03 AF |
55 | } else { |
56 | $errormessage = $Lang::tr{'mac address error not valid'}; | |
57 | } | |
58 | $macsettings{'MAC2'} =~ s/\-/:/g; | |
59 | my @mac = split(/:/,$macsettings{"MAC2"}); | |
60 | if ($#mac == 5) { | |
61 | foreach (@mac) { | |
62 | unless ($_ =~ /^[a-fA-F0-9]{1,2}$/) { | |
63 | $errormessage = $Lang::tr{'mac address error not valid'}; | |
64 | last; | |
65 | } | |
ed7079a4 JPT |
66 | } |
67 | } else { | |
68 | $errormessage = $Lang::tr{'mac address error not valid'}; | |
69 | } | |
d4ca4a03 AF |
70 | if ($errormessage eq "") { |
71 | $macsettings{'MAC'} =~ s/\:/-/g; | |
72 | $macsettings{'MAC2'} =~ s/\:/-/g; | |
73 | &General::writehash("${General::swroot}/mac/settings", \%macsettings); | |
74 | &Header::openbox('100%', 'left', $Lang::tr{'mac address saved'}); | |
75 | print "<font class='base'>$Lang::tr{'mac address saved txt'}</font>\n"; | |
76 | &Header::closebox(); | |
77 | } | |
ed7079a4 | 78 | } |
2e7457d3 | 79 | if ($macsettings{'ACTION'} eq $Lang::tr{'reconnect'}) { |
ed7079a4 JPT |
80 | system("/usr/local/bin/redctrl restart >/dev/null 2>&1 &"); |
81 | &Header::openbox('100%', 'left', $Lang::tr{'mac address recon'} ); | |
82 | print "<font class='base'>$Lang::tr{'mac address done'}</font>\n"; | |
83 | &Header::closebox(); | |
84 | } | |
2e7457d3 | 85 | if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) { |
958a98a2 JPT |
86 | system("cat /dev/null > ${General::swroot}/mac/settings &"); |
87 | &Header::openbox('100%', 'left', $Lang::tr{'mac address deleted'} ); | |
88 | print "<font class='base'>$Lang::tr{'mac address deleted txt'}</font>\n"; | |
89 | &Header::closebox(); | |
90 | } | |
2e7457d3 JPT |
91 | if ($macsettings{'ACTION'} eq $Lang::tr{'reboot'}) { |
92 | &General::log($Lang::tr{'rebooting ipfire'}); | |
93 | system("/usr/local/bin/ipfirereboot boot"); | |
94 | &Header::openbox('100%', 'left', $Lang::tr{'rebooting ipfire'} ); | |
95 | print " <img src='/images/indicator.gif' /><br /><br />"; | |
96 | print "<meta http-equiv='refresh' content='120;'>"; | |
97 | &Header::closebox(); | |
98 | } | |
ed7079a4 JPT |
99 | |
100 | # DPC move error message to top so it is seen! | |
101 | if ($errormessage) { | |
102 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
103 | print "<font class='base'>$errormessage </font>\n"; | |
104 | &Header::closebox(); | |
105 | } | |
106 | ||
107 | print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n"; | |
108 | ||
109 | &Header::openbox('100%', 'left', $Lang::tr{'mac address header'}); | |
110 | print <<END | |
111 | ||
112 | <table border="0" width='100%'> | |
113 | <tr> | |
d4ca4a03 | 114 | <td colspan=2><font class='base'>$Lang::tr{'mac desc'}</font></td> |
ed7079a4 JPT |
115 | </tr> |
116 | <tr> | |
d4ca4a03 | 117 | <td colspan=2> </td><td> </td> |
ed7079a4 JPT |
118 | </tr> |
119 | <tr> | |
d4ca4a03 | 120 | <td><font class='base'>$Lang::tr{'mac new'} </font></td><td> |
2e7457d3 JPT |
121 | END |
122 | ; | |
123 | if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) { | |
124 | print <<END | |
125 | <input type="text" name="MAC" maxlength="17" value=''/></td> | |
126 | END | |
127 | ; | |
128 | } else { | |
129 | print <<END | |
13c13410 | 130 | <input type="text" name="MAC" maxlength="17" value='$macsettings{"MAC"}'/></td> |
2e7457d3 JPT |
131 | END |
132 | ; | |
133 | } | |
134 | print <<END | |
ed7079a4 JPT |
135 | </tr> |
136 | <tr> | |
d4ca4a03 AF |
137 | <td colspan=2> </td><td> </td> |
138 | </tr> | |
139 | <tr> | |
140 | <td><font class='base'>$Lang::tr{'mac2 new'} </font></td><td> | |
141 | END | |
142 | ; | |
143 | if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) { | |
144 | print <<END | |
145 | <input type="text" name="MAC2" maxlength="17" value=''/></td> | |
146 | END | |
147 | ; | |
148 | } else { | |
149 | print <<END | |
150 | <input type="text" name="MAC2" maxlength="17" value='$macsettings{"MAC2"}'/></td> | |
151 | END | |
152 | ; | |
153 | } | |
154 | print <<END | |
155 | </tr> | |
156 | <tr> | |
157 | <td colspan=2> </td><td> </td> | |
158 | </tr> | |
159 | <tr> | |
160 | <td colspan=2><hr /></td> | |
ed7079a4 JPT |
161 | </tr> |
162 | <tr> | |
d4ca4a03 | 163 | <td colspan=2><div align="center"> |
2e7457d3 JPT |
164 | END |
165 | ; | |
166 | if ($macsettings{'ACTION'} eq $Lang::tr{'delete'} ) { | |
167 | print <<END | |
168 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /> | |
169 | | |
170 | <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /> | |
171 | | |
172 | <input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /> | |
173 | END | |
174 | ; | |
175 | } elsif ($macsettings{'ACTION'} eq $Lang::tr{'save'} && $errormessage eq "") { | |
176 | print <<END | |
13c13410 JPT |
177 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /> |
178 | | |
2e7457d3 | 179 | <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /> |
958a98a2 | 180 | |
2e7457d3 JPT |
181 | <input type='submit' name='ACTION' value='$Lang::tr{'reconnect'}' /> |
182 | END | |
183 | ; | |
184 | } elsif ($macsettings{'ACTION'} eq $Lang::tr{'save'}) { | |
185 | print <<END | |
186 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /> | |
187 | END | |
188 | ; | |
189 | } else { | |
190 | print <<END | |
191 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /> | |
192 | | |
193 | <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' /> | |
194 | END | |
195 | ; | |
196 | } | |
197 | print <<END | |
13c13410 | 198 | </div></td> |
ed7079a4 | 199 | </tr> |
2e7457d3 JPT |
200 | |
201 | ||
202 | ||
ed7079a4 JPT |
203 | </table> |
204 | ||
205 | END | |
206 | ; | |
ed7079a4 JPT |
207 | &Header::closebox(); |
208 | ||
209 | print "</form>\n"; | |
210 | ||
211 | &Header::closebigbox(); | |
212 | ||
213 | &Header::closepage(); | |
214 |