Fossil Forum

"baseurl" with CGI?
Login

"baseurl" with CGI?

(1) By anonymous on 2021-01-30 20:49:08 [source]

I'm self-hosting a repository on https://fossil.example.com/, running Apache. I've created a CGI script named index.cgi under DOCUMENT_ROOT as described in https://www.fossil-scm.org/fossil/doc/trunk/www/server/any/cgi.md. So far navigating to https://fossil.example.com/index.cgi works as expected.

Now I want to remove that index.cgi part. I added an .htaccess with a single line:

FallbackResource /index.cgi

Now when I navigate to a URL like https://fossil.example.com/repo-name/timeline it also works as expected. However, all the URLs returned by fossil are of the invalid form https://fossil.example.com/index.cgirepo-name/timeline.

I tried adding a baseurl into the CGI, but it looks like that property isn't supported.

How do I make fossil cooperate?

(2) By Richard Hipp (drh) on 2021-01-30 21:04:20 in reply to 1 [link] [source]

I'm not familar with Apache or "FallbackResource". What is the output of

  • https://fossil.example.com/index.cgi/test_env
  • https://fossil.example.com/test_env

(3) By anonymous on 2021-01-30 22:53:28 in reply to 2 [link] [source]

Hi Richard,

test_env redirects to the notfound resource. Instead I enabled the cgi-debug log, and this is what it contains for the two requests with and without index.cgi:

-------- BEGIN cgi at 2021-00-30 22:40:44 --------
DOCUMENT_ROOT = /home/public/fossil.example.com
GATEWAY_INTERFACE = CGI/1.1
HOME = /home/protected/
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_ENCODING = gzip, deflate, br
HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.5
HTTP_CONNECTION = close
HTTP_HOST = fossil.example.com
HTTP_IF_NONE_MATCH = 742e74529b4af5265cb1d15912e2af35
HTTP_REFERER = https://fossil.example.com/
HTTP_USER_AGENT = Mozilla/5.0 (X11; FreeBSD amd64; rv:84.0) Gecko/20100101 Firefox/84.0
PATH_INFO = /repo-name/timeline
PATH_TRANSLATED = /fs3c/example/public/fossil.example.com/index.cgi
REMOTE_ADDR = 0.0.0.0
REMOTE_PORT = 35231
REQUEST_METHOD = GET
REQUEST_URI = /index.cgi/repo-name/timeline
SCRIPT_FILENAME = /home/public/fossil.example.com/index.cgi
SCRIPT_NAME = /index.cgi
SERVER_PROTOCOL = HTTP/1.1
TMPDIR = /home/tmp/
USER = 25000
mem-match [REQUEST_URI] = [/index.cgi/repo-name/timeline]
mem-match [SCRIPT_NAME] = [/index.cgi]
mem-match [PATH_INFO] = [/repo-name/timeline]
no-match [no_json]
env-match [HTTP_COOKIE] = [fossil-8c52360cbe4d3798=8B7627F41ABFED3ABBE3B4877470D780410B56759D7875824E%2F8c52360cbe4d3798%2Fyakov]
no-match [QUERY_STRING]
mem-match [REMOTE_ADDR] = [0.0.0.0]
no-match [CONTENT_LENGTH]
no-match [CONTENT_TYPE]
mem-match [PATH_INFO] = [/repo-name/timeline]
no-match [utc]
no-match [localtime]
mem-match [SCRIPT_NAME] = [/index.cgi]
mem-match [HTTP_HOST] = [fossil.example.com]
env-match [HTTPS] = [on]
mem-match [SCRIPT_NAME] = [/index.cgi/repo-name]
no-match [p]
... 40 similar lines ...
no-match [dp]
mem-match [REMOTE_ADDR] = [0.0.0.0]
mem-match [fossil-8c52360cbe4d3798] = [8B7627F41ABFED3ABBE3B4877470D780410B56759D7875824E/8c52360cbe4d3798/yakov]
no-match [isrobot]
no-match [fossil_display_settings]
no-match [QUERY_STRING]
mem-match [PATH_INFO] = [timeline]
mem-match [HTTP_IF_NONE_MATCH] = [742e74529b4af5265cb1d15912e2af35]
-------- END cgi ---------



-------- BEGIN cgi at 2021-00-30 22:40:52 --------
DOCUMENT_ROOT = /home/public/fossil.example.com
GATEWAY_INTERFACE = CGI/1.1
HOME = /home/protected/
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_ENCODING = gzip, deflate, br
HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.5
HTTP_CONNECTION = close
HTTP_HOST = fossil.example.com
HTTP_IF_NONE_MATCH = 36a184cb957c95f25a04320012713706
HTTP_USER_AGENT = Mozilla/5.0 (X11; FreeBSD amd64; rv:84.0) Gecko/20100101 Firefox/84.0
REMOTE_ADDR = 0.0.0.0
REMOTE_PORT = 35655
REQUEST_METHOD = GET
REQUEST_URI = /repo-name/timeline
SCRIPT_FILENAME = /home/public/fossil.example.com/index.cgi
SCRIPT_NAME = /index.cgi
SERVER_PROTOCOL = HTTP/1.1
TMPDIR = /home/tmp/
USER = 25000
mem-match [REQUEST_URI] = [/repo-name/timeline]
mem-match [SCRIPT_NAME] = [/index.cgi]
no-match [PATH_INFO]
no-match [no_json]
no-match [HTTP_COOKIE]
no-match [QUERY_STRING]
mem-match [REMOTE_ADDR] = [0.0.0.0]
no-match [CONTENT_LENGTH]
no-match [CONTENT_TYPE]
mem-match [PATH_INFO] = [repo-name/timeline]
no-match [utc]
no-match [localtime]
mem-match [SCRIPT_NAME] = [/index.cgi]
mem-match [HTTP_HOST] = [fossil.example.com]
env-match [HTTPS] = [on]
mem-match [SCRIPT_NAME] = [/index.cgirepo-name]
no-match [p]
... 40 similar lines ...
no-match [dp]
mem-match [REMOTE_ADDR] = [0.0.0.0]
no-match [fossil-8c52360cbe4d3798]
no-match [REMOTE_USER]
no-match [isrobot]
mem-match [HTTP_USER_AGENT] = [Mozilla/5.0 (X11; FreeBSD amd64; rv:84.0) Gecko/20100101 Firefox/84.0]
no-match [fossil_display_settings]
no-match [QUERY_STRING]
mem-match [PATH_INFO] = [timeline]
mem-match [HTTP_IF_NONE_MATCH] = [36a184cb957c95f25a04320012713706]
-------- END cgi ---------

(4) By Richard Hipp (drh) on 2021-01-30 23:42:17 in reply to 3 [link] [source]

Regarding test_env: Visit the /Admin/Access page and click the box that allows access to /test_env, then press the "Apply Changes" button.

As for the URL problem, I think the crux of the matter is the "cgi_init()" routine seen here:

Your second example omits PATH_INFO, so Fossil has only REQUEST_URI and SCRIPT_NAME. But the relation:

  REQUEST_URI == SCRIPT_NAME + PATH_INFO

Does not hold. Perhaps you can suggest a change that will recognize the unusual case generated by Apache here, and correct it into something that Fossil can use - without breaking the cgi_init() routine for any other web-server configurations. Perhaps Fossil needs to observer that SCRIPT_NAME is not a prefix of REQUEST_URI and hence it should ignore the supplied SCRIPT_NAME and substitute "/" instead. Would this break anybody else's setup?

(5) By anonymous on 2021-01-31 00:33:21 in reply to 4 [link] [source]

Hi Richard,

First, I figured out that test_env didn't work because I'm serving a directory rather than a single repository, so it was interpreting it as a repository name... It works now with https://fossil.example.com/index.cgi/repo-name/test_env.

Next, I gave it a thought, and there's no enough information in the environment to determine the "SCRIPT_NAME" prior to the URL rewrite. Indeed, Apache allows rewriting URLs in arbitrary ways, and it cannot know itself what part of the original REQUEST_URI would be the SCRIPT_NAME.

So the right thing would be for me to set the expected SCRIPT_NAME. I tried adding setenv SCRIPT_NAME / to the index.cgi, but it's not picked-up for some reason. To test my hypothesis, though, I renamed index.cgi to index2.cgi and created a new index.cgi:

#!/bin/sh
SCRIPT_NAME=/
exec ./index2.cgi

and it works!

I wish there was a better solution without running an additional exec for every request, but I'll call it solved for now.

Thank you for your help and your work on SQLite and fossil :)

(6) By Richard Hipp (drh) on 2021-01-31 00:36:02 in reply to 1 [link] [source]

Please rebuild your Fossil using check-in 140cb312ca6e5c83 or later and report back whether or not this improves your situation. Please test carefully.

(7) By Richard Hipp (drh) on 2021-01-31 11:54:15 in reply to 5 [link] [source]

There should be a colon after "setenv:" in the cgi file. Like this:

    setenv: SCRIPT_NAME /

Is that a typo in your post, or did you omit the colon in your test? The setenv: SCRIPT_NAME line in the cgi file does work. I tested it just yesterday. I don't know why it isn't working for you.

But if you do that, then the https://fossil.example.com/index.cgi/repo-name/timeline style URLs (that include the "index.cgi" in the name, would fail, I think.

If you want both URLs with and without the /index.cgi/ part to work, I think you have to use the patch I wrote and posted about yesterday. Please give it a try and let me know if it helps.