├── .gitattributes ├── .gitignore ├── README.md ├── bin └── obscure.js ├── index.js └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directories 27 | node_modules 28 | jspm_packages 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | # ========================= 37 | # Operating System Files 38 | # ========================= 39 | 40 | # OSX 41 | # ========================= 42 | 43 | .DS_Store 44 | .AppleDouble 45 | .LSOverride 46 | 47 | # Thumbnails 48 | ._* 49 | 50 | # Files that might appear in the root of a volume 51 | .DocumentRevisions-V100 52 | .fseventsd 53 | .Spotlight-V100 54 | .TemporaryItems 55 | .Trashes 56 | .VolumeIcon.icns 57 | 58 | # Directories potentially created on remote AFP share 59 | .AppleDB 60 | .AppleDesktop 61 | Network Trash Folder 62 | Temporary Items 63 | .apdisk 64 | 65 | # Windows 66 | # ========================= 67 | 68 | # Windows image file caches 69 | Thumbs.db 70 | ehthumbs.db 71 | 72 | # Folder config file 73 | Desktop.ini 74 | 75 | # Recycle Bin used on file shares 76 | $RECYCLE.BIN/ 77 | 78 | # Windows Installer files 79 | *.cab 80 | *.msi 81 | *.msm 82 | *.msp 83 | 84 | # Windows shortcuts 85 | *.lnk 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # obscure 2 | *by Jason Yung - [http://callmejay.com](http://callmejay.com "http://callmejay.com")* 3 | 4 | no nonsense obfuscation for html/css based frontend applications 5 | 6 | ### Installing to Command Line 7 | 8 | $ npm install -g obscure 9 | 10 | ### Basic Usage 11 | 12 | $ obscure style.css --apply index.html 13 | 14 | This will grab all **ids and classes** (which I'm calling **definitions**) from `style.css` to be obfuscated, and apply that obfuscation to `index.html` (as well as `style.css` itself) 15 | 16 | ### Output Directory 17 | 18 | $ obscure style.css --apply index.html --output ./obfuscated 19 | Use `--output` to specify where the obfuscated source files will be written 20 | 21 | ### Exclusion 22 | 23 | $ obscure style.css --exclude bootstrap.css 24 | 25 | You might have some **definitions** in you CSS that should not be obfuscated. No problem, just `--exclude` 26 | 27 | ### Batch Support 28 | Most likely you will be obfuscating multiple source files together. 29 | Here's some examples on how to get that done: 30 | 31 | ##### List 32 | 33 | $ obscure style.css,other.css --apply index.html,other.html 34 | 35 | ##### Glob 36 | 37 | $ obscure *.css --apply *.html 38 | 39 | ##### Mixed 40 | 41 | $ obscure *.css,app/style.css --apply *.html,app/index.html 42 | -------------------------------------------------------------------------------- /bin/obscure.js: -------------------------------------------------------------------------------- 1 | var TAAG ="\n ____ ____ ____ ____ _ ____ _____\n / _ \\/ _ \\/ ___\\/ _\\/ \\ /\\/ __\\/ __/\n | / \\|| | //| \\| / | | ||| \\/|| \\ \n | \\_/|| |_\\\\\\___ || \\_ | \\_/|| /| /_ \n \\____/\\____/\\____/\\____/\\____/\\_/\\_\\\\____\\" 2 | 3 | //obscure style.css --exclude css\bootstrap.min.css --apply single.php,single-video.php,frontpage.php,footer.php,footer-social.php,content.php,page.php,partials\cards\mini.php,partials\cards\video.php,partials\cards\audio.php,partials\cards\post.php,header.php 4 | 5 | process.argv[1]='obscure'; //rename for commander 6 | var obscure = require('../index.js') 7 | var program = require('commander'); 8 | 9 | program 10 | .usage(" [options]") 11 | .version('1.0.1') 12 | .arguments('') 13 | .option('-o, --output ', 'directory to output obfuscated files') 14 | .option('-e, --exclude ', '.css file(s) containing definitions (classes and ids) to be excluded from obfuscation') 15 | .option('-a, --apply ', '.html file(s) to be obfuscated using the included definitions') 16 | .option('-s, --seed ', 'seed value for obfuscation term generation') 17 | .action(function(include) { 18 | console.log(TAAG); 19 | 20 | if(include == undefined) console.log(program.helpInformation()); 21 | else { 22 | program.include = include; 23 | 24 | if(program.seed) program.seed = parseInt(program.seed); 25 | 26 | if(program.output && program.output[program.output.length-1] != '/') program.output += '/'; 27 | 28 | obscure(program); //main entry point 29 | } 30 | }) 31 | .parse(process.argv) 32 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var mkdirp = require('mkdirp'); 4 | var path = require('path'); 5 | var _ = require('lodash'); 6 | var fs = require('fs'); 7 | var glob = require('glob'); 8 | var cheerio = require('cheerio'); 9 | var Hashids = require("hashids"), 10 | hashids = new Hashids("what does that say?"); 11 | 12 | var DEFINITIONS_CAP = /([#.][\w-]+)/g; 13 | 14 | var STRIP = { 15 | defs : /\{[^\}]*?\}/g, 16 | comments: /\/\*[\s\S]*?\*\//g, 17 | scope: /\([\s\S]*?\)/g, 18 | query: /\[[\s\S]*?\]/g 19 | } 20 | 21 | var SAFE_PREFIX = "obscure-"; 22 | var SEED = (new Date()).getTime(); 23 | var OUTPUT = './obscure-'+SEED+'/'; 24 | 25 | function getDefinitions(cssString) { 26 | //prep csstring, STRIPping out all the defs 27 | for(var k in STRIP) { 28 | cssString = cssString.replace(STRIP[k],''); 29 | } 30 | var matchs = []; 31 | var match = DEFINITIONS_CAP.exec(cssString); 32 | while (match != null) { 33 | //console.log(match); 34 | matchs.push(match[1]); 35 | match = DEFINITIONS_CAP.exec(cssString); 36 | } 37 | return _.uniq(matchs); 38 | } 39 | 40 | function globlist(s) { 41 | 42 | var split = s.split(',') 43 | var list = [] 44 | for (var i in split) { 45 | var files = glob.sync(split[i]); 46 | list.push(files) 47 | } 48 | return _.uniq(_.flatten(list)); 49 | } 50 | 51 | function obscure(opts) { 52 | 53 | if(opts.output === undefined) opts.output = OUTPUT 54 | if(opts.seed === undefined) opts.seed = OUTPUT 55 | 56 | mkdirp.sync(opts.output) 57 | 58 | console.log(); 59 | console.log(" * Obfuscation term generation using seed value of: " + opts.seed); 60 | console.log(" * Output directory set to: " + opts.output); 61 | console.log(); 62 | 63 | 64 | var excluded = []; 65 | if(opts.exclude) { 66 | console.log("Building exclusion map..."); 67 | 68 | var excludes = opts.exclude ? globlist(opts.exclude) : []; 69 | for(var e in excludes) { 70 | var css = fs.readFileSync(excludes[e], 'utf8'); 71 | 72 | var defs = getDefinitions(css); 73 | 74 | for(var i = 0; i{ 177 | if(err) console.error(err); 178 | else fs.writeFileSync(fd, buffer); 179 | }) 180 | } 181 | 182 | 183 | module.exports = obscure; 184 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "obscure", 3 | "version": "1.0.1", 4 | "description": "no nonsense obfuscation for html/css based frontend applications", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository":{ 10 | "type": "git", 11 | "url": "https://github.com/bitstrider/obscure" 12 | }, 13 | "author": "bitstrider", 14 | "license": "MIT", 15 | "bin": "./bin/obscure.js", 16 | "keywords": [ 17 | "obfuscate", "css", "html" 18 | ], 19 | "dependencies": { 20 | "cheerio": "^0.20.0", 21 | "commander": "^2.9.0", 22 | "glob": "^7.0.3", 23 | "hashids": "^1.0.2", 24 | "lodash": "^4.13.1", 25 | "mkdirp": "^0.5.1" 26 | } 27 | } 28 | --------------------------------------------------------------------------------