Skip to content
This repository was archived by the owner on Mar 17, 2018. It is now read-only.

Commit c217098

Browse files
authored
Merge pull request #8 from TehSatoshi3/master
Solves #5 and internal issues.
2 parents f4b2cb4 + 4d282ee commit c217098

File tree

3,455 files changed

+266
-494348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,455 files changed

+266
-494348
lines changed
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,63 @@
22
logs
33
*.log
44
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
57

68
# Runtime data
79
pids
810
*.pid
911
*.seed
12+
*.pid.lock
1013

1114
# Directory for instrumented libs generated by jscoverage/JSCover
1215
lib-cov
1316

1417
# Coverage directory used by tools like istanbul
1518
coverage
1619

20+
# nyc test coverage
21+
.nyc_output
22+
1723
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
1824
.grunt
1925

26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
2029
# node-waf configuration
2130
.lock-wscript
2231

2332
# Compiled binary addons (http://nodejs.org/api/addons.html)
2433
build/Release
2534

26-
# Dependency directory
27-
node_modules
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
2841

2942
# Optional npm cache directory
3043
.npm
3144

45+
# Optional eslint cache
46+
.eslintcache
47+
3248
# Optional REPL history
3349
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# Config file
61+
config.json
62+
63+
# MongoDB
64+
data

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# cesium
2+
A domain registry system, coded in Node.js
3+
4+
## Usage
5+
1. Install nodejs, MySQL server, MongoDB.
6+
2. Run `npm install`
7+
3. Prepare the database
8+
* Install PowerDNS (or run `mysql -u [username] -p [password] -D [name of the database] < _schema_test.sql`)
9+
* Run `mysql -u [username] -p [password] -D [name of the database] < _schema_extra.sql`
10+
4. Set up the config
11+
5. Run `node app.js`
12+
6. Voilà!
13+
14+
## Configuration file
15+
The example file is `config.json.example`.
16+
17+
### Web --web--
18+
| key | value type | details |
19+
| --- | --- | --- |
20+
| port | integer | the port on which the Express server should run on |
21+
22+
### Database --database--
23+
_(MySQL connection)_
24+
25+
| key | value type | details |
26+
| --- | --- | --- |
27+
| host | string | the host of the MySQL server |
28+
| user | string | the username of the MySQL server |
29+
| password | string | the password of the MySQL server |
30+
| database | string | the name of the database |
31+
32+
## TODO
33+
- Fix all issues
34+
- Restructure the project
35+
- Clean the mess
36+

_schema_extra.sql

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Courtesy of @theos-space
2+
CREATE TABLE user_to_domain (
3+
id INT AUTO_INCREMENT,
4+
user VARCHAR(255),
5+
domain VARCHAR(255),
6+
nameserver VARCHAR(255),
7+
PRIMARY KEY (id)
8+
) Engine=InnoDB;
9+

_schema_pdns.sql

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
CREATE TABLE domains (
2+
id INT AUTO_INCREMENT,
3+
name VARCHAR(255) NOT NULL,
4+
master VARCHAR(128) DEFAULT NULL,
5+
last_check INT DEFAULT NULL,
6+
type VARCHAR(6) NOT NULL,
7+
notified_serial INT DEFAULT NULL,
8+
account VARCHAR(40) DEFAULT NULL,
9+
PRIMARY KEY (id)
10+
) Engine=InnoDB;
11+
12+
CREATE UNIQUE INDEX name_index ON domains(name);
13+
14+
15+
CREATE TABLE records (
16+
id INT AUTO_INCREMENT,
17+
domain_id INT DEFAULT NULL,
18+
name VARCHAR(255) DEFAULT NULL,
19+
type VARCHAR(10) DEFAULT NULL,
20+
content VARCHAR(64000) DEFAULT NULL,
21+
ttl INT DEFAULT NULL,
22+
prio INT DEFAULT NULL,
23+
change_date INT DEFAULT NULL,
24+
disabled TINYINT(1) DEFAULT 0,
25+
ordername VARCHAR(255) BINARY DEFAULT NULL,
26+
auth TINYINT(1) DEFAULT 1,
27+
PRIMARY KEY (id)
28+
) Engine=InnoDB;
29+
30+
CREATE INDEX nametype_index ON records(name,type);
31+
CREATE INDEX domain_id ON records(domain_id);
32+
CREATE INDEX recordorder ON records (domain_id, ordername);
33+
34+
35+
CREATE TABLE supermasters (
36+
ip VARCHAR(64) NOT NULL,
37+
nameserver VARCHAR(255) NOT NULL,
38+
account VARCHAR(40) NOT NULL,
39+
PRIMARY KEY (ip, nameserver)
40+
) Engine=InnoDB;
41+
42+
43+
CREATE TABLE comments (
44+
id INT AUTO_INCREMENT,
45+
domain_id INT NOT NULL,
46+
name VARCHAR(255) NOT NULL,
47+
type VARCHAR(10) NOT NULL,
48+
modified_at INT NOT NULL,
49+
account VARCHAR(40) NOT NULL,
50+
comment VARCHAR(64000) NOT NULL,
51+
PRIMARY KEY (id)
52+
) Engine=InnoDB;
53+
54+
CREATE INDEX comments_domain_id_idx ON comments (domain_id);
55+
CREATE INDEX comments_name_type_idx ON comments (name, type);
56+
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
57+
58+
59+
CREATE TABLE domainmetadata (
60+
id INT AUTO_INCREMENT,
61+
domain_id INT NOT NULL,
62+
kind VARCHAR(32),
63+
content TEXT,
64+
PRIMARY KEY (id)
65+
) Engine=InnoDB;
66+
67+
CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
68+
69+
70+
CREATE TABLE cryptokeys (
71+
id INT AUTO_INCREMENT,
72+
domain_id INT NOT NULL,
73+
flags INT NOT NULL,
74+
active BOOL,
75+
content TEXT,
76+
PRIMARY KEY(id)
77+
) Engine=InnoDB;
78+
79+
CREATE INDEX domainidindex ON cryptokeys(domain_id);
80+
81+
82+
CREATE TABLE tsigkeys (
83+
id INT AUTO_INCREMENT,
84+
name VARCHAR(255),
85+
algorithm VARCHAR(50),
86+
secret VARCHAR(255),
87+
PRIMARY KEY (id)
88+
) Engine=InnoDB;
89+
90+
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);

