diff mbox series

2 instances of moongose [PATCH?]

Message ID edc9eeae-e8fa-44e2-b849-17c2448fef7a@googlegroups.com
State Rejected
Headers show
Series 2 instances of moongose [PATCH?] | expand

Commit Message

darkokomljenovic2502@gmail.com Jan. 13, 2020, 8:50 a.m. UTC
Hi,

is it possible to run 2 instances of moongose at the same time? 

E.g. One on port 80, other ssl on 443.

For recovery OS, which should not change, but it is possible that some 
firewalls don't use port 80, and some companys don't want to hussle with 
self signed https



Possible patch, (tested, and working on my board):



From 3f091b648fa5a856fb92ac8c3ad98a7b2fef0100 Mon Sep 17 00:00:00 2001
From: Darko Komljenovic <darko.komljenovic@zenitel.com>
Date: Mon, 13 Jan 2020 09:16:23 +0100
Subject: [PATCH] Added the option to have 2 web servers at the same time

Signed-off-by: Darko Komljenovic <darko.komljenovic@zenitel.com>
---
 core/swupdate.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

 #endif
 }
@@ -607,6 +610,10 @@ int main(int argc, char **argv)
  char *weboptions;
  char **av = NULL;
  int ac = 0;
+ int opt_x = 0;
+ char *weboptions_x;
+ char **av_x = NULL;
+ int ac_x = 0;
 #endif
 #ifdef CONFIG_DOWNLOAD
  int opt_d = 0;
@@ -632,6 +639,7 @@ int main(int argc, char **argv)
 #endif
 #ifdef CONFIG_WEBSERVER
  strcat(main_options, "w:");
+ strcat(main_options, "x:");
 #endif
 #ifdef CONFIG_HW_COMPATIBILITY
  strcat(main_options, "H:");
