diff --git a/README b/README
index 926f392..dd916a6 100644
--- a/README
+++ b/README
@@ -27,6 +27,9 @@ pseudo-terminal are represented in normal font, the files that links to an
external content is instead represented as an `executable' file (by default, in
colour green).
+Q.: Which is the default password for 'root' user?
+A.: blash. Remember to use it only one time, then change it using the passwd command.
+
Q.: Which browsers are compatible with blash?
A.: So far blash has been successfully tested with the following browsers:
@@ -45,11 +48,14 @@ blash. Internet Explorer is currently NOT working with blash, at least any
release <= 8. I'm sorry, choose a decent browser.
Q.: How do I add the contents for my web site in blash?
-A.: Open the file blash.json. This JSON file contains the preferences for your
+A.: Open the file system/blash.json. This JSON file contains the preferences for your
shell (banner, prompt style, default user, escape sequences recognized in the
-prompt string...), the commands to be used, and the array "directories". This
-array is the container of your web site data. Each element can have the
-following fields:
+prompt string...), the commands to be used, and so on. Change this file in order to
+change the preferences of your CMS.
+
+The contents of your web site are held in the file system/files_json.php. Modify this
+file directly using the example contents as trace for adding or removing new contents.
+Each content can include the following fields:
- path (MANDATORY), the full absolute path that identifies that resource
- type (MANDATORY), the resource type (directory or file)
diff --git a/blash.json b/blash.json
deleted file mode 100644
index a3accad..0000000
--- a/blash.json
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * Sample configuration and contents
- */
-
-{
- "banner" : "blash version 0.1
" +
- "Copyright (C) 2010 BlackLight <blacklight@autistici.org>" +
- "
Licence GPLv3+: GNU GPL version 3 or later " +
- "<" +
- "http://gnu.org/licences/gpl.html>
" +
- "Source code available at " +
- "https://github.com/BlackLight/blash
" +
- "This is free software; you are free to change and " +
- "redistribuite it.
There is NO WARRANTY, to the " +
- "extent permitted by law.
" +
- "Type 'man blash' for help on usage and available commands
",
-
- "user" : "guest",
- "machine" : "localhost",
- "shellName" : "blash",
- "basepath" : "/",
- "promptText" : "[#{800}%n#{888}@#{800}%m#{888} %W] $ ",
- "promptSequences" : [
- {
- "sequence" : "%n",
- "default_text" : "guest",
- "text" : function () {
- return shell.user;
- },
- },
- {
- "sequence" : "%m",
- "default_text" : "localhost",
- "text" : function () {
- return shell.json.machine;
- },
- },
- {
- "sequence" : "%W",
- "default_text" : "/",
- "text" : function () {
- return shell.path;
- },
- }
- ],
-
- "directories" : [
- {
- "path" : "/",
- "type" : "directory",
- },
- {
- "path" : "/blog",
- "type" : "directory",
- },
- {
- "path" : "/news",
- "type" : "directory",
- },
- {
- "path" : "/forum",
- "type" : "directory",
- },
- {
- "path" : "/tutorials",
- "type" : "directory",
- },
- {
- "path" : "/software",
- "type" : "directory",
- },
- {
- "path" : "/etc",
- "type" : "directory",
- },
- {
- "path" : "/home",
- "type" : "directory",
- },
- {
- "path" : "/home/guest",
- "type" : "directory",
- },
- {
- "path" : "/home/guest/mbox",
- "type" : "file",
- "content" : "No new mail",
- },
- {
- "path" : "/google",
- "type" : "file",
- "href" : "http://www.google.com",
- },
- {
- "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" : "Sent by admin at 00:00:01
Welcome to the forum
\n" +
- "Sent by troll at 00:00:02
lulz
\n",
- },
- {
- "path" : "/forum/post2",
- "type" : "file",
- "content" : "Sent by lolcat at 00:00:03
Can I haz cheezburger?
\n",
- },
- {
- "path" : "/home/guest/.blashrc",
- "type" : "file",
- "content" : "Custom blash configuration file",
- },
- {
- "path" : "/home/guest/mbox",
- "type" : "file",
- "content" : "No new mail",
- },
- {
- "path" : "/news/news1",
- "type" : "file",
- "content" : "Nothing new under the sun",
- },
- {
- "path" : "/software/soft1",
- "type" : "file",
- "href" : "/software/soft1.tar.gz",
- },
- {
- "path" : "/software/soft2",
- "type" : "file",
- "href" : "/software/soft2.tar.gz",
- },
- {
- "path" : "/software/soft3",
- "type" : "file",
- "href" : "/software/soft3.tar.gz",
- },
- {
- "path" : "/tutorials/tut1",
- "type" : "file",
- "href" : "/software/tut1.pdf",
- },
- {
- "path" : "/tutorials/tut2",
- "type" : "file",
- "href" : "/software/tut2.pdf",
- },
- {
- "path" : "/github",
- "type" : "file",
- "href" : "https://github.com/BlackLight/blash",
- },
- {
- "path" : "/aboutme",
- "type" : "file",
- "content" : "Luke, I am your father",
- },
- {
- "path" : "/contacts",
- "type" : "file",
- "content" : "Contact me at spam@montypython.com",
- },
- {
- "path" : "/irc",
- "type" : "file",
- "content" : "IRC channel at #thegame@irc.randomstuff.com",
- },
- ],
-
- "commands" : [
- "cat",
- "cd",
- "clear",
- "echo",
- "eval",
- "find",
- "logout",
- "ls",
- "man",
- "passwd",
- "pwd",
- "su",
- "useradd",
- "whoami",
- ],
-}
-
diff --git a/commands/cat.json b/commands/cat.json
index 753ca61..e560b36 100644
--- a/commands/cat.json
+++ b/commands/cat.json
@@ -9,14 +9,14 @@
"action" : function ( arg )
{
var out = '';
+ var found = false;
+ var dir = shell.files;
if ( !arg || arg.length == 0 )
{
return "Argument required
\n";
}
- var found = false;
- var dir = shell.json.directories;
arg = shell.expandPath ( arg );
for ( var i=0; i < dir.length && !found; i++ )
@@ -39,7 +39,15 @@
}
}
+ if ( !found )
+ {
+ arg = arg.replace ( '<', '<' );
+ arg = arg.replace ( '>', '>' );
+ return "cat: " + arg + ": No such file or directory
\n";
+ }
+
+ out = out.replace ( /
\s*$/, '' );
return out;
- },
+ }
}
diff --git a/commands/cd.json b/commands/cd.json
index e1665fb..4dedda8 100644
--- a/commands/cd.json
+++ b/commands/cd.json
@@ -18,13 +18,13 @@
var found = false;
arg = shell.expandPath ( arg );
- for ( var i=0; i < shell.json.directories.length && !found; i++ )
+ for ( var i=0; i < shell.files.length && !found; i++ )
{
- if ( shell.json.directories[i].path == arg )
+ if ( shell.files[i].path == arg )
{
found = true;
- if ( shell.json.directories[i].type != 'directory' )
+ if ( shell.files[i].type != 'directory' )
{
return "cd: not a directory: " + arg + "
\n";
}
diff --git a/commands/find.json b/commands/find.json
index 596b6fd..c5501b7 100644
--- a/commands/find.json
+++ b/commands/find.json
@@ -22,9 +22,9 @@
var re = new RegExp ( arg, "i" );
- for ( var i in shell.json.directories )
+ for ( var i in shell.files )
{
- var dir = shell.json.directories[i];
+ var dir = shell.files[i];
if ( dir.path.match ( re ))
{
diff --git a/commands/logout.json b/commands/logout.json
index 116ee78..856b626 100644
--- a/commands/logout.json
+++ b/commands/logout.json
@@ -10,6 +10,12 @@
{
var out = '';
+ if ( !shell.has_users )
+ {
+ return "Users module not enabled
\n";
+ }
+
+
if ( shell.user == shell.json.user )
{
return out;
@@ -27,6 +33,29 @@
http.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
http.setRequestHeader( "Content-length", params.length );
http.setRequestHeader( "Connection", "close" );
+
+ http.onreadystatechange = function ()
+ {
+ if ( http.readyState == 4 && http.status == 200 )
+ {
+ var files_config = window.location.href;
+ files_config = files_config.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/files.php' );
+
+ var http2 = new XMLHttpRequest();
+ http2.open ( "GET", files_config, true );
+
+ http2.onreadystatechange = function ()
+ {
+ if ( http2.readyState == 4 && http2.status == 200 )
+ {
+ shell.files = eval ( '(' + http2.responseText + ')' );
+ }
+ }
+
+ http2.send ( null );
+ }
+ }
+
http.send ( params );
return out;
},
diff --git a/commands/ls.json b/commands/ls.json
index 373845d..56e421b 100644
--- a/commands/ls.json
+++ b/commands/ls.json
@@ -9,12 +9,13 @@
"action" : function ( arg )
{
var dirs = new Array();
- var out = '';
var exists = false;
+ var re = null;
if ( !arg || arg.length == 0 )
{
- var re = null;
+ re = null;
+ arg = shell.path;
if ( shell.path == '/' )
{
@@ -24,14 +25,24 @@
}
} else if ( arg && arg.length > 0 ) {
arg = shell.expandPath ( arg );
- var re = new RegExp ( '^' + arg + '/[^/]+$' );
+ re = new RegExp ( '^' + arg + '/[^/]+$' );
}
- for ( var i=0; i < shell.json.directories.length; i++ )
- {
- var dir = shell.json.directories[i];
+ shell.re = re;
+ return this.ls ( arg );
+ },
- if ( dir.path.match ( re ))
+ "ls" : function ( arg )
+ {
+ var dirs = new Array();
+ var out = '';
+ var exists = false;
+
+ for ( var i=0; i < shell.files.length; i++ )
+ {
+ var dir = shell.files[i];
+
+ if ( dir.path.match ( shell.re ))
{
exists = true;
dir.path.match ( /\/([^\/]+)$/ );
@@ -114,9 +125,9 @@
if ( !exists )
{
- for ( var i=0; i < shell.json.directories.length; i++ )
+ for ( var i=0; i < shell.files.length; i++ )
{
- var dir = shell.json.directories[i];
+ var dir = shell.files[i];
arg = arg.replace ( /\/+$/, '' );
if ( dir.path.match ( arg ))
@@ -135,9 +146,9 @@
(( shell.path == '/' ) ? '' : '/' ) + arg );
}
- for ( var i=0; i < shell.json.directories.length; i++ )
+ for ( var i=0; i < shell.files.length; i++ )
{
- var dir = shell.json.directories[i];
+ var dir = shell.files[i];
if ( dir.path.match ( re ))
{
diff --git a/commands/passwd.json b/commands/passwd.json
index 84f400b..842e7b8 100644
--- a/commands/passwd.json
+++ b/commands/passwd.json
@@ -97,6 +97,12 @@
{
var out = '';
+ if ( !shell.has_users )
+ {
+ return "Users module not enabled
\n";
+ }
+
+
shell.auto_prompt_focus = false;
shell.auto_prompt_refresh = false;
shell.newuser = arg;
diff --git a/commands/su.json b/commands/su.json
index ea03868..07e5189 100644
--- a/commands/su.json
+++ b/commands/su.json
@@ -10,6 +10,11 @@
{
var out = '';
+ if ( !shell.has_users )
+ {
+ return "Users module not enabled
\n";
+ }
+
if ( !arg || arg.length == 0 )
{
arg = 'root';
@@ -60,17 +65,29 @@
{
if ( http.readyState == 4 && http.status == 200 )
{
- if ( http.responseText.match ( /^Successfully logged in as '(.+?)'\s+(.*)\s*$/i ))
+ if ( http.responseText.match ( /^Successfully logged in as '(.+?)'/i ))
{
var user = RegExp.$1;
- var auth = RegExp.$2;
-
shell.user = user;
- shell.cmdOut.innerHTML = "Successfully logged in as '" + user + "'";
- } else {
- shell.cmdOut.innerHTML = '';
+
+ var files_config = window.location.href;
+ files_config = files_config.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/files.php' );
+
+ var http2 = new XMLHttpRequest();
+ http2.open ( "GET", files_config, true );
+
+ http2.onreadystatechange = function ()
+ {
+ if ( http2.readyState == 4 && http2.status == 200 )
+ {
+ shell.files = eval ( '(' + http2.responseText + ')' );
+ }
+ }
+
+ http2.send ( null );
}
+ shell.cmdOut.innerHTML = http.responseText;
shell.refreshPrompt ( false, false );
}
}
diff --git a/commands/useradd.json b/commands/useradd.json
index c1dc323..b218b2f 100644
--- a/commands/useradd.json
+++ b/commands/useradd.json
@@ -78,6 +78,12 @@
{
var out = '';
+ if ( !shell.has_users )
+ {
+ return "Users module not enabled
\n";
+ }
+
+
if ( !arg || arg.length == 0 )
{
return "Usage: " + this.name + " <username>
\n";
diff --git a/commands/whoami.json b/commands/whoami.json
index 049a868..7ad70c0 100644
--- a/commands/whoami.json
+++ b/commands/whoami.json
@@ -9,6 +9,12 @@
"action" : function ( arg )
{
var out = '';
+
+ if ( !shell.has_users )
+ {
+ return "guest
\n";
+ }
+
if ( arg )
{
diff --git a/index.html b/index.html
index 5c6f0b4..95664f2 100644
--- a/index.html
+++ b/index.html
@@ -1,8 +1,8 @@