--- /dev/null
+_ = require 'underscore'
+url = require 'url'
+minimatch = require 'minimatch'
+request = require 'request'
+
+
+matchesList = (list, value) ->
+ for pat of list
+ return true if pat(value)
+ false
+
+ProxyMiddleware = (options={}) ->
+ {whitelist, blacklist} = options = {whitelist:[], blacklist:[], ...options}
+ whitelist .= map -> minimatch.filter it, {+nocase}
+ blacklist .= map -> minimatch.filter it, {+nocase}
+
+ return (req, res) ->
+ targetUrl = ( req.params.url or url.parse(req.url).pathname.slice(3) ).trim()
+ return res.send {error:'URL required'}, 400 unless targetUrl
+
+ targetUrl = "http://#targetUrl" unless /^https?:\/\//.test targetUrl
+ target = url.parse targetUrl, true, true
+
+ if matchesList blacklist, target.hostname
+ return res.send {error:'Domain is blacklisted'}, 403
+ unless matchesList whitelist, target.hostname
+ return res.send {error:'Domain is not whitelisted'}, 403
+
+ console.log "[Proxy] #targetUrl"
+ request.get targetUrl .pipe res
+
+
+module.exports = exports = ProxyMiddleware
+exports.ProxyMiddleware = ProxyMiddleware
app.controller require './controllers/datasource'
+# Data Proxy
+PROXY_DOMAIN_BLACKLIST = <[
+ *.ru
+]>
+PROXY_DOMAIN_WHITELIST = <[
+ wmflabs.org mediawiki.org wikimedia.org wikipedia.org
+ *.wmflabs.org *.mediawiki.org *.wikimedia.org *.wikipedia.org
+]>
+
+if NODE_ENV is 'dev'
+ PROXY_DOMAIN_WHITELIST.push 'localhost', 'github.com', '*.github.com'
+
+
+proxy = require('./proxy')({
+ blacklist: PROXY_DOMAIN_BLACKLIST
+ whitelist: PROXY_DOMAIN_WHITELIST
+})
+app.get '/x', proxy
+app.get '/x/*', proxy
+
+
+
app.get '/', (req, res) ->
- ### XXX: Temporary, while I implement backwards compat with the old data format
res.render 'dashboard'
- # res.redirect '/graphs/ohai/edit'
app.get '/geo', (req, res) ->
res.render 'geo'
dependencies :
'coco' : '>= 0.7.0'
+ 'request' : '>= 2.9.0'
+ 'underscore' : '>= 1.3.3'
+ 'underscore.string' : '>= 2.1.1'
+ 'seq' : '>= 0.3.5'
+ 'hashish' : '>= 0.0.4'
+ 'js-yaml' : '>= 0.3.5'
+ 'minimatch' : '>= 0.2.5'
+ 'glob' : '>= 3.1.9'
+ 'findit' : '>= 0.1.2'
+ 'remove' : '>= 0.1.1'
'mime' : '>= 1.2.5'
'express' : '>= 2.5.9'
'express-resource' : '>= 0.2.4'
'stylus' : '>= 0.25.0'
'nib' : '>= 0.4.0'
'browserify' : '>= 1.9.4'
- 'seq' : '>= 0.3.5'
- 'underscore' : '>= 1.3.3'
- 'underscore.string' : '>= 2.1.1'
- 'js-yaml' : '>= 0.3.5'
- 'hashish' : '>= 0.0.4'
'backbone' : '>= 0.9.1'
- 'findit' : '>= 0.1.2'
- 'glob' : '>= 3.1.9'
- 'remove' : '>= 0.1.1'
+ 'd3' : '>= 2.9.2'
+
devDependencies :
'buildtools' : 'https://github.com/dsc/node-buildtools/tarball/master'
'expresso' : '>= 0.9.2'
"author": "David Schoonover <dsc@less.ly> (http://less.ly)",
"dependencies": {
"coco": ">= 0.7.0",
+ "request": ">= 2.9.0",
+ "underscore": ">= 1.3.3",
+ "underscore.string": ">= 2.1.1",
+ "seq": ">= 0.3.5",
+ "hashish": ">= 0.0.4",
+ "js-yaml": ">= 0.3.5",
+ "minimatch": ">= 0.2.5",
+ "glob": ">= 3.1.9",
+ "findit": ">= 0.1.2",
+ "remove": ">= 0.1.1",
"mime": ">= 1.2.5",
"express": ">= 2.5.9",
"express-resource": ">= 0.2.4",
"stylus": ">= 0.25.0",
"nib": ">= 0.4.0",
"browserify": ">= 1.9.4",
- "seq": ">= 0.3.5",
- "underscore": ">= 1.3.3",
- "underscore.string": ">= 2.1.1",
- "js-yaml": ">= 0.3.5",
- "hashish": ">= 0.0.4",
"backbone": ">= 0.9.1",
- "findit": ">= 0.1.2",
- "glob": ">= 3.1.9",
- "remove": ">= 0.1.1"
+ "d3": ">= 2.9.2"
},
"devDependencies": {
"buildtools": "https://github.com/dsc/node-buildtools/tarball/master",
},
"repository": {
"type": "git",
- "url": "git://git@less.ly:kraken-ui.git"
+ "url": "git://less.ly/kraken-ui.git"
},
"engine": {
"node": ">=0.6.2"
--- /dev/null
+#!/usr/bin/env coco
+express = require 'express'
+
+app = express.createServer()
+
+PROXY_DOMAIN_BLACKLIST = <[
+ *.ru
+]>
+PROXY_DOMAIN_WHITELIST = <[
+ wmflabs.org mediawiki.org wikimedia.org
+ *.wmflabs.org *.mediawiki.org *.wikimedia.org
+ github.com dsc.github.com mbostock.github.com
+]>
+
+
+proxy = require('kraken/server/proxy')({
+ blacklist: PROXY_DOMAIN_BLACKLIST
+ whitelist: PROXY_DOMAIN_WHITELIST
+})
+app.get '/x', proxy
+app.get '/x/*', proxy
+
+app.listen 8081