sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0

add webaccess and mailforward

This commit is contained in:
Martin Geno 2016-11-15 20:50:57 +01:00
parent 1c07e35024
commit 3d88bbfacd
6 changed files with 87 additions and 44 deletions

View File

@ -4,4 +4,17 @@
``` ```
ALTER TABLE login ALTER createat TYPE timestamptz; ALTER TABLE login ALTER createat TYPE timestamptz;
ALTER TABLE login ALTER lastloginat TYPE timestamptz; ALTER TABLE login ALTER lastloginat TYPE timestamptz;
BEGIN;
insert into host_web_webaccess (web,login) (select id,unnest(httpaccess) from host_web);
ALTER TABLE host_web DROP httpaccess;
insert into host_web_ftpaccess (web,login) (select id,unnest(ftp) from host_web);
ALTER TABLE host_web DROP ftp;
insert into host_mail_forward (mail,"to") (select id,unnest(forward) from host_mail);
ALTER TABLE host_mail DROP forward;
COMMIT;
``` ```

View File

@ -24,9 +24,9 @@ func getMail(ctx context.Context, w http.ResponseWriter) (mail Mail, returnerr *
return return
} }
if login.Superadmin { if login.Superadmin {
dbconnection.Where("id = ?", id).Find(&mail) dbconnection.Where("id = ?", id).Preload("Forwards").Find(&mail)
} else { } else {
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Find(&mail) dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("Forwards").Find(&mail)
} }
if mail.ID <= 0 { if mail.ID <= 0 {
returnerr = &libapi.ErrorResult{Fields: []string{"mail"}, Message: "not found"} returnerr = &libapi.ErrorResult{Fields: []string{"mail"}, Message: "not found"}
@ -44,7 +44,7 @@ func mailList(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
logger.Info("not found") logger.Info("not found")
return return
} }
dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Find(&mail) dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Preload("Forwards").Find(&mail)
logger.Info("done") logger.Info("done")
returndata = mail returndata = mail
return return
@ -69,7 +69,7 @@ func mailAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (retur
mail := &Mail{ mail := &Mail{
DomainID: domain.ID, DomainID: domain.ID,
Name: mailRequest.Name, Name: mailRequest.Name,
//Forward: mailRequest.Forward, Forwards: mailRequest.Forwards,
LoginID: mailRequest.LoginID, LoginID: mailRequest.LoginID,
} }
@ -105,7 +105,7 @@ func mailEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
} }
mail.Name = mailRequest.Name mail.Name = mailRequest.Name
//mail.Forward = mailRequest.Forward mail.Forwards = mailRequest.Forwards
mail.LoginID = mailRequest.LoginID mail.LoginID = mailRequest.LoginID
if err := dbconnection.Save(mail).Error; err != nil { if err := dbconnection.Save(mail).Error; err != nil {

View File

@ -24,9 +24,9 @@ func getWeb(ctx context.Context, w http.ResponseWriter) (web Web, returnerr *lib
return return
} }
if login.Superadmin { if login.Superadmin {
dbconnection.Where("id = ?", id).Find(&web) dbconnection.Where("id = ?", id).Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web)
} else { } else {
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Find(&web) dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web)
} }
if web.ID <= 0 { if web.ID <= 0 {
returnerr = &libapi.ErrorResult{Fields: []string{"web"}, Message: "not found"} returnerr = &libapi.ErrorResult{Fields: []string{"web"}, Message: "not found"}
@ -44,7 +44,7 @@ func webList(ctx context.Context, w http.ResponseWriter, r *http.Request) (retur
logger.Info("not found") logger.Info("not found")
return return
} }
dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Find(&web) dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web)
logger.Info("done") logger.Info("done")
returndata = web returndata = web
return return
@ -74,8 +74,8 @@ func webAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (return
SSLRedirect: webRequest.SSLRedirect, SSLRedirect: webRequest.SSLRedirect,
Redirect: webRequest.Redirect, Redirect: webRequest.Redirect,
Proxy: webRequest.Proxy, Proxy: webRequest.Proxy,
//FTP: webRequest.FTP, FTPAccess: webRequest.FTPAccess,
//HTTPAccess: webRequest.HTTPAccess, WebAccess: webRequest.WebAccess,
} }
if err := dbconnection.Create(web).Error; err != nil { if err := dbconnection.Create(web).Error; err != nil {
@ -115,8 +115,8 @@ func webEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retur
web.SSLRedirect = webRequest.SSLRedirect web.SSLRedirect = webRequest.SSLRedirect
web.Redirect = webRequest.Redirect web.Redirect = webRequest.Redirect
web.Proxy = webRequest.Proxy web.Proxy = webRequest.Proxy
//web.FTP = webRequest.FTP web.FTPAccess = webRequest.FTPAccess
//web.HTTPAccess = webRequest.HTTPAccess web.WebAccess = webRequest.WebAccess
if err := dbconnection.Save(web).Error; err != nil { if err := dbconnection.Save(web).Error; err != nil {
logger.Error("database: during modify host web: ", err) logger.Error("database: during modify host web: ", err)

View File

@ -1,8 +1,6 @@
package host package host
import ( import (
"database/sql"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"dev.sum7.eu/sum7/warehost/system" "dev.sum7.eu/sum7/warehost/system"
@ -45,26 +43,59 @@ type Web struct {
SSLRedirect bool `sql:"default:false;column:sslredirect" json:"sslredirect"` SSLRedirect bool `sql:"default:false;column:sslredirect" json:"sslredirect"`
Redirect string `sql:"type:varchar(255);column:redirect" json:"redirect"` Redirect string `sql:"type:varchar(255);column:redirect" json:"redirect"`
Proxy string `sql:"type:varchar(255);column:proxy" json:"proxy"` Proxy string `sql:"type:varchar(255);column:proxy" json:"proxy"`
//FTP []int64 `sql:"type:bigint[];column:ftp" json:"ftp"` FTPAccess []*FTPAccess `json:"ftpaccess"`
//HTTPAccess []int64 `sql:"type:bigint[];column:httpaccess" json:"httpaccess"` WebAccess []*WebAccess `json:"webaccess"`
} }
// TableName of struct // TableName of struct
func (Web) TableName() string { return "host_web" } func (Web) TableName() string { return "host_web" }
// FTPAccess is a Object which user has access by ftp on the data of this website
type FTPAccess struct {
WebID int64 `sql:"type:bigint NOT NULL REFERENCES host_web(id) ON UPDATE CASCADE ON DELETE CASCADE;column:web" json:"-"`
Web *Web `gorm:"foreignkey:Web;unique_index:idx_host_domain_ftp_access" json:"web"`
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
Login *system.Login `gorm:"foreignkey:Login;unique_index:idx_host_domain_ftp_access" json:"login"`
}
// TableName of struct
func (FTPAccess) TableName() string { return "host_web_ftpaccess" }
// WebAccess is a Object which user has access by httpaccess on the data of this website
type WebAccess struct {
WebID int64 `sql:"type:bigint NOT NULL REFERENCES host_web(id) ON UPDATE CASCADE ON DELETE CASCADE;column:web" json:"-"`
Web *Web `gorm:"foreignkey:Web;unique_index:idx_host_domain_web_access" json:"web"`
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
Login *system.Login `gorm:"foreignkey:Login;unique_index:idx_host_domain_web_access" json:"login"`
}
// TableName of struct
func (WebAccess) TableName() string { return "host_web_webaccess" }
// Mail struct // Mail struct
type Mail struct { type Mail struct {
ID int64 ID int64
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"` DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"`
Domain *Domain `gorm:"foreignkey:Domain;unique_index:idx_host_domain_mail" json:"domain"` Domain *Domain `gorm:"foreignkey:Domain;unique_index:idx_host_domain_mail" json:"domain"`
Name string `sql:"type:varchar(255);column:name" gorm:"unique_index:idx_host_domain_mail" json:"name"` Name string `sql:"type:varchar(255);column:name" gorm:"unique_index:idx_host_domain_mail" json:"name"`
//Forward []string `sql:"type:varchar(255)[];column:forward" json:"forward"` Forwards []*MailForward `json:"forwards"`
LoginID sql.NullInt64 `sql:"type:bigint NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"` LoginID *int64 `sql:"type:bigint NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
} }
// TableName of struct // TableName of struct
func (Mail) TableName() string { return "host_mail" } func (Mail) TableName() string { return "host_mail" }
// MailForward is a Object on with address a copy of the mail should be send
type MailForward struct {
ID int64
MailID int64 `sql:"type:bigint NOT NULL REFERENCES host_mail(id) ON UPDATE CASCADE ON DELETE CASCADE;column:mail" json:"-"`
Mail *Mail `gorm:"foreignkey:Mail;unique_index:idx_host_domain_mail_forward" json:"mail"`
To string `sql:"type:varchar(255);column:to" gorm:"unique_index:idx_host_domain_mail_forward" json:"to"`
}
// TableName of struct
func (MailForward) TableName() string { return "host_mail_forward" }
// Database struct // Database struct
type Database struct { type Database struct {
ID int64 ID int64
@ -79,5 +110,5 @@ func (Database) TableName() string { return "host_database" }
// SyncModels to verify the database schema // SyncModels to verify the database schema
func SyncModels(dbconnection *gorm.DB) { func SyncModels(dbconnection *gorm.DB) {
dbconnection.AutoMigrate(&Profil{}, &Domain{}, &Web{}, &Mail{}, &Database{}) dbconnection.AutoMigrate(&Profil{}, &Domain{}, &Web{}, &WebAccess{}, &FTPAccess{}, &Mail{}, &MailForward{}, &Database{})
} }

View File

@ -74,7 +74,7 @@ func menuEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
menuEntry.ID = menuid menuEntry.ID = menuid
if err := dbconnection.Save(menuEntry).Error; err != nil { if err := dbconnection.Save(menuEntry).Error; err != nil {
logger.Error("database: during delete website menu entry") logger.Error("database: during edit website menu entry")
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"} returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
return return
} }

View File

@ -1,7 +1,6 @@
package web package web
import ( import (
"database/sql"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
system "dev.sum7.eu/sum7/warehost/system" system "dev.sum7.eu/sum7/warehost/system"
@ -52,7 +51,7 @@ type Menu struct {
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website" json:"-"` WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website" json:"-"`
Name string `gorm:"type:varchar(255);column:name" json:"name"` Name string `gorm:"type:varchar(255);column:name" json:"name"`
Shorturl string `gorm:"type:varchar(255);column:url" json:"url"` Shorturl string `gorm:"type:varchar(255);column:url" json:"url"`
ParentID sql.NullInt64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu" json:"parentid"` ParentID *int64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu" json:"parentid"`
Position int `sql:"type:int;column:position" json:"position"` Position int `sql:"type:int;column:position" json:"position"`
Children []*Menu `json:"children"` Children []*Menu `json:"children"`
} }
@ -86,13 +85,13 @@ func BuildMenuTree(items []*Menu) []*Menu {
menumap[item.ID] = item menumap[item.ID] = item
menumap[item.ID].Children = tmp menumap[item.ID].Children = tmp
} }
if !item.ParentID.Valid { if item.ParentID == nil {
menuexit = append(menuexit, item) menuexit = append(menuexit, item)
} else { } else {
if menumap[item.ParentID.Int64] == nil { if menumap[*item.ParentID] == nil {
menumap[item.ParentID.Int64] = &Menu{ID: -1} menumap[*item.ParentID] = &Menu{ID: -1}
} }
menumap[item.ParentID.Int64].Children = append(menumap[item.ParentID.Int64].Children, item) menumap[*item.ParentID].Children = append(menumap[*item.ParentID].Children, item)
} }
} }
return menuexit return menuexit