mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-02 15:35:13 +01:00
Ticket refs #319: TR-181: Device.DNS object
This commit is contained in:
parent
fc822f940c
commit
d68bc46907
17 changed files with 1541 additions and 18 deletions
|
|
@ -59,7 +59,8 @@ libdatamodel_la_SOURCES += \
|
|||
../dm/dmtree/tr181/nat.c \
|
||||
../dm/dmtree/tr181/routing.c \
|
||||
../dm/dmtree/tr181/userinterface.c \
|
||||
../dm/dmtree/tr181/firewall.c
|
||||
../dm/dmtree/tr181/firewall.c \
|
||||
../dm/dmtree/tr181/dns.c
|
||||
|
||||
if UPNP_TR064
|
||||
libdatamodel_la_SOURCES += \
|
||||
|
|
|
|||
6
cwmp.c
6
cwmp.c
|
|
@ -557,6 +557,12 @@ int run_session_end_func (struct session *session)
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (end_session_flag & END_SESSION_NSLOOKUP_DIAGNOSTIC)
|
||||
{
|
||||
CWMP_LOG (INFO,"Executing nslookupdiagnostic: end session request");
|
||||
cwmp_nslookup_diagnostic();
|
||||
}
|
||||
|
||||
dm_entry_restart_services();
|
||||
|
||||
end_session_flag = 0;
|
||||
|
|
|
|||
|
|
@ -722,3 +722,8 @@ int cwmp_start_diagnostic(int diagnostic_type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_nslookup_diagnostic()
|
||||
{
|
||||
dmcmd_no_wait("/bin/sh", 2, NSLOOKUP_PATH, "run");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -318,8 +318,8 @@ struct uci_section *create_firewall_zone_config(char *fwl, char *iface, char *in
|
|||
{
|
||||
struct uci_section *s;
|
||||
char *value, *name;
|
||||
|
||||
dmuci_add_section("firewall", "zone", &s, &value);
|
||||
|
||||
dmuci_add_section_and_rename("firewall", "zone", &s, &value);
|
||||
dmasprintf(&name, "%s_%s", fwl, iface);
|
||||
dmuci_set_value_by_section(s, "name", name);
|
||||
dmuci_set_value_by_section(s, "input", input);
|
||||
|
|
@ -415,12 +415,13 @@ int dmcmd_no_wait(char *cmd, int n, ...)
|
|||
int i, pid;
|
||||
static int dmcmd_pfds[2];
|
||||
char *argv[n+2];
|
||||
|
||||
static char sargv[4][128];
|
||||
argv[0] = cmd;
|
||||
va_start(arg,n);
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
argv[i+1] = strdup(va_arg(arg, char*));
|
||||
strcpy(sargv[i], va_arg(arg, char*));
|
||||
argv[i+1] = sargv[i];
|
||||
}
|
||||
va_end(arg);
|
||||
|
||||
|
|
@ -650,7 +651,7 @@ void update_section_option_list(char *config, char *section, char *option, char
|
|||
dmuci_delete_by_section(prev_s, NULL, NULL);
|
||||
}
|
||||
if (add_sec) {
|
||||
dmuci_add_section(config, section, &s, &add_value);
|
||||
dmuci_add_section_and_rename(config, section, &s, &add_value);
|
||||
dmuci_set_value_by_section(s, option, val);
|
||||
dmuci_set_value_by_section(s, option_2, val_2);
|
||||
}
|
||||
|
|
@ -717,7 +718,7 @@ void update_section_list(char *config, char *section, char *option, int number,
|
|||
}
|
||||
}
|
||||
while (i < number) {
|
||||
dmuci_add_section(config, section, &s, &add_value);
|
||||
dmuci_add_section_and_rename(config, section, &s, &add_value);
|
||||
if (option)dmuci_set_value_by_section(s, option, filter);
|
||||
if (option1)dmuci_set_value_by_section(s, option1, val1);
|
||||
if (option2)dmuci_set_value_by_section(s, option2, val2);
|
||||
|
|
@ -1058,7 +1059,7 @@ void synchronize_specific_config_sections_with_dmmap(char *package, char *sectio
|
|||
uci_path_foreach_sections_safe(icwmpd, dmmap_package, section_type, stmp, s) {
|
||||
dmuci_get_value_by_section_string(s, "section_name", &v);
|
||||
if(get_origin_section_from_config(package, section_type, v) == NULL){
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
dmuci_delete_by_section_unnamed_icwmpd(s, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ do { \
|
|||
#define UPLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/upload_launch"
|
||||
#define UPLOAD_DUMP_FILE "/tmp/upload_dump"
|
||||
#define UPLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, UPLOAD_DIAGNOSTIC_PATH, "stop");
|
||||
#define NSLOOKUP_STOP DMCMD("/bin/sh", 2, NSLOOKUP_PATH, "stop");
|
||||
#define NSLOOKUP_PATH "/usr/share/icwmp/functions/nslookup_launch"
|
||||
#define NSLOOKUP_LOG_FILE "/tmp/nslookup.log"
|
||||
|
||||
enum notification_enum {
|
||||
notification_none,
|
||||
|
|
@ -118,6 +121,7 @@ struct dmmap_sect {
|
|||
char *section_name;
|
||||
char *instance;
|
||||
};
|
||||
|
||||
struct dm_args
|
||||
{
|
||||
struct uci_section *section;
|
||||
|
|
|
|||
|
|
@ -374,7 +374,8 @@ enum end_session_enum {
|
|||
END_SESSION_IPPING_DIAGNOSTIC = 1<<4,
|
||||
END_SESSION_DOWNLOAD_DIAGNOSTIC = 1<<5,
|
||||
END_SESSION_UPLOAD_DIAGNOSTIC = 1<<6,
|
||||
END_SESSION_X_FACTORY_RESET_SOFT = 1<<7
|
||||
END_SESSION_X_FACTORY_RESET_SOFT = 1<<7,
|
||||
END_SESSION_NSLOOKUP_DIAGNOSTIC = 1<<8
|
||||
};
|
||||
|
||||
enum dm_browse_enum {
|
||||
|
|
|
|||
|
|
@ -227,7 +227,6 @@ char *__dmjson_get_value_in_array_idx(json_object *mainjobj, json_object **arrob
|
|||
return (v ? v : defret) ;
|
||||
}
|
||||
|
||||
|
||||
char *____dmjson_get_value_array_all(json_object *mainjobj, char *delim, char *argv[])
|
||||
{
|
||||
json_object *arrobj;
|
||||
|
|
|
|||
|
|
@ -42,4 +42,9 @@ char *__dmjson_get_value_array_all(json_object *mainjobj, char *delim, int argc,
|
|||
#define dmjson_get_value_array_all(MAINJOBJ,DELIM,ARGC,args...) \
|
||||
__dmjson_get_value_array_all(MAINJOBJ, DELIM, ARGC, ##args);
|
||||
|
||||
#define dmjson_foreach_value_in_array(MAINJOBJ,ARROBJ,VAL,INDEX,ARGC,args...) \
|
||||
for (INDEX = 0, ARROBJ = NULL, VAL = __dmjson_get_value_in_array_idx(MAINJOBJ, &(ARROBJ), NULL, INDEX, ARGC, ##args);\
|
||||
VAL; \
|
||||
VAL = __dmjson_get_value_in_array_idx(MAINJOBJ, &(ARROBJ), NULL, ++INDEX, 0))
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
#include "uploaddiagnostic.h"
|
||||
#include "deviceconfig.h"
|
||||
#include "firewall.h"
|
||||
#include "dns.h"
|
||||
|
||||
/* *** CWMP *** */
|
||||
DMOBJ tEntry098Obj[] = {
|
||||
|
|
@ -134,6 +135,7 @@ DMOBJ tRoot_181_Obj[] = {
|
|||
{"Routing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tRoutingObj, tRoutingParam, NULL},
|
||||
{"UserInterface", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUserInterfaceObj, NULL, NULL},
|
||||
{"Firewall", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tFirewallObj, tFirewallParams, NULL},
|
||||
{"DNS", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDNSObj, tDNSParams, NULL},
|
||||
#ifdef XMPP_ENABLE
|
||||
{"XMPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL,tXMPPObj, tXMPPParams, NULL},
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ DMLEAF tTimeParams[] = {
|
|||
int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *path = "/etc/rc.d/*ntpd";
|
||||
|
||||
|
||||
if (check_file(path))
|
||||
*value = "1";
|
||||
else
|
||||
|
|
|
|||
|
|
@ -102,7 +102,6 @@ int set_ipping_interface(char *refparam, struct dmctx *ctx, void *data, char *in
|
|||
|
||||
int get_ipping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
|
||||
dmuci_get_varstate_string("cwmp", "@ippingdiagnostic[0]", "Host", value);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -238,14 +237,12 @@ int set_ipping_dscp(char *refparam, struct dmctx *ctx, void *data, char *instanc
|
|||
int get_ipping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ipping_get("SuccessCount", "0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_ipping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ipping_get("FailureCount", "0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
1304
dm/dmtree/tr181/dns.c
Normal file
1304
dm/dmtree/tr181/dns.c
Normal file
File diff suppressed because it is too large
Load diff
128
dm/dmtree/tr181/dns.h
Normal file
128
dm/dmtree/tr181/dns.h
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Copyright (C) 2019 iopsys Software Solutions AB
|
||||
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#ifndef _DNS_H
|
||||
#define _DNS_H
|
||||
|
||||
#include "dmcwmp.h"
|
||||
|
||||
|
||||
extern DMOBJ tDNSObj[];
|
||||
extern DMLEAF tDNSParams[];
|
||||
extern DMLEAF tClientParams[];
|
||||
extern DMOBJ tClientObj[];
|
||||
extern DMLEAF tServerParams[];
|
||||
extern DMLEAF tRelayParams[];
|
||||
extern DMOBJ tRelayObj[];
|
||||
extern DMLEAF tForwardingParams[];
|
||||
extern DMOBJ tDiagnosticsObj[];
|
||||
extern DMLEAF tNSLookupDiagnosticsParams[];
|
||||
extern DMOBJ tNSLookupDiagnosticsObj[];
|
||||
extern DMLEAF tResultParams[];
|
||||
extern DMLEAF tSDParams[];
|
||||
extern DMOBJ tSDObj[];
|
||||
extern DMLEAF tServiceParams[];
|
||||
extern DMOBJ tSDServiceObj[];
|
||||
extern DMLEAF tTextRecordParams[];
|
||||
|
||||
struct NSLookupResult
|
||||
{
|
||||
char *Status;
|
||||
char *AnswerType;
|
||||
char *HostNameReturned;
|
||||
char *IPAddresses;
|
||||
char *DNSServerIP;
|
||||
char *ResponseTime;
|
||||
};
|
||||
|
||||
int browseServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
int browseRelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
int browseServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
int browseTextRecordInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
|
||||
int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **instance);
|
||||
int add_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance);
|
||||
|
||||
int delete_client_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);
|
||||
int delete_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);
|
||||
|
||||
int get_dns_supported_record_types(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_client_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_client_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_server_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_server_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_relay_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_relay_forward_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_forwarding_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_nslookupdiagnostics_result_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_result_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_result_answer_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_result_host_name_returned(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_result_i_p_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_result_d_n_s_server_i_p(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_result_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_sd_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_sd_service_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_sd_advertised_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_instance_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_application_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_transport_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_last_update(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_time_to_live(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_service_text_record_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_textrecord_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int get_textrecord_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
|
||||
int set_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_sd_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int set_sd_advertised_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
|
||||
#endif
|
||||
|
|
@ -312,14 +312,12 @@ int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *
|
|||
int get_ip_ping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ipping_get("SuccessCount", "0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_ip_ping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ipping_get("FailureCount", "0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -332,14 +330,12 @@ int get_ip_ping_average_response_time(char *refparam, struct dmctx *ctx, void *d
|
|||
int get_ip_ping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ipping_get("MinimumResponseTime", "0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ipping_get("MaximumResponseTime", "0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -676,6 +676,7 @@ int dmuci_delete_by_section(struct uci_section *s, char *option, char *value)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dmuci_delete_by_section_unnamed(struct uci_section *s, char *option, char *value)
|
||||
{
|
||||
struct uci_ptr up = {0};
|
||||
|
|
|
|||
|
|
@ -67,5 +67,6 @@ enum diagnostic_type {
|
|||
|
||||
int cwmp_ip_ping_diagnostic();
|
||||
int cwmp_start_diagnostic(int diagnostic_type);
|
||||
int cwmp_nslookup_diagnostic();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
72
scripts/functions/nslookup_launch
Normal file
72
scripts/functions/nslookup_launch
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2019 PIVA Software <www.pivasoftware.com>
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
|
||||
UCI_CONFIG_DIR="/etc/config/"
|
||||
UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get "
|
||||
UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set "
|
||||
LOG_FILE="/tmp/nslookup.log"
|
||||
|
||||
nslookup_get() {
|
||||
local val=`$UCI_GET_VARSTATE $1`
|
||||
echo ${val:-$2}
|
||||
}
|
||||
|
||||
nslookup_set() {
|
||||
$UCI_SET_VARSTATE $1=$2
|
||||
return 0
|
||||
}
|
||||
|
||||
nslookup_launch() {
|
||||
local i time1 time2 timeresponse
|
||||
[ "`$UCI_GET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState`" != "Requested" ] && return
|
||||
local hostname=`nslookup_get cwmp.@nslookupdiagnostic[0].HostName`
|
||||
local dnsserver=`nslookup_get cwmp.@nslookupdiagnostic[0].DNSServer`
|
||||
local cnt=`nslookup_get cwmp.@nslookupdiagnostic[0].NumberOfRepetitions 1`
|
||||
[ "$hostname" = "" ] && return
|
||||
i=0
|
||||
[ -e "${LOG_FILE}" ] && rm ${LOG_FILE}
|
||||
while [ $i -lt $cnt ]; do
|
||||
let i++
|
||||
time1=`date +%s`
|
||||
if [ -z "$dnsserver" ]; then
|
||||
nslookup $hostname >>${LOG_FILE} 2>&1
|
||||
else
|
||||
nslookup $hostname $dnsserver >>${LOG_FILE} 2>&1
|
||||
fi
|
||||
time2=`date +%s`
|
||||
timeresponse=$(($(($time2-$time1))*1000))
|
||||
echo "ResponseTime: $timeresponse" >>${LOG_FILE}
|
||||
echo "***********************" >>${LOG_FILE}
|
||||
done
|
||||
$UCI_SET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState=Complete
|
||||
event_dignostic
|
||||
}
|
||||
|
||||
event_dignostic() {
|
||||
local e=1
|
||||
local i=0
|
||||
while [ "$e" != 0 -a $i -lt 200 ]; do
|
||||
ubus -t 1 call tr069 inform '{"event":"8 DIAGNOSTICS COMPLETE"}' &>/dev/null
|
||||
e=$?
|
||||
[ "$e" != "0" ] && sleep 1;
|
||||
let i++
|
||||
done
|
||||
}
|
||||
|
||||
nslookup_stop_diagnostic() {
|
||||
local pids=`ps | grep nslookup_launch | grep -v grep | awk '{print $1}'`
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 $pids &>/dev/null
|
||||
$UCI_SET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState=None
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" == "run" ]; then
|
||||
nslookup_launch
|
||||
elif [ "$1" == "stop" ]; then
|
||||
nslookup_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
Loading…
Add table
Reference in a new issue