summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-03-14 04:13:24 +0000
committerAndrew Tridgell <tridge@samba.org>1998-03-14 04:13:24 +0000
commitd5c1af5d9fb33e42e24dc3f1c0ea235eb1fb904a (patch)
tree8e224afbdd5c78c2be82f5b1fae82122db49a251 /source3
parent914a0b14aad364dd91ca4da90a82995919596e42 (diff)
downloadsamba-d5c1af5d9fb33e42e24dc3f1c0ea235eb1fb904a.tar.gz
samba-d5c1af5d9fb33e42e24dc3f1c0ea235eb1fb904a.tar.bz2
samba-d5c1af5d9fb33e42e24dc3f1c0ea235eb1fb904a.zip
fixed support for running swat via cgi-bin
(This used to be commit 9dbfb16990954ee3518ce3bc73e067c82b653930)
Diffstat (limited to 'source3')
-rw-r--r--source3/web/cgi.c50
-rw-r--r--source3/web/swat.c10
2 files changed, 50 insertions, 10 deletions
diff --git a/source3/web/cgi.c b/source3/web/cgi.c
index 6468c92917..46654b1303 100644
--- a/source3/web/cgi.c
+++ b/source3/web/cgi.c
@@ -44,6 +44,7 @@ static int request_post;
static int request_get;
static char *query_string;
static char *baseurl;
+static char *pathinfo;
static void unescape(char *buf)
{
@@ -545,9 +546,7 @@ void cgi_setup(char *rootdir, int auth_required)
char *url=NULL;
char *p;
#if CGI_LOGGING
- FILE *f = fopen("/tmp/cgi.log", "a");
-
- fprintf(f,"\n[Date: %s]\n", http_timestring(time(NULL)));
+ FILE *f;
#endif
if (chdir(rootdir)) {
@@ -560,11 +559,16 @@ void cgi_setup(char *rootdir, int auth_required)
return;
}
+#if CGI_LOGGING
+ f = fopen("/tmp/cgi.log", "a");
+ if (f) fprintf(f,"\n[Date: %s]\n", http_timestring(time(NULL)));
+#endif
+
/* we are a mini-web server. We need to read the request from stdin
and handle authentication etc */
while (fgets(line, sizeof(line)-1, stdin)) {
#if CGI_LOGGING
- fputs(line, f);
+ if (f) fputs(line, f);
#endif
if (line[0] == '\r' || line[0] == '\n') break;
if (strncasecmp(line,"GET ", 4)==0) {
@@ -584,7 +588,7 @@ void cgi_setup(char *rootdir, int auth_required)
/* ignore all other requests! */
}
#if CGI_LOGGING
- fclose(f);
+ if (f) fclose(f);
#endif
if (auth_required && !authenticated) {
@@ -618,7 +622,8 @@ void cgi_setup(char *rootdir, int auth_required)
printf("HTTP/1.1 200 OK\r\nConnection: close\r\n");
printf("Date: %s\r\n", http_timestring(time(NULL)));
- baseurl = url+1;
+ baseurl = "";
+ pathinfo = url+1;
}
@@ -627,5 +632,36 @@ return the current pages URL
***************************************************************************/
char *cgi_baseurl(void)
{
- return baseurl;
+ if (baseurl) {
+ return baseurl;
+ }
+ return getenv("SCRIPT_NAME");
}
+
+/***************************************************************************
+return the root URL for images etc
+ ***************************************************************************/
+char *cgi_rooturl(void)
+{
+ if (baseurl) {
+ return "/";
+ }
+ return "/swat/";
+}
+
+
+/***************************************************************************
+return the current pages path info
+ ***************************************************************************/
+char *cgi_pathinfo(void)
+{
+ char *r;
+ if (pathinfo) {
+ return pathinfo;
+ }
+ r = getenv("PATH_INFO");
+ if (!r) return "";
+ if (*r == '/') r++;
+ return r;
+}
+
diff --git a/source3/web/swat.c b/source3/web/swat.c
index 09d0f08ea6..987520d2cf 100644
--- a/source3/web/swat.c
+++ b/source3/web/swat.c
@@ -219,7 +219,11 @@ static void load_config(void)
/* spit out the html for a link with an image */
static void image_link(char *name,char *hlink, char *src, int width, int height)
{
- printf("<A HREF=\"%s\"><img width=%d height=%d src=\"%s\" alt=\"%s\"></A>\n", hlink, width, height, src, name);
+ printf("<A HREF=\"%s/%s\"><img width=%d height=%d src=\"%s%s\" alt=\"%s\"></A>\n",
+ cgi_baseurl(),
+ hlink, width, height,
+ cgi_rooturl(),
+ src, name);
}
/* display the main navigation controls at the top of each page along
@@ -562,7 +566,7 @@ int main(int argc, char *argv[])
cgi_setup(SWATDIR, auth_required);
print_header();
-
+
charset_initialise();
/* if this binary is setuid then run completely as root */
@@ -574,7 +578,7 @@ int main(int argc, char *argv[])
show_main_buttons();
- page = cgi_baseurl();
+ page = cgi_pathinfo();
if (strcmp(page, "globals")==0) {
globals_page();