parent
c4b901e805
commit
253825768b
|
@ -0,0 +1,41 @@
|
|||
package town
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
)
|
||||
|
||||
const adminGroup = "admin"
|
||||
|
||||
func IsAdmin(u os.User) (bool, error) {
|
||||
adminGroup, err := user.LookupGroup(adminGroup)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get admin group info: %w", err)
|
||||
}
|
||||
|
||||
groupIds, err := u.GroupIds()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get groups info: %w", err)
|
||||
}
|
||||
|
||||
for _, groupId := range groupIds {
|
||||
if groupId == adminGroup.Gid {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func SendLocalEmail(username, subject, body string) error {
|
||||
cmd := exec.Command("/usr/sbin/sendmail", "-s", subject, username)
|
||||
cmd.Stdin = bytes.NewBufferString(body)
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errof("failed to send local email: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue