2018-07-13 17:53:34 +08:00
|
|
|
|
/************************************************************
|
|
|
|
|
|
** @Description: controllers
|
|
|
|
|
|
** @Author: haodaquan
|
|
|
|
|
|
** @Date: 2018-06-09 16:11
|
2019-02-18 00:03:35 +08:00
|
|
|
|
** @Last Modified by: Bee
|
|
|
|
|
|
** @Last Modified time: 2019-02-17 22:15:15
|
2018-07-13 17:53:34 +08:00
|
|
|
|
*************************************************************/
|
2017-08-17 11:49:53 +08:00
|
|
|
|
package controllers
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2019-07-03 22:31:27 +08:00
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
|
|
|
"github.com/george518/PPGo_Job/libs"
|
2017-08-17 11:49:53 +08:00
|
|
|
|
"github.com/george518/PPGo_Job/models"
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type ServerController struct {
|
|
|
|
|
|
BaseController
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
func (self *ServerController) List() {
|
2019-07-03 22:31:27 +08:00
|
|
|
|
self.Data["pageTitle"] = "执行资源管理"
|
2019-03-19 19:43:45 +08:00
|
|
|
|
self.Data["serverGroup"] = serverGroupLists(self.serverGroups, self.userId)
|
2018-07-13 17:53:34 +08:00
|
|
|
|
self.display()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (self *ServerController) Add() {
|
2019-07-03 22:31:27 +08:00
|
|
|
|
self.Data["pageTitle"] = "新增执行资源"
|
2018-07-13 17:53:34 +08:00
|
|
|
|
self.Data["serverGroup"] = serverGroupLists(self.serverGroups, self.userId)
|
|
|
|
|
|
self.display()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (self *ServerController) GetServerByGroupId() {
|
|
|
|
|
|
gid, _ := self.GetInt("gid", 0)
|
|
|
|
|
|
if gid == 0 {
|
|
|
|
|
|
self.ajaxMsg("groupId is not exist", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//列表
|
|
|
|
|
|
page, err := self.GetInt("page")
|
|
|
|
|
|
if err != nil {
|
2017-08-17 11:49:53 +08:00
|
|
|
|
page = 1
|
|
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
limit, err := self.GetInt("limit")
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
limit = 30
|
|
|
|
|
|
}
|
|
|
|
|
|
//serverName := strings.TrimSpace(self.GetString("serverName"))
|
|
|
|
|
|
StatusText := []string{
|
|
|
|
|
|
"正常",
|
|
|
|
|
|
"<font color='red'>禁用</font>",
|
|
|
|
|
|
}
|
2017-08-17 11:49:53 +08:00
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
loginType := [2]string{
|
|
|
|
|
|
"密码",
|
|
|
|
|
|
"密钥",
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
serverGroup := serverGroupLists(self.serverGroups, self.userId)
|
|
|
|
|
|
|
|
|
|
|
|
self.pageSize = limit
|
|
|
|
|
|
//查询条件
|
|
|
|
|
|
filters := make([]interface{}, 0)
|
|
|
|
|
|
filters = append(filters, "status", 0)
|
|
|
|
|
|
filters = append(filters, "group_id", gid)
|
|
|
|
|
|
|
|
|
|
|
|
result, count := models.TaskServerGetList(page, self.pageSize, filters...)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
list := make([]map[string]interface{}, len(result))
|
|
|
|
|
|
for k, v := range result {
|
|
|
|
|
|
row := make(map[string]interface{})
|
|
|
|
|
|
row["id"] = v.Id
|
2019-02-18 00:03:35 +08:00
|
|
|
|
row["connection_type"] = v.ConnectionType
|
2017-08-17 11:49:53 +08:00
|
|
|
|
row["server_name"] = v.ServerName
|
|
|
|
|
|
row["detail"] = v.Detail
|
2018-07-13 17:53:34 +08:00
|
|
|
|
if serverGroup[v.GroupId] == "" {
|
|
|
|
|
|
v.GroupId = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
row["group_name"] = serverGroup[v.GroupId]
|
|
|
|
|
|
row["type"] = loginType[v.Type]
|
|
|
|
|
|
row["status"] = v.Status
|
|
|
|
|
|
row["status_text"] = StatusText[v.Status]
|
2017-08-17 11:49:53 +08:00
|
|
|
|
list[k] = row
|
|
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
|
|
|
|
|
|
self.ajaxList("成功", MSG_OK, count, list)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
func (self *ServerController) Edit() {
|
2019-07-03 22:31:27 +08:00
|
|
|
|
self.Data["pageTitle"] = "编辑执行资源"
|
2018-07-13 17:53:34 +08:00
|
|
|
|
|
|
|
|
|
|
id, _ := self.GetInt("id", 0)
|
|
|
|
|
|
server, _ := models.TaskServerGetById(id)
|
|
|
|
|
|
row := make(map[string]interface{})
|
|
|
|
|
|
row["id"] = server.Id
|
2019-02-18 00:03:35 +08:00
|
|
|
|
row["connection_type"] = server.ConnectionType
|
2018-07-13 17:53:34 +08:00
|
|
|
|
row["server_name"] = server.ServerName
|
|
|
|
|
|
row["group_id"] = server.GroupId
|
|
|
|
|
|
row["server_ip"] = server.ServerIp
|
|
|
|
|
|
row["server_account"] = server.ServerAccount
|
|
|
|
|
|
row["server_outer_ip"] = server.ServerOuterIp
|
|
|
|
|
|
row["port"] = server.Port
|
|
|
|
|
|
row["type"] = server.Type
|
|
|
|
|
|
row["password"] = server.Password
|
|
|
|
|
|
row["public_key_src"] = server.PublicKeySrc
|
|
|
|
|
|
row["private_key_src"] = server.PrivateKeySrc
|
|
|
|
|
|
row["detail"] = server.Detail
|
|
|
|
|
|
self.Data["server"] = row
|
|
|
|
|
|
self.Data["serverGroup"] = serverGroupLists(self.serverGroups, self.userId)
|
|
|
|
|
|
self.display()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (self *ServerController) AjaxTestServer() {
|
|
|
|
|
|
|
|
|
|
|
|
server := new(models.TaskServer)
|
2019-02-18 00:03:35 +08:00
|
|
|
|
server.ConnectionType, _ = self.GetInt("connection_type")
|
2018-07-13 17:53:34 +08:00
|
|
|
|
server.ServerName = strings.TrimSpace(self.GetString("server_name"))
|
|
|
|
|
|
server.ServerAccount = strings.TrimSpace(self.GetString("server_account"))
|
|
|
|
|
|
server.ServerOuterIp = strings.TrimSpace(self.GetString("server_outer_ip"))
|
|
|
|
|
|
server.ServerIp = strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
server.PrivateKeySrc = strings.TrimSpace(self.GetString("private_key_src"))
|
|
|
|
|
|
server.PublicKeySrc = strings.TrimSpace(self.GetString("public_key_src"))
|
|
|
|
|
|
server.Password = strings.TrimSpace(self.GetString("password"))
|
|
|
|
|
|
server.Detail = strings.TrimSpace(self.GetString("detail"))
|
|
|
|
|
|
server.Type, _ = self.GetInt("type")
|
|
|
|
|
|
server.Port, _ = self.GetInt("port")
|
|
|
|
|
|
server.GroupId, _ = self.GetInt("group_id")
|
|
|
|
|
|
|
|
|
|
|
|
var err error
|
2019-02-18 00:03:35 +08:00
|
|
|
|
|
|
|
|
|
|
if server.ConnectionType == 0 {
|
|
|
|
|
|
if server.Type == 0 {
|
|
|
|
|
|
//密码登录
|
2019-07-03 22:31:27 +08:00
|
|
|
|
err = libs.RemoteCommandByPassword(server)
|
2019-02-18 00:03:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if server.Type == 1 {
|
|
|
|
|
|
//密钥登录
|
2019-07-03 22:31:27 +08:00
|
|
|
|
err = libs.RemoteCommandByKey(server)
|
2019-02-18 00:03:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
self.ajaxMsg("Success", MSG_OK)
|
|
|
|
|
|
} else if server.ConnectionType == 1 {
|
|
|
|
|
|
if server.Type == 0 {
|
|
|
|
|
|
//密码登录
|
2019-07-03 22:31:27 +08:00
|
|
|
|
err = libs.RemoteCommandByTelnetPassword(server)
|
2019-02-18 00:03:35 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
self.ajaxMsg("Telnet方式暂不支持密钥登陆!", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
self.ajaxMsg("Success", MSG_OK)
|
2019-07-03 22:31:27 +08:00
|
|
|
|
} else if server.ConnectionType == 2 {
|
2019-02-18 00:03:35 +08:00
|
|
|
|
|
2019-07-03 22:31:27 +08:00
|
|
|
|
if err := libs.RemoteAgent(server); err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.ajaxMsg("Success", MSG_OK)
|
2018-07-13 17:53:34 +08:00
|
|
|
|
|
2019-07-03 22:31:27 +08:00
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-03 22:31:27 +08:00
|
|
|
|
self.ajaxMsg("未知连接方式", MSG_ERR)
|
2018-07-13 17:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (self *ServerController) Copy() {
|
|
|
|
|
|
self.Data["pageTitle"] = "复制服务器资源"
|
|
|
|
|
|
|
|
|
|
|
|
id, _ := self.GetInt("id", 0)
|
|
|
|
|
|
server, _ := models.TaskServerGetById(id)
|
|
|
|
|
|
row := make(map[string]interface{})
|
|
|
|
|
|
row["id"] = server.Id
|
2019-02-18 00:03:35 +08:00
|
|
|
|
row["connection_type"] = server.ConnectionType
|
2018-07-13 17:53:34 +08:00
|
|
|
|
row["server_name"] = server.ServerName
|
|
|
|
|
|
row["group_id"] = server.GroupId
|
|
|
|
|
|
row["server_ip"] = server.ServerIp
|
|
|
|
|
|
row["server_account"] = server.ServerAccount
|
|
|
|
|
|
row["server_outer_ip"] = server.ServerOuterIp
|
|
|
|
|
|
row["port"] = server.Port
|
|
|
|
|
|
row["type"] = server.Type
|
|
|
|
|
|
row["password"] = server.Password
|
|
|
|
|
|
row["public_key_src"] = server.PublicKeySrc
|
|
|
|
|
|
row["private_key_src"] = server.PrivateKeySrc
|
|
|
|
|
|
row["detail"] = server.Detail
|
|
|
|
|
|
self.Data["server"] = row
|
|
|
|
|
|
self.Data["serverGroup"] = serverGroupLists(self.serverGroups, self.userId)
|
|
|
|
|
|
self.display()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (self *ServerController) AjaxSave() {
|
|
|
|
|
|
server_id, _ := self.GetInt("id")
|
|
|
|
|
|
if server_id == 0 {
|
|
|
|
|
|
server := new(models.TaskServer)
|
2019-02-18 00:03:35 +08:00
|
|
|
|
server.ConnectionType, _ = self.GetInt("connection_type")
|
2018-07-13 17:53:34 +08:00
|
|
|
|
server.ServerName = strings.TrimSpace(self.GetString("server_name"))
|
|
|
|
|
|
server.ServerAccount = strings.TrimSpace(self.GetString("server_account"))
|
|
|
|
|
|
server.ServerOuterIp = strings.TrimSpace(self.GetString("server_outer_ip"))
|
|
|
|
|
|
server.ServerIp = strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
server.PrivateKeySrc = strings.TrimSpace(self.GetString("private_key_src"))
|
|
|
|
|
|
server.PublicKeySrc = strings.TrimSpace(self.GetString("public_key_src"))
|
|
|
|
|
|
server.Password = strings.TrimSpace(self.GetString("password"))
|
|
|
|
|
|
|
|
|
|
|
|
server.Detail = strings.TrimSpace(self.GetString("detail"))
|
|
|
|
|
|
server.Type, _ = self.GetInt("type")
|
|
|
|
|
|
server.Port, _ = self.GetInt("port")
|
|
|
|
|
|
server.GroupId, _ = self.GetInt("group_id")
|
|
|
|
|
|
|
|
|
|
|
|
server.CreateTime = time.Now().Unix()
|
2017-08-17 11:49:53 +08:00
|
|
|
|
server.UpdateTime = time.Now().Unix()
|
|
|
|
|
|
server.Status = 0
|
2018-07-13 17:53:34 +08:00
|
|
|
|
|
|
|
|
|
|
if _, err := models.TaskServerAdd(server); err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
self.ajaxMsg("", MSG_OK)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
server, _ := models.TaskServerGetById(server_id)
|
|
|
|
|
|
//修改
|
|
|
|
|
|
server.Id = server_id
|
|
|
|
|
|
server.UpdateTime = time.Now().Unix()
|
|
|
|
|
|
|
2019-02-18 00:03:35 +08:00
|
|
|
|
server.ConnectionType, _ = self.GetInt("connection_type")
|
2018-07-13 17:53:34 +08:00
|
|
|
|
server.ServerName = strings.TrimSpace(self.GetString("server_name"))
|
|
|
|
|
|
server.ServerAccount = strings.TrimSpace(self.GetString("server_account"))
|
|
|
|
|
|
server.ServerOuterIp = strings.TrimSpace(self.GetString("server_outer_ip"))
|
|
|
|
|
|
server.ServerIp = strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
server.PrivateKeySrc = strings.TrimSpace(self.GetString("private_key_src"))
|
|
|
|
|
|
server.PublicKeySrc = strings.TrimSpace(self.GetString("public_key_src"))
|
|
|
|
|
|
server.Detail = strings.TrimSpace(self.GetString("detail"))
|
|
|
|
|
|
server.Password = strings.TrimSpace(self.GetString("password"))
|
|
|
|
|
|
|
|
|
|
|
|
server.Type, _ = self.GetInt("type")
|
|
|
|
|
|
server.Port, _ = self.GetInt("port")
|
|
|
|
|
|
server.GroupId, _ = self.GetInt("group_id")
|
|
|
|
|
|
|
|
|
|
|
|
if err := server.Update(); err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
self.ajaxMsg("", MSG_OK)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (self *ServerController) AjaxDel() {
|
|
|
|
|
|
id, _ := self.GetInt("id")
|
2019-07-03 22:31:27 +08:00
|
|
|
|
|
|
|
|
|
|
if id == 1 {
|
|
|
|
|
|
self.ajaxMsg("默认分组id=1,禁止删除", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
server, _ := models.TaskServerGetById(id)
|
|
|
|
|
|
server.UpdateTime = time.Now().Unix()
|
2019-07-03 22:31:27 +08:00
|
|
|
|
server.Status = 2
|
2018-07-13 17:53:34 +08:00
|
|
|
|
server.Id = id
|
2017-08-17 11:49:53 +08:00
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
//TODO 查询服务器是否用于定时任务
|
|
|
|
|
|
if err := server.Update(); err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
self.ajaxMsg("操作成功", MSG_OK)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
func (self *ServerController) Table() {
|
|
|
|
|
|
//列表
|
|
|
|
|
|
page, err := self.GetInt("page")
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
page = 1
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
limit, err := self.GetInt("limit")
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
limit = 30
|
|
|
|
|
|
}
|
2019-03-19 19:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
serverGroupId, err := self.GetInt("serverGroupId")
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
serverName := strings.TrimSpace(self.GetString("serverName"))
|
|
|
|
|
|
StatusText := []string{
|
2019-07-03 22:31:27 +08:00
|
|
|
|
"<i class='fa fa-refresh' style='color:#5FB878'></i>",
|
|
|
|
|
|
"<i class='fa fa-ban' style='color:#FF5722'></i>",
|
2018-07-13 17:53:34 +08:00
|
|
|
|
}
|
2019-07-03 22:31:27 +08:00
|
|
|
|
//
|
|
|
|
|
|
//loginType := [2]string{
|
|
|
|
|
|
// "密码",
|
|
|
|
|
|
// "密钥",
|
|
|
|
|
|
//}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
|
2019-07-03 22:31:27 +08:00
|
|
|
|
connectionType := [3]string{
|
2019-02-18 00:03:35 +08:00
|
|
|
|
"SSH",
|
|
|
|
|
|
"Telnet",
|
2019-07-03 22:31:27 +08:00
|
|
|
|
"Agent",
|
2019-02-18 00:03:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
serverGroup := serverGroupLists(self.serverGroups, self.userId)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
self.pageSize = limit
|
|
|
|
|
|
//查询条件
|
|
|
|
|
|
filters := make([]interface{}, 0)
|
2019-07-03 22:31:27 +08:00
|
|
|
|
ids := []int{0, 1}
|
|
|
|
|
|
filters = append(filters, "status__in", ids)
|
2019-03-19 19:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
groupsIds := make([]int, 0)
|
2018-07-13 17:53:34 +08:00
|
|
|
|
if self.userId != 1 {
|
|
|
|
|
|
groups := strings.Split(self.serverGroups, ",")
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range groups {
|
|
|
|
|
|
id, _ := strconv.Atoi(v)
|
2019-03-19 19:43:45 +08:00
|
|
|
|
if serverGroupId > 0 {
|
|
|
|
|
|
if id == serverGroupId {
|
|
|
|
|
|
groupsIds = append(groupsIds, id)
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
groupsIds = append(groupsIds, id)
|
|
|
|
|
|
}
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
2018-07-13 17:53:34 +08:00
|
|
|
|
filters = append(filters, "group_id__in", groupsIds)
|
2019-03-19 19:43:45 +08:00
|
|
|
|
} else if serverGroupId > 0 {
|
|
|
|
|
|
groupsIds = append(groupsIds, serverGroupId)
|
|
|
|
|
|
filters = append(filters, "group_id__in", groupsIds)
|
2018-07-13 17:53:34 +08:00
|
|
|
|
}
|
2019-03-19 19:43:45 +08:00
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
if serverName != "" {
|
|
|
|
|
|
filters = append(filters, "server_name__icontains", serverName)
|
|
|
|
|
|
}
|
|
|
|
|
|
result, count := models.TaskServerGetList(page, self.pageSize, filters...)
|
|
|
|
|
|
list := make([]map[string]interface{}, len(result))
|
|
|
|
|
|
for k, v := range result {
|
|
|
|
|
|
row := make(map[string]interface{})
|
|
|
|
|
|
row["id"] = v.Id
|
2019-02-18 00:03:35 +08:00
|
|
|
|
row["connection_type"] = connectionType[v.ConnectionType]
|
2019-07-03 22:31:27 +08:00
|
|
|
|
row["server_name"] = StatusText[v.Status] + " " + v.ServerName
|
2018-07-13 17:53:34 +08:00
|
|
|
|
row["detail"] = v.Detail
|
|
|
|
|
|
if serverGroup[v.GroupId] == "" {
|
|
|
|
|
|
v.GroupId = 0
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
2019-07-03 22:31:27 +08:00
|
|
|
|
row["ip_port"] = v.ServerIp + ":" + strconv.Itoa(v.Port)
|
2018-07-13 17:53:34 +08:00
|
|
|
|
row["group_name"] = serverGroup[v.GroupId]
|
2019-07-03 22:31:27 +08:00
|
|
|
|
//row["type"] = loginType[v.Type]
|
2018-07-13 17:53:34 +08:00
|
|
|
|
row["status"] = v.Status
|
|
|
|
|
|
list[k] = row
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 17:53:34 +08:00
|
|
|
|
self.ajaxList("成功", MSG_OK, count, list)
|
2017-08-17 11:49:53 +08:00
|
|
|
|
}
|
2019-07-03 22:31:27 +08:00
|
|
|
|
|
|
|
|
|
|
//以下函数为执行器接口
|
|
|
|
|
|
//注册
|
|
|
|
|
|
func (self *ServerController) ApiSave() {
|
|
|
|
|
|
//唯一确定值 ip+port
|
|
|
|
|
|
serverIp := strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
port, _ := self.GetInt("port")
|
|
|
|
|
|
|
|
|
|
|
|
if serverIp == "" || port == 0 {
|
|
|
|
|
|
self.ajaxMsg("执行器和端口号必填", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
defaultActName := "agent-" + serverIp + "-" + strconv.Itoa(port)
|
|
|
|
|
|
|
|
|
|
|
|
id := models.TaskServerForActuator(serverIp, port)
|
|
|
|
|
|
if id == 0 {
|
|
|
|
|
|
//新增
|
|
|
|
|
|
server := new(models.TaskServer)
|
|
|
|
|
|
server.ConnectionType, _ = self.GetInt("connection_type", 3)
|
|
|
|
|
|
server.ServerName = strings.TrimSpace(self.GetString("server_name", defaultActName))
|
|
|
|
|
|
server.ServerAccount = strings.TrimSpace(self.GetString("server_account", "agent"))
|
|
|
|
|
|
server.ServerOuterIp = strings.TrimSpace(self.GetString("server_outer_ip", ""))
|
|
|
|
|
|
server.ServerIp = strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
server.PrivateKeySrc = strings.TrimSpace(self.GetString("private_key_src", ""))
|
|
|
|
|
|
server.PublicKeySrc = strings.TrimSpace(self.GetString("public_key_src", ""))
|
|
|
|
|
|
server.Password = strings.TrimSpace(self.GetString("password", "agent"))
|
|
|
|
|
|
|
|
|
|
|
|
server.Detail = strings.TrimSpace(self.GetString("detail", ""))
|
|
|
|
|
|
server.Type, _ = self.GetInt("type", 0)
|
|
|
|
|
|
server.Port, _ = self.GetInt("port")
|
|
|
|
|
|
server.GroupId, _ = self.GetInt("group_id", 0)
|
|
|
|
|
|
server.Status = 0
|
|
|
|
|
|
|
|
|
|
|
|
server.CreateTime = time.Now().Unix()
|
|
|
|
|
|
server.UpdateTime = time.Now().Unix()
|
|
|
|
|
|
server.Status = 0
|
|
|
|
|
|
serverId, err := models.TaskServerAdd(server)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
self.ajaxMsg(serverId, MSG_OK)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//修改状态
|
|
|
|
|
|
server, _ := models.TaskServerGetById(id)
|
|
|
|
|
|
server.UpdateTime = time.Now().Unix()
|
|
|
|
|
|
server.Status, _ = self.GetInt("status", 0)
|
|
|
|
|
|
if err := server.Update(); err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
self.ajaxMsg(id, MSG_OK)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//检测0-正常,1-异常,2-删除
|
|
|
|
|
|
func (self *ServerController) ApiStatus() {
|
|
|
|
|
|
//唯一确定值 ip+port
|
|
|
|
|
|
serverId := strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
port, _ := self.GetInt("port")
|
|
|
|
|
|
status, _ := self.GetInt("status", 0)
|
|
|
|
|
|
|
|
|
|
|
|
if serverId == "" || port == 0 {
|
|
|
|
|
|
self.ajaxMsg("执行器和端口号必填", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
id := models.TaskServerForActuator(serverId, port)
|
|
|
|
|
|
if id == 0 {
|
|
|
|
|
|
self.ajaxMsg("执行器不存在", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if status != 0 && status != 1 {
|
|
|
|
|
|
status = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
server, _ := models.TaskServerGetById(id)
|
|
|
|
|
|
server.UpdateTime = time.Now().Unix()
|
|
|
|
|
|
server.Status = status
|
|
|
|
|
|
server.Id = id
|
|
|
|
|
|
|
|
|
|
|
|
logs.Info(server)
|
|
|
|
|
|
|
|
|
|
|
|
//TODO 查询执行器是否正在使用中
|
|
|
|
|
|
if err := server.Update(); err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
self.ajaxMsg(id, MSG_OK)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取 不检测执行器状态
|
|
|
|
|
|
func (self *ServerController) ApiGet() {
|
|
|
|
|
|
//唯一确定值 ip+port
|
|
|
|
|
|
serverId := strings.TrimSpace(self.GetString("server_ip"))
|
|
|
|
|
|
port, _ := self.GetInt("port")
|
|
|
|
|
|
|
|
|
|
|
|
if serverId == "" || port == 0 {
|
|
|
|
|
|
self.ajaxMsg("执行器和端口号必填", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
id := models.TaskServerForActuator(serverId, port)
|
|
|
|
|
|
if id == 0 {
|
|
|
|
|
|
self.ajaxMsg("执行器不存在", MSG_ERR)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
server, err := models.TaskServerGetById(id)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.ajaxMsg(server, MSG_OK)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|