minimal_web_site_vc.anubis
8.9 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
*Project* The Anubis Project
*Title* A minimal web site.
*Copyright* Copyright © David RENÉ.
*Released*
*Author* David RENÉ
*Overview*
This file is just an example which may help to start making a web site with
Anubis Calexium Library
It was based on the example for making a minimal web site made by Alain Prouté and located
in examples/network folder in standard library example
This example is absolutely minimalist and manage only page.
read tools/basis.anubis // required for 'make_directory' and .
read system/convert.anubis
read system/logger.anubis
read calexium_lib/web/CXM_common.anubis // required for type 'Web_arg'
read calexium_lib/web/CXM_multihost_http_server.anubis // required for type 'HTTP_Info'
read calexium_lib/web/controllers_web_site.anubis
read calexium_lib/web/CXM_making_a_web_site.anubis
read web/mime.anubis // required for list of known MIME types
read calexium_lib/web/CXM_web_arg_utils.anubis
read calexium_lib/web/CXM_web_session.anubis
read calexium_lib/web/CXM_form.anubis
read calexium_lib/web/jQuery/CXM_jquery_button.anubis
*** Server directory.
A directory for putting files for all web sites. There will be one subdirectory per web
site.
public define WEB_Action_Name show_login = controller_action("root", "show_login").
public define WEB_Action_Name after_login = controller_action("root", "after_login").
define String web_sites_directory = my_anubis_directory+"/web_sites".
define HTML_Partial_Content
create_login_form
=
partial_content(
[css(css_file("css/login.css"))],
div([id("login")],
sequence([
//BODY
div([id("login_body")],
cxm_form( "login_form", [], after_login, [], [],
[
input (label(("LOGIN_NAME"), no_help), wan("login_name"), init(""), narrow, non_mandatory),
password_input(label(("PASSWORD"), no_help), wan("password"), init(""), narrow, non_mandatory),
partial(img_submit_button(("CONNECTION"), "login_form" ))
])
),
])
)).
define WEB_Controller_Result
show_login
(
WEB_Session _session
)=
http_answer(
html_page
(
"Example Site 1", // title of web site
[], // list of 'META' tags (empty for this site)
body // body of page
(
// list of body options
[
background_color(rgb(255,200,200))
// add more body options here
],
// content of page
partial(create_login_form)
)
))
.
define WEB_Controller_Result
after_login
(
WEB_Session _session
)=
with lwa = *_session.web_request.lwa,
http_answer(
html_page
(
"Example Site 1", // title of web site
[], // list of 'META' tags (empty for this site)
body // body of page
(
// list of body options
[
background_color(rgb(255,200,200))
// add more body options here
],
// content of the page
div([center(text("This is the 'Example 1' web site.")), br,
text("Login from :")])
)
))
.
define List(WEB_Action)
root_controller_actions
=
[
web_action(show_login, http_https, (WEB_Session _session) |-> true, show_login),
web_action(after_login, http_https, (WEB_Session _session) |-> true, after_login),
].
define WEB_Controller
make_root_controller
=
web_controller("root", var(root_controller_actions))
.
Making the description of web site 1. In this description, several elements are the
bare minimum. There is no action at all, no data base, almost nothing. See
'web/making_a_web_site.anubis' for the declaration of the function
'make_web_site_description'.
define Web_Site
example_site_1
=
// make the directory for web site 1
// (subdirectories of it will be created automatically by the HTTP server)
forget((String)make_directory(web_sites_directory+"/example_site_1"));
// make a list of all possible 'host names' for web site 1:
with addresses = (List(String))
[
"example-site-1",
"127.0.0.1",
"192.168.0.1"
// add more adresses here
],
// now make the description of the web site
make_web_site_controller_description(
//this is the unique ID of the web site. This ID will be use for prepend the cookies
//names belonging to that web site
"example",
// the list of addresses defined above
addresses,
// directory for the files of web site 1
web_sites_directory+"/example_site_1",
// directory for the states of that web_site
web_sites_directory+"/example_site_1/states",
// initializing function
(One u) |-> u, // nothing to initialize for web site 1
// the function producing the initial session
(HTTP_Info info,
Var(List(Web_arg)) lwa,
Bool is_https) |-> web_session(get_new_session_id, "en", empty_fields_list, web_request(info, var([web_arg("aws_c","root"), web_arg("aws_a", "show_login")]), is_https), web_request(info, lwa, is_https), web_request(info, lwa, is_https)), //
// the function for handling expired tickets
// (tickets are kept on the server's disk and represent states. They are used for
// passing session informations from pages to pages. See
// 'web/CXM_making_a_web_site.anubis' for detailed explanations.)
(WEB_Session expired,
HTTP_Info info,
Var(List(Web_arg)) lwa,
Bool is_https) |-> expired, // keep the same session
var([make_root_controller]), //controllers
var([]), //desktop renderer
var([]), //list of plugins
// the function for producing additional HTTP headers depending of the session
(Maybe(WEB_Session) session) |-> [],
//function for adding constant additional headers
[],
// timeout for tickets (in seconds)
3600, // does'nt matter since only one state
// list of redirections (one for each address)
// (see 'web/CXM_common.anubis' for the type 'Redirection')
redirection_list(map((String address) |-> redirect("/",address,"/index.awp"), addresses)),
// character encoding for web site 1
"UTF-8",
// list of URI extensions producing a console/journal message
[
".awp", // pages computed by this program
".jpg", // images, etc...
".gif",
".png"
// add more extensions here (they must be known; see 'web/mime.anubis')
],
// list of HTTP headers which are traced in the console/journal messages
[
"host",
"user-agent"
// add more HTTP headers here
],
(LogLevel level, String txt) |-> println(txt), //logger. Here is minimal logger which make only print
// secret string (used by 'private download')
"HUD76GRD56FD7GFDS4RT", // for a real site, please choose another one
// it must remain secret
// list of known MIME types (taken from 'web/mime.anubis')
known_mime_types,
// action to be performed before a file is sent
// (for example, this may be used for counting downloads)
(String action_name,
List(Web_arg) lwa) |-> unique // no action at all
)
.
*** Example site 2.
Imagine another web site here...
*** Starting all our web sites together.
global define One
minimal_web_site_vc
(
List(String) args
) =
// make the directory for all web sites (if needed)
forget((String) make_directory(web_sites_directory));
with http_port = (Word32)80,
https_port = (Word32)443,
// create a variable for handling the shutdown of our web sites
with shutdown_required = var(false),
with is_shutdown = (One u) |-> *shutdown_required,
// start all web sites
if start_web_sites(
0, // listen on all IP addresses
http_port, // port for HTTP
https_port, // port for HTTPS
"www.georges.example.com", // common name of SSL certificate
[
example_site_1
// add other web sites here
],
is_shutdown) is
{
cannot_bind_to_port(n) then println("Cannot bind to port: "+n),
cannot_bind_to_port(n,m) then println("Cannot bind to ports: "+n+", "+m),
ok(s1,s2) then println("Servers started on ports "+http_port+" (HTTP) and "+https_port+" (HTTPS).")
}
.