Compare commits
5 Commits
4b438bc70d
...
c0d79480d6
| Author | SHA1 | Date | |
|---|---|---|---|
| c0d79480d6 | |||
| 5fdf026536 | |||
| 289e95280c | |||
| 520a0c888f | |||
| 896be50c0a |
56
palps.rkt
56
palps.rkt
@@ -1,40 +1,41 @@
|
|||||||
#! /usr/bin/env /usr/local/bin/racket
|
#! /usr/bin/env /usr/local/bin/racket
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
;; get callsign, first thing passed by BPQ
|
;; default directory used for storing dynamic application data
|
||||||
(define call (read-line (current-input-port) 'any))
|
(define data-dir
|
||||||
|
(build-path (find-system-path 'home-dir)
|
||||||
|
(build-path ".local" "share" "palps")))
|
||||||
|
|
||||||
;; drop SSID
|
(define (call-valid? call)
|
||||||
(set! call (first (string-split call "-")))
|
(and
|
||||||
|
(<= (string-length call) 9)
|
||||||
|
(andmap
|
||||||
|
(or/c char-numeric? char-alphabetic? (curry char=? #\-))
|
||||||
|
(string->list call))))
|
||||||
|
|
||||||
;; downcase callsign
|
(define (our-make-temporary-file [copy-from #f])
|
||||||
(set! call (string-downcase call))
|
;; when deployed as a systemd socket, this program is expected to be
|
||||||
|
;; ran with PrivateTmp. however, in case this is not true, we still
|
||||||
;; if the sysadmin has created a directory for that callsign, then
|
;; make our own directory. "red", the restricted version of "ed",
|
||||||
;; they are an authorized user.
|
;; has no facility for getting outside of the directory we start it
|
||||||
(when (not (directory-exists? call))
|
;; in.
|
||||||
(displayln "sorry, but you are not an authorized user of the PALPS system")
|
(make-temporary-file "red.~a"
|
||||||
(displayln "visit https://gitea.farpn.net/w6vvn/palps for an explanation")
|
#:copy-from copy-from
|
||||||
(flush-output)
|
#:base-dir (make-temporary-directory)))
|
||||||
(exit))
|
|
||||||
|
|
||||||
;; change to the authroized users directory
|
|
||||||
(current-directory call)
|
|
||||||
|
|
||||||
(printf "welcome ~a. now starting (r)ed, the standard text editor~n" call)
|
|
||||||
(flush-output)
|
|
||||||
|
|
||||||
;; unfortunately, we cannot just exec red and let it take over the
|
;; unfortunately, we cannot just exec red and let it take over the
|
||||||
;; I/O. ed, being the standard text editor, only works with standard
|
;; I/O. ed, being the standard text editor, only works with standard
|
||||||
;; line endings, \n. telnet and BPQ, however, use \r\n. \r\n upsets
|
;; line endings, \n. telnet and BPQ, however, use \r\n. \r\n upsets
|
||||||
;; ed, the standard text editor. so we need to wrap the input and
|
;; ed, the standard text editor. so we need to wrap the input and
|
||||||
;; output ports ourselves in order to provide this translation.
|
;; output ports ourselves in order to provide this translation.
|
||||||
|
(define (ed [path (our-make-temporary-file)])
|
||||||
(match-define
|
(match-define
|
||||||
(list stdout stdin pid stderr proc)
|
(list stdout stdin pid stderr proc)
|
||||||
|
(parameterize ([current-directory (path-only path)])
|
||||||
(process* "/usr/bin/red"
|
(process* "/usr/bin/red"
|
||||||
"-p*"
|
"-p*"
|
||||||
#:set-pwd? #t))
|
(path->string (file-name-from-path path))
|
||||||
|
#:set-pwd? #t)))
|
||||||
|
|
||||||
(define buffer (make-bytes 128))
|
(define buffer (make-bytes 128))
|
||||||
|
|
||||||
@@ -61,15 +62,12 @@
|
|||||||
|
|
||||||
;; either event may EOF, which means that ed has died.
|
;; either event may EOF, which means that ed has died.
|
||||||
[(eof-object? evt-result)
|
[(eof-object? evt-result)
|
||||||
|
|
||||||
;; clean up
|
;; clean up
|
||||||
(close-output-port stdin)
|
(close-output-port stdin)
|
||||||
(close-input-port stdout)
|
(close-input-port stdout)
|
||||||
(close-input-port stderr)
|
(close-input-port stderr)
|
||||||
(proc 'kill)])))
|
(proc 'kill)
|
||||||
|
|
||||||
(loop)
|
path])))
|
||||||
|
(loop))
|
||||||
(displayln "goodbye")
|
|
||||||
(flush-output)
|
|
||||||
|
|
||||||
(exit)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user