Skip to content

Commit

Permalink
Remove recaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
jason5ng32 committed May 10, 2024
1 parent 6c7ff68 commit 4e9f449
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 151 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ IPINFO_API_TOKEN=""
KEYCDN_USER_AGENT=""
IPCHECKING_API_KEY=""
CLOUDFLARE_API=""
VITE_RECAPTCHA_SITE_KEY=""
RECAPTCHA_SECRET_KEY=""
SECURITY_BLACKLIST_LOG_FILE_PATH=""
SECURITY_RATE_LIMIT=""
SECURITY_DELAY_AFTER=""
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ You can use the program without adding any environment variables, but if you wan
| `IPAPIIS_API_KEY` | No | `""` | API Key for IPAPI.is, used to obtain IP geolocation information through IPAPI.is |
| `KEYCDN_USER_AGENT` | No | `""` | The domain name when using KeyCDN, must contain https prefix. Used to obtain IP address information through KeyCDN |
| `CLOUDFLARE_API` | No | `""` | API Key for Cloudflare, used to obtain AS system information through Cloudflare |
| `VITE_RECAPTCHA_SITE_KEY` | No | `""` | Google reCAPTCHA's Site Key, used to display reCAPTCHA verification on the frontend |
| `RECAPTCHA_SECRET_KEY` | No | `""` | Google reCAPTCHA's Secret Key, used to verify reCAPTCHA verification on the backend |

> [!TIP]
> Environment variables starting with `SECURITY_` are only valid when deploying using npm or Docker.
Expand Down
2 changes: 0 additions & 2 deletions README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ Vous pouvez utiliser le programme sans ajouter de variables d'environnement, mai
| `IPAPIIS_API_KEY` | Non | `""` | Clé API pour IPAPI.is, utilisée pour obtenir des informations de géolocalisation sur l'adresse IP via IPAPI.is |
| `KEYCDN_USER_AGENT` | Non | `""` | Le nom de domaine lorsque vous utilisez KeyCDN, doit contenir le préfixe https. Utilisé pour obtenir des informations sur l'adresse IP via KeyCDN |
| `CLOUDFLARE_API` | Non | `""` | Clé API pour Cloudflare, utilisée pour obtenir des informations sur le système AS via Cloudflare |
| `VITE_RECAPTCHA_SITE_KEY` | Non | `""` | Clé de site reCAPTCHA de Google, utilisée pour afficher la vérification reCAPTCHA sur le frontend |
| `RECAPTCHA_SECRET_KEY` | Non | `""` | Clé secrète reCAPTCHA de Google, utilisée pour vérifier la vérification reCAPTCHA sur le backend |

> [!TIP]
> Les variables d'environnement commençant par `SECURITY_` ne sont valides que lors du déploiement à l'aide de npm ou de Docker.
Expand Down
2 changes: 0 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ docker run -d -p 18966:18966 --name myip --restart always jason5ng32/myip:latest
| `IPAPIIS_API_KEY` | 否 | `""` | IPAPI.is 的 API Key,用于通过 IPAPI.is 获取 IP 归属地信息 |
| `KEYCDN_USER_AGENT` | 否 | `""` | 使用 KeyCDN 时的域名,需包含 https 前缀。用于通过 KeyCDN 获取 IP 归属地信息 |
| `CLOUDFLARE_API` | 否 | `""` | Cloudflare 的 API Key,用于通过 Cloudflare 获取 AS 系统的信息 |
| `VITE_RECAPTCHA_SITE_KEY` | 否 | `""` | Google reCAPTCHA 的 Site Key,用于在前端显示 reCAPTCHA 验证 |
| `RECAPTCHA_SECRET_KEY` | 否 | `""` | Google reCAPTCHA 的 Secret Key,用于在后端验证 reCAPTCHA 验证 |

> [!TIP]
> 以 `SECURITY_` 开头的环境变量仅在使用 npm 或 Docker 部署时有效。
Expand Down
1 change: 0 additions & 1 deletion api/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default (req, res) => {
keyCDN: process.env.KEYCDN_USER_AGENT,
originalSite,
cloudFlare: process.env.CLOUDFLARE_API,
recaptcha: process.env.VITE_RECAPTCHA_SITE_KEY && process.env.RECAPTCHA_SECRET_KEY,
ipapiis: process.env.IPAPIIS_API_KEY,
};
let result = {};
Expand Down
63 changes: 0 additions & 63 deletions api/recaptcha.js

This file was deleted.

2 changes: 0 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import keycdnHandler from './api/keycdn.js';
import ipCheckingHandler from './api/ipchecking.js';
import ipsbHandler from './api/ipsb.js';
import cfHander from './api/cfradar.js';
import recaptchaHandler from './api/recaptcha.js';
import validateConfigs from './api/configs.js';
import dnsResolver from './api/dnsresolver.js';
import rateLimit from 'express-rate-limit';
Expand Down Expand Up @@ -132,7 +131,6 @@ app.get('/api/keycdn', keycdnHandler);
app.get('/api/ipchecking', ipCheckingHandler);
app.get('/api/ipsb', ipsbHandler);
app.get('/api/cfradar', cfHander);
app.get('/api/recaptcha', recaptchaHandler);
app.get('/api/dnsresolver', dnsResolver);
app.get('/api/whois', whois);
app.get('/api/ipapiis', ipapiisHandler);
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export default {
keys: "q",
action: () => {
this.openModal("IPCheck");
this.$refs.queryIPRef.loadRecaptchaScript();
this.$refs.queryIPRef.openQueryIP();
this.$trackEvent('ShortCut', 'ShortCut', 'QueryIP');
},
description: this.$t('shortcutKeys.IPCheck'),
Expand Down
69 changes: 3 additions & 66 deletions src/components/queryip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<li class="list-group-item jn-list-group-item" :class="{ 'dark-mode': isDarkMode }">
<span class="jn-text col-auto"><i class="bi bi-sign-turn-right"></i> {{
$t('ipInfos.City')
}}</span>&nbsp;:&nbsp;
}}</span>&nbsp;:&nbsp;
<span class="col-10 ">
{{ modalQueryResult.city }}
</span>
Expand Down Expand Up @@ -102,14 +102,9 @@
<div class="modal-footer" :class="{ 'dark-mode-border': isDarkMode }">
<button id="sumitQueryButton" type="button" class="btn btn-primary"
:class="{ 'btn-secondary': !isValidIP(inputIP), 'btn-primary': isValidIP(inputIP) }"
@click="submitQuery" :disabled="!isValidIP(inputIP) || reCaptchaStatus === false || isChecking === 'running'
@click="submitQuery" :disabled="!isValidIP(inputIP) || isChecking === 'running'
">{{
$t('ipcheck.Button') }}</button>
<span v-if="configs.recaptcha" class="text-secondary" style="font-size:10px">
This site is protected by reCAPTCHA and the Google
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
<a href="https://policies.google.com/terms">Terms of Service</a> apply.
</span>
</div>


