ddns 3.1.5__py2.py3-none-any.whl → 4.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ddns might be problematic. Click here for more details.

@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ddns = ddns.__main__:main
@@ -0,0 +1 @@
1
+ ddns
@@ -1,281 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ddns
3
- Version: 3.1.5
4
- Summary: automatically update DNS records to dynamic local IP [自动更新DNS记录指向本地IP]
5
- Home-page: https://ddns.newfuture.cc
6
- Author: NewFuture
7
- Author-email: python@newfuture.cc
8
- License: MIT
9
- Project-URL: Bug Reports, https://github.com/NewFuture/DDNS/issues
10
- Project-URL: Source, https://github.com/NewFuture/DDNS
11
- Keywords: ddns ipv6 ipv4 dns dnspod alidns cloudflare
12
- Platform: any
13
- Classifier: Development Status :: 5 - Production/Stable
14
- Classifier: Intended Audience :: Developers
15
- Classifier: Topic :: Software Development :: Build Tools
16
- Classifier: License :: OSI Approved :: MIT License
17
- Classifier: Programming Language :: Python :: 3
18
- Requires-Python: >=2.5, <4
19
- Description-Content-Type: text/markdown
20
- License-File: LICENSE
21
- Dynamic: author
22
- Dynamic: author-email
23
- Dynamic: classifier
24
- Dynamic: description
25
- Dynamic: description-content-type
26
- Dynamic: home-page
27
- Dynamic: keywords
28
- Dynamic: license
29
- Dynamic: license-file
30
- Dynamic: platform
31
- Dynamic: project-url
32
- Dynamic: requires-python
33
- Dynamic: summary
34
-
35
- # [DDNS](https://github.com/NewFuture/DDNS)
36
-
37
- > 自动更新 DNS 解析 到本机 IP 地址,支持 ipv4 和 ipv6 以 本地(内网)IP 和 公网 IP。
38
- > 代理模式,支持自动创建域名记录。
39
-
40
- [![PyPI](https://img.shields.io/pypi/v/ddns.svg?label=DDNS&style=social)](https://pypi.org/project/ddns/)
41
- [![Build Status](https://github.com/NewFuture/DDNS/actions/workflows/build.yml/badge.svg?event=push)](https://github.com/NewFuture/DDNS/actions/workflows/build.yml)
42
- [![Publish Status](https://github.com/NewFuture/DDNS/actions/workflows/publish.yml/badge.svg)](https://github.com/NewFuture/DDNS/releases/latest)
43
-
44
- ---
45
-
46
- ## Features
47
-
48
- - 兼容和跨平台:
49
- - [x] 可执行文件(无需 python 环境)
50
- - [x] 多系统兼容 ![cross platform](https://img.shields.io/badge/platform-windows_%7C%20linux_%7C%20osx-success.svg?style=social)
51
- - [x] python3 支持 ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ddns.svg?style=social)(2.x支持python2和python3)
52
- - [x] PIP 安装 ![PyPI - Wheel](https://img.shields.io/pypi/wheel/ddns.svg?style=social)
53
- - [x] Docker 支持(@NN708)
54
- - 域名支持:
55
- - [x] 多个域名支持
56
- - [x] 多级域名解析
57
- - [x] 自动创建新记录
58
- - IP 类型:
59
- - [x] 内网 IPv4 / IPv6
60
- - [x] 公网 IPv4 / IPv6 (支持自定义 API)
61
- - [x] 自定义命令(shell)
62
- - [x] 正则选取支持(@rufengsuixing)
63
- - 网络代理:
64
- - [x] http 代理支持
65
- - [x] 多代理自动切换
66
- - 服务商支持:
67
- - [x] [DNSPOD](https://www.dnspod.cn/)
68
- - [x] [阿里 DNS](http://www.alidns.com/)
69
- - [x] [DNS.COM](https://www.dns.com/)(@loftor-git)
70
- - [x] [DNSPOD 国际版](https://www.dnspod.com/)
71
- - [x] [CloudFlare](https://www.cloudflare.com/)(@tongyifan)
72
- - [x] [HE.net](https://dns.he.net/)(@NN708) (不支持自动创建记录)
73
- - [x] [华为云](https://huaweicloud.com/)(@cybmp3)
74
- - 其他:
75
- - [x] 可设置定时任务
76
- - [x] TTL 配置支持
77
- - [x] 本地文件缓存(减少 API 请求)
78
- - [x] 地址变更时触发自定义回调API(与 DDNS 功能互斥)
79
-
80
- ## 使用
81
-
82
- ### ① 安装
83
-
84
- 根据需要选择一种方式: `二进制`版,`pip`版,`源码`运行,或者`Docker`
85
-
86
- - #### pip 安装(需要 pip 或 easy_install)
87
- 1. 安装 ddns: `pip install ddns` 或 `easy_install ddns`
88
- 2. 运行: `ddns`
89
- - #### 二进制版(单文件,无需 python)
90
- - Windows [ddns.exe](https://github.com/NewFuture/DDNS/releases/latest)
91
- - Linux (仅 Ubuntu 测试) [ddns](https://github.com/NewFuture/DDNS/releases/latest)
92
- - Mac OSX [ddns-osx](https://github.com/NewFuture/DDNS/releases/latest)
93
- - #### 源码运行(无任何依赖, 需 python 环境)
94
- 1. clone 或者[下载此仓库](https://github.com/NewFuture/DDNS/archive/master.zip)并解压
95
- 2. 运行./run.py (widnows 双击`run.bat`或者运行`python run.py`)
96
- - #### Docker(需要安装 Docker)
97
- - 使用环境变量:
98
- ```
99
- docker run -d \
100
- -e DDNS_DNS=dnspod \
101
- -e DDNS_ID=12345 \
102
- -e DDNS_TOKEN=mytokenkey \
103
- -e DDNS_IPV4=ddns.newfuture.cc \
104
- -e DDNS_IPV6=ddns.newfuture.cc \
105
- --network host \
106
- newfuture/ddns
107
- ```
108
- - 使用配置文件:
109
- ```
110
- docker run -d \
111
- -v /path/to/config.json:/config.json \
112
- --network host \
113
- newfuture/ddns
114
- ```
115
-
116
- ### ② 快速配置
117
-
118
- 1. 申请 api `token`,填写到对应的`id`和`token`字段:
119
-
120
- - [DNSPOD(国内版)创建 token](https://support.dnspod.cn/Kb/showarticle/tsid/227/)
121
- - [阿里云 accesskey](https://help.aliyun.com/document_detail/87745.htm)
122
- - [DNS.COM API Key/Secret](https://www.dns.com/member/apiSet)
123
- - [DNSPOD(国际版)](https://www.dnspod.com/docs/info.html#get-the-user-token)
124
- - [CloudFlare API Key](https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key-) (除了`email + API KEY`,也可使用`Token`需要列出 Zone 权限)
125
- - [HE.net DDNS 文档](https://dns.he.net/docs.html)(仅需将设置的密码填入`token`字段,`id`字段可留空)
126
- - [华为 APIKEY 申请](https://console.huaweicloud.com/iam/)(点左边访问密钥,然后点新增访问密钥)
127
- - 自定义回调的参数填写方式请查看下方的自定义回调配置说明
128
-
129
- 2. 修改配置文件,`ipv4`和`ipv6`字段,为待更新的域名,详细参照配置说明
130
-
131
- ## 详细配置
132
-
133
- 所有字段可通过三种方式进行配置
134
-
135
- 1. 命令行参数 `ddns --key=value` (`ddns -h` 查看详情),优先级最高
136
- 2. JSON配置文件(值为null认为是有效值,会覆盖环境变量的设置,如果没有对应的key则会尝试试用环境变量)
137
- 3. 环境变量DDNS_前缀加上key 全大写或者全小写 (`${ddns_key}` 或 `${DDNS_KEY}`)
138
-
139
- <details open>
140
-
141
- <summary markdown="span">config.json 配置文件
142
- </summary>
143
-
144
- - 首次运行会自动生成一个模板配置文件
145
- - 可以使用 `-c`使用指定的配置文件 (默认读取当前目录的 config.json)
146
- - 推荐使用 vscode 等支持 JsonSchema 的编辑器编辑配置文件
147
-
148
- ```bash
149
- ddns -c path/to/config.json
150
- # 或者源码运行
151
- python run.py -c /path/to/config.json
152
- ```
153
-
154
- #### 配置参数表
155
-
156
- | key | type | required | default | description | tips |
157
- | :----: | :----------------: | :------: | :---------: | :---------------: | ----------------------------------------------------------------------------------------------------------- |
158
- | id | string | √ | 无 | api 访问 ID | Cloudflare 为邮箱(使用 Token 时留空)<br>HE.net 可留空<br>华为云为 Access Key ID (AK) |
159
- | token | string | √ | 无 | api 授权 token | 部分平台叫 secret key , **反馈粘贴时删除** |
160
- | dns | string | No | `"dnspod"` | dns 服务商 | 阿里 DNS 为`alidns`,<br>Cloudflare 为 `cloudflare`,<br>dns.com 为 `dnscom`,<br>DNSPOD 国内为 `dnspod`,<br>DNSPOD 国际版为 `dnspod_com`,<br>HE.net 为`he`,<br>华为 DNS 为`huaweidns`,<br>自定义回调为`callback` |
161
- | ipv4 | array | No | `[]` | ipv4 域名列表 | 为`[]`时,不会获取和更新 IPv4 地址 |
162
- | ipv6 | array | No | `[]` | ipv6 域名列表 | 为`[]`时,不会获取和更新 IPv6 地址 |
163
- | index4 | string\|int\|array | No | `"default"` | ipv4 获取方式 | 可设置`网卡`,`内网`,`公网`,`正则`等方式 |
164
- | index6 | string\|int\|array | No | `"default"` | ipv6 获取方式 | 可设置`网卡`,`内网`,`公网`,`正则`等方式 |
165
- | ttl | number | No | `null` | DNS 解析 TTL 时间 | 不设置采用 DNS 默认策略 |
166
- | proxy | string | No | 无 | http 代理`;`分割 | 多代理逐个尝试直到成功,`DIRECT`为直连 |
167
- | debug | bool | No | `false` | 是否开启调试 | 运行异常时,打开调试输出,方便诊断错误 |
168
- | cache | string\|bool | No | `true` | 是否缓存记录 | 正常情况打开避免频繁更新,默认位置为临时目录下`ddns.cache`,<br>也可以指定一个具体文件实现自定义文件缓存位置 |
169
-
170
- #### index4 和 index6 参数说明
171
-
172
- - 数字(`0`,`1`,`2`,`3`等): 第 i 个网卡 ip
173
- - 字符串`"default"`(或者无此项): 系统访问外网默认 IP
174
- - 字符串`"public"`: 使用公网 ip(使用公网 API 查询,url 的简化模式)
175
- - 字符串`"url:xxx"`: 打开 URL `xxx`(如:`"url:http://ip.sb"`),从返回的数据提取 IP 地址
176
- - 字符串`"regex:xxx"` 正则表达(如`"regex:192.*"`): 提取`ifconfig`/`ipconfig`中与之匹配的首个 IP 地址,**注意 json 转义**(`\`要写成`\\`)
177
- - `"192.*"`表示 192 开头的所有 ip (注意`regex:`不可省略)
178
- - 如果想匹配`10.00.xxxx`应该写成`"regex:10\\.00\\..*"` (`"\\"` json 转义成`\`)
179
- - 字符串`"cmd:xxxx"`: 执行命令`xxxx`的 stdout 输出结果作为目标 IP
180
- - 字符串`"shell:xxx"`: 使用系统 shell 运行`xxx`,并把结果 stdout 作为目标 IP
181
- - `false`: 强制禁止更新 ipv4 或 ipv6 的 DNS 解析
182
- - 列表:依次执行列表中的index规则,并将最先获得的结果作为目标 IP
183
- - 例如`["public", "regex:172\\..*"]`将先查询公网API,未获取到IP后再从本地寻找172开头的IP
184
-
185
- #### 自定义回调配置说明
186
-
187
- - `id` 字段填写回调地址,以 HTTP 或 HTTPS 开头,推荐采用 HTTPS 方式的回调 API ,当 `token` 字段非空且 URL 参数包含下表所示的常量字符串时,常量会被程序替换为实际值
188
- - `token` 字段为 POST 参数,本字段为空或不存在则使用 GET 方式发起回调,回调参数采用 JSON 格式编码,当 JSON 的首层参数值包含下表所示的常量字符串时,常量会被程序替换为实际值
189
-
190
- | 常量名称 | 常量内容 | 说明 |
191
- | ---------------- | ---------------------- | -------- |
192
- | `__DOMAIN__` | DDNS 域名 | |
193
- | `__RECORDTYPE__` | DDNS 记录类型 | |
194
- | `__TTL__` | DDNS TTL | |
195
- | `__TIMESTAMP__` | 请求发起时间戳 | 包含小数 |
196
- | `__IP__` | 获取的对应类型的IP地址 | |
197
-
198
- #### 配置示例
199
-
200
- ```json
201
- {
202
- "$schema": "https://ddns.newfuture.cc/schema/v2.8.json",
203
- "id": "12345",
204
- "token": "mytokenkey",
205
- "dns": "dnspod 或 dnspod_com 或 alidns 或 dnscom 或 cloudflare 或 he 或 huaweidns 或 callback",
206
- "ipv4": ["ddns.newfuture.cc", "ipv4.ddns.newfuture.cc"],
207
- "ipv6": ["ddns.newfuture.cc", "ipv6.ddns.newfuture.cc"],
208
- "index4": 0,
209
- "index6": "public",
210
- "ttl": 600,
211
- "proxy": "127.0.0.1:1080;DIRECT",
212
- "debug": false
213
- }
214
- ```
215
-
216
- </details>
217
-
218
- ## 定时任务
219
-
220
- <details>
221
-
222
- <summary markdown="span">可以通过脚本设置定时任务(默认每5分钟检查一次ip,自动更新)
223
- </summary>
224
-
225
- #### Windows
226
-
227
- - [推荐]以系统身份运行,右键"以管理员身份运行"`task.bat`(或者在管理员命令行中运行)
228
- - 以当前用户身份运行定时任务,双击或者运行`task.bat` (执行时会闪黑框)
229
-
230
- #### Linux
231
-
232
- - 使用init.d和crontab:
233
- `sudo ./task.sh`
234
- - 使用systemd:
235
- ```bash
236
- 安装:
237
- sudo ./systemd.sh install
238
- 卸载:
239
- sudo ./systemd.sh uninstall
240
- ```
241
- 该脚本安装的文件符合 [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard):
242
- 可执行文件所在目录为 `/usr/share/DDNS`
243
- 配置文件所在目录为 `/etc/DDNS`
244
-
245
- #### Docker
246
-
247
- Docker镜像在无额外参数的情况下,已默认启用每5分钟执行一次的定时任务
248
- </details>
249
-
250
- ## FAQ
251
-
252
- <details>
253
-
254
- <summary markdown="span"> Windows Server [SSL: CERTIFICATE_VERIFY_FAILED]
255
- </summary>
256
-
257
- > Windows Server 默认安全策略会禁止任何未添加的信任 ssl 证书,可手动添加一下对应的证书 [#56](https://github.com/NewFuture/DDNS/issues/56#issuecomment-487371078)
258
-
259
- 使用系统自带的 IE 浏览器访问一次对应的 API 即可
260
-
261
- - alidns 打开: <https://alidns.aliyuncs.com>
262
- - cloudflare 打开: <https://api.cloudflare.com>
263
- - dns.com 打开: <https://www.dns.com>
264
- - dnspod.cn 打开: <https://dnsapi.cn>
265
- - dnspod 国际版: <https://api.dnspod.com>
266
- - 华为 DNS <https://dns.myhuaweicloud.com>
267
- </details>
268
-
269
- <details>
270
-
271
- <summary markdown="span"> 问题排查反馈
272
- </summary>
273
-
274
- 1. 先确认排查是否是系统/网络环境问题
275
- 2. 在[issues](https://github.com/NewFuture/DDNS/issues)中搜索是否有类似问题
276
- 3. 前两者均无法解决或者确定是 bug,[在此新建 issue](https://github.com/NewFuture/DDNS/issues/new)
277
- - [ ] 开启 debug 配置
278
- - [ ] 附上这些内容 **运行版本和方式**,**系统环境**, **出错日志**,**去掉 id/token**的配置文件
279
- - [ ] 源码运行注明使用的 python 环境
280
-
281
- </details>
@@ -1,20 +0,0 @@
1
- run.py,sha256=lzR1gFKX3VQybC3SSvLn_xNlrVs42d8wApKIFxjDpaw,6072
2
- ddns-3.1.5.dist-info/licenses/LICENSE,sha256=MI-ECjp-Vl7WZLiSPY6r5VwrOReNiICVB1QCXiUGt_s,1111
3
- dns/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- dns/alidns.py,sha256=qA1jm6qYxuLHYWVlCkHOizP7EisCXwSndqKibu_0CbM,5788
5
- dns/callback.py,sha256=gVszmwu2OENYXJKEz1ay1v0H03fBO-REZdwBcxn490U,3214
6
- dns/cloudflare.py,sha256=t_VNM4QfkVVyoLZxHEL0zZrh_1BaEi2tR8Ckx1Z6dek,5653
7
- dns/dnscom.py,sha256=PKKVd4O1696RVSc_abMh5BVs6fiVm86hYZVFTNgt_54,5304
8
- dns/dnspod.py,sha256=c2i6-Gz-So8EzHPMN0u4Eu4nG_VEan_gjp6LoRO0OlQ,6148
9
- dns/dnspod_com.py,sha256=9DW7Oz1f2fYSLDDGdwQKMp9OhRJ_CYB8bfzGhf0fIMI,339
10
- dns/he.py,sha256=iSB9XWAIq_njYbudHpIrI0CZTuxQb46b0ungTVvenNk,2148
11
- dns/huaweidns.py,sha256=MeVTFwLAT6Y0AiDo-6vMUVcBFKxyV5sYJYpvSv_Mw1o,8753
12
- util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- util/cache.py,sha256=nt_x_BUORwUAZZW13UNeEBOFrIksWWhdj9k4AGyvnU8,3337
14
- util/config.py,sha256=8zvjdYEzQF7XaQHG7tyjXl6JBAHcOhl9ARCFQkcBeJs,4774
15
- util/ip.py,sha256=IZDcxOeY6IYrrRJbgxfDtA_Ibb842hbTTwW4yhhydyg,3842
16
- ddns-3.1.5.dist-info/METADATA,sha256=W9E-FYIGT6d7iYSNJI_w8MstGvsB61rGleF6y4yDNng,13520
17
- ddns-3.1.5.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
18
- ddns-3.1.5.dist-info/entry_points.txt,sha256=vpxxBE6Kepc-SHatr-FRRLmZecrTupYejyDB8ovJbLg,34
19
- ddns-3.1.5.dist-info/top_level.txt,sha256=dS3_ClQTIG1ousHykZ1P3AzQa-MKq4jT_rbm21D-KxE,13
20
- ddns-3.1.5.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- ddns = run:main
@@ -1,3 +0,0 @@
1
- dns
2
- run
3
- util
run.py DELETED
@@ -1,169 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- DDNS
5
- @author: New Future
6
- @modified: rufengsuixing
7
- """
8
- from __future__ import print_function
9
- from time import ctime, asctime
10
- from os import path, environ, name as os_name
11
- from tempfile import gettempdir
12
- from logging import DEBUG, basicConfig, info, warning, error, debug
13
- from subprocess import check_output
14
-
15
- import sys
16
-
17
- from util import ip
18
- from util.cache import Cache
19
- from util.config import init_config, get_config
20
-
21
- __version__ = "v3.1.5@2025-04-09T18:52:50+00:00" # CI 时会被Tag替换
22
- __description__ = "automatically update DNS records to dynamic local IP [自动更新DNS记录指向本地IP]"
23
- __doc__ = """
24
- ddns[%s]
25
- (i) homepage or docs [文档主页]: https://ddns.newfuture.cc/
26
- (?) issues or bugs [问题和帮助]: https://github.com/NewFuture/DDNS/issues
27
- Copyright (c) New Future (MIT License)
28
- """ % (__version__)
29
-
30
- environ["DDNS_VERSION"] = "v3.1.5"
31
-
32
- if getattr(sys, 'frozen', False):
33
- # https://github.com/pyinstaller/pyinstaller/wiki/Recipe-OpenSSL-Certificate
34
- environ['SSL_CERT_FILE'] = path.join(
35
- getattr(sys, '_MEIPASS'), 'lib', 'cert.pem')
36
-
37
-
38
- def get_ip(ip_type, index="default"):
39
- """
40
- get IP address
41
- """
42
- # CN: 捕获异常
43
- # EN: Catch exceptions
44
- value = None
45
- try:
46
- debug(f"get_ip({ip_type}, {index})")
47
- if index is False: # disabled
48
- return False
49
- elif type(index) is list: # 如果获取到的规则是列表,则依次判断列表中每一个规则,直到找到一个可以正确获取到的IP
50
- for i in index:
51
- value = get_ip(ip_type, i)
52
- if value:
53
- break
54
- elif str(index).isdigit(): # 数字 local eth
55
- value = getattr(ip, "local_v" + ip_type)(index)
56
- elif index.startswith('cmd:'): # cmd
57
- value = str(check_output(index[4:]).strip().decode('utf-8'))
58
- elif index.startswith('shell:'): # shell
59
- value = str(check_output(
60
- index[6:], shell=True).strip().decode('utf-8'))
61
- elif index.startswith('url:'): # 自定义 url
62
- value = getattr(ip, "public_v" + ip_type)(index[4:])
63
- elif index.startswith('regex:'): # 正则 regex
64
- value = getattr(ip, "regex_v" + ip_type)(index[6:])
65
- else:
66
- value = getattr(ip, index + "_v" + ip_type)()
67
- except Exception as e:
68
- error(e)
69
- finally:
70
- return value
71
-
72
-
73
- def change_dns_record(dns, proxy_list, **kw):
74
- for proxy in proxy_list:
75
- if not proxy or (proxy.upper() in ['DIRECT', 'NONE']):
76
- dns.Config.PROXY = None
77
- else:
78
- dns.Config.PROXY = proxy
79
- record_type, domain = kw['record_type'], kw['domain']
80
- print('\n%s %s(%s) ==> %s [via %s]' %
81
- (asctime(), domain, record_type, kw['ip'], proxy))
82
- try:
83
- return dns.update_record(domain, kw['ip'], record_type=record_type)
84
- except Exception as e:
85
- error(e)
86
- return False
87
-
88
-
89
- def update_ip(ip_type, cache, dns, proxy_list):
90
- """
91
- 更新IP
92
- """
93
- ipname = 'ipv' + ip_type
94
- domains = get_config(ipname)
95
- if not domains:
96
- return None
97
- if not isinstance(domains, list):
98
- domains = domains.strip('; ').replace(
99
- ',', ';').replace(' ', ';').split(';')
100
- index_rule = get_config('index' + ip_type, "default") # 从配置中获取index配置
101
- address = get_ip(ip_type, index_rule)
102
- if not address:
103
- error('Fail to get %s address!', ipname)
104
- return False
105
- elif cache and (address == cache[ipname]):
106
- print('.', end=" ") # 缓存命中
107
- return True
108
- record_type = (ip_type == '4') and 'A' or 'AAAA'
109
- update_fail = False # https://github.com/NewFuture/DDNS/issues/16
110
- for domain in domains:
111
- domain = domain.lower() # https://github.com/NewFuture/DDNS/issues/431
112
- if change_dns_record(dns, proxy_list, domain=domain, ip=address, record_type=record_type):
113
- update_fail = True
114
- if cache is not False:
115
- # 如果更新失败删除缓存
116
- cache[ipname] = update_fail and address
117
-
118
-
119
- def main():
120
- """
121
- 更新
122
- """
123
- init_config(__description__, __doc__, __version__)
124
- # Dynamicly import the dns module as configuration
125
- dns_provider = str(get_config('dns', 'dnspod').lower())
126
- dns = getattr(__import__('dns', fromlist=[dns_provider]), dns_provider)
127
- dns.Config.ID = get_config('id')
128
- dns.Config.TOKEN = get_config('token')
129
- dns.Config.TTL = get_config('ttl')
130
- if get_config('debug'):
131
- ip.DEBUG = get_config('debug')
132
- basicConfig(
133
- level=DEBUG,
134
- format='%(asctime)s <%(module)s.%(funcName)s> %(lineno)d@%(pathname)s \n[%(levelname)s] %(message)s')
135
- print("DDNS[", __version__, "] run:", os_name, sys.platform)
136
- if get_config("config"):
137
- print("Configuration was loaded from <==",
138
- path.abspath(get_config("config")))
139
- print("=" * 25, ctime(), "=" * 25, sep=' ')
140
-
141
- proxy = get_config('proxy') or 'DIRECT'
142
- proxy_list = proxy if isinstance(
143
- proxy, list) else proxy.strip('; ').replace(',', ';').split(';')
144
-
145
- cache_config = get_config('cache', True)
146
- if cache_config is False:
147
- cache = cache_config
148
- elif cache_config is True:
149
- cache = Cache(path.join(gettempdir(), 'ddns.cache'))
150
- else:
151
- cache = Cache(cache_config)
152
-
153
- if cache is False:
154
- info("Cache is disabled!")
155
- elif get_config("config_modified_time") is None or get_config("config_modified_time") >= cache.time:
156
- warning("Cache file is out of dated.")
157
- cache.clear()
158
- else:
159
- debug("Cache is empty.")
160
- update_ip('4', cache, dns, proxy_list)
161
- update_ip('6', cache, dns, proxy_list)
162
-
163
-
164
- if __name__ == '__main__':
165
- if sys.version_info.major == 3 and os_name == 'nt':
166
- from io import TextIOWrapper
167
- sys.stdout = TextIOWrapper(sys.stdout.detach(), encoding='utf-8')
168
- sys.stderr = TextIOWrapper(sys.stderr.detach(), encoding='utf-8')
169
- main()
util/config.py DELETED
@@ -1,126 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- from argparse import ArgumentParser, ArgumentTypeError, Namespace, RawTextHelpFormatter # noqa: F401
4
- from json import load as loadjson, dump as dumpjson
5
- from logging import error
6
- from os import stat, environ
7
- from time import time
8
-
9
- import sys
10
-
11
-
12
- __cli_args = {} # type: Namespace
13
- __config = {} # type: dict
14
-
15
-
16
- def str2bool(v):
17
- """
18
- parse string to boolean
19
- """
20
- if isinstance(v, bool):
21
- return v
22
- if v.lower() in ('yes', 'true', 't', 'y', '1'):
23
- return True
24
- elif v.lower() in ('no', 'false', 'f', 'n', '0'):
25
- return False
26
- else:
27
- raise ArgumentTypeError('Boolean value expected.')
28
-
29
-
30
- def init_config(description, doc, version):
31
- """
32
- 配置
33
- """
34
- global __cli_args
35
- parser = ArgumentParser(description=description,
36
- epilog=doc, formatter_class=RawTextHelpFormatter)
37
- parser.add_argument('-v', '--version',
38
- action='version', version=version)
39
- parser.add_argument('-c', '--config', help="run with config file [配置文件路径]")
40
-
41
- # 参数定义
42
- parser.add_argument('--dns', help="DNS Provider [DNS服务提供商]", choices=[
43
- 'alidns', 'cloudflare', 'dnscom', 'dnspod', 'dnspod_com', 'he', 'huaweidns', 'callback'])
44
- parser.add_argument('--id', help="api ID [授权账户]")
45
- parser.add_argument('--token', help="api token or Secret key [授权访问凭证或密钥]")
46
- parser.add_argument('--ipv4', nargs="*",
47
- help="ipv4 domain list [IPV4域名列表]")
48
- parser.add_argument('--ipv6', nargs="*",
49
- help="ipv6 domain list [IPV6域名列表]")
50
- parser.add_argument('--index4', help="the way to get ipv4 [IPV4 获取方式]")
51
- parser.add_argument('--index6', help="the way to get ipv6 [IPV6获取方式]")
52
- parser.add_argument('--ttl', type=int, help="ttl for DNS [DNS 解析 TTL 时间]")
53
- parser.add_argument('--proxy', nargs="*",
54
- help="https proxy [设置http 代理,多代理逐个尝试直到成功]")
55
- parser.add_argument('--debug', type=str2bool, nargs='?',
56
- const=True, help="debug mode [是否开启调试,默认否]", )
57
- parser.add_argument('--cache', type=str2bool, nargs='?',
58
- const=True, help="enable cache [是否缓存记录,默认是]")
59
-
60
- __cli_args = parser.parse_args()
61
- is_configfile_optional = get_config("token") or get_config("id")
62
- config_file = get_config("config")
63
- if not is_configfile_optional or config_file is not None:
64
- __load_config(config_file or "config.json", is_configfile_optional)
65
- __cli_args.config = config_file or "config.json"
66
-
67
-
68
- def __load_config(path="config.json", skip_auto_generation=False):
69
- """
70
- 加载配置
71
- """
72
- global __config
73
- try:
74
- with open(path) as configfile:
75
- __config = loadjson(configfile)
76
- __config["config_modified_time"] = stat(path).st_mtime
77
- except IOError:
78
- if skip_auto_generation:
79
- __config["config_modified_time"] = time()
80
- return
81
- error(' Config file `%s` does not exist!' % path)
82
- with open(path, 'w') as configfile:
83
- configure = {
84
- "$schema": "https://ddns.newfuture.cc/schema/v2.8.json",
85
- "id": "YOUR ID or EMAIL for DNS Provider",
86
- "token": "YOUR TOKEN or KEY for DNS Provider",
87
- "dns": "dnspod",
88
- "ipv4": [
89
- "newfuture.cc",
90
- "ddns.newfuture.cc"
91
- ],
92
- "ipv6": [
93
- "newfuture.cc",
94
- "ipv6.ddns.newfuture.cc"
95
- ],
96
- "index4": "default",
97
- "index6": "default",
98
- "ttl": None,
99
- "proxy": None,
100
- "debug": False,
101
- }
102
- dumpjson(configure, configfile, indent=2, sort_keys=True)
103
- sys.stdout.write(
104
- "New template configure file `%s` is generated.\n" % path)
105
- sys.exit(1)
106
- except Exception:
107
- sys.exit('fail to load config from file: %s' % path)
108
-
109
-
110
- def get_config(key, default=None):
111
- """
112
- 读取配置
113
- 1. 命令行参数
114
- 2. 配置文件
115
- 3. 环境变量
116
- """
117
- if hasattr(__cli_args, key) and getattr(__cli_args, key) is not None:
118
- return getattr(__cli_args, key)
119
- if key in __config:
120
- return __config.get(key)
121
- env_name = 'DDNS_'+key.upper() # type:str
122
- if env_name in environ: # 大写环境变量
123
- return environ.get(env_name)
124
- if env_name.lower() in environ: # 小写环境变量
125
- return environ.get(env_name.lower())
126
- return default
File without changes
File without changes