Commit eac7cdde authored by Franco Fichtner's avatar Franco Fichtner

captive portal: address recent paranoia of Sqlite(); fixes #215

parent 1454f5da
...@@ -126,34 +126,36 @@ class DB ...@@ -126,34 +126,36 @@ class DB
try { try {
$this->handle = new Sqlite(array("dbname" => $db_path)); $this->handle = new Sqlite(array("dbname" => $db_path));
$sql = array();
// create structure on new database // create structure on new database
$sql = "CREATE TABLE IF NOT EXISTS captiveportal (" .# table used for authenticated users $sql[] = "CREATE TABLE IF NOT EXISTS captiveportal (" .# table used for authenticated users
"allow_time INTEGER, pipeno_in INTEGER, pipeno_out INTEGER, ip TEXT, mac TEXT, username TEXT, " . "allow_time INTEGER, pipeno_in INTEGER, pipeno_out INTEGER, ip TEXT, mac TEXT, username TEXT, " .
"sessionid TEXT, bpassword TEXT, session_timeout INTEGER, idle_timeout INTEGER, " . "sessionid TEXT, bpassword TEXT, session_timeout INTEGER, idle_timeout INTEGER, " .
"session_terminate_time INTEGER, interim_interval INTEGER, radiusctx TEXT); " . "session_terminate_time INTEGER, interim_interval INTEGER, radiusctx TEXT)";
"CREATE UNIQUE INDEX IF NOT EXISTS idx_active ON captiveportal (sessionid, username); " . $sql[] = "CREATE UNIQUE INDEX IF NOT EXISTS idx_active ON captiveportal (sessionid, username)";
"CREATE INDEX IF NOT EXISTS user ON captiveportal (username); " . $sql[] = "CREATE INDEX IF NOT EXISTS user ON captiveportal (username)";
"CREATE INDEX IF NOT EXISTS ip ON captiveportal (ip); " . $sql[] = "CREATE INDEX IF NOT EXISTS ip ON captiveportal (ip)";
"CREATE INDEX IF NOT EXISTS starttime ON captiveportal (allow_time);" . $sql[] = "CREATE INDEX IF NOT EXISTS starttime ON captiveportal (allow_time)";
"CREATE TABLE IF NOT EXISTS captiveportal_mac (" . # table used for static mac's $sql[] = "CREATE TABLE IF NOT EXISTS captiveportal_mac (" . # table used for static mac's
"mac TEXT, ip TEXT,pipeno_in INTEGER, pipeno_out INTEGER, last_checked INTEGER );" . "mac TEXT, ip TEXT,pipeno_in INTEGER, pipeno_out INTEGER, last_checked INTEGER )";
"CREATE UNIQUE INDEX IF NOT EXISTS idx_mac ON captiveportal_mac (mac) ;" . $sql[] = "CREATE UNIQUE INDEX IF NOT EXISTS idx_mac ON captiveportal_mac (mac)";
"CREATE TABLE IF NOT EXISTS captiveportal_ip (" . # table used for static ip's $sql[] = "CREATE TABLE IF NOT EXISTS captiveportal_ip (" . # table used for static ip's
"ip TEXT,pipeno_in INTEGER, pipeno_out INTEGER, last_checked INTEGER );" . "ip TEXT,pipeno_in INTEGER, pipeno_out INTEGER, last_checked INTEGER )";
"CREATE UNIQUE INDEX IF NOT EXISTS idx_ip ON captiveportal_ip (ip) " ; $sql[] = "CREATE UNIQUE INDEX IF NOT EXISTS idx_ip ON captiveportal_ip (ip)";
if (! $this->handle->execute($sql)) { foreach ($sql as $cmd) {
$logger = new Syslog("logportalauth", array( if (!$this->handle->execute($cmd)) {
'option' => LOG_PID, $logger = new Syslog("logportalauth", array(
'facility' => LOG_LOCAL4 'option' => LOG_PID,
)); 'facility' => LOG_LOCAL4
$msg = "Error during table {$this->zone} creation. Error message: {$this->handle->lastErrorMsg()}"; ));
$logger->error($msg); $msg = "Error during table {$this->zone} creation. Error message: {$this->handle->lastErrorMsg()}";
$this->handle = null; $logger->error($msg);
$this->handle = null;
break;
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$logger = new Syslog("logportalauth", array( $logger = new Syslog("logportalauth", array(
'option' => LOG_PID, 'option' => LOG_PID,
...@@ -164,7 +166,6 @@ class DB ...@@ -164,7 +166,6 @@ class DB
} }
return $this->handle; return $this->handle;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment