mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-31 18:18:02 +01:00
connectmode, add stubs for export/setenv command
This commit is contained in:
parent
b2a2b6252d
commit
9d150dc7e3
@ -78,7 +78,7 @@ CREATE TABLE remote (
|
||||
remotesudo boolean NOT NULL,
|
||||
remoteuser varchar(50) NOT NULL,
|
||||
remotehost varchar(200) NOT NULL,
|
||||
autoconnect boolean NOT NULL,
|
||||
connectmode varchar(20) NOT NULL,
|
||||
initpk json NOT NULL,
|
||||
sshopts json NOT NULL,
|
||||
remoteopts json NOT NULL,
|
||||
|
@ -73,9 +73,10 @@ CREATE TABLE remote (
|
||||
remotesudo boolean NOT NULL,
|
||||
remoteuser varchar(50) NOT NULL,
|
||||
remotehost varchar(200) NOT NULL,
|
||||
autoconnect boolean NOT NULL,
|
||||
connectmode varchar(20) NOT NULL,
|
||||
initpk json NOT NULL,
|
||||
sshopts json NOT NULL,
|
||||
remoteopts json NOT NULL,
|
||||
lastconnectts bigint NOT NULL
|
||||
);
|
||||
CREATE TABLE cmd (
|
||||
|
@ -53,6 +53,8 @@ func SubMetaCmd(cmd string) string {
|
||||
return "comment"
|
||||
case "e":
|
||||
return "eval"
|
||||
case "export":
|
||||
return "setenv"
|
||||
default:
|
||||
return cmd
|
||||
}
|
||||
@ -66,6 +68,7 @@ var ValidCommands = []string{
|
||||
"/comment",
|
||||
"/cd",
|
||||
"/compgen",
|
||||
"/setenv",
|
||||
}
|
||||
|
||||
func HandleCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
@ -94,6 +97,9 @@ func HandleCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
|
||||
case "compgen":
|
||||
return CompGenCommand(ctx, pk)
|
||||
|
||||
case "setenv":
|
||||
return SetEnvCommand(ctx, pk)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid command '/%s', no handler", pk.MetaCmd)
|
||||
}
|
||||
@ -338,6 +344,12 @@ func evalCommandInternal(ctx context.Context, pk *scpacket.FeCommandPacketType)
|
||||
} else if commandStr == "cr" || strings.HasPrefix(commandStr, "cr ") {
|
||||
metaCmd = "cr"
|
||||
commandStr = strings.TrimSpace(commandStr[2:])
|
||||
} else if commandStr == "export" || strings.HasPrefix(commandStr, "export ") {
|
||||
metaCmd = "setenv"
|
||||
commandStr = strings.TrimSpace(commandStr[6:])
|
||||
} else if commandStr == "setenv" || strings.HasPrefix(commandStr, "setenv ") {
|
||||
metaCmd = "setenv"
|
||||
commandStr = strings.TrimSpace(commandStr[6:])
|
||||
} else if commandStr[0] == '/' {
|
||||
spaceIdx := strings.Index(commandStr, " ")
|
||||
if spaceIdx == -1 {
|
||||
@ -425,6 +437,10 @@ func ScreenCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
|
||||
return update, nil
|
||||
}
|
||||
|
||||
func SetEnvCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CrCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
ids, err := resolveIds(ctx, pk, R_Session|R_Window)
|
||||
if err != nil {
|
||||
|
@ -62,7 +62,7 @@ type RemoteState struct {
|
||||
Status string `json:"status"`
|
||||
ErrorStr string `json:"errorstr,omitempty"`
|
||||
DefaultState *sstore.RemoteState `json:"defaultstate"`
|
||||
AutoConnect bool `json:"autoconnect"`
|
||||
ConnectMode string `json:"connectmode"`
|
||||
}
|
||||
|
||||
type MShellProc struct {
|
||||
@ -91,7 +91,7 @@ func LoadRemotes(ctx context.Context) error {
|
||||
for _, remote := range allRemotes {
|
||||
msh := MakeMShell(remote)
|
||||
GlobalStore.Map[remote.RemoteId] = msh
|
||||
if remote.AutoConnect {
|
||||
if remote.ConnectMode == sstore.ConnectModeStartup {
|
||||
go msh.Launch()
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ func GetAllRemoteState() []RemoteState {
|
||||
RemoteCanonicalName: proc.Remote.RemoteCanonicalName,
|
||||
PhysicalId: proc.Remote.PhysicalId,
|
||||
Status: proc.Status,
|
||||
AutoConnect: proc.Remote.AutoConnect,
|
||||
ConnectMode: proc.Remote.ConnectMode,
|
||||
}
|
||||
if proc.Err != nil {
|
||||
state.ErrorStr = proc.Err.Error()
|
||||
|
@ -90,8 +90,8 @@ func InsertRemote(ctx context.Context, remote *RemoteType) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query := `INSERT INTO remote ( remoteid, physicalid, remotetype, remotealias, remotecanonicalname, remotesudo, remoteuser, remotehost, autoconnect, initpk, sshopts, remoteopts, lastconnectts) VALUES
|
||||
(:remoteid,:physicalid,:remotetype,:remotealias,:remotecanonicalname,:remotesudo,:remoteuser,:remotehost,:autoconnect,:initpk,:sshopts,:remoteopts,:lastconnectts)`
|
||||
query := `INSERT INTO remote ( remoteid, physicalid, remotetype, remotealias, remotecanonicalname, remotesudo, remoteuser, remotehost, connectmode, initpk, sshopts, remoteopts, lastconnectts) VALUES
|
||||
(:remoteid,:physicalid,:remotetype,:remotealias,:remotecanonicalname,:remotesudo,:remoteuser,:remotehost,:connectmode,:initpk,:sshopts,:remoteopts,:lastconnectts)`
|
||||
_, err = db.NamedExec(query, remote.ToMap())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -50,6 +50,16 @@ const (
|
||||
ShareModeShared = "shared"
|
||||
)
|
||||
|
||||
const (
|
||||
ConnectModeStartup = "startup"
|
||||
ConnectModeAuto = "auto"
|
||||
ConnectModeManual = "manual"
|
||||
)
|
||||
|
||||
const (
|
||||
RemoteTypeSsh = "ssh"
|
||||
)
|
||||
|
||||
var globalDBLock = &sync.Mutex{}
|
||||
var globalDB *sqlx.DB
|
||||
var globalDBErr error
|
||||
@ -298,7 +308,7 @@ type RemoteType struct {
|
||||
RemoteSudo bool `json:"remotesudo"`
|
||||
RemoteUser string `json:"remoteuser"`
|
||||
RemoteHost string `json:"remotehost"`
|
||||
AutoConnect bool `json:"autoconnect"`
|
||||
ConnectMode string `json:"connectmode"`
|
||||
InitPk *packet.InitPacketType `json:"inipk"`
|
||||
SSHOpts *SSHOpts `json:"sshopts"`
|
||||
RemoteOpts *RemoteOptsType `json:"remoteopts"`
|
||||
@ -340,7 +350,7 @@ func (r *RemoteType) ToMap() map[string]interface{} {
|
||||
rtn["remotesudo"] = r.RemoteSudo
|
||||
rtn["remoteuser"] = r.RemoteUser
|
||||
rtn["remotehost"] = r.RemoteHost
|
||||
rtn["autoconnect"] = r.AutoConnect
|
||||
rtn["connectmode"] = r.ConnectMode
|
||||
rtn["initpk"] = quickJson(r.InitPk)
|
||||
rtn["sshopts"] = quickJson(r.SSHOpts)
|
||||
rtn["remoteopts"] = quickJson(r.RemoteOpts)
|
||||
@ -361,7 +371,7 @@ func RemoteFromMap(m map[string]interface{}) *RemoteType {
|
||||
quickSetBool(&r.RemoteSudo, m, "remotesudo")
|
||||
quickSetStr(&r.RemoteUser, m, "remoteuser")
|
||||
quickSetStr(&r.RemoteHost, m, "remotehost")
|
||||
quickSetBool(&r.AutoConnect, m, "autoconnect")
|
||||
quickSetStr(&r.ConnectMode, m, "connectmode")
|
||||
quickSetJson(&r.InitPk, m, "initpk")
|
||||
quickSetJson(&r.SSHOpts, m, "sshopts")
|
||||
quickSetJson(&r.RemoteOpts, m, "remoteopts")
|
||||
@ -470,13 +480,13 @@ func EnsureLocalRemote(ctx context.Context) error {
|
||||
localRemote := &RemoteType{
|
||||
RemoteId: uuid.New().String(),
|
||||
PhysicalId: physicalId,
|
||||
RemoteType: "ssh",
|
||||
RemoteType: RemoteTypeSsh,
|
||||
RemoteAlias: LocalRemoteName,
|
||||
RemoteCanonicalName: fmt.Sprintf("%s@%s", user.Username, hostName),
|
||||
RemoteSudo: false,
|
||||
RemoteUser: user.Username,
|
||||
RemoteHost: hostName,
|
||||
AutoConnect: true,
|
||||
ConnectMode: ConnectModeStartup,
|
||||
}
|
||||
err = InsertRemote(ctx, localRemote)
|
||||
if err != nil {
|
||||
@ -496,7 +506,7 @@ func AddTest01Remote(ctx context.Context) error {
|
||||
}
|
||||
testRemote := &RemoteType{
|
||||
RemoteId: uuid.New().String(),
|
||||
RemoteType: "ssh",
|
||||
RemoteType: RemoteTypeSsh,
|
||||
RemoteAlias: "test01",
|
||||
RemoteCanonicalName: "ubuntu@test01.ec2",
|
||||
RemoteSudo: false,
|
||||
@ -507,7 +517,7 @@ func AddTest01Remote(ctx context.Context) error {
|
||||
SSHUser: "ubuntu",
|
||||
SSHIdentity: "/Users/mike/aws/mfmt.pem",
|
||||
},
|
||||
AutoConnect: true,
|
||||
ConnectMode: ConnectModeStartup,
|
||||
}
|
||||
err = InsertRemote(ctx, testRemote)
|
||||
if err != nil {
|
||||
@ -527,7 +537,7 @@ func AddTest02Remote(ctx context.Context) error {
|
||||
}
|
||||
testRemote := &RemoteType{
|
||||
RemoteId: uuid.New().String(),
|
||||
RemoteType: "ssh",
|
||||
RemoteType: RemoteTypeSsh,
|
||||
RemoteAlias: "test2",
|
||||
RemoteCanonicalName: "test2@test01.ec2",
|
||||
RemoteSudo: false,
|
||||
@ -537,7 +547,7 @@ func AddTest02Remote(ctx context.Context) error {
|
||||
SSHHost: "test01.ec2",
|
||||
SSHUser: "test2",
|
||||
},
|
||||
AutoConnect: true,
|
||||
ConnectMode: ConnectModeStartup,
|
||||
}
|
||||
err = InsertRemote(ctx, testRemote)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user