Skip to content

Commit

Permalink
finish imunifyav
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Aug 18, 2020
1 parent 67842a7 commit 4b1f76c
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 1 deletion.
49 changes: 49 additions & 0 deletions CLManager/CageFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,53 @@ def submitinstallImunify(key):
except BaseException as msg:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)

@staticmethod
def submitinstallImunifyAV():
try:


mailUtilities.checkHome()

statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')

logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
"Starting ImunifyAV Installation..\n", 1)

##

command = 'mkdir -p /etc/sysconfig/imunify360'
ServerStatusUtil.executioner(command, statusFile)


integrationFile = '/etc/sysconfig/imunify360/integration.conf'

content = """[paths]
ui_path = /usr/local/CyberCP/public/imunifyav
ui_path_owner = lscpd:lscpd
"""

writeToFile = open(integrationFile, 'w')
writeToFile.write(content)
writeToFile.close()

##

if not os.path.exists('imav-deploy.sh'):
command = 'wget https://repo.imunify360.cloudlinux.com/defence360/imav-deploy.sh'
ServerStatusUtil.executioner(command, statusFile)

command = 'bash imav-deploy.sh'
ServerStatusUtil.executioner(command, statusFile)

logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
"ImunifyAV reinstalled..\n", 1)

logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
"Packages successfully installed.[200]\n", 1)

except BaseException as msg:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)

def main():

parser = argparse.ArgumentParser(description='CyberPanel CageFS Manager')
Expand All @@ -193,6 +240,8 @@ def main():
CageFS.submitCageFSInstall()
elif args["function"] == "submitinstallImunify":
CageFS.submitinstallImunify(args["key"])
elif args["function"] == "submitinstallImunifyAV":
CageFS.submitinstallImunifyAV()



Expand Down
3 changes: 3 additions & 0 deletions baseTemplate/templates/baseTemplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@
<li><a href="{% url 'imunify' %}"
title="{% trans 'Imunify 360' %}"><span>{% trans "Imunify 360" %}</span></a>
</li>
<li><a href="{% url 'imunifyAV' %}"
title="{% trans 'ImunifyAV' %}"><span>{% trans "ImunifyAV" %}</span></a>
</li>
</ul>

</div><!-- .sidebar-submenu -->
Expand Down
65 changes: 64 additions & 1 deletion firewall/firewallManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FirewallManager:

imunifyPath = '/usr/bin/imunify360-agent'
CLPath = '/etc/sysconfig/cloudlinux'
imunifyAVPath = '/etc/sysconfig/imunify360/integration.conf'

def __init__(self, request = None):
self.request = request
Expand Down Expand Up @@ -1561,8 +1562,10 @@ def imunify(self):
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]

fullAddress = '%s:%s' % (ipAddress, ProcessUtilities.fetchCurrentPort())

data = {}
data['ipAddress'] = ipAddress
data['ipAddress'] = fullAddress

if os.path.exists(FirewallManager.CLPath):
data['CL'] = 1
Expand Down Expand Up @@ -1610,3 +1613,63 @@ def submitinstallImunify(self):

except BaseException as msg:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)

def imunifyAV(self):
try:
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()

ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]

fullAddress = '%s:%s' % (ipAddress, ProcessUtilities.fetchCurrentPort())

data = {}
data['ipAddress'] = fullAddress



if os.path.exists(FirewallManager.imunifyAVPath):
data['imunify'] = 1
else:
data['imunify'] = 0

if data['imunify'] == 0:
return render(self.request, 'firewall/notAvailableAV.html', data)
else:
return render(self.request, 'firewall/imunifyAV.html', data)


except BaseException as msg:
return HttpResponse(str(msg))

def submitinstallImunifyAV(self):
try:
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
'Not authorized to install container packages. [404].',
1)
return 0

execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/CLManager/CageFS.py"
execPath = execPath + " --function submitinstallImunifyAV"
ProcessUtilities.popenExecutioner(execPath)

