2010-12-25 21:52:37 +01:00
|
|
|
{
|
|
|
|
"name" : "su",
|
|
|
|
|
|
|
|
"info" : {
|
|
|
|
"syntax" : "su [username]",
|
|
|
|
"brief" : "Change user ID or become superuser",
|
|
|
|
},
|
|
|
|
|
|
|
|
"action" : function ( arg )
|
|
|
|
{
|
|
|
|
var out = '';
|
|
|
|
|
2010-12-29 21:32:43 +01:00
|
|
|
if ( !shell.has_users )
|
|
|
|
{
|
|
|
|
return "Users module not enabled<br/>\n";
|
|
|
|
}
|
|
|
|
|
2010-12-25 21:52:37 +01:00
|
|
|
if ( !arg || arg.length == 0 )
|
|
|
|
{
|
|
|
|
arg = 'root';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( shell.__first_cmd )
|
|
|
|
{
|
2010-12-30 23:05:42 +01:00
|
|
|
shell.cmdOut.innerHTML = '<br/>Password: <input type="password" ' +
|
|
|
|
'name="password" class="password" ' +
|
|
|
|
'onkeyup="shell.getPassword ( event )">' +
|
|
|
|
'<br/>';
|
|
|
|
|
2010-12-25 21:52:37 +01:00
|
|
|
shell.__first_cmd = false;
|
2010-12-30 23:05:42 +01:00
|
|
|
} else {
|
|
|
|
shell.cmdOut.innerHTML = 'Password: <input type="password" ' +
|
|
|
|
'name="password" class="password" ' +
|
|
|
|
'onkeyup="shell.getPassword ( event )">' +
|
|
|
|
'<br/>';
|
2010-12-25 21:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
shell.getPassword = this.getPassword;
|
|
|
|
shell.newuser = arg;
|
|
|
|
|
|
|
|
shell.auto_prompt_focus = false;
|
|
|
|
shell.auto_prompt_refresh = false;
|
|
|
|
|
|
|
|
this.password = document.getElementsByName ( "password" )[0];
|
|
|
|
this.password.focus();
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
|
|
|
|
|
|
|
"getPassword" : function ( e )
|
|
|
|
{
|
|
|
|
var evt = ( window.event ) ? window.event : e;
|
|
|
|
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
|
|
|
|
var password = document.getElementsByName ( "password" )[0];
|
|
|
|
|
|
|
|
if ( key == 13 && password.value.length > 0 )
|
|
|
|
{
|
|
|
|
var users_php = window.location.href;
|
|
|
|
users_php = users_php.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/users.php' );
|
|
|
|
params = 'action=login&user=' + escape ( shell.newuser ) + '&pass=' + md5 ( password.value );
|
|
|
|
|
|
|
|
var http = new XMLHttpRequest();
|
|
|
|
http.open ( "POST", users_php, true );
|
|
|
|
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 )
|
|
|
|
{
|
2010-12-29 21:32:43 +01:00
|
|
|
if ( http.responseText.match ( /^Successfully logged in as '(.+?)'/i ))
|
2010-12-25 21:52:37 +01:00
|
|
|
{
|
|
|
|
var user = RegExp.$1;
|
|
|
|
shell.user = user;
|
2010-12-29 21:32:43 +01:00
|
|
|
|
|
|
|
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 + ')' );
|
2010-12-30 03:27:26 +01:00
|
|
|
|
|
|
|
// Remove duplicates
|
|
|
|
var tmp = new Array();
|
|
|
|
|
|
|
|
for ( var i in shell.files )
|
|
|
|
{
|
|
|
|
var contains = false;
|
|
|
|
|
|
|
|
for ( var j=0; j < tmp.length && !contains; j++ )
|
|
|
|
{
|
|
|
|
if ( shell.files[i].path == tmp[j].path )
|
|
|
|
{
|
|
|
|
contains = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !contains )
|
|
|
|
{
|
|
|
|
tmp.push ( shell.files[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shell.files = tmp;
|
2010-12-29 21:32:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
http2.send ( null );
|
2010-12-25 21:52:37 +01:00
|
|
|
|
2010-12-31 03:00:35 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-07 22:54:07 +01:00
|
|
|
shell.files_json = window.location.href;
|
2011-01-07 11:42:38 +01:00
|
|
|
|
2011-01-07 22:54:07 +01:00
|
|
|
if ( shell.has_users )
|
2011-01-07 11:42:38 +01:00
|
|
|
{
|
2011-01-07 22:54:07 +01:00
|
|
|
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' );
|
2011-01-07 11:42:38 +01:00
|
|
|
}
|
|
|
|
|
2011-01-07 22:54:07 +01:00
|
|
|
var http3 = new XMLHttpRequest();
|
|
|
|
http3.open ( "GET", shell.files_json, true );
|
2011-01-07 11:42:38 +01:00
|
|
|
|
2011-01-07 22:54:07 +01:00
|
|
|
http3.onreadystatechange = function ()
|
|
|
|
{
|
|
|
|
if ( http3.readyState == 4 && http3.status == 200 )
|
2011-01-07 11:42:38 +01:00
|
|
|
{
|
2011-01-07 22:54:07 +01:00
|
|
|
shell.files = eval ( '(' + http3.responseText + ')' );
|
|
|
|
blashrcIndex = -1; // Index of .blashrc file
|
|
|
|
stylercIndex = -1; // Index of .stylerc file
|
2011-01-07 11:42:38 +01:00
|
|
|
|
2011-01-07 22:54:07 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-07 11:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-07 22:54:07 +01:00
|
|
|
|
|
|
|
http3.send ( null );
|
2010-12-31 03:00:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml2.send ( params );
|
|
|
|
}
|
2011-01-07 22:54:07 +01:00
|
|
|
|
|
|
|
shell.cmdOut.innerHTML = http.responseText;
|
|
|
|
shell.auto_prompt_focus = true;
|
|
|
|
shell.auto_prompt_refresh = true;
|
|
|
|
shell.refreshPrompt ( false, false );
|
2010-12-25 21:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
http.send ( params );
|
|
|
|
shell.cmdOut.innerHTML = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|