Fossil SCM

Added ui/server/cgi --mainmenu FILE option, and CGI wrapper script mainmenu: option, to override the mainmenu setting, similar to how --skin/skin: overrides the skin.

stephan 2021-02-05 10:36 trunk
Commit bcca09106b2aa813fca1aa4691d6e06ec1b93ceb9376bd535beea7453da51bba
3 files changed +23 -1 +24 -1 +11
+23 -1
--- src/main.c
+++ src/main.c
@@ -2143,10 +2143,13 @@
21432143
** an unconditional redirect to URL is taken.
21442144
**
21452145
** jsmode: VALUE Specifies the delivery mode for JavaScript
21462146
** files. See the help text for the --jsmode
21472147
** flag of the http command.
2148
+**
2149
+** mainmenu: FILE Override the mainmenu config setting with the
2150
+** contents of the given file.
21482151
**
21492152
** Most CGI files contain only a "repository:" line. It is uncommon to
21502153
** use any other option.
21512154
**
21522155
** See also: [[http]], [[server]], [[winsrv]]
@@ -2333,10 +2336,21 @@
23332336
** requirements of any given page.
23342337
*/
23352338
builtin_set_js_delivery_mode(blob_str(&value),0);
23362339
blob_reset(&value);
23372340
continue;
2341
+ }
2342
+ if( blob_eq(&key, "mainmenu:") && blob_token(&line, &value) ){
2343
+ /* mainmenu: FILENAME
2344
+ **
2345
+ ** Use the contents of FILENAME as the value of the site's
2346
+ ** "mainmenu" setting, overriding the contents (for this
2347
+ ** request) of the db-side setting or the hard-coded default.
2348
+ */
2349
+ style_default_mainmenu_override(blob_str(&value));
2350
+ blob_reset(&value);
2351
+ continue;
23382352
}
23392353
if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
23402354
/* cgi-debug: FILENAME
23412355
**
23422356
** Causes output from cgi_debug() and CGIDEBUG(()) calls to go
@@ -2797,10 +2811,12 @@
27972811
** -P|--port TCPPORT listen to request on port TCPPORT
27982812
** --th-trace trace TH1 execution (for debugging purposes)
27992813
** --repolist If REPOSITORY is dir, URL "/" lists repos.
28002814
** --scgi Accept SCGI rather than HTTP
28012815
** --skin LABEL Use override skin LABEL
2816
+** --mainmenu FILE Override the mainmenu config setting with the contents
2817
+** of the given file.
28022818
** --usepidkey Use saved encryption key from parent process. This is
28032819
** only necessary when using SEE on Windows.
28042820
**
28052821
** See also: [[cgi]], [[http]], [[winsrv]]
28062822
*/
@@ -2820,10 +2836,11 @@
28202836
const char *zAltBase; /* Argument to the --baseurl option */
28212837
const char *zFileGlob; /* Static content must match this */
28222838
char *zIpAddr = 0; /* Bind to this IP address */
28232839
int fCreate = 0; /* The --create flag */
28242840
const char *zInitPage = 0; /* Start on this page. --page option */
2841
+ const char *zMainMenu = 0; /* --mainmenu option */
28252842
28262843
#if defined(_WIN32)
28272844
const char *zStopperFile; /* Name of file used to terminate server */
28282845
zStopperFile = find_option("stopper", 0, 1);
28292846
#endif
@@ -2868,11 +2885,16 @@
28682885
}
28692886
if( find_option("localhost", 0, 0)!=0 ){
28702887
flags |= HTTP_SERVER_LOCALHOST;
28712888
}
28722889
g.zCkoutAlias = find_option("ckout-alias",0,1);
2873
-
2890
+ zMainMenu = find_option("mainmenu",0,1);
2891
+ if( zMainMenu!=0 ){
2892
+ if(0!=style_default_mainmenu_override(zMainMenu)){
2893
+ fossil_fatal("Cannot read --mainmenu file %s", zMainMenu);
2894
+ }
2895
+ }
28742896
/* We should be done with options.. */
28752897
verify_all_options();
28762898
28772899
if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
28782900
if( isUiCmd ){
28792901
--- src/main.c
+++ src/main.c
@@ -2143,10 +2143,13 @@
2143 ** an unconditional redirect to URL is taken.
2144 **
2145 ** jsmode: VALUE Specifies the delivery mode for JavaScript
2146 ** files. See the help text for the --jsmode
2147 ** flag of the http command.
 
 
 
2148 **
2149 ** Most CGI files contain only a "repository:" line. It is uncommon to
2150 ** use any other option.
2151 **
2152 ** See also: [[http]], [[server]], [[winsrv]]
@@ -2333,10 +2336,21 @@
2333 ** requirements of any given page.
2334 */
2335 builtin_set_js_delivery_mode(blob_str(&value),0);
2336 blob_reset(&value);
2337 continue;
 
 
 
 
 
 
 
 
 
 
 
2338 }
2339 if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
2340 /* cgi-debug: FILENAME
2341 **
2342 ** Causes output from cgi_debug() and CGIDEBUG(()) calls to go
@@ -2797,10 +2811,12 @@
2797 ** -P|--port TCPPORT listen to request on port TCPPORT
2798 ** --th-trace trace TH1 execution (for debugging purposes)
2799 ** --repolist If REPOSITORY is dir, URL "/" lists repos.
2800 ** --scgi Accept SCGI rather than HTTP
2801 ** --skin LABEL Use override skin LABEL
 
 
2802 ** --usepidkey Use saved encryption key from parent process. This is
2803 ** only necessary when using SEE on Windows.
2804 **
2805 ** See also: [[cgi]], [[http]], [[winsrv]]
2806 */
@@ -2820,10 +2836,11 @@
2820 const char *zAltBase; /* Argument to the --baseurl option */
2821 const char *zFileGlob; /* Static content must match this */
2822 char *zIpAddr = 0; /* Bind to this IP address */
2823 int fCreate = 0; /* The --create flag */
2824 const char *zInitPage = 0; /* Start on this page. --page option */
 
