]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/captive/index.cgi
captive: Get MAC address of a device without calling arp
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / captive / index.cgi
index 71bff37a2912008161bb005268841721922dcece..bcaf8561af3275ccecf5e757b8453af207bf0d13 100755 (executable)
@@ -53,14 +53,13 @@ unless (-f $clients){ system("touch $clients"); }
 #Read settings
 &General::readhash("$settingsfile", \%settings) if(-f $settingsfile);
 
-#Actions
-if ($cgiparams{'ACTION'} eq "$Lang::tr{'gpl i accept these terms and conditions'}"){
+# Actions
+if ($cgiparams{'ACTION'} eq "SUBMIT") {
        #Get Clients IP-Address
        my $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
 
-       #Ask arp to give the corresponding MAC-Address
-       my $mac_address = qx(arp -a|grep $ip_address|cut -d ' ' -f 4);
-       $mac_address =~ s/\n+\z//;
+       # Retrieve the MAC address from the ARP table
+       my $mac_address = &Network::get_hardware_address($ip_address);
 
        &General::readhasharray("$clients", \%clientshash);
        my $key = &General::findhasharraykey(\%clientshash);
@@ -82,17 +81,15 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'gpl i accept these terms and conditions'
        }       
 }
 
-if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive activate'}"){
+if ($cgiparams{'ACTION'} eq "SUBMIT") {
        my $ip_address;
-       my $mac_address;
        my $granted=0;
        #Convert voucherinput to uppercase
        $cgiparams{'VOUCHER'} = uc $cgiparams{'VOUCHER'};
        #Get Clients IP-Address
        $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
        #Ask arp to give the corresponding MAC-Address
-       $mac_address = qx(arp -a|grep $ip_address|cut -d ' ' -f 4);
-       $mac_address =~ s/\n+\z//;
+       my $mac_address = &Network::get_hardware_address($ip_address);
        #Check if voucher is valid and write client to clients file, delete voucher from voucherout
        &General::readhasharray("$voucherout", \%voucherhash);
        &General::readhasharray("$clients", \%clientshash);
@@ -142,10 +139,23 @@ my $tmpl = HTML::Template->new(
 
 $tmpl->param(REDIRECT_URL => $url);
 
-$tmpl->param(AUTH  => $settings{'AUTH'});
+# Voucher
+if ($settings{'AUTH'} eq "VOUCHER") {
+       $tmpl->param(VOUCHER  => 1);
+}
+
 $tmpl->param(TITLE => $settings{'TITLE'});
 $tmpl->param(ERROR => $errormessage);
 
+$tmpl->param(TAC => &gettac());
+
+# Some translated strings
+$tmpl->param(L_ACTIVATE        => $Lang::tr{'Captive ACTIVATE'});
+$tmpl->param(L_GAIN_ACCESS     => $Lang::tr{'Captive GAIN ACCESS'});
+$tmpl->param(L_HEADING_TAC     => $Lang::tr{'Captive heading tac'});
+$tmpl->param(L_HEADING_VOUCHER => $Lang::tr{'Captive heading voucher'});
+$tmpl->param(L_AGREE_TAC       => $Lang::tr{'Captive agree tac'});
+
 # Print header
 print "Pragma: no-cache\n";
 print "Cache-control: no-cache\n";
@@ -153,7 +163,7 @@ print "Connection: close\n";
 print "Content-type: text/html\n\n";
 
 # Print rendered template
-print $tmpl->output;
+print $tmpl->output();
 
 sub getcgihash {
        my ($hash, $params) = @_;
@@ -187,11 +197,20 @@ sub getcgihash {
        return;
 }
 
-sub getagb(){
-       open( my $handle, "<:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!");
-               while(<$handle>){
-                       $_ = HTML::Entities::decode_entities($_);
-                       print $_;
-               }
-       close( $handle );
+sub gettac() {
+       my @tac = ();
+
+       open(my $handle, "<:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!");
+       while(<$handle>) {
+               $_ = HTML::Entities::decode_entities($_);
+               push(@tac, $_);
+       }
+       close($handle);
+
+       my $tac = join("\n", @tac);
+
+       # Format paragraphs
+       $tac =~ s/\n\n/<\/p>\n<p>/g;
+
+       return $tac;
 }