members: add multiuser profile.

This commit is contained in:
Miroslav Šedivý 2023-09-25 18:28:05 +02:00
parent d09e421a51
commit 8753e7b69a
4 changed files with 67 additions and 24 deletions

View File

@ -99,6 +99,8 @@ member:
# multiuser:
# admin_password: "admin"
# user_password: "neko"
# admin_profile: # optional
# user_profile: # optional
# provider: "noauth"
session:

View File

@ -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")
}
}

View File

@ -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

View File

@ -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
}