{
"name" : "nano",
"info" : {
"syntax" : "nano <file name>",
"brief" : "Edit the content of a new or existing file",
},
"action" : function ( arg )
{
var file = null;
var parent_dir = null;
var newfile = false;
if ( !arg || arg.length == 0 )
{
return "nano: Parameter expected
\n";
}
arg = shell.expandPath ( arg );
if (!( parent_dir = shell.getParentDirectory ( arg )))
{
return "nano: Parent directory not found
\n";
}
if ( !( file = shell.getFile ( arg )))
{
newfile = true;
}
if ( !newfile )
{
if ( file['type'] == 'directory' )
{
arg = arg.replace ( //g, '>' );
return "nano: Cannot edit '" + arg + "': Is a directory
\n";
}
}
var users_php = window.location.href;
users_php = users_php.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/users.php' );
params = 'action=getperms&resource=' +
( newfile ? escape ( parent_dir['path'] ) : escape ( arg ));
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 )
{
if ( http.responseText.length > 0 )
{
shell.perms = eval ( '(' + http.responseText + ')' );
}
}
}
http.send ( params );
fname = arg.replace ( //g, '>' );
shell.fname = arg;
shell.editorkeypressed = this.editorkeypressed;
shell.confirmkey = this.confirmkey;
shell.bufferSave = this.bufferSave;
shell.firstKey = true; // Set when no key has been pressed yet
shell.default_editor_status = "[^X Exit] [^O WriteOut] [^F Where Is]";
if ( shell.perms )
{
if ( shell.perms.write == false )
{
shell.default_editor_status += ' [read-only]';
}
}
shell.default_editor_head = "
blash nano | File: " + fname + " |