2825
2826 #if defined(_WIN32)
2827 const char *zStopperFile; /* Name of file used to terminate server */
2828 zStopperFile = find_option("stopper", 0, 1);
2829 #endif
@@ -2868,11 +2885,16 @@
2868 }
2869 if( find_option("localhost", 0, 0)!=0 ){
2870 flags |= HTTP_SERVER_LOCALHOST;
2871 }
2872 g.zCkoutAlias = find_option("ckout-alias",0,1);
2873
 
 
 
 
 
2874 /* We should be done with options.. */
2875 verify_all_options();
2876
2877 if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
2878 if( isUiCmd ){
2879
--- src/main.c
+++ src/main.c
@@ -2143,10 +2143,13 @@
2143 ** an unconditional redirect to URL is taken.
2144 **
2145 ** jsmode: VALUE Specifies the delivery mode for JavaScript
2146 ** files. See the help text for the --jsmode
2147 ** flag of the http command.
2148 **
2149 ** mainmenu: FILE Override the mainmenu config setting with the
2150 ** contents of the given file.
2151 **
2152 ** Most CGI files contain only a "repository:" line. It is uncommon to
2153 ** use any other option.
2154 **
2155 ** See also: [[http]], [[server]], [[winsrv]]
@@ -2333,10 +2336,21 @@
2336 ** requirements of any given page.
2337 */
2338 builtin_set_js_delivery_mode(blob_str(&value),0);
2339 blob_reset(&value);
2340 continue;
2341 }
2342 if( blob_eq(&key, "mainmenu:") && blob_token(&line, &value) ){
2343 /* mainmenu: FILENAME
2344 **
2345 ** Use the contents of FILENAME as the value of the site's
2346 ** "mainmenu" setting, overriding the contents (for this
2347 ** request) of the db-side setting or the hard-coded default.
2348 */
2349 style_default_mainmenu_override(blob_str(&value));
2350 blob_reset(&value);
2351 continue;
2352 }
2353 if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
2354 /* cgi-debug: FILENAME
2355 **
2356 ** Causes output from cgi_debug() and CGIDEBUG(()) calls to go
@@ -2797,10 +2811,12 @@
2811 ** -P|--port TCPPORT listen to request on port TCPPORT
2812 ** --th-trace trace TH1 execution (for debugging purposes)
2813 ** --repolist If REPOSITORY is dir, URL "/" lists repos.
2814 ** --scgi Accept SCGI rather than HTTP
2815 ** --skin LABEL Use override skin LABEL
2816 ** --mainmenu FILE Override the mainmenu config setting with the contents
2817 ** of the given file.
2818 ** --usepidkey Use saved encryption key from parent process. This is
2819 ** only necessary when using SEE on Windows.
2820 **
2821 ** See also: [[cgi]], [[http]], [[winsrv]]
2822 */
@@ -2820,10 +2836,11 @@
2836 const char *zAltBase; /* Argument to the --baseurl option */
2837 const char *zFileGlob; /* Static content must match this */
2838 char *zIpAddr = 0; /* Bind to this IP address */
2839 int fCreate = 0; /* The --create flag */
2840 const char *zInitPage = 0; /* Start on this page. --page option */
2841 const char *zMainMenu = 0; /* --mainmenu option */
2842
2843 #if defined(_WIN32)
2844 const char *zStopperFile; /* Name of file used to terminate server */
2845 zStopperFile = find_option("stopper", 0, 1);
2846 #endif
@@ -2868,11 +2885,16 @@
2885 }
2886 if( find_option("localhost", 0, 0)!=0 ){
2887 flags |= HTTP_SERVER_LOCALHOST;
2888 }
2889 g.zCkoutAlias = find_option("ckout-alias",0,1);
2890 zMainMenu = find_option("mainmenu",0,1);
2891 if( zMainMenu!=0 ){
2892 if(0!=style_default_mainmenu_override(zMainMenu)){
2893 fossil_fatal("Cannot read --mainmenu file %s", zMainMenu);
2894 }
2895 }
2896 /* We should be done with options.. */
2897 verify_all_options();
2898
2899 if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
2900 if( isUiCmd ){
2901
+24 -1
--- src/style.c
+++ src/style.c
@@ -618,10 +618,31 @@
618618
** Return the default menu
619619
*/
620620
const char *style_default_mainmenu(void){
621621
return zDfltMainMenu;
622622
}
623
+
624
+/*
625
+** Main menu setting value overridden by the server/ui/cgi --mainmenu
626
+** CLI flag or the "mainmenu:" CGI wrapper script config option.
627
+*/
628
+static const char * zOverrideMainMenu = 0;
629
+/*
630
+** Sets the contents of the given filename (of type ExtFILE) to
631
+** override the "mainmenu" site config setting. Returns 0 on success,
632
+** non-0 if the file cannot be stat'd.
633
+*/
634
+int style_default_mainmenu_override(const char *zFilename){
635
+ if(file_size(zFilename, ExtFILE)<0){
636
+ return 1;
637
+ }else{
638
+ Blob content = empty_blob;
639
+ blob_read_from_file(&content, zFilename, ExtFILE);
640
+ zOverrideMainMenu = blob_str(&content);
641
+ return 0;
642
+ }
643
+}
623644
624645
/*
625646
** Given a URL path, extract the first element as a "feature" name,
626647
** used as the <body class="FEATURE"> value by default, though
627648
** later-running code may override this, typically to group multiple
@@ -682,11 +703,13 @@
682703
Th_Store("csrf_token", g.zCsrfToken);
683704
Th_Store("release_version", RELEASE_VERSION);
684705
Th_Store("manifest_version", MANIFEST_VERSION);
685706
Th_Store("manifest_date", MANIFEST_DATE);
686707
Th_Store("compiler_name", COMPILER_NAME);
687
- Th_Store("mainmenu", db_get("mainmenu", style_default_mainmenu()));
708
+ Th_Store("mainmenu", zOverrideMainMenu
709
+ ? zOverrideMainMenu
710
+ : db_get("mainmenu", style_default_mainmenu()));
688711
url_var("stylesheet", "css", "style.css");
689712
image_url_var("logo");
690713
image_url_var("background");
691714
if( !login_is_nobody() ){
692715
Th_Store("login", g.zLogin);
693716
--- src/style.c
+++ src/style.c
@@ -618,10 +618,31 @@
618 ** Return the default menu
619 */
620 const char *style_default_mainmenu(void){
621 return zDfltMainMenu;
622 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
624 /*
625 ** Given a URL path, extract the first element as a "feature" name,
626 ** used as the <body class="FEATURE"> value by default, though
627 ** later-running code may override this, typically to group multiple
@@ -682,11 +703,13 @@
682 Th_Store("csrf_token", g.zCsrfToken);
683 Th_Store("release_version", RELEASE_VERSION);
684 Th_Store("manifest_version", MANIFEST_VERSION);
685 Th_Store("manifest_date", MANIFEST_DATE);
686 Th_Store("compiler_name", COMPILER_NAME);
687 Th_Store("mainmenu", db_get("mainmenu", style_default_mainmenu()));
 
 
688 url_var("stylesheet", "css", "style.css");
689 image_url_var("logo");
690 image_url_var("background");
691 if( !login_is_nobody() ){
692 Th_Store("login", g.zLogin);
693
--- src/style.c
+++ src/style.c
@@ -618,10 +618,31 @@
618 ** Return the default menu
619 */
620 const char *style_default_mainmenu(void){
621 return zDfltMainMenu;
622 }
623
624 /*
625 ** Main menu setting value overridden by the server/ui/cgi --mainmenu
626 ** CLI flag or the "mainmenu:" CGI wrapper script config option.
627 */
628 static const char * zOverrideMainMenu = 0;
629 /*
630 ** Sets the contents of the given filename (of type ExtFILE) to
631 ** override the "mainmenu" site config setting. Returns 0 on success,
632 ** non-0 if the file cannot be stat'd.
633 */
634 int style_default_mainmenu_override(const char *zFilename){
635 if(file_size(zFilename, ExtFILE)<0){
636 return 1;
637 }else{
638 Blob content = empty_blob;
639 blob_read_from_file(&content, zFilename, ExtFILE);
640 zOverrideMainMenu = blob_str(&content);
641 return 0;
642 }
643 }
644
645 /*
646 ** Given a URL path, extract the first element as a "feature" name,
647 ** used as the <body class="FEATURE"> value by default, though
648 ** later-running code may override this, typically to group multiple
@@ -682,11 +703,13 @@
703 Th_Store("csrf_token", g.zCsrfToken);
704 Th_Store("release_version", RELEASE_VERSION);
705 Th_Store("manifest_version", MANIFEST_VERSION);
706 Th_Store("manifest_date", MANIFEST_DATE);
707 Th_Store("compiler_name", COMPILER_NAME);
708 Th_Store("mainmenu", zOverrideMainMenu
709 ? zOverrideMainMenu
710 : db_get("mainmenu", style_default_mainmenu()));
711 url_var("stylesheet", "css", "style.css");
712 image_url_var("logo");
713 image_url_var("background");
714 if( !login_is_nobody() ){
715 Th_Store("login", g.zLogin);
716
+11
--- www/cgi.wiki
+++ www/cgi.wiki
@@ -135,10 +135,21 @@
135135
This parameter can be repeated as many times as necessary.
136136
137137
<h2 id="HOME">HOME: <i>PATH</i></h2>
138138
139139
This parameter is a short-hand for "<b>setenv HOME <i>PATH</i></b>".
140
+
141
+<h2 id="mainmenu">mainmenu: <i>FILE</i></h2>
142
+
143
+This parameter causes the contents of the given file to override the
144
+site's <tt>mainmenu</tt> configuration setting, much in the same way
145
+that the <tt>skin</tt> setting overrides the skin. This can be used to
146
+apply a common main menu to a number of sites, and centrally maintain
147
+it, without having to copy its contents into each site. Note, however,
148
+that the contents of this setting are not stored in the repository and
149
+will not be cloned along with the repository.
150
+
140151
141152
<h2 id="cgi-debug">cgi-debug: <i>FILE</i></h2>
142153
143154
Cause CGI-related debugging information to be appended in <i>FILE</i>. Use
144155
this to help debug CGI problems.
145156
--- www/cgi.wiki
+++ www/cgi.wiki
@@ -135,10 +135,21 @@
135 This parameter can be repeated as many times as necessary.
136
137 <h2 id="HOME">HOME: <i>PATH</i></h2>
138
139 This parameter is a short-hand for "<b>setenv HOME <i>PATH</i></b>".
 
 
 
 
 
 
 
 
 
 
 
140
141 <h2 id="cgi-debug">cgi-debug: <i>FILE</i></h2>
142
143 Cause CGI-related debugging information to be appended in <i>FILE</i>. Use
144 this to help debug CGI problems.
145
--- www/cgi.wiki
+++ www/cgi.wiki
@@ -135,10 +135,21 @@
135 This parameter can be repeated as many times as necessary.
136
137 <h2 id="HOME">HOME: <i>PATH</i></h2>
138
139 This parameter is a short-hand for "<b>setenv HOME <i>PATH</i></b>".
140
141 <h2 id="mainmenu">mainmenu: <i>FILE</i></h2>
142
143 This parameter causes the contents of the given file to override the
144 site's <tt>mainmenu</tt> configuration setting, much in the same way
145 that the <tt>skin</tt> setting overrides the skin. This can be used to
146 apply a common main menu to a number of sites, and centrally maintain
147 it, without having to copy its contents into each site. Note, however,
148 that the contents of this setting are not stored in the repository and
149 will not be cloned along with the repository.
150
151
152 <h2 id="cgi-debug">cgi-debug: <i>FILE</i></h2>
153
154 Cause CGI-related debugging information to be appended in <i>FILE</i>. Use
155 this to help debug CGI problems.
156

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button