diff --git a/blash.css b/blash.css index 1100a9f..c4f3b13 100644 --- a/blash.css +++ b/blash.css @@ -7,6 +7,12 @@ body tabindex : -1; } +pre +{ + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; +} + input.promptInput { background-color : black; diff --git a/commands/cat.json b/commands/cat.json index e560b36..fe7d212 100644 --- a/commands/cat.json +++ b/commands/cat.json @@ -33,7 +33,7 @@ { window.open ( dir[i].href ); } else if ( dir[i].content ) { - return dir[i].content + "
\n"; + return '
' + dir[i].content + "
"; } } } @@ -46,7 +46,7 @@ return "cat: " + arg + ": No such file or directory
\n"; } - out = out.replace ( /\s*$/, '' ); + out = out.replace ( /\s*$/, '' ); return out; } } diff --git a/commands/chmod.json b/commands/chmod.json index 628da0b..265563c 100644 --- a/commands/chmod.json +++ b/commands/chmod.json @@ -3,7 +3,7 @@ "info" : { "syntax" : "chmod <perms> <file|directory>", - "brief" : "Change the access permissions to a file or directory for one or more users or groups, for example chmod user1,user2,@group1,@group2+r" + "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 ) diff --git a/commands/su.json b/commands/su.json index 98d9267..49c6758 100644 --- a/commands/su.json +++ b/commands/su.json @@ -132,56 +132,103 @@ shell.user = shell.json.user; } - shell.auto_prompt_focus = true; - shell.auto_prompt_refresh = true; - shell.refreshPrompt ( false, false ); + shell.files_json = window.location.href; - blashrcIndex = -1; // Index of .blashrc file - - for ( var i in shell.files ) + if ( shell.has_users ) { - if ( shell.files[i].path.match ( new RegExp ( '^' + shell.home + '/.blashrc$' ))) + shell.files_json = shell.files_json.replace ( /\/([a-zA-Z_\.]+)$/, '/modules/users/files.php' ); + } else { + shell.files_json = shell.files_json.replace ( /\/([a-zA-Z_\.]+)$/, '/system/files.json' ); + } + + var http3 = new XMLHttpRequest(); + http3.open ( "GET", shell.files_json, true ); + + http3.onreadystatechange = function () + { + if ( http3.readyState == 4 && http3.status == 200 ) { - blashrcIndex = i; - break; + shell.files = eval ( '(' + http3.responseText + ')' ); + blashrcIndex = -1; // Index of .blashrc file + stylercIndex = -1; // Index of .stylerc file + + for ( var i in shell.files ) + { + if ( shell.files[i].path.match ( new RegExp ( '^' + shell.home + '/.blashrc$' ))) + { + blashrcIndex = i; + } + + if ( shell.files[i].path.match ( new RegExp ( '^' + shell.home + '/.stylerc$' ))) + { + stylercIndex = i; + } + + if ( blashrcIndex >= 0 && stylercIndex >= 0 ) + { + break; + } + } + + if ( blashrcIndex > 0 ) + { + var blashrc = shell.files[blashrcIndex].content.replace ( //g, ' ' ); + blashrc = eval ( '(' + blashrc + ')' ); + + if ( !blashrc ) + { + return false; + } + + for ( var i in blashrc ) + { + shell.json[i] = blashrc[i]; + } + } + + if ( stylercIndex > 0 ) + { + var cur_style = document.getElementsByTagName ( 'link' ); + + for ( var i in cur_style ) + { + if ( cur_style[i].getAttribute ) + { + if ( cur_style[i].getAttribute ( 'rel' ) && cur_style[i].getAttribute ( 'href' )) + { + if ( cur_style[i].getAttribute ( 'rel' ) == 'stylesheet' + && cur_style[i].getAttribute ( 'href' ).match ( /blash\.css$/ )) + { + var parent = cur_style[i].parentNode; + cur_style[i].parentNode.removeChild ( cur_style[i] ); + + var stylerc = document.createElement ( 'style', { type: 'text/css' }); + stylerc.innerHTML = shell.files[stylercIndex].content.replace ( //g, ' ' ); + parent.appendChild ( stylerc ); + } + } + } + } + } } } - if ( blashrcIndex > 0 ) - { - var blashrc = shell.files[blashrcIndex].content.replace ( //g, ' ' ); - blashrc = eval ( '(' + blashrc + ')' ); - - if ( !blashrc ) - { - return false; - } - - for ( var i in blashrc ) - { - shell.json[i] = blashrc[i]; - } - } + http3.send ( null ); } } xml2.send ( params ); - shell.cmdOut.innerHTML = http.responseText; - } else { - shell.cmdOut.innerHTML = http.responseText; - shell.auto_prompt_focus = true; - shell.auto_prompt_refresh = true; - shell.refreshPrompt ( false, false ); } + + shell.cmdOut.innerHTML = http.responseText; + shell.auto_prompt_focus = true; + shell.auto_prompt_refresh = true; + shell.refreshPrompt ( false, false ); } } http.send ( params ); - shell.cmdOut.innerHTML = ''; - // shell.auto_prompt_focus = true; - // shell.auto_prompt_refresh = true; - // shell.refreshPrompt ( false, false ); } }, } diff --git a/modules/users/users.php b/modules/users/users.php index 8ed8479..2dd64a3 100644 --- a/modules/users/users.php +++ b/modules/users/users.php @@ -73,6 +73,7 @@ switch ( $action ) print __mkdir ( '/home/'.$username, $perms )."
\n"; set_content ( '/home/'.$username.'/.blashrc', file_get_contents ( '../../system/default_blashrc.json' )); + set_content ( '/home/'.$username.'/.stylerc', file_get_contents ( '../../system/default_stylerc.css' )); include "../../system/files_json.php"; @@ -90,7 +91,8 @@ switch ( $action ) for ( $i=0; $i < count ( $json ); $i++ ) { - if ( $json[$i]['path'] == '/home/'.$username.'/.blashrc' ) + if ( $json[$i]['path'] == '/home/'.$username.'/.blashrc' + || $json[$i]['path'] == '/home/'.$username.'/.stylerc' ) { $json[$i]['can_read'] = $username; $json[$i]['can_write'] = $username; @@ -102,8 +104,6 @@ switch ( $action ) fwrite ( $fp, ""); fclose ( $fp ); - - break; } } diff --git a/system/blash.js b/system/blash.js index 878b240..1f3308c 100644 --- a/system/blash.js +++ b/system/blash.js @@ -234,12 +234,22 @@ function blash () shell.files = tmp; blashrcIndex = -1; // Index of .blashrc file + stylercIndex = -1; // Index of .stylerc file for ( var i in shell.files ) { if ( shell.files[i].path.match ( new RegExp ( '^' + shell.home + '/.blashrc$' ))) { blashrcIndex = i; + } + + if ( shell.files[i].path.match ( new RegExp ( '^' + shell.home + '/.stylerc$' ))) + { + stylercIndex = i; + } + + if ( blashrcIndex >= 0 && stylercIndex >= 0 ) + { break; } } @@ -259,6 +269,31 @@ function blash () shell.json[i] = blashrc[i]; } } + + if ( stylercIndex > 0 ) + { + var cur_style = document.getElementsByTagName ( 'link' ); + + for ( var i in cur_style ) + { + if ( cur_style[i].getAttribute ) + { + if ( cur_style[i].getAttribute ( 'rel' ) && cur_style[i].getAttribute ( 'href' )) + { + if ( cur_style[i].getAttribute ( 'rel' ) == 'stylesheet' + && cur_style[i].getAttribute ( 'href' ).match ( /blash\.css$/ )) + { + var parent = cur_style[i].parentNode; + cur_style[i].parentNode.removeChild ( cur_style[i] ); + + var stylerc = document.createElement ( 'style', { type: 'text/css' }); + stylerc.innerHTML = shell.files[stylercIndex].content.replace ( //g, ' ' ); + parent.appendChild ( stylerc ); + } + } + } + } + } } } @@ -650,14 +685,20 @@ function blash () if (( this.prompt = document.getElementById ( "promptText" ))) { - value = this.prompt.innerHTML; - this.window.removeChild ( this.prompt ); + value = this.prompt.innerHTML + (( document.getElementsByName ( 'blashPrompt' )[0].value.length > 0 ) ? + ' ' + document.getElementsByName ( 'blashPrompt' )[0].value : '' ); + this.prompt.parentNode.removeChild ( document.getElementsByName ( 'blashPrompt' )[0] ); + } + + if ( document.getElementsByName ( 'blashPrompt' )[0] ) + { + document.getElementsByName ( 'blashPrompt' )[0].parentNode.removeChild ( document.getElementsByName ( 'blashPrompt' )[0] ); } if (( this.cmdOut = document.getElementById ( "blashCmdOut" ))) { out = this.cmdOut.innerHTML; - this.window.removeChild ( this.cmdOut ); + this.cmdOut.parentNode.removeChild ( this.cmdOut ); } if ( clearTerm ) @@ -667,9 +708,15 @@ function blash () if ( !clearOut ) { + if ( document.getElementById ( 'promptText' )) + { + document.getElementById ( 'promptText' ).parentNode.removeChild ( document.getElementById ( 'promptText' )); + } + var outDiv = document.createElement ( 'span' ); outDiv.innerHTML = ((value.length > 0) ? value : '') + - '
' + ((out.length > 0) ? (out + '
') : '') + text + (( shell.__first_cmd ) ? '
' : '' ); + ( value.match ( /\s*$/ ) ? '' : '
' ) + ((out.length > 0) ? (out + '
') : '') + text + (( shell.__first_cmd ) ? '
' : '' ); + outDiv.innerHTML = outDiv.innerHTML.replace ( /\s*$/, '' ); this.window.appendChild ( outDiv ); } diff --git a/system/default_stylerc.css b/system/default_stylerc.css new file mode 100644 index 0000000..12a4c0f --- /dev/null +++ b/system/default_stylerc.css @@ -0,0 +1,141 @@ +/** + * Default style for blash + */ + +body +{ + background-color : black; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; + tabindex : -1; +} + +pre +{ + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; +} + +input.promptInput +{ + background-color : black; + border : 0; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; + width : 500px; +} + +input.password +{ + background-color : black; + border : 0; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; + width : 500px; +} + +div#blashWindow +{ + /* width : 800px; */ + /* height : 400px; */ + margin : auto; + /* padding : 10px; */ + /* border : 1px solid #888; */ + overflow : auto; + tabindex : -1; +} + +span.directory +{ + color : #2553ee; +} + +a +{ + color : green; + tabindex : -1; +} + +a:visited +{ + color : green; + tabindex : -1; +} + +span.syntax +{ + color : white; + font-weight : bold; +} + +span.brief +{ + color : green; +} + +span.filematch +{ + color : #672377; +} + +span.linematch +{ + color : #73d216; +} + +span.match +{ + color : #992010; + font-weight : bold; +} + +div.editor_container +{ + width : 100%; + height : 100%; + overflow : hidden; +} + +textarea.editor_window +{ + border : 0px; + width : 100%; + height : 93%; + background-color : black; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; +} + +.editor_status +{ + width : 100%; + background-color : black; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; + margin-bottom : 0; +} + +.editor_head +{ + width : 100%; + background-color : #222; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; + margin-bottom : 0; +} + +input.editor_status_input +{ + background-color : black; + color : #888; + font-family : Terminus, courier, monospace, fixed; + font-size : 13px; + border : 0; +} + diff --git a/system/files_json.php b/system/files_json.php index b7b5445..3f25ef4 100644 --- a/system/files_json.php +++ b/system/files_json.php @@ -29,8 +29,6 @@ $files_json = << * Sample configuration and contents
*/

{
\u0009'banner' : 'Welcome back to blash<br/><br/>',
\u0009'machine' : 'localhost',

\u0009/**
\u0009 * Macros for promptText:
\u0009 * #{xxx} or #{xxxxxx} - use the specified HTML colour
\u0009 * %n - username
\u0009 * %m - machine name
\u0009 * %W - current working directory
\u0009 */
\u0009'promptText' : '[#{008}%n#{888}@#{008}%m#{888} %W] $ '
}

"} ] JSON;