Skip to content

Instantly share code, notes, and snippets.

@hatsuyuki280
Last active October 16, 2024 15:28
Show Gist options
  • Save hatsuyuki280/c644544e87b4b2d68d30a3f088dbd705 to your computer and use it in GitHub Desktop.
Save hatsuyuki280/c644544e87b4b2d68d30a3f088dbd705 to your computer and use it in GitHub Desktop.
Cloudflare Universal SSL switch to Google CA

About

This tool can switch Cloudflare Universal SSL to Google CA.
这个工具可以帮助你切换cloudflare的SSL合作商到Google Trust Services
このツールはCloudflareのSSLパートナーをGoogle Trust Servicesに変更できる。

Usage

  1. 有请中文用户先去吃点东西~
  2. そして日本の方も、ミルクティーでも飲みながら待ちましょう~
  3. Make sure you have Python3 Environment.
  4. Make sure "requests" is installed or install it frist.
  5. We have 3 version of file for english, chinese, and japanese. Except language, all will same.
  6. Get any .py file as your favorite filename and remenber where is they in.
  7. Open your favorite editor to edit downloaded .py file.
  8. Read comment and make sure variable API_TOKEN is filled with valid value.
  9. OK, Take some coffee and let's wait a moments. Someone maybe reading this script now and make sure they know what will be happen. but for safety, I actually recommend everyone to read it before running it. Although it is technicaly not a work of art.
  10. OKey! Let's try to use python3 to run it!
  11. If you see anything is "success". please be carefully! Because anything is successfully done and cloudflare will send a lot of Email to fill your mailbox until it explode.

  1. ここに日本語版の取説書き込みたいんが。。。お腹が空いたので。。英語版で我慢して~
  2. 気合と根性で!

  1. 假装已经写了一些中文说明.png
  2. 看着你们吃东西咱的肚子都饿了.png
  3. 总之。。。你们先努力看英语吧~咱吃饭去了quq
#!/bin/env python3
# Written by @hatsuyuki280
# with The Unlicense
# for more? refer to <https://unlicense.org>
# Use it and have fun!
from requests import get,patch
## Please make sure this token is valid to operate zone/ssl&cert (edit)
## Notice! If you want NOT to switch some zone, please exclude a specific zone from the token.
## always, I recommend creating a new token for every different operation and let life time as well as short.
API_TOKEN = ''
data = r'{"certificate_authority":"google"}'
## Usable["google", "digicert", "lets_encrypt"]
header = {"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"}
base_url = r"https://api.cloudflare.com/client/v4/zones/{zone_id}/ssl/universal/settings"
zones = get('https://api.cloudflare.com/client/v4/zones',headers = header).json()
for zone in zones['result']:
temp_response = patch(base_url.format(zone_id=zone['id']),headers = header,data = data).json()
print(f'{zone["name"]}: {"success" if temp_response["success"] else f"""Error: {temp_response["errors"]}""" }')
#!/bin/env python3
# 作り:@hatsuyuki280
# The Unlicenseで共有
# 許可証について:https://unlicense.org
# 役に立つと嬉しい
from requests import get,patch
## 該当Tokenが有効かつ ゾーン/SSL&証明書 の編集を許可していることを確認しましょう。
## 注目:変更したくないゾーンがある場合、予めTokenの生成時にてそれを排除するように!
## セキュリティのため、Tokenは使い旅に新しいものを生成するようにしましょう!
## Tokenの有効時間をできるだけ短時間のものにしましょう!
API_TOKEN = ''
header = {"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"}
data = r'{"certificate_authority":"google"}'
## 使える選択肢["google", "digicert", "lets_encrypt"]
base_url = r"https://api.cloudflare.com/client/v4/zones/{zone_id}/ssl/universal/settings"
zones = get('https://api.cloudflare.com/client/v4/zones',headers = header).json()
for zone in zones['result']:
temp_response = patch(base_url.format(zone_id=zone['id']),headers = header,data = data).json()
print(f'{zone["name"]}: {"無事完了" if temp_response["success"] else f"""エラーでした: {temp_response["errors"]}""" }')
#!/bin/env python3
# 初版由 @hatsuyuki280 编写
# 使用 The Unlicense 协议共享
# 想知道更多?阅读:https://unlicense.org
# 人生苦短,我选____。
from requests import get,patch
## 请确保该 Token 有效且有 区域/SSL&证书 的编辑权
## 注意!如果你有不希望编辑的区域,请在生成 Token 时排除他们。
## 无论何时,我都会推荐为每一个操作生成独立且尽可能短效的Token!
API_TOKEN = ''
header = {"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"}
data = r'{"certificate_authority":"google"}'
## 可用选项["google", "digicert", "lets_encrypt"]
base_url = r"https://api.cloudflare.com/client/v4/zones/{zone_id}/ssl/universal/settings"
zones = get('https://api.cloudflare.com/client/v4/zones',headers = header).json()
for zone in zones['result']:
temp_response = patch(base_url.format(zone_id=zone['id']),headers = header,data = data).json()
print(f'{zone["name"]}: {"成功完成" if temp_response["success"] else f"""内部错误: {temp_response["errors"]}""" }')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment