mirror of
https://github.com/donl/gPanel.git
synced 2026-06-30 06:12:06 -06:00
Merge pull request #83 from george-e-shaw-iv/master
Account Management from Server gPanel is working
This commit is contained in:
commit
e8a5251f7e
6 changed files with 86 additions and 5 deletions
|
|
@ -11,7 +11,7 @@ import (
|
|||
// 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" {
|
||||
if req.Method != "GET" && req.Method != "POST" {
|
||||
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,19 @@
|
|||
package gpserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/Ennovar/gPanel/pkg/api/bundle"
|
||||
"github.com/Ennovar/gPanel/pkg/api/log"
|
||||
"github.com/Ennovar/gPanel/pkg/api/server"
|
||||
"github.com/Ennovar/gPanel/pkg/api/user"
|
||||
)
|
||||
|
||||
func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request, curBundle int) (bool, bool) {
|
||||
func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request) (bool, bool) {
|
||||
path := req.URL.Path[1:]
|
||||
if len(path) == 0 {
|
||||
path = (con.Directory + "index.html")
|
||||
|
|
@ -21,6 +25,34 @@ func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request, cu
|
|||
splitUrl := strings.SplitN(path, "api", 2)
|
||||
suspectApi := strings.ToLower(splitUrl[len(splitUrl)-1])
|
||||
|
||||
if req.ContentLength > 0 {
|
||||
var bundleRequestData struct {
|
||||
BName string `json:"bundle_name,omitempty"`
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
|
||||
b1 := ioutil.NopCloser(bytes.NewBuffer(buf))
|
||||
req.Body = ioutil.NopCloser(bytes.NewBuffer(buf))
|
||||
|
||||
err = json.NewDecoder(b1).Decode(&bundleRequestData)
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
|
||||
if specific, ok := con.Bundles[bundleRequestData.BName]; ok {
|
||||
switch suspectApi {
|
||||
case "/server/status":
|
||||
return true, server.Status(res, req, specific.Public)
|
||||
default:
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch suspectApi {
|
||||
case "/user/auth":
|
||||
return true, user.Auth(res, req, con.Directory)
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func (con *Controller) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
isApi, _ := con.apiHandler(res, req, 0)
|
||||
isApi, _ := con.apiHandler(res, req)
|
||||
|
||||
if isApi {
|
||||
// API methods handle HTTP logic from here
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
var specificBundleModal = jQuery('.specific-bundle-modal');
|
||||
|
||||
jQuery(document).on('click', '._js_specific-bundle', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var name = jQuery(this).attr('data');
|
||||
|
||||
jQuery('.manage-bundles-modal').modal('hide');
|
||||
jQuery('.specific-bundle-modal').find('.modal-title').html("Bundle \"" + name + "\" Management");
|
||||
jQuery('.specific-bundle-modal').modal('show');
|
||||
specificBundleModal.find('.modal-title').html("Bundle \"" + name + "\" Management");
|
||||
specificBundleModal.attr('data', name);
|
||||
|
||||
getPublicServerStatus(name);
|
||||
|
||||
specificBundleModal.modal('show');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
var statusSpan = jQuery("._js_specific-bundle-public-status");
|
||||
|
||||
function getPublicServerStatus(name) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
var requestData = {};
|
||||
requestData["bundle_name"] = name;
|
||||
console.log(requestData);
|
||||
|
||||
xhr.open('POST', 'api/server/status', true);
|
||||
xhr.send(JSON.stringify(requestData));
|
||||
|
||||
xhr.onloadend = function() {
|
||||
if(xhr.status == 200) {
|
||||
statusSpan.attr('class', '_js_specific-bundle-public-status');
|
||||
|
||||
switch(parseInt(xhr.response)) {
|
||||
case 0:
|
||||
statusSpan.addClass('text-danger').html("OFF");
|
||||
break;
|
||||
case 1:
|
||||
statusSpan.addClass('text-success').html("ON");
|
||||
break;
|
||||
case 2:
|
||||
statusSpan.addClass('text-warning').html("MAINTENANCE");
|
||||
break;
|
||||
case 3:
|
||||
statusSpan.addClass('text-info').html("RESTARTING");
|
||||
break;
|
||||
default:
|
||||
console.log(xhr.response);
|
||||
statusSpan.addClass('text-danger').html('ERROR');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log(xhr.response);
|
||||
statusSpan.attr('class', '_js_specific-bundle-public-status').addClass('text-danger').html('ERROR');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -229,6 +229,8 @@
|
|||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/create.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/manage.js"></script>
|
||||
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/specific/server/status.js"></script>
|
||||
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/specific/open.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/specific/back.js"></script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue