commit - 7e0628b4fbe442954b4e75dc0b7dde1f91d5f387ac86ba40bc120225d34932d9
commit + d4278f033868731068d1423ea050234901387f9d9a26d59c4d5c76895a5fab72
blob - 8824f9213bfb272ea5664994cb5709d50e94113bc23eedf4d6c3329c90818d2a
blob + 665ce020a5e96ea761937ca13107d51932deda5d3d1c5d759f26b706b8d2445b
--- gotsysd/gotsysd.conf.5
+++ gotsysd/gotsysd.conf.5
.It Ic login hint port Ar number
Sets the SSH port number displayed in login hints which are shown on the error
page if authentication has failed.
+.It Ic redirect_method Ar method
+Set the
+.Ar method
+used by
+.Xr gotwebd 8
+when redirecting clients to another page, such as from the login page
+to the summary page.
+.Pp
+The available methods are:
+.Bl -tag -width Ds
+.It page_refresh
+Send HTTP response status code 200 (success) and serve a
+.Dv meta
+tag in the HTML response body with the
+.Dv http-equiv
+attribute set to
+.Dq refresh
+and a new URL in the
+.Dv url
+attribute.
+.Pp
+This method is the default and provides good browser compatibility overall.
+.pp
+This method can get in the way of scripts trying to navigate through a
+.Xr gotsh 1
+.Cm weblogin
+link, which is usually desirable, but not always.
+.It status_code
+Send HTTP response status code 307 (redirect) with a target URL in HTTP
+headers and with an empty response body.
+.Pp
+This method generally works as expected.
+In some situations browsers fail to follow the redirect and display the
+redirecting page instead.
+For example,
+.Xr gotsh 1
+.Cm weblogin
+links have been known to fail loading the summary page if the redirecting
+link is opened by an external application asking Mozilla Firefox to open
+the login link, even though the redirect is followed as expected when
+the login link is visited via the browser's address bar.
+.El
.It Ic user Ar name
Set the
.Ar user
blob - 63765fdf80169fd36e5e5f8bddcb9d6ce50c40bdba8db1d4403a54276dbd482e
blob + 5cc79791938726d4a4744617b44443ae1f117e6fd472e133fc95539764871ee9
--- gotsysd/gotsysd.h
+++ gotsysd/gotsysd.h
GOTSYSD_WEB_AUTH_INSECURE = 0x0f7f7f00
};
+enum gotsysd_web_redirect_method {
+ GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH,
+ GOTSYSD_WEB_REDIRECT_METHOD_STATUS_CODE
+};
+
enum gotsysd_web_address_family {
GOTSYSD_LISTEN_ADDR_UNIX = 0,
GOTSYSD_LISTEN_ADDR_INET,
char login_hint_user[MAX_IDENTIFIER_SIZE];
char login_hint_port[8];
+ enum gotsysd_web_redirect_method redirect_method;
enum gotsysd_web_auth_config auth_config;
struct gotsysd_web_addresslist listen_addrs;
struct gotsysd_web_serverlist servers;
blob - 47e8149e1f629f7a94a65335545503d20982da0ffe9af240b7d57ef7f934a0e2
blob + 29f186d581971e23760620cfdabe086bd28686305d35123fa5f3ab57b31173bf
--- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
+++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
}
+ switch (webcfg.redirect_method) {
+ case GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH:
+ ret = dprintf(fd, "redirect_method page_refresh\n");
+ if (ret == -1)
+ return got_error_from_errno2("dprintf", path);
+ if (ret != 29) {
+ return got_error_fmt(GOT_ERR_IO, "short write to %s",
+ path);
+ }
+ break;
+ case GOTSYSD_WEB_REDIRECT_METHOD_STATUS_CODE:
+ ret = dprintf(fd, "redirect_method status_code\n");
+ if (ret == -1)
+ return got_error_from_errno2("dprintf", path);
+ if (ret != 28) {
+ return got_error_fmt(GOT_ERR_IO, "short write to %s",
+ path);
+ }
+ break;
+ }
+
switch (webcfg.auth_config) {
case GOTSYSD_WEB_AUTH_UNSET:
break;
blob - 1840729815167cee388cf8d878cfca9e88ae239209c607eb8b5bed469a5e0889
blob + 2602f09c74aec036807a1f1d9d9032c66d9fa100aeef421a8ea58ee5ed5c1f34
--- gotsysd/parse.y
+++ gotsysd/parse.y
%token HTDOCS INSECURE PORT PREFORK SERVER NAME SOCKET WWW HINT SHOW_REPO_AGE
%token ERROR LISTEN ON USER GOTD DIRECTORY REPOSITORY UID RANGE PERMIT
%token DENY RO RW WEB GOTSYSD_LOGIN ENABLE DISABLE HIDE REPOSITORIES
+%token REDIRECT_METHOD PAGE_REFRESH STATUS_CODE
%token <v.string> STRING
%token <v.number> NUMBER
}
gotsysd->web.auth_config = GOTSYSD_WEB_AUTH_INSECURE;
}
+ | REDIRECT_METHOD PAGE_REFRESH {
+ gotsysd->web.redirect_method =
+ GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH;
+ }
+ | REDIRECT_METHOD STATUS_CODE {
+ gotsysd->web.redirect_method =
+ GOTSYSD_WEB_REDIRECT_METHOD_STATUS_CODE;
+ }
;
webopts2 : webopts2 webopts1 nl
{ "login", GOTSYSD_LOGIN },
{ "name", NAME },
{ "on", ON },
+ { "page_refresh", PAGE_REFRESH },
{ "permit", PERMIT },
{ "port", PORT },
{ "prefork", PREFORK },
{ "range", RANGE },
+ { "redirect_method", REDIRECT_METHOD },
{ "repositories", REPOSITORIES },
{ "repository", REPOSITORY },
{ "ro", RO },
{ "server", SERVER },
{ "show_repo_age", SHOW_REPO_AGE },
{ "socket", SOCKET },
+ { "status_code", STATUS_CODE },
{ "uid", UID },
{ "user", USER },
{ "web", WEB },
blob - 26b70536e74a0d008e6fa8d7536140c5cff9a0d4a34b498693a4da18bb4dd8af
blob + 168b2171ffb0ca52fa31c0a3c3242dbd78195e03bab389605a559fee2514a607
--- gotwebd/auth.c
+++ gotwebd/auth.c
char *token = NULL;
const char *identifier = NULL;
const time_t validity = 24 * 60 * 60; /* 1 day */
+ struct gotweb_url url;
struct gotwebd_repo *repo;
int r;
goto err;
}
- if (gotweb_reply(c, 200, "text/html", NULL) == -1)
- return;
- gotweb_render_refresh_redirect(c->tp);
+ switch (srv->redirect_method) {
+ case GOTWEBD_REDIRECT_METHOD_UNSET:
+ case GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH:
+ if (gotweb_reply(c, 200, "text/html", NULL) == -1)
+ return;
+ gotweb_render_refresh_redirect(c->tp);
+ break;
+ case GOTWEBD_REDIRECT_METHOD_STATUS_CODE:
+ memset(&url, 0, sizeof(url));
+ url.action = INDEX;
+ gotweb_reply(c, 307, "text/html", &url);
+ break;
+ }
return;
blob - 0eb76c0205979ce822876db213d9fd8c17e7abd3ff360f75e7361f2cd03c4df9
blob + 7551b93a0d85dd27c717c5776f714d5c64d67337d30838b128f19294f21b8e7f
--- gotwebd/config.c
+++ gotwebd/config.c
strlcpy(env->htdocs_path, D_HTDOCS_PATH, sizeof(env->htdocs_path));
strlcpy(env->gotweb_url_root, "/", sizeof(env->gotweb_url_root));
+ env->redirect_method = D_REDIRECT_METHOD;
+
env->prefork = GOTWEBD_NUMPROC;
TAILQ_INIT(&env->servers);
TAILQ_INIT(&env->sockets);
blob - e773a2271e42e904099db29aca4ed0627c6084a5498ab20ef97188a45bee441b
blob + 0a87481cb50a10ed9748985d09ed194a671a6026ffef432942b83c583a9690b6
--- gotwebd/gotwebd.conf.5
+++ gotwebd/gotwebd.conf.5
.Xr httpd 8 .
.Pp
This setting can also be configured on a per-server basis.
+.It Ic redirect_method Ar method
+Set the
+.Ar method
+used by
+.Xr gotwebd 8
+when redirecting clients to another page, such as from the login page
+to the summary page.
+.Pp
+The available methods are:
+.Bl -tag -width Ds
+.It page_refresh
+Send HTTP response status code 200 (success) and serve a
+.Dv meta
+tag in the HTML response body with the
+.Dv http-equiv
+attribute set to
+.Dq refresh
+and a new URL in the
+.Dv url
+attribute.
+.Pp
+This method is the default and provides good browser compatibility overall.
+.pp
+This method can get in the way of scripts trying to navigate through a
+.Xr gotsh 1
+.Cm weblogin
+link, which is usually desirable, but not always.
+.It status_code
+Send HTTP response status code 307 (redirect) with a target URL in HTTP
+headers and with an empty response body.
+.Pp
+This method generally works as expected.
+In some situations browsers fail to follow the redirect and display the
+redirecting page instead.
+For example,
+.Xr gotsh 1
+.Cm weblogin
+links have been known to fail loading the summary page if the redirecting
+link is opened by an external application asking Mozilla Firefox to open
+the login link, even though the redirect is followed as expected when
+the login link is visited via the browser's address bar.
+.El
.It Ic repos_url_path Ar path
Sets the URL path under which Git repositories will be displayed by
.Xr gotwebd 8 .
blob - baedf7154aaebcea7787e9cbb4ba372e01f7885f946c965e5a07b85cd88b3cd5
blob + 95317c0793464be5ce6e837738dda479416609d6250fed5afacf36425b883aa7
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
#define D_MAXSLCOMMDISP 10
#define D_MAXCOMMITDISP 25
#define D_MAXSLTAGDISP 3
+#define D_REDIRECT_METHOD GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH
#define BUF 8192
struct got_tree_entry;
struct got_reflist_head;
+enum gotwebd_redirect_method {
+ GOTWEBD_REDIRECT_METHOD_UNSET,
+ GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH,
+ GOTWEBD_REDIRECT_METHOD_STATUS_CODE,
+};
+
enum gotwebd_proc_type {
GOTWEBD_PROC_PARENT,
GOTWEBD_PROC_SOCKETS,
enum gotwebd_auth_config auth_config;
struct gotwebd_access_rule_list access_rules;
+ enum gotwebd_redirect_method redirect_method;
+
struct gotwebd_repolist repos;
struct got_pathlist_head websites;
};
char login_hint_user[MAX_IDENTIFIER_SIZE];
char login_hint_port[GOTWEBD_MAXPORT];
+
+ enum gotwebd_redirect_method redirect_method;
};
/*
blob - 9688d9e288f654ceeb75559a3266938ca90733666bae766c6e58a93964f64c33
blob + c8c047ca1f3587958b6505e3da87d3768b579f40f66a9148857ad48ca80abd3f
--- gotwebd/parse.y
+++ gotwebd/parse.y
%token WEBSITE PATH BRANCH REPOS_URL_PATH DESCRIPTION
%token TYPES INCLUDE GOTWEBD_CONTROL
%token SSH_HOSTKEY_ECDSA SSH_HOSTKEY_ED25519 SSH_HOSTKEY_RSA
+%token REDIRECT_METHOD STATUS_CODE PAGE_REFRESH
%token <v.string> STRING
%token <v.number> NUMBER
free($2);
}
+ | REDIRECT_METHOD STATUS_CODE {
+ gotwebd->redirect_method =
+ GOTWEBD_REDIRECT_METHOD_STATUS_CODE;
+ }
+ | REDIRECT_METHOD PAGE_REFRESH {
+ gotwebd->redirect_method =
+ GOTWEBD_REDIRECT_METHOD_PAGE_REFRESH;
+ }
;
server : SERVER STRING {
{ "max_commits_display", MAX_COMMITS_DISPLAY },
{ "max_repos_display", MAX_REPOS_DISPLAY },
{ "on", ON },
+ { "page_refresh", PAGE_REFRESH },
{ "path", PATH },
{ "permit", PERMIT },
{ "port", PORT },
{ "prefork", PREFORK },
+ { "redirect_method", REDIRECT_METHOD },
{ "repos_path", REPOS_PATH },
{ "repos_url_path", REPOS_URL_PATH },
{ "repositories", REPOSITORIES },
{ "ssh_hostkey_ecdsa", SSH_HOSTKEY_ECDSA},
{ "ssh_hostkey_ed25519", SSH_HOSTKEY_ED25519},
{ "ssh_hostkey_rsa", SSH_HOSTKEY_RSA},
+ { "status_code", STATUS_CODE },
{ "summary_commits_display", SUMMARY_COMMITS_DISPLAY },
{ "summary_tags_display", SUMMARY_TAGS_DISPLAY },
{ "types", TYPES },
return -1;
}
}
+
+ /*
+ * The redirect method is not configurable on a per-server
+ * basis in gotwebd.conf so currently it will always be UNSET.
+ *
+ * And gotwebd child processes will not see fields that are
+ * set in our global env, unless we copy them across manually.
+ * For now, let this field ride along in per-server config.
+ * Maybe it will become configurable on a per-server basis
+ * eventually, in which case this code remains correct.
+ */
+ if (srv->redirect_method == GOTWEBD_REDIRECT_METHOD_UNSET)
+ srv->redirect_method = env->redirect_method;
}
TAILQ_FOREACH(srv, &env->servers, entry) {
TAILQ_INIT(&srv->repos);
RB_INIT(&srv->websites);
+ srv->redirect_method = GOTWEBD_REDIRECT_METHOD_UNSET;
+
TAILQ_INSERT_TAIL(&gotwebd->servers, srv, entry);
return srv;
blob - 08a01601508057ed5a38b2da6fe49db5d1a49bf56a5be5ad7d6e5277d65a5392
blob + 00824b174c59b4eb0cbb7c0af3268eede16687bfe1a0bd51f9133f8e342bb40b
--- lib/gotsys_imsg.c
+++ lib/gotsys_imsg.c
TAILQ_INIT(&webcfg->listen_addrs);
STAILQ_INIT(&webcfg->servers);
webcfg->auth_config = GOTSYSD_WEB_AUTH_UNSET;
+ webcfg->redirect_method = GOTSYSD_WEB_REDIRECT_METHOD_PAGE_REFRESH;
}
const struct got_error *
blob - 6fd1cbe4540d20332ee16bcae92b69ee52ff0526e8214571736d227180c6e88e
blob + 0aa2fe071737a49dbfe329c62750867b57620d176fd66e0ca17cce641f97ae25
--- regress/gotsysd/Makefile
+++ regress/gotsysd/Makefile
@${UNPRIV} "printf '\tprefork 1\n' >> $@"
@${UNPRIV} "printf '\tenable authentication insecure\n' >> $@"
@${UNPRIV} "printf '\tlogin hint user \"${GOTSYSD_TEST_USER}\"\n' >> $@"
+ @${UNPRIV} "printf '\tredirect_method status_code\n' >> $@"
@${UNPRIV} "printf '\tlisten on socket \\\"/var/www/run/gotweb.sock\\\"\n' >> $@"
@${UNPRIV} "printf '\tlisten on 127.0.0.1 port 9000\n' >> $@"
@${UNPRIV} "printf '\tlisten on ::1 port 9000\n' >> $@"