20 Commits

Author SHA1 Message Date
e0af9cd82e use alpine image 2024-02-27 18:05:18 +01:00
3ca15c532f use bun and remove some deps 2024-02-27 17:59:00 +01:00
500d7b2423 typo 2024-02-27 17:55:58 +01:00
144d5abeb6 update pnpm version 2024-02-27 13:14:34 +01:00
0b6e6e07dd update packages 2024-02-27 13:13:47 +01:00
dependabot[bot]
43bc492c49 Bump follow-redirects from 1.15.2 to 1.15.4 (#9)
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.2 to 1.15.4.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.2...v1.15.4)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-27 13:11:33 +01:00
dependabot[bot]
b9f77f24ca Bump axios from 1.4.0 to 1.6.0 (#8)
Bumps [axios](https://github.com/axios/axios) from 1.4.0 to 1.6.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.4.0...v1.6.0)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-16 20:53:49 +01:00
18a5a40b43 update deps and use corepack for pnpm 2023-08-20 22:37:36 +02:00
37cdc12439 update deps 2023-06-24 16:19:36 +02:00
02c27afd29 1.3.1 (#7)
* update deps

* changelog

* allow 'y' as yes values
2022-11-28 02:12:08 +01:00
04b3acc509 update sample env 2022-10-20 15:25:21 +02:00
a1af82501c 1.3.0 (#6) 2022-10-20 15:18:57 +02:00
fb7416dbec Merge pull request #5 from cupcakearmy/1.2.1
1.2.1
2022-05-14 15:59:53 +02:00
54eb94135b changelog, update deps & adapt pr 2022-05-14 15:58:38 +02:00
47c0adbfb6 Merge pull request #4 from borisbm/master
Added proxied option
2022-05-14 15:52:54 +02:00
borisbm
d25c33d015 Update README.md 2022-05-13 19:42:05 +10:00
borisbm
c007fbb848 Update .sample.env 2022-05-13 19:37:57 +10:00
borisbm
f6d825b843 Update index.ts 2022-05-13 19:37:27 +10:00
10b4d5473b badges 2022-04-07 12:05:47 +02:00
157ce6b7b6 1.2.0 2022-02-07 13:14:23 +01:00
19 changed files with 427 additions and 1002 deletions

View File

@@ -1,5 +1,4 @@
*
!src
!tsconfig.json
!package.json
!pnpm-lock.yaml
!bun.lockb

26
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Build Docker image
on:
pull_request:
push:
concurrency:
group: build
cancel-in-progress: true
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Build and push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
push: false

View File

@@ -1,39 +1,47 @@
name: ci
name: Publish Docker image
on:
workflow_dispatch:
push:
tags:
- "v*.*.*"
release:
types: [published]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Docker Labels
id: meta
uses: crazy-max/ghaction-docker-meta@v2
uses: docker/metadata-action@v4
with:
images: cupcakearmy/ddns-cloudflare
images: |
cupcakearmy/ddns-cloudflare
ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Login to DockerHub
uses: docker/login-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
.env
ip.log
dist
node_modules
.vscode

View File

@@ -1,8 +1,10 @@
# Required
TOKEn=myapitoken
TOKEN=myapitoken
ZONE=example.org
DNS_RECORD=some.example.org
# Optional
#PROXIED=false
#CRON=* * * * *
#RESOLVER=http://ipv4.icanhazip.com/
#LOG_LEVEL=debug

View File

@@ -5,6 +5,82 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.1] - 2024-02-27
### Changed
- Use the alpine `bun` image to half the image size.
## [1.4.0] - 2024-02-27
### Changed
- Moved to bun.
- Removed some dependencies.
## [1.3.4] - 2024-02-27
### Security
- Updated dependencies.
## [1.3.3] - 2023-08-20
### Security
- Updated dependencies.
## [1.3.2] - 2023-06-24
### Security
- Updated dependencies.
## [1.3.1] - 2022-11-28
### Added
- `y` is now a valid truthy value.
### Security
- Updated dependencies.
## [1.3.0] - 2022-10-20
### Removed
- Login with username and password as it's considered deprecated.
### Added
- `LOG_LEVEL` env variable.
- Config parsing and validation.
### Changed
- Removed Cloudflare SDK due to outdated and bloated package.
## [1.2.1] - 2022-05-14
### Added
- Support for `proxied` parameter thanks to @borisbm.
### Security
- Updated dependencies.
## [1.2.0] - 2022-02-07
### Added
- Sigterm and Sigkill hooks for graceful shutdown
### Changed
- Multistage steps to reduce image size
## [1.1.1] - 2022-02-07
### Security

View File

@@ -1,10 +1,10 @@
FROM node:16-alpine
FROM oven/bun:1-alpine as base
WORKDIR /app
COPY package.json bun.lockb /app/
RUN bun install --production --frozen-lockfile
ADD . .
RUN npm install -g pnpm
RUN pnpm install --frozen-lockfile
RUN pnpm run build
COPY . .
CMD ["node", "."]
STOPSIGNAL SIGTERM
CMD ["bun", "."]

View File

@@ -1,7 +1,8 @@
# Docker DDNS Cloudflare
![Docker Size](https://img.shields.io/docker/image-size/cupcakearmy/ddns-cloudflare)
![Docker Downloads](https://img.shields.io/docker/pulls/cupcakearmy/ddns-cloudflare)
![Docker Pulls](https://img.shields.io/docker/pulls/cupcakearmy/ddns-cloudflare?style=flat-square)
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/cupcakearmy/ddns-cloudflare/latest?style=flat-square)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/cupcakearmy/ddns-cloudflare/latest?style=flat-square)
## Features 🌈
@@ -19,12 +20,10 @@ Click create token. You can then use the Edit DNS Zone template. Give it a name.
```bash
TOKEN=mytoken
# Or (Legacy mode)
EMAIL=my@mail.com
KEY=Global_API_Key
ZONE=example.org
DNS_RECORD=some.example.org
PROXIED=false
```
3. Run the container
@@ -46,15 +45,15 @@ docker-compose up -d
## ENV Reference
| Env | Description | Default |
| ------------ | ------------------------------------------------------ | ---------------------- |
| `EMAIL` | [Legacy] E-Mail of the Cloudflare account. | |
| `KEY` | [Legacy] Key for authentication. | |
| `TOKEN` | API Token that can be used instead of `EMAIL` & `KEY`. | |
| `ZONE` | Cloudflare zone where your domain is. | |
| `DNS_RECORD` | The actual DNS record that should be updated. | |
| `CRON` | Frequency of updates. | \*/5 \* \* \* \* |
| `RESOLVER` | The endpoint used to determine your public ip. | https://api.ipify.org/ |
| Env | Default | Description |
| ------------ | ------------------------ | ----------------------------------------------------------------------------------------------------------- |
| `TOKEN` | | API Token. |
| `ZONE` | | Cloudflare zone where your domain is. |
| `DNS_RECORD` | | The actual DNS record that should be updated. |
| `PROXIED` | `true` | Whether the record is proxied by CloudFlare or not. |
| `CRON` | `*/5 * * * *` | Frequency of updates. The [following syntax](https://croner.56k.guru/usage/pattern/) is supported |
| `RESOLVER` | `https://api.ipify.org/` | The endpoint used to determine your public ip. |
| `LOG_LEVEL` | `info` | Log level to run at. See [winston](https://github.com/winstonjs/winston#logging-levels) for possible values |
## Customize

BIN
bun.lockb Executable file

Binary file not shown.

View File

@@ -1,21 +1,20 @@
{
"version": "1.4.1",
"license": "MIT",
"main": "dist",
"type": "module",
"main": "./src/index.ts",
"scripts": {
"dev": "tsnd src/index.ts",
"build": "tsc"
"check": "tsc --noEmit",
"dev": "bun --watch ./src/index.ts",
"start": "bun ./src/index.ts"
},
"dependencies": {
"axios": "^0.25.0",
"cloudflare": "^2.9.1",
"cron": "^1.8.2",
"dotenv": "^16.0.0",
"winston": "^3.5.1"
"axios": "^1.6.7",
"croner": "^8.0.1",
"winston": "^3.11.0"
},
"devDependencies": {
"@types/cloudflare": "^2.7.7",
"@types/cron": "^1.7.3",
"ts-node-dev": "^1.1.8",
"typescript": "^4.5.5"
"@types/bun": "^1.0.7",
"typescript": "^5.3.3"
}
}

748
pnpm-lock.yaml generated
View File

@@ -1,748 +0,0 @@
lockfileVersion: 5.3
specifiers:
'@types/cloudflare': ^2.7.7
'@types/cron': ^1.7.3
axios: ^0.25.0
cloudflare: ^2.9.1
cron: ^1.8.2
dotenv: ^16.0.0
ts-node-dev: ^1.1.8
typescript: ^4.5.5
winston: ^3.5.1
dependencies:
axios: 0.25.0
cloudflare: 2.9.1
cron: 1.8.2
dotenv: 16.0.0
winston: 3.5.1
devDependencies:
'@types/cloudflare': 2.7.7
'@types/cron': 1.7.3
ts-node-dev: 1.1.8_typescript@4.5.5
typescript: 4.5.5
packages:
/@dabh/diagnostics/2.0.2:
resolution: {integrity: sha512-+A1YivoVDNNVCdfozHSR8v/jyuuLTMXwjWuxPFlFlUapXoGc+Gj9mDlTDDfrwl7rXCl2tNZ0kE8sIBO6YOn96Q==}
dependencies:
colorspace: 1.1.4
enabled: 2.0.0
kuler: 2.0.0
dev: false
/@types/cloudflare/2.7.7:
resolution: {integrity: sha512-BPihnRqzm+NtFPG9gNd+Asf/KGcFfBY3zc53j9P7dW9qh3V+3wrYTBc1SOQs/DLDJxdpc+HI0N26NImAfZxg5g==}
dev: true
/@types/cron/1.7.3:
resolution: {integrity: sha512-iPmUXyIJG1Js+ldPYhOQcYU3kCAQ2FWrSkm1FJPoii2eYSn6wEW6onPukNTT0bfiflexNSRPl6KWmAIqS+36YA==}
dependencies:
'@types/node': 17.0.15
moment: 2.29.1
dev: true
/@types/node/17.0.15:
resolution: {integrity: sha512-zWt4SDDv1S9WRBNxLFxFRHxdD9tvH8f5/kg5/IaLFdnSNXsDY4eL3Q3XXN+VxUnWIhyVFDwcsmAprvwXoM/ClA==}
dev: true
/@types/strip-bom/3.0.0:
resolution: {integrity: sha1-FKjsOVbC6B7bdSB5CuzyHCkK69I=}
dev: true
/@types/strip-json-comments/0.0.30:
resolution: {integrity: sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==}
dev: true
/agent-base/6.0.2:
resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==}
engines: {node: '>= 6.0.0'}
dependencies:
debug: 4.3.3
transitivePeerDependencies:
- supports-color
dev: false
/anymatch/3.1.2:
resolution: {integrity: sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==}
engines: {node: '>= 8'}
dependencies:
normalize-path: 3.0.0
picomatch: 2.3.1
dev: true
/arg/4.1.3:
resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==}
dev: true
/async/3.2.3:
resolution: {integrity: sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==}
dev: false
/autocreate/1.2.0:
resolution: {integrity: sha1-UiFnmSxBcsFUeeX4jzSGpFKkDLo=}
dev: false
/axios/0.25.0:
resolution: {integrity: sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==}
dependencies:
follow-redirects: 1.14.7
transitivePeerDependencies:
- debug
dev: false
/balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true
/binary-extensions/2.2.0:
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
engines: {node: '>=8'}
dev: true
/brace-expansion/1.1.11:
resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==}
dependencies:
balanced-match: 1.0.2
concat-map: 0.0.1
dev: true
/braces/3.0.2:
resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==}
engines: {node: '>=8'}
dependencies:
fill-range: 7.0.1
dev: true
/buffer-from/1.1.2:
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
dev: true
/capture-stack-trace/1.0.1:
resolution: {integrity: sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==}
engines: {node: '>=0.10.0'}
dev: false
/chokidar/3.5.3:
resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==}
engines: {node: '>= 8.10.0'}
dependencies:
anymatch: 3.1.2
braces: 3.0.2
glob-parent: 5.1.2
is-binary-path: 2.1.0
is-glob: 4.0.3
normalize-path: 3.0.0
readdirp: 3.6.0
optionalDependencies:
fsevents: 2.3.2
dev: true
/cloudflare/2.9.1:
resolution: {integrity: sha512-x8yXPPoloy7xQ9GCKnsvQ3U1nwvcLndA2B3nxwSjIWxgLTUJOyakeEDsrqxZO8Dr6FkGdaXwy554fQVMpOabiw==}
dependencies:
autocreate: 1.2.0
es-class: 2.1.1
got: 6.7.1
https-proxy-agent: 5.0.0
object-assign: 4.1.1
should-proxy: 1.0.4
url-pattern: 1.0.3
transitivePeerDependencies:
- supports-color
dev: false
/color-convert/1.9.3:
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
dependencies:
color-name: 1.1.3
dev: false
/color-name/1.1.3:
resolution: {integrity: sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=}
dev: false
/color-name/1.1.4:
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
dev: false
/color-string/1.9.0:
resolution: {integrity: sha512-9Mrz2AQLefkH1UvASKj6v6hj/7eWgjnT/cVsR8CumieLoT+g900exWeNogqtweI8dxloXN9BDQTYro1oWu/5CQ==}
dependencies:
color-name: 1.1.4
simple-swizzle: 0.2.2
dev: false
/color/3.2.1:
resolution: {integrity: sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==}
dependencies:
color-convert: 1.9.3
color-string: 1.9.0
dev: false
/colors/1.4.0:
resolution: {integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==}
engines: {node: '>=0.1.90'}
dev: false
/colorspace/1.1.4:
resolution: {integrity: sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==}
dependencies:
color: 3.2.1
text-hex: 1.0.0
dev: false
/concat-map/0.0.1:
resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=}
dev: true
/create-error-class/3.0.2:
resolution: {integrity: sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y=}
engines: {node: '>=0.10.0'}
dependencies:
capture-stack-trace: 1.0.1
dev: false
/create-require/1.1.1:
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
dev: true
/cron/1.8.2:
resolution: {integrity: sha512-Gk2c4y6xKEO8FSAUTklqtfSr7oTq0CiPQeLBG5Fl0qoXpZyMcj1SG59YL+hqq04bu6/IuEA7lMkYDAplQNKkyg==}
dependencies:
moment-timezone: 0.5.34
dev: false
/debug/4.3.3:
resolution: {integrity: sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.2
dev: false
/diff/4.0.2:
resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
engines: {node: '>=0.3.1'}
dev: true
/dotenv/16.0.0:
resolution: {integrity: sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==}
engines: {node: '>=12'}
dev: false
/duplexer3/0.1.4:
resolution: {integrity: sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=}
dev: false
/dynamic-dedupe/0.3.0:
resolution: {integrity: sha1-BuRMIj9eTpTXjvnbI6ZRXOL5YqE=}
dependencies:
xtend: 4.0.2
dev: true
/enabled/2.0.0:
resolution: {integrity: sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==}
dev: false
/es-class/2.1.1:
resolution: {integrity: sha1-bsIkO1oeNYHAt+7O4BMMnA1vsrc=}
dev: false
/fecha/4.2.1:
resolution: {integrity: sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q==}
dev: false
/fill-range/7.0.1:
resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}
engines: {node: '>=8'}
dependencies:
to-regex-range: 5.0.1
dev: true
/fn.name/1.1.0:
resolution: {integrity: sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==}
dev: false
/follow-redirects/1.14.7:
resolution: {integrity: sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==}
engines: {node: '>=4.0'}
peerDependencies:
debug: '*'
peerDependenciesMeta:
debug:
optional: true
dev: false
/fs.realpath/1.0.0:
resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=}
dev: true
/fsevents/2.3.2:
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
requiresBuild: true
dev: true
optional: true
/function-bind/1.1.1:
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
dev: true
/get-stream/3.0.0:
resolution: {integrity: sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=}
engines: {node: '>=4'}
dev: false
/glob-parent/5.1.2:
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
engines: {node: '>= 6'}
dependencies:
is-glob: 4.0.3
dev: true
/glob/7.2.0:
resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==}
dependencies:
fs.realpath: 1.0.0
inflight: 1.0.6
inherits: 2.0.4
minimatch: 3.0.5
once: 1.4.0
path-is-absolute: 1.0.1
dev: true
/got/6.7.1:
resolution: {integrity: sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=}
engines: {node: '>=4'}
dependencies:
create-error-class: 3.0.2
duplexer3: 0.1.4
get-stream: 3.0.0
is-redirect: 1.0.0
is-retry-allowed: 1.2.0
is-stream: 1.1.0
lowercase-keys: 1.0.1
safe-buffer: 5.2.1
timed-out: 4.0.1
unzip-response: 2.0.1
url-parse-lax: 1.0.0
dev: false
/has/1.0.3:
resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==}
engines: {node: '>= 0.4.0'}
dependencies:
function-bind: 1.1.1
dev: true
/https-proxy-agent/5.0.0:
resolution: {integrity: sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==}
engines: {node: '>= 6'}
dependencies:
agent-base: 6.0.2
debug: 4.3.3
transitivePeerDependencies:
- supports-color
dev: false
/inflight/1.0.6:
resolution: {integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=}
dependencies:
once: 1.4.0
wrappy: 1.0.2
dev: true
/inherits/2.0.4:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
/is-arrayish/0.3.2:
resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==}
dev: false
/is-binary-path/2.1.0:
resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==}
engines: {node: '>=8'}
dependencies:
binary-extensions: 2.2.0
dev: true
/is-core-module/2.8.1:
resolution: {integrity: sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==}
dependencies:
has: 1.0.3
dev: true
/is-extglob/2.1.1:
resolution: {integrity: sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=}
engines: {node: '>=0.10.0'}
dev: true
/is-glob/4.0.3:
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
engines: {node: '>=0.10.0'}
dependencies:
is-extglob: 2.1.1
dev: true
/is-number/7.0.0:
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
engines: {node: '>=0.12.0'}
dev: true
/is-redirect/1.0.0:
resolution: {integrity: sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ=}
engines: {node: '>=0.10.0'}
dev: false
/is-retry-allowed/1.2.0:
resolution: {integrity: sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==}
engines: {node: '>=0.10.0'}
dev: false
/is-stream/1.1.0:
resolution: {integrity: sha1-EtSj3U5o4Lec6428hBc66A2RykQ=}
engines: {node: '>=0.10.0'}
dev: false
/is-stream/2.0.1:
resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==}
engines: {node: '>=8'}
dev: false
/kuler/2.0.0:
resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==}
dev: false
/logform/2.3.2:
resolution: {integrity: sha512-V6JiPThZzTsbVRspNO6TmHkR99oqYTs8fivMBYQkjZj6rxW92KxtDCPE6IkAk1DNBnYKNkjm4jYBm6JDUcyhOA==}
dependencies:
colors: 1.4.0
fecha: 4.2.1
ms: 2.1.3
safe-stable-stringify: 1.1.1
triple-beam: 1.3.0
dev: false
/lowercase-keys/1.0.1:
resolution: {integrity: sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==}
engines: {node: '>=0.10.0'}
dev: false
/make-error/1.3.6:
resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
dev: true
/minimatch/3.0.5:
resolution: {integrity: sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==}
dependencies:
brace-expansion: 1.1.11
dev: true
/minimist/1.2.5:
resolution: {integrity: sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==}
dev: true
/mkdirp/1.0.4:
resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==}
engines: {node: '>=10'}
hasBin: true
dev: true
/moment-timezone/0.5.34:
resolution: {integrity: sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==}
dependencies:
moment: 2.29.1
dev: false
/moment/2.29.1:
resolution: {integrity: sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==}
/ms/2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
dev: false
/ms/2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
dev: false
/normalize-path/3.0.0:
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
engines: {node: '>=0.10.0'}
dev: true
/object-assign/4.1.1:
resolution: {integrity: sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=}
engines: {node: '>=0.10.0'}
dev: false
/once/1.4.0:
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=}
dependencies:
wrappy: 1.0.2
dev: true
/one-time/1.0.0:
resolution: {integrity: sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==}
dependencies:
fn.name: 1.1.0
dev: false
/path-is-absolute/1.0.1:
resolution: {integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18=}
engines: {node: '>=0.10.0'}
dev: true
/path-parse/1.0.7:
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
dev: true
/picomatch/2.3.1:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
dev: true
/prepend-http/1.0.4:
resolution: {integrity: sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=}
engines: {node: '>=0.10.0'}
dev: false
/readable-stream/3.6.0:
resolution: {integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==}
engines: {node: '>= 6'}
dependencies:
inherits: 2.0.4
string_decoder: 1.3.0
util-deprecate: 1.0.2
dev: false
/readdirp/3.6.0:
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
engines: {node: '>=8.10.0'}
dependencies:
picomatch: 2.3.1
dev: true
/resolve/1.22.0:
resolution: {integrity: sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==}
hasBin: true
dependencies:
is-core-module: 2.8.1
path-parse: 1.0.7
supports-preserve-symlinks-flag: 1.0.0
dev: true
/rimraf/2.7.1:
resolution: {integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==}
hasBin: true
dependencies:
glob: 7.2.0
dev: true
/safe-buffer/5.2.1:
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
dev: false
/safe-stable-stringify/1.1.1:
resolution: {integrity: sha512-ERq4hUjKDbJfE4+XtZLFPCDi8Vb1JqaxAPTxWFLBx8XcAlf9Bda/ZJdVezs/NAfsMQScyIlUMx+Yeu7P7rx5jw==}
dev: false
/safe-stable-stringify/2.3.1:
resolution: {integrity: sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==}
engines: {node: '>=10'}
dev: false
/should-proxy/1.0.4:
resolution: {integrity: sha1-yAWlAav2lTlgBjSAnmL78ji6NeQ=}
dev: false
/simple-swizzle/0.2.2:
resolution: {integrity: sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=}
dependencies:
is-arrayish: 0.3.2
dev: false
/source-map-support/0.5.21:
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
dependencies:
buffer-from: 1.1.2
source-map: 0.6.1
dev: true
/source-map/0.6.1:
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
engines: {node: '>=0.10.0'}
dev: true
/stack-trace/0.0.10:
resolution: {integrity: sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=}
dev: false
/string_decoder/1.3.0:
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
dependencies:
safe-buffer: 5.2.1
dev: false
/strip-bom/3.0.0:
resolution: {integrity: sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=}
engines: {node: '>=4'}
dev: true
/strip-json-comments/2.0.1:
resolution: {integrity: sha1-PFMZQukIwml8DsNEhYwobHygpgo=}
engines: {node: '>=0.10.0'}
dev: true
/supports-preserve-symlinks-flag/1.0.0:
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
engines: {node: '>= 0.4'}
dev: true
/text-hex/1.0.0:
resolution: {integrity: sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==}
dev: false
/timed-out/4.0.1:
resolution: {integrity: sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=}
engines: {node: '>=0.10.0'}
dev: false
/to-regex-range/5.0.1:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'}
dependencies:
is-number: 7.0.0
dev: true
/tree-kill/1.2.2:
resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==}
hasBin: true
dev: true
/triple-beam/1.3.0:
resolution: {integrity: sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==}
dev: false
/ts-node-dev/1.1.8_typescript@4.5.5:
resolution: {integrity: sha512-Q/m3vEwzYwLZKmV6/0VlFxcZzVV/xcgOt+Tx/VjaaRHyiBcFlV0541yrT09QjzzCxlDZ34OzKjrFAynlmtflEg==}
engines: {node: '>=0.8.0'}
hasBin: true
peerDependencies:
node-notifier: '*'
typescript: '*'
peerDependenciesMeta:
node-notifier:
optional: true
dependencies:
chokidar: 3.5.3
dynamic-dedupe: 0.3.0
minimist: 1.2.5
mkdirp: 1.0.4
resolve: 1.22.0
rimraf: 2.7.1
source-map-support: 0.5.21
tree-kill: 1.2.2
ts-node: 9.1.1_typescript@4.5.5
tsconfig: 7.0.0
typescript: 4.5.5
dev: true
/ts-node/9.1.1_typescript@4.5.5:
resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==}
engines: {node: '>=10.0.0'}
hasBin: true
peerDependencies:
typescript: '>=2.7'
dependencies:
arg: 4.1.3
create-require: 1.1.1
diff: 4.0.2
make-error: 1.3.6
source-map-support: 0.5.21
typescript: 4.5.5
yn: 3.1.1
dev: true
/tsconfig/7.0.0:
resolution: {integrity: sha512-vZXmzPrL+EmC4T/4rVlT2jNVMWCi/O4DIiSj3UHg1OE5kCKbk4mfrXc6dZksLgRM/TZlKnousKH9bbTazUWRRw==}
dependencies:
'@types/strip-bom': 3.0.0
'@types/strip-json-comments': 0.0.30
strip-bom: 3.0.0
strip-json-comments: 2.0.1
dev: true
/typescript/4.5.5:
resolution: {integrity: sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==}
engines: {node: '>=4.2.0'}
hasBin: true
dev: true
/unzip-response/2.0.1:
resolution: {integrity: sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c=}
engines: {node: '>=4'}
dev: false
/url-parse-lax/1.0.0:
resolution: {integrity: sha1-evjzA2Rem9eaJy56FKxovAYJ2nM=}
engines: {node: '>=0.10.0'}
dependencies:
prepend-http: 1.0.4
dev: false
/url-pattern/1.0.3:
resolution: {integrity: sha1-BAkpJHGyTyPFDWWkeTF5PStaz8E=}
engines: {node: '>=0.12.0'}
dev: false
/util-deprecate/1.0.2:
resolution: {integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=}
dev: false
/winston-transport/4.5.0:
resolution: {integrity: sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==}
engines: {node: '>= 6.4.0'}
dependencies:
logform: 2.3.2
readable-stream: 3.6.0
triple-beam: 1.3.0
dev: false
/winston/3.5.1:
resolution: {integrity: sha512-tbRtVy+vsSSCLcZq/8nXZaOie/S2tPXPFt4be/Q3vI/WtYwm7rrwidxVw2GRa38FIXcJ1kUM6MOZ9Jmnk3F3UA==}
engines: {node: '>= 6.4.0'}
dependencies:
'@dabh/diagnostics': 2.0.2
async: 3.2.3
is-stream: 2.0.1
logform: 2.3.2
one-time: 1.0.0
readable-stream: 3.6.0
safe-stable-stringify: 2.3.1
stack-trace: 0.0.10
triple-beam: 1.3.0
winston-transport: 4.5.0
dev: false
/wrappy/1.0.2:
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=}
dev: true
/xtend/4.0.2:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'}
dev: true
/yn/3.1.1:
resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
engines: {node: '>=6'}
dev: true

