Пример #1
0
func (as *TcpServer) onAppDisconnected(ac *App) {
	delete(as.connMap, ac.conn)
	id := ac.id
	if id != "" {
		delete(as.appIdMap, id)
		m := &skynet.Pstring{
			Value: proto.String(id),
		}
		p, _ := skn.NewMessagePacket(0x0001, m)
		matrixClient.Write(p)
	}
	log.Printf("app: disconnected id=%s,addr=%s", id, ac.conn.RemoteAddr())
}
Пример #2
0
/*
URL: /matrix/cmd?agent=agent_addr&cmd=
send command to agent and run on agent machine
@param agent: addr of agent server
@param cmd: shell command to execute
*/
func (h *HttpServer) execAgentCmd(w http.ResponseWriter, r *http.Request) {
	addr := r.FormValue("agent")
	mutex.Lock()
	agent := tcpServer.FindAgentByAddr(addr)
	mutex.Unlock()
	if agent == nil {
		log.Printf("No agent of addr=%s\n", addr)
		return
	}
	cmd := r.FormValue("cmd")
	log.Printf("exec agent command - agent=%s,cmd=%s,\n", addr, cmd)
	p, err := net.NewMessagePacket(0x0020, &skynet.Pstring{Value: proto.String(cmd)})
	if err != nil {
		log.Println(err)
		return
	}
	agent.Write(p)
}