mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-05-24 00:24:07 +03:00
Initial import and public 'release'
This commit is contained in:
parent
327597ca02
commit
90ee4dfea0
792 changed files with 147584 additions and 0 deletions
47
htdocs/includes/config.inc.php
Normal file
47
htdocs/includes/config.inc.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
$apiuser = ''; # The PowerDNS API username
|
||||
$apipass = ''; # The PowerDNS API-user password
|
||||
$apiip = ''; # The IP of the PowerDNS API
|
||||
$apiport = '8081'; # The port of the PowerDNS API
|
||||
$apisid = ''; # PowerDNS's :server_id
|
||||
|
||||
$authdb = "../etc/pdns.users.sqlite3";
|
||||
|
||||
$templates = array();
|
||||
/*
|
||||
$templates[] = array(
|
||||
'name' => 'Tuxis',
|
||||
'owner' => 'username', # Set to 'public' to make it available to all users
|
||||
'records' => array(
|
||||
array(
|
||||
'label' => '',
|
||||
'type' => 'MX',
|
||||
'content' => 'mx2.tuxis.nl',
|
||||
'priority' => '200')
|
||||
)
|
||||
);
|
||||
*/
|
||||
|
||||
$defaults['defaulttype'] = 'Master'; # Choose between 'Native' or 'Master'
|
||||
$defaults['primaryns'] = 'unconfigured.primaryns'; # The value of the first NS-record
|
||||
$defaults['secondaryns'] = 'unconfigured.secondaryns'; # The value of the second NS-record
|
||||
$defaults['ttl'] = 3600; # Default TTL for records
|
||||
$defaults['priority'] = 0; # Default for priority in records
|
||||
|
||||
|
||||
|
||||
|
||||
/* No need to change stuf below */
|
||||
$defaults['defaulttype'] = ucfirst(strtolower($defaults['defaulttype']));
|
||||
|
||||
if (!file_exists($authdb)) {
|
||||
is_dir(dirname($authdb)) || mkdir(dirname($authdb));
|
||||
$db = new SQLite3($authdb, SQLITE3_OPEN_CREATE|SQLITE3_OPEN_READWRITE);
|
||||
$createsql = file_get_contents('scheme.sql');
|
||||
$db->exec($createsql);
|
||||
$salt = bin2hex(openssl_random_pseudo_bytes(16));
|
||||
$db->exec("INSERT INTO users (emailaddress, password, isadmin) VALUES ('admin', '".crypt("admin", '$6$'.$salt)."', 1)");
|
||||
}
|
||||
|
||||
?>
|
83
htdocs/includes/misc.inc.php
Normal file
83
htdocs/includes/misc.inc.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
include('config.inc.php');
|
||||
|
||||
function _get_db() {
|
||||
global $authdb;
|
||||
|
||||
$db = new SQLite3($authdb, SQLITE3_OPEN_READWRITE);
|
||||
$db->exec('PRAGMA foreign_keys = 1');
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
||||
function gen_pw() {
|
||||
$password = exec('/usr/bin/pwgen -s -B -c -n 10 -1');
|
||||
return $password;
|
||||
}
|
||||
|
||||
function get_all_users() {
|
||||
$db = _get_db();
|
||||
$r = $db->query('SELECT id, emailaddress, isadmin FROM users');
|
||||
$ret = array();
|
||||
while ($row = $r->fetchArray()) {
|
||||
array_push($ret, $row);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function get_pw($username) {
|
||||
$db = _get_db();
|
||||
$pw = $db->querySingle("SELECT password FROM users WHERE emailaddress = '".$username."'");
|
||||
$db->close();
|
||||
return $pw;
|
||||
}
|
||||
|
||||
function add_user($username, $isadmin = '0', $password = FALSE) {
|
||||
if ($password === FALSE or $password == "") {
|
||||
$password = get_pw($username);
|
||||
} elseif (!preg_match('/\$6\$/', $password)) {
|
||||
$salt = bin2hex(openssl_random_pseudo_bytes(16));
|
||||
$password = crypt($password, '$6$'.$salt);
|
||||
}
|
||||
|
||||
$db = _get_db();
|
||||
$ret = $db->exec("INSERT OR REPLACE INTO users (emailaddress, password, isadmin) VALUES ('".$username."', '".$password."', $isadmin)");
|
||||
$db->close();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function delete_user($id) {
|
||||
$db = _get_db();
|
||||
$ret = $db->exec("DELETE FROM users WHERE id = $id");
|
||||
$db->close();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function _jtable_respond($records, $method = 'multiple', $msg = 'Undefined errormessage') {
|
||||
$jTableResult = array();
|
||||
if ($method == 'error') {
|
||||
$jTableResult['Result'] = "ERROR";
|
||||
$jTableResult['Message'] = $msg;
|
||||
} elseif ($method == 'single') {
|
||||
$jTableResult['Result'] = "OK";
|
||||
$jTableResult['Record'] = $records;
|
||||
} elseif ($method == 'delete') {
|
||||
$jTableResult['Result'] = "OK";
|
||||
} else {
|
||||
if (isset($_GET['jtPageSize'])) {
|
||||
$jTableResult['TotalRecordCount'] = count($records);
|
||||
$records = array_slice($records, $_GET['jtStartIndex']*$_GET['jtPageSize'], $_GET['jtPageSize']);
|
||||
}
|
||||
$jTableResult['Result'] = "OK";
|
||||
$jTableResult['Records'] = $records;
|
||||
$jTableResult['RecordCount'] = count($records);
|
||||
}
|
||||
|
||||
print json_encode($jTableResult);
|
||||
exit(0);
|
||||
}
|
||||
?>
|
14
htdocs/includes/scheme.sql
Normal file
14
htdocs/includes/scheme.sql
Normal file
|
@ -0,0 +1,14 @@
|
|||
PRAGMA foreign_keys = 1;
|
||||
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
emailaddress VARCHAR UNIQUE NOT NULL,
|
||||
password VARCHAR NOT NULL,
|
||||
isadmin BOOLEAN DEFAULT FALSE);
|
||||
|
||||
CREATE TABLE zones (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
zone VARCHAR NOT NULL,
|
||||
owner INTEGER NOT NULL,
|
||||
UNIQUE(zone,owner),
|
||||
FOREIGN KEY(owner) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE );
|
58
htdocs/includes/session.inc.php
Normal file
58
htdocs/includes/session.inc.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
include_once('config.inc.php');
|
||||
include_once('misc.inc.php');
|
||||
|
||||
session_start();
|
||||
|
||||
function is_logged_in() {
|
||||
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == "true") {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function set_logged_in($login_user) {
|
||||
$_SESSION['logged_in'] = 'true';
|
||||
$_SESSION['username'] = $login_user;
|
||||
}
|
||||
|
||||
function set_is_adminuser() {
|
||||
$_SESSION['is_adminuser'] = 'true';
|
||||
}
|
||||
|
||||
function is_adminuser() {
|
||||
if (isset($_SESSION['is_adminuser']) && $_SESSION['is_adminuser'] == 'true') {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function get_sess_user() {
|
||||
return $_SESSION['username'];
|
||||
}
|
||||
|
||||
function logout() {
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
function try_login() {
|
||||
if (isset($_POST['username']) and isset($_POST['password'])) {
|
||||
$db = _get_db();
|
||||
$userinfo = $db->querySingle("SELECT * FROM users WHERE emailaddress = '".$_POST['username']."'", 1);
|
||||
if (isset($userinfo['password']) and (crypt($_POST['password'], $userinfo['password']) == $userinfo['password'])) {
|
||||
set_logged_in($_POST['username']);
|
||||
if (isset($userinfo['isadmin']) && $userinfo['isadmin'] == 1) {
|
||||
set_is_adminuser();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
$db->close();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue