Skip to content

Commit

Permalink
bring in SQL schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Feb 18, 2024
1 parent 28130f5 commit 678fbe2
Show file tree
Hide file tree
Showing 21 changed files with 665 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

env:
CI: true
NODE_ENV: test
DB_USER: root
DB_PASS: root

Expand Down
6 changes: 4 additions & 2 deletions conf.d/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

default:
host: 127.0.0.1
host: localhost
port: 3306
user: nictool
database: nictool
Expand All @@ -11,10 +11,12 @@ default:
decimalNumbers: true

production:
host: mysql
password: "********"

test:
password: NicToolTesting
user: root
password: root

development:
password: StaySafeOutThere
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class config {
constructor(opts = {}) {
this.cfg = {}
this.debug = process.env.NODE_DEBUG ? true : false
this.env = process.env.NODE_ENV ?? opts.env ?? 'development'
this.env = process.env.NODE_ENV ?? opts.env
if (this.debug) console.log(`debug: true, env: ${this.env}`)
}

Expand Down
1 change: 1 addition & 0 deletions lib/group.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const mysql = require('./mysql')

const util = require('./util')

Check failure on line 3 in lib/group.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used

Check failure on line 3 in lib/group.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used
const validate = require('@nictool/nt-validate')

class Group {
Expand Down
1 change: 1 addition & 0 deletions lib/mysql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// const crypto = require('crypto')
const mysql = require('mysql2/promise')

const util = require('./util')

Check failure on line 4 in lib/mysql.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used

Check failure on line 4 in lib/mysql.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used
const config = require('./config')

class MySQL {
Expand Down
1 change: 1 addition & 0 deletions lib/session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// const crypto = require('crypto')
// const { createHmac, pbkdf2 } = require('node:crypto')

const util = require('./util')

Check failure on line 4 in lib/session.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used

Check failure on line 4 in lib/session.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used
const Mysql = require('./mysql')
// const User = require('./user')

Expand Down
1 change: 1 addition & 0 deletions lib/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// const crypto = require('crypto')
const { createHmac, pbkdf2 } = require('node:crypto')

const util = require('./util')

Check failure on line 4 in lib/user.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used

Check failure on line 4 in lib/user.js

View workflow job for this annotation

GitHub Actions / lint / lint

'util' is assigned a value but never used
const mysql = require('./mysql')

const validate = require('@nictool/nt-validate')
Expand Down
23 changes: 23 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

if (process.env.NODE_ENV === undefined) {
switch (require('os').hostname()) {
case 'mbp.simerson.net':
case 'imac27.simerson.net':
process.env.NODE_ENV = 'development'
break
default:
process.env.NODE_ENV = 'test'
}
console.log(`NODE_ENV: ${process.env.NODE_ENV}`)
}

// exports.meta = {
// api: {
// version: require('../package.json').version,
// }
// }

// exports.asInt = function (i) {
// if (parseInt(i, 10)) return parseInt(i, 10)
// return
// }
10 changes: 0 additions & 10 deletions routes/base.js

This file was deleted.

50 changes: 50 additions & 0 deletions sql/01_nt_group.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright 2001 Dajoba, LLC - <[email protected]>
# Copyright 2004-2024 The Network People, Inc.

DROP TABLE IF EXISTS nt_group;
CREATE TABLE `nt_group` (
nt_group_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
parent_group_id INT UNSIGNED NOT NULL DEFAULT 0,
name varchar(255) NOT NULL,
deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`nt_group_id`),
KEY `nt_group_idx1` (`parent_group_id`),
KEY `nt_group_idx2` (`name`(191)),
KEY `nt_group_idx3` (`deleted`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;


DROP TABLE IF EXISTS nt_group_log;
CREATE TABLE nt_group_log(
nt_group_log_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
nt_group_id INT UNSIGNED NOT NULL,
nt_user_id INT UNSIGNED NOT NULL,
action ENUM('added','modified','deleted','moved') NOT NULL,
timestamp INT UNSIGNED NOT NULL,
modified_group_id INT UNSIGNED NOT NULL,
parent_group_id INT UNSIGNED,
name VARCHAR(255),
PRIMARY KEY (`nt_group_log_id`),
KEY `nt_group_log_idx1` (`nt_group_id`),
KEY `nt_group_log_idx2` (`timestamp`)
/* CONSTRAINT `nt_group_log_ibfk_1` FOREIGN KEY (`nt_group_id`) REFERENCES `nt_group` (`nt_group_id`) ON DELETE CASCADE ON UPDATE CASCADE */
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;


DROP TABLE IF EXISTS nt_group_subgroups;
CREATE TABLE nt_group_subgroups(
nt_group_id INT UNSIGNED NOT NULL,
nt_subgroup_id INT UNSIGNED NOT NULL,
rank INT UNSIGNED NOT NULL,
KEY `nt_group_subgroups_idx1` (`nt_group_id`),
KEY `nt_group_subgroups_idx2` (`nt_subgroup_id`)
/* CONSTRAINT `nt_group_subgroups_ibfk_1` FOREIGN KEY (`nt_group_id`) REFERENCES `nt_group` (`nt_group_id`) ON DELETE CASCADE ON UPDATE CASCADE */
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

INSERT INTO `nt_group` (`nt_group_id`, `parent_group_id`, `name`)
VALUES
(1,0,'NicTool');
INSERT INTO nt_group_log(nt_group_id, nt_user_id, action, timestamp, modified_group_id, parent_group_id)
VALUES
(1, 1, 'added', UNIX_TIMESTAMP(), 1, 0);
95 changes: 95 additions & 0 deletions sql/02_nt_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Copyright 2001 Damon Edwards, Abe Shelton & Greg Schueler
# Copyright 2004-2024 The Network People, Inc.
#
# NicTool is free software; you can redistribute it and/or modify it under
# the terms of the Affero General Public License as published by Affero,
# Inc.; either version 1 of the License, or any later version.
#
# NicTool is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the Affero GPL for details.
#
# You should have received a copy of the Affero General Public License
# along with this program; if not, write to Affero Inc., 521 Third St,
# Suite 225, San Francisco, CA 94107, USA
#


DROP TABLE IF EXISTS nt_user;
CREATE TABLE nt_user(
nt_user_id INT UNSIGNED AUTO_INCREMENT NOT NULL,
nt_group_id INT UNSIGNED NOT NULL,
first_name VARCHAR(120),
last_name VARCHAR(160),
username VARCHAR(200) NOT NULL,
password VARCHAR(1020) NOT NULL,
pass_salt VARCHAR(16),
email VARCHAR(400) NOT NULL,
is_admin TINYINT(1) UNSIGNED DEFAULT NULL,
deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL,
PRIMARY KEY (`nt_user_id`),
KEY `nt_user_idx1` (`username`(191),`password`(191)),
KEY `nt_user_idx2` (`deleted`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;


DROP TABLE IF EXISTS nt_user_log;
CREATE TABLE nt_user_log(
nt_user_log_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
nt_group_id INT UNSIGNED NOT NULL,
nt_user_id INT UNSIGNED NOT NULL,
action ENUM('added','modified','deleted','moved') NOT NULL,
timestamp INT UNSIGNED NOT NULL,
modified_user_id INT UNSIGNED NOT NULL,
first_name VARCHAR(120),
last_name VARCHAR(160),
username VARCHAR(200),
password VARCHAR(1020),
pass_salt VARCHAR(16),
email VARCHAR(400)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;


DROP TABLE IF EXISTS nt_user_session;
CREATE TABLE nt_user_session(
nt_user_session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
nt_user_id INT UNSIGNED NOT NULL,
nt_user_session VARCHAR(100) NOT NULL,
last_access INT UNSIGNED NOT NULL,
PRIMARY KEY (`nt_user_session_id`),
KEY `nt_user_session_idx1` (`nt_user_id`,`nt_user_session`)
/* CONSTRAINT `nt_user_session_ibfk_1` FOREIGN KEY (`nt_user_id`) REFERENCES `nt_user` (`nt_user_id`) ON DELETE CASCADE ON UPDATE CASCADE */
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

DROP TABLE IF EXISTS nt_user_session_log;
CREATE TABLE nt_user_session_log(
nt_user_session_log_id INT UNSIGNED AUTO_INCREMENT NOT NULL,
nt_user_id INT UNSIGNED NOT NULL,
action ENUM('login','logout','timeout') NOT NULL,
timestamp INT UNSIGNED NOT NULL,
nt_user_session_id INT UNSIGNED,
nt_user_session VARCHAR(100),
PRIMARY KEY (`nt_user_session_log_id`),
KEY `nt_user_id` (`nt_user_id`)
/* CONSTRAINT `nt_user_session_log_ibfk_1` FOREIGN KEY (`nt_user_id`) REFERENCES `nt_user` (`nt_user_id`) ON DELETE CASCADE ON UPDATE CASCADE */
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

DROP TABLE IF EXISTS nt_user_global_log;
CREATE TABLE nt_user_global_log(
nt_user_global_log_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
nt_user_id INT UNSIGNED NOT NULL,
timestamp INT UNSIGNED NOT NULL,
action ENUM('added','deleted','modified','moved','recovered','delegated','modified delegation','removed delegation') NOT NULL,
object ENUM('zone','group','user','nameserver','zone_record') NOT NULL,
object_id INT UNSIGNED NOT NULL,
target ENUM('zone','group','user','nameserver','zone_record') ,
target_id INT UNSIGNED ,
target_name VARCHAR(255),
log_entry_id INT UNSIGNED NOT NULL,
title VARCHAR(255),
description VARCHAR(255),
PRIMARY KEY (`nt_user_global_log_id`),
KEY `nt_user_global_log_idx1` (`nt_user_id`)
/* CONSTRAINT `nt_user_global_log_ibfk_1` FOREIGN KEY (`nt_user_id`) REFERENCES `nt_user` (`nt_user_id`) ON DELETE CASCADE ON UPDATE CASCADE */
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;
101 changes: 101 additions & 0 deletions sql/04_nt_nameserver.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# Copyright 2001 Dajoba, LLC - <[email protected]>
# Copyright 2004-2024 The Network People, Inc.

DROP TABLE IF EXISTS nt_nameserver;
CREATE TABLE nt_nameserver(
nt_nameserver_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL,
nt_group_id INT UNSIGNED NOT NULL,
name VARCHAR(127) NOT NULL,
ttl INT UNSIGNED,
description VARCHAR(255),
address VARCHAR(127) NOT NULL,
address6 VARCHAR(127) DEFAULT NULL,
remote_login VARCHAR(127) DEFAULT NULL,
export_type_id INT UNSIGNED DEFAULT '1',
logdir VARCHAR(255),
datadir VARCHAR(255),
export_interval SMALLINT UNSIGNED,
export_serials tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
export_status varchar(255) NULL DEFAULT NULL,
deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL,
PRIMARY KEY (`nt_nameserver_id`),
KEY `nt_nameserver_idx1` (`name`),
KEY `nt_nameserver_idx2` (`deleted`),
KEY `nt_group_id` (`nt_group_id`)
/* CONSTRAINT `nt_nameserver_ibfk_1` FOREIGN KEY (`nt_group_id`) REFERENCES `nt_group` (`nt_group_id`) ON DELETE CASCADE ON UPDATE CASCADE */
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;


DROP TABLE IF EXISTS nt_nameserver_log;
CREATE TABLE nt_nameserver_log(
nt_nameserver_log_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
nt_group_id INT UNSIGNED NOT NULL,
nt_user_id INT UNSIGNED NOT NULL,
action ENUM('added','modified','deleted','moved') NOT NULL,
timestamp INT UNSIGNED NOT NULL,
nt_nameserver_id SMALLINT UNSIGNED NOT NULL,
name VARCHAR(127),
ttl INT UNSIGNED,
description VARCHAR(255),
address VARCHAR(127),
address6 VARCHAR(127),
export_type_id INT UNSIGNED DEFAULT '1',
logdir VARCHAR(255),
datadir VARCHAR(255),
export_interval SMALLINT UNSIGNED,
export_serials tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
PRIMARY KEY (`nt_nameserver_log_id`),
KEY `nt_nameserver_log_idx1` (`nt_nameserver_id`),
KEY `nt_nameserver_log_idx2` (`timestamp`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;


DROP TABLE IF EXISTS nt_nameserver_export_type;
CREATE TABLE `nt_nameserver_export_type` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(16) NOT NULL DEFAULT '',
`descr` varchar(56) NOT NULL DEFAULT '',
`url` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8mb4;

INSERT INTO `nt_nameserver_export_type` (`id`, `name`, `descr`, `url`)
VALUES (1,'djbdns','djbdns (tinydns & axfrdns)','cr.yp.to/djbdns.html'),
(2,'bind','BIND (zone files)', 'www.isc.org/downloads/bind/'),
(3,'maradns','MaraDNS', 'maradns.samiam.org'),
(4,'powerdns','PowerDNS','www.powerdns.com'),
(5,'bind-nsupdate','BIND (nsupdate protocol)',''),
(6,'NSD','Name Server Daemon (NSD)','www.nlnetlabs.nl/projects/nsd/'),
(7,'dynect','DynECT Standard DNS','dyn.com/managed-dns/'),
(8,'knot','Knot DNS','www.knot-dns.cz');

INSERT INTO nt_nameserver(nt_group_id, name, ttl, description, address,
export_type_id, logdir, datadir, export_interval) values (1,'ns1.example.com.',86400,'ns east',
'198.93.97.188','1','/etc/tinydns-ns1/log/main/',
'/etc/tinydns-ns1/root/',120);
INSERT INTO nt_nameserver(nt_group_id, name, ttl, description, address,
export_type_id, logdir, datadir, export_interval) values (1,'ns2.example.com.',86400,'ns west',
'216.133.235.6','1','/etc/tinydns-ns2/log/main/','/etc/tinydns-ns2/root/',120);
INSERT INTO nt_nameserver(nt_group_id, name, ttl, description, address,
export_type_id, logdir, datadir, export_interval) values (1,'ns3.example.com.',86400,'ns test',
'127.0.0.1','2','/var/log', '/etc/namedb/master/',120);
INSERT INTO nt_nameserver_log(nt_group_id,nt_user_id, action, timestamp, nt_nameserver_id) VALUES (1,1,'added',UNIX_TIMESTAMP(), 1);
INSERT INTO nt_nameserver_log(nt_group_id,nt_user_id, action, timestamp, nt_nameserver_id) VALUES (1,1,'added',UNIX_TIMESTAMP(), 2);
INSERT INTO nt_nameserver_log(nt_group_id,nt_user_id, action, timestamp, nt_nameserver_id) VALUES (1,1,'added',UNIX_TIMESTAMP(), 3);

DROP TABLE IF EXISTS nt_nameserver_export_log;
CREATE TABLE nt_nameserver_export_log(
nt_nameserver_export_log_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
nt_nameserver_id SMALLINT UNSIGNED NOT NULL,
date_start timestamp NULL DEFAULT NULL,
date_end timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
copied tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
message VARCHAR(256) NULL DEFAULT NULL,
success tinyint(1) UNSIGNED NULL DEFAULT NULL,
partial tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
KEY `nt_nameserver_export_log_idx1` (`nt_nameserver_id`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

DROP TABLE IF EXISTS nt_nameserver_qlog;
DROP TABLE IF EXISTS nt_nameserver_qlogfile;
44 changes: 44 additions & 0 deletions sql/06_resource_records.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2004-2024 The Network People, Inc.

DROP TABLE IF EXISTS resource_record_type;
CREATE TABLE resource_record_type (
id smallint(2) unsigned NOT NULL,
name varchar(10) NOT NULL,
description varchar(55) NULL DEFAULT NULL,
reverse tinyint(1) UNSIGNED NOT NULL DEFAULT 1,
forward tinyint(1) UNSIGNED NOT NULL DEFAULT 1,
obsolete tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE `name` (`name`)
) DEFAULT CHARSET=utf8mb4;

INSERT INTO `resource_record_type` (`id`, `name`, `description`, `reverse`, `forward`, `obsolete`)
VALUES
(1,'A','Address',1,1,0),
(2,'NS','Name Server',1,1,0),
(5,'CNAME','Canonical Name',1,1,0),
(6,'SOA','Start Of Authority',0,0,0),
(12,'PTR','Pointer',1,0,0),
(13,'HINFO','Host Info',0,0,1),
(15,'MX','Mail Exchanger',0,1,0),
(16,'TXT','Text',1,1,0),
(24,'SIG','Signature',0,0,0),
(25,'KEY','Key',0,0,0),
(28,'AAAA','Address IPv6',0,1,0),
(29,'LOC','Location',0,1,0),
(30,'NXT','Next',0,0,1),
(33,'SRV','Service',0,1,0),
(35,'NAPTR','Naming Authority Pointer',1,1,0),
(39,'DNAME','Delegation Name',0,0,0),
(43,'DS','Delegation Signer',1,1,0),
(44,'SSHFP','Secure Shell Key Fingerprints',0,1,0),
(46,'RRSIG','Resource Record Signature',0,1,0),
(47,'NSEC','Next Secure',0,1,0),
(48,'DNSKEY','DNS Public Key',0,1,0),
(50,'NSEC3','Next Secure v3',0,0,0),
(51,'NSEC3PARAM','NSEC3 Parameters',0,0,0),
(99,'SPF','Sender Policy Framework',0,0,1),
(250,'TSIG','Transaction Signature',0,0,0),
(252,'AXFR',NULL,0,0,0),
(256,'URI','URI',0,1,0),
(257,'CAA','Certification Authority Authorization',0,1,0);
Loading

0 comments on commit 678fbe2

Please sign in to comment.