setting.go 18 KB

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