Add files
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -174,3 +174,5 @@ cython_debug/
|
|||||||
# PyPI configuration file
|
# PyPI configuration file
|
||||||
.pypirc
|
.pypirc
|
||||||
|
|
||||||
|
# custom
|
||||||
|
config.py
|
||||||
|
31
README.md
31
README.md
@@ -1,3 +1,30 @@
|
|||||||
# cfedge-check
|
# Cloudflare Edge Location Checker
|
||||||
|
|
||||||
Cloudflare Edge Location Checker
|
Cloudflareを使用するサイトに接続するとき、エッジロケーションが想定されている場所になるかを確認します<br>
|
||||||
|
その確認結果をMisskeyに投稿します
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
- 引数なし: 確認から結果投稿までを行います
|
||||||
|
- `--dry-run`: 確認を行い、結果はMisskeyに投稿せず標準出力に表示します
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Pythonのenvを作る<br>
|
||||||
|
```
|
||||||
|
python3 -m venv env
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 必須パッケージをインストール<br>
|
||||||
|
```
|
||||||
|
env/bin/pip install -U -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
3. config.py をサンプルに従い編集
|
||||||
|
|
||||||
|
4. 実行
|
||||||
|
```
|
||||||
|
env/bin/python3 cfedge.py
|
||||||
|
```
|
||||||
|
|
||||||
|
cronに登録するなどして自動実行できます
|
62
cfedge.py
Normal file
62
cfedge.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2025 CyberRex
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
class CFSite:
|
||||||
|
def __init__(self, url, plan):
|
||||||
|
self.url = url
|
||||||
|
self.plan = plan
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Check Cloudflare Edge Locations and post to Misskey.')
|
||||||
|
parser.add_argument('--dry-run', action='store_true', help='Run without posting to Misskey')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if os.path.exists('config.py'):
|
||||||
|
import config
|
||||||
|
else:
|
||||||
|
print("config.py not found")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
test_sites = [
|
||||||
|
CFSite('misskey.io', 'Enterprise'),
|
||||||
|
CFSite('misskey.systems', 'Pro'),
|
||||||
|
CFSite('ohtrmi.cbrx.io', 'Free'),
|
||||||
|
]
|
||||||
|
|
||||||
|
result_txt = []
|
||||||
|
result_txt.append('Cloudflare Edge Location Check')
|
||||||
|
result_txt.append('')
|
||||||
|
|
||||||
|
# read from /cdn-cgi/trace
|
||||||
|
for site in test_sites:
|
||||||
|
try:
|
||||||
|
response = requests.get(f"https://{site.url}/cdn-cgi/trace", timeout=5)
|
||||||
|
response.raise_for_status()
|
||||||
|
trace_info = response.text
|
||||||
|
colo_line = next((line for line in trace_info.splitlines() if line.startswith('colo=')), None)
|
||||||
|
if colo_line:
|
||||||
|
colo = colo_line.split('=')[1]
|
||||||
|
if colo in config.expected_edge_locations:
|
||||||
|
result_txt.append(f'- {site.url} ({site.plan}) : {colo}✅️')
|
||||||
|
else:
|
||||||
|
result_txt.append(f'- {site.url} ({site.plan}) : {colo}⚠')
|
||||||
|
else:
|
||||||
|
print(f"Could not find 'colo' in the trace info for {site.url}")
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print(f"Error accessing {site.url}: {e}")
|
||||||
|
|
||||||
|
txt = '\n'.join(result_txt)
|
||||||
|
|
||||||
|
# post to misskey
|
||||||
|
payload = {
|
||||||
|
'text': txt,
|
||||||
|
'visibility': 'home'
|
||||||
|
}
|
||||||
|
|
||||||
|
if not args.dry_run:
|
||||||
|
requests.post(f"{config.misskey_url}/api/notes/create", headers={'Authorization': 'Bearer ' + config.misskey_token}, json=payload)
|
||||||
|
else:
|
||||||
|
print(txt)
|
11
config.example.py
Normal file
11
config.example.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# URL of Misskey instance
|
||||||
|
misskey_url = 'https://your-misskey-instance.com'
|
||||||
|
|
||||||
|
# Access token of Misskey
|
||||||
|
# API token with notes:write permission is required
|
||||||
|
misskey_token = 'your-misskey-token'
|
||||||
|
|
||||||
|
# Expected locations
|
||||||
|
# Default is 4 locations in Japan
|
||||||
|
# For location codes you want to add, see https://www.feitsui.com/en/article/26
|
||||||
|
expected_edge_locations = ['NRT', 'KIX', 'FUK', 'OKA']
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
requests
|
Reference in New Issue
Block a user