diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..55f5727 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +## +## ---------------------------------------------------------------------------- +## Docker +## ---------------------------------------------------------------------------- +## + +docker-start-chaturbate-dvr: ## Start docker Chaturbate DVR + docker-compose -f docker-compose.yml up -d + +docker-stop-chaturbate-dvr: ## Stop docker Chaturbate DVR + docker-compose -f docker-compose.yml down + +docker-restart-chaturbate-dvr: ## Restart project Chaturbate DVR + docker-compose -f docker-compose.yml restart + +docker-start-chaturbate-dvr-web: ## Start docker Chaturbate DVR WEB + docker-compose -f docker-compose-web.yml up -d + +docker-stop-chaturbate-dvr-web: ## Stop docker Chaturbate DVR WEB + docker-compose -f docker-compose-web.yml down + +docker-restart-chaturbate-dvr-web: ## Restart project Chaturbate DVR WEB + docker-compose -f docker-compose-web.yml restart + +.PHONY: docker-start-chaturbate-dvr docker-stop-chaturbate-dvr docker-restart-chaturbate-dvr docker-start-chaturbate-dvr-web docker-stop-chaturbate-dvr-web docker-restart-chaturbate-dvr-web + +## +## ---------------------------------------------------------------------------- +## Compile +## ---------------------------------------------------------------------------- +## + +64bit-windows-macos-linux: ## Compile all arch amd64 + GOOS=windows GOARCH=amd64 go build -o bin/windows/chatubrate-dvr.exe && \ + GOOS=darwin GOARCH=amd64 go build -o bin/darwin/chatubrate-dvr && \ + GOOS=linux GOARCH=amd64 go build -o bin/linux/chatubrate-dvr + +arm64-windows-macos-linux: ## Compile all arch arm64 + GOOS=windows GOARCH=arm64 go build -o bin/arm64/windows/chatubrate-dvr.exe && \ + GOOS=darwin GOARCH=arm64 go build -o bin/arm64/darwin/chatubrate-dvr && \ + GOOS=linux GOARCH=arm64 go build -o bin/arm64/linux/chatubrate-dvr + +compile-all: ## Compile all + GOOS=windows GOARCH=amd64 go build -o bin/windows/chatubrate-dvr.exe && \ + GOOS=darwin GOARCH=amd64 go build -o bin/darwin/chatubrate-dvr && \ + GOOS=linux GOARCH=amd64 go build -o bin/linux/chatubrate-dvr && \ + GOOS=windows GOARCH=arm64 go build -o bin/arm64/windows/chatubrate-dvr.exe && \ + GOOS=darwin GOARCH=arm64 go build -o bin/arm64/darwin/chatubrate-dvr && \ + GOOS=linux GOARCH=arm64 go build -o bin/arm64/linux/chatubrate-dvr + +.PHONY: 64bit-windows-macos-linux arm64-windows-macos-linux + +## +## ---------------------------------------------------------------------------- +## Help +## ---------------------------------------------------------------------------- +## + +.DEFAULT_GOAL := help +.PHONY: help +help: ## Show this help + @egrep -h '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' \ + | sed -e 's/\[32m##/[33m/' \ No newline at end of file diff --git a/README.md b/README.md index b0460bb..2d4cb4c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,18 @@ $ 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) diff --git a/accounts.json b/accounts.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/accounts.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/bin/arm64/darwin/chatubrate-dvr b/bin/arm64/darwin/chatubrate-dvr old mode 100644 new mode 100755 index 924fe02..6bfa599 Binary files a/bin/arm64/darwin/chatubrate-dvr and b/bin/arm64/darwin/chatubrate-dvr differ diff --git a/bin/arm64/linux/chatubrate-dvr b/bin/arm64/linux/chatubrate-dvr old mode 100644 new mode 100755 index 56745e4..c2099c8 Binary files a/bin/arm64/linux/chatubrate-dvr and b/bin/arm64/linux/chatubrate-dvr differ diff --git a/bin/arm64/windows/chatubrate-dvr.exe b/bin/arm64/windows/chatubrate-dvr.exe old mode 100644 new mode 100755 index 5299c43..757e1ee Binary files a/bin/arm64/windows/chatubrate-dvr.exe and b/bin/arm64/windows/chatubrate-dvr.exe differ diff --git a/bin/darwin/chatubrate-dvr b/bin/darwin/chatubrate-dvr old mode 100644 new mode 100755 index 191f6c1..07d05b0 Binary files a/bin/darwin/chatubrate-dvr and b/bin/darwin/chatubrate-dvr differ diff --git a/bin/linux/chatubrate-dvr b/bin/linux/chatubrate-dvr old mode 100644 new mode 100755 index a231b5e..fc0d55f Binary files a/bin/linux/chatubrate-dvr and b/bin/linux/chatubrate-dvr differ diff --git a/bin/windows/chatubrate-dvr.exe b/bin/windows/chatubrate-dvr.exe old mode 100644 new mode 100755 index 5e0a86d..468f978 Binary files a/bin/windows/chatubrate-dvr.exe and b/bin/windows/chatubrate-dvr.exe differ diff --git a/docker-compose-web.yml b/docker-compose-web.yml new file mode 100644 index 0000000..7fa9b7c --- /dev/null +++ b/docker-compose-web.yml @@ -0,0 +1,12 @@ +version: "3.0" + +services: + chaturbate-dvr-web: + container_name: chaturbate-dvr-web + build: + context: . + dockerfile: web.Dockerfile + ports: + - "8080:8080" + volumes: + - ./accounts.json:/usr/src/app/accounts.json \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0ae7cae..4c217e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,10 @@ version: "3.0" services: - chaturbate-dvr: - build: . - environment: - - USERNAME=CHANNEL_USERNAME - volumes: - - ./videos:/usr/src/app/videos + chaturbate-dvr: + container_name: chaturbate-dvr + build: . + environment: + - USERNAME=CHANNEL_USERNAME + volumes: + - ./videos:/usr/src/app/videos diff --git a/main.go b/main.go index 461a308..5122ffc 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "embed" + "encoding/json" "fmt" "io/fs" "log" @@ -126,6 +127,21 @@ 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() @@ -140,18 +156,30 @@ func startWeb(c *cli.Context) error { if err != nil { log.Fatalln(err) } - r.StaticFS("/static", http.FS(fe)) - r.StaticFileFS("/", "/", http.FS(fe)) - r.POST("/api/get_channel", handler.NewGetChannelHandler(m, c).Handle) - r.POST("/api/create_channel", handler.NewCreateChannelHandler(m, c).Handle) - r.POST("/api/list_channels", handler.NewListChannelsHandler(m, c).Handle) - r.POST("/api/delete_channel", handler.NewDeleteChannelHandler(m, c).Handle) - r.POST("/api/pause_channel", handler.NewPauseChannelHandler(m, c).Handle) - r.POST("/api/resume_channel", handler.NewResumeChannelHandler(m, c).Handle) - r.GET("/api/listen_update", handler.NewListenUpdateHandler(m, c).Handle) - r.POST("/api/get_settings", handler.NewGetSettingsHandler(c).Handle) - r.POST("/api/terminate_program", handler.NewTerminateProgramHandler(c).Handle) + accounts := listAccounts() + + var authorized = r.Group("/") + var authorizedApi = r.Group("/api") + + if len(accounts) > 0 { + ginBasicAuth := gin.BasicAuth(accounts) + authorized.Use(ginBasicAuth) + authorizedApi.Use(ginBasicAuth) + } + + authorized.StaticFS("/static", http.FS(fe)) + authorized.StaticFileFS("/", "/", http.FS(fe)) + + authorizedApi.POST("/get_channel", handler.NewGetChannelHandler(m, c).Handle) + authorizedApi.POST("/create_channel", handler.NewCreateChannelHandler(m, c).Handle) + authorizedApi.POST("/list_channels", handler.NewListChannelsHandler(m, c).Handle) + authorizedApi.POST("/delete_channel", handler.NewDeleteChannelHandler(m, c).Handle) + authorizedApi.POST("/pause_channel", handler.NewPauseChannelHandler(m, c).Handle) + authorizedApi.POST("/resume_channel", handler.NewResumeChannelHandler(m, c).Handle) + authorizedApi.GET("/listen_update", handler.NewListenUpdateHandler(m, c).Handle) + authorizedApi.POST("/get_settings", handler.NewGetSettingsHandler(c).Handle) + authorizedApi.POST("/terminate_program", handler.NewTerminateProgramHandler(c).Handle) fmt.Printf("👋 Visit http://localhost:%s to use the Web UI\n", c.String("port")) diff --git a/web.Dockerfile b/web.Dockerfile new file mode 100644 index 0000000..c256c0b --- /dev/null +++ b/web.Dockerfile @@ -0,0 +1,11 @@ +FROM golang:latest + +WORKDIR /usr/src/app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . +RUN go build + +CMD [ "sh", "-c", "./chaturbate-dvr" ] \ No newline at end of file