diff --git a/external/README.md b/external/README.md new file mode 100644 index 0000000..c4ed0b6 --- /dev/null +++ b/external/README.md @@ -0,0 +1 @@ +this folder contains the things that external people can access via ssh: join@tilde.town, welcome@tilde.town, and help@tilde.town diff --git a/cmd/help/README.md b/external/cmd/help/README.md similarity index 100% rename from cmd/help/README.md rename to external/cmd/help/README.md diff --git a/cmd/help/email.go b/external/cmd/help/email.go similarity index 100% rename from cmd/help/email.go rename to external/cmd/help/email.go diff --git a/external/cmd/help/help b/external/cmd/help/help new file mode 100755 index 0000000..9912b03 Binary files /dev/null and b/external/cmd/help/help differ diff --git a/cmd/help/main.go b/external/cmd/help/main.go similarity index 100% rename from cmd/help/main.go rename to external/cmd/help/main.go diff --git a/external/cmd/helpers/appendkeyfile/appendkeyfile b/external/cmd/helpers/appendkeyfile/appendkeyfile new file mode 100755 index 0000000..926d4d3 Binary files /dev/null and b/external/cmd/helpers/appendkeyfile/appendkeyfile differ diff --git a/cmd/appendkeyfile/main.go b/external/cmd/helpers/appendkeyfile/main.go similarity index 100% rename from cmd/appendkeyfile/main.go rename to external/cmd/helpers/appendkeyfile/main.go diff --git a/external/cmd/helpers/createkeyfile/createkeyfile b/external/cmd/helpers/createkeyfile/createkeyfile new file mode 100755 index 0000000..d5fdbf5 Binary files /dev/null and b/external/cmd/helpers/createkeyfile/createkeyfile differ diff --git a/cmd/createkeyfile/main.go b/external/cmd/helpers/createkeyfile/main.go similarity index 100% rename from cmd/createkeyfile/main.go rename to external/cmd/helpers/createkeyfile/main.go diff --git a/external/cmd/helpers/emailtouser/emailtouser b/external/cmd/helpers/emailtouser/emailtouser new file mode 100755 index 0000000..9d243ce Binary files /dev/null and b/external/cmd/helpers/emailtouser/emailtouser differ diff --git a/cmd/emailtouser/main.go b/external/cmd/helpers/emailtouser/main.go similarity index 100% rename from cmd/emailtouser/main.go rename to external/cmd/helpers/emailtouser/main.go diff --git a/cmd/registeruser/main.go b/external/cmd/helpers/registeruser/main.go similarity index 100% rename from cmd/registeruser/main.go rename to external/cmd/helpers/registeruser/main.go diff --git a/external/cmd/helpers/registeruser/registeruser b/external/cmd/helpers/registeruser/registeruser new file mode 100755 index 0000000..b23402a Binary files /dev/null and b/external/cmd/helpers/registeruser/registeruser differ diff --git a/cmd/signup/README.md b/external/cmd/signup/README.md similarity index 100% rename from cmd/signup/README.md rename to external/cmd/signup/README.md diff --git a/cmd/signup/main.go b/external/cmd/signup/main.go similarity index 100% rename from cmd/signup/main.go rename to external/cmd/signup/main.go diff --git a/external/cmd/signup/signup b/external/cmd/signup/signup new file mode 100755 index 0000000..2fdfd3b Binary files /dev/null and b/external/cmd/signup/signup differ diff --git a/cmd/signup/thoughts.md b/external/cmd/signup/thoughts.md similarity index 100% rename from cmd/signup/thoughts.md rename to external/cmd/signup/thoughts.md diff --git a/cmd/welcome/README.md b/external/cmd/welcome/README.md similarity index 100% rename from cmd/welcome/README.md rename to external/cmd/welcome/README.md diff --git a/cmd/welcome/form.go b/external/cmd/welcome/form.go similarity index 100% rename from cmd/welcome/form.go rename to external/cmd/welcome/form.go diff --git a/cmd/welcome/main.go b/external/cmd/welcome/main.go similarity index 100% rename from cmd/welcome/main.go rename to external/cmd/welcome/main.go diff --git a/external/cmd/welcome/welcome b/external/cmd/welcome/welcome new file mode 100755 index 0000000..e031aa4 Binary files /dev/null and b/external/cmd/welcome/welcome differ diff --git a/cmd/welcome/welcome.txt b/external/cmd/welcome/welcome.txt similarity index 100% rename from cmd/welcome/welcome.txt rename to external/cmd/welcome/welcome.txt diff --git a/external/lockingwriter/logger.go b/external/lockingwriter/logger.go new file mode 100644 index 0000000..ee87559 --- /dev/null +++ b/external/lockingwriter/logger.go @@ -0,0 +1,51 @@ +package lockingwriter + +import ( + "os" + "time" + + "github.com/gofrs/flock" +) + +// for now this package defines a writer for use with log.New(). It it intended to be used from the external ssh applications. This logger uses a file lock to allow all the various ssh applications to log to the same file. + +type LockingWriter struct { + path string +} + +const fp = "/town/var/log/external.log" + +func NewLockingWriter() *LockingWriter { + f, err := os.Create(fp) + if err != nil { + panic(err) + } + defer f.Close() + + return &LockingWriter{ + path: fp, + } +} + +func (l *LockingWriter) Write(p []byte) (n int, err error) { + fl := flock.New(l.path) + + var locked bool + for !locked { + locked, err = fl.TryLock() + if err != nil { + return + } + time.Sleep(time.Second) + } + var f *os.File + f, err = os.OpenFile(l.path, os.O_APPEND|os.O_WRONLY, 0600) + if err != nil { + return + } + + defer f.Close() + defer fl.Unlock() + + return f.Write(p) +} diff --git a/go.mod b/go.mod index a175d22..fad1bb5 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/charmbracelet/glamour v0.5.0 github.com/charmbracelet/lipgloss v0.6.0 github.com/gdamore/tcell/v2 v2.5.3 + github.com/gofrs/flock v0.8.1 github.com/mattn/go-sqlite3 v1.14.16 github.com/mattn/go-tty v0.0.5 github.com/rivo/tview v0.0.0-20230130130022-4a1b7a76c01c diff --git a/go.sum b/go.sum index 5ee8fbd..e946d2b 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,8 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.5.3 h1:b9XQrT6QGbgI7JvZOJXFNczOQeIYbo8BfeSMzt2sAV0= github.com/gdamore/tcell/v2 v2.5.3/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo= +github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=