Merge pull request #7 from zhanghan177/master
Add support for new API tokens.
This commit is contained in:
commit
d7ef763c8d
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
|
config.json
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
@ -122,4 +124,4 @@ venv.bak/
|
|||||||
dmypy.json
|
dmypy.json
|
||||||
|
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|||||||
30
README.md
30
README.md
@ -8,13 +8,35 @@ This script was written for the Raspberry Pi platform to enable low cost, simple
|
|||||||
|
|
||||||
## :vertical_traffic_light: Getting Started
|
## :vertical_traffic_light: Getting Started
|
||||||
|
|
||||||
Edit config.json and replace the values with your own.
|
First copy the example configuration file into the real one.
|
||||||
|
|
||||||
Values explained:
|
```bash
|
||||||
|
cp config-example.json config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit `config.json` and replace the values with your own.
|
||||||
|
|
||||||
|
### Authentication methods
|
||||||
|
|
||||||
|
You can choose to use either the newer API tokens, or the traditional API keys
|
||||||
|
|
||||||
|
To generate a new API tokens, go to https://dash.cloudflare.com/profile/api-tokens and create a token capable of **Edit DNS**. Then replace the value in
|
||||||
|
```json
|
||||||
|
"authentication":
|
||||||
|
"api_token": "Your cloudflare API token, including the capability of **Edit DNS**"
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, you can use the traditional API keys by setting appropriate values for:
|
||||||
|
```json
|
||||||
|
"authentication":
|
||||||
|
"api_key":
|
||||||
|
"api_key": "Your cloudflare API Key",
|
||||||
|
"account_email": "The email address you use to sign in to cloudflare",
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other values explained
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"api_key": "Your cloudflare API Key",
|
|
||||||
"account_email": "The email address you use to sign in to cloudflare",
|
|
||||||
"zone_id": "The ID of the zone that will get the records. From your dashboard click into the zone. Under the overview tab, scroll down and the zone ID is listed in the right rail",
|
"zone_id": "The ID of the zone that will get the records. From your dashboard click into the zone. Under the overview tab, scroll down and the zone ID is listed in the right rail",
|
||||||
"subdomains": "Array of subdomains you want to update the A & where applicable, AAAA records. IMPORTANT! Only write subdomain name. Do not include the base domain name. (e.g. foo or an empty string to update the base domain)",
|
"subdomains": "Array of subdomains you want to update the A & where applicable, AAAA records. IMPORTANT! Only write subdomain name. Do not include the base domain name. (e.g. foo or an empty string to update the base domain)",
|
||||||
"proxied": false (defaults to false. Make it true if you want CDN/SSL benefits from cloudflare. This usually disables SSH)
|
"proxied": false (defaults to false. Make it true if you want CDN/SSL benefits from cloudflare. This usually disables SSH)
|
||||||
|
|||||||
@ -83,11 +83,17 @@ def commitRecord(ip):
|
|||||||
|
|
||||||
|
|
||||||
def cf_api(endpoint, method, config, headers={}, data=False):
|
def cf_api(endpoint, method, config, headers={}, data=False):
|
||||||
headers = {
|
api_token = config['authentication']['api_token']
|
||||||
"X-Auth-Email": config['account_email'],
|
if api_token != '' and api_token != 'api_token_here':
|
||||||
"X-Auth-Key": config['api_key'],
|
headers = {
|
||||||
**headers
|
"Authorization": "Bearer " + config['authentication']['api_token'],
|
||||||
}
|
**headers
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
headers = {
|
||||||
|
"X-Auth-Email": config['authentication']['api_key']['account_email'],
|
||||||
|
"X-Auth-Key": config['authentication']['api_key']['api_key'],
|
||||||
|
}
|
||||||
|
|
||||||
if(data == False):
|
if(data == False):
|
||||||
response = requests.request(
|
response = requests.request(
|
||||||
@ -98,7 +104,6 @@ def cf_api(endpoint, method, config, headers={}, data=False):
|
|||||||
|
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
for ip in getIPs():
|
for ip in getIPs():
|
||||||
print("Checking " + ip["type"] + " records")
|
print("Checking " + ip["type"] + " records")
|
||||||
commitRecord(ip)
|
commitRecord(ip)
|
||||||
|
|||||||
19
config-example.json
Executable file
19
config-example.json
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"cloudflare": [
|
||||||
|
{
|
||||||
|
"authentication": {
|
||||||
|
"api_token": "api_token_here",
|
||||||
|
"api_key": {
|
||||||
|
"api_key": "api_key_here",
|
||||||
|
"account_email": "your_email_here"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zone_id": "your_zone_id_here",
|
||||||
|
"subdomains": [
|
||||||
|
"",
|
||||||
|
"subdomain"
|
||||||
|
],
|
||||||
|
"proxied": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
config.json
14
config.json
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"cloudflare": [
|
|
||||||
{
|
|
||||||
"api_key": "api_key_here",
|
|
||||||
"account_email": "your_email_here",
|
|
||||||
"zone_id": "your_zone_id_here",
|
|
||||||
"subdomains": [
|
|
||||||
"",
|
|
||||||
"subdomain"
|
|
||||||
],
|
|
||||||
"proxied": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user