Commit 523277fc authored by Ulf Steinberg's avatar Ulf Steinberg
Browse files

feat: initial commit

parents
node_modules
dist
build
{}
\ No newline at end of file
FROM node:10.13.0-alpine
# Env
ENV TIME_ZONE=Asia/Hong_Kong
ENV ENV_NAME dev
ENV EGG_SERVER_ENV dev
ENV NODE_ENV dev
ENV NODE_CONFIG_ENV dev
# Create Directory for the Container
WORKDIR /usr/src/app
# Only copy the package.json file to work directory
COPY package.json .
# Install all Packages
RUN npm install
# Copy all other source code to work directory
ADD . /usr/src/app
# TypeScript
RUN npm run build
# Start
CMD [ "npm", "start" ]
EXPOSE 7001
\ No newline at end of file
MIT License
Copyright (c) 2019 Ulf Steinberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
### DynDnsUpdate
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "@ulfalfa/dyndns-cloudflare",
"version": "0.0.1",
"description": "DynDns update for cloudflare base on current fritzbox ip",
"main": "dist/index",
"author": "ulfalfa",
"license": "MIT",
"private": false,
"scripts": {
"start": "node dist/index",
"build": "trash dist && npm run build:main",
"build:main": "tsc -p src/tsconfig.main.json",
"build:tests": "tsc -p src/tsconfig.spec.json",
"lint": "tslint --project tsconfig.json --fix",
"unit": "nyc ava",
"watch": "ava -vw",
"check-coverage": "nyc check-coverage",
"html-coverage": "nyc report --reporter=html",
"test": "yarn lint && yarn unit && yarn check-coverage",
"cov": "yarn unit && yarn html-coverage && opn build/coverage/index.html",
"docs": "yarn docs:html && opn build/docs/index.html",
"docs:html": "typedoc src/index.ts --excludePrivate --excludeNotExported --excludeProtected --mode file --theme minimal --out build/docs",
"docs:publish": "yarn docs:html && gh-pages -d build/docs",
"changelog": "standard-version",
"release": "yarn reset && yarn test && yarn build && yarn docs:publish && yarn changelog",
"reset": "git clean -dfx && git reset --hard && yarn"
},
"ava": {
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"sources": [
"src/**/*.ts"
],
"files": [
"src/**/*.spec.ts"
]
},
"nyc": {
"exclude": [
"**/*.js",
"**/*.d.ts",
"**/*.spec.ts"
],
"extension": [
".ts"
],
"reporter": [
"html",
"text"
],
"cache": true,
"sourceMap": true,
"instrument": true,
"all": false,
"report-dir": "./build/coverage",
"temp-directory": "./build/nyc_output"
},
"devDependencies": {
"@types/node": "^10.17.11",
"@types/yargs": "^13.0.4",
"ava": "^1.4.1",
"cz-conventional-changelog": "^2.1.0",
"gh-pages": "^2.1.1",
"nyc": "^14.1.1",
"opn-cli": "^3.1.0",
"standard-version": "^7.0.1",
"trash-cli": "^1.4.0",
"ts-node": "^6.0.5",
"tslint": "^5.16.0",
"typedoc": "^0.15.3",
"typescript": "^3.7.4"
},
"dependencies": {
"@ulfalfa/fritzbox": "0.0.9",
"cloudflare": "^2.7.0",
"debug": "^4.1.1",
"rxjs": "^6.5.3",
"yargs": "^15.0.2"
},
"peerDependencies": {},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
import test from 'ava'
test.todo('Test not implemented')
import { Fritzbox } from '@ulfalfa/fritzbox'
import * as Cloudflare from 'cloudflare'
import Debug from 'debug'
import { interval } from 'rxjs'
import { mergeMap, distinctUntilChanged } from 'rxjs/operators'
const debug = Debug('ulfalfa:dyndns-cloudflare')
import yargs = require('yargs')
async function getIp(): Promise<string> {
// for ip 6
// .exec(
// 'urn:schemas-upnp-org:service:WANIPConnection:1',
// 'X_AVM_DE_GetExternalIPv6Address'
// )
return fb
.exec(
'urn:schemas-upnp-org:service:WANIPConnection:1',
'GetExternalIPAddress'
)
.then((result: any) => {
debug(`IP read ${result.NewExternalIPAddress}`)
return result.NewExternalIPAddress
})
}
async function updateCloudFlare(host: string, domain: string, ip: string) {
const name = `${host}.${domain}`
debug(`updating A record of ${name} with ${ip}`)
// first getting info
const zone = await cf.zones
.browse()
.then(result => result.result.find(zone => zone.name === domain))
if (!zone) {
throw new Error(`Zone for ${domain} not found `)
}
const dnsrecord = await cf.dnsRecords
.browse(zone.id)
.then(result =>
result.result.find(record => record.name === name && record.type === 'A')
)
if (!dnsrecord) {
throw new Error(`DnsRecord of type A for ${name} not found `)
}
if (dnsrecord.content !== ip) {
debug(`Updating zone ${zone.id} and record ${dnsrecord.id} with ${ip}`)
return await cf.dnsRecords
.edit(zone.id, dnsrecord.id, {
type: 'A',
name,
ttl: 1,
content: ip,
})
.then(result => result.result)
} else {
debug('IP already there')
return dnsrecord
}
}
const argv = yargs.options({
cfApiKey: { type: 'string', demandOption: true, alias: 'k' },
cfEmail: { type: 'string', demandOption: true, alias: 'e' },
cfDomain: { type: 'string', demandOption: true, alias: 'd' },
cfHost: { type: 'string', demandOption: true, alias: 'h' },
fritz: {
type: 'string',
default: 'http://fritz.box:49000',
alias: 'f',
demandOption: false,
},
intervall: { type: 'number', demandOption: false, alias: 'i', default: 60 },
}).argv
const fb = new Fritzbox({ url: argv.fritz })
const cf = new Cloudflare({
email: argv.cfEmail,
key: argv.cfApiKey,
})
const observable = interval(argv.intervall * 1000)
.pipe(
mergeMap(() => getIp()),
distinctUntilChanged(),
mergeMap(ip => updateCloudFlare('krusty', 'steinberg-online.de', ip))
)
.subscribe(debug, console.error)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist"
},
"include": [
"**/*.ts",
"**/*.d.ts"
],
"sourceMap":false,
"exclude" : [
"**/*.spec.ts"
]
}
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "es6",
"outDir": "../build/spec",
"module": "commonjs",
"types": [
"ava",
"node"
],
"sourceMap": true
},
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"declaration": true,
"allowJs":false,
"sourceMap":true,
"typeRoots": [ "node_modules/@types" ],
"lib":["es2015"],
"strict":false
},
"include": [
"src/**/*.ts"
]
}
{
"extends": "tslint:recommended",
"rules": {
"array-type": false,
"arrow-parens": false,
"deprecation": {
"severity": "warn"
},
"import-blacklist": [
true,
"rxjs/Rx"
],
"interface-name": false,
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-consecutive-blank-lines": false,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [
true,
"single"
],
"trailing-comma": false,
"semicolon": [true, "never"],
"variable-name": [true, "check-format", "allow-leading-underscore"],
"no-namespace": false
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment