mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Allow certain IPs for certain pages
Former-commit-id: ff23e987f818f840742da0dcca1d9148b54329b9 [formerly 09e7073733503d998128b78be261d48cd91eee68] [formerly 4fff11f4bfd132937354ea5ffd06460de5c6fbc2 [formerly 44f48dc97089a15a94c2af64995a743ae2197862 [formerly467eb4d5b6
]]] Former-commit-id: 14ceb7f40eb4ed9bdd20a6858ee5edcc23fc3ff8 [formerly 520934eeca459f2d94e7fa8e68ab83904549cb24] Former-commit-id: c1adb3e8ea81e13d1c0742f493a4517765846191 Former-commit-id:d55bc9e0f9
This commit is contained in:
parent
df5dd991ea
commit
fe8dfe55bc
12
main.go
12
main.go
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user