1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Allow certain IPs for certain pages

This commit is contained in:
Zack Scholl 2016-02-07 00:24:17 -05:00
parent 29bc3f6350
commit 467eb4d5b6
2 changed files with 12 additions and 2 deletions

12
main.go
View File

@ -9,6 +9,7 @@ import (
"os"
"path"
"runtime"
"strings"
"time"
"github.com/boltdb/bolt"
@ -21,6 +22,11 @@ import (
var db *bolt.DB
var open bool
var ExternalIP string
var AllowedIPs string
func init() {
AllowedIPs = "192.168.1.13,192.168.1.12"
}
func Open() error {
var err error
@ -128,14 +134,18 @@ func main() {
})
r.GET("/:title", func(c *gin.Context) {
title := c.Param("title")
fmt.Println("------")
fmt.Println("[" + c.ClientIP() + "]")
fmt.Println("------")
if title == "ws" {
wshandler(c.Writer, c.Request)
} else if title == "about" && strings.Contains(AllowedIPs, c.ClientIP()) != true {
c.Redirect(302, "/about/view")
} else {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Title": title,
"ExternalIP": ExternalIP,
})
}
})
r.GET("/:title/*option", func(c *gin.Context) {

View File

@ -125,7 +125,7 @@
border: none;
overflow: auto;
outline: none;
font-size: x-large;
font-size: large;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;