mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-20 20:13:40 +03:00
Don't close the database connection and make it global. Also, honour the account that is set in pdns, unless its empty
This commit is contained in:
parent
92ac4576ab
commit
77192d84b1
2 changed files with 10 additions and 14 deletions
|
@ -85,10 +85,12 @@ function string_ends_with($string, $suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_db() {
|
function get_db() {
|
||||||
global $authdb;
|
global $authdb, $db;
|
||||||
|
|
||||||
$db = new SQLite3($authdb, SQLITE3_OPEN_READWRITE);
|
if (!isset($db)) {
|
||||||
$db->exec('PRAGMA foreign_keys = 1');
|
$db = new SQLite3($authdb, SQLITE3_OPEN_READWRITE);
|
||||||
|
$db->exec('PRAGMA foreign_keys = 1');
|
||||||
|
}
|
||||||
|
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,6 @@ function get_user_info($u) {
|
||||||
$q->bindValue(1, $u);
|
$q->bindValue(1, $u);
|
||||||
$result = $q->execute();
|
$result = $q->execute();
|
||||||
$userinfo = $result->fetchArray(SQLITE3_ASSOC);
|
$userinfo = $result->fetchArray(SQLITE3_ASSOC);
|
||||||
$db->close();
|
|
||||||
|
|
||||||
return $userinfo;
|
return $userinfo;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +126,6 @@ function do_db_auth($u, $p) {
|
||||||
$q->bindValue(1, $u);
|
$q->bindValue(1, $u);
|
||||||
$result = $q->execute();
|
$result = $q->execute();
|
||||||
$userinfo = $result->fetchArray(SQLITE3_ASSOC);
|
$userinfo = $result->fetchArray(SQLITE3_ASSOC);
|
||||||
$db->close();
|
|
||||||
|
|
||||||
if ($userinfo and $userinfo['password'] and (crypt($p, $userinfo['password']) === $userinfo['password'])) {
|
if ($userinfo and $userinfo['password'] and (crypt($p, $userinfo['password']) === $userinfo['password'])) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -149,7 +149,6 @@ function add_user($username, $isadmin = FALSE, $password = '') {
|
||||||
$q->bindValue(2, $password, SQLITE3_TEXT);
|
$q->bindValue(2, $password, SQLITE3_TEXT);
|
||||||
$q->bindValue(3, (int)(bool) $isadmin, SQLITE3_INTEGER);
|
$q->bindValue(3, (int)(bool) $isadmin, SQLITE3_INTEGER);
|
||||||
$ret = $q->execute();
|
$ret = $q->execute();
|
||||||
$db->close();
|
|
||||||
|
|
||||||
if ($isadmin) {
|
if ($isadmin) {
|
||||||
writelog("Added user $username as admin.");
|
writelog("Added user $username as admin.");
|
||||||
|
@ -187,7 +186,6 @@ function update_user($id, $isadmin, $password) {
|
||||||
writelog("Updating settings for $username. Admin: ".(int)(bool)$isadmin);
|
writelog("Updating settings for $username. Admin: ".(int)(bool)$isadmin);
|
||||||
}
|
}
|
||||||
$ret = $q->execute();
|
$ret = $q->execute();
|
||||||
$db->close();
|
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +203,6 @@ function delete_user($id) {
|
||||||
$q = $db->prepare('DELETE FROM users WHERE id = ?');
|
$q = $db->prepare('DELETE FROM users WHERE id = ?');
|
||||||
$q->bindValue(1, $id, SQLITE3_INTEGER);
|
$q->bindValue(1, $id, SQLITE3_INTEGER);
|
||||||
$ret = $q->execute();
|
$ret = $q->execute();
|
||||||
$db->close();
|
|
||||||
|
|
||||||
writelog("Deleted user " . $userinfo['emailaddress'] . ".");
|
writelog("Deleted user " . $userinfo['emailaddress'] . ".");
|
||||||
return $ret;
|
return $ret;
|
||||||
|
@ -241,6 +238,8 @@ function jtable_respond($records, $method = 'multiple', $msg = 'Undefined errorm
|
||||||
$jTableResult['RecordCount'] = count($records);
|
$jTableResult['RecordCount'] = count($records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db = get_db();
|
||||||
|
$db->close();
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
print json_encode($jTableResult);
|
print json_encode($jTableResult);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -290,7 +289,6 @@ function clearlogs() {
|
||||||
|
|
||||||
$db = get_db();
|
$db = get_db();
|
||||||
$q = $db->query('DELETE FROM logs;');
|
$q = $db->query('DELETE FROM logs;');
|
||||||
$db->close();
|
|
||||||
writelog("Logtable truncated.");
|
writelog("Logtable truncated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +366,6 @@ function writelog($line, $user=False) {
|
||||||
$q->bindValue(':user', $user, SQLITE3_TEXT);
|
$q->bindValue(':user', $user, SQLITE3_TEXT);
|
||||||
$q->bindValue(':log', $line, SQLITE3_TEXT);
|
$q->bindValue(':log', $line, SQLITE3_TEXT);
|
||||||
$q->execute();
|
$q->execute();
|
||||||
$db->close();
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return jtable_respond(null, 'error', $e->getMessage());
|
return jtable_respond(null, 'error', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,6 @@ function add_db_zone($zonename, $accountname) {
|
||||||
$q->bindValue(1, $zonename, SQLITE3_TEXT);
|
$q->bindValue(1, $zonename, SQLITE3_TEXT);
|
||||||
$q->bindValue(2, $accountname, SQLITE3_TEXT);
|
$q->bindValue(2, $accountname, SQLITE3_TEXT);
|
||||||
$q->execute();
|
$q->execute();
|
||||||
$db->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_db_zone($zonename) {
|
function delete_db_zone($zonename) {
|
||||||
|
@ -123,7 +122,6 @@ function delete_db_zone($zonename) {
|
||||||
$q = $db->prepare("DELETE FROM zones WHERE zone = ?");
|
$q = $db->prepare("DELETE FROM zones WHERE zone = ?");
|
||||||
$q->bindValue(1, $zonename, SQLITE3_TEXT);
|
$q->bindValue(1, $zonename, SQLITE3_TEXT);
|
||||||
$q->execute();
|
$q->execute();
|
||||||
$db->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_zone_account($zonename, $default) {
|
function get_zone_account($zonename, $default) {
|
||||||
|
@ -135,7 +133,6 @@ function get_zone_account($zonename, $default) {
|
||||||
$q->bindValue(1, $zonename, SQLITE3_TEXT);
|
$q->bindValue(1, $zonename, SQLITE3_TEXT);
|
||||||
$result = $q->execute();
|
$result = $q->execute();
|
||||||
$zoneinfo = $result->fetchArray(SQLITE3_ASSOC);
|
$zoneinfo = $result->fetchArray(SQLITE3_ASSOC);
|
||||||
$db->close();
|
|
||||||
if (isset($zoneinfo['emailaddress']) && $zoneinfo['emailaddress'] != null ) {
|
if (isset($zoneinfo['emailaddress']) && $zoneinfo['emailaddress'] != null ) {
|
||||||
return $zoneinfo['emailaddress'];
|
return $zoneinfo['emailaddress'];
|
||||||
}
|
}
|
||||||
|
@ -165,7 +162,9 @@ case "listslaves":
|
||||||
foreach ($api->listzones($q) as $sresult) {
|
foreach ($api->listzones($q) as $sresult) {
|
||||||
$zone = new Zone();
|
$zone = new Zone();
|
||||||
$zone->parse($sresult);
|
$zone->parse($sresult);
|
||||||
$zone->setAccount(get_zone_account($zone->name, 'admin'));
|
if ($zone->account == '') {
|
||||||
|
$zone->setAccount(get_zone_account($zone->name, 'admin'));
|
||||||
|
}
|
||||||
|
|
||||||
if (!check_account($zone))
|
if (!check_account($zone))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue