diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b2a2d0..30964f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: env: CI: true + NODE_ENV: test DB_USER: root DB_PASS: root diff --git a/conf.d/mysql.yml b/conf.d/mysql.yml index 1017678..56a231e 100644 --- a/conf.d/mysql.yml +++ b/conf.d/mysql.yml @@ -1,6 +1,6 @@ default: - host: 127.0.0.1 + host: localhost port: 3306 user: nictool database: nictool @@ -11,10 +11,12 @@ default: decimalNumbers: true production: + host: mysql password: "********" test: - password: NicToolTesting + user: root + password: root development: password: StaySafeOutThere diff --git a/lib/config.js b/lib/config.js index 34c28e0..a293b61 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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}`) } diff --git a/lib/group.js b/lib/group.js index 4bc2e7e..93ed4d0 100644 --- a/lib/group.js +++ b/lib/group.js @@ -1,5 +1,6 @@ const mysql = require('./mysql') +const util = require('./util') const validate = require('@nictool/nt-validate') class Group { diff --git a/lib/mysql.js b/lib/mysql.js index d004681..ab7b729 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -1,6 +1,7 @@ // const crypto = require('crypto') const mysql = require('mysql2/promise') +const util = require('./util') const config = require('./config') class MySQL { diff --git a/lib/session.js b/lib/session.js index 190ac49..15e8102 100644 --- a/lib/session.js +++ b/lib/session.js @@ -1,6 +1,7 @@ // const crypto = require('crypto') // const { createHmac, pbkdf2 } = require('node:crypto') +const util = require('./util') const Mysql = require('./mysql') // const User = require('./user') diff --git a/lib/user.js b/lib/user.js index c2ce2ce..5e6a53d 100644 --- a/lib/user.js +++ b/lib/user.js @@ -1,6 +1,7 @@ // const crypto = require('crypto') const { createHmac, pbkdf2 } = require('node:crypto') +const util = require('./util') const mysql = require('./mysql') const validate = require('@nictool/nt-validate') diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000..c4a3ee8 --- /dev/null +++ b/lib/util.js @@ -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 +// } diff --git a/routes/base.js b/routes/base.js deleted file mode 100644 index 6bc8175..0000000 --- a/routes/base.js +++ /dev/null @@ -1,10 +0,0 @@ -// exports.meta = { -// api: { -// version: require('../package.json').version, -// } -// } - -// exports.asInt = function (i) { -// if (parseInt(i, 10)) return parseInt(i, 10) -// return -// } diff --git a/sql/01_nt_group.sql b/sql/01_nt_group.sql new file mode 100644 index 0000000..16a5e78 --- /dev/null +++ b/sql/01_nt_group.sql @@ -0,0 +1,50 @@ +# +# Copyright 2001 Dajoba, LLC - +# 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); diff --git a/sql/02_nt_user.sql b/sql/02_nt_user.sql new file mode 100644 index 0000000..7e79d1b --- /dev/null +++ b/sql/02_nt_user.sql @@ -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; diff --git a/sql/04_nt_nameserver.sql b/sql/04_nt_nameserver.sql new file mode 100644 index 0000000..2e4841f --- /dev/null +++ b/sql/04_nt_nameserver.sql @@ -0,0 +1,101 @@ +# +# Copyright 2001 Dajoba, LLC - +# 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; \ No newline at end of file diff --git a/sql/06_resource_records.sql b/sql/06_resource_records.sql new file mode 100644 index 0000000..e7ae115 --- /dev/null +++ b/sql/06_resource_records.sql @@ -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); diff --git a/sql/08_nt_zone.sql b/sql/08_nt_zone.sql new file mode 100644 index 0000000..fe2ca3a --- /dev/null +++ b/sql/08_nt_zone.sql @@ -0,0 +1,77 @@ +# +# 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_zone; +CREATE TABLE nt_zone( + nt_zone_id INT UNSIGNED AUTO_INCREMENT NOT NULL, + nt_group_id INT UNSIGNED NOT NULL, + zone VARCHAR(255) NOT NULL, + mailaddr VARCHAR(127), + description VARCHAR(255), + serial INT UNSIGNED NOT NULL DEFAULT '1', + refresh INT UNSIGNED, + retry INT UNSIGNED, + expire INT UNSIGNED, + minimum INT UNSIGNED, + ttl INT UNSIGNED, + location VARCHAR(8) DEFAULT NULL, + last_modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + last_publish DATETIME DEFAULT NULL, + deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL, + PRIMARY KEY (`nt_zone_id`), + KEY `nt_zone_idx1` (`nt_group_id`), + KEY `nt_zone_idx2` (`deleted`), + KEY `nt_zone_idx3` (`zone`) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED; + + +DROP TABLE IF EXISTS nt_zone_log; +CREATE TABLE nt_zone_log( + nt_zone_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','recovered') NOT NULL, + timestamp INT UNSIGNED NOT NULL, + nt_zone_id INT UNSIGNED NOT NULL, + zone VARCHAR(255) NOT NULL, + mailaddr VARCHAR(127), + description VARCHAR(255), + serial INT UNSIGNED, + refresh INT UNSIGNED, + retry INT UNSIGNED, + expire INT UNSIGNED, + minimum INT UNSIGNED, + ttl INT UNSIGNED, + location VARCHAR(8) DEFAULT NULL, + PRIMARY KEY (`nt_zone_log_id`), + KEY `nt_zone_log_idx1` (`timestamp`), + KEY `nt_zone_log_idx2` (`nt_zone_id`), + KEY `nt_zone_log_idx3` (`action`), + KEY `nt_group_id` (`nt_group_id`), + KEY `nt_user_id` (`nt_user_id`) + /* CONSTRAINT `nt_zone_log_ibfk_3` FOREIGN KEY (`nt_user_id`) REFERENCES `nt_user` (`nt_user_id`) ON DELETE CASCADE ON UPDATE CASCADE, + ** CONSTRAINT `nt_zone_log_ibfk_1` FOREIGN KEY (`nt_zone_id`) REFERENCES `nt_zone` (`nt_zone_id`) ON DELETE CASCADE ON UPDATE CASCADE, + ** CONSTRAINT `nt_zone_log_ibfk_2` 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; + + +CREATE TABLE nt_zone_nameserver ( + nt_zone_id int(10) unsigned NOT NULL, + nt_nameserver_id smallint(5) unsigned NOT NULL, + UNIQUE KEY `zone_ns_id` (`nt_zone_id`,`nt_nameserver_id`) +) DEFAULT CHARSET=utf8mb4; diff --git a/sql/09_nt_zone_record.sql b/sql/09_nt_zone_record.sql new file mode 100644 index 0000000..0214a21 --- /dev/null +++ b/sql/09_nt_zone_record.sql @@ -0,0 +1,69 @@ +# +# 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_zone_record; +CREATE TABLE nt_zone_record( + nt_zone_record_id INT UNSIGNED AUTO_INCREMENT NOT NULL, + nt_zone_id INT UNSIGNED NOT NULL, + name VARCHAR(255) NOT NULL, + ttl INT UNSIGNED NOT NULL DEFAULT 0, + description VARCHAR(255), + type_id SMALLINT(2) UNSIGNED NOT NULL, + address VARCHAR(5120) NOT NULL, + weight SMALLINT UNSIGNED, + priority SMALLINT UNSIGNED, + other VARCHAR(512), + location VARCHAR(2) DEFAULT NULL, + timestamp timestamp NULL DEFAULT NULL, + deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL, + PRIMARY KEY (`nt_zone_record_id`), + KEY `nt_zone_record_idx1` (`name`), + KEY `nt_zone_record_idx2` (address(191)), + KEY `nt_zone_record_idx3` (`nt_zone_id`), + KEY `nt_zone_record_idx4` (`deleted`) + /* CONSTRAINT `nt_zone_record_ibfk_1` FOREIGN KEY (`nt_zone_id`) REFERENCES `nt_zone` (`nt_zone_id`) ON DELETE CASCADE ON UPDATE CASCADE */ +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED; + + +DROP TABLE IF EXISTS nt_zone_record_log; +CREATE TABLE nt_zone_record_log( + nt_zone_record_log_id INT UNSIGNED NOT NULL AUTO_INCREMENT, + nt_zone_id INT UNSIGNED NOT NULL, + nt_user_id INT UNSIGNED NOT NULL, + action ENUM('added','modified','deleted','recovered') NOT NULL, + timestamp INT UNSIGNED NOT NULL, + nt_zone_record_id INT UNSIGNED NOT NULL, + name VARCHAR(255), + ttl INT UNSIGNED, + description VARCHAR(255), + type_id SMALLINT(2) UNSIGNED NOT NULL, + address VARCHAR(5120), + weight SMALLINT UNSIGNED, + priority SMALLINT UNSIGNED, + other VARCHAR(512), + location VARCHAR(2) DEFAULT NULL, + PRIMARY KEY (`nt_zone_record_log_id`), + KEY `nt_zone_record_log_idx1` (`timestamp`), + KEY `nt_zone_record_log_idx2` (`nt_zone_record_id`), + KEY `nt_zone_record_log_idx3` (`nt_zone_id`), + KEY `nt_zone_record_log_idx4` (`action`), + KEY `nt_user_id` (`nt_user_id`) + /* CONSTRAINT `nt_zone_record_log_ibfk_3` FOREIGN KEY (`nt_zone_record_id`) REFERENCES `nt_zone_record` (`nt_zone_record_id`) ON DELETE CASCADE ON UPDATE CASCADE, + ** CONSTRAINT `nt_zone_record_log_ibfk_1` FOREIGN KEY (`nt_zone_id`) REFERENCES `nt_zone` (`nt_zone_id`) ON DELETE CASCADE ON UPDATE CASCADE, + ** CONSTRAINT `nt_zone_record_log_ibfk_2` 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; + diff --git a/sql/10_nt_perm.sql b/sql/10_nt_perm.sql new file mode 100644 index 0000000..5ab958e --- /dev/null +++ b/sql/10_nt_perm.sql @@ -0,0 +1,145 @@ +# +# 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_perm; +CREATE TABLE nt_perm( + nt_perm_id INT UNSIGNED AUTO_INCREMENT NOT NULL, + nt_group_id INT UNSIGNED DEFAULT NULL, + nt_user_id INT UNSIGNED DEFAULT NULL, + inherit_perm INT UNSIGNED DEFAULT NULL, + perm_name VARCHAR(50), + + group_write TINYINT UNSIGNED NOT NULL DEFAULT 0, + group_create TINYINT UNSIGNED NOT NULL DEFAULT 0, + #group_delegate TINYINT UNSIGNED NOT NULL DEFAULT 0, + group_delete TINYINT UNSIGNED NOT NULL DEFAULT 0, + + zone_write TINYINT UNSIGNED NOT NULL DEFAULT 0, + zone_create TINYINT UNSIGNED NOT NULL DEFAULT 0, + zone_delegate TINYINT UNSIGNED NOT NULL DEFAULT 0, + zone_delete TINYINT UNSIGNED NOT NULL DEFAULT 0, + + zonerecord_write TINYINT UNSIGNED NOT NULL DEFAULT 0, + zonerecord_create TINYINT UNSIGNED NOT NULL DEFAULT 0, + zonerecord_delegate TINYINT UNSIGNED NOT NULL DEFAULT 0, + zonerecord_delete TINYINT UNSIGNED NOT NULL DEFAULT 0, + + user_write TINYINT UNSIGNED NOT NULL DEFAULT 0, + user_create TINYINT UNSIGNED NOT NULL DEFAULT 0, + user_delete TINYINT UNSIGNED NOT NULL DEFAULT 0, + + nameserver_write TINYINT UNSIGNED NOT NULL DEFAULT 0, + nameserver_create TINYINT UNSIGNED NOT NULL DEFAULT 0, + nameserver_delete TINYINT UNSIGNED NOT NULL DEFAULT 0, + + self_write TINYINT UNSIGNED NOT NULL DEFAULT 0, + + usable_ns VARCHAR(50), + + deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL, + + PRIMARY KEY (`nt_perm_id`), + KEY `nt_perm_idx1` (`nt_group_id`,`nt_user_id`), + KEY `nt_perm_idx2` (`nt_user_id`) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +INSERT into nt_perm VALUES(1,1,0,NULL,NULL,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,0); + +DROP TABLE IF EXISTS nt_delegate; +CREATE TABLE nt_delegate( + #nt_delegate_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, + nt_group_id INT UNSIGNED NOT NULL, + nt_object_id INT UNSIGNED NOT NULL, + nt_object_type ENUM('ZONE','ZONERECORD','NAMESERVER','USER','GROUP') NOT NULL , + delegated_by_id INT UNSIGNED NOT NULL, + delegated_by_name VARCHAR(50), + + perm_write TINYINT UNSIGNED DEFAULT 1 NOT NULL, + perm_delete TINYINT UNSIGNED DEFAULT 1 NOT NULL, + perm_delegate TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + zone_perm_add_records TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_delete_records TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + # more specific access perms --- not used yet + + zone_perm_modify_zone TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_mailaddr TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_desc TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_minimum TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_serial TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_refresh TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_retry TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_expire TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_ttl TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_nameservers TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + zonerecord_perm_modify_name TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_type TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_addr TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_weight TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_ttl TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_desc TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL, + KEY `nt_delegate_idx1` (`nt_group_id`,`nt_object_id`,`nt_object_type`), + KEY `nt_delegate_idx2` (`nt_object_id`,`nt_object_type`) + /* CONSTRAINT `nt_delegate_ibfk_1` FOREIGN KEY (`nt_group_id`) REFERENCES `nt_group` (`nt_group_id`) ON DELETE CASCADE ON UPDATE CASCADE */ +); + + +DROP TABLE IF EXISTS nt_delegate_log; +CREATE TABLE nt_delegate_log( + nt_delegate_log_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + nt_user_id INT UNSIGNED NOT NULL, + nt_user_name VARCHAR(50), + action ENUM('delegated','modified','deleted') NOT NULL, + nt_object_type ENUM('ZONE','ZONERECORD','NAMESERVER','USER','GROUP') NOT NULL , + nt_object_id INT UNSIGNED NOT NULL, + nt_group_id INT UNSIGNED NOT NULL, + timestamp INT UNSIGNED NOT NULL, + + perm_write TINYINT UNSIGNED DEFAULT 1 NOT NULL, + perm_delete TINYINT UNSIGNED DEFAULT 1 NOT NULL, + perm_delegate TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + zone_perm_add_records TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_delete_records TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + # more specific access perms --- not used yet + + zone_perm_modify_zone TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_mailaddr TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_desc TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_minimum TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_serial TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_refresh TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_retry TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_expire TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_ttl TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zone_perm_modify_nameservers TINYINT UNSIGNED DEFAULT 1 NOT NULL, + + zonerecord_perm_modify_name TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_type TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_addr TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_weight TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_ttl TINYINT UNSIGNED DEFAULT 1 NOT NULL, + zonerecord_perm_modify_desc TINYINT UNSIGNED DEFAULT 1 NOT NULL + + #delegating groups: not implemented yet + #group_perm_modify_name TINYINT UNSIGNED DEFAULT 1 NOT NULL, +); diff --git a/sql/12_nt_options.sql b/sql/12_nt_options.sql new file mode 100644 index 0000000..107cf8c --- /dev/null +++ b/sql/12_nt_options.sql @@ -0,0 +1,16 @@ +# Copyright 2004-2024 The Network People, Inc. + +DROP TABLE IF EXISTS nt_options; +CREATE TABLE nt_options ( + option_id int(11) unsigned NOT NULL auto_increment, + option_name varchar(64) NOT NULL default '', + option_value text NOT NULL, + PRIMARY KEY (`option_id`), + UNIQUE KEY `option_name` (`option_name`) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +INSERT INTO `nt_options` +VALUES (1,'db_version','2.34'), + (2,'session_timeout','45'), + (3,'default_group','NicTool') + ; diff --git a/sql/90_nt_summary.sql b/sql/90_nt_summary.sql new file mode 100644 index 0000000..9840616 --- /dev/null +++ b/sql/90_nt_summary.sql @@ -0,0 +1,30 @@ +# +# 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_group_summary; +DROP TABLE IF EXISTS nt_group_current_summary; +DROP TABLE IF EXISTS nt_nameserver_general_summary; +DROP TABLE IF EXISTS nt_nameserver_summary; +DROP TABLE IF EXISTS nt_nameserver_current_summary; +DROP TABLE IF EXISTS nt_user_general_summary; +DROP TABLE IF EXISTS nt_user_summary; +DROP TABLE IF EXISTS nt_user_current_summary; +DROP TABLE IF EXISTS nt_zone_general_summary; +DROP TABLE IF EXISTS nt_zone_summary; +DROP TABLE IF EXISTS nt_zone_current_summary; +DROP TABLE IF EXISTS nt_zone_record_summary; +DROP TABLE IF EXISTS nt_zone_record_current_summary; diff --git a/test/.setup.js b/test/.setup.js index cb2c262..90f0a31 100644 --- a/test/.setup.js +++ b/test/.setup.js @@ -1,3 +1,5 @@ + +const util = require('../lib/util') const group = require('../lib/group') // const session = require('../lib/session') const user = require('../lib/user') diff --git a/test/config.js b/test/config.js index 51fd54c..8196357 100644 --- a/test/config.js +++ b/test/config.js @@ -28,10 +28,10 @@ describe('config', function () { }) const mysqlCfg = { - host: '127.0.0.1', + host: 'localhost', port: 3306, - user: 'nictool', - password: 'NicToolTesting', + user: 'root', + password: 'root', database: 'nictool', timezone: '+00:00', dateStrings: ['DATETIME', 'TIMESTAMP'], diff --git a/test/mysql.js b/test/mysql.js index 5d28c45..9f3c66a 100644 --- a/test/mysql.js +++ b/test/mysql.js @@ -3,8 +3,6 @@ const { describe, it } = require('node:test') const mysql = require('../lib/mysql') -process.env.NODE_ENV = 'test' - describe('mysql', () => { it('connects', async () => { this.dbh = await mysql.connect()