dynamic_http_server.anubis
5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
The Anubis Project.
A 'generic' web server automatically loading web sites.
read tools/basis.anubis
read web/multihost_http_server.anubis
read web/making_a_web_site.anubis
Since Anubis 1.13, .adm files can be loaded dynamically (see 'predefined.anubis', section 7.8).
The web server defined here automatically loads web sites whose .adm files (secondary modules)
are in a given directory. If such a secondary adm is updated, it is automatically reloaded by
the server within 5 seconds.
Each secondary adm must be of type 'Web_Site_Description' (defined in 'multihost_http_server.anubis'),
hence constructed as follows (using the tools in 'making_a_web_site.anubis'):
global define Web_Site_Description
site_name
=
...
The program 'multihost_http_server.anubis' has been enhanced so that if a requested web site is
not loaded, a default web site is served. This default web site needs just have the name "default"
among its common names. A generic default site is provided in 'default_web_site.anubis'.
The web server itself is the primary module defined by:
global define One
dynamic_http_server
(
List(String) args
).
You can pass parameters (in any order) on the command line:
parameter meaning default value
--------------------------------------------------------------------------------------------------------
-a:nnn.nnn.nnn.nnn the IP address on which the server listens 0.0.0.0 (listen on all interfaces)
-p:nnnn the port number for HTTP 80
-sp:nnnn the port number for HTTPS 443
-c:name SSL certificate common name georges
-d:directory directory for adm files my_anubis/web_site_modules
You can also modify the following definitions if you like:
define One
warn_admin
(
String message
) =
print(message+"\n").
This function is called each time the web server has a message for the administrator.
--- That's all for the public part ! ---------------------------------------------------------------------
Handling command line arguments.
define $T
get_parameter
(
List(String) args,
String -> Maybe($T) read,
$T default
) =
if args is
{
[ ] then default,
[h . t] then if read(h) is
{
failure then get_parameter(t,read,default),
success(p) then p
}
}.
define Maybe(String)
extract_String
(
String arg,
String prefix
) =
with la = length(arg),
lp = length(prefix),
if sub_string(arg,0,lp) is
{
failure then failure,
success(p) then
if p = prefix
then sub_string(arg,lp,la-lp)
else failure
}.
define Maybe(Word32)
extract_Word32
(
String arg,
String prefix
) =
if extract_String(arg,prefix) is
{
failure then failure,
success(s) then if decimal_scan(s) is
{
failure then failure,
success(n) then success(truncate_to_Word32(n))
}
}.
global define One
dynamic_http_server
(
List(String) args
) =
with
/* get command line arguments values (or default values) */
ip_addr = get_parameter(args,
(String s) |-> if extract_String(s,"-a:") is
{
failure then failure,
success(a) then ip_address(a)
},
0),
http_port = get_parameter(args,
(String s) |-> extract_Word32(s,"-p:"),
80),
https_port = get_parameter(args,
(String s) |-> extract_Word32(s,"-sp:"),
443),
ssl_cert = get_parameter(args,
(String s) |-> extract_String(s,"-c:"),
"georges"),
adm_dir = get_parameter(args,
(String s) |-> extract_String(s,"-d:"),
my_anubis_directory/"web_site_modules"/"/"),
/* start the site loader */
site_loader = make_site_loader(http_port,https_port,adm_dir,var(false),warn_admin),
warn_admin("Trying to listen on ports "+http_port+"/"+https_port+".\n");
warn_admin("Web site modules to be searched for in: "+adm_dir+"\n");
/* start the http and https servers */
if start_http_server(ip_addr,http_port,site_loader,load_denial_of_service_info) is
{
cannot_create_the_socket then warn_admin("Cannot create the http socket for listening")
cannot_bind_to_port then warn_admin("Cannot bind to port "+to_decimal(http_port))
cannot_listen_on_port then warn_admin("Cannot listen on port "+to_decimal(http_port))
ok(http_s) then
if start_https_server(ip_addr,https_port,ssl_cert,site_loader,load_denial_of_service_info) is
{
cannot_create_the_socket then warn_admin("Cannot create the https socket for listening")
cannot_bind_to_port then warn_admin("Cannot bind to port "+to_decimal(https_port))
cannot_listen_on_port then warn_admin("Cannot listen on port "+to_decimal(https_port))
ok(https_s) then
warn_admin("Servers started on "+ip_addr_to_string(ip_addr)+":"+to_decimal(http_port)+"/"+to_decimal(https_port))
}
}.