Web Server #324

Parent #5Owner #361Flags readSource hellcore/hellcore.db

Aliases: Web Server, WWW

12 verbs · 36 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
startthis none nonerxd#3249
do_login_commandnone none nonerx#32425
do_getthis none thisrx#32424
errornone none nonerxd#3243
indexnone none nonerxd#3241
server_startedthis none thisrx#3241
look_selfthis none thisrx#3248
authorisenone none nonerx#32422
GetVariablethis none thisrxd#3249
from64this none thisrx#32430
testthis none thisrx#3247
loginthis none thisrx#3247

Properties

PropertyDefinerFlagsOwnerValue
port#324rc#3616969
calls#324rc#361{"index", "login"}
base64#324rc#361"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
help_msg#324rc#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#324rc#3610
version#324rc#3610.4
handed#5rc#361<clear>
wield_msg#5rc#361<clear>
unwield_msg#5rc#361<clear>
size#5rc#361<clear>
look_place_msg#5rc#361<clear>
value#5rc#361<clear>
get_msg#5rc#361<clear>
drop_msg#5rc#361<clear>
get_fail_msg#5rc#361<clear>
junk_ok#5rc#361<clear>
floats#5rc#361<clear>
long_name_msg#5rc#361<clear>
article#5rc#361<clear>
setup_list#5rc#361<clear>
health#5rc#361<clear>
health_max#5rc#361<clear>
min_skill#5rc#361<clear>
skill#5rc#361<clear>
recipe_for#5rc#361<clear>
carried_msg#5rc#361<clear>
aliases#1rc#361{"Web Server", "WWW"}
description#1rc#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#1r#29{10145, 1298434750}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rwc#361<clear>
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #5 generic thing#1 root

Children: none

Call graph

calls n324_0 #324:start n107_43 #107:tell n324_0->n107_43 n324_5 #324:server_started n324_0->n324_5 n324_1 #324:do_login_command n20_38 #20:explode n324_1->n20_38 n6_9 #6:notify n324_1->n6_9 n324_2 #324:do_get n324_1->n324_2 n324_2->n20_38 n324_3 #324:error n324_2->n324_3 n48_8 #48:suspend_if_needed n324_2->n48_8 n324_4 #324:index n1_44 #1:_www n324_4->n1_44 n324_6 #324:look_self n324_6->n107_43 n1_11 #1:tell_lines n324_6->n1_11 n324_7 #324:authorise n324_7->n20_38 n324_8 #324:GetVariable n324_7->n324_8 n324_9 #324:from64 n324_7->n324_9 n20_20 #20:match_player n324_7->n20_20 n324_8->n20_38 n20_2 #20:right n324_9->n20_2 n18_27 #18:base_conversion n324_9->n18_27 n20_64 #20:from_ASCII n324_9->n20_64 n324_10 #324:test n324_10->n324_7 n324_11 #324:login n324_11->n324_4 n324_11->n324_7

Source

start

Spec this none noneFlags rxdOwner #361Definer #324

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

Spec none none noneFlags rxOwner #361Definer #324

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

Spec this none thisFlags rxOwner #361Definer #324

Referenced by

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

Spec none none noneFlags rxdOwner #361Definer #324

Referenced by

Source

1where = args[1];
2code = args[2];
3return {"Server Error: ", tostr(code)};

index

Spec none none noneFlags rxdOwner #361Definer #324

Referenced by

Source

1return $player_start:_html(@args);

server_started

Spec this none thisFlags rxOwner #361Definer #324

Referenced by

Source

1return listen(this, this.port);

look_self

Spec this none thisFlags rxOwner #361Definer #324

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

Spec none none noneFlags rxOwner #361Definer #324

Referenced by

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

Spec this none thisFlags rxdOwner #361Definer #324

Referenced by

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

Spec this none thisFlags rxOwner #361Definer #324

Referenced by

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

Spec this none thisFlags rxOwner #361Definer #324

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

Spec this none thisFlags rxOwner #361Definer #324

Referenced by

none

Source

1if ($httpd.noauth)
2$httpd.noauth = 0;
3return $httpd:index(@args);
4else
5$httpd.noauth = 1;
6return $httpd:authorise("", "");
7endif