Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DDNS support #324

Merged
merged 13 commits into from
Feb 24, 2024
Merged

Add DDNS support #324

merged 13 commits into from
Feb 24, 2024

Conversation

DarcJC
Copy link
Contributor

@DarcJC DarcJC commented Feb 22, 2024

添加DDNS支持,可以定时检查并为设置的域名更新DNS记录

新增配置

ddns:
  enable: false
  checkperiod: 60
  provider: "webhook"
  accessid: ""
  accesssecret: ""
  webhookmethod: ""
  webhookurl: ""
  webhookrequestbody: ""
  webhookheaders: ""
  maxretries: 3

其中webhookurlwebhookrequestbody以及webhookheaders可以使用如下参数:
{ip} - 主机当前IP
{domain} - ddns域名
{type} - IP类型,可能为"ipv4"和"ipv6"
{access_id} - 凭据1
{access_secret} - 凭据2

示例:

DDNS:
  AccessID: "123"
  AccessSecret: "456"
  CheckPeriod: 10
  Enable: true
  Provider: webhook
  WebhookMethod: "POST"
  WebhookHeaders: |
    a:{access_id}
    b:{access_secret}
  WebhookRequestBody: '{"domain": "{domain}", "ip": "{ip}", "type": "{type}"}'
  WebhookURL: "http://localhost:8081"
  MaxRetries: 3

说明

增加了一个定时任务RefreshDDNSRecords,增加了一个singleton模块ddns。可以通过实现接口DDNSProvider并修改选择函数GetDDNSProviderFromString来实现新的Provider。

例子:

type DDNSProviderMy struct{}

// 实现接口,如果更新成功则返回true
func (provider DDNSProviderMy ) UpdateDomain(domainConfig *DDNSDomainConfig) bool { return true }

func GetDDNSProviderFromString(provider string) (DDNSProvider, error) {
	switch provider {
	// 省略已有的分支...
        case "my_provider":
            return DDNSProviderMy{}, nil
	}
	return DDNSProviderDummy{}, errors.New(fmt.Sprintf("无法找到配置的DDNS提供者%s", Conf.DDNS.Provider))
}

效果预览

已完成Webhook DDNS功能发送的请求

Webhook

新增字段效果图

image
image

@DarcJC DarcJC changed the title [WIP] Add DDNS support Add DDNS support Feb 23, 2024
@naiba
Copy link
Owner

naiba commented Feb 23, 2024

现在 agent 更新 IP 不及时

@DarcJC
Copy link
Contributor Author

DarcJC commented Feb 23, 2024

现在 agent 更新 IP 不及时

坏,那岂不是agent也要改。做这个功能主要是不想把DDNS提供商的凭据丢到小鸡上,感觉不太安全。集中在哪吒面板做的话安全性会高一点。

@naiba
Copy link
Owner

naiba commented Feb 23, 2024

现在 agent 更新 IP 不及时

坏,那岂不是agent也要改。做这个功能主要是不想把DDNS提供商的凭据丢到小鸡上,感觉不太安全。集中在哪吒面板做的话安全性会高一点。

现在 30 分钟才更新一次公网 IP

@DarcJC
Copy link
Contributor Author

DarcJC commented Feb 23, 2024

现在 agent 更新 IP 不及时

坏,那岂不是agent也要改。做这个功能主要是不想把DDNS提供商的凭据丢到小鸡上,感觉不太安全。集中在哪吒面板做的话安全性会高一点。

现在 30 分钟才更新一次公网 IP

已提PR
nezhahq/agent#13

@naiba
Copy link
Owner

naiba commented Feb 23, 2024

检测的逻辑可以考虑做到ip变动那里,不需要一个单独逻辑

@DarcJC
Copy link
Contributor Author

DarcJC commented Feb 23, 2024

检测的逻辑可以考虑做到ip变动那里,不需要一个单独逻辑

好,我晚点有空改完提交上来

@DarcJC
Copy link
Contributor Author

DarcJC commented Feb 23, 2024

@naiba 改了,康康还有什么地方要动的?没咋写过go,service/rpc/nezha.go:L117是不是应该开个协程跑啥的

resource/l10n/zh-CN.toml Show resolved Hide resolved
service/rpc/nezha.go Outdated Show resolved Hide resolved
service/singleton/singleton.go Outdated Show resolved Hide resolved
@naiba
Copy link
Owner

naiba commented Feb 23, 2024

@naiba 改了,康康还有什么地方要动的?没咋写过go,service/rpc/nezha.go:L117是不是应该开个协程跑啥的

在updatedomain那个方法上开就好,可以内部加错误重试几次的逻辑

@DarcJC
Copy link
Contributor Author

DarcJC commented Feb 23, 2024

@naiba 改了,康康还有什么地方要动的?没咋写过go,service/rpc/nezha.go:L117是不是应该开个协程跑啥的

在updatedomain那个方法上开就好,可以内部加错误重试几次的逻辑

已完成,agent那个PR也需要看一下~

service/rpc/nezha.go Outdated Show resolved Hide resolved
script/config.yaml Outdated Show resolved Hide resolved
@@ -38,6 +39,20 @@ func init() {
initSystem()
}

func secondsToCronString(seconds uint32) (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像没用到了

resource/static/main.js Show resolved Hide resolved
service/rpc/nezha.go Outdated Show resolved Hide resolved
@DarcJC
Copy link
Contributor Author

DarcJC commented Feb 23, 2024

已完成🚀

@naiba
Copy link
Owner

naiba commented Feb 24, 2024

有事 晚点看

@naiba naiba merged commit 3b5ee46 into naiba:master Feb 24, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants