当前位置: 首页>>代码示例>>Golang>>正文


Golang New.Parse方法代码示例

本文整理汇总了Golang中github.com/protosam/vision.New.Parse方法的典型用法代码示例。如果您正苦于以下问题:Golang New.Parse方法的具体用法?Golang New.Parse怎么用?Golang New.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/protosam/vision.New的用法示例。


在下文中一共展示了New.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: logout

func logout(ctx *macaron.Context) string {
	var tpl vision.New
	tpl.TemplateFile("template/login.tpl")

	user, auth := util.Auth(ctx, "any")

	if user.Sudo {
		ctx.SetCookie("sudo", "", -1)
		set_error("No longer logged in as "+user.System_username+".", ctx)
		ctx.Redirect("/dashboard", 302)
		return "success"
	}

	if auth {
		new_token := util.MkToken()
		db, _ := util.MySQL()
		defer db.Close()

		ustmt, _ := db.Prepare("update hostcontrol_users set login_token=? where system_username=?")
		ustmt.Exec(new_token, user.System_username)
		ustmt.Close()
	}

	ctx.SetCookie("hostcontrol_id", "", -1)
	ctx.SetCookie("login_token", "", -1)

	tpl.Parse("login")
	tpl.Parse("login/logged_out")
	return tpl.Out()

}
开发者ID:kpetku,项目名称:hostcontrol,代码行数:31,代码来源:web.login.go

示例2: websites

