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