Network Utilities #72
Aliases: Network Utilities
25 verbs · 27 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
parse_address | this none this | rxd | #72 | 6 |
local_domain | this none this | rxd | #72 | 28 |
open | this none this | rxd | #72 | 24 |
close | this none this | rxd | #72 | 12 |
sendmail | any none none | rxd | #72 | 17 |
trust | this none this | rxd | #72 | 1 |
init_for_core | this none this | rxd | #72 | 17 |
raw_sendmail | any none none | rxd | #72 | 69 |
invalid_email_address | this none this | rxd | #72 | 20 |
invalid_hostname | this none this | rxd | #72 | 1 |
email_will_fail | this none this | rxd | #72 | 29 |
read | this none this | rxd | #72 | 10 |
is_open | this none this | rxd | #72 | 4 |
incoming_connection | this none this | rxd | #72 | 17 |
return_address_for | this none this | rxd | #72 | 7 |
server_started | this none this | rxd | #72 | 5 |
is_outgoing_connection | this none this | rxd | #72 | 1 |
notify | this none this | rxd | #72 | 9 |
suspend_if_needed | this none this | rxd | #72 | 5 |
error | this none this | rxd | #72 | 11 |
help_msg | this none this | rxd | #72 | 2 |
adjust_postmaster_for_password | this none this | rxd | #72 | 10 |
add_queued_mail | this none this | rxd | #72 | 14 |
send_queued_mail | this none this | rxd | #72 | 11 |
tcp_wait | this none this | rxd | #72 | 18 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
site | #72 | r | #2 | "yoursite" |
large_domains | #72 | r | #2 | {} |
connect_connections_to | #72 | | #2 | {} |
postmaster | #72 | rc | #2 | "postmastername@yourhost" |
port | #72 | rc | #2 | 7777 |
MOO_name | #72 | rc | #2 | "YourMOO" |
valid_host_regexp | #72 | rc | #2 | "^%([-_a-z0-9]+%.%)+%(gov%|edu%|com%|org%|int%|mil%|net%|%nato%|arpa%|[a-z][a-z]%)$" |
maildrop | #72 | rc | #2 | "localhost" |
trusts | #72 | r | #2 | {#36} |
reply_address | #72 | rc | #2 | "moomailreplyto@yourhost" |
active | #72 | rc | #2 | 0 |
valid_email_regexp | #72 | rc | #2 | "^[-a-z0-9_!.%+$'=/]*[-a-z0-9_!%+$'=]$" |
invalid_userids | #72 | rc | #2 | {"", "sysadmin", "root", "postmaster", "system", "operator", "bin"} |
debugging | #72 | rc | #2 | 0 |
errors_to_address | #72 | rc | #2 | "moomailerrors@yourhost" |
suspicious_userids | #72 | rc | #2 | list of 12{"", "sysadmin", "root", "postmaster", "bin", "SYSTEM", "OPERATOR", "guest", "me", "mailer-daemon", "webmaster", "sysop"} |
usual_postmaster | #72 | rc | #2 | "postmastername@yourhost" |
password_postmaster | #72 | rc | #2 | "postmastername@yourhost" |
queued_mail | #72 | | #36 | list of 1{{-1165412055, {"grhager@zubi.com", "Date: Thu Mar 4 16:54:01 1999 ", "From: 2@beel.wskcc.com (Wizard)", "To: grhager@zubi.com", "Subject: Your nefandous character, Titus_Crowe", "Errors-to: moomailerrors@yourhost", "X-Mail-Agent: nefandous (beel.wskcc.com 5050)", "Reply-to: ", "From Wizard@nefandous:", "A character has been created, with name \"Titus_Crowe\" and password \"veNyz\".", "Passwords are case sensitive, which means you have to type it exactly as", "it appears here, including capital and lowercase letters.", "So, to log in, you would type:", " Connect Titus_Crowe veNyz"}}} |
queued_mail_task | #72 | r | #36 | 68853779 |
envelope_from | #72 | rc | #2 | "postmastername@yourhost" |
blank_envelope | #72 | rc | #2 | 0 |
key | #1 | c | #2 | 0 |
aliases | #1 | rc | #2 | {"Network Utilities"} |
description | #1 | rc | #2 | list of 74{"Utilities for dealing with network connections", "---------------", "Creating & tracking hosts:", "", ":open(host, port [, connect-connection-to]) => connection", " open a network connection (using open_network_connection).", " If 'connect-connection-to' is a player object, the", " connection will be connected to that object when it", " gets the first line of input.", "", ":close(connection)", " closes the connection & cleans up data", "", "------------------", "Parsing network things:", "", ":invalid_email_address(email)", " return \"\" or string saying why 'email' is invalid.", " uses .valid_email_regexp", "", ":invalid_hostname(host)", " return \"\" or string saying why 'host' doesn't look", " like a valid internet host name", "", ":local_domain(host)", " returns the 'important' part of a host name, e.g.", " golden.parc.xerox.com => parc.xerox.com", "", "-------------------", "Sending mail", "", ":sendmail(to, subject, @lines)", " send mail to the email address 'to' with indicated subject.", " header fields like 'from', 'date', etc. are filled in.", " lines can start with additional header lines.", "", ":raw_sendmail(to, @lines)", " used by :sendmail. Send mail to given user at host, just", " as specified, no error checking.", "", "================================================================", "Parameters:", "", ".active If 0, disabled sending of mail.", "", ".site Where does this MOO run?", " (Maybe MOOnet will use it later).", "", ".port The network port this MOO listens on.", "", ".large_domains ", " A list of sites where more than 2 levels of host name are", " significant, e.g., if you want 'parc.xerox.com' to be", " different than 'cinops.xerox.com', put \"xerox.com\" as an", " element in .large_domains.", "", ".postmaster", " Email address to which problems with MOO mail should", " go. This should be a real email address that someone reads.", "", ".maildrop", " Hostname to connect to for dropping off mail. Usually can", " just be \"localhost\".", "", ".reply_address", " If a MOO character sends email, where does a reply go?", " Inserted in 'From:' for mail from characters without", " registration addresses. ", "", ".trusts", " List of (non-wizard) programmers who can call", " :open, :sendmail, :close", "", " "} |
object_size | #1 | r | #36 | {26956, -1090650497} |
html | #1 | rc | #2 | <clear> |
Ancestry
Ancestors (nearest first): #1 Root Class
Children: none
Call graph
Source
parse_address
Referenced by
- #16:suspicious_address line 16:
$network:parse_address - #24:check_player_request line 42:
$network:parse_address - #72:email_will_fail line 17:
this:parse_address - #72:email_will_fail line 19:
this:parse_address
Source
1"Given an email address, return {userid, site}."; 2"Valid addresses are of the form `userid[@site]'."; 3"At least for now, if [@site] is left out, site will be returned as blank."; 4"Should be a default address site, or something, somewhere."; 5address = args[1]; 6return (at = index(address, "@")) ? {address[1..at - 1], address[at + 1..$]} | {address, ""};
local_domain
Referenced by
- #16:suspicious_address line 21:
$network:local_domain - #24:check_player_request line 52:
$network:local_domain - #24:check_player_request line 52:
$network:local_domain
Source
1"given a site, try to figure out what the `local' domain is."; 2"if site has a @ or a % in it, give up and return E_INVARG."; 3"blank site is returned as is; try this:local_domain(this.localhost) for the answer you probably want."; 4site = args[1]; 5if (index(site, "@") || index(site, "%")) 6return E_INVARG; 7elseif (match(site, "^[0-9.]+$")) 8return E_INVARG; 9elseif (!site) 10return ""; 11elseif (!(dot = rindex(site, "."))) 12dot = rindex(site = this.site, "."); 13endif 14if ((!dot) || (!(dot = rindex(site[1..dot - 1], ".")))) 15return site; 16else 17domain = site[dot + 1..$]; 18site = site[1..dot - 1]; 19while (site && (domain in this.large_domains)) 20if (dot = rindex(site, ".")) 21domain = tostr(site[dot + 1..$], ".", domain); 22site = site[1..dot - 1]; 23else 24return tostr(site, ".", domain); 25endif 26endwhile 27return domain; 28endif
open
Referenced by
- #72:raw_sendmail line 33:
$network:open - #75:get_now line 14:
$network:open - #75:show_text line 7:
$network:open - #87:open line 5:
$network:open - #87:open_data line 13:
$network:open
Source
1":open(address, port, [connect-connection-to])"; 2"Open a network connection to address/port. If the connect-connection-to is passed, then the connection will be connected to that object when $login gets ahold of it. If not, then the connection is just ignored by $login, i.e. not bothered by it with $welcome_message etc."; 3"The object specified by connect-connection-to has to be a player (though it need not be a $player)."; 4"Returns the (initial) connection or an error, as in open_network_connection"; 5if (!this:trust(caller_perms())) 6return E_PERM; 7endif 8address = args[1]; 9port = args[2]; 10if (length(args) < 3) 11connect_to = $nothing; 12elseif ((typeof(connect_to = args[3]) == OBJ) && (valid(connect_to) && is_player(connect_to))) 13if (!$perm_utils:controls(caller_perms(), connect_to)) 14return E_PERM; 15endif 16else 17return E_INVARG; 18endif 19if (typeof(connection = `open_network_connection(address, port) ! ANY') != ERR) 20if (valid(connect_to)) 21this.connect_connections_to = {@this.connect_connections_to, {connection, connect_to}}; 22endif 23endif 24return connection;
close
Referenced by
- #72:raw_sendmail line 67:
$network:close - #75:get_now line 35:
$network:close - #75:show_text line 30:
$network:close - #87:open line 12:
$network:close - #87:close line 8:
$network:close - #87:close line 10:
$network:close - #87:close_data line 8:
$network:close
Source
1if (!this:trust(caller_perms())) 2return E_PERM; 3endif 4con = args[1]; 5if (!index(`connection_name(con) ! ANY => ""', " to ")) 6return E_INVARG; 7endif 8boot_player(con); 9if (i = $list_utils:iassoc(con, $network.connect_connections_to)) 10$network.connect_connections_to = listdelete($network.connect_connections_to, i); 11endif 12return 1;
sendmail
Referenced by
- #6:@registerme line 45:
$network:sendmail - #9:mailme line 15:
$network:sendmail - #24:send_new_player_mail line 12:
$network:sendmail - #24:do_new_password line 26:
$network:sendmail - #40:send_self_netmail line 15:
$network:sendmail - #45:expire_old_messages line 14:
$network:sendmail - #45:@register line 34:
$network:sendmail
Source
1"sendmail(to, subject, line1, line2, ...)"; 2" sends mail to internet address 'to', with given subject."; 3" It fills in various fields, such as date, from (from player), etc."; 4" the rest of the arguments are remaining lines of the message, and may begin with additional header fields."; 5" (must match RFC822 specification)."; 6"Requires $network.trust to call (no anonymous mail from MOO)."; 7"Returns 0 if successful, or else error condition or string saying why not."; 8if (!this:trust(caller_perms())) 9return E_PERM; 10endif 11mooname = this.MOO_name; 12mooinfo = tostr(mooname, " (", this.site, " ", this.port, ")"); 13if (reason = this:invalid_email_address(to = args[1])) 14return reason; 15endif 16"took out Envelope-from: + this.errors_to_address"; 17return this:raw_sendmail(to, "Date: " + ctime(), "From: " + this:return_address_for(player), "To: " + to, "Subject: " + args[2], "Errors-to: " + this.errors_to_address, "X-Mail-Agent: " + mooinfo, @args[3..$]);
trust
Referenced by
- #72:open line 5:
this:trust - #72:close line 1:
this:trust - #72:sendmail line 8:
this:trust - #72:read line 2:
this:trust - #72:notify line 2:
this:trust
Source
1return (who = args[1]).wizard || (who in this.trusts);
init_for_core
Referenced by
none
Source
1if (caller_perms().wizard) 2pass(@args); 3this.active = 0; 4this.errors_to_address = "moomailerrors@yourhost"; 5this.site = "yoursite"; 6this.postmaster = "postmastername@yourhost"; 7this.usual_postmaster = "postmastername@yourhost"; 8this.password_postmaster = "postmastername@yourhost"; 9this.envelope_from = "postmastername@yourhost"; 10this.blank_envelope = 0; 11this.MOO_name = "YourMOO"; 12this.maildrop = "localhost"; 13this.port = 7777; 14this.large_domains = {}; 15this.trusts = {$hacker}; 16this.connect_connections_to = {}; 17endif
raw_sendmail
Referenced by
- #72:sendmail line 17:
this:raw_sendmail - #72:send_queued_mail line 5:
this:raw_sendmail
Source
1"Copied from sendmail fix (#88079):raw_sendmail by Lineman (#108318) Mon Feb 1 19:29:43 1999 PST"; 2"rawsendmail(to, @lines)"; 3"sends mail without processing. Returns 0 if successful, or else reason why not."; 4if (!caller_perms().wizard) 5return E_PERM; 6endif 7if (!this.active) 8return "Networking is disabled."; 9endif 10if (typeof(this.debugging) == LIST) 11"who to notify"; 12debugging = this.debugging; 13else 14"notify this owner"; 15debugging = this.debugging && {this.owner}; 16endif 17address = args[1]; 18body = listdelete(args, 1); 19data = {"HELO " + this.site, ("MAIL FROM:<" + this.postmaster) + ">", ("RCPT TO:<" + address) + ">", "DATA"}; 20blank = 0; 21for x in (body) 22this:suspend_if_needed(0); 23if (!(blank || match(x, "[a-z0-9-]*: "))) 24if (x) 25data = {@data, ""}; 26endif 27blank = 1; 28endif 29data = {@data, (x && (x[1] == ".")) ? "." + x | x}; 30endfor 31data = {@data, ".", "QUIT", ""}; 32suspend(0); 33target = $network:open(this.maildrop, 25); 34if (typeof(target) == ERR) 35return tostr("Cannot open connection to maildrop ", this.maildrop, ": ", target); 36endif 37set_connection_option(target, "hold-input", 1); 38blast = 0; 39msg = 0; 40expects = {"220", "250", "250", "250%|251", "354", "250", "221"}; 41for line in (data) 42if (!blast) 43reply = this:tcp_wait(target); 44if (typeof(reply) == ERR) 45msg = "Connection dropped or timed out."; 46break; 47elseif (!match(reply[1..3], expects[1])) 48msg = (("Expected " + expects[1]) + " but got ") + reply; 49break; 50endif 51debugging && notify(debugging[1], "GET: " + reply); 52expects[1..1] = {}; 53if (reply[1..3] == "221") 54"Service closing transmission channel"; 55break; 56elseif (reply[1..3] == "354") 57"Start mail input; end with <CRLF>.<CRLF>"; 58blast = 1; 59endif 60elseif (line == ".") 61blast = 0; 62endif 63debugging && notify(debugging[1], "SEND:" + line); 64notify(target, line); 65((ticks_left() < 4000) || (seconds_left() < 2)) && suspend(0); 66endfor 67$network:close(target); 68debugging && notify(debugging[1], "EXIT:" + (msg || "Mail sent successfully.")); 69return msg;
invalid_email_address
Referenced by
- #24:check_player_request line 39:
$network:invalid_email_address - #24:do_register line 16:
$network:invalid_email_address - #40:send_self_netmail line 5:
$network:invalid_email_address - #45:@register line 28:
$network:invalid_email_address - #72:sendmail line 13:
this:invalid_email_address - #72:email_will_fail line 3:
this:invalid_email_address
Source
1"invalid_email_address(email) -- check to see if email looks like a valid email address. Return reason why not."; 2address = args[1]; 3if (!address) 4return "no email address supplied"; 5endif 6if (!(at = rindex(address, "@"))) 7return ("'" + address) + "' doesn't look like a valid internet email address"; 8endif 9name = address[1..at - 1]; 10host = address[at + 1..$]; 11if (match(name, "^in%%") || match(name, "^smtp%%")) 12return tostr("'", name, "' doesn't look like a valid username (try removing the 'in%' or 'smtp%')"); 13endif 14if (!match(host, $network.valid_host_regexp)) 15return tostr("'", host, "' doesn't look like a valid internet host"); 16endif 17if (!match(name, $network.valid_email_regexp)) 18return tostr("'", name, "' doesn't look like a valid user name for internet mail"); 19endif 20return "";
invalid_hostname
Referenced by
none
Source
1return match(args[1], this.valid_host_regexp) ? "" | tostr("'", args[1], "' doesn't look like a valid internet host name");
email_will_fail
Referenced by
- #40:@netforw*ard line 7:
$network:email_will_fail - #65:check_netmail line 8:
$network:email_will_fail
Source
1":email_will_fail(email-address[, display?]) => Makes sure the email-address is one that can actually be used by $network:sendmail()."; 2{email, ?display = 0} = args; 3reason = this:invalid_email_address(email); 4if (reason && display) 5player:tell("Invalid email address: ", reason); 6endif 7return reason; 8"following is code from OpalMOO, not used here"; 9"Possible situations where the address would be unusable are when the address is invalid or we can't connect to the site to send mail."; 10"If <display> is true, error messages are displayed to the player and 1 is returned when address is unuable. If <display> is false and address is unusable, the error message is returned. If the address is usable, 0 is always returned."; 11if (!this:approved_for_network(caller_perms())) 12return E_PERM; 13endif 14if (!this:valid_email_address(email)) 15msg = tostr("Your email address (", email, ") is not a usable account."); 16elseif ((result = this:verify_email_address(email)) == E_INVARG) 17msg = tostr("Unable to connect to ", this:parse_address(email)[2], "."); 18elseif (typeof(result) == STR) 19msg = tostr("The site ", (parse = this:parse_address(email))[2], " does not recognize ", parse[1], " as a valid account."); 20else 21return 0; 22endif 23if (display) 24player:tell(msg); 25return 1; 26else 27return msg; 28endif 29"Last modified Tue Jun 15 00:19:01 1993 EDT by Ranma (#200).";
read
Referenced by
- #87:wait_for_response line 9:
$network:read
Source
1"for trusted players, they can read from objects they own or open connections"; 2if (!this:trust(caller_perms())) 3return E_PERM; 4elseif (valid(x = args[1])) 5if ((x.owner == x) || (x.owner != caller_perms())) 6return E_INVARG; 7endif 8"elseif (!this:is_outgoing_connection(x) return E_PERM"; 9endif 10return `read(@args) ! ANY';
is_open
Referenced by
- #87:close line 9:
$network:is_open - #87:open_data line 6:
$network:is_open - #87:put_data line 7:
$network:is_open - #87:close_data line 5:
$network:is_open
Source
1":is_open(object)"; 2"return true if the object is somehow connected, false otherwise."; 3return typeof(`idle_seconds(@args) ! ANY') == INT; 4"Relies on test in idle_seconds, and the error catching";
incoming_connection
Referenced by
- #0:do_login_command line 5:
$network:incoming_connection
Source
1"Peer at an incoming connection. Decide if it should be connected to something, return that object. If it should be ignored (outbound connection), return 1. Called only by #0:do_login_command"; 2if (caller != #0) 3return; 4endif 5what = args[1]; 6"this code for unix servers >= 1.7.5 only"; 7if (index(`connection_name(what) ! ANY => ""', " to ")) 8"outbound connection"; 9if (ct = $list_utils:assoc(what, this.connect_connections_to)) 10this.connect_connections_to = setremove(this.connect_connections_to, ct); 11return ct[2]; 12else 13return 1; 14endif 15else 16return 0; 17endif
return_address_for
Referenced by
- #72:sendmail line 17:
this:return_address_for
Source
1":return_address_for(player) => string of 'return address'. Currently inbound mail doesn't work, so this is a bogus address."; 2who = args[1]; 3if (valid(who) && is_player(who)) 4return tostr(toint(who), "@", this.site, " (", who.name, ")"); 5else 6return tostr($login.registration_address, " (non-player ", who, ")"); 7endif
server_started
Referenced by
- #0:server_started line 3:
$network:server_started
Source
1"called when restarting to clean out state."; 2if (caller != #0) 3return E_PERM; 4endif 5this.connect_connections_to = {};
is_outgoing_connection
Referenced by
- #72:notify line 6:
this:is_outgoing_connection
Source
1return index(`connection_name(args[1]) ! ANY => ""', " to ");
notify
Referenced by
- #87:do_command line 5:
$network:notify
Source
1"for trusted players, they can write to connections"; 2if (!this:trust(caller_perms())) 3return E_PERM; 4elseif (valid(x = args[1])) 5return E_INVARG; 6elseif (!this:is_outgoing_connection(x)) 7return E_PERM; 8endif 9return notify(x, args[2]);
suspend_if_needed
Referenced by
- #72:raw_sendmail line 22:
this:suspend_if_needed
Source
1"$command_utils:suspend_if_needed but chowned to player"; 2if ($command_utils:running_out_of_time()) 3set_task_perms(caller_perms().wizard ? player | caller_perms()); 4return $command_utils:suspend_if_needed(@args); 5endif
error
Referenced by
none
Source
1":error(ERN, host, port) interpret open_network_connection(host, port) error"; 2{msg, host, port} = args; 3if (msg == E_PERM) 4return "Networking not enabled in server, or else user doesn't have permission to call o_n_c();"; 5elseif (msg == E_INVARG) 6return tostr("The host/port ", toliteral(host), "/", toliteral(port), " is invalid or is not responding."); 7elseif (msg == E_QUOTA) 8return tostr("The connection to ", toliteral(host), "/", toliteral(port), " cannot be made at this time."); 9else 10return tostr("Unusual error: ", toliteral(msg)); 11endif
help_msg
Referenced by
none
Source
1"'cause this doesn't have a $_utils name"; 2return this:description();
adjust_postmaster_for_password
Referenced by
- #24:do_new_password line 25:
$network:adjust_postmaster_for_password - #24:do_new_password line 31:
$network:adjust_postmaster_for_password
Source
1"adjust_postmaster_for_password(enter_or_exit): permits the MOO to have two different postmasters for different kinds of bounces. If entering password (argument \"enter\"), change to $network.password_postmaster, else (argument \"exit\") change to $network.usual_postmaster."; 2if (args[1] == "enter") 3$network.postmaster = $network.password_postmaster; 4$network.errors_to_address = $network.password_postmaster; 5$network.envelope_from = $network.password_postmaster; 6else 7$network.postmaster = $network.usual_postmaster; 8$network.errors_to_address = $network.usual_postmaster; 9$network.envelope_from = $network.blank_envelope ? "" | $network.usual_postmaster; 10endif
add_queued_mail
Referenced by
none
Source
1"$network:add_queued_mail( mail message )"; 2" -- where `mail message' is in the same format as passed to :raw_sendmail"; 3if (caller == this) 4this.queued_mail = {@this.queued_mail, {time(), args}}; 5if (!$code_utils:task_valid(this.queued_mail_task)) 6fork fid (3600) 7this:send_queued_mail(); 8endfork 9this.queued_mail_task = fid; 10endif 11return 1; 12else 13return E_PERM; 14endif
send_queued_mail
Referenced by
- #72:add_queued_mail line 7:
this:send_queued_mail
Source
1"$network:send_queued_mail()"; 2" -- tries to send the mail stored in the .queued_mail property"; 3while (queued_mail = this.queued_mail) 4message = queued_mail[1]; 5if (!this:raw_sendmail(@message[2])) 6this.queued_mail = setremove(this.queued_mail, message); 7else 8"wait an hour"; 9suspend(3600); 10endif 11endwhile
tcp_wait
Referenced by
- #72:raw_sendmail line 43:
this:tcp_wait
Source
1"Copied from sendmail fix (#88079):tcp_wait by Lineman (#108318) Mon Feb 1 19:28:18 1999 PST"; 2{conn, ?timeout = 0} = args; 3if (!caller_perms().wizard) 4return E_PERM; 5elseif (timeout) 6fork task (timeout) 7boot_player(conn); 8endfork 9endif 10while (1) 11if (typeof(line = `read(conn) ! ANY') == ERR) 12break; 13elseif (match(line, "^[0-9][0-9][0-9] ")) 14timeout && `kill_task(task) ! ANY'; 15break; 16endif 17endwhile 18return line;