1
src/cache.ts Normal file
View File

@@ -0,0 +1 @@
export const Cache = new Map<'ip' | 'zone', string>()

128
src/cloudflare.ts Normal file
View File

@@ -0,0 +1,128 @@
import axios from 'axios'
import { Cache } from './cache.js'
import { Config } from './config.js'
import { logger } from './logger.js'
type DNSRecord = {
id: string
zone_id: string
zone_name: string
name: string
type: string
content: string
proxiable: boolean
proxied: boolean
ttl: number // 1 means automatic
locked: boolean
}
type DNSRecordCreate = Pick<DNSRecord, 'name' | 'type' | 'ttl' | 'proxied' | 'content'>
type DNSRecordPatch = Partial<DNSRecordCreate>
const l = logger.child({ context: 'cloudflare' })
const Base = axios.create({
baseURL: 'https://api.cloudflare.com/client/v4',
headers: {
Authorization: `Bearer ${Config.auth.token}`,
},
})
export const API = {
zones: {
async findByName(name: string): Promise<string | null> {
try {
const { data } = await Base({
url: '/zones',
params: {
name,
},
})
return data.result[0].id
} catch {
return null
}
},
},
records: {
async create(zoneId: string, zone: DNSRecordCreate): Promise<void> {
await Base({
url: `/zones/${zoneId}/dns_records`,
method: 'POST',
data: zone,
})
},
async remove(zoneId: string, recordId: string): Promise<void> {
await Base({
url: `/zones/${zoneId}/dns_records/${recordId}`,
method: 'DELETE',
})
},
async patch(zoneId: string, recordId: string, data: DNSRecordPatch): Promise<void> {
await Base({
url: `/zones/${zoneId}/dns_records/${recordId}`,
method: 'PATCH',
data,
})
},
async find(zoneId: string): Promise<DNSRecord[]> {
const { data } = await Base({
url: `/zones/${zoneId}/dns_records`,
params: {
type: 'A',
name: Config.dns.record,
},
})
return data.result as DNSRecord[]
},
},
}
export async function update(ip: string) {
// Find zone
if (!Cache.has('zone')) {
l.debug('Fetching zone')
const zone = await API.zones.findByName(Config.dns.zone)
if (!zone) {
l.error(`Zone "${Config.dns.zone}" not found`)
process.exit(1)
}
Cache.set('zone', zone)
}
const zoneId = Cache.get('zone')!
l.debug(`Zone ID: ${zoneId}`)
// Set record
const records = await API.records.find(zoneId)
l.debug('Updating record', ip)
switch (records.length) {
case 0:
// Create DNS Record
l.debug('Creating DNS record')
await API.records.create(zoneId, {
content: ip,
name: Config.dns.record,
proxied: Config.dns.proxied,
ttl: 1,
type: 'A',
})
return
case 1:
// Only one record, thats fine
break
default:
// More than one record, delete all but the first
l.debug('Deleting other DNS records')
for (const record of records.slice(1)) {
await API.records.remove(zoneId, record.id)
}
break
}
// Update the remaining record
await API.records.patch(zoneId, records[0]!.id, { content: ip, proxied: Config.dns.proxied })
}

