util  Check-in [e82124aeb7]

Overview
Comment:updates
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e82124aeb7366f10622ff5431f4b81019e873a2ad2afee35a1ea515c98c7e701
User & Date: lexi on 2019-07-29 06:11:18
Other Links: manifest | tags
Context
2019-07-29
06:11
add fabulist stylesheet check-in: 689acafd82 user: lexi tags: trunk
06:11
updates check-in: e82124aeb7 user: lexi tags: trunk
2019-07-28
12:40
add fabulist collaborative interaction fiction server (keeping it here until it gets its own repo) check-in: 9259bf507d user: lexi tags: trunk
Changes

Modified fabulist.scm from [e734573397] to [189c348a0b].

4
5
6
7
8
9
10







11
12
13
14
15
16
17
..
79
80
81
82
83
84
85
86



87
88
89
90
91
92
93
94
...
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
...
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
(import (chicken tcp)
		(chicken pretty-print)
		(chicken io)
		(chicken string)
		(chicken bitwise)
		(chicken random))








(tcp-read-timeout 300)

(define-record db (setter stories) (setter pages))
(define-record story title genre
			   desc key start)
(define-record page link story body choices)
(define *database* (make-db '() '()))
................................................................................
(define-record netstr sz val rest)
(define-record netreq body method path
			   query origin accept
			   ref ua)

(define (netreq-post-params req) (map (cut string-split <> "=")
								 (string-split (netreq-body req) "&")))
