forked from okTurtles/dnschain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.coffee
135 lines (108 loc) · 4.19 KB
/
config.coffee
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
###
dnschain
http://dnschain.net
Copyright (c) 2014 okTurtles Foundation
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
###
# TODO: go through 'TODO's!
###
- DNSChain configuration:
- local in ~/.dnschain.conf (or ~/.dnschain/dnschain.conf)
- global in /etc/dnschain/dnschain.conf
- Namecoin
- Non-Windows: ~/.namecoin/namecoin.conf
- Windows: %APPDATA%\Namecoin\namecoin.conf
All parametrs can be overwritten using command line args and/or environment variables.
###
nconf = require 'nconf'
props = require 'properties'
fs = require 'fs'
tty = require 'tty'
module.exports = (dnschain) ->
# expose these into our namespace
for k of dnschain.globals
eval "var #{k} = dnschain.globals.#{k};"
# TODO: add path to our private key for signing answers
amRoot = process.getuid() is 0
defaults =
log:
level: if process.env.DNS_EXAMPLE then 'debug' else 'info'
colors: true
pretty: tty.isatty process.stdout
timestamp: tty.isatty process.stdout
dns:
port: if amRoot then 53 else 5333
host: '0.0.0.0' # what we bind to
externalIP: gExternalIP() # Advertised IP for .dns metaTLD (ex: namecoin.dns)
oldDNSMethod: 'NATIVE_DNS' # see 'globals.coffee' for possible values
oldDNS:
address: '8.8.8.8' # Google (we recommend running PowerDNS yourself and sending it there)
port: 53
type: 'udp'
http:
port: if amRoot then 80 else 8088
tlsPort: if amRoot then 443 else 4443
host: '0.0.0.0' # what we bind to
nmcDefs =
rpcport: 8336
rpcconnect: '127.0.0.1'
rpcuser: undefined
rpcpassword: undefined
bdnsDefs =
rpc:
rpc_user: undefined
rpc_password: undefined
httpd_endpoint: undefined
fileFormatOpts =
comments: ['#', ';']
sections: true
namespaces: true
props.parse = _.partialRight props.parse, fileFormatOpts
props.stringify = _.partialRight props.stringify, fileFormatOpts
# load our config
appname = "dnschain"
nconf.argv().env()
if process.env.HOME?
dnscConf = path.join process.env.HOME, ".#{appname}.conf"
unless fs.existsSync dnscConf
dnscConf = path.join process.env.HOME, ".#{appname}", "#{appname}.conf"
nconf.file 'user', {file: dnscConf, format: props}
nconf.file 'global', {file:"/etc/#{appname}/#{appname}.conf", format:props}
# TODO: this blockchain-specific config stuff should be moved out of
# this file and into the constructors (NMCPeer, BDNSPeer, etc.)
# namecoin
nmc = (new nconf.Provider()).argv().env()
# TODO: use the same _.find technique as done below for bdnsConf
nmcConf = if process.env.APPDATA?
path.join process.env.APPDATA, "Namecoin", "namecoin.conf"
else if process.env.HOME?
path.join process.env.HOME, ".namecoin", "namecoin.conf"
nmc.file('user', {file:nmcConf,format:props}) if nmcConf
# bdns
bdns = (new nconf.Provider()).argv().env()
bdnsConf = _.find _.filter([
[process.env.APPDATA, "KeyID"],
[process.env.HOME, ".KeyID"],
[process.env.HOME, "Library", "Application Support", "KeyID"]]
, (x) -> !!x[0])
, (x) -> fs.existsSync path.join x...
if bdnsConf
bdns.file 'user', file: path.join(bdnsConf..., 'config.json')
else
# TODO: this!
stores =
dnschain: nconf.defaults defaults
nmc: nmc.defaults nmcDefs
bdns: bdns.defaults bdnsDefs
config =
get: (key, store="dnschain") -> stores[store].get key
set: (key, value, store="dnschain") -> stores[store].set key, value
# Namecoin's config is not ours, so we don't pretend it is
nmc:
get: (key)-> config.get key, 'nmc'
set: (key, value)-> config.set key, value, 'nmc'
bdns:
get: (key)-> config.get key, 'bdns'
set: (key, value)-> config.set key, value, 'bdns'