Compare commits

..

No commits in common. "aeecc9c6db3ddc6f9913094a695e48032f30d34b" and "b1b6206baa14c569d1ac5ff67f035e324a33935d" have entirely different histories.

8 changed files with 25 additions and 183 deletions

View file

@ -35,10 +35,7 @@
} else if ( dir[i].link_to && dir[i].link_to.length > 0 ) { } else if ( dir[i].link_to && dir[i].link_to.length > 0 ) {
return this.action ( dir[i].link_to ); return this.action ( dir[i].link_to );
} else if ( dir[i].content ) { } else if ( dir[i].content ) {
var replaced=dir[i].content.replace(/(https?:\/\/(www\.)?[0-9a-zA-Z-_\.\/:\?#=&]*)/g, "<a href='$1'>$1</a>"); return '<pre>' + dir[i].content + "</pre>";
replaced = replaced.replace(".'>", "'>");
replaced = replaced.replace(".</a>", "</a>.");
return "<pre>"+replaced+"</pre>";
} }
} }
} }
@ -56,4 +53,3 @@
} }
} }

View file

@ -1,19 +0,0 @@
{
"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,11 +68,9 @@
shell.fname = arg; shell.fname = arg;
shell.editorkeypressed = this.editorkeypressed; shell.editorkeypressed = this.editorkeypressed;
shell.editorpaste = this.editorpaste;
shell.editorclick = this.editorclick;
shell.confirmkey = this.confirmkey; shell.confirmkey = this.confirmkey;
shell.bufferSave = this.bufferSave; shell.bufferSave = this.bufferSave;
shell.firstKey = 1; // Set when no key has been pressed yet shell.firstKey = true; // 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]"; shell.default_editor_status = "[<b>^X</b> Exit] [<b>^O</b> WriteOut] [<b>^F</b> Where Is]";
@ -107,13 +105,9 @@
shell.editor_head = document.getElementById ( 'editor_head' ); shell.editor_head = document.getElementById ( 'editor_head' );
var editor = document.createElement ( 'textarea' ); var editor = document.createElement ( 'textarea' );
editor.setAttribute ( 'class', 'editor_window' ); editor.setAttribute ( 'class', 'editor_window' );
editor.setAttribute ( 'id', 'editor_window' ); editor.setAttribute ( 'id', 'editor_window' );
editor.setAttribute ( 'onkeypress', 'shell.editorkeypressed ( event )' ); 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; has_content = false;
@ -123,7 +117,7 @@
{ {
if ( file.content.length > 0 ) 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 ( /&lt;/g, '<' );
content = content.replace ( /&gt;/g, '>' ); content = content.replace ( /&gt;/g, '>' );
editor.value = content; editor.value = content;
@ -152,44 +146,29 @@
container.appendChild ( status ); container.appendChild ( status );
shell.editor_status = document.getElementById ( 'editor_status' ); shell.editor_status = document.getElementById ( 'editor_status' );
shell.hitCount = 0;
return ''; return '';
}, },
"editorkeypressed" : function ( e ) "editorkeypressed" : function ( e )
{ {
shell.hitCount++;
var evt = ( window.event ) ? window.event : e; var evt = ( window.event ) ? window.event : e;
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode; var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
if ( shell.firstKey == 1 && key == 13 ) if ( shell.firstKey && key == 13 )
{ {
evt.preventDefault(); evt.preventDefault();
shell.firstKey = -1; shell.firstKey = false;
return false; 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 ); key = String.fromCharCode ( key );
if (( key == 'x' || key == 'X' ) && evt.ctrlKey ) if (( key == 'x' || key == 'X' ) && evt.ctrlKey )
{ {
evt.preventDefault(); evt.preventDefault();
if(shell.originalContent != shell.editor_window.value) if ( shell.file_changed )
shell.file_changed = true;
if ( shell.file_changed && shell.hitCount > 2)
{ {
var can_write = false; var can_write = false;
@ -224,9 +203,6 @@
} else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) { } else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) {
evt.preventDefault(); evt.preventDefault();
if( shell.originalContent != shell.editor_window.value )
shell.file_changed = true;
if ( shell.file_changed ) if ( shell.file_changed )
{ {
var can_write = false; var can_write = false;
@ -259,23 +235,23 @@
return false; return false;
} }
if( !shell.file_changed ) if ( !shell.file_changed )
{ {
if ( shell.originalContent != shell.editor_window.value ) if ( shell.originalContent != shell.editor_window.value )
{ {
if ( shell.perms ) if ( shell.perms )
{ {
if ( shell.perms.write == false ) if ( shell.perms.write == false )
{ {
shell.default_editor_status += ' [read-only]'; shell.default_editor_status += ' [read-only]';
shell.editor_status.innerHTML += ' [read-only]'; shell.editor_status.innerHTML += ' [read-only]';
} }
} }
shell.editor_status.innerHTML += ' [modified]';
shell.file_changed = true; shell.editor_status.innerHTML += ' [modified]';
} shell.file_changed = true;
}
} }
}, },
"confirmkey" : function ( e, arg ) "confirmkey" : function ( e, arg )
@ -421,41 +397,6 @@
http.send ( params ); http.send ( params );
shell.originalContent = shell.editor_window.value; shell.originalContent = shell.editor_window.value;
shell.file_changed = false; 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;
} }
} }

View file

@ -1,59 +0,0 @@
{
"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> <html>
<head> <head>
<title>blash</title> <title>Blash - An AJAX interactive shell emulator for web browsing</title>
<script type="text/javascript" language="javascript" src="system/blash.js"></script> <script type="text/javascript" language="javascript" src="system/blash.js"></script>
<script type="text/javascript" language="javascript" src="system/md5.js"></script> <script type="text/javascript" language="javascript" src="system/md5.js"></script>
<link rel="stylesheet" href="blash.css" type="text/css"> <link rel="stylesheet" href="blash.css" type="text/css">

View file

@ -850,25 +850,6 @@ 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; return arg;
} }

View file

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

View file

@ -10,6 +10,9 @@ $files_json = <<<JSON
, {"path": "/software", "type": "directory"} , {"path": "/software", "type": "directory"}
, {"path": "/etc", "type": "directory"} , {"path": "/etc", "type": "directory"}
, {"path": "/home", "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": "/etc/blashrc", "type": "file", "content": "This is the default blash configuration file"}
, {"path": "/forum/post1", "type": "file", "content": "lol"} , {"path": "/forum/post1", "type": "file", "content": "lol"}
, {"path": "/forum/post2", "type": "file", "content": "lol"} , {"path": "/forum/post2", "type": "file", "content": "lol"}