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 38 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
10 years ago
11 years ago
9 years ago
11 years ago
11 years ago
9 years ago
9 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
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
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
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
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
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
11 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
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  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. "regexp"
  17. "runtime"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "code.gitea.io/git"
  22. "code.gitea.io/gitea/modules/log"
  23. _ "code.gitea.io/gitea/modules/minwinsvc" // import minwinsvc for windows services
  24. "code.gitea.io/gitea/modules/user"
  25. "github.com/Unknwon/com"
  26. _ "github.com/go-macaron/cache/memcache" // memcache plugin for cache
  27. _ "github.com/go-macaron/cache/redis"
  28. "github.com/go-macaron/session"
  29. _ "github.com/go-macaron/session/redis" // redis plugin for store session
  30. "github.com/go-xorm/core"
  31. ini "gopkg.in/ini.v1"
  32. "strk.kbt.io/projects/go/libravatar"
  33. )
  34. // Scheme describes protocol types
  35. type Scheme string
  36. // enumerates all the scheme types
  37. const (
  38. HTTP Scheme = "http"
  39. HTTPS Scheme = "https"
  40. FCGI Scheme = "fcgi"
  41. UnixSocket Scheme = "unix"
  42. )
  43. // LandingPage describes the default page
  44. type LandingPage string
  45. // enumerates all the landing page types
  46. const (
  47. LandingPageHome LandingPage = "/"
  48. LandingPageExplore LandingPage = "/explore"
  49. )
  50. // settings
  51. var (
  52. // AppVer settings
  53. AppVer string
  54. AppBuiltWith string
  55. AppName string
  56. AppURL string
  57. AppSubURL string
  58. AppSubURLDepth int // Number of slashes
  59. AppPath string
  60. AppDataPath string
  61. // Server settings
  62. Protocol Scheme
  63. Domain string
  64. HTTPAddr string
  65. HTTPPort string
  66. LocalURL string
  67. OfflineMode bool
  68. DisableRouterLog bool
  69. CertFile string
  70. KeyFile string
  71. StaticRootPath string
  72. EnableGzip bool
  73. LandingPageURL LandingPage
  74. UnixSocketPermission uint32
  75. EnablePprof bool
  76. SSH = struct {
  77. Disabled bool `ini:"DISABLE_SSH"`
  78. StartBuiltinServer bool `ini:"START_SSH_SERVER"`
  79. Domain string `ini:"SSH_DOMAIN"`
  80. Port int `ini:"SSH_PORT"`
  81. ListenHost string `ini:"SSH_LISTEN_HOST"`
  82. ListenPort int `ini:"SSH_LISTEN_PORT"`
  83. RootPath string `ini:"SSH_ROOT_PATH"`
  84. KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
  85. KeygenPath string `ini:"SSH_KEYGEN_PATH"`
  86. MinimumKeySizeCheck bool `ini:"-"`
  87. MinimumKeySizes map[string]int `ini:"-"`
  88. }{
  89. Disabled: false,
  90. StartBuiltinServer: false,
  91. Domain: "",
  92. Port: 22,
  93. KeygenPath: "ssh-keygen",
  94. }
  95. LFS struct {
  96. StartServer bool `ini:"LFS_START_SERVER"`
  97. ContentPath string `ini:"LFS_CONTENT_PATH"`
  98. JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
  99. JWTSecretBytes []byte `ini:"-"`
  100. }
  101. // Security settings
  102. InstallLock bool
  103. SecretKey string
  104. LogInRememberDays int
  105. CookieUserName string
  106. CookieRememberName string
  107. ReverseProxyAuthUser string
  108. MinPasswordLength int
  109. ImportLocalPaths bool
  110. // OpenID settings
  111. EnableOpenIDSignIn bool
  112. EnableOpenIDSignUp bool
  113. OpenIDWhitelist []*regexp.Regexp
  114. OpenIDBlacklist []*regexp.Regexp
  115. // Database settings
  116. UseSQLite3 bool
  117. UseMySQL bool
  118. UseMSSQL bool
  119. UsePostgreSQL bool
  120. UseTiDB bool
  121. // Indexer settings
  122. Indexer struct {
  123. IssuePath string
  124. UpdateQueueLength int
  125. }
  126. // Webhook settings
  127. Webhook = struct {
  128. QueueLength int
  129. DeliverTimeout int
  130. SkipTLSVerify bool
  131. Types []string
  132. PagingNum int
  133. }{
  134. QueueLength: 1000,
  135. DeliverTimeout: 5,
  136. SkipTLSVerify: false,
  137. PagingNum: 10,
  138. }
  139. // Repository settings
  140. Repository = struct {
  141. AnsiCharset string
  142. ForcePrivate bool
  143. MaxCreationLimit int
  144. MirrorQueueLength int
  145. PullRequestQueueLength int
  146. PreferredLicenses []string
  147. DisableHTTPGit bool
  148. // Repository editor settings
  149. Editor struct {
  150. LineWrapExtensions []string
  151. PreviewableFileModes []string
  152. } `ini:"-"`
  153. // Repository upload settings
  154. Upload struct {
  155. Enabled bool
  156. TempPath string
  157. AllowedTypes []string `delim:"|"`
  158. FileMaxSize int64
  159. MaxFiles int
  160. } `ini:"-"`
  161. }{
  162. AnsiCharset: "",
  163. ForcePrivate: false,
  164. MaxCreationLimit: -1,
  165. MirrorQueueLength: 1000,
  166. PullRequestQueueLength: 1000,
  167. PreferredLicenses: []string{"Apache License 2.0,MIT License"},
  168. DisableHTTPGit: false,
  169. // Repository editor settings
  170. Editor: struct {
  171. LineWrapExtensions []string
  172. PreviewableFileModes []string
  173. }{
  174. LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
  175. PreviewableFileModes: []string{"markdown"},
  176. },
  177. // Repository upload settings
  178. Upload: struct {
  179. Enabled bool
  180. TempPath string
  181. AllowedTypes []string `delim:"|"`
  182. FileMaxSize int64
  183. MaxFiles int
  184. }{
  185. Enabled: true,
  186. TempPath: "data/tmp/uploads",
  187. AllowedTypes: []string{},
  188. FileMaxSize: 3,
  189. MaxFiles: 5,
  190. },
  191. }
  192. RepoRootPath string
  193. ScriptType = "bash"
  194. // UI settings
  195. UI = struct {
  196. ExplorePagingNum int
  197. IssuePagingNum int
  198. FeedMaxCommitNum int
  199. ThemeColorMetaTag string
  200. MaxDisplayFileSize int64
  201. ShowUserEmail bool
  202. Admin struct {
  203. UserPagingNum int
  204. RepoPagingNum int
  205. NoticePagingNum int
  206. OrgPagingNum int
  207. } `ini:"ui.admin"`
  208. User struct {
  209. RepoPagingNum int
  210. } `ini:"ui.user"`
  211. }{
  212. ExplorePagingNum: 20,
  213. IssuePagingNum: 10,
  214. FeedMaxCommitNum: 5,
  215. ThemeColorMetaTag: `#6cc644`,
  216. MaxDisplayFileSize: 8388608,
  217. Admin: struct {
  218. UserPagingNum int
  219. RepoPagingNum int
  220. NoticePagingNum int
  221. OrgPagingNum int
  222. }{
  223. UserPagingNum: 50,
  224. RepoPagingNum: 50,
  225. NoticePagingNum: 25,
  226. OrgPagingNum: 50,
  227. },
  228. User: struct {
  229. RepoPagingNum int
  230. }{
  231. RepoPagingNum: 15,
  232. },
  233. }
  234. // Markdown settings
  235. Markdown = struct {
  236. EnableHardLineBreak bool
  237. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  238. FileExtensions []string
  239. }{
  240. EnableHardLineBreak: false,
  241. FileExtensions: strings.Split(".md,.markdown,.mdown,.mkd", ","),
  242. }
  243. // Admin settings
  244. Admin struct {
  245. DisableRegularOrgCreation bool
  246. }
  247. // Picture settings
  248. AvatarUploadPath string
  249. GravatarSource string
  250. DisableGravatar bool
  251. EnableFederatedAvatar bool
  252. LibravatarService *libravatar.Libravatar
  253. // Log settings
  254. LogRootPath string
  255. LogModes []string
  256. LogConfigs []string
  257. // Attachment settings
  258. AttachmentPath string
  259. AttachmentAllowedTypes string
  260. AttachmentMaxSize int64
  261. AttachmentMaxFiles int
  262. AttachmentEnabled bool
  263. // Time settings
  264. TimeFormat string
  265. // Cache settings
  266. CacheAdapter string
  267. CacheInterval int
  268. CacheConn string
  269. // Session settings
  270. SessionConfig session.Options
  271. CSRFCookieName = "_csrf"
  272. // Cron tasks
  273. Cron = struct {
  274. UpdateMirror struct {
  275. Enabled bool
  276. RunAtStart bool
  277. Schedule string
  278. } `ini:"cron.update_mirrors"`
  279. RepoHealthCheck struct {
  280. Enabled bool
  281. RunAtStart bool
  282. Schedule string
  283. Timeout time.Duration
  284. Args []string `delim:" "`
  285. } `ini:"cron.repo_health_check"`
  286. CheckRepoStats struct {
  287. Enabled bool
  288. RunAtStart bool
  289. Schedule string
  290. } `ini:"cron.check_repo_stats"`
  291. ArchiveCleanup struct {
  292. Enabled bool
  293. RunAtStart bool
  294. Schedule string
  295. OlderThan time.Duration
  296. } `ini:"cron.archive_cleanup"`
  297. }{
  298. UpdateMirror: struct {
  299. Enabled bool
  300. RunAtStart bool
  301. Schedule string
  302. }{
  303. Enabled: true,
  304. RunAtStart: false,
  305. Schedule: "@every 10m",
  306. },
  307. RepoHealthCheck: struct {
  308. Enabled bool
  309. RunAtStart bool
  310. Schedule string
  311. Timeout time.Duration
  312. Args []string `delim:" "`
  313. }{
  314. Enabled: true,
  315. RunAtStart: false,
  316. Schedule: "@every 24h",
  317. Timeout: 60 * time.Second,
  318. Args: []string{},
  319. },
  320. CheckRepoStats: struct {
  321. Enabled bool
  322. RunAtStart bool
  323. Schedule string
  324. }{
  325. Enabled: true,
  326. RunAtStart: true,
  327. Schedule: "@every 24h",
  328. },
  329. ArchiveCleanup: struct {
  330. Enabled bool
  331. RunAtStart bool
  332. Schedule string
  333. OlderThan time.Duration
  334. }{
  335. Enabled: true,
  336. RunAtStart: true,
  337. Schedule: "@every 24h",
  338. OlderThan: 24 * time.Hour,
  339. },
  340. }
  341. // Git settings
  342. Git = struct {
  343. Version string `ini:"-"`
  344. DisableDiffHighlight bool
  345. MaxGitDiffLines int
  346. MaxGitDiffLineCharacters int
  347. MaxGitDiffFiles int
  348. GCArgs []string `delim:" "`
  349. Timeout struct {
  350. Migrate int
  351. Mirror int
  352. Clone int
  353. Pull int
  354. GC int `ini:"GC"`
  355. } `ini:"git.timeout"`
  356. }{
  357. DisableDiffHighlight: false,
  358. MaxGitDiffLines: 1000,
  359. MaxGitDiffLineCharacters: 500,
  360. MaxGitDiffFiles: 100,
  361. GCArgs: []string{},
  362. Timeout: struct {
  363. Migrate int
  364. Mirror int
  365. Clone int
  366. Pull int
  367. GC int `ini:"GC"`
  368. }{
  369. Migrate: 600,
  370. Mirror: 300,
  371. Clone: 300,
  372. Pull: 300,
  373. GC: 60,
  374. },
  375. }
  376. // Mirror settings
  377. Mirror = struct {
  378. DefaultInterval int
  379. }{
  380. DefaultInterval: 8,
  381. }
  382. // API settings
  383. API = struct {
  384. MaxResponseItems int
  385. }{
  386. MaxResponseItems: 50,
  387. }
  388. // I18n settings
  389. Langs []string
  390. Names []string
  391. dateLangs map[string]string
  392. // Highlight settings are loaded in modules/template/highlight.go
  393. // Other settings
  394. ShowFooterBranding bool
  395. ShowFooterVersion bool
  396. ShowFooterTemplateLoadTime bool
  397. // Global setting objects
  398. Cfg *ini.File
  399. CustomPath string // Custom directory path
  400. CustomConf string
  401. CustomPID string
  402. ProdMode bool
  403. RunUser string
  404. IsWindows bool
  405. HasRobotsTxt bool
  406. )
  407. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  408. func DateLang(lang string) string {
  409. name, ok := dateLangs[lang]
  410. if ok {
  411. return name
  412. }
  413. return "en"
  414. }
  415. // execPath returns the executable path.
  416. func execPath() (string, error) {
  417. file, err := exec.LookPath(os.Args[0])
  418. if err != nil {
  419. return "", err
  420. }
  421. return filepath.Abs(file)
  422. }
  423. func init() {
  424. IsWindows = runtime.GOOS == "windows"
  425. log.NewLogger(0, "console", `{"level": 0}`)
  426. var err error
  427. if AppPath, err = execPath(); err != nil {
  428. log.Fatal(4, "Failed to get app path: %v", err)
  429. }
  430. // Note: we don't use path.Dir here because it does not handle case
  431. // which path starts with two "/" in Windows: "//psf/Home/..."
  432. AppPath = strings.Replace(AppPath, "\\", "/", -1)
  433. }
  434. // WorkDir returns absolute path of work directory.
  435. func WorkDir() (string, error) {
  436. wd := os.Getenv("GITEA_WORK_DIR")
  437. if len(wd) > 0 {
  438. return wd, nil
  439. }
  440. // Use GOGS_WORK_DIR if available, for backward compatibility
  441. // TODO: drop in 1.1.0 ?
  442. wd = os.Getenv("GOGS_WORK_DIR")
  443. if len(wd) > 0 {
  444. log.Warn(`Usage of GOGS_WORK_DIR is deprecated and will be *removed* in a future release,
  445. please consider changing to GITEA_WORK_DIR`)
  446. return wd, nil
  447. }
  448. i := strings.LastIndex(AppPath, "/")
  449. if i == -1 {
  450. return AppPath, nil
  451. }
  452. return AppPath[:i], nil
  453. }
  454. func forcePathSeparator(path string) {
  455. if strings.Contains(path, "\\") {
  456. log.Fatal(4, "Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
  457. }
  458. }
  459. // IsRunUserMatchCurrentUser returns false if configured run user does not match
  460. // actual user that runs the app. The first return value is the actual user name.
  461. // This check is ignored under Windows since SSH remote login is not the main
  462. // method to login on Windows.
  463. func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
  464. if IsWindows {
  465. return "", true
  466. }
  467. currentUser := user.CurrentUsername()
  468. return currentUser, runUser == currentUser
  469. }
  470. func createPIDFile(pidPath string) {
  471. currentPid := os.Getpid()
  472. if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil {
  473. log.Fatal(4, "Failed to create PID folder: %v", err)
  474. }
  475. file, err := os.Create(pidPath)
  476. if err != nil {
  477. log.Fatal(4, "Failed to create PID file: %v", err)
  478. }
  479. defer file.Close()
  480. if _, err := file.WriteString(strconv.FormatInt(int64(currentPid), 10)); err != nil {
  481. log.Fatal(4, "Failed to write PID information: %v", err)
  482. }
  483. }
  484. // NewContext initializes configuration context.
  485. // NOTE: do not print any log except error.
  486. func NewContext() {
  487. workDir, err := WorkDir()
  488. if err != nil {
  489. log.Fatal(4, "Failed to get work directory: %v", err)
  490. }
  491. Cfg = ini.Empty()
  492. CustomPath = os.Getenv("GITEA_CUSTOM")
  493. if len(CustomPath) == 0 {
  494. // For backward compatibility
  495. // TODO: drop in 1.1.0 ?
  496. CustomPath = os.Getenv("GOGS_CUSTOM")
  497. if len(CustomPath) == 0 {
  498. CustomPath = workDir + "/custom"
  499. } else {
  500. log.Warn(`Usage of GOGS_CUSTOM is deprecated and will be *removed* in a future release,
  501. please consider changing to GITEA_CUSTOM`)
  502. }
  503. }
  504. if len(CustomPID) > 0 {
  505. createPIDFile(CustomPID)
  506. }
  507. if len(CustomConf) == 0 {
  508. CustomConf = CustomPath + "/conf/app.ini"
  509. }
  510. if com.IsFile(CustomConf) {
  511. if err = Cfg.Append(CustomConf); err != nil {
  512. log.Fatal(4, "Failed to load custom conf '%s': %v", CustomConf, err)
  513. }
  514. } else {
  515. log.Warn("Custom config '%s' not found, ignore this if you're running first time", CustomConf)
  516. }
  517. Cfg.NameMapper = ini.AllCapsUnderscore
  518. homeDir, err := com.HomeDir()
  519. if err != nil {
  520. log.Fatal(4, "Failed to get home directory: %v", err)
  521. }
  522. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  523. LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log"))
  524. forcePathSeparator(LogRootPath)
  525. sec := Cfg.Section("server")
  526. AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
  527. AppURL = sec.Key("ROOT_URL").MustString("http://localhost:3000/")
  528. AppURL = strings.TrimRight(AppURL, "/") + "/"
  529. // Check if has app suburl.
  530. url, err := url.Parse(AppURL)
  531. if err != nil {
  532. log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err)
  533. }
  534. // Suburl should start with '/' and end without '/', such as '/{subpath}'.
  535. // This value is empty if site does not have sub-url.
  536. AppSubURL = strings.TrimSuffix(url.Path, "/")
  537. AppSubURLDepth = strings.Count(AppSubURL, "/")
  538. Protocol = HTTP
  539. if sec.Key("PROTOCOL").String() == "https" {
  540. Protocol = HTTPS
  541. CertFile = sec.Key("CERT_FILE").String()
  542. KeyFile = sec.Key("KEY_FILE").String()
  543. } else if sec.Key("PROTOCOL").String() == "fcgi" {
  544. Protocol = FCGI
  545. } else if sec.Key("PROTOCOL").String() == "unix" {
  546. Protocol = UnixSocket
  547. UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
  548. UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
  549. if err != nil || UnixSocketPermissionParsed > 0777 {
  550. log.Fatal(4, "Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
  551. }
  552. UnixSocketPermission = uint32(UnixSocketPermissionParsed)
  553. }
  554. Domain = sec.Key("DOMAIN").MustString("localhost")
  555. HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
  556. HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
  557. LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(string(Protocol) + "://localhost:" + HTTPPort + "/")
  558. OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
  559. DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()
  560. StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(workDir)
  561. AppDataPath = sec.Key("APP_DATA_PATH").MustString("data")
  562. EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
  563. EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
  564. switch sec.Key("LANDING_PAGE").MustString("home") {
  565. case "explore":
  566. LandingPageURL = LandingPageExplore
  567. default:
  568. LandingPageURL = LandingPageHome
  569. }
  570. if len(SSH.Domain) == 0 {
  571. SSH.Domain = Domain
  572. }
  573. SSH.RootPath = path.Join(homeDir, ".ssh")
  574. SSH.KeyTestPath = os.TempDir()
  575. if err = Cfg.Section("server").MapTo(&SSH); err != nil {
  576. log.Fatal(4, "Failed to map SSH settings: %v", err)
  577. }
  578. SSH.KeygenPath = sec.Key("SSH_KEYGEN_PATH").MustString("ssh-keygen")
  579. SSH.Port = sec.Key("SSH_PORT").MustInt(22)
  580. SSH.ListenPort = sec.Key("SSH_LISTEN_PORT").MustInt(SSH.Port)
  581. // When disable SSH, start builtin server value is ignored.
  582. if SSH.Disabled {
  583. SSH.StartBuiltinServer = false
  584. }
  585. if !SSH.Disabled && !SSH.StartBuiltinServer {
  586. if err := os.MkdirAll(SSH.RootPath, 0700); err != nil {
  587. log.Fatal(4, "Failed to create '%s': %v", SSH.RootPath, err)
  588. } else if err = os.MkdirAll(SSH.KeyTestPath, 0644); err != nil {
  589. log.Fatal(4, "Failed to create '%s': %v", SSH.KeyTestPath, err)
  590. }
  591. }
  592. SSH.MinimumKeySizeCheck = sec.Key("MINIMUM_KEY_SIZE_CHECK").MustBool()
  593. SSH.MinimumKeySizes = map[string]int{}
  594. minimumKeySizes := Cfg.Section("ssh.minimum_key_sizes").Keys()
  595. for _, key := range minimumKeySizes {
  596. if key.MustInt() != -1 {
  597. SSH.MinimumKeySizes[strings.ToLower(key.Name())] = key.MustInt()
  598. }
  599. }
  600. if err = Cfg.Section("server").MapTo(&LFS); err != nil {
  601. log.Fatal(4, "Failed to map LFS settings: %v", err)
  602. }
  603. if LFS.StartServer {
  604. if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
  605. log.Fatal(4, "Failed to create '%s': %v", LFS.ContentPath, err)
  606. }
  607. LFS.JWTSecretBytes = make([]byte, 32)
  608. n, err := base64.RawURLEncoding.Decode(LFS.JWTSecretBytes, []byte(LFS.JWTSecretBase64))
  609. if err != nil || n != 32 {
  610. //Generate new secret and save to config
  611. _, err := io.ReadFull(rand.Reader, LFS.JWTSecretBytes)
  612. if err != nil {
  613. log.Fatal(4, "Error reading random bytes: %v", err)
  614. }
  615. LFS.JWTSecretBase64 = base64.RawURLEncoding.EncodeToString(LFS.JWTSecretBytes)
  616. // Save secret
  617. cfg := ini.Empty()
  618. if com.IsFile(CustomConf) {
  619. // Keeps custom settings if there is already something.
  620. if err := cfg.Append(CustomConf); err != nil {
  621. log.Error(4, "Failed to load custom conf '%s': %v", CustomConf, err)
  622. }
  623. }
  624. cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
  625. if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
  626. log.Fatal(4, "Failed to create '%s': %v", CustomConf, err)
  627. }
  628. if err := cfg.SaveTo(CustomConf); err != nil {
  629. log.Fatal(4, "Error saving generated JWT Secret to custom config: %v", err)
  630. return
  631. }
  632. }
  633. //Disable LFS client hooks if installed for the current OS user
  634. //Needs at least git v2.1.2
  635. binVersion, err := git.BinVersion()
  636. if err != nil {
  637. log.Fatal(4, "Error retrieving git version: %v", err)
  638. }
  639. splitVersion := strings.SplitN(binVersion, ".", 3)
  640. majorVersion, err := strconv.ParseUint(splitVersion[0], 10, 64)
  641. if err != nil {
  642. log.Fatal(4, "Error parsing git major version: %v", err)
  643. }
  644. minorVersion, err := strconv.ParseUint(splitVersion[1], 10, 64)
  645. if err != nil {
  646. log.Fatal(4, "Error parsing git minor version: %v", err)
  647. }
  648. revisionVersion, err := strconv.ParseUint(splitVersion[2], 10, 64)
  649. if err != nil {
  650. log.Fatal(4, "Error parsing git revision version: %v", err)
  651. }
  652. if !((majorVersion > 2) || (majorVersion == 2 && minorVersion > 1) ||
  653. (majorVersion == 2 && minorVersion == 1 && revisionVersion >= 2)) {
  654. LFS.StartServer = false
  655. log.Error(4, "LFS server support needs at least Git v2.1.2")
  656. } else {
  657. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "filter.lfs.required=",
  658. "-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
  659. }
  660. }
  661. sec = Cfg.Section("security")
  662. InstallLock = sec.Key("INSTALL_LOCK").MustBool(false)
  663. SecretKey = sec.Key("SECRET_KEY").MustString("!#@FDEWREWR&*(")
  664. LogInRememberDays = sec.Key("LOGIN_REMEMBER_DAYS").MustInt(7)
  665. CookieUserName = sec.Key("COOKIE_USERNAME").MustString("gitea_awesome")
  666. CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").MustString("gitea_incredible")
  667. ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
  668. MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
  669. ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
  670. sec = Cfg.Section("openid")
  671. EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(true)
  672. EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(true)
  673. pats := sec.Key("WHITELISTED_URIS").Strings(" ")
  674. if len(pats) != 0 {
  675. OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
  676. for i, p := range pats {
  677. OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
  678. }
  679. }
  680. pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
  681. if len(pats) != 0 {
  682. OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
  683. for i, p := range pats {
  684. OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)
  685. }
  686. }
  687. sec = Cfg.Section("attachment")
  688. AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))
  689. if !filepath.IsAbs(AttachmentPath) {
  690. AttachmentPath = path.Join(workDir, AttachmentPath)
  691. }
  692. AttachmentAllowedTypes = strings.Replace(sec.Key("ALLOWED_TYPES").MustString("image/jpeg,image/png,application/zip,application/gzip"), "|", ",", -1)
  693. AttachmentMaxSize = sec.Key("MAX_SIZE").MustInt64(4)
  694. AttachmentMaxFiles = sec.Key("MAX_FILES").MustInt(5)
  695. AttachmentEnabled = sec.Key("ENABLE").MustBool(true)
  696. TimeFormatKey := Cfg.Section("time").Key("FORMAT").MustString("RFC1123")
  697. TimeFormat = map[string]string{
  698. "ANSIC": time.ANSIC,
  699. "UnixDate": time.UnixDate,
  700. "RubyDate": time.RubyDate,
  701. "RFC822": time.RFC822,
  702. "RFC822Z": time.RFC822Z,
  703. "RFC850": time.RFC850,
  704. "RFC1123": time.RFC1123,
  705. "RFC1123Z": time.RFC1123Z,
  706. "RFC3339": time.RFC3339,
  707. "RFC3339Nano": time.RFC3339Nano,
  708. "Kitchen": time.Kitchen,
  709. "Stamp": time.Stamp,
  710. "StampMilli": time.StampMilli,
  711. "StampMicro": time.StampMicro,
  712. "StampNano": time.StampNano,
  713. }[TimeFormatKey]
  714. // When the TimeFormatKey does not exist in the previous map e.g.'2006-01-02 15:04:05'
  715. if len(TimeFormat) == 0 {
  716. TimeFormat = TimeFormatKey
  717. TestTimeFormat, _ := time.Parse(TimeFormat, TimeFormat)
  718. if TestTimeFormat.Format(time.RFC3339) != "2006-01-02T15:04:05Z" {
  719. log.Fatal(4, "Can't create time properly, please check your time format has 2006, 01, 02, 15, 04 and 05")
  720. }
  721. log.Trace("Custom TimeFormat: %s", TimeFormat)
  722. }
  723. RunUser = Cfg.Section("").Key("RUN_USER").MustString(user.CurrentUsername())
  724. // Does not check run user when the install lock is off.
  725. if InstallLock {
  726. currentUser, match := IsRunUserMatchCurrentUser(RunUser)
  727. if !match {
  728. log.Fatal(4, "Expect user '%s' but current user is: %s", RunUser, currentUser)
  729. }
  730. }
  731. // Determine and create root git repository path.
  732. sec = Cfg.Section("repository")
  733. Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
  734. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
  735. forcePathSeparator(RepoRootPath)
  736. if !filepath.IsAbs(RepoRootPath) {
  737. RepoRootPath = path.Join(workDir, RepoRootPath)
  738. } else {
  739. RepoRootPath = path.Clean(RepoRootPath)
  740. }
  741. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  742. if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
  743. log.Fatal(4, "Failed to map Repository settings: %v", err)
  744. } else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
  745. log.Fatal(4, "Failed to map Repository.Editor settings: %v", err)
  746. } else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
  747. log.Fatal(4, "Failed to map Repository.Upload settings: %v", err)
  748. }
  749. if !filepath.IsAbs(Repository.Upload.TempPath) {
  750. Repository.Upload.TempPath = path.Join(workDir, Repository.Upload.TempPath)
  751. }
  752. sec = Cfg.Section("picture")
  753. AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
  754. forcePathSeparator(AvatarUploadPath)
  755. if !filepath.IsAbs(AvatarUploadPath) {
  756. AvatarUploadPath = path.Join(workDir, AvatarUploadPath)
  757. }
  758. switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
  759. case "duoshuo":
  760. GravatarSource = "http://gravatar.duoshuo.com/avatar/"
  761. case "gravatar":
  762. GravatarSource = "https://secure.gravatar.com/avatar/"
  763. case "libravatar":
  764. GravatarSource = "https://seccdn.libravatar.org/avatar/"
  765. default:
  766. GravatarSource = source
  767. }
  768. DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool()
  769. EnableFederatedAvatar = sec.Key("ENABLE_FEDERATED_AVATAR").MustBool()
  770. if OfflineMode {
  771. DisableGravatar = true
  772. EnableFederatedAvatar = false
  773. }
  774. if DisableGravatar {
  775. EnableFederatedAvatar = false
  776. }
  777. if EnableFederatedAvatar {
  778. LibravatarService = libravatar.New()
  779. parts := strings.Split(GravatarSource, "/")
  780. if len(parts) >= 3 {
  781. if parts[0] == "https:" {
  782. LibravatarService.SetUseHTTPS(true)
  783. LibravatarService.SetSecureFallbackHost(parts[2])
  784. } else {
  785. LibravatarService.SetUseHTTPS(false)
  786. LibravatarService.SetFallbackHost(parts[2])
  787. }
  788. }
  789. }
  790. if err = Cfg.Section("ui").MapTo(&UI); err != nil {
  791. log.Fatal(4, "Failed to map UI settings: %v", err)
  792. } else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
  793. log.Fatal(4, "Failed to map Markdown settings: %v", err)
  794. } else if err = Cfg.Section("admin").MapTo(&Admin); err != nil {
  795. log.Fatal(4, "Fail to map Admin settings: %v", err)
  796. } else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
  797. log.Fatal(4, "Failed to map Cron settings: %v", err)
  798. } else if err = Cfg.Section("git").MapTo(&Git); err != nil {
  799. log.Fatal(4, "Failed to map Git settings: %v", err)
  800. } else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil {
  801. log.Fatal(4, "Failed to map Mirror settings: %v", err)
  802. } else if err = Cfg.Section("api").MapTo(&API); err != nil {
  803. log.Fatal(4, "Failed to map API settings: %v", err)
  804. }
  805. if Mirror.DefaultInterval <= 0 {
  806. Mirror.DefaultInterval = 24
  807. }
  808. Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
  809. if len(Langs) == 0 {
  810. Langs = defaultLangs
  811. }
  812. Names = Cfg.Section("i18n").Key("NAMES").Strings(",")
  813. if len(Names) == 0 {
  814. Names = defaultLangNames
  815. }
  816. dateLangs = Cfg.Section("i18n.datelang").KeysHash()
  817. ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool(false)
  818. ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true)
  819. ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
  820. UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
  821. HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
  822. }
  823. // Service settings
  824. var Service struct {
  825. ActiveCodeLives int
  826. ResetPwdCodeLives int
  827. RegisterEmailConfirm bool
  828. DisableRegistration bool
  829. ShowRegistrationButton bool
  830. RequireSignInView bool
  831. EnableNotifyMail bool
  832. EnableReverseProxyAuth bool
  833. EnableReverseProxyAutoRegister bool
  834. EnableCaptcha bool
  835. DefaultKeepEmailPrivate bool
  836. NoReplyAddress string
  837. }
  838. func newService() {
  839. sec := Cfg.Section("service")
  840. Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
  841. Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
  842. Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
  843. Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!Service.DisableRegistration)
  844. Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
  845. Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
  846. Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
  847. Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
  848. Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
  849. Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
  850. }
  851. var logLevels = map[string]string{
  852. "Trace": "0",
  853. "Debug": "1",
  854. "Info": "2",
  855. "Warn": "3",
  856. "Error": "4",
  857. "Critical": "5",
  858. }
  859. func newLogService() {
  860. log.Info("Gitea v%s%s", AppVer, AppBuiltWith)
  861. LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
  862. LogConfigs = make([]string, len(LogModes))
  863. useConsole := false
  864. for i := 0; i < len(LogModes); i++ {
  865. LogModes[i] = strings.TrimSpace(LogModes[i])
  866. if LogModes[i] == "console" {
  867. useConsole = true
  868. }
  869. }
  870. if !useConsole {
  871. log.DelLogger("console")
  872. }
  873. for i, mode := range LogModes {
  874. sec, err := Cfg.GetSection("log." + mode)
  875. if err != nil {
  876. sec, _ = Cfg.NewSection("log." + mode)
  877. }
  878. validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
  879. // Log level.
  880. levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
  881. Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
  882. validLevels)
  883. level, ok := logLevels[levelName]
  884. if !ok {
  885. log.Fatal(4, "Unknown log level: %s", levelName)
  886. }
  887. // Generate log configuration.
  888. switch mode {
  889. case "console":
  890. LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
  891. case "file":
  892. logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "gitea.log"))
  893. if err = os.MkdirAll(path.Dir(logPath), os.ModePerm); err != nil {
  894. panic(err.Error())
  895. }
  896. LogConfigs[i] = fmt.Sprintf(
  897. `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
  898. logPath,
  899. sec.Key("LOG_ROTATE").MustBool(true),
  900. sec.Key("MAX_LINES").MustInt(1000000),
  901. 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
  902. sec.Key("DAILY_ROTATE").MustBool(true),
  903. sec.Key("MAX_DAYS").MustInt(7))
  904. case "conn":
  905. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
  906. sec.Key("RECONNECT_ON_MSG").MustBool(),
  907. sec.Key("RECONNECT").MustBool(),
  908. sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
  909. sec.Key("ADDR").MustString(":7020"))
  910. case "smtp":
  911. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":["%s"],"subject":"%s"}`, level,
  912. sec.Key("USER").MustString("example@example.com"),
  913. sec.Key("PASSWD").MustString("******"),
  914. sec.Key("HOST").MustString("127.0.0.1:25"),
  915. strings.Replace(sec.Key("RECEIVERS").MustString("example@example.com"), ",", "\",\"", -1),
  916. sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
  917. case "database":
  918. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
  919. sec.Key("DRIVER").String(),
  920. sec.Key("CONN").String())
  921. }
  922. log.NewLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, LogConfigs[i])
  923. log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
  924. }
  925. }
  926. // NewXORMLogService initializes xorm logger service
  927. func NewXORMLogService(disableConsole bool) {
  928. logModes := strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
  929. var logConfigs string
  930. for _, mode := range logModes {
  931. mode = strings.TrimSpace(mode)
  932. if disableConsole && mode == "console" {
  933. continue
  934. }
  935. sec, err := Cfg.GetSection("log." + mode)
  936. if err != nil {
  937. sec, _ = Cfg.NewSection("log." + mode)
  938. }
  939. validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
  940. // Log level.
  941. levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
  942. Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
  943. validLevels)
  944. level, ok := logLevels[levelName]
  945. if !ok {
  946. log.Fatal(4, "Unknown log level: %s", levelName)
  947. }
  948. // Generate log configuration.
  949. switch mode {
  950. case "console":
  951. logConfigs = fmt.Sprintf(`{"level":%s}`, level)
  952. case "file":
  953. logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "xorm.log"))
  954. if err = os.MkdirAll(path.Dir(logPath), os.ModePerm); err != nil {
  955. panic(err.Error())
  956. }
  957. logPath = filepath.Join(filepath.Dir(logPath), "xorm.log")
  958. logConfigs = fmt.Sprintf(
  959. `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
  960. logPath,
  961. sec.Key("LOG_ROTATE").MustBool(true),
  962. sec.Key("MAX_LINES").MustInt(1000000),
  963. 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
  964. sec.Key("DAILY_ROTATE").MustBool(true),
  965. sec.Key("MAX_DAYS").MustInt(7))
  966. case "conn":
  967. logConfigs = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
  968. sec.Key("RECONNECT_ON_MSG").MustBool(),
  969. sec.Key("RECONNECT").MustBool(),
  970. sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
  971. sec.Key("ADDR").MustString(":7020"))
  972. case "smtp":
  973. logConfigs = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
  974. sec.Key("USER").MustString("example@example.com"),
  975. sec.Key("PASSWD").MustString("******"),
  976. sec.Key("HOST").MustString("127.0.0.1:25"),
  977. sec.Key("RECEIVERS").MustString("[]"),
  978. sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
  979. case "database":
  980. logConfigs = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
  981. sec.Key("DRIVER").String(),
  982. sec.Key("CONN").String())
  983. }
  984. log.NewXORMLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, logConfigs)
  985. if !disableConsole {
  986. log.Info("XORM Log Mode: %s(%s)", strings.Title(mode), levelName)
  987. }
  988. var lvl core.LogLevel
  989. switch levelName {
  990. case "Trace", "Debug":
  991. lvl = core.LOG_DEBUG
  992. case "Info":
  993. lvl = core.LOG_INFO
  994. case "Warn":
  995. lvl = core.LOG_WARNING
  996. case "Error", "Critical":
  997. lvl = core.LOG_ERR
  998. }
  999. log.XORMLogger.SetLevel(lvl)
  1000. }
  1001. if len(logConfigs) == 0 {
  1002. log.DiscardXORMLogger()
  1003. }
  1004. }
  1005. func newCacheService() {
  1006. CacheAdapter = Cfg.Section("cache").Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
  1007. switch CacheAdapter {
  1008. case "memory":
  1009. CacheInterval = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
  1010. case "redis", "memcache":
  1011. CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
  1012. default:
  1013. log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
  1014. }
  1015. log.Info("Cache Service Enabled")
  1016. }
  1017. func newSessionService() {
  1018. SessionConfig.Provider = Cfg.Section("session").Key("PROVIDER").In("memory",
  1019. []string{"memory", "file", "redis", "mysql"})
  1020. SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").String(), "\" ")
  1021. SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gitea")
  1022. SessionConfig.CookiePath = AppSubURL
  1023. SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool(false)
  1024. SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
  1025. SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
  1026. log.Info("Session Service Enabled")
  1027. }
  1028. // Mailer represents mail service.
  1029. type Mailer struct {
  1030. // Mailer
  1031. QueueLength int
  1032. Name string
  1033. From string
  1034. FromEmail string
  1035. EnableHTMLAlternative bool
  1036. // SMTP sender
  1037. Host string
  1038. User, Passwd string
  1039. DisableHelo bool
  1040. HeloHostname string
  1041. SkipVerify bool
  1042. UseCertificate bool
  1043. CertFile, KeyFile string
  1044. // Sendmail sender
  1045. UseSendmail bool
  1046. SendmailPath string
  1047. }
  1048. var (
  1049. // MailService the global mailer
  1050. MailService *Mailer
  1051. )
  1052. func newMailService() {
  1053. sec := Cfg.Section("mailer")
  1054. // Check mailer setting.
  1055. if !sec.Key("ENABLED").MustBool() {
  1056. return
  1057. }
  1058. MailService = &Mailer{
  1059. QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
  1060. Name: sec.Key("NAME").MustString(AppName),
  1061. EnableHTMLAlternative: sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(),
  1062. Host: sec.Key("HOST").String(),
  1063. User: sec.Key("USER").String(),
  1064. Passwd: sec.Key("PASSWD").String(),
  1065. DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
  1066. HeloHostname: sec.Key("HELO_HOSTNAME").String(),
  1067. SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
  1068. UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
  1069. CertFile: sec.Key("CERT_FILE").String(),
  1070. KeyFile: sec.Key("KEY_FILE").String(),
  1071. UseSendmail: sec.Key("USE_SENDMAIL").MustBool(),
  1072. SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"),
  1073. }
  1074. MailService.From = sec.Key("FROM").MustString(MailService.User)
  1075. parsed, err := mail.ParseAddress(MailService.From)
  1076. if err != nil {
  1077. log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err)
  1078. }
  1079. MailService.FromEmail = parsed.Address
  1080. log.Info("Mail Service Enabled")
  1081. }
  1082. func newRegisterMailService() {
  1083. if !Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").MustBool() {
  1084. return
  1085. } else if MailService == nil {
  1086. log.Warn("Register Mail Service: Mail Service is not enabled")
  1087. return
  1088. }
  1089. Service.RegisterEmailConfirm = true
  1090. log.Info("Register Mail Service Enabled")
  1091. }
  1092. func newNotifyMailService() {
  1093. if !Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").MustBool() {
  1094. return
  1095. } else if MailService == nil {
  1096. log.Warn("Notify Mail Service: Mail Service is not enabled")
  1097. return
  1098. }
  1099. Service.EnableNotifyMail = true
  1100. log.Info("Notify Mail Service Enabled")
  1101. }
  1102. func newWebhookService() {
  1103. sec := Cfg.Section("webhook")
  1104. Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000)
  1105. Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
  1106. Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
  1107. Webhook.Types = []string{"gogs", "slack"}
  1108. Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
  1109. }
  1110. // NewServices initializes the services
  1111. func NewServices() {
  1112. newService()
  1113. newLogService()
  1114. NewXORMLogService(false)
  1115. newCacheService()
  1116. newSessionService()
  1117. newMailService()
  1118. newRegisterMailService()
  1119. newNotifyMailService()
  1120. newWebhookService()
  1121. }