-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
79 lines (73 loc) · 2.58 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var flatiron = require('flatiron'),
path = require('path'),
app = flatiron.app,
cliff = require('cliff');
app.config.file({ file: path.join(__dirname, 'config', 'config.json') });
app.use(flatiron.plugins.cli, {
source: path.join(__dirname, 'lib', 'commands'),
usage: [
"domains [list|add|remove]",
"domains list [<name> [<type> [<ttl> [<created_at>]]]] : List all domains matching the parameters",
"domains add <domain.tld> [<type> [<ttl>]] [--soa [<soa_content>]] [--mx [<mx_content>]] [--ns [<ns_content>]] : Add a new domain",
"\t --soa : Generate a default SOA record",
"\t --soa=<soa_content> : Generate a SOA record using <soa_content>",
"\t --mx : Generate a default MX record",
"\t --mx=<mx_content> : Generate an MX record using <mx_content>",
"\t --ns : Generate a default NS record",
"\t --ns=<ns_content> : Generate an NS record using <ns_content>",
"domains remove <name> [<type> [<ttl> [<created_at> [updated_at]]]] : Remove all domains matching the parameters",
"",
"records [list|add|remove] [--domain|-d]",
"records list [<name> [<type> [<content>]]] -d=<domain.tld> : List all records for domain_name matching the parameters",
"records add <name> <type> <content> [<ttl>] -d=<domain.tld> : Add a new record for <domain.tld>",
"records remove <name> [<type> [<content> [<ttl>]]] -d=<domain.tld> : Remove all records for <domain.tld> matching the parameters"
],
argv: {
domain: {
alias: 'd',
description: 'Domain to use for the records command',
string: true
},
ns: {
description: 'NameServer address when adding a new domain, default is "ns1.<domain.tld>"'
},
soa: {
description: 'Start of autority when adding a new domain, default is "ns1.<domain.tld> admin@<domain.tld> 0 10800 7200 604800 10800"'
},
mx: {
description: 'SMTP server when adding a new domain, default is "mail.<domain.tld>"'
},
}
});
app.use(require('flatiron-cli-config'));
app.start(function(err, result) {
if(err) {
console.log(err.message);
}
if(result) {
if(result.affectedRows !== undefined) {
console.log("Affected rows : "+result.affectedRows);
}
if(result.message) {
console.log(message);
}
if(typeof result == 'object' && result.constructor == Array) {
printArray(result);
} else if(typeof result == 'string') {
console.log(result);
}
}
process.exit(1);
});
function printArray(arr) {
if(arr.length == 0) return;
var keys = getKeys(arr[0]);
cliff.putObjectRows('data', arr, keys);
}
function getKeys(obj) {
var acc = [];
for(var k in obj) {
acc.push(k);
}
return acc;
}