setting.go 18 KB

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