Compare commits
5 commits
b1b6206baa
...
aeecc9c6db
Author | SHA1 | Date | |
---|---|---|---|
|
aeecc9c6db | ||
|
1f75240b42 | ||
|
fbb1d6ff5b | ||
|
22f8950012 | ||
|
66562780cf |
8 changed files with 183 additions and 25 deletions
|
@ -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 '<pre>' + dir[i].content + "</pre>";
|
||||
var replaced=dir[i].content.replace(/(https?:\/\/(www\.)?[0-9a-zA-Z-_\.\/:\?#=&]*)/g, "<a href='$1'>$1</a>");
|
||||
replaced = replaced.replace(".'>", "'>");
|
||||
replaced = replaced.replace(".</a>", "</a>.");
|
||||
return "<pre>"+replaced+"</pre>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,3 +56,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
19
commands/chown.js
Normal file
19
commands/chown.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"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 + "<br/>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,9 +68,11 @@
|
|||
|
||||
shell.fname = arg;
|
||||
shell.editorkeypressed = this.editorkeypressed;
|
||||
shell.editorpaste = this.editorpaste;
|
||||
shell.editorclick = this.editorclick;
|
||||
shell.confirmkey = this.confirmkey;
|
||||
shell.bufferSave = this.bufferSave;
|
||||
shell.firstKey = true; // Set when no key has been pressed yet
|
||||
shell.firstKey = 1; // Set when no key has been pressed yet
|
||||
|
||||
shell.default_editor_status = "[<b>^X</b> Exit] [<b>^O</b> WriteOut] [<b>^F</b> Where Is]";
|
||||
|
||||
|
@ -105,9 +107,13 @@
|
|||
shell.editor_head = document.getElementById ( 'editor_head' );
|
||||
|
||||
var editor = document.createElement ( 'textarea' );
|
||||
|
||||
editor.setAttribute ( 'class', 'editor_window' );
|
||||
editor.setAttribute ( 'id', 'editor_window' );
|
||||
editor.setAttribute ( 'onkeypress', 'shell.editorkeypressed ( event )' );
|
||||
// editor.setAttribute ( 'onmousedown', 'shell.editorclick ( event )' ); /* This might be useful someday */
|
||||
editor.setAttribute ( 'onpaste', 'shell.editorpaste ( )' );
|
||||
editor.setAttribute ( 'oncut', 'shell.editorpaste( )' );
|
||||
|
||||
has_content = false;
|
||||
|
||||
|
@ -117,7 +123,7 @@
|
|||
{
|
||||
if ( file.content.length > 0 )
|
||||
{
|
||||
var content = file.content.replace ( /<br\/?>/g, "\n" );
|
||||
var content = file.content.replace ( /(<br ?\/?>)/g, "\n" );
|
||||
content = content.replace ( /</g, '<' );
|
||||
content = content.replace ( />/g, '>' );
|
||||
editor.value = content;
|
||||
|
@ -146,29 +152,44 @@
|
|||
|
||||
container.appendChild ( status );
|
||||
shell.editor_status = document.getElementById ( 'editor_status' );
|
||||
shell.hitCount = 0;
|
||||
|
||||
return '';
|
||||
},
|
||||
|
||||
"editorkeypressed" : function ( e )
|
||||
{
|
||||
shell.hitCount++;
|
||||
var evt = ( window.event ) ? window.event : e;
|
||||
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
|
||||
|
||||
if ( shell.firstKey && key == 13 )
|
||||
if ( shell.firstKey == 1 && key == 13 )
|
||||
{
|
||||
evt.preventDefault();
|
||||
shell.firstKey = false;
|
||||
shell.firstKey = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(shell.firstKey == -1)
|
||||
{
|
||||
shell.file_changed = true;
|
||||
if(shell.perms.write == false)
|
||||
shell.editor_status.innerHTML += " [read-only]";
|
||||
shell.editor_status.innerHTML += " [modified]";
|
||||
shell.firstKey = 0;
|
||||
shell.editor_window.value = shell.editor_window.value.replace(/(\n|\r)+$/, '');
|
||||
}
|
||||
|
||||
key = String.fromCharCode ( key );
|
||||
|
||||
if (( key == 'x' || key == 'X' ) && evt.ctrlKey )
|
||||
{
|
||||
evt.preventDefault();
|
||||
|
||||
if ( shell.file_changed )
|
||||
if(shell.originalContent != shell.editor_window.value)
|
||||
shell.file_changed = true;
|
||||
|
||||
if ( shell.file_changed && shell.hitCount > 2)
|
||||
{
|
||||
var can_write = false;
|
||||
|
||||
|
@ -203,6 +224,9 @@
|
|||
} else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) {
|
||||
evt.preventDefault();
|
||||
|
||||
if( shell.originalContent != shell.editor_window.value )
|
||||
shell.file_changed = true;
|
||||
|
||||
if ( shell.file_changed )
|
||||
{
|
||||
var can_write = false;
|
||||
|
@ -247,11 +271,11 @@
|
|||
shell.editor_status.innerHTML += ' [read-only]';
|
||||
}
|
||||
}
|
||||
|
||||
shell.editor_status.innerHTML += ' [modified]';
|
||||
shell.file_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
"confirmkey" : function ( e, arg )
|
||||
|
@ -397,6 +421,41 @@
|
|||
http.send ( params );
|
||||
shell.originalContent = shell.editor_window.value;
|
||||
shell.file_changed = false;
|
||||
},
|
||||
|
||||
"editorpaste" : function ()
|
||||
{
|
||||
if(shell.perms)
|
||||
{
|
||||
if(shell.perms.write == true)
|
||||
{
|
||||
if(shell.file_changed == false)
|
||||
{
|
||||
shell.file_changed = true;
|
||||
shell.editor_status.innerHTML += ' [modified]';
|
||||
}
|
||||
}
|
||||
else
|
||||
if(shell.file_changed == false)
|
||||
{
|
||||
shell.file_changed = true;
|
||||
shell.editor_status.innerHTML += ' [read-only] [modified]';
|
||||
}
|
||||
}
|
||||
|
||||
if (shell.firstKey==-1)
|
||||
{
|
||||
shell.hitCount++;
|
||||
shell.firstKey=0;
|
||||
}
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
"editorclick": function ( e )
|
||||
{
|
||||
if (e.button == 2); /* Do something with the right button */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
59
commands/wget.json
Normal file
59
commands/wget.json
Normal file
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"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<br/>\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<br/>\n";
|
||||
} else {
|
||||
if ( dir[i].content ) {
|
||||
var wgetWin = window.open("_blank","");
|
||||
if(wgetWin)
|
||||
{
|
||||
wgetWin.document.write("<pre>"+dir[i].content+"</pre>");
|
||||
return "<br />";
|
||||
}
|
||||
else
|
||||
return "wget: cannot open new window.<br />";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !found )
|
||||
{
|
||||
arg = arg.replace ( '<', '<' );
|
||||
arg = arg.replace ( '>', '>' );
|
||||
return "wget: " + arg + ": No such file or directory<br/>\n";
|
||||
}
|
||||
|
||||
out = out.replace ( /<br\/?>\s*$/, '' );
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Blash - An AJAX interactive shell emulator for web browsing</title>
|
||||
<title>blash</title>
|
||||
<script type="text/javascript" language="javascript" src="system/blash.js"></script>
|
||||
<script type="text/javascript" language="javascript" src="system/md5.js"></script>
|
||||
<link rel="stylesheet" href="blash.css" type="text/css">
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@
|
|||
"useradd",
|
||||
"userdel",
|
||||
"users",
|
||||
"wget",
|
||||
"whoami"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -10,9 +10,6 @@ $files_json = <<<JSON
|
|||
, {"path": "/software", "type": "directory"}
|
||||
, {"path": "/etc", "type": "directory"}
|
||||
, {"path": "/home", "type": "directory"}
|
||||
, {"path": "/blog/post1", "type": "file", "content": "This is my first post"}
|
||||
, {"path": "/blog/post2", "type": "file", "content": "This is my second post"}
|
||||
, {"path": "/blog/post3", "type": "file", "content": "This is my third post"}
|
||||
, {"path": "/etc/blashrc", "type": "file", "content": "This is the default blash configuration file"}
|
||||
, {"path": "/forum/post1", "type": "file", "content": "lol"}
|
||||
, {"path": "/forum/post2", "type": "file", "content": "lol"}
|
||||
|
|
Loading…
Reference in a new issue