Expand Down Expand Up @@ -147,8 +142,6 @@ export default {
inputIP: '',
modalQueryResult: null,
modalQueryError: "",
reCaptchaStatus: true,
reCaptchaLoaded: false,
isChecking: "idle",
ipGeoSource: this.userPreferences.ipGeoSource,
}
Expand All @@ -162,28 +155,7 @@ export default {
this.modalQueryError = "";
this.modalQueryResult = null;
this.isChecking = "running";
// 如果 reCAPTCHA 已启用,验证令牌
switch (this.configs.recaptcha) {
case true:
// 执行 reCAPTCHA 验证
grecaptcha.ready(async () => {
grecaptcha.execute(import.meta.env.VITE_RECAPTCHA_SITE_KEY, { action: 'submit' }).then(async (token) => {
let recaptchaSuccess = await this.verifyRecaptchaToken(token);
if (recaptchaSuccess) {
this.reCaptchaStatus = true;
await this.fetchIPForModal(this.inputIP);
} else {
this.reCaptchaStatus = false;
this.modalQueryError = this.$t('ipcheck.recaptchaError');
this.isChecking = "idle";
}
});
});
break;
case false:
await this.fetchIPForModal(this.inputIP);
break;
}
await this.fetchIPForModal(this.inputIP);
} else {
// 如果 IP 无效,设置错误信息
this.modalQueryError = this.$t('ipcheck.Error');
Expand All @@ -192,38 +164,8 @@ export default {
}
},

// 加载 reCAPTCHA 脚本
loadRecaptchaScript() {
if (this.configs.recaptcha === false || this.reCaptchaLoaded === true) {
return;
}
// 创建一个 script 元素
const script = document.createElement('script');
script.src = `https://www.google.com/recaptcha/api.js?render=${import.meta.env.VITE_RECAPTCHA_SITE_KEY}`;
script.async = true;
script.defer = true;
document.head.appendChild(script);
// 获取加载完成的状态
script.onload = () => {
this.reCaptchaLoaded = true;
};
},

// 验证 reCAPTCHA 令牌
async verifyRecaptchaToken(token) {
const response = await fetch(`/api/recaptcha?token=${token}`, {
method: 'GET',
});
const data = await response.json();
return data.success;
},

// 打开查询 IP 的模态框
openQueryIP() {
// 如果 reCAPTCHA 脚本尚未加载,加载它
if (!window.grecaptcha && this.configs.recaptcha) {
this.loadRecaptchaScript();
}
this.$trackEvent('SideButtons', 'ToggleClick', 'QueryIP');
},

Expand Down Expand Up @@ -290,11 +232,6 @@ export default {
// 获取 IP 信息
async fetchIPForModal(ip, sourceID = null) {

if (this.reCaptchaStatus === false) {
this.modalQueryError = this.$t('ipcheck.recaptchaError');
return;
}

let lang = this.$Lang;
if (lang === 'zh') {
lang = 'zh-CN';
Expand Down
3 changes: 1 addition & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@
"Title": "IP Check",
"Placeholder": "Please enter an IP address",
"Button": "Check",
"Error": "Please enter a valid IPv4 or IPv6 address.",
"recaptchaError": "It looks like you are a bot."
"Error": "Please enter a valid IPv4 or IPv6 address."
},
"alert": {
"id": "alert",
Expand Down
3 changes: 1 addition & 2 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@
"Title": "Vérification IP",
"Placeholder": "Veuillez entrer une adresse IP",
"Button": "Vérifier",
"Error": "Veuillez entrer une adresse IPv4 ou IPv6 valide.",
"recaptchaError": "Il semble que vous êtes un robot."
"Error": "Veuillez entrer une adresse IPv4 ou IPv6 valide."
},
"alert": {
"id": "alert",
Expand Down
3 changes: 1 addition & 2 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@
"Title": "IP 查询",
"Placeholder": "请输入 IP 地址",
"Button": "查询",
"Error": "请输入有效的 IPv4 或 IPv6 地址。",
"recaptchaError": "你未通过 reCAPTCHA 验证,查询功能已被禁用"
"Error": "请输入有效的 IPv4 或 IPv6 地址。"
},
"alert": {
"id": "alert",
Expand Down
4 changes: 0 additions & 4 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ footer {
min-width: 140pt;
}

.grecaptcha-badge {
visibility: hidden;
}

.svgMap-tooltip {
z-index: 100000 !important;
}

0 comments on commit 4e9f449

Please sign in to comment.