diff --git a/clite/commands.js b/clite/commands.js index 56f2408..94074bc 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -10,7 +10,7 @@ clite.commands.load('help',function(args,env,io) { stdio.printf(` Welcome to CLIte (pronounced like 'site' with an added L). -Various unix-like commands are available for navigating the CLIte shell: +Various common Unix commands are available in the CLIte shell: ls - list directory contents cat - concatenate files and print to std output or local file @@ -21,11 +21,10 @@ file - determines the file type And many more. Running any command with the argument -? will give you help for that program. -Or you can run help to get the same info. As a basic guide for guests: Use ls to see what content is available, eg: ls web -Use view or less to view the content, eg: view web/about +Use less to view the content, eg: less web/about `); return 0; }); @@ -516,12 +515,6 @@ Options: return null; }); -clite.commands.load('view',function(args,env,io) { - var stdio = io.include('stdio'); - stdio.printf('view is under development\n'); - return 0; -}); - clite.commands.load('rm',function(args,env,io) { var short = null; var file = null; @@ -2173,7 +2166,9 @@ Options: clite.commands.load('su',function(args,env,io) { var stdio = io.include('stdio'); var stdlib = io.include('stdlib'); + var clite = io.include('clite'); var auth = io.include('auth'); + var term = io.include('term'); var pw = null; var preserve = true; @@ -2232,6 +2227,7 @@ Options: } function doLogin(str) { + term.ttyctrl('echo',true); if (!auth.checkpassuid(pw.pw_uid,str)) { stdio.printf('authentication error\n'); io.exit(1); @@ -2241,9 +2237,44 @@ Options: changeUser(); } + function preLogin(str) { + if (str == 'no') { + io.exit(0); + return; + } + if (str != 'yes') { + cookies(); + return; + } + + if (stdlib.getuid() != 0) { + stdio.write(io.stdout,'password: '); + term.ttyctrl('echo',false); + if (!stdio.read(io.stdin,doLogin)) { + term.ttyctrl('echo',true); + stdio.write(io.stderr,'authentication error\n'); + io.exit(1); + } + return; + } + + changeUser(); + } + + function cookies() { + clite.cookienotice(); + + stdio.printf("Enter 'yes' to agree, or 'no' to cancel: "); + if (!stdio.read(io.stdin,preLogin)) { + stdio.write(io.stderr,'internal error\n'); + io.exit(1); + } + } + function main(args) { var user = 'root'; var shellnext = false; + var accept = false; for (var i=1; i