referencing issue #92

This commit is contained in:
George Shaw 2017-12-06 15:52:23 -06:00
parent cb0a9ae577
commit 242f665f1a
5 changed files with 86 additions and 1 deletions

51
pkg/api/bundle/delete.go Normal file
View file

@ -0,0 +1,51 @@
package bundle
import (
"encoding/json"
"log"
"net/http"
"os"
"strconv"
"github.com/Ennovar/gPanel/pkg/gpaccount"
)
func Delete(res http.ResponseWriter, req *http.Request, logger *log.Logger, bundles map[string]*gpaccount.Controller, dir string) bool {
if req.Method != "DELETE" {
logger.Println(req.URL.Path + "::" + req.Method + "::" + strconv.Itoa(http.StatusMethodNotAllowed) + "::" + http.StatusText(http.StatusMethodNotAllowed))
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return false
}
var rqData struct {
Name string `json:"name"`
}
err := json.NewDecoder(req.Body).Decode(&rqData)
if err != nil {
logger.Println(req.URL.Path + "::" + err.Error())
http.Error(res, err.Error(), http.StatusBadRequest)
return false
}
if _, ok := bundles[rqData.Name]; !ok {
logger.Println(req.URL.Path + ":: bundle does not exist")
http.Error(res, err.Error(), http.StatusBadRequest)
return false
}
_ = bundles[rqData.Name].Public.Stop(false)
_ = bundles[rqData.Name].Stop(false)
err = os.RemoveAll(dir)
if err != nil {
logger.Println(req.URL.Path + "::" + err.Error())
http.Error(res, err.Error(), http.StatusInternalServerError)
return false
}
delete(bundles, rqData.Name)
res.WriteHeader(http.StatusNoContent)
return true
}

View file

@ -60,6 +60,8 @@ func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request) (b
return true, logapi.Read(res, req, con.APILogger, specific.Directory)
case "/log/truncate":
return true, logapi.Truncate(res, req, con.APILogger, specific.Directory)
case "/bundle/delete":
return true, bundle.Delete(res, req, con.APILogger, con.Bundles, specific.Directory)
default:
return false, false
}

View file

@ -0,0 +1,31 @@
jQuery('._js_delete-specific-bundle').on('click', function(e){
e.preventDefault();
var bundle = jQuery('.specific-bundle-modal').attr('data');
var ensure = confirm('Are you sure you want to delete this bundle? This action CANNOT be undone.');
if(ensure) {
var requestData = {};
requestData["name"] = bundle;
requestData["bundle_name"] = bundle;
var xhr = new XMLHttpRequest();
xhr.open('DELETE', 'api/bundle/delete', true);
xhr.send(JSON.stringify(requestData));
xhr.onloadend = function() {
if(xhr.status == 204) {
alert('Bundle \"' + bundle + '\" has been successfully deleted.');
jQuery('.specific-bundle-modal').modal('hide');
}
else {
if(xhr.response != undefined && xhr.response.length != 0) {
alert('Error: ' + xhr.response);
}
else {
alert('An error has occurred. Please refresh and try again. If error persists please contact your administrator.');
}
}
}
}
});

View file

@ -5,7 +5,6 @@ function getPublicServerStatus(name) {
var requestData = {};
requestData["bundle_name"] = name;
console.log(requestData);
xhr.open('POST', 'api/server/status', true);
xhr.send(JSON.stringify(requestData));

View file

@ -151,6 +151,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-warning _js_back-to-bundle-menu">Back to Bundle Menu</button>
<button type="button" class="btn btn-danger _js_delete-specific-bundle">Delete Bundle</button>
</div>
</div>
</div>
@ -424,6 +425,7 @@
<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>
<script type="text/javascript" src="assets/js/panelHandlers/bundles/specific/delete.js"></script>
<script type="text/javascript" src="assets/js/panelHandlers/log/view.js"></script>
<script type="text/javascript" src="assets/js/panelHandlers/log/delete.js"></script>