Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/config/websocket.go

75 lines
2.3 KiB
Go
Raw Permalink Normal View History

2020-01-19 12:30:09 +13:00
package config
import (
2022-11-20 06:29:21 +13:00
"path/filepath"
2020-01-19 12:30:09 +13:00
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
type WebSocket struct {
Password string
AdminPassword string
2020-04-07 08:14:30 +12:00
Proxy bool
2021-11-17 11:00:24 +13:00
Locks []string
2021-11-17 11:48:40 +13:00
ControlProtection bool
2022-10-31 14:06:05 +13:00
2022-11-20 08:26:45 +13:00
FileTransferEnabled bool
FileTransferPath string
2020-01-19 12:30:09 +13:00
}
func (WebSocket) Init(cmd *cobra.Command) error {
2020-01-29 14:27:59 +13:00
cmd.PersistentFlags().String("password", "neko", "password for connecting to stream")
2020-01-19 12:30:09 +13:00
if err := viper.BindPFlag("password", cmd.PersistentFlags().Lookup("password")); err != nil {
return err
}
2020-04-05 13:24:54 +12:00
cmd.PersistentFlags().String("password_admin", "admin", "admin password for connecting to stream")
if err := viper.BindPFlag("password_admin", cmd.PersistentFlags().Lookup("password_admin")); err != nil {
2020-01-19 12:30:09 +13:00
return err
}
2020-04-07 08:14:30 +12:00
cmd.PersistentFlags().Bool("proxy", false, "enable reverse proxy mode")
if err := viper.BindPFlag("proxy", cmd.PersistentFlags().Lookup("proxy")); err != nil {
return err
}
2021-11-17 11:00:24 +13:00
cmd.PersistentFlags().StringSlice("locks", []string{}, "resources, that will be locked when starting (control, login)")
if err := viper.BindPFlag("locks", cmd.PersistentFlags().Lookup("locks")); err != nil {
return err
}
cmd.PersistentFlags().Bool("control_protection", false, "control protection means, users can gain control only if at least one admin is in the room")
2021-11-17 11:48:40 +13:00
if err := viper.BindPFlag("control_protection", cmd.PersistentFlags().Lookup("control_protection")); err != nil {
return err
}
2022-11-20 08:26:45 +13:00
// File transfer
2022-10-31 14:06:05 +13:00
2022-11-20 08:45:38 +13:00
cmd.PersistentFlags().Bool("file_transfer_enabled", false, "enable file transfer feature")
2022-11-20 08:26:45 +13:00
if err := viper.BindPFlag("file_transfer_enabled", cmd.PersistentFlags().Lookup("file_transfer_enabled")); err != nil {
2022-10-31 14:06:05 +13:00
return err
}
cmd.PersistentFlags().String("file_transfer_path", "/home/neko/Downloads", "path to use for file transfer")
if err := viper.BindPFlag("file_transfer_path", cmd.PersistentFlags().Lookup("file_transfer_path")); err != nil {
return err
}
2020-01-19 12:30:09 +13:00
return nil
}
func (s *WebSocket) Set() {
s.Password = viper.GetString("password")
2020-04-05 13:24:54 +12:00
s.AdminPassword = viper.GetString("password_admin")
2020-04-07 08:14:30 +12:00
s.Proxy = viper.GetBool("proxy")
2021-11-17 11:00:24 +13:00
s.Locks = viper.GetStringSlice("locks")
2021-11-17 11:48:40 +13:00
s.ControlProtection = viper.GetBool("control_protection")
2022-10-31 14:06:05 +13:00
2022-11-20 08:26:45 +13:00
s.FileTransferEnabled = viper.GetBool("file_transfer_enabled")
2022-10-31 14:06:05 +13:00
s.FileTransferPath = viper.GetString("file_transfer_path")
2022-11-20 06:29:21 +13:00
s.FileTransferPath = filepath.Clean(s.FileTransferPath)
2020-01-19 12:30:09 +13:00
}