Login

This plugin is called when you open TinyShell and is not already logged in. It makes no sense to execute it when logged in. The plugin uses a ticket based zero-knowledge algorithm to authorize a user. See section Security for further details.

Command line interface

Syntax

  1. $ login

Arguments

This command takes no arguments.

Example

login.php

  1. <?
  2. require("../plugin.php");
  3. if (is_ajax(false)) {
  4. switch ($_POST["action"]) {
  5. case 'ticket':
  6. die(ticket_request());
  7. break;
  8. case 'login':
  9. if (ticket_validate($_POST['hash'], SHELL_USERNAME.SHELL_PASSWORD)) {
  10. // notice you can change the ticket validation
  11. // to validate something else, and the still keep
  12. // the following to prove authorization
  13. $_SESSION = array();
  14. $_SESSION['login']['username'] = SHELL_USERNAME;
  15. $_SESSION['login']['password'] = SHELL_PASSWORD;
  16. $_SESSION['login']['IP'] = $_SERVER['REMOTE_ADDR'];
  17. $_SESSION['login']['UA'] = $_SERVER['HTTP_USER_AGENT'];
  18. die("0");
  19. }
  20. die("1");
  21. break;
  22. }
  23. exit;
  24. }
  25. ?>
  26. /**
  27. * Login
  28. **/
  29. TinyShell.plugins.login = new Class({
  30. description: "Login to TinyShell",
  31. username: '',
  32. run : function(terminal, args) {
  33. this.t = terminal;
  34. this.t.set_protocol("Login as: ").read_line(this.set_username);
  35. },
  36. set_username: function(terminal, line) {
  37. this.username = line;
  38. this.get_password();
  39. },
  40. get_password: function() {
  41. this.t.print("Using keyboard-interactive authentication.");
  42. this.t.set_protocol("Password: ", "password").read_line(this.set_password);
  43. },
  44. set_password: function(terminal, line) {
  45. this.password = line;
  46. this.t.ajax_request(this.use_ticket, "<?php echo $_AJAX_URL?>", "action=ticket");
  47. },
  48. use_ticket : function(ticket) {
  49. this.t.ajax_request(this.validate_auth, "<?php echo $_AJAX_URL?>", "action=login&hash="+encodeURIComponent(this.t.ticket_hash(ticket, this.username+this.password)));
  50. },
  51. validate_auth: function(response) {
  52. if (response != "0") {
  53. this.t.print("Access denied");
  54. this.get_password();
  55. } else {
  56. this.t.user = this.username;
  57. this.t.print("Login: <?=date("r")?> from <?=gethostbyaddr($_SERVER["REMOTE_ADDR"])?>");
  58. this.t.print();
  59. this.t.print("The plugins included with the TinyShell system are free software;");
  60. this.t.print("TinyShell is brought to you by Theis Mackeprang.");
  61. this.t.print("You can download more plugins from <a href='http://www.5p.dk/tinyshell/' alt='TinyShell'>TinyShell's homepage</a>.", true);
  62. this.t.print();
  63. this.t.print("TinyShell comes with ABSOLUTELY NO WARRANTY, to the extent");
  64. this.t.print("permitted by applicable law.");
  65. this.t.print();
  66. this.t.print("Type 'help' to get started with TinyShell.");
  67. this.t.print();
  68. this.t.resume();
  69. }
  70. }
  71. });

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>