added asn, fixed bugs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2022-08-19 20:36:59 +02:00
parent c320cc8133
commit fc4b4cc2e6
4 changed files with 61 additions and 34 deletions

View File

@ -15,6 +15,7 @@ import (
// InitServer instanciate the main echo instance
func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
ws.e = echo.New()
ws.e.Pre(middleware.RemoveTrailingSlash())
ws.e.HideBanner = true
ws.e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
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) {
ws.InitServer(templatefiles, staticfiles)
ws.e.GET("/", ws.Page.Process)
ws.e.GET("/:ip", ws.Page.Process)
ws.e.GET("/static/*", func(c echo.Context) error {
ws.e.GET("/", func(c echo.Context) (err error) {
ws.Page.Process(c, "")
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)
})

View File

@ -2,7 +2,6 @@ package ws
import (
"net/http"
"strings"
"git.paulbsd.com/paulbsd/dip/src/dip"
"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
func (p *Page) Process(c echo.Context) (err error) {
func (p *Page) Process(c echo.Context, querytype string) (err error) {
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.JSONPretty(http.StatusOK, p.IP, " ")

View File

@ -13,10 +13,11 @@ var vue = new Vue({
mounted () {
var ip = "";
if (window.location.pathname.length > 1) {
if (window.location.pathname.length > 4) {
ip = window.location.pathname.split("/")[1];
console.log(ip);
}
axios.get(`https://ip.paulbsd.com/${ip}`)
axios.get(`/json/${ip}`)
.then(response => {
this.dip = response.data
})

View File

@ -1,27 +1,39 @@
<html>
{{ template "head.html" .}}
<body>
<div id="dip_main_div">
<h1 class="dip_h1">{{ .Title }}</h1>
<table class="uk-table uk-table-striped uk-table-hover">
<caption>IP informations</caption>
<tr>
<td>IP</td>
<td>{{ "{{" }} dip.ip {{ "}}" }}</td>
</tr>
<tr>
<td>Reverse DNS</td>
<td>{{ "{{" }} dip.hostname {{ "}}" }}</td>
</tr>
<tr>
<td>City</td>
<td>{{ "{{" }} dip.city {{ "}}" }}</td>
</tr>
<tr>
<td>Country</td>
<td>{{ "{{" }} dip.country {{ "}}" }}</td>
</tr>
</div>
{{ template "footer_js.html" .}}
</body>
</html>
{{ template "head.html" .}}
<body>
<div id="dip_main_div">
<h1 class="dip_h1">{{ .Title }}</h1>
<table class="uk-table uk-table-striped uk-table-hover">
<caption>IP informations</caption>
<tr>
<td>IP</td>
<td>{{ "{{" }} dip.ip {{ "}}" }}</td>
</tr>
<tr>
<td>Reverse DNS</td>
<td>{{ "{{" }} dip.hostname {{ "}}" }}</td>
</tr>
<tr>
<td>City</td>
<td>{{ "{{" }} dip.city {{ "}}" }}</td>
</tr>
<tr>
<td>Country</td>
<td>{{ "{{" }} dip.country {{ "}}" }}</td>
</tr>
<tr>
<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>