diff --git a/nodejs/controller/host.js b/nodejs/controller/host.js index d952324..ff5a591 100644 --- a/nodejs/controller/host.js +++ b/nodejs/controller/host.js @@ -9,7 +9,10 @@ const socket = new SocketServerJson({ socketFile: conf.socketFile, onData: function(data, clientSocket) { try{ - let parentHost = Host.lookUp(data['domain']) || {host: 'none'}; + console.log('socket lookup', data) + let parentHost = Host.lookUp(data['domain']); + console.log('socket found host', parentHost); + if(!parentHost) return clientSocket.write(JSON.stringify({})); if(!parentHost.wildcard_parent){ parentHost.wildcard_parent = parentHost.host; Host.addCache(data['domain'], parentHost); diff --git a/nodejs/models/host.js b/nodejs/models/host.js index 36210e7..0453899 100755 --- a/nodejs/models/host.js +++ b/nodejs/models/host.js @@ -321,11 +321,6 @@ class Host extends Table{ while(!this.__lookUpIsReady) await new Promise(r => setTimeout(r, 5)); return true; } - - static test(pass){ - return `yes ${pass}` - } - } @@ -335,19 +330,17 @@ class Cached extends Table{ 'host': {isRequired: true, type: 'string', min: 3, max: 500}, 'parent': {isRequired: true, type: 'string', min: 3, max: 500}, } - } (async function(){ - await Host.buildLookUpObj(); -})() +})(); module.exports = {Host: ModelPs(Host)}; (async function(){ try{ - // await Host.lookUpReady(); + await Host.lookUpReady(); // let res = await Host.create({ // host: '*.test.holycore.quest', // ip: '192.168.1.47', @@ -360,7 +353,8 @@ try{ // console.log('IIFE res:\n', res) // console.log(Host.test(55)) - // console.log(await Host.listDetail()) + console.log(await Host.list()) + console.log(await Cached.listDetail()) // console.log('IIFE lookup:', Host.lookUp('bld3324sdf.test.holycore.quest')) diff --git a/nodejs/views/hosts.ejs b/nodejs/views/hosts.ejs index 92719ee..255aa10 100755 --- a/nodejs/views/hosts.ejs +++ b/nodejs/views/hosts.ejs @@ -54,7 +54,7 @@ host['wildcard_text_bg'] = 'success'; host['wildcard_text'] = undefined; } - if(host['wildcard_status'].includes('failed')){ + if(host['wildcard_status'] && host['wildcard_status'].includes('failed')){ host['wildcard_text_bg'] = 'danger'; } diff --git a/ops/nginx_conf/nginx.conf b/ops/nginx_conf/nginx.conf index 271530c..e9a1f74 100644 --- a/ops/nginx_conf/nginx.conf +++ b/ops/nginx_conf/nginx.conf @@ -25,7 +25,7 @@ http { auto_ssl = (require "resty.auto-ssl").new() auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis") auto_ssl:set("allow_domain", function(domain) - return ngx.req.toAllow + return ngx.ctx.toAllow end) auto_ssl:set("request_domain", function(ssl, ssl_options) @@ -57,10 +57,10 @@ http { return ngx.exit(598) end - local res, err = red:hgetall("proxy_host_"..domain) + local res, err = red:hgetall("proxy_Host_"..domain) local res = red:array_to_hash(res) - ngx.req.targetInfo = res + ngx.ctx.targetInfo = res if not res["ip"] then if connect("/var/run/proxy_lookup.socket") then @@ -76,7 +76,7 @@ http { end end - ngx.req.targetInfo = res + ngx.ctx.targetInfo = res if not res["ip"] then ngx.log(ngx.ERR, "no host found for key ", domain) @@ -84,7 +84,7 @@ http { return false end - ngx.req.toAllow = true; + ngx.ctx.toAllow = true; if res['wildcard_parent'] then return res['wildcard_parent'], err diff --git a/ops/nginx_conf/proxy.conf b/ops/nginx_conf/proxy.conf index 7bf7c60..cb1ebfc 100644 --- a/ops/nginx_conf/proxy.conf +++ b/ops/nginx_conf/proxy.conf @@ -25,21 +25,21 @@ server { local scheme = ngx.var.scheme if scheme == "http" then - if ngx.req.targetInfo["forcessl"] == "true" then + if ngx.ctx.targetInfo["forcessl"] == "true" then return ngx.redirect("https://"..host..uri, 301) end end - if ngx.req.targetInfo["targetssl"] == "true" then + if ngx.ctx.targetInfo["targetssl"] == "true" then ngx.var.target_scheme = "https" end - if ngx.req.targetInfo["host-pass-though"] == "false" then - ngx.var.header_host = ngx.req.targetInfo["ip"] + if ngx.ctx.targetInfo["host-pass-though"] == "false" then + ngx.var.header_host = ngx.ctx.targetInfo["ip"] end - ngx.var.target = ngx.req.targetInfo["ip"] - ngx.var.target_port = ngx.req.targetInfo["targetPort"] + ngx.var.target = ngx.ctx.targetInfo["ip"] + ngx.var.target_port = ngx.ctx.targetInfo["targetPort"] ';