Index: doc/howto.txt ================================================================== --- doc/howto.txt +++ doc/howto.txt @@ -83,19 +83,22 @@ make a selection drop down ~~~~~~~~~~~~~~~~~~~~~~~~~~ In view.scm: -(s:select '(("World" 0)("Country" 1)("State" 2 #t)("Town/City" 3)) 'name 'scope) +;; Label Value visible-str selected +(s:select '(("World" 0)("Country" 1)("State" 2 "The state" #t )("Town/City" 3)) 'name 'scope) + +Visible str will be shown if provided. Selected will set that entry to pre-selected. In control.scm: (let ((scope (s:get-input 'scope)) (scope-num (s:get-input 'scope 'number))) ;; 'number, 'raw or 'escaped .... -The optional third entry sets that item as selected if true +The optional fourth entry sets that item as selected if true Simple error reporting ~~~~~~~~~~~~~~~~~~~~~~ In control.scm: Index: misc-stml.scm ================================================================== --- misc-stml.scm +++ misc-stml.scm @@ -10,13 +10,12 @@ ;;====================================================================== ;; dumbobj helpers ;;====================================================================== (declare (unit misc-stml)) +(use (prefix crypt c:)) (use regex) -(use dbi) -(import (prefix dbi dbi:)) ;; given a list of symbols give the count of the matching symbol ;; l => '(a b c) (dumobj:indx a 'b) => 1 (define (s:get-fieldnum lst field-name) (let loop ((head (car lst)) @@ -127,22 +126,15 @@ (n 1)) (if (> n len) res (loop (string-append res (session:get-rand-char)) (+ n 1))))) -;; openssl passwd -crypt -salt xx password +;; Rely on crypt egg's default settings being secure enough, accept +;; backwards-compatible OpenSSL crypt passwords too. ;; (define (s:crypt-passwd pw s) - (let* ((salt (if s s (session:make-rand-string 2))) - (inp (open-input-pipe - ;;(string-append "echo " pw " | mkpasswd -S " salt " -s"))) - ;; (conc "mkpasswd " pw " " salt) - (conc "openssl passwd -crypt -salt " salt " " pw) - )) - (res (read-line inp))) - (close-input-port inp) - res)) + (c:crypt pw (or s (c:crypt-gensalt)))) (define (s:password-match? password crypted) (let* ((salt (substring crypted 0 2)) (pcrypted (s:crypt-passwd password salt))) (s:log "INFO: pcrypted=" pcrypted " crypted=" crypted) Index: session.scm ================================================================== --- session.scm +++ session.scm @@ -734,10 +734,19 @@ ((raw) res) ((number) (if (string? res)(string->number res) #f)) ((escaped) (if (string? res) (s:html-filter->string res tags) res)) + ((escaped-nl) (if (string? res) ;; escape \n and \r + (string-intersperse + (string-split + (string-intersperse + (string-split (s:html-filter->string res tags) "\n") + "\\n") + "\r") + "\\r") + res)) (else (if (string? res) (s:html-filter->string res '()) res))))) (define (session:get-param self key type-params) Index: setup.scm ================================================================== --- setup.scm +++ setup.scm @@ -9,10 +9,14 @@ (declare (unit setup)) (declare (uses session)) (require-extension srfi-69) (require-extension regex) + +;; macros in sugar don't work, have to load in all files or use compiled mode? +;; +;; (include "sugar.scm") ;; use this for getting data from page to page when scope and evals ;; get in the way (define s:local-vars (make-hash-table)) Index: sugar.scm ================================================================== --- sugar.scm +++ sugar.scm @@ -87,12 +87,21 @@ ;; v ; => 16 ;; (+= v) ;; v ; => 16 ;; +(define-simple-syntax (s:if-param varname first ...) + (if (s:get varname) + first + ...)) + +(define-simple-syntax (s:if-sessionvar varname first ...) + (if (s:session-var-get varname) + first + ...)) -;; (define-macro (s:if-param varname . dat) +;; (define-macro (s:if-param varname ...) ;; (match dat ;; (() '()) ;; ((a) `(if (s:get ,varname) ,a '())) ;; ((a b) `(if (s:get ,varname) ,a ,b)))) ;; Index: tests/test.scm ================================================================== --- tests/test.scm +++ tests/test.scm @@ -12,11 +12,12 @@ (use test md5) (require-extension sqlite3) (import (prefix sqlite3 sqlite3:)) -(require-library dbi) +;; (require-library dbi) +(use (prefix dbi dbi:)) (load "./requirements.scm") (load "./cookie.scm") (load "./misc-stml.scm") (load "./formdat.scm") @@ -96,11 +97,12 @@ (loop (read-line fh))))) (close-input-port fh)) ;; Should have poll:poll defined now. (test "Make a random string" 2 (string-length (session:make-rand-string 2))) -(test "Create a encrypted password" "abQ9KY.KfrYrc" (s:crypt-passwd "foo" "ab")) +(test "Create an encrypted password using DES (backwards compat)" "abQ9KY.KfrYrc" (s:crypt-passwd "foo" "ab")) +(test "Create an encrypted password using Blowfish" "$2a$12$GyoKHX/UOxMLGtwdSTr7EOF9KQzlyyyRqFTKx1YvLA3sMukbV4WBC" (s:crypt-passwd "foo" "$2a$12$GyoKHX/UOxMLGtwdSTr7EO")) (test "s:any->string on a hash-table" "#" (s:any->string (make-hash-table))) (define select-list '((a b c)(d (e f g)(h i j #t))))