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
}
func (this WarehostAuth) CheckPasswd(user, pass string) (returndata bool, err error) {
func (auth WarehostAuth) CheckPasswd(user, pass string) (returndata bool, err error) {
returndata = false
var login = system.Login{Username: user}
this.db.Where("mail = ?", user).First(&login)
auth.db.Where("mail = ?", user).First(&login)
if login.ID <= 0 {
liblog.Log.Warn("user not found")
return

View File

@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"
"time"
@ -87,7 +88,7 @@ func (f *FileInfo) Group() string {
func (driver *FileDriver) chechLogin() {
if driver.login.ID <= 0 && driver.conn.IsLogin() {
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) {
@ -99,20 +100,36 @@ func (driver *FileDriver) realPath(path string) (string, bool) {
switch paths[1] {
case DriverFolderOwn:
root = fmt.Sprintf(driver.config.Own, driver.login.ID)
paths = append([]string{paths[0]}, paths[2:]...)
paths = paths[2:]
real = true
break
case DriverFolderDomain:
if len(paths) > 2 {
root = fmt.Sprintf(driver.config.Host, driver.login.ID)
paths = append([]string{paths[0]}, paths[3:]...)
real = true
var web host.Web
domain := paths[2]
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:
if len(paths) > 2 {
root = fmt.Sprintf(driver.config.Web, driver.login.ID)
paths = append([]string{paths[0]}, paths[3:]...)
real = true
id, _ := strconv.ParseInt(paths[2], 10, 64)
res := driver.db.Where(map[string]int64{"website": id, "login": driver.login.ID}).Find(&web.Manager{})
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
@ -212,7 +229,12 @@ func (driver *FileDriver) ListDir(path string, callback func(ftpd.FileInfo) erro
return nil
case fmt.Sprintf("/%s", DriverFolderDomain):
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 {
domain := i.Domain.FQDN
if len(i.Subdomain) > 0 {
@ -225,10 +247,14 @@ func (driver *FileDriver) ListDir(path string, callback func(ftpd.FileInfo) erro
}
return nil
case fmt.Sprintf("/%s", DriverFolderWeb):
var list []*web.Website
driver.db.Find(&list)
var list []*web.Manager
if driver.login.Superadmin {
driver.db.Find(&list)
} else {
driver.db.Where("login = ?", driver.login.ID).Find(&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 {
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
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")
returnerr = &ErrorResult{
Message: "Internal Request Error",
@ -72,6 +72,7 @@ func JSONDecoder(w http.ResponseWriter, r *http.Request, logger *log.Entry, data
w.WriteHeader(http.StatusBadRequest)
return
}
*/
err := json.NewDecoder(r.Body).Decode(data)
if err != nil {
logger.Error("fetch request")