mirror of
https://github.com/wushuo894/ani-rss.git
synced 2026-03-13 09:20:23 +00:00
refactor: 优化ip白名单
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package ani.rss.auth.fun;
|
||||
|
||||
import ani.rss.commons.CacheUtils;
|
||||
import ani.rss.entity.Config;
|
||||
import ani.rss.util.basic.CidrRangeChecker;
|
||||
import ani.rss.util.other.AuthUtil;
|
||||
@@ -8,13 +7,10 @@ import ani.rss.util.other.ConfigUtil;
|
||||
import cn.hutool.core.lang.PatternPool;
|
||||
import cn.hutool.core.net.Ipv4Util;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Slf4j
|
||||
@@ -34,41 +30,33 @@ public class IpWhitelist implements Function<HttpServletRequest, Boolean> {
|
||||
if (StrUtil.isBlank(ip)) {
|
||||
return false;
|
||||
}
|
||||
String key = "IpWhitelist:" + SecureUtil.md5(ipWhitelistStr) + ":" + ip;
|
||||
try {
|
||||
if (!PatternPool.IPV4.matcher(ip).matches() && !PatternPool.IPV6.matcher(ip).matches()) {
|
||||
return false;
|
||||
}
|
||||
Boolean b = CacheUtils.get(key);
|
||||
if (Objects.nonNull(b)) {
|
||||
return b;
|
||||
}
|
||||
List<String> list = StrUtil.split(ipWhitelistStr, "\n", true, true);
|
||||
for (String string : list) {
|
||||
// 判断是否为 ipv4 或 ipv6
|
||||
if (PatternPool.IPV4.matcher(string).matches() || PatternPool.IPV6.matcher(string).matches()) {
|
||||
if (string.equals(ip)) {
|
||||
CacheUtils.put(key, Boolean.TRUE, TimeUnit.MINUTES.toMillis(10));
|
||||
return true;
|
||||
}
|
||||
if (string.equals(ip)) {
|
||||
return true;
|
||||
}
|
||||
// 非ipv4
|
||||
if (!PatternPool.IPV4.matcher(string).matches()) {
|
||||
continue;
|
||||
}
|
||||
// 通配符,如 192.168.*.1
|
||||
if (string.contains("*")) {
|
||||
if (Ipv4Util.matches(string, ip)) {
|
||||
CacheUtils.put(key, Boolean.TRUE, TimeUnit.MINUTES.toMillis(10));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// X.X.X.X/X
|
||||
if (CidrRangeChecker.CIDR_PATTERN.matcher(string).matches()) {
|
||||
if (CidrRangeChecker.isIpInRange(ip, string)) {
|
||||
CacheUtils.put(key, Boolean.TRUE, TimeUnit.MINUTES.toMillis(10));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// X.X.X.X-X.X.X.X
|
||||
if (isIpInRange(ip, string)) {
|
||||
CacheUtils.put(key, Boolean.TRUE, TimeUnit.MINUTES.toMillis(10));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +64,6 @@ public class IpWhitelist implements Function<HttpServletRequest, Boolean> {
|
||||
log.error("ip白名单存在问题");
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
CacheUtils.put(key, Boolean.FALSE, TimeUnit.MINUTES.toMillis(10));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,9 @@ import ani.rss.commons.MavenUtils;
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.headers.Header;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import io.swagger.v3.oas.models.security.OAuthFlows;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -99,7 +99,6 @@
|
||||
|
||||
<script setup>
|
||||
import {onMounted, ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import {ElMessage, ElText} from "element-plus";
|
||||
import Popconfirm from "@/other/Popconfirm.vue";
|
||||
import {Book, Github, Telegram} from "@vicons/fa";
|
||||
|
||||
@@ -76,7 +76,6 @@
|
||||
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {config} from "@/js/http.js";
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {Download} from '@element-plus/icons-vue'
|
||||
import {config} from "@/js/http.js";
|
||||
|
||||
@@ -65,7 +65,6 @@
|
||||
<script setup>
|
||||
|
||||
import {ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import * as http from "@/js/http.js";
|
||||
|
||||
let me = ref({
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
|
||||
<script setup>
|
||||
import {ElMessage} from "element-plus";
|
||||
import api from "@/js/api.js";
|
||||
import {ref} from "vue";
|
||||
import * as http from "@/js/http.js";
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ import Mikan from "./Mikan.vue";
|
||||
import Ani from "./Ani.vue";
|
||||
import Bgm from "./Bgm.vue";
|
||||
import {aniData} from "@/js/ani.js";
|
||||
import * as http from "@/js/http.js";
|
||||
import * as http from "@/js/http.js";
|
||||
|
||||
const showRss = ref(true)
|
||||
const mikan = ref()
|
||||
|
||||
@@ -137,7 +137,6 @@ import Config from "./Config.vue";
|
||||
import List from "./List.vue";
|
||||
import Add from "./Add.vue";
|
||||
import Logs from "./Logs.vue";
|
||||
import api from "@/js/api.js";
|
||||
import {ElMessage} from "element-plus";
|
||||
import Popconfirm from "@/other/Popconfirm.vue";
|
||||
import Manage from "./Manage.vue";
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import {authorization} from "@/js/global.js";
|
||||
import * as http from "@/js/http.js";
|
||||
|
||||
|
||||
@@ -184,7 +184,6 @@ import {ref} from "vue";
|
||||
import {UploadFilled} from "@element-plus/icons-vue";
|
||||
import {ElMessage, ElMessageBox} from "element-plus";
|
||||
import Bgm from "./Bgm.vue";
|
||||
import api from "@/js/api.js";
|
||||
import Exclude from "@/config/Exclude.vue";
|
||||
import CollectionPreview from "./CollectionPreview.vue";
|
||||
import CustomTags from "@/config/CustomTags.vue";
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
import {ref} from "vue";
|
||||
import {ElMessage} from "element-plus";
|
||||
import CryptoJS from "crypto-js";
|
||||
import api from "@/js/api.js";
|
||||
import Exclude from "@/config/Exclude.vue";
|
||||
import Notification from "@/config/Notification.vue";
|
||||
import Proxy from "@/config/Proxy.vue";
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {UploadFilled} from "@element-plus/icons-vue";
|
||||
import {authorization} from "@/js/global.js";
|
||||
@@ -91,7 +90,7 @@ let show = (newAni) => {
|
||||
let okLoading = ref(false)
|
||||
let ok = () => {
|
||||
okLoading.value = true
|
||||
http.setAni(false,ani.value)
|
||||
http.setAni(false, ani.value)
|
||||
.then(res => {
|
||||
ElMessage.success(res.message)
|
||||
window.$reLoadList()
|
||||
|
||||
@@ -86,7 +86,6 @@
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import Mikan from "./Mikan.vue";
|
||||
import api from "@/js/api.js";
|
||||
|
||||
const editIndex = ref(-1)
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import api from "@/js/api.js";
|
||||
import * as http from "@/js/http.js";
|
||||
|
||||
// 记录排序方式
|
||||
|
||||
Reference in New Issue
Block a user