[SOLVED] Re-starting Unbound after USB hotplug

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Goto page Previous  1, 2, 3  Next
Author Message
blkt
DD-WRT Guru


Joined: 20 Jan 2019
Posts: 5660

PostPosted: Mon Oct 03, 2022 9:53    Post subject: Reply with quote
I saw those changes, and this is very cool! Thank you BrainSlayer and egc!
Sponsor
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Mon Oct 03, 2022 12:41    Post subject: Reply with quote
mwchang wrote:
I think we forgot one thing: a patch can be submitted via the forum as a file attachment! Wink

Thus developers and helpers can review and talk about the patch using the forum.

I don't wanna directly touch the source codes using git until I can properly secure my PC like those mainframe computers in big banks. It's really very dangerous to do it otherwise.



This is what GitHub is for and pull requests allow fine grained feedback, you can comment on any given line of the patch, something you will never get where a patch is attached or any other means.

Sorry, personally I do not support convoluted methodologies for patch reviews, where better and modern technologies exist that are tried and tested for said reviews over a web browser, any git web frontend will beat this.

As for security, Ive no idea what you're so belt and braces, git -- Github and Gitlab offer 2 layer security logins Github even offers a physical security key login, and unless youre not that type of person who falls for dumb phishing emails, no such issues will happen, and FYI bank mainframes are not that secure mk? Most large institutions run severely outdated software.

And plus you can run a sandboxed Virtual machine like I do for development. I wouldn't dream of using the host OS for this.

But OK you are clearly inexperienced so you're going to be afraid of your own shadow for a while.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Mon Oct 03, 2022 15:31    Post subject: Reply with quote
egc wrote:
But BS has found a more sophisticated and universal solution which he also implemented for other services which can have a .conf file on USB.

blkt wrote:
I saw those changes, and this is very cool! Thank you BrainSlayer and egc!

If you were talking about these 2 changes, they were not related to reloading Unbound... unless custom_configs had something related.

10:10 AM Changeset [50315] by brainslayer
restart configs which are loaded from custom location
https://svn.dd-wrt.com/changeset/50315

10:04 AM Changeset [50314] by brainslayer
track services which are loaded from a custom config
https://svn.dd-wrt.com/changeset/50314

You can read:

https://svn.dd-wrt.com/browser/src/router/services/services/usb_hotplug_adv.c?rev=50328

I think you needed to use eval() to add Unbound into the list? I dunno... as for example:
Code:
/* when adding external media some services should be restarted, e.g. minidlna in order to scan for media files*/
static bool usb_startservices(void)
....
#ifdef HAVE_PLEX
        eval("startservice", "plex", "-f");
#endif
#ifdef HAVE_UNBOUND
        eval("startservice", "unbound", "-f");
#endif
        char *next;
        char *services = nvram_safe_get("custom_configs");
        char service[32];
        foreach(service, services, next) {
                eval("service", service, "stop");
                eval("service", service, "start");
        }
}


I think I need to track variable custom_configs. Um... how could I do it via the SVN webiste?

"nvram_safe_get("custom_configs");" is not like regular nvram... Smile
Code:
root@rt-n18u:~# nvram show | grep custom_con
size: 31519 bytes (34017 left)

Maybe it's still a work-in-progress. Beter check again later. Bed time, good_night("hkt")!


_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw


Last edited by mwchang on Mon Oct 03, 2022 15:59; edited 9 times in total
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Mon Oct 03, 2022 15:35    Post subject: Reply with quote
the-joker wrote:
Sorry, personally I do not support convoluted methodologies for patch reviews, where better and modern technologies exist that are tried and tested for said reviews over a web browser, any git web frontend will beat this.

As for security, Ive no idea what you're so belt and braces, git -- Github and Gitlab offer 2 layer security logins Github even offers a physical security key login, and unless youre not that type of person who falls for dumb phishing emails, no such issues will happen, and FYI bank mainframes are not that secure mk? Most large institutions run severely outdated software.

