You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setting.go 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. UseTiDB bool
  66. // Webhook settings.
  67. Webhook struct {
  68. QueueLength int
  69. DeliverTimeout int
  70. SkipTLSVerify bool
  71. Types []string
  72. PagingNum int
  73. }
  74. // Repository settings.
  75. RepoRootPath string
  76. ScriptType string
  77. AnsiCharset string
  78. // UI settings.
  79. ExplorePagingNum int
  80. IssuePagingNum int
  81. AdminUserPagingNum 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. sec = Cfg.Section("picture")
  321. PictureService = sec.Key("SERVICE").In("server", []string{"server"})
  322. AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString("data/avatars")
  323. forcePathSeparator(AvatarUploadPath)
  324. if !filepath.IsAbs(AvatarUploadPath) {
  325. AvatarUploadPath = path.Join(workDir, AvatarUploadPath)
  326. }
  327. switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
  328. case "duoshuo":
  329. GravatarSource = "http://gravatar.duoshuo.com/avatar/"
  330. case "gravatar":
  331. GravatarSource = "//1.gravatar.com/avatar/"
  332. default:
  333. GravatarSource = source
  334. }
  335. DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool()
  336. if OfflineMode {
  337. DisableGravatar = true
  338. }
  339. if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
  340. log.Fatal(4, "Fail to map Markdown settings: %v", err)
  341. } else if err = Cfg.Section("git").MapTo(&Git); err != nil {
  342. log.Fatal(4, "Fail to map Git settings: %v", err)
  343. } else if Cfg.Section("cron").MapTo(&Cron); err != nil {
  344. log.Fatal(4, "Fail to map Cron settings: %v", err)
  345. }
  346. Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
  347. Names = Cfg.Section("i18n").Key("NAMES").Strings(",")
  348. dateLangs = Cfg.Section("i18n.datelang").KeysHash()
  349. ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool()
  350. HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
  351. }
  352. var Service struct {
  353. ActiveCodeLives int
  354. ResetPwdCodeLives int
  355. RegisterEmailConfirm bool
  356. DisableRegistration bool
  357. ShowRegistrationButton bool
  358. RequireSignInView bool
  359. EnableCacheAvatar bool
  360. EnableNotifyMail bool
  361. EnableReverseProxyAuth bool
  362. EnableReverseProxyAutoRegister bool
  363. DisableMinimumKeySizeCheck bool
  364. EnableCaptcha bool
  365. }
  366. func newService() {
  367. sec := Cfg.Section("service")
  368. Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
  369. Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
  370. Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
  371. Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!Service.DisableRegistration)
  372. Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
  373. Service.EnableCacheAvatar = sec.Key("ENABLE_CACHE_AVATAR").MustBool()
  374. Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
  375. Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
  376. Service.DisableMinimumKeySizeCheck = sec.Key("DISABLE_MINIMUM_KEY_SIZE_CHECK").MustBool()
  377. Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
  378. }
  379. var logLevels = map[string]string{
  380. "Trace": "0",
  381. "Debug": "1",
  382. "Info": "2",
  383. "Warn": "3",
  384. "Error": "4",
  385. "Critical": "5",
  386. }
  387. func newLogService() {
  388. log.Info("%s %s", AppName, AppVer)
  389. // Get and check log mode.
  390. LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
  391. LogConfigs = make([]string, len(LogModes))
  392. for i, mode := range LogModes {
  393. mode = strings.TrimSpace(mode)
  394. sec, err := Cfg.GetSection("log." + mode)
  395. if err != nil {
  396. log.Fatal(4, "Unknown log mode: %s", mode)
  397. }
  398. validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
  399. // Log level.
  400. levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
  401. Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
  402. validLevels)
  403. level, ok := logLevels[levelName]
  404. if !ok {
  405. log.Fatal(4, "Unknown log level: %s", levelName)
  406. }
  407. // Generate log configuration.
  408. switch mode {
  409. case "console":
  410. LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
  411. case "file":
  412. logPath := sec.Key("FILE_NAME").MustString(path.Join(LogRootPath, "gogs.log"))
  413. os.MkdirAll(path.Dir(logPath), os.ModePerm)
  414. LogConfigs[i] = fmt.Sprintf(
  415. `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
  416. logPath,
  417. sec.Key("LOG_ROTATE").MustBool(true),
  418. sec.Key("MAX_LINES").MustInt(1000000),
  419. 1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
  420. sec.Key("DAILY_ROTATE").MustBool(true),
  421. sec.Key("MAX_DAYS").MustInt(7))
  422. case "conn":
  423. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
  424. sec.Key("RECONNECT_ON_MSG").MustBool(),
  425. sec.Key("RECONNECT").MustBool(),
  426. sec.Key("PROTOCOL").In("tcp", []string{"tcp", "unix", "udp"}),
  427. sec.Key("ADDR").MustString(":7020"))
  428. case "smtp":
  429. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
  430. sec.Key("USER").MustString("example@example.com"),
  431. sec.Key("PASSWD").MustString("******"),
  432. sec.Key("HOST").MustString("127.0.0.1:25"),
  433. sec.Key("RECEIVERS").MustString("[]"),
  434. sec.Key("SUBJECT").MustString("Diagnostic message from serve"))
  435. case "database":
  436. LogConfigs[i] = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level,
  437. sec.Key("DRIVER").String(),
  438. sec.Key("CONN").String())
  439. }
  440. log.NewLogger(Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000), mode, LogConfigs[i])
  441. log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
  442. }
  443. }
  444. func newCacheService() {
  445. CacheAdapter = Cfg.Section("cache").Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
  446. if EnableRedis {
  447. log.Info("Redis Supported")
  448. }
  449. if EnableMemcache {
  450. log.Info("Memcache Supported")
  451. }
  452. switch CacheAdapter {
  453. case "memory":
  454. CacheInternal = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
  455. case "redis", "memcache":
  456. CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
  457. default:
  458. log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
  459. }
  460. log.Info("Cache Service Enabled")
  461. }
  462. func newSessionService() {
  463. SessionConfig.Provider = Cfg.Section("session").Key("PROVIDER").In("memory",
  464. []string{"memory", "file", "redis", "mysql"})
  465. SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").String(), "\" ")
  466. SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gogits")
  467. SessionConfig.CookiePath = AppSubUrl
  468. SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool()
  469. SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
  470. SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
  471. log.Info("Session Service Enabled")
  472. }
  473. // Mailer represents mail service.
  474. type Mailer struct {
  475. QueueLength int
  476. Name string
  477. Host string
  478. From string
  479. User, Passwd string
  480. DisableHelo bool
  481. HeloHostname string
  482. SkipVerify bool
  483. UseCertificate bool
  484. CertFile, KeyFile string
  485. }
  486. type OauthInfo struct {
  487. oauth2.Options
  488. AuthUrl, TokenUrl string
  489. }
  490. // Oauther represents oauth service.
  491. type Oauther struct {
  492. GitHub, Google, Tencent,
  493. Twitter, Weibo bool
  494. OauthInfos map[string]*OauthInfo
  495. }
  496. var (
  497. MailService *Mailer
  498. OauthService *Oauther
  499. )
  500. func newMailService() {
  501. sec := Cfg.Section("mailer")
  502. // Check mailer setting.
  503. if !sec.Key("ENABLED").MustBool() {
  504. return
  505. }
  506. MailService = &Mailer{
  507. QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
  508. Name: sec.Key("NAME").MustString(AppName),
  509. Host: sec.Key("HOST").String(),
  510. User: sec.Key("USER").String(),
  511. Passwd: sec.Key("PASSWD").String(),
  512. DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
  513. HeloHostname: sec.Key("HELO_HOSTNAME").String(),
  514. SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
  515. UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
  516. CertFile: sec.Key("CERT_FILE").String(),
  517. KeyFile: sec.Key("KEY_FILE").String(),
  518. }
  519. MailService.From = sec.Key("FROM").MustString(MailService.User)
  520. log.Info("Mail Service Enabled")
  521. }
  522. func newRegisterMailService() {
  523. if !Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").MustBool() {
  524. return
  525. } else if MailService == nil {
  526. log.Warn("Register Mail Service: Mail Service is not enabled")
  527. return
  528. }
  529. Service.RegisterEmailConfirm = true
  530. log.Info("Register Mail Service Enabled")
  531. }
  532. func newNotifyMailService() {
  533. if !Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").MustBool() {
  534. return
  535. } else if MailService == nil {
  536. log.Warn("Notify Mail Service: Mail Service is not enabled")
  537. return
  538. }
  539. Service.EnableNotifyMail = true
  540. log.Info("Notify Mail Service Enabled")
  541. }
  542. func newWebhookService() {
  543. sec := Cfg.Section("webhook")
  544. Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000)
  545. Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
  546. Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
  547. Webhook.Types = []string{"gogs", "slack"}
  548. Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
  549. }
  550. func NewServices() {
  551. newService()
  552. newLogService()
  553. newCacheService()
  554. newSessionService()
  555. newMailService()
  556. newRegisterMailService()
  557. newNotifyMailService()
  558. newWebhookService()
  559. // ssh.Listen("2222")
  560. }