|
|
@ -48,6 +48,16 @@ var moduleSchemas = { |
|
|
|
, challenge_type: { type: 'string' } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// the dns control modules for DDNS
|
|
|
|
, dns_oauth3_org: { |
|
|
|
name: 'dns@oauth3.org' |
|
|
|
, type: 'object' |
|
|
|
, required: [ 'token' ] |
|
|
|
, properties: { |
|
|
|
token: { type: 'string' } |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
// forward is basically the same as proxy, but specifies the relevant incoming port(s).
|
|
|
|
// only allows for the raw transport layers (TCP/UDP)
|
|
|
@ -57,6 +67,10 @@ moduleSchemas.forward.properties.ports = { type: 'array', items: portSchema }; |
|
|
|
|
|
|
|
Object.keys(moduleSchemas).forEach(function (name) { |
|
|
|
var schema = moduleSchemas[name]; |
|
|
|
if (schema.name) { |
|
|
|
name = schema.name; |
|
|
|
delete schema.name; |
|
|
|
} |
|
|
|
schema.id = '/modules/'+name; |
|
|
|
schema.required = ['id', 'type'].concat(schema.required || []); |
|
|
|
schema.properties.id = { type: 'string' }; |
|
|
@ -72,12 +86,13 @@ var moduleRefs = { |
|
|
|
, tls: [ 'proxy', 'acme' ].map(toSchemaRef) |
|
|
|
, tcp: [ 'forward' ].map(toSchemaRef) |
|
|
|
, udp: [ 'forward' ].map(toSchemaRef) |
|
|
|
, ddns: [ 'dns@oauth3.org' ].map(toSchemaRef) |
|
|
|
}; |
|
|
|
|
|
|
|
function addDomainRequirement(itemSchema) { |
|
|
|
itemSchema.required = (itemSchema.required || []).concat('domains'); |
|
|
|
itemSchema.properties = itemSchema.properties || {}; |
|
|
|
itemSchema.domains = { type: 'array', items: { type: 'string' }, minLength: 1}; |
|
|
|
itemSchema.properties.domains = { type: 'array', items: { type: 'string' }, minLength: 1}; |
|
|
|
return itemSchema; |
|
|
|
} |
|
|
|
|
|
|
@ -93,6 +108,7 @@ var domainSchema = { |
|
|
|
, properties: { |
|
|
|
tls: { type: 'array', items: { oneOf: moduleRefs.tls }} |
|
|
|
, http: { type: 'array', items: { oneOf: moduleRefs.http }} |
|
|
|
, ddns: { type: 'array', items: { oneOf: moduleRefs.ddns }} |
|
|
|
} |
|
|
|
, additionalProperties: false |
|
|
|
} |
|
|
@ -158,7 +174,23 @@ var mdnsSchema = { |
|
|
|
var ddnsSchema = { |
|
|
|
type: 'object' |
|
|
|
, properties: { |
|
|
|
enabled: { type: 'boolean' } |
|
|
|
loopback: { |
|
|
|
type: 'object' |
|
|
|
, required: [ 'type', 'domain' ] |
|
|
|
, properties: { |
|
|
|
type: { type: 'string', const: 'tunnel@oauth3.org' } |
|
|
|
, domain: { type: 'string'} |
|
|
|
} |
|
|
|
} |
|
|
|
, tunnel: { |
|
|
|
type: 'object' |
|
|
|
, required: [ 'type', 'token' ] |
|
|
|
, properties: { |
|
|
|
type: { type: 'string', const: 'tunnel@oauth3.org' } |
|
|
|
, token: { type: 'string'} |
|
|
|
} |
|
|
|
} |
|
|
|
, modules: { type: 'array', items: { oneOf: moduleRefs.ddns }} |
|
|
|
} |
|
|
|
}; |
|
|
|
var socks5Schema = { |
|
|
@ -265,6 +297,7 @@ class DomainList extends IdList { |
|
|
|
dom.modules = { |
|
|
|
http: new ModuleList((dom.modules || {}).http) |
|
|
|
, tls: new ModuleList((dom.modules || {}).tls) |
|
|
|
, ddns: new ModuleList((dom.modules || {}).ddns) |
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
@ -280,14 +313,16 @@ class DomainList extends IdList { |
|
|
|
var modLists = { |
|
|
|
http: new ModuleList() |
|
|
|
, tls: new ModuleList() |
|
|
|
, ddns: new ModuleList() |
|
|
|
}; |
|
|
|
// We add these after instead of in the constructor to run the validation and manipulation
|
|
|
|
// in the ModList add function since these are all new modules.
|
|
|
|
if (dom.modules && Array.isArray(dom.modules.http)) { |
|
|
|
dom.modules.http.forEach(modLists.http.add, modLists.http); |
|
|
|
} |
|
|
|
if (dom.modules && Array.isArray(dom.modules.tls)) { |
|
|
|
dom.modules.tls.forEach(modLists.tls.add, modLists.tls); |
|
|
|
if (dom.modules) { |
|
|
|
Object.keys(modLists).forEach(function (key) { |
|
|
|
if (Array.isArray(dom.modules[key])) { |
|
|
|
dom.modules[key].forEach(modLists[key].add, modLists[key]); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
dom.id = require('crypto').randomBytes(4).toString('hex'); |
|
|
@ -306,6 +341,7 @@ class ConfigChanger { |
|
|
|
this.tls.modules = new ModuleList(this.tls.modules); |
|
|
|
this.tcp.modules = new ModuleList(this.tcp.modules); |
|
|
|
this.udp.modules = new ModuleList(this.udp.modules); |
|
|
|
this.ddns.modules = new ModuleList(this.ddns.modules); |
|
|
|
} |
|
|
|
|
|
|
|
update(update) { |
|
|
@ -314,7 +350,7 @@ class ConfigChanger { |
|
|
|
if (update.domains) { |
|
|
|
update.domains.forEach(self.domains.add, self.domains); |
|
|
|
} |
|
|
|
[ 'http', 'tls', 'tcp', 'udp' ].forEach(function (name) { |
|
|
|
[ 'http', 'tls', 'tcp', 'udp', 'ddns' ].forEach(function (name) { |
|
|
|
if (update[name] && update[name].modules) { |
|
|
|
update[name].modules.forEach(self[name].modules.add, self[name].modules); |
|
|
|
delete update[name].modules; |
|
|
|