Revision 79e46ebd
Added by Jim Pingle about 10 years ago
etc/inc/captiveportal.inc | ||
---|---|---|
1404 | 1404 |
function captiveportal_opendb() { |
1405 | 1405 |
global $g, $cpzone; |
1406 | 1406 |
|
1407 |
$DB = new SQLite3("{$g['vardb_path']}/captiveportal{$cpzone}.db"); |
|
1408 |
if (! $DB->exec("CREATE TABLE IF NOT EXISTS captiveportal (" . |
|
1409 |
"allow_time INTEGER, pipeno INTEGER, ip TEXT, mac TEXT, username TEXT, " . |
|
1410 |
"sessionid TEXT, bpassword TEXT, session_timeout INTEGER, idle_timeout INTEGER, " . |
|
1411 |
"session_terminate_time INTEGER, interim_interval INTEGER, radiusctx TEXT); " . |
|
1412 |
"CREATE UNIQUE INDEX IF NOT EXISTS idx_active ON captiveportal (sessionid, username); " . |
|
1413 |
"CREATE INDEX IF NOT EXISTS user ON captiveportal (username); " . |
|
1414 |
"CREATE INDEX IF NOT EXISTS ip ON captiveportal (ip); " . |
|
1415 |
"CREATE INDEX IF NOT EXISTS starttime ON captiveportal (allow_time)")) { |
|
1416 |
captiveportal_syslog("Error during table {$cpzone} creation. Error message: {$DB->lastErrorMsg()}"); |
|
1407 |
$db_path = "{$g['vardb_path']}/captiveportal{$cpzone}.db"; |
|
1408 |
$createquery = "CREATE TABLE IF NOT EXISTS captiveportal (" . |
|
1409 |
"allow_time INTEGER, pipeno INTEGER, ip TEXT, mac TEXT, username TEXT, " . |
|
1410 |
"sessionid TEXT, bpassword TEXT, session_timeout INTEGER, idle_timeout INTEGER, " . |
|
1411 |
"session_terminate_time INTEGER, interim_interval INTEGER, radiusctx TEXT); " . |
|
1412 |
"CREATE UNIQUE INDEX IF NOT EXISTS idx_active ON captiveportal (sessionid, username); " . |
|
1413 |
"CREATE INDEX IF NOT EXISTS user ON captiveportal (username); " . |
|
1414 |
"CREATE INDEX IF NOT EXISTS ip ON captiveportal (ip); " . |
|
1415 |
"CREATE INDEX IF NOT EXISTS starttime ON captiveportal (allow_time)"; |
|
1416 |
|
|
1417 |
$DB = new SQLite3($db_path); |
|
1418 |
if (! $DB->exec($createquery)) { |
|
1419 |
captiveportal_syslog("Error during table {$cpzone} creation. Error message: {$DB->lastErrorMsg()}. Resetting and trying again."); |
|
1420 |
|
|
1421 |
/* If unable to initialize the database, reset and try again. */ |
|
1422 |
$DB->close(); |
|
1423 |
unset($DB); |
|
1424 |
unlink_if_exists($db_path); |
|
1425 |
$DB = new SQLite3($db_path); |
|
1426 |
if ($DB->exec($createquery)) { |
|
1427 |
captiveportal_syslog("Successfully reinitialized tables for {$cpzone} -- database has been reset."); |
|
1428 |
} else { |
|
1429 |
captiveportal_syslog("Still unable to create tables for {$cpzone}. Error message: {$DB->lastErrorMsg()}. Remove the database file manually and try again."); |
|
1430 |
} |
|
1417 | 1431 |
} |
1418 | 1432 |
|
1419 | 1433 |
return $DB; |
Also available in: Unified diff
Reinitialize the captive portal database for a zone if it is corrupt/unreadable. Fixes #4904