123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- package conf
- import (
- "net/url"
- "os"
- "time"
- "github.com/gogs/go-libravatar"
- )
- var HasMinWinSvc bool
- var (
- BuildTime string
- BuildCommit string
- )
- var CustomConf string
- var (
-
- App struct {
-
- Version string `ini:"-"`
- BrandName string
- RunUser string
- RunMode string
-
- AppName string
- }
-
- SSH struct {
- Disabled bool `ini:"DISABLE_SSH"`
- Domain string `ini:"SSH_DOMAIN"`
- Port int `ini:"SSH_PORT"`
- RootPath string `ini:"SSH_ROOT_PATH"`
- KeygenPath string `ini:"SSH_KEYGEN_PATH"`
- KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
- MinimumKeySizeCheck bool
- MinimumKeySizes map[string]int `ini:"-"`
- RewriteAuthorizedKeysAtStart bool
- StartBuiltinServer bool `ini:"START_SSH_SERVER"`
- ListenHost string `ini:"SSH_LISTEN_HOST"`
- ListenPort int `ini:"SSH_LISTEN_PORT"`
- ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
- }
-
- Repository struct {
- Root string
- ScriptType string
- ANSICharset string `ini:"ANSI_CHARSET"`
- ForcePrivate bool
- MaxCreationLimit int
- PreferredLicenses []string
- DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
- EnableLocalPathMigration bool
- EnableRawFileRenderMode bool
- CommitsFetchConcurrency int
-
- Editor struct {
- LineWrapExtensions []string
- PreviewableFileModes []string
- } `ini:"repository.editor"`
-
- Upload struct {
- Enabled bool
- TempPath string
- AllowedTypes []string `delim:"|"`
- FileMaxSize int64
- MaxFiles int
- } `ini:"repository.upload"`
- }
-
- Security struct {
- InstallLock bool
- SecretKey string
- LoginRememberDays int
- CookieRememberName string
- CookieUsername string
- CookieSecure bool
- EnableLoginStatusCookie bool
- LoginStatusCookieName string
-
- ReverseProxyAuthenticationUser string
- }
-
- Email struct {
- Enabled bool
- SubjectPrefix string
- Host string
- From string
- User string
- Password string
- DisableHELO bool `ini:"DISABLE_HELO"`
- HELOHostname string `ini:"HELO_HOSTNAME"`
- SkipVerify bool
- UseCertificate bool
- CertFile string
- KeyFile string
- UsePlainText bool
- AddPlainTextAlt bool
-
- FromEmail string `ini:"-"`
-
- Passwd string
- }
-
- Auth struct {
- ActivateCodeLives int
- ResetPasswordCodeLives int
- RequireEmailConfirmation bool
- RequireSigninView bool
- DisableRegistration bool
- EnableRegistrationCaptcha bool
- EnableReverseProxyAuthentication bool
- EnableReverseProxyAutoRegistration bool
- ReverseProxyAuthenticationHeader string
-
- ActiveCodeLiveMinutes int
-
- ResetPasswdCodeLiveMinutes int
-
- RegisterEmailConfirm bool
-
- EnableCaptcha bool
-
- EnableNotifyMail bool
- }
-
- User struct {
- EnableEmailNotification bool
- }
-
- Session struct {
- Provider string
- ProviderConfig string
- CookieName string
- CookieSecure bool
- GCInterval int64 `ini:"GC_INTERVAL"`
- MaxLifeTime int64
- CSRFCookieName string `ini:"CSRF_COOKIE_NAME"`
-
- GCIntervalTime int64 `ini:"GC_INTERVAL_TIME"`
-
- SessionLifeTime int64
- }
-
- Cache struct {
- Adapter string
- Interval int
- Host string
- }
-
- HTTP struct {
- AccessControlAllowOrigin string
- }
-
- Attachment struct {
- Enabled bool
- Path string
- AllowedTypes []string `delim:"|"`
- MaxSize int64
- MaxFiles int
- }
-
- Release struct {
- Attachment struct {
- Enabled bool
- AllowedTypes []string `delim:"|"`
- MaxSize int64
- MaxFiles int
- } `ini:"release.attachment"`
- }
-
- Time struct {
- Format string
-
- FormatLayout string `ini:"-"`
- }
-
- Picture struct {
- AvatarUploadPath string
- RepositoryAvatarUploadPath string
- GravatarSource string
- DisableGravatar bool
- EnableFederatedAvatar bool
-
- LibravatarService *libravatar.Libravatar `ini:"-"`
- }
-
- Mirror struct {
- DefaultInterval int
- }
-
- Webhook struct {
- Types []string
- DeliverTimeout int
- SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
- PagingNum int
- }
-
- Markdown struct {
- EnableHardLineBreak bool
- CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
- FileExtensions []string
- }
-
- Smartypants struct {
- Enabled bool
- Fractions bool
- Dashes bool
- LatexDashes bool
- AngledQuotes bool
- }
-
- Admin struct {
- DisableRegularOrgCreation bool
- }
-
- Cron struct {
- UpdateMirror struct {
- Enabled bool
- RunAtStart bool
- Schedule string
- } `ini:"cron.update_mirrors"`
- RepoHealthCheck struct {
- Enabled bool
- RunAtStart bool
- Schedule string
- Timeout time.Duration
- Args []string `delim:" "`
- } `ini:"cron.repo_health_check"`
- CheckRepoStats struct {
- Enabled bool
- RunAtStart bool
- Schedule string
- } `ini:"cron.check_repo_stats"`
- RepoArchiveCleanup struct {
- Enabled bool
- RunAtStart bool
- Schedule string
- OlderThan time.Duration
- } `ini:"cron.repo_archive_cleanup"`
- }
-
- Git struct {
-
- Version string `ini:"-"`
- DisableDiffHighlight bool
- MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"`
- MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"`
- MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"`
- GCArgs []string `ini:"GC_ARGS" delim:" "`
- Timeout struct {
- Migrate int
- Mirror int
- Clone int
- Pull int
- GC int `ini:"GC"`
- } `ini:"git.timeout"`
- }
-
- API struct {
- MaxResponseItems int
- }
-
- UI struct {
- ExplorePagingNum int
- IssuePagingNum int
- FeedMaxCommitNum int
- ThemeColorMetaTag string
- MaxDisplayFileSize int64
- Admin struct {
- UserPagingNum int
- RepoPagingNum int
- NoticePagingNum int
- OrgPagingNum int
- } `ini:"ui.admin"`
- User struct {
- RepoPagingNum int
- NewsFeedPagingNum int
- CommitsPagingNum int
- } `ini:"ui.user"`
- }
-
- Prometheus struct {
- Enabled bool
- EnableBasicAuth bool
- BasicAuthUsername string
- BasicAuthPassword string
- }
-
- Other struct {
- ShowFooterBranding bool
- ShowFooterTemplateLoadTime bool
- }
-
- HasRobotsTxt bool
- )
- type ServerOpts struct {
- ExternalURL string `ini:"EXTERNAL_URL"`
- Domain string
- Protocol string
- HTTPAddr string `ini:"HTTP_ADDR"`
- HTTPPort string `ini:"HTTP_PORT"`
- CertFile string
- KeyFile string
- TLSMinVersion string `ini:"TLS_MIN_VERSION"`
- UnixSocketPermission string
- LocalRootURL string `ini:"LOCAL_ROOT_URL"`
- OfflineMode bool
- DisableRouterLog bool
- EnableGzip bool
- AppDataPath string
- LoadAssetsFromDisk bool
- LandingURL string `ini:"LANDING_URL"`
-
- URL *url.URL `ini:"-"`
- Subpath string `ini:"-"`
- SubpathDepth int `ini:"-"`
- UnixSocketMode os.FileMode `ini:"-"`
-
- RootURL string `ini:"ROOT_URL"`
-
- LangdingPage string `ini:"LANDING_PAGE"`
- }
- var Server ServerOpts
- type DatabaseOpts struct {
- Type string
- Host string
- Name string
- User string
- Password string
- SSLMode string `ini:"SSL_MODE"`
- Path string
- MaxOpenConns int
- MaxIdleConns int
-
- DbType string
-
- Passwd string
- }
- var Database DatabaseOpts
- type LFSOpts struct {
- Storage string
- ObjectsPath string
- }
- var LFS LFSOpts
- type i18nConf struct {
- Langs []string `delim:","`
- Names []string `delim:","`
- dateLangs map[string]string `ini:"-"`
- }
- func (c *i18nConf) DateLang(lang string) string {
- name, ok := c.dateLangs[lang]
- if ok {
- return name
- }
- return "en"
- }
- var I18n *i18nConf
- func handleDeprecated() {
- if App.AppName != "" {
- App.BrandName = App.AppName
- App.AppName = ""
- }
- if Server.RootURL != "" {
- Server.ExternalURL = Server.RootURL
- Server.RootURL = ""
- }
- if Server.LangdingPage == "explore" {
- Server.LandingURL = "/explore"
- Server.LangdingPage = ""
- }
- if Database.DbType != "" {
- Database.Type = Database.DbType
- Database.DbType = ""
- }
- if Database.Passwd != "" {
- Database.Password = Database.Passwd
- Database.Passwd = ""
- }
- if Email.Passwd != "" {
- Email.Password = Email.Passwd
- Email.Passwd = ""
- }
- if Auth.ActiveCodeLiveMinutes > 0 {
- Auth.ActivateCodeLives = Auth.ActiveCodeLiveMinutes
- Auth.ActiveCodeLiveMinutes = 0
- }
- if Auth.ResetPasswdCodeLiveMinutes > 0 {
- Auth.ResetPasswordCodeLives = Auth.ResetPasswdCodeLiveMinutes
- Auth.ResetPasswdCodeLiveMinutes = 0
- }
- if Auth.RegisterEmailConfirm {
- Auth.RequireEmailConfirmation = true
- Auth.RegisterEmailConfirm = false
- }
- if Auth.EnableCaptcha {
- Auth.EnableRegistrationCaptcha = true
- Auth.EnableCaptcha = false
- }
- if Security.ReverseProxyAuthenticationUser != "" {
- Auth.ReverseProxyAuthenticationHeader = Security.ReverseProxyAuthenticationUser
- Security.ReverseProxyAuthenticationUser = ""
- }
- if Auth.EnableNotifyMail {
- User.EnableEmailNotification = true
- Auth.EnableNotifyMail = false
- }
- if Session.GCIntervalTime > 0 {
- Session.GCInterval = Session.GCIntervalTime
- Session.GCIntervalTime = 0
- }
- if Session.SessionLifeTime > 0 {
- Session.MaxLifeTime = Session.SessionLifeTime
- Session.SessionLifeTime = 0
- }
- }
- var HookMode bool
- var (
- UseSQLite3 bool
- UseMySQL bool
- UsePostgreSQL bool
- UseMSSQL bool
- )
|