Tons of multiuser support improvements
This commit is contained in:
parent
5168c2c0f0
commit
ca7eee7e7c
6 changed files with 127 additions and 23 deletions
|
@ -8,9 +8,7 @@
|
|||
|
||||
"action" : function ( arg )
|
||||
{
|
||||
var out = '';
|
||||
shell.refreshPrompt ( true );
|
||||
return out;
|
||||
shell.refreshPrompt ( true, true );
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
}
|
||||
|
||||
http.send ( params );
|
||||
shell.path = shell.json.basepath;
|
||||
return out;
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 "";
|
||||
|
||||
?>
|
||||
|
|
|
@ -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 = '<br/>' + out + '<br/>' + text;
|
||||
this.window.appendChild ( outDiv );
|
||||
}
|
||||
var outDiv = document.createElement ( 'span' );
|
||||
outDiv.innerHTML = ((value.length > 0) ? value : '') +
|
||||
'<br/>' + ((out.length > 0) ? (out + '<br/>') : '') + text;
|
||||
this.window.appendChild ( outDiv );
|
||||
}
|
||||
|
||||
this.prompt = document.createElement ( 'input' );
|
||||
|
|
Loading…
Reference in a new issue