File: session.xml

package info (click to toggle)
libapache2-mod-rivet 3.2.6-1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 6,384 kB
  • sloc: tcl: 8,982; xml: 8,619; ansic: 7,074; sh: 5,039; makefile: 195; sql: 91; lisp: 78
file content (463 lines) | stat: -rw-r--r-- 14,335 bytes parent folder | download | duplicates (6)
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  <section id="session_package">
    <title>Session Package</title>
    <section>
      <title>Introduction</title>
      <para>
	This is session management code.  It provides an interface
	to allow you to generate and track a browser's visit as a
	"session", giving you a unique session ID and an interface
	for storing and retrieving data for that session on the
	server.
      </para>

      <para>
	This is an alpha/beta release -- documentation is not in
	final form, but everything you need should be in this file.
      </para>

      <para>
	Using sessions and their included ability to store and
	retrieve session-related data on the server, programmers can
	generate more secure and higher-performance websites.  For
	example, hidden fields do not have to be included in forms
	(and the risk of them being manipulated by the user
	mitigated) since data that would be stored in hidden fields
	can now be stored in the session cache on the server.  Forms
	are then faster since no hidden data is transmitted --
	hidden fields must be sent twice, once in the form to the
	broswer and once in the response from it.
      </para>

      <para>
	Robust login systems, etc, can be built on top of this code.
      </para>
    </section>

    <section id="requirements">
      <title>Requirements</title>
	<para>
	  Currently has only been tested with Postgresql, MySql and Oracle.
	  All DB interfacing is done through DIO, though, so it
	  should be relatively easy to add support for other
	  databases.
	</para>
      </section>

      <section>
	<title>Preparing To Use It</title>

	<para>Create the tables in your SQL server.  With Postgres,
	  do a <command>psql www</command> or whatever DB you
	  connect as, then a backslash-i on
	  <filename>session-create.sql</filename></para>

	<para>(If you need to delete the tables, use <filename>session-drop.sql</filename>)</para>

	<para>The session code by default requires a DIO handle
	  called <varname>DIO</varname> (the name of which can be
	  overridden).  We get it by doing a</para>

	    <programlisting>RivetServerConf ChildInitScript "package require DIO"
