-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.43 2006/12/17 17:57:56 fabiankeil Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.48 2007/01/20 15:31:31 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
* Functions declared include:
*
*
- * Copyright : Written by and Copyright (C) 2001 the SourceForge
+ * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge
* Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
*
* Revisions :
* $Log: cgisimple.c,v $
+ * Revision 1.48 2007/01/20 15:31:31 fabiankeil
+ * Display warning if show-url-info CGI page
+ * is used while Privoxy is toggled off.
+ *
+ * Revision 1.47 2007/01/12 15:07:10 fabiankeil
+ * Use zalloc in cgi_send_user_manual.
+ *
+ * Revision 1.46 2007/01/02 12:49:46 fabiankeil
+ * Add FEATURE_ZLIB to the list of conditional
+ * defines at the show-status page.
+ *
+ * Revision 1.45 2006/12/28 18:16:41 fabiankeil
+ * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
+ * body memory before using it, replaced sprintf calls with snprintf.
+ *
+ * Revision 1.44 2006/12/22 14:19:27 fabiankeil
+ * Removed checks whether or not AF_FILES have
+ * data structures associated with them in cgi_show_status.
+ * It doesn't matter as we're only interested in the file names.
+ *
+ * For the action files the checks were always true,
+ * but they prevented empty filter files from being
+ * listed. Fixes parts of BR 1619208.
+ *
* Revision 1.43 2006/12/17 17:57:56 fabiankeil
* - Added FEATURE_GRACEFUL_TERMINATION to the
* "conditional #defines" section
#include <string.h>
#include <assert.h>
+#ifdef HAVE_ACCESS
+#include <unistd.h>
+#endif /* def HAVE_ACCESS */
+
#ifdef _WIN32
#define snprintf _snprintf
#endif /* def _WIN32 */
/* Get file length */
fseek(fp, 0, SEEK_END);
- length = ftell(fp);
+ length = (size_t)ftell(fp);
fseek(fp, 0, SEEK_SET);
/* Allocate memory and load the file directly into the body */
- rsp->body = (char *)malloc(length+1);
+ rsp->body = (char *)zalloc(length+1);
if (!rsp->body)
{
fclose(fp);
{
/*
* This happens if we didn't fopen in binary mode.
- * If it does, we just log it and serve what we got,
- * most likely padded with garbage.
+ * If it does, we just log it and serve what we got.
*/
log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
}
fclose(fp);
free(full_path);
- rsp->content_length = (int)length;
+ rsp->content_length = length;
/* Guess correct Content-Type based on the filename's ending */
if (filename)
perc_rej = (float)local_urls_rejected * 100.0F /
(float)local_urls_read;
- sprintf(buf, "%d", local_urls_read);
+ snprintf(buf, sizeof(buf), "%d", local_urls_read);
if (!err) err = map(exports, "requests-received", 1, buf, 1);
- sprintf(buf, "%d", local_urls_rejected);
+ snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
- sprintf(buf, "%6.2f", perc_rej);
+ snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
}
#ifdef FEATURE_CGI_EDIT_ACTIONS
if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
{
- snprintf(buf, 100, " <a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
- if (!err) err = string_append(&s, buf);
+#ifdef HAVE_ACCESS
+ if (access(csp->config->actions_file[i], W_OK) == 0)
+ {
+#endif /* def HAVE_ACCESS */
+ snprintf(buf, 100, " <a href=\"/edit-actions-list?f=%s\">Edit</a>",
+ csp->config->actions_file_short[i]);
+ if (!err) err = string_append(&s, buf);
+#ifdef HAVE_ACCESS
+ }
+ else
+ {
+ if (!err) err = string_append(&s, " <strong>No write access.</strong>");
+ }
+#endif /* def HAVE_ACCESS */
}
#endif
url_param = url_param_prefixed;
}
+ /*
+ * Hide "toggle off" warning if Privoxy is toggled on.
+ */
+ if (
+#ifdef FEATURE_TOGGLE
+ (global_toggle_state == 1) &&
+#endif /* def FEATURE_TOGGLE */
+ map_block_killer(exports, "privoxy-is-toggled-off")
+ )
+ {
+ free_map(exports);
+ return JB_ERR_MEMORY;
+ }
if (url_param[0] == '\0')
{
if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
#endif /* ndef FEATURE_TRUST */
+#ifdef FEATURE_ZLIB
+ if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
+#else /* ifndef FEATURE_ZLIB */
+ if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
+#endif /* ndef FEATURE_ZLIB */
+
#ifdef STATIC_PCRE
if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
#else /* ifndef STATIC_PCRE */
#define SHOW_RCS(__x) \
{ \
extern const char __x[]; \
- sprintf(buf, "%s\n", __x); \
+ snprintf(buf, sizeof(buf), " %s\n", __x); \
string_append(&result, buf); \
}