summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcello Coutinho <marcellocoutinho@gmail.com>2016-08-25 16:58:01 -0300
committerRenato Botelho <garga@FreeBSD.org>2016-09-02 18:05:53 -0300
commitf0f52fbb0922710aa7e565b9aa9db05f6c73dba9 (patch)
treeb9b834c2040dd449876f3ffd9b9307485c4a5dcb
parent92dff75ab9f535f710c56285d18fe483f61db9ba (diff)
downloadFreeBSD-ports-f0f52fbb0922710aa7e565b9aa9db05f6c73dba9.zip
FreeBSD-ports-f0f52fbb0922710aa7e565b9aa9db05f6c73dba9.tar.gz
squid - fix captive portal authentication integration on 2.3.x
(cherry picked from commit d6ea46943e8e01e466acabb4f323d9950f5875a5)
-rw-r--r--www/pfSense-pkg-squid/files/usr/local/bin/check_ip.php43
1 files changed, 18 insertions, 25 deletions
diff --git a/www/pfSense-pkg-squid/files/usr/local/bin/check_ip.php b/www/pfSense-pkg-squid/files/usr/local/bin/check_ip.php
index f6686be..e6a781a 100644
--- a/www/pfSense-pkg-squid/files/usr/local/bin/check_ip.php
+++ b/www/pfSense-pkg-squid/files/usr/local/bin/check_ip.php
@@ -40,35 +40,28 @@ if (!defined(STDOUT)) {
define("STDOUT", fopen('php://stdout', 'w'));
}
while (!feof(STDIN)) {
- $line = trim(fgets(STDIN));
- $files = glob("{$g['vardb_path']}/captive.*db");
- $answer="ERR";
- foreach ($files as $file) {
- $result = squid_cp_read_db($file);
- //1419045939,1419045939,2000,2000,192.168.10.11,192.168.10.11,08:00:27:5c:e1:ee,08:00:27:5c:e1:ee,marcello,marcello,605a1f46e2d64556,605a1f46e2d64556,,,,,,,,,,,first,first
- foreach ($result as $row) {
- if ($row[4] != "" && $row[4] == $line) {
- $answer = "OK user={$row[8]}";
- break 2;
- }
+ $check_ip = trim(fgets(STDIN));
+ $dbs = glob("{$g['vardb_path']}/captiveportal*.db");
+
+ foreach ($dbs as $db) {
+ if(!strpos($db, "_radius")) {
+ $status = squid_check_ip($db, $check_ip);
+ break;
}
}
- fwrite(STDOUT, "{$answer}\n");
+ if (isset($status)) {
+ fwrite(STDOUT, "OK user={$status}\n");
+ } else {
+ fwrite(STDOUT, "ERR\n");
+ }
}
-/* read captive portal DB into array */
-function squid_cp_read_db($file) {
- $cpdb = array();
- $DB = new SQLite3($file);
- if ($DB) {
- $response = $DB->query("SELECT * FROM captiveportal");
- if ($response != FALSE) {
- while ($row = $response->fetchArray()) {
- $cpdb[] = $row;
- }
- }
- $DB->close();
+
+function squid_check_ip($db, $check_ip) {
+ exec("sqlite3 {$db} \"SELECT ip FROM captiveportal WHERE ip='{$check_ip}'\"", $ip);
+ if ($check_ip == $ip[0]) {
+ exec("sqlite3 {$db} \"SELECT username FROM captiveportal WHERE ip='{$check_ip}'\"", $user);
+ return $user[0];
}
- return $cpdb;
}
?>
OpenPOWER on IntegriCloud