Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
members: add multiuser profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Sep 25, 2023
1 parent d09e421 commit 8753e7b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 24 deletions.
2 changes: 2 additions & 0 deletions dev/runtime/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ member:
# multiuser:
# admin_password: "admin"
# user_password: "neko"
# admin_profile: # optional
# user_profile: # optional
# provider: "noauth"

session:
Expand Down
51 changes: 51 additions & 0 deletions internal/config/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand All @@ -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")
}
}
34 changes: 10 additions & 24 deletions internal/member/multiuser/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/member/multiuser/types.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 8753e7b

Please sign in to comment.