-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_dns_server.js
82 lines (72 loc) · 2.83 KB
/
win_dns_server.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
79
80
81
82
/** Depencies **/
var DnsCmd = global.requireCached(global.path('/rpc_modules/win_dns_server/dns_cmd.js')),
PlatinToken = global.requireCached(global.path('/lib/platin-token.js'));
/**
* Check Dns Service Command
*/
module.exports._before = function(req, res, next, args) {
DnsCmd.Test(function(error){
if (error instanceof Error) return res.status(500).end(error.message);
PlatinToken.control(req, 'win_dns_server', function(error){
if (error instanceof Error) return res.parseError(error);
next();
});
});
};
/**
* List Of Dns Zones
*/
module.exports.index = function(req, res, next, args) {
DnsCmd.Zones(function(error, zones){
if (error) return res.parseError(error.message);
return res.json(zones);
});
};
/**
* Get Zone Info
*/
module.exports.read = function(req, res, next, args) {
if (!req.body.hasOwnProperty('zone')) return res.parseError(global.error('Zone require', 400));
var type = req.body.hasOwnProperty('type') ? req.body['type'].toUpperCase() : undefined;
if (type && (Object.keys(DnsCmd.RecordTypes)).indexOf(req.body['type'].toUpperCase()) == -1) return res.parseError(global.error('Unsupported type \'' + type + '\'', 400));
DnsCmd.Records(req.body['zone'], function(error, records){
if (error) return res.parseError(error);
if (type && records.hasOwnProperty(type.toLocaleLowerCase())) return res.json(records[type.toLocaleLowerCase()]);
if (type && !records.hasOwnProperty(type.toLocaleLowerCase())) return res.parseError(global.error(type + ' record not found!', 404))
return res.json(records);
});
};
/**
* Create New Zone
*/
module.exports.create = function(req, res, next, args) {
if (!req.body.hasOwnProperty('zone')) return res.parseError(global.error('Zone require', 400));
DnsCmd.Create(req.body['zone'], function(error, records){
if (error) return res.parseError(error);
return res.json(records);
});
};
/**
* Create New Zone Record
*/
module.exports.record_create = function(req, res, next, args) {
if (!req.body.hasOwnProperty('zone')) return res.parseError(global.error('Zone require', 400));
if (!req.body.hasOwnProperty('type')) return res.parseError(global.error('Type require', 400));
var Record = DnsCmd.CreateRecord(req.body.type, req.body);
if (Record instanceof Error) return res.parseError(Record);
DnsCmd.RecordAdd(req.body['zone'], Record, function(error, result){
if (error) return res.parseError(error);
return res.json(Record);
});
};
/**
* Delete Zone
*/
module.exports.delete = function(req, res, next, args) {
//res.status(200).end('Not Allowed');
if (!req.body.hasOwnProperty('zone')) return res.parseError(global.error('Zone require', 400));
DnsCmd.Delete(req.body['zone'], function(error, deleted){
if (error) return res.parseError(Record);
return res.json({deleted: deleted});
});
};