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:
parent
29bc3f6350
commit
467eb4d5b6
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