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;
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;
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
func Validate(hash, password string) (output, replace bool) {
parts := strings.Split(hash, "$")
if len(parts) == 3 {
if len(parts) != 4 {
return false, false
}
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.Forwards = mailRequest.Forwards
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 {
logger.Error("database: during modify host mail: ", err)
w.WriteHeader(http.StatusInternalServerError)

View File

@ -24,9 +24,9 @@ func getWeb(ctx context.Context, w http.ResponseWriter) (web Web, returnerr *lib
return
}
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 {
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 {
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")
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")
returndata = web
return
@ -74,8 +74,8 @@ func webAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (return
SSLRedirect: webRequest.SSLRedirect,
Redirect: webRequest.Redirect,
Proxy: webRequest.Proxy,
FTPAccess: webRequest.FTPAccess,
WebAccess: webRequest.WebAccess,
//FTPAccess: webRequest.FTPAccess,
//HTTPAccess: webRequest.HTTPAccess,
}
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.Redirect = webRequest.Redirect
web.Proxy = webRequest.Proxy
web.FTPAccess = webRequest.FTPAccess
web.WebAccess = webRequest.WebAccess
//web.FTPAccess = webRequest.FTPAccess
//web.HTTPAccess = webRequest.HTTPAccess
if err := dbconnection.Save(web).Error; err != nil {
logger.Error("database: during modify host web: ", err)

View File

@ -35,16 +35,16 @@ func (Domain) TableName() string { return "host_domain" }
// Web struct
type Web struct {
ID int64
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_web" json:"domain"`
Subdomain string `sql:"type:varchar(255);column:subdomain" gorm:"unique_index:idx_host_domain_web" json:"subdomain"`
PHP bool `sql:"default:false;column:php" json:"php"`
SSL bool `sql:"default:true;column:ssl" json:"ssl"`
SSLRedirect bool `sql:"default:false;column:sslredirect" json:"sslredirect"`
Redirect string `sql:"type:varchar(255);column:redirect" json:"redirect"`
Proxy string `sql:"type:varchar(255);column:proxy" json:"proxy"`
FTPAccess []*FTPAccess `json:"ftpaccess"`
WebAccess []*WebAccess `json:"webaccess"`
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_web" json:"domain"`
Subdomain string `sql:"type:varchar(255);column:subdomain" gorm:"unique_index:idx_host_domain_web" json:"subdomain"`
PHP bool `sql:"default:false;column:php" json:"php"`
SSL bool `sql:"default:true;column:ssl" json:"ssl"`
SSLRedirect bool `sql:"default:false;column:sslredirect" json:"sslredirect"`
Redirect string `sql:"type:varchar(255);column:redirect" json:"redirect"`
Proxy string `sql:"type:varchar(255);column:proxy" json:"proxy"`
FTPAccess []*FTPAccess `json:"ftpaccess"`
HTTPAccess []*HTTPAccess `json:"httpaccess"`
}
// TableName of struct
@ -61,8 +61,8 @@ type FTPAccess struct {
// 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 {
// HTTPAccess is a Object which user has access by httpaccess on the data of this website
type HTTPAccess 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:"-"`
@ -70,7 +70,7 @@ type WebAccess struct {
}
// TableName of struct
func (WebAccess) TableName() string { return "host_web_webaccess" }
func (HTTPAccess) TableName() string { return "host_web_httpaccess" }
// Mail struct
type Mail struct {
@ -110,5 +110,5 @@ func (Database) TableName() string { return "host_database" }
// SyncModels to verify the database schema
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{})
}