Tons of multiuser support improvements

This commit is contained in:
BlackLight 2010-12-31 03:00:35 +01:00
parent 5168c2c0f0
commit ca7eee7e7c
6 changed files with 127 additions and 23 deletions

View File

@ -8,9 +8,7 @@
"action" : function ( arg ) "action" : function ( arg )
{ {
var out = ''; shell.refreshPrompt ( true, true );
shell.refreshPrompt ( true );
return out;
}, },
} }

View File

@ -80,6 +80,7 @@
} }
http.send ( params ); http.send ( params );
shell.path = shell.json.basepath;
return out; return out;
}, },
} }

View File

@ -112,19 +112,49 @@
} }
http2.send ( null ); http2.send ( null );
}
shell.cmdOut.innerHTML = http.responseText; var xml2 = new XMLHttpRequest();
shell.refreshPrompt ( false, false ); 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 ); http.send ( params );
shell.cmdOut.innerHTML = ''; shell.cmdOut.innerHTML = '';
shell.auto_prompt_focus = true; // shell.auto_prompt_focus = true;
shell.auto_prompt_refresh = true; // shell.auto_prompt_refresh = true;
shell.refreshPrompt ( false, false ); // shell.refreshPrompt ( false, false );
} }
}, },
} }

View File

@ -34,6 +34,38 @@ function getUser ()
return "guest"; 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 ) function getPerms ( $resource )
{ {
include "../../system/files_json.php"; include "../../system/files_json.php";
@ -377,7 +409,7 @@ function __rmdir ( $dir )
$json = json_decode ( $files_json, true ); $json = json_decode ( $files_json, true );
$dir_found = false; $dir_found = false;
for ( $i=0; $i < count ( $json ) && !$dir_found; $i++ ) for ( $i=0; $i < count ( $json ); $i++ )
{ {
$path = $json[$i]['path']; $path = $json[$i]['path'];
@ -387,18 +419,29 @@ function __rmdir ( $dir )
} }
if ( $path == $dir ) if ( $path == $dir )
{
if ( $json[$i]['type'] != 'directory' )
{
$dir = str_replace ( '<', '&lt;', $dir );
$dir = str_replace ( '>', '&gt;', $dir );
return "rmdir: Could not remove directory $dir: It is not a directory\n";
}
}
if ( preg_match ( "@^".$dir."(/+.*)?@", $path ))
{ {
$dir_found = true; $dir_found = true;
$perms = getPerms ( $dir ); $perms = getPerms ( $path );
$perms = json_decode ( $perms, true ); $perms = json_decode ( $perms, true );
if ( $perms['write'] == false ) if ( $perms['write'] == false )
{ {
$dir = str_replace ( '<', '&lt;', $dir ); $path = str_replace ( '<', '&lt;', $path );
$dir = str_replace ( '>', '&gt;', $dir ); $path = str_replace ( '>', '&gt;', $path );
return "rmdir: Could not remove directory $dir: Permission denied\n"; return "rmdir: Could not remove directory $path Permission denied\n";
} else { } else {
array_splice ( $json, $i, 1 ); array_splice ( $json, $i, 1 );
$i--;
} }
} }
} }

View File

@ -117,12 +117,14 @@ switch ( $action )
} }
print "Username not found: '$username'\n"; print "Username not found: '$username'\n";
return '';
break; break;
case 'getuser': case 'getuser':
print getUser(); print getUser();
return 0; break;
case 'gethome':
print getHome();
break; break;
case 'logout': case 'logout':
@ -216,6 +218,12 @@ switch ( $action )
print __rmdir ( $dir ); print __rmdir ( $dir );
break; break;
default :
print "Unallowed action\n";
break;
} }
return "";
?> ?>

View File

@ -16,6 +16,9 @@ function blash ()
/** Current user */ /** Current user */
this.user = ''; this.user = '';
/** Home directory */
this.home = '/';
/** Object containing the parsed JSON configuration object */ /** Object containing the parsed JSON configuration object */
this.json = {}; this.json = {};
@ -116,6 +119,29 @@ function blash ()
} }
xml.send ( params ); 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; return false;
} else if ( key == 76 && evt.ctrlKey ) { } else if ( key == 76 && evt.ctrlKey ) {
// CTRL-l clears the screen // CTRL-l clears the screen
this.refreshPrompt ( true ); this.refreshPrompt ( true, false );
return false; return false;
} else if ( key == 13 || key == 10 || ( key == 67 && evt.ctrlKey )) { } else if ( key == 13 || key == 10 || ( key == 67 && evt.ctrlKey )) {
if ( this.prompt.value.length != 0 && ( key != 67 || !evt.ctrlKey )) if ( this.prompt.value.length != 0 && ( key != 67 || !evt.ctrlKey ))
@ -602,12 +628,10 @@ function blash ()
if ( !clearOut ) if ( !clearOut )
{ {
if ( out.length > 0 ) var outDiv = document.createElement ( 'span' );
{ outDiv.innerHTML = ((value.length > 0) ? value : '') +
var outDiv = document.createElement ( 'span' ); '<br/>' + ((out.length > 0) ? (out + '<br/>') : '') + text;
outDiv.innerHTML = '<br/>' + out + '<br/>' + text; this.window.appendChild ( outDiv );
this.window.appendChild ( outDiv );
}
} }
this.prompt = document.createElement ( 'input' ); this.prompt = document.createElement ( 'input' );