And plus you can run a sandboxed Virtual machine like I do for development. I wouldn't dream of using the host OS for this.

But OK you are clearly inexperienced so you're going to be afraid of your own shadow for a while.


I am not ready to carry the burden. I rather just suggest and persuade in the forum. Wink

And I am more experienced with business applications (Foxpro, SQL, some PHP+Javascript) than firmware. I know C and some C++.

My programming jobs never required the use of version control system, and nothing had gone wrong! That included patching an old and kind-of-buggy MIS system to get pass year 2000.


_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Tue Oct 04, 2022 15:37    Post subject: Reply with quote
the-joker wrote:
This is what GitHub is for and pull requests allow fine grained feedback, you can comment on any given line of the patch, something you will never get where a patch is attached or any other means.


Are version control tools really about making maintenance easy? Or are they disguising tools to track (criminal?) responsibilities? Well... well ... well....

How do you prevent bad guys from forging evidences inside the system? You cannot just trust the top management because they could be bad guys.

I better stay away from them. Smile

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Tue Oct 04, 2022 16:03    Post subject: Reply with quote
Nice argument for living under a rock, now shove over to the next rock over ->there<- mk? This ->one<- is mine.
Welcome to year zero.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Tue Oct 04, 2022 16:07    Post subject: Reply with quote
the-joker wrote:
Nice argument for living under a rock, now shove over to the next rock over ->there<- mk? This ->one<- is mine.
Welcome to year zero.

Don't worry... I will throw out patch suggestions from under the rock. Smile

To be fair, how do you 100% secure GIT? What about police and medical databases!?

How do you prevent trusted people from being corrupted?

How do you pass along knowledge?

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 2927
Location: Germany

PostPosted: Tue Oct 04, 2022 16:22    Post subject: Reply with quote
Sorry but git and svn are opensource and no one forces you to host the repositories at a provider.

You can easily host the repos yourself, you just need a machine running linux, as an authentication method are for example ssh keys available.

The dd-wrt repository is also self-hosted and GitHub is just a mirror.

Just mentioned by the way if you don't trust GitHub.

GIT is as secure as you make it
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Tue Oct 04, 2022 16:56    Post subject: Reply with quote
ho1Aetoo wrote:
Just mentioned by the way if you don't trust GitHub.

GIT is as secure as you make it

Too bad I am NOT a security expert. So I will continue to use the forum to suggest patches.

Back to my hole under a rock. But could the rock be hacked and be turned into bread? Smile


_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Wed Oct 05, 2022 6:39    Post subject: Reply with quote
Sorry.... problem *NOT* yet fixed in build 50357! Still needed to manually reload Unbound to read /jffs/etc/unbound.conf in USB storage.

Code:
# ps | grep -i conf | grep -v ddns

 1422 root     dnsmasq -u root -g root -C /tmp/dnsmasq.conf
 1428 root     unbound -c /tmp/unbound.conf
 2352 root     ksmbd.mountd -c /tmp/smb.conf -u /tmp/smb.db
 2353 root     ksmbd.mountd -c /tmp/smb.conf -u /tmp/smb.db
 2375 root     lighttpd -f /jffs/etc/lighttpd.conf
 4463 root     grep -i conf

I think you needed to use eval() to add Unbound into the list? I dunno... as for example:
Code:

/* TODO improvement: use procfs to identify pids that have openfiles on externel discs and then stop them before umount*/
static bool usb_stopservices()
{
        eval("stopservice", "cron");
        eval("stopservice", "samba3");
        eval("stopservice", "nfs");
        eval("stopservice", "rsync");
        eval("stopservice", "dlna");
        eval("stopservice", "ftpsrv");
   #ifdef HAVE_WEBSERVER
           eval("stopservice", "lighttpd");
   #endif
   #ifdef HAVE_TRANSMISSION
           eval("stopservice", "transmission");
   #endif
   #ifdef HAVE_PLEX
           eval("stopservice", "plex");
   #endif
   #ifdef HAVE_UNBOUND
           eval("stopservice", "unbound");
   #endif
        eval("stopservice", "run_rc_usb");
        return 0;
}
   
