mirror of https://github.com/1Panel-dev/1Panel
feat: Add Return Pages for Unauthorized Domains and IPs (#7306)
parent
dbe62082ff
commit
db7180a761
|
@ -3,6 +3,7 @@ package helper
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/res"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
|
@ -138,3 +139,23 @@ func ErrResponse(ctx *gin.Context, code int) {
|
|||
ctx.JSON(code, nil)
|
||||
ctx.Abort()
|
||||
}
|
||||
|
||||
func ErrWithHtml(ctx *gin.Context, code int, scope string) {
|
||||
if code == 444 {
|
||||
ctx.String(444, "")
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
file := fmt.Sprintf("html/%d.html", code)
|
||||
if code == 200 && scope != "" {
|
||||
file = fmt.Sprintf("html/200_%s.html", scope)
|
||||
}
|
||||
data, err := res.ErrorMsg.ReadFile(file)
|
||||
if err != nil {
|
||||
ctx.String(http.StatusInternalServerError, "Internal Server Error")
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
ctx.Data(code, "text/html; charset=utf-8", data)
|
||||
ctx.Abort()
|
||||
}
|
||||
|
|
|
@ -156,6 +156,9 @@ func Routers() *gin.Engine {
|
|||
Router.Use(middleware.DemoHandle())
|
||||
}
|
||||
|
||||
Router.Use(middleware.WhiteAllow())
|
||||
Router.Use(middleware.BindDomain())
|
||||
|
||||
Router.NoRoute(func(c *gin.Context) {
|
||||
if checkFrontendPath(c) {
|
||||
toIndexHtml(c)
|
||||
|
@ -182,8 +185,7 @@ func Routers() *gin.Engine {
|
|||
setWebStatic(PublicGroup)
|
||||
}
|
||||
PrivateGroup := Router.Group("/api/v1")
|
||||
PrivateGroup.Use(middleware.WhiteAllow())
|
||||
PrivateGroup.Use(middleware.BindDomain())
|
||||
|
||||
PrivateGroup.Use(middleware.GlobalLoading())
|
||||
for _, router := range rou.RouterGroupApp {
|
||||
router.InitRouter(PrivateGroup)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||
|
@ -30,11 +29,7 @@ func BindDomain() gin.HandlerFunc {
|
|||
|
||||
if domains != status.Value {
|
||||
code := LoadErrCode()
|
||||
if code != 200 {
|
||||
helper.ErrResponse(c, code)
|
||||
return
|
||||
}
|
||||
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed"))
|
||||
helper.ErrWithHtml(c, code, "err_domain")
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
|
@ -36,11 +35,7 @@ func WhiteAllow() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
code := LoadErrCode()
|
||||
if code != 200 {
|
||||
helper.ErrResponse(c, code)
|
||||
return
|
||||
}
|
||||
helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, errors.New("IP address not allowed"))
|
||||
helper.ErrWithHtml(c, code, "ip_limit")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Access Temporarily Unavailable</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
background-color: #f9f9f9;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.icon img {
|
||||
width: 100px;
|
||||
height: auto;
|
||||
}
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
color: #555;
|
||||
}
|
||||
p {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.command {
|
||||
font-family: monospace;
|
||||
background: #f0f0f0;
|
||||
padding: 5px 10px;
|
||||
border-radius: 4px;
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Access Temporarily Unavailable</h1>
|
||||
<p>The current environment has enabled domain name binding.</p>
|
||||
<p>You can enter the following command in the SSH terminal to reset the binding information:</p>
|
||||
<p class="command">1pctl rest domain</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Access Temporarily Unavailable</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
background-color: #f9f9f9;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.icon img {
|
||||
width: 100px;
|
||||
height: auto;
|
||||
}
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
color: #555;
|
||||
}
|
||||
p {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.command {
|
||||
font-family: monospace;
|
||||
background: #f0f0f0;
|
||||
padding: 5px 10px;
|
||||
border-radius: 4px;
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Access Temporarily Unavailable</h1>
|
||||
<p>The current environment has enabled authorized IP access.</p>
|
||||
<p>You can enter the following command in the SSH terminal to reset the binding information:</p>
|
||||
<p class="command">1pctl reset ips</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,55 +0,0 @@
|
|||
<template>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/unsafe.svg" class="not-img" alt="404" />
|
||||
<div class="not-detail">
|
||||
<h2>{{ $t('commons.login.notSafe') }}</h2>
|
||||
<h4>{{ $t('commons.login.errDomain1') }}</h4>
|
||||
<div>
|
||||
<h4>{{ $t('commons.login.errHelper') }} 1pctl reset domain</h4>
|
||||
<div class="float-left cursor-pointer">
|
||||
<el-icon color="#409EFC" class="ml-1.5 mt-8" :size="18" @click="copyText('1pctl reset domain')">
|
||||
<DocumentCopy />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="404">
|
||||
import { copyText } from '@/utils/util';
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.not-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
.not-img {
|
||||
margin-top: 300px;
|
||||
}
|
||||
.not-detail {
|
||||
margin-top: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
h2,
|
||||
h4 {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
h2 {
|
||||
font-size: 60px;
|
||||
color: #434e59;
|
||||
}
|
||||
h4 {
|
||||
margin: 30px 0 20px;
|
||||
float: left;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
color: #848587;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -1,54 +0,0 @@
|
|||
<template>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/unsafe.svg" class="not-img" alt="404" />
|
||||
<div class="not-detail">
|
||||
<h2>{{ $t('commons.login.notSafe') }}</h2>
|
||||
<h4>{{ $t('commons.login.errIP1') }}</h4>
|
||||
<div>
|
||||
<h4>{{ $t('commons.login.errHelper') }} 1pctl reset ips</h4>
|
||||
<div class="float-left cursor-pointer">
|
||||
<el-icon color="#409EFC" class="ml-1.5 mt-8" :size="18" @click="copyText('1pctl reset ips')">
|
||||
<DocumentCopy />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="404">
|
||||
import { copyText } from '@/utils/util';
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.not-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
.not-img {
|
||||
margin-top: 300px;
|
||||
}
|
||||
.not-detail {
|
||||
margin-top: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
h2,
|
||||
h4 {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
h2 {
|
||||
font-size: 60px;
|
||||
color: #434e59;
|
||||
}
|
||||
h4 {
|
||||
margin: 30px 0 20px;
|
||||
float: left;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
color: #848587;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -1,55 +0,0 @@
|
|||
<template>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/unsafe.svg" class="not-img" alt="404" />
|
||||
<div class="not-detail">
|
||||
<h2>{{ $t('commons.login.notSafe') }}</h2>
|
||||
<h4>{{ $t('commons.login.safeEntrance1') }}</h4>
|
||||
<div>
|
||||
<h4>{{ $t('commons.login.safeEntrance2') }}</h4>
|
||||
<div class="float-left cursor-pointer">
|
||||
<el-icon color="#409EFC" class="ml-1.5 mt-8" :size="18" @click="copyText('1pctl user-info')">
|
||||
<DocumentCopy />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="404">
|
||||
import { copyText } from '@/utils/util';
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.not-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
.not-img {
|
||||
margin-top: 300px;
|
||||
}
|
||||
.not-detail {
|
||||
margin-top: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
h2,
|
||||
h4 {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
h2 {
|
||||
font-size: 60px;
|
||||
color: #434e59;
|
||||
}
|
||||
h4 {
|
||||
margin: 30px 0 20px;
|
||||
float: left;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
color: #848587;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue