setup service manager to install applications

This commit is contained in:
Usman Nasir
2020-08-19 22:35:46 +05:00
parent 928acec39c
commit 84b2411a6e
5 changed files with 135 additions and 44 deletions

View File

@@ -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()

View File

@@ -11,7 +11,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
$scope.couldNotConnect = true;
$scope.changesApplied = true;
$scope.slaveIPs = true;
$scope.masterServerHD = true;
$scope.masterServerHD = true;
var pdnsStatus = false;
@@ -21,6 +21,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
});
fetchPDNSStatus('powerdns');
function fetchPDNSStatus(service) {
$scope.pdnsLoading = false;
@@ -99,7 +100,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
slaveServer3: $scope.slaveServer3,
slaveServerIP3: $scope.slaveServerIP3,
};
}else {
} else {
var data = {
status: pdnsStatus,
service: service
@@ -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;
@@ -149,14 +149,14 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
$scope.modeChange = function () {
if ($scope.dnsMode === 'MASTER') {
$scope.slaveIPs = false;
$scope.masterServerHD = true;
$scope.masterServerHD = true;
} else if($scope.dnsMode == 'SLAVE') {
} else if ($scope.dnsMode == 'SLAVE') {
$scope.slaveIPs = true;
$scope.masterServerHD = false;
}else{
$scope.masterServerHD = false;
} else {
$scope.slaveIPs = true;
$scope.masterServerHD = true;
$scope.masterServerHD = true;
}
}
@@ -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,39 +456,74 @@ 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'
});
}
}
});

View File

@@ -62,7 +62,7 @@
<button type="button" class="close" data-dismiss="modal">
&times;
</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>

View File

@@ -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'),
]

View File

@@ -331,4 +331,33 @@ def manageApplications(request):
return HttpResponse("See CyberCP main log file.")
except KeyError:
return redirect(loadLoginPage)
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)