#!/usr/bin/perl ####################################### # OpenSplash - Wireless Captive Portal # Copyright (c) Aleksandr Melentiev # See LICENSE for copyright information ####################################### require 5.004; use Fcntl qw(:DEFAULT); use NDBM_File; # Import the configuration file require '/usr/local/opensplash/splash.cfg'; 1; # Check if UID is 0 unless ($> == 0 || $< == 0) { die "You must be root to run this daemon!\n" } open(PIDFILE,">$pidfile") or die "Can't open $pidfile: $!\n"; print PIDFILE "$$\n"; close(PIDFILE); # Add the forwarding rule system("ipfw -q add $fwdrulenum fwd $gateway tcp from $wnet to any $fwdports"); $rulenum = $fwdrulenum; if ($IPFW = "ipfw1") { ipfw1(); } # We are using ipfw version 1 sub ipfw1 { while (1) { if (-e "$dbfile.db") { tie %hash, "NDBM_File", $dbfile, O_RDWR, 0644; $ip = $hash{userip}; $time = $hash{tstamp} + $browsetime; $now = time(); $dup = `ipfw show | grep -w "$ip" | cut -f 1 -d " "`; if ($dup) { # see if timestamp is new enough... if ( $time < $now ) { # oops too old, let's kick them out... system("ipfw del $dup"); } # otherwise, just let them go on browsing... } else { if ( $now < $time ) { # if they checked in recently, let's allow them access.... $rulenum--; system("ipfw -q add $rulenum allow all from $ip to any"); } } #sleep 1; untie %hash; } sleep 1; } } # end sub exit(0);