mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
setup service manager to install applications
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import subprocess, shlex
|
||||
from random import randint
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
from dns.models import Supermasters
|
||||
from manageServices.models import SlaveServers
|
||||
import argparse
|
||||
from serverStatus.serverStatusUtil import ServerStatusUtil
|
||||
|
||||
class ServiceManager:
|
||||
|
||||
@@ -125,3 +126,27 @@ superslave=yes
|
||||
|
||||
Supermasters(ip=self.extraArgs['masterServerIP'], nameserver=self.extraArgs['slaveServerNS'], account='').save()
|
||||
|
||||
@staticmethod
|
||||
def installElasticSearch():
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Packages successfully installed.[200]\n", 1)
|
||||
return 0
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description='CyberPanel Application Manager')
|
||||
parser.add_argument('--function', help='Function')
|
||||
|
||||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
if args["function"] == "InstallElasticSearch":
|
||||
ServiceManager.InstallElasticSearch()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
|
||||
});
|
||||
|
||||
fetchPDNSStatus('powerdns');
|
||||
|
||||
function fetchPDNSStatus(service) {
|
||||
|
||||
$scope.pdnsLoading = false;
|
||||
@@ -125,8 +126,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.changesApplied = false;
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
$scope.failedToFetch = false;
|
||||
@@ -182,6 +182,7 @@ app.controller('postfix', function ($scope, $http, $timeout, $window) {
|
||||
});
|
||||
|
||||
fetchPDNSStatus('postfix');
|
||||
|
||||
function fetchPDNSStatus(service) {
|
||||
|
||||
$scope.serviceLoading = false;
|
||||
@@ -269,8 +270,7 @@ app.controller('postfix', function ($scope, $http, $timeout, $window) {
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.changesApplied = false;
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
$scope.failedToFetch = false;
|
||||
@@ -312,6 +312,7 @@ app.controller('pureFTPD', function ($scope, $http, $timeout, $window) {
|
||||
});
|
||||
|
||||
fetchPDNSStatus('pureftpd');
|
||||
|
||||
function fetchPDNSStatus(service) {
|
||||
|
||||
$scope.serviceLoading = false;
|
||||
@@ -399,8 +400,7 @@ app.controller('pureFTPD', function ($scope, $http, $timeout, $window) {
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.changesApplied = false;
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
$scope.failedToFetch = false;
|
||||
@@ -428,19 +428,20 @@ app.controller('pureFTPD', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
app.controller('manageApplications', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
|
||||
$scope.cyberpanelLoading = true;
|
||||
|
||||
$scope.saveStatus = function (service) {
|
||||
$scope.removeInstall = function (appName, status) {
|
||||
|
||||
$scope.status = status;
|
||||
$scope.appName = appName;
|
||||
|
||||
$scope.cyberpanelLoading = false;
|
||||
|
||||
|
||||
url = "/manageservices/saveStatus";
|
||||
url = "/manageservices/removeInstall";
|
||||
|
||||
var data = {
|
||||
status: serviceStatus,
|
||||
service: service
|
||||
appName: appName,
|
||||
status: status
|
||||
};
|
||||
|
||||
var config = {
|
||||
@@ -455,40 +456,75 @@ app.controller('manageApplications', function ($scope, $http, $timeout, $window)
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberpanelLoading = true;
|
||||
|
||||
if (response.data.status === 1) {
|
||||
|
||||
$scope.failedToFetch = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.changesApplied = false;
|
||||
|
||||
}
|
||||
else {
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
$scope.failedToFetch = false;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.changesApplied = true;
|
||||
getRequestStatus();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.serviceLoading = true;
|
||||
$scope.failedToFetch = true;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.changesApplied = true;
|
||||
$scope.cyberpanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.removeInstall = function (appName, status) {
|
||||
$scope.status = status;
|
||||
$scope.appName = appName;
|
||||
function getRequestStatus() {
|
||||
$scope.cyberpanelLoading = false;
|
||||
|
||||
url = "/serverstatus/switchTOLSWSStatus";
|
||||
|
||||
var data = {};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberpanelLoading = true;
|
||||
if (response.data.abort === 0) {
|
||||
$scope.requestData = response.data.requestStatus;
|
||||
$timeout(getRequestStatus, 1000);
|
||||
} else {
|
||||
// Notifications
|
||||
$timeout.cancel();
|
||||
$scope.requestData = response.data.requestStatus;
|
||||
if (response.data.installed === 1) {
|
||||
$timeout(function () {
|
||||
$window.location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.cyberpanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Java script code */
|
||||
@@ -62,7 +62,7 @@
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
×
|
||||
</button>
|
||||
<h4 class="modal-title">{$ status $} {$ appName $} ...
|
||||
<h4 class="modal-title">{$ status $} {$ appName $} ... <img ng-hide="cyberpanelLoading" src="{% static 'images/loading.gif' %}">
|
||||
<img ng-hide="cyberpanelLoading"
|
||||
src="{% static 'images/loading.gif' %}">
|
||||
</h4>
|
||||
|
||||
@@ -11,4 +11,5 @@ urlpatterns = [
|
||||
url(r'^saveStatus$', views.saveStatus, name='saveStatus'),
|
||||
|
||||
url(r'^manageApplications$', views.manageApplications, name='manageApplications'),
|
||||
url(r'^removeInstall$', views.removeInstall, name='removeInstall'),
|
||||
]
|
||||
@@ -332,3 +332,32 @@ def manageApplications(request):
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def removeInstall(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
|
||||
status = data['status']
|
||||
service = data['service']
|
||||
|
||||
command = '/usr/local/CyberCP/manageServices/serviceManager.py --function InstallElasticSearch'
|
||||
|
||||
|
||||
except BaseException as msg:
|
||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
Reference in New Issue
Block a user