-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
93 lines (75 loc) · 1.79 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"github.com/gin-gonic/gin"
)
type router []struct {
ID string `json:"id"`
Name string `json:"name"`
IP string `json:"ip"`
}
func indexPage(c *gin.Context) {
if c.Param("version") == "v1" {
c.HTML(200, "v1.tmpl", nil)
} else if c.Param("version") == "" {
c.HTML(200, "v2.tmpl", nil)
} else {
pageNotAvailable(c)
}
}
func LookingGlass(c *gin.Context) {
Router := c.PostForm("Router")
Action := c.PostForm("Action")
IP := c.PostForm("IP")
data, err := ioutil.ReadFile("router.json")
var router router
json.Unmarshal(data, &router)
var RouterIP string
RouterIP = "NULL"
for n := range router {
if router[n].Name == Router {
fmt.Println("Router IP: ", router[n].IP)
RouterIP = router[n].IP
}
}
RouterURL := "http://" + RouterIP + ":32991"
resp, err := http.PostForm(RouterURL,
url.Values{"Action": {Action}, "IP": {IP}})
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
c.String(200, string(body))
}
func pageNotAvailable(c *gin.Context) {
c.HTML(404, "404.tmpl", nil)
}
func main() {
fmt.Print("\n")
fmt.Print("-------------------\n")
fmt.Print("\n")
fmt.Print("FRRouting Looking Glass\n")
fmt.Print("Port listing at 32280\n")
fmt.Print("Repo: https://github.com/steveyiyo/frrouting-lg\n")
fmt.Print("Author: SteveYi\n")
fmt.Print("Demo: https://lg.steveyi.net\n")
fmt.Print("\n")
fmt.Print("-------------------\n")
fmt.Print("\n")
router := gin.New()
router.Use(gin.Logger(), gin.Recovery())
router.LoadHTMLGlob("static/*")
router.GET("/", indexPage)
router.GET("/:version", indexPage)
router.POST("/", LookingGlass)
router.NoRoute(pageNotAvailable)
router.Run("127.0.0.1:32280")
}