Add basic flags
This commit is contained in:
parent
94952b5766
commit
1bd41cad43
7 changed files with 28 additions and 5 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -18,10 +18,10 @@
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
# Executable
|
# Executable
|
||||||
hibiscus
|
hibiscus-txt
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Because currently it's used in "prod"
|
# Because currently it's used in "prod"
|
||||||
data/
|
data/
|
||||||
/config/log.txt
|
config/log.txt
|
1
TODO.md
1
TODO.md
|
@ -5,7 +5,6 @@ List of things to add to this project
|
||||||
* Check export function for improvements
|
* Check export function for improvements
|
||||||
* Add missing frontend pages
|
* Add missing frontend pages
|
||||||
* More slog.Debug?
|
* More slog.Debug?
|
||||||
* Make the CLI multi-functional - export to path, edit file etc.
|
|
||||||
* Think about timezones
|
* Think about timezones
|
||||||
* Consider more secure auth methods
|
* Consider more secure auth methods
|
||||||
* *Go* dependency-less? <-- this is a terrible idea
|
* *Go* dependency-less? <-- this is a terrible idea
|
1
auth.go
1
auth.go
|
@ -19,6 +19,7 @@ type failedLogin struct {
|
||||||
|
|
||||||
var failedLogins []failedLogin
|
var failedLogins []failedLogin
|
||||||
|
|
||||||
|
// NoteLoginFail attempts to counteract bruteforce/spam attacks
|
||||||
func NoteLoginFail(username string, password string, r *http.Request) {
|
func NoteLoginFail(username string, password string, r *http.Request) {
|
||||||
slog.Warn("failed auth", "username", username, "password", password, "address", r.RemoteAddr)
|
slog.Warn("failed auth", "username", username, "password", password, "address", r.RemoteAddr)
|
||||||
NotifyTelegram(fmt.Sprintf("Failed auth attempt in hibiscus:\nusername=%s\npassword=%s\nremote=%s", username, password, r.RemoteAddr))
|
NotifyTelegram(fmt.Sprintf("Failed auth attempt in hibiscus:\nusername=%s\npassword=%s\nremote=%s", username, password, r.RemoteAddr))
|
||||||
|
|
|
@ -23,7 +23,7 @@ func Export(filename string) error {
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
|
||||||
walker := func(path string, info os.FileInfo, err error) error {
|
walker := func(path string, info os.FileInfo, err error) error {
|
||||||
if path == filename { // Do not add export .zip itself
|
if path == filename || filepath.Ext(path) == ".zip" { //Ignore export file itself and .zip archives
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
slog.Debug("export crawling", "path", path)
|
slog.Debug("export crawling", "path", path)
|
||||||
|
|
22
flags.go
Normal file
22
flags.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FlagInit() {
|
||||||
|
username := flag.String("user", "", "override username")
|
||||||
|
password := flag.String("pass", "", "override password")
|
||||||
|
port := flag.Int("port", 0, "override port")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
if *username != "" {
|
||||||
|
Cfg.Username = *username
|
||||||
|
}
|
||||||
|
if *password != "" {
|
||||||
|
Cfg.Password = *password
|
||||||
|
}
|
||||||
|
if *port != 0 {
|
||||||
|
Cfg.Port = *port
|
||||||
|
}
|
||||||
|
}
|
1
main.go
1
main.go
|
@ -4,5 +4,6 @@ var Cfg = ConfigInit()
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
LogInit()
|
LogInit()
|
||||||
|
FlagInit()
|
||||||
Serve()
|
Serve()
|
||||||
}
|
}
|
||||||
|
|
2
serve.go
2
serve.go
|
@ -12,7 +12,7 @@ import (
|
||||||
func Serve() {
|
func Serve() {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes)
|
r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes)
|
||||||
r.Use(BasicAuth) // TODO: is this good enough?
|
r.Use(BasicAuth) // Is this good enough? Sure hope so
|
||||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
http.ServeFile(w, r, "./pages/error/404.html")
|
http.ServeFile(w, r, "./pages/error/404.html")
|
||||||
|
|
Loading…
Reference in a new issue