1 const char cgi_rcs[] = "$Id: cgi.c,v 1.27 2001/09/16 17:08:54 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $
6 * Purpose : Declares functions to intercept request, generate
7 * html or gif answers, and to compose HTTP resonses.
8 * This only contains the framework functions, the
9 * actual handler functions are declared elsewhere.
11 * Functions declared include:
14 * Copyright : Written by and Copyright (C) 2001 the SourceForge
15 * IJBSWA team. http://ijbswa.sourceforge.net
17 * Based on the Internet Junkbuster originally written
18 * by and Copyright (C) 1997 Anonymous Coders and
19 * Junkbusters Corporation. http://www.junkbusters.com
21 * This program is free software; you can redistribute it
22 * and/or modify it under the terms of the GNU General
23 * Public License as published by the Free Software
24 * Foundation; either version 2 of the License, or (at
25 * your option) any later version.
27 * This program is distributed in the hope that it will
28 * be useful, but WITHOUT ANY WARRANTY; without even the
29 * implied warranty of MERCHANTABILITY or FITNESS FOR A
30 * PARTICULAR PURPOSE. See the GNU General Public
31 * License for more details.
33 * The GNU General Public License should be included with
34 * this file. If not, you can view it at
35 * http://www.gnu.org/copyleft/gpl.html
36 * or write to the Free Software Foundation, Inc., 59
37 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 * Revision 1.27 2001/09/16 17:08:54 jongfoster
42 * Moving simple CGI functions from cgi.c to new file cgisimple.c
44 * Revision 1.26 2001/09/16 15:47:37 jongfoster
45 * First version of CGI-based edit interface. This is very much a
46 * work-in-progress, and you can't actually use it to edit anything
47 * yet. You must #define FEATURE_CGI_EDIT_ACTIONS for these changes
50 * Revision 1.25 2001/09/16 15:02:35 jongfoster
51 * Adding i.j.b/robots.txt.
52 * Inlining add_stats() since it's only ever called from one place.
54 * Revision 1.24 2001/09/16 11:38:01 jongfoster
55 * Splitting fill_template() into 2 functions:
56 * template_load() loads the file
57 * template_fill() performs the PCRS regexps.
58 * This is because the CGI edit interface has a "table row"
59 * template which is used many times in the page - this
60 * change means it's only loaded from disk once.
62 * Revision 1.23 2001/09/16 11:16:05 jongfoster
63 * Better error handling in dispatch_cgi() and parse_cgi_parameters()
65 * Revision 1.22 2001/09/16 11:00:10 jongfoster
66 * New function alloc_http_response, for symmetry with free_http_response
68 * Revision 1.21 2001/09/13 23:53:03 jongfoster
69 * Support for both static and dynamically generated CGI pages.
70 * Correctly setting Last-Modified: and Expires: HTTP headers.
72 * Revision 1.20 2001/09/13 23:40:36 jongfoster
73 * (Cosmetic only) Indentation correction
75 * Revision 1.19 2001/09/13 23:31:25 jongfoster
76 * Moving image data to cgi.c rather than cgi.h.
78 * Revision 1.18 2001/08/05 16:06:20 jongfoster
79 * Modifiying "struct map" so that there are now separate header and
80 * "map_entry" structures. This means that functions which modify a
81 * map no longer need to return a pointer to the modified map.
82 * Also, it no longer reverses the order of the entries (which may be
83 * important with some advanced template substitutions).
85 * Revision 1.17 2001/08/05 15:57:38 oes
86 * Adapted finish_http_response to new list_to_text
88 * Revision 1.16 2001/08/01 21:33:18 jongfoster
89 * Changes to fill_template() that reduce memory usage without having
90 * an impact on performance. I also renamed some variables so as not
91 * to clash with the C++ keywords "new" and "template".
93 * Revision 1.15 2001/08/01 21:19:22 jongfoster
94 * Moving file version information to a separate CGI page.
96 * Revision 1.14 2001/08/01 00:19:03 jongfoster
97 * New function: map_conditional() for an if-then-else syntax.
98 * Changing to use new version of show_defines()
100 * Revision 1.13 2001/07/30 22:08:36 jongfoster
101 * Tidying up #defines:
102 * - All feature #defines are now of the form FEATURE_xxx
103 * - Permanently turned off WIN_GUI_EDIT
104 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
106 * Revision 1.12 2001/07/29 18:47:05 jongfoster
107 * Adding missing #include "loadcfg.h"
109 * Revision 1.11 2001/07/18 17:24:37 oes
110 * Changed to conform to new pcrs interface
112 * Revision 1.10 2001/07/13 13:53:13 oes
113 * Removed all #ifdef PCRS and related code
115 * Revision 1.9 2001/06/29 21:45:41 oes
116 * Indentation, CRLF->LF, Tab-> Space
118 * Revision 1.8 2001/06/29 13:21:46 oes
119 * - Cosmetics: renamed and reordered functions, variables,
120 * texts, improved comments etc
122 * - Removed ij_untrusted_url() The relevant
123 * info is now part of the "untrusted" page,
124 * which is generated by filters.c:trust_url()
126 * - Generators of content now call finish_http_response()
127 * themselves, making jcc.c:chat() a little less
130 * - Removed obsolete "Pragma: no-cache" from our headers
132 * - http_responses now know their head length
134 * - fill_template now uses the new interface to pcrs, so that
135 * - long jobs (like whole files) no longer have to be assembled
136 * in a fixed size buffer
137 * - the new T (trivial) option is used, and the replacement may
138 * contain Perl syntax backrefs without confusing pcrs
140 * - Introduced default_exports() which generates a set of exports
141 * common to all CGIs and other content generators
143 * - Introduced convenience function map_block_killer()
145 * - Introduced convenience function make_menu()
147 * - Introduced CGI-like function error_response() which generates
148 * the "No such domain" and "Connect failed" messages using the
151 * - cgi_show_url_info:
152 * - adapted to new CGI features
153 * - form and answers now generated from same template
154 * - http:// prefix in URL now OK
157 * - adapted to new CGI features
158 * - no longer uses csp->init_proxy_args
161 * - moved menu generation to make_menu()
163 * - add_stats now writes single export map entries instead
166 * - Moved redirect_url() to filters.c
168 * - Fixed mem leak in free_http_response(), map_block_killer(),
170 * - Removed logentry from cancelled commit
172 * Revision 1.7 2001/06/09 10:51:58 jongfoster
173 * Changing "show URL info" handler to new style.
174 * Changing BUFSIZ ==> BUFFER_SIZE
176 * Revision 1.6 2001/06/07 23:05:19 jongfoster
177 * Removing code related to old forward and ACL files.
179 * Revision 1.5 2001/06/05 19:59:16 jongfoster
180 * Fixing multiline character string (a GCC-only "feature"), and snprintf (it's _snprintf under VC++).
182 * Revision 1.4 2001/06/04 10:41:52 swa
183 * show version string of cgi.h and cgi.c
185 * Revision 1.3 2001/06/03 19:12:16 oes
186 * introduced new cgi handling
188 * No revisions before 1.3
190 **********************************************************************/
196 #include <sys/types.h>
203 #define snprintf _snprintf
204 #endif /* def _WIN32 */
212 #include "miscutil.h"
213 #include "cgisimple.h"
214 #ifdef FEATURE_CGI_EDIT_ACTIONS
216 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
218 const char cgi_h_rcs[] = CGI_H_VERSION;
220 const struct cgi_dispatcher cgi_dispatcher[] = {
223 "HIDE Sends a robots.txt file to tell robots to go away." },
226 "Show information about the current configuration" },
228 13, cgi_show_url_info,
229 "Show which actions apply to a URL and why" },
231 12, cgi_show_version,
232 "Show the source code version numbers" },
235 "HIDE Send the transparent or \"Junkbuster\" gif" },
236 #ifdef FEATURE_CGI_EDIT_ACTIONS
237 { "edit-actions-list",
238 17, cgi_edit_actions_list,
239 "Edit the actions list" },
240 { "edit-actions-submit",
241 19, cgi_edit_actions_submit,
242 "HIDE Change the actions for (a) specified URL(s)" },
244 12, cgi_edit_actions,
245 "HIDE Edit the actions for (a) specified URL(s)" },
246 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
249 "Junkbuster main page" },
250 { NULL, 0, NULL, NULL }
257 * Hint: You can encode your own GIFs like that:
258 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
261 const char image_junkbuster_gif_data[] =
262 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
263 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
264 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
265 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
266 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
267 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
268 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
271 const int image_junkbuster_gif_length = sizeof(image_junkbuster_gif_data) - 1;
274 const char image_blank_gif_data[] =
275 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
276 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
277 "\000\001\000\000\002\002D\001\000;";
279 const int image_blank_gif_length = sizeof(image_blank_gif_data) - 1;
282 /*********************************************************************
284 * Function : dispatch_cgi
286 * Description : Checks if a request URL has either the magical hostname
287 * i.j.b or matches HOME_PAGE_URL/config/. If so, it parses
288 * the (rest of the) path as a cgi name plus query string,
289 * prepares a map that maps CGI parameter names to their values,
290 * initializes the http_response struct, and calls the
291 * relevant CGI handler function.
294 * 1 : csp = Current client state (buffers, headers, etc...)
296 * Returns : http_response if match, NULL if nonmatch or handler fail
298 *********************************************************************/
299 struct http_response *dispatch_cgi(struct client_state *csp)
301 char *argstring = NULL;
302 const struct cgi_dispatcher *d;
303 struct map *param_list;
304 struct http_response *rsp;
307 * Should we intercept ?
310 /* Either the host matches CGI_PREFIX_HOST ..*/
311 if (0 == strcmpic(csp->http->host, CGI_PREFIX_HOST))
313 /* ..then the path will all be for us */
314 argstring = csp->http->path;
316 /* Or it's the host part HOME_PAGE_URL, and the path /config ? */
317 else if ( (0 == strcmpic(csp->http->host, HOME_PAGE_URL + 7 ))
318 && (0 == strncmpic(csp->http->path,"/config", 7))
319 && ((csp->http->path[7] == '/') || (csp->http->path[7] == '\0')))
321 /* then it's everything following "/config" */
322 argstring = csp->http->path + 7;
330 * This is a CGI call.
333 /* Get mem for response or fail*/
334 if (NULL == (rsp = alloc_http_response()))
340 /* Remove leading slash */
341 if (*argstring == '/')
346 log_error(LOG_LEVEL_GPC, "%s%s cgi call", csp->http->hostport, csp->http->path);
347 log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 200 3",
348 csp->ip_addr_str, csp->http->cmd);
350 /* Find and start the right CGI function*/
351 for (d = cgi_dispatcher; d->handler; d++)
353 if (strncmp(argstring, d->name, d->name_length) == 0)
355 if (NULL == (param_list =
356 parse_cgi_parameters(argstring + d->name_length)))
358 free_map(param_list);
359 free_http_response(rsp);
362 if ((d->handler)(csp, rsp, param_list))
364 free_map(param_list);
365 free_http_response(rsp);
369 free_map(param_list);
370 return(finish_http_response(rsp));
374 /* Can't get here, since cgi_default will match all requests */
375 free_http_response(rsp);
381 /*********************************************************************
383 * Function : parse_cgi_parameters
385 * Description : Parse a URL-encoded argument string into name/value
386 * pairs and store them in a struct map list.
389 * 1 : string = string to be parsed
391 * Returns : pointer to param list, or NULL if out of memory.
393 *********************************************************************/
394 struct map *parse_cgi_parameters(char *argstring)
397 char *vector[BUFFER_SIZE];
399 struct map *cgi_params;
401 if (NULL == (cgi_params = new_map()))
406 if(*argstring == '?')
410 if (NULL == (tmp = strdup(argstring)))
412 free_map(cgi_params);
416 pairs = ssplit(tmp, "&", vector, SZ(vector), 1, 1);
418 for (i = 0; i < pairs; i++)
420 if ((NULL != (p = strchr(vector[i], '='))) && (*(p+1) != '\0'))
423 map(cgi_params, url_decode(vector[i]), 0, url_decode(++p), 0);
433 /*********************************************************************
435 * Function : error_response
437 * Description : returns an http_response that explains the reason
438 * why a request failed.
441 * 1 : csp = Current client state (buffers, headers, etc...)
442 * 2 : templatename = Which template should be used for the answer
443 * 3 : errno = system error number
445 * Returns : NULL if no memory, else http_response
447 *********************************************************************/
448 struct http_response *error_response(struct client_state *csp, const char *templatename, int err)
450 struct http_response *rsp;
451 struct map * exports = default_exports(csp, NULL);
453 if (NULL == (rsp = alloc_http_response()))
458 map(exports, "host-html", 1, html_encode(csp->http->host), 0);
459 map(exports, "hostport", 1, csp->http->hostport, 1);
460 map(exports, "hostport-html", 1, html_encode(csp->http->hostport), 0);
461 map(exports, "path", 1, csp->http->path, 1);
462 map(exports, "path-html", 1, html_encode(csp->http->path), 0);
463 map(exports, "error", 1, safe_strerror(err), 0);
464 map(exports, "host-ip", 1, csp->http->host_ip_addr_str, 1);
466 rsp->body = template_load(csp, templatename);
467 template_fill(&rsp->body, exports);
470 if (!strcmp(templatename, "no-such-domain"))
472 rsp->status = strdup("404 No such domain");
474 else if (!strcmp(templatename, "connect-failed"))
476 rsp->status = strdup("503 Connect failed");
479 return(finish_http_response(rsp));
484 /*********************************************************************
486 * Function : get_http_time
488 * Description : Get the time in a format suitable for use in a
489 * HTTP header - e.g.:
490 * "Sun, 06 Nov 1994 08:49:37 GMT"
493 * 1 : time_offset = Time returned will be current time
494 * plus this number of seconds.
495 * 2 : buf = Destination for result. Must be long enough
496 * to hold 29 characters plus a trailing zero.
500 *********************************************************************/
501 void get_http_time(int time_offset, char *buf)
503 static const char day_names[7][4] =
504 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
505 static const char month_names[12][4] =
506 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
507 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
514 time(¤t_time); /* get current time */
516 current_time += time_offset;
518 /* get and save the gmt */
519 t = gmtime(¤t_time);
521 /* Format: "Sun, 06 Nov 1994 08:49:37 GMT" */
523 "%s, %02d %s %4d %02d:%02d:%02d GMT",
524 day_names[t->tm_wday],
526 month_names[t->tm_mon],
537 /*********************************************************************
539 * Function : finish_http_response
541 * Description : Fill in the missing headers in an http response,
542 * and flatten the headers to an http head.
545 * 1 : rsp = pointer to http_response to be processed
547 * Returns : http_response, or NULL on failiure
549 *********************************************************************/
550 struct http_response *finish_http_response(struct http_response *rsp)
552 char buf[BUFFER_SIZE];
555 * Fill in the HTTP Status
557 sprintf(buf, "HTTP/1.0 %s", rsp->status ? rsp->status : "200 OK");
558 enlist_first(rsp->headers, buf);
561 * Set the Content-Length
563 if (rsp->content_length == 0)
565 rsp->content_length = rsp->body ? strlen(rsp->body) : 0;
567 sprintf(buf, "Content-Length: %d", rsp->content_length);
568 enlist(rsp->headers, buf);
571 * Fill in the default headers:
573 * Content-Type: default to text/html if not already specified.
574 * Date: set to current date/time.
575 * Last-Modified: set to date/time the page was last changed.
576 * Expires: set to date/time page next needs reloading.
577 * Cache-Control: set to "no-cache" if applicable.
579 * See http://www.w3.org/Protocols/rfc2068/rfc2068
581 enlist_unique(rsp->headers, "Content-Type: text/html", 13);
586 * Set Expires to about 10 min into the future so it'll get reloaded
587 * occasionally, e.g. if IJB gets upgraded.
590 get_http_time(0, buf);
591 enlist_unique_header(rsp->headers, "Date", buf);
593 /* Some date in the past. */
594 enlist_unique_header(rsp->headers, "Last-Modified", "Sat, 17 Jun 2000 12:00:00 GMT");
596 get_http_time(10 * 60, buf); /* 10 * 60sec = 10 minutes */
597 enlist_unique_header(rsp->headers, "Expires", buf);
602 * Compliant browsers should not cache this due to the "Cache-Control"
603 * setting. However, to be certain, we also set both "Last-Modified"
604 * and "Expires" to the current time.
606 enlist_unique_header(rsp->headers, "Cache-Control", "no-cache");
607 get_http_time(0, buf);
608 enlist_unique_header(rsp->headers, "Date", buf);
609 enlist_unique_header(rsp->headers, "Last-Modified", buf);
610 enlist_unique_header(rsp->headers, "Expires", buf);
617 if (NULL == (rsp->head = list_to_text(rsp->headers)))
619 free_http_response(rsp);
622 rsp->head_length = strlen(rsp->head);
629 /*********************************************************************
631 * Function : alloc_http_response
633 * Description : Allocates a new http_response structure.
637 * Returns : pointer to a new http_response, or NULL.
639 *********************************************************************/
640 struct http_response *alloc_http_response(void)
642 return (struct http_response *) zalloc(sizeof(struct http_response));
647 /*********************************************************************
649 * Function : free_http_response
651 * Description : Free the memory occupied by an http_response
652 * and its depandant structures.
655 * 1 : rsp = pointer to http_response to be freed
659 *********************************************************************/
660 void free_http_response(struct http_response *rsp)
667 destroy_list(rsp->headers);
674 /*********************************************************************
676 * Function : fill_template
678 * Description : CGI support function that loads a given HTML
679 * template from the confdir, ignoring comment
683 * 1 : csp = Current client state (buffers, headers, etc...)
684 * 3 : template = name of the HTML template to be used
686 * Returns : char * with loaded template, or NULL if failure
688 *********************************************************************/
689 char *template_load(struct client_state *csp, const char *templatename)
691 char buf[BUFFER_SIZE];
692 char *file_buffer = NULL;
696 * Open template file or fail
698 snprintf(buf, BUFFER_SIZE, "%s/templates/%s", csp->config->confdir, templatename);
700 if(NULL == (fp = fopen(buf, "r")))
702 log_error(LOG_LEVEL_ERROR, "error loading template %s: %E", buf);
708 * Read the file, ignoring comments
710 while (fgets(buf, BUFFER_SIZE, fp))
712 /* skip lines starting with '#' */
718 file_buffer = strsav(file_buffer, buf);
727 /*********************************************************************
729 * Function : fill_template
731 * Description : CGI support function that fills in a pre-loaded
732 * HTML template by replacing @name@ with value using
733 * pcrs, for each item in the output map.
735 * Note that a leading '$' charachter in the export map's
736 * values will be stripped and toggle on backreference
740 * 1 : template_ptr = IN: Template to be filled out.
742 * OUT: Filled out template.
743 * Caller must free().
744 * 2 : exports = map with fill in symbol -> name pairs
748 *********************************************************************/
749 void template_fill(char **template_ptr, struct map *exports)
753 char buf[BUFFER_SIZE];
754 char *tmp_out_buffer;
760 assert(template_ptr);
761 assert(*template_ptr);
764 file_buffer = *template_ptr;
765 size = strlen(file_buffer) + 1;
768 * Assemble pcrs joblist from exports map
770 for (m = exports->first; m != NULL; m = m->next)
775 * First character of name is '$', so remove this flag
776 * character and allow backreferences ($1 etc) in the
777 * "replace with" text.
779 snprintf(buf, BUFFER_SIZE, "%s", m->name + 1);
785 * Treat the "replace with" text as a literal string -
786 * no quoting needed, no backreferences allowed.
787 * ("Trivial" ['T'] flag).
791 /* Enclose name in @@ */
792 snprintf(buf, BUFFER_SIZE, "@%s@", m->name);
796 log_error(LOG_LEVEL_CGI, "Substituting: s/%s/%s/%s", buf, m->value, flags);
798 /* Make and run job. */
799 job = pcrs_compile(buf, m->value, flags, &error);
802 log_error(LOG_LEVEL_ERROR, "Error compiling template fill job %s: %d", m->name, error);
806 pcrs_execute(job, file_buffer, size, &tmp_out_buffer, &size);
807 if (NULL != tmp_out_buffer)
810 file_buffer = tmp_out_buffer;
819 *template_ptr = file_buffer;
824 /*********************************************************************
826 * Function : default_exports
828 * Description : returns a struct map list that contains exports
829 * which are common to all CGI functions.
832 * 1 : exports = Structure to write output to. This
833 * structure should be newly allocated and will be
835 * 1 : csp = Current client state (buffers, headers, etc...)
836 * 2 : caller = name of CGI who calls us and which should
837 * be excluded from the generated menu.
838 * Returns : NULL if no memory, else map
840 *********************************************************************/
841 struct map *default_exports(const struct client_state *csp, const char *caller)
844 struct map * exports = new_map();
846 map(exports, "version", 1, VERSION, 1);
847 map(exports, "my-ip-address", 1, csp->my_ip_addr_str ? csp->my_ip_addr_str : "unknown", 1);
848 map(exports, "my-hostname", 1, csp->my_hostname ? csp->my_hostname : "unknown", 1);
849 map(exports, "admin-address", 1, csp->config->admin_address ? csp->config->admin_address : "fill@me.in.please", 1);
850 map(exports, "homepage", 1, HOME_PAGE_URL, 1);
851 map(exports, "default-cgi", 1, HOME_PAGE_URL "/config", 1);
852 map(exports, "menu", 1, make_menu(caller), 0);
853 map(exports, "code-status", 1, CODE_STATUS, 1);
855 snprintf(buf, 20, "%d", csp->config->hport);
856 map(exports, "my-port", 1, buf, 1);
858 if(!strcmp(CODE_STATUS, "stable"))
860 map_block_killer(exports, "unstable");
863 if(csp->config->proxy_info_url != NULL)
865 map(exports, "proxy-info-url", 1, csp->config->proxy_info_url, 1);
869 map_block_killer(exports, "have-proxy-info");
877 /*********************************************************************
879 * Function : map_block_killer
881 * Description : Convenience function.
882 * Adds a "killer" for the conditional HTML-template
883 * block <name>, i.e. a substitution of the regex
884 * "if-<name>-start.*if-<name>-end" to the given
888 * 1 : exports = map to extend
889 * 2 : name = name of conditional block
891 * Returns : extended map
893 *********************************************************************/
894 void map_block_killer(struct map *exports, const char *name)
896 char buf[1000]; /* Will do, since the names are hardwired */
898 snprintf(buf, 1000, "if-%s-start.*if-%s-end", name, name);
899 map(exports, buf, 1, "", 1);
904 /*********************************************************************
906 * Function : map_conditional
908 * Description : Convenience function.
909 * Adds an "if-then-else" for the conditional HTML-template
910 * block <name>, i.e. a substitution of the form:
917 * The control structure and one of the alternatives
921 * 1 : exports = map to extend
922 * 2 : name = name of conditional block
923 * 3 : choose_first = nonzero for first, zero for second.
925 * Returns : extended map
927 *********************************************************************/
928 void map_conditional(struct map *exports, const char *name, int choose_first)
930 char buf[1000]; /* Will do, since the names are hardwired */
932 snprintf(buf, 1000, (choose_first
933 ? "else-not-%s@.*@endif-%s"
934 : "if-%s-then@.*@else-not-%s"),
936 map(exports, buf, 1, "", 1);
938 snprintf(buf, 1000, (choose_first ? "if-%s-then" : "endif-%s"), name);
939 map(exports, buf, 1, "", 1);
944 /*********************************************************************
946 * Function : make_menu
948 * Description : Returns an HTML-formatted menu of the available
949 * unhidden CGIs, excluding the one given in <self>.
951 * Parameters : self = name of CGI to leave out, can be NULL
953 * Returns : menu string
955 *********************************************************************/
956 char *make_menu(const char *self)
958 const struct cgi_dispatcher *d;
959 char buf[BUFFER_SIZE];
964 self = "NO-SUCH-CGI!";
967 /* List available unhidden CGI's and export as "other-cgis" */
968 for (d = cgi_dispatcher; d->handler; d++)
970 if (strncmp(d->description, "HIDE", 4) && strcmp(d->name, self))
972 snprintf(buf, BUFFER_SIZE, "<li><a href=%s/config/%s>%s</a></li>\n",
973 HOME_PAGE_URL, d->name, d->description);
974 result = strsav(result, buf);
982 /*********************************************************************
984 * Function : dump_map
986 * Description : HTML-dump a map for debugging
989 * 1 : the_map = map to dump
991 * Returns : string with HTML
993 *********************************************************************/
994 char *dump_map(const struct map *the_map)
996 struct map_entry *cur_entry = the_map->first;
999 ret = strsav(ret, "<table>\n");
1003 ret = strsav(ret, "<tr><td><b>");
1004 ret = strsav(ret, cur_entry->name);
1005 ret = strsav(ret, "</b></td><td>");
1006 ret = strsav(ret, cur_entry->value);
1007 ret = strsav(ret, "</td></tr>\n");
1008 cur_entry = cur_entry->next;
1011 ret = strsav(ret, "</table>\n");