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
- $ login
Arguments
This command takes no arguments.
Example

login.php
- <?
- require("../plugin.php");
- if (is_ajax(false)) {
- switch ($_POST["action"]) {
- case 'ticket':
- die(ticket_request());
- break;
- case 'login':
- if (ticket_validate($_POST['hash'], SHELL_USERNAME.SHELL_PASSWORD)) {
- // notice you can change the ticket validation
- // to validate something else, and the still keep
- // the following to prove authorization
- $_SESSION = array();
- $_SESSION['login']['username'] = SHELL_USERNAME;
- $_SESSION['login']['password'] = SHELL_PASSWORD;
- $_SESSION['login']['IP'] = $_SERVER['REMOTE_ADDR'];
- $_SESSION['login']['UA'] = $_SERVER['HTTP_USER_AGENT'];
- die("0");
- }
- die("1");
- break;
- }
- exit;
- }
- ?>
- /**
- * Login
- **/
- TinyShell.plugins.login = new Class({
- description: "Login to TinyShell",
- username: '',
- run : function(terminal, args) {
- this.t = terminal;
- this.t.set_protocol("Login as: ").read_line(this.set_username);
- },
- set_username: function(terminal, line) {
- this.username = line;
- this.get_password();
- },
- get_password: function() {
- this.t.print("Using keyboard-interactive authentication.");
- this.t.set_protocol("Password: ", "password").read_line(this.set_password);
- },
- set_password: function(terminal, line) {
- this.password = line;
- this.t.ajax_request(this.use_ticket, "<?php echo $_AJAX_URL?>", "action=ticket");
- },
- use_ticket : function(ticket) {
- this.t.ajax_request(this.validate_auth, "<?php echo $_AJAX_URL?>", "action=login&hash="+encodeURIComponent(this.t.ticket_hash(ticket, this.username+this.password)));
- },
- validate_auth: function(response) {
- if (response != "0") {
- this.t.print("Access denied");
- this.get_password();
- } else {
- this.t.user = this.username;
- this.t.print("Login: <?=date("r")?> from <?=gethostbyaddr($_SERVER["REMOTE_ADDR"])?>");
- this.t.print();
- this.t.print("The plugins included with the TinyShell system are free software;");
- this.t.print("TinyShell is brought to you by Theis Mackeprang.");
- this.t.print("You can download more plugins from <a href='http://www.5p.dk/tinyshell/' alt='TinyShell'>TinyShell's homepage</a>.", true);
- this.t.print();
- this.t.print("TinyShell comes with ABSOLUTELY NO WARRANTY, to the extent");
- this.t.print("permitted by applicable law.");
- this.t.print();
- this.t.print("Type 'help' to get started with TinyShell.");
- this.t.print();
- this.t.resume();
- }
- }
- });