sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0

fix error on empty password + mail api forward

This commit is contained in:
Martin Geno 2016-11-17 23:15:30 +01:00
parent 3d88bbfacd
commit f10964d27a
5 changed files with 47 additions and 24 deletions

View File

@ -7,7 +7,7 @@ ALTER TABLE login ALTER lastloginat TYPE timestamptz;
BEGIN; BEGIN;
insert into host_web_webaccess (web,login) (select id,unnest(httpaccess) from host_web); insert into host_web_httpaccess (web,login) (select id,unnest(httpaccess) from host_web);
ALTER TABLE host_web DROP httpaccess; ALTER TABLE host_web DROP httpaccess;
insert into host_web_ftpaccess (web,login) (select id,unnest(ftp) from host_web); insert into host_web_ftpaccess (web,login) (select id,unnest(ftp) from host_web);

View File

@ -27,7 +27,7 @@ var hashlib = map[string]func() hash.Hash{
// Validate a password and a hash // Validate a password and a hash
func Validate(hash, password string) (output, replace bool) { func Validate(hash, password string) (output, replace bool) {
parts := strings.Split(hash, "$") parts := strings.Split(hash, "$")
if len(parts) == 3 { if len(parts) != 4 {
return false, false return false, false
} }
curIter, err := strconv.Atoi(parts[1]) curIter, err := strconv.Atoi(parts[1])

View File

@ -105,9 +105,32 @@ func mailEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
} }
mail.Name = mailRequest.Name mail.Name = mailRequest.Name
mail.Forwards = mailRequest.Forwards
mail.LoginID = mailRequest.LoginID mail.LoginID = mailRequest.LoginID
idsStay := map[int64]struct{}{}
idsStay[0] = struct{}{}
for _, item := range mailRequest.Forwards {
if item.ID == 0 {
mail.Forwards = append(mail.Forwards, item)
} else {
idsStay[item.ID] = struct{}{}
}
}
idsDel := []int64{}
for _, item := range mail.Forwards {
if _, ok := idsStay[item.ID]; !ok {
idsDel = append(idsDel, item.ID)
}
}
if err := dbconnection.Unscoped().Delete(MailForward{}, "id in (?)", idsDel).Error; err != nil {
logger.Error("database: during delete host mail forwards: ", err)
w.WriteHeader(http.StatusInternalServerError)
returnerr = &libapi.ErrorResult{Message: "Internal Database Error with Database"}
return
}
if err := dbconnection.Save(mail).Error; err != nil { if err := dbconnection.Save(mail).Error; err != nil {
logger.Error("database: during modify host mail: ", err) logger.Error("database: during modify host mail: ", err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)

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).Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web) dbconnection.Where("id = ?", id).Preload("HTTPAccess.Login").Preload("FTPAccess.Login").Find(&web)
} else { } else {
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web) dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("HTTPAccess.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").Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web) dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Preload("HTTPAccess.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,
FTPAccess: webRequest.FTPAccess, //FTPAccess: webRequest.FTPAccess,
WebAccess: webRequest.WebAccess, //HTTPAccess: webRequest.HTTPAccess,
} }
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.FTPAccess = webRequest.FTPAccess //web.FTPAccess = webRequest.FTPAccess
web.WebAccess = webRequest.WebAccess //web.HTTPAccess = webRequest.HTTPAccess
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

@ -44,7 +44,7 @@ type Web struct {
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"`
FTPAccess []*FTPAccess `json:"ftpaccess"` FTPAccess []*FTPAccess `json:"ftpaccess"`
WebAccess []*WebAccess `json:"webaccess"` HTTPAccess []*HTTPAccess `json:"httpaccess"`
} }
// TableName of struct // TableName of struct
@ -61,8 +61,8 @@ type FTPAccess struct {
// TableName of struct // TableName of struct
func (FTPAccess) TableName() string { return "host_web_ftpaccess" } func (FTPAccess) TableName() string { return "host_web_ftpaccess" }
// WebAccess is a Object which user has access by httpaccess on the data of this website // HTTPAccess is a Object which user has access by httpaccess on the data of this website
type WebAccess struct { type HTTPAccess struct {
WebID int64 `sql:"type:bigint NOT NULL REFERENCES host_web(id) ON UPDATE CASCADE ON DELETE CASCADE;column:web" json:"-"` 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"` 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:"-"` LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
@ -70,7 +70,7 @@ type WebAccess struct {
} }
// TableName of struct // TableName of struct
func (WebAccess) TableName() string { return "host_web_webaccess" } func (HTTPAccess) TableName() string { return "host_web_httpaccess" }
// Mail struct // Mail struct
type Mail struct { type Mail struct {
@ -110,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{}, &WebAccess{}, &FTPAccess{}, &Mail{}, &MailForward{}, &Database{}) dbconnection.AutoMigrate(&Profil{}, &Domain{}, &Web{}, &HTTPAccess{}, &FTPAccess{}, &Mail{}, &MailForward{}, &Database{})
} }