فهرست منبع

Added wip structure for webdab worker manager

Toby Chui 1 ماه پیش
والد
کامیت
5d3c90c93c
3فایلهای تغییر یافته به همراه82 افزوده شده و 26 حذف شده
  1. 0 26
      main.go
  2. 19 0
      mod/bokoworker/bokoworker.go
  3. 63 0
      mod/webdav/webdav.go

+ 0 - 26
main.go

@@ -54,32 +54,6 @@ func main() {
 
 		dir = *dirFlag
 
-		srv := &webdav.Handler{
-			FileSystem: webdav.Dir(dir),
-			LockSystem: webdav.NewMemLS(),
-			Logger: func(r *http.Request, err error) {
-				if err != nil {
-					log.Printf("WEBDAV [%s]: %s, ERROR: %s\n", r.Method, r.URL, err)
-				} else {
-					log.Printf("WEBDAV [%s]: %s \n", r.Method, r.URL)
-				}
-			},
-		}
-		http.Handle("/", srv)
-		if *serveSecure == true {
-			if _, err := os.Stat("./cert.pem"); err != nil {
-				fmt.Println("[x] No cert.pem in current directory. Please provide a valid cert")
-				return
-			}
-			if _, er := os.Stat("./key.pem"); er != nil {
-				fmt.Println("[x] No key.pem in current directory. Please provide a valid cert")
-				return
-			}
 
-			go http.ListenAndServeTLS(fmt.Sprintf(":%d", *httpsPort), "cert.pem", "key.pem", nil)
-		}
-		if err := http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil); err != nil {
-			log.Fatalf("Error with WebDAV server: %v", err)
-		}
 	*/
 }

+ 19 - 0
mod/bokoworker/bokoworker.go

@@ -0,0 +1,19 @@
+package bokoworker
+
+/*
+	Boko Worker
+
+	A boko worker is an instance of WebDAV file server that serves a specific
+	disk partition or subpath in which the user can interact with the disk
+	via WebDAV interface
+*/
+
+type Worker struct {
+	/* Worker Properties */
+	UUID     string //UUID of this worker
+	DiskUUID string // Disk UUID, when provided, will be used instead of disk path
+	DiskPath string // Disk device path (e.g. /dev/sda1), Disk UUID will have higher priority
+	Subpath  string // Subpath to serve, default is root
+	ReadOnly bool   //Label this worker as read only
+
+}

+ 63 - 0
mod/webdav/webdav.go

@@ -0,0 +1,63 @@
+package webdav
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"os"
+
+	"golang.org/x/net/webdav"
+	"imuslab.com/bokofs/bokofsd/mod/bokoworker"
+)
+
+/*
+	WebDAV module
+
+	This module handle the interfacing to the underlying file system
+	through the middle ware
+*/
+
+type Options struct {
+	ListeningAddress string //Listening address, e.g. 0.0.0.0:8443
+	SecureServe      bool   //Use TLS to serve the WebDAV request
+	PublicKeyPath    string
+	PrivateKeyPath   string
+}
+
+type Server struct {
+	LoadedWorkers *bokoworker.Worker
+}
+
+func NewWebdavInterfaceServer() *Server {
+	return &Server{}
+}
+
+func (s *Server) Start() error {
+	srv := &webdav.Handler{
+		FileSystem: webdav.Dir(dir),
+		LockSystem: webdav.NewMemLS(),
+		Logger: func(r *http.Request, err error) {
+			if err != nil {
+				log.Printf("WEBDAV [%s]: %s, ERROR: %s\n", r.Method, r.URL, err)
+			} else {
+				log.Printf("WEBDAV [%s]: %s \n", r.Method, r.URL)
+			}
+		},
+	}
+	http.Handle("/", srv)
+	if *serveSecure == true {
+		if _, err := os.Stat("./cert.pem"); err != nil {
+			fmt.Println("[x] No cert.pem in current directory. Please provide a valid cert")
+			return
+		}
+		if _, er := os.Stat("./key.pem"); er != nil {
+			fmt.Println("[x] No key.pem in current directory. Please provide a valid cert")
+			return
+		}
+
+		go http.ListenAndServeTLS(fmt.Sprintf(":%d", *httpsPort), "cert.pem", "key.pem", nil)
+	}
+	if err := http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil); err != nil {
+		log.Fatalf("Error with WebDAV server: %v", err)
+	}
+}