Esempio n. 1
0
// SendIssueMentionMail sends mail notification for who are mentioned in issue.
func SendIssueMentionMail(r macaron.Render, u, owner *models.User,
	repo *models.Repository, issue *models.Issue, tos []string) error {

	if len(tos) == 0 {
		return nil
	}

	subject := fmt.Sprintf("[%s] %s (#%d)", repo.Name, issue.Name, issue.Index)

	data := ComposeTplData(nil)
	data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index)
	data["Subject"] = subject
	data["ActUserName"] = u.DisplayName()
	data["Content"] = string(base.RenderSpecialLink([]byte(issue.Content), owner.Name+"/"+repo.Name))

	body, err := r.HTMLString(string(NOTIFY_MENTION), data)
	if err != nil {
		return fmt.Errorf("HTMLString: %v", err)
	}

	msg := NewMessage(tos, subject, body)
	msg.Info = fmt.Sprintf("Subject: %s, issue mention", subject)

	SendAsync(msg)
	return nil
}
Esempio n. 2
0
func Host(r macaron.Render) {
	var ss = map[string]*sheep.SHEEP{}
	for i, s := range sheep.SHEEPS {
		ss[i] = s.Obj()
	}
	a := PARAHOST{Sheeps: ss, MapStatus: sheep.MAPSTATUS}
	r.HTML(200, "host", a)
}
Esempio n. 3
0
func Dashboard(r macaron.Render) {
	var ss = map[string]*sheep.SHEEP{}
	for i, s := range sheep.SHEEPS {
		ss[i] = s.Obj()
	}
	a := PARADASHBOARD{Sheeps: ss, Requset: REQ / 3}
	r.HTML(200, "dashboard", a)
}
Esempio n. 4
0
//Escape the last failed job
func WI_FailEscape(r macaron.Render, req *http.Request) {
	req.ParseForm()
	var success bool = false
	var message string = ""
	shpid := req.Form.Get("sheepid")
	sheepobj, ok := sheep.SHEEPS[shpid]
	if !ok {
		message = "sheepid is unavaliable."
		r.JSON(200, map[string]interface{}{"success": success, "message": message})
		return
	} else {
		success = true
	}
	sheepobj.SetLastFail(nil)
	r.JSON(200, map[string]interface{}{"success": success, "message": message})
}
Esempio n. 5
0
//Monitor length of job queue stack
func WI_JobQueueLen(r macaron.Render, req *http.Request) {
	req.ParseForm()
	var success bool = false
	var message interface{}
	shpid := req.Form.Get("sheepid")
	sheepobj, ok := sheep.SHEEPS[shpid]
	if !ok {
		message = "sheepid is unavaliable."
		r.JSON(200, map[string]interface{}{"success": success, "message": message})
		return
	} else {
		success = true
	}
	message = sheepobj.JobLen()
	r.JSON(200, map[string]interface{}{"success": success, "message": message})
}
Esempio n. 6
0
// Send user register mail with active code
func SendRegisterMail(r macaron.Render, u *models.User) {
	code := CreateUserActiveCode(u, nil)
	subject := "Register success, Welcome"

	data := GetMailTmplData(u)
	data["Code"] = code
	body, err := r.HTMLString(string(AUTH_REGISTER_SUCCESS), data)
	if err != nil {
		log.Error(4, "mail.SendRegisterMail(fail to render): %v", err)
		return
	}

	msg := NewMailMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, send register mail", u.Id)

	SendAsync(&msg)
}
Esempio n. 7
0
//sheeps` status
func WI_SheepStatus(r macaron.Render, req *http.Request) {
	var success bool = true
	var message interface{}
	var data []SHEEPSTATUS
	var tmp SHEEPSTATUS
	for shpid, sheepobj := range sheep.SHEEPS {
		rs := sheepobj.RuningStatus()
		tmp.ID = shpid
		tmp.ENABLE = rs["ENABLE"].(bool)
		tmp.STATUS = rs["STATUS"].(int)
		tmp.JOBQLEN = rs["JOBQLEN"].(int)
		tmp.FOQLEN = rs["FOQLEN"].(int)
		tmp.CAPACITY = rs["CAPACITY"].(int)
		data = append(data, tmp)
	}
	r.JSON(200, map[string]interface{}{"success": success, "message": message, "data": data})
}
Esempio n. 8
0
// Send email verify active email.
func SendActiveMail(r macaron.Render, u *models.User) {
	code := CreateUserActiveCode(u, nil)

	subject := "Verify your e-mail address"

	data := GetMailTmplData(u)
	data["Code"] = code
	body, err := r.HTMLString(string(AUTH_ACTIVE), data)
	if err != nil {
		log.Error(4, "mail.SendActiveMail(fail to render): %v", err)
		return
	}

	msg := NewMailMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, send active mail", u.Id)

	SendAsync(&msg)
}
Esempio n. 9
0
// Send reset password email.
func SendResetPasswdMail(r macaron.Render, u *models.User) {
	code := CreateUserActiveCode(u, nil)

	subject := "Reset your password"

	data := GetMailTmplData(u)
	data["Code"] = code
	body, err := r.HTMLString(string(AUTH_RESET_PASSWORD), data)
	if err != nil {
		log.Error(4, "mail.SendResetPasswdMail(fail to render): %v", err)
		return
	}

	msg := NewMailMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, send reset password email", u.Id)

	SendAsync(&msg)
}
Esempio n. 10
0
// SendCollaboratorMail sends mail notification to new collaborator.
func SendCollaboratorMail(r macaron.Render, u, doer *models.User, repo *models.Repository) error {
	subject := fmt.Sprintf("%s added you to %s/%s", doer.Name, repo.Owner.Name, repo.Name)

	data := ComposeTplData(nil)
	data["RepoLink"] = path.Join(repo.Owner.Name, repo.Name)
	data["Subject"] = subject

	body, err := r.HTMLString(string(NOTIFY_COLLABORATOR), data)
	if err != nil {
		return fmt.Errorf("HTMLString: %v", err)
	}

	msg := NewMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.Id)

	SendAsync(msg)
	return nil
}
Esempio n. 11
0
// Send email to verify secondary email.
func SendActivateEmail(r macaron.Render, user *models.User, email *models.EmailAddress) {
	code := CreateUserEmailActivateCode(user, email, nil)

	subject := "Verify your e-mail address"

	data := GetMailTmplData(user)
	data["Code"] = code
	data["Email"] = email.Email
	body, err := r.HTMLString(string(AUTH_ACTIVATE_EMAIL), data)
	if err != nil {
		log.Error(4, "mail.SendActiveMail(fail to render): %v", err)
		return
	}

	msg := NewMailMessage([]string{email.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, send activate email to %s", user.Id, email.Email)

	SendAsync(&msg)
}
Esempio n. 12
0
//Assign jobs
func WI_JobAssign(r macaron.Render, req *http.Request) {
	REQ += 1
	req.ParseForm()
	var success bool = false
	var message interface{}
	var isbypass bool = false
	bypass := req.Form.Get("bypass")
	key := req.Form.Get("key")
	if bypass == "1" { // check if bypass mode is
		isbypass = true
	}
	isOk, message := sheep.Assign(req.Form.Get("info"), key, isbypass)
	success = isOk
	message_e, isError := message.(error)
	if isError {
		message = message_e.Error()
	}
	r.JSON(200, map[string]interface{}{"success": success, "message": message})
}
Esempio n. 13
0
// SendCollaboratorMail sends mail notification to new collaborator.
func SendCollaboratorMail(r macaron.Render, u, owner *models.User,
	repo *models.Repository) error {

	subject := fmt.Sprintf("%s added you to %s", owner.Name, repo.Name)

	data := GetMailTmplData(nil)
	data["RepoLink"] = path.Join(owner.Name, repo.Name)
	data["Subject"] = subject

	body, err := r.HTMLString(string(NOTIFY_COLLABORATOR), data)
	if err != nil {
		return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err)
	}

	msg := NewMailMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, send register mail", u.Id)

	SendAsync(&msg)
	return nil
}
Esempio n. 14
0
// SendIssueMentionMail sends mail notification for who are mentioned in issue.
func SendIssueMentionMail(r macaron.Render, u, owner *models.User,
	repo *models.Repository, issue *models.Issue, tos []string) error {

	if len(tos) == 0 {
		return nil
	}

	subject := fmt.Sprintf("[%s] %s (#%d)", repo.Name, issue.Name, issue.Index)

	data := GetMailTmplData(nil)
	data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index)
	data["Subject"] = subject

	body, err := r.HTMLString(string(NOTIFY_MENTION), data)
	if err != nil {
		return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err)
	}

	msg := NewMailMessageFrom(tos, u.Email, subject, body)
	msg.Info = fmt.Sprintf("Subject: %s, send issue mention emails", subject)
	SendAsync(&msg)
	return nil
}
Esempio n. 15
0
func WI_HostEnable(r macaron.Render, req *http.Request) {
	req.ParseForm()
	var success bool = false
	var message string = ""
	shpid := req.Form.Get("sheepid")
	sheepobj, ok := sheep.SHEEPS[shpid]
	if !ok {
		message = "sheepid is unavaliable."
		r.JSON(200, map[string]interface{}{"success": success, "message": message})
		return
	}
	enable := req.Form.Get("enable")
	switch enable {
	case "0":
		sheepobj.Disable()
		success = true
	case "1":
		sheepobj.Enable()
		success = true
	default:
		message = fmt.Sprintf("enable type '%s'is undefined.", enable)
	}
	r.JSON(200, map[string]interface{}{"success": success, "message": message})
}
Esempio n. 16
0
func renderDoc(render macaron.Render, pdoc *Package, docPath string) error {
	data := make(map[string]interface{})
	data["PkgFullIntro"] = pdoc.Doc

	exports := make([]exportSearchObject, 0, 10)

	var buf bytes.Buffer
	links := make([]*Link, 0, len(pdoc.Types)+len(pdoc.Imports)+len(pdoc.TestImports)+
		len(pdoc.Funcs)+10)
	// Get all types, functions and import packages
	for _, t := range pdoc.Types {
		links = append(links, &Link{
			Name:    t.Name,
			Comment: template.HTMLEscapeString(t.Doc),
		})
		exports = append(exports, exportSearchObject{t.Name})
		// buf.WriteString("'" + t.Name + "',")
	}

	for _, f := range pdoc.Funcs {
		f.Code = template.HTMLEscapeString(f.Code)
		links = append(links, &Link{
			Name:    f.Name,
			Comment: template.HTMLEscapeString(f.Doc),
		})
		exports = append(exports, exportSearchObject{f.Name})
		// buf.WriteString("'" + f.Name + "',")
	}

	for _, t := range pdoc.Types {
		for _, f := range t.Funcs {
			links = append(links, &Link{
				Name:    f.Name,
				Comment: template.HTMLEscapeString(f.Doc),
			})
			exports = append(exports, exportSearchObject{f.Name})
			// buf.WriteString("'" + f.Name + "',")
		}

		for _, m := range t.Methods {
			exports = append(exports, exportSearchObject{t.Name + "." + m.Name})
			// buf.WriteString("'" + t.Name + "_" + m.Name + "',")
		}
	}

	// Ignore C.
	for _, v := range append(pdoc.Imports, pdoc.TestImports...) {
		if v != "C" {
			links = append(links, &Link{
				Name: path.Base(v) + ".",
				Path: v,
			})
		}
	}

	// Set exported objects type-ahead.
	// exportDataSrc := buf.String()
	if len(exports) > 0 {
		pdoc.IsHasExport = true
		data["IsHasExports"] = true
		exportDataSrc, _ := json.Marshal(exports)
		data["ExportDataSrc"] = "<script>var exportDataSrc = " + string(exportDataSrc) + ";</script>"
	}

	pdoc.IsHasConst = len(pdoc.Consts) > 0
	pdoc.IsHasVar = len(pdoc.Vars) > 0
	if len(pdoc.Examples) > 0 {
		pdoc.IsHasExample = true
		data["IsHasExample"] = pdoc.IsHasExample
		data["Examples"] = pdoc.Examples
	}

	// Constants.
	data["IsHasConst"] = pdoc.IsHasConst
	data["Consts"] = pdoc.Consts
	for i, v := range pdoc.Consts {
		if len(v.Doc) > 0 {
			buf.Reset()
			doc.ToHTML(&buf, v.Doc, nil)
			v.Doc = buf.String()
		}
		buf.Reset()
		v.Decl = template.HTMLEscapeString(v.Decl)
		v.Decl = strings.Replace(v.Decl, "&#34;", "\"", -1)
		FormatCode(&buf, &v.Decl, links)
		v.FmtDecl = buf.String()
		pdoc.Consts[i] = v
	}

	// Variables.
	data["IsHasVar"] = pdoc.IsHasVar
	data["Vars"] = pdoc.Vars
	for i, v := range pdoc.Vars {
		if len(v.Doc) > 0 {
			buf.Reset()
			doc.ToHTML(&buf, v.Doc, nil)
			v.Doc = buf.String()
		}
		buf.Reset()
		FormatCode(&buf, &v.Decl, links)
		v.FmtDecl = buf.String()
		pdoc.Vars[i] = v
	}

	// Files.
	if len(pdoc.Files) > 0 {
		pdoc.IsHasFile = true
		data["IsHasFiles"] = pdoc.IsHasFile
		data["Files"] = pdoc.Files

		var query string
		if i := strings.Index(pdoc.Files[0].BrowseUrl, "?"); i > -1 {
			query = pdoc.Files[0].BrowseUrl[i:]
		}

		viewFilePath := path.Dir(pdoc.Files[0].BrowseUrl) + "/" + query
		// GitHub URL change.
		if strings.HasPrefix(viewFilePath, "github.com") {
			viewFilePath = strings.Replace(viewFilePath, "blob/", "tree/", 1)
		}
		data["ViewFilePath"] = viewFilePath
	}

	var err error
	renderFuncs(pdoc)

	data["Funcs"] = pdoc.Funcs
	for i, f := range pdoc.Funcs {
		if len(f.Doc) > 0 {
			buf.Reset()
			doc.ToHTML(&buf, f.Doc, nil)
			f.Doc = buf.String()
		}
		buf.Reset()
		FormatCode(&buf, &f.Decl, links)
		f.FmtDecl = buf.String() + " {"
		if exs := getExamples(pdoc, "", f.Name); len(exs) > 0 {
			f.Examples = exs
		}
		pdoc.Funcs[i] = f
	}

	data["Types"] = pdoc.Types
	for i, t := range pdoc.Types {
		for j, v := range t.Consts {
			if len(v.Doc) > 0 {
				buf.Reset()
				doc.ToHTML(&buf, v.Doc, nil)
				v.Doc = buf.String()
			}
			buf.Reset()
			v.Decl = template.HTMLEscapeString(v.Decl)
			v.Decl = strings.Replace(v.Decl, "&#34;", "\"", -1)
			FormatCode(&buf, &v.Decl, links)
			v.FmtDecl = buf.String()
			t.Consts[j] = v
		}
		for j, v := range t.Vars {
			if len(v.Doc) > 0 {
				buf.Reset()
				doc.ToHTML(&buf, v.Doc, nil)
				v.Doc = buf.String()
			}
			buf.Reset()
			FormatCode(&buf, &v.Decl, links)
			v.FmtDecl = buf.String()
			t.Vars[j] = v
		}

		for j, f := range t.Funcs {
			if len(f.Doc) > 0 {
				buf.Reset()
				doc.ToHTML(&buf, f.Doc, nil)
				f.Doc = buf.String()
			}
			buf.Reset()
			FormatCode(&buf, &f.Decl, links)
			f.FmtDecl = buf.String() + " {"
			if exs := getExamples(pdoc, "", f.Name); len(exs) > 0 {
				f.Examples = exs
			}
			t.Funcs[j] = f
		}
		for j, m := range t.Methods {
			if len(m.Doc) > 0 {
				buf.Reset()
				doc.ToHTML(&buf, m.Doc, nil)
				m.Doc = buf.String()
			}
			buf.Reset()
			FormatCode(&buf, &m.Decl, links)
			m.FmtDecl = buf.String() + " {"
			if exs := getExamples(pdoc, t.Name, m.Name); len(exs) > 0 {
				m.Examples = exs
			}
			t.Methods[j] = m
		}
		if len(t.Doc) > 0 {
			buf.Reset()
			doc.ToHTML(&buf, t.Doc, nil)
			t.Doc = buf.String()
		}
		buf.Reset()
		FormatCode(&buf, &t.Decl, links)
		t.FmtDecl = buf.String()
		if exs := getExamples(pdoc, "", t.Name); len(exs) > 0 {
			t.Examples = exs
		}
		pdoc.Types[i] = t
	}

	// Examples.
	links = append(links, &Link{
		Name: path.Base(pdoc.ImportPath) + ".",
	})

	for _, e := range pdoc.Examples {
		buf.Reset()
		FormatCode(&buf, &e.Code, links)
		e.Code = buf.String()
	}

	data["ProjectPath"] = pdoc.ProjectPath
	data["ImportPath"] = pdoc.ImportPath

	// GitHub redirects non-HTTPS link and Safari loses "#XXX".
	if strings.HasPrefix(pdoc.ProjectPath, "github") {
		data["Secure"] = "s"
	}

	result, err := render.HTMLBytes("docs/tpl", data)
	if err != nil {
		return fmt.Errorf("error rendering HTML: %v", err)
	}

	pdoc.JsNum = SaveDocPage(docPath, result)
	if pdoc.JsNum == -1 {
		return errors.New("Save JS file wasn't successful")
	}
	SavePkgDoc(pdoc.ImportPath, pdoc.Readme)

	data["UtcTime"] = time.Unix(pdoc.Created, 0).UTC()
	// data["TimeSince"] = calTimeSince(time.Unix(pdoc.Created, 0))
	return nil
}
Esempio n. 17
0
func NotFound(r macaron.Render) {
	r.HTML(404, "notfound", nil)
}
Esempio n. 18
0
func Setting(r macaron.Render) {
	url := fmt.Sprintf("%s:%d", cfg.HOST, cfg.PORT)
	a := PARASETTING{Cfg: map[string]interface{}{"Client Port": cfg.DEFAULTCPORT, "Version": cfg.VER, "Url": url, "Heartbeat Period": cfg.PERIOD, "Log path": cfg.LOGPATH, "Retry times": cfg.RETRY, "Algorithm": cfg.ALGORITHM, "Assign Script": cfg.ASSIGNSCRIPT, "Assign Type": cfg.ASSIGNTYPE}}
	r.HTML(200, "setting", a)
}