~/.stylerc support added

This commit is contained in:
BlackLight 2011-01-07 22:54:07 +01:00
parent bc50ada7d9
commit 4507ef5d06
8 changed files with 285 additions and 46 deletions

View File

@ -7,6 +7,12 @@ body
tabindex : -1;
}
pre
{
font-family : Terminus, courier, monospace, fixed;
font-size : 13px;
}
input.promptInput
{
background-color : black;

View File

@ -33,7 +33,7 @@
{
window.open ( dir[i].href );
} else if ( dir[i].content ) {
return dir[i].content + "<br/>\n";
return '<pre>' + dir[i].content + "</pre>";
}
}
}
@ -46,7 +46,7 @@
return "cat: " + arg + ": No such file or directory<br/>\n";
}
out = out.replace ( /<br\/>\s*$/, '' );
out = out.replace ( /<br\/?>\s*$/, '' );
return out;
}
}

View File

@ -3,7 +3,7 @@
"info" : {
"syntax" : "chmod &lt;perms&gt; &lt;file|directory&gt;",
"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 )

View File

@ -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 ( /<br\/?>/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 ( /<br\/?>/g, ' ' );
parent.appendChild ( stylerc );
}
}
}
}
}
}
}
if ( blashrcIndex > 0 )
{
var blashrc = shell.files[blashrcIndex].content.replace ( /<br\/?>/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 );
}
},
}

View File

@ -73,6 +73,7 @@ switch ( $action )
print __mkdir ( '/home/'.$username, $perms )."<br/>\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, "<?php\n\n\$files_json = <<<JSON\n".__json_encode ( $json )."\nJSON;\n\n?>");
fclose ( $fp );
break;
}
}

View File

@ -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 ( /<br\/?>/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 : '') +
'<br/>' + ((out.length > 0) ? (out + '<br/>') : '') + text + (( shell.__first_cmd ) ? '<br/>' : '' );
( value.match ( /<br\/?>\s*$/ ) ? '' : '<br/>' ) + ((out.length > 0) ? (out + '<br/>') : '') + text + (( shell.__first_cmd ) ? '<br/>' : '' );
outDiv.innerHTML = outDiv.innerHTML.replace ( /<br\/?>\s*$/, '' );
this.window.appendChild ( outDiv );
}

141
system/default_stylerc.css Normal file
View File

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

View File

@ -29,8 +29,6 @@ $files_json = <<<JSON
, {"path": "/contacts", "type": "file", "content": "Contact me at spam@montypython.com"}
, {"path": "/irc", "type": "file", "content": "IRC channel at #thegame@irc.randomstuff.com"}
, {"path": "/root", "type": "directory", "can_write": "root", "can_read": "root"}
, {"path": "/home/blacklight", "type": "directory", "owner": "blacklight", "can_read": "blacklight", "can_write": "blacklight"}
, {"path": "/home/blacklight/.blashrc", "type": "file", "owner": "guest", "can_read": "blacklight", "can_write": "blacklight", "content": "/**<br/> * Sample configuration and contents<br/> */<br/><br/>{<br/>\u0009'banner' : 'Welcome back to blash&lt;br/&gt;&lt;br/&gt;',<br/>\u0009'machine' : 'localhost',<br/><br/>\u0009/**<br/>\u0009 * Macros for promptText:<br/>\u0009 * #{xxx} or #{xxxxxx} - use the specified HTML colour<br/>\u0009 * %n - username<br/>\u0009 * %m - machine name<br/>\u0009 * %W - current working directory<br/>\u0009 */<br/>\u0009'promptText' : '[#{008}%n#{888}@#{008}%m#{888} %W] $ '<br/>}<br/><br/>"}
]
JSON;