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