Remove accounts.json

Added two arguments cli gui-username and gui-password
This commit is contained in:
gunter423 2024-02-16 19:48:02 +01:00
parent 21c689768c
commit 554a6e7ff3
11 changed files with 25 additions and 36 deletions

View File

@ -42,18 +42,6 @@ $ chaturbate-dvr -u CHANNEL_USERNAME
 
**🔒 Restrict access page**
If you want to restrict access to the page using a username and password, add this to the accounts.json file
```json
{
"john.doe": "password"
}
```
 
## Preview
![image_1](https://github.com/teacat/chaturbate-dvr/assets/7308718/c6d17ffe-eba7-4296-9315-f501489d85f3)
@ -107,6 +95,8 @@ COMMANDS:
GLOBAL OPTIONS:
--username value, -u value channel username to record.
--gui-username value, --gui-u value username for auth web.
--gui-password value, --gui-p value password for auth web.
--framerate value, -f value preferred framerate. (default: 30)
--resolution value, -r value preferred resolution (default: 1080)
--resolution-fallback value, --rf value fallback to 'up' (larger) or 'down' (smaller) resolution if preferred resolution is not available (default: "down")

View File

@ -1 +0,0 @@
{}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,8 @@ services:
build:
context: .
dockerfile: web.Dockerfile
environment:
- GUI_USERNAME=johndoe
- GUI_PASSWORD=password
ports:
- "8080:8080"
volumes:
- ./accounts.json:/usr/src/app/accounts.json
- "8080:8080"

37
main.go
View File

@ -2,7 +2,6 @@ package main
import (
"embed"
"encoding/json"
"fmt"
"io/fs"
"log"
@ -41,6 +40,18 @@ func main() {
Usage: "channel username to record.",
Value: "",
},
&cli.StringFlag{
Name: "gui-username",
Aliases: []string{"gui-u"},
Usage: "username for auth web.",
Value: "",
},
&cli.StringFlag{
Name: "gui-password",
Aliases: []string{"gui-p"},
Usage: "password for auth web.",
Value: "",
},
&cli.IntFlag{
Name: "framerate",
Aliases: []string{"f"},
@ -127,21 +138,6 @@ func start(c *cli.Context) error {
//go:embed handler/view
var FS embed.FS
func listAccounts() gin.Accounts {
b, err := os.ReadFile("accounts.json")
if err != nil {
if os.IsNotExist(err) {
return nil
}
return nil
}
var configs gin.Accounts
if err := json.Unmarshal(b, &configs); err != nil {
return nil
}
return configs
}
func startWeb(c *cli.Context) error {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
@ -157,13 +153,16 @@ func startWeb(c *cli.Context) error {
log.Fatalln(err)
}
accounts := listAccounts()
guiUsername := c.String("gui-username")
guiPassword := c.String("gui-password")
var authorized = r.Group("/")
var authorizedApi = r.Group("/api")
if len(accounts) > 0 {
ginBasicAuth := gin.BasicAuth(accounts)
if guiUsername != "" && guiPassword != "" {
ginBasicAuth := gin.BasicAuth(gin.Accounts{
guiUsername: guiPassword,
})
authorized.Use(ginBasicAuth)
authorizedApi.Use(ginBasicAuth)
}

View File

@ -8,4 +8,4 @@ RUN go mod download && go mod verify
COPY . .
RUN go build
CMD [ "sh", "-c", "./chaturbate-dvr" ]
CMD [ "sh", "-c", "./chaturbate-dvr -gui-username ${GUI_USERNAME} -gui-password ${GUI_PASSWORD}" ]