(define (post-field arr p) (let ((v (assoc p arr)))



							 (if (eq? #f v) "" (url-decode (cadr v)))))
(define (alist->netreq al body)
  (define (method->symbol m) (cond [(equal? m "GET") 'get]
								   [(equal? m "POST") 'post]
								   [(equal? m "PUT") 'put]
								   [else 'unknown]))
  (define (field key) 
	(let ((result (assoc key al)))
................................................................................
								   final-text)])
	  response)))


(define (get-new-story req) 0)

(define (get-stylesheet req)
  (define style #<<_END_
	body {
	background: #370017;
	color: #FFE1ED;
	max-width: 35em;
	padding: 1em;
	margin: auto;
	font-family: Alegreya, Junicode, GaramondNo8, "Garamond Premier Pro", "Adobe Garamond", Garamond, serif;
	font-size: 15pt;
	}
	input, textarea {
	font-family: Alegreya, Junicode, GaramondNo8, "Garamond Premier Pro", "Adobe Garamond", Garamond, serif;
	font-size: 14pt;
	border: 1px solid #FF4C96;
	background: #610028;
	color: white;
	padding: 0.3em;
	flex-grow: 2;
	text-shadow: 0 0 10px #E84B8C;
	}
	code {
	font-family: Inconsolata, Monaco, monocode;
	padding: 0.2em 0.3em;
	background: #740C38;
	border: 1px solid #260010;
	}
	textarea {
	height: 6em;
	}
	input[type=submit] {
	position: absolute;
	flex-grow: 0;
	width: 30%;
	right: 0;
	top: 1em;
	text-shadow: 0 0 10px #E84B8C;
	}
	form > div {
	position: relative;
	display: flex;
	width: 100%;
	align-items: center;
	}
	form label {
	margin-right: 0.5em;
	margin-bottom: 0.5em;
	margin-top: 0.5em;
	font-weight: bold;
	}
	a[href] {
	color: #FF2E84;
	}
	h1 {
		font-weight: 100;
		margin-bottom: 0.0em;
	}
	h1 a[href] {
	color: #FF7AB1;
	text-decoration: none;
	}
_END_
	)
  (make-netresp 'ok (list (cons "Server" "")
						  (cons "Content-Type" "text/css")
						  (cons "Content-Length" (number->string
												   (string-length style))))
				style))

(define (get-new-chapter req)
  (let* ([path (netreq-path req)]
		 [place (follow-path (cdr path))]
		 [params (netreq-post-params req)])
	(if (eq? #f place) (error-not-found req)

		(let* ([story-key (text-path-story-key place)]
			   [story (text-path-story-rec place)]
			   [chapter-key (text-path-chapter-key place)])
		  (new-chapter-page req story-key story chapter-key)))))

(define (get-flag-chapter req) 0)
(define (post-flag-chapter req) 0)

(define (error-not-found req)
  (respond req 'nofile "error"
		   '((p "the path you have entered is not meaningful."))
		   '(("start over" . "/"))))







(define (display-index-page req)
  (respond req 'ok ""
		   '((p "welcome to this " (b "fabulist" ) " instance.")
			 (p "fabulist is a server for hosting collaborative interactive fiction." )
			 (p "select one of the links below."))
		   '(("start a new story" . "/init")
			 ("play an existing story" . "/find")
			 ("start a random story" . "/rand"))))



(define (new-chapter-page req key story last-page)
  (let ([new-url (string-append "/new/" key (if (eq? #f last-page) ""
												(string-append "/" last-page)))])
	(respond req 'ok (string-append (story-title story) " :: new chapter")
		   (list
			 '(p "write your chapter and hit " (b "commit") " to add it to the story")
................................................................................
	(let* ([destkey (string-append story-key "." dest)]
		   [dest-pg (alist-ref destkey (db-pages *database*) equal?)]
		   [old-choices (page-choices dest-pg)])
	  (page-choices-set! dest-pg (append old-choices (list new-key)))))
	  
  (let* ([path (netreq-path req)]
		 [place (follow-path (cdr path))]
		 [params (netreq-post-params req)])

	(if (eq? #f place) (error-not-found req)
		(let* ([story-key (text-path-story-key place)]
			   [story (text-path-story-rec place)]
			   [chapter-key (text-path-chapter-key place)]


			   [choice-link (post-field params "choice-link")]
			   [chapter-body (post-field params "chapter-body")])





			  (let* ([new-key (generate-key 4)]
					 [full-key (string-append story-key "." new-key)]
					 [new-page
					   (make-page choice-link
								  story-key
								  (format-user-text chapter-body)
								  '())])
				(if (= (length path) 2)
					(if (eq? #f (story-start story))
						(begin (save-chapter full-key new-page)
							   (save-to-start story new-key)
							   (redirect (string-append "/p/" story-key "/" new-key)))
						(error-not-found req))
					; FIXME: insert error checking to make sure [chapter-key]
					; really exists; right now this will crash the program!


					(begin (save-chapter full-key new-page)
						   (add-to-page story-key chapter-key new-key)
						   (redirect (string-append "/p/" story-key "/" chapter-key))))

		  )))))


(define (get-story-chapter req)
  (define (render-chapter story-key story chapter)
	(define (lookup-chapter ch) (alist-ref (string-append story-key "." ch)
										   (db-pages *database*) equal?))
	(define (format-choice ch)







>
>
>
>
>
>
>







 







|
>
>
>
|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|


|
|





|
>












>
>
>
>
>
>








|
>
>







 







|
>




>
>


>
>
>
>
>
|
|
<
|



|







>
>




|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
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
...
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
(import (chicken tcp)
		(chicken pretty-print)
		(chicken io)
		(chicken string)
		(chicken bitwise)
		(chicken random))

(begin-for-syntax (import (chicken io)))
(include "scmlib/lisp-macro.scm")
(define-macro (static-import-string . body)
			  (call-with-input-file (car body)
									(cut read-string #f <>)))
(define *stylesheet* (static-import-string "fabulist.css"))

(tcp-read-timeout 300)

(define-record db (setter stories) (setter pages))
(define-record story title genre
			   desc key start)
(define-record page link story body choices)
(define *database* (make-db '() '()))
................................................................................
(define-record netstr sz val rest)
(define-record netreq body method path
			   query origin accept
			   ref ua)

(define (netreq-post-params req) (map (cut string-split <> "=")
								 (string-split (netreq-body req) "&")))
(define (post-field arr p)
  (let ((v (assoc p arr))) (if (or (null? v)
								   (eq? #f v)
								   (null? (cdr v))) ""
							   (url-decode (cadr v)))))
(define (alist->netreq al body)
  (define (method->symbol m) (cond [(equal? m "GET") 'get]
								   [(equal? m "POST") 'post]
								   [(equal? m "PUT") 'put]
								   [else 'unknown]))
  (define (field key) 
	(let ((result (assoc key al)))
................................................................................
								   final-text)])
	  response)))


(define (get-new-story req) 0)

(define (get-stylesheet req)






























































  (make-netresp 'ok (list (cons "Server" "fabulist")
						  (cons "Content-Type" "text/css")
						  (cons "Content-Length" (number->string
												   (string-length *stylesheet*))))
				*stylesheet*))

(define (get-new-chapter req)
  (let* ([path (netreq-path req)]
		 [place (follow-path (cdr path))]
		 [params (netreq-post-params req)])
	(if (or (eq? #f place)
			(eq? #f (text-path-story-rec place))) (error-not-found req)
		(let* ([story-key (text-path-story-key place)]
			   [story (text-path-story-rec place)]
			   [chapter-key (text-path-chapter-key place)])
		  (new-chapter-page req story-key story chapter-key)))))

(define (get-flag-chapter req) 0)
(define (post-flag-chapter req) 0)

(define (error-not-found req)
  (respond req 'nofile "error"
		   '((p "the path you have entered is not meaningful."))
		   '(("start over" . "/"))))

(define (error-bad-request req back)
  (respond req 'badreq "error"
		   '((p "the data you have supplied is not valid."))
		   `(("return to story" . ,back)
			 ("start over" . "/"))))

(define (display-index-page req)
  (respond req 'ok ""
		   '((p "welcome to this " (b "fabulist" ) " instance.")
			 (p "fabulist is a server for hosting collaborative interactive fiction." )
			 (p "select one of the links below."))
		   '(("start a new story" . "/init")
			 ("play an existing story" . "/find")
			 ("start a random story" . "/rand")
			 ("set your author details" . "/auth")
			 )))

(define (new-chapter-page req key story last-page)
  (let ([new-url (string-append "/new/" key (if (eq? #f last-page) ""
												(string-append "/" last-page)))])
	(respond req 'ok (string-append (story-title story) " :: new chapter")
			 (list
			   '(p "write your chapter and hit " (b "commit") " to add it to the story")
................................................................................
	(let* ([destkey (string-append story-key "." dest)]
		   [dest-pg (alist-ref destkey (db-pages *database*) equal?)]
		   [old-choices (page-choices dest-pg)])
	  (page-choices-set! dest-pg (append old-choices (list new-key)))))

  (let* ([path (netreq-path req)]
		 [place (follow-path (cdr path))]
		 [params (netreq-post-params req)]
		 [raw-path (foldl string-append "" (intersperse (cdr path) "/"))])
	(if (eq? #f place) (error-not-found req)
		(let* ([story-key (text-path-story-key place)]
			   [story (text-path-story-rec place)]
			   [chapter-key (text-path-chapter-key place)]
			   [chapter-full-key (if (eq? #f chapter-key) #f
									 (string-append story-key "." chapter-key))]
			   [choice-link (post-field params "choice-link")]
			   [chapter-body (post-field params "chapter-body")])
		  (cond [(or (equal? chapter-body "")
					 (and (equal? choice-link "")
						  (not (eq? chapter-key #f))))
				 (error-bad-request req (string-append "/p/" raw-path))]
				[else
				  (let* ([new-key (generate-key 4)]
						 [full-key (string-append story-key "." new-key)]

						 [new-page (make-page choice-link
											  story-key
											  (format-user-text chapter-body)
											  '())])
					(if (= (length path) 2); new story or new branch?
						(if (eq? #f (story-start story))
							(begin (save-chapter full-key new-page)
								   (save-to-start story new-key)
								   (redirect (string-append "/p/" story-key "/" new-key)))
							(error-not-found req))
						; FIXME: insert error checking to make sure [chapter-key]
						; really exists; right now this will crash the program!
						(if (eq? #f (alist-ref chapter-full-key (db-pages *database*) equal?))
							(error-not-found req)
							(begin (save-chapter full-key new-page)
								   (add-to-page story-key chapter-key new-key)
								   (redirect (string-append "/p/" story-key "/" chapter-key))))

						))])))))


(define (get-story-chapter req)
  (define (render-chapter story-key story chapter)
	(define (lookup-chapter ch) (alist-ref (string-append story-key "." ch)
										   (db-pages *database*) equal?))
	(define (format-choice ch)

Modified nkvd.c from [6971590b48] to [ca4bf4ac94].

106
107
108
109
110
111
112




113
114
115
116
117
118
119
 *
 * TODO: support a mappings file/variable for those programs
 *       too special to simply name their config file
 *       "~/.(argv[0])". 
 *
 * TODO: exempt xdg dirs beginning with ~/. from proscription
 *       in nkvd_interdict_all=1 mode




 */

#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <limits.h>







>
>
>
>







106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 *
 * TODO: support a mappings file/variable for those programs
 *       too special to simply name their config file
 *       "~/.(argv[0])". 
 *
 * TODO: exempt xdg dirs beginning with ~/. from proscription
 *       in nkvd_interdict_all=1 mode
 *
 * TODO: instead of function passthrough,  alter environment
 *       to delete  LD_PRELOAD and re-exec  whitelisted apps
 *       without nkvd loading at all
 */

#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <limits.h>