Skip to content

Commit

Permalink
feat: support english (#967)
Browse files Browse the repository at this point in the history
* feat: init the i18n

* fix: porkbun

* refactor: http_util GetHTTPResponse

* fix: save

* fix: add more i18n

* feat: i18n at writing.html

* feat: README EN

* fix: default api

* fix: pic
  • Loading branch information
jeessy2 authored Jan 11, 2024
1 parent 8b508c6 commit eec9840
Show file tree
Hide file tree
Showing 31 changed files with 703 additions and 448 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![GitHub release](https://img.shields.io/github/release/jeessy2/ddns-go.svg?logo=github&style=flat-square) ![GitHub release downloads](https://img.shields.io/github/downloads/jeessy2/ddns-go/total?logo=github)](https://github.com/jeessy2/ddns-go/releases/latest) [![Go version](https://img.shields.io/github/go-mod/go-version/jeessy2/ddns-go)](https://github.com/jeessy2/ddns-go/blob/master/go.mod) [![](https://goreportcard.com/badge/github.com/jeessy2/ddns-go/v5)](https://goreportcard.com/report/github.com/jeessy2/ddns-go/v5) [![](https://img.shields.io/docker/image-size/jeessy/ddns-go)](https://registry.hub.docker.com/r/jeessy/ddns-go) [![](https://img.shields.io/docker/pulls/jeessy/ddns-go)](https://registry.hub.docker.com/r/jeessy/ddns-go)

中文 | [English](https://github.com/jeessy2/ddns-go/blob/master/README_EN.md)

自动获得你的公网 IPv4 或 IPv6 地址,并解析到对应的域名服务。

- [特性](#特性)
Expand All @@ -16,7 +18,7 @@
## 特性

- 支持Mac、Windows、Linux系统,支持ARM、x86架构
- 支持的域名服务商 `Alidns(阿里云)` `Dnspod(腾讯云)` `Cloudflare` `华为云` `Callback` `百度云` `Porkbun` `GoDaddy` `Google Domain`
- 支持的域名服务商 `阿里云` `腾讯云` `Dnspod` `Cloudflare` `华为云` `Callback` `百度云` `Porkbun` `GoDaddy` `Google Domain`
- 支持接口/网卡/[命令](https://github.com/jeessy2/ddns-go/wiki/通过命令获取IP参考)获取IP
- 支持以服务的方式运行
- 默认间隔5分钟同步一次
Expand All @@ -35,20 +37,18 @@
## 系统中使用

-[Releases](https://github.com/jeessy2/ddns-go/releases) 下载并解压 ddns-go
- [可选] 使用 [Homebrew](https://brew.sh) 安装 [ddns-go](https://formulae.brew.sh/formula/ddns-go)

```bash
brew install ddns-go
```

- 双击运行, 如没有找到配置, 程序将自动打开 http://127.0.0.1:9876
- [可选] 安装服务
- 安装服务
- Mac/Linux: `sudo ./ddns-go -s install`
- Win(以管理员打开cmd): `.\ddns-go.exe -s install`
- [可选] 服务卸载
- Mac/Linux: `sudo ./ddns-go -s uninstall`
- Win(以管理员打开cmd): `.\ddns-go.exe -s uninstall`
- [可选] 支持安装或启动时带参数 `-l`监听地址 `-f`同步间隔时间(秒) `-cacheTimes`间隔N次与服务商比对 `-c`自定义配置文件路径 `-noweb`不启动web服务 `-skipVerify`跳过证书验证 `-dns` 自定义 DNS 服务器。如:`./ddns-go -s install -l :9877 -f 600 -c /Users/name/ddns-go.yaml`
- [可选] 支持安装带参数 `-l`监听地址 `-f`同步间隔时间(秒) `-cacheTimes`间隔N次与服务商比对 `-c`自定义配置文件路径 `-noweb`不启动web服务 `-skipVerify`跳过证书验证 `-dns` 自定义 DNS 服务器。如:`./ddns-go -s install -l :9876 -f 600 -c /Users/name/ddns-go.yaml`
- [可选] 使用 [Homebrew](https://brew.sh) 安装 [ddns-go](https://formulae.brew.sh/formula/ddns-go)

```bash
brew install ddns-go
```

> [!NOTE]
> 通过合理的配置 `-f``-cacheTimes` 可以实现 IP 变化即时触发更新且不会被 DDNS 服务商限流, 例如 `-f 10 -cacheTimes 360` 效果为每 10 秒检查一次本地 IP 变化, 每小时去公网对比一下 IP 变化
Expand All @@ -61,7 +61,7 @@
docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root jeessy/ddns-go
```

- 在浏览器中打开`http://主机IP:9876`修改你的配置,成功
- 在浏览器中打开`http://主机IP:9876`并修改你的配置

- [可选] 使用 `ghcr.io` 镜像

Expand Down
140 changes: 140 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# ddns-go

[![GitHub release](https://img.shields.io/github/release/jeessy2/ddns-go.svg?logo=github&style=flat-square) ![GitHub release downloads](https://img.shields.io/github/downloads/jeessy2/ddns-go/total?logo=github)](https://github.com/jeessy2/ddns-go/releases/latest) [![Go version](https://img.shields.io/github/go-mod/go-version/jeessy2/ddns-go)](https://github.com/jeessy2/ddns-go/blob/master/go.mod) [![](https://goreportcard.com/badge/github.com/jeessy2/ddns-go/v5)](https://goreportcard.com/report/github.com/jeessy2/ddns-go/v5) [![](https://img.shields.io/docker/image-size/jeessy/ddns-go)](https://registry.hub.docker.com/r/jeessy/ddns-go) [![](https://img.shields.io/docker/pulls/jeessy/ddns-go)](https://registry.hub.docker.com/r/jeessy/ddns-go)

[中文](https://github.com/jeessy2/ddns-go/blob/master/README.md) | English

Automatically obtain your public IPv4 or IPv6 address and resolve it to the corresponding domain name service.

- [Features](#Features)
- [Use in system](#Use-in-system)
- [Use in docker](#Use-in-docker)
- [Webhook](#webhook)
- [Callback](#callback)
- [Web interfaces](#Web-interfaces)

## Features

- Support Mac, Windows, Linux system, support ARM, x86 architecture
- Support domain service providers `Aliyun` `Tencent` `Dnspod` `Cloudflare` `Huawei` `Callback` `Baidu` `Porkbun` `GoDaddy` `Google Domain` `Namecheap` `NameSilo`
- Support interface / netcard / command to get IP
- Support running as a service
- Default interval is 5 minutes
- Support configuring multiple DNS service providers at the same time
- Support multiple domain name resolution at the same time
- Support multi-level domain name
- Configured on the web page, simple and convenient
- In the web page, you can quickly view the latest 50 logs
- Support Webhook notification
- Support TTL

> [!NOTE]
> If you enable public network access, it is recommended to use Nginx and other reverse proxy software to enable HTTPS access to ensure security.
## Use in system

- Download and unzip ddns-go from [Releases](https://github.com/jeessy2/ddns-go/releases)
- Run in service mode
- Mac/Linux: `sudo ./ddns-go -s install`
- Win(Run as administrator): `.\ddns-go.exe -s install`
- [Optional] Uninstall service
- Mac/Linux: `sudo ./ddns-go -s uninstall`
- Win(Run as administrator): `.\ddns-go.exe -s uninstall`
- [Optional] Support installation with parameters `-l` listen address `-f` Sync frequency(seconds) `-cacheTimes` interval N times compared with service providers `-c` custom configuration file path `-noweb` does not start web service `-skipVerify` skip certificate verification `-dns` custom DNS server. example:`./ddns-go -s install -l :9876 -f 600 -c /Users/name/ddns-go.yaml`
- [Optional] You can use [Homebrew](https://brew.sh) to install [ddns-go](https://formulae.brew.sh/formula/ddns-go)

```bash
brew install ddns-go
```

## Use in docker

- Mount the host directory, use the docker host mode. You can replace `/opt/ddns-go` with any directory on your host, the configuration file is a hidden file

```bash
docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root jeessy/ddns-go
```

- Open `http://DOCKER_IP:9876` in the browser, modify your configuration

- [Optional] Use `ghcr.io` mirror

```bash
docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root ghcr.io/jeessy2/ddns-go
```

- [Optional] Support startup with parameters `-l`listen address `-f`Sync frequency(seconds)

```bash
docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root jeessy/ddns-go -l :9877 -f 600
```

- [Optional] Without using docker host mode

```bash
docker run -d --name ddns-go --restart=always -p 9876:9876 -v /opt/ddns-go:/root jeessy/ddns-go
```

## Webhook

- Support webhook, when the domain name is updated successfully or not, the URL filled in will be called back
- Support variables

| Variable name | Comments |
| ---- | ---- |
| #{ipv4Addr} | The new IPv4 |
| #{ipv4Result} | IPv4 update result: `no changed` `success` `failed`|
| #{ipv4Domains} | IPv4 domains,Split by `,` |
| #{ipv6Addr} | The new IPv6 |
| #{ipv6Result} | IPv6 update result: `no changed` `success` `failed`|
| #{ipv6Domains} | IPv6 domains,Split by `,` |

- If RequestBody is empty, it is a `GET` request, otherwise it is a `POST` request

- <details><summary>Telegram</summary>

[ddns-telegram-bot](https://github.com/WingLim/ddns-telegram-bot)
</details>
- <details><summary>Discord</summary>

- Discord client -> Server -> Channel Settings -> Integration -> View Webhook -> New Webhook -> Copy Webhook URL
- Input the `Webhook URL` copied from Discord in the URL
- Input in RequestBody
```json
{
"content": "The domain name #{ipv4Domains} dynamically resolves to #{ipv4Result}.",
"embeds": [
{
"description": "Domains: #{ipv4Domains}, Result: #{ipv4Result}, IP: #{ipv4Addr}",
"color": 15258703,
"author": {
"name": "DDNS"
},
"footer": {
"text": "DDNS #{ipv4Result}"
}
}
]
}
```
</details>

- [More webhook configuration reference](https://github.com/jeessy2/ddns-go/issues/327)

## Callback

- Support more third-party DNS service providers through custom callback
- Callback will be called as many times as there are lines in the configured domain name
- Support variables

| Variable name | Comments |
| ---- | ---- |
| #{ip} | The new IPv4/IPv6 address|
| #{domain} | Current domain |
| #{recordType} | Record type `A` or `AAAA` |
| #{ttl} | TTL |
- If RequestBody is empty, it is a `GET` request, otherwise it is a `POST` request

## Web interfaces

![screenshots](https://raw.githubusercontent.com/jeessy2/ddns-go/master/ddns-web.png)
55 changes: 29 additions & 26 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Config struct {
Webhook
// 禁止公网访问
NotAllowWanAccess bool
// 语言
Lang string
}

// ConfigCache ConfigCache
Expand Down Expand Up @@ -92,14 +94,14 @@ func GetConfigCached() (conf Config, err error) {

byt, err := os.ReadFile(configFilePath)
if err != nil {
log.Println(configFilePath + " 读取失败")
util.Log("异常信息: %s", err)
cache.Err = err
return *cache.ConfigSingle, err
}

err = yaml.Unmarshal(byt, cache.ConfigSingle)
if err != nil {
log.Println("反序列化配置文件失败", err)
util.Log("异常信息: %s", err)
cache.Err = err
return *cache.ConfigSingle, err
}
Expand All @@ -109,6 +111,9 @@ func GetConfigCached() (conf Config, err error) {
cache.ConfigSingle.NotAllowWanAccess = true
}

// 初始化语言
util.InitLogLang(cache.ConfigSingle.Lang)

// remove err
cache.Err = nil
return *cache.ConfigSingle, err
Expand Down Expand Up @@ -161,7 +166,7 @@ func (conf *Config) SaveConfig() (err error) {
return
}

log.Printf("配置文件已保存在: %s\n", configFilePath)
util.Log("配置文件已保存在: %s", configFilePath)

// 清空配置缓存
cache.ConfigSingle = nil
Expand All @@ -172,7 +177,7 @@ func (conf *Config) SaveConfig() (err error) {
func (conf *DnsConfig) getIpv4AddrFromInterface() string {
ipv4, _, err := GetNetInterface()
if err != nil {
log.Println("从网卡获得IPv4失败!")
util.Log("从网卡获得IPv4失败")
return ""
}

Expand All @@ -182,7 +187,7 @@ func (conf *DnsConfig) getIpv4AddrFromInterface() string {
}
}

log.Println("从网卡中获得IPv4失败! 网卡名: ", conf.Ipv4.NetInterface)
util.Log("从网卡中获得IPv4失败! 网卡名: %s", conf.Ipv4.NetInterface)
return ""
}

Expand All @@ -193,20 +198,20 @@ func (conf *DnsConfig) getIpv4AddrFromUrl() string {
url = strings.TrimSpace(url)
resp, err := client.Get(url)
if err != nil {
log.Printf("连接失败! <a target='blank' href='%s'>点击查看接口能否返回IPv4地址</a>\n", url)
log.Printf("错误信息: %s\n", err)
util.Log("通过接口获取IPv4失败! 接口地址: %s", url)
util.Log("异常信息: %s", err)
continue
}
defer resp.Body.Close()
lr := io.LimitReader(resp.Body, 1024000)
body, err := io.ReadAll(lr)
if err != nil {
log.Println("读取IPv4结果失败! 接口: ", url)
util.Log("异常信息: %s", err)
continue
}
result := Ipv4Reg.FindString(string(body))
if result == "" {
log.Printf("获取IPv4结果失败! 接口: %s ,返回值: %s\n", url, result)
util.Log("获取IPv4结果失败! 接口: %s ,返回值: %s", url, string(body))
}
return result
}
Expand Down Expand Up @@ -243,14 +248,14 @@ func (conf *DnsConfig) getAddrFromCmd(addrType string) string {
// run cmd
out, err := execCmd.CombinedOutput()
if err != nil {
log.Printf("获取%s结果失败! 未能成功执行命令:%s错误:%q退出状态码:%s\n", addrType, execCmd.String(), out, err)
util.Log("获取%s结果失败! 未能成功执行命令:%s, 错误:%q, 退出状态码:%s", addrType, execCmd.String(), out, err)
return ""
}
str := string(out)
// get result
result := comp.FindString(str)
if result == "" {
log.Printf("获取%s结果失败! 命令:%s,标准输出:%q\n", addrType, execCmd.String(), str)
util.Log("获取%s结果失败! 命令: %s, 标准输出: %q", addrType, execCmd.String(), str)
}
return result
}
Expand All @@ -269,15 +274,15 @@ func (conf *DnsConfig) GetIpv4Addr() string {
// 从命令行获取 IP
return conf.getAddrFromCmd("IPv4")
default:
log.Println("IPv4 的 获取 IP 方式 未知!")
log.Println("IPv4's get IP method is unknown")
return "" // unknown type
}
}

func (conf *DnsConfig) getIpv6AddrFromInterface() string {
_, ipv6, err := GetNetInterface()
if err != nil {
log.Println("从网卡获得IPv6失败!")
util.Log("从网卡获得IPv6失败")
return ""
}

Expand All @@ -289,34 +294,32 @@ func (conf *DnsConfig) getIpv6AddrFromInterface() string {
num, err := strconv.Atoi(conf.Ipv6.IPv6Reg[1:])
if err == nil {
if num > 0 {
log.Printf("IPv6将使用第 %d 个IPv6地址\n", num)
if num <= len(netInterface.Address) {
return netInterface.Address[num-1]
}
log.Printf("未找到第 %d 个IPv6地址! 将使用第一个IPv6地址\n", num)
util.Log("未找到第 %d 个IPv6地址! 将使用第一个IPv6地址", num)
return netInterface.Address[0]
}
log.Printf("IPv6匹配表达式 %s 不正确! 最小从1开始\n", conf.Ipv6.IPv6Reg)
util.Log("IPv6匹配表达式 %s 不正确! 最小从1开始", conf.Ipv6.IPv6Reg)
return ""
}
}
// 正则表达式匹配
log.Printf("IPv6将使用正则表达式 %s 进行匹配\n", conf.Ipv6.IPv6Reg)
util.Log("IPv6将使用正则表达式 %s 进行匹配", conf.Ipv6.IPv6Reg)
for i := 0; i < len(netInterface.Address); i++ {
matched, err := regexp.MatchString(conf.Ipv6.IPv6Reg, netInterface.Address[i])
if matched && err == nil {
log.Println("匹配成功! 匹配到地址: ", netInterface.Address[i])
util.Log("匹配成功! 匹配到地址: ", netInterface.Address[i])
return netInterface.Address[i]
}
log.Printf("第 %d 个地址 %s 不匹配, 将匹配下一个地址\n", i+1, netInterface.Address[i])
}
log.Println("没有匹配到任何一个IPv6地址, 将使用第一个地址")
util.Log("没有匹配到任何一个IPv6地址, 将使用第一个地址")
}
return netInterface.Address[0]
}
}

log.Println("从网卡中获得IPv6失败! 网卡名: ", conf.Ipv6.NetInterface)
util.Log("从网卡中获得IPv6失败! 网卡名: %s", conf.Ipv6.NetInterface)
return ""
}

Expand All @@ -327,21 +330,21 @@ func (conf *DnsConfig) getIpv6AddrFromUrl() string {
url = strings.TrimSpace(url)
resp, err := client.Get(url)
if err != nil {
log.Printf("连接失败! <a target='blank' href='%s'>点击查看接口能否返回IPv6地址</a>, 参考说明:<a target='blank' href='%s'>点击访问</a>\n", url, "https://github.com/jeessy2/ddns-go#使用ipv6")
log.Printf("错误信息: %s\n", err)
util.Log("通过接口获取IPv6失败! 接口地址: %s", url)
util.Log("异常信息: %s", err)
continue
}

defer resp.Body.Close()
lr := io.LimitReader(resp.Body, 1024000)
body, err := io.ReadAll(lr)
if err != nil {
log.Println("读取IPv6结果失败! 接口: ", url)
util.Log("异常信息: %s", err)
continue
}
result := Ipv6Reg.FindString(string(body))
if result == "" {
log.Printf("获取IPv6结果失败! 接口: %s ,返回值: %s\n", url, result)
util.Log("获取IPv6结果失败! 接口: %s ,返回值: %s", url, result)
}
return result
}
Expand All @@ -362,7 +365,7 @@ func (conf *DnsConfig) GetIpv6Addr() (result string) {
// 从命令行获取 IP
return conf.getAddrFromCmd("IPv6")
default:
log.Println("IPv6 的 获取 IP 方式 未知!")
log.Println("IPv6's get IP method is unknown")
return "" // unknown type
}
}
Loading

0 comments on commit eec9840

Please sign in to comment.