Re: [users@httpd] mod_frontpage state of the art

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK, I think I have solved getting mod_frontpage to work with a mod_rewrite
virtual host configuration. For the benefit of the archives, here's what I
learned.

(1) The CGIs make use of the SERVER_NAME environment variable
(2) They then look this up in the httpd.conf pointed to by
    /usr/local/frontpage/version5.0/www.example.com:80.cnf
    and look for a <VirtualHost> container to find the DocumentRoot

So I needed a small patch to mod_frontpage to set SERVER_NAME from HTTP_HOST
(or HTTP_X_FORWARDED_HOST in my proxy environment), and I also needed to
generate a plaintext mini-httpd.conf purely for frontpage to read:

----------------------------------------------------------------------
Port 80 
ServerRoot "/usr/local"
ResourceConfig /dev/null
AccessConfig /dev/null
DocumentRoot /usr/local/www/data

<VirtualHost _default_>
ServerName www.example.com
DocumentRoot /usr/local/www/data-example
</VirtualHost>
----------------------------------------------------------------------

Then point /usr/local/frontpage/www.example.com:80.cnf at that:

vti_encoding:SR|utf8-nl
servertype:apache-fp
authoring:enabled
extenderversion:5.0.2.2634
frontpageroot:/usr/local/frontpage/version5.0
serverconfig:/conf/fp.conf

Doing it this way, rather than driving Apache from the <VirtualHost>
containers, means I can add and remove sites dynamically without having to
restart Apache; mod_rewrite looks them up in a separate dbm file.

One other point to note: you should put
AddModule mod_frontpage.c
at the *end* of the AddModules. This is so that it processes the request
first; it looks at the pathname and sets the magic MIME type automatically,
but returns DECLINED so that other modules can perform the actual URI to
Filename translation. As a result, I no longer have to mess with MIME types
in mod_rewrite: just

RewriteCond %{ENV:HOSTMAP} ^(/[^,]+)
RewriteRule ^(/_vti_bin/?.*)$ \
        %1$1 [L]

is all I need, where the HOSTMAP environment variable has been set up from a
previous RewriteMap lookup giving the path to the site's root dir.

Regards,

Brian.
--- fpexec.c.orig	Tue Aug  2 14:38:31 2005
+++ fpexec.c	Wed Aug  3 11:23:41 2005
@@ -125,6 +125,9 @@
 	"FILEPATH_INFO",
 	"GATEWAY_INTERFACE",
 	"LAST_MODIFIED",
+#if 0
+	"NEW_DOCUMENT_ROOT",
+#endif
 	"PATH_INFO",
 	"PATH_TRANSLATED",
 	"QUERY_STRING",
@@ -768,6 +771,53 @@
 
 	clean_env();
 
+	/* fixup environment */
+	{
+		char *e = getenv("HTTP_X_FORWARDED_HOST");
+		if (e)
+			setenv("HTTP_HOST", e, 1);
+		else
+			e = getenv("HTTP_HOST");
+		if (e) {
+			char tmp[256];
+			char *pp;
+			snprintf(tmp, sizeof(tmp), "%s", e);
+			pp = strchr(tmp, ':');
+			if (pp) *pp = '\0';
+			setenv("SERVER_NAME", tmp, 1);
+		}
+#if 0
+		e = getenv("NEW_DOCUMENT_ROOT");
+		if(e) {
+			setenv("DOCUMENT_ROOT", e, 1);
+			unsetenv("NEW_DOCUMENT_ROOT");
+		}
+
+		unsetenv("SCRIPT_URL");
+		unsetenv("SCRIPT_URI");
+#endif
+	}
+
+#if 0
+	/* debugging of script environment */
+	{
+		char **ep;
+		log_msg("cwd: %s\n", cwd);
+		log_msg("fpd (new argv[0]): %s\n", fpd);
+		ep = argv;
+		while (*ep) {
+			log_msg("arg: %s\n", *ep);
+			ep++;
+		}
+		log_msg("arg count: %d\n", ep - argv);
+		ep = environ;
+		while (*ep) {
+			log_msg("%s\n", *ep);
+			ep++;
+		}
+	}
+#endif
+
 	/* 
 	 * Be sure to close the log file so the CGI can't
 	 * mess with it.  If the exec fails, it will be reopened 
@@ -803,6 +853,52 @@
 		printf("Content-Type: text/html\n");
 		fflush(stdout);
 	}
+
+#if 0
+	/*
+	 * Execute the command in a subprocess; sometimes we get <html>
+         * without a header, so fake one up.
+	 */
+        {
+        	pid_t pid;
+        	int status, first;
+        	int rpipe[2];
+        	FILE *cdata;
+        	char buf[256];
+        	
+        	if (pipe(rpipe) < 0) {
+        		log_err("pipe failed");
+        		exit(255);
+		}
+
+		pid = fork();
+		if (pid < 0) {
+			log_err("fork failed");
+			exit(255);
+		}
+		if (pid == 0) { /* child */
+			close(rpipe[0]);
+			dup2(rpipe[1], 1);
+			execv(fpd, &argv[0]);
+		}
+		close(rpipe[1]);
+		cdata = fdopen(rpipe[0], "r");
+		if (cdata == 0) {
+			log_err("fdopen failed");
+			exit(255);
+		}
+		first = 1;
+		while (fgets(buf, sizeof(buf), cdata) != 0) {
+			if (first && !strncasecmp(buf, "<html>", 6)) {
+				fputs("Content-Type: text/html\r\n\r\n", stdout);
+			}
+			first = 0;
+			fputs(buf, stdout);
+		}
+		waitpid(pid, &status, 0);
+		exit(WEXITSTATUS(status));
+	}
+#endif
 
 	/*
 	 * Execute the command, replacing our image with its own.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux