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 random import randint
from plogical.processUtilities import ProcessUtilities from plogical.processUtilities import ProcessUtilities
from dns.models import Supermasters from dns.models import Supermasters
from manageServices.models import SlaveServers from manageServices.models import SlaveServers
import argparse
from serverStatus.serverStatusUtil import ServerStatusUtil
class ServiceManager: class ServiceManager:
@@ -125,3 +126,27 @@ superslave=yes
Supermasters(ip=self.extraArgs['masterServerIP'], nameserver=self.extraArgs['slaveServerNS'], account='').save() 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

@@ -21,6 +21,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
}); });
fetchPDNSStatus('powerdns'); fetchPDNSStatus('powerdns');
function fetchPDNSStatus(service) { function fetchPDNSStatus(service) {
$scope.pdnsLoading = false; $scope.pdnsLoading = false;
@@ -125,8 +126,7 @@ app.controller('powerDNS', function ($scope, $http, $timeout, $window) {
$scope.couldNotConnect = true; $scope.couldNotConnect = true;
$scope.changesApplied = false; $scope.changesApplied = false;
} } else {
else {
$scope.errorMessage = response.data.error_message; $scope.errorMessage = response.data.error_message;
$scope.failedToFetch = false; $scope.failedToFetch = false;
@@ -182,6 +182,7 @@ app.controller('postfix', function ($scope, $http, $timeout, $window) {
}); });
fetchPDNSStatus('postfix'); fetchPDNSStatus('postfix');
function fetchPDNSStatus(service) { function fetchPDNSStatus(service) {
$scope.serviceLoading = false; $scope.serviceLoading = false;
@@ -269,8 +270,7 @@ app.controller('postfix', function ($scope, $http, $timeout, $window) {
$scope.couldNotConnect = true; $scope.couldNotConnect = true;
$scope.changesApplied = false; $scope.changesApplied = false;
} } else {
else {
$scope.errorMessage = response.data.error_message; $scope.errorMessage = response.data.error_message;
$scope.failedToFetch = false; $scope.failedToFetch = false;
@@ -312,6 +312,7 @@ app.controller('pureFTPD', function ($scope, $http, $timeout, $window) {
}); });
fetchPDNSStatus('pureftpd'); fetchPDNSStatus('pureftpd');
function fetchPDNSStatus(service) { function fetchPDNSStatus(service) {
$scope.serviceLoading = false; $scope.serviceLoading = false;
@@ -399,8 +400,7 @@ app.controller('pureFTPD', function ($scope, $http, $timeout, $window) {
$scope.couldNotConnect = true; $scope.couldNotConnect = true;
$scope.changesApplied = false; $scope.changesApplied = false;
} } else {
else {
$scope.errorMessage = response.data.error_message; $scope.errorMessage = response.data.error_message;
$scope.failedToFetch = false; $scope.failedToFetch = false;
@@ -428,19 +428,20 @@ app.controller('pureFTPD', function ($scope, $http, $timeout, $window) {
app.controller('manageApplications', function ($scope, $http, $timeout, $window) { app.controller('manageApplications', function ($scope, $http, $timeout, $window) {
$scope.cyberpanelLoading = true; $scope.cyberpanelLoading = true;
$scope.saveStatus = function (service) { $scope.removeInstall = function (appName, status) {
$scope.status = status;
$scope.appName = appName;
$scope.cyberpanelLoading = false; $scope.cyberpanelLoading = false;
url = "/manageservices/removeInstall";
url = "/manageservices/saveStatus";
var data = { var data = {
status: serviceStatus, appName: appName,
service: service status: status
}; };
var config = { var config = {
@@ -455,40 +456,75 @@ app.controller('manageApplications', function ($scope, $http, $timeout, $window)
function ListInitialDatas(response) { function ListInitialDatas(response) {
$scope.cyberpanelLoading = true; $scope.cyberpanelLoading = true;
if (response.data.status === 1) { if (response.data.status === 1) {
getRequestStatus();
$scope.failedToFetch = true; } else {
$scope.couldNotConnect = true; new PNotify({
$scope.changesApplied = false; title: 'Operation Failed!',
text: response.data.error_message,
} type: 'error'
else { });
$scope.errorMessage = response.data.error_message;
$scope.failedToFetch = false;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
} }
} }
function cantLoadInitialDatas(response) { function cantLoadInitialDatas(response) {
$scope.serviceLoading = true; $scope.cyberpanelLoading = true;
$scope.failedToFetch = true; new PNotify({
$scope.couldNotConnect = false; title: 'Operation Failed!',
$scope.changesApplied = true; text: 'Could not connect to server, please refresh this page',
type: 'error'
});
} }
}; };
$scope.removeInstall = function (appName, status) { function getRequestStatus() {
$scope.status = status; $scope.cyberpanelLoading = false;
$scope.appName = appName;
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 */ /* Java script code */

View File

@@ -62,7 +62,7 @@
<button type="button" class="close" data-dismiss="modal"> <button type="button" class="close" data-dismiss="modal">
&times; &times;
</button> </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" <img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}"> src="{% static 'images/loading.gif' %}">
</h4> </h4>

View File

@@ -11,4 +11,5 @@ urlpatterns = [
url(r'^saveStatus$', views.saveStatus, name='saveStatus'), url(r'^saveStatus$', views.saveStatus, name='saveStatus'),
url(r'^manageApplications$', views.manageApplications, name='manageApplications'), url(r'^manageApplications$', views.manageApplications, name='manageApplications'),
url(r'^removeInstall$', views.removeInstall, name='removeInstall'),
] ]

View File

@@ -332,3 +332,32 @@ def manageApplications(request):
except KeyError: 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)