1 const char cgi_rcs[] = "$Id: cgi.c,v 1.26 2001/09/16 15:47:37 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.26 2001/09/16 15:47:37 jongfoster
42 * First version of CGI-based edit interface. This is very much a
43 * work-in-progress, and you can't actually use it to edit anything
44 * yet. You must #define FEATURE_CGI_EDIT_ACTIONS for these changes
47 * Revision 1.25 2001/09/16 15:02:35 jongfoster
48 * Adding i.j.b/robots.txt.
49 * Inlining add_stats() since it's only ever called from one place.
51 * Revision 1.24 2001/09/16 11:38:01 jongfoster
52 * Splitting fill_template() into 2 functions:
53 * template_load() loads the file
54 * template_fill() performs the PCRS regexps.
55 * This is because the CGI edit interface has a "table row"
56 * template which is used many times in the page - this
57 * change means it's only loaded from disk once.
59 * Revision 1.23 2001/09/16 11:16:05 jongfoster
60 * Better error handling in dispatch_cgi() and parse_cgi_parameters()
62 * Revision 1.22 2001/09/16 11:00:10 jongfoster
63 * New function alloc_http_response, for symmetry with free_http_response
65 * Revision 1.21 2001/09/13 23:53:03 jongfoster
66 * Support for both static and dynamically generated CGI pages.
67 * Correctly setting Last-Modified: and Expires: HTTP headers.
69 * Revision 1.20 2001/09/13 23:40:36 jongfoster
70 * (Cosmetic only) Indentation correction
72 * Revision 1.19 2001/09/13 23:31:25 jongfoster
73 * Moving image data to cgi.c rather than cgi.h.
75 * Revision 1.18 2001/08/05 16:06:20 jongfoster
76 * Modifiying "struct map" so that there are now separate header and
77 * "map_entry" structures. This means that functions which modify a
78 * map no longer need to return a pointer to the modified map.
79 * Also, it no longer reverses the order of the entries (which may be
80 * important with some advanced template substitutions).
82 * Revision 1.17 2001/08/05 15:57:38 oes
83 * Adapted finish_http_response to new list_to_text
85 * Revision 1.16 2001/08/01 21:33:18 jongfoster
86 * Changes to fill_template() that reduce memory usage without having
87 * an impact on performance. I also renamed some variables so as not
88 * to clash with the C++ keywords "new" and "template".
90 * Revision 1.15 2001/08/01 21:19:22 jongfoster
91 * Moving file version information to a separate CGI page.
93 * Revision 1.14 2001/08/01 00:19:03 jongfoster
94 * New function: map_conditional() for an if-then-else syntax.
95 * Changing to use new version of show_defines()
97 * Revision 1.13 2001/07/30 22:08:36 jongfoster
98 * Tidying up #defines:
99 * - All feature #defines are now of the form FEATURE_xxx
100 * - Permanently turned off WIN_GUI_EDIT
101 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
103 * Revision 1.12 2001/07/29 18:47:05 jongfoster
104 * Adding missing #include "loadcfg.h"
106 * Revision 1.11 2001/07/18 17:24:37 oes
107 * Changed to conform to new pcrs interface
109 * Revision 1.10 2001/07/13 13:53:13 oes
110 * Removed all #ifdef PCRS and related code
112 * Revision 1.9 2001/06/29 21:45:41 oes
113 * Indentation, CRLF->LF, Tab-> Space
115 * Revision 1.8 2001/06/29 13:21:46 oes
116 * - Cosmetics: renamed and reordered functions, variables,
117 * texts, improved comments etc
119 * - Removed ij_untrusted_url() The relevant
120 * info is now part of the "untrusted" page,
121 * which is generated by filters.c:trust_url()
123 * - Generators of content now call finish_http_response()
124 * themselves, making jcc.c:chat() a little less
127 * - Removed obsolete "Pragma: no-cache" from our headers
129 * - http_responses now know their head length
131 * - fill_template now uses the new interface to pcrs, so that
132 * - long jobs (like whole files) no longer have to be assembled
133 * in a fixed size buffer
134 * - the new T (trivial) option is used, and the replacement may
135 * contain Perl syntax backrefs without confusing pcrs
137 * - Introduced default_exports() which generates a set of exports
138 * common to all CGIs and other content generators
140 * - Introduced convenience function map_block_killer()
142 * - Introduced convenience function make_menu()
144 * - Introduced CGI-like function error_response() which generates
145 * the "No such domain" and "Connect failed" messages using the
148 * - cgi_show_url_info:
149 * - adapted to new CGI features
150 * - form and answers now generated from same template
151 * - http:// prefix in URL now OK
154 * - adapted to new CGI features
155 * - no longer uses csp->init_proxy_args
158 * - moved menu generation to make_menu()
160 * - add_stats now writes single export map entries instead
163 * - Moved redirect_url() to filters.c
165 * - Fixed mem leak in free_http_response(), map_block_killer(),
167 * - Removed logentry from cancelled commit
169 * Revision 1.7 2001/06/09 10:51:58 jongfoster
170 * Changing "show URL info" handler to new style.
171 * Changing BUFSIZ ==> BUFFER_SIZE
173 * Revision 1.6 2001/06/07 23:05:19 jongfoster
174 * Removing code related to old forward and ACL files.
176 * Revision 1.5 2001/06/05 19:59:16 jongfoster
177 * Fixing multiline character string (a GCC-only "feature"), and snprintf (it's _snprintf under VC++).
179 * Revision 1.4 2001/06/04 10:41:52 swa
180 * show version string of cgi.h and cgi.c
182 * Revision 1.3 2001/06/03 19:12:16 oes
183 * introduced new cgi handling
185 * No revisions before 1.3
187 **********************************************************************/
193 #include <sys/types.h>
200 #define snprintf _snprintf
201 #endif /* def _WIN32 */
209 #include "miscutil.h"
210 #include "cgisimple.h"
211 #ifdef FEATURE_CGI_EDIT_ACTIONS
213 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
215 const char cgi_h_rcs[] = CGI_H_VERSION;
217 const struct cgi_dispatcher cgi_dispatcher[] = {
220 "HIDE Sends a robots.txt file to tell robots to go away." },
223 "Show information about the current configuration" },
225 13, cgi_show_url_info,
226 "Show which actions apply to a URL and why" },
228 12, cgi_show_version,
229 "Show the source code version numbers" },
232 "HIDE Send the transparent or \"Junkbuster\" gif" },
233 #ifdef FEATURE_CGI_EDIT_ACTIONS
234 { "edit-actions-list",
235 17, cgi_edit_actions_list,
236 "Edit the actions list" },
237 { "edit-actions-submit",
238 19, cgi_edit_actions_submit,
239 "HIDE Change the actions for (a) specified URL(s)" },
241 12, cgi_edit_actions,
242 "HIDE Edit the actions for (a) specified URL(s)" },
243 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
246 "Junkbuster main page" },
247 { NULL, 0, NULL, NULL }
254 * Hint: You can encode your own GIFs like that:
255 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
258 const char image_junkbuster_gif_data[] =
259 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
260 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
261 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
262 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
263 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
264 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
265 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
268 const int image_junkbuster_gif_length = sizeof(image_junkbuster_gif_data) - 1;
271 const char image_blank_gif_data[] =
272 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
273 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
274 "\000\001\000\000\002\002D\001\000;";
276 const int image_blank_gif_length = sizeof(image_blank_gif_data) - 1;
279 /*********************************************************************
281 * Function : dispatch_cgi
283 * Description : Checks if a request URL has either the magical hostname
284 * i.j.b or matches HOME_PAGE_URL/config/. If so, it parses
285 * the (rest of the) path as a cgi name plus query string,
286 * prepares a map that maps CGI parameter names to their values,
287 * initializes the http_response struct, and calls the
288 * relevant CGI handler function.
291 * 1 : csp = Current client state (buffers, headers, etc...)
293 * Returns : http_response if match, NULL if nonmatch or handler fail
295 *********************************************************************/
296 struct http_response *dispatch_cgi(struct client_state *csp)
298 char *argstring = NULL;
299 const struct cgi_dispatcher *d;
300 struct map *param_list;
301 struct http_response *rsp;
304 * Should we intercept ?
307 /* Either the host matches CGI_PREFIX_HOST ..*/
308 if (0 == strcmpic(csp->http->host, CGI_PREFIX_HOST))
310 /* ..then the path will all be for us */
311 argstring = csp->http->path;
313 /* Or it's the host part HOME_PAGE_URL, and the path /config ? */
314 else if ( (0 == strcmpic(csp->http->host, HOME_PAGE_URL + 7 ))
315 && (0 == strncmpic(csp->http->path,"/config", 7))
316 && ((csp->http->path[7] == '/') || (csp->http->path[7] == '\0')))
318 /* then it's everything following "/config" */
319 argstring = csp->http->path + 7;
327 * This is a CGI call.
330 /* Get mem for response or fail*/
331 if (NULL == (rsp = alloc_http_response()))
337 /* Remove leading slash */
338 if (*argstring == '/')
343 log_error(LOG_LEVEL_GPC, "%s%s cgi call", csp->http->hostport, csp->http->path);
344 log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 200 3",
345 csp->ip_addr_str, csp->http->cmd);
347 /* Find and start the right CGI function*/
348 for (d = cgi_dispatcher; d->handler; d++)
350 if (strncmp(argstring, d->name, d->name_length) == 0)
352 if (NULL == (param_list =
353 parse_cgi_parameters(argstring + d->name_length)))
355 free_map(param_list);
356 free_http_response(rsp);
359 if ((d->handler)(csp, rsp, param_list))
361 free_map(param_list);
362 free_http_response(rsp);
366 free_map(param_list);
367 return(finish_http_response(rsp));
371 /* Can't get here, since cgi_default will match all requests */
372 free_http_response(rsp);
377 /*********************************************************************
379 * Function : parse_cgi_parameters
381 * Description : Parse a URL-encoded argument string into name/value
382 * pairs and store them in a struct map list.
385 * 1 : string = string to be parsed
387 * Returns : pointer to param list, or NULL if out of memory.
389 *********************************************************************/
390 struct map *parse_cgi_parameters(char *argstring)
393 char *vector[BUFFER_SIZE];
395 struct map *cgi_params;
397 if (NULL == (cgi_params = new_map()))
402 if(*argstring == '?')
406 if (NULL == (tmp = strdup(argstring)))
408 free_map(cgi_params);
412 pairs = ssplit(tmp, "&", vector, SZ(vector), 1, 1);
414 for (i = 0; i < pairs; i++)
416 if ((NULL != (p = strchr(vector[i], '='))) && (*(p+1) != '\0'))
419 map(cgi_params, url_decode(vector[i]), 0, url_decode(++p), 0);
429 /*********************************************************************
431 * Function : error_response
433 * Description : returns an http_response that explains the reason
434 * why a request failed.
437 * 1 : csp = Current client state (buffers, headers, etc...)
438 * 2 : templatename = Which template should be used for the answer
439 * 3 : errno = system error number
441 * Returns : NULL if no memory, else http_response
443 *********************************************************************/
444 struct http_response *error_response(struct client_state *csp, const char *templatename, int err)
446 struct http_response *rsp;
447 struct map * exports = default_exports(csp, NULL);
449 if (NULL == (rsp = alloc_http_response()))
454 map(exports, "host-html", 1, html_encode(csp->http->host), 0);
455 map(exports, "hostport", 1, csp->http->hostport, 1);
456 map(exports, "hostport-html", 1, html_encode(csp->http->hostport), 0);
457 map(exports, "path", 1, csp->http->path, 1);
458 map(exports, "path-html", 1, html_encode(csp->http->path), 0);
459 map(exports, "error", 1, safe_strerror(err), 0);
460 map(exports, "host-ip", 1, csp->http->host_ip_addr_str, 1);
462 rsp->body = template_load(csp, templatename);
463 template_fill(&rsp->body, exports);
466 if (!strcmp(templatename, "no-such-domain"))
468 rsp->status = strdup("404 No such domain");
470 else if (!strcmp(templatename, "connect-failed"))
472 rsp->status = strdup("503 Connect failed");
475 return(finish_http_response(rsp));
479 /*********************************************************************
481 * Function : get_http_time
483 * Description : Get the time in a format suitable for use in a
484 * HTTP header - e.g.:
485 * "Sun, 06 Nov 1994 08:49:37 GMT"
488 * 1 : time_offset = Time returned will be current time
489 * plus this number of seconds.
490 * 2 : buf = Destination for result. Must be long enough
491 * to hold 29 characters plus a trailing zero.
495 *********************************************************************/
496 void get_http_time(int time_offset, char * buf)
498 static const char day_names[7][4] =
499 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
500 static const char month_names[12][4] =
501 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
502 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
509 time(¤t_time); /* get current time */
511 /* FIXME: is this needed? time() can't fail on Win32. What about Linux?
512 if(current_time <= 0)
518 current_time += time_offset;
520 /* get and save the gmt */
521 t = gmtime(¤t_time);
523 /* Format: "Sun, 06 Nov 1994 08:49:37 GMT" */
525 "%s, %02d %s %4d %02d:%02d:%02d GMT",
526 day_names[t->tm_wday],
528 month_names[t->tm_mon],
538 /*********************************************************************
540 * Function : finish_http_response
542 * Description : Fill in the missing headers in an http response,
543 * and flatten the headers to an http head.
546 * 1 : rsp = pointer to http_response to be processed
548 * Returns : http_response, or NULL on failiure
550 *********************************************************************/
551 struct http_response *finish_http_response(struct http_response *rsp)
553 char buf[BUFFER_SIZE];
556 * Fill in the HTTP Status
558 sprintf(buf, "HTTP/1.0 %s", rsp->status ? rsp->status : "200 OK");
559 enlist_first(rsp->headers, buf);
562 * Set the Content-Length
564 if (rsp->content_length == 0)
566 rsp->content_length = rsp->body ? strlen(rsp->body) : 0;
568 sprintf(buf, "Content-Length: %d", rsp->content_length);
569 enlist(rsp->headers, buf);
572 * Fill in the default headers:
574 * Content-Type: default to text/html if not already specified.
575 * Date: set to current date/time.
576 * Last-Modified: set to date/time the page was last changed.
577 * Expires: set to date/time page next needs reloading.
578 * Cache-Control: set to "no-cache" if applicable.
580 * See http://www.w3.org/Protocols/rfc2068/rfc2068
582 enlist_unique(rsp->headers, "Content-Type: text/html", 13);
587 * Set Expires to about 10 min into the future so it'll get reloaded
588 * occasionally, e.g. if IJB gets upgraded.
591 get_http_time(0, buf);
592 enlist_unique_header(rsp->headers, "Date", buf);
594 /* Some date in the past. */
595 enlist_unique_header(rsp->headers, "Last-Modified", "Sat, 17 Jun 2000 12:00:00 GMT");
597 get_http_time(10 * 60, buf); /* 10 * 60sec = 10 minutes */
598 enlist_unique_header(rsp->headers, "Expires", buf);
603 * Compliant browsers should not cache this due to the "Cache-Control"
604 * setting. However, to be certain, we also set both "Last-Modified"
605 * and "Expires" to the current time.
607 enlist_unique_header(rsp->headers, "Cache-Control", "no-cache");
608 get_http_time(0, buf);
609 enlist_unique_header(rsp->headers, "Date", buf);
610 enlist_unique_header(rsp->headers, "Last-Modified", buf);
611 enlist_unique_header(rsp->headers, "Expires", buf);
618 if (NULL == (rsp->head = list_to_text(rsp->headers)))
620 free_http_response(rsp);
623 rsp->head_length = strlen(rsp->head);
630 /*********************************************************************
632 * Function : alloc_http_response
634 * Description : Allocates a new http_response structure.
638 * Returns : pointer to a new http_response, or NULL.
640 *********************************************************************/
641 struct http_response * alloc_http_response(void)
643 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, and fills it in
680 * by replacing @name@ with value using pcrs,
681 * for each item in the output map.
684 * 1 : csp = Current client state (buffers, headers, etc...)
685 * 3 : template = name of the HTML template to be used
687 * Returns : char * with loaded template, or NULL if failure
689 *********************************************************************/
690 char *template_load(struct client_state *csp, const char *templatename)
692 char buf[BUFFER_SIZE];
693 char *file_buffer = NULL;
697 * Open template file or fail
699 snprintf(buf, BUFFER_SIZE, "%s/templates/%s", csp->config->confdir, templatename);
701 if(NULL == (fp = fopen(buf, "r")))
703 log_error(LOG_LEVEL_ERROR, "error loading template %s: %E", buf);
709 * Read the file, ignoring comments
711 while (fgets(buf, BUFFER_SIZE, fp))
713 /* skip lines starting with '#' */
719 file_buffer = strsav(file_buffer, buf);
727 /*********************************************************************
729 * Function : fill_template
731 * Description : CGI support function that loads a given HTML
732 * template from the confdir, and fills it in
733 * by replacing @name@ with value using pcrs,
734 * for each item in the output map.
737 * 1 : template_ptr = IN: Template to be filled out.
739 * OUT: Filled out template.
740 * Caller must free().
741 * 2 : exports = map with fill in symbol -> name pairs
745 *********************************************************************/
746 void template_fill(char ** template_ptr, struct map *exports)
750 char buf[BUFFER_SIZE];
751 char *tmp_out_buffer;
757 assert(template_ptr);
758 assert(*template_ptr);
761 file_buffer = *template_ptr;
762 size = strlen(file_buffer) + 1;
765 * Assemble pcrs joblist from exports map
767 for (m = exports->first; m != NULL; m = m->next)
772 * First character of name is '$', so remove this flag
773 * character and allow backreferences ($1 etc) in the
774 * "replace with" text.
776 snprintf(buf, BUFFER_SIZE, "%s", m->name + 1);
782 * Treat the "replace with" text as a literal string -
783 * no quoting needed, no backreferences allowed.
784 * ("Trivial" ['T'] flag).
788 /* Enclose name in @@ */
789 snprintf(buf, BUFFER_SIZE, "@%s@", m->name);
793 log_error(LOG_LEVEL_CGI, "Substituting: s/%s/%s/%s", buf, m->value, flags);
795 /* Make and run job. */
796 job = pcrs_compile(buf, m->value, flags, &error);
799 log_error(LOG_LEVEL_ERROR, "Error compiling template fill job %s: %d", m->name, error);
803 pcrs_execute(job, file_buffer, size, &tmp_out_buffer, &size);
804 if (file_buffer != tmp_out_buffer)
807 file_buffer = tmp_out_buffer;
816 *template_ptr = file_buffer;
820 /*********************************************************************
822 * Function : default_exports
824 * Description : returns a struct map list that contains exports
825 * which are common to all CGI functions.
828 * 1 : exports = Structure to write output to. This
829 * structure should be newly allocated and will be
831 * 1 : csp = Current client state (buffers, headers, etc...)
832 * 2 : caller = name of CGI who calls us and which should
833 * be excluded from the generated menu.
834 * Returns : NULL if no memory, else map
836 *********************************************************************/
837 struct map * default_exports(const struct client_state *csp, const char *caller)
840 struct map * exports = new_map();
842 map(exports, "version", 1, VERSION, 1);
843 map(exports, "my-ip-address", 1, csp->my_ip_addr_str ? csp->my_ip_addr_str : "unknown", 1);
844 map(exports, "my-hostname", 1, csp->my_hostname ? csp->my_hostname : "unknown", 1);
845 map(exports, "admin-address", 1, csp->config->admin_address ? csp->config->admin_address : "fill@me.in.please", 1);
846 map(exports, "homepage", 1, HOME_PAGE_URL, 1);
847 map(exports, "default-cgi", 1, HOME_PAGE_URL "/config", 1);
848 map(exports, "menu", 1, make_menu(caller), 0);
849 map(exports, "code-status", 1, CODE_STATUS, 1);
851 snprintf(buf, 20, "%d", csp->config->hport);
852 map(exports, "my-port", 1, buf, 1);
854 if(!strcmp(CODE_STATUS, "stable"))
856 map_block_killer(exports, "unstable");
859 if(csp->config->proxy_info_url != NULL)
861 map(exports, "proxy-info-url", 1, csp->config->proxy_info_url, 1);
865 map_block_killer(exports, "have-proxy-info");
872 /*********************************************************************
874 * Function : map_block_killer
876 * Description : Convenience function.
877 * Adds a "killer" for the conditional HTML-template
878 * block <name>, i.e. a substitution of the regex
879 * "if-<name>-start.*if-<name>-end" to the given
883 * 1 : exports = map to extend
884 * 2 : name = name of conditional block
886 * Returns : extended map
888 *********************************************************************/
889 void map_block_killer(struct map *exports, const char *name)
891 char buf[1000]; /* Will do, since the names are hardwired */
893 snprintf(buf, 1000, "if-%s-start.*if-%s-end", name, name);
894 map(exports, buf, 1, "", 1);
898 /*********************************************************************
900 * Function : map_conditional
902 * Description : Convenience function.
903 * Adds an "if-then-else" for the conditional HTML-template
904 * block <name>, i.e. a substitution of the form:
911 * The control structure and one of the alternatives
915 * 1 : exports = map to extend
916 * 2 : name = name of conditional block
917 * 3 : choose_first = nonzero for first, zero for second.
919 * Returns : extended map
921 *********************************************************************/
922 void map_conditional(struct map *exports, const char *name, int choose_first)
924 char buf[1000]; /* Will do, since the names are hardwired */
926 snprintf(buf, 1000, (choose_first
927 ? "else-not-%s@.*@endif-%s"
928 : "if-%s-then@.*@else-not-%s"),
930 map(exports, buf, 1, "", 1);
932 snprintf(buf, 1000, (choose_first ? "if-%s-then" : "endif-%s"), name);
933 map(exports, buf, 1, "", 1);
937 /*********************************************************************
939 * Function : make_menu
941 * Description : Returns an HTML-formatted menu of the available
942 * unhidden CGIs, excluding the one given in <self>.
944 * Parameters : self = name of CGI to leave out, can be NULL
946 * Returns : menu string
948 *********************************************************************/
949 char *make_menu(const char *self)
951 const struct cgi_dispatcher *d;
952 char buf[BUFFER_SIZE];
957 self = "NO-SUCH-CGI!";
960 /* List available unhidden CGI's and export as "other-cgis" */
961 for (d = cgi_dispatcher; d->handler; d++)
963 if (strncmp(d->description, "HIDE", 4) && strcmp(d->name, self))
965 snprintf(buf, BUFFER_SIZE, "<li><a href=%s/config/%s>%s</a></li>\n",
966 HOME_PAGE_URL, d->name, d->description);
967 result = strsav(result, buf);
975 /*********************************************************************
977 * Function : dump_map
979 * Description : HTML-dump a map for debugging
982 * 1 : the_map = map to dump
984 * Returns : string with HTML
986 *********************************************************************/
987 char *dump_map(const struct map *the_map)
989 struct map_entry *cur_entry = the_map->first;
992 ret = strsav(ret, "<table>\n");
996 ret = strsav(ret, "<tr><td><b>");
997 ret = strsav(ret, cur_entry->name);
998 ret = strsav(ret, "</b></td><td>");
999 ret = strsav(ret, cur_entry->value);
1000 ret = strsav(ret, "</td></tr>\n");
1001 cur_entry = cur_entry->next;
1004 ret = strsav(ret, "</table>\n");