- Go + Gin + html/template 服务端渲染 - 主页:Google 风格搜索框 + 导航卡片 - 后台:卡片 CRUD、搜索引擎配置、主页背景/标题配置 - 图片上传:支持 jpg/jpeg/png/gif,自动压缩,缩略图参数 ?thumb=1 - 安全:登录日志、修改密码、IP 自动封禁、IP 白名单 - 访问统计:主页访问/卡片点击/搜索追踪、实时流量、IP 统计 - SQLite 存储(modernc.org/sqlite,纯 Go) - 内存 Session + bcrypt 密码哈希
47 lines
956 B
Go
47 lines
956 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"simple_portal/models"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// AccessLogsGet 渲染访问日志页面,支持按IP和动作类型筛选。
|
|
func AccessLogsGet(c *gin.Context) {
|
|
username, _ := c.Get("username")
|
|
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
if page < 1 {
|
|
page = 1
|
|
}
|
|
pageSize := 30
|
|
|
|
filterIP := c.Query("ip")
|
|
filterAction := c.DefaultQuery("action", "")
|
|
|
|
logs, total, err := models.GetAccessLogs(page, pageSize, filterIP, filterAction)
|
|
if err != nil {
|
|
logs = []models.AccessLog{}
|
|
total = 0
|
|
}
|
|
|
|
totalPages := (total + pageSize - 1) / pageSize
|
|
if totalPages < 1 {
|
|
totalPages = 1
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "admin/access_logs.html", gin.H{
|
|
"Title": "访问日志",
|
|
"Username": username,
|
|
"Logs": logs,
|
|
"Page": page,
|
|
"TotalPages": totalPages,
|
|
"Total": total,
|
|
"FilterIP": filterIP,
|
|
"FilterAction": filterAction,
|
|
})
|
|
}
|