setting.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. "fmt"
  7. "net/url"
  8. "os"
  9. "os/exec"
  10. "path"
  11. "path/filepath"
  12. "runtime"
  13. "strings"
  14. "time"
  15. "gopkg.in/ini.v1"
  16. "github.com/Unknwon/com"
  17. "github.com/macaron-contrib/oauth2"
  18. "github.com/macaron-contrib/session"
  19. "github.com/gogits/gogs/modules/bindata"
  20. "github.com/gogits/gogs/modules/log"
  21. // "github.com/gogits/gogs/modules/ssh"
  22. "github.com/gogits/gogs/modules/user"
  23. )
  24. type Scheme string
  25. const (
  26. HTTP Scheme = "http"
  27. HTTPS Scheme = "https"
  28. FCGI Scheme = "fcgi"
  29. )
  30. type LandingPage string
  31. const (
  32. LANDING_PAGE_HOME LandingPage = "/"
  33. LANDING_PAGE_EXPLORE LandingPage = "/explore"
  34. )
  35. var (
  36. // App settings.
  37. AppVer string
  38. AppName string
  39. AppUrl string
  40. AppSubUrl string
  41. // Server settings.
  42. Protocol Scheme
  43. Domain string
  44. HttpAddr, HttpPort string
  45. DisableSSH bool
  46. SSHPort int
  47. SSHDomain string
  48. OfflineMode bool
  49. DisableRouterLog bool
  50. CertFile, KeyFile string
  51. StaticRootPath string
  52. EnableGzip bool
  53. LandingPageUrl LandingPage
  54. // Security settings.
  55. InstallLock bool
  56. SecretKey string
  57. LogInRememberDays int
  58. CookieUserName string
  59. CookieRememberName string
  60. ReverseProxyAuthUser string
  61. // Database settings.
  62. UseSQLite3 bool
  63. UseMySQL bool
  64. UsePostgreSQL bool
  65. // Webhook settings.
  66. Webhook struct {
  67. QueueLength int
  68. DeliverTimeout int
  69. SkipTLSVerify bool
  70. Types []string
  71. PagingNum int
  72. }
  73. // Repository settings.
  74. RepoRootPath string
  75. ScriptType string
  76. AnsiCharset string
  77. // UI settings.
  78. IssuePagingNum int
  79. // Picture settings.
  80. PictureService string
  81. AvatarUploadPath string
  82. GravatarSource string
  83. DisableGravatar bool
  84. // Log settings.
  85. LogRootPath string
  86. LogModes []string
  87. LogConfigs []string
  88. // Attachment settings.
  89. AttachmentPath string
  90. AttachmentAllowedTypes string
  91. AttachmentMaxSize int64
  92. AttachmentMaxFiles int
  93. AttachmentEnabled bool
  94. // Time settings.
  95. TimeFormat string
  96. // Cache settings.
  97. CacheAdapter string
  98. CacheInternal int
  99. CacheConn string
  100. EnableRedis bool
  101. EnableMemcache bool
  102. // Session settings.
  103. SessionConfig session.Options
  104. // Git settings.
  105. Git struct {
  106. MaxGitDiffLines int
  107. GcArgs []string `delim:" "`
  108. }
  109. // Cron tasks.
  110. Cron struct {
  111. UpdateMirror struct {
  112. Enabled bool
  113. RunAtStart bool
  114. Schedule string
  115. } `ini:"cron.update_mirrors"`
  116. RepoHealthCheck struct {
  117. Enabled bool
  118. RunAtStart bool
  119. Schedule string
  120. Args []string `delim:" "`
  121. } `ini:"cron.repo_health_check"`
  122. CheckRepoStats struct {
  123. Enabled bool
  124. RunAtStart bool
  125. Schedule string
  126. } `ini:"cron.check_repo_stats"`
  127. }
  128. // I18n settings.
  129. Langs, Names []string
  130. dateLangs map[string]string
  131. // Other settings.
  132. ShowFooterBranding bool
  133. // Global setting objects.
  134. Cfg *ini.File
  135. CustomPath string // Custom directory path.
  136. CustomConf string
  137. ProdMode bool
  138. RunUser string
  139. IsWindows bool
  140. HasRobotsTxt bool
  141. )
  142. func DateLang(lang string) string {
  143. name, ok := dateLangs[lang]
  144. if ok {
  145. return name
  146. }
  147. return "en"
  148. }
  149. func init() {
  150. IsWindows = runtime.GOOS == "windows"
  151. log.NewLogger(0, "console", `{"level": 0}`)
  152. }
  153. func ExecPath() (string, error) {
  154. file, err := exec.LookPath(os.Args[0])
  155. if err != nil {
  156. return "", err
  157. }
  158. p, err := filepath.Abs(file)
  159. if err != nil {
  160. return "", err
  161. }
  162. return p, nil
  163. }
  164. // WorkDir returns absolute path of work directory.
  165. func WorkDir() (string, error) {
  166. execPath, err := ExecPath()
  167. if err != nil {
  168. return execPath, err
  169. }
  170. // Note: we don't use path.Dir here because it does not handle case
  171. // which path starts with two "/" in Windows: "//psf/Home/..."
  172. execPath = strings.Replace(execPath, "\\", "/", -1)
  173. i := strings.LastIndex(execPath, "/")
  174. if i == -1 {
  175. return execPath, nil
  176. }
  177. return execPath[:i], nil
  178. }
  179. func forcePathSeparator(path string) {
  180. if strings.Contains(path, "\\") {
  181. log.Fatal(4, "Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
  182. }
  183. }
  184. // NewConfigContext initializes configuration context.
  185. // NOTE: do not print any log except error.
  186. func NewConfigContext() {
  187. workDir, err := WorkDir()
  188. if err != nil {
  189. log.Fatal(4, "Fail to get work directory: %v", err)
  190. }
  191. Cfg, err = ini.Load(bindata.MustAsset("conf/app.ini"))
  192. if err != nil {
  193. log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err)
  194. }
  195. CustomPath = os.Getenv("GOGS_CUSTOM")
  196. if len(CustomPath) == 0 {
  197. CustomPath = workDir + "/custom"
  198. }
  199. if len(CustomConf) == 0 {
  200. CustomConf = CustomPath + "/conf/app.ini"
  201. }
  202. if com.IsFile(CustomConf) {
  203. if err = Cfg.Append(CustomConf); err != nil {
  204. log.Fatal(4, "Fail to load custom conf '%s': %v", CustomConf, err)
  205. }
  206. } else {
  207. log.Warn("Custom config (%s) not found, ignore this if you're running first time", CustomConf)
  208. }
  209. Cfg.NameMapper = ini.AllCapsUnderscore
  210. LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log"))
  211. forcePathSeparator(LogRootPath)
  212. sec := Cfg.Section("server")
  213. AppName = Cfg.Section("").Key("APP_NAME").MustString("Gogs: Go Git Service")
  214. AppUrl = sec.Key("ROOT_URL").MustString("http://localhost:3000/")
  215. if AppUrl[len(AppUrl)-1] != '/' {
  216. AppUrl += "/"
  217. }
  218. // Check if has app suburl.
  219. url, err := url.Parse(AppUrl)
  220. if err != nil {
  221. log.Fatal(4, "Invalid ROOT_URL(%s): %s", AppUrl, err)
  222. }
  223. AppSubUrl = strings.TrimSuffix(url.Path, "/")
  224. Protocol = HTTP
  225. if sec.Key("PROTOCOL").String() == "https" {
  226. Protocol = HTTPS
  227. CertFile = sec.Key("CERT_FILE").String()
  228. KeyFile = sec.Key("KEY_FILE").String()
  229. } else if sec.Key("PROTOCOL").String() == "fcgi" {
  230. Protocol = FCGI
  231. }
  232. Domain = sec.Key("DOMAIN").MustString("localhost")
  233. HttpAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
  234. HttpPort = sec.Key("HTTP_PORT").MustString("3000")
  235. DisableSSH = sec.Key("DISABLE_SSH").MustBool()
  236. SSHDomain = sec.Key("SSH_DOMAIN").MustString(Domain)
  237. SSHPort = sec.Key("SSH_PORT").MustInt(22)
  238. OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
  239. DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()
  240. StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(workDir)
  241. EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
  242. switch sec.Key("LANDING_PAGE").MustString("home") {
  243. case "explore":
  244. LandingPageUrl = LANDING_PAGE_EXPLORE
  245. default:
  246. LandingPageUrl = LANDING_PAGE_HOME
  247. }
  248. sec = Cfg.Section("security")
  249. InstallLock = sec.Key("INSTALL_LOCK").MustBool()
  250. SecretKey = sec.Key("SECRET_KEY").String()
  251. LogInRememberDays = sec.Key("LOGIN_REMEMBER_DAYS").MustInt()
  252. CookieUserName = sec.Key("COOKIE_USERNAME").String()
  253. CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").String()
  254. ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
  255. sec = Cfg.Section("attachment")
  256. AttachmentPath = sec.Key("PATH").MustString("data/attachments")
  257. if !filepath.IsAbs(AttachmentPath) {
  258. AttachmentPath = path.Join(workDir, AttachmentPath)
  259. }
  260. AttachmentAllowedTypes = strings.Replace(sec.Key("ALLOWED_TYPES").MustString("image/jpeg,image/png"), "|", ",", -1)
  261. AttachmentMaxSize = sec.Key("MAX_SIZE").MustInt64(32)
  262. AttachmentMaxFiles = sec.Key("MAX_FILES").MustInt(5)
  263. AttachmentEnabled = sec.Key("ENABLE").MustBool(true)
  264. TimeFormat = map[string]string{
  265. "ANSIC": time.ANSIC,
  266. "UnixDate": time.UnixDate,
  267. "RubyDate": time.RubyDate,
  268. "RFC822": time.RFC822,
  269. "RFC822Z": time.RFC822Z,
  270. "RFC850": time.RFC850,
  271. "RFC1123": time.RFC1123,
  272. "RFC1123Z": time.RFC1123Z,
  273. "RFC3339": time.RFC3339,
  274. "RFC3339Nano": time.RFC3339Nano,
  275. "Kitchen": time.Kitchen,
  276. "Stamp": time.Stamp,
  277. "StampMilli": time.StampMilli,
  278. "StampMicro": time.StampMicro,
  279. "StampNano": time.StampNano,
  280. }[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")]
  281. RunUser = Cfg.Section("").Key("RUN_USER").String()
  282. curUser := user.CurrentUsername()
  283. // Does not check run user when the install lock is off.
  284. if InstallLock && RunUser != curUser {
  285. log.Fatal(4, "Expect user(%s) but current user is: %s", RunUser, curUser)
  286. }
  287. // Determine and create root git repository path.
  288. homeDir, err := com.HomeDir()
  289. if err != nil {
  290. log.Fatal(4, "Fail to get home directory: %v", err)
  291. }
  292. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  293. sec = Cfg.Section("repository")
  294. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gogs-repositories"))
  295. forcePathSeparator(RepoRootPath)
  296. if !filepath.IsAbs(RepoRootPath) {
  297. RepoRootPath = path.Join(workDir, RepoRootPath)
  298. } else {
  299. RepoRootPath = path.Clean(RepoRootPath)
  300. }
  301. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  302. AnsiCharset = sec.Key("ANSI_CHARSET").MustString("")
  303. // UI settings.
  304. IssuePagingNum = Cfg.Section("ui").Key("ISSUE_PAGING_NUM").MustInt(10)
  305. sec = Cfg.Section("picture")
  306. PictureService = sec.Key("SERVICE").In("server", []string{"server"})
  307. AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString("data/avatars")
  308. forcePathSeparator(AvatarUploadPath)
  309. if !filepath.IsAbs(AvatarUploadPath) {
  310. AvatarUploadPath = path.Join(workDir, AvatarUploadPath)
  311. }
  312. switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
  313. case "duoshuo":
  314. GravatarSource = "http://gravatar.duoshuo.com/avatar/"
  315. case "gravatar":
  316. GravatarSource = "//1.gravatar.com/avatar/"
  317. default:
  318. GravatarSource = source
  319. }
  320. DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool()
  321. if OfflineMode {
  322. DisableGravatar = true
  323. }
  324. if err = Cfg.Section("git").MapTo(&Git); err != nil {
  325. log.Fatal(4, "Fail to map Git settings: %v", err)
  326. } else if Cfg.Section("cron").MapTo(&Cron); err != nil {
  327. log.Fatal(4, "Fail to map Cron settings: %v", err)
  328. }
  329. Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
  330. Names = Cfg.Section("i18n").Key("NAMES").Strings(",")
  331. dateLangs = Cfg.Section("i18n.datelang").KeysHash()
  332. ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool()
  333. HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
  334. }
  335. var Service struct {
  336. ActiveCodeLives int
  337. ResetPwdCodeLives int
  338. RegisterEmailConfirm bool
  339. DisableRegistration bool
  340. ShowRegistrationButton bool
  341. RequireSignInView bool
  342. EnableCacheAvatar bool
  343. EnableNotifyMail bool
  344. EnableReverseProxyAuth bool
  345. EnableReverseProxyAutoRegister bool
  346. DisableMinimumKeySizeCheck bool
  347. }
  348. func newService() {
  349. sec := Cfg.Section("service")
  350. Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
  351. Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
  352. Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
  353. Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!Service.DisableRegistration)
  354. Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
  355. Service.EnableCacheAvatar = sec.Key("ENABLE_CACHE_AVATAR").MustBool()
  356. Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
  357. Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
  358. Service.DisableMinimumKeySizeCheck = sec.Key("DISABLE_MINIMUM_KEY_SIZE_CHECK").MustBool()
  359. }
  360. var logLevels = map[string]string{
  361. "Trace": "0",
  362. "Debug": "1",
  363. "Info": "2",
  364. "Warn": "3",
  365. "Error": "4",
  366. "Critical": "5",
  367. }
  368. func newLogService() {
  369. log.Info("%s %s", AppName, AppVer)
  370. // Get and check log mode.
  371. LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
  372. LogConfigs = make([]string, len(LogModes))
  373. for i, mode := range LogModes {
  374. mode = strings.TrimSpace(mode)
  375. sec, err := Cfg.GetSection("log." + mode)
  376. if err != nil {
  377. log.Fatal(4, "Unknown log mode: %s", mode)
  378. }
  379. validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
  380. // Log level.
  381. levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
  382. Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
  383. validLevels)
  384. level, ok := logLevels[levelName]
  385. if !ok {
  386. log.Fatal(4, "Unknown log level: %s", levelName)
  387. }
  388. // Generate log configuration.
  389. switch mode {
  390. case "console":
  391. LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
  392. case "file":
  393. logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "gogs.log"))
  394. os.MkdirAll(path.Dir(logPath), os.ModePerm)
  395. LogConfigs[i] = fmt.Sprintf(
  396. `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
  397. logPath,
  398. sec.Key("LOG_ROTATE").MustBool(true),
  399. sec.Key("MAX_LINES").MustInt(1000000),
  400. 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
  401. sec.Key("DAILY_ROTATE").MustBool(true),
  402. sec.Key("MAX_DAYS").MustInt(7))
  403. case "conn":
  404. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
  405. sec.Key("RECONNECT_ON_MSG").MustBool(),
  406. sec.Key("RECONNECT").MustBool(),
  407. sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
  408. sec.Key("ADDR").MustString(":7020"))
  409. case "smtp":
  410. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
  411. sec.Key("USER").MustString("[email protected]"),
  412. sec.Key("PASSWD").MustString("******"),
  413. sec.Key("HOST").MustString("127.0.0.1:25"),
  414. sec.Key("RECEIVERS").MustString("[]"),
  415. sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
  416. case "database":
  417. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
  418. sec.Key("DRIVER").String(),
  419. sec.Key("CONN").String())
  420. }
  421. log.NewLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, LogConfigs[i])
  422. log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
  423. }
  424. }
  425. func newCacheService() {
  426. CacheAdapter = Cfg.Section("cache").Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
  427. if EnableRedis {
  428. log.Info("Redis Supported")
  429. }
  430. if EnableMemcache {
  431. log.Info("Memcache Supported")
  432. }
  433. switch CacheAdapter {
  434. case "memory":
  435. CacheInternal = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
  436. case "redis", "memcache":
  437. CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
  438. default:
  439. log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
  440. }
  441. log.Info("Cache Service Enabled")
  442. }
  443. func newSessionService() {
  444. SessionConfig.Provider = Cfg.Section("session").Key("PROVIDER").In("memory",
  445. []string{"memory", "file", "redis", "mysql"})
  446. SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").String(), "\" ")
  447. SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gogits")
  448. SessionConfig.CookiePath = AppSubUrl
  449. SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool()
  450. SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
  451. SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
  452. log.Info("Session Service Enabled")
  453. }
  454. // Mailer represents mail service.
  455. type Mailer struct {
  456. Name string
  457. Host string
  458. From string
  459. User, Passwd string
  460. DisableHelo bool
  461. HeloHostname string
  462. SkipVerify bool
  463. UseCertificate bool
  464. CertFile, KeyFile string
  465. }
  466. type OauthInfo struct {
  467. oauth2.Options
  468. AuthUrl, TokenUrl string
  469. }
  470. // Oauther represents oauth service.
  471. type Oauther struct {
  472. GitHub, Google, Tencent,
  473. Twitter, Weibo bool
  474. OauthInfos map[string]*OauthInfo
  475. }
  476. var (
  477. MailService *Mailer
  478. OauthService *Oauther
  479. )
  480. func newMailService() {
  481. sec := Cfg.Section("mailer")
  482. // Check mailer setting.
  483. if !sec.Key("ENABLED").MustBool() {
  484. return
  485. }
  486. MailService = &Mailer{
  487. Name: sec.Key("NAME").MustString(AppName),
  488. Host: sec.Key("HOST").String(),
  489. User: sec.Key("USER").String(),
  490. Passwd: sec.Key("PASSWD").String(),
  491. DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
  492. HeloHostname: sec.Key("HELO_HOSTNAME").String(),
  493. SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
  494. UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
  495. CertFile: sec.Key("CERT_FILE").String(),
  496. KeyFile: sec.Key("KEY_FILE").String(),
  497. }
  498. MailService.From = sec.Key("FROM").MustString(MailService.User)
  499. log.Info("Mail Service Enabled")
  500. }
  501. func newRegisterMailService() {
  502. if !Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").MustBool() {
  503. return
  504. } else if MailService == nil {
  505. log.Warn("Register Mail Service: Mail Service is not enabled")
  506. return
  507. }
  508. Service.RegisterEmailConfirm = true
  509. log.Info("Register Mail Service Enabled")
  510. }
  511. func newNotifyMailService() {
  512. if !Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").MustBool() {
  513. return
  514. } else if MailService == nil {
  515. log.Warn("Notify Mail Service: Mail Service is not enabled")
  516. return
  517. }
  518. Service.EnableNotifyMail = true
  519. log.Info("Notify Mail Service Enabled")
  520. }
  521. func newWebhookService() {
  522. sec := Cfg.Section("webhook")
  523. Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000)
  524. Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
  525. Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
  526. Webhook.Types = []string{"gogs", "slack"}
  527. Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
  528. }
  529. func NewServices() {
  530. newService()
  531. newLogService()
  532. newCacheService()
  533. newSessionService()
  534. newMailService()
  535. newRegisterMailService()
  536. newNotifyMailService()
  537. newWebhookService()
  538. // ssh.Listen("2222")
  539. }