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 | |
parent | 693fc4e8f92df17dd944755176d6fe34b0de40e3 (diff) |
flags
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | default.nix | 7 | ||||
l--------- | result | 1 | ||||
-rwxr-xr-x | run.sh | 2 | ||||
-rw-r--r-- | src/db.go | 2 | ||||
-rw-r--r-- | src/main.go | 21 | ||||
-rw-r--r-- | src/user.go | 7 |
7 files changed, 34 insertions, 13 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb254ae --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# r2wars + +If you want to clone from git.emile.space, you can do so like this: + +``` +git clone git://git.emile.space/r2wars-web.git +``` diff --git a/default.nix b/default.nix index dd888fa..c74f585 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import <nixpkgs> {}, lib }: +{ pkgs ? import <nixpkgs> {}, lib ? pkgs.lib, ... }: pkgs.buildGoModule rec { name = "r2wars-web-${version}"; @@ -9,6 +9,11 @@ pkgs.buildGoModule rec { CGO_ENABLED=0; + subPackages = [ "src" ]; + postInstall = '' + mv $out/bin/src $out/bin/r2wars-web + ''; + meta = { description = "A golang implementation of r2wars"; homepage = "https://r2wa.rs"; diff --git a/result b/result new file mode 120000 index 0000000..24ab111 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/qh5wr5nq2lm08457yxrhs0j8cbqnwddv-r2wars-web-1.0.0 \ No newline at end of file diff --git a/run.sh b/run.sh index a9628da..64b35c5 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ set +e -CGO_ENABLED=0 SESSION_KEY=aes1Itheich4aeQu9Ouz7ahcaiVoogh9 go run ./... +CGO_ENABLED=0 SESSION_KEY=aes1Itheich4aeQu9Ouz7ahcaiVoogh9 go run ./... -h "" 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 { |