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

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