From 66562780cf0ec13af0a5f1f3e6d626bc32c896fe Mon Sep 17 00:00:00 2001 From: BlackLight Date: Fri, 4 Feb 2011 11:16:41 +0100 Subject: [PATCH] Improving cat, implementing wget (thanks tragic0mic) --- commands/cat.json | 5 +++- commands/chown.js | 16 ++++++++++++ commands/wget.json | 58 +++++++++++++++++++++++++++++++++++++++++++ index.html | 2 +- system/blash.js | 19 ++++++++++++++ system/blash.json | 1 + system/files_json.php | 3 --- 7 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 commands/chown.js create mode 100644 commands/wget.json diff --git a/commands/cat.json b/commands/cat.json index 6b65b49..5916f59 100644 --- a/commands/cat.json +++ b/commands/cat.json @@ -35,7 +35,10 @@ } else if ( dir[i].link_to && dir[i].link_to.length > 0 ) { return this.action ( dir[i].link_to ); } else if ( dir[i].content ) { - return '
' + dir[i].content + "
"; + var replaced=dir[i].content.replace(/(https?:\/\/(www\.)?[0-9a-zA-Z-_\.\/:]*)/g, "$1"); + replaced = replaced.replace(".'>", "'>"); + replaced = replaced.replace(".", "."); + return "
"+replaced+"
"; } } } diff --git a/commands/chown.js b/commands/chown.js new file mode 100644 index 0000000..cace995 --- /dev/null +++ b/commands/chown.js @@ -0,0 +1,16 @@ +{ + "name" : "chown", + + "info" : { + "syntax" : "chown <new_user> <file|directory>", + "brief" : "Change the access permissions to a file or directory for one or more users or groups, example: \"chmod user1,user2,@group1,@group2+r /path\", \"chmod @all+rw /path\"" + }, + + "action" : function ( arg ) + { + var out = ''; + + if ( !arg.match ( /^\s*([^+|-]*)(\+|\-)((r|w)+)\s+(.+)\s*$/ )) + { + return "Usage: " + this.info.syntax + "
\n"; + } diff --git a/commands/wget.json b/commands/wget.json new file mode 100644 index 0000000..4e041e7 --- /dev/null +++ b/commands/wget.json @@ -0,0 +1,58 @@ +{ + "name" : "wget", + + "info" : { + "syntax" : "wget <file>", + "brief" : "Creates a static textual version of the selected file, suitable for download", + }, + + "action" : function ( arg ) + { + var out = ''; + var found = false; + var dir = shell.files; + + if ( !arg || arg.length == 0 ) + { + return "Argument required
\n"; + } + + arg = shell.expandPath ( arg ); + + for ( var i=0; i < dir.length && !found; i++ ) + { + if ( dir[i].path == arg ) + { + found = true; + + if ( dir[i].type == 'directory' ) + { + return "wget: " + dir[i].path + ": Is a directory
\n"; + } else { + if ( dir[i].content ) { + var wgetWin = window.open("_blank",""); + if(wgetWin) + { + wgetWin.document.write(dir[i].content); + return "
"; + } + else + return "wget: cannot open new window.
"; + + } + } + } + } + + if ( !found ) + { + arg = arg.replace ( '<', '<' ); + arg = arg.replace ( '>', '>' ); + return "wget: " + arg + ": No such file or directory
\n"; + } + + out = out.replace ( /\s*$/, '' ); + return out; + } +} + diff --git a/index.html b/index.html index 95664f2..7e56761 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@ - Blash - An AJAX interactive shell emulator for web browsing + blash diff --git a/system/blash.js b/system/blash.js index 85f459e..b3b454f 100644 --- a/system/blash.js +++ b/system/blash.js @@ -850,6 +850,25 @@ function blash () } } + if ( arg.match ( /\*/ )) + { + args = shell.expandStar ( arg ); + + if ( args.length == 1 ) + { + return args[0].path; + } else { + var out = ''; + + for ( var i in args ) + { + out += args[i].path + ' '; + } + + return out; + } + } + return arg; } diff --git a/system/blash.json b/system/blash.json index 9008e90..3e4881b 100644 --- a/system/blash.json +++ b/system/blash.json @@ -78,6 +78,7 @@ "useradd", "userdel", "users", + "wget", "whoami" ] } diff --git a/system/files_json.php b/system/files_json.php index 1368e18..4beab8a 100644 --- a/system/files_json.php +++ b/system/files_json.php @@ -10,9 +10,6 @@ $files_json = <<