data_ret = {'status': 1, 'error_message': 'None'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

except BaseException as msg:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
99 changes: 99 additions & 0 deletions firewall/static/firewall/firewall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,105 @@ app.controller('installImunify', function ($scope, $http, $timeout, $window) {
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);


function ListInitialDatas(response) {
if (response.data.abort === 0) {
$scope.requestData = response.data.requestStatus;
$timeout(getRequestStatus, 1000);
} else {
// Notifications
$scope.installDockerStatus = true;
$timeout.cancel();
$scope.requestData = response.data.requestStatus;
if (response.data.installed === 1) {
$timeout(function () {
$window.location.reload();
}, 3000);
}

}
}

function cantLoadInitialDatas(response) {
$scope.installDockerStatus = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}

}
});

/* ImunifyAV */

app.controller('installImunifyAV', function ($scope, $http, $timeout, $window) {

$scope.installDockerStatus = true;
$scope.installBoxGen = true;
$scope.dockerInstallBTN = false;

$scope.submitinstallImunify = function () {

$scope.installDockerStatus = false;
$scope.installBoxGen = true;
$scope.dockerInstallBTN = true;

url = "/firewall/submitinstallImunifyAV";

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.status === 1) {
$scope.installBoxGen = false;
getRequestStatus();
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}

}

function cantLoadInitialDatas(response) {
$scope.cyberPanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}

};

function getRequestStatus() {
$scope.installDockerStatus = false;

url = "/serverstatus/switchTOLSWSStatus";

var data = {};

var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};


$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);


function ListInitialDatas(response) {
if (response.data.abort === 0) {
$scope.requestData = response.data.requestStatus;
Expand Down
41 changes: 41 additions & 0 deletions firewall/templates/firewall/imunifyAV.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "ImunifyAV - CyberPanel" %}{% endblock %}
{% block content %}

{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->


<div class="container">
<div id="page-title">
<h2>{% trans "ImunifyAV" %} - <a target="_blank"
href="https://go.cyberpanel.net/imunify"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "Imunify Docs" %}</span></a></h2>
<p>{% trans "Access ImunifyAV" %}</p>
</div>

<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "ImunifyAV" %}
</h3>
<div class="example-box-wrapper">

<p>{% trans "ImunifyAV is now integrated via their new API. You can manage Imunify by clicking below. You can use your server root credentials to access Imunify." %}</p>
<br>
<a target="_blank" href="http://{{ ipAddress }}/imunifyav">
<button class="btn btn-primary">Access Now
</button>
</a>

</div>
</div>
</div>

</div>
{% endblock %}

69 changes: 69 additions & 0 deletions firewall/templates/firewall/notAvailableAV.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Not available - CyberPanel" %}{% endblock %}
{% block content %}

{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->


<div class="container">
<div id="page-title">
<h2>{% trans "Not available" %} - <a target="_blank"
href="https://go.cyberpanel.net/imunify"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "ImunifyAV Docs" %}</span></a></h2>
<p>{% trans "ImunifyAV is not installed" %}</p>
</div>

<div ng-controller="installImunifyAV" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Activate Now" %} <img ng-hide="installDockerStatus"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">

<p>{% trans "Imunify is not installed, click to install now." %}</p>
<!------ LSWS Switch box ----------------->

<div style="margin-top: 2%" ng-hide="installBoxGen" class="col-md-12">

<form action="/" id="" class="form-horizontal bordered-row">

<div class="form-group">
<div style="margin-top: 2%;" class="col-sm-12">
<textarea ng-model="requestData" rows="15"
class="form-control">{{ requestData }}</textarea>
</div>
</div>
</form>
</div>


<!----- LSWS Switch box ----------------->
<br>

<form action="/" id="" class="form-horizontal bordered-row">

<div ng-hide="dockerInstallBTN" ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<button type="button" class="btn btn-primary"
ng-click="submitinstallImunify()">
Install Now
</button>
</div>
</div>

</form>

</div>
</div>
</div>

</div>
{% endblock %}

5 changes: 5 additions & 0 deletions firewall/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
url(r'^imunify$', views.imunify, name='imunify'),
url(r'^submitinstallImunify$', views.submitinstallImunify, name='submitinstallImunify'),

## ImunifyAV

url(r'^imunifyAV$', views.imunifyAV, name='imunifyAV'),
url(r'^submitinstallImunifyAV$', views.submitinstallImunifyAV, name='submitinstallImunifyAV'),




Expand Down
Loading

0 comments on commit 4b1f76c

Please sign in to comment.