本文整理汇总了Golang中github.com/protosam/vision.New类的典型用法代码示例。如果您正苦于以下问题:Golang New类的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了New类的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()
}
示例2: 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)
}
示例3: 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()
}
示例4: 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)
}
示例5: 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)
}
示例6: databases
func databases(ctx *macaron.Context) string {
_, auth := util.Auth(ctx, "databases")
if !auth {
ctx.Redirect("/", 302)
return ""
}
//hostname := string(ctx.Req.Host)
hostname := string(ctx.Req.Header.Get("X-FORWARDED-HOST"))
if hostname == "" {
hostname = string(ctx.Req.Host)
}
hostname = strings.Split(hostname, ":")[0]
var tpl vision.New
tpl.TemplateFile("template/databases.tpl")
tpl.Assign("phpmyadmin_url", "https://"+hostname+"/phpmyadmin")
tpl.Parse("databases")
// list db users
dbuser_data := API("/api/sql/users/list", ctx)
var users []string
json.Unmarshal([]byte(dbuser_data), &users)
for _, user := range users {
tpl.Assign("db_user", user)
tpl.Parse("databases/user")
}
// end: list db users
// list databases
db_data := API("/api/sql/databases/list", ctx)
var databases []string
json.Unmarshal([]byte(db_data), &databases)
for _, db_name := range databases {
// list grants
grant_data := API("/api/sql/grants/list?db_name="+db_name, ctx)
var grants []string
json.Unmarshal([]byte(grant_data), &grants)
tpl.Assign("db_name", db_name)
tpl.Parse("databases/database")
// grant add dropdown
for _, user := range users {
tpl.Assign("db_user", user)
tpl.Assign("db_name", db_name)
tpl.Parse("databases/database/add_grant")
}
// END: grant add dropdown
for _, gdb_user := range grants {
tpl.Assign("db_user", gdb_user)
tpl.Assign("db_name", db_name)
tpl.Parse("databases/database/grant")
}
// end: list grants
}
// end: list databases
return header(ctx) + tpl.Out() + footer(ctx)
}
示例7: 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)
}
示例8: footer
func footer(ctx *macaron.Context) string {
var tpl vision.New
tpl.TemplateFile("template/overall.tpl")
tpl.Parse("footer")
return tpl.Out()
}
示例9: 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)
}
示例10: 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)
}
示例11: header
func header(ctx *macaron.Context) string {
var tpl vision.New
tpl.TemplateFile("template/overall.tpl")
hcuser, auth := util.Auth(ctx, "any")
if auth {
tpl.Assign("username", hcuser.System_username)
}
hostname := string(ctx.Req.Header.Get("X-FORWARDED-HOST"))
if hostname == "" {
hostname = string(ctx.Req.Host)
}
hostname = strings.Split(hostname, ":")[0]
tpl.Assign("console_url", "https://"+hostname+"/shellinabox")
tpl.Parse("header")
if auth {
if (strings.Contains(hcuser.Privileges, "websites") || strings.Contains(hcuser.Privileges, "all")) && hcuser.System_username != "root" {
tpl.Parse("header/websitesbtn")
}
if strings.Contains(hcuser.Privileges, "databases") || strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("header/databasesbtn")
}
if strings.Contains(hcuser.Privileges, "dns") || strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("header/dnsbtn")
}
if (strings.Contains(hcuser.Privileges, "mail") || strings.Contains(hcuser.Privileges, "all")) && hcuser.System_username != "root" {
tpl.Parse("header/mailbtn")
}
if (strings.Contains(hcuser.Privileges, "ftpusers") || strings.Contains(hcuser.Privileges, "all")) && hcuser.System_username != "root" {
tpl.Parse("header/ftpusersbtn")
}
if strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("header/firewallbtn")
}
if strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("header/servicesbtn")
}
if strings.Contains(hcuser.Privileges, "sysusers") || strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("header/usersbtn")
}
}
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()
}
示例12: dashboard
func dashboard(ctx *macaron.Context) string {
hcuser, auth := util.Auth(ctx, "any")
if !auth {
ctx.Redirect("/", 302)
return ""
}
var tpl vision.New
tpl.TemplateFile("template/dashboard.tpl")
hostname := string(ctx.Req.Header.Get("X-FORWARDED-HOST"))
if hostname == "" {
hostname = string(ctx.Req.Host)
}
hostname = strings.Split(hostname, ":")[0]
tpl.Assign("console_url", "https://"+hostname+"/shellinabox")
tpl.Parse("dashboard")
if (strings.Contains(hcuser.Privileges, "websites") || strings.Contains(hcuser.Privileges, "all")) && hcuser.System_username != "root" {
tpl.Parse("dashboard/websitesbtn")
}
if strings.Contains(hcuser.Privileges, "databases") || strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("dashboard/databasesbtn")
}
if strings.Contains(hcuser.Privileges, "dns") || strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("dashboard/dnsbtn")
}
if (strings.Contains(hcuser.Privileges, "mail") || strings.Contains(hcuser.Privileges, "all")) && hcuser.System_username != "root" {
tpl.Parse("dashboard/mailbtn")
}
if (strings.Contains(hcuser.Privileges, "ftpusers") || strings.Contains(hcuser.Privileges, "all")) && hcuser.System_username != "root" {
tpl.Parse("dashboard/ftpusersbtn")
}
if strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("dashboard/firewallbtn")
}
if strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("dashboard/servicesbtn")
}
if strings.Contains(hcuser.Privileges, "sysusers") || strings.Contains(hcuser.Privileges, "all") {
tpl.Parse("dashboard/usersbtn")
}
return header(ctx) + tpl.Out() + footer(ctx)
}
示例13: login_post
func login_post(ctx *macaron.Context) string {
db, err := util.MySQL()
defer db.Close()
if err != nil {
return "Problem opening MySQL"
}
new_token := util.MkToken()
username := util.Query(ctx, "username")
password := util.Query(ctx, "password")
rememberme := util.Query(ctx, "rememberme")
login_failed := false
if chklogin(username, password) {
stmt, _ := db.Prepare("SELECT * from hostcontrol_users WHERE system_username = ?")
rows, _ := stmt.Query(username)
stmt.Close()
var hostcontrol_id int
var system_username string
var privileges string
var owned_by string
var login_token string
var email_address string
// check if we have a row returned...
if rows.Next() {
rows.Scan(&hostcontrol_id, &system_username, &privileges, &owned_by, &login_token, &email_address)
ustmt, _ := db.Prepare("update hostcontrol_users set login_token=? where system_username=?")
ustmt.Exec(new_token, username)
ustmt.Close()
// insert root if login worked and he doesn't exist!
} else if username == "root" {
istmt, _ := db.Prepare("insert hostcontrol_users set hostcontrol_id=null, system_username=?, privileges=?, owned_by=?, login_token=?, email_address=?")
istmt.Exec("root", "all", "root", new_token, "")
istmt.Close()
// fallback to failure.
} else {
login_failed = true
}
if !login_failed {
// set cookies
if rememberme == "checked" {
ctx.SetCookie("hostcontrol_id", strconv.Itoa(hostcontrol_id), 864000)
ctx.SetCookie("login_token", new_token, 864000)
ctx.SetCookie("sudo", "", 864000)
} else {
ctx.SetCookie("hostcontrol_id", strconv.Itoa(hostcontrol_id), 0)
ctx.SetCookie("login_token", new_token, 0)
ctx.SetCookie("sudo", "", 0)
}
// send to dashboard
ctx.Redirect("/dashboard", 302)
return "Redirecting to the dashboard. Click <a href=\"/dashboard\">here</a> if you are not redirected."
}
} else {
login_failed = true
}
var tpl vision.New
tpl.TemplateFile("template/login.tpl")
tpl.Parse("login")
if login_failed {
tpl.Parse("login/fail")
}
return tpl.Out()
}
示例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)
}
示例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())
}