mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
T#7765: DynamicDNS: Update implementation
This commit is contained in:
parent
3ff96f1d5b
commit
0e16d6b040
4 changed files with 477 additions and 574 deletions
|
|
@ -93723,21 +93723,6 @@
|
|||
{
|
||||
"max": 64
|
||||
}
|
||||
],
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "dmmap_ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "clientalias"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"LastError": {
|
||||
|
|
@ -94023,16 +94008,6 @@
|
|||
],
|
||||
"access": true,
|
||||
"array": true,
|
||||
"mapping": {
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service"
|
||||
},
|
||||
"dmmapfile": "dmmap_ddns"
|
||||
}
|
||||
},
|
||||
"Enable": {
|
||||
"type": "string",
|
||||
"read": true,
|
||||
|
|
@ -94047,21 +94022,6 @@
|
|||
{
|
||||
"max": 64
|
||||
}
|
||||
],
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "enabled"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Name": {
|
||||
|
|
@ -94110,21 +94070,6 @@
|
|||
{
|
||||
"max": 256
|
||||
}
|
||||
],
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "service_name"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"ServerAddress": {
|
||||
|
|
@ -94141,21 +94086,6 @@
|
|||
{
|
||||
"max": 256
|
||||
}
|
||||
],
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "dns_server"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"ServerPort": {
|
||||
|
|
@ -94173,21 +94103,6 @@
|
|||
"min": 0,
|
||||
"max": 65535
|
||||
}
|
||||
],
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "dns_server"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"SupportedProtocols": {
|
||||
|
|
@ -94216,22 +94131,7 @@
|
|||
"cwmp",
|
||||
"usp"
|
||||
],
|
||||
"datatype": "string",
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "use_https"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"datatype": "string"
|
||||
},
|
||||
"CheckInterval": {
|
||||
"type": "unsignedInt",
|
||||
|
|
@ -94243,22 +94143,7 @@
|
|||
"usp"
|
||||
],
|
||||
"datatype": "unsignedInt",
|
||||
"unit": "seconds",
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "check_interval"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"unit": "seconds"
|
||||
},
|
||||
"RetryInterval": {
|
||||
"type": "unsignedInt",
|
||||
|
|
@ -94270,22 +94155,7 @@
|
|||
"usp"
|
||||
],
|
||||
"datatype": "unsignedInt",
|
||||
"unit": "seconds",
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "retry_interval"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"unit": "seconds"
|
||||
},
|
||||
"MaxRetries": {
|
||||
"type": "unsignedInt",
|
||||
|
|
@ -94296,22 +94166,7 @@
|
|||
"cwmp",
|
||||
"usp"
|
||||
],
|
||||
"datatype": "unsignedInt",
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "ddns",
|
||||
"section": {
|
||||
"type": "service",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "retry_count"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"datatype": "unsignedInt"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2019 iopsys Software Solutions AB
|
||||
* Copyright (C) 2022 iopsys Software Solutions AB
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License version 2.1
|
||||
|
|
@ -11,23 +11,213 @@
|
|||
#include "dmentry.h"
|
||||
#include "dynamicdns.h"
|
||||
|
||||
#define DDNS_PROVIDERS_FILE "/etc/ddns/services"
|
||||
#define DDNS_SERVICES_DEFAULT "/usr/share/ddns/default"
|
||||
#define DDNS_SERVICES_CUSTOM "/usr/share/ddns/custom"
|
||||
#define DDNS_SERVICES_BACKUP "/usr/share/ddns/backup"
|
||||
|
||||
/**************************************************************************
|
||||
* LINKER
|
||||
***************************************************************************/
|
||||
static int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
|
||||
{
|
||||
char *service_name;
|
||||
if (data) {
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
dmasprintf(linker, "%s", service_name);
|
||||
} else {
|
||||
*linker = "";
|
||||
}
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", linker);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* COMMON FUNCTIONS
|
||||
**************************************************************/
|
||||
static bool service_exists(char *file_name)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
|
||||
uci_path_foreach_option_eq(bbfdm, "dmmap_ddns", "server", "file_name", file_name, s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void update_supported_services(void)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
char *service_name = NULL;
|
||||
char supported_services[1024] = {0};
|
||||
unsigned pos = 0;
|
||||
|
||||
supported_services[0] = 0;
|
||||
|
||||
uci_path_foreach_sections(bbfdm, "dmmap_ddns", "server", s) {
|
||||
dmuci_get_value_by_section_string(s, "service_name", &service_name);
|
||||
|
||||
pos += snprintf(&supported_services[pos], sizeof(supported_services) - pos, "%s,", service_name);
|
||||
}
|
||||
|
||||
if (pos)
|
||||
supported_services[pos - 1] = 0;
|
||||
|
||||
dmuci_set_value_bbfdm("dmmap_ddns", "global", "supported_services", supported_services);
|
||||
}
|
||||
|
||||
static void update_dmmap_ddns_global_settings(long int filecount)
|
||||
{
|
||||
char last_update[16] = {0};
|
||||
char file_count[16] = {0};
|
||||
|
||||
time_t t_time = time(NULL);
|
||||
|
||||
snprintf(last_update, sizeof(last_update), "%ld", t_time);
|
||||
snprintf(file_count, sizeof(file_count), "%ld", filecount);
|
||||
|
||||
dmuci_set_value_bbfdm("dmmap_ddns", "global", "last_update", last_update);
|
||||
dmuci_set_value_bbfdm("dmmap_ddns", "global", "file_count", file_count);
|
||||
update_supported_services();
|
||||
}
|
||||
|
||||
static void check_deleted_files(long int nbr_deleted_file)
|
||||
{
|
||||
struct uci_section *s = NULL, *stmp = NULL;
|
||||
char *file_name = NULL;
|
||||
char buf[512] = {0};
|
||||
int deleted_file_count = 0;
|
||||
|
||||
uci_path_foreach_sections_safe(bbfdm, "dmmap_ddns", "server", stmp, s) {
|
||||
dmuci_get_value_by_section_string(s, "file_name", &file_name);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", DDNS_SERVICES_DEFAULT, file_name);
|
||||
if (file_exists(buf))
|
||||
continue;
|
||||
|
||||
if (folder_exists(DDNS_SERVICES_CUSTOM)) {
|
||||
snprintf(buf, sizeof(buf), "%s/%s", DDNS_SERVICES_CUSTOM, file_name);
|
||||
if (file_exists(buf))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (folder_exists(DDNS_SERVICES_BACKUP)) {
|
||||
snprintf(buf, sizeof(buf), "%s/%s", DDNS_SERVICES_BACKUP, file_name);
|
||||
if (file_exists(buf))
|
||||
continue;
|
||||
}
|
||||
|
||||
deleted_file_count++;
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
|
||||
if (nbr_deleted_file == deleted_file_count)
|
||||
break;
|
||||
}
|
||||
|
||||
update_supported_services();
|
||||
}
|
||||
|
||||
static void fill_dmmap_ddns_services(const char *ddns_path, const char *last_update,
|
||||
long int *last_file_count, long int *file_count,
|
||||
bool is_enabled, bool is_custom)
|
||||
{
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
DIR *dirp = NULL;
|
||||
struct dirent *entry = NULL;
|
||||
struct stat stats = {0};
|
||||
char buf[512] = {0};
|
||||
|
||||
if (!folder_exists(ddns_path))
|
||||
return;
|
||||
|
||||
dirp = opendir(ddns_path);
|
||||
if (!dirp)
|
||||
return;
|
||||
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
|
||||
if (!strstr(entry->d_name, ".json"))
|
||||
continue;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", ddns_path, entry->d_name);
|
||||
|
||||
if (stat(buf, &stats))
|
||||
continue;
|
||||
|
||||
(*file_count)++;
|
||||
|
||||
if (strcmp(ddns_path, DDNS_SERVICES_BACKUP) == 0)
|
||||
continue;
|
||||
|
||||
if (DM_STRLEN(last_update)) {
|
||||
|
||||
if (DM_STRTOL(last_update) >= stats.st_ctime)
|
||||
continue;
|
||||
|
||||
if (service_exists(entry->d_name))
|
||||
continue;
|
||||
|
||||
(*last_file_count)++;
|
||||
update_dmmap_ddns_global_settings(*last_file_count);
|
||||
}
|
||||
|
||||
json_object *json = json_object_from_file(buf);
|
||||
if (!json)
|
||||
continue;
|
||||
|
||||
char *service_name = dmjson_get_value(json, 1, "name");
|
||||
char *ipv4_url = dmjson_get_value(json, 2, "ipv4", "url");
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "server", &dmmap_s);
|
||||
dmuci_set_value_by_section(dmmap_s, "enabled", is_enabled ? "1" : "0");
|
||||
dmuci_set_value_by_section(dmmap_s, "service_name", service_name);
|
||||
dmuci_set_value_by_section(dmmap_s, "file_name", entry->d_name);
|
||||
dmuci_set_value_by_section(dmmap_s, "server_name", service_name);
|
||||
dmuci_set_value_by_section(dmmap_s, "server_address", ipv4_url);
|
||||
dmuci_set_value_by_section(dmmap_s, "is_https", !strncmp(ipv4_url, "https", 5) ? "1" : "0");
|
||||
dmuci_set_value_by_section(dmmap_s, "is_custom", is_custom ? "1" : "0");
|
||||
|
||||
json_object_put(json);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
static void dmmap_synchronizeDynamicDNSServer(void)
|
||||
{
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
char *last_update = NULL;
|
||||
char *filecount = NULL;
|
||||
long int file_count = 0;
|
||||
|
||||
dmuci_get_option_value_string_bbfdm("dmmap_ddns", "global", "last_update", &last_update);
|
||||
dmuci_get_option_value_string_bbfdm("dmmap_ddns", "global", "file_count", &filecount);
|
||||
|
||||
if (!DM_STRLEN(last_update)) {
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "ddns", &dmmap_s);
|
||||
dmuci_rename_section_by_section(dmmap_s, "global");
|
||||
}
|
||||
|
||||
long int last_file_count = DM_STRTOL(filecount);
|
||||
|
||||
fill_dmmap_ddns_services(DDNS_SERVICES_DEFAULT, last_update, &last_file_count, &file_count, true, false);
|
||||
fill_dmmap_ddns_services(DDNS_SERVICES_CUSTOM, last_update, &last_file_count, &file_count, true, true);
|
||||
fill_dmmap_ddns_services(DDNS_SERVICES_BACKUP, last_update, &last_file_count, &file_count, false, false);
|
||||
|
||||
if (DM_STRLEN(filecount)) {
|
||||
|
||||
long int nbr_deleted_file = last_file_count - file_count;
|
||||
if (nbr_deleted_file == 0)
|
||||
return;
|
||||
|
||||
check_deleted_files(nbr_deleted_file);
|
||||
}
|
||||
|
||||
update_dmmap_ddns_global_settings(file_count);
|
||||
}
|
||||
|
||||
static char *get_server_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance)
|
||||
{
|
||||
char *server_perm = NULL;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "is_custom", &server_perm);
|
||||
return server_perm;
|
||||
}
|
||||
|
||||
struct dm_permession_s DMServer = {"1", &get_server_perm};
|
||||
/*************************************************************
|
||||
* ENTRY METHOD
|
||||
*************************************************************/
|
||||
|
|
@ -41,7 +231,7 @@ static int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node,
|
|||
synchronize_specific_config_sections_with_dmmap("ddns", "service", "dmmap_ddns", &dup_list);
|
||||
list_for_each_entry(p, &dup_list, list) {
|
||||
|
||||
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "clientinstance", "clientalias");
|
||||
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "client_instance", "client_alias");
|
||||
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
|
||||
break;
|
||||
|
|
@ -50,94 +240,15 @@ static int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dmmap_synchronizeDynamicDNSServer(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
struct uci_section *s = NULL, *sddns = NULL, *stmp = NULL, *ss = NULL;
|
||||
char *service_name = NULL, *dmmap_service_name = NULL, *retry_interval = NULL, *retry_unit = NULL;
|
||||
char *enabled = NULL, *dns_server = NULL, *use_https = NULL, *check_interval = NULL, *check_unit = NULL, *retry_count = NULL;
|
||||
int found;
|
||||
|
||||
uci_path_foreach_sections_safe(bbfdm, "dmmap_ddns", "ddns_server", stmp, s) {
|
||||
dmuci_get_value_by_section_string(s, "service_name", &dmmap_service_name);
|
||||
found = 0;
|
||||
uci_foreach_sections("ddns", "service", ss) {
|
||||
dmuci_get_value_by_section_string(ss, "service_name", &service_name);
|
||||
if (DM_STRCMP(service_name, dmmap_service_name) == 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
}
|
||||
|
||||
uci_foreach_sections("ddns", "service", s) {
|
||||
dmuci_get_value_by_section_string(s, "service_name", &service_name);
|
||||
if (service_name == NULL)
|
||||
continue;
|
||||
|
||||
if (*service_name == '\0')
|
||||
continue;
|
||||
dmuci_get_value_by_section_string(s, "enabled", &enabled);
|
||||
dmuci_get_value_by_section_string(s, "dns_server", &dns_server);
|
||||
dmuci_get_value_by_section_string(s, "use_https", &use_https);
|
||||
dmuci_get_value_by_section_string(s, "check_interval", &check_interval);
|
||||
dmuci_get_value_by_section_string(s, "check_unit", &check_unit);
|
||||
dmuci_get_value_by_section_string(s, "retry_interval", &retry_interval);
|
||||
dmuci_get_value_by_section_string(s, "retry_unit", &retry_unit);
|
||||
dmuci_get_value_by_section_string(s, "retry_count", &retry_count);
|
||||
found = 0;
|
||||
uci_path_foreach_sections(bbfdm, "dmmap_ddns", "ddns_server", ss) {
|
||||
dmuci_get_value_by_section_string(ss, "service_name", &dmmap_service_name);
|
||||
if (dmmap_service_name == NULL)
|
||||
continue;
|
||||
|
||||
if (strcmp(service_name, dmmap_service_name) == 0) {
|
||||
found = 1;
|
||||
//Update dmmap with ddns config
|
||||
dmuci_set_value_by_section(ss, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(ss, "enabled", enabled);
|
||||
dmuci_set_value_by_section(ss, "service_name", service_name);
|
||||
dmuci_set_value_by_section(ss, "dns_server", dns_server);
|
||||
dmuci_set_value_by_section(ss, "use_https", use_https);
|
||||
dmuci_set_value_by_section(ss, "check_interval", check_interval);
|
||||
dmuci_set_value_by_section(ss, "check_unit", check_unit);
|
||||
dmuci_set_value_by_section(ss, "retry_interval", retry_interval);
|
||||
dmuci_set_value_by_section(ss, "retry_unit", retry_unit);
|
||||
dmuci_set_value_by_section(ss, "retry_count", retry_count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
continue;
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "ddns_server", &sddns);
|
||||
dmuci_set_value_by_section(sddns, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(sddns, "enabled", enabled);
|
||||
dmuci_set_value_by_section(sddns, "service_name", service_name);
|
||||
dmuci_set_value_by_section(sddns, "dns_server", dns_server);
|
||||
dmuci_set_value_by_section(sddns, "use_https", use_https);
|
||||
dmuci_set_value_by_section(sddns, "check_interval", check_interval);
|
||||
dmuci_set_value_by_section(sddns, "check_unit", check_unit);
|
||||
dmuci_set_value_by_section(sddns, "retry_interval", retry_interval);
|
||||
dmuci_set_value_by_section(sddns, "retry_unit", retry_unit);
|
||||
dmuci_set_value_by_section(sddns, "retry_count", retry_count);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.!UCI:ddns/service/dmmap_ddns*/
|
||||
static int browseDynamicDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
char *inst = NULL;
|
||||
struct uci_section *s = NULL;
|
||||
char *inst = NULL;
|
||||
|
||||
dmmap_synchronizeDynamicDNSServer(dmctx, NULL, NULL, NULL);
|
||||
uci_path_foreach_sections(bbfdm, "dmmap_ddns", "ddns_server", s) {
|
||||
dmmap_synchronizeDynamicDNSServer();
|
||||
uci_path_foreach_sections(bbfdm, "dmmap_ddns", "server", s) {
|
||||
|
||||
inst = handle_instance(dmctx, parent_node, s, "serverinstance", "serveralias");
|
||||
inst = handle_instance(dmctx, parent_node, s, "server_instance", "server_alias");
|
||||
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
|
||||
break;
|
||||
|
|
@ -156,14 +267,14 @@ static int browseDynamicDNSClientHostnameInst(struct dmctx *dmctx, DMNODE *paren
|
|||
*************************************************************/
|
||||
static int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char **instance)
|
||||
{
|
||||
struct uci_section *dmmap = NULL, *s = NULL;
|
||||
char s_name[32];
|
||||
struct uci_section *s = NULL, *dmmap_s = NULL;
|
||||
char s_name[16];
|
||||
|
||||
snprintf(s_name, sizeof(s_name), "Ddns_%s", *instance);
|
||||
snprintf(s_name, sizeof(s_name), "ddns_%s", *instance);
|
||||
|
||||
dmuci_add_section("ddns", "service", &s);
|
||||
dmuci_rename_section_by_section(s, s_name);
|
||||
dmuci_set_value_by_section(s, "enabled", "1");
|
||||
dmuci_set_value_by_section(s, "enabled", "0");
|
||||
dmuci_set_value_by_section(s, "use_syslog", "0");
|
||||
dmuci_set_value_by_section(s, "use_https", "0");
|
||||
dmuci_set_value_by_section(s, "force_interval", "72");
|
||||
|
|
@ -174,9 +285,9 @@ static int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data,
|
|||
dmuci_set_value_by_section(s, "retry_unit", "value");
|
||||
dmuci_set_value_by_section(s, "ip_source", "interface");
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "service", &dmmap);
|
||||
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(dmmap, "clientinstance", *instance);
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "service", &dmmap_s);
|
||||
dmuci_set_value_by_section(dmmap_s, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(dmmap_s, "client_instance", *instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -205,54 +316,70 @@ static int delObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data,
|
|||
|
||||
static int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char **instance)
|
||||
{
|
||||
struct uci_section *dmmap = NULL, *s = NULL;
|
||||
char s_name[16];
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
char custom_service_path[128];
|
||||
char file_name[40];
|
||||
char service_name[32];
|
||||
char *file_count = NULL;
|
||||
|
||||
snprintf(s_name, sizeof(s_name), "server_%s", *instance);
|
||||
snprintf(service_name, sizeof(service_name), "custom_service_%s", *instance);
|
||||
snprintf(file_name, sizeof(file_name), "%s.json", service_name);
|
||||
snprintf(custom_service_path, sizeof(custom_service_path), "%s/%s", DDNS_SERVICES_CUSTOM, file_name);
|
||||
|
||||
dmuci_add_section("ddns", "service", &s);
|
||||
dmuci_rename_section_by_section(s, s_name);
|
||||
dmuci_set_value_by_section(s, "service_name", s_name);
|
||||
dmuci_set_value_by_section(s, "enabled", "1");
|
||||
dmuci_set_value_by_section(s, "use_syslog", "0");
|
||||
dmuci_set_value_by_section(s, "use_https", "0");
|
||||
dmuci_set_value_by_section(s, "force_interval", "72");
|
||||
dmuci_set_value_by_section(s, "force_unit", "hours");
|
||||
dmuci_set_value_by_section(s, "check_interval", "10");
|
||||
dmuci_set_value_by_section(s, "check_unit", "minutes");
|
||||
dmuci_set_value_by_section(s, "retry_interval", "60");
|
||||
dmuci_set_value_by_section(s, "retry_unit", "value");
|
||||
dmuci_set_value_by_section(s, "ip_source", "interface");
|
||||
if (!folder_exists(DDNS_SERVICES_CUSTOM))
|
||||
mkdir(DDNS_SERVICES_CUSTOM, S_IRWXU);
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "ddns_server", &dmmap);
|
||||
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(dmmap, "serverinstance", *instance);
|
||||
return 0;
|
||||
struct json_object *service_obj = json_object_new_object();
|
||||
struct json_object *ipv4_obj = json_object_new_object();
|
||||
|
||||
json_object_object_add(ipv4_obj, "url", json_object_new_string("http://"));
|
||||
json_object_object_add(service_obj, "name", json_object_new_string(service_name));
|
||||
json_object_object_add(service_obj, "ipv4", ipv4_obj);
|
||||
|
||||
int res = json_object_to_file_ext(custom_service_path, service_obj, JSON_C_TO_STRING_PRETTY);
|
||||
|
||||
json_object_put(service_obj);
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_ddns", "server", &dmmap_s);
|
||||
dmuci_set_value_by_section(dmmap_s, "enabled", "1");
|
||||
dmuci_set_value_by_section(dmmap_s, "service_name", service_name);
|
||||
dmuci_set_value_by_section(dmmap_s, "file_name", file_name);
|
||||
dmuci_set_value_by_section(dmmap_s, "server_name", service_name);
|
||||
dmuci_set_value_by_section(dmmap_s, "server_address", "http://");
|
||||
dmuci_set_value_by_section(dmmap_s, "is_https", "0");
|
||||
dmuci_set_value_by_section(dmmap_s, "is_custom", "1");
|
||||
|
||||
dmuci_get_option_value_string_bbfdm("dmmap_ddns", "global", "file_count", &file_count);
|
||||
long int filecount = DM_STRTOL(file_count) + 1;
|
||||
update_dmmap_ddns_global_settings(filecount);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
|
||||
{
|
||||
struct uci_section *s = NULL, *stmp = NULL;
|
||||
char *service_name;
|
||||
char *is_custom = NULL;
|
||||
char *enabled = NULL;
|
||||
char *file_name = NULL;
|
||||
char file_path[128] = {0};
|
||||
|
||||
switch (del_action) {
|
||||
case DEL_INST:
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq_safe("ddns", "service", "service_name", service_name, stmp, s) {
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
}
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "is_custom", &is_custom);
|
||||
if (*is_custom == '0')
|
||||
break;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enabled);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "file_name", &file_name);
|
||||
snprintf(file_path, sizeof(file_path), "%s/%s", (*enabled == '1') ? DDNS_SERVICES_CUSTOM : DDNS_SERVICES_BACKUP, file_name);
|
||||
|
||||
if (file_exists(file_path))
|
||||
remove(file_path);
|
||||
|
||||
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
|
||||
break;
|
||||
case DEL_ALL:
|
||||
uci_foreach_sections_safe("ddns", "service", stmp, s) {
|
||||
struct uci_section *dmmap_section = NULL;
|
||||
|
||||
get_dmmap_section_of_config_section("dmmap_ddns", "ddns_server", section_name(s), &dmmap_section);
|
||||
dmuci_delete_by_section(dmmap_section, NULL, NULL);
|
||||
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
}
|
||||
break;
|
||||
return FAULT_9005;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -276,32 +403,7 @@ static int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ct
|
|||
|
||||
static int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *pch = NULL, *spch = NULL;
|
||||
|
||||
*value = "";
|
||||
FILE *fp = fopen(DDNS_PROVIDERS_FILE, "r");
|
||||
if ( fp != NULL) {
|
||||
char line[256] = {0};
|
||||
char buf[1028] = {0};
|
||||
char buf_tmp[1024] = {0};
|
||||
|
||||
while (fgets(line, 256, fp) != NULL) {
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
|
||||
pch = strtok_r(line, "\t", &spch);
|
||||
pch = DM_LSTRSTR(pch, "\"") + 1;
|
||||
pch[DM_STRCHR(pch, '\"')-pch] = 0;
|
||||
if (DM_LSTRCMP(buf, "") == 0) {
|
||||
snprintf(buf, sizeof(buf), "%s", pch);
|
||||
} else {
|
||||
DM_STRNCPY(buf_tmp, buf, sizeof(buf_tmp));
|
||||
snprintf(buf, sizeof(buf), "%s,%s", buf_tmp, pch);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
*value = dmstrdup(buf);
|
||||
}
|
||||
dmuci_get_option_value_string_bbfdm("dmmap_ddns", "global", "supported_services", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +472,7 @@ static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *
|
|||
/*#Device.DynamicDNS.Client.{i}.Alias!UCI:dmmap_ddns/service,@i-1/clientalias*/
|
||||
static int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "clientalias", value);
|
||||
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "client_alias", value);
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
|
|
@ -384,7 +486,7 @@ static int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *d
|
|||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "clientalias", value);
|
||||
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "client_alias", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -665,29 +767,54 @@ static int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.Enable!UCI:ddns/service,@i-1/enabled*/
|
||||
static int get_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "0");
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char *service_name;
|
||||
char *enabled = NULL;
|
||||
char *file_name = NULL;
|
||||
char *is_custom = NULL;
|
||||
char old_path[512] = {0};
|
||||
char new_path[512] = {0};
|
||||
bool b;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 64, NULL, NULL))
|
||||
if (dm_validate_boolean(value))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "enabled", value);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_set_value_by_section(s, "enabled", value);
|
||||
string_to_bool(value, &b);
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enabled);
|
||||
if ((*enabled == '1' && b) || (*enabled == '0' && !b))
|
||||
break;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "file_name", &file_name);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "is_custom", &is_custom);
|
||||
|
||||
if (b) {
|
||||
snprintf(old_path, sizeof(old_path), "%s/%s", DDNS_SERVICES_BACKUP, file_name);
|
||||
snprintf(new_path, sizeof(old_path), "%s/%s", (*is_custom == '1') ? DDNS_SERVICES_CUSTOM : DDNS_SERVICES_DEFAULT, file_name);
|
||||
|
||||
if (!folder_exists(DDNS_SERVICES_CUSTOM))
|
||||
mkdir(DDNS_SERVICES_CUSTOM, S_IRWXU);
|
||||
} else {
|
||||
snprintf(old_path, sizeof(old_path), "%s/%s", (*is_custom == '1') ? DDNS_SERVICES_CUSTOM : DDNS_SERVICES_DEFAULT, file_name);
|
||||
snprintf(new_path, sizeof(old_path), "%s/%s", DDNS_SERVICES_BACKUP, file_name);
|
||||
|
||||
if (!folder_exists(DDNS_SERVICES_BACKUP))
|
||||
mkdir(DDNS_SERVICES_BACKUP, S_IRWXU);
|
||||
}
|
||||
|
||||
if (rename(old_path, new_path))
|
||||
return FAULT_9007;
|
||||
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -695,40 +822,19 @@ static int set_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *
|
|||
|
||||
static int get_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", value);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "server_name", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char *service_name;
|
||||
char *curr_sec_name;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 64, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &curr_sec_name);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
|
||||
// Setting section name
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "section_name", value);
|
||||
|
||||
// Update section name of config ddns service section
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_rename_section_by_section(s, value);
|
||||
break;
|
||||
}
|
||||
|
||||
// Update section name of dmmap_ddns service section
|
||||
uci_path_foreach_option_eq(bbfdm, "dmmap_ddns", "service", "section_name", curr_sec_name, s) {
|
||||
dmuci_set_value_by_section(s, "section_name", value);
|
||||
break;
|
||||
}
|
||||
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "server_name", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -736,7 +842,7 @@ static int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *da
|
|||
|
||||
static int get_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "serveralias", value);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "server_alias", value);
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
|
|
@ -750,13 +856,12 @@ static int set_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *d
|
|||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "serveralias", value);
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "server_alias", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.ServiceName!UCI:ddns/service,@i-1/service_name*/
|
||||
static int get_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", value);
|
||||
|
|
@ -765,8 +870,12 @@ static int get_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, v
|
|||
|
||||
static int set_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char *service_name;
|
||||
struct json_object *service_obj = NULL;
|
||||
struct json_object *ipv4_obj = NULL;
|
||||
char *enabled = NULL;
|
||||
char *file_name = NULL;
|
||||
char *server_address = NULL;
|
||||
char file_path[128] = {0};
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
|
|
@ -774,56 +883,43 @@ static int set_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, v
|
|||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_set_value_by_section(s, "service_name", value);
|
||||
}
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enabled);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "file_name", &file_name);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "server_address", &server_address);
|
||||
|
||||
snprintf(file_path, sizeof(file_path), "%s/%s", (*enabled == '1') ? DDNS_SERVICES_CUSTOM : DDNS_SERVICES_BACKUP, file_name);
|
||||
if (file_exists(file_path))
|
||||
remove(file_path);
|
||||
|
||||
service_obj = json_object_new_object();
|
||||
ipv4_obj = json_object_new_object();
|
||||
|
||||
json_object_object_add(ipv4_obj, "url", json_object_new_string(server_address));
|
||||
json_object_object_add(service_obj, "name", json_object_new_string(value));
|
||||
json_object_object_add(service_obj, "ipv4", ipv4_obj);
|
||||
json_object_to_file_ext(file_path, service_obj, JSON_C_TO_STRING_PRETTY);
|
||||
json_object_put(service_obj);
|
||||
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "service_name", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.ServerAddress!UCI:ddns/service,@i-1/dns_server*/
|
||||
static int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *dns_server;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "dns_server", &dns_server);
|
||||
if (*dns_server == '\0') {
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", value);
|
||||
} else {
|
||||
char *addr = DM_STRCHR(dns_server, ':');
|
||||
if (addr)
|
||||
*addr = '\0';
|
||||
*value = dmstrdup(dns_server);
|
||||
}
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "server_address", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void set_server_address(struct uci_section *section, char *value)
|
||||
{
|
||||
char *dns_server = NULL;
|
||||
|
||||
dmuci_get_value_by_section_string(section, "dns_server", &dns_server);
|
||||
if (dns_server && *dns_server == '\0') {
|
||||
dmuci_set_value_by_section(section, "dns_server", value);
|
||||
} else {
|
||||
char new[64] = {0};
|
||||
|
||||
char *addr = dns_server ? DM_STRCHR(dns_server, ':') : NULL;
|
||||
if (addr)
|
||||
snprintf(new, sizeof(new), "%s%s", value, addr);
|
||||
else
|
||||
DM_STRNCPY(new, value, sizeof(new));
|
||||
dmuci_set_value_by_section(section, "dns_server", new);
|
||||
}
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
char *service_name;
|
||||
struct json_object *service_obj = NULL;
|
||||
struct json_object *ipv4_obj = NULL;
|
||||
char *enabled = NULL;
|
||||
char *file_name = NULL;
|
||||
char *service_name = NULL;
|
||||
char file_path[128] = {0};
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
|
|
@ -831,65 +927,24 @@ static int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx,
|
|||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
set_server_address((struct uci_section *)data, value);
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enabled);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "file_name", &file_name);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
set_server_address(s, value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.ServerPort!UCI:ddns/service,@i-1/dns_server*/
|
||||
static int get_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *dns_server;
|
||||
*value = "0";
|
||||
snprintf(file_path, sizeof(file_path), "%s/%s", (*enabled == '1') ? DDNS_SERVICES_CUSTOM : DDNS_SERVICES_BACKUP, file_name);
|
||||
if (file_exists(file_path))
|
||||
remove(file_path);
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "dns_server", &dns_server);
|
||||
if (*dns_server == '\0')
|
||||
return 0;
|
||||
service_obj = json_object_new_object();
|
||||
ipv4_obj = json_object_new_object();
|
||||
|
||||
char *port = DM_STRCHR(dns_server, ':');
|
||||
if (port)
|
||||
*value = dmstrdup(port+1);
|
||||
return 0;
|
||||
}
|
||||
json_object_object_add(ipv4_obj, "url", json_object_new_string(value));
|
||||
json_object_object_add(service_obj, "name", json_object_new_string(service_name));
|
||||
json_object_object_add(service_obj, "ipv4", ipv4_obj);
|
||||
json_object_to_file_ext(file_path, service_obj, JSON_C_TO_STRING_PRETTY);
|
||||
json_object_put(service_obj);
|
||||
|
||||
static void set_server_port(struct uci_section *section, char *value)
|
||||
{
|
||||
char new[64], *dns_server;
|
||||
|
||||
dmuci_get_value_by_section_string(section, "dns_server", &dns_server);
|
||||
if (*dns_server == '\0') {
|
||||
snprintf(new, sizeof(new), ":%s", value);
|
||||
} else {
|
||||
char *addr = DM_STRCHR(dns_server, ':');
|
||||
if (addr) *addr = '\0';
|
||||
snprintf(new, sizeof(new), "%s:%s", dns_server, value);
|
||||
}
|
||||
dmuci_set_value_by_section(section, "dns_server", new);
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
char *service_name;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"0","65535"}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
set_server_port((struct uci_section *)data, value);
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
set_server_port(s, value);
|
||||
}
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "server_address", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -901,136 +956,24 @@ static int get_DynamicDNSServer_SupportedProtocols(char *refparam, struct dmctx
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.Protocol!UCI:ddns/service,@i-1/use_https*/
|
||||
static int get_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "use_https", value);
|
||||
if (*value[0] == '\0' || DM_LSTRCMP(*value, "0") == 0)
|
||||
*value = "HTTP";
|
||||
else
|
||||
*value = "HTTPS";
|
||||
char *is_https = NULL;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "is_https", &is_https);
|
||||
*value = (*is_https == '1') ? "HTTPS" : "HTTP";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char *service_name;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, -1, SupportedProtocols, NULL))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "use_https", (DM_LSTRCMP(value, "HTTPS") == 0) ? "1" : "0");
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_set_value_by_section(s, "use_https", (DM_LSTRCMP(value, "HTTPS") == 0) ? "1" : "0");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.CheckInterval!UCI:ddns/service,@i-1/check_interval*/
|
||||
static int get_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "check_interval", "600");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char buf[16] = "", *check_unit, *service_name;
|
||||
int check_interval = 0;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{NULL,NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "check_unit", &check_unit);
|
||||
if (DM_LSTRCMP(check_unit, "hours") == 0)
|
||||
check_interval = DM_STRTOL(value) * 3600;
|
||||
else if (DM_LSTRCMP(check_unit, "minutes") == 0)
|
||||
check_interval = DM_STRTOL(value) * 60;
|
||||
else
|
||||
check_interval = DM_STRTOL(value);
|
||||
snprintf(buf, sizeof(buf), "%d", check_interval);
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "check_interval", buf);
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_set_value_by_section(s, "check_interval", buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.RetryInterval!UCI:ddns/service,@i-1/retry_interval*/
|
||||
static int get_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "retry_interval", "259200");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char buf[16] = "", *retry_unit, *service_name;
|
||||
int retry_interval = 0;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{NULL,NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "retry_unit", &retry_unit);
|
||||
if (DM_LSTRCMP(retry_unit, "hours") == 0)
|
||||
retry_interval = DM_STRTOL(value) * 3600;
|
||||
else if (DM_LSTRCMP(retry_unit, "minutes") == 0)
|
||||
retry_interval = DM_STRTOL(value) * 60;
|
||||
else
|
||||
retry_interval = DM_STRTOL(value);
|
||||
snprintf(buf, sizeof(buf), "%d", retry_interval);
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "retry_interval", buf);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_set_value_by_section(s, "retry_interval", buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DynamicDNS.Server.{i}.MaxRetries!UCI:ddns/service,@i-1/retry_count*/
|
||||
static int get_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "retry_count", "5");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s;
|
||||
char *service_name;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{NULL,NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "retry_count", value);
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
|
||||
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {
|
||||
dmuci_set_value_by_section(s, "retry_count", value);
|
||||
}
|
||||
//TODO
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -1092,13 +1035,13 @@ DMLEAF tDynamicDNSServerParams[] = {
|
|||
{"Enable", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Enable, set_DynamicDNSServer_Enable, BBFDM_BOTH, "2.10"},
|
||||
{"Name", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Name, set_DynamicDNSServer_Name, BBFDM_BOTH, "2.10"},
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Alias, set_DynamicDNSServer_Alias, BBFDM_BOTH, "2.10"},
|
||||
{"ServiceName", &DMWRITE, DMT_STRING, get_DynamicDNSServer_ServiceName, set_DynamicDNSServer_ServiceName, BBFDM_BOTH, "2.10"},
|
||||
{"ServerAddress", &DMWRITE, DMT_STRING, get_DynamicDNSServer_ServerAddress, set_DynamicDNSServer_ServerAddress, BBFDM_BOTH, "2.10"},
|
||||
{"ServerPort", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_ServerPort, set_DynamicDNSServer_ServerPort, BBFDM_BOTH, "2.10"},
|
||||
{"ServiceName", &DMServer, DMT_STRING, get_DynamicDNSServer_ServiceName, set_DynamicDNSServer_ServiceName, BBFDM_BOTH, "2.10"},
|
||||
{"ServerAddress", &DMServer, DMT_STRING, get_DynamicDNSServer_ServerAddress, set_DynamicDNSServer_ServerAddress, BBFDM_BOTH, "2.10"},
|
||||
//{"ServerPort", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_ServerPort, set_DynamicDNSServer_ServerPort, BBFDM_BOTH, "2.10"},
|
||||
{"SupportedProtocols", &DMREAD, DMT_STRING, get_DynamicDNSServer_SupportedProtocols, NULL, BBFDM_BOTH, "2.10"},
|
||||
{"Protocol", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Protocol, set_DynamicDNSServer_Protocol, BBFDM_BOTH, "2.10"},
|
||||
{"CheckInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_CheckInterval, set_DynamicDNSServer_CheckInterval, BBFDM_BOTH, "2.10"},
|
||||
{"RetryInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_RetryInterval, set_DynamicDNSServer_RetryInterval, BBFDM_BOTH, "2.10"},
|
||||
{"MaxRetries", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_MaxRetries, set_DynamicDNSServer_MaxRetries, BBFDM_BOTH, "2.10"},
|
||||
{"Protocol", &DMServer, DMT_STRING, get_DynamicDNSServer_Protocol, set_DynamicDNSServer_Protocol, BBFDM_BOTH, "2.10"},
|
||||
//{"CheckInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_CheckInterval, set_DynamicDNSServer_CheckInterval, BBFDM_BOTH, "2.10"},
|
||||
//{"RetryInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_RetryInterval, set_DynamicDNSServer_RetryInterval, BBFDM_BOTH, "2.10"},
|
||||
//{"MaxRetries", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_MaxRetries, set_DynamicDNSServer_MaxRetries, BBFDM_BOTH, "2.10"},
|
||||
{0}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,16 +9,24 @@ config ddns "global"
|
|||
option upd_privateip "0"
|
||||
option use_curl "1"
|
||||
|
||||
|
||||
config service "myddns_ipv4"
|
||||
option service_name "dyndns.org"
|
||||
option lookup_host "yourhost.example.com"
|
||||
option domain "yourhost.example.com"
|
||||
option username "your_username"
|
||||
option password "your_password"
|
||||
option interface "wan"
|
||||
option ip_source "network"
|
||||
option ip_network "wan"
|
||||
config service 'myddns_ipv4'
|
||||
option enabled '1'
|
||||
option use_ipv6 '0'
|
||||
option service_name 'no-ip.com'
|
||||
option lookup_host 'iopsys_test.ddns.net'
|
||||
option domain 'iopsys_test.ddns.net'
|
||||
option username 'iopsys'
|
||||
option password 'iopsys'
|
||||
option ip_source 'web'
|
||||
option interface 'wan'
|
||||
option use_syslog '2'
|
||||
option check_interval '15'
|
||||
option check_unit 'minutes'
|
||||
option force_interval '64'
|
||||
option force_unit 'minutes'
|
||||
option retry_count '5'
|
||||
option retry_interval '60'
|
||||
option retry_unit 'seconds'
|
||||
|
||||
config service "myddns_ipv6"
|
||||
option update_url "http://[USERNAME]:[PASSWORD]@your.provider.net/nic/update?hostname=[DOMAIN]&myip=[IP]"
|
||||
|
|
|
|||
97
test/files/var/log/ddns/myddns_ipv4.log
Normal file
97
test/files/var/log/ddns/myddns_ipv4.log
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
152742 : ************ ************** ************** **************
|
||||
152742 note : PID '8493' started at 2022-04-12 15:27
|
||||
152743 : ddns version : 2.8.2-12
|
||||
152743 : uci configuration:
|
||||
ddns.myddns_ipv4.domain='yourhost.example.com'
|
||||
ddns.myddns_ipv4.interface='wan'
|
||||
ddns.myddns_ipv4.ip_network='wan'
|
||||
ddns.myddns_ipv4.ip_source='network'
|
||||
ddns.myddns_ipv4.lookup_host='yourhost.example.com'
|
||||
ddns.myddns_ipv4.password='***PW***'
|
||||
ddns.myddns_ipv4.service_name='dyndns.org'
|
||||
ddns.myddns_ipv4.username='your_username'
|
||||
ddns.myddns_ipv4=service
|
||||
152743 : verbose mode : 0 - run normal, NO console output
|
||||
152743 WARN : Service section disabled! - TERMINATE
|
||||
152743 WARN : PID '8493' exit WITH ERROR '1' at 2022-04-12 15:27
|
||||
152747 : ************ ************** ************** **************
|
||||
152747 note : PID '10386' started at 2022-04-12 15:27
|
||||
152747 : ddns version : 2.8.2-12
|
||||
152747 : uci configuration:
|
||||
ddns.myddns_ipv4.domain='yourhost.example.com'
|
||||
ddns.myddns_ipv4.interface='wan'
|
||||
ddns.myddns_ipv4.ip_network='wan'
|
||||
ddns.myddns_ipv4.ip_source='network'
|
||||
ddns.myddns_ipv4.lookup_host='yourhost.example.com'
|
||||
ddns.myddns_ipv4.password='***PW***'
|
||||
ddns.myddns_ipv4.service_name='dyndns.org'
|
||||
ddns.myddns_ipv4.username='your_username'
|
||||
ddns.myddns_ipv4=service
|
||||
152747 : verbose mode : 0 - run normal, NO console output
|
||||
152747 WARN : Service section disabled! - TERMINATE
|
||||
152747 WARN : PID '10386' exit WITH ERROR '1' at 2022-04-12 15:27
|
||||
150905 : ************ ************** ************** **************
|
||||
150905 note : PID '13900' started at 2022-04-13 15:09
|
||||
150905 : ddns version : 2.8.2-12
|
||||
150905 : uci configuration:
|
||||
ddns.myddns_ipv4.domain='yourhost.example.com'
|
||||
ddns.myddns_ipv4.interface='wan'
|
||||
ddns.myddns_ipv4.ip_network='wan'
|
||||
ddns.myddns_ipv4.ip_source='network'
|
||||
ddns.myddns_ipv4.lookup_host='yourhost.example.com'
|
||||
ddns.myddns_ipv4.password='***PW***'
|
||||
ddns.myddns_ipv4.service_name='dyndns.org'
|
||||
ddns.myddns_ipv4.username='your_username'
|
||||
ddns.myddns_ipv4=service
|
||||
150905 : verbose mode : 0 - run normal, NO console output
|
||||
150905 WARN : Service section disabled! - TERMINATE
|
||||
150905 WARN : PID '13900' exit WITH ERROR '1' at 2022-04-13 15:09
|
||||
153634 : ************ ************** ************** **************
|
||||
153634 note : PID '26238' started at 2022-04-13 15:36
|
||||
153634 : ddns version : 2.8.2-12
|
||||
153634 : uci configuration:
|
||||
ddns.myddns_ipv4.check_interval='15'
|
||||
ddns.myddns_ipv4.check_unit='minutes'
|
||||
ddns.myddns_ipv4.domain='iopsys_test.ddns.net'
|
||||
ddns.myddns_ipv4.enabled='1'
|
||||
ddns.myddns_ipv4.force_interval='64'
|
||||
ddns.myddns_ipv4.force_unit='minutes'
|
||||
ddns.myddns_ipv4.interface='wan'
|
||||
ddns.myddns_ipv4.ip_source='web'
|
||||
ddns.myddns_ipv4.lookup_host='iopsys_test.ddns.net'
|
||||
ddns.myddns_ipv4.password='***PW***'
|
||||
ddns.myddns_ipv4.retry_count='5'
|
||||
ddns.myddns_ipv4.retry_interval='60'
|
||||
ddns.myddns_ipv4.retry_unit='seconds'
|
||||
ddns.myddns_ipv4.service_name='no-ip.com'
|
||||
ddns.myddns_ipv4.use_ipv6='0'
|
||||
ddns.myddns_ipv4.use_syslog='2'
|
||||
ddns.myddns_ipv4.username='iopsys'
|
||||
ddns.myddns_ipv4=service
|
||||
153634 : verbose mode : 0 - run normal, NO console output
|
||||
153634 : check interval: 900 seconds
|
||||
153635 : force interval: 3840 seconds
|
||||
153635 : retry interval: 60 seconds
|
||||
153635 : retry counter : 5 times
|
||||
153635 : No old process
|
||||
153635 : last update: never
|
||||
153635 : Detect registered/public IP
|
||||
153635 : #> /usr/bin/nslookup iopsys_test.ddns.net >/var/run/ddns/myddns_ipv4.dat 2>/var/run/ddns/myddns_ipv4.err
|
||||
153635 : Registered IP '9.9.9.9' detected
|
||||
153635 info : Starting main loop at 2022-04-13 15:36
|
||||
153635 : Detect local IP on 'web'
|
||||
153635 : #> /usr/bin/curl -RsS -o /var/run/ddns/myddns_ipv4.dat --stderr /var/run/ddns/myddns_ipv4.err --noproxy '*' 'http://checkip.dyndns.com'
|
||||
153635 : Local IP '41.228.252.24' detected on web at 'http://checkip.dyndns.com'
|
||||
153635 : Update needed - L: '41.228.252.24' <> R: '9.9.9.9'
|
||||
153635 : parsing script '/usr/lib/ddns/update_no-ip_com.sh'
|
||||
153636 : sending dummy IP to 'no-ip.com'
|
||||
153636 : #> /usr/bin/curl -RsS -o /var/run/ddns/myddns_ipv4.dat --stderr /var/run/ddns/myddns_ipv4.err --noproxy '*' 'http://iopsys:***PW***@dynupdate.noip.com/nic/update?hostname=iopsys_test.ddns.net&myip=127.0.0.1'
|
||||
153636 : 'no-ip.com' answered:
|
||||
good 127.0.0.1
|
||||
153637 : sending real IP to 'no-ip.com'
|
||||
153637 : #> /usr/bin/curl -RsS -o /var/run/ddns/myddns_ipv4.dat --stderr /var/run/ddns/myddns_ipv4.err --noproxy '*' 'http://iopsys:***PW***@dynupdate.noip.com/nic/update?hostname=iopsys_test.ddns.net&myip=41.228.252.24'
|
||||
153638 : 'no-ip.com' answered:
|
||||
good 41.228.252.24
|
||||
153638 info : Update successful - IP '41.228.252.24' send
|
||||
153638 info : Forced update successful - IP: '41.228.252.24' send
|
||||
153638 : Waiting 900 seconds (Check Interval)
|
||||
Loading…
Add table
Reference in a new issue