Link to IPv4 page from IPv6 page

This commit is contained in:
Ian Bishop 2016-03-06 16:10:58 +10:00
parent aab394d141
commit 2b340fc2ec
3 changed files with 20 additions and 4 deletions

View File

@ -141,12 +141,19 @@ func (a *API) DefaultHandler(w http.ResponseWriter, r *http.Request) *appError {
return internalServerError(err)
}
IsV6 := true
ip := net.ParseIP(r.Header.Get(IP_HEADER))
if ip.To4() != nil {
IsV6 = false
}
var data = struct {
IP string
IsV6 bool
JSON string
Header http.Header
Cmd
}{r.Header.Get(IP_HEADER), string(b), r.Header, cmd}
}{ip.String(), IsV6, string(b), r.Header, cmd}
if err := t.Execute(w, &data); err != nil {
return internalServerError(err)

View File

@ -24,6 +24,10 @@
margin-bottom: 10px;
text-align: center;
}
#footer {
margin-top: 10px;
text-align: center;
}
.ip {
border: 1px solid #cbcbcb;
background: #f2f2f2;
@ -66,6 +70,11 @@
</tbody>
</table>
</div>
<div id="footer">
{{ if .IsV6 }}
<a href="http://v4.ifconfig.co">IPv4 page</a>
{{end}}
</div>
<a href="https://github.com/martinp/ifconfigd"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
</body>
</html>

View File

@ -13,13 +13,13 @@ func main() {
var opts struct {
DBPath string `short:"f" long:"file" description:"Path to GeoIP database" value-name:"FILE" default:""`
Listen string `short:"l" long:"listen" description:"Listening address" value-name:"ADDR" default:":8080"`
CORS bool `short:"x" long:"cors" description:"Allow requests from other domains" default:"false"`
ReverseLookup bool `short:"r" long:"reverselookup" description:"Perform reverse hostname lookups" default:"false"`
CORS bool `short:"x" long:"cors" description:"Allow requests from other domains"`
ReverseLookup bool `short:"r" long:"reverselookup" description:"Perform reverse hostname lookups"`
Template string `short:"t" long:"template" description:"Path to template" default:"index.html"`
}
_, err := flags.ParseArgs(&opts, os.Args)
if err != nil {
os.Exit(1)
log.Fatal(err)
}
var a *api.API