summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2015-07-30 10:13:25 -0400
committerjim-p <jimp@pfsense.org>2015-07-30 10:15:10 -0400
commit79e46ebda9eb3b92fc911fd82ef3b701ef3a64da (patch)
tree0cf4b2058f522ae7aa796cd7870f38e363ba21ff
parentf688185c9fd30b65fcd550d5346cdf514f051801 (diff)
downloadpfsense-79e46ebda9eb3b92fc911fd82ef3b701ef3a64da.zip
pfsense-79e46ebda9eb3b92fc911fd82ef3b701ef3a64da.tar.gz
Reinitialize the captive portal database for a zone if it is corrupt/unreadable. Fixes #4904
-rw-r--r--etc/inc/captiveportal.inc34
1 files changed, 24 insertions, 10 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc
index 3d29791..dd4f35a 100644
--- a/etc/inc/captiveportal.inc
+++ b/etc/inc/captiveportal.inc
@@ -1404,16 +1404,30 @@ function radius($username, $password, $clientip, $clientmac, $type, $radiusctx =
function captiveportal_opendb() {
global $g, $cpzone;
- $DB = new SQLite3("{$g['vardb_path']}/captiveportal{$cpzone}.db");
- if (! $DB->exec("CREATE TABLE IF NOT EXISTS captiveportal (" .
- "allow_time INTEGER, pipeno INTEGER, ip TEXT, mac TEXT, username TEXT, " .
- "sessionid TEXT, bpassword TEXT, session_timeout INTEGER, idle_timeout INTEGER, " .
- "session_terminate_time INTEGER, interim_interval INTEGER, radiusctx TEXT); " .
- "CREATE UNIQUE INDEX IF NOT EXISTS idx_active ON captiveportal (sessionid, username); " .
- "CREATE INDEX IF NOT EXISTS user ON captiveportal (username); " .
- "CREATE INDEX IF NOT EXISTS ip ON captiveportal (ip); " .
- "CREATE INDEX IF NOT EXISTS starttime ON captiveportal (allow_time)")) {
- captiveportal_syslog("Error during table {$cpzone} creation. Error message: {$DB->lastErrorMsg()}");
+ $db_path = "{$g['vardb_path']}/captiveportal{$cpzone}.db";
+ $createquery = "CREATE TABLE IF NOT EXISTS captiveportal (" .
+ "allow_time INTEGER, pipeno INTEGER, ip TEXT, mac TEXT, username TEXT, " .
+ "sessionid TEXT, bpassword TEXT, session_timeout INTEGER, idle_timeout INTEGER, " .
+ "session_terminate_time INTEGER, interim_interval INTEGER, radiusctx TEXT); " .
+ "CREATE UNIQUE INDEX IF NOT EXISTS idx_active ON captiveportal (sessionid, username); " .
+ "CREATE INDEX IF NOT EXISTS user ON captiveportal (username); " .
+ "CREATE INDEX IF NOT EXISTS ip ON captiveportal (ip); " .
+ "CREATE INDEX IF NOT EXISTS starttime ON captiveportal (allow_time)";
+
+ $DB = new SQLite3($db_path);
+ if (! $DB->exec($createquery)) {
+ captiveportal_syslog("Error during table {$cpzone} creation. Error message: {$DB->lastErrorMsg()}. Resetting and trying again.");
+
+ /* If unable to initialize the database, reset and try again. */
+ $DB->close();
+ unset($DB);
+ unlink_if_exists($db_path);
+ $DB = new SQLite3($db_path);
+ if ($DB->exec($createquery)) {
+ captiveportal_syslog("Successfully reinitialized tables for {$cpzone} -- database has been reset.");
+ } else {
+ captiveportal_syslog("Still unable to create tables for {$cpzone}. Error message: {$DB->lastErrorMsg()}. Remove the database file manually and try again.");
+ }
}
return $DB;
OpenPOWER on IntegriCloud