setting.go 17 KB

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