mirror of
https://github.com/donl/gPanel.git
synced 2026-06-30 06:12:06 -06:00
server finds existing bundles on startup and is able to list them in the backend now
This commit is contained in:
parent
0407be5573
commit
66266f24a5
9 changed files with 169 additions and 14 deletions
|
|
@ -171,8 +171,8 @@
|
|||
<script type="text/javascript" src="assets/js/panelHandlers/publicServer/shutdown.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/publicServer/restart.js"></script>
|
||||
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/logs/view.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/logs/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>
|
||||
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/security/ipFiltering.js"></script>
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
|
|
|
|||
|
|
@ -79,19 +79,20 @@ func Create(res http.ResponseWriter, req *http.Request, bundles map[string]*gpac
|
|||
}
|
||||
defer ds.Close()
|
||||
|
||||
err = ds.Put(database.BUCKET_PORTS, []byte("account"), createBundleRequestData.AccPort)
|
||||
var databaseBundlePorts struct {
|
||||
Account int `json:"account"`
|
||||
Public int `json:"public"`
|
||||
}
|
||||
databaseBundlePorts.Account = createBundleRequestData.AccPort
|
||||
databaseBundlePorts.Public = createBundleRequestData.PubPort
|
||||
|
||||
err = ds.Put(database.BUCKET_PORTS, []byte("bundle_ports"), databaseBundlePorts)
|
||||
if err != nil {
|
||||
http.Error(res, err.Error(), http.StatusBadRequest)
|
||||
return false
|
||||
}
|
||||
|
||||
err = ds.Put(database.BUCKET_PORTS, []byte("public"), createBundleRequestData.PubPort)
|
||||
if err != nil {
|
||||
http.Error(res, err.Error(), http.StatusBadRequest)
|
||||
return false
|
||||
}
|
||||
|
||||
bundles[createBundleRequestData.Name] = gpaccount.New(newBundle+"/", createBundleRequestData.AccPort, createBundleRequestData.PubPort)
|
||||
bundles[createBundleRequestData.Name] = gpaccount.New(newBundle+"/", databaseBundlePorts.Account, databaseBundlePorts.Public)
|
||||
_ = bundles[createBundleRequestData.Name].Start()
|
||||
_ = bundles[createBundleRequestData.Name].Public.Start()
|
||||
|
||||
|
|
|
|||
37
pkg/api/bundle/list.go
Normal file
37
pkg/api/bundle/list.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package bundle
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/Ennovar/gPanel/pkg/gpaccount"
|
||||
)
|
||||
|
||||
func List(res http.ResponseWriter, req *http.Request, bundles map[string]*gpaccount.Controller) bool {
|
||||
if req.Method != "GET" {
|
||||
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(bundles) <= 0 {
|
||||
res.WriteHeader(http.StatusNoContent)
|
||||
return true
|
||||
}
|
||||
|
||||
keys := make([]string, 0, len(bundles))
|
||||
for key := range bundles {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(keys)
|
||||
if err != nil {
|
||||
http.Error(res, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return false
|
||||
}
|
||||
|
||||
res.WriteHeader(http.StatusOK)
|
||||
res.Header().Set("Content-Type", "application/json")
|
||||
res.Write(jsonData)
|
||||
|
||||
return true
|
||||
}
|
||||
31
pkg/api/bundle/ports.go
Normal file
31
pkg/api/bundle/ports.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package bundle
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/Ennovar/gPanel/pkg/database"
|
||||
)
|
||||
|
||||
func GetPorts(dir string) (error, int, int) {
|
||||
if _, err := os.Stat(dir + "datastore.db"); os.IsNotExist(err) {
|
||||
return err, 0, 0
|
||||
}
|
||||
|
||||
ds, err := database.Open(dir + database.DB_MAIN)
|
||||
if err != nil {
|
||||
return err, 0, 0
|
||||
}
|
||||
defer ds.Close()
|
||||
|
||||
var databaseBundlePorts struct {
|
||||
Account int `json:"account"`
|
||||
Public int `json:"public"`
|
||||
}
|
||||
|
||||
err = ds.Get(database.BUCKET_PORTS, []byte("bundle_ports"), &databaseBundlePorts)
|
||||
if err != nil {
|
||||
return err, 0, 0
|
||||
}
|
||||
|
||||
return nil, databaseBundlePorts.Account, databaseBundlePorts.Public
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
package gpaccount
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -80,7 +79,6 @@ func (con *Controller) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|||
|
||||
if err != nil {
|
||||
// con.ServerLogger.Write(path + "::" + strconv.Itoa(http.StatusNotFound) + "::" + err.Error())
|
||||
fmt.Println(err.Error())
|
||||
routing.HttpThrowStatus(http.StatusNotFound, res)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request, cu
|
|||
return true, user.Logout(res, req, con.Directory)
|
||||
case "/bundle/create":
|
||||
return true, bundle.Create(res, req, con.Bundles)
|
||||
case "/bundle/list":
|
||||
return true, bundle.List(res, req, con.Bundles)
|
||||
default:
|
||||
return false, false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@ package gpserver
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Ennovar/gPanel/pkg/api/bundle"
|
||||
"github.com/Ennovar/gPanel/pkg/gpaccount"
|
||||
"github.com/Ennovar/gPanel/pkg/routing"
|
||||
)
|
||||
|
|
@ -17,10 +21,38 @@ type Controller struct {
|
|||
}
|
||||
|
||||
func New() *Controller {
|
||||
bundles := make(map[string]*gpaccount.Controller)
|
||||
|
||||
dirs, err := ioutil.ReadDir("bundles/")
|
||||
if err != nil {
|
||||
log.Fatal("Error finding bundles: %v\n", err.Error())
|
||||
}
|
||||
|
||||
for _, dir := range dirs {
|
||||
if dir.Name() == "default_bundle" || !dir.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(dir.Name(), "bundle_") {
|
||||
dirPath := "bundles/" + dir.Name() + "/"
|
||||
err, accPort, pubPort := bundle.GetPorts(dirPath)
|
||||
|
||||
curBundle := gpaccount.New(dirPath, accPort, pubPort)
|
||||
|
||||
err = curBundle.Start()
|
||||
err2 := curBundle.Public.Start()
|
||||
if err != nil || err2 != nil {
|
||||
log.Fatal("Error starting bundle: %v\n", dir.Name())
|
||||
}
|
||||
|
||||
bundles[strings.Replace(dir.Name(), "bundle_", "", 1)] = curBundle
|
||||
}
|
||||
}
|
||||
|
||||
return &Controller{
|
||||
Directory: "server/",
|
||||
DocumentRoot: "document_root/",
|
||||
Bundles: make(map[string]*gpaccount.Controller),
|
||||
Bundles: bundles,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
manageBundlesModal = jQuery(".manage-bundles-modal");
|
||||
|
||||
jQuery('._js_bundles-manage').on('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'api/bundle/list', true);
|
||||
xhr.send();
|
||||
|
||||
xhr.onloadend = function() {
|
||||
if(xhr.status == 200) {
|
||||
if(xhr.response != undefined && xhr.response.length != 0) {
|
||||
manageBundlesModal.find('.modal-body').html(xhr.response)
|
||||
}
|
||||
else {
|
||||
manageBundlesModal.find('.modal-body').html("An error has occurred. Please try again. If problem persists contact server administrator.")
|
||||
}
|
||||
manageBundlesModal.modal('show');
|
||||
}
|
||||
else if(xhr.status == 204) {
|
||||
manageBundlesModal.modal('show');
|
||||
}
|
||||
else {
|
||||
if(xhr.response != undefined && xhr.response.length != 0) {
|
||||
manageBundlesModal.find('.modal-body').html(xhr.response)
|
||||
}
|
||||
else {
|
||||
manageBundlesModal.find('.modal-body').html(xhr.status + " Error!")
|
||||
}
|
||||
manageBundlesModal.modal('show');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -64,6 +64,26 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Manage Existing Bundles Modal -->
|
||||
<div class="modal fade manage-bundles-modal" tabindex="-1" role="dialog" aria-labelledby="manage-bundles-modal" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Manage Existing Bundles</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>No bundles current exist on the server.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
|
@ -73,7 +93,7 @@
|
|||
<h6 class="card-subtitle mb-4 text-muted">Create new bundles and update current bundles.</h6>
|
||||
<div class="btn-group" role="group">
|
||||
<button class="btn btn-outline-primary _js_bundles-create">Create New Bundle</button>
|
||||
<button class="btn btn-outline-primary">Manage Current Bundles</button>
|
||||
<button class="btn btn-outline-primary _js_bundles-manage">Manage Current Bundles</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -103,6 +123,7 @@
|
|||
<script type="text/javascript" src="assets/js/formHandlers/logout.js"></script>
|
||||
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/create.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/bundles/manage.js"></script>
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue