setting.go 17 KB

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