diff --git a/src/cmd/root.go b/src/cmd/root.go index cf73dbe..8c3b64d 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -9,6 +9,7 @@ import ( "github.com/aldinokemal/go-whatsapp-web-multidevice/utils" "github.com/dustin/go-humanize" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/basicauth" "github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/template/html" @@ -16,6 +17,7 @@ import ( _ "github.com/mattn/go-sqlite3" "log" "os" + "strings" "github.com/spf13/cobra" ) @@ -32,6 +34,7 @@ func init() { rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.PersistentFlags().StringVarP(&config.AppPort, "port", "p", config.AppPort, "change port number with --port | example: --port=8080") rootCmd.PersistentFlags().BoolVarP(&config.AppDebug, "debug", "d", config.AppDebug, "hide or displaying log with --debug | example: --debug=true") + rootCmd.PersistentFlags().StringVarP(&config.AppBasicAuthCredential, "basic-auth", "b", config.AppBasicAuthCredential, "basic auth credential | yourUsername:yourPassword") rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyMessage, "autoreply", "", config.WhatsappAutoReplyMessage, `auto reply when received message --autoreply | example: --autoreply="Don't reply this message"`) } @@ -75,6 +78,19 @@ func runRest(cmd *cobra.Command, args []string) { sendController := controllers.NewSendController(sendService) userController := controllers.NewUserController(userService) + if config.AppBasicAuthCredential != "" { + ba := strings.Split(config.AppBasicAuthCredential, ":") + if len(ba) != 2 { + log.Fatalln("Basic auth is not valid, please this following format :") + } + + app.Use(basicauth.New(basicauth.Config{ + Users: map[string]string{ + ba[0]: ba[1], + }, + })) + } + appController.Route(app) sendController.Route(app) userController.Route(app) diff --git a/src/config/settings.go b/src/config/settings.go index 8cdb3cb..4671306 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -8,11 +8,12 @@ import ( type Browser string var ( - AppVersion string = "v3.4.1" - AppPort string = "3000" - AppDebug bool = false - AppOs string = fmt.Sprintf("AldinoKemal") - AppPlatform waProto.DeviceProps_PlatformType = waProto.DeviceProps_PlatformType(1) + AppVersion string = "v3.5.0" + AppPort string = "3000" + AppDebug bool = false + AppOs string = fmt.Sprintf("AldinoKemal") + AppBasicAuthCredential string + AppPlatform waProto.DeviceProps_PlatformType = waProto.DeviceProps_PlatformType(1) PathQrCode string = "statics/qrcode" PathSendItems string = "statics/senditems"