forked from tildetown/town
		
	rearrange things, add locking writer
This commit is contained in:
		
							parent
							
								
									69666edefa
								
							
						
					
					
						commit
						0764534fed
					
				
							
								
								
									
										1
									
								
								external/README.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								external/README.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										
											BIN
										
									
								
								external/cmd/help/help
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/help/help
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								external/cmd/helpers/appendkeyfile/appendkeyfile
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/helpers/appendkeyfile/appendkeyfile
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								external/cmd/helpers/createkeyfile/createkeyfile
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/helpers/createkeyfile/createkeyfile
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								external/cmd/helpers/emailtouser/emailtouser
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/helpers/emailtouser/emailtouser
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								external/cmd/helpers/registeruser/registeruser
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/helpers/registeruser/registeruser
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								external/cmd/signup/signup
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/signup/signup
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								external/cmd/welcome/welcome
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								external/cmd/welcome/welcome
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										51
									
								
								external/lockingwriter/logger.go
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								external/lockingwriter/logger.go
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -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) | ||||
| } | ||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								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 | ||||
|  | ||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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= | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user