Web Server #324
Aliases: Web Server, WWW
12 verbs · 36 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
start | this none none | rxd | #324 | 9 |
do_login_command | none none none | rx | #324 | 25 |
do_get | this none this | rx | #324 | 24 |
error | none none none | rxd | #324 | 3 |
index | none none none | rxd | #324 | 1 |
server_started | this none this | rx | #324 | 1 |
look_self | this none this | rx | #324 | 8 |
authorise | none none none | rx | #324 | 22 |
GetVariable | this none this | rxd | #324 | 9 |
from64 | this none this | rx | #324 | 30 |
test | this none this | rx | #324 | 7 |
login | this none this | rx | #324 | 7 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
port | #324 | rc | #361 | 6969 |
calls | #324 | rc | #361 | {"index", "login"} |
base64 | #324 | rc | #361 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
help_msg | #324 | rc | #361 | list of 54{"Ender/Amigo's Generic Web Server", "-------------------------------------", "(For updates, e-mail ender@worfie.net)", "-------------------------------------", "This object, $httpd, contains all the verbs", "needed for the main handling of HTML requests.", "", "$webbable (Generic Webbable) contains all the", "properties and verbs for returning most actual", "HTML responses from individual objects.", "", "Operation", "---------", "Upon recieving a HTML request, this object first", "searches it's .call's property, which contains a", "list of verbs on $httpd itself which are callable.", "If the URL requested doesn't exist on $httpd, the", "server treats it as an object and attempts to call", ":_html on it.", "Eg:", " http://moo.server:port/54", "", "The Web Server will attempt to execute #54:_html.", "To this verb, it will pass two arguments. The first", "is the exact page requested, the second a list of", "headers the web browser passed to the server.", "Note the server will also try and check the page against", "corified objects (eg http://moo.server:port/$httpd)", "", "All :_html and other callable verbage should return", "valid HTML -AS A LIST-. ", " ", "The following properties are available:", " $httpd.port - The port this server listens on", " $httpd.calls - Contains a list of verbs on $httpd", " accessable directly (eg, with", " http://moo.server:port/verbname)", "", "The following verbs are available (help $httpd:verbname", "for more information on each of these):", "", " $httpd:start - Frontend to $httpd:server_started.", " Allows user to type 'start $httpd'", " $httpd:server_started - Starts the web server listening", " $httpd:do_login_command - Parses the initial client connection", " $httpd:do_get - Searches for a valid object/verb, and", " executes it (for GET requests only)", " $httpd:do_post - As above, but for POST requests", " $httpd:error - Return an error page", " $httpd:index - A wrapper to the page to use by default.", " $httpd:authorise - Used to force a player to login via WWW", " $httpd:GetVariable - Return one of the header values", " $httpd:from64 - De-Base64 encode something", ""} |
noauth | #324 | rc | #361 | 0 |
version | #324 | rc | #361 | 0.4 |
handed | #5 | rc | #361 | <clear> |
wield_msg | #5 | rc | #361 | <clear> |
unwield_msg | #5 | rc | #361 | <clear> |
size | #5 | rc | #361 | <clear> |
look_place_msg | #5 | rc | #361 | <clear> |
value | #5 | rc | #361 | <clear> |
get_msg | #5 | rc | #361 | <clear> |
drop_msg | #5 | rc | #361 | <clear> |
get_fail_msg | #5 | rc | #361 | <clear> |
junk_ok | #5 | rc | #361 | <clear> |
floats | #5 | rc | #361 | <clear> |
long_name_msg | #5 | rc | #361 | <clear> |
article | #5 | rc | #361 | <clear> |
setup_list | #5 | rc | #361 | <clear> |
health | #5 | rc | #361 | <clear> |
health_max | #5 | rc | #361 | <clear> |
min_skill | #5 | rc | #361 | <clear> |
skill | #5 | rc | #361 | <clear> |
recipe_for | #5 | rc | #361 | <clear> |
carried_msg | #5 | rc | #361 | <clear> |
aliases | #1 | rc | #361 | {"Web Server", "WWW"} |
description | #1 | rc | #361 | {"You see a small black cube, with a speaker mounted on one side, and a small power light on the top. There is one button next to the light labelled 'Stop'"} |
object_size | #1 | r | #29 | {10145, 1298434750} |
hidden_verbs | #1 | rc | #361 | <clear> |
phelp_msg | #1 | rc | #361 | <clear> |
weight | #1 | rwc | #361 | <clear> |
owner_verbs | #1 | rc | #361 | <clear> |
plural_name | #1 | rc | #361 | <clear> |
client_image | #1 | rc | #361 | <clear> |
listening | #1 | rc | #361 | <clear> |
Ancestry
Ancestors (nearest first): #5 generic thing → #1 root
Children: none
Call graph
Source
start
Referenced by
none
Source
1if ((caller != #0) && (!caller.wizard)) 2player:tell("The cube bleeps, and a female voice whispers 'Access Denied'"); 3endif 4result = this:server_started(); 5if (typeof(result) == INT) 6player:tell("The cube bleeps, and a female voice whispers 'System Online'"); 7else 8player:tell("The cube bleeps, and a female voice whispers 'System Failure'"); 9endif
do_login_command
Referenced by
none
Source
1args = $string_utils:explode(argstr, " "); 2what = args[1]; 3where = args[2]; 4if (!what) 5return; 6endif 7if ((what != "POST") && (what != "GET")) 8player:notify("501 Method Not Implimented"); 9boot_player(player); 10endif 11envirovars = ""; 12while (1) 13string = read(player); 14if (string == "") 15break; 16endif 17envirovars = (envirovars + "***") + string; 18endwhile 19if (what == "POST") 20this:do_post(args[2], envirovars); 21endif 22if (what == "GET") 23this:do_get(args[2], envirovars); 24endif 25return 0;
do_get
Referenced by
- #324:do_login_command line 23:
this:do_get
Source
1where = $string_utils:explode(args[1], "/"); 2connection = player; 3if (where[1] == E_RANGE) 4where = {"index"}; 5endif 6if (where[1] in this.calls) 7out = this:(where[1])(args[1], args[2]); 8else 9out = #0.(where[1]):_html(args[1], args[2]); 10if (typeof(out) == ERR) 11out = toobj(where[1]):_html(args[1], args[2]); 12if (out == E_VERBNF) 13out = this:error(where[1], 404); 14endif 15endif 16endif 17for line in (out) 18notify(connection, line, 1); 19$command_utils:suspend_if_needed(1); 20if (!(connection in connected_players(1))) 21return; 22endif 23endfor 24boot_player(connection);
error
Referenced by
- #324:do_get line 13:
this:error
Source
1where = args[1]; 2code = args[2]; 3return {"Server Error: ", tostr(code)};
index
Referenced by
- #324:login line 3:
$httpd:index
Source
1return $player_start:_html(@args);
server_started
Referenced by
- #324:start line 4:
this:server_started
Source
1return listen(this, this.port);
look_self
Referenced by
none
Source
1player:Tell_lines(this.description); 2for z in (listeners()) 3if (z[1] == this) 4player:tell("The power light is on."); 5return; 6endif 7endfor 8player:tell("The power light is off.");
authorise
Referenced by
- #324:test line 2:
$httpd:authorise - #324:login line 6:
$httpd:authorise
Source
1whom = #-1; 2pwd = "notvalid"; 3out = {}; 4basic = $httpd:GetVariable(args[2], "Authorization"); 5basic = basic[8..$]; 6if (basic) 7plaintext = $httpd:from64(basic); 8pwdpair = $string_utils:explode(plaintext, ":"); 9whom = $string_utils:match_player(pwdpair[1]); 10if (valid(whom)) 11pwd = crypt(pwdpair[2], whom.password); 12endif 13endif 14if (whom.password == 0) 15return whom; 16endif 17if (pwd == whom.password) 18return whom; 19endif 20out = {@out, "HTTP/1.1 401 Access Denied", "WWW-Authenticate: Basic realm=\"MOO Login\""}; 21out = {@out, "", "You must enter a valid MOO username/password to access this resource"}; 22return out;
GetVariable
Referenced by
- #324:authorise line 4:
$httpd:GetVariable
Source
1envirovars = args[1]; 2variables = $string_utils:explode(envirovars, "***"); 3for z in (variables) 4string = $string_utils:explode(z, ":"); 5if (string[1] == args[2]) 6return string[2]; 7endif 8endfor 9return "";
from64
Referenced by
- #324:authorise line 7:
$httpd:from64
Source
1"This code stolen from $math_utils:from64 @ Midgard"; 2"Thanks Marty :)"; 3":from64(STR base64-encoded input) => STR decoded output"; 4Out = {}; 5Input = args[1]; 6for I in [1..length(Input)] 7if (Input[I] != "=") 8Char = index(this.base64, Input[I], 1) - 1; 9Out = {@Out, Char}; 10endif 11if ((ticks_left() < 2000) || (seconds_left() < 2)) 12suspend(0); 13endif 14endfor 15Bin = ""; 16for I in (Out) 17Bin = Bin + $string_utils:right($math_utils:base_conversion(I, 10, 2), 6, "0"); 18if ((ticks_left() < 2000) || (seconds_left() < 2)) 19suspend(0); 20endif 21endfor 22Out = ""; 23for I in [1..length(Bin) / 8] 24Char = Bin[((I - 1) * 8) + 1..((I - 1) * 8) + 8]; 25Out = Out + $string_utils:from_ascii(tonum($math_utils:base_conversion(Char, 2, 10))); 26if ((ticks_left() < 2000) || (seconds_left() < 2)) 27suspend(0); 28endif 29endfor 30return Out;
test
Referenced by
none
Source
1"Example of authentication"; 2authorised = $httpd:authorise(@args); 3if (typeof(authorised) == LIST) 4return authorised; 5endif 6out = {("Your an OK user, " + tostr(authorised)) + " :)", "<HR>"}; 7return out;
login
Referenced by
none
Source
1if ($httpd.noauth) 2$httpd.noauth = 0; 3return $httpd:index(@args); 4else 5$httpd.noauth = 1; 6return $httpd:authorise("", ""); 7endif