Beispiel #1
0
func initMailing() {
	meth := confhelper.ConfStringOrFatal(conf, "mail", "method")
	MailFrom = confhelper.ConfStringOrFatal(conf, "mail", "from")

	parallel := confhelper.ConfIntOrFatal(conf, "mail", "parallel")
	if parallel <= 0 {
		log.Fatalln("mail.parallel must be > 0")
	}

	mailchan = make(chan *email)

	mc, ok := mailing.MailersByName[meth]
	if !ok {
		log.Fatalf("Unknown mail method: %s", meth)
	}

	for i := int64(0); i < parallel; i++ {
		mailer, err := mc(conf)
		if err != nil {
			log.Fatalf("Error while initializing mail: %s", err)
		}

		go func(mailer mailing.Mailer) {
			for {
				mail := <-mailchan
				if err := mailer.Mail(mail.To, mail.From, mail.Msg); err != nil {
					log.Printf("Could not send mail to \"%s\": %s", mail.To, err)
					mail.OK <- false
				} else {
					mail.OK <- true
				}
			}
		}(mailer)
	}
}
Beispiel #2
0
func initDB() {
	dbdrv := confhelper.ConfStringOrFatal(conf, "db", "driver")
	dbconf := confhelper.ConfStringOrFatal(conf, "db", "conf")

	var ok bool
	if db, ok = model.GetDBInfo(dbdrv); !ok {
		log.Fatalf("Could not get info for dbdrv %s", dbdrv)
	}

	var err error
	if dbcon, err = db.Connect(dbconf); err != nil {
		log.Fatalf("Unable to connect to %s database: %s", dbdrv, err)
	}
}
Beispiel #3
0
func main() {
	confpath := flag.String("config", "", "Path to config file")
	flag.Parse()

	var err error
	if conf, err = simpleconf.LoadByFilename(*confpath); err != nil {
		log.Fatalf("Could not read config: %s", err)
	}

	baseurl = confhelper.ConfStringOrFatal(conf, "web", "baseurl")

	rand.Seed(time.Now().UnixNano())

	initSessions()
	initTpls()
	loadTimeLocs()
	initMailing()
	initMails()
	initDB()
	initLimits()
	defer dbcon.Close()

	staticpath := confhelper.ConfStringOrFatal(conf, "paths", "static")
	laddr := confhelper.ConfStringOrFatal(conf, "net", "laddr")

	initCheckjobs()
	go checkjobs()

	router := mux.NewRouter()
	router.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticpath))))
	router.HandleFunc("/register", mkHttpHandler(register, tplRegister))
	router.HandleFunc("/activate", mkHttpHandler(activate, tplMsg))
	router.HandleFunc("/login", mkHttpHandler(login, tplLogin))
	router.HandleFunc("/logout", mkHttpHandler(logout, tplMsg))
	router.HandleFunc("/delete-acc/yes", mkHttpHandler(deleteacc, tplMsg))
	router.HandleFunc("/delete-acc", mkHttpHandler(deleteask, tplReallyDelete))
	router.HandleFunc("/pwreset", mkHttpHandler(pwreset, tplPwreset))
	router.HandleFunc("/forgotpw", mkHttpHandler(forgotpw, tplForgotpw))
	router.HandleFunc("/jobs", mkHttpHandler(jobs, tplJobs))
	router.HandleFunc("/jobedit", mkHttpHandler(jobedit, tplJobedit))
	router.HandleFunc("/jobedit/{ID}", mkHttpHandler(jobedit, tplJobedit))
	router.HandleFunc("/settings", mkHttpHandler(settings, tplSettings))
	router.HandleFunc("/", mkHttpHandler(index, tplIndex))

	http.Handle("/", router)

	if err := http.ListenAndServe(laddr, nil); err != nil {
		log.Fatalf("Could not ListenAndServe: %s", err)
	}
}
Beispiel #4
0
func initSessions() {
	_auth := confhelper.ConfStringOrFatal(conf, "securecookies", "auth")
	auth, err := hex.DecodeString(_auth)
	if err != nil {
		log.Fatalf("Could not decode securecookies.auth as hex: %s", err)
	}

	_crypt := confhelper.ConfStringOrFatal(conf, "securecookies", "crypt")
	crypt, err := hex.DecodeString(_crypt)
	if err != nil {
		log.Fatalf("Could not decode securecookies.auth as hex: %s", err)
	}

	SessionStorage = sessions.NewCookieStore(auth, crypt)
}
Beispiel #5
0
func initTpls() {
	tplpath := confhelper.ConfStringOrFatal(conf, "paths", "tpls")

	tplRegister = loadTpl(tplpath, "register")
	tplMsg = loadTpl(tplpath, "msg")
	tplLogin = loadTpl(tplpath, "login")
	tplReallyDelete = loadTpl(tplpath, "reallydelete")
	tplPwreset = loadTpl(tplpath, "pwreset")
	tplForgotpw = loadTpl(tplpath, "forgotpw")
	tplJobs = loadTpl(tplpath, "jobs")
	tplJobedit = loadTpl(tplpath, "jobedit")
	tplSettings = loadTpl(tplpath, "settings")
	tplIndex = loadTpl(tplpath, "index")
}
Beispiel #6
0
func initMails() {
	tplroot := confhelper.ConfStringOrFatal(conf, "paths", "mailtpls")

	mailActivationcode = loadMailTpl(tplroot, "activationcode")
	mailPwreset = loadMailTpl(tplroot, "pwreset")
}