8000 Update chown webftp command by Apdul0329 · Pull Request #78 · alpacanetworks/alpamon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update chown webftp command #78

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 2 commits into from
May 29, 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
8 changes: 4 additions & 4 deletions pkg/runner/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (fc *FtpClient) handleFtpCommand(command FtpCommand, data FtpData) (Command
case Chmod:
return fc.chmod(data.Path, data.Mode, data.Recursive)
case Chown:
return fc.chown(data.Path, data.UID, data.GID, data.Recursive)
return fc.chown(data.Path, data.Username, data.Groupname, data.Recursive)
default:
return CommandResult{}, fmt.Errorf("unknown FTP command: %s", command)
}
Expand Down Expand Up @@ -500,17 +500,17 @@ func (fc *FtpClient) chmodRecursive(path string, fileMode os.FileMode) error {
})
}

func (fc *FtpClient) chown(path, uidStr, gidStr string, recursive bool) (CommandResult, error) {
func (fc *FtpClient) chown(path, username, groupname string, recursive bool) (CommandResult, error) {
path = fc.parsePath(path)

uid, err := strconv.Atoi(uidStr)
uid, err := utils.LookUpUID(username)
if err != nil {
return CommandResult{
Message: err.Error(),
}, err
}

gid, err := strconv.Atoi(gidStr)
gid, err := utils.LookUpGID(groupname)
if err != nil {
return CommandResult{
Message: err.Error(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/ftp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type FtpData struct {
Src string `json:"src,omitempty"`
Dst string `json:"dst,omitempty"`
Mode string `json:"mode,omitempty"`
UID string `json:"uid,omitempty"`
GID string `json:"gid,omitempty"`
Username string `json:"username,omitempty"`
Groupname string `json:"groupname,omitempty"`
}

type FtpContent struct {
Expand Down
35 changes: 31 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"bytes"
"context"
"fmt"
"github.com/alpacanetworks/alpamon/pkg/version"
"github.com/google/go-github/github"
"github.com/rs/zerolog/log"
"github.com/shirou/gopsutil/v4/host"
"net/url"
"os"
"os/user"
"regexp"
"runtime"
"strconv"
"strings"

"github.com/alpacanetworks/alpamon/pkg/version"
"github.com/google/go-github/github"
"github.com/rs/zerolog/log"
"github.com/shirou/gopsutil/v4/host"
)

var (
Expand Down Expand Up @@ -158,3 +159,29 @@ func GetLatestVersion() string {
func GetUserAgent(name string) string {
return fmt.Sprintf("%s/%s", name, version.Version)
}

func LookUpUID(username string) (int, error) {
if username == "" {
return -1, nil
}

usr, err := user.Lookup(username)
if err != nil {
return 0, err
}

return strconv.Atoi(usr.Uid)
}

func LookUpGID(groupname string) (int, error) {
if groupname == "" {
return -1, nil
}

group, err := user.LookupGroup(groupname)
if err != nil {
return 0, err
}

return strconv.Atoi(group.Gid)
}
Loading
0