@@ -710,7 +718,7 @@ int main(int argc, char **argv)
  /* Process options with getopt */
  while ((c = getopt_long(argc, argv, main_options,
  long_options, NULL)) != EOF) {
- if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w')) {
+ if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w' && c != 
'x')) {
  /* An option's value starting with '-' is not allowed except
  * for downloader, webserver, and suricatta doing their own
  * argv parsing.
@@ -825,6 +833,16 @@ int main(int argc, char **argv)
  opt_w = 1;
  free(weboptions);
  break;
+ case 'x':
+ if (asprintf(&weboptions_x,"%s %s", argv[0], optarg) ==
+ ENOMEM_ASPRINTF) {
+ ERROR("Cannot allocate memory for webserver options.");
+ exit(EXIT_FAILURE);
+ }
+ av_x = splitargs(weboptions_x, &ac_x);
+ opt_x = 1;
+ free(weboptions_x);
+ break;
 #endif
  case 'c':
  opt_c = 1;
@@ -913,6 +931,12 @@ int main(int argc, char **argv)
  start_mongoose);
  freeargs(av);
  }
+ if (opt_x) {
+ start_subprocess(SOURCE_WEBSERVER, "webserver_secondary",
+ cfgfname, ac_x, av_x,
+ start_mongoose);
+ freeargs(av_x);
+ }
 #endif
 
 #if defined(CONFIG_SURICATTA)

Comments

Stefano Babic Jan. 13, 2020, 5:39 p.m. UTC | #1
Hi Darko,

On 13/01/20 09:50, darkokomljenovic2502@gmail.com wrote:
> Hi,
> 
> is it possible to run 2 instances of moongose at the same time? 
> 
> E.g. One on port 80, other ssl on 443.
> 
> For recovery OS, which should not change, but it is possible that some
> firewalls don't use port 80, and some companys don't want to hussle with
> self signed https
> 

This seems to me the wrong way to obtain the goal. You can already start
swupdate and pass the port number. You could run swupdate with -w "-p
80" or "-p 443" to select which port the werbserver should listen.

If you need more ports at the same time (but this does not seem your use
case), the correct way seems to use a proxy to forward data to the
SWUpdate's webserver.

> 
> 
> Possible patch, (tested, and working on my board):
> 
> 
> 
> From 3f091b648fa5a856fb92ac8c3ad98a7b2fef0100 Mon Sep 17 00:00:00 2001
> From: Darko Komljenovic <darko.komljenovic@zenitel.com>
> Date: Mon, 13 Jan 2020 09:16:23 +0100
> Subject: [PATCH] Added the option to have 2 web servers at the same time
> 
> Signed-off-by: Darko Komljenovic <darko.komljenovic@zenitel.com>
> ---
>  core/swupdate.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/core/swupdate.c b/core/swupdate.c
> index 38e5a56..9a3a44a 100644
> --- a/core/swupdate.c
> +++ b/core/swupdate.c
> @@ -105,6 +105,7 @@ static struct option long_options[] = {
>  #endif
>  #ifdef CONFIG_WEBSERVER
>  {"webserver", required_argument, NULL, 'w'},
> +{"webserver_seconday", required_argument, NULL, 'x'},

If more instances are required, I do not like this. It does not scale.
What about with a third webserver ? An array of options should be passed
instead of having "secondary" "third", fourth and so on.

>  #endif
>  {"check", no_argument, NULL, 'c'},
>  {"postupdate", required_argument, NULL, 'p'},
> @@ -168,6 +169,8 @@ static void usage(char *programname)
>  #ifdef CONFIG_WEBSERVER
>  fprintf(stdout,
>  " -w, --webserver [OPTIONS]      : Parameters to be passed to
> webserver\n");
> +fprintf(stdout,
> +" -x, --webserver_secondary [OPTIONS]      : Parameters to be passed to
> the secondary webserver\n");
>  mongoose_print_help();
>  #endif
>  }
> @@ -607,6 +610,10 @@ int main(int argc, char **argv)
>  char *weboptions;
>  char **av = NULL;
>  int ac = 0;
> +int opt_x = 0;
> +char *weboptions_x;
> +char **av_x = NULL;
> +int ac_x = 0;
>  #endif
>  #ifdef CONFIG_DOWNLOAD
>  int opt_d = 0;
> @@ -632,6 +639,7 @@ int main(int argc, char **argv)
>  #endif
>  #ifdef CONFIG_WEBSERVER
>  strcat(main_options, "w:");
> +strcat(main_options, "x:");
>  #endif
>  #ifdef CONFIG_HW_COMPATIBILITY
>  strcat(main_options, "H:");
> @@ -710,7 +718,7 @@ int main(int argc, char **argv)
>  /* Process options with getopt */
>  while ((c = getopt_long(argc, argv, main_options,
>  long_options, NULL)) != EOF) {
> -if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w')) {
> +if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w' && c
> != 'x')) {
>  /* An option's value starting with '-' is not allowed except
>  * for downloader, webserver, and suricatta doing their own
>  * argv parsing.
> @@ -825,6 +833,16 @@ int main(int argc, char **argv)
>  opt_w = 1;
>  free(weboptions);
>  break;
> +case 'x':
> +if (asprintf(&weboptions_x,"%s %s", argv[0], optarg) ==
> +ENOMEM_ASPRINTF) {
> +ERROR("Cannot allocate memory for webserver options.");
> +exit(EXIT_FAILURE);
> +}
> +av_x = splitargs(weboptions_x, &ac_x);
> +opt_x = 1;
> +free(weboptions_x);
> +break;
>  #endif
>  case 'c':
>  opt_c = 1;
> @@ -913,6 +931,12 @@ int main(int argc, char **argv)
>  start_mongoose);
>  freeargs(av);
>  }
> +if (opt_x) {
> +start_subprocess(SOURCE_WEBSERVER, "webserver_secondary",
> +cfgfname, ac_x, av_x,
> +start_mongoose);
> +freeargs(av_x);
> +}
>  #endif
>  
>  #if defined(CONFIG_SURICATTA)
> -- 
> 2.20.1
> 

Best regards,
Stefano Babic
darkokomljenovic2502@gmail.com Jan. 13, 2020, 5:50 p.m. UTC | #2
Hi,

On Monday, January 13, 2020 at 6:39:58 PM UTC+1, Stefano Babic wrote:
>
> Hi Darko, 
>
> On 13/01/20 09:50, darkokomlj...@gmail.com <javascript:> wrote: 
> > Hi, 
> > 
> > is it possible to run 2 instances of moongose at the same time?  
> > 
> > E.g. One on port 80, other ssl on 443. 
> > 
> > For recovery OS, which should not change, but it is possible that some 
> > firewalls don't use port 80, and some companys don't want to hussle with 
> > self signed https 
> > 
>
> This seems to me the wrong way to obtain the goal. You can already start 
> swupdate and pass the port number. You could run swupdate with -w "-p 
> 80" or "-p 443" to select which port the werbserver should listen. 
>
> If you need more ports at the same time (but this does not seem your use 
> case), the correct way seems to use a proxy to forward data to the 
> SWUpdate's webserver. 
>
Hi, do you have a recommendation for a lightweight proxy? As my general 
idea is that usually the web is used either for http, or https, and if we 
want only one recovery, with both options at the same time, this would be 
the easiest. And of course, keep it it as lightweight as possible, for a 
small recoveryOS. Agree that someone would maybe want multiple ports, but 
with this i would dare to say that we cover 90% of most used options
 

> > 
> > 
> > Possible patch, (tested, and working on my board): 
> > 
> > 
> > 
> > From 3f091b648fa5a856fb92ac8c3ad98a7b2fef0100 Mon Sep 17 00:00:00 2001 
> > From: Darko Komljenovic <darko.ko...@zenitel.com <javascript:>> 
> > Date: Mon, 13 Jan 2020 09:16:23 +0100 
> > Subject: [PATCH] Added the option to have 2 web servers at the same time 
> > 
> > Signed-off-by: Darko Komljenovic <darko.ko...@zenitel.com <javascript:>> 
>
> > --- 
> >  core/swupdate.c | 26 +++++++++++++++++++++++++- 
> >  1 file changed, 25 insertions(+), 1 deletion(-) 
> > 
> > diff --git a/core/swupdate.c b/core/swupdate.c 
> > index 38e5a56..9a3a44a 100644 
> > --- a/core/swupdate.c 
> > +++ b/core/swupdate.c 
> > @@ -105,6 +105,7 @@ static struct option long_options[] = { 
> >  #endif 
> >  #ifdef CONFIG_WEBSERVER 
> >  {"webserver", required_argument, NULL, 'w'}, 
> > +{"webserver_seconday", required_argument, NULL, 'x'}, 
>
> If more instances are required, I do not like this. It does not scale. 
> What about with a third webserver ? An array of options should be passed 
> instead of having "secondary" "third", fourth and so on. 
>
> >  #endif 
> >  {"check", no_argument, NULL, 'c'}, 
> >  {"postupdate", required_argument, NULL, 'p'}, 
> > @@ -168,6 +169,8 @@ static void usage(char *programname) 
> >  #ifdef CONFIG_WEBSERVER 
> >  fprintf(stdout, 
> >  " -w, --webserver [OPTIONS]      : Parameters to be passed to 
> > webserver\n"); 
> > +fprintf(stdout, 
> > +" -x, --webserver_secondary [OPTIONS]      : Parameters to be passed to 
> > the secondary webserver\n"); 
> >  mongoose_print_help(); 
> >  #endif 
> >  } 
> > @@ -607,6 +610,10 @@ int main(int argc, char **argv) 
> >  char *weboptions; 
> >  char **av = NULL; 
> >  int ac = 0; 
> > +int opt_x = 0; 
> > +char *weboptions_x; 
> > +char **av_x = NULL; 
> > +int ac_x = 0; 
> >  #endif 
> >  #ifdef CONFIG_DOWNLOAD 
> >  int opt_d = 0; 
> > @@ -632,6 +639,7 @@ int main(int argc, char **argv) 
> >  #endif 
> >  #ifdef CONFIG_WEBSERVER 
> >  strcat(main_options, "w:"); 
> > +strcat(main_options, "x:"); 
> >  #endif 
> >  #ifdef CONFIG_HW_COMPATIBILITY 
> >  strcat(main_options, "H:"); 
> > @@ -710,7 +718,7 @@ int main(int argc, char **argv) 
> >  /* Process options with getopt */ 
> >  while ((c = getopt_long(argc, argv, main_options, 
> >  long_options, NULL)) != EOF) { 
> > -if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w')) { 
> > +if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w' && c 
> > != 'x')) { 
> >  /* An option's value starting with '-' is not allowed except 
> >  * for downloader, webserver, and suricatta doing their own 
> >  * argv parsing. 
> > @@ -825,6 +833,16 @@ int main(int argc, char **argv) 
> >  opt_w = 1; 
> >  free(weboptions); 
> >  break; 
> > +case 'x': 
> > +if (asprintf(&weboptions_x,"%s %s", argv[0], optarg) == 
> > +ENOMEM_ASPRINTF) { 
> > +ERROR("Cannot allocate memory for webserver options."); 
> > +exit(EXIT_FAILURE); 
> > +} 
> > +av_x = splitargs(weboptions_x, &ac_x); 
> > +opt_x = 1; 
> > +free(weboptions_x); 
> > +break; 
> >  #endif 
> >  case 'c': 
> >  opt_c = 1; 
> > @@ -913,6 +931,12 @@ int main(int argc, char **argv) 
> >  start_mongoose); 
> >  freeargs(av); 
> >  } 
> > +if (opt_x) { 
> > +start_subprocess(SOURCE_WEBSERVER, "webserver_secondary", 
> > +cfgfname, ac_x, av_x, 
> > +start_mongoose); 
> > +freeargs(av_x); 
> > +} 
> >  #endif 
> >   
> >  #if defined(CONFIG_SURICATTA) 
> > --  
> > 2.20.1 
> > 
>
> Best regards, 
> Stefano Babic 
>
> -- 
> ===================================================================== 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk 
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany 
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de 
> <javascript:> 
> ===================================================================== 
>
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index 38e5a56..9a3a44a 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -105,6 +105,7 @@  static struct option long_options[] = {
 #endif
 #ifdef CONFIG_WEBSERVER
  {"webserver", required_argument, NULL, 'w'},
+ {"webserver_seconday", required_argument, NULL, 'x'},
 #endif
  {"check", no_argument, NULL, 'c'},
  {"postupdate", required_argument, NULL, 'p'},
@@ -168,6 +169,8 @@  static void usage(char *programname)
 #ifdef CONFIG_WEBSERVER
  fprintf(stdout,
  " -w, --webserver [OPTIONS]      : Parameters to be passed to 
webserver\n");
+ fprintf(stdout,
+ " -x, --webserver_secondary [OPTIONS]      : Parameters to be passed to 
the secondary webserver\n");
  mongoose_print_help();