setting.go 18 KB

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