dns and http relay with api check
This commit is contained in:
		
							parent
							
								
									ca01e3112f
								
							
						
					
					
						commit
						45800a42ec
					
				
							
								
								
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -4,6 +4,12 @@ | |||||||
|   "lockfileVersion": 1, |   "lockfileVersion": 1, | ||||||
|   "requires": true, |   "requires": true, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|  |     "@root/request": { | ||||||
|  |       "version": "1.3.10", | ||||||
|  |       "resolved": "https://registry.npmjs.org/@root/request/-/request-1.3.10.tgz", | ||||||
|  |       "integrity": "sha512-GSn8dfsGp0juJyXS9k7B/DjYm7Axe85wiCHfPs30eQ+/V6p2aqey45e1czb3ZwP+iPmzWCKXahhWnZhSDIil6w==", | ||||||
|  |       "dev": true | ||||||
|  |     }, | ||||||
|     "accepts": { |     "accepts": { | ||||||
|       "version": "1.3.6", |       "version": "1.3.6", | ||||||
|       "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.6.tgz", |       "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.6.tgz", | ||||||
|  | |||||||
| @ -29,6 +29,7 @@ | |||||||
|   "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", |   "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", | ||||||
|   "license": "MPL-2.0", |   "license": "MPL-2.0", | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|  |     "@root/request": "^1.3.10", | ||||||
|     "dig.js": "^1.3.9", |     "dig.js": "^1.3.9", | ||||||
|     "dns-suite": "^1.2.12", |     "dns-suite": "^1.2.12", | ||||||
|     "express": "^4.16.4" |     "express": "^4.16.4" | ||||||
|  | |||||||
							
								
								
									
										19
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								server.js
									
									
									
									
									
								
							| @ -3,6 +3,7 @@ | |||||||
| var crypto = require('crypto'); | var crypto = require('crypto'); | ||||||
| //var dnsjs = require('dns-suite');
 | //var dnsjs = require('dns-suite');
 | ||||||
| var dig = require('dig.js/dns-request'); | var dig = require('dig.js/dns-request'); | ||||||
|  | var request = require('util').promisify(require('@root/request')); | ||||||
| var express = require('express'); | var express = require('express'); | ||||||
| var app = express(); | var app = express(); | ||||||
| 
 | 
 | ||||||
| @ -13,7 +14,6 @@ var nameserver = nameservers[index]; | |||||||
| app.use('/', express.static('./')); | app.use('/', express.static('./')); | ||||||
| app.use('/api', express.json()); | app.use('/api', express.json()); | ||||||
| app.get('/api/dns/:domain', function (req, res, next) { | app.get('/api/dns/:domain', function (req, res, next) { | ||||||
|   console.log(req.params); |  | ||||||
|   var domain = req.params.domain; |   var domain = req.params.domain; | ||||||
|   var casedDomain = domain.toLowerCase().split('').map(function (ch) { |   var casedDomain = domain.toLowerCase().split('').map(function (ch) { | ||||||
| 		// dns0x20 takes advantage of the fact that the binary operation for toUpperCase is
 | 		// dns0x20 takes advantage of the fact that the binary operation for toUpperCase is
 | ||||||
| @ -117,12 +117,23 @@ app.get('/api/dns/:domain', function (req, res, next) { | |||||||
| 
 | 
 | ||||||
|   dig.resolveJson(query, opts); |   dig.resolveJson(query, opts); | ||||||
| }); | }); | ||||||
|  | app.get('/api/http', function (req, res) { | ||||||
|  |   var url = req.query.url; | ||||||
|  |   return request({ method: 'GET', url: url }).then(function (resp) { | ||||||
|  |     res.send(resp.body); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
|  | app.get('/api/_acme_api_', function (req, res) { | ||||||
|  |   res.send({ success: true }); | ||||||
|  | }); | ||||||
| 
 | 
 | ||||||
| module.exports = app; | module.exports = app; | ||||||
| if (require.main === module) { | if (require.main === module) { | ||||||
|   // curl -L http://localhost:3000/api/dns/example.com?type=A
 |   // curl -L http://localhost:3000/api/dns/example.com?type=A
 | ||||||
|   console.log("Listening on localhost:3000"); |   console.info("Listening on localhost:3000"); | ||||||
|   app.listen(3000); |   app.listen(3000); | ||||||
|   console.log("Try this:"); |   console.info("Try this:"); | ||||||
|   console.log("\tcurl -L 'http://localhost:3000/api/dns/example.com?type=A'"); |   console.info("\tcurl -L 'http://localhost:3000/api/_acme_api_/'"); | ||||||
|  |   console.info("\tcurl -L 'http://localhost:3000/api/dns/example.com?type=A'"); | ||||||
|  |   console.info("\tcurl -L 'http://localhost:3000/api/http/?url=https://example.com'"); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user