diff options
author | Emile <git@emile.space> | 2024-08-16 22:08:39 +0200 |
---|---|---|
committer | Emile <git@emile.space> | 2024-08-16 22:08:39 +0200 |
commit | 294659add1082f4a2333871f2a45fe0ec22fa2a7 (patch) | |
tree | 8f5fad5fe6d7c3fc57aea16bcc37c4cd3bcdeee4 /src | |
parent | 693fc4e8f92df17dd944755176d6fe34b0de40e3 (diff) |
flags
Diffstat (limited to 'src')
-rw-r--r-- | src/db.go | 2 | ||||
-rw-r--r-- | src/main.go | 21 | ||||
-rw-r--r-- | src/user.go | 7 |
3 files changed, 19 insertions, 11 deletions
diff --git a/src/db.go b/src/db.go index e36cf21..47d8158 100644 --- a/src/db.go +++ b/src/db.go @@ -112,7 +112,7 @@ type State struct { } func NewState() (*State, error) { - db, err := sql.Open("sqlite3", database_file) + db, err := sql.Open("sqlite3", databasePath) if err != nil { log.Println("Error opening the db: ", err) return nil, err diff --git a/src/main.go b/src/main.go index 6442aa8..22e5eb7 100644 --- a/src/main.go +++ b/src/main.go @@ -12,8 +12,10 @@ import ( var host string var port int +var logFilePath string +var databasePath string +var sessiondbPath string -const database_file string = "main.db" const salt = "oogha3AiH7taimohreeH8Lexoonea5zi" var ( @@ -21,10 +23,15 @@ var ( ) func initFlags() { - flag.StringVar(&host, "host", "127.0.0.1", "the host to listen on") - flag.StringVar(&host, "h", "127.0.0.1", "the host to listen on (shorthand)") - flag.IntVar(&port, "port", 8080, "the port to listen on") - flag.IntVar(&port, "p", 8080, "the port to listen on (shorthand)") + flag.StringVar(&host, "host", "127.0.0.1", "The host to listen on") + flag.StringVar(&host, "h", "127.0.0.1", "The host to listen on (shorthand)") + + flag.IntVar(&port, "port", 8080, "The port to listen on") + flag.IntVar(&port, "p", 8080, "The port to listen on (shorthand)") + + flag.StringVar(&logFilePath, "logfilepath", "./server.log", "The path to the log file") + flag.StringVar(&databasePath, "databasepath", "./main.db", "The path to the main database") + flag.StringVar(&sessiondbPath, "sessiondbpath", "./sesions.db", "The path to the session database") } func main() { @@ -33,7 +40,7 @@ func main() { // log init log.Println("[i] Setting up logging...") - logFile, err := os.OpenFile("server.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0664) + logFile, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0664) if err != nil { log.Fatal("Error opening the server.log file: ", err) } @@ -49,7 +56,7 @@ func main() { // session init log.Println("[i] Setting up Session Storage...") - store, err := NewSqliteStore("./sessions.db", "sessions", "/", 3600, []byte(os.Getenv("SESSION_KEY"))) + store, err := NewSqliteStore(sessiondbPath, "sessions", "/", 3600, []byte(os.Getenv("SESSION_KEY"))) if err != nil { panic(err) } diff --git a/src/user.go b/src/user.go index cc77657..04a9fd4 100644 --- a/src/user.go +++ b/src/user.go @@ -5,6 +5,7 @@ import ( "html/template" "log" "net/http" + "os" "strconv" "time" @@ -284,7 +285,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { // if we've got a password, hash it and compare it with the stored one if password != "" { - passwordHash := argon2.IDKey([]byte(password), []byte(salt), 1, 64*1024, 4, 32) + passwordHash := argon2.IDKey([]byte(password), []byte(os.Getenv("SALT")), 1, 64*1024, 4, 32) // check if it's valid valid := UserCheckPasswordHash(username, passwordHash) @@ -379,7 +380,7 @@ func registerHandler(w http.ResponseWriter, r *http.Request) { // if we've got a password, hash it and store it and create a User if password1 != "" { - passwordHash := argon2.IDKey([]byte(password1), []byte(salt), 1, 64*1024, 4, 32) + passwordHash := argon2.IDKey([]byte(password1), []byte(os.Getenv("SALT")), 1, 64*1024, 4, 32) _, err := UserRegister(username, passwordHash) if err != nil { @@ -630,7 +631,7 @@ func profileHandler(w http.ResponseWriter, r *http.Request) { // first update the password, as they might have also changed their // username if password1 != "" { - passwordHash := argon2.IDKey([]byte(password1), []byte(salt), 1, 64*1024, 4, 32) + passwordHash := argon2.IDKey([]byte(password1), []byte(os.Getenv("SALT")), 1, 64*1024, 4, 32) err := UserUpdatePasswordHash(orig_username, passwordHash) if err != nil { |