(newWebshell *model.WebShellAllocRequest, oldWebshell *model.WebShellAllocRequest)
| 21 | } |
| 22 | |
| 23 | func UpdateWebShellState(newWebshell *model.WebShellAllocRequest, oldWebshell *model.WebShellAllocRequest) error { |
| 24 | |
| 25 | if newWebshell.WebShellID != oldWebshell.WebShellID { |
| 26 | if newWebshell.WebShellID != "" { |
| 27 | logrus.Infof("Start Webshell: %s", newWebshell.WebShellID) |
| 28 | port, err := utils.AllocTcpPort(key.SelfNode.L3AddrV4) |
| 29 | |
| 30 | if err != nil { |
| 31 | return fmt.Errorf("alloc tcp port error: %s", err.Error()) |
| 32 | } |
| 33 | logrus.Infof("Alloc Port: %d", port) |
| 34 | info, err := utils.StartWebShell( |
| 35 | utils.FormatIPv4(key.SelfNode.L3AddrV4), |
| 36 | port, |
| 37 | newWebshell.Writeable, |
| 38 | newWebshell.Command, |
| 39 | newWebshell.Args, |
| 40 | newWebshell.ExpireMinute, |
| 41 | func() { |
| 42 | err := synchronizer.DelGetWebshellInfo(key.NodeIndex, newWebshell.WebShellID) |
| 43 | if err != nil { |
| 44 | logrus.Errorf("delete webshell info error: %s", err.Error()) |
| 45 | } |
| 46 | err = synchronizer.DeleteWebshellRequest(key.NodeIndex, newWebshell.WebShellID) |
| 47 | if err != nil { |
| 48 | logrus.Errorf("delete webshell request error: %s", err.Error()) |
| 49 | } |
| 50 | }, |
| 51 | ) |
| 52 | if err != nil { |
| 53 | return fmt.Errorf("start webshell error: %s", err.Error()) |
| 54 | } |
| 55 | err = synchronizer.UpdateGetWebshellInfo(key.NodeIndex, newWebshell.WebShellID, &model.WebShellAllocInfo{ |
| 56 | WebShellID: newWebshell.WebShellID, |
| 57 | Addr: info.Addr, |
| 58 | Port: info.Port, |
| 59 | Pid: info.Pid, |
| 60 | }) |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("update webshell info error: %s", err.Error()) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | func webShellDaemonFunc(sigChan chan int, errChan chan error) { |
| 70 |
no outgoing calls
no test coverage detected