setting.go 17 KB

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