Add to ssh.go the functionality that ctlrpc.go had.

This commit is contained in:
Mikkel Krautz 2011-11-11 20:28:40 +01:00
parent 69abacbb19
commit fa3770bffb

96
ssh.go
View file

@ -10,6 +10,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
) )
@ -71,7 +72,7 @@ func RunSSH() {
"Set a config value for the server with the given id") "Set a config value for the server with the given id")
RegisterSSHCmd("getconf", RegisterSSHCmd("getconf",
GetConfCmd, GetConfCmd,
"<id> <key> <value>", "<id> <key>",
"Get a config value for the server with the given id") "Get a config value for the server with the given id")
pemBytes, err := ioutil.ReadFile(filepath.Join(Args.DataDir, "key.pem")) pemBytes, err := ioutil.ReadFile(filepath.Join(Args.DataDir, "key.pem"))
@ -212,21 +213,108 @@ func HelpCmd(reply SshCmdReply, args []string) error {
} }
func StartServerCmd(reply SshCmdReply, args []string) error { func StartServerCmd(reply SshCmdReply, args []string) error {
if len(args) != 2 {
return errors.New("argument count mismatch")
}
serverId, err := strconv.Atoi64(args[1])
if err != nil {
return errors.New("bad server id")
}
server, exists := servers[serverId]
if !exists {
return errors.New("no such server")
}
_ = server
return errors.New("not implemented") return errors.New("not implemented")
} }
func StopServerCmd(reply SshCmdReply, args []string) error { func StopServerCmd(reply SshCmdReply, args []string) error {
if len(args) != 2 {
return errors.New("argument count mismatch")
}
serverId, err := strconv.Atoi64(args[1])
if err != nil {
return errors.New("bad server id")
}
server, exists := servers[serverId]
if !exists {
return errors.New("no such server")
}
_ = server
return errors.New("not implemented") return errors.New("not implemented")
} }
func SetSuperUserPasswordCmd(reply SshCmdReply, args []string) error { func SetSuperUserPasswordCmd(reply SshCmdReply, args []string) error {
return errors.New("not implemented") if len(args) != 3 {
return errors.New("argument count mismatch")
}
serverId, err := strconv.Atoi64(args[1])
if err != nil {
return errors.New("bad server id")
}
server, exists := servers[serverId]
if !exists {
return errors.New("no such server")
}
server.SetSuperUserPassword(args[2])
reply.WriteString(fmt.Sprintf("[%v] SuperUser password updated.\r\n", serverId))
return nil
} }
func SetConfCmd(reply SshCmdReply, args []string) error { func SetConfCmd(reply SshCmdReply, args []string) error {
return errors.New("not implemented") if len(args) != 4 {
return errors.New("argument count mismatch")
}
serverId, err := strconv.Atoi64(args[1])
if err != nil {
return errors.New("bad server id")
}
server, exists := servers[serverId]
if !exists {
return errors.New("no such server")
}
key := args[2]
value := args[3]
server.cfg.Set(key, value)
server.cfgUpdate <- &KeyValuePair{Key: key, Value: value}
reply.WriteString(fmt.Sprintf("[%v] %v = %v\r\n", serverId, key, value))
return nil
} }
func GetConfCmd(reply SshCmdReply, args []string) error { func GetConfCmd(reply SshCmdReply, args []string) error {
return errors.New("not implemented") if len(args) != 3 {
return errors.New("argument count mismatch")
}
serverId, err := strconv.Atoi64(args[1])
if err != nil {
return errors.New("bad server id")
}
server, exists := servers[serverId]
if !exists {
return errors.New("no such server")
}
key := args[2]
value := server.cfg.StringValue(key)
reply.WriteString(fmt.Sprintf("[%v] %v = %v\r\n", serverId, key, value))
return nil
} }