88 lines
2.5 KiB
Scheme
88 lines
2.5 KiB
Scheme
;;
|
|
;; dokuwiki.scm
|
|
;;
|
|
;; Dokuwiki internals support.
|
|
;;
|
|
;; ISC License
|
|
;;
|
|
;; Copyright 2023 Dominik Pantůček <dominik.pantucek@trustica.cz>
|
|
;;
|
|
;; Permission to use, copy, modify, and/or distribute this software
|
|
;; for any purpose with or without fee is hereby granted, provided
|
|
;; that the above copyright notice and this permission notice appear
|
|
;; in all copies.
|
|
;;
|
|
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
;;
|
|
|
|
(declare (unit dokuwiki))
|
|
|
|
(module
|
|
dokuwiki
|
|
(
|
|
dokuwiki-load-users
|
|
)
|
|
|
|
(import scheme
|
|
(chicken base)
|
|
(chicken pathname)
|
|
(chicken io)
|
|
(chicken string)
|
|
(chicken condition)
|
|
racket-kwargs
|
|
configuration
|
|
util-parser
|
|
util-csv
|
|
logging
|
|
util-stdout)
|
|
|
|
;; Special CSV-like parser
|
|
(define auth-line-parser
|
|
(make-csv-line-parser #\: #f))
|
|
|
|
;; Parses all dokuwiki users from current-input-port, returns a list
|
|
;; of lists: username, name, email, groups (list)
|
|
(define (parse-dokuwiki-users-auth)
|
|
(let loop ((lines (read-lines))
|
|
(users '()))
|
|
(if (null? lines)
|
|
users
|
|
(let ((line (parser-preprocess-line (car lines) #:strip-comments? #f)))
|
|
(if (equal? line "")
|
|
(loop (cdr lines)
|
|
users)
|
|
(let* ((row (auth-line-parser line))
|
|
(username (car row))
|
|
(name (caddr row))
|
|
(email (cadddr row))
|
|
(groupstr (list-ref row 4))
|
|
(groups (string-split groupstr ",")))
|
|
;;(print "u=" username " n=" name " e=" email " g=" groups)
|
|
(loop (cdr lines)
|
|
(cons (list username name email groups)
|
|
users))))))))
|
|
|
|
;; Parses all users from given filename
|
|
(define (load-dokuwiki-users-auth fname)
|
|
(handle-exceptions
|
|
exn
|
|
(let ()
|
|
(log-warning "DokuWiki (~A) exception ~A" fname (condition->list exn))
|
|
(stdout-printf "DokuWiki (~A) exception ~A" fname (condition->list exn))
|
|
'())
|
|
(with-input-from-file fname
|
|
parse-dokuwiki-users-auth)))
|
|
|
|
;; Loads all users from default dokuwiki users database
|
|
(define* (dokuwiki-load-users (doku-base (*doku-base*)))
|
|
(load-dokuwiki-users-auth
|
|
(make-pathname doku-base "conf/users.auth.php")))
|
|
|
|
)
|