Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

setting.go 18KB

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