-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
104 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
# Server | ||
BACKEND_PORT="11966" | ||
FRONTEND_PORT="18966" | ||
BING_MAP_API_KEY="" | ||
ALLOWED_DOMAINS="" | ||
# APIs | ||
BING_MAP_API_KEY="" | ||
IPINFO_API_TOKEN="" | ||
KEYCDN_USER_AGENT="" | ||
IPCHECKING_API_KEY="" | ||
CLOUDFLARE_API="" | ||
IPAPIIS_API_KEY="" | ||
IPCHECKING_API_KEY="" | ||
MAC_LOOKUP_API_KEY="" | ||
# Security related | ||
SECURITY_BLACKLIST_LOG_FILE_PATH="" | ||
SECURITY_RATE_LIMIT="" | ||
SECURITY_DELAY_AFTER="" | ||
IPAPIIS_API_KEY="" | ||
MAC_LOOKUP_API_KEY="" | ||
# Google Analytics | ||
VITE_GOOGLE_ANALYTICS_ID="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import maxmind from 'maxmind'; | ||
import { isValidIP } from '../common/valid-ip.js'; | ||
import { refererCheck } from '../common/referer-check.js'; | ||
|
||
let cityLookup, asnLookup; | ||
|
||
// 异步初始化数据库 | ||
async function initDatabases() { | ||
cityLookup = await maxmind.open('./common/maxmind-db/GeoLite2-City.mmdb'); | ||
asnLookup = await maxmind.open('./common/maxmind-db/GeoLite2-ASN.mmdb'); | ||
} | ||
|
||
initDatabases(); | ||
|
||
export default (req, res) => { | ||
|
||
// 限制只能从指定域名访问 | ||
const referer = req.headers.referer; | ||
if (!refererCheck(referer)) { | ||
return res.status(403).json({ error: referer ? 'Access denied' : 'What are you doing?' }); | ||
} | ||
|
||
const ip = req.query.ip; | ||
if (!ip) { | ||
return res.status(400).json({ error: 'No IP address provided' }); | ||
} | ||
|
||
// 检查 IP 地址是否合法 | ||
if (!isValidIP(ip)) { | ||
return res.status(400).json({ error: 'Invalid IP address' }); | ||
} | ||
|
||
// 获取请求语言 | ||
const lang = req.query.lang === 'zh-CN' || req.query.lang === 'en' || req.query.lang === 'fr' ? req.query.lang : 'en'; | ||
|
||
try { | ||
const city = cityLookup.get(ip); | ||
const asn = asnLookup.get(ip); | ||
let result = modifyJson(ip, lang, city, asn); | ||
res.json(result); | ||
} catch (e) { | ||
res.status(500).json({ error: e.message }); | ||
} | ||
} | ||
|
||
function modifyJson(ip, lang, city, asn) { | ||
city = city || {}; | ||
asn = asn || {}; | ||
return { | ||
ip, | ||
city: city.city ? city.city.names[lang] || city.city.names.en : "N/A", | ||
region: city.subdivisions ? city.subdivisions[0].names[lang] || city.subdivisions[0].names.en : "N/A", | ||
country: city.country ? city.country.iso_code : "N/A", | ||
country_name: city.country ? city.country.names[lang] : "N/A", | ||
country_code: city.country ? city.country.iso_code : "N/A", | ||
latitude: city.location ? city.location.latitude : "N/A", | ||
longitude: city.location ? city.location.longitude : "N/A", | ||
asn: asn.autonomous_system_number ? "AS" + asn.autonomous_system_number : "N/A", | ||
org: asn.autonomous_system_organization ? asn.autonomous_system_organization : "N/A" | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters