From 08e431f980f3b46835af833e21ae9dbf2c087e18 Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 15:58:51 -0600 Subject: [PATCH 1/7] issue #49 --- pkg/networking/session_store.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/networking/session_store.go b/pkg/networking/session_store.go index 62181a4..1e831d1 100644 --- a/pkg/networking/session_store.go +++ b/pkg/networking/session_store.go @@ -19,6 +19,7 @@ type store struct { cookieName string } +// GetStore function takes a name and either creates/grabs a store with that name. func GetStore(name string) store { sessionStore := store{ handle: sessions.NewCookieStore(key), @@ -28,6 +29,7 @@ func GetStore(name string) store { return sessionStore } +// Set function is attached to the store struct and will set a session value inside of the current store. func (s *store) Set(res http.ResponseWriter, req *http.Request, key string, value interface{}, expire int) error { session, err := s.handle.Get(req, s.cookieName) @@ -45,6 +47,7 @@ func (s *store) Set(res http.ResponseWriter, req *http.Request, key string, valu return nil } +// Read function is attached to the store struct and will read a given session value inside of the current store. func (s *store) Read(res http.ResponseWriter, req *http.Request, key string) (interface{}, error) { session, err := s.handle.Get(req, s.cookieName) @@ -56,6 +59,7 @@ func (s *store) Read(res http.ResponseWriter, req *http.Request, key string) (in return value, nil } +// Delete function is attached to the store struct and will delete a given session value inside of the current store. func (s *store) Delete(res http.ResponseWriter, req *http.Request) error { session, err := s.handle.Get(req, s.cookieName) From 9c186df91bd625c7f499f9c175d408327d2c7f2e Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 16:02:35 -0600 Subject: [PATCH 2/7] issue #61 --- pkg/api/user/auth.go | 10 ++++++++++ pkg/api/user/get_secret.go | 5 +++++ pkg/api/user/register.go | 10 ++++++++++ pkg/api/user/user.go | 16 ---------------- 4 files changed, 25 insertions(+), 16 deletions(-) delete mode 100644 pkg/api/user/user.go diff --git a/pkg/api/user/auth.go b/pkg/api/user/auth.go index 36b51f1..cced68b 100644 --- a/pkg/api/user/auth.go +++ b/pkg/api/user/auth.go @@ -21,6 +21,11 @@ func Auth(res http.ResponseWriter, req *http.Request) bool { return false } + var userRequestData struct { + User string `json:"user"` + Pass string `json:"pass"` + } + err := json.NewDecoder(req.Body).Decode(&userRequestData) if err != nil { http.Error(res, err.Error(), http.StatusBadRequest) @@ -34,6 +39,11 @@ func Auth(res http.ResponseWriter, req *http.Request) bool { } defer ds.Close() + var userDatabaseData struct { + Pass string `json:"pass"` + Secret string `json:"secret"` + } + err = ds.Get(database.BUCKET_USERS, []byte(userRequestData.User), &userDatabaseData) if err == database.ErrKeyNotExist { diff --git a/pkg/api/user/get_secret.go b/pkg/api/user/get_secret.go index 649e979..6c8a0e9 100644 --- a/pkg/api/user/get_secret.go +++ b/pkg/api/user/get_secret.go @@ -13,6 +13,11 @@ func GetSecret(user string) (string, error) { } defer ds.Close() + var userDatabaseData struct { + Pass string `json:"pass"` + Secret string `json:"secret"` + } + err = ds.Get(database.BUCKET_USERS, []byte(user), &userDatabaseData) if err != nil { return "", err diff --git a/pkg/api/user/register.go b/pkg/api/user/register.go index 23f5f76..cd6fb8d 100644 --- a/pkg/api/user/register.go +++ b/pkg/api/user/register.go @@ -18,6 +18,11 @@ func Register(res http.ResponseWriter, req *http.Request) bool { return false } + var userRequestData struct { + User string `json:"user"` + Pass string `json:"pass"` + } + err := json.NewDecoder(req.Body).Decode(&userRequestData) if err != nil { http.Error(res, err.Error(), http.StatusBadRequest) @@ -34,6 +39,11 @@ func Register(res http.ResponseWriter, req *http.Request) bool { } defer ds.Close() + var userDatabaseData struct { + Pass string `json:"pass"` + Secret string `json:"secret"` + } + err = ds.Get(database.BUCKET_USERS, []byte(userRequestData.User), &userDatabaseData) if err != database.ErrKeyNotExist { http.Error(res, "Username already exists in the database", http.StatusBadRequest) diff --git a/pkg/api/user/user.go b/pkg/api/user/user.go deleted file mode 100644 index 2e48fd2..0000000 --- a/pkg/api/user/user.go +++ /dev/null @@ -1,16 +0,0 @@ -// Package user is a child of package api to handle api calls concerning users -package user - -// userRequestData struct is the structure of the JSON data to be -// retrieved from the authentication API request -var userRequestData struct { - User string `json:"user"` - Pass string `json:"pass"` -} - -// userDatabaseData struct is the structure of the JSON data to be retrieved from -// the bolt database inside of the user bucket, using the username as the key. -var userDatabaseData struct { - Pass string `json:"pass"` - Secret string `json:"secret"` -} From 3da84454ee875ce4f1a19356c8cf18315b074e6c Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 16:10:02 -0600 Subject: [PATCH 3/7] issue #63 --- pkg/api/server/README.md | 27 +++++++++++++++++---------- pkg/api/server/maintenance.go | 2 ++ pkg/api/server/restart.go | 2 ++ pkg/api/server/shutdown.go | 2 ++ pkg/api/server/start.go | 1 + pkg/api/server/status.go | 2 ++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pkg/api/server/README.md b/pkg/api/server/README.md index e7a4062..ae210f1 100644 --- a/pkg/api/server/README.md +++ b/pkg/api/server/README.md @@ -6,8 +6,11 @@ Relative API Path: api/server/status Request: N/A -Response(): - N/A +Response(200, 405): + "0" - OFF, + "1" - ON, + "2" - "MAINTENANCE", + "3" - "RESTARTING" */ func Status(res http.ResponseWriter, req *http.Request) bool {} @@ -16,27 +19,31 @@ Relative API Path: api/server/start Request: N/A -Response(): +Response(204, 405, 409): N/A */ func Start(res http.ResponseWriter, req *http.Request) bool {} /* Relative API Path: - api/server/Shutdown + api/server/shutdown Request: - N/A -Response(): + { + "graceful": boolean + } +Response(204, 404, 405): N/A */ func Shutdown(res http.ResponseWriter, req *http.Request) bool {} /* Relative API Path: - api/server/Restart + api/server/restart Request: - N/A -Response(): + { + "graceful": boolean + } +Response(204, 404, 405): N/A */ func Restart(res http.ResponseWriter, req *http.Request) bool {} @@ -46,7 +53,7 @@ Relative API Path: api/server/maintenance Request: N/A -Response(): +Response(204, 405): N/A */ func Maintenance(res http.ResponseWriter, req *http.Request) bool {} diff --git a/pkg/api/server/maintenance.go b/pkg/api/server/maintenance.go index 40eb7f8..d09327f 100644 --- a/pkg/api/server/maintenance.go +++ b/pkg/api/server/maintenance.go @@ -7,6 +7,8 @@ import ( "github.com/Ennovar/gPanel/pkg/public" ) +// Maintenance function is called from /api/server/maintenance and will place the public server into +// maintenance mode. func Maintenance(res http.ResponseWriter, req *http.Request, publicServer *public.Controller) bool { if req.Method != "UPDATE" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) diff --git a/pkg/api/server/restart.go b/pkg/api/server/restart.go index 9098c07..6e553ad 100644 --- a/pkg/api/server/restart.go +++ b/pkg/api/server/restart.go @@ -8,6 +8,8 @@ import ( "github.com/Ennovar/gPanel/pkg/public" ) +// Restart function is called from /api/server/restart and will attempt to shutdown, either gracefully +// or not gracefully (contingent on request data), and then turn back on the public server. func Restart(res http.ResponseWriter, req *http.Request, publicServer *public.Controller) bool { if req.Method != "UPDATE" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) diff --git a/pkg/api/server/shutdown.go b/pkg/api/server/shutdown.go index a14b880..3d6224d 100644 --- a/pkg/api/server/shutdown.go +++ b/pkg/api/server/shutdown.go @@ -8,6 +8,8 @@ import ( "github.com/Ennovar/gPanel/pkg/public" ) +// Shutdown function is called from /api/server/shutdown and will attempt to shutdown, either gracefully +// or not gracefully (contingent on request data). func Shutdown(res http.ResponseWriter, req *http.Request, publicServer *public.Controller) bool { if req.Method != "UPDATE" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) diff --git a/pkg/api/server/start.go b/pkg/api/server/start.go index 1b5c1b4..6ca1d17 100644 --- a/pkg/api/server/start.go +++ b/pkg/api/server/start.go @@ -7,6 +7,7 @@ import ( "github.com/Ennovar/gPanel/pkg/public" ) +// Start function is called from /api/server/start and turn the public server on. func Start(res http.ResponseWriter, req *http.Request, publicServer *public.Controller) bool { if req.Method != "UPDATE" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) diff --git a/pkg/api/server/status.go b/pkg/api/server/status.go index fba7927..1212937 100644 --- a/pkg/api/server/status.go +++ b/pkg/api/server/status.go @@ -8,6 +8,8 @@ import ( "github.com/Ennovar/gPanel/pkg/public" ) +// Status function is called from api/server/status and will return the current status of +// the public server. func Status(res http.ResponseWriter, req *http.Request, publicServer *public.Controller) bool { if req.Method != "GET" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) From 3f9e9687d3a538abe9ecd553c5fc6e957a64d1e7 Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 16:12:13 -0600 Subject: [PATCH 4/7] issue #64 --- document_roots/webhost/README.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/document_roots/webhost/README.md b/document_roots/webhost/README.md index 2b6c63d..249d16f 100644 --- a/document_roots/webhost/README.md +++ b/document_roots/webhost/README.md @@ -1,17 +1,3 @@ # gPanel Frontend Development -The client side, front end of gPanel. Developed using Angular, SASS, and Bootstrap. Managed with NPM package manager. - -__Note__: In the early stages of development the frontend will be static HTML/CSS/JS. Once enough progress is made it will then be translated into Angular and SASS code. - -## Contribution Set-up & Deployment - -Layout and Components -```shell -gPanel/document_roots/webhost/gPanel.html -``` - -Styles -```shell -gPanel/document_roots/webhost/styles.css -``` +In the early stages of gPanel the only technologies we will be using on the front end are HTML/CSS/JS, utilizing the jQuery, bootstrap, and font-awesome libraries respectively. The reason for doing this is to keep front end development as simple as possible in order to push development of the overall software faster. From aa01bb5707a7dd1184a39ad5e8f0ecc998a1d78a Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 16:16:52 -0600 Subject: [PATCH 5/7] issue #70 --- pkg/file/file.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/file/file.go b/pkg/file/file.go index ebef3f2..3ad480c 100644 --- a/pkg/file/file.go +++ b/pkg/file/file.go @@ -21,6 +21,10 @@ type Handler struct { append bool } +// Open function attempts to open a file and returns the handler for said file. +// This function takes a parameter append which if set to false will truncate the +// file upon writing to it. The log parameter denotes whether or not to look inside +// of the log folder when attempting to open a given file. func Open(file string, append bool, log bool) (*Handler, error) { var err error var absPath string @@ -57,6 +61,10 @@ func Open(file string, append bool, log bool) (*Handler, error) { }, nil } +// checkexistence function is ran everytime the handler has a function called from it. +// This function ensures that the file still exists whenever trying to perform various +// operations on it. The boolean parameter, createIfNotExist, if set to true, will create +// the file again if it has been deleted. func (h *Handler) checkExistence(createIfNotExist bool) (bool, error) { if _, err := os.Stat(h.path); os.IsNotExist(err) { if createIfNotExist { @@ -78,6 +86,7 @@ func (h *Handler) checkExistence(createIfNotExist bool) (bool, error) { return true, nil } +// Read function is attached to the file handler type and will read the current file. func (h *Handler) Read() ([]byte, error) { _, err := h.checkExistence(true) if err != nil { @@ -92,6 +101,7 @@ func (h *Handler) Read() ([]byte, error) { return data, err } +// Write function is attached to the file handler type and will write to the current file. func (h *Handler) Write(data string) (int, error) { _, err := h.checkExistence(true) if err != nil { @@ -106,6 +116,9 @@ func (h *Handler) Write(data string) (int, error) { return written, err } +// Close function is attached to the current file and will attempt to close the current file. +// The boolean parameter delete, if set to true, will also attempt to delete the file +// upon closing it. func (h *Handler) Close(delete bool) (error, error) { exist, _ := h.checkExistence(false) if !exist { From a45e23c6c4659a43c02d9d230e228f16786e9fc0 Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 16:25:42 -0600 Subject: [PATCH 6/7] issue #73 --- .../deleteLog.js => logs/delete.js} | 6 ++--- .../{diagnostics/viewLog.js => logs/view.js} | 6 ++--- document_roots/webhost/gPanel.html | 8 +++--- pkg/api/api_handler.go | 10 +++---- pkg/api/log/README.md | 27 +++++++++++++++++++ pkg/api/{logs => log}/delete.go | 4 ++- pkg/api/{logs => log}/read.go | 4 ++- 7 files changed, 48 insertions(+), 17 deletions(-) rename document_roots/webhost/assets/js/panelHandlers/{diagnostics/deleteLog.js => logs/delete.js} (89%) rename document_roots/webhost/assets/js/panelHandlers/{diagnostics/viewLog.js => logs/view.js} (91%) create mode 100644 pkg/api/log/README.md rename pkg/api/{logs => log}/delete.go (90%) rename pkg/api/{logs => log}/read.go (90%) diff --git a/document_roots/webhost/assets/js/panelHandlers/diagnostics/deleteLog.js b/document_roots/webhost/assets/js/panelHandlers/logs/delete.js similarity index 89% rename from document_roots/webhost/assets/js/panelHandlers/diagnostics/deleteLog.js rename to document_roots/webhost/assets/js/panelHandlers/logs/delete.js index 21b07ba..0737396 100644 --- a/document_roots/webhost/assets/js/panelHandlers/diagnostics/deleteLog.js +++ b/document_roots/webhost/assets/js/panelHandlers/logs/delete.js @@ -8,10 +8,10 @@ jQuery('._js_diagnostics-clear-log').on('click', function(e){ var title; switch(logName) { case "client_errors": - title = "Client Error Log (4xx)"; + title = "Client Error Log"; break; case "server_errors": - title = "Server Error Log (5xx)"; + title = "Server Error Log"; break; case "load_time": title = "Load Time Log"; @@ -27,7 +27,7 @@ jQuery('._js_diagnostics-clear-log').on('click', function(e){ requestData["name"] = logName+".log"; var xhr = new XMLHttpRequest(); - xhr.open('UPDATE', 'api/logs/delete', true); + xhr.open('UPDATE', 'api/log/delete', true); xhr.send(JSON.stringify(requestData)); xhr.onloadend = function() { diff --git a/document_roots/webhost/assets/js/panelHandlers/diagnostics/viewLog.js b/document_roots/webhost/assets/js/panelHandlers/logs/view.js similarity index 91% rename from document_roots/webhost/assets/js/panelHandlers/diagnostics/viewLog.js rename to document_roots/webhost/assets/js/panelHandlers/logs/view.js index d3e6bc9..423892e 100644 --- a/document_roots/webhost/assets/js/panelHandlers/diagnostics/viewLog.js +++ b/document_roots/webhost/assets/js/panelHandlers/logs/view.js @@ -8,10 +8,10 @@ jQuery('._js_diagnostics-view-log').on('click', function(e){ var title; switch(logName) { case "client_errors": - title = "Client Error Log (4xx)"; + title = "Client Error Log"; break; case "server_errors": - title = "Server Error Log (5xx)"; + title = "Server Error Log"; break; case "load_time": title = "Load Time Log"; @@ -27,7 +27,7 @@ jQuery('._js_diagnostics-view-log').on('click', function(e){ requestData["name"] = logName+".log"; var xhr = new XMLHttpRequest(); - xhr.open('POST', 'api/logs/read', true); + xhr.open('POST', 'api/log/read', true); xhr.send(JSON.stringify(requestData)); xhr.onloadend = function() { diff --git a/document_roots/webhost/gPanel.html b/document_roots/webhost/gPanel.html index 87681ca..8b0f623 100644 --- a/document_roots/webhost/gPanel.html +++ b/document_roots/webhost/gPanel.html @@ -72,8 +72,8 @@
-