func websites(ctx *macaron.Context) string {
	_, auth := util.Auth(ctx, "websites")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/websites.tpl")
	tpl.Parse("websites")

	websites := API("/api/web/domain/list", ctx)

	domains := make(map[string]map[string]string)
	json.Unmarshal([]byte(websites), &domains)

	for _, domain := range domains {
		tpl.Assign("vhost_id", domain["vhost_id"])
		tpl.Assign("system_username", domain["system_username"])
		tpl.Assign("domain", domain["domain"])
		tpl.Assign("documentroot", domain["documentroot"])
		tpl.Assign("ipaddr", domain["ipaddr"])
		tpl.Assign("ssl_enabled", domain["ssl_enabled"])

		determin_fm_page := strings.Split(domain["documentroot"], "www")
		filemanager_path := "www" + determin_fm_page[1]

		tpl.Assign("filemanager_path", filemanager_path)
		tpl.Parse("websites/domain")
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:33,代码来源:web.websites.go

示例3: ftpusers

func ftpusers(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "ftpusers")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/ftpusers.tpl")

	tpl.Assign("homedir", hcuser.HomeDir)
	tpl.Parse("ftpusers")

	userdata := API("/api/ftpusers/list", ctx)

	users := make(map[string]map[string]string)
	json.Unmarshal([]byte(userdata), &users)

	for _, user := range users {
		tpl.Assign("username", user["username"])
		tpl.Assign("homedir", user["homedir"])

		tpl.Parse("ftpusers/user")
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:27,代码来源:web.ftpusers.go

示例4: login

func login(ctx *macaron.Context) string {
	var tpl vision.New
	tpl.TemplateFile("template/login.tpl")
	tpl.Assign("x", "y")
	tpl.Parse("login")
	return tpl.Out()

}
开发者ID:kpetku,项目名称:hostcontrol,代码行数:8,代码来源:web.login.go

示例5: die

func die(ctx *macaron.Context, msg string) string {
	var tpl vision.New
	tpl.TemplateFile("template/error.tpl")
	tpl.Assign("message", msg)
	tpl.Parse("error")
	return header(ctx) + tpl.Out() + footer(ctx)

}
开发者ID:kpetku,项目名称:hostcontrol,代码行数:8,代码来源:core.common.go

示例6: dashboard

func dashboard(ctx *macaron.Context) string {
	//hcuser, auth := util.Auth(ctx, "any")
	_, auth := util.Auth(ctx, "any")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/dashboard.tpl")

	tpl.Parse("dashboard")

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:15,代码来源:web.login.go

示例7: file_editor

func file_editor(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "any")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	suser, err := user.Lookup(hcuser.System_username)

	if err != nil {
		return die(ctx, string(err.Error()))
	}

	selected_object := path.Clean(util.Query(ctx, "path"))
	full_object := path.Clean(suser.HomeDir + "/" + selected_object)

	// check ownership...
	uid, _ := strconv.Atoi(suser.Uid)
	gid, _ := strconv.Atoi(suser.Gid)
	if !util.ChkPerms(full_object, uid, gid) {
		return die(ctx, "You do not have access to object "+full_object)
	}

	filecontents := util.Query(ctx, "filecontents")
	if filecontents != "" {
		filecontents = strings.Replace(filecontents, "\r\n", "\n", -1)
		ioutil.WriteFile(full_object, []byte(filecontents), 0644)
	}

	rawcontents, err := ioutil.ReadFile(full_object)
	if err != nil {
		return die(ctx, string(err.Error()))
	}

	content := html.EscapeString(string(rawcontents))

	var tpl vision.New
	tpl.TemplateFile("template/file-editor.tpl")

	tpl.Assign("path_up", path.Dir(selected_object))
	tpl.Assign("selected_path", selected_object)
	tpl.Assign("current_path", full_object)
	tpl.Assign("filedata", content)

	tpl.Parse("file-editor")

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:48,代码来源:web.filemanager.go

示例8: sslmanager

func sslmanager(ctx *macaron.Context) string {
	_, auth := util.Auth(ctx, "websites")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	vhost_id := util.Query(ctx, "vhost_id")

	var tpl vision.New
	tpl.TemplateFile("template/websites.sslmanager.tpl")

	websites := API("/api/web/domain/list", ctx)

	domains := make(map[string]map[string]string)
	json.Unmarshal([]byte(websites), &domains)

	found := false
	for _, domain := range domains {
		if domain["vhost_id"] == vhost_id {
			tpl.Assign("vhost_id", domain["vhost_id"])
			tpl.Assign("system_username", domain["system_username"])
			tpl.Assign("domain", domain["domain"])
			tpl.Assign("documentroot", domain["documentroot"])
			tpl.Assign("ipaddr", domain["ipaddr"])
			tpl.Assign("ssl_certificate", domain["ssl_certificate"])
			tpl.Assign("ssl_key", domain["ssl_key"])
			tpl.Assign("ssl_ca_certificate", domain["ssl_ca_certificate"])

			if domain["ssl_enabled"] == "Y" {
				tpl.Assign("ssl_enabled", "checked")
			} else {
				tpl.Assign("ssl_enabled", "")
			}
			found = true
		}
	}

	if !found {
		set_error("Failed to find requested domain.", ctx)
		ctx.Redirect("/websites", 302)
		return ""
	}
	tpl.Parse("sslmanager")

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:47,代码来源:web.websites.go

示例9: header

func header(ctx *macaron.Context) string {
	var tpl vision.New
	tpl.TemplateFile("template/overall.tpl")

	user, auth := util.Auth(ctx, "any")
	if auth {
		tpl.Assign("username", user.System_username)
	}

	tpl.Parse("header")

	err_str := ctx.GetCookie("err_str")
	if err_str != "" {
		tpl.Assign("message", err_str)
		tpl.Parse("header/error")
		ctx.SetCookie("err_str", "")
	}

	info_str := ctx.GetCookie("info_str")
	if info_str != "" {
		tpl.Assign("message", info_str)
		tpl.Parse("header/info")
		ctx.SetCookie("info_str", "")
	}

	return tpl.Out()
}
开发者ID:kpetku,项目名称:hostcontrol,代码行数:27,代码来源:core.common.go

示例10: settings

func settings(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "any")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/settings.tpl")
	tpl.Assign("username", hcuser.System_username)
	tpl.Parse("settings")

	db, _ := util.MySQL()
	defer db.Close()

	// tokens
	stmt, _ := db.Prepare("select * from hostcontrol_user_tokens where hostcontrol_id=?")
	rows, _ := stmt.Query(hcuser.Hostcontrol_id)
	stmt.Close()

	for rows.Next() {
		var token string
		var hostcontrol_id string
		var description string
		var token_id string

		rows.Scan(&token, &hostcontrol_id, &description, &token_id)

		tpl.Assign("raw_token", token)
		tpl.Assign("token", hostcontrol_id+"/"+token)
		tpl.Assign("description", description)

		tpl.Parse("settings/token")
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:37,代码来源:web.settings.go

示例11: mail

func mail(ctx *macaron.Context) string {
	_, auth := util.Auth(ctx, "mail")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/mail.tpl")

	hostname := string(ctx.Req.Header.Get("X-FORWARDED-HOST"))
	if hostname == "" {
		hostname = string(ctx.Req.Host)
	}
	hostname = strings.Split(hostname, ":")[0]

	tpl.Assign("webmail_url", "https://"+hostname+"/roundcubemail")

	tpl.Parse("mail")

	// list domains and records
	dns_data := API("/api/mail/list", ctx)

	// map[domain]map[record_id]map[key]value
	data := make(map[string]map[string]map[string]string)
	json.Unmarshal([]byte(dns_data), &data)

	for domain, email_accounts := range data {
		tpl.Assign("domain_name", domain)
		tpl.Parse("mail/domain")

		for key, email := range email_accounts {
			if key == "placebo" {
				continue
			}
			tpl.Assign("email", email["email"])
			tpl.Assign("email_id", email["email_id"])
			tpl.Parse("mail/domain/email")
		}
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:43,代码来源:web.mail.go

示例12: dns

func dns(ctx *macaron.Context) string {
	_, auth := util.Auth(ctx, "dns")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/dns.tpl")
	tpl.Parse("dns")

	// list domains and records
	dns_data := API("/api/dns/list", ctx)

	// map[domain]map[record_id]map[key]value
	data := make(map[string]map[string]map[string]string)
	json.Unmarshal([]byte(dns_data), &data)

	for domain, records := range data {
		tpl.Assign("domain_name", domain)
		tpl.Parse("dns/domain")

		for key, record := range records {
			if key == "placebo" {
				continue
			}
			tpl.Assign("record_change_date", record["record_change_date"])
			tpl.Assign("record_content", record["record_content"])
			tpl.Assign("record_disabled", record["record_disabled"])
			tpl.Assign("record_domain_id", record["record_domain_id"])
			tpl.Assign("record_id", record["record_id"])
			tpl.Assign("record_name", record["record_name"])
			tpl.Assign("record_ordername", record["record_ordername"])
			tpl.Assign("record_prio", record["record_prio"])
			tpl.Assign("record_ttl", record["record_ttl"])
			tpl.Assign("record_type", record["record_type"])
			tpl.Parse("dns/domain/record")
		}
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:42,代码来源:web.dns.go

示例13: filemanager

func filemanager(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "any")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/filemanager.tpl")

	suser, err := user.Lookup(hcuser.System_username)

	if err != nil {
		return die(ctx, string(err.Error()))
	}

	uid, err := strconv.Atoi(suser.Uid)
	if err != nil {
		return die(ctx, string(err.Error()))
	}

	gid, err := strconv.Atoi(suser.Gid)
	if err != nil {
		return die(ctx, string(err.Error()))
	}

	selected_object := path.Clean(util.Query(ctx, "path"))

	full_object := path.Clean(suser.HomeDir + "/" + selected_object)

	// check ownership...
	if !util.ChkPerms(full_object, uid, gid) {
		return die(ctx, "You do not have access to object "+full_object)
	}

	delete_objectin := util.Query(ctx, "delete")
	delete_object := path.Clean(util.Query(ctx, "delete"))
	delete_object = path.Clean(suser.HomeDir + "/" + delete_object)

	if delete_objectin != "" {
		os.RemoveAll(delete_object)
	}

	newdirin := util.Query(ctx, "dirname")
	newdir := path.Clean(util.Query(ctx, "dirname"))
	newdir = path.Clean(full_object + "/" + newdir)

	newfilein := util.Query(ctx, "filename")
	newfile := path.Clean(util.Query(ctx, "filename"))
	newfile = path.Clean(full_object + "/" + newfile)

	if newdirin != "" {
		os.Mkdir(newdir, 0755)
		os.Chown(newdir, uid, gid)
	}

	if newfilein != "" {
		f, _ := os.Create(newfile)
		f.Close()
		os.Chown(newfile, uid, gid)
		os.Chmod(newfile, 0644)
	}

	tpl.GAssign("path_up", path.Dir(selected_object))
	tpl.GAssign("current_path", full_object)
	tpl.GAssign("selected_path", selected_object)

	objects, err := ioutil.ReadDir(full_object)

	if err != nil {
		return die(ctx, string(err.Error()))
	}

	tpl.Parse("filemanager")

	for _, file := range objects {
		tpl.Assign("filename", file.Name())

		mode := string(fmt.Sprintf("%s", file.Mode()))
		tpl.Assign("mode", mode)
		if file.IsDir() {
			tpl.Parse("filemanager/directory")
		} else {
			tpl.Parse("filemanager/file")
		}
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:89,代码来源:web.filemanager.go

示例14: users

func users(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "sysusers")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

	var tpl vision.New
	tpl.TemplateFile("template/users.tpl")
	tpl.Parse("users")

	if strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_all")
	}
	if strings.Contains(hcuser.Privileges, "websites") || strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_websites")
	}
	if strings.Contains(hcuser.Privileges, "mail") || strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_mail")
	}
	if strings.Contains(hcuser.Privileges, "databases") || strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_databases")
	}
	if strings.Contains(hcuser.Privileges, "ftpusers") || strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_ftpusers")
	}
	if strings.Contains(hcuser.Privileges, "dns") || strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_dns")
	}
	if strings.Contains(hcuser.Privileges, "sysusers") || strings.Contains(hcuser.Privileges, "all") {
		tpl.Parse("users/perms_sysusers")
	}

	userdata := API("/api/users/list", ctx)

	users := make(map[string]map[string]string)
	json.Unmarshal([]byte(userdata), &users)

	for _, user := range users {
		tpl.Assign("hostcontrol_id", user["hostcontrol_id"])
		tpl.Assign("system_username", user["system_username"])
		tpl.Assign("privileges", user["privileges"])
		tpl.Assign("owned_by", user["owned_by"])
		tpl.Assign("login_token", user["login_token"])
		tpl.Assign("email_address", user["email_address"])

		tpl.Parse("users/user")
	}

	return header(ctx) + tpl.Out() + footer(ctx)
}
开发者ID:protosam,项目名称:hostcontrol,代码行数:51,代码来源:web.users.go

示例15: main

func main() {

	var tpl vision.New
	tpl.TemplateFile("tpl/hello.tpl")

	tpl.Assign("testvar", "Foobar")

	tpl.Parse("main")
	tpl.Parse("main/row")
	tpl.Parse("main/row")
	tpl.Parse("main/row")

	tpl.Assign("foovar", "Hello World")
	tpl.Parse("main/vrow")
	tpl.Assign("foovar", "Hello Dog")
	tpl.Parse("main/vrow")
	tpl.Assign("foovar", "Hello Cat")
	tpl.Parse("main/vrow")

	fmt.Println(tpl.Out())
}
开发者ID:protosam,项目名称:vision,代码行数:21,代码来源:example.go


注:本文中的github.com/protosam/vision.New.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。