Default login crediantials in config

This commit is contained in:
Deividas Raila 2024-05-07 18:11:07 +03:00
parent 65d58cfd92
commit 3b69fcf770
2 changed files with 9 additions and 3 deletions

View file

@ -27,6 +27,10 @@ $logsdirectory = "../etc";
# Location of user-database. Make sure its writeable and not served by the webserver! # Location of user-database. Make sure its writeable and not served by the webserver!
$authdb = "../etc/pdns.users.sqlite3"; $authdb = "../etc/pdns.users.sqlite3";
# Admin login and password at first start-up
$default_admin_username = "admin";
$default_admin_password = "admin";
# Set a random generated secret to enable auto-login and long living csrf tokens # Set a random generated secret to enable auto-login and long living csrf tokens
// $secret = '...'; // $secret = '...';

View file

@ -50,7 +50,7 @@ if (class_exists('SQLite3') === FALSE) {
$errormsg = "You need PHP SQLite3 to run nsedit"; $errormsg = "You need PHP SQLite3 to run nsedit";
$blocklogin = TRUE; $blocklogin = TRUE;
} }
if (function_exists('openssl_random_pseudo_bytes') === FALSE) { if (function_exists('openssl_random_pseudo_bytes') === FALSE) {
$errormsg = "You need PHP compiled with openssl to run nsedit"; $errormsg = "You need PHP compiled with openssl to run nsedit";
$blocklogin = TRUE; $blocklogin = TRUE;
@ -66,7 +66,9 @@ try {
$createsql = file_get_contents('includes/scheme.sql'); $createsql = file_get_contents('includes/scheme.sql');
$db->exec($createsql); $db->exec($createsql);
$salt = bin2hex(openssl_random_pseudo_bytes(16)); $salt = bin2hex(openssl_random_pseudo_bytes(16));
$db->exec("INSERT INTO users (emailaddress, password, isadmin) VALUES ('admin', '".crypt("admin", '$6$'.$salt)."', 1)"); $default_admin_username = $default_admin_username ?? "admin";
$default_admin_password = $default_admin_password ?? "admin";
$db->exec("INSERT INTO users (emailaddress, password, isadmin) VALUES ('".$default_admin_username."', '".crypt($default_admin_password, '$6$'.$salt)."', 1)");
} }
} catch (Exception $e) { } catch (Exception $e) {
print("We have issues getting the authdb working: $e"); print("We have issues getting the authdb working: $e");
@ -187,7 +189,7 @@ function update_user($id, $isadmin, $password) {
} else { } else {
$q = $db->prepare('UPDATE users SET isadmin = ? WHERE id = ?'); $q = $db->prepare('UPDATE users SET isadmin = ? WHERE id = ?');
$q->bindValue(1, (int)(bool)$isadmin, SQLITE3_INTEGER); $q->bindValue(1, (int)(bool)$isadmin, SQLITE3_INTEGER);
$q->bindValue(2, $id, SQLITE3_INTEGER); $q->bindValue(2, $id, SQLITE3_INTEGER);
writelog("Updating settings for $username. Admin: ".(int)(bool)$isadmin); writelog("Updating settings for $username. Admin: ".(int)(bool)$isadmin);
} }
$ret = $q->execute(); $ret = $q->execute();