Use config, improve README
This commit is contained in:
parent
2565a6f397
commit
a62901a790
5 changed files with 9 additions and 13 deletions
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
Simple plaintext diary.
|
Simple plaintext diary.
|
||||||
|
|
||||||
This project is *very* opinionated and minimal. It is designed primarily for myself.
|
This project is *very* opinionated and minimal, and is designed primarily for my usage.
|
||||||
|
As a result of this, it is also neither secure nor idiot-proof.
|
||||||
|
|
||||||
## Features:
|
## Features:
|
||||||
* Each day, you get a txt file. You have until 23:59 of that very day to finalise it.
|
* Each day, you get a txt file. You have until 23:59 of that very day to finalise it.
|
||||||
* At any moment, you can log a single line to the log
|
* At any moment, you can append a single line to log.txt
|
||||||
* You can save named notes to document milestones, big events, or just a nice game you played this month
|
* You can save named notes to document milestones, big events, or just a nice game you played this month
|
||||||
* You can easily export everything in a zip file for backups
|
* You can easily export everything in a zip file for backups
|
||||||
|
|
||||||
* Everything is in plain text. No databases, encryption, OAuth, or anything fancy. Even the password is plain te- wait is this a feature?
|
* Everything is plain(text) and simple. No databases, encryption, OAuth, or anything fancy. Even the password is plainte- *wait is this a feature?*
|
4
auth.go
4
auth.go
|
@ -17,8 +17,8 @@ func basicAuth(next http.Handler) http.Handler {
|
||||||
// Calculate SHA-256 hashes for equal length in ConstantTimeCompare
|
// Calculate SHA-256 hashes for equal length in ConstantTimeCompare
|
||||||
usernameHash := sha256.Sum256([]byte(username))
|
usernameHash := sha256.Sum256([]byte(username))
|
||||||
passwordHash := sha256.Sum256([]byte(password))
|
passwordHash := sha256.Sum256([]byte(password))
|
||||||
expectedUsernameHash := sha256.Sum256([]byte("test")) // TODO: put user & pass outside
|
expectedUsernameHash := sha256.Sum256([]byte(Cfg.Username))
|
||||||
expectedPasswordHash := sha256.Sum256([]byte("pass"))
|
expectedPasswordHash := sha256.Sum256([]byte(Cfg.Password))
|
||||||
|
|
||||||
usernameMatch := subtle.ConstantTimeCompare(usernameHash[:], expectedUsernameHash[:]) == 1
|
usernameMatch := subtle.ConstantTimeCompare(usernameHash[:], expectedUsernameHash[:]) == 1
|
||||||
passwordMatch := subtle.ConstantTimeCompare(passwordHash[:], expectedPasswordHash[:]) == 1
|
passwordMatch := subtle.ConstantTimeCompare(passwordHash[:], expectedPasswordHash[:]) == 1
|
||||||
|
|
|
@ -15,15 +15,11 @@ type Config struct {
|
||||||
Port int
|
Port int
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateConfig(config Config) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadConfig() (Config, error) {
|
func LoadConfig() (Config, error) {
|
||||||
filename := "config/config.txt"
|
filename := "config/config.txt"
|
||||||
|
|
||||||
if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
|
if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
|
||||||
CreateConfig(Config{})
|
log.Fatal(err)
|
||||||
return Config{}, err
|
return Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
port=7101
|
port=7101
|
||||||
username=test
|
username=test
|
||||||
password=pass
|
password=pass
|
||||||
export_code=hibiscus
|
|
2
files.go
2
files.go
|
@ -51,7 +51,7 @@ func PostFile(filename string, w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := f.Write(body); err != nil {
|
if _, err := f.Write(body); err != nil {
|
||||||
fmt.Println("Error writing to the file")
|
fmt.Println("error writing to the file")
|
||||||
w.Write([]byte("error writing to file"))
|
w.Write([]byte("error writing to file"))
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue