sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This commit is contained in:
Martin Geno 2016-12-20 00:35:03 +01:00
parent cfbb6a619f
commit 449960098a
3 changed files with 42 additions and 15 deletions

View File

@ -12,10 +12,10 @@ type WarehostAuth struct {
db *gorm.DB db *gorm.DB
} }
func (this WarehostAuth) CheckPasswd(user, pass string) (returndata bool, err error) { func (auth WarehostAuth) CheckPasswd(user, pass string) (returndata bool, err error) {
returndata = false returndata = false
var login = system.Login{Username: user} var login = system.Login{Username: user}
this.db.Where("mail = ?", user).First(&login) auth.db.Where("mail = ?", user).First(&login)
if login.ID <= 0 { if login.ID <= 0 {
liblog.Log.Warn("user not found") liblog.Log.Warn("user not found")
return return

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"time" "time"
@ -87,7 +88,7 @@ func (f *FileInfo) Group() string {
func (driver *FileDriver) chechLogin() { func (driver *FileDriver) chechLogin() {
if driver.login.ID <= 0 && driver.conn.IsLogin() { if driver.login.ID <= 0 && driver.conn.IsLogin() {
driver.db.Where("mail = ?", driver.conn.LoginUser()).First(&driver.login) driver.db.Where("mail = ?", driver.conn.LoginUser()).First(&driver.login)
fmt.Printf("Connection:%s:%d", driver.conn.LoginUser(), driver.login.ID) fmt.Printf("Connection:%s:%d\n", driver.conn.LoginUser(), driver.login.ID)
} }
} }
func (driver *FileDriver) realPath(path string) (string, bool) { func (driver *FileDriver) realPath(path string) (string, bool) {
@ -99,20 +100,36 @@ func (driver *FileDriver) realPath(path string) (string, bool) {
switch paths[1] { switch paths[1] {
case DriverFolderOwn: case DriverFolderOwn:
root = fmt.Sprintf(driver.config.Own, driver.login.ID) root = fmt.Sprintf(driver.config.Own, driver.login.ID)
paths = append([]string{paths[0]}, paths[2:]...) paths = paths[2:]
real = true real = true
break
case DriverFolderDomain: case DriverFolderDomain:
if len(paths) > 2 { if len(paths) > 2 {
root = fmt.Sprintf(driver.config.Host, driver.login.ID) var web host.Web
paths = append([]string{paths[0]}, paths[3:]...) domain := paths[2]
real = true if driver.login.Superadmin {
driver.db.Joins("LEFT JOIN host_domain ON host_domain.id=host_web.domain").Where("CONCAT(host_web.subdomain,'.',host_domain.fqdn) = ?", domain).Or("host_web.subdomain='' AND host_domain.fqdn = ?", domain).First(&web)
} else {
driver.db.Joins("LEFT JOIN host_domain ON host_domain.id=host_web.domain").Joins("LEFT JOIN host_web_ftpaccess ftp ON ftp.web=host_web.id AND ftp.login = ?", driver.login.ID).Where("CONCAT(host_web.subdomain,'.',host_domain.fqdn) = ?", domain).Or("host_web.subdomain='' AND host_domain.fqdn = ?", domain).First(&web)
}
if web.ID > 0 {
root = fmt.Sprintf(driver.config.Host, domain)
paths = paths[3:]
real = true
}
} }
break
case DriverFolderWeb: case DriverFolderWeb:
if len(paths) > 2 { if len(paths) > 2 {
root = fmt.Sprintf(driver.config.Web, driver.login.ID) id, _ := strconv.ParseInt(paths[2], 10, 64)
paths = append([]string{paths[0]}, paths[3:]...) res := driver.db.Where(map[string]int64{"website": id, "login": driver.login.ID}).Find(&web.Manager{})
real = true if !res.RecordNotFound() || driver.login.Superadmin {
root = fmt.Sprintf(driver.config.Web, id)
paths = paths[3:]
real = true
}
} }
break
} }
} }
return filepath.Join(append([]string{root}, paths...)...), real return filepath.Join(append([]string{root}, paths...)...), real
@ -212,7 +229,12 @@ func (driver *FileDriver) ListDir(path string, callback func(ftpd.FileInfo) erro
return nil return nil
case fmt.Sprintf("/%s", DriverFolderDomain): case fmt.Sprintf("/%s", DriverFolderDomain):
var list []*host.Web var list []*host.Web
driver.db.Preload("Domain.Profil.Login").Order("length(subdomain) asc").Find(&list) if driver.login.Superadmin {
driver.db.Preload("Domain").Find(&list)
} else {
driver.db.Joins("LEFT JOIN host_web_ftpaccess ftp ON ftp.web=host_web.id AND ftp.login = ?", driver.login.ID).Preload("Domain").Find(&list)
}
for _, i := range list { for _, i := range list {
domain := i.Domain.FQDN domain := i.Domain.FQDN
if len(i.Subdomain) > 0 { if len(i.Subdomain) > 0 {
@ -225,10 +247,14 @@ func (driver *FileDriver) ListDir(path string, callback func(ftpd.FileInfo) erro
} }
return nil return nil
case fmt.Sprintf("/%s", DriverFolderWeb): case fmt.Sprintf("/%s", DriverFolderWeb):
var list []*web.Website var list []*web.Manager
driver.db.Find(&list) if driver.login.Superadmin {
driver.db.Find(&list)
} else {
driver.db.Where("login = ?", driver.login.ID).Find(&list)
}
for _, i := range list { for _, i := range list {
err := callback(&FackFileInfo{name: fmt.Sprintf("%d", i.ID)}) err := callback(&FackFileInfo{name: fmt.Sprintf("%d", i.WebsiteID)})
if err != nil { if err != nil {
return err return err
} }

View File

@ -64,7 +64,7 @@ func JSONWrite(w http.ResponseWriter, r *http.Request, data interface{}, errorre
//JSONDecoder handle complete request of JSON //JSONDecoder handle complete request of JSON
func JSONDecoder(w http.ResponseWriter, r *http.Request, logger *log.Entry, data interface{}) (returnerr *ErrorResult) { func JSONDecoder(w http.ResponseWriter, r *http.Request, logger *log.Entry, data interface{}) (returnerr *ErrorResult) {
if r.Header.Get("Content-Type") != "application/json" { /*if r.Header.Get("Content-Type") != "application/json" {
logger.Error("fetch wrong request type") logger.Error("fetch wrong request type")
returnerr = &ErrorResult{ returnerr = &ErrorResult{
Message: "Internal Request Error", Message: "Internal Request Error",
@ -72,6 +72,7 @@ func JSONDecoder(w http.ResponseWriter, r *http.Request, logger *log.Entry, data
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
*/
err := json.NewDecoder(r.Body).Decode(data) err := json.NewDecoder(r.Body).Decode(data)
if err != nil { if err != nil {
logger.Error("fetch request") logger.Error("fetch request")