app.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var LocalStrategy = require('passport-local').Strategy;
1111

1212
var routes = require('./routes/index');
1313
var users = require('./routes/users');
14+
var webConfig = require('./config.json').web;
1415

1516
var app = express();
1617

@@ -35,6 +36,9 @@ app.use(express.static(path.join(__dirname, 'public')));
3536

3637

3738
app.use('/', routes);
39+
var listener = app.listen(webConfig.port, function(){
40+
console.log('Listening on port ' + listener.address().port); //Listening on port 8888
41+
});
3842

3943
// passport config
4044
var Account = require('./models/account');

bin/www

-90
This file was deleted.

config.json.example

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"web": {
3+
"port": 80
4+
},
5+
"database": {
6+
"host" : "localhost",
7+
"user" : "root",
8+
"password" : "",
9+
"database" : "pdns"
10+
}
11+
}

data/WiredTiger

-2
This file was deleted.

data/WiredTiger.lock

-1
This file was deleted.

data/WiredTiger.turtle

-6
This file was deleted.

data/WiredTiger.wt

-60 KB
Binary file not shown.

data/WiredTigerLAS.wt

-4 KB
Binary file not shown.

data/_mdb_catalog.wt

-16 KB
Binary file not shown.
-16 KB
Binary file not shown.
-16 KB
Binary file not shown.
-16 KB
Binary file not shown.
Binary file not shown.

data/index-1--7826458676457691310.wt

-16 KB
Binary file not shown.

data/index-3--7826458676457691310.wt

-16 KB
Binary file not shown.

data/index-4--7826458676457691310.wt

-16 KB
Binary file not shown.

data/index-6--7826458676457691310.wt

-16 KB
Binary file not shown.

data/journal/WiredTigerLog.0000000001

-100 MB
Binary file not shown.
-100 MB
Binary file not shown.
-100 MB
Binary file not shown.

data/sizeStorer.wt

-32 KB
Binary file not shown.

data/storage.bson

-95 Bytes
Binary file not shown.

models/database.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This is in replacement of @theospace code
2+
3+
var databaseConfig = require('../config.json').database;
4+
var mysql = require('mysql');
5+
var databaseConn = mysql.createConnection(databaseConfig);
6+
7+
var database = {};
8+
9+
database.checkIfDomainValid = function(domainName) {
10+
return /(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{1,63}$)/.test(domainName)
11+
}
12+
13+
database.checkIfDomainExists = function(domainName, callback) {
14+
if (database.checkIfDomainValid(domainName)) {
15+
var query = 'SELECT * FROM `records` WHERE `name` = ?';
16+
databaseConn.query(query, [domainName], function (error, result, fields) {
17+
if (result.length > 0)
18+
callback(true, null);
19+
else
20+
callback(false, null);
21+
});
22+
} else {
23+
callback(false, new Error('The given domain name is not valid.'));
24+
}
25+
};
26+
27+
database.registerDomain = function(user, domainName, nameserver) {
28+
if (!database.checkIfDomainValid(domainName))
29+
throw new Error('The given domain name is not valid.');
30+
31+
var dateTime = Date.now();
32+
var timestamp = Math.floor(dateTime / 1000);
33+
34+
databaseConn.query('INSERT INTO `user_to_domain` (`user`, `domain`, `nameserver`) VALUES (?, ?, ?);', [user.username, domainName, nameserver], function (error, results, fields) {if (error) throw error;});
35+
databaseConn.query('INSERT INTO `records` (`id`, `domain_id`, `name`, `type`, `content`, `ttl`, `prio`, `change_date`, `disabled`, `ordername`, `auth`) VALUES (NULL, \'17\', ?, \'NS\', ?, \'86400\', \'0\', ?, \'0\', NULL, \'1\');',
36+
[domainName, nameserver, timestamp], function (error, results, fields) {if (error) throw error;});
37+
};
38+
39+
database.getAllUserDomain = function(user, callback) {
40+
databaseConn.query('SELECT `domain`, `nameserver` FROM `user_to_domain` WHERE `user` = ?', [user.username], function (error, rows, fields) {
41+
callback(error, rows, fields);
42+
});
43+
};
44+
45+
database.updateNameServer = function(user, nameserver, domain) {
46+
databaseConn.query('SELECT * FROM `user_to_domain` WHERE `user` = ? AND `domain` = ?', [user.username, domain], function(err, res, fields) {
47+
if (res.length > 0){
48+
databaseConn.query('UPDATE `user_to_domain` SET `nameserver`= ? WHERE `domain` = ?;', [nameserver, domain], function (error, results, fields) {if (error) throw error;});
49+
databaseConn.query('UPDATE `records` SET `content` = ? WHERE `records`.`name` = ?', [nameserver, domain], function (error, results, fields) {if (error) throw error;});
50+
}
51+
});
52+
};
53+
54+
module.exports = database;

node_modules/.bin/_mocha

-1
This file was deleted.

node_modules/.bin/jade

-1
This file was deleted.

0 commit comments

Comments
 (0)