From f8b1131038f1a8ced102c79ed6c72ef9dc05e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ermal=20Lu=E7i?= Date: Thu, 21 May 2009 21:44:38 +0000 Subject: Make CP multi-interface capable. --- etc/inc/captiveportal.inc | 132 ++++++++++++++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 44 deletions(-) (limited to 'etc/inc/captiveportal.inc') diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc index 0093495..ef793e7 100644 --- a/etc/inc/captiveportal.inc +++ b/etc/inc/captiveportal.inc @@ -47,10 +47,32 @@ function captiveportal_configure() { global $config, $g; $captiveportallck = lock('captiveportal'); + + $cpactive = false; + if (isset($config['captiveportal']['enable'])) { + $cpips = array(); + $ifaces = get_configured_interface_list(); + $cpinterfaces = explode(",", $config['captiveportal']['interface']); + $firsttime = 0; + foreach ($cpinterfaces as $cpifgrp) { + if (!isset($ifaces[$cpifgrp])) + continue; + if ($firsttime > 0) + $cpinterface .= " or "; + $firsttime = 1; + $tmpif = get_real_interface($cpifgrp); + if (!empty($tmpif)) { + $cpinterface .= "via {$tmpif}"; + $cpips[] = get_interface_ip($cpifgrp); + } + } + if (count($cpips) > 0) { + $cpactive = true; + $cpinterface = "{ {$cpinterface} } "; + } + } - if (isset($config['captiveportal']['enable']) && - (($config['captiveportal']['interface'] == "lan") || - isset($config['interfaces'][$config['captiveportal']['interface']]['enable']))) { + if ($cpactive == true) { if ($g['booting']) echo "Starting captive portal... "; @@ -69,7 +91,7 @@ function captiveportal_configure() { mwexec("/sbin/kldload dummynet"); /* generate ipfw rules */ - $cprules = captiveportal_rules_generate(); + $cprules = captiveportal_rules_generate($cpinterface, $cpips); /* stop accounting on all clients */ captiveportal_radius_stop_all(true); @@ -276,17 +298,15 @@ EOD; mwexec("/sbin/kldunload ipfw.ko"); } - unlock($captiveportallck); + unlock($captiveportallck); return 0; } -function captiveportal_rules_generate() { +function captiveportal_rules_generate($cpif, &$cpiparray) { global $config, $g; $cpifn = $config['captiveportal']['interface']; - $cpif = get_real_interface($cpifn); - $cpip = get_interface_ip($cpifn); $lanip = get_interface_ip("lan"); /* note: the captive portal daemon inserts all pass rules for authenticated @@ -301,27 +321,27 @@ function captiveportal_rules_generate() { /* if list */ $iflist = get_configured_interface_list(); foreach ($iflist as $ifent => $ifname) { - if($cpifn == $ifname) + if(stristr($cpifn, $ifname)) continue; $int = get_real_interface($ifname); $cprules .= "add 30 set 1 skipto 50000 all from any to any in via {$int} keep-state\n"; } /* captive portal on LAN interface? */ - if ($cpifn == "lan") { + if (stristr($cpifn, "lan")) { /* add anti-lockout rules */ $cprules .= << -- cgit v1.1