diff --git a/commands/clear.json b/commands/clear.json index 5e9fff6..937d430 100644 --- a/commands/clear.json +++ b/commands/clear.json @@ -8,9 +8,7 @@ "action" : function ( arg ) { - var out = ''; - shell.refreshPrompt ( true ); - return out; + shell.refreshPrompt ( true, true ); }, } diff --git a/commands/logout.json b/commands/logout.json index f3d597a..19c55af 100644 --- a/commands/logout.json +++ b/commands/logout.json @@ -80,6 +80,7 @@ } http.send ( params ); + shell.path = shell.json.basepath; return out; }, } diff --git a/commands/su.json b/commands/su.json index f5916ea..6fdf346 100644 --- a/commands/su.json +++ b/commands/su.json @@ -112,19 +112,49 @@ } http2.send ( null ); - } - shell.cmdOut.innerHTML = http.responseText; - shell.refreshPrompt ( false, false ); + var xml2 = new XMLHttpRequest(); + xml2.open ( "POST", users_php, true ); + xml2.setRequestHeader ( "Content-type", "application/x-www-form-urlencoded" ); + xml2.setRequestHeader ( "Content-length", params.length ); + xml2.setRequestHeader ( "Connection", "close" ); + params = 'action=gethome'; + + xml2.onreadystatechange = function () + { + if ( xml2.readyState == 4 && xml2.status == 200 ) + { + if ( xml2.responseText.length > 0 ) + { + shell.home = xml2.responseText; + shell.path = shell.home; + } else { + shell.user = shell.json.user; + } + + shell.auto_prompt_focus = true; + shell.auto_prompt_refresh = true; + shell.refreshPrompt ( false, false ); + } + } + + 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 ); + } } } http.send ( params ); shell.cmdOut.innerHTML = ''; - shell.auto_prompt_focus = true; - shell.auto_prompt_refresh = true; - shell.refreshPrompt ( false, false ); + // shell.auto_prompt_focus = true; + // shell.auto_prompt_refresh = true; + // shell.refreshPrompt ( false, false ); } }, } diff --git a/modules/users/user_utils.php b/modules/users/user_utils.php index 95cb9a9..b0560aa 100644 --- a/modules/users/user_utils.php +++ b/modules/users/user_utils.php @@ -34,6 +34,38 @@ function getUser () return "guest"; } +function getHome () +{ + include 'userlist.php'; + + if ( isset ( $_COOKIE['username'] ) && isset ( $_COOKIE['auth'] )) + { + if ( !( $xml = new SimpleXMLElement ( $xmlcontent ))) + { + return "Unable to open the users XML file\n"; + } + + for ( $i = 0; $i < count ( $xml->user ); $i++ ) + { + if ( !strcasecmp ( $xml->user[$i]['name'], $_COOKIE['username'] )) + { + $auth = md5 ( $xml->user[$i]['name'] . $xml->user[$i]['pass'] ); + + if ( !strcasecmp ( $auth, $_COOKIE['auth'] )) + { + return $xml->user[$i]['home']; + } else { + return '/'; + } + } + } + + return '/'; + } + + return '/'; +} + function getPerms ( $resource ) { include "../../system/files_json.php"; @@ -377,7 +409,7 @@ function __rmdir ( $dir ) $json = json_decode ( $files_json, true ); $dir_found = false; - for ( $i=0; $i < count ( $json ) && !$dir_found; $i++ ) + for ( $i=0; $i < count ( $json ); $i++ ) { $path = $json[$i]['path']; @@ -387,18 +419,29 @@ function __rmdir ( $dir ) } if ( $path == $dir ) + { + if ( $json[$i]['type'] != 'directory' ) + { + $dir = str_replace ( '<', '<', $dir ); + $dir = str_replace ( '>', '>', $dir ); + return "rmdir: Could not remove directory $dir: It is not a directory\n"; + } + } + + if ( preg_match ( "@^".$dir."(/+.*)?@", $path )) { $dir_found = true; - $perms = getPerms ( $dir ); + $perms = getPerms ( $path ); $perms = json_decode ( $perms, true ); if ( $perms['write'] == false ) { - $dir = str_replace ( '<', '<', $dir ); - $dir = str_replace ( '>', '>', $dir ); - return "rmdir: Could not remove directory $dir: Permission denied\n"; + $path = str_replace ( '<', '<', $path ); + $path = str_replace ( '>', '>', $path ); + return "rmdir: Could not remove directory $path Permission denied\n"; } else { array_splice ( $json, $i, 1 ); + $i--; } } } diff --git a/modules/users/users.php b/modules/users/users.php index 0edf75f..2f58dfd 100644 --- a/modules/users/users.php +++ b/modules/users/users.php @@ -117,12 +117,14 @@ switch ( $action ) } print "Username not found: '$username'\n"; - return ''; break; case 'getuser': print getUser(); - return 0; + break; + + case 'gethome': + print getHome(); break; case 'logout': @@ -216,6 +218,12 @@ switch ( $action ) print __rmdir ( $dir ); break; + + default : + print "Unallowed action\n"; + break; } +return ""; + ?> diff --git a/system/blash.js b/system/blash.js index d6686ba..c5fdfda 100644 --- a/system/blash.js +++ b/system/blash.js @@ -16,6 +16,9 @@ function blash () /** Current user */ this.user = ''; + /** Home directory */ + this.home = '/'; + /** Object containing the parsed JSON configuration object */ this.json = {}; @@ -116,6 +119,29 @@ function blash () } xml.send ( params ); + + var xml2 = new XMLHttpRequest(); + xml2.open ( "POST", users_php, true ); + xml2.setRequestHeader ( "Content-type", "application/x-www-form-urlencoded" ); + xml2.setRequestHeader ( "Content-length", params.length ); + xml2.setRequestHeader ( "Connection", "close" ); + params = 'action=gethome'; + + xml2.onreadystatechange = function () + { + if ( xml2.readyState == 4 && xml2.status == 200 ) + { + if ( xml2.responseText.length > 0 ) + { + shell.home = xml2.responseText; + shell.path = shell.home; + } else { + shell.user = shell.json.user; + } + } + } + + xml2.send ( params ); } } @@ -286,7 +312,7 @@ function blash () return false; } else if ( key == 76 && evt.ctrlKey ) { // CTRL-l clears the screen - this.refreshPrompt ( true ); + this.refreshPrompt ( true, false ); return false; } else if ( key == 13 || key == 10 || ( key == 67 && evt.ctrlKey )) { if ( this.prompt.value.length != 0 && ( key != 67 || !evt.ctrlKey )) @@ -602,12 +628,10 @@ function blash () if ( !clearOut ) { - if ( out.length > 0 ) - { - var outDiv = document.createElement ( 'span' ); - outDiv.innerHTML = '
' + out + '
' + text; - this.window.appendChild ( outDiv ); - } + var outDiv = document.createElement ( 'span' ); + outDiv.innerHTML = ((value.length > 0) ? value : '') + + '
' + ((out.length > 0) ? (out + '
') : '') + text; + this.window.appendChild ( outDiv ); } this.prompt = document.createElement ( 'input' );