/* when adding external media some services should be restarted, e.g. minidlna in order to scan for media files*/
static bool usb_startservices(void)
{
        eval("startservice", "cron", "-f");
        eval("startservice", "samba3", "-f");
        eval("startservice", "nfs", "-f");
        eval("startservice", "rsync", "-f");
        eval("startservice", "dlna", "-f");
        eval("startservice", "ftpsrv", "-f");
   #ifdef HAVE_WEBSERVER
           eval("startservice", "lighttpd", "-f");
   #endif
   #ifdef HAVE_TRANSMISSION
           eval("startservice", "transmission", "-f");
   #endif
   #ifdef HAVE_PLEX
           eval("startservice", "plex", "-f");
   #endif
   #ifdef HAVE_UNBOUND
           eval("startservice", "unbound", "-f");
   #endif
        char *next;
        char *services = nvram_safe_get("custom_configs");
        char service[32];
        foreach(service, services, next) {
                eval("service", service, "stop");
                eval("service", service, "start");
        }
        return 0;
}

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12839
Location: Netherlands

PostPosted: Tue Oct 11, 2022 10:34    Post subject: Reply with quote
I have not forgotten you but was busy doing other things for WireGuard and OpenVPN.

The code we are looking at should restart all registered services (services in nvram custom_configs).

Those services are registered in libutils/libutils/bcmutils.c

The code to register the services ( registerCustom(service); ) seems to run only after the USB is up that seems the problem.

I will talk to BS about it Smile

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Tue Oct 11, 2022 11:01    Post subject: Reply with quote
egc wrote:
I have not forgotten you but was busy doing other things for WireGuard and OpenVPN.
....
I will talk to BS about it Smile

Take your time... I can wait. Again, thank you!
Quote:
Those services are registered in libutils/libutils/bcmutils.c

Flying there... reading it! Smile

https://svn.dd-wrt.com/browser/src/router/libutils/libutils/bcmutils.c



Side-notes:

Um... this httpd_filter_name() is interesting. Might explain why some HTML character were not escaped when displayed in those textboxes of WEBUI. And this function might affect Javascript HTML escape function in the WEBUI... Will come back to this later, with a new thread.

How about adding "&quot;" and "&amp;" to patterns[] and see what might happen? Meow... Wink
Code:
1970   int httpd_filter_name(char *old_name, char *new_name, size_t size, int type)
1971   {
.... [snipped] ....
1981           struct pattern patterns[] = {
1982                   { ' ', "&nbsp;" },
1983                   { ':', "&semi;" },
1984                   { '<', "&lt;" },
1985                   { '>', "&gt;" },
1986           };



_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Tue Oct 11, 2022 12:15    Post subject: Reply with quote
which textboxes? be specific. some examples and a screenshot may even help.
_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Tue Oct 11, 2022 12:30    Post subject: Reply with quote
the-joker wrote:
which textboxes? be specific. some examples and a screenshot may even help.

All those textboxes in the tab Admin -> Commands -> the Command Shell -> Commands, including USB Script, Firewall Script...

But for experiment, try Command Shell first. Could be interesting... of course, it might break things. Still httpd_filter_name() might be for sanitizing HTTP POST strings, that is, input not output.


_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Tue Oct 11, 2022 12:49    Post subject: Reply with quote
The commands boxes and execution renders everything to HTML that you execute in there without exception including that crap in the filters. Anything anywahere that goes in UI like that will do similar aberration.

For a fun test but any html file in /tmp folder than cat the file. deja-vu here -> https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1262725#1262725

Shouldn't happen but it does and your filter thing would have no effect, cant remember anymore the function for this what I can remember is that the parsing via UI is and has always been broken.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
Goto page Previous  1, 2, 3  Next Display posts from previous:    Page 2 of 3
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum