+#!/usr/bin/perl
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+my %macsettings=();
+my $errormessage = '';
+
+&Header::showhttpheaders();
+
+&General::readhash("${General::swroot}/mac/settings", \%macsettings);
+
+&Header::getcgihash(\%macsettings);
+
+&Header::openpage($Lang::tr{'mac address title'}, 1, );
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($macsettings{'ACTION'} eq $Lang::tr{'save'}) {
+ $macsettings{'MAC'} =~ s/\-/:/g;
+ my @mac = split(/:/,$macsettings{"MAC"});
+ if ($#mac == 5) {
+ if (($mac[0] eq "00")||($mac[0] eq "0")){
+ foreach (@mac) {
+ unless ($_ =~ /^[a-fA-F0-9]{1,2}$/) {
+ $errormessage = $Lang::tr{'mac address error not valid'};
+ last;
+ }
+ }
+ } else {
+ $errormessage = $Lang::tr{'mac address error not 00'};
+ }
+ if ($errormessage eq "") {
+ $macsettings{'MAC'} =~ s/\:/-/g;
+ &General::writehash("${General::swroot}/mac/settings", \%macsettings);
+ &Header::openbox('100%', 'left', $Lang::tr{'mac address saved'});
+ print "<font class='base'>$Lang::tr{'mac address saved txt'}</font>\n";
+ &Header::closebox();
+ }
+ } else {
+ $errormessage = $Lang::tr{'mac address error not valid'};
+ }
+}
+if ($macsettings{'RECONNECT'} eq "Reconnect") {
+ system("/usr/local/bin/redctrl restart >/dev/null 2>&1 &");
+ &Header::openbox('100%', 'left', $Lang::tr{'mac address recon'} );
+ print "<font class='base'>$Lang::tr{'mac address done'}</font>\n";
+ &Header::closebox();
+}
+
+# DPC move error message to top so it is seen!
+if ($errormessage) {
+ &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+ print "<font class='base'>$errormessage </font>\n";
+ &Header::closebox();
+}
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+&Header::openbox('100%', 'left', $Lang::tr{'mac address header'});
+print <<END
+
+<table border="0" width='100%'>
+ <tr>
+ <td colspan="2"><font class='base'>$Lang::tr{'mac desc'}</font></td>
+ </tr>
+ <tr>
+ <td colspan="2"> </td>
+ </tr>
+ <tr>
+ <td colspan="2"><font class='base'>$Lang::tr{'mac new'} </font>
+ <input type="text" name="MAC" maxlength="17" value="$macsettings{"MAC"}"/></td>
+ </tr>
+ <tr>
+ <td colspan="2"><hr /></td>
+ </tr>
+ <tr>
+ <td width="50%"><div align="right">
+ <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
+ </div></td>
+ <td width="50%"><div align="left">
+ <input type='submit' name='RECONNECT' value="$Lang::tr{'mac reconnection'}" />
+ </div></td>
+ </tr>
+</table>
+
+END
+;
+
+&Header::closebox();
+
+print "</form>\n";
+
+&Header::closebigbox();
+
+&Header::closepage();
+