55
src/config.ts Normal file
View File

@@ -0,0 +1,55 @@
import { Cron } from 'croner'
import pkg from '../package.json'
function getEnv(key: string, fallback: string, parse?: undefined, validator?: (s: string) => boolean): string
function getEnv<T>(key: string, fallback: T, parse: (value: string) => T, validator?: (T: string) => boolean): T
function getEnv<T>(
key: string,
fallback: T,
parse?: (value: string) => T,
validator?: (s: string | T) => boolean
): T | string {
const value = process.env[key]
const parsed = value === undefined ? fallback : parse ? parse(value) : value
if (validator && !validator(parsed)) {
console.error(`Invalid or missing value for ${key}: ${value}`)
process.exit(1)
}
return parsed
}
function parseBoolean(value: string): boolean {
value = value.toLowerCase()
const truthy = ['true', 'yes', '1', 'y']
return truthy.includes(value)
}
function isPresent(s: string): boolean {
return s.length > 0
}
export const Config = {
version: pkg.version,
logging: {
level: getEnv('LOG_LEVEL', 'info'),
},
auth: {
token: getEnv('TOKEN', '', undefined, isPresent),
},
dns: {
zone: getEnv('ZONE', '', undefined, isPresent),
record: getEnv('DNS_RECORD', '', undefined, isPresent),
proxied: getEnv('PROXIED', false, parseBoolean),
},
runner: {
cron: getEnv('CRON', '*/5 * * * *', undefined, (s) => {
try {
new Cron(s)
return true
} catch {
return false
}
}),
resolver: getEnv('RESOLVER', 'https://api.ipify.org'),
},
}

