├── .gitignore ├── .gitmodules ├── .middlefiddle ├── config.json ├── fiddles │ └── add_csp.coffee └── sites │ ├── default.coffee │ ├── ft.com.coffee │ ├── github.com.coffee │ ├── google.com.coffee │ ├── httpbin.org.coffee │ ├── snip.it.coffee │ └── soundcloud.com.coffee ├── LICENSE ├── README.md ├── bin ├── certgen.sh └── middlefiddle ├── package.json ├── setup.js ├── src ├── cert_generator.coffee ├── command.coffee ├── config.coffee ├── fiddles │ ├── logger.coffee │ ├── sites.coffee │ ├── tor.coffee │ └── user_agent.coffee ├── http_proxy.coffee ├── index.coffee ├── logger.coffee ├── middleware │ ├── console_logger.coffee │ ├── live_logger.coffee │ ├── live_logger │ │ ├── index.html │ │ └── public │ │ │ ├── app.js │ │ │ ├── backbone-min.js │ │ │ ├── images │ │ │ └── background.png │ │ │ ├── jquery.min.js │ │ │ ├── jquery.mustache.js │ │ │ ├── json2.js │ │ │ ├── stylesheets │ │ │ ├── default.css │ │ │ └── reset.css │ │ │ └── underscore-min.js │ ├── replace.coffee │ └── user_agent.coffee ├── proxy.coffee ├── session_filter.coffee └── utils │ └── ringbuffer.coffee └── test ├── helpers ├── fake_server.coffee ├── mock_request.coffee └── public │ └── index.html ├── http_proxy_test.coffee ├── session_filter_test.coffee └── test_project.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib/* 3 | !/lib/bin 4 | .middlefiddle/* 5 | !.middlefiddle/config.json 6 | !.middlefiddle/sites 7 | !.middlefiddle/fiddles 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "docs"] 2 | path = docs 3 | url = git@github.com:mdp/middlefiddle.git 4 | -------------------------------------------------------------------------------- /.middlefiddle/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": 8080 3 | , "liveLoggerPort": 8411 4 | } 5 | -------------------------------------------------------------------------------- /.middlefiddle/fiddles/add_csp.coffee: -------------------------------------------------------------------------------- 1 | addCSP = (urlRegex) -> 2 | (req, res, next) -> 3 | if req.href.match(urlRegex) 4 | res.on 'headers', (headers) -> 5 | headers['x-content-security-policy'] = "allow 'self'" 6 | next() 7 | 8 | exports.middleware = (Mf) -> 9 | addCSP(/\.com/) 10 | -------------------------------------------------------------------------------- /.middlefiddle/sites/default.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (Mf) -> 2 | (req, res, next) -> 3 | next() 4 | -------------------------------------------------------------------------------- /.middlefiddle/sites/ft.com.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (Mf) -> 2 | # I'm the Google, let me in! 3 | (req, res, next) -> 4 | req.headers['user-agent'] = "GoogleBot" 5 | next() 6 | -------------------------------------------------------------------------------- /.middlefiddle/sites/github.com.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (Mf) -> 2 | cookieKiller = (req, res, next) -> 3 | res.removeHeader("set-cookie") 4 | next() 5 | replacement = (string, req, res) -> 6 | contentType = res.headers['content-type'] || '' 7 | if contentType.search(/html/) >= 0 8 | string.replace(/repositories/ig, "suppositories") 9 | else 10 | false 11 | 12 | return [cookieKiller, Mf.replace(replacement)] 13 | 14 | -------------------------------------------------------------------------------- /.middlefiddle/sites/google.com.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (Mf) -> 2 | ua = (req, res, next) -> 3 | req.headers['user-agent'] = "GoogleBotZ" 4 | res.on 'headers', (headers) -> 5 | headers['server'] = "Apache" 6 | next() 7 | 8 | replace = (string, req, res) -> 9 | if res.headers['content-type'].match('html') 10 | string.replace(/Lucky/gi, 'Unlucky') 11 | else 12 | false 13 | return [ua, Mf.replace(replace)] 14 | 15 | -------------------------------------------------------------------------------- /.middlefiddle/sites/httpbin.org.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (Mf) -> 2 | (req, res, next) -> 3 | res.removeHeader('server') 4 | next() 5 | -------------------------------------------------------------------------------- /.middlefiddle/sites/snip.it.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (Mf) -> 2 | (req, res, next) -> 3 | req.headers['user-agent'] = "iPhone" 4 | next() 5 | -------------------------------------------------------------------------------- /.middlefiddle/sites/soundcloud.com.coffee: -------------------------------------------------------------------------------- 1 | fs = require 'fs' 2 | module.exports = (Mf) -> 3 | (req, res, next) -> 4 | res.on 'body', -> 5 | if res.headers["content-type"] == 'audio/mpeg' 6 | fileName = req.path.replace(/^[a-zA-Z]/, '').split('.')[0] 7 | path = "#{process.env["HOME"]}/Downloads/soundcloud#{fileName}.mp3" 8 | fs.writeFile path, res.body, -> 9 | console.log "Saved #{res.body.length} bytes to #{path}" 10 | next() 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Mark Percival 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MiddleFiddle 2 | 3 | MiddleFiddle is an outbound local proxy which lets to modify your outbound request and responses 4 | via [Connect](http://senchalabs.github.com/connect/) middleware. It support HTTP and HTTPS, the 5 | latter through a hijacking of the request with locally generated SSL certs. 6 | 7 | ## Installtion 8 | 9 | $ npm install -g middlefiddle 10 | 11 | ## Installation via Github 12 | 13 | # Depends on Node 0.6.x 14 | $ git clone git://github.com/mdp/middlefiddle.git 15 | $ cd middlefiddle 16 | $ npm install 17 | $ npm link #If you want to use it globally 18 | 19 | ## Usage 20 | 21 | ### Basic usage 22 | 23 | By default middlefiddle will start logging traffic and modifying 24 | requests based on site specific middleware found in '.middlefiddle/sites' 25 | 26 | You can find an example in 27 | [.middlefiddle/sites](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/sites) 28 | 29 | # Start middlefiddle with default options 30 | $ middlefiddle 31 | # Proxy will be at port 8080 32 | 33 | ### Using the logger 34 | 35 | $ middlefiddle logger 36 | # Now open http://localhost:8411 37 | 38 | # Only log for a certain URL 39 | $ middlefiddle logger --url google.com 40 | 41 | # Only log certain statuses 42 | $ middlefiddle logger --status 404 43 | 44 | # Only log responses containing text 45 | $ middlefiddle logger --grep "setTimeout" 46 | # Also work with regex 47 | $ middlefiddle logger -r --grep "Mark(Percival)?" 48 | # And case insensitive 49 | $ middlefiddle logger -ri --grep "m@mdp\.im" 50 | 51 | ## Site specific middleware 52 | 53 | MiddleFiddle can alter requests based on the host name. You'll find some examples in 54 | [.middlefiddle/sites](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/sites) 55 | 56 | Simple add the middleware to your __~/.middlefiddle/sites__ directory, with 57 | the appropriate hostname. For example, __~/.middlefiddle/sites/github.com.coffee'__ 58 | would get injected on any request to github.com 59 | 60 | MiddleFiddle middleware is connect compatible. Anything you can do with 61 | Connect, you can do with middlefiddle middleware. 62 | 63 | ### Examples 64 | ---- 65 | 66 | ### Saving any mp3's from a site 67 | 68 | For example, lets say you want to save all the streamed mp3's from 69 | Soundcloud.com 70 | 71 | *Found in [soundcloud.com.coffee](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/sites/soundcloud.com.coffee)* 72 | 73 | fs = require 'fs' 74 | module.exports = (Mf) -> 75 | (req, res, next) -> 76 | res.on 'body', -> 77 | if res.headers["content-type"] == 'audio/mpeg' 78 | fileName = req.path.replace(/^[a-zA-Z]/, '').split('.')[0] 79 | path = "#{process.env["HOME"]}/Downloads/soundcloud#{fileName}.mp3" 80 | fs.writeFile path, res.body, -> 81 | console.log "Saved #{res.body.length} bytes to #{path}" 82 | next() 83 | 84 | ### Find and replace any text 85 | 86 | In this case we used the MiddleFiddle helper 'replace' 87 | 88 | *Found in [github.com.coffee](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/sites/github.com.coffee)* 89 | 90 | module.exports = (Mf) -> 91 | replacement = (string, req, res) -> 92 | contentType = res.headers['content-type'] || '' 93 | if contentType.search(/html/) >= 0 94 | string.replace(/repositories/ig, "suppositories") 95 | else 96 | false 97 | return Mf.replace(replacement) 98 | 99 | ### Modify outbound request headers 100 | 101 | Here we are going to change the user agent to GoogleBot 102 | 103 | *Found in [ft.com.coffee](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/sites/ft.com.coffee)* 104 | 105 | module.exports = (Mf) -> 106 | # I'm the Google, let me in! 107 | (req, res, next) -> 108 | req.headers['user-agent'] = "GoogleBot" 109 | next() 110 | 111 | ## Web Logging 112 | 113 | By default MiddleFiddle logs all outbound traffic to a web based logger on localhost:8411 114 | 115 | ![Request Logger](http://mdp.github.com/middlefiddle/images/RequestLogger.jpg) 116 | ![Request Logger](http://mdp.github.com/middlefiddle/images/RequestDetails.jpg) 117 | 118 | 119 | ## Configuration 120 | 121 | MiddleFiddle looks for a .middlefiddle directory in the current working directory, or at ~/.middlefiddle. 122 | 123 | Inside you'll find a config.coffee file, https certs, and a sites directory. 124 | 125 | You'll need to add the https certs to you keychain if you want to avoid 126 | the browser warning. The certs are generated on the first launch of 127 | middlefiddle and are therefor unique to each machine. 128 | 129 | 130 | ## HTTPS Hijacking 131 | 132 | When an HTTPS request is first seen, MiddleFiddle generates a certificate for that domain, signs 133 | it with its own generated root cert, and stores the cert for future use in 134 | ~/.middlefiddle/certs 135 | 136 | In order to make this look legit to your browser, you'll need to add the generated 137 | root cert in ~/.middlefiddle/ca.crt to your keychain. This cert is auto generated 138 | just for your machine, so you won't be compromising your browser security. 139 | 140 | ## Things to note 141 | 142 | Connect typically doesn't have a simple way to hijack downstream responses since it's streaming, so 143 | middlefiddle emits events on the response along with writing to the stream. 144 | 145 | res.on 'data', (chunk) -> 146 | console.log chunk.toString() 147 | 148 | res.on 'end', (chunk) -> 149 | console.log chunk.toString() 150 | 151 | res.on 'close', (chunk) -> 152 | console.log "Closed response" 153 | 154 | You've also got a couple helper properties: 155 | 156 | - req.href #=> String: The full requested URL, including the scheme, 157 | host, path, and query params 158 | - req.ssl #=> Boolean: Did it come via SSL? 159 | - req.startTime #=> Datetime: When the request was started 160 | - res.endTime #=> Datetime: I'll let you guess 161 | 162 | ## Modify responses 163 | 164 | ### Modifying the headers 165 | 166 | Response headers can be modified before they are sent to the browser. 167 | Just wait till they're available: 168 | 169 | *Example in [add_csp.coffee](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/fiddles/add_csp.coffee)* 170 | 171 | ### Replace the response body 172 | 173 | Modifying the a response body means buffering the stream, 174 | waiting for it to finish, then making the replacement and sending it 175 | back downstream. The 'replace' middleware provides this. 176 | 177 | * Usage example in [github.com.coffee](https://github.com/mdp/middlefiddle/tree/master/.middlefiddle/sites/github.com.coffee)* 178 | 179 | ## Testing 180 | 181 | Tests can be run from within the repo 182 | 183 | npm install 184 | npm test 185 | 186 | ## TODO 187 | 188 | - Clean up cert generation 189 | - Expand logging 190 | - Add more middleware 191 | 192 | ## Want to contribute 193 | 194 | Criticism is gladly accepted as long as it's in the form of a pull request. 195 | 196 | ## Development 197 | 198 | MiddleFiddle is written in CoffeeScript. It's set 199 | up with a Cakefile for building files in `src/` to `lib/` and running 200 | tests with nodeunit. There's also a `docs` task that generates Docco 201 | documentation from the source in `src/`. 202 | 203 | Released under the MIT license. 204 | 205 | Mark Percival 206 | -------------------------------------------------------------------------------- /bin/certgen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dir=$3 4 | serial=$2 5 | cert_dir="$dir/certs" 6 | ca_key_file="$dir/ca.key" 7 | ca_crt_file="$dir/ca.crt" 8 | cert_key_file="$cert_dir/$1.key" 9 | cert_csr_file="$cert_dir/$1.csr" 10 | cert_crt_file="$cert_dir/$1.crt" 11 | 12 | if [ ! -e $ca_key_file ]; then 13 | mkdir -p $dotfile_dir 14 | openssl genrsa -out $ca_key_file 1024 15 | openssl req -new -x509 -days 36500 -key $ca_key_file -out $ca_crt_file -subj "/C=US/ST=CA/L=SF/O=MiddleFiddle/OU=STFU/CN=middlefiddle.info CA" 16 | fi 17 | 18 | # Setup the server key 19 | if [ ! -e $cert_key_file ]; then 20 | mkdir -p $cert_dir 21 | openssl genrsa -out $cert_key_file 1024 22 | openssl req -new -key $cert_key_file -out $cert_csr_file -subj "/C=US/ST=CA/L=SF/O=MiddleFiddle/OU=STFU/CN=$1" 23 | # Sign with the CA 24 | openssl x509 -req -days 365 -in $cert_csr_file -CA $ca_crt_file -CAkey $ca_key_file -set_serial $serial -out $cert_crt_file 25 | fi 26 | 27 | -------------------------------------------------------------------------------- /bin/middlefiddle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require("coffee-script") 3 | require("../src/command") 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "middlefiddle", 3 | "version": "0.3.3", 4 | "description": "Middleware as a proxy for HTTP/HTTPS traffic", 5 | "keywords": ["proxy", "middleware", "connect"], 6 | "repository": "git://github.com/mdp/middlefiddle.git", 7 | "author": "Mark Percival (http://markpercival.us)", 8 | "repository": "git://github.com/mdp/middlefiddle", 9 | "dependencies": { 10 | "connect": "~>1.8.7", 11 | "coffee-script": ">=1.3.0", 12 | "underscore": ">=1.2.2", 13 | "colors": ">=0.5.1", 14 | "chain-gang": "1.0.0-beta4", 15 | "express": ">=2.5.1", 16 | "optimist": ">=0.3.0", 17 | "socket.io": ">=0.8.7", 18 | "mkdirp": ">=0.0.0" 19 | }, 20 | "scripts": { 21 | "postinstall": "node setup.js postinstall", 22 | "test": "node setup.js test" 23 | }, 24 | "devDependencies": { 25 | "mocha": ">=0.0.0" 26 | }, 27 | "bin": { 28 | "middlefiddle": "./bin/middlefiddle" 29 | }, 30 | "main": "./src/index.coffee", 31 | "engines": { "node": ">= 0.6.0" } 32 | } 33 | -------------------------------------------------------------------------------- /setup.js: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec; 2 | var sysPath = require('path'); 3 | var mkdirp = require('mkdirp'); 4 | var fs = require('fs'); 5 | var util = require("util"); 6 | 7 | var mode = process.argv[2]; 8 | 9 | var execute = function(pathParts, params, callback) { 10 | if (callback === null) callback = function() {}; 11 | var path = sysPath.join.apply(null, pathParts); 12 | var command = 'node ' + path + ' ' + params; 13 | console.log('Executing', command); 14 | exec(command, function(error, stdout, stderr) { 15 | if (error !== null) return process.stderr.write(stderr.toString()); 16 | console.log(stdout.toString()); 17 | }); 18 | }; 19 | 20 | var copy = function(path, targetPath) { 21 | var target = fs.createWriteStream(targetPath); 22 | var original = fs.createReadStream(path); 23 | target.once('open', function(fd){ 24 | util.pump(original, target); 25 | }); 26 | } 27 | 28 | if (mode === 'postinstall') { 29 | console.log("Creating .middlefiddle home directory"); 30 | mkdirp.sync(process.env["HOME"] + "/.middlefiddle"); 31 | mkdirp.sync(process.env["HOME"] + "/.middlefiddle/sites"); 32 | copy(__dirname + "/.middlefiddle/config.json", process.env["HOME"] + "/.middlefiddle/config.json"); 33 | } else if (mode === 'test') { 34 | execute(['node_modules', 'mocha', 'bin', 'mocha'], 35 | '--compilers coffee:coffee-script test/*.coffee'); 36 | } 37 | -------------------------------------------------------------------------------- /src/cert_generator.coffee: -------------------------------------------------------------------------------- 1 | fs = require('fs') 2 | path = require('path') 3 | {spawn} = require('child_process') 4 | chainGang = require('chain-gang') 5 | chain = chainGang.create({workers: 1}) 6 | log = require './logger' 7 | config = require './config' 8 | 9 | generateCerts = (host, callback) -> 10 | # TODO: Make async 11 | currentCerts = getCerts(host) 12 | if currentCerts 13 | log.debug("Found existing certs for #{host}") 14 | callback(currentCerts) 15 | else 16 | log.info("Generating certs for #{host}") 17 | prc = spawn "#{__dirname}/../bin/certgen.sh", [host, Date.now(), config.mfDir] 18 | prc.on 'exit', (code, err) -> 19 | if code == 0 20 | callback getCerts(host) 21 | else 22 | log.error(err) 23 | callback getCerts(host) 24 | 25 | CERTS_DIR = "#{config.mfDir}/certs" 26 | getCerts = (host) -> 27 | if path.existsSync("#{CERTS_DIR}/#{host}.key") && path.existsSync("#{CERTS_DIR}/#{host}.crt") 28 | tlsOptions = 29 | key: fs.readFileSync("#{CERTS_DIR}/#{host}.key"), 30 | cert: fs.readFileSync("#{CERTS_DIR}/#{host}.crt"), 31 | ca: fs.readFileSync("#{CERTS_DIR}/../ca.crt") 32 | tlsSettings = require('crypto').createCredentials(tlsOptions) 33 | tlsSettings.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA') 34 | tlsSettings 35 | else 36 | return false 37 | 38 | exports.build = (host, tlsCallback) -> 39 | # Using Chaingang to prevent the forked 40 | # bash script from creating the same cert at the same time 41 | # Hacky, but it works 42 | # TODO: Gen and sign certs using native Node Openssl hooks 43 | if tlsSettings = getCerts(host) 44 | tlsCallback(tlsSettings) 45 | else 46 | log.debug("Queuing up cert gen") 47 | callback = (err)-> 48 | tlsCallback(getCerts(host)) 49 | job = (host)-> 50 | (worker) -> 51 | generateCerts host, -> 52 | worker.finish() 53 | chain.add job(host), host, callback 54 | -------------------------------------------------------------------------------- /src/command.coffee: -------------------------------------------------------------------------------- 1 | # Require coffee-script to allow us to use .coffee proxies 2 | require 'coffee-script' 3 | optimist = require 'optimist' 4 | path = require 'path' 5 | log = require './logger' 6 | 7 | # Let us find this in 'top' 8 | process.title = "middlefiddle" 9 | 10 | # Print valid command-line arguments and exit with a non-zero exit 11 | usage = -> 12 | console.error "usage: mf [middleware]" 13 | process.exit -1 14 | unless process.argv.length > 1 15 | usage() 16 | 17 | passedArgs = optimist.parse(process.argv.slice(3)) 18 | Mf = require './index' # Dependency injection for the middleware proxies 19 | 20 | # Look for the appropriate 'fiddle' 21 | # First looks locally 22 | # Then in the ./middlefiddle/fiddles directory 23 | # And finally in the modules own list 24 | fiddlePaths = [ 25 | process.cwd() 26 | Mf.config.mfDir + '/fiddles' 27 | __dirname + '/fiddles' 28 | ] 29 | 30 | log.debug("Checking the following locations") 31 | log.debug(fiddlePaths) 32 | 33 | activeFiddle = null 34 | middleware = [] 35 | if process.argv.length > 2 36 | for fiddlePath in fiddlePaths 37 | testPath = fiddlePath + "/" + process.argv[2] 38 | if path.existsSync(testPath + ".coffee") || path.existsSync(testPath + ".js") 39 | activeFiddle = testPath 40 | break 41 | if activeFiddle == null 42 | log.error("Can't find a fiddle named '#{process.argv[2]}'. Looked in: " + fiddlePaths) 43 | process.exit -1 44 | middleware = middleware.concat require(activeFiddle).middleware(Mf, passedArgs) 45 | 46 | else 47 | # Default to the 'sites' fiddle for now 48 | middleware = middleware.concat Mf.defaultFiddle().middleware() 49 | 50 | # Middleware are passed both the MiddleFiddle object, and any additional arguments 51 | 52 | log.info("Starting HTTP Proxy on port #{Mf.config.port}") 53 | unless Array.isArray middleware 54 | middleware = [middleware] 55 | Mf.createProxy.apply(this, middleware).listen(Mf.config.port) 56 | 57 | -------------------------------------------------------------------------------- /src/config.coffee: -------------------------------------------------------------------------------- 1 | _ = require('underscore') 2 | path = require('path') 3 | homeDir = process.env['HOME'] 4 | defaultMfDir = homeDir + "/.middlefiddle" 5 | mfDir = null 6 | log = require './logger' 7 | 8 | 9 | # Check first to see if we have a local .middlefiddle directory 10 | # If not, default to $HOME/.middlefiddle 11 | mfPaths = [ 12 | process.cwd() + '/.middlefiddle' 13 | defaultMfDir 14 | ] 15 | 16 | for mfPath in mfPaths 17 | if path.existsSync(mfPath) 18 | mfDir = mfPath 19 | break 20 | unless mfDir 21 | mfDir = defaultMfDir 22 | log.info("Loading from #{mfDir}") 23 | 24 | configFile = mfDir + "/config.json" 25 | try 26 | userConfig = require(configFile) 27 | catch error 28 | log.warn("Unable to load " + configFile) 29 | userConfig = {} 30 | 31 | defaultConfig = 32 | mfDir: mfDir 33 | httpPort: 8088 34 | httpsPort: 8089 35 | liveLoggerPort: 8411 36 | 37 | config = _.extend(defaultConfig, userConfig) 38 | module.exports = config 39 | -------------------------------------------------------------------------------- /src/fiddles/logger.coffee: -------------------------------------------------------------------------------- 1 | # Take the following command line arguments 2 | # --url URL 3 | # --status STATUSCODE 4 | # --contains TEXT 5 | exports.middleware = (Mf, args) -> 6 | checkArguments(args) 7 | if args.h 8 | usage() 9 | requestFilter = {} 10 | responseFilter = {} 11 | if args.url 12 | requestFilter.href = args.url 13 | if args.status 14 | responseFilter.statusCode = args.status 15 | if args.grep 16 | flags = 'g' 17 | flags += 'i' if args.i 18 | search = RegExp args.grep, flags 19 | Mf.log.info "Searching for \"#{search}\"" 20 | responseFilter.contains = search 21 | 22 | [Mf.live_logger(requestFilter, responseFilter)] 23 | 24 | checkArguments = (args) -> 25 | validArguments = ['grep', 'url', 'status'] 26 | for prop, val of args 27 | if prop.search(/^[a-zA-Z0-9]+$/) >= 0 28 | if validArguments.indexOf(prop) 29 | usage() 30 | 31 | usage = -> 32 | console.error "usage: mf logger --url URL --status STATUS --contains TEXT" 33 | console.error "--url/--status/--contains can be combined and used multiple time" 34 | process.exit -1 35 | -------------------------------------------------------------------------------- /src/fiddles/sites.coffee: -------------------------------------------------------------------------------- 1 | # This is the default Fiddle loaded when you start MiddleFiddle 2 | # Logs traffic to the weblogger, and injects middleware into sites 3 | # using files found in .middlefiddle/site/*.coffee[.js] 4 | # Sites are matched to the host 5 | # Example: 6 | # google.com.coffee will run on any request to google.com as well as www.google.com 7 | # 8 | fs = require 'fs' 9 | path = require 'path' 10 | _ = require 'underscore' 11 | Mf = require '../index' 12 | sitesDir = Mf.config.mfDir + '/sites' 13 | siteMiddlewares = {} 14 | 15 | # To reload middlewares, simple press Ctrl-R 16 | stdin = process.openStdin() 17 | require('tty').setRawMode(true) 18 | 19 | stdin.on 'keypress', (chunk, key) -> 20 | if (key && key.ctrl && key.name == 'r') 21 | console.log("Reloading Middleware") 22 | loadMiddlewares() 23 | if (key && key.ctrl && key.name == 'c') 24 | process.exit() 25 | 26 | # Looks in '/sites' inside you .middlefiddle directory 27 | # Matches to the host 28 | loadMiddlewares = () -> 29 | siteMiddlewares = {} 30 | return unless path.existsSync(sitesDir) 31 | for site in fs.readdirSync(sitesDir) 32 | loadSiteMiddleware(site) 33 | watchMiddleware(site) 34 | 35 | watchMiddleware = (site) -> 36 | fs.watchFile "#{sitesDir}/#{site}", (c, p) -> 37 | loadSiteMiddleware(site) 38 | 39 | loadSiteMiddleware = (site) -> 40 | key = site.replace(/\.coffee$/,'').replace(/\.js$/,'') 41 | Mf.log.info("Loading: #{key}") 42 | delete require.cache[sitesDir + '/' + site] 43 | siteMiddlewares[key] = require(sitesDir + '/' + site) 44 | fs.unwatchFile "#{sitesDir}/#{site}" 45 | watchMiddleware(site) 46 | 47 | exports.middleware = () -> 48 | loadMiddlewares() 49 | 50 | siteMiddleware = (req, res, next) -> 51 | middlewares = [] 52 | if defMiddleware = siteMiddlewares['default'] 53 | middlewares.push defMiddleware(Mf) 54 | for key, m of siteMiddlewares 55 | if req.host.match(key) 56 | Mf.log.debug("Fiddling with #{req.host} using #{key}") 57 | middlewares = middlewares.concat m(Mf) 58 | break 59 | nextMw = (i) -> 60 | if n = middlewares[i] 61 | -> n(req, res, nextMw(i+1)) 62 | else 63 | -> next() 64 | if middlewares.length > 0 65 | nextMw(0)() 66 | else 67 | next() 68 | 69 | [siteMiddleware, Mf.live_logger()] 70 | -------------------------------------------------------------------------------- /src/fiddles/tor.coffee: -------------------------------------------------------------------------------- 1 | exports.middleware = (Mf, args) -> 2 | Mf.config.transparent = true 3 | minLength = args.minLength || 100 4 | responseFilter = (res) -> 5 | contentType = res.headers['content-type'] 6 | if contentType && contentType.search(/html/) < 0 7 | return false 8 | if res.statusCode != 200 9 | return false 10 | if res.length < Number(minLength) 11 | return false 12 | return true 13 | [Mf.logger(null, responseFilter)] 14 | 15 | usage = -> 16 | console.error "Logs relevant tor traffice through a transparent proxy" 17 | console.error "minLength is the minumum length of the body, default 100" 18 | console.error "usage: tor [--minLength 1000]" 19 | process.exit -1 20 | 21 | -------------------------------------------------------------------------------- /src/fiddles/user_agent.coffee: -------------------------------------------------------------------------------- 1 | exports.middleware = (Mf, args) -> 2 | checkArgs(args) 3 | user_agent = args._.shift() 4 | if args.url 5 | requestFilter = 6 | href: args.url 7 | [Mf.logger(), Mf.user_agent(user_agent, requestFilter)] 8 | 9 | usage = -> 10 | console.error "usage: user_agent UA_STRING [--url site.com]" 11 | process.exit -1 12 | 13 | checkArgs = (args) -> 14 | unless args._.length > 0 15 | usage() 16 | -------------------------------------------------------------------------------- /src/http_proxy.coffee: -------------------------------------------------------------------------------- 1 | util = require 'util' 2 | _ = require('underscore') 3 | Stream = require "stream" 4 | fs = require 'fs' 5 | zlib = require "zlib" 6 | http = require "http" 7 | https = require "https" 8 | url = require "url" 9 | connect = require "connect" 10 | config = require "./config" 11 | log = require "./logger" 12 | sessionFilter = require "./session_filter" 13 | 14 | safeParsePath = (req) -> 15 | 16 | isSecure = (req) -> 17 | if req.client && req.client.pair 18 | true 19 | else if req.forceSsl 20 | true 21 | else 22 | false 23 | 24 | exports.createProxy = (middlewares...) -> 25 | proxy = new HttpProxy(middlewares) 26 | return proxy 27 | 28 | exports.HttpProxy = class HttpProxy extends connect.HTTPServer 29 | 30 | constructor: (middlewares) -> 31 | if _.isArray middlewares 32 | @middlewares = middlewares 33 | else 34 | @middlewares = [middlewares] 35 | super @bookendedMiddleware() 36 | 37 | bookendedMiddleware: -> 38 | @middlewares.unshift(@proxyCleanup) 39 | @middlewares.push(@outboundProxy) 40 | @middlewares 41 | 42 | proxyCleanup: (req, res, next) -> 43 | # Attach a namespace object to request and response for safer stashing of 44 | # properties and functions you'd like to have tag along 45 | req.mf ||= {} 46 | res.mf ||= {} 47 | # Request now has an explicit host which can be overridden later 48 | req.host = req.headers['host'].split(":")[0] 49 | req.port = req.headers['host'].split(":")[1] 50 | 51 | if isSecure(req) 52 | # Helper property 53 | req.href = "https://" + req.headers['host'] + req.path 54 | req.ssl = true 55 | req.port ||= 443 56 | else 57 | req.port ||= 80 58 | 59 | # Act as a completely transparent proxy 60 | # This implies that the sender is unaware of the proxy, 61 | # and being forced here from a network level redirect 62 | # Therefore the request come in as a normal path 63 | # Id est: '/' vs '/http://google.com' 64 | if config.transparent 65 | # Helper property 66 | req.href = "http://" + req.headers['host'] + req.url 67 | 68 | # Proxy requests send the full URL, not just the path 69 | # Node HTTP sees this at '/http://google.com' 70 | else 71 | safeUrl = '' 72 | proxyUrl = url.parse(req.url.slice(1)) 73 | safeUrl += proxyUrl.pathname 74 | safeUrl += proxyUrl.search if proxyUrl.search? 75 | req.url = safeUrl 76 | req.port = proxyUrl.port 77 | # Helper property 78 | req.href = proxyUrl.href 79 | 80 | bodyLogger req, 'request' 81 | next() 82 | 83 | outboundProxy: (req, res, next) -> 84 | req.startTime = new Date 85 | passed_opts = {method:req.method, path:req.url, host:req.host, headers:req.headers, port:req.port} 86 | upstream_processor = (upstream_res) -> 87 | # Helpers for easier logging upstream 88 | res.statusCode = upstream_res.statusCode 89 | res.headers = upstream_res.headers 90 | 91 | if res.headers && res.headers['content-type'] && res.headers['content-type'].search(/(text)|(application)/) >= 0 92 | res.isBinary = false 93 | else 94 | res.isBinary = true 95 | 96 | res.emit 'headers', res.headers 97 | 98 | # Store body data with the response 99 | bodyLogger(res, 'response') 100 | 101 | res.writeHead(res.statusCode, res.headers) 102 | upstream_res.on 'data', (chunk) -> 103 | res.write(chunk, 'binary') 104 | res.emit 'data', chunk 105 | upstream_res.on 'end', (data)-> 106 | res.endTime = new Date 107 | res.end(data) 108 | res.emit 'end' 109 | upstream_res.on 'close', -> 110 | res.emit 'close' 111 | upstream_res.on 'error', (err) -> 112 | log.error("Upstream Response Error - #{err}") 113 | res.emit 'close' 114 | req.on 'data', (chunk) -> 115 | upstream_request.write(chunk) 116 | req.on 'error', (error) -> 117 | log.error("ERROR: #{error}") 118 | if req.ssl 119 | upstream_request = https.request passed_opts, upstream_processor 120 | else 121 | upstream_request = http.request passed_opts, upstream_processor 122 | 123 | upstream_request.on 'error', (err)-> 124 | log.error("Upstream Fail - #{req.method} - #{req.href}") 125 | log.error(err) 126 | upstream_request.end() 127 | 128 | bodyLogger = (stream, type, callback) -> 129 | data = [] 130 | assembleBody = -> 131 | stream.body = new Buffer(stream.length) 132 | offset = 0 133 | for buffer in data 134 | buffer.copy(stream.body, offset) 135 | offset += buffer.length 136 | data = null 137 | callback ||= () -> 138 | assembleBody() 139 | stream.emit 'body' 140 | if type == 'response' 141 | log.debug("Captured #{stream.body.length} bytes from #{stream.statusCode}") 142 | length = parseInt(stream.headers['content-length'], 10) || 0 143 | stream.body = new Buffer(parseInt(stream.headers['content-length'], 10)) 144 | stream.length = 0 145 | unzipper = zlib.createUnzip() 146 | unzipper.on 'data', (datum) -> 147 | data.push(datum) 148 | stream.length += datum.length 149 | unzipper.on 'end', -> 150 | callback() 151 | unzipper.destroy = -> 152 | console.log stream.href 153 | console.log stream.headers 154 | switch (stream.headers['content-encoding']) 155 | when 'gzip' 156 | log.debug("Unzipping") 157 | stream.pipe(unzipper) 158 | break 159 | when 'deflate' 160 | log.debug("Deflating") 161 | stream.pipe(unzipper) 162 | break 163 | else 164 | stream.on 'data', (datum)-> 165 | data.push datum 166 | stream.length += datum.length 167 | stream.on 'end', -> 168 | callback() 169 | break 170 | -------------------------------------------------------------------------------- /src/index.coffee: -------------------------------------------------------------------------------- 1 | fs = require 'fs' 2 | 3 | exports.createProxy = require("./proxy").createProxy 4 | exports.config = require("./config") 5 | exports.log = require('./logger') 6 | exports.defaultFiddle = () -> 7 | require('./fiddles/sites') 8 | 9 | fs.readdirSync(__dirname + '/middleware').forEach (filename) -> 10 | name = filename.substr(0, filename.lastIndexOf('.')) 11 | exports.__defineGetter__ name, -> 12 | return require('./middleware/' + name) 13 | 14 | # HTTPS DNS lookup errors throw an exception which 15 | # it difficult to catch 16 | # process.on 'uncaughtException', (err)-> 17 | # console.log(err) 18 | 19 | -------------------------------------------------------------------------------- /src/logger.coffee: -------------------------------------------------------------------------------- 1 | sys = require('util') 2 | colors = require('colors') 3 | verbosity = ()-> 4 | switch(process.env['LOGLEVEL']) 5 | when "DEBUG" 6 | 3 7 | when "INFO" 8 | 2 9 | when "WARN" 10 | 1 11 | when "ERROR" 12 | 0 13 | else 14 | 2 15 | 16 | level = verbosity() 17 | module.exports = 18 | debug: (msg) -> 19 | if level >= 3 20 | sys.puts(msg) 21 | info: (msg) -> 22 | if level >= 2 23 | sys.puts(msg.green) 24 | warn: (msg) -> 25 | if level >= 1 26 | sys.puts("WARNING: #{msg}".magenta) 27 | error: (msg) -> 28 | if level >= 0 29 | sys.puts("ERROR: #{msg}".red) 30 | 31 | -------------------------------------------------------------------------------- /src/middleware/console_logger.coffee: -------------------------------------------------------------------------------- 1 | exports = module.exports = (options) -> 2 | options ||= {} 3 | stream = options.stream || process.stdout 4 | 5 | return (req, res, next) -> 6 | req._startTime = new Date 7 | 8 | if (req._logging) 9 | return next() 10 | 11 | req._logging = true 12 | end = res.end 13 | res.end = (chunk, encoding) -> 14 | res.end = end; 15 | res.end(chunk, encoding) 16 | stream.write(fmt(req, res) + '\n', 'ascii') 17 | next() 18 | 19 | fmt = (req, res) -> 20 | "#{res.statusCode} - #{req.href}" 21 | -------------------------------------------------------------------------------- /src/middleware/live_logger.coffee: -------------------------------------------------------------------------------- 1 | express = require('express') 2 | io = require('socket.io') 3 | ringBuffer = require('../utils/ringbuffer').create(100) 4 | log = require '../logger' 5 | sessionFilter = require '../session_filter' 6 | config = require '../config' 7 | currentSocket = null 8 | # Things I don't want to dump into the content field 9 | impracticalMimeTypes = /^(image|audio|video)\// 10 | 11 | createServer = (callback) -> 12 | app = express.createServer() 13 | io = io.listen(app, {"log level": 0}) 14 | app.configure -> 15 | app.use express.static(__dirname + '/live_logger/public') 16 | 17 | app.get '/', (req, res) -> 18 | index = require('fs').readFileSync(__dirname + '/live_logger/index.html') 19 | res.send index.toString(), 200 20 | 21 | app.get '/all', (req, res) -> 22 | requestLogs = ringBuffer.all(req.params.key) 23 | if requestLogs 24 | items = [] 25 | for request in requestLogs 26 | items.push(shortFormat.apply(this, [request[0], request[1]])) 27 | res.send JSON.stringify(items, 200) 28 | else 29 | res.send JSON.stringify([], 200) 30 | 31 | app.get '/:key', (req, res) -> 32 | requestLog = ringBuffer.retrieve(req.params.key) 33 | if requestLog 34 | res.send JSON.stringify(longFormat.apply(this, requestLog), 200) 35 | else 36 | res.send "Not Found", 404 37 | 38 | io.sockets.on 'connection', (socket) -> 39 | currentSocket = socket 40 | 41 | app.listen(config.liveLoggerPort) 42 | 43 | exports = module.exports = (requestFilter, responseFilter) -> 44 | log.info ("Starting LiveLogger on #{config.liveLoggerPort}") 45 | createServer() 46 | 47 | return (req, res, next) -> 48 | unless sessionFilter.matches(requestFilter, req) 49 | next() 50 | return 51 | # Wait till we have the body unzipped and processed 52 | res.on 'body', () -> 53 | if sessionFilter.matches(responseFilter, res) 54 | liveLog(req, res) 55 | next() 56 | 57 | liveLog = (req, res) -> 58 | res.mf.logKey = ringBuffer.add([req, res]) 59 | if currentSocket 60 | currentSocket.emit 'request', { request: shortFormat(req, res) } 61 | currentSocket.broadcast.emit 'request', { request: shortFormat(req, res) } 62 | 63 | shortFormat = (req, res) -> 64 | id: res.mf.logKey 65 | status: res.statusCode 66 | url: req.href 67 | method: req.method 68 | length: res.length 69 | time: (res.endTime - req.startTime) 70 | 71 | longFormat = (req, res) -> 72 | req_headers = for key, val of req.headers 73 | "#{key}: #{val}" 74 | res_headers = for key, val of res.headers 75 | "#{key}: #{val}" 76 | requestContent = req.body.toString('utf-8') 77 | unless res.headers['content-type'] && res.headers['content-type'].match(impracticalMimeTypes) 78 | responseContent = res.body.toString('utf-8') 79 | 80 | request: 81 | url: req.href 82 | method: req.method 83 | headers: req_headers 84 | content: requestContent 85 | response: 86 | status: res.statusCode 87 | headers: res_headers 88 | content: responseContent 89 | time: (res.endTime - req.startTime) 90 | 91 | -------------------------------------------------------------------------------- /src/middleware/live_logger/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Request Logger 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 24 | 66 | 67 | 68 |
69 |
    70 |
    71 |
    72 |
    73 |
    74 | 75 | 76 | -------------------------------------------------------------------------------- /src/middleware/live_logger/public/app.js: -------------------------------------------------------------------------------- 1 | // Load the application once the DOM is ready, using `jQuery.ready`: 2 | $(function(){ 3 | 4 | // Router 5 | window.Router = Backbone.Router.extend({ 6 | routes: { 7 | "request/:id": "showRequest", 8 | "": "index", 9 | "/": "index" 10 | }, 11 | 12 | showRequest: function(id){ 13 | App.rememberScrollPosition(); 14 | var reqDetails = new RequestDetail({id: id}); 15 | reqDetails.fetch({ 16 | success: function(model){ 17 | var view = new RequestDetailView({model: model}); 18 | view.render(); 19 | } 20 | }); 21 | $("#list-view").hide(); 22 | }, 23 | 24 | index: function(){ 25 | $("#list-view").show(); 26 | App.setScrollPosition(); 27 | $("#detail-view").hide(); 28 | } 29 | }); 30 | 31 | // Request Model 32 | // ---------- 33 | window.Request = Backbone.Model.extend({ 34 | 35 | statusClass: function(){ 36 | var status = this.attributes.status; 37 | if (status >= 500) { 38 | return 'five_hundred'; 39 | } else if (status >= 400) { 40 | return 'four_hundred'; 41 | } else if (status >= 300) { 42 | return 'three_hundred'; 43 | } else if (status >= 200) { 44 | return 'two_hundred'; 45 | } else { 46 | return 'two_hundred'; 47 | } 48 | } 49 | 50 | }); 51 | 52 | window.Requests = Backbone.Collection.extend({ 53 | model: Request, 54 | url: function() { 55 | return '/all' 56 | } 57 | }); 58 | 59 | window.RequestDetail = Backbone.Model.extend({ 60 | url: function(){ 61 | return "/" + this.id; 62 | } 63 | 64 | }); 65 | 66 | // The DOM element for an individual request... 67 | window.RequestView = Backbone.View.extend({ 68 | tagName: 'li', 69 | 70 | // Cache the template function for a single item. 71 | template: $("#request-item").html(), 72 | 73 | container: $('#list-view'), 74 | 75 | events: { 76 | "click": "openRequestDetail" 77 | }, 78 | 79 | openRequestDetail: function(){ Controller.navigate("request/" + this.model.id, true) }, 80 | 81 | // Render the Request 82 | render: function() { 83 | var req = $.mustache(this.template, this.model.attributes); 84 | $(this.el).attr('class', this.model.get('method') + ' ' + this.model.statusClass()); 85 | $(this.el).html(req); 86 | return this; 87 | } 88 | 89 | }); 90 | 91 | window.RequestDetailView = Backbone.View.extend({ 92 | // Cache the template function for a single item. 93 | template: $("#requestDetailTemplate").html(), 94 | 95 | container: $('#detail-view'), 96 | 97 | events: { 98 | "click": "closeRequestDetail" 99 | }, 100 | 101 | closeRequestDetail: function(){ Controller.navigate("/", true) }, 102 | 103 | // Render the Request 104 | render: function() { 105 | var reqDetail = $.mustache(this.template, this.model.toJSON()); 106 | this.container.show(); 107 | this.container.html(reqDetail); 108 | App.disableScrolling(); 109 | return this; 110 | } 111 | }); 112 | 113 | window.ScrollButtonView = Backbone.View.extend({ 114 | className: 'scroll-btn', 115 | render: function(){ 116 | $(this.el).html(req); 117 | } 118 | }); 119 | 120 | // The Application 121 | // --------------- 122 | 123 | window.AppView = Backbone.View.extend({ 124 | 125 | initialize: function() { 126 | var self = this; 127 | this.Requests = new Requests; 128 | window.socket.on('request', function (data) { 129 | self.Requests.add(data['request']) 130 | }); 131 | this.Requests.bind('add', function(model){ 132 | var view = new RequestView({model: model}); 133 | $("ul#requests").append(view.render().el); 134 | if (window.scrollWithIt == true) { 135 | window.scrollTo(0, document.body.scrollHeight); 136 | } 137 | }); 138 | this.Requests.bind('reset', function(models){ 139 | _.each(models.models, function(model){ 140 | var view = new RequestView({model: model}); 141 | $("ul#requests").append(view.render().el); 142 | }); 143 | window.scrollTo(0, document.body.scrollHeight); 144 | }); 145 | this.Requests.fetch(); 146 | }, 147 | 148 | disableScrolling: function(){ 149 | window.scrollWithIt = false; 150 | $('#scroll-btn').attr('class', ''); 151 | }, 152 | 153 | enableScrolling: function(){ 154 | window.scrollWithIt = true; 155 | $('#scroll-btn').attr('class', 'active'); 156 | window.scrollTo(0, document.body.scrollHeight); 157 | }, 158 | 159 | rememberScrollPosition: function(){ 160 | if (window.scrollWithIt === true) { 161 | this.disableScrolling(); 162 | this.lastScrollPosition = -1; 163 | } else { 164 | this.lastScrollPosition = window.pageYOffset; 165 | } 166 | }, 167 | 168 | setScrollPosition: function(){ 169 | if (this.lastScrollPosition >= 0) { 170 | window.scrollTo(0, this.lastScrollPosition); 171 | } else { 172 | this.enableScrolling(); 173 | } 174 | }, 175 | 176 | scrollEvent: function(){ 177 | if (window.pageYOffset < this.lastScrollPosition){ 178 | this.disableScrolling(); 179 | } 180 | if (window.scrollWithIt === true) { 181 | this.lastScrollPosition = window.pageYOffset; 182 | } 183 | }, 184 | 185 | toggleScrolling: function() { 186 | if (window.scrollWithIt == true) { 187 | this.disableScrolling(); 188 | } else { 189 | this.enableScrolling(); 190 | } 191 | } 192 | 193 | }); 194 | 195 | window.socket = io.connect('/'); 196 | window.App = new AppView; 197 | window.Controller = new Router; 198 | Backbone.history.start(); 199 | 200 | $('#scroll-btn').click(function() { 201 | App.toggleScrolling(); 202 | }); 203 | }); 204 | -------------------------------------------------------------------------------- /src/middleware/live_logger/public/backbone-min.js: -------------------------------------------------------------------------------- 1 | // Backbone.js 0.5.3 2 | // (c) 2010 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Backbone may be freely distributed under the MIT license. 4 | // For all details and documentation: 5 | // http://documentcloud.github.com/backbone 6 | (function(){var h=this,p=h.Backbone,e;e=typeof exports!=="undefined"?exports:h.Backbone={};e.VERSION="0.5.3";var f=h._;if(!f&&typeof require!=="undefined")f=require("underscore")._;var g=h.jQuery||h.Zepto;e.noConflict=function(){h.Backbone=p;return this};e.emulateHTTP=!1;e.emulateJSON=!1;e.Events={bind:function(a,b,c){var d=this._callbacks||(this._callbacks={});(d[a]||(d[a]=[])).push([b,c]);return this},unbind:function(a,b){var c;if(a){if(c=this._callbacks)if(b){c=c[a];if(!c)return this;for(var d= 7 | 0,e=c.length;d/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},has:function(a){return this.attributes[a]!=null},set:function(a,b){b||(b={});if(!a)return this;if(a.attributes)a=a.attributes;var c=this.attributes,d=this._escapedAttributes;if(!b.silent&&this.validate&&!this._performValidation(a,b))return!1;if(this.idAttribute in a)this.id=a[this.idAttribute]; 10 | var e=this._changing;this._changing=!0;for(var g in a){var h=a[g];if(!f.isEqual(c[g],h))c[g]=h,delete d[g],this._changed=!0,b.silent||this.trigger("change:"+g,this,h,b)}!e&&!b.silent&&this._changed&&this.change(b);this._changing=!1;return this},unset:function(a,b){if(!(a in this.attributes))return this;b||(b={});var c={};c[a]=void 0;if(!b.silent&&this.validate&&!this._performValidation(c,b))return!1;delete this.attributes[a];delete this._escapedAttributes[a];a==this.idAttribute&&delete this.id;this._changed= 11 | !0;b.silent||(this.trigger("change:"+a,this,void 0,b),this.change(b));return this},clear:function(a){a||(a={});var b,c=this.attributes,d={};for(b in c)d[b]=void 0;if(!a.silent&&this.validate&&!this._performValidation(d,a))return!1;this.attributes={};this._escapedAttributes={};this._changed=!0;if(!a.silent){for(b in c)this.trigger("change:"+b,this,void 0,a);this.change(a)}return this},fetch:function(a){a||(a={});var b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&& 12 | c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"read",this,a)},save:function(a,b){b||(b={});if(a&&!this.set(a,b))return!1;var c=this,d=b.success;b.success=function(a,e,f){if(!c.set(c.parse(a,f),b))return!1;d&&d(c,a,f)};b.error=i(b.error,c,b);var f=this.isNew()?"create":"update";return(this.sync||e.sync).call(this,f,this,b)},destroy:function(a){a||(a={});if(this.isNew())return this.trigger("destroy",this,this.collection,a);var b=this,c=a.success;a.success=function(d){b.trigger("destroy", 13 | b,b.collection,a);c&&c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"delete",this,a)},url:function(){var a=k(this.collection)||this.urlRoot||l();if(this.isNew())return a;return a+(a.charAt(a.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this)},isNew:function(){return this.id==null},change:function(a){this.trigger("change",this,a);this._previousAttributes=f.clone(this.attributes);this._changed=!1},hasChanged:function(a){if(a)return this._previousAttributes[a]!= 14 | this.attributes[a];return this._changed},changedAttributes:function(a){a||(a=this.attributes);var b=this._previousAttributes,c=!1,d;for(d in a)f.isEqual(b[d],a[d])||(c=c||{},c[d]=a[d]);return c},previous:function(a){if(!a||!this._previousAttributes)return null;return this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},_performValidation:function(a,b){var c=this.validate(a);if(c)return b.error?b.error(this,c,b):this.trigger("error",this,c,b),!1;return!0}}); 15 | e.Collection=function(a,b){b||(b={});if(b.comparator)this.comparator=b.comparator;f.bindAll(this,"_onModelEvent","_removeReference");this._reset();a&&this.reset(a,{silent:!0});this.initialize.apply(this,arguments)};f.extend(e.Collection.prototype,e.Events,{model:e.Model,initialize:function(){},toJSON:function(){return this.map(function(a){return a.toJSON()})},add:function(a,b){if(f.isArray(a))for(var c=0,d=a.length;c').hide().appendTo("body")[0].contentWindow,this.navigate(a); 25 | this._hasPushState?g(window).bind("popstate",this.checkUrl):"onhashchange"in window&&!b?g(window).bind("hashchange",this.checkUrl):setInterval(this.checkUrl,this.interval);this.fragment=a;m=!0;a=window.location;b=a.pathname==this.options.root;if(this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;else if(this._wantsPushState&&this._hasPushState&&b&&a.hash)this.fragment=a.hash.replace(j,""),window.history.replaceState({}, 26 | document.title,a.protocol+"//"+a.host+this.options.root+this.fragment);if(!this.options.silent)return this.loadUrl()},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.iframe.location.hash));if(a==this.fragment||a==decodeURIComponent(this.fragment))return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(a){var b=this.fragment=this.getFragment(a); 27 | return f.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){var c=(a||"").replace(j,"");if(!(this.fragment==c||this.fragment==decodeURIComponent(c))){if(this._hasPushState){var d=window.location;c.indexOf(this.options.root)!=0&&(c=this.options.root+c);this.fragment=c;window.history.pushState({},document.title,d.protocol+"//"+d.host+c)}else if(window.location.hash=this.fragment=c,this.iframe&&c!=this.getFragment(this.iframe.location.hash))this.iframe.document.open().close(), 28 | this.iframe.location.hash=c;b&&this.loadUrl(a)}}});e.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.delegateEvents();this.initialize.apply(this,arguments)};var u=/^(\S+)\s*(.*)$/,n=["model","collection","el","id","attributes","className","tagName"];f.extend(e.View.prototype,e.Events,{tagName:"div",$:function(a){return g(a,this.el)},initialize:function(){},render:function(){return this},remove:function(){g(this.el).remove();return this},make:function(a, 29 | b,c){a=document.createElement(a);b&&g(a).attr(b);c&&g(a).html(c);return a},delegateEvents:function(a){if(a||(a=this.events))for(var b in f.isFunction(a)&&(a=a.call(this)),g(this.el).unbind(".delegateEvents"+this.cid),a){var c=this[a[b]];if(!c)throw Error('Event "'+a[b]+'" does not exist');var d=b.match(u),e=d[1];d=d[2];c=f.bind(c,this);e+=".delegateEvents"+this.cid;d===""?g(this.el).bind(e,c):g(this.el).delegate(d,e,c)}},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b= 30 | 0,c=n.length;b").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cn||(cn=c.createElement("iframe"),cn.frameBorder=cn.width=cn.height=0),b.appendChild(cn);if(!co||!cn.createElement)co=(cn.contentWindow||cn.contentDocument).document,co.write((c.compatMode==="CSS1Compat"?"":"")+""),co.close();d=co.createElement(a),co.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cn)}cm[a]=e}return cm[a]}function cw(a,b){var c={};f.each(cs.concat.apply([],cs.slice(0,b)),function(){c[this]=a});return c}function cv(){ct=b}function cu(){setTimeout(cv,0);return ct=f.now()}function cl(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ck(){try{return new a.XMLHttpRequest}catch(b){}}function ce(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){c!=="border"&&f.each(e,function(){c||(d-=parseFloat(f.css(a,"padding"+this))||0),c==="margin"?d+=parseFloat(f.css(a,c+this))||0:d-=parseFloat(f.css(a,"border"+this+"Width"))||0});return d+"px"}d=bB(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0,c&&f.each(e,function(){d+=parseFloat(f.css(a,"padding"+this))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+this+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+this))||0)});return d+"px"}function br(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bi,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bq(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bp(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bp)}function bp(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bo(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bn(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bm(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d=0===c})}function V(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function N(){return!0}function M(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/\d/,n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,o=/^[\],:{}\s]*$/,p=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,q=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,r=/(?:^|:|,)(?:\s*\[)+/g,s=/(webkit)[ \/]([\w.]+)/,t=/(opera)(?:.*version)?[ \/]([\w.]+)/,u=/(msie) ([\w.]+)/,v=/(mozilla)(?:.*? rv:([\w.]+))?/,w=/-([a-z]|[0-9])/ig,x=/^-ms-/,y=function(a,b){return(b+"").toUpperCase()},z=d.userAgent,A,B,C,D=Object.prototype.toString,E=Object.prototype.hasOwnProperty,F=Array.prototype.push,G=Array.prototype.slice,H=String.prototype.trim,I=Array.prototype.indexOf,J={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=n.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7",length:0,size:function(){return this.length},toArray:function(){return G.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?F.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),B.add(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(G.apply(this,arguments),"slice",G.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:F,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;B.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!B){B=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",C,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",C),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&K()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return a!=null&&m.test(a)&&!isNaN(a)},type:function(a){return a==null?String(a):J[D.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!E.call(a,"constructor")&&!E.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||E.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(o.test(b.replace(p,"@").replace(q,"]").replace(r,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(x,"ms-").replace(w,y)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c
    a",d=a.getElementsByTagName("*"),e=a.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=a.getElementsByTagName("input")[0],k={leadingWhitespace:a.firstChild.nodeType===3,tbody:!a.getElementsByTagName("tbody").length,htmlSerialize:!!a.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,unknownElems:!!a.getElementsByTagName("nav").length,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:a.className!=="t",enctype:!!c.createElement("form").enctype,submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,k.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,k.optDisabled=!h.disabled;try{delete a.test}catch(v){k.deleteExpando=!1}!a.addEventListener&&a.attachEvent&&a.fireEvent&&(a.attachEvent("onclick",function(){k.noCloneEvent=!1}),a.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),k.radioValue=i.value==="t",i.setAttribute("checked","checked"),a.appendChild(i),l=c.createDocumentFragment(),l.appendChild(a.lastChild),k.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,a.innerHTML="",a.style.width=a.style.paddingLeft="1px",m=c.getElementsByTagName("body")[0],o=c.createElement(m?"div":"body"),p={visibility:"hidden",width:0,height:0,border:0,margin:0,background:"none"},m&&f.extend(p,{position:"absolute",left:"-999px",top:"-999px"});for(t in p)o.style[t]=p[t];o.appendChild(a),n=m||b,n.insertBefore(o,n.firstChild),k.appendChecked=i.checked,k.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,k.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="
    ",k.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="
    t
    ",q=a.getElementsByTagName("td"),u=q[0].offsetHeight===0,q[0].style.display="",q[1].style.display="none",k.reliableHiddenOffsets=u&&q[0].offsetHeight===0,a.innerHTML="",c.defaultView&&c.defaultView.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",a.appendChild(j),k.reliableMarginRight=(parseInt((c.defaultView.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(a.attachEvent)for(t in{submit:1,change:1,focusin:1})s="on"+t,u=s in a,u||(a.setAttribute(s,"return;"),u=typeof a[s]=="function"),k[t+"Bubbles"]=u;f(function(){var a,b,d,e,g,h,i=1,j="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",l="visibility:hidden;border:0;",n="style='"+j+"border:5px solid #000;padding:0;'",p="
    "+""+"
    ";m=c.getElementsByTagName("body")[0];!m||(a=c.createElement("div"),a.style.cssText=l+"width:0;height:0;position:static;top:0;margin-top:"+i+"px",m.insertBefore(a,m.firstChild),o=c.createElement("div"),o.style.cssText=j+l,o.innerHTML=p,a.appendChild(o),b=o.firstChild,d=b.firstChild,g=b.nextSibling.firstChild.firstChild,h={doesNotAddBorder:d.offsetTop!==5,doesAddBorderForTableAndCells:g.offsetTop===5},d.style.position="fixed",d.style.top="20px",h.fixedPosition=d.offsetTop===20||d.offsetTop===15,d.style.position=d.style.top="",b.style.overflow="hidden",b.style.position="relative",h.subtractsBorderForOverflowNotVisible=d.offsetTop===-5,h.doesNotIncludeMarginInBodyOffset=m.offsetTop!==i,m.removeChild(a),o=a=null,f.extend(k,h))}),o.innerHTML="",n.removeChild(o),o=l=g=h=m=j=a=i=null;return k}(),f.boxModel=f.support.boxModel;var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[f.expando]:a[f.expando]&&f.expando,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[f.expando]=n=++f.uuid:n=f.expando),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[f.expando]:f.expando;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)?b=b:b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" "));for(e=0,g=b.length;e-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];if(!arguments.length){if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}return b}e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!a||j===3||j===8||j===2)return b;if(e&&c in f.attrFn)return f(a)[c](d);if(!("getAttribute"in a))return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return b}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g},removeAttr:function(a,b){var c,d,e,g,h=0;if(a.nodeType===1){d=(b||"").split(p),g=d.length;for(;h=0}})});var z=/\.(.*)$/,A=/^(?:textarea|input|select)$/i,B=/\./g,C=/ /g,D=/[^\w\s.|`]/g,E=/^([^\.]*)?(?:\.(.+))?$/,F=/\bhover(\.\S+)?/,G=/^key/,H=/^(?:mouse|contextmenu)|click/,I=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,J=function(a){var b=I.exec(a);b&& 3 | (b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},K=function(a,b){return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||a.id===b[2])&&(!b[3]||b[3].test(a.className))},L=function(a){return f.event.special.hover?a:a.replace(F,"mouseenter$1 mouseleave$1")};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=L(c).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"",(g||!e)&&c.preventDefault();if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,n=null;for(m=e.parentNode;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l=0:t===b&&(t=o[s]=r.quick?K(m,r.quick):f(m).is(s)),t&&q.push(r);q.length&&j.push({elem:m,matches:q})}d.length>e&&j.push({elem:this,matches:d.slice(e)});for(k=0;k0?this.bind(b,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),G.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),H.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

    ";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
    ";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(V(c[0])||V(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c),g=S.call(arguments);O.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!U[a]?f.unique(e):e,(this.length>1||Q.test(d))&&P.test(a)&&(e=e.reverse());return this.pushStack(e,a,g.join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var Y="abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",Z=/ jQuery\d+="(?:\d+|null)"/g,$=/^\s+/,_=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,ba=/<([\w:]+)/,bb=/",""],legend:[1,"
    ","
    "],thead:[1,"","
    "],tr:[2,"","
    "],td:[3,"","
    "],col:[2,"","
    "],area:[1,"",""],_default:[0,"",""]},bk=X(c);bj.optgroup=bj.option,bj.tbody=bj.tfoot=bj.colgroup=bj.caption=bj.thead,bj.th=bj.td,f.support.htmlSerialize||(bj._default=[1,"div
    ","
    "]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){f(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after" 4 | ,arguments);a.push.apply(a,f(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Z,""):null;if(typeof a=="string"&&!bd.test(a)&&(f.support.leadingWhitespace||!$.test(a))&&!bj[(ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(_,"<$1>");try{for(var c=0,d=this.length;c1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d=a.cloneNode(!0),e,g,h;if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bn(a,d),e=bo(a),g=bo(d);for(h=0;e[h];++h)g[h]&&bn(e[h],g[h])}if(b){bm(a,d);if(c){e=bo(a),g=bo(d);for(h=0;e[h];++h)bm(e[h],g[h])}}e=g=null;return d},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!bc.test(k))k=b.createTextNode(k);else{k=k.replace(_,"<$1>");var l=(ba.exec(k)||["",""])[1].toLowerCase(),m=bj[l]||bj._default,n=m[0],o=b.createElement("div");b===c?bk.appendChild(o):X(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=bb.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]===""&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&$.test(k)&&o.insertBefore(b.createTextNode($.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bt.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bs,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bs.test(g)?g.replace(bs,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bB(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bC=function(a,c){var d,e,g;c=c.replace(bu,"-$1").toLowerCase();if(!(e=a.ownerDocument.defaultView))return b;if(g=e.getComputedStyle(a,null))d=g.getPropertyValue(c),d===""&&!f.contains(a.ownerDocument.documentElement,a)&&(d=f.style(a,c));return d}),c.documentElement.currentStyle&&(bD=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bv.test(f)&&bw.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bB=bC||bD,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bF=/%20/g,bG=/\[\]$/,bH=/\r?\n/g,bI=/#.*$/,bJ=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bK=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bL=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bM=/^(?:GET|HEAD)$/,bN=/^\/\//,bO=/\?/,bP=/)<[^<]*)*<\/script>/gi,bQ=/^(?:select|textarea)/i,bR=/\s+/,bS=/([?&])_=[^&]*/,bT=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bU=f.fn.load,bV={},bW={},bX,bY,bZ=["*/"]+["*"];try{bX=e.href}catch(b$){bX=c.createElement("a"),bX.href="",bX=bX.href}bY=bT.exec(bX.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bU)return bU.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("
    ").append(c.replace(bP,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bQ.test(this.nodeName)||bK.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bH,"\r\n")}}):{name:b.name,value:c.replace(bH,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.bind(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?cb(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),cb(a,b);return a},ajaxSettings:{url:bX,isLocal:bL.test(bY[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bZ},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:b_(bV),ajaxTransport:b_(bW),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cd(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=ce(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bJ.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bI,"").replace(bN,bY[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bR),d.crossDomain==null&&(r=bT.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bY[1]&&r[2]==bY[2]&&(r[3]||(r[1]==="http:"?80:443))==(bY[3]||(bY[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),ca(bV,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bM.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bO.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bS,"$1_="+x);d.url=y+(y===d.url?(bO.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bZ+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=ca(bW,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){s<2?w(-1,z):f.error(z)}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)cc(g,a[g],c,e);return d.join("&").replace(bF,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cf=f.now(),cg=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cf++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(cg.test(b.url)||e&&cg.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(cg,l),b.url===j&&(e&&(k=k.replace(cg,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ch=a.ActiveXObject?function(){for(var a in cj)cj[a](0,1)}:!1,ci=0,cj;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ck()||cl()}:ck,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ch&&delete cj[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++ci,ch&&(cj||(cj={},f(a).unload(ch)),cj[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cm={},cn,co,cp=/^(?:toggle|show|hide)$/,cq=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cr,cs=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],ct;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cw("show",3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cz.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cz.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cA(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cA(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f})(window); -------------------------------------------------------------------------------- /src/middleware/live_logger/public/jquery.mustache.js: -------------------------------------------------------------------------------- 1 | /* 2 | Shameless port of a shameless port 3 | @defunkt => @janl => @aq 4 | 5 | See http://github.com/defunkt/mustache for more info. 6 | */ 7 | 8 | ;(function($) { 9 | 10 | /* 11 | mustache.js — Logic-less templates in JavaScript 12 | 13 | See http://mustache.github.com/ for more info. 14 | */ 15 | 16 | var Mustache = function() { 17 | var regexCache = {}; 18 | var Renderer = function() {}; 19 | 20 | Renderer.prototype = { 21 | otag: "{{", 22 | ctag: "}}", 23 | pragmas: {}, 24 | buffer: [], 25 | pragmas_implemented: { 26 | "IMPLICIT-ITERATOR": true 27 | }, 28 | context: {}, 29 | 30 | render: function(template, context, partials, in_recursion) { 31 | // reset buffer & set context 32 | if(!in_recursion) { 33 | this.context = context; 34 | this.buffer = []; // TODO: make this non-lazy 35 | } 36 | 37 | // fail fast 38 | if(!this.includes("", template)) { 39 | if(in_recursion) { 40 | return template; 41 | } else { 42 | this.send(template); 43 | return; 44 | } 45 | } 46 | 47 | // get the pragmas together 48 | template = this.render_pragmas(template); 49 | 50 | // render the template 51 | var html = this.render_section(template, context, partials); 52 | 53 | // render_section did not find any sections, we still need to render the tags 54 | if (html === false) { 55 | html = this.render_tags(template, context, partials, in_recursion); 56 | } 57 | 58 | if (in_recursion) { 59 | return html; 60 | } else { 61 | this.sendLines(html); 62 | } 63 | }, 64 | 65 | /* 66 | Sends parsed lines 67 | */ 68 | send: function(line) { 69 | if(line !== "") { 70 | this.buffer.push(line); 71 | } 72 | }, 73 | 74 | sendLines: function(text) { 75 | if (text) { 76 | var lines = text.split("\n"); 77 | for (var i = 0; i < lines.length; i++) { 78 | this.send(lines[i]); 79 | } 80 | } 81 | }, 82 | 83 | /* 84 | Looks for %PRAGMAS 85 | */ 86 | render_pragmas: function(template) { 87 | // no pragmas 88 | if(!this.includes("%", template)) { 89 | return template; 90 | } 91 | 92 | var that = this; 93 | var regex = this.getCachedRegex("render_pragmas", function(otag, ctag) { 94 | return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g"); 95 | }); 96 | 97 | return template.replace(regex, function(match, pragma, options) { 98 | if(!that.pragmas_implemented[pragma]) { 99 | throw({message: 100 | "This implementation of mustache doesn't understand the '" + 101 | pragma + "' pragma"}); 102 | } 103 | that.pragmas[pragma] = {}; 104 | if(options) { 105 | var opts = options.split("="); 106 | that.pragmas[pragma][opts[0]] = opts[1]; 107 | } 108 | return ""; 109 | // ignore unknown pragmas silently 110 | }); 111 | }, 112 | 113 | /* 114 | Tries to find a partial in the curent scope and render it 115 | */ 116 | render_partial: function(name, context, partials) { 117 | name = this.trim(name); 118 | if(!partials || partials[name] === undefined) { 119 | throw({message: "unknown_partial '" + name + "'"}); 120 | } 121 | if(typeof(context[name]) != "object") { 122 | return this.render(partials[name], context, partials, true); 123 | } 124 | return this.render(partials[name], context[name], partials, true); 125 | }, 126 | 127 | /* 128 | Renders inverted (^) and normal (#) sections 129 | */ 130 | render_section: function(template, context, partials) { 131 | if(!this.includes("#", template) && !this.includes("^", template)) { 132 | // did not render anything, there were no sections 133 | return false; 134 | } 135 | 136 | var that = this; 137 | 138 | var regex = this.getCachedRegex("render_section", function(otag, ctag) { 139 | // This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder 140 | return new RegExp( 141 | "^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1) 142 | 143 | otag + // {{ 144 | "(\\^|\\#)\\s*(.+)\\s*" + // #foo (# == $2, foo == $3) 145 | ctag + // }} 146 | 147 | "\n*([\\s\\S]*?)" + // between the tag ($2). leading newlines are dropped 148 | 149 | otag + // {{ 150 | "\\/\\s*\\3\\s*" + // /foo (backreference to the opening tag). 151 | ctag + // }} 152 | 153 | "\\s*([\\s\\S]*)$", // everything else in the string ($4). leading whitespace is dropped. 154 | 155 | "g"); 156 | }); 157 | 158 | 159 | // for each {{#foo}}{{/foo}} section do... 160 | return template.replace(regex, function(match, before, type, name, content, after) { 161 | // before contains only tags, no sections 162 | var renderedBefore = before ? that.render_tags(before, context, partials, true) : "", 163 | 164 | // after may contain both sections and tags, so use full rendering function 165 | renderedAfter = after ? that.render(after, context, partials, true) : "", 166 | 167 | // will be computed below 168 | renderedContent, 169 | 170 | value = that.find(name, context); 171 | 172 | if (type === "^") { // inverted section 173 | if (!value || that.is_array(value) && value.length === 0) { 174 | // false or empty list, render it 175 | renderedContent = that.render(content, context, partials, true); 176 | } else { 177 | renderedContent = ""; 178 | } 179 | } else if (type === "#") { // normal section 180 | if (that.is_array(value)) { // Enumerable, Let's loop! 181 | renderedContent = that.map(value, function(row) { 182 | return that.render(content, that.create_context(row), partials, true); 183 | }).join(""); 184 | } else if (that.is_object(value)) { // Object, Use it as subcontext! 185 | renderedContent = that.render(content, that.create_context(value), 186 | partials, true); 187 | } else if (typeof value === "function") { 188 | // higher order section 189 | renderedContent = value.call(context, content, function(text) { 190 | return that.render(text, context, partials, true); 191 | }); 192 | } else if (value) { // boolean section 193 | renderedContent = that.render(content, context, partials, true); 194 | } else { 195 | renderedContent = ""; 196 | } 197 | } 198 | 199 | return renderedBefore + renderedContent + renderedAfter; 200 | }); 201 | }, 202 | 203 | /* 204 | Replace {{foo}} and friends with values from our view 205 | */ 206 | render_tags: function(template, context, partials, in_recursion) { 207 | // tit for tat 208 | var that = this; 209 | 210 | 211 | 212 | var new_regex = function() { 213 | return that.getCachedRegex("render_tags", function(otag, ctag) { 214 | return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g"); 215 | }); 216 | }; 217 | 218 | var regex = new_regex(); 219 | var tag_replace_callback = function(match, operator, name) { 220 | switch(operator) { 221 | case "!": // ignore comments 222 | return ""; 223 | case "=": // set new delimiters, rebuild the replace regexp 224 | that.set_delimiters(name); 225 | regex = new_regex(); 226 | return ""; 227 | case ">": // render partial 228 | return that.render_partial(name, context, partials); 229 | case "{": // the triple mustache is unescaped 230 | return that.find(name, context); 231 | default: // escape the value 232 | return that.escape(that.find(name, context)); 233 | } 234 | }; 235 | var lines = template.split("\n"); 236 | for(var i = 0; i < lines.length; i++) { 237 | lines[i] = lines[i].replace(regex, tag_replace_callback, this); 238 | if(!in_recursion) { 239 | this.send(lines[i]); 240 | } 241 | } 242 | 243 | if(in_recursion) { 244 | return lines.join("\n"); 245 | } 246 | }, 247 | 248 | set_delimiters: function(delimiters) { 249 | var dels = delimiters.split(" "); 250 | this.otag = this.escape_regex(dels[0]); 251 | this.ctag = this.escape_regex(dels[1]); 252 | }, 253 | 254 | escape_regex: function(text) { 255 | // thank you Simon Willison 256 | if(!arguments.callee.sRE) { 257 | var specials = [ 258 | '/', '.', '*', '+', '?', '|', 259 | '(', ')', '[', ']', '{', '}', '\\' 260 | ]; 261 | arguments.callee.sRE = new RegExp( 262 | '(\\' + specials.join('|\\') + ')', 'g' 263 | ); 264 | } 265 | return text.replace(arguments.callee.sRE, '\\$1'); 266 | }, 267 | 268 | /* 269 | find `name` in current `context`. That is find me a value 270 | from the view object 271 | */ 272 | find: function(name, context) { 273 | name = this.trim(name); 274 | 275 | // Checks whether a value is thruthy or false or 0 276 | function is_kinda_truthy(bool) { 277 | return bool === false || bool === 0 || bool; 278 | } 279 | 280 | var value; 281 | 282 | // check for dot notation eg. foo.bar 283 | if(name.match(/([a-z_]+)\./ig)){ 284 | var childValue = this.walk_context(name, context); 285 | if(is_kinda_truthy(childValue)) { 286 | value = childValue; 287 | } 288 | } 289 | else{ 290 | if(is_kinda_truthy(context[name])) { 291 | value = context[name]; 292 | } else if(is_kinda_truthy(this.context[name])) { 293 | value = this.context[name]; 294 | } 295 | } 296 | 297 | if(typeof value === "function") { 298 | return value.apply(context); 299 | } 300 | if(value !== undefined) { 301 | return value; 302 | } 303 | // silently ignore unkown variables 304 | return ""; 305 | }, 306 | 307 | walk_context: function(name, context){ 308 | var path = name.split('.'); 309 | // if the var doesn't exist in current context, check the top level context 310 | var value_context = (context[path[0]] != undefined) ? context : this.context; 311 | var value = value_context[path.shift()]; 312 | while(value != undefined && path.length > 0){ 313 | value_context = value; 314 | value = value[path.shift()]; 315 | } 316 | // if the value is a function, call it, binding the correct context 317 | if(typeof value === "function") { 318 | return value.apply(value_context); 319 | } 320 | return value; 321 | }, 322 | 323 | // Utility methods 324 | 325 | /* includes tag */ 326 | includes: function(needle, haystack) { 327 | return haystack.indexOf(this.otag + needle) != -1; 328 | }, 329 | 330 | /* 331 | Does away with nasty characters 332 | */ 333 | escape: function(s) { 334 | s = String(s === null ? "" : s); 335 | return s.replace(/&(?!\w+;)|["'<>\\]/g, function(s) { 336 | switch(s) { 337 | case "&": return "&"; 338 | case '"': return '"'; 339 | case "'": return '''; 340 | case "<": return "<"; 341 | case ">": return ">"; 342 | default: return s; 343 | } 344 | }); 345 | }, 346 | 347 | // by @langalex, support for arrays of strings 348 | create_context: function(_context) { 349 | if(this.is_object(_context)) { 350 | return _context; 351 | } else { 352 | var iterator = "."; 353 | if(this.pragmas["IMPLICIT-ITERATOR"]) { 354 | iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator; 355 | } 356 | var ctx = {}; 357 | ctx[iterator] = _context; 358 | return ctx; 359 | } 360 | }, 361 | 362 | is_object: function(a) { 363 | return a && typeof a == "object"; 364 | }, 365 | 366 | is_array: function(a) { 367 | return Object.prototype.toString.call(a) === '[object Array]'; 368 | }, 369 | 370 | /* 371 | Gets rid of leading and trailing whitespace 372 | */ 373 | trim: function(s) { 374 | return s.replace(/^\s*|\s*$/g, ""); 375 | }, 376 | 377 | /* 378 | Why, why, why? Because IE. Cry, cry cry. 379 | */ 380 | map: function(array, fn) { 381 | if (typeof array.map == "function") { 382 | return array.map(fn); 383 | } else { 384 | var r = []; 385 | var l = array.length; 386 | for(var i = 0; i < l; i++) { 387 | r.push(fn(array[i])); 388 | } 389 | return r; 390 | } 391 | }, 392 | 393 | getCachedRegex: function(name, generator) { 394 | var byOtag = regexCache[this.otag]; 395 | if (!byOtag) { 396 | byOtag = regexCache[this.otag] = {}; 397 | } 398 | 399 | var byCtag = byOtag[this.ctag]; 400 | if (!byCtag) { 401 | byCtag = byOtag[this.ctag] = {}; 402 | } 403 | 404 | var regex = byCtag[name]; 405 | if (!regex) { 406 | regex = byCtag[name] = generator(this.otag, this.ctag); 407 | } 408 | 409 | return regex; 410 | } 411 | }; 412 | 413 | return({ 414 | name: "mustache.js", 415 | version: "0.4.0-dev", 416 | 417 | /* 418 | Turns a template and view into HTML 419 | */ 420 | to_html: function(template, view, partials, send_fun) { 421 | var renderer = new Renderer(); 422 | if(send_fun) { 423 | renderer.send = send_fun; 424 | } 425 | renderer.render(template, view || {}, partials); 426 | if(!send_fun) { 427 | return renderer.buffer.join("\n"); 428 | } 429 | } 430 | }); 431 | }(); 432 | 433 | $.mustache = function(template, view, partials) { 434 | return Mustache.to_html(template, view, partials); 435 | }; 436 | 437 | })(jQuery); 438 | -------------------------------------------------------------------------------- /src/middleware/live_logger/public/json2.js: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.JSON.org/json2.js 3 | 2009-09-29 4 | 5 | Public Domain. 6 | 7 | NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. 8 | 9 | See http://www.JSON.org/js.html 10 | 11 | 12 | This code should be minified before deployment. 13 | See http://javascript.crockford.com/jsmin.html 14 | 15 | USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO 16 | NOT CONTROL. 17 | 18 | 19 | This file creates a global JSON object containing two methods: stringify 20 | and parse. 21 | 22 | JSON.stringify(value, replacer, space) 23 | value any JavaScript value, usually an object or array. 24 | 25 | replacer an optional parameter that determines how object 26 | values are stringified for objects. It can be a 27 | function or an array of strings. 28 | 29 | space an optional parameter that specifies the indentation 30 | of nested structures. If it is omitted, the text will 31 | be packed without extra whitespace. If it is a number, 32 | it will specify the number of spaces to indent at each 33 | level. If it is a string (such as '\t' or ' '), 34 | it contains the characters used to indent at each level. 35 | 36 | This method produces a JSON text from a JavaScript value. 37 | 38 | When an object value is found, if the object contains a toJSON 39 | method, its toJSON method will be called and the result will be 40 | stringified. A toJSON method does not serialize: it returns the 41 | value represented by the name/value pair that should be serialized, 42 | or undefined if nothing should be serialized. The toJSON method 43 | will be passed the key associated with the value, and this will be 44 | bound to the value 45 | 46 | For example, this would serialize Dates as ISO strings. 47 | 48 | Date.prototype.toJSON = function (key) { 49 | function f(n) { 50 | // Format integers to have at least two digits. 51 | return n < 10 ? '0' + n : n; 52 | } 53 | 54 | return this.getUTCFullYear() + '-' + 55 | f(this.getUTCMonth() + 1) + '-' + 56 | f(this.getUTCDate()) + 'T' + 57 | f(this.getUTCHours()) + ':' + 58 | f(this.getUTCMinutes()) + ':' + 59 | f(this.getUTCSeconds()) + 'Z'; 60 | }; 61 | 62 | You can provide an optional replacer method. It will be passed the 63 | key and value of each member, with this bound to the containing 64 | object. The value that is returned from your method will be 65 | serialized. If your method returns undefined, then the member will 66 | be excluded from the serialization. 67 | 68 | If the replacer parameter is an array of strings, then it will be 69 | used to select the members to be serialized. It filters the results 70 | such that only members with keys listed in the replacer array are 71 | stringified. 72 | 73 | Values that do not have JSON representations, such as undefined or 74 | functions, will not be serialized. Such values in objects will be 75 | dropped; in arrays they will be replaced with null. You can use 76 | a replacer function to replace those with JSON values. 77 | JSON.stringify(undefined) returns undefined. 78 | 79 | The optional space parameter produces a stringification of the 80 | value that is filled with line breaks and indentation to make it 81 | easier to read. 82 | 83 | If the space parameter is a non-empty string, then that string will 84 | be used for indentation. If the space parameter is a number, then 85 | the indentation will be that many spaces. 86 | 87 | Example: 88 | 89 | text = JSON.stringify(['e', {pluribus: 'unum'}]); 90 | // text is '["e",{"pluribus":"unum"}]' 91 | 92 | 93 | text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); 94 | // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' 95 | 96 | text = JSON.stringify([new Date()], function (key, value) { 97 | return this[key] instanceof Date ? 98 | 'Date(' + this[key] + ')' : value; 99 | }); 100 | // text is '["Date(---current time---)"]' 101 | 102 | 103 | JSON.parse(text, reviver) 104 | This method parses a JSON text to produce an object or array. 105 | It can throw a SyntaxError exception. 106 | 107 | The optional reviver parameter is a function that can filter and 108 | transform the results. It receives each of the keys and values, 109 | and its return value is used instead of the original value. 110 | If it returns what it received, then the structure is not modified. 111 | If it returns undefined then the member is deleted. 112 | 113 | Example: 114 | 115 | // Parse the text. Values that look like ISO date strings will 116 | // be converted to Date objects. 117 | 118 | myData = JSON.parse(text, function (key, value) { 119 | var a; 120 | if (typeof value === 'string') { 121 | a = 122 | /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); 123 | if (a) { 124 | return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], 125 | +a[5], +a[6])); 126 | } 127 | } 128 | return value; 129 | }); 130 | 131 | myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { 132 | var d; 133 | if (typeof value === 'string' && 134 | value.slice(0, 5) === 'Date(' && 135 | value.slice(-1) === ')') { 136 | d = new Date(value.slice(5, -1)); 137 | if (d) { 138 | return d; 139 | } 140 | } 141 | return value; 142 | }); 143 | 144 | 145 | This is a reference implementation. You are free to copy, modify, or 146 | redistribute. 147 | */ 148 | 149 | /*jslint evil: true, strict: false */ 150 | 151 | /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, 152 | call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, 153 | getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, 154 | lastIndex, length, parse, prototype, push, replace, slice, stringify, 155 | test, toJSON, toString, valueOf 156 | */ 157 | 158 | 159 | // Create a JSON object only if one does not already exist. We create the 160 | // methods in a closure to avoid creating global variables. 161 | 162 | if (!this.JSON) { 163 | this.JSON = {}; 164 | } 165 | 166 | (function () { 167 | 168 | function f(n) { 169 | // Format integers to have at least two digits. 170 | return n < 10 ? '0' + n : n; 171 | } 172 | 173 | if (typeof Date.prototype.toJSON !== 'function') { 174 | 175 | Date.prototype.toJSON = function (key) { 176 | 177 | return isFinite(this.valueOf()) ? 178 | this.getUTCFullYear() + '-' + 179 | f(this.getUTCMonth() + 1) + '-' + 180 | f(this.getUTCDate()) + 'T' + 181 | f(this.getUTCHours()) + ':' + 182 | f(this.getUTCMinutes()) + ':' + 183 | f(this.getUTCSeconds()) + 'Z' : null; 184 | }; 185 | 186 | String.prototype.toJSON = 187 | Number.prototype.toJSON = 188 | Boolean.prototype.toJSON = function (key) { 189 | return this.valueOf(); 190 | }; 191 | } 192 | 193 | var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, 194 | escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, 195 | gap, 196 | indent, 197 | meta = { // table of character substitutions 198 | '\b': '\\b', 199 | '\t': '\\t', 200 | '\n': '\\n', 201 | '\f': '\\f', 202 | '\r': '\\r', 203 | '"' : '\\"', 204 | '\\': '\\\\' 205 | }, 206 | rep; 207 | 208 | 209 | function quote(string) { 210 | 211 | // If the string contains no control characters, no quote characters, and no 212 | // backslash characters, then we can safely slap some quotes around it. 213 | // Otherwise we must also replace the offending characters with safe escape 214 | // sequences. 215 | 216 | escapable.lastIndex = 0; 217 | return escapable.test(string) ? 218 | '"' + string.replace(escapable, function (a) { 219 | var c = meta[a]; 220 | return typeof c === 'string' ? c : 221 | '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 222 | }) + '"' : 223 | '"' + string + '"'; 224 | } 225 | 226 | 227 | function str(key, holder) { 228 | 229 | // Produce a string from holder[key]. 230 | 231 | var i, // The loop counter. 232 | k, // The member key. 233 | v, // The member value. 234 | length, 235 | mind = gap, 236 | partial, 237 | value = holder[key]; 238 | 239 | // If the value has a toJSON method, call it to obtain a replacement value. 240 | 241 | if (value && typeof value === 'object' && 242 | typeof value.toJSON === 'function') { 243 | value = value.toJSON(key); 244 | } 245 | 246 | // If we were called with a replacer function, then call the replacer to 247 | // obtain a replacement value. 248 | 249 | if (typeof rep === 'function') { 250 | value = rep.call(holder, key, value); 251 | } 252 | 253 | // What happens next depends on the value's type. 254 | 255 | switch (typeof value) { 256 | case 'string': 257 | return quote(value); 258 | 259 | case 'number': 260 | 261 | // JSON numbers must be finite. Encode non-finite numbers as null. 262 | 263 | return isFinite(value) ? String(value) : 'null'; 264 | 265 | case 'boolean': 266 | case 'null': 267 | 268 | // If the value is a boolean or null, convert it to a string. Note: 269 | // typeof null does not produce 'null'. The case is included here in 270 | // the remote chance that this gets fixed someday. 271 | 272 | return String(value); 273 | 274 | // If the type is 'object', we might be dealing with an object or an array or 275 | // null. 276 | 277 | case 'object': 278 | 279 | // Due to a specification blunder in ECMAScript, typeof null is 'object', 280 | // so watch out for that case. 281 | 282 | if (!value) { 283 | return 'null'; 284 | } 285 | 286 | // Make an array to hold the partial results of stringifying this object value. 287 | 288 | gap += indent; 289 | partial = []; 290 | 291 | // Is the value an array? 292 | 293 | if (Object.prototype.toString.apply(value) === '[object Array]') { 294 | 295 | // The value is an array. Stringify every element. Use null as a placeholder 296 | // for non-JSON values. 297 | 298 | length = value.length; 299 | for (i = 0; i < length; i += 1) { 300 | partial[i] = str(i, value) || 'null'; 301 | } 302 | 303 | // Join all of the elements together, separated with commas, and wrap them in 304 | // brackets. 305 | 306 | v = partial.length === 0 ? '[]' : 307 | gap ? '[\n' + gap + 308 | partial.join(',\n' + gap) + '\n' + 309 | mind + ']' : 310 | '[' + partial.join(',') + ']'; 311 | gap = mind; 312 | return v; 313 | } 314 | 315 | // If the replacer is an array, use it to select the members to be stringified. 316 | 317 | if (rep && typeof rep === 'object') { 318 | length = rep.length; 319 | for (i = 0; i < length; i += 1) { 320 | k = rep[i]; 321 | if (typeof k === 'string') { 322 | v = str(k, value); 323 | if (v) { 324 | partial.push(quote(k) + (gap ? ': ' : ':') + v); 325 | } 326 | } 327 | } 328 | } else { 329 | 330 | // Otherwise, iterate through all of the keys in the object. 331 | 332 | for (k in value) { 333 | if (Object.hasOwnProperty.call(value, k)) { 334 | v = str(k, value); 335 | if (v) { 336 | partial.push(quote(k) + (gap ? ': ' : ':') + v); 337 | } 338 | } 339 | } 340 | } 341 | 342 | // Join all of the member texts together, separated with commas, 343 | // and wrap them in braces. 344 | 345 | v = partial.length === 0 ? '{}' : 346 | gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + 347 | mind + '}' : '{' + partial.join(',') + '}'; 348 | gap = mind; 349 | return v; 350 | } 351 | } 352 | 353 | // If the JSON object does not yet have a stringify method, give it one. 354 | 355 | if (typeof JSON.stringify !== 'function') { 356 | JSON.stringify = function (value, replacer, space) { 357 | 358 | // The stringify method takes a value and an optional replacer, and an optional 359 | // space parameter, and returns a JSON text. The replacer can be a function 360 | // that can replace values, or an array of strings that will select the keys. 361 | // A default replacer method can be provided. Use of the space parameter can 362 | // produce text that is more easily readable. 363 | 364 | var i; 365 | gap = ''; 366 | indent = ''; 367 | 368 | // If the space parameter is a number, make an indent string containing that 369 | // many spaces. 370 | 371 | if (typeof space === 'number') { 372 | for (i = 0; i < space; i += 1) { 373 | indent += ' '; 374 | } 375 | 376 | // If the space parameter is a string, it will be used as the indent string. 377 | 378 | } else if (typeof space === 'string') { 379 | indent = space; 380 | } 381 | 382 | // If there is a replacer, it must be a function or an array. 383 | // Otherwise, throw an error. 384 | 385 | rep = replacer; 386 | if (replacer && typeof replacer !== 'function' && 387 | (typeof replacer !== 'object' || 388 | typeof replacer.length !== 'number')) { 389 | throw new Error('JSON.stringify'); 390 | } 391 | 392 | // Make a fake root object containing our value under the key of ''. 393 | // Return the result of stringifying the value. 394 | 395 | return str('', {'': value}); 396 | }; 397 | } 398 | 399 | 400 | // If the JSON object does not yet have a parse method, give it one. 401 | 402 | if (typeof JSON.parse !== 'function') { 403 | JSON.parse = function (text, reviver) { 404 | 405 | // The parse method takes a text and an optional reviver function, and returns 406 | // a JavaScript value if the text is a valid JSON text. 407 | 408 | var j; 409 | 410 | function walk(holder, key) { 411 | 412 | // The walk method is used to recursively walk the resulting structure so 413 | // that modifications can be made. 414 | 415 | var k, v, value = holder[key]; 416 | if (value && typeof value === 'object') { 417 | for (k in value) { 418 | if (Object.hasOwnProperty.call(value, k)) { 419 | v = walk(value, k); 420 | if (v !== undefined) { 421 | value[k] = v; 422 | } else { 423 | delete value[k]; 424 | } 425 | } 426 | } 427 | } 428 | return reviver.call(holder, key, value); 429 | } 430 | 431 | 432 | // Parsing happens in four stages. In the first stage, we replace certain 433 | // Unicode characters with escape sequences. JavaScript handles many characters 434 | // incorrectly, either silently deleting them, or treating them as line endings. 435 | 436 | cx.lastIndex = 0; 437 | if (cx.test(text)) { 438 | text = text.replace(cx, function (a) { 439 | return '\\u' + 440 | ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 441 | }); 442 | } 443 | 444 | // In the second stage, we run the text against regular expressions that look 445 | // for non-JSON patterns. We are especially concerned with '()' and 'new' 446 | // because they can cause invocation, and '=' because it can cause mutation. 447 | // But just to be safe, we want to reject all unexpected forms. 448 | 449 | // We split the second stage into 4 regexp operations in order to work around 450 | // crippling inefficiencies in IE's and Safari's regexp engines. First we 451 | // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we 452 | // replace all simple value tokens with ']' characters. Third, we delete all 453 | // open brackets that follow a colon or comma or that begin the text. Finally, 454 | // we look to see that the remaining characters are only whitespace or ']' or 455 | // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. 456 | 457 | if (/^[\],:{}\s]*$/. 458 | test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). 459 | replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). 460 | replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { 461 | 462 | // In the third stage we use the eval function to compile the text into a 463 | // JavaScript structure. The '{' operator is subject to a syntactic ambiguity 464 | // in JavaScript: it can begin a block or an object literal. We wrap the text 465 | // in parens to eliminate the ambiguity. 466 | 467 | j = eval('(' + text + ')'); 468 | 469 | // In the optional fourth stage, we recursively walk the new structure, passing 470 | // each name/value pair to a reviver function for possible transformation. 471 | 472 | return typeof reviver === 'function' ? 473 | walk({'': j}, '') : j; 474 | } 475 | 476 | // If the text is not JSON parseable, then a SyntaxError is thrown. 477 | 478 | throw new SyntaxError('JSON.parse'); 479 | }; 480 | } 481 | }()); -------------------------------------------------------------------------------- /src/middleware/live_logger/public/stylesheets/default.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-image: url(/images/background.png); 3 | padding: 2em 0; 4 | color: #CCC; 5 | } 6 | 7 | pre { 8 | white-space: pre-wrap; /* css-3 */ 9 | white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ 10 | white-space: -pre-wrap; /* Opera 4-6 */ 11 | white-space: -o-pre-wrap; /* Opera 7 */ 12 | word-wrap: break-word; /* Internet Explorer 5.5+ */ 13 | } 14 | 15 | h1 { 16 | font-size: 3em; 17 | } 18 | 19 | h2 { 20 | font-size: 2em; 21 | } 22 | 23 | h3 { 24 | font-size: 1.5em; 25 | margin-bottom: 0.25em; 26 | margin-top: 0.5em; 27 | border-bottom: 1px solid #333; 28 | } 29 | 30 | #request { 31 | margin:0 4em; 32 | padding-left: 0.75em; 33 | padding-bottom: 1em; 34 | background-color: rgba(0, 0, 0, 0.25); 35 | } 36 | 37 | #scroll-btn { 38 | position:fixed; 39 | font-size: 10em; 40 | color: #333; 41 | bottom:10px; 42 | left:10px; 43 | cursor: pointer; 44 | -webkit-user-select: none; 45 | -moz-user-select: none; 46 | user-select: none; 47 | } 48 | 49 | #scroll-btn.active { 50 | color: #FF9933; 51 | background: none; 52 | -webkit-text-fill-color: #FF9933; 53 | } 54 | .header { 55 | border-bottom: 1px solid #FF9933; 56 | margin: 1em 0; 57 | } 58 | 59 | .content { 60 | margin-left: 1em; 61 | } 62 | 63 | ul#requests li{ 64 | width: 80%; 65 | margin-left:10%; 66 | margin-bottom: 0.75em; 67 | padding: 0.25em 0.5em; 68 | overflow: hidden; 69 | background-color: #222; 70 | list-style-type: none; 71 | color: #CCC; 72 | } 73 | 74 | ul.headers li { 75 | margin-bottom:0.20em; 76 | } 77 | 78 | ul#requests li .line div { 79 | display: inline-block; 80 | } 81 | 82 | ul#requests li .subline div { 83 | display: inline-block; 84 | } 85 | 86 | li .method { 87 | width: 5%; 88 | overflow: hidden; 89 | border-right: 1px solid #333; 90 | } 91 | 92 | li .url { 93 | width: 85%; 94 | padding-left: 1em; 95 | overflow: hidden; 96 | white-space: nowrap; 97 | } 98 | 99 | li .status { 100 | text-align: center; 101 | width: 5%; 102 | overflow: hidden; 103 | white-space: nowrap; 104 | border-left: 1px solid #333; 105 | float: right; 106 | } 107 | 108 | .line { 109 | width: 100%; 110 | } 111 | 112 | .subline { 113 | font-size: 80%; 114 | font-style: italic; 115 | width: 100%; 116 | } 117 | 118 | .put { 119 | border-left: 3px solid #FC3; 120 | } 121 | 122 | .post { 123 | border-left: 3px solid #F93; 124 | } 125 | 126 | .get { 127 | border-left: 3px solid #993; 128 | } 129 | 130 | .delete { 131 | border-left: 3px solid #F33; 132 | } 133 | 134 | .two_hundred { 135 | border-right: 3px solid #993; 136 | } 137 | 138 | .three_hundred { 139 | border-right: 3px solid #339; 140 | } 141 | 142 | .four_hundred { 143 | border-right: 3px solid #F33; 144 | } 145 | 146 | .five_hundred { 147 | border-right: 3px solid #F93; 148 | } 149 | -------------------------------------------------------------------------------- /src/middleware/live_logger/public/stylesheets/reset.css: -------------------------------------------------------------------------------- 1 | /* 2 | YUI 3.4.1 (build 4118) 3 | Copyright 2011 Yahoo! Inc. All rights reserved. 4 | Licensed under the BSD License. 5 | http://yuilibrary.com/license/ 6 | */ 7 | html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit}input,textarea,select{*font-size:100%}legend{color:#000} -------------------------------------------------------------------------------- /src/middleware/live_logger/public/underscore-min.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.2.2 2 | // (c) 2011 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function r(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(b.isFunction(a.isEqual))return a.isEqual(c);if(b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return String(a)==String(c);case "[object Number]":return a=+a,c=+c,a!=a?c!=c:a==0?1/a==1/c:a==c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&r(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(m.call(a,h)&&(f++,!(g=m.call(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(m.call(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var s=this,F=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,G=k.unshift,l=p.toString,m=p.hasOwnProperty,v=k.forEach,w=k.map,x=k.reduce,y=k.reduceRight,z=k.filter,A=k.every,B=k.some,q=k.indexOf,C=k.lastIndexOf,p=Array.isArray,H=Object.keys,t=Function.prototype.bind,b=function(a){return new n(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else typeof define==="function"&&define.amd? 11 | define("underscore",function(){return b}):s._=b;b.VERSION="1.2.2";var j=b.each=b.forEach=function(a,c,b){if(a!=null)if(v&&a.forEach===v)a.forEach(c,b);else if(a.length===+a.length)for(var e=0,f=a.length;e=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,c){var b=e(a,c);(d[b]||(d[b]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e< 17 | f;){var g=e+f>>1;d(a[g])=0})})};b.difference=function(a,c){return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=H||function(a){if(a!== 24 | Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)m.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)b[d]!==void 0&&(a[d]=b[d])});return a};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)? 25 | a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(m.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=l.call(arguments)=="[object Arguments]"?function(a){return l.call(a)=="[object Arguments]"}: 26 | function(a){return!(!a||!m.call(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null}; 27 | b.isUndefined=function(a){return a===void 0};b.noConflict=function(){s._=F;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a),function(c){I(c,b[c]=a[c])})};var J=0;b.uniqueId=function(a){var b=J++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g, 28 | interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape,function(a,b){return"',_.escape("+b.replace(/\\'/g,"'")+"),'"}).replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g, 29 | "\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e(a,b)}};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var u=function(a,c){return c?b(a).chain():a},I=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);G.call(a,this._wrapped);return u(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){b.apply(this._wrapped, 30 | arguments);return u(this._wrapped,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return u(b.apply(this._wrapped,arguments),this._chain)}});n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this); 31 | -------------------------------------------------------------------------------- /src/middleware/replace.coffee: -------------------------------------------------------------------------------- 1 | sessionFilter = require '../session_filter' 2 | 3 | # Can only be filtered by request for now 4 | # Takes a function(bodyString){return "new value") 5 | exports = module.exports = (replacer, filter) -> 6 | filter ||= {} 7 | return (req, res, next) -> 8 | if !sessionFilter.matches(filter.request, req) 9 | return next() 10 | writeHead = res.writeHead 11 | write = res.write 12 | end = res.end 13 | res.writeHead = (status, h) -> 14 | # Nope 15 | res.write = (data) -> 16 | # Nope 17 | res.end = (data) -> 18 | # Nope 19 | res.on 'body', -> 20 | if res.isBinary 21 | res.headers['content-length'] = res.length 22 | writeHead.call(res, res.statusCode, res.headers) 23 | write.call(res, res.body) if res.length > 0 24 | end.call(res) 25 | else 26 | content = res.body.toString('utf-8') 27 | 28 | # Can return false if no action needs to be taken 29 | replacedContent = replacer(content, req, res) 30 | content = replacedContent || content 31 | 32 | # Set the new length 33 | res.headers['content-length'] = content.length 34 | # No more gzip for you 35 | delete res.headers['content-encoding'] 36 | 37 | writeHead.call(res, res.statusCode, res.headers) 38 | end.call(res, content) 39 | next() 40 | 41 | -------------------------------------------------------------------------------- /src/middleware/user_agent.coffee: -------------------------------------------------------------------------------- 1 | sessionFilter = require '../session_filter' 2 | exports = module.exports = (ua, requestFilter) -> 3 | return (req, res, next) -> 4 | if sessionFilter.matches(requestFilter,req) 5 | req.headers['user-agent'] = ua 6 | next() 7 | 8 | -------------------------------------------------------------------------------- /src/proxy.coffee: -------------------------------------------------------------------------------- 1 | net = require('net') 2 | _ = require('underscore') 3 | tls = require('tls') 4 | http = require('http') 5 | {HttpProxy} = require('./http_proxy') 6 | certGenerator = require('./cert_generator') 7 | log = require("./logger") 8 | 9 | STATES = 10 | UNCONNECTED: 0, 11 | CONNECTING : 1, 12 | CONNECTED : 2 13 | 14 | exports.createProxy = (middlewares...) -> 15 | proxy = new exports.Proxy(middlewares) 16 | return proxy 17 | 18 | # Handles both HTTP and HTTPS connections 19 | class exports.Proxy extends HttpProxy 20 | 21 | hijackSsl: (headers, c) -> 22 | match = headers.match("CONNECT +([^:]+):([0-9]+).*") 23 | host = match[1] 24 | port = match[2] 25 | certGenerator.build host, (tlsContext) => 26 | pair = tls.createSecurePair(tlsContext, true, false, false) 27 | pair.on 'error', (err) -> 28 | console.log err 29 | httpServer = new http.Server 30 | httpServer.addListener 'request', @handle 31 | cleartext = pipe(pair, c) 32 | http._connectionListener.call(this, cleartext) 33 | @httpAllowHalfOpen = false; 34 | c.write("HTTP/1.0 200 Connection established\r\nProxy-agent: MiddleFiddle\r\n\r\n") 35 | 36 | hijackHttp: (headers, c) -> 37 | httpServer = new http.Server 38 | httpServer.addListener 'request', @handle 39 | http._connectionListener.call(this, c) 40 | @httpAllowHalfOpen = false; 41 | 42 | listen: (port) -> 43 | tlsServer = net.createServer (c) => 44 | headers = '' 45 | data = [] 46 | state = STATES.UNCONNECTED 47 | c.addListener 'connect', -> 48 | state = STATES.CONNECTING 49 | c.addListener 'data', (data) => 50 | if (state != STATES.CONNECTED) 51 | headers += data.toString() 52 | if headers.match("\r\n\r\n") 53 | state = STATES.CONNECTED 54 | if (headers.match(/^CONNECT/)) 55 | @hijackSsl(headers, c) 56 | else 57 | @hijackHttp(headers, c) 58 | tlsServer.listen(port) 59 | 60 | 61 | pipe = (pair, socket) -> 62 | pair.encrypted.pipe(socket) 63 | socket.pipe(pair.encrypted) 64 | 65 | pair.fd = socket.fd 66 | cleartext = pair.cleartext 67 | cleartext.socket = socket 68 | cleartext.encrypted = pair.encrypted 69 | cleartext.authorized = false 70 | 71 | onerror = (e) -> 72 | if cleartext._controlReleased 73 | cleartext.emit('error', e) 74 | 75 | onclose = () -> 76 | socket.removeListener('error', onerror) 77 | socket.removeListener('close', onclose) 78 | socket.removeListener('timeout', ontimeout) 79 | 80 | ontimeout = () -> 81 | cleartext.emit('timeout') 82 | 83 | socket.on 'error', onerror 84 | socket.on 'close', onclose 85 | socket.on 'timeout', ontimeout 86 | 87 | return cleartext 88 | -------------------------------------------------------------------------------- /src/session_filter.coffee: -------------------------------------------------------------------------------- 1 | _ = require 'underscore' 2 | 3 | # Test the values in a reqeust or response 4 | exports.matches = matches = (filter, session) -> 5 | return true unless filter 6 | return true if filter == true 7 | if _.isFunction(filter) 8 | match = filter(session) || false 9 | return match 10 | return true unless _.keys(filter).length > 0 11 | 12 | # A word of warning about contains: 13 | # After a page loads you'll have it catched, and subsequent loads will 14 | # result in a likely 304, which of course won't show up 15 | if filter.contains && session.headers 16 | contentType = session.headers['content-type'] || '' 17 | if session.body && (contentType.search(/^(image|audio|video)/) < 0) 18 | content = '' 19 | if _.isRegExp(filter.contains) 20 | regex = filter.contains 21 | else 22 | regex = new RegExp(filter.contains, 'g') 23 | for s in session.body 24 | content += s.toString('utf-8') 25 | if(content.search(regex) >= 0) 26 | return true 27 | else 28 | return false 29 | 30 | match = false 31 | for key, test of filter 32 | if session[key] 33 | if Array.isArray(test) 34 | for t in test 35 | if check(session[key], t) 36 | match = true 37 | break 38 | else if check(session[key], test) 39 | match = true 40 | return match 41 | 42 | check = (value, test) -> 43 | if _.isRegExp(test) 44 | return true if value.search(test) >= 0 45 | else if _.isString(test) 46 | return true if value.search(test) >= 0 47 | else if _.isNumber(test) 48 | return true if value.toString().search(test.toString()) >= 0 49 | else if _.isFunction(test) 50 | return true if test(value) 51 | -------------------------------------------------------------------------------- /src/utils/ringbuffer.coffee: -------------------------------------------------------------------------------- 1 | class Ringbuffer 2 | constructor: (@size)-> 3 | @items = [] 4 | @count = 0 5 | 6 | add: (item) -> 7 | index = @count % @size 8 | @count++ 9 | item._timestamp = Number(new Date) 10 | @items[index] = item 11 | @buildKey(index, item) 12 | 13 | all: () -> 14 | @items 15 | 16 | retrieve: (key) -> 17 | if !key.match(/^[0-9]+\-[0-9]+$/) 18 | return null 19 | index = Number(key.match(/^[0-9]+/)[0]) 20 | ts = Number(key.match(/[0-9]+$/)[0]) 21 | if index != undefined && ts 22 | item = @items[index] 23 | if item && item._timestamp == ts 24 | item 25 | else 26 | null 27 | 28 | buildKey: (index, item) -> 29 | "#{index}-#{item._timestamp}" 30 | 31 | 32 | exports.create = (size) -> 33 | new Ringbuffer(size || 1000) 34 | -------------------------------------------------------------------------------- /test/helpers/fake_server.coffee: -------------------------------------------------------------------------------- 1 | # Test image server 2 | fs = require 'fs' 3 | express = require 'express' 4 | app = express.createServer() 5 | app.listen 4040 6 | 7 | app.get '/status/:code', (req, res) -> 8 | res.send('Status code: ' + req.params.code, Number(req.params.code)); 9 | 10 | -------------------------------------------------------------------------------- /test/helpers/mock_request.coffee: -------------------------------------------------------------------------------- 1 | exports.module = 2 | url: "/foo?baz" 3 | host: "google.com" 4 | port: 80 5 | href: "http://google.com" 6 | -------------------------------------------------------------------------------- /test/helpers/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Express - node web framework 4 | 5 | 6 | 19 | 177 | 189 | 190 | 191 | 192 | Fork me on GitHub 193 | 194 |
    195 |
    196 | 197 |

    198 | High performance, high class web development for 199 | Node.js 200 |

    201 | 207 |
    var app = express.createServer();
    208 | 
    209 | app.get('/', function(req, res){
    210 |     res.send('Hello World');
    211 | });
    212 | 
    213 | app.listen(3000);
    214 | 
    215 | 216 |

    Features

    217 | 218 |
      219 |
    • Robust routing
    • 220 |
    • Redirection helpers
    • 221 |
    • Dynamic view helpers
    • 222 |
    • Application level view options
    • 223 |
    • Content negotiation
    • 224 |
    • Application mounting
    • 225 |
    • Focus on high performance
    • 226 |
    • View rendering and partials support
    • 227 |
    • Environment based configuration
    • 228 |
    • Session based flash notifications
    • 229 |
    • Built on Connect
    • 230 |
    • Executable for generating applications quickly
    • 231 |
    • High test coverage
    • 232 |
    233 | 234 | 235 |

    Contributors

    236 | 237 |

    The following are the major contributors of Express (in no specific order).

    238 | 239 | 245 | 246 | 247 |

    Third-Party Modules

    248 | 249 |

    The following modules complement or extend Express directly:

    250 | 251 | 260 | 261 | 262 |

    More Information

    263 | 264 | 271 | 272 |
    273 |
    274 | 275 | -------------------------------------------------------------------------------- /test/http_proxy_test.coffee: -------------------------------------------------------------------------------- 1 | assert = require 'assert' 2 | fake_server = require './helpers/fake_server' 3 | http = require 'http' 4 | Mf = require '../src/index' 5 | Port = 15888 6 | Mf.createProxy().listen(Port) 7 | 8 | describe 'A basic HTTP Proxy', -> 9 | 10 | describe "pass a request through", -> 11 | it 'should return 200 for a valid request', ()-> 12 | options = 13 | host: '127.0.0.1' 14 | port: Port 15 | path: '/http://127.0.0.1:4040/status/200' 16 | req = http.get options, (res) -> 17 | assert.equal res.statusCode, 200 18 | it 'should return 404 for a 404 request', ()-> 19 | options = 20 | host: '127.0.0.1' 21 | port: Port 22 | path: '/http://127.0.0.1:4040/status/404' 23 | req = http.get options, (res) -> 24 | assert.equal res.statusCode, 404 25 | 26 | describe 'A basic transparent HTTP Proxy', -> 27 | beforeEach (done) -> 28 | Mf.config.transparent = true 29 | done() 30 | 31 | describe "pass a request through", -> 32 | it 'should return 200 for a valid request', ()-> 33 | options = 34 | host: 'localhost' 35 | port: Port 36 | path: '/status/200' 37 | headers: { 38 | host: "test.dev" # Need local server running on port 80 and forwarding to 4040/Fakeserver to work 39 | } 40 | req = http.get options, (res) -> 41 | assert.equal res.statusCode, 200 42 | 43 | -------------------------------------------------------------------------------- /test/session_filter_test.coffee: -------------------------------------------------------------------------------- 1 | assert = require 'assert' 2 | session_filter = require '../src/session_filter' 3 | mock_request = require './helpers/mock_request' 4 | mock_request.headers = {} 5 | 6 | describe 'Testing a filter', -> 7 | describe "when it's given a null/undefined value", -> 8 | beforeEach (done) -> 9 | mock_request['href'] = 'http://google.com' 10 | done() 11 | 12 | it 'should return true', -> 13 | assert.equal true, session_filter.matches(null, mock_request) 14 | 15 | describe 'when given a string matcher that matches', -> 16 | 17 | it 'should return true', -> 18 | mock_request['href'] = 'http://google.com' 19 | filter = 20 | href: 'google.com' 21 | assert.equal true, session_filter.matches(filter, mock_request) 22 | 23 | describe 'when given a string matcher that does not match', -> 24 | it 'should return false', () -> 25 | mock_request['href'] = 'http://google.com' 26 | filter = 27 | href: 'bing.com' 28 | assert.equal session_filter.matches(filter, mock_request), false 29 | 30 | describe 'when given a function', -> 31 | it 'should return the function result', () -> 32 | filter = (req) -> 33 | return true 34 | assert.equal session_filter.matches(filter, mock_request), true 35 | 36 | describe 'when given a function for a key', () -> 37 | it 'should return the function result', () -> 38 | mock_request['href'] = 'http://google.com' 39 | filter = 40 | href: (url) -> 41 | return true if url.match("google") 42 | assert.equal session_filter.matches(filter, mock_request), true 43 | 44 | # Handling a contains key 45 | describe 'when given a contains with a match', () -> 46 | it 'should return true', () -> 47 | buffers = [new Buffer('middle'), new Buffer('fiddle')] 48 | mock_request['body'] = buffers 49 | mock_request.headers['content-type'] = 'text/html' 50 | filter = 51 | contains: /middlefiddle/ 52 | assert.equal session_filter.matches(filter, mock_request), true 53 | 54 | describe 'when given a contains with a string is a match', () -> 55 | it 'should return true', () -> 56 | buffers = [new Buffer('middle'), new Buffer('fiddle')] 57 | mock_request['body'] = buffers 58 | mock_request.headers['content-type'] = 'text/html' 59 | filter = 60 | contains: 'middlefiddle' 61 | assert.equal session_filter.matches(filter, mock_request), true 62 | 63 | describe 'when given a contains with a miss', () -> 64 | it 'should return false', () -> 65 | buffers = [new Buffer('middle'), new Buffer('fiddle')] 66 | mock_request['content'] = buffers 67 | mock_request.headers['content-type'] = 'text/html' 68 | filter = 69 | contains: /middlef1ddle/ 70 | assert.equal session_filter.matches(filter, mock_request), false 71 | 72 | -------------------------------------------------------------------------------- /test/test_project.coffee: -------------------------------------------------------------------------------- 1 | project = require ".." 2 | 3 | module.exports = 4 | "true is ok": (test) -> 5 | test.ok true 6 | test.done() 7 | --------------------------------------------------------------------------------