Permalink
Browse files

recursive directory cloning

  • Loading branch information...
contra committed Sep 23, 2011
1 parent 528afc6 commit cc04373984eb1da790b20227cef4fc00475a56aa
Showing 1,710 changed files with 653,857 additions and 12 deletions.
View
@@ -15,7 +15,8 @@ short =
o: ['--out']
parsed = nopt known, short, process.argv, 2
-return log.error 'Please enter all required parameters' unless parsed.in and parsed.out
+return log.error 'Please enter all required parameters' unless parsed.in
+parsed.out ?= path.join parsed.in, '/build/'
logo = ''
logo += ' _ \r\n'
@@ -25,10 +26,10 @@ logo += '| _ \\ | _ \\ | |_/ )/ _ |\r\n'
logo += '| | | || |_| || _ (( (_| |\r\n'
logo += '|_| |_|| __/ |_| \\_)\\___ |\r\n'
logo += ' |_| (_____|\r\n'
-console.log logo
+console.log logo.red
npkg = require '../lib/main'
-basedir = './temp/'
+basedir = path.join parsed.in, '/npkg-temp/'
try
npkg.build basedir, parsed, ->
log.info 'Build completed! - Files located at ' + parsed.out
View
@@ -11,7 +11,7 @@ module.exports =
url: pack.homepage
author: pack.author
requiresjdk: 'no'
- createdBy: 'npkg' # Shameless watermarking, this isnt displayed anywhere
+ generator: 'npkg' # Shameless watermarking, this isnt displayed anywhere
# Installer variables - TODO: Let devs have a config to change these via CLI
# Example - These can be used to automatically tick desktop shortcuts etc.
View
@@ -1,3 +1,4 @@
+require 'protege'
log = require 'node-log'
log.setName 'npkg'
@@ -17,6 +18,7 @@ module.exports =
log.info 'Starting ' + pack.name + ' build'
dirs = {}
dirs.temp = temp
+ dirs.app = path.join temp, 'app/'
dirs.node = path.join temp, 'node/'
dirs.deps = path.join temp, 'deps/'
dirs.npm = path.join dirs.node, 'node_modules/'
@@ -26,8 +28,7 @@ module.exports =
if path.existsSync(dirs[dir])
rimraf.sync dirs[dir]
fs.mkdirSync dirs[dir], 0777
-
+
packer.save dirs, pack, opt, ->
info = izpack.generateXML dirs, pack, opt # Todo: Run it through izpack compile, run it though converter utils
cb()
-
View
@@ -6,7 +6,11 @@ fs = require 'fs'
util = require './util'
async = require 'async'
rimraf = require 'rimraf'
-
+
+copyApp = (dirs, pack, opt, cb) ->
+ log.info 'Cloning application...'
+ util.cloneDirectory opt.in, dirs.app, true, ['npkg-temp'], cb
+
saveNPM = (dirs, pack, opt, cb) ->
log.info 'Analyzing dependencies...'
npm.resolve opt.in, (deps) ->
@@ -22,10 +26,10 @@ saveNPM = (dirs, pack, opt, cb) ->
fs.mkdir outf, 0777, (err) ->
throw err if err
util.unpack result, outf, true, (err) ->
- throw err if err
+ if err then log.error 'Unpacking ' + dep + ' failed! Error: ' + err
call()
- async.forEach Object.keys(deps), saveModule, -> rimraf(dirs.deps, cb)
+ async.forEach Object.keys(deps), saveModule, -> rimraf dirs.deps, cb
return
saveNode = (dirs, pack, opt, cb) ->
@@ -60,4 +64,5 @@ module.exports =
## TODO: Writing installation scripts to config folder and app data to app
npmfn = (call) -> saveNPM dirs, pack, opt, call
nodefn = (call) -> saveNode dirs, pack, opt, call
- async.parallel [npmfn, nodefn], cb
+ copyfn = (call) -> copyApp dirs, pack, opt, call
+ async.parallel [copyfn, npmfn, nodefn], cb
View
@@ -1,11 +1,72 @@
path = require 'path'
log = require 'node-log'
fs = require 'fs'
+path = require 'path'
exec = require('child_process').exec
+async = require 'async'
module.exports =
unpack: (inf, out, striptop, cb) ->
cmd = 'tar -xvzf ' + inf + ' -C ' + out
if striptop then cmd += ' --strip 1'
exec cmd, (err, stdout, stderr) ->
- cb(err || stderr)
+ err ?= stderr if stderr? and !stderr.containsIgnoreCase 'Ignoring unknown extended header keyword'
+ cb err
+
+ cloneDirectory: (dir, newdir, ignore, excludes, cb) ->
+ if !cb
+ cb = excludes
+ excludes = []
+
+ clone = (file, call) ->
+ oldf = path.join dir, file
+ newf = path.join newdir, file
+ fs.stat oldf, (err, stat) ->
+ throw err if err
+ if stat.isDirectory()
+ module.exports.cloneDirectory oldf, newf, true, excludes, call
+ else
+ fs.readFile oldf, (err, data) ->
+ throw err if err
+ fs.writeFile newf, data, (err) ->
+ throw err if err
+ call()
+
+ copyAll = (call) ->
+ fs.readdir dir, (err, files) ->
+ excludes = excludes.unique()
+ files = (x for x in files when excludes.indexOf(x) is -1) # TODO: REGEX TESTING
+ async.forEach files, clone, call
+
+ npmExclude = (call) ->
+ npmignore = path.join dir, '/.npmignore'
+ path.exists npmignore, (exists) ->
+ return call() unless exists
+ fs.readFile npmignore, (err, data) ->
+ throw err if err
+ excludes.merge data.toString().split '\n'
+ call()
+
+ gitExclude = (call) ->
+ gitignore = path.join dir, '/.gitignore'
+ path.exists gitignore, (exists) ->
+ return call() unless exists
+ fs.readFile gitignore, (err, data) ->
+ throw err if err
+ excludes.merge data.toString().split '\n'
+ call()
+
+ run = (call) ->
+ if ignore
+ async.parallel [npmExclude, gitExclude], -> copyAll call
+ else
+ copyAll call
+
+ path.exists newdir, (exists) ->
+ if exists
+ run cb
+ else
+ fs.mkdir newdir, 0777, (err) ->
+ throw err if err
+ run cb
+
View
@@ -14,14 +14,16 @@
"dependencies":{
"coffee-script":"*",
"node-log":"*",
+ "colors":"*",
"protege":"*",
"nopt":"*",
"get":"*",
"node-dep":"*",
"semver":"*",
"rimraf":"*",
"jsontoxml":"*",
- "async":"*"
+ "async":"*",
+ "wrench":"*"
},
"engines":{
"node":">= 0.4.0"
View
@@ -0,0 +1,4 @@
+.DS_Store
+*.log
+node_modules
+temp
View
@@ -0,0 +1,4 @@
+.DS_Store
+*.log
+node_modules
+temp
View
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Fractal <contact@wearefractal.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,33 @@
+<html>
+<head>
+<title>Fusker - Test Page</title>
+<script type="text/javascript" src="/socket.io/socket.io.js"></script>
+<script>
+ var socket = io.connect();
+
+ socket.on('connect', function () {
+ console.log('Socket.IO connected!');
+ });
+
+ socket.on('HelloClient', function (msg) {
+ console.log('Server: ' + msg);
+ socket.emit('TestObject', {username: 'ez-money', message: 'waz gud diz ya boi e-z e'});
+
+ //Uncomment this block to send attacks to the server on page load
+ /*
+ socket.emit('TestXSS', '"><img src=x onerror=alert("XSS")><noscript>');
+ socket.emit('TestLFI', '../../etc/passwd/');
+ socket.emit('TestSQL', '\' OR \'1\'=\'1');*/
+ });
+</script>
+</head>
+<body bgcolor="black" background="http://content.ytmnd.com/content/1/d/b/1db6ede2772ba8f5428dbff9f1f2e3be.gif">
+<br/><br/>
+<center>
+<h1>Fusker Test Page</h1><br/>
+<img src="http://content.ytmnd.com/content/1/7/c/17c9f89183c18613f48450a649e3f64c.gif"/><br/>
+<embed src="http://www.youtube.com/v/pOu1BvuhtRw?autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="1" height="1"></embed>
+</center>
+</body>
+</html>
+
View
@@ -0,0 +1,41 @@
+var log = require('node-log')
+log.setName('TestApp')
+var fusker = require('fusker');
+
+fusker.config.dir = __dirname;
+fusker.config.banLength = 1;
+fusker.config.verbose = true;
+fusker.http.detect('csrf', 'xss', 'sqli', 'lfi', '404');
+fusker.http.punish('blacklist', 'bush');
+fusker.socket.detect('xss', 'sqli', 'lfi');
+fusker.socket.punish('blacklist');
+
+var server = fusker.http.createServer(8080);
+var io = fusker.socket.listen(server);
+
+io.sockets.on('connection', function(socket) {
+ socket.emit('HelloClient', 'o hay thar client');
+
+ socket.on('TestObject', function(msg) {
+ return console.log('HelloServer1! Contents: ' + msg);
+ });
+ socket.on('TestObject', function(msg) {
+ return console.log('HelloServer2! Contents: ' + msg);
+ });
+ socket.on('TestObject', function(msg) {
+ return console.log('HelloServer3! Contents: ' + msg);
+ });
+
+ /* Uncomment the attack senders in index.html to test these */;
+ socket.on('TestSQL', function(msg) {
+ return console.log('SQL Handled! Contents: ' + msg);
+ });
+
+ socket.on('TestLFI', function(msg) {
+ return console.log('LFI Handled! Contents: ' + msg);
+ });
+
+ socket.on('TestXSS', function(msg) {
+ return console.log('XSS Handled! Contents: ' + msg);
+ });
+});
@@ -0,0 +1,4 @@
+.DS_Store
+*.log
+node_modules
+temp
@@ -0,0 +1,4 @@
+.DS_Store
+*.log
+node_modules
+temp
View
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Fractal <contact@wearefractal.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
+<html>
+<head>
+<title>Fusker - Test Page</title>
+<script type="text/javascript" src="/socket.io/socket.io.js"></script>
+<script>
+ var socket = io.connect();
+
+ socket.on('connect', function () {
+ console.log('Socket.IO connected!');
+ });
+
+ socket.on('HelloClient', function (msg) {
+ console.log('Server: ' + msg);
+ socket.emit('TestObject', {username: 'ez-money', message: 'waz gud diz ya boi e-z e'});
+
+ //Uncomment this block to send attacks to the server on page load
+ /*
+ socket.emit('TestXSS', '"><img src=x onerror=alert("XSS")><noscript>');
+ socket.emit('TestLFI', '../../etc/passwd/');
+ socket.emit('TestSQL', '\' OR \'1\'=\'1');*/
+ });
+</script>
+</head>
+<body bgcolor="black" background="http://content.ytmnd.com/content/1/d/b/1db6ede2772ba8f5428dbff9f1f2e3be.gif">
+<br/><br/>
+<center>
+<h1>Fusker Test Page</h1><br/>
+<img src="http://content.ytmnd.com/content/1/7/c/17c9f89183c18613f48450a649e3f64c.gif"/><br/>
+<embed src="http://www.youtube.com/v/pOu1BvuhtRw?autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="1" height="1"></embed>
+</center>
+</body>
+</html>
+
@@ -0,0 +1,41 @@
+var log = require('node-log')
+log.setName('TestApp')
+var fusker = require('fusker');
+
+fusker.config.dir = __dirname;
+fusker.config.banLength = 1;
+fusker.config.verbose = true;
+fusker.http.detect('csrf', 'xss', 'sqli', 'lfi', '404');
+fusker.http.punish('blacklist', 'bush');
+fusker.socket.detect('xss', 'sqli', 'lfi');
+fusker.socket.punish('blacklist');
+
+var server = fusker.http.createServer(8080);
+var io = fusker.socket.listen(server);
+
+io.sockets.on('connection', function(socket) {
+ socket.emit('HelloClient', 'o hay thar client');
+
+ socket.on('TestObject', function(msg) {
+ return console.log('HelloServer1! Contents: ' + msg);
+ });
+ socket.on('TestObject', function(msg) {
+ return console.log('HelloServer2! Contents: ' + msg);
+ });
+ socket.on('TestObject', function(msg) {
+ return console.log('HelloServer3! Contents: ' + msg);
+ });
+
+ /* Uncomment the attack senders in index.html to test these */;
+ socket.on('TestSQL', function(msg) {
+ return console.log('SQL Handled! Contents: ' + msg);
+ });
+
+ socket.on('TestLFI', function(msg) {
+ return console.log('LFI Handled! Contents: ' + msg);
+ });
+
+ socket.on('TestXSS', function(msg) {
+ return console.log('XSS Handled! Contents: ' + msg);
+ });
+});
Oops, something went wrong.

0 comments on commit cc04373

Please sign in to comment.