View File

@@ -1,114 +1,28 @@
import Cloudflare from 'cloudflare'
import Axios from 'axios'
import { CronJob } from 'cron'
import { config } from 'dotenv'
import winston from 'winston'
import { Cron } from 'croner'
import process from 'node:process'
const logger = winston.createLogger({
level: 'info',
transports: [
new winston.transports.Console({
format: winston.format.combine(winston.format.timestamp(), winston.format.colorize(), winston.format.simple()),
}),
],
})
const Cache = new Map<string, string>()
async function getCurrentIp(resolver?: string): Promise<string> {
const { data } = await Axios({
url: resolver || 'https://api.ipify.org/',
method: 'GET',
})
return data as string
}
function checkIfUpdateIsRequired(newIP: string): boolean {
// Check if IP has changed.
const current = Cache.get('ip')
if (newIP !== current) {
Cache.set('ip', newIP)
return true
}
return false
}
type DNSRecord = {
zone: string
record: string
ip: string
}
async function update(cf: Cloudflare, options: DNSRecord) {
// Find zone
if (!Cache.has('zone')) {
logger.debug('Fetching zone')
const zones: { result: { id: string; name: string }[] } = (await cf.zones.browse()) as any
const zone = zones.result.find((z) => z.name === options.zone)
if (!zone) {
logger.error(`Zone "${options.zone}"" not found`)
process.exit(1)
}
Cache.set('zone', zone.id)
}
const zoneId = Cache.get('zone')!
logger.debug(`Zone ID: ${zoneId}`)
// Set record
const records: { result: { id: string; type: string; name: string; ttl: number }[] } = (await cf.dnsRecords.browse(
zoneId
)) as any
const relevant = records.result.filter((r) => r.name === options.record && r.type === 'A')
if (relevant.length === 0) {
// Create DNS Record
logger.debug('Creating DNS record')
await cf.dnsRecords.add(zoneId, {
type: 'A',
name: options.record,
content: options.ip,
ttl: 1,
})
} else {
if (relevant.length > 1) {
// Delete other records as they cannot all point to the same IP
logger.debug('Deleting other DNS records')
for (const record of relevant.slice(1)) {
await cf.dnsRecords.del(zoneId, record.id)
}
}
// Update DNS Record
logger.debug('Updating DNS record')
const record = relevant[0]!
await cf.dnsRecords.edit(zoneId, record.id, {
type: 'A',
name: options.record,
content: options.ip,
ttl: record.ttl,
})
logger.info(`Updated DNS record ${record.name}`)
}
}
import { Config } from './config.js'
import { logger } from './logger.js'
import { loop } from './runner.js'
async function main() {
config()
const { EMAIL, KEY, TOKEN, ZONE, DNS_RECORD, CRON, RESOLVER } = process.env
if (!ZONE || !DNS_RECORD) {
logger.error('Missing environment variables')
process.exit(1)
const cron = new Cron(Config.runner.cron, { protect: true }, loop)
logger.info('started service', { version: Config.version })
logger.debug('config', Config)
const nextRun = cron.nextRun()
if (nextRun) {
const pretty = new Intl.DateTimeFormat(undefined, { dateStyle: 'long', timeStyle: 'long' }).format(nextRun)
logger.info(`next run scheduled for ${pretty}`, { nextRunAt: nextRun })
}
// Initialize Cloudflare
const cf = new Cloudflare(TOKEN ? { token: TOKEN } : { email: EMAIL, key: KEY })
async function fn() {
const ip = await getCurrentIp(RESOLVER)
const changed = checkIfUpdateIsRequired(ip)
logger.info(`Running. Update required: ${!!changed}`)
if (changed) await update(cf, { ip, record: DNS_RECORD!, zone: ZONE! }).catch((e) => logger.error(e.message))
function terminate() {
logger.info('Stopping service.')
cron.stop()
process.exit(0)
}
new CronJob(CRON || '*/5 * * * *', fn, null, true, undefined, null, true)
logger.info('Started service.')
process.on('SIGINT', terminate)
process.on('SIGTERM', terminate)
}
main()

22
src/ip.ts Normal file
View File

@@ -0,0 +1,22 @@
import axios from 'axios'
import { Cache } from './cache.js'
import { Config } from './config.js'
export async function getCurrentIp(): Promise<string> {
const { data } = await axios({
url: Config.runner.resolver,
method: 'GET',
})
return data as string
}
export function checkIfUpdateIsRequired(newIP: string): boolean {
// Check if IP has changed.
const current = Cache.get('ip')
if (newIP !== current) {
Cache.set('ip', newIP)
return true
}
return false
}

12
src/logger.ts Normal file
View File

@@ -0,0 +1,12 @@
import winston from 'winston'
import { Config } from './config.js'
export const logger = winston.createLogger({
level: Config.logging.level,
transports: [
new winston.transports.Console({
format: winston.format.combine(winston.format.timestamp(), winston.format.colorize(), winston.format.simple()),
}),
],
})

20
src/runner.ts Normal file
View File

@@ -0,0 +1,20 @@
import { update } from './cloudflare.js'
import { checkIfUpdateIsRequired, getCurrentIp } from './ip.js'
import { logger } from './logger.js'
const l = logger.child({ context: 'runner' })
export async function loop() {
const ip = await getCurrentIp()
const changed = checkIfUpdateIsRequired(ip)
l.info(`Running. Update required: ${!!changed}`)
if (changed) {
try {
await update(ip)
l.info('Successfully updated DNS record')
} catch (e) {
l.error(e)
l.error('Failed to update DNS record')
}
}
}

View File

@@ -1,100 +1,12 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Projects */
// "incremental": true, /* Enable incremental compilation */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
"rootDir": "./src" /* Specify the root folder within your source files. */,
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied `any` type.. */,
"strictNullChecks": true /* When type checking, take into account `null` and `undefined`. */,
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
"strictBindCallApply": true /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */,
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
"noImplicitThis": true /* Enable error reporting when `this` is given the type `any`. */,
"useUnknownInCatchVariables": true /* Type catch clause variables as 'unknown' instead of 'any'. */,
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
// "noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */,
// "noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
"exactOptionalPropertyTypes": true /* Interpret optional property types as written, rather than adding 'undefined'. */,
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
"noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
"noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type */,
"allowUnusedLabels": true /* Disable error reporting for unused labels. */,
"allowUnreachableCode": true /* Disable error reporting for unreachable code. */,
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"target": "ES2022",
"module": "ES2022",
"rootDir": "./src",
"moduleResolution": "Bundler",
"noEmit": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
}
}