From 75b65b5e86e2500a22cd3c33eb86846288b5e319 Mon Sep 17 00:00:00 2001 From: George Shaw Date: Tue, 14 Nov 2017 17:38:35 -0600 Subject: [PATCH] starting to create server->account->public structure --- .../default_bundle/account}/README.md | 0 .../account}/assets/css/style.css | 0 .../account}/assets/js/formHandlers/login.js | 0 .../account}/assets/js/formHandlers/logout.js | 0 .../assets/js/formHandlers/register.js | 0 .../account}/assets/js/formHandlers/search.js | 0 .../assets/js/panelHandlers/logs/delete.js | 0 .../assets/js/panelHandlers/logs/view.js | 0 .../panelHandlers/publicServer/maintenance.js | 0 .../js/panelHandlers/publicServer/restart.js | 0 .../js/panelHandlers/publicServer/shutdown.js | 0 .../js/panelHandlers/publicServer/start.js | 0 .../js/panelHandlers/publicServer/status.js | 0 .../js/panelHandlers/security/ipFiltering.js | 0 .../default_bundle/account}/gPanel.html | 0 .../default_bundle/account}/index.html | 0 .../default_bundle}/public/test.html | 0 main.go | 13 +-- .../webhost.go => account/account.go} | 80 ++++++++++++-- pkg/account/authentication.go | 88 +++++++++++++++ pkg/api/user/auth.go | 2 +- pkg/api/user/get_secret.go | 4 +- pkg/api/user/logout.go | 2 +- pkg/database/database.go | 4 +- pkg/networking/session_store.go | 3 +- pkg/public/public.go | 12 +- pkg/{webhost => server}/authentication.go | 9 +- pkg/server/server.go | 62 +++++++++++ server/document_root/assets/css/style.css | 31 ++++++ .../assets/js/formHandlers/login.js | 31 ++++++ .../assets/js/formHandlers/logout.js | 20 ++++ .../assets/js/formHandlers/register.js | 27 +++++ .../assets/js/formHandlers/search.js | 4 + server/document_root/gPanel.html | 69 ++++++++++++ server/document_root/index.html | 104 ++++++++++++++++++ 35 files changed, 527 insertions(+), 38 deletions(-) rename {document_roots/webhost => bundles/default_bundle/account}/README.md (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/css/style.css (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/formHandlers/login.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/formHandlers/logout.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/formHandlers/register.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/formHandlers/search.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/logs/delete.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/logs/view.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/publicServer/maintenance.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/publicServer/restart.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/publicServer/shutdown.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/publicServer/start.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/publicServer/status.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/assets/js/panelHandlers/security/ipFiltering.js (100%) rename {document_roots/webhost => bundles/default_bundle/account}/gPanel.html (100%) rename {document_roots/webhost => bundles/default_bundle/account}/index.html (100%) rename {document_roots => bundles/default_bundle}/public/test.html (100%) rename pkg/{webhost/webhost.go => account/account.go} (52%) create mode 100644 pkg/account/authentication.go rename pkg/{webhost => server}/authentication.go (86%) create mode 100644 pkg/server/server.go create mode 100644 server/document_root/assets/css/style.css create mode 100644 server/document_root/assets/js/formHandlers/login.js create mode 100644 server/document_root/assets/js/formHandlers/logout.js create mode 100644 server/document_root/assets/js/formHandlers/register.js create mode 100644 server/document_root/assets/js/formHandlers/search.js create mode 100644 server/document_root/gPanel.html create mode 100644 server/document_root/index.html diff --git a/document_roots/webhost/README.md b/bundles/default_bundle/account/README.md similarity index 100% rename from document_roots/webhost/README.md rename to bundles/default_bundle/account/README.md diff --git a/document_roots/webhost/assets/css/style.css b/bundles/default_bundle/account/assets/css/style.css similarity index 100% rename from document_roots/webhost/assets/css/style.css rename to bundles/default_bundle/account/assets/css/style.css diff --git a/document_roots/webhost/assets/js/formHandlers/login.js b/bundles/default_bundle/account/assets/js/formHandlers/login.js similarity index 100% rename from document_roots/webhost/assets/js/formHandlers/login.js rename to bundles/default_bundle/account/assets/js/formHandlers/login.js diff --git a/document_roots/webhost/assets/js/formHandlers/logout.js b/bundles/default_bundle/account/assets/js/formHandlers/logout.js similarity index 100% rename from document_roots/webhost/assets/js/formHandlers/logout.js rename to bundles/default_bundle/account/assets/js/formHandlers/logout.js diff --git a/document_roots/webhost/assets/js/formHandlers/register.js b/bundles/default_bundle/account/assets/js/formHandlers/register.js similarity index 100% rename from document_roots/webhost/assets/js/formHandlers/register.js rename to bundles/default_bundle/account/assets/js/formHandlers/register.js diff --git a/document_roots/webhost/assets/js/formHandlers/search.js b/bundles/default_bundle/account/assets/js/formHandlers/search.js similarity index 100% rename from document_roots/webhost/assets/js/formHandlers/search.js rename to bundles/default_bundle/account/assets/js/formHandlers/search.js diff --git a/document_roots/webhost/assets/js/panelHandlers/logs/delete.js b/bundles/default_bundle/account/assets/js/panelHandlers/logs/delete.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/logs/delete.js rename to bundles/default_bundle/account/assets/js/panelHandlers/logs/delete.js diff --git a/document_roots/webhost/assets/js/panelHandlers/logs/view.js b/bundles/default_bundle/account/assets/js/panelHandlers/logs/view.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/logs/view.js rename to bundles/default_bundle/account/assets/js/panelHandlers/logs/view.js diff --git a/document_roots/webhost/assets/js/panelHandlers/publicServer/maintenance.js b/bundles/default_bundle/account/assets/js/panelHandlers/publicServer/maintenance.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/publicServer/maintenance.js rename to bundles/default_bundle/account/assets/js/panelHandlers/publicServer/maintenance.js diff --git a/document_roots/webhost/assets/js/panelHandlers/publicServer/restart.js b/bundles/default_bundle/account/assets/js/panelHandlers/publicServer/restart.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/publicServer/restart.js rename to bundles/default_bundle/account/assets/js/panelHandlers/publicServer/restart.js diff --git a/document_roots/webhost/assets/js/panelHandlers/publicServer/shutdown.js b/bundles/default_bundle/account/assets/js/panelHandlers/publicServer/shutdown.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/publicServer/shutdown.js rename to bundles/default_bundle/account/assets/js/panelHandlers/publicServer/shutdown.js diff --git a/document_roots/webhost/assets/js/panelHandlers/publicServer/start.js b/bundles/default_bundle/account/assets/js/panelHandlers/publicServer/start.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/publicServer/start.js rename to bundles/default_bundle/account/assets/js/panelHandlers/publicServer/start.js diff --git a/document_roots/webhost/assets/js/panelHandlers/publicServer/status.js b/bundles/default_bundle/account/assets/js/panelHandlers/publicServer/status.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/publicServer/status.js rename to bundles/default_bundle/account/assets/js/panelHandlers/publicServer/status.js diff --git a/document_roots/webhost/assets/js/panelHandlers/security/ipFiltering.js b/bundles/default_bundle/account/assets/js/panelHandlers/security/ipFiltering.js similarity index 100% rename from document_roots/webhost/assets/js/panelHandlers/security/ipFiltering.js rename to bundles/default_bundle/account/assets/js/panelHandlers/security/ipFiltering.js diff --git a/document_roots/webhost/gPanel.html b/bundles/default_bundle/account/gPanel.html similarity index 100% rename from document_roots/webhost/gPanel.html rename to bundles/default_bundle/account/gPanel.html diff --git a/document_roots/webhost/index.html b/bundles/default_bundle/account/index.html similarity index 100% rename from document_roots/webhost/index.html rename to bundles/default_bundle/account/index.html diff --git a/document_roots/public/test.html b/bundles/default_bundle/public/test.html similarity index 100% rename from document_roots/public/test.html rename to bundles/default_bundle/public/test.html diff --git a/main.go b/main.go index f262ee4..b5b55cb 100644 --- a/main.go +++ b/main.go @@ -4,20 +4,15 @@ import ( "log" "net/http" - "github.com/Ennovar/gPanel/pkg/webhost" + "github.com/Ennovar/gPanel/pkg/server" "github.com/gorilla/context" ) func main() { - webhost := webhost.New() + gpServer := server.New() log.Printf("To Exit: CTRL+C") - go func() { - log.Print("Listening (public) on localhost:3000, serving out of the document_roots/public/ directory...") - _ = webhost.Public.Start() - }() - - log.Print("Listening (private) on localhost:2082, serving out of the document_roots/webhost/ directory...") - http.ListenAndServe("localhost:2082", context.ClearHandler(&webhost)) + log.Print("Listening (server) on localhost:2083, serving out of the server/document_root/ directory...") + http.ListenAndServe("localhost:2083", context.ClearHandler(gpServer)) } diff --git a/pkg/webhost/webhost.go b/pkg/account/account.go similarity index 52% rename from pkg/webhost/webhost.go rename to pkg/account/account.go index dfdbc30..6a7a16b 100644 --- a/pkg/webhost/webhost.go +++ b/pkg/account/account.go @@ -1,11 +1,15 @@ -// Package webhost handles the logic of the webhosting panel -package webhost +// Package account handles the logic of the gPanel account server +package account import ( + "context" + "errors" + "fmt" "io" "net/http" "os" "strconv" + "time" "github.com/Ennovar/gPanel/pkg/api" "github.com/Ennovar/gPanel/pkg/file" @@ -14,20 +18,72 @@ import ( ) type Controller struct { - Directory string - Public *public.Controller - ServerLogger *file.Handler + Directory string + DocumentRoot string + Port int + Public *public.Controller + GracefulShutdownTimeout time.Duration + Status int + ServerLogger *file.Handler } -// New returns a new PrivateHost type. -func New() Controller { +var controller Controller +var server http.Server + +// New returns a new Controller reference. +func New(root string) *Controller { serverErrorLogger, _ := file.Open(file.LOG_SERVER_ERRORS, true, true) - return Controller{ - Directory: "document_roots/webhost/", - Public: public.New(), - ServerLogger: serverErrorLogger, + controller = Controller{ + Directory: root, + DocumentRoot: "account/", + Port: 2082, + Public: public.New(root + "public/"), + GracefulShutdownTimeout: 5 * time.Second, + Status: 0, + ServerLogger: serverErrorLogger, } + + server = http.Server{ + Addr: "localhost:" + strconv.Itoa(controller.Port), + Handler: &controller, + ReadTimeout: 30 * time.Second, + WriteTimeout: 30 * time.Second, + MaxHeaderBytes: 0, + } + + return &controller +} + +func (con *Controller) Start() error { + if con.Status == 1 { + return errors.New("Account server is already on.") + } + + con.Status = 1 + go server.ListenAndServe() + return nil +} + +func (con *Controller) Stop(graceful bool) error { + if graceful { + context, cancel := context.WithTimeout(context.Background(), con.GracefulShutdownTimeout) + defer cancel() + + err := server.Shutdown(context) + if err == nil { + return nil + } + + fmt.Printf("Graceful shutdown failed attempting forced: %v\n", err) + } + + if err := server.Close(); err != nil { + return err + } + + con.Status = 0 + return nil } // ServeHTTP function routes all requests for the private webhost server. It is used in the main @@ -41,7 +97,7 @@ func (con *Controller) ServeHTTP(res http.ResponseWriter, req *http.Request) { } if reqAuth(path) { - if !checkAuth(res, req) { + if !con.checkAuth(res, req) { con.ServerLogger.Write(path + "::" + strconv.Itoa(http.StatusUnauthorized) + "::" + http.StatusText(http.StatusUnauthorized)) http.Error(res, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return diff --git a/pkg/account/authentication.go b/pkg/account/authentication.go new file mode 100644 index 0000000..6631470 --- /dev/null +++ b/pkg/account/authentication.go @@ -0,0 +1,88 @@ +// Package account handles the logic of the gPanel account server +package account + +import ( + "net/http" + "strings" + + "github.com/Ennovar/gPanel/pkg/api/user" + "github.com/Ennovar/gPanel/pkg/networking" + jwt "github.com/dgrijalva/jwt-go" +) + +// reqAuth function checks to see if the given path requires authentication. +func reqAuth(path string) bool { + path = strings.ToLower(path) + + dismissibleTypes := []string{".css", ".js"} + for _, t := range dismissibleTypes { + if strings.HasSuffix(path, t) { + return false + } + } + + dismissibleFiles := []string{ + "index.html", + "api/user/auth", + "api/user/register", + "api/user/logout", + } + for _, f := range dismissibleFiles { + if strings.HasSuffix(path, f) { + return false + } + } + + return true +} + +// checkAuth function returns a boolean based on whether or not the current +// caller is authenticated based off of encrypted sessions using JWT values. +func (con *Controller) checkAuth(res http.ResponseWriter, req *http.Request) bool { + store := networking.GetStore(networking.ACCOUNT_USER_AUTH) + + session_value, err := store.Read(res, req, "user") + if err != nil || session_value == nil { + return false + } + + username, ok := session_value.(string) + if !ok { + return false + } + + stored_secret, err := user.GetSecret(username, con.Directory) + if stored_secret == "" { + return false + } + + session_value, err = store.Read(res, req, "token") + if err != nil || session_value == nil { + return false + } + + tokenString, ok := session_value.(string) + if !ok { + return false + } + + keyfunc := func(t *jwt.Token) (interface{}, error) { + return []byte(stored_secret), nil + } + + p := jwt.Parser{ + ValidMethods: []string{"HS256", "HS384", "HS512"}, + } + t, err := p.ParseWithClaims(tokenString, &jwt.StandardClaims{}, keyfunc) + + if err != nil { + return false + } + + claims := t.Claims.(*jwt.StandardClaims) + if claims.Subject != username { + return false + } + + return true +} diff --git a/pkg/api/user/auth.go b/pkg/api/user/auth.go index cced68b..a83e3ed 100644 --- a/pkg/api/user/auth.go +++ b/pkg/api/user/auth.go @@ -80,7 +80,7 @@ func Auth(res http.ResponseWriter, req *http.Request) bool { return false } - store := networking.GetStore(networking.COOKIES_USER_AUTH) + store := networking.GetStore(networking.ACCOUNT_USER_AUTH) err = store.Set(res, req, "token", token, (60 * 60 * 24)) err2 := store.Set(res, req, "user", userRequestData.User, (60 * 60 * 24)) if err != nil || err2 != nil { diff --git a/pkg/api/user/get_secret.go b/pkg/api/user/get_secret.go index 6c8a0e9..f0d1e06 100644 --- a/pkg/api/user/get_secret.go +++ b/pkg/api/user/get_secret.go @@ -6,8 +6,8 @@ import "github.com/Ennovar/gPanel/pkg/database" // GetSecret is not accessible from the any client side request. It is // only used on the server side to help verify users are who they say they // are. -func GetSecret(user string) (string, error) { - ds, err := database.Open(database.DBLOC_MAIN) +func GetSecret(user string, directory string) (string, error) { + ds, err := database.Open(directory + database.DBLOC_MAIN) if err != nil { return "", err } diff --git a/pkg/api/user/logout.go b/pkg/api/user/logout.go index a6ec8f2..cfecb5c 100644 --- a/pkg/api/user/logout.go +++ b/pkg/api/user/logout.go @@ -16,7 +16,7 @@ func Logout(res http.ResponseWriter, req *http.Request) bool { return false } - store := networking.GetStore(networking.COOKIES_USER_AUTH) + store := networking.GetStore(networking.ACCOUNT_USER_AUTH) err := store.Delete(res, req) if err != nil { diff --git a/pkg/database/database.go b/pkg/database/database.go index 0a81b15..dfcf525 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -30,8 +30,8 @@ type Datastore struct { // Open function will open the database and return a Datastore struct // that has a handle within it for various datastore functions. -func Open(filename string) (*Datastore, error) { - db, err := bolt.Open(filename, 0666, &bolt.Options{Timeout: 15 * time.Second}) +func Open(filepath string) (*Datastore, error) { + db, err := bolt.Open(filepath, 0666, &bolt.Options{Timeout: 15 * time.Second}) if err != nil { return nil, err diff --git a/pkg/networking/session_store.go b/pkg/networking/session_store.go index 1e831d1..44d6647 100644 --- a/pkg/networking/session_store.go +++ b/pkg/networking/session_store.go @@ -11,7 +11,8 @@ import ( var key = []byte("GbP=K4#f$khYuZpStK68GyHxGg$4@5K-") const ( - COOKIES_USER_AUTH = "gpanel-webhost-user-auth" + ACCOUNT_USER_AUTH = "gpanel-account-user-auth" + SERVER_USER_AUTH = "gpanel-server-user-auth" ) type store struct { diff --git a/pkg/public/public.go b/pkg/public/public.go index 06450cd..304ebdf 100644 --- a/pkg/public/public.go +++ b/pkg/public/public.go @@ -16,7 +16,8 @@ import ( ) type Controller struct { - Directory string + DocumentRoot string + Port int GracefulShutdownTimeout time.Duration Status int ClientLogger *file.Handler @@ -28,13 +29,14 @@ var controller Controller var server http.Server // New function returns a new PublicWeb type. -func New() *Controller { +func New(root string) *Controller { clientLogHandler, _ := file.Open(file.LOG_CLIENT_ERRORS, true, true) serverLogHandler, _ := file.Open(file.LOG_CLIENT_ERRORS, true, true) loadLogHandler, _ := file.Open(file.LOG_LOADTIME, true, true) controller = Controller{ - Directory: "document_roots/public/", + DocumentRoot: root, + Port: 3000, GracefulShutdownTimeout: 5 * time.Second, Status: 0, ClientLogger: clientLogHandler, @@ -141,9 +143,9 @@ func (con *Controller) ServeHTTP(res http.ResponseWriter, req *http.Request) { path := req.URL.Path[1:] if len(path) == 0 { - path = (con.Directory + "index.html") + path = (con.DocumentRoot + "index.html") } else { - path = (con.Directory + path) + path = (con.DocumentRoot + path) } f, err := os.Open(path) diff --git a/pkg/webhost/authentication.go b/pkg/server/authentication.go similarity index 86% rename from pkg/webhost/authentication.go rename to pkg/server/authentication.go index f126339..8c31f9f 100644 --- a/pkg/webhost/authentication.go +++ b/pkg/server/authentication.go @@ -1,5 +1,4 @@ -// Package webhost handles the logic of the webhosting panel -package webhost +package server import ( "net/http" @@ -38,8 +37,8 @@ func reqAuth(path string) bool { // checkAuth function returns a boolean based on whether or not the current // caller is authenticated based off of encrypted sessions using JWT values. -func checkAuth(res http.ResponseWriter, req *http.Request) bool { - store := networking.GetStore(networking.COOKIES_USER_AUTH) +func (con *Controller) checkAuth(res http.ResponseWriter, req *http.Request) bool { + store := networking.GetStore(networking.SERVER_USER_AUTH) session_value, err := store.Read(res, req, "user") if err != nil || session_value == nil { @@ -51,7 +50,7 @@ func checkAuth(res http.ResponseWriter, req *http.Request) bool { return false } - stored_secret, err := user.GetSecret(username) + stored_secret, err := user.GetSecret(username, con.Directory) if stored_secret == "" { return false } diff --git a/pkg/server/server.go b/pkg/server/server.go new file mode 100644 index 0000000..f7f4260 --- /dev/null +++ b/pkg/server/server.go @@ -0,0 +1,62 @@ +package server + +import ( + "io" + "net/http" + "os" + + "github.com/Ennovar/gPanel/pkg/account" + "github.com/Ennovar/gPanel/pkg/routing" +) + +type Controller struct { + Directory string + DocumentRoot string + Bundles []account.Controller +} + +func New() *Controller { + return &Controller{ + Directory: "server/", + DocumentRoot: "document_root/", + Bundles: []account.Controller{}, + } +} + +func (con *Controller) ServeHTTP(res http.ResponseWriter, req *http.Request) { + path := req.URL.Path[1:] + if len(path) == 0 { + path = (con.Directory + con.DocumentRoot + "index.html") + } else { + path = (con.Directory + con.DocumentRoot + path) + } + + if reqAuth(path) { + if !con.checkAuth(res, req) { + http.Error(res, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) + return + } + } + + f, err := os.Open(path) + + if err != nil { + routing.HttpThrowStatus(http.StatusNotFound, res) + return + } + + contentType, err := routing.GetContentType(path) + + if err != nil { + routing.HttpThrowStatus(http.StatusUnsupportedMediaType, res) + return + } + + res.Header().Add("Content-Type", contentType) + _, err = io.Copy(res, f) + + if err != nil { + routing.HttpThrowStatus(http.StatusInternalServerError, res) + return + } +} diff --git a/server/document_root/assets/css/style.css b/server/document_root/assets/css/style.css new file mode 100644 index 0000000..52547f1 --- /dev/null +++ b/server/document_root/assets/css/style.css @@ -0,0 +1,31 @@ +/* Sticky Footer Start */ +html { + position:relative; + min-height:100%; +} + +body { + margin-bottom:60px; +} + +.sticky-footer { + position:absolute; + bottom:0; + width:100%; + height:60px; + line-height:60px; + background-color:#E0EBF5; +} +/* Sticky Footer End */ + +/* Navbar Start */ +.navbar { + background-color:#E0EBF5 !important; +} +/* Navbar End */ + +/* General Start */ +.btn { + cursor:pointer; +} +/* General End */ diff --git a/server/document_root/assets/js/formHandlers/login.js b/server/document_root/assets/js/formHandlers/login.js new file mode 100644 index 0000000..3d12a41 --- /dev/null +++ b/server/document_root/assets/js/formHandlers/login.js @@ -0,0 +1,31 @@ +jQuery('#loginForm').on('submit', function(e){ + e.preventDefault(); + + var formData = {}; + for(var y = 0, yy = this.length; y < yy; y++) { + var input = this[y]; + if(input.name) { + formData[input.name] = input.value; + } + } + + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(formData)); + + xhr.onloadend = function() { + if(xhr.status == 200 || xhr.status == 204) { + jQuery('.index-alert').html('Login Success: Redirecting in 2 seconds...'); + jQuery('.index-alert').removeClass('alert-danger').addClass('alert-success').removeClass('d-none'); + + setTimeout(function(){ + window.location.href = "/gPanel.html"; + }, 2000); + } + else { + jQuery('.index-alert').html("Login Error: " + xhr.response); + jQuery('.index-alert').removeClass('alert-success').addClass('alert-danger').removeClass('d-none'); + } + } +}); diff --git a/server/document_root/assets/js/formHandlers/logout.js b/server/document_root/assets/js/formHandlers/logout.js new file mode 100644 index 0000000..cf2e99a --- /dev/null +++ b/server/document_root/assets/js/formHandlers/logout.js @@ -0,0 +1,20 @@ +jQuery('#logoutForm').on('submit', function(e){ + e.preventDefault(); + + var check = confirm('Are you sure you want to logut?'); + + if(check) { + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.send(); + + xhr.onloadend = function() { + if(xhr.status == 200 || xhr.status == 204) { + window.location.href = '/'; + } + else { + alert('An error has occurred. Please contact your server\'s administrator.'); + } + } + } +}); diff --git a/server/document_root/assets/js/formHandlers/register.js b/server/document_root/assets/js/formHandlers/register.js new file mode 100644 index 0000000..074a719 --- /dev/null +++ b/server/document_root/assets/js/formHandlers/register.js @@ -0,0 +1,27 @@ +jQuery('#registerForm').on('submit', function(e){ + e.preventDefault(); + + var formData = {}; + for(var y = 0, yy = this.length; y < yy; y++) { + var input = this[y]; + if(input.name) { + formData[input.name] = input.value; + } + } + + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(formData)); + + xhr.onloadend = function() { + if(xhr.status == 200 || xhr.status == 204) { + jQuery('.index-alert').html('Register Success: You may now login.'); + jQuery('.index-alert').removeClass('alert-danger').addClass('alert-success').removeClass('d-none'); + } + else { + jQuery('.index-alert').html("Register Error: " + xhr.response); + jQuery('.index-alert').removeClass('alert-success').addClass('alert-danger').removeClass('d-none'); + } + } +}); diff --git a/server/document_root/assets/js/formHandlers/search.js b/server/document_root/assets/js/formHandlers/search.js new file mode 100644 index 0000000..e659a8a --- /dev/null +++ b/server/document_root/assets/js/formHandlers/search.js @@ -0,0 +1,4 @@ +jQuery('#searchForm').on('submit', function(e){ + e.preventDefault(); + alert('Search functionality coming soon.'); +}); diff --git a/server/document_root/gPanel.html b/server/document_root/gPanel.html new file mode 100644 index 0000000..4df6c16 --- /dev/null +++ b/server/document_root/gPanel.html @@ -0,0 +1,69 @@ + + + + gPanel Server + + + + + + + + + + + +
+
+
+
+
+

Test

+
Test
+ +
+ +
+
+
+
+ + + + + + + + + + + + + diff --git a/server/document_root/index.html b/server/document_root/index.html new file mode 100644 index 0000000..4f9f450 --- /dev/null +++ b/server/document_root/index.html @@ -0,0 +1,104 @@ + + + + gPanel Server + + + + + + + + + + + +
+
+ +
+ +
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+ Register is Temporary, for development purposes only. +
+ +
+
+ + + + + + + + + + + + + +