ソースを参照

一键部署-服务器管理界面

maxiaoshan 3 年 前
コミット
adac3373e5

+ 1 - 0
src/front/spider.go

@@ -1331,6 +1331,7 @@ func (f *Front) Heart() {
 		count := u.MgoS.Count("spider_heart", query)
 		for _, l := range *list {
 			code := qu.ObjToString(l["code"])
+			qu.Debug(code)
 			d, _ := u.MgoE.FindOneByField("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"state": 1, "param_common": 1, "str_list": 1, "type_list": 1})
 			l["state"] = (*d)["state"]
 			l["param_common"] = (*d)["param_common"]

+ 4 - 1
src/main.go

@@ -5,7 +5,7 @@ import (
 	"front"
 	"quesManager"
 	"spider"
-
+	"vps"
 	//. "luaweb/task"
 	"luaerrdata"
 	"taskManager"
@@ -34,6 +34,8 @@ func init() {
 	qu.ReadConfig(&util.Config)
 	qu.ReadConfig("autoimport.json", &front.AutoTpl)
 	qu.ReadConfig("transfercode.json", &front.Transfercode)
+	//vps
+	qu.ReadConfig("vpsconfig.json", &vps.VpsConfig)
 	//redis
 	redis.InitRedis(util.Config.Redisservers)
 	//验证码识别client
@@ -67,6 +69,7 @@ func init() {
 	xweb.RootApp().AppConfig.CacheTemplates = false
 	xweb.AddAction(&front.Front{})
 	xweb.AddAction(&front.Site{})
+	xweb.AddAction(&vps.Vps{})
 	xweb.AddAction(&taskManager.TaskM{})
 	xweb.AddAction(&quesManager.QuesM{})
 	xweb.AddAction(&luaerrdata.ErrorData{})

+ 17 - 0
src/vps/config.go

@@ -0,0 +1,17 @@
+package vps
+
+type vpsconfig struct {
+	Available    bool      `json:"available"`
+	AccessId     string    `json:"accessid"`
+	AccessSecret string    `json:"accesssecret"`
+	ZoneIds      []ZoneMap `json:"zoneids"`
+}
+
+type ZoneMap struct {
+	ZoneId            string `json:"zoneid"`
+	LaunchTemplateId4 string `json:"launchtemplateid4"`
+	LaunchTemplateId8 string `json:"launchtemplateid8"`
+	VswitchId         string `json:"vswitchid"`
+}
+
+var VpsConfig vpsconfig

+ 134 - 0
src/vps/vps.go

@@ -0,0 +1,134 @@
+package vps
+
+import (
+	"github.com/go-xweb/xweb"
+	qu "qfw/util"
+	"strings"
+	"util"
+)
+
+type Vps struct {
+	*xweb.Action
+	vpsList xweb.Mapper `xweb:"/center/vps"`        //服务器管理列表
+	apply   xweb.Mapper `xweb:"/center/vps/apply"`  //申请实例
+	update  xweb.Mapper `xweb:"/center/vps/update"` //更新实例
+	delay   xweb.Mapper `xweb:"/center/vps/delay"`  //延迟实例
+	//deploy     xweb.Mapper `xweb:"/center/vps/deploy"`     //部署实例
+	release xweb.Mapper `xweb:"/center/vps/release"` //释放实例
+	delete  xweb.Mapper `xweb:"/center/vps/delete"`  //删除信息
+	//allDeploy  xweb.Mapper `xweb:"/center/vps/alldeploy"`  //一键部署
+	allRelease xweb.Mapper `xweb:"/center/vps/allrelease"` //一键释放
+}
+
+func (vps *Vps) VpsList() {
+	defer qu.Catch()
+	draw, _ := vps.GetInteger("draw")
+	start, _ := vps.GetInteger("start")
+	limit, _ := vps.GetInteger("length")
+	if vps.Method() == "POST" {
+		query := map[string]interface{}{
+			// "modifytime": map[string]interface{}{
+			// 	"$exists": false,
+			// },
+		}
+		count := util.MgoE.Count("ecs", query)
+		qu.Debug("query:", query, count)
+		list, _ := util.MgoE.Find("ecs", query, nil, nil, false, start, limit)
+		vps.ServeJson(map[string]interface{}{"draw": draw, "data": *list, "recordsFiltered": count, "recordsTotal": count})
+	} else {
+		vps.Render("vps/vpslist.html")
+	}
+}
+
+func (vps *Vps) Apply() {
+	defer qu.Catch()
+	vpsname := vps.GetString("vpsname")
+	vpsimage := vps.GetString("vpsimage")
+	vpsnum, _ := vps.GetInteger("vpsnum")
+	vpsduration, _ := vps.GetInteger("vpsduration")
+	vpstype := vps.GetString("vpstype")
+	vpspublic, _ := vps.GetBool("vpspublic")
+	ok := false
+	RunInstances(vpsname, vpsimage, vpstype, vpspublic, vpsnum, vpsduration, &ok)
+	vps.ServeJson(map[string]interface{}{"ok": ok})
+}
+
+func (vps *Vps) Update() {
+	defer qu.Catch()
+	qu.Debug("更新实例...")
+	ok := false
+	DescribeInstances(&ok)
+	vps.ServeJson(map[string]interface{}{"ok": ok})
+}
+
+func (vps *Vps) Delay() {
+	defer qu.Catch()
+	delayid := vps.GetString("delayid")
+	delaytime, _ := vps.GetInteger("delaytime")
+	allOk := true
+	failedAll := []string{}
+	if delayid != "" { //单个实例延时
+		qu.Debug("单个实例延时:", delayid, delaytime)
+		ModifyInstanceAutoReleaseTime(delayid, delaytime, &allOk)
+		if !allOk {
+			failedAll = append(failedAll, delayid)
+		}
+	} else { //延时所有实例
+		qu.Debug("所有实例延时:", delaytime)
+		list, _ := util.MgoE.Find("ecs", map[string]interface{}{"Status": "Running"}, nil, map[string]interface{}{"InstanceId": 1}, false, -1, -1)
+		for _, l := range *list {
+			ok := false
+			instanceId := qu.ObjToString(l["InstanceId"])
+			ModifyInstanceAutoReleaseTime(instanceId, delaytime, &ok)
+			if !ok {
+				failedAll = append(failedAll, instanceId)
+				allOk = false
+			}
+		}
+	}
+	msg := "延时失败实例:" + strings.Join(failedAll, ",")
+	vps.ServeJson(map[string]interface{}{"ok": allOk, "msg": msg})
+}
+
+func (vps *Vps) Release() {
+	defer qu.Catch()
+	instanceId := vps.GetString("instanceId")
+	qu.Debug("释放实例:", instanceId)
+	ok := false
+	if instanceId != "" {
+		DeleteInstance(instanceId, &ok)
+	}
+	vps.ServeJson(map[string]interface{}{"ok": ok})
+}
+
+func (vps *Vps) AllRelease() {
+	defer qu.Catch()
+	qu.Debug("释放所有实例...")
+	allOk := true
+	failedAll := []string{}
+	list, _ := util.MgoE.Find("ecs", map[string]interface{}{"Status": "Running"}, nil, map[string]interface{}{"InstanceId": 1}, false, -1, -1)
+	for _, l := range *list {
+		ok := false
+		instanceId := qu.ObjToString(l["InstanceId"])
+		DeleteInstance(instanceId, &ok)
+		if !ok {
+			failedAll = append(failedAll, instanceId)
+			allOk = false
+		}
+	}
+	msg := "释放失败实例:" + strings.Join(failedAll, ",")
+	vps.ServeJson(map[string]interface{}{"ok": allOk, "msg": msg})
+}
+
+func (vps *Vps) Delete() {
+	defer qu.Catch()
+	instanceId := vps.GetString("instanceId")
+	qu.Debug("删除实例信息:", instanceId)
+	ok := false
+	if instanceId != "" {
+		ok = util.MgoE.Del("ecs", map[string]interface{}{"InstanceId": instanceId})
+	} else {
+		ok = util.MgoE.Del("ecs", nil)
+	}
+	vps.ServeJson(map[string]interface{}{"ok": ok})
+}

+ 13 - 0
src/vpsconfig.json

@@ -0,0 +1,13 @@
+{
+  "available": true,
+  "accessid": "LTAI4G5x9aoZx8dDamQ7vfZi",
+  "accesssecret": "Bk98FsbPYXcJe72n1bG3Ssf73acuNh",
+  "zoneids": [
+    {
+      "zoneid": "cn-beijing-h",
+      "launchtemplateid4": "lt-2ze5ir54gy4ui8okr71f",
+      "launchtemplateid8": "lt-2ze5fzxwgt8jcqczvmjy",
+      "vswitchid": "vsw-2ze1n1k3mo3fv2irsfdps"
+    }
+  ]
+}

+ 4 - 9
src/web/staticres/css/otherStyle.css

@@ -33,19 +33,14 @@
     font-size: 14px;
     font-weight: 400;
 }
-#myModal-addUser .close{
-	margin-top:-19px;
-}
-#myModal-createTask .close{
-	margin-top:-19px;
-}
-#myModal-createQues .close{
-	margin-top:-19px;
+
+.modal .close{
+	margin-top:-12px;
 }
 .glyphicon-zoom-in{
 	margin-left:20px;
 }
-.glyphicon-briefcase{
+.modal .glyphicon{
 	margin-left:20px;
 }
 .check{

+ 0 - 1
src/web/templates/audit.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
 		<section class="content-header">
 		   <h1>

+ 0 - 1
src/web/templates/auditedit.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper" >
 	<section class="content-header">
 		<h1>

+ 0 - 1
src/web/templates/errdata.html

@@ -1,7 +1,6 @@
 {{include "head.html"}}
 <script src="/time/js/angular.min.js"></script>
 <script src="/time/js/wui-date.js"></script>
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <style>
 #timebox {
     display: flex;

+ 0 - 1
src/web/templates/errhreflist.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
 		<section class="content-header">
 		   <h1>

+ 0 - 1
src/web/templates/errlualist.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <style>
 </style>
 <div class="content-wrapper">

+ 4 - 3
src/web/templates/head.html

@@ -25,7 +25,7 @@
 	<link rel="stylesheet" href="/codemirror/theme/the-matrix.css">
   <link rel="stylesheet" href="/time/css/wui.min.css">
   <link rel="stylesheet" href="/time/css/style.css">
-  
+	<link rel="stylesheet"  href="/css/otherStyle.css">
 	
 	<script src="/js/common.js"></script>
 	<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
@@ -570,8 +570,9 @@
         <!-- Optionally, you can add icons to the links -->
 
         {{if eq (session "auth") 4}}
-			<li data="index_yhgl"><a href="/center/user.html"><i class="glyphicon glyphicon-user"></i> <span>用户管理</span></a></li>
-		{{else if eq (session "auth") 3}}
+		  <li data="index_yhgl"><a href="/center/user.html"><i class="glyphicon glyphicon-user"></i> <span>用户管理</span></a></li>
+		  <li data="index_vps"><a href="/center/vps"><i class="fa fa-server"></i> <span>服务器管理</span></a></li>
+		  {{else if eq (session "auth") 3}}
 			<li data="index"><a href="/center"><i class="glyphicon glyphicon-eye-open"></i> <span>脚本列表</span></a></li>
 			<li data="index_rwgl"><a href="/center/managerTask"><i class="glyphicon glyphicon glyphicon-tasks"></i> <span>任务管理</span></a></li>
 			<li data="index_fbgl"><a href="/center/lualist.html"><i class="glyphicon glyphicon-credit-card"></i> <span>运行监控中心</span></a></li>

+ 0 - 1
src/web/templates/jsonInfo.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 
 <div class="content-wrapper" >
 	<section class="content">

+ 0 - 1
src/web/templates/lualist.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
     <section class="content-header">
         <h1>

+ 0 - 1
src/web/templates/luamovecode.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
 		<section class="content-header">
 		   <h1>

+ 0 - 1
src/web/templates/luamovesite.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
 		<section class="content-header">
 		   <h1>

+ 0 - 1
src/web/templates/mytask.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
 		<section class="content-header">
 		   <h1>

+ 0 - 1
src/web/templates/mytaskedit.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper" >
 	<section class="content-header">
 		<h1>

+ 0 - 1
src/web/templates/question.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper">
 		<section class="content-header">
 		   <h1>

+ 1 - 2
src/web/templates/task.html

@@ -1,6 +1,5 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
-<div class="modal fade" id="modal-assigntask" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+`<div class="modal fade" id="modal-assigntask" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <div class="modal-dialog">
         <div class="modal-content">
 			<div class="modal-header">

+ 0 - 1
src/web/templates/taskedit.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper" >
 	<section class="content-header">
 		<h1>

+ 0 - 1
src/web/templates/user.html

@@ -1,5 +1,4 @@
 {{include "head.html"}}
-<link rel="stylesheet"  href="/css/otherStyle.css">
 <div class="content-wrapper" >
 	<section class="content-header">
 		<h1>