RivetServerConf ChildInitScript "::DIO::handle Postgresql DIO -user www"</programlisting>

      </section>

      <section>
	<title>Example Usage</title>

	<para>In your httpd.conf, add:</para>

	<programlisting>RivetServerConf ChildInitScript "package require Session; Session SESSION"</programlisting>

	<para>
	  This tells Rivet you want to create a session object named
	  SESSION in every child process Apache creates.</para>

	<para>
	  You can configure the session at this point using numerous
	  key-value pairs (which are defined later in this doc).
	  Here's a quick example:</para>

	<programlisting>RivetServerConf ChildInitScript "package require Session; Session SESSION \
  -cookieLifetime 120 -debugMode 1"</programlisting>

	<para>
	  Turn debugging on <option>-debugMode 1</option> to figure
	  out what's going on -- it's really useful, if
	  verbose.</para>

	<para>
	  In your .rvt file, when you're generating the &lt;HEAD&gt;
	  section:
	</para>

	<programlisting>SESSION activate</programlisting>

	<para>
	  Activate handles everything for you with respect to
	  creating new sessions, and for locating, validating, and
	  updating existing sessions.  Activate will either locate
	  an existing session, or create a new one.  Sessions will
	  automatically be refreshed (their lifetimes extended) as
	  additional requests are received during the session, all
	  under the control of the key-value pairs controlling the
	  session object.
	</para>
      </section>

      <section>
	<title>Using Sessions From Your Code</title>

	<para>The main methods your code will use are:</para>

	<variablelist>
	  <varlistentry>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION</command> <command>id</command>
	      </cmdsynopsis>
	      <para>
		After doing a <command>SESSION activate</command>,
		this will return a 32-byte ASCII-encoded random
		hexadecimal string.  Every time this browser comes
		to us with a request within the timeout period, this
		same string will be returned (assuming they have
		cookies enabled).
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION</command>
		<command>is_new_session</command>
	      </cmdsynopsis>
	      <para>returns 1 if it's a new session or 0 if it has
		previously existed (i.e. it's a zero if this request
		represents a "return" or subsequent visit to a
		current session.)</para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION new_session_reason</command></cmdsynopsis>
	      <para>
		This will return why this request is the first
		request of a new session, either "no_cookie" saying
		the browser didn't give us a session cookie,
		"no_session" indicating we got a cookie but couldn't
		find it in our session table, or "timeout" where
		they had a cookie and we found the matching session
		but the session has timed out.
	      </para>
	    </listitem>
	  </varlistentry>
	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION store</command>
		<arg><replaceable>packageName</replaceable></arg>
		<arg><replaceable>key</replaceable></arg>
		<arg><replaceable>data</replaceable></arg>
	      </cmdsynopsis>
	      <para>
		Given the name of a package, a key, and some data.
		Stores the data in the rivet session cache table.
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION fetch</command>
		<arg><replaceable>packageName</replaceable></arg>
		<arg><replaceable>key</replaceable></arg>
	      </cmdsynopsis>
	      <para>
		Given a package name and a key, return the data
		stored by the store method, or an empty string if
		none was set.  (Status is set to the DIO error that
		occurred, it can be fetched using the status
		method.)
	      </para>
	    </listitem>
	  </varlistentry>
	</variablelist>
      </section>

      <section>
	<title>Session Configuration Options</title>

	<para>The following key-value pairs can be specified when a
	  session object (like SESSION above) is created:</para>

	<variablelist>

	  <varlistentry>
	    <term><option>sessionLifetime</option></term>

	    <listitem>
	      <para>how many seconds the session will live for.
		7200 == 2 hours
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term>sessionRefreshInterval</term>
	    <listitem>
	      <para>
		If a request is processed for a browser that
		currently has a session and this long has elapsed
		since the session update time was last updated,
		update it.  900 == 15 minutes.  so if at least 15
		minutes has elapsed and we've gotten a new request
		for a page, update the session update time,
		extending the session lifetime (sessions that are in
		use keep getting extended).
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term>cookieName</term>
	    <listitem>
	      <para></para>
	      name of the cookie stored on the user's web browser
	      default rivetSession
	    </listitem>
	  </varlistentry>

	  <varlistentry><term>dioObject</term> 
	    <listitem>
	      <para>
		The name of the DIO object we'll use to access the
		database (default DIO)
	      </para>
	    </listitem></varlistentry>

	  <varlistentry><term>gcProbability</term>
	    <listitem>
	      <para>
		The probability that garbage collection will occur
		in percent.  (default 1%, i.e. 1)</para></listitem></varlistentry>

	  <varlistentry><term>gcMaxLifetime</term>
		<listitem><para>the number of seconds after which
		data will be seen as "garbage" and cleaned up --
		defaults to 1 day (86400)</para></listitem></varlistentry>

	  <varlistentry><term>refererCheck</term>
		<listitem><para>The substring you want to check each
		HTTP referer for.  If the referer was sent by the
		browser and the substring is not found, the session
		will be deleted. (not coded yet)</para></listitem></varlistentry>

	  <varlistentry><term>entropyFile</term> <listitem><para>The
		name of a file that random binary data can be read
		from.  (<filename>/dev/urandom</filename>) Data will
		be used from this file to help generate a
		super-hard-to-guess session ID.</para></listitem></varlistentry>

	  <varlistentry><term>entropyLength</term>
		<listitem><para>The number of bytes which will be
		read from the entropy file.  If 0, the entropy file
		will not be read (default 0)</para></listitem></varlistentry>

	  <varlistentry><term>scrambleCode</term> <listitem><para>
		Set the scramble code to something unique for the
		site or your app or whatever, to slightly increase
		the unguessability of session ids (default "some
		random string")</para></listitem></varlistentry>

	  <varlistentry><term>cookieLifetime</term>
		<listitem><para>The lifetime of the cookie in
		minutes.  0 means until the browser is closed (I
		think). (default 0)</para></listitem></varlistentry>

	  <varlistentry><term>cookiePath</term> <listitem><para>The
		webserver subpath that the session cookie applies to
		(defaults to
		<filename>/</filename>)</para></listitem></varlistentry>

	  <!--varlistentry><term>cookieDomain</term>
	  <listitem><para>The domain to set in the session cookie
	  (FIXME - not coded yet)</para></listitem></varlistentry-->

	  <varlistentry><term>cookieSecure</term>
		<listitem><para>Specifies whether the cookie should
		only be sent over secure connections, 0 = any, 1 =
		secure connections only (default
		0)</para></listitem></varlistentry>

	  <varlistentry><term>sessionTable</term>
		<listitem><para>The name of the table that session
		info will be stored in (default
		<varname>rivet_session</varname>)</para></listitem></varlistentry>

	  <varlistentry><term>sessionCacheTable</term>
		<listitem><para>The name of the table that contains
		cached session data (default
		<varname>rivet_session_cache</varname>)</para></listitem></varlistentry>

	  <varlistentry><term>debugMode</term> <listitem><para>Set
		debug mode to 1 to trace through and see the session
		object do its thing (default 0)</para></listitem></varlistentry>

	  <varlistentry><term>debugFile</term> <listitem><para>The
		file handle that debugging messages will be written
		to (default
		<varname>stdout</varname>)
	      </para>
	    </listitem>
	  </varlistentry>

	</variablelist>
      </section>

      <section>
	<title>Session Methods</title>

	<para>
	  The following methods can be invoked to find out
	  information about the current session, store and fetch
	  server data identified with this session, etc:
	</para>

	<variablelist>
	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION status</command></cmdsynopsis>
	      <para>
		Return the status of the last operation
	      </para>
	    </listitem>
	  </varlistentry>


	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION id</command></cmdsynopsis>
	      <para>
		Get the session ID of the current browser.  Returns
		an empty string if there's no session (will not
		happen is SESSION activate has been issued.)
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION new_session_reason</command>
	      </cmdsynopsis>
	      <para>
		Returns the reason why there wasn't a previous
		session, either "no_cookie" saying the browser
		didn't give us a session cookie, "no_session"
		indicating we got a cookie but couldn't find it in
		the session table, or "timeout" when we had a cookie
		and a session but the session had timed out.
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION store</command>
		<arg><replaceable>packageName</replaceable></arg>
		<arg><replaceable>key</replaceable></arg>
		<arg><replaceable>data</replaceable></arg>
	      </cmdsynopsis>
	      <para>
		Given a package name, a key string, and a data
		string, store the data in the rivet session
		cache.
	      </para>
	    </listitem>
	  </varlistentry>


	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION fetch</command>
		<arg><replaceable>packageName</replaceable></arg>
		<arg><replaceable>key</replaceable></arg>
	      </cmdsynopsis>
	      <para>
		Given a package name and a key, return the data
		stored by the store method, or an empty string if
		none was set.  Status is set to the DIO error that
		occurred, it can be fetched using the status
		method.
	      </para>
	    </listitem></varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION delete</command></cmdsynopsis>

	      <para>
		Given a user ID and looking at their IP address we
		inherited from the environment (thanks, Apache),
		remove them from the session table.  (the session
		table is how the server remembers stuff about
		sessions). If the session ID was not specified the
		current session is deleted.
	      </para>
	    </listitem>
	  </varlistentry>

	  <varlistentry>
	    <term></term>
	    <listitem>
	      <cmdsynopsis>
		<command>SESSION activate</command></cmdsynopsis>

	      <para>
		Find and validate the session ID if they have one.
		If they don't have one or it isn't valid (timed out,
		etc), create a session and drop a cookie on
		them.
	      </para>
	    </listitem>
	  </varlistentry></variablelist>
      </section>

      <section>
	<title>Getting Additional Randomness From The Entropy File</title>

	<programlisting>RivetServerConf ChildInitScript "Session SESSION -entropyFile /dev/urandom \
  -entropyLength 10 -debugMode 1"</programlisting>

	<para>
	  This options say we want to get randomness from an entropy
	  file (random data pseudo-device) of /dev/urandom, to get ten
	  bytes of random data from that entropy device, and to turn
	  on debug mode, which will cause the SESSION object to output
	  all manner of debugging information as it does stuff.  This
	  has been tested on FreeBSD and appears to work.
      </para>
    </section>
  </section>