From 8c764ec13636964e415315bf42e2cd74d41a7ba8 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Apr 2022 16:03:43 -0400 Subject: [PATCH 1/4] Allow custom redirect for landing page --- custom/conf/app.example.ini | 5 ++++- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 3 ++- modules/setting/setting.go | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 822be00baeb24..0dc9f29cd64c3 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -237,10 +237,13 @@ RUN_MODE = ; prod ;; PPROF_DATA_PATH, use an absolute path when you start gitea as service ;PPROF_DATA_PATH = data/tmp/pprof ;; -;; Landing page, can be "home", "explore", "organizations" or "login" +;; Landing page, can be "home", "explore", "organizations", "login", or "custom" ;; The "login" choice is not a security measure but just a UI flow change, use REQUIRE_SIGNIN_VIEW to force users to log in. ;LANDING_PAGE = home ;; +;; URL for landing page redirect if `LANDING_PAGE` is set to `custom` +;LANDING_PAGE_CUSTOM = +;; ;; Enables git-lfs support. true or false, default is false. ;LFS_START_SERVER = false ;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index b3c015cb88dd7..e92dd96e17861 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -300,7 +300,8 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `ENABLE_GZIP`: **false**: Enable gzip compression for runtime-generated content, static resources excluded. - `ENABLE_PPROF`: **false**: Application profiling (memory and cpu). For "web" command it listens on localhost:6060. For "serv" command it dumps to disk at `PPROF_DATA_PATH` as `(cpuprofile|memprofile)__` - `PPROF_DATA_PATH`: **data/tmp/pprof**: `PPROF_DATA_PATH`, use an absolute path when you start Gitea as service -- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore, organizations, login\]. +- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore, organizations, login, custom\]. +- `LANDING_PAGE_CUSTOM`: ****: If `LANDING_PAGE` is set to `custom`, this is the URL for the custom landing page redirect. - `LFS_START_SERVER`: **false**: Enables Git LFS support. - `LFS_CONTENT_PATH`: **%(APP_DATA_PATH)/lfs**: Default LFS content path. (if it is on local storage.) **DEPRECATED** use settings in `[lfs]`. diff --git a/modules/setting/setting.go b/modules/setting/setting.go index ed91382de37b6..afaeb065ea15e 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -106,6 +106,7 @@ var ( StaticCacheTime time.Duration EnableGzip bool LandingPageURL LandingPage + LandingPageCustom string UnixSocketPermission uint32 EnablePprof bool PprofDataPath string @@ -776,6 +777,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) { PprofDataPath = filepath.Join(AppWorkPath, PprofDataPath) } + LandingPageURL = LandingPageHome switch sec.Key("LANDING_PAGE").MustString("home") { case "explore": LandingPageURL = LandingPageExplore @@ -783,8 +785,11 @@ func loadFromConf(allowEmpty bool, extraConfig string) { LandingPageURL = LandingPageOrganizations case "login": LandingPageURL = LandingPageLogin - default: - LandingPageURL = LandingPageHome + case "custom": + customUrl := LandingPage(sec.Key("LANDING_PAGE_CUSTOM").MustString("")) + if customUrl != "" { + LandingPageURL = customUrl + } } if len(SSH.Domain) == 0 { From 07a6e3e8bd6668b8783a22f2cc1eeef65f4340f5 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Apr 2022 18:26:42 -0400 Subject: [PATCH 2/4] Update modules/setting/setting.go Co-authored-by: delvh --- modules/setting/setting.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index afaeb065ea15e..79c5f9d0ce3c6 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -786,9 +786,9 @@ func loadFromConf(allowEmpty bool, extraConfig string) { case "login": LandingPageURL = LandingPageLogin case "custom": - customUrl := LandingPage(sec.Key("LANDING_PAGE_CUSTOM").MustString("")) + customUrl := sec.Key("LANDING_PAGE_CUSTOM").MustString("") if customUrl != "" { - LandingPageURL = customUrl + LandingPageURL = LandingPage(customUrl) } } From 23579ab1208816ec4894c3bc528677f7e0e19864 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Apr 2022 18:28:04 -0400 Subject: [PATCH 3/4] fix lint --- modules/setting/setting.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 79c5f9d0ce3c6..cb8e7e5d77ab1 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -786,9 +786,9 @@ func loadFromConf(allowEmpty bool, extraConfig string) { case "login": LandingPageURL = LandingPageLogin case "custom": - customUrl := sec.Key("LANDING_PAGE_CUSTOM").MustString("") - if customUrl != "" { - LandingPageURL = LandingPage(customUrl) + customURL := sec.Key("LANDING_PAGE_CUSTOM").MustString("") + if customURL != "" { + LandingPageURL = LandingPage(customURL) } } From 8b475c4cd239f4974a37b162eeecaeb1fc464f55 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Apr 2022 11:41:34 -0400 Subject: [PATCH 4/4] one option --- custom/conf/app.example.ini | 5 +---- .../doc/advanced/config-cheat-sheet.en-us.md | 4 +--- modules/setting/setting.go | 14 +++++++------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 0dc9f29cd64c3..df49851311883 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -237,13 +237,10 @@ RUN_MODE = ; prod ;; PPROF_DATA_PATH, use an absolute path when you start gitea as service ;PPROF_DATA_PATH = data/tmp/pprof ;; -;; Landing page, can be "home", "explore", "organizations", "login", or "custom" +;; Landing page, can be "home", "explore", "organizations", "login", or any URL such as "/org/repo" or even "https://anotherwebsite.com" ;; The "login" choice is not a security measure but just a UI flow change, use REQUIRE_SIGNIN_VIEW to force users to log in. ;LANDING_PAGE = home ;; -;; URL for landing page redirect if `LANDING_PAGE` is set to `custom` -;LANDING_PAGE_CUSTOM = -;; ;; Enables git-lfs support. true or false, default is false. ;LFS_START_SERVER = false ;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index e92dd96e17861..fc4b1bc768e6b 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -300,9 +300,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `ENABLE_GZIP`: **false**: Enable gzip compression for runtime-generated content, static resources excluded. - `ENABLE_PPROF`: **false**: Application profiling (memory and cpu). For "web" command it listens on localhost:6060. For "serv" command it dumps to disk at `PPROF_DATA_PATH` as `(cpuprofile|memprofile)__` - `PPROF_DATA_PATH`: **data/tmp/pprof**: `PPROF_DATA_PATH`, use an absolute path when you start Gitea as service -- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore, organizations, login, custom\]. -- `LANDING_PAGE_CUSTOM`: ****: If `LANDING_PAGE` is set to `custom`, this is the URL for the custom landing page redirect. - +- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore, organizations, login, **custom**\]. Where custom would instead be any URL such as "/org/repo" or even "https://anotherwebsite.com" - `LFS_START_SERVER`: **false**: Enables Git LFS support. - `LFS_CONTENT_PATH`: **%(APP_DATA_PATH)/lfs**: Default LFS content path. (if it is on local storage.) **DEPRECATED** use settings in `[lfs]`. - `LFS_JWT_SECRET`: **\**: LFS authentication secret, change this a unique string. diff --git a/modules/setting/setting.go b/modules/setting/setting.go index cb8e7e5d77ab1..5e317b39ea289 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -777,19 +777,19 @@ func loadFromConf(allowEmpty bool, extraConfig string) { PprofDataPath = filepath.Join(AppWorkPath, PprofDataPath) } - LandingPageURL = LandingPageHome - switch sec.Key("LANDING_PAGE").MustString("home") { + landingPage := sec.Key("LANDING_PAGE").MustString("home") + switch landingPage { case "explore": LandingPageURL = LandingPageExplore case "organizations": LandingPageURL = LandingPageOrganizations case "login": LandingPageURL = LandingPageLogin - case "custom": - customURL := sec.Key("LANDING_PAGE_CUSTOM").MustString("") - if customURL != "" { - LandingPageURL = LandingPage(customURL) - } + case "": + case "home": + LandingPageURL = LandingPageHome + default: + LandingPageURL = LandingPage(landingPage) } if len(SSH.Domain) == 0 {