Example #1
0
//  /ajax/domain/{domain}/all
func AjaxHandlerDomainAll(resp http.ResponseWriter, req *http.Request) {

	log.Info("DomainAllAjaxHandler")

	vars := mux.Vars(req)
	domain := vars["domain"]

	payload := DomainAllPayload{}
	payload.Success = true

	var err error
	payload.Domain, err = LoadDomain(domain)
	if err != nil {
		log.Info(err.Error())
		payload.Error = "" + err.Error()
	}
	payload.Mailboxes, err = GetMailboxes(domain)
	if err != nil {
		log.Info(err.Error())
		payload.Error = "" + err.Error()
	}
	payload.Aliases, err = GetAliases(domain)
	if err != nil {
		log.Info(err.Error())
		payload.Error = "" + err.Error()
	}

	json_str, _ := json.MarshalIndent(payload, "", "  ")
	fmt.Fprint(resp, string(json_str))
}
Example #2
0
func main() {

	// Default logger
	log.Debug("Debug")
	log.Info("Info")
	log.Notice("Notice")
	log.Warning("Warning")
	log.Error("Error")
	log.Critical("Critical")

	// Custom logger with default handler
	l := log.NewLogger("test")

	l.Debug("Debug")
	l.Info("Info")
	l.Notice("Notice")
	l.Warning("Warning")
	l.Error("Error")
	l.Critical("Critical")

	// Custom logger with custom handler
	l2 := log.NewLogger("test2")
	h := NewMyHandler("!!!")
	h.SetLevel(log.WARNING)
	l2.SetHandler(h)

	l2.Debug("Debug")
	l2.Info("Info")
	l2.Notice("Notice")
	l2.Warning("Warning")
	l2.Error("Error")
	l2.Critical("Critical")
}
Example #3
0
//=  /ajax/domain/{domain}
func AjaxHandlerDomain(resp http.ResponseWriter, req *http.Request) {

	//fmt.Println("DomainAjaxHandler")
	log.Info("DomainAjaxHandler")
	if AjaxAuth(resp, req) == false {
		return
	}
	vars := mux.Vars(req)

	payload := DomainPayload{}
	payload.Success = true

	var err error
	payload.Domain, err = LoadDomain(vars["domain"])
	if err != nil {
		log.Info(err.Error())
		payload.Error = "" + err.Error()
	}

	json_str, _ := json.MarshalIndent(payload, "", "  ")
	fmt.Fprint(resp, string(json_str))
}
Example #4
0
//  /ajax/domain/{domain}/virtual
func AjaxHandlerDomainVirtual(resp http.ResponseWriter, req *http.Request) {

	if AjaxAuth(resp, req) == false {
		return
	}
	log.Info("DomainVirtualAjaxHandler")

	vars := mux.Vars(req)
	domain := vars["domain"]

	payload := DomainVirtualPayload{}
	payload.Success = true

	var err error
	payload.Domain, err = LoadDomain(domain)
	if err != nil {
		log.Info(err.Error())
		payload.Error = err.Error()
	}

	// Get mailboxes with virtual struct
	payload.Mailboxes, err = GetMailboxesVirtual(domain)
	if err != nil {
		log.Info(err.Error())
		payload.Error = err.Error()
	}

	// make mailboxes map with user > MailboxVirt and init mbox
	mailboxes_map := make(map[string]*MailboxVirtual)
	for _, mb := range payload.Mailboxes {
		mb.ForwardFrom = make([]string, 0)
		mb.ForwardTo = make([]string, 0)
		mb.ForwardOnly = true
		mailboxes_map[mb.Username] = mb
	}
	//fmt.Println(mb_map)

	// Load the Vacations
	vacations, errv := GetVacations(domain)
	if errv != nil {
		log.Info(errv.Error())
		payload.Error = err.Error()
	}
	for _, va := range vacations {
		mailboxes_map[va.Email].Vacation = va
	}

	// Get list of aliases and postfix
	// does curious things such as forwarding to same mailbox
	aliases, err_al := GetAliases(domain)
	if err_al != nil {
		log.Info(err_al.Error())
		payload.Error = "" + err_al.Error()
	}
	//aliases_map := make(map[string][]string)

	for _, alias := range aliases {

		mbox, ok := mailboxes_map[alias.Address]
		if ok {
			// Alias is also a mailbox - postfix style
			gotos := SplitEmail(alias.Goto)

			for _, gotto := range gotos {

				// postfix forwards alias to mailbox
				if gotto == mbox.Username {
					mbox.ForwardOnly = false

					// User on vactaion
				} else if IsVacationAddress(gotto) {
					// to nothing

				} else {
					mbox.ForwardTo = append(mbox.ForwardTo, gotto)

				}

				if gotto != mbox.Username {
					targetBox, ok2 := mailboxes_map[gotto]
					if ok2 {
						//fmt.Println("----", alias.Address, gotto, targetBox.Username, aliases_map)

						targetBox.ForwardFrom = append(targetBox.ForwardFrom, mbox.Username)

					}
				}

			}

		} else {
			fmt.Println("========", alias)
			gotos2 := SplitEmail(alias.Goto)
			for _, got2 := range gotos2 {
				targetBox2, ok3 := mailboxes_map[got2]
				if ok3 {
					targetBox2.ForwardFrom = append(targetBox2.ForwardFrom, alias.Address)
				}
			}
			payload.Aliases = append(payload.Aliases, alias)
		}
	}

	json_str, _ := json.MarshalIndent(payload, "", "  ")
	fmt.Fprint(resp, string(json_str))
}