Fix issues caused by accessing clients via array identifier
This commit is contained in:
parent
85d5bfd1ca
commit
d07e6435fb
|
@ -76,6 +76,13 @@ func removeClient(c *gin.Context) {
|
|||
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
||||
return
|
||||
}
|
||||
client, err := returnClient(intClientID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
client.Instruct(Instructions{
|
||||
IsKillswitch: true,
|
||||
})
|
||||
log.Printf("Removing client %v\n", intClientID)
|
||||
if len(clientList) != 1 {
|
||||
clientList = append(clientList[:intClientID], clientList[intClientID+1:]...)
|
||||
|
@ -143,14 +150,19 @@ func execCMD(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if clientList[idInt].IsOnline == false {
|
||||
client, err := returnClient(idInt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if client.IsOnline == false {
|
||||
c.String(http.StatusOK, "Client is currently offline!")
|
||||
return
|
||||
}
|
||||
|
||||
command, _ := c.GetPostForm("cmd")
|
||||
|
||||
out, err := sendCommand(idInt, command)
|
||||
out, err := sendCommand(client, command)
|
||||
if err != nil {
|
||||
e := fmt.Sprintf("Error happened executing command: %v\n", err)
|
||||
c.String(http.StatusOK, e)
|
||||
|
|
|
@ -119,13 +119,13 @@ func handleConn(conn net.Conn) {
|
|||
go Heartbeat(ID)
|
||||
}
|
||||
|
||||
func sendCommand(ID int, command string) (Output string, err error) {
|
||||
func sendCommand(client Client, command string) (Output string, err error) {
|
||||
inst := Instructions{
|
||||
IsCommand: true,
|
||||
Message: command,
|
||||
}
|
||||
clientList[ID].Instruct(inst)
|
||||
resp, err := ServerMessageReceiver(clientList[ID].Conn)
|
||||
client.Instruct(inst)
|
||||
resp, err := ServerMessageReceiver(client.Conn)
|
||||
if err != nil || resp.Successful != true {
|
||||
e := fmt.Errorf("%v\n", resp.Message)
|
||||
return "", e
|
||||
|
@ -135,22 +135,24 @@ func sendCommand(ID int, command string) (Output string, err error) {
|
|||
|
||||
func Heartbeat(ID int) {
|
||||
for {
|
||||
if len(clientList) == 0 {
|
||||
client, err := returnClient(ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
inst := Instructions{
|
||||
IsHeartbeat: true,
|
||||
Message: "PING",
|
||||
}
|
||||
clientList[ID].Instruct(inst)
|
||||
resp, err := ServerMessageReceiver(clientList[ID].Conn)
|
||||
client.Instruct(inst)
|
||||
resp, err := ServerMessageReceiver(client.Conn)
|
||||
if err == nil && resp.Message == "PONG" {
|
||||
if clientList[ID].IsOnline != true {
|
||||
clientList[ID].IsOnline = true
|
||||
if client.IsOnline != true {
|
||||
client.IsOnline = true
|
||||
}
|
||||
} else {
|
||||
log.Printf("Client %v is offline :(\n", clientList[ID].ClientBasicInfo.Hostname)
|
||||
clientList[ID].IsOnline = false
|
||||
log.Printf("Client %v is offline :(\n", client.ClientBasicInfo.Hostname)
|
||||
client.IsOnline = false
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue