206 lines
5.9 KiB
Scheme
206 lines
5.9 KiB
Scheme
;;
|
|
;; configuraiton.scm
|
|
;;
|
|
;; Configuration parameters used by various modules.
|
|
;;
|
|
;; ISC License
|
|
;;
|
|
;; Copyright 2023 Brmlab, z.s.
|
|
;; 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 configuration))
|
|
|
|
(module
|
|
configuration
|
|
(
|
|
*etc-hackerbase*
|
|
|
|
*members-directory*
|
|
*apikeys-file*
|
|
*checked-file*
|
|
*bank-dir*
|
|
*email-from*
|
|
*summary-mailto*
|
|
*doku-base*
|
|
*mailman2-bin*
|
|
*mailman-version*
|
|
*mailman3-bin*
|
|
*mailman3-sql*
|
|
*mailman3-sql-path*
|
|
|
|
load-configuration!
|
|
)
|
|
|
|
(import scheme
|
|
(chicken base)
|
|
(chicken time)
|
|
(chicken time posix)
|
|
(chicken file)
|
|
(chicken io)
|
|
(chicken process-context)
|
|
(chicken pathname)
|
|
util-parser)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; Initial configuration from *etc-hackerbase*
|
|
|
|
;; Where to load initial configuration from
|
|
(define *etc-hackerbase* (make-parameter
|
|
(list "/etc/hackerbase"
|
|
(make-pathname
|
|
(get-environment-variable "HOME")
|
|
".hackerbaserc"))))
|
|
|
|
;; Needed by multiple modules actually
|
|
(define *members-directory* (make-parameter #f))
|
|
(define =members-directory= "members")
|
|
|
|
;; List of bank accounts and Fio API keys (no support for other banks now)
|
|
(define *apikeys-file* (make-parameter #f))
|
|
(define =apikeys-file= "apikey.ntlm")
|
|
|
|
;; Old last checket transaction id support
|
|
(define *checked-file* (make-parameter #f))
|
|
(define =checked-file= "checked.ntlm")
|
|
|
|
;; Where are the bank CSV files
|
|
(define *bank-dir* (make-parameter #f))
|
|
|
|
;; From address for emails
|
|
(define *email-from* (make-parameter #f))
|
|
(define =email-from= "Brmlab - Rada <rada@brmlab.cz>")
|
|
|
|
;; Summary email address
|
|
(define *summary-mailto* (make-parameter #f))
|
|
(define =summary-mailto= "rada@brmlab.cz")
|
|
|
|
;; DokuWiki base dir
|
|
(define *doku-base* (make-parameter #f))
|
|
(define =doku-base= "/var/www")
|
|
|
|
;; Where does the mailman binaries reside
|
|
(define *mailman2-bin* (make-parameter #f))
|
|
(define =mailman2-bin= "/usr/lib/mailman/bin")
|
|
|
|
;; Which version of mailman to use
|
|
(define *mailman-version* (make-parameter #f))
|
|
(define =mailman-version= 2)
|
|
|
|
;; What is the mailman 3 command
|
|
(define *mailman3-bin* (make-parameter #f))
|
|
;; The default value requires the following sudoers line:
|
|
;; %hackerbase ALL=(list) NOPASSWD:/usr/lib/mailman3/bin/mailman
|
|
(define =mailman3-bin= "sudo -u list /usr/lib/mailman3/bin/mailman")
|
|
|
|
;; A string is the default, gets converted to boolean at the end of
|
|
;; loading configuration
|
|
(define *mailman3-sql* (make-parameter #f))
|
|
(define =mailman3-sql= "0")
|
|
|
|
;; The path to SQLite3 DB file
|
|
(define *mailman3-sql-path* (make-parameter #f))
|
|
(define =mailman3-sql-path= "mailman.db")
|
|
|
|
(define (load-single-configuration! fname)
|
|
(when (file-exists? fname)
|
|
(let loop ((lines (read-lines (open-input-file fname))))
|
|
(when (not (null? lines))
|
|
(let* ((line (car lines))
|
|
(kv (parser-parse-line
|
|
(parser-preprocess-line line))))
|
|
(when (pair? kv)
|
|
(let ((k (car kv))
|
|
(v (cdr kv)))
|
|
(case k
|
|
((members-directory)
|
|
(when (not (*members-directory*))
|
|
(*members-directory* v)))
|
|
((apikeys-file)
|
|
(when (not (*apikeys-file*))
|
|
(*apikeys-file* v)))
|
|
((checked-file)
|
|
(when (not (*checked-file*))
|
|
(*checked-file* v)))
|
|
((bank-dir)
|
|
(when (not (*bank-dir*))
|
|
(*bank-dir* v)))
|
|
((email-from)
|
|
(when (not (*email-from*))
|
|
(*email-from* v)))
|
|
((summary-mailto)
|
|
(when (not (*summary-mailto*))
|
|
(*summary-mailto* v)))
|
|
((dokuwiki)
|
|
(when (not (*doku-base*))
|
|
(*doku-base* v)))
|
|
((mailman2)
|
|
(when (not (*mailman2-bin*))
|
|
(*mailman2-bin* v)))
|
|
((mailman-version)
|
|
(when (not (*mailman-version*))
|
|
(*mailman-version* (string->number v))))
|
|
((mailman3)
|
|
(when (not (*mailman3-bin*))
|
|
(*mailman3-bin* v)))
|
|
((mailman3-sql)
|
|
;; Gets to be string? - convert to boolean at the
|
|
;; end of loading!
|
|
(when (not (*mailman3-sql*))
|
|
(*mailman3-sql* v)))
|
|
((mailman3-sql-path)
|
|
(when (not (*mailman3-sql-path*))
|
|
(*mailman3-sql-path* v)))
|
|
)))
|
|
(loop (cdr lines)))))))
|
|
|
|
;; Loads the configuration file and possibly changes the default
|
|
;; parameters.
|
|
(define (load-configuration!)
|
|
(let ((fnames (*etc-hackerbase*)))
|
|
(if (string? fnames)
|
|
(load-single-configuration! fnames)
|
|
(let loop ((fnames fnames))
|
|
(when (not (null? fnames))
|
|
(load-single-configuration! (car fnames))
|
|
(loop (cdr fnames))))))
|
|
(when (not (*members-directory*))
|
|
(*members-directory* =members-directory=))
|
|
(when (not (*apikeys-file*))
|
|
(*apikeys-file* =apikeys-file=))
|
|
(when (not (*checked-file*))
|
|
(*checked-file* =checked-file=))
|
|
;; No bank-dir - #f default
|
|
(when (not (*email-from*))
|
|
(*email-from* =email-from=))
|
|
(when (not (*summary-mailto*))
|
|
(*summary-mailto* =summary-mailto=))
|
|
(when (not (*doku-base*))
|
|
(*doku-base* =doku-base=))
|
|
(when (not (*mailman2-bin*))
|
|
(*mailman2-bin* =mailman2-bin=))
|
|
(when (not (*mailman-version*))
|
|
(*mailman-version* =mailman-version=))
|
|
(when (not (*mailman3-bin*))
|
|
(*mailman3-bin* =mailman3-bin=))
|
|
(when (not (*mailman3-sql*))
|
|
(*mailman3-sql* =mailman3-sql=))
|
|
(*mailman3-sql* (not (equal? (*mailman3-sql*) "0")))
|
|
(when (not (*mailman3-sql-path*))
|
|
(*mailman3-sql-path* =mailman3-sql-path=)))
|
|
|
|
)
|