introduce deplyoment config
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 2 Jan 2022 01:16:53 +0000 (12:16 +1100)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 2 Jan 2022 01:16:53 +0000 (12:16 +1100)
12 files changed:
command.lsp
control-logic.lsp
control.dat
hourglass.conf [new file with mode: 0644]
howto.adoc
ipset-control.lsp
listener.lsp
manager/basic_login.lsp
manager/install.lsp
manager/tmpl/controls-form.html
run-manager.sh
setup.sh

index 3e5094c45a002d2fb808a22a4eecd65735519f43..8751fc3082e4c5de8571b94d06f5787d22e62c4d 100644 (file)
@@ -2,6 +2,46 @@
 # This script is intended as main script for packnl embedding, it
 # dispatches to the command of the first argument.
 
+(context 'MAIN:SITE)
+
+(define (set-int K V) (set K (int V 0 10)))
+
+(define (set-ints K V)
+  (map (curry set-int K) (clean empty? (parse V "\\s*,?\\s*" 0))))
+
+(define (set-list K V)
+  (map (curry set K) (clean empty? (parse V "\\s*,?\\s*" 0))))
+
+(constant
+ 'FILE "hourglass.conf"
+ 'KEYS '(
+         ("libc" set)
+         ("listener.ports" set-ints)
+         ("listener.ip" set)
+         ("listener.activity.dir" set)
+         ("control.action" set)
+         ("control.dat" set)
+         ("control.net" set)
+         ("control.extra.dat" set)
+         ("control.usage.dat" set)
+         ("control.usage.tmp" set)
+
+         ("wui.port" set-int)
+         ("wui.roles" set)
+         ("wui.passwd" set)
+         )
+ )
+
+(define (setting LINE)
+  (when (regex "^\\s([^;#][^=]*)=(.*)" LINE 0)
+    (let ((KV (map trim (list $1 $2))))
+      (if (lookup (KV 0) KEYS) (apply $it (list (sym (KV 0)) (KV 1)))))))
+
+(map setting (parse (or (read-file FILE) "") "\n"))
+
+####################
+(context MAIN)
+
 (if (exists file? (list (main-args 1)
                         (string (main-args 1) ".lsp")))
     (load $it)
index c842c06eee67d320d6270d87548e66ec80baf1b6..d75a9133a629e0fe46a2d24b9f0c8fe8baa52311 100644 (file)
@@ -9,7 +9,14 @@
   (write-line 2 (join (map string args)))
   (exit 1))
 
-(constant 'NOW (date-value))
+(constant
+ 'NOW (date-value)
+ 'ACTDIR SITE:listener.activity.dir
+ 'CONTROL.DAT SITE:control.dat
+ 'EXTRA.DAT SITE:control.extra.dat
+ 'USAGE.DAT SITE:usage.dat
+ 'USAGE.TMP SITE:usage.tmp
+ )
 
 # Set current time variables in local timezone
 (map set '(YEAR MONTH DATE HOUR MINUTE SECOND DOY DOW)
  DAY (list YEAR MONTH DATE)
  HM (list HOUR MINUTE)
  TOTAL '()
- CONTROL.DAT "control.dat"
- EXTRA.DAT "control-extra.dat"
- USAGE.DAT "usage.dat"
- USAGE.TMP ".usage.dat" 
  )
 
 # Load CONTROL.DAT
@@ -40,7 +43,6 @@
 (setf
  GAP (or (lookup 'gap CONTROL) 15)
  CLIP (or (lookup 'clip CONTROL) 1000)
- NET  (or (lookup 'net CONTROL) "10.0.0.0/8")
  )
 
 # Load the configured control mechanism
 ;;==== Utilities for activity data
 # Activity is lines of timestamps. Collect TOTAL as list of unique
 # time values (H M) within the start-end time span.
+
 (define (log-name-fmt t)
   (format "%d%02d%02d-.*\\.dat" (0 3 (date-list t))))
 
 (define (log-lines f)
-  (find-all "([0-9]+( \\S+)?).*" (read-file (string "activity/" f)) $1 0))
+  (find-all "([0-9]+( \\S+)?).*" (read-file (format "%s/%s" ACTDIR f)) $1 0))
 
 # Collect all timestamps of the UTC date of the given time stamp
 (define (logs t)
-  (flat (map log-lines (directory "activity" (log-name-fmt t)))))
+  (flat (map log-lines (directory ACTDIR (log-name-fmt t)))))
 
 # Translate timestamp into its local time (hour minute), if it's
 # within the applicable day, null otherwise.
index 3eda9d4b4a854f770e9b6df5fa84c2b7fdbf5611..551e938830c1e2130e251f0d18cb7a8190d1f6cd 100644 (file)
@@ -1,6 +1,5 @@
 ; Updated at Sun Aug  8 22:53:01 2021
-((control "ipset-control.lsp")
- (net "192.168.104.0/24")
+((net "192.168.104.0/24")
  (gap 10)
  (clip 1000)
  (1 timed (5 30) (2 0) (20 0))
diff --git a/hourglass.conf b/hourglass.conf
new file mode 100644 (file)
index 0000000..c424ffb
--- /dev/null
@@ -0,0 +1,21 @@
+; Hourglass site configuration
+libc = /lib/x86_64-linux-gnu/libc.so.6
+
+listener.net = 192.168.255
+listener.ports = 80 443
+listener.activity.dir = activity
+listener.tap = hourglass
+listener.tundev = /dev/net/tun
+
+control.action = ipset-control.lsp
+control.dat = control.dat
+control.net = 10.0.0.0/8
+control.extra.dat = control-extra.dat
+control.usage.dat = usage.dat
+control.usage.tmp = .usage.dat
+
+ipset.bin = /sbin/ipset
+ipset.table = TIMO
+
+wui.port = 1070
+wui.passwd = .htpassswd
index e0c25cfe8561e76a9570d4a8b0bc4cc53a229ff9..fea2a54d1dddf5169600002161d2e1c673a9cf2b 100644 (file)
@@ -30,6 +30,13 @@ control policy, held in the +control.dat+ file, as well as the control
 override setting, in file +control-extra.dat+, whilst also showing
 current usage measure from file +usage.dat+.
 
+The server +hourglass-web+ is first installed with
+----
+$ ./hourglass-web install
+----
+That installation sets up a small +www+ sub directory with "CGI"
+scripting to provide the Hourglass User Interface on port 1070.
+
 Hourglass Network Traffic Capture
 ---------------------------------
 
index 899e37af2fbec9f633b39d3f57b0b628d6dabb56..cd813840eb3fbe52300b75b1e7aa5ad2a7499a22 100644 (file)
@@ -1,10 +1,10 @@
 
 # Should load from "ipset.cfg"
-(constant 'IPSET "/sbin/ipset" 'TABLE "TIMO" )
+(constant 'IPSET SITE:ipset.bin 'TABLE SITE:ipset.table NET SITE:control.net)
 
 ;; Return current low-leve "close" or "open" status
 (define (current-status)
-  (if (exec (format "%s list %s | grep %s" IPSET TABLE NET)) "close" "open"))
+  (if (member NET (exec (format "%s list %s" IPSET TABLE))) "close" "open"))
 
 ;; Ensure low-level setting is "close" or "open" as given
 (define (control cmd reason)
index bd823f2fc7c2faf31a9a88a9ff9085fff534c770..ceefed46da0b86bfec0e5549aebce86f6b9f9e40 100644 (file)
@@ -11,9 +11,7 @@
 (signal 2 (fn (x) (exit 0)))
 
 # The following is for Devuan GNU+Linux
-(constant 'LIBC (exists file? '("/lib/x86_64-linux-gnu/libc.so.6"
-                               "/lib/i386-linux-gnu/libc.so.6"
-                               )))
+(constant 'LIBC SITE:libc)
 (import LIBC "ioctl" "int" "int" "long" "void*" )
 (import LIBC "perror" "void" "char*" )
 (import LIBC "ntohl" "int" "int" )
     (if (null? a) v (nil? v) true (null? (1 a)) v (a 1))))
 
 # Set logging mode.
-(constant 'listener-log-ip (mainarg "-l" nil))
-
 # Open the tap named by "-t tapX" on the command line, or "tap0" byt
 # default. Then make a TUNSETIFF call to initialize it (as
 # IFF_TAP|IFF_NO_PI).
-(constant 'IFNAME (mainarg "-t" "tap0") 'IFD (open "/dev/net/tun" "u") )
+(constant
+ 'listener-log-ip SITE:listener.ip
+ 'IFNAME SITE:listener.tap
+ 'PORTS SITE:listener.ports
+ 'IFD (open SITE:listener.tundev "u")
+ 'ACTNAMEFMT "%d%02d%02d-network.dat"
+ 'ACTDIR SITE:listener.activity.dir
+ 'ACTFILEFMT (format "%s/%s" ACTDIR ACTNAMEFMT )
+)
 (unless (number? IFD) (die "open"))
 (unless (zero? (ioctl IFD 0x400454ca (pack "s16 u s22" IFNAME 0x1002 "")))
   (die (string "set " IFNAME)))
 
 # The TCP ports of interest
-(constant 'PORTS '(80 443))
 
 # Set up for optional tracking of IP addresses
 (define counter:counter nil)
 # This funcion collates all given ips, and it extends the log line
 # with the list of ips used during the minute.
 (setf next-mark 0 packet-count 0)
+     
 (define (mark-active t) ; buffer
   (when listener-log-ip (track-data))
   (inc packet-count)
   ;(write-line 2 (string (list t packet-count ports (counter))))
   (when (>= t next-mark)
-    (let ((d (format "activity/%d%02d%02d-network.dat" (0 3 (date-list t))))
+    (let ((d (format ACTFILEFMT (0 3 (date-list t))))
           (c (map string (counter))))
       (append-file d (string t " " packet-count " " (join c " ") "\n"))
       (setf next-mark (+ t 60) packet-count 0)
index 7231ef0e0e7f7b3b62d4f5965a3655dafd7d5497..f491a9eee47ead9952defe603dd782c9f6792e76 100644 (file)
   (write-line 1 (read-file "tmpl/unauthorized.http"))
   (exit 0))
 
-(define (role-script ROLE)
+;; Determine actual script name respecting given role, if any.
+(define (role-script (ROLE "."))
   (let ((CMD (and (regex "([^/]*).cgi$" (main-args 0) 0) $1)))
-    (if (= "." ROLE) (string CMD ".lsp")
-      (format "%s/%s.lsp" ROLE CMD))))
+    (if (= "." ROLE) (string CMD ".lsp") (format "%s/%s.lsp" ROLE CMD))))
 
 (setf
- ROLES (map (fn (x) (parse x ":")) (parse (read-file "roles.txt") "\n"))
  REMOTE_USER (and (regex "([^:]+):" (base64-dec (6 AUTH)) 0) $1)
- ROLE (or (lookup REMOTE_USER ROLES) "child")
- SCRIPT (role-script ROLE)
+ SCRIPT (role-script)
  )
 (env "REMOTE_USER" REMOTE_USER)
 (env "ROLE" ROLE)
index 6e234d2a5d30105038ef2fc8336a3e99b48dcad3..c4193bea8cb792abe0388212c20eb253e9e76bd7 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/newlisp
 #
-# Install the Hourglass service to new directory www
+# Install the Hourglass web tree to a new "www" subdirectory
 
 (when (directory? "www")
   (write-line 2 "** directory www exists. aborting")
index 88dd6fa4eeac134a783f1d9576cfb975ee007020..84b26114435c502db045c4283c520e1007588d94 100644 (file)
          </select>
          networks packets in a minute, to count as activity.
        </div>
-       <div id="net_field" class="extra">
-         <input type="textfield" name="net" value="<?newlisp NET ?>">
-         controlled network.
-       </div>
       </div>
       <div id="form_submit" class="extra" >
        <?newlisp UPDATE?>
index a7b3c32e6807bfaf3284fbc66c7f9817ba3d114d..3e2690af059fa06eda5426cfdf14402fc280b0b5 100755 (executable)
@@ -5,7 +5,7 @@ function die() {
     exit 1
 }
 
-SERVICE=manager/hourglass-web
+SERVICE=hourglass-web
 
 [ -f "$SERVICE" ] || die "** missing $SERVICE ** aborting"
 
index 3585d74d12bbe45a9053ba1f657f25e83bcc8fa0..4cf7a80d8c6ffdb89e89bab1042029d40583208c 100755 (executable)
--- a/setup.sh
+++ b/setup.sh
@@ -3,10 +3,14 @@
 # This is a control script to start and stop the network activity
 # listening.
 
-CMD=${1-start}
-NET=192.168.249
-TAP=hourglass0
-SET=TIMO
+CONF="hourglass.conf"
+function getcfg() {
+    grep -E "\\s*[^;#]$1]\\s*=" $CONF | sed 's/.*=\s*(.*)/\1/;s/\s*$//'
+}
+
+NET="$(getcfg listener.ip)"
+TAP="$(getcfg listener.tap)"
+SET="$(getcfg ipset.table)"
 
 cd $(dirname $0)