updated functions, templates
This commit is contained in:
parent
bbc0b707e8
commit
f77f3f95a9
23
functions.go
23
functions.go
@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetIPInfo returns IP address informations
|
// GetIPInfo returns IP address informations
|
||||||
func GetIPInfo(c echo.Context) (ip IP, err error) {
|
func (ip *IP) GetIPInfo(c echo.Context) (err error) {
|
||||||
if c.QueryParam("ip") != "" {
|
if c.QueryParam("ip") != "" {
|
||||||
ip.IP = c.QueryParam("ip")
|
ip.IP = c.QueryParam("ip")
|
||||||
} else {
|
} else {
|
||||||
@ -24,26 +24,25 @@ func GetIPInfo(c echo.Context) (ip IP, err error) {
|
|||||||
|
|
||||||
err = ip.CheckIPAddress()
|
err = ip.CheckIPAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(fmt.Sprintf("Error checking IP address %s",ip.IP))
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ip.GetHostname()
|
err = ip.GetHostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(fmt.Sprintf("Error checking revers DNS for IP address %s",ip.IP))
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dip return webpage
|
// Dip returns webpage
|
||||||
func Dip(c echo.Context) (err error) {
|
func Dip(c echo.Context) (err error) {
|
||||||
var ip IP
|
var ip IP
|
||||||
|
|
||||||
ip, err = GetIPInfo(c)
|
err = ip.GetIPInfo(c)
|
||||||
fmt.Println(err)
|
if err != nil {
|
||||||
if err != nil {
|
return c.Render(http.StatusInternalServerError, "error.html", err)
|
||||||
return c.Render(http.StatusInternalServerError, "error.html", nil)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
||||||
return c.Render(http.StatusOK, "index.html", ip)
|
return c.Render(http.StatusOK, "index.html", ip)
|
||||||
@ -62,7 +61,7 @@ func Static(c echo.Context) (err error) {
|
|||||||
func (ip *IP) CheckIPAddress() (err error) {
|
func (ip *IP) CheckIPAddress() (err error) {
|
||||||
addr := net.ParseIP(ip.IP)
|
addr := net.ParseIP(ip.IP)
|
||||||
if addr == nil {
|
if addr == nil {
|
||||||
return fmt.Errorf("Supplied string isn't an IP address")
|
return fmt.Errorf("Supplied string isn't an IP address \"%s\"", ip.IP)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -71,7 +70,7 @@ func (ip *IP) CheckIPAddress() (err error) {
|
|||||||
func (ip *IP) GetHostname() (err error) {
|
func (ip *IP) GetHostname() (err error) {
|
||||||
revip, err := net.LookupAddr(ip.IP)
|
revip, err := net.LookupAddr(ip.IP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(fmt.Sprintf("Supplied address %s doesn't have a valid reverse DNS entry", ip.IP))
|
return fmt.Errorf(fmt.Sprintf("Supplied address \"%s\" doesn't have a valid reverse DNS entry", ip.IP))
|
||||||
}
|
}
|
||||||
ip.Hostname = revip[0]
|
ip.Hostname = revip[0]
|
||||||
return
|
return
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,7 +31,6 @@ func BuildTemplates(box packr.Box) (builttemplates *Template, err error) {
|
|||||||
tmpl := template.New("template")
|
tmpl := template.New("template")
|
||||||
|
|
||||||
for _, filename := range box.List() {
|
for _, filename := range box.List() {
|
||||||
fmt.Println(filename)
|
|
||||||
tmplContent, _ := box.FindString(filename)
|
tmplContent, _ := box.FindString(filename)
|
||||||
tmpl.New(filename).Parse(tmplContent)
|
tmpl.New(filename).Parse(tmplContent)
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Error</h1>
|
<h1>Error</h1>
|
||||||
|
<p>{{ . }} isn't a IP address</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{{ template "head.html" .}}
|
{{ template "head.html" .}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>IP: {{ .IP }}</h1>
|
<h1>IP : {{ .IP }}</h1>
|
||||||
<h2>Reverse DNS: {{ .Hostname }}</h2>
|
<h2>Reverse DNS : {{ .Hostname }}</h2>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user