From 1eaa69ecd3ccb8fbef26f1c3d4c453882b29b94d Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Sat, 28 Dec 2019 14:18:33 -0500 Subject: [PATCH 1/9] Updated documentation --- Changelog-NG.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changelog-NG.txt b/Changelog-NG.txt index 5e0d7fb848e..8f88aabbb0d 100644 --- a/Changelog-NG.txt +++ b/Changelog-NG.txt @@ -9,6 +9,12 @@ Asuswrt-Merlin 384/NG Changelog be identical to when the original wan-start script was being run (wan-start should be considered deprecated and will be removed in a future release) + - NEW: Added five mount points within /www to allow script + developers to easily add their own pages to the webui. + See the documentation for a fully working example that + will add your custom page as well as your own tab on + the webui. + - UPDATED: Merged with GPL 385-10002 (from RT-AC68U) - UPDATED: odhcp6c to 1.1-97-ge199804 (themiron) - UPDATED: curl to 7.67.0. From 7727551b5a14119c99bc43e94aab1061a02356af Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Mon, 30 Dec 2019 02:17:24 -0500 Subject: [PATCH 2/9] rom: update stun servers used by getrealip.sh The default server (stun.services.mozilla.com) is down, so don't use it. Remove stun.iptel.org because hostname doesn't resolve Remove stun.xten.com because it seems to return random IP addresses (?) Google will now be primarily used, and if it fails (for instance in China) then the stunprotocol server will be used as failover. --- release/src/router/rom/apps_scripts/getrealip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/src/router/rom/apps_scripts/getrealip.sh b/release/src/router/rom/apps_scripts/getrealip.sh index 60b5d3a7d97..41333e5093a 100755 --- a/release/src/router/rom/apps_scripts/getrealip.sh +++ b/release/src/router/rom/apps_scripts/getrealip.sh @@ -1,7 +1,7 @@ #!/bin/sh # use STUN to find the external IP. -servers="default stun.l.google.com:19302 stun.iptel.org stun.stunprotocol.org stun.xten.com" +servers="stun.l.google.com:19302 stun.stunprotocol.org" prefixes="wan0_ wan1_" which ministun >/dev/null || exit 1 From 2770fa4b0f7754e90647e0f7ad688484c174fd77 Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Mon, 30 Dec 2019 19:22:16 -0500 Subject: [PATCH 3/9] rc: only intercept udp requests to port 123, ntpd does not listen to tcp --- release/src/router/rc/firewall.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/release/src/router/rc/firewall.c b/release/src/router/rc/firewall.c index e79fc3153fb..2a8f0928029 100644 --- a/release/src/router/rc/firewall.c +++ b/release/src/router/rc/firewall.c @@ -1696,9 +1696,7 @@ void nat_setting(char *wan_if, char *wan_ip, char *wanx_if, char *wanx_ip, char #ifdef RTCONFIG_NTPD if (nvram_get_int("ntpd_enable") && nvram_get_int("ntpd_server_redir")) { - fprintf(fp, "-A PREROUTING -i %s -p udp -m udp --dport 123 -j REDIRECT --to-port 123\n" - "-A PREROUTING -i %s -p tcp -m tcp --dport 123 -j REDIRECT --to-port 123\n", - lan_if, lan_if); + fprintf(fp, "-A PREROUTING -i %s -p udp -m udp --dport 123 -j REDIRECT --to-port 123\n", lan_if); } #endif @@ -2081,9 +2079,7 @@ void nat_setting2(char *lan_if, char *lan_ip, char *logaccept, char *logdrop) // #ifdef RTCONFIG_NTPD if (nvram_get_int("ntpd_enable") && nvram_get_int("ntpd_server_redir")) { - fprintf(fp, "-A PREROUTING -i %s -p udp -m udp --dport 123 -j REDIRECT --to-port 123\n" - "-A PREROUTING -i %s -p tcp -m tcp --dport 123 -j REDIRECT --to-port 123\n", - lan_if, lan_if); + fprintf(fp, "-A PREROUTING -i %s -p udp -m udp --dport 123 -j REDIRECT --to-port 123\n", lan_if); } #endif From 31268c61859b2c35ce13be45be95cbfb3149282f Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Tue, 31 Dec 2019 00:10:48 -0500 Subject: [PATCH 4/9] httpd: implement support for storing third party settings into jffs storage File stored in /jffs will contain settings defined by third party devs, allowing them to interact with them from the webui. Web-side is presented as an object, router-side is a flatfile containing one setting per line. Combined with the custom user pages added with previous commit, this allows add-on devs to fully implement a webui, and be able to create, read and write their own settings independently from nvram and its limitations. --- release/src/router/httpd/data_arrays.c | 53 ++++++++++++++++++++++++++ release/src/router/httpd/data_arrays.h | 2 + release/src/router/httpd/web.c | 6 +++ release/src/router/shared/defaults.c | 1 + 4 files changed, 62 insertions(+) diff --git a/release/src/router/httpd/data_arrays.c b/release/src/router/httpd/data_arrays.c index db7068dc845..6ddf6dcb4b0 100644 --- a/release/src/router/httpd/data_arrays.c +++ b/release/src/router/httpd/data_arrays.c @@ -64,6 +64,8 @@ #include #endif +#include + int ej_get_leases_array(int eid, webs_t wp, int argc, char_t **argv) { @@ -1211,3 +1213,54 @@ void _fix_TM_ipv6(char* str) { strcat(str,"00"); } #endif + + +int ej_get_custom_settings(int eid, webs_t wp, int argc, char **argv_) { + + struct json_object *settings_obj; + int ret = 0; + char line[3040]; + char name[30]; + char value[3000]; + FILE *fp; + + fp = fopen("/jffs/custom_settings.txt", "r"); + if (fp == NULL) { + ret += websWrite(wp," new Object()"); + return 0; + } + + settings_obj = json_object_new_object(); + while (fgets(line, sizeof(line), fp)) { + if (sscanf(line,"%29s%*[ ]%2999s%*[ \n]",name, value) == 2) { + json_object_object_add(settings_obj, name, json_object_new_string(value)); + } + } + fclose(fp); + + ret += websWrite(wp, "%s", json_object_to_json_string(settings_obj)); + + json_object_put(settings_obj); + return ret; +} + + +void write_custom_settings(char *jstring) { + char line[3040]; + FILE *fp; + struct json_object *settings_obj; + + settings_obj = json_tokener_parse(jstring); + if (!settings_obj) return; + + fp = fopen("/jffs/custom_settings.txt", "w"); + if (!fp) return; + + json_object_object_foreach(settings_obj, key, val) { + snprintf(line, sizeof(line), "%s %s\n", key, json_object_get_string(val)); + fwrite(line, 1, strlen(line), fp); + } + fclose(fp); + + json_object_put(settings_obj); +} diff --git a/release/src/router/httpd/data_arrays.h b/release/src/router/httpd/data_arrays.h index 053e1df3121..b85e2dc6b95 100644 --- a/release/src/router/httpd/data_arrays.h +++ b/release/src/router/httpd/data_arrays.h @@ -44,3 +44,5 @@ void _fix_TM_ipv6(char* str); #endif int ej_connlist_array(int eid, webs_t wp, int argc, char **argv); +extern int ej_get_custom_settings(int eid, webs_t wp, int argc, char **argv_); +extern void write_custom_settings(char *jstring); diff --git a/release/src/router/httpd/web.c b/release/src/router/httpd/web.c index f74d14cc87f..8d1d4910703 100644 --- a/release/src/router/httpd/web.c +++ b/release/src/router/httpd/web.c @@ -3141,6 +3141,11 @@ static int validate_apply(webs_t wp, json_object *root) { nvram_modified = 1; } #endif + else if(!strcmp(name, "amng_custom")) { + write_custom_settings(value); + _dprintf("set amng_custom to %s\n", value); + nvram_modified = 1; + } #ifdef RTCONFIG_DISK_MONITOR else if(!strncmp(name, "diskmon_", 8)) { @@ -23398,6 +23403,7 @@ struct ej_handler ej_handlers[] = { { "get_route_array", ej_get_route_array}, { "get_tcclass_array", ej_tcclass_dump_array}, { "get_connlist_array", ej_connlist_array}, + { "get_custom_settings", ej_get_custom_settings}, #ifdef RTCONFIG_BCMWL6 { "get_wl_status", ej_wl_status_2g_array}, #endif diff --git a/release/src/router/shared/defaults.c b/release/src/router/shared/defaults.c index 4bfacbbc22d..92b7d686c86 100644 --- a/release/src/router/shared/defaults.c +++ b/release/src/router/shared/defaults.c @@ -3532,6 +3532,7 @@ struct nvram_tuple router_defaults[] = { { "ntpd_enable", "0", CKN_STR1, CKN_TYPE_DEFAULT, CKN_ACC_LEVEL_DEFAULT, CKN_ENC_DEFAULT, 0 }, { "ntpd_server_redir", "0", CKN_STR1, CKN_TYPE_DEFAULT, CKN_ACC_LEVEL_DEFAULT, CKN_ENC_DEFAULT, 0 }, #endif + { "amng_custom", "", CKN_STR8192, CKN_TYPE_DEFAULT, CKN_ACC_LEVEL_DEFAULT, CKN_ENC_DEFAULT, 0 }, // Dummy variable /* End of Merlin-specific settings */ From 9b62157bf664855200409479a44310f8c90f4d54 Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Tue, 31 Dec 2019 01:01:25 -0500 Subject: [PATCH 5/9] httpd: rc: locate addons content to a dedicated /jffs/addons/ folder --- release/src/router/httpd/data_arrays.c | 4 ++-- release/src/router/rc/jffs2.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/release/src/router/httpd/data_arrays.c b/release/src/router/httpd/data_arrays.c index 6ddf6dcb4b0..18636e377b7 100644 --- a/release/src/router/httpd/data_arrays.c +++ b/release/src/router/httpd/data_arrays.c @@ -1224,7 +1224,7 @@ int ej_get_custom_settings(int eid, webs_t wp, int argc, char **argv_) { char value[3000]; FILE *fp; - fp = fopen("/jffs/custom_settings.txt", "r"); + fp = fopen("/jffs/addons/custom_settings.txt", "r"); if (fp == NULL) { ret += websWrite(wp," new Object()"); return 0; @@ -1253,7 +1253,7 @@ void write_custom_settings(char *jstring) { settings_obj = json_tokener_parse(jstring); if (!settings_obj) return; - fp = fopen("/jffs/custom_settings.txt", "w"); + fp = fopen("/jffs/addons/custom_settings.txt", "w"); if (!fp) return; json_object_object_foreach(settings_obj, key, val) { diff --git a/release/src/router/rc/jffs2.c b/release/src/router/rc/jffs2.c index fb45c306de9..c5f9e7f051a 100644 --- a/release/src/router/rc/jffs2.c +++ b/release/src/router/rc/jffs2.c @@ -366,6 +366,7 @@ void start_jffs2(void) if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755); if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755); + if !(check_if_dir_exist("/jffs/addons/")) mkdir("/jffs/addons/", 0755); if (!check_if_dir_exist(UPLOAD_CERT_FOLDER)) mkdir(UPLOAD_CERT_FOLDER, 0600); adjust_jffs_content(); From 7fa7c2b299156c3a5311b2a241f02890875ab18b Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Tue, 31 Dec 2019 02:02:58 -0500 Subject: [PATCH 6/9] Updated documentation --- Changelog-NG.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Changelog-NG.txt b/Changelog-NG.txt index 8f88aabbb0d..ee7244bb4eb 100644 --- a/Changelog-NG.txt +++ b/Changelog-NG.txt @@ -9,11 +9,15 @@ Asuswrt-Merlin 384/NG Changelog be identical to when the original wan-start script was being run (wan-start should be considered deprecated and will be removed in a future release) - - NEW: Added five mount points within /www to allow script - developers to easily add their own pages to the webui. - See the documentation for a fully working example that - will add your custom page as well as your own tab on - the webui. + - NEW: Implemented an official API for addon developers to + better integrate with the router. This includes up + to five different pages that can be added anywhere within + the webui, and a dedicated storage repository for your + settings, which can be interacted with through your + custom web page. See the Wiki for more information: + + https://github.com/RMerl/asuswrt-merlin/wiki/Addons-API + - UPDATED: Merged with GPL 385-10002 (from RT-AC68U) - UPDATED: odhcp6c to 1.1-97-ge199804 (themiron) - UPDATED: curl to 7.67.0. From bb8eac14325e5c2dcfdb31c212bfb1f953619390 Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Tue, 31 Dec 2019 14:35:08 -0500 Subject: [PATCH 7/9] webui: increase user mount points from 5 to 10 --- release/src/router/others/helper.sh | 2 +- release/src/router/www/Makefile | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/release/src/router/others/helper.sh b/release/src/router/others/helper.sh index 212615089da..1584fc2b7db 100755 --- a/release/src/router/others/helper.sh +++ b/release/src/router/others/helper.sh @@ -41,7 +41,7 @@ pc_delete() { # in use. get_webui_page() { - for i in 1 2 3 4 5 + for i in 1 2 3 4 5 6 7 8 9 10 do page=/www/ext/user$i.asp if [ ! -f $page ] diff --git a/release/src/router/www/Makefile b/release/src/router/www/Makefile index c6dc638b645..bb181de426b 100644 --- a/release/src/router/www/Makefile +++ b/release/src/router/www/Makefile @@ -714,3 +714,8 @@ endif ln -sf user/user3.asp $(INSTALLDIR)/www/user3.asp ln -sf user/user4.asp $(INSTALLDIR)/www/user4.asp ln -sf user/user5.asp $(INSTALLDIR)/www/user5.asp + ln -sf user/user6.asp $(INSTALLDIR)/www/user6.asp + ln -sf user/user7.asp $(INSTALLDIR)/www/user7.asp + ln -sf user/user8.asp $(INSTALLDIR)/www/user8.asp + ln -sf user/user9.asp $(INSTALLDIR)/www/user9.asp + ln -sf user/user10.asp $(INSTALLDIR)/www/user10.asp From 6ec061b8d23bfb73d432d0f4466428c7aa793687 Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Wed, 1 Jan 2020 13:54:03 -0500 Subject: [PATCH 8/9] Updated documentation --- Changelog-NG.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Changelog-NG.txt b/Changelog-NG.txt index ee7244bb4eb..8300557ce7d 100644 --- a/Changelog-NG.txt +++ b/Changelog-NG.txt @@ -11,11 +11,12 @@ Asuswrt-Merlin 384/NG Changelog and will be removed in a future release) - NEW: Implemented an official API for addon developers to better integrate with the router. This includes up - to five different pages that can be added anywhere within + to ten different pages that can be added anywhere within the webui, and a dedicated storage repository for your settings, which can be interacted with through your custom web page. See the Wiki for more information: + (first draft of the documentation, need to be reorganized) https://github.com/RMerl/asuswrt-merlin/wiki/Addons-API - UPDATED: Merged with GPL 385-10002 (from RT-AC68U) @@ -23,6 +24,18 @@ Asuswrt-Merlin 384/NG Changelog - UPDATED: curl to 7.67.0. +384.14_2 (1-1-2020) + - FIXED: Missing cifs kernel module + - FIXED: stubby was linked with OpenSSL 1.0 instead of 1.1 + - FIXED: some routers were reporting the Internet connection being + disconnected. If you were affected and you had flashed + a customized bootloader, then please reflash your original + bootloader, as your modded bootloader is invalid, and other + potential issues may appear over time. + - FIXED: Random traffic spikes logged in Traffic Monitor (regression + from 384_81351) + + 384.14 (14-Dec-2019) - NEW: Implement option to prevent Firefox's automatic usage of DoH. By default, this will only apply if you have DNSPrivacy From 8070a50a355555bd5d2c7b43873c7503f5aba7d8 Mon Sep 17 00:00:00 2001 From: Eric Sauvageau Date: Wed, 1 Jan 2020 19:06:03 -0500 Subject: [PATCH 9/9] Fix typos in 9b62157bf6 and bb8eac1432 --- release/src/router/rc/jffs2.c | 2 +- release/src/router/www/Makefile | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/release/src/router/rc/jffs2.c b/release/src/router/rc/jffs2.c index c5f9e7f051a..d34509a15bc 100644 --- a/release/src/router/rc/jffs2.c +++ b/release/src/router/rc/jffs2.c @@ -366,7 +366,7 @@ void start_jffs2(void) if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755); if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755); - if !(check_if_dir_exist("/jffs/addons/")) mkdir("/jffs/addons/", 0755); + if (!check_if_dir_exist("/jffs/addons/")) mkdir("/jffs/addons/", 0755); if (!check_if_dir_exist(UPLOAD_CERT_FOLDER)) mkdir(UPLOAD_CERT_FOLDER, 0600); adjust_jffs_content(); diff --git a/release/src/router/www/Makefile b/release/src/router/www/Makefile index bb181de426b..f77ca5e2173 100644 --- a/release/src/router/www/Makefile +++ b/release/src/router/www/Makefile @@ -714,8 +714,9 @@ endif ln -sf user/user3.asp $(INSTALLDIR)/www/user3.asp ln -sf user/user4.asp $(INSTALLDIR)/www/user4.asp ln -sf user/user5.asp $(INSTALLDIR)/www/user5.asp - ln -sf user/user6.asp $(INSTALLDIR)/www/user6.asp - ln -sf user/user7.asp $(INSTALLDIR)/www/user7.asp - ln -sf user/user8.asp $(INSTALLDIR)/www/user8.asp - ln -sf user/user9.asp $(INSTALLDIR)/www/user9.asp - ln -sf user/user10.asp $(INSTALLDIR)/www/user10.asp + ln -sf user/user6.asp $(INSTALLDIR)/www/user6.asp + ln -sf user/user7.asp $(INSTALLDIR)/www/user7.asp + ln -sf user/user8.asp $(INSTALLDIR)/www/user8.asp + ln -sf user/user9.asp $(INSTALLDIR)/www/user9.asp + ln -sf user/user10.asp $(INSTALLDIR)/www/user10.asp +