diff --git a/dev/runtime/config.yml b/dev/runtime/config.yml index 235287a3..866cd941 100644 --- a/dev/runtime/config.yml +++ b/dev/runtime/config.yml @@ -99,6 +99,8 @@ member: # multiuser: # admin_password: "admin" # user_password: "neko" + # admin_profile: # optional + # user_profile: # optional # provider: "noauth" session: diff --git a/internal/config/member.go b/internal/config/member.go index ee27efb4..634ea2bd 100644 --- a/internal/config/member.go +++ b/internal/config/member.go @@ -8,6 +8,7 @@ import ( "github.com/demodesk/neko/internal/member/file" "github.com/demodesk/neko/internal/member/multiuser" "github.com/demodesk/neko/internal/member/object" + "github.com/demodesk/neko/pkg/types" "github.com/demodesk/neko/pkg/utils" ) @@ -49,6 +50,16 @@ func (Member) Init(cmd *cobra.Command) error { return err } + cmd.PersistentFlags().String("member.multiuser.user_profile", "{}", "member multiuser provider: user profile in JSON format") + if err := viper.BindPFlag("member.multiuser.user_profile", cmd.PersistentFlags().Lookup("member.multiuser.user_profile")); err != nil { + return err + } + + cmd.PersistentFlags().String("member.multiuser.admin_profile", "{}", "member multiuser provider: admin profile in JSON format") + if err := viper.BindPFlag("member.multiuser.admin_profile", cmd.PersistentFlags().Lookup("member.multiuser.admin_profile")); err != nil { + return err + } + return nil } @@ -68,4 +79,44 @@ func (s *Member) Set() { // multiuser provider s.Multiuser.UserPassword = viper.GetString("member.multiuser.user_password") s.Multiuser.AdminPassword = viper.GetString("member.multiuser.admin_password") + + // default user profile + s.Multiuser.UserProfile = types.MemberProfile{ + IsAdmin: false, + CanLogin: true, + CanConnect: true, + CanWatch: true, + CanHost: true, + CanShareMedia: true, + CanAccessClipboard: true, + SendsInactiveCursor: true, + CanSeeInactiveCursors: false, + } + + // override user profile + if err := viper.UnmarshalKey("member.multiuser.user_profile", &s.Multiuser.UserProfile, viper.DecodeHook( + utils.JsonStringAutoDecode(s.Multiuser.UserProfile), + )); err != nil { + log.Warn().Err(err).Msgf("unable to parse member multiuser user profile") + } + + // default admin profile + s.Multiuser.AdminProfile = types.MemberProfile{ + IsAdmin: true, + CanLogin: true, + CanConnect: true, + CanWatch: true, + CanHost: true, + CanShareMedia: true, + CanAccessClipboard: true, + SendsInactiveCursor: true, + CanSeeInactiveCursors: true, + } + + // override admin profile + if err := viper.UnmarshalKey("member.multiuser.admin_profile", &s.Multiuser.AdminProfile, viper.DecodeHook( + utils.JsonStringAutoDecode(s.Multiuser.AdminProfile), + )); err != nil { + log.Warn().Err(err).Msgf("unable to parse member multiuser admin profile") + } } diff --git a/internal/member/multiuser/provider.go b/internal/member/multiuser/provider.go index 915a19fe..aeb55f17 100644 --- a/internal/member/multiuser/provider.go +++ b/internal/member/multiuser/provider.go @@ -38,34 +38,20 @@ func (provider *MemberProviderCtx) Authenticate(username string, password string // if logged in as administrator if provider.config.AdminPassword == password { - return id, types.MemberProfile{ - Name: username, - IsAdmin: true, - CanLogin: true, - CanConnect: true, - CanWatch: true, - CanHost: true, - CanShareMedia: true, - CanAccessClipboard: true, - SendsInactiveCursor: true, - CanSeeInactiveCursors: true, - }, nil + profile := provider.config.AdminProfile + if profile.Name == "" { + profile.Name = username + } + return id, profile, nil } // if logged in as user if provider.config.UserPassword == password { - return id, types.MemberProfile{ - Name: username, - IsAdmin: false, - CanLogin: true, - CanConnect: true, - CanWatch: true, - CanHost: true, - CanShareMedia: true, - CanAccessClipboard: true, - SendsInactiveCursor: true, - CanSeeInactiveCursors: false, - }, nil + profile := provider.config.UserProfile + if profile.Name == "" { + profile.Name = username + } + return id, profile, nil } return "", types.MemberProfile{}, types.ErrMemberInvalidPassword diff --git a/internal/member/multiuser/types.go b/internal/member/multiuser/types.go index 4d6103d9..dfdedfb3 100644 --- a/internal/member/multiuser/types.go +++ b/internal/member/multiuser/types.go @@ -1,6 +1,10 @@ package multiuser +import "github.com/demodesk/neko/pkg/types" + type Config struct { AdminPassword string UserPassword string + AdminProfile types.MemberProfile + UserProfile types.MemberProfile }