40 lines
616 B
Go
40 lines
616 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func ShellJail(args []string) error {
|
|
var jailnames []string
|
|
if len(args) > 0 {
|
|
for _, a := range args {
|
|
jailnames = append(jailnames, a)
|
|
}
|
|
}
|
|
|
|
for _, cj := range gJails {
|
|
for _, jn := range jailnames {
|
|
if strings.EqualFold(cj.Name, jn) {
|
|
err := shellJail(cj)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func shellJail(jail Jail) error {
|
|
cmd := fmt.Sprintf("jexec %s /bin/csh", jail.JID)
|
|
_, err := executeCommand(cmd)
|
|
if err != nil {
|
|
fmt.Errorf("Error executing %s: %s", cmd, err.Error())
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|