You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

setting.go 32 kB

11 years ago
11 years ago
11 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
11 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
11 years ago
11 years ago
11 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
9 years ago
11 years ago
11 years ago
9 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
10 years ago
10 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "crypto/rand"
  7. "encoding/base64"
  8. "fmt"
  9. "io"
  10. "net/mail"
  11. "net/url"
  12. "os"
  13. "os/exec"
  14. "path"
  15. "path/filepath"
  16. "runtime"
  17. "strconv"
  18. "strings"
  19. "time"
  20. "code.gitea.io/git"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/user"
  23. "github.com/Unknwon/com"
  24. _ "github.com/go-macaron/cache/memcache" // memcache plugin for cache
  25. _ "github.com/go-macaron/cache/redis"
  26. "github.com/go-macaron/session"
  27. _ "github.com/go-macaron/session/redis" // redis plugin for store session
  28. _ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services
  29. "gopkg.in/ini.v1"
  30. "strk.kbt.io/projects/go/libravatar"
  31. )
  32. // Scheme describes protocol types
  33. type Scheme string
  34. // enumerates all the scheme types
  35. const (
  36. HTTP Scheme = "http"
  37. HTTPS Scheme = "https"
  38. FCGI Scheme = "fcgi"
  39. UnixSocket Scheme = "unix"
  40. )
  41. // LandingPage describes the default page
  42. type LandingPage string
  43. // enumerates all the landing page types
  44. const (
  45. LandingPageHome LandingPage = "/"
  46. LandingPageExplore LandingPage = "/explore"
  47. )
  48. // settings
  49. var (
  50. // AppVer settings
  51. AppVer string
  52. AppName string
  53. AppURL string
  54. AppSubURL string
  55. AppSubURLDepth int // Number of slashes
  56. AppPath string
  57. AppDataPath string
  58. // Server settings
  59. Protocol Scheme
  60. Domain string
  61. HTTPAddr string
  62. HTTPPort string
  63. LocalURL string
  64. OfflineMode bool
  65. DisableRouterLog bool
  66. CertFile string
  67. KeyFile string
  68. StaticRootPath string
  69. EnableGzip bool
  70. LandingPageURL LandingPage
  71. UnixSocketPermission uint32
  72. SSH = struct {
  73. Disabled bool `ini:"DISABLE_SSH"`
  74. StartBuiltinServer bool `ini:"START_SSH_SERVER"`
  75. Domain string `ini:"SSH_DOMAIN"`
  76. Port int `ini:"SSH_PORT"`
  77. ListenHost string `ini:"SSH_LISTEN_HOST"`
  78. ListenPort int `ini:"SSH_LISTEN_PORT"`
  79. RootPath string `ini:"SSH_ROOT_PATH"`
  80. KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
  81. KeygenPath string `ini:"SSH_KEYGEN_PATH"`
  82. MinimumKeySizeCheck bool `ini:"-"`
  83. MinimumKeySizes map[string]int `ini:"-"`
  84. }{
  85. Disabled: false,
  86. StartBuiltinServer: false,
  87. Domain: "localhost",
  88. Port: 22,
  89. KeygenPath: "ssh-keygen",
  90. }
  91. LFS struct {
  92. StartServer bool `ini:"LFS_START_SERVER"`
  93. ContentPath string `ini:"LFS_CONTENT_PATH"`
  94. JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
  95. JWTSecretBytes []byte `ini:"-"`
  96. }
  97. // Security settings
  98. InstallLock bool
  99. SecretKey string
  100. LogInRememberDays int
  101. CookieUserName string
  102. CookieRememberName string
  103. ReverseProxyAuthUser string
  104. MinPasswordLength int
  105. ImportLocalPaths bool
  106. // Database settings
  107. UseSQLite3 bool
  108. UseMySQL bool
  109. UseMSSQL bool
  110. UsePostgreSQL bool
  111. UseTiDB bool
  112. // Indexer settings
  113. Indexer struct {
  114. IssuePath string
  115. UpdateQueueLength int
  116. }
  117. // Webhook settings
  118. Webhook = struct {
  119. QueueLength int
  120. DeliverTimeout int
  121. SkipTLSVerify bool
  122. Types []string
  123. PagingNum int
  124. }{
  125. QueueLength: 1000,
  126. DeliverTimeout: 5,
  127. SkipTLSVerify: false,
  128. PagingNum: 10,
  129. }
  130. // Repository settings
  131. Repository = struct {
  132. AnsiCharset string
  133. ForcePrivate bool
  134. MaxCreationLimit int
  135. MirrorQueueLength int
  136. PullRequestQueueLength int
  137. PreferredLicenses []string
  138. DisableHTTPGit bool
  139. // Repository editor settings
  140. Editor struct {
  141. LineWrapExtensions []string
  142. PreviewableFileModes []string
  143. } `ini:"-"`
  144. // Repository upload settings
  145. Upload struct {
  146. Enabled bool
  147. TempPath string
  148. AllowedTypes []string `delim:"|"`
  149. FileMaxSize int64
  150. MaxFiles int
  151. } `ini:"-"`
  152. }{
  153. AnsiCharset: "",
  154. ForcePrivate: false,
  155. MaxCreationLimit: -1,
  156. MirrorQueueLength: 1000,
  157. PullRequestQueueLength: 1000,
  158. PreferredLicenses: []string{"Apache License 2.0,MIT License"},
  159. DisableHTTPGit: false,
  160. // Repository editor settings
  161. Editor: struct {
  162. LineWrapExtensions []string
  163. PreviewableFileModes []string
  164. }{
  165. LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
  166. PreviewableFileModes: []string{"markdown"},
  167. },
  168. // Repository upload settings
  169. Upload: struct {
  170. Enabled bool
  171. TempPath string
  172. AllowedTypes []string `delim:"|"`
  173. FileMaxSize int64
  174. MaxFiles int
  175. }{
  176. Enabled: true,
  177. TempPath: "data/tmp/uploads",
  178. AllowedTypes: []string{},
  179. FileMaxSize: 3,
  180. MaxFiles: 5,
  181. },
  182. }
  183. RepoRootPath string
  184. ScriptType = "bash"
  185. // UI settings
  186. UI = struct {
  187. ExplorePagingNum int
  188. IssuePagingNum int
  189. FeedMaxCommitNum int
  190. ThemeColorMetaTag string
  191. MaxDisplayFileSize int64
  192. ShowUserEmail bool
  193. Admin struct {
  194. UserPagingNum int
  195. RepoPagingNum int
  196. NoticePagingNum int
  197. OrgPagingNum int
  198. } `ini:"ui.admin"`
  199. User struct {
  200. RepoPagingNum int
  201. } `ini:"ui.user"`
  202. }{
  203. ExplorePagingNum: 20,
  204. IssuePagingNum: 10,
  205. FeedMaxCommitNum: 5,
  206. ThemeColorMetaTag: `#6cc644`,
  207. MaxDisplayFileSize: 8388608,
  208. Admin: struct {
  209. UserPagingNum int
  210. RepoPagingNum int
  211. NoticePagingNum int
  212. OrgPagingNum int
  213. }{
  214. UserPagingNum: 50,
  215. RepoPagingNum: 50,
  216. NoticePagingNum: 25,
  217. OrgPagingNum: 50,
  218. },
  219. User: struct {
  220. RepoPagingNum int
  221. }{
  222. RepoPagingNum: 15,
  223. },
  224. }
  225. // Markdown sttings
  226. Markdown = struct {
  227. EnableHardLineBreak bool
  228. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  229. FileExtensions []string
  230. }{
  231. EnableHardLineBreak: false,
  232. FileExtensions: strings.Split(".md,.markdown,.mdown,.mkd", ","),
  233. }
  234. // Picture settings
  235. AvatarUploadPath string
  236. GravatarSource string
  237. DisableGravatar bool
  238. EnableFederatedAvatar bool
  239. LibravatarService *libravatar.Libravatar
  240. // Log settings
  241. LogRootPath string
  242. LogModes []string
  243. LogConfigs []string
  244. // Attachment settings
  245. AttachmentPath string
  246. AttachmentAllowedTypes string
  247. AttachmentMaxSize int64
  248. AttachmentMaxFiles int
  249. AttachmentEnabled bool
  250. // Time settings
  251. TimeFormat string
  252. // Cache settings
  253. CacheAdapter string
  254. CacheInterval int
  255. CacheConn string
  256. // Session settings
  257. SessionConfig session.Options
  258. CSRFCookieName = "_csrf"
  259. // Cron tasks
  260. Cron = struct {
  261. UpdateMirror struct {
  262. Enabled bool
  263. RunAtStart bool
  264. Schedule string
  265. } `ini:"cron.update_mirrors"`
  266. RepoHealthCheck struct {
  267. Enabled bool
  268. RunAtStart bool
  269. Schedule string
  270. Timeout time.Duration
  271. Args []string `delim:" "`
  272. } `ini:"cron.repo_health_check"`
  273. CheckRepoStats struct {
  274. Enabled bool
  275. RunAtStart bool
  276. Schedule string
  277. } `ini:"cron.check_repo_stats"`
  278. }{
  279. UpdateMirror: struct {
  280. Enabled bool
  281. RunAtStart bool
  282. Schedule string
  283. }{
  284. Schedule: "@every 10m",
  285. },
  286. RepoHealthCheck: struct {
  287. Enabled bool
  288. RunAtStart bool
  289. Schedule string
  290. Timeout time.Duration
  291. Args []string `delim:" "`
  292. }{
  293. Schedule: "@every 24h",
  294. Timeout: 60 * time.Second,
  295. Args: []string{},
  296. },
  297. CheckRepoStats: struct {
  298. Enabled bool
  299. RunAtStart bool
  300. Schedule string
  301. }{
  302. RunAtStart: true,
  303. Schedule: "@every 24h",
  304. },
  305. }
  306. // Git settings
  307. Git = struct {
  308. DisableDiffHighlight bool
  309. MaxGitDiffLines int
  310. MaxGitDiffLineCharacters int
  311. MaxGitDiffFiles int
  312. GCArgs []string `delim:" "`
  313. Timeout struct {
  314. Migrate int
  315. Mirror int
  316. Clone int
  317. Pull int
  318. GC int `ini:"GC"`
  319. } `ini:"git.timeout"`
  320. }{
  321. DisableDiffHighlight: false,
  322. MaxGitDiffLines: 1000,
  323. MaxGitDiffLineCharacters: 500,
  324. MaxGitDiffFiles: 100,
  325. GCArgs: []string{},
  326. Timeout: struct {
  327. Migrate int
  328. Mirror int
  329. Clone int
  330. Pull int
  331. GC int `ini:"GC"`
  332. }{
  333. Migrate: 600,
  334. Mirror: 300,
  335. Clone: 300,
  336. Pull: 300,
  337. GC: 60,
  338. },
  339. }
  340. // Mirror settings
  341. Mirror = struct {
  342. DefaultInterval int
  343. }{
  344. DefaultInterval: 8,
  345. }
  346. // API settings
  347. API = struct {
  348. MaxResponseItems int
  349. }{
  350. MaxResponseItems: 50,
  351. }
  352. // I18n settings
  353. Langs []string
  354. Names []string
  355. dateLangs map[string]string
  356. // Highlight settings are loaded in modules/template/hightlight.go
  357. // Other settings
  358. ShowFooterBranding bool
  359. ShowFooterVersion bool
  360. ShowFooterTemplateLoadTime bool
  361. // Global setting objects
  362. Cfg *ini.File
  363. CustomPath string // Custom directory path
  364. CustomConf string
  365. CustomPID string
  366. ProdMode bool
  367. RunUser string
  368. IsWindows bool
  369. HasRobotsTxt bool
  370. )
  371. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  372. func DateLang(lang string) string {
  373. name, ok := dateLangs[lang]
  374. if ok {
  375. return name
  376. }
  377. return "en"
  378. }
  379. // execPath returns the executable path.
  380. func execPath() (string, error) {
  381. file, err := exec.LookPath(os.Args[0])
  382. if err != nil {
  383. return "", err
  384. }
  385. return filepath.Abs(file)
  386. }
  387. func init() {
  388. IsWindows = runtime.GOOS == "windows"
  389. log.NewLogger(0, "console", `{"level": 0}`)
  390. var err error
  391. if AppPath, err = execPath(); err != nil {
  392. log.Fatal(4, "fail to get app path: %v\n", err)
  393. }
  394. // Note: we don't use path.Dir here because it does not handle case
  395. // which path starts with two "/" in Windows: "//psf/Home/..."
  396. AppPath = strings.Replace(AppPath, "\\", "/", -1)
  397. }
  398. // WorkDir returns absolute path of work directory.
  399. func WorkDir() (string, error) {
  400. wd := os.Getenv("GITEA_WORK_DIR")
  401. if len(wd) > 0 {
  402. return wd, nil
  403. }
  404. // Use GOGS_WORK_DIR if available, for backward compatibility
  405. // TODO: drop in 1.1.0 ?
  406. wd = os.Getenv("GOGS_WORK_DIR")
  407. if len(wd) > 0 {
  408. log.Warn(`Usage of GOGS_WORK_DIR is deprecated and will be *removed* in a future release,
  409. please consider changing to GITEA_WORK_DIR`)
  410. return wd, nil
  411. }
  412. i := strings.LastIndex(AppPath, "/")
  413. if i == -1 {
  414. return AppPath, nil
  415. }
  416. return AppPath[:i], nil
  417. }
  418. func forcePathSeparator(path string) {
  419. if strings.Contains(path, "\\") {
  420. log.Fatal(4, "Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
  421. }
  422. }
  423. // IsRunUserMatchCurrentUser returns false if configured run user does not match
  424. // actual user that runs the app. The first return value is the actual user name.
  425. // This check is ignored under Windows since SSH remote login is not the main
  426. // method to login on Windows.
  427. func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
  428. if IsWindows {
  429. return "", true
  430. }
  431. currentUser := user.CurrentUsername()
  432. return currentUser, runUser == currentUser
  433. }
  434. func createPIDFile(pidPath string) {
  435. currentPid := os.Getpid()
  436. if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil {
  437. log.Fatal(4, "Can't create PID folder on %s", err)
  438. }
  439. file, err := os.Create(pidPath)
  440. if err != nil {
  441. log.Fatal(4, "Can't create PID file: %v", err)
  442. }
  443. defer file.Close()
  444. if _, err := file.WriteString(strconv.FormatInt(int64(currentPid), 10)); err != nil {
  445. log.Fatal(4, "Can'write PID information on %s", err)
  446. }
  447. }
  448. // NewContext initializes configuration context.
  449. // NOTE: do not print any log except error.
  450. func NewContext() {
  451. workDir, err := WorkDir()
  452. if err != nil {
  453. log.Fatal(4, "Fail to get work directory: %v", err)
  454. }
  455. Cfg = ini.Empty()
  456. if err != nil {
  457. log.Fatal(4, "Fail to parse 'app.ini': %v", err)
  458. }
  459. CustomPath = os.Getenv("GITEA_CUSTOM")
  460. if len(CustomPath) == 0 {
  461. // For backward compatibility
  462. // TODO: drop in 1.1.0 ?
  463. CustomPath = os.Getenv("GOGS_CUSTOM")
  464. if len(CustomPath) == 0 {
  465. CustomPath = workDir + "/custom"
  466. } else {
  467. log.Warn(`Usage of GOGS_CUSTOM is deprecated and will be *removed* in a future release,
  468. please consider changing to GITEA_CUSTOM`)
  469. }
  470. }
  471. if len(CustomPID) > 0 {
  472. createPIDFile(CustomPID)
  473. }
  474. if len(CustomConf) == 0 {
  475. CustomConf = CustomPath + "/conf/app.ini"
  476. }
  477. if com.IsFile(CustomConf) {
  478. if err = Cfg.Append(CustomConf); err != nil {
  479. log.Fatal(4, "Fail to load custom conf '%s': %v", CustomConf, err)
  480. }
  481. } else {
  482. log.Warn("Custom config '%s' not found, ignore this if you're running first time", CustomConf)
  483. }
  484. Cfg.NameMapper = ini.AllCapsUnderscore
  485. homeDir, err := com.HomeDir()
  486. if err != nil {
  487. log.Fatal(4, "Fail to get home directory: %v", err)
  488. }
  489. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  490. LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log"))
  491. forcePathSeparator(LogRootPath)
  492. sec := Cfg.Section("server")
  493. AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
  494. AppURL = sec.Key("ROOT_URL").MustString("http://localhost:3000/")
  495. if AppURL[len(AppURL)-1] != '/' {
  496. AppURL += "/"
  497. }
  498. // Check if has app suburl.
  499. url, err := url.Parse(AppURL)
  500. if err != nil {
  501. log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err)
  502. }
  503. // Suburl should start with '/' and end without '/', such as '/{subpath}'.
  504. // This value is empty if site does not have sub-url.
  505. AppSubURL = strings.TrimSuffix(url.Path, "/")
  506. AppSubURLDepth = strings.Count(AppSubURL, "/")
  507. Protocol = HTTP
  508. if sec.Key("PROTOCOL").String() == "https" {
  509. Protocol = HTTPS
  510. CertFile = sec.Key("CERT_FILE").String()
  511. KeyFile = sec.Key("KEY_FILE").String()
  512. } else if sec.Key("PROTOCOL").String() == "fcgi" {
  513. Protocol = FCGI
  514. } else if sec.Key("PROTOCOL").String() == "unix" {
  515. Protocol = UnixSocket
  516. UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
  517. UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
  518. if err != nil || UnixSocketPermissionParsed > 0777 {
  519. log.Fatal(4, "Fail to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
  520. }
  521. UnixSocketPermission = uint32(UnixSocketPermissionParsed)
  522. }
  523. Domain = sec.Key("DOMAIN").MustString("localhost")
  524. HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
  525. HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
  526. LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(string(Protocol) + "://localhost:" + HTTPPort + "/")
  527. OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
  528. DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()
  529. StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(workDir)
  530. AppDataPath = sec.Key("APP_DATA_PATH").MustString("data")
  531. EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
  532. switch sec.Key("LANDING_PAGE").MustString("home") {
  533. case "explore":
  534. LandingPageURL = LandingPageExplore
  535. default:
  536. LandingPageURL = LandingPageHome
  537. }
  538. SSH.RootPath = path.Join(homeDir, ".ssh")
  539. SSH.KeyTestPath = os.TempDir()
  540. if err = Cfg.Section("server").MapTo(&SSH); err != nil {
  541. log.Fatal(4, "Fail to map SSH settings: %v", err)
  542. }
  543. SSH.KeygenPath = sec.Key("SSH_KEYGEN_PATH").MustString("ssh-keygen")
  544. SSH.Port = sec.Key("SSH_PORT").MustInt(22)
  545. SSH.ListenPort = sec.Key("SSH_LISTEN_PORT").MustInt(SSH.Port)
  546. // When disable SSH, start builtin server value is ignored.
  547. if SSH.Disabled {
  548. SSH.StartBuiltinServer = false
  549. }
  550. if !SSH.Disabled && !SSH.StartBuiltinServer {
  551. if err := os.MkdirAll(SSH.RootPath, 0700); err != nil {
  552. log.Fatal(4, "Fail to create '%s': %v", SSH.RootPath, err)
  553. } else if err = os.MkdirAll(SSH.KeyTestPath, 0644); err != nil {
  554. log.Fatal(4, "Fail to create '%s': %v", SSH.KeyTestPath, err)
  555. }
  556. }
  557. SSH.MinimumKeySizeCheck = sec.Key("MINIMUM_KEY_SIZE_CHECK").MustBool()
  558. SSH.MinimumKeySizes = map[string]int{}
  559. minimumKeySizes := Cfg.Section("ssh.minimum_key_sizes").Keys()
  560. for _, key := range minimumKeySizes {
  561. if key.MustInt() != -1 {
  562. SSH.MinimumKeySizes[strings.ToLower(key.Name())] = key.MustInt()
  563. }
  564. }
  565. if err = Cfg.Section("server").MapTo(&LFS); err != nil {
  566. log.Fatal(4, "Fail to map LFS settings: %v", err)
  567. }
  568. if LFS.StartServer {
  569. if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
  570. log.Fatal(4, "Fail to create '%s': %v", LFS.ContentPath, err)
  571. }
  572. LFS.JWTSecretBytes = make([]byte, 32)
  573. n, err := base64.RawURLEncoding.Decode(LFS.JWTSecretBytes, []byte(LFS.JWTSecretBase64))
  574. if err != nil || n != 32 {
  575. //Generate new secret and save to config
  576. _, err := io.ReadFull(rand.Reader, LFS.JWTSecretBytes)
  577. if err != nil {
  578. log.Fatal(4, "Error reading random bytes: %s", err)
  579. }
  580. LFS.JWTSecretBase64 = base64.RawURLEncoding.EncodeToString(LFS.JWTSecretBytes)
  581. // Save secret
  582. cfg := ini.Empty()
  583. if com.IsFile(CustomConf) {
  584. // Keeps custom settings if there is already something.
  585. if err := cfg.Append(CustomConf); err != nil {
  586. log.Error(4, "Fail to load custom conf '%s': %v", CustomConf, err)
  587. }
  588. }
  589. cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
  590. if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
  591. log.Fatal(4, "Fail to create '%s': %v", CustomConf, err)
  592. }
  593. if err := cfg.SaveTo(CustomConf); err != nil {
  594. log.Fatal(4, "Error saving generated JWT Secret to custom config: %v", err)
  595. return
  596. }
  597. }
  598. //Disable LFS client hooks if installed for the current OS user
  599. //Needs at least git v2.1.2
  600. binVersion, err := git.BinVersion()
  601. if err != nil {
  602. log.Fatal(4, "Error retrieving git version: %s", err)
  603. }
  604. splitVersion := strings.SplitN(binVersion, ".", 3)
  605. majorVersion, err := strconv.ParseUint(splitVersion[0], 10, 64)
  606. if err != nil {
  607. log.Fatal(4, "Error parsing git major version: %s", err)
  608. }
  609. minorVersion, err := strconv.ParseUint(splitVersion[1], 10, 64)
  610. if err != nil {
  611. log.Fatal(4, "Error parsing git minor version: %s", err)
  612. }
  613. revisionVersion, err := strconv.ParseUint(splitVersion[2], 10, 64)
  614. if err != nil {
  615. log.Fatal(4, "Error parsing git revision version: %s", err)
  616. }
  617. if !((majorVersion > 2) || (majorVersion == 2 && minorVersion > 1) ||
  618. (majorVersion == 2 && minorVersion == 1 && revisionVersion >= 2)) {
  619. LFS.StartServer = false
  620. log.Error(4, "LFS server support needs at least Git v2.1.2")
  621. } else {
  622. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "filter.lfs.required=",
  623. "-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
  624. }
  625. }
  626. sec = Cfg.Section("security")
  627. InstallLock = sec.Key("INSTALL_LOCK").MustBool(false)
  628. SecretKey = sec.Key("SECRET_KEY").MustString("!#@FDEWREWR&*(")
  629. LogInRememberDays = sec.Key("LOGIN_REMEMBER_DAYS").MustInt(7)
  630. CookieUserName = sec.Key("COOKIE_USERNAME").MustString("gitea_awesome")
  631. CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").MustString("gitea_incredible")
  632. ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
  633. MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
  634. ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
  635. sec = Cfg.Section("attachment")
  636. AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))
  637. if !filepath.IsAbs(AttachmentPath) {
  638. AttachmentPath = path.Join(workDir, AttachmentPath)
  639. }
  640. AttachmentAllowedTypes = strings.Replace(sec.Key("ALLOWED_TYPES").MustString("image/jpeg,image/png,application/zip,application/gzip"), "|", ",", -1)
  641. AttachmentMaxSize = sec.Key("MAX_SIZE").MustInt64(4)
  642. AttachmentMaxFiles = sec.Key("MAX_FILES").MustInt(5)
  643. AttachmentEnabled = sec.Key("ENABLE").MustBool(true)
  644. TimeFormat = map[string]string{
  645. "ANSIC": time.ANSIC,
  646. "UnixDate": time.UnixDate,
  647. "RubyDate": time.RubyDate,
  648. "RFC822": time.RFC822,
  649. "RFC822Z": time.RFC822Z,
  650. "RFC850": time.RFC850,
  651. "RFC1123": time.RFC1123,
  652. "RFC1123Z": time.RFC1123Z,
  653. "RFC3339": time.RFC3339,
  654. "RFC3339Nano": time.RFC3339Nano,
  655. "Kitchen": time.Kitchen,
  656. "Stamp": time.Stamp,
  657. "StampMilli": time.StampMilli,
  658. "StampMicro": time.StampMicro,
  659. "StampNano": time.StampNano,
  660. }[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")]
  661. RunUser = Cfg.Section("").Key("RUN_USER").MustString(user.CurrentUsername())
  662. // Does not check run user when the install lock is off.
  663. if InstallLock {
  664. currentUser, match := IsRunUserMatchCurrentUser(RunUser)
  665. if !match {
  666. log.Fatal(4, "Expect user '%s' but current user is: %s", RunUser, currentUser)
  667. }
  668. }
  669. // Determine and create root git repository path.
  670. sec = Cfg.Section("repository")
  671. Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
  672. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
  673. forcePathSeparator(RepoRootPath)
  674. if !filepath.IsAbs(RepoRootPath) {
  675. RepoRootPath = path.Join(workDir, RepoRootPath)
  676. } else {
  677. RepoRootPath = path.Clean(RepoRootPath)
  678. }
  679. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  680. if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
  681. log.Fatal(4, "Fail to map Repository settings: %v", err)
  682. } else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
  683. log.Fatal(4, "Fail to map Repository.Editor settings: %v", err)
  684. } else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
  685. log.Fatal(4, "Fail to map Repository.Upload settings: %v", err)
  686. }
  687. if !filepath.IsAbs(Repository.Upload.TempPath) {
  688. Repository.Upload.TempPath = path.Join(workDir, Repository.Upload.TempPath)
  689. }
  690. sec = Cfg.Section("picture")
  691. AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
  692. forcePathSeparator(AvatarUploadPath)
  693. if !filepath.IsAbs(AvatarUploadPath) {
  694. AvatarUploadPath = path.Join(workDir, AvatarUploadPath)
  695. }
  696. switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
  697. case "duoshuo":
  698. GravatarSource = "http://gravatar.duoshuo.com/avatar/"
  699. case "gravatar":
  700. GravatarSource = "https://secure.gravatar.com/avatar/"
  701. case "libravatar":
  702. GravatarSource = "https://seccdn.libravatar.org/avatar/"
  703. default:
  704. GravatarSource = source
  705. }
  706. DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool()
  707. EnableFederatedAvatar = sec.Key("ENABLE_FEDERATED_AVATAR").MustBool()
  708. if OfflineMode {
  709. DisableGravatar = true
  710. EnableFederatedAvatar = false
  711. }
  712. if DisableGravatar {
  713. EnableFederatedAvatar = false
  714. }
  715. if EnableFederatedAvatar {
  716. LibravatarService = libravatar.New()
  717. parts := strings.Split(GravatarSource, "/")
  718. if len(parts) >= 3 {
  719. if parts[0] == "https:" {
  720. LibravatarService.SetUseHTTPS(true)
  721. LibravatarService.SetSecureFallbackHost(parts[2])
  722. } else {
  723. LibravatarService.SetUseHTTPS(false)
  724. LibravatarService.SetFallbackHost(parts[2])
  725. }
  726. }
  727. }
  728. if err = Cfg.Section("ui").MapTo(&UI); err != nil {
  729. log.Fatal(4, "Fail to map UI settings: %v", err)
  730. } else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
  731. log.Fatal(4, "Fail to map Markdown settings: %v", err)
  732. } else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
  733. log.Fatal(4, "Fail to map Cron settings: %v", err)
  734. } else if err = Cfg.Section("git").MapTo(&Git); err != nil {
  735. log.Fatal(4, "Fail to map Git settings: %v", err)
  736. } else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil {
  737. log.Fatal(4, "Fail to map Mirror settings: %v", err)
  738. } else if err = Cfg.Section("api").MapTo(&API); err != nil {
  739. log.Fatal(4, "Fail to map API settings: %v", err)
  740. }
  741. if Mirror.DefaultInterval <= 0 {
  742. Mirror.DefaultInterval = 24
  743. }
  744. Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
  745. if len(Langs) == 0 {
  746. Langs = defaultLangs
  747. }
  748. Names = Cfg.Section("i18n").Key("NAMES").Strings(",")
  749. if len(Names) == 0 {
  750. Names = defaultLangNames
  751. }
  752. dateLangs = Cfg.Section("i18n.datelang").KeysHash()
  753. ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool(false)
  754. ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true)
  755. ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
  756. UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
  757. HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
  758. }
  759. // Service settings
  760. var Service struct {
  761. ActiveCodeLives int
  762. ResetPwdCodeLives int
  763. RegisterEmailConfirm bool
  764. DisableRegistration bool
  765. ShowRegistrationButton bool
  766. RequireSignInView bool
  767. EnableNotifyMail bool
  768. EnableReverseProxyAuth bool
  769. EnableReverseProxyAutoRegister bool
  770. EnableCaptcha bool
  771. DefaultKeepEmailPrivate bool
  772. NoReplyAddress string
  773. }
  774. func newService() {
  775. sec := Cfg.Section("service")
  776. Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
  777. Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
  778. Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
  779. Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!Service.DisableRegistration)
  780. Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
  781. Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
  782. Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
  783. Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
  784. Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
  785. Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
  786. }
  787. var logLevels = map[string]string{
  788. "Trace": "0",
  789. "Debug": "1",
  790. "Info": "2",
  791. "Warn": "3",
  792. "Error": "4",
  793. "Critical": "5",
  794. }
  795. func newLogService() {
  796. log.Info("Gitea v%s", AppVer)
  797. LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
  798. LogConfigs = make([]string, len(LogModes))
  799. useConsole := false
  800. for _, mode := range LogModes {
  801. if mode == "console" {
  802. useConsole = true
  803. }
  804. }
  805. if !useConsole {
  806. log.DelLogger("console")
  807. }
  808. for i, mode := range LogModes {
  809. mode = strings.TrimSpace(mode)
  810. sec, err := Cfg.GetSection("log." + mode)
  811. if err != nil {
  812. sec, _ = Cfg.NewSection("log." + mode)
  813. }
  814. validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
  815. // Log level.
  816. levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
  817. Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
  818. validLevels)
  819. level, ok := logLevels[levelName]
  820. if !ok {
  821. log.Fatal(4, "Unknown log level: %s", levelName)
  822. }
  823. // Generate log configuration.
  824. switch mode {
  825. case "console":
  826. LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
  827. case "file":
  828. logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "gitea.log"))
  829. if err = os.MkdirAll(path.Dir(logPath), os.ModePerm); err != nil {
  830. panic(err.Error())
  831. }
  832. LogConfigs[i] = fmt.Sprintf(
  833. `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
  834. logPath,
  835. sec.Key("LOG_ROTATE").MustBool(true),
  836. sec.Key("MAX_LINES").MustInt(1000000),
  837. 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
  838. sec.Key("DAILY_ROTATE").MustBool(true),
  839. sec.Key("MAX_DAYS").MustInt(7))
  840. case "conn":
  841. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
  842. sec.Key("RECONNECT_ON_MSG").MustBool(),
  843. sec.Key("RECONNECT").MustBool(),
  844. sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
  845. sec.Key("ADDR").MustString(":7020"))
  846. case "smtp":
  847. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":["%s"],"subject":"%s"}`, level,
  848. sec.Key("USER").MustString("example@example.com"),
  849. sec.Key("PASSWD").MustString("******"),
  850. sec.Key("HOST").MustString("127.0.0.1:25"),
  851. strings.Replace(sec.Key("RECEIVERS").MustString("example@example.com"), ",", "\",\"", -1),
  852. sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
  853. case "database":
  854. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
  855. sec.Key("DRIVER").String(),
  856. sec.Key("CONN").String())
  857. }
  858. log.NewLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, LogConfigs[i])
  859. log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
  860. }
  861. }
  862. func newCacheService() {
  863. CacheAdapter = Cfg.Section("cache").Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
  864. switch CacheAdapter {
  865. case "memory":
  866. CacheInterval = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
  867. case "redis", "memcache":
  868. CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
  869. default:
  870. log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
  871. }
  872. log.Info("Cache Service Enabled")
  873. }
  874. func newSessionService() {
  875. SessionConfig.Provider = Cfg.Section("session").Key("PROVIDER").In("memory",
  876. []string{"memory", "file", "redis", "mysql"})
  877. SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").String(), "\" ")
  878. SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gitea")
  879. SessionConfig.CookiePath = AppSubURL
  880. SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool(false)
  881. SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
  882. SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
  883. log.Info("Session Service Enabled")
  884. }
  885. // Mailer represents mail service.
  886. type Mailer struct {
  887. // Mailer
  888. QueueLength int
  889. Name string
  890. From string
  891. FromEmail string
  892. EnableHTMLAlternative bool
  893. // SMTP sender
  894. Host string
  895. User, Passwd string
  896. DisableHelo bool
  897. HeloHostname string
  898. SkipVerify bool
  899. UseCertificate bool
  900. CertFile, KeyFile string
  901. // Sendmail sender
  902. UseSendmail bool
  903. SendmailPath string
  904. }
  905. var (
  906. // MailService the global mailer
  907. MailService *Mailer
  908. )
  909. func newMailService() {
  910. sec := Cfg.Section("mailer")
  911. // Check mailer setting.
  912. if !sec.Key("ENABLED").MustBool() {
  913. return
  914. }
  915. MailService = &Mailer{
  916. QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
  917. Name: sec.Key("NAME").MustString(AppName),
  918. EnableHTMLAlternative: sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(),
  919. Host: sec.Key("HOST").String(),
  920. User: sec.Key("USER").String(),
  921. Passwd: sec.Key("PASSWD").String(),
  922. DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
  923. HeloHostname: sec.Key("HELO_HOSTNAME").String(),
  924. SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
  925. UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
  926. CertFile: sec.Key("CERT_FILE").String(),
  927. KeyFile: sec.Key("KEY_FILE").String(),
  928. UseSendmail: sec.Key("USE_SENDMAIL").MustBool(),
  929. SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"),
  930. }
  931. MailService.From = sec.Key("FROM").MustString(MailService.User)
  932. parsed, err := mail.ParseAddress(MailService.From)
  933. if err != nil {
  934. log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err)
  935. }
  936. MailService.FromEmail = parsed.Address
  937. log.Info("Mail Service Enabled")
  938. }
  939. func newRegisterMailService() {
  940. if !Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").MustBool() {
  941. return
  942. } else if MailService == nil {
  943. log.Warn("Register Mail Service: Mail Service is not enabled")
  944. return
  945. }
  946. Service.RegisterEmailConfirm = true
  947. log.Info("Register Mail Service Enabled")
  948. }
  949. func newNotifyMailService() {
  950. if !Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").MustBool() {
  951. return
  952. } else if MailService == nil {
  953. log.Warn("Notify Mail Service: Mail Service is not enabled")
  954. return
  955. }
  956. Service.EnableNotifyMail = true
  957. log.Info("Notify Mail Service Enabled")
  958. }
  959. func newWebhookService() {
  960. sec := Cfg.Section("webhook")
  961. Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000)
  962. Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
  963. Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
  964. Webhook.Types = []string{"gogs", "slack"}
  965. Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
  966. }
  967. // NewServices initializes the services
  968. func NewServices() {
  969. newService()
  970. newLogService()
  971. newCacheService()
  972. newSessionService()
  973. newMailService()
  974. newRegisterMailService()
  975. newNotifyMailService()
  976. newWebhookService()
  977. }