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

setting.go 38 kB

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