From 1904a2fbd4e27822e73aba3333f1d70f5e103de5 Mon Sep 17 00:00:00 2001 From: Sukru Senli Date: Sat, 13 Mar 2021 11:02:35 +0100 Subject: [PATCH] UserInterface: remove obsoleted implementation --- bin/Makefile.am | 1 - dmtree/tr181/device.c | 2 - dmtree/tr181/userinterface.c | 211 ----------------------------------- dmtree/tr181/userinterface.h | 21 ---- 4 files changed, 235 deletions(-) delete mode 100644 dmtree/tr181/userinterface.c delete mode 100644 dmtree/tr181/userinterface.h diff --git a/bin/Makefile.am b/bin/Makefile.am index cc41ca5e..e859b052 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -64,7 +64,6 @@ libbbfdm_la_SOURCES += \ ../dmtree/tr181/ppp.c \ ../dmtree/tr181/nat.c \ ../dmtree/tr181/routing.c \ - ../dmtree/tr181/userinterface.c \ ../dmtree/tr181/firewall.c \ ../dmtree/tr181/dns.c \ ../dmtree/tr181/users.c \ diff --git a/dmtree/tr181/device.c b/dmtree/tr181/device.c index f7a86109..95c1d732 100644 --- a/dmtree/tr181/device.c +++ b/dmtree/tr181/device.c @@ -32,7 +32,6 @@ #include "nat.h" #include "ppp.h" #include "routing.h" -#include "userinterface.h" #include "firewall.h" #include "dns.h" #include "users.h" @@ -100,7 +99,6 @@ DMOBJ tDeviceObj[] = { {"NAT", &DMREAD, NULL, NULL, "file:/etc/config/firewall", NULL, NULL, tNATObj, tNATParams, NULL, BBFDM_BOTH}, {"PPP", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/ppp.sh", NULL, NULL, tPPPObj, tPPPParams, NULL, BBFDM_BOTH}, {"Routing", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, tRoutingObj, tRoutingParams, NULL, BBFDM_BOTH}, -{"UserInterface", &DMREAD, NULL, NULL, NULL, NULL, NULL, tUserInterfaceObj, NULL, NULL, BBFDM_BOTH}, {"Firewall", &DMREAD, NULL, NULL, "file:/etc/config/firewall", NULL, NULL, tFirewallObj, tFirewallParams, NULL, BBFDM_BOTH}, {"DNS", &DMREAD, NULL, NULL, "file:/etc/config/dhcp", NULL, NULL, tDNSObj, tDNSParams, NULL, BBFDM_BOTH}, {"Users", &DMREAD, NULL, NULL, "file:/etc/config/users", NULL, NULL, tUsersObj, tUsersParams, NULL, BBFDM_BOTH}, diff --git a/dmtree/tr181/userinterface.c b/dmtree/tr181/userinterface.c deleted file mode 100644 index 0aa961a9..00000000 --- a/dmtree/tr181/userinterface.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2019 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 - * as published by the Free Software Foundation - * - * Author: Omar Kallel - * Author: Amin Ben Ramdhane - * - */ - -#include "userinterface.h" - -/************************************************************************** -* GET & SET PARAMETERS -***************************************************************************/ -static void add_default_rule(char *port, char *enable, char *owsd) -{ - struct uci_section *ss; - - dmuci_add_section("firewall", "rule", &ss); - dmuci_set_value_by_section(ss, "name", "juci-remote-access"); - dmuci_set_value_by_section(ss, "src", "wan"); - dmuci_set_value_by_section(ss, "proto", "tcp"); - dmuci_set_value_by_section(ss, "target", "ACCEPT"); - dmuci_set_value_by_section(ss, "dest_port", port); - dmuci_set_value_by_section(ss, "owsd", owsd); - dmuci_set_value_by_section(ss, "enabled", enable); -} - -static int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *ss = NULL; - char *rule_name, *rule_enabled; - - uci_foreach_sections("firewall", "rule", ss) { - dmuci_get_value_by_section_string(ss, "name", &rule_name); - if (strcmp(rule_name, "juci-remote-access") == 0) { - dmuci_get_value_by_section_string(ss, "enabled", &rule_enabled); - *value= (strcmp(rule_enabled, "0") == 0) ? "0": "1"; - return 0; - } - } - *value = "0"; - return 0; -} - -static int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *ss; - char *rule_name; - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - uci_foreach_sections("firewall", "rule", ss) { - dmuci_get_value_by_section_string(ss, "name", &rule_name); - if (strcmp(rule_name, "juci-remote-access") == 0) { - dmuci_set_value_by_section(ss, "enabled", b ? "" : "0"); - return 0; - } - } - add_default_rule("80", value, "wan"); - return 0; - } - return 0; -} - -static int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *ss = NULL; - char *rule_name, *dest_port; - - uci_foreach_sections("firewall", "rule", ss) { - dmuci_get_value_by_section_string(ss, "name", &rule_name); - if (strcmp(rule_name, "juci-remote-access") == 0) { - dmuci_get_value_by_section_string(ss, "dest_port", &dest_port); - *value= dest_port; - return 0; - } - } - *value = "80"; - return 0; -} - -static int set_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *ss; - char *rule_name, *owsd; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, RANGE_ARGS{{NULL,"65535"}}, 1)) - return FAULT_9007; - return 0; - case VALUESET: - uci_foreach_sections("firewall", "rule", ss) { - dmuci_get_value_by_section_string(ss, "name", &rule_name); - if (strcmp(rule_name, "juci-remote-access") == 0) { - dmuci_set_value_by_section(ss, "dest_port", value); - dmuci_get_value_by_section_string(ss, "owsd", &owsd); - dmuci_set_value("owsd", owsd, "port", value); - return 0; - } - } - - add_default_rule(value, "0", "wan"); - dmuci_set_value("owsd", "wan", "port", value); - return 0; - } - return 0; -} - -static bool get_supportedprotocols(void) -{ - char *cert = NULL, *key = NULL, *ca = NULL; - - dmuci_get_option_value_string("owsd", "wan_https", "cert", &cert); - dmuci_get_option_value_string("owsd", "wan_https", "key", &key); - dmuci_get_option_value_string("owsd", "wan_https", "ca", &ca); - - if ((cert && *cert && file_exists(cert)) || - (key && *key && file_exists(key)) || - (ca && *ca && file_exists(ca))) - return true; - - return false; -} - -static int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = (get_supportedprotocols()) ? "HTTP,HTTPS" : "HTTP"; - return 0; -} - -static int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *ss = NULL; - char *rule_name, *rule_owsd; - - uci_foreach_sections("firewall", "rule", ss) { - dmuci_get_value_by_section_string(ss, "name", &rule_name); - if (strcmp(rule_name, "juci-remote-access") == 0) { - dmuci_get_value_by_section_string(ss, "owsd", &rule_owsd); - if (strcmp(rule_owsd, "wan") == 0) - *value = "HTTP"; - else - *value = "HTTPS"; - return 0; - } - } - *value = "HTTP"; - return 0; -} - -static int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *ss; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, -1, SupportedProtocols, NULL)) - return FAULT_9007; - - if (get_supportedprotocols()) { - if ((strcmp(value, "HTTP") != 0) && (strcmp(value, "HTTPS") != 0)) - return FAULT_9007; - } else { - if (strcmp(value, "HTTP") != 0) - return FAULT_9007; - } - return 0; - case VALUESET: - uci_foreach_sections("firewall", "rule", ss) { - char *rule_name; - - dmuci_get_value_by_section_string(ss, "name", &rule_name); - if (strcmp(rule_name, "juci-remote-access") == 0) { - dmuci_set_value_by_section(ss, "owsd", (strcmp(value, "HTTPS") == 0) ? "wan_https" : "wan"); - return 0; - } - } - - add_default_rule("80", "0", (strcmp(value, "HTTPS") == 0) ? "wan_https" : "wan"); - return 0; - } - return 0; -} - -/* *** Device.UserInterface. *** */ -DMOBJ tUserInterfaceObj[] = { -/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/ -{"RemoteAccess", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUserInterfaceRemoteAccessParams, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.UserInterface.RemoteAccess. *** */ -DMLEAF tUserInterfaceRemoteAccessParams[] = { -/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_userint_remoteaccesss_enable, set_userint_remoteaccesss_enable, BBFDM_BOTH}, -{"Port", &DMWRITE, DMT_UNINT, get_userint_remoteaccesss_port, set_userint_remoteaccesss_port, BBFDM_BOTH}, -{"SupportedProtocols", &DMREAD, DMT_STRING, get_userint_remoteaccesss_supportedprotocols, NULL, BBFDM_BOTH}, -{"Protocol", &DMWRITE, DMT_STRING, get_userint_remoteaccesss_protocol, set_userint_remoteaccesss_protocol, BBFDM_BOTH}, -{0} -}; diff --git a/dmtree/tr181/userinterface.h b/dmtree/tr181/userinterface.h deleted file mode 100644 index 74d0c604..00000000 --- a/dmtree/tr181/userinterface.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2019 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 - * as published by the Free Software Foundation - * - * Author: Omar Kallel - * Author: Amin Ben Ramdhane - * - */ - -#ifndef __USER_INTERFACE_H -#define __USER_INTERFACE_H - -#include - -extern DMLEAF tUserInterfaceRemoteAccessParams[]; -extern DMOBJ tUserInterfaceObj[]; - -#endif