8000 Add moduser command to handle updates in user and membership by seowonnoh · Pull Request #81 · alpacanetworks/alpamon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add moduser command to handle updates in user and membership #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions pkg/runner/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func (cr *CommandRunner) handleInternalCmd() (int, string) {
return cr.delUser()
case "delgroup":
return cr.delGroup()
case "moduser":
return cr.modUser()
case "ping":
return 0, time.Now().Format(time.RFC3339)
//case "debug":
Expand Down Expand Up @@ -537,6 +539,38 @@ func (cr *CommandRunner) delGroup() (exitCode int, result string) {
return 0, "Successfully deleted the group."
}

func (cr *CommandRunner) modUser() (exitCode int, result string) {
data := modUserData{
Username: cr.data.Username,
Comment: cr.data.Comment,
}

err := cr.validateData(data)
if err != nil {
return 1, fmt.Sprintf("moduser: Not enough information. %s", err)
}

if utils.PlatformLike == "debian" || utils.PlatformLike == "rhel" {
exitCode, result = runCmdWithOutput(
[]string{
"/usr/sbin/usermod",
"--comment", data.Comment,
"-G", utils.JoinUint64s(cr.data.Groups),
data.Username,
},
"root", "", nil, 60,
)
if exitCode != 0 {
return exitCode, result
}
} else {
return 1, "Not implemented 'moduser' command for this platform."
}

cr.sync([]string{"groups", "users"})
return 0, "Successfully modified user information."
}

func (cr *CommandRunner) runFileUpload(fileName string) (exitCode int, result string) {
log.Debug().Msgf("Uploading file to %s. (username: %s, groupname: %s)", fileName, cr.data.Username, cr.data.Groupname)

Expand Down
5 changes: 5 additions & 0 deletions pkg/runner/command_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ type deleteGroupData struct {
Groupname string `validate:"required"`
}

type modUserData struct {
Username string `validate:"required"`
Comment string `validate:"required"`
}

type openPtyData struct {
SessionID string `validate:"required"`
URL string `validate:"required"`
Expand Down
0