Diagnostics

-
View various server data pools that may help pinpoint issues
+

Logs

+
View various client and server data logs that may help pinpoint issues
@@ -110,8 +110,8 @@ - - + + diff --git a/pkg/api/api_handler.go b/pkg/api/api_handler.go index d0f91fc..87f814f 100644 --- a/pkg/api/api_handler.go +++ b/pkg/api/api_handler.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "github.com/Ennovar/gPanel/pkg/api/logs" + "github.com/Ennovar/gPanel/pkg/api/log" "github.com/Ennovar/gPanel/pkg/api/server" "github.com/Ennovar/gPanel/pkg/api/user" "github.com/Ennovar/gPanel/pkg/public" @@ -40,10 +40,10 @@ func HandleAPI(res http.ResponseWriter, req *http.Request, path string, publicSe return true, server.Restart(res, req, publicServer) case "/server/maintenance": return true, server.Maintenance(res, req, publicServer) - case "/logs/read": - return true, logs.Read(res, req) - case "/logs/delete": - return true, logs.Delete(res, req) + case "/log/read": + return true, log.Read(res, req) + case "/log/delete": + return true, log.Delete(res, req) default: return false, false } diff --git a/pkg/api/log/README.md b/pkg/api/log/README.md new file mode 100644 index 0000000..7bcf6a0 --- /dev/null +++ b/pkg/api/log/README.md @@ -0,0 +1,27 @@ +# Log API Documentation + +```go +/* +Relative API Path: + api/log/read +Request: + { + "name": string + } +Response(200, 404, 405): + [log contents] +*/ +func Read(res http.ResponseWriter, req *http.Request) bool {} + +/* +Relative API Path: + api/log/delete +Request: + { + "name": string + } +Response(204, 404, 405): + N/A +*/ +func Delete(res http.ResponseWriter, req *http.Request) bool {} +``` diff --git a/pkg/api/logs/delete.go b/pkg/api/log/delete.go similarity index 90% rename from pkg/api/logs/delete.go rename to pkg/api/log/delete.go index cb7ecac..fc5957f 100644 --- a/pkg/api/logs/delete.go +++ b/pkg/api/log/delete.go @@ -1,5 +1,5 @@ // Package logs is a child of package api to handle api calls concerning log files -package logs +package log import ( "encoding/json" @@ -8,6 +8,8 @@ import ( "github.com/Ennovar/gPanel/pkg/file" ) +// Delete function is accessed from api/logs/delete and will attempt to +// delete a given log based off of request data. func Delete(res http.ResponseWriter, req *http.Request) bool { if req.Method != "UPDATE" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) diff --git a/pkg/api/logs/read.go b/pkg/api/log/read.go similarity index 90% rename from pkg/api/logs/read.go rename to pkg/api/log/read.go index 9f62855..74346d7 100644 --- a/pkg/api/logs/read.go +++ b/pkg/api/log/read.go @@ -1,5 +1,5 @@ // Package logs is a child of package api to handle api calls concerning log files -package logs +package log import ( "encoding/json" @@ -8,6 +8,8 @@ import ( "github.com/Ennovar/gPanel/pkg/file" ) +// Read function is accessed from api/logs/read and will attempt to read +// a given log based off of the request data. func Read(res http.ResponseWriter, req *http.Request) bool { if req.Method != "POST" { http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) From fb472d2258c17607598b5bf4997a166f27fd7254 Mon Sep 17 00:00:00 2001 From: George Shaw Date: Mon, 13 Nov 2017 16:26:28 -0600 Subject: [PATCH 7/7] generalized user request data readme --- pkg/api/user/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/api/user/README.md b/pkg/api/user/README.md index f472847..887a23a 100644 --- a/pkg/api/user/README.md +++ b/pkg/api/user/README.md @@ -6,8 +6,8 @@ Relative API Path: api/user/auth Request: { - "user": "test", - "pass": "test", + "user": string, + "pass": string, } Response(204, 400, 401, 405, 500): N/A @@ -19,8 +19,8 @@ Relative API Path: api/user/register Request: { - "user": "test", - "pass": "test", + "user": string, + "pass": string, } Response (204, 400, 405, 500): N/A