Compare commits

...

5 commits

Author SHA1 Message Date
BlackLight
aeecc9c6db Another fix to nano (by tragic0mic) 2011-02-10 23:00:42 +01:00
BlackLight
1f75240b42 Improving nano editor (thanks to tragic0mic) 2011-02-09 18:16:44 +01:00
BlackLight
fbb1d6ff5b Fixing cat and wget (thanks again to tragic0mic) 2011-02-09 17:02:30 +01:00
BlackLight
22f8950012 Buggy chown command, fixing later 2011-02-04 13:58:33 +01:00
BlackLight
66562780cf Improving cat, implementing wget (thanks tragic0mic) 2011-02-04 11:16:41 +01:00
8 changed files with 183 additions and 25 deletions

View file

@ -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
View file

@ -0,0 +1,19 @@
{
"name" : "chown",
"info" : {
"syntax" : "chown &lt;new_user&gt; &lt;file|directory&gt;",
"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";
}
}
}

View file

@ -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 ( /&lt;/g, '<' );
content = content.replace ( /&gt;/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;
@ -235,23 +259,23 @@
return false;
}
if ( !shell.file_changed )
if( !shell.file_changed )
{
if ( shell.originalContent != shell.editor_window.value )
{
if ( shell.perms )
{
if ( shell.perms.write == false )
{
shell.default_editor_status += ' [read-only]';
shell.editor_status.innerHTML += ' [read-only]';
}
}
shell.editor_status.innerHTML += ' [modified]';
shell.file_changed = true;
}
if ( shell.originalContent != shell.editor_window.value )
{
if ( shell.perms )
{
if ( shell.perms.write == false )
{
shell.default_editor_status += ' [read-only]';
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
View file

@ -0,0 +1,59 @@
{
"name" : "wget",
"info" : {
"syntax" : "wget &lt;file&gt;",
"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 ( '<', '&lt;' );
arg = arg.replace ( '>', '&gt;' );
return "wget: " + arg + ": No such file or directory<br/>\n";
}
out = out.replace ( /<br\/?>\s*$/, '' );
return out;
}
}

View file

@ -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">

View file

@ -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;
}

View file

@ -78,6 +78,7 @@
"useradd",
"userdel",
"users",
"wget",
"whoami"
]
}

View file

@ -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"}