commit 3f0158b49db4d4cb897b892d200ffe07edb29e8e from: Omar Polo via: Thomas Adam date: Tue Aug 30 18:37:47 2022 UTC gotwebd: use SCRIPT_NAME to derive URLs This makes gotwebd use SCRIPT_NAME instead of the DOCUMENT_ROOT fastcgi param to generate the links to the assets and changes some links so every page is consistently linked with a relative URL. It allows to drop the `root "/"' in the location for fastcgi and, as a bonus, also makes possible to run gotwebd on non "/" paths. ok stsp@ commit - b73ef4cf9863a0caacba2b8f7570bc969fd4bf48 commit + 3f0158b49db4d4cb897b892d200ffe07edb29e8e blob - bdfdd35a553466d74a4e3ede850696fce898a0d3 blob + 6efdd7576792bc4590348536799267e5cc6b1d68 --- gotwebd/fcgi.c +++ gotwebd/fcgi.c @@ -276,19 +276,13 @@ fcgi_parse_params(uint8_t *buf, uint16_t n, struct req bcopy(buf, c->http_host, val_len); c->http_host[val_len] = '\0'; } - if (val_len < MAX_DOCUMENT_ROOT && strcmp(env_entry->val, - "DOCUMENT_ROOT") == 0 && c->document_root[0] == '\0') { - - /* drop first char, as it's always / */ - dr_buf = &buf[1]; - - bcopy(dr_buf, c->document_root, val_len - 1); - c->document_root[val_len] = '\0'; + if (val_len < MAX_SCRIPT_NAME && strcmp(env_entry->val, + "SCRIPT_NAME") == 0 && c->script_name[0] == '\0') { + bcopy(dr_buf, c->script_name, val_len); + c->script_name[val_len] = '\0'; } if (val_len < MAX_SERVER_NAME && strcmp(env_entry->val, "SERVER_NAME") == 0 && c->server_name[0] == '\0') { - /* drop first char, as it's always / */ - bcopy(buf, c->server_name, val_len); c->server_name[val_len] = '\0'; } blob - ed4ed098d767289969a6803e69f59e13fb9f2b85 blob + 85b940eabaac43f5c561a5ede946f4dc3f634a36 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -108,7 +108,7 @@ static const struct got_error *gotweb_render_branches( static void gotweb_free_querystring(struct querystring *); static void gotweb_free_repo_dir(struct repo_dir *); -struct server *gotweb_get_server(uint8_t *, uint8_t *, uint8_t *); +struct server *gotweb_get_server(uint8_t *, uint8_t *); void gotweb_process_request(struct request *c) @@ -130,7 +130,7 @@ gotweb_process_request(struct request *c) if (c->sock->client_status == CLIENT_DISCONNECT) return; /* get the gotwebd server */ - srv = gotweb_get_server(c->server_name, c->document_root, c->http_host); + srv = gotweb_get_server(c->server_name, c->http_host); if (srv == NULL) { log_warnx("%s: error server is NULL", __func__); goto err; @@ -299,24 +299,17 @@ done: } struct server * -gotweb_get_server(uint8_t *server_name, uint8_t *document_root, - uint8_t *subdomain) +gotweb_get_server(uint8_t *server_name, uint8_t *subdomain) { struct server *srv = NULL; - /* check against document_root first */ + /* check against the server name first */ if (strlen(server_name) > 0) TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) if (strcmp(srv->name, server_name) == 0) - goto done; - - /* check against document_root second */ - if (strlen(document_root) > 0) - TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) - if (strcmp(srv->name, document_root) == 0) goto done; - /* check against subdomain third */ + /* check against subdomain second */ if (strlen(subdomain) > 0) TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) if (strcmp(srv->name, subdomain) == 0) @@ -650,15 +643,7 @@ gotweb_render_header(struct request *c) { struct server *srv = c->srv; struct querystring *qs = c->t->qs; - char droot[PATH_MAX]; int r; - - if (strlen(c->document_root) > 0) { - r = snprintf(droot, sizeof(droot), "/%s/", c->document_root); - if (r < 0 || (size_t)r >= sizeof(droot)) - return got_error(GOT_ERR_NO_SPACE); - } else - strlcpy(droot, "/", sizeof(droot)); r = fcgi_printf(c, "\n" "\n" @@ -689,22 +674,21 @@ gotweb_render_header(struct request *c) "\n" /* #header */ "
\n" "