Ejemplo n.º 1
0
// Send campaign
func (c campaign) send() {
	var r recipient
	var wg sync.WaitGroup

	query, err := models.Db.Prepare("SELECT `id`, `email`, `name` FROM recipient WHERE campaign_id=? AND removed=0 AND status IS NULL")
	checkErr(err)
	defer query.Close()

	q, err := query.Query(c.id)
	checkErr(err)
	defer q.Close()

	for q.Next() {
		err = q.Scan(&r.id, &r.to_email, &r.to_name)
		checkErr(err)
		if r.unsubscribe(c.id) == false || c.sendUnsubscribe {
			models.Db.Exec("UPDATE recipient SET status='Sending', date=NOW() WHERE id=?", r.id)
			pid, iface, host := models.ProfileNext(c.profileId)
			go func(d recipient, p int, i, h string) {
				wg.Add(1)
				rs := d.send(&c, i, h)
				wg.Done()
				models.ProfileFree(p)
				models.Db.Exec("UPDATE recipient SET status=?, date=NOW() WHERE id=?", rs, d.id)
			}(r, pid, iface, host)
		} else {
			models.Db.Exec("UPDATE recipient SET status='Unsubscribe', date=NOW() WHERE id=?", r.id)
			camplog.Printf("Recipient id %s email %s is unsubscribed", r.id, r.to_email)
		}
	}
	wg.Wait()
	camplog.Printf("Done campaign id %s.", c.id)
}
Ejemplo n.º 2
0
func (c campaign) resend() {
	var r recipient

	count := c.countSoftBounce()
	if count == 0 {
		return
	}

	if c.resendCount != 0 {
		camplog.Printf("Start %d resend by campaign id %s ", count, c.id)
	}

	for n := 0; n < c.resendCount; n++ {
		if c.countSoftBounce() == 0 {
			return
		}
		time.Sleep(time.Duration(c.resendDelay) * time.Second)
		query, err := models.Db.Prepare("SELECT DISTINCT r.`id`, r.`email`, r.`name` FROM `recipient` as r,`status` as s WHERE r.`campaign_id`=? AND r.`removed`=0 AND s.`bounce_id`=2 AND UPPER(`r`.`status`) LIKE CONCAT(\"%\",s.`pattern`,\"%\")")
		checkErr(err)
		defer query.Close()

		q, err := query.Query(c.id)
		checkErr(err)
		defer q.Close()

		for q.Next() {
			err = q.Scan(&r.id, &r.to_email, &r.to_name)
			checkErr(err)
			if r.unsubscribe(c.id) == false || c.sendUnsubscribe {
				models.Db.Exec("UPDATE recipient SET status='Sending', date=NOW() WHERE id=?", r.id)
				p, i, h := models.ProfileNext(c.profileId)
				rs := r.send(&c, i, h)
				models.ProfileFree(p)
				models.Db.Exec("UPDATE recipient SET status=?, date=NOW() WHERE id=?", rs, r.id)
			} else {
				models.Db.Exec("UPDATE recipient SET status='Unsubscribe', date=NOW() WHERE id=?", r.id)
				camplog.Printf("Recipient id %s email %s is unsubscribed", r.id, r.to_email)
			}
		}
	}
}
Ejemplo n.º 3
0
Archivo: auth.go Proyecto: Supme/gonder
func (a *Auth) Check(fn http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var authorize bool
		user, password, _ := r.BasicAuth()
		a.userId, a.unitId, authorize = check(user, password)
		if !authorize {
			if user != "" {
				ip := models.GetIP(r)
				apilog.Printf("%s bad auth login '%s'", ip, user)
				if models.Config.GonderMail != "" && models.Config.GonderMail != "" {
					go func() {
						_, iface, host := models.ProfileNext(models.Config.DefaultProfile)
						m := mailer.MailData{
							Iface:      iface,
							Host:       host,
							From_email: models.Config.GonderMail,
							To_email:   models.Config.AdminMail,
							Subject:    "Bad login to Gonder",
							Html:       ip + " bad auth login '" + user + "'",
						}
						if err := m.Send(); err != nil {
							apilog.Print("Error send mail:", err)
						}
					}()
				}
			}
			w.Header().Set("WWW-Authenticate", `Basic realm="Gonder"`)
			w.WriteHeader(401)
			return
		}
		a.Name = user
		logging(r)

		fn(w, r)
	}
}