sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This commit is contained in:
Martin Geno 2016-12-19 12:52:43 +01:00
parent 48cab176df
commit cfbb6a619f
11 changed files with 42 additions and 39 deletions

View File

@ -27,7 +27,7 @@ const (
)
type FileDriver struct {
config Config
config *Config
db *gorm.DB
Perm ftpd.Perm
login system.Login
@ -98,18 +98,18 @@ func (driver *FileDriver) realPath(path string) (string, bool) {
if len(paths) > 1 && driver.login.ID > 0 {
switch paths[1] {
case DriverFolderOwn:
root = fmt.Sprintf(driver.Own, driver.login.ID)
root = fmt.Sprintf(driver.config.Own, driver.login.ID)
paths = append([]string{paths[0]}, paths[2:]...)
real = true
case DriverFolderDomain:
if len(paths) > 2 {
root = fmt.Sprintf(driver.Host, driver.login.ID)
root = fmt.Sprintf(driver.config.Host, driver.login.ID)
paths = append([]string{paths[0]}, paths[3:]...)
real = true
}
case DriverFolderWeb:
if len(paths) > 2 {
root = fmt.Sprintf(driver.Web, driver.login.ID)
root = fmt.Sprintf(driver.config.Web, driver.login.ID)
paths = append([]string{paths[0]}, paths[3:]...)
real = true
}
@ -215,7 +215,7 @@ func (driver *FileDriver) ListDir(path string, callback func(ftpd.FileInfo) erro
driver.db.Preload("Domain.Profil.Login").Order("length(subdomain) asc").Find(&list)
for _, i := range list {
domain := i.Domain.FQDN
if len(item.Subdomain) > 0 {
if len(i.Subdomain) > 0 {
domain = fmt.Sprintf("%s.%s", i.Subdomain, domain)
}
err := callback(&FackFileInfo{name: domain})
@ -228,7 +228,7 @@ func (driver *FileDriver) ListDir(path string, callback func(ftpd.FileInfo) erro
var list []*web.Website
driver.db.Find(&list)
for _, i := range list {
err := callback(&FackFileInfo{name: strconv.Itoa(i.ID)})
err := callback(&FackFileInfo{name: fmt.Sprintf("%d", i.ID)})
if err != nil {
return err
}
@ -370,7 +370,7 @@ func (driver *FileDriver) PutFile(destPath string, data io.Reader, appendData bo
}
type FileDriverFactory struct {
config Config
config *Config
db *gorm.DB
Perm ftpd.Perm
}

View File

@ -46,7 +46,7 @@ func main() {
opt := &ftpd.ServerOpts{
Name: "",
Factory: &FileDriverFactory{Config: config, db: dbconnection, Perm: ftpd.NewSimplePerm("warehost", "http")},
Factory: &FileDriverFactory{config: config, db: dbconnection, Perm: ftpd.NewSimplePerm("warehost", "http")},
Port: config.Port,
Auth: WarehostAuth{db: dbconnection},
}

View File

@ -11,7 +11,6 @@ import (
"github.com/rs/cors"
"goji.io"
"goji.io/pat"
"golang.org/x/net/context"
config "dev.sum7.eu/sum7/warehost/config"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
@ -75,10 +74,9 @@ func main() {
// END Module deklations
// Make Modules debugable
router.HandleFuncC(pat.Get("/modules"), libapi.SessionHandler(
func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
returndata = modules
return
router.HandleFunc(pat.Get("/modules"), libapi.SessionHandler(
func(w http.ResponseWriter, r *http.Request) {
libapi.JSONWrite(w, r, modules, nil)
}))
liblog.Log.Info("load modul: ", modules)

View File

@ -58,6 +58,7 @@ func domainShow(w http.ResponseWriter, r *http.Request) {
domain, returnerr := getDomain(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("dID", domain.ID)
@ -107,6 +108,7 @@ func domainEdit(w http.ResponseWriter, r *http.Request) {
domain, returnerr := getDomain(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("dID", domain.ID)
@ -142,6 +144,7 @@ func domainDelete(w http.ResponseWriter, r *http.Request) {
domain, returnerr := getDomain(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("dID", domain.ID)

View File

@ -28,7 +28,6 @@ func TestAPIDomain(t *testing.T) {
result, w := session.JSONRequest("DELETE", "/host/delete", nil)
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(true, result.Data)
// Need a Profile for Next tests
result, w = session.JSONRequest("POST", "/host/signup", nil)
@ -78,7 +77,7 @@ func TestAPIDomain(t *testing.T) {
result, w = session.JSONRequest("POST", "/host/domain", Domain{
FQDN: "example.de",
})
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(http.StatusInternalServerError, w.StatusCode)
assertion.Equal(false, result.Data)
/*

View File

@ -23,12 +23,12 @@ func getMail(w http.ResponseWriter, r *http.Request) (mail Mail, returnerr *liba
w.WriteHeader(http.StatusBadRequest)
return
}
mail = Mail{ID: id}
mail = Mail{}
if login.Superadmin {
dbconnection.Preload("Forwards").Find(&mail)
dbconnection.Where("ID = ?", id).Preload("Forwards").Find(&mail)
} else {
dbconnection.Where(map[string]int64{"domain.profil": profil.ID}).Preload("Forwards").Find(&mail)
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("Forwards").Find(&mail)
}
if mail.ID <= 0 {
returnerr = &libapi.ErrorResult{Fields: []string{"mail"}, Message: "not found"}
@ -43,6 +43,7 @@ func mailList(w http.ResponseWriter, r *http.Request) {
domain, returnerr := getDomain(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("dID", domain.ID)
@ -98,6 +99,7 @@ func mailEdit(w http.ResponseWriter, r *http.Request) {
mail, returnerr := getMail(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("mID", mail.ID)

View File

@ -59,7 +59,7 @@ func TestAPIMail(t *testing.T) {
session.Clean()
result, w = session.JSONRequest("GET", "/host/domain/"+strconv.Itoa(domain)+"/mail", nil)
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
@ -80,13 +80,13 @@ func TestAPIMail(t *testing.T) {
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(domain)+"/mail", Mail{
Name: "test-bug",
})
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(domain)+"/mail", []byte{2, 3})
assertion.Equal(w.StatusCode, http.StatusBadRequest)
assertion.Equal(http.StatusBadRequest, w.StatusCode)
assertion.Equal(false, result.Data)
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(-1)+"/mail", Mail{
@ -104,7 +104,7 @@ func TestAPIMail(t *testing.T) {
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(domain)+"/mail", Mail{
Name: "test",
})
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(http.StatusInternalServerError, w.StatusCode)
assertion.Equal(false, result.Data)
/*
@ -126,13 +126,13 @@ func TestAPIMail(t *testing.T) {
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain)+"/mail/"+strconv.Itoa(mail), Mail{
Name: "test-bug-auth",
})
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain)+"/mail/"+strconv.Itoa(mail), []byte{2, 3})
assertion.Equal(w.StatusCode, http.StatusBadRequest)
assertion.Equal(http.StatusBadRequest, w.StatusCode)
assertion.Equal(false, result.Data)
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain)+"/mail/"+strconv.Itoa(-1), Mail{
@ -153,7 +153,7 @@ func TestAPIMail(t *testing.T) {
session.Clean()
result, w = session.JSONRequest("DELETE", "/host/domain/"+strconv.Itoa(domain)+"/mail/"+strconv.Itoa(mail), nil)
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)

View File

@ -39,7 +39,7 @@ func TestAPIProfil(t *testing.T) {
*/
session.Clean()
result, w = session.JSONRequest("GET", "/host/profils", nil)
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
@ -63,7 +63,7 @@ func TestAPIProfil(t *testing.T) {
session.Clean()
result, w = session.JSONRequest("PATCH", "/host/profil/"+strconv.Itoa(id), nil)
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)

View File

@ -36,11 +36,11 @@ func getWeb(w http.ResponseWriter, r *http.Request) (web Web, returnerr *libapi.
w.WriteHeader(http.StatusBadRequest)
return
}
web = Web{ID: id}
web = Web{}
if login.Superadmin {
dbconnection.Preload("HTTPAccess.Login").Preload("FTPAccess.Login").Find(&web)
dbconnection.Where("ID = ?", id).Preload("HTTPAccess.Login").Preload("FTPAccess.Login").Find(&web)
} else {
dbconnection.Where(map[string]int64{"domain.profil": profil.ID}).Preload("HTTPAccess.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"}
@ -55,6 +55,7 @@ func webList(w http.ResponseWriter, r *http.Request) {
domain, returnerr := getDomain(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("dID", domain.ID)
@ -211,6 +212,7 @@ func webDelete(w http.ResponseWriter, r *http.Request) {
web, returnerr := getWeb(w, r)
if returnerr != nil {
logger.Info("not found")
libapi.JSONWrite(w, r, false, returnerr)
return
}
logger = logger.WithField("wID", web.ID)

View File

@ -59,7 +59,7 @@ func TestAPIWeb(t *testing.T) {
session.Clean()
result, w = session.JSONRequest("GET", "/host/domain/"+strconv.Itoa(domain)+"/web", nil)
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
@ -80,13 +80,13 @@ func TestAPIWeb(t *testing.T) {
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(domain)+"/web", Web{
Subdomain: "",
})
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(domain)+"/web", []byte{2, 3})
assertion.Equal(w.StatusCode, http.StatusBadRequest)
assertion.Equal(http.StatusBadRequest, w.StatusCode)
assertion.Equal(false, result.Data)
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(-1)+"/web", Web{
@ -104,7 +104,7 @@ func TestAPIWeb(t *testing.T) {
result, w = session.JSONRequest("POST", "/host/domain/"+strconv.Itoa(domain)+"/web", Web{
Subdomain: "",
})
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(http.StatusInternalServerError, w.StatusCode)
assertion.Equal(false, result.Data)
/*
@ -126,13 +126,13 @@ func TestAPIWeb(t *testing.T) {
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain)+"/web/"+strconv.Itoa(web), Web{
Subdomain: "test-bug-auth",
})
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain)+"/web/"+strconv.Itoa(web), []byte{2, 3})
assertion.Equal(w.StatusCode, http.StatusBadRequest)
assertion.Equal(http.StatusBadRequest, w.StatusCode)
assertion.Equal(false, result.Data)
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain)+"/web/"+strconv.Itoa(-1), Web{
@ -153,7 +153,7 @@ func TestAPIWeb(t *testing.T) {
session.Clean()
result, w = session.JSONRequest("DELETE", "/host/domain/"+strconv.Itoa(domain)+"/web/"+strconv.Itoa(web), nil)
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
assertion.Equal(false, result.Data)
loginTest(session, assertion)

View File

@ -1,10 +1,9 @@
package system
import (
"context"
"net/http"
"golang.org/x/net/context"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
liblog "dev.sum7.eu/sum7/warehost/lib/log"
libsession "dev.sum7.eu/sum7/warehost/lib/session"