This commit is contained in:
parent
c320cc8133
commit
fc4b4cc2e6
@ -15,6 +15,7 @@ import (
|
|||||||
// InitServer instanciate the main echo instance
|
// InitServer instanciate the main echo instance
|
||||||
func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
||||||
ws.e = echo.New()
|
ws.e = echo.New()
|
||||||
|
ws.e.Pre(middleware.RemoveTrailingSlash())
|
||||||
ws.e.HideBanner = true
|
ws.e.HideBanner = true
|
||||||
ws.e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
ws.e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
||||||
Level: 5,
|
Level: 5,
|
||||||
@ -34,9 +35,23 @@ func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err er
|
|||||||
func (ws *WS) RunServer(config config.Config, templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
func (ws *WS) RunServer(config config.Config, templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
||||||
ws.InitServer(templatefiles, staticfiles)
|
ws.InitServer(templatefiles, staticfiles)
|
||||||
|
|
||||||
ws.e.GET("/", ws.Page.Process)
|
ws.e.GET("/", func(c echo.Context) (err error) {
|
||||||
ws.e.GET("/:ip", ws.Page.Process)
|
ws.Page.Process(c, "")
|
||||||
ws.e.GET("/static/*", func(c echo.Context) error {
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/:ip", func(c echo.Context) (err error) {
|
||||||
|
ws.Page.Process(c, "")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/json", func(c echo.Context) (err error) {
|
||||||
|
ws.Page.Process(c, "json")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/json/:ip", func(c echo.Context) (err error) {
|
||||||
|
ws.Page.Process(c, "json")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/static/*", func(c echo.Context) (err error) {
|
||||||
return static.GetStatic(staticfiles, c)
|
return static.GetStatic(staticfiles, c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package ws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.paulbsd.com/paulbsd/dip/src/dip"
|
"git.paulbsd.com/paulbsd/dip/src/dip"
|
||||||
"git.paulbsd.com/paulbsd/dip/src/templates"
|
"git.paulbsd.com/paulbsd/dip/src/templates"
|
||||||
@ -18,9 +17,9 @@ func (p *Page) GetContent(c echo.Context) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process returns main webpage or a JSON
|
// Process returns main webpage or a JSON
|
||||||
func (p *Page) Process(c echo.Context) (err error) {
|
func (p *Page) Process(c echo.Context, querytype string) (err error) {
|
||||||
p.GetContent(c)
|
p.GetContent(c)
|
||||||
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
if querytype != "json" {
|
||||||
return c.Render(http.StatusOK, "index.html", p)
|
return c.Render(http.StatusOK, "index.html", p)
|
||||||
}
|
}
|
||||||
return c.JSONPretty(http.StatusOK, p.IP, " ")
|
return c.JSONPretty(http.StatusOK, p.IP, " ")
|
||||||
|
@ -13,10 +13,11 @@ var vue = new Vue({
|
|||||||
|
|
||||||
mounted () {
|
mounted () {
|
||||||
var ip = "";
|
var ip = "";
|
||||||
if (window.location.pathname.length > 1) {
|
if (window.location.pathname.length > 4) {
|
||||||
ip = window.location.pathname.split("/")[1];
|
ip = window.location.pathname.split("/")[1];
|
||||||
|
console.log(ip);
|
||||||
}
|
}
|
||||||
axios.get(`https://ip.paulbsd.com/${ip}`)
|
axios.get(`/json/${ip}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.dip = response.data
|
this.dip = response.data
|
||||||
})
|
})
|
||||||
|
@ -1,27 +1,39 @@
|
|||||||
<html>
|
<html>
|
||||||
{{ template "head.html" .}}
|
{{ template "head.html" .}}
|
||||||
<body>
|
|
||||||
<div id="dip_main_div">
|
<body>
|
||||||
<h1 class="dip_h1">{{ .Title }}</h1>
|
<div id="dip_main_div">
|
||||||
<table class="uk-table uk-table-striped uk-table-hover">
|
<h1 class="dip_h1">{{ .Title }}</h1>
|
||||||
<caption>IP informations</caption>
|
<table class="uk-table uk-table-striped uk-table-hover">
|
||||||
<tr>
|
<caption>IP informations</caption>
|
||||||
<td>IP</td>
|
<tr>
|
||||||
<td>{{ "{{" }} dip.ip {{ "}}" }}</td>
|
<td>IP</td>
|
||||||
</tr>
|
<td>{{ "{{" }} dip.ip {{ "}}" }}</td>
|
||||||
<tr>
|
</tr>
|
||||||
<td>Reverse DNS</td>
|
<tr>
|
||||||
<td>{{ "{{" }} dip.hostname {{ "}}" }}</td>
|
<td>Reverse DNS</td>
|
||||||
</tr>
|
<td>{{ "{{" }} dip.hostname {{ "}}" }}</td>
|
||||||
<tr>
|
</tr>
|
||||||
<td>City</td>
|
<tr>
|
||||||
<td>{{ "{{" }} dip.city {{ "}}" }}</td>
|
<td>City</td>
|
||||||
</tr>
|
<td>{{ "{{" }} dip.city {{ "}}" }}</td>
|
||||||
<tr>
|
</tr>
|
||||||
<td>Country</td>
|
<tr>
|
||||||
<td>{{ "{{" }} dip.country {{ "}}" }}</td>
|
<td>Country</td>
|
||||||
</tr>
|
<td>{{ "{{" }} dip.country {{ "}}" }}</td>
|
||||||
</div>
|
</tr>
|
||||||
{{ template "footer_js.html" .}}
|
<tr>
|
||||||
</body>
|
<td>ASN id</td>
|
||||||
|
<td>{{ "{{" }} dip.asn.id {{ "}}" }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>ASN name</td>
|
||||||
|
<td>
|
||||||
|
{{ "{{" }} dip.asn.name {{ "}}" }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</div>
|
||||||
|
{{ template "footer_js.html" .}}
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user