diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5f5fcf6..830cfd6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,18 @@ +update-ip: + image: 3.10.8-slim-buster + when: manual + before_script: + - apt-get update + - apt-get install -y python3-pip + - python --version + - pip install -r requirements.txt + script: + - python cloudflare-updater.py $CF_API_TOKEN $NEW_IP + deploy-site: stage: deploy + rules: + - if: $CI_COMMIT_BRANCH == "main" before_script: - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - eval $(ssh-agent -s) diff --git a/package-lock.json b/package-lock.json index 0307404..dd9e883 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@firq/fgosite", - "version": "0.0.1", + "version": "0.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@firq/fgosite", - "version": "0.0.1", + "version": "0.1.1", "dependencies": { "astro": "^2.0.2", "iconoir": "^6.1.0" @@ -992,6 +992,13 @@ "@types/unist": "*" } }, + "node_modules/@types/node": { + "version": "18.14.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz", + "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==", + "optional": true, + "peer": true + }, "node_modules/@types/parse5": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/parse5/-/parse5-6.0.3.tgz", @@ -5604,6 +5611,13 @@ "@types/unist": "*" } }, + "@types/node": { + "version": "18.14.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz", + "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==", + "optional": true, + "peer": true + }, "@types/parse5": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/parse5/-/parse5-6.0.3.tgz", diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..ca5e3f2 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,2 @@ +venv/ +.idea/ \ No newline at end of file diff --git a/scripts/cloudflare-updater.py b/scripts/cloudflare-updater.py new file mode 100644 index 0000000..6047188 --- /dev/null +++ b/scripts/cloudflare-updater.py @@ -0,0 +1,52 @@ +import sys, logging, ipaddress, json +import CloudFlare + + +def main(TOKEN, NEW_IP): + logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) + cf = CloudFlare.CloudFlare(token=TOKEN) + zones = cf.zones.get() + zone_identifier = [] + for zone in zones: + if zone['name'] == "firq.dev": + zone_identifier = zone + + if not zone_identifier: + raise Exception("No Zone identifier extracted") + + logging.info(f" Zone Identifier is {zone_identifier['id']}") + + records = cf.zones.dns_records.get(zone_identifier['id']) + update_records = [] + + if not records: + raise Exception(f"Could not extract records from {zone_identifier['name']}") + + for record in records: + if record['type'] == 'AAAA': + update_records.append({"id": record['id'], "type": record['type'], "name": record['name'], "content": record['content']}) + + logging.info(f" Got the following DNS records registered to {zone_identifier['name']}") + logging.info(json.dumps(update_records, sort_keys=True, indent=2)) + records_done = 0 + + for record in update_records: + data = { + "name": record['name'], + "type": record['type'], + "content": NEW_IP + } + try: + cf.zones.dns_records.patch(zone_identifier['id'], record['id'], data=data) + records_done += 1 + except Exception as e: + logging.error(e) + + logging.info(f"Finished updating {records_done} records for {zone_identifier['name']}") + + +if __name__ == '__main__': + assert len(sys.argv) == 3 + assert isinstance(ipaddress.ip_address(sys.argv[2]), ipaddress.IPv6Address), \ + f'IP {sys.argv[2]} is not a valid IPv4 address' + main(sys.argv[1], sys.argv[2]) diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..c4afa28 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1 @@ +cloudflare>=2.11.1 diff --git a/src/layouts/customFooter.astro b/src/layouts/customFooter.astro index 7540cca..c514e19 100644 --- a/src/layouts/customFooter.astro +++ b/src/layouts/customFooter.astro @@ -8,7 +8,7 @@ use. | View the official website for more information.
I am in no way affiliated with Fate/Grand Order, Aniplex, Type Moon or Lasengle. I claim no ownership of any of the assets used that are - created by any of the mentioned companies. + created by any of the mentioned companies.
All of the opinions expressed are my own and may not reflect those of the asset providers.