Enable Disable FTP Service.

This commit is contained in:
usmannasir
2018-07-23 22:11:42 +05:00
parent d54e05ec4c
commit e62c9f7d1c
13 changed files with 589 additions and 12 deletions

View File

@@ -566,6 +566,23 @@
</li> </li>
<li id="normalUserJ">
<a href="#" title="{% trans 'Manage Services' %}">
<i class="glyph-icon icon-linecons-fire"></i>
<span>{% trans "Manage Services" %}</span>
</a>
<div class="sidebar-submenu">
<ul>
<li><a href="{% url 'managePowerDNS' %}" title="{% trans 'Manage PowerDNS' %}"><span>{% trans "Manage PowerDNS" %}</span></a></li>
<li><a href="{% url 'managePostfix' %}" title="{% trans 'Manage Postfix' %}"><span>{% trans "Manage Postfix" %}</span></a></li>
<li><a href="{% url 'managePureFtpd' %}" title="{% trans 'Manage FTP' %}"><span>{% trans "Manage FTP" %}</span></a></li>
</ul>
</div><!-- .sidebar-submenu -->
</li>
</ul><!-- #sidebar-menu --> </ul><!-- #sidebar-menu -->

View File

@@ -20,6 +20,18 @@
</h3> </h3>
<div class="example-box-wrapper"> <div class="example-box-wrapper">
{% if not status %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "PureFTPD is disabled." %}
<a href="{% url 'managePureFtpd' %}"><button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Enable Now" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button></a></h3>
</div>
{% else %}
<form action="/" class="form-horizontal bordered-row"> <form action="/" class="form-horizontal bordered-row">
@@ -96,6 +108,8 @@
</form> </form>
{% endif %}

View File

@@ -19,6 +19,18 @@
</h3> </h3>
<div ng-controller="deleteFTPAccount" class="example-box-wrapper"> <div ng-controller="deleteFTPAccount" class="example-box-wrapper">
{% if not status %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "PureFTPD is disabled." %}
<a href="{% url 'managePureFtpd' %}"><button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Enable Now" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button></a></h3>
</div>
{% else %}
<form action="/" class="form-horizontal bordered-row"> <form action="/" class="form-horizontal bordered-row">
@@ -87,6 +99,8 @@
</form> </form>
{% endif %}

View File

@@ -20,6 +20,18 @@
</h3> </h3>
<div class="example-box-wrapper"> <div class="example-box-wrapper">
{% if not status %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "PureFTPD is disabled." %}
<a href="{% url 'managePureFtpd' %}"><button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Enable Now" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button></a></h3>
</div>
{% else %}
<form action="/" class="form-horizontal bordered-row"> <form action="/" class="form-horizontal bordered-row">
@@ -110,6 +122,8 @@
</form> </form>
{% endif %}

View File

@@ -13,6 +13,7 @@ import subprocess
from plogical.virtualHostUtilities import virtualHostUtilities from plogical.virtualHostUtilities import virtualHostUtilities
import shlex import shlex
from plogical.ftpUtilities import FTPUtilities from plogical.ftpUtilities import FTPUtilities
import os
# Create your views here. # Create your views here.
def loadFTPHome(request): def loadFTPHome(request):
@@ -29,6 +30,9 @@ def createFTPAccount(request):
try: try:
admin = Administrator.objects.get(pk=val) admin = Administrator.objects.get(pk=val)
if not os.path.exists('/home/cyberpanel/pureftpd'):
return render(request, "ftp/createFTPAccount.html", {"status": 0})
if admin.type == 1: if admin.type == 1:
websites = Websites.objects.all() websites = Websites.objects.all()
websitesName = [] websitesName = []
@@ -55,7 +59,7 @@ def createFTPAccount(request):
for items in websites: for items in websites:
websitesName.append(items.domain) websitesName.append(items.domain)
return render(request, 'ftp/createFTPAccount.html', {'websiteList':websitesName,'admin':admin.userName}) return render(request, 'ftp/createFTPAccount.html', {'websiteList':websitesName,'admin':admin.userName, "status": 1})
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg)) logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg)) return HttpResponse(str(msg))
@@ -124,7 +128,10 @@ def deleteFTPAccount(request):
try: try:
val = request.session['userID'] val = request.session['userID']
try: try:
admin = Administrator.objects.get(pk=request.session['userID']) admin = Administrator.objects.get(pk=val)
if not os.path.exists('/home/cyberpanel/pureftpd'):
return render(request, "ftp/deleteFTPAccount.html", {"status": 0})
if admin.type == 1: if admin.type == 1:
websites = Websites.objects.all() websites = Websites.objects.all()
@@ -152,7 +159,7 @@ def deleteFTPAccount(request):
for items in websites: for items in websites:
websitesName.append(items.domain) websitesName.append(items.domain)
return render(request, 'ftp/deleteFTPAccount.html', {'websiteList':websitesName}) return render(request, 'ftp/deleteFTPAccount.html', {'websiteList':websitesName, "status": 1})
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg)) logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg)) return HttpResponse(str(msg))
@@ -249,6 +256,9 @@ def listFTPAccounts(request):
try: try:
admin = Administrator.objects.get(pk=val) admin = Administrator.objects.get(pk=val)
if not os.path.exists('/home/cyberpanel/pureftpd'):
return render(request, "ftp/listFTPAccounts.html", {"status": 0})
if admin.type == 1: if admin.type == 1:
websites = Websites.objects.all() websites = Websites.objects.all()
websitesName = [] websitesName = []
@@ -275,7 +285,7 @@ def listFTPAccounts(request):
for items in websites: for items in websites:
websitesName.append(items.domain) websitesName.append(items.domain)
return render(request, 'ftp/listFTPAccounts.html', {'websiteList':websitesName}) return render(request, 'ftp/listFTPAccounts.html', {'websiteList':websitesName, "status": 1})
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg)) logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg)) return HttpResponse(str(msg))

View File

@@ -687,8 +687,8 @@ class preFlightsChecks:
count = 0 count = 0
while (1): while (1):
command = "wget http://cyberpanel.net/CyberPanel.1.7.0.tar.gz" #command = "wget http://cyberpanel.net/CyberPanel.1.7.0.tar.gz"
#command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz" command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz"
res = subprocess.call(shlex.split(command)) res = subprocess.call(shlex.split(command))
if res == 1: if res == 1:
@@ -707,8 +707,8 @@ class preFlightsChecks:
count = 0 count = 0
while(1): while(1):
command = "tar zxf CyberPanel.1.7.0.tar.gz" #command = "tar zxf CyberPanel.1.7.0.tar.gz"
#command = "tar zxf CyberPanelTemp.tar.gz" command = "tar zxf CyberPanelTemp.tar.gz"
res = subprocess.call(shlex.split(command)) res = subprocess.call(shlex.split(command))
@@ -2818,6 +2818,85 @@ milter_default_action = accept
logging.InstallLog.writeToFile(str(msg) + " [setupVirtualEnv]") logging.InstallLog.writeToFile(str(msg) + " [setupVirtualEnv]")
return 0 return 0
@staticmethod
def enableDisableDNS(state):
try:
servicePath = '/home/cyberpanel/powerdns'
if state == 'Off':
command = 'sudo systemctl stop pdns'
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable pdns'
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
else:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableDisableDNS]")
return 0
@staticmethod
def enableDisableEmail(state):
try:
servicePath = '/home/cyberpanel/postfix'
if state == 'Off':
command = 'sudo systemctl stop postfix'
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable postfix'
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
else:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]")
return 0
@staticmethod
def enableDisableFTP(state):
try:
servicePath = '/home/cyberpanel/pureftpd'
if state == 'Off':
command = 'sudo systemctl stop pure-ftpd'
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable pure-ftpd'
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
else:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]")
return 0
@@ -2826,6 +2905,9 @@ def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer') parser = argparse.ArgumentParser(description='CyberPanel Installer')
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.') parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
parser.add_argument('--mysql', help='Specify number of MySQL instances to be used.') parser.add_argument('--mysql', help='Specify number of MySQL instances to be used.')
parser.add_argument('--postfix', help='Enable or disable Email Service.')
parser.add_argument('--powerdns', help='Enable or disable DNS Service.')
parser.add_argument('--ftp', help='Enable or disable ftp Service.')
args = parser.parse_args() args = parser.parse_args()
logging.InstallLog.writeToFile("Starting CyberPanel installation..") logging.InstallLog.writeToFile("Starting CyberPanel installation..")
@@ -2906,7 +2988,24 @@ def main():
checks.modSecPreReqs() checks.modSecPreReqs()
checks.setupVirtualEnv() checks.setupVirtualEnv()
checks.setupPHPAndComposer() checks.setupPHPAndComposer()
checks.installation_successfull()
try:
postfix = args.postfix
checks.enableDisableEmail(postfix)
except:
checks.enableDisableEmail('On')
try:
powerdns = args.powerdns
checks.enableDisableDNS(powerdns)
except:
checks.enableDisableDNS('On')
try:
ftp = args.ftp
checks.enableDisableFTP(ftp)
except:
checks.enableDisableFTP('On')
logging.InstallLog.writeToFile("CyberPanel installation successfully completed!") logging.InstallLog.writeToFile("CyberPanel installation successfully completed!")

View File

@@ -263,5 +263,135 @@ app.controller('postfix', function($scope, $http, $timeout, $window) {
}); });
/* Java script code */
/* Java script code */
app.controller('pureFTPD', function($scope, $http, $timeout, $window) {
$scope.serviceLoading = true;
$scope.failedToFetch = true;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
var serviceStatus = false;
$('#serviceStatus').change(function() {
serviceStatus = $(this).prop('checked');
});
fetchPDNSStatus('pureftpd');
function fetchPDNSStatus(service){
$scope.serviceLoading = false;
$('#serviceStatus').bootstrapToggle('off');
url = "/manageservices/fetchStatus";
var data = {
'service' : service
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.serviceLoading = true;
if(response.data.status === 1){
if (response.data.installCheck === 1) {
$('#serviceStatus').bootstrapToggle('on');
}
}else{
$scope.failedToFetch = false;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.serviceLoading = true;
$scope.failedToFetch = true;
$scope.couldNotConnect = false;
$scope.changesApplied = true;
}
}
$scope.saveStatus = function (service) {
$scope.serviceLoading = false;
$scope.failedToFetch = true;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
url = "/manageservices/saveStatus";
var data = {
status:serviceStatus,
service: service
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.serviceLoading = 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;
}
}
function cantLoadInitialDatas(response) {
$scope.serviceLoading = true;
$scope.failedToFetch = true;
$scope.couldNotConnect = false;
$scope.changesApplied = true;
}
};
});
/* Java script code */ /* Java script code */

View File

@@ -10,7 +10,7 @@
<div class="container"> <div class="container">
<div id="page-title"> <div id="page-title">
<h2>{% trans "Manage Email Server (Postfix)!" %} - <a target="_blank" href="http://go.cyberpanel.net/emailLimits" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Emai Limits Docs" %}</span></a> </h2> <h2>{% trans "Manage Email Server (Postfix)!" %} - <a target="_blank" href="https://go.cyberpanel.net/manage-services" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Services Docs" %}</span></a> </h2>
<p>{% trans "Enable or disable Email services. " %}</p> <p>{% trans "Enable or disable Email services. " %}</p>
</div> </div>

View File

@@ -10,7 +10,7 @@
<div class="container"> <div class="container">
<div id="page-title"> <div id="page-title">
<h2>{% trans "Manage PowerDNS!" %} - <a target="_blank" href="http://go.cyberpanel.net/emailLimits" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Emai Limits Docs" %}</span></a> </h2> <h2>{% trans "Manage PowerDNS!" %} - <a target="_blank" href="https://go.cyberpanel.net/manage-services" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Services Docs" %}</span></a> </h2>
<p>{% trans "Enable or disable DNS services. " %}</p> <p>{% trans "Enable or disable DNS services. " %}</p>
</div> </div>

View File

@@ -0,0 +1,91 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Manage FTP Server (Pure FTPD) - 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 "Manage FTP Server (Pure FTPD)!" %} - <a target="_blank" href="https://go.cyberpanel.net/manage-services" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Services Docs" %}</span></a> </h2>
<p>{% trans "Enable or disable FTP services. " %}</p>
</div>
{% if status %}
<div ng-controller="pureFTPD" class="example-box-wrapper">
<div style="border-radius: 25px;border-color:#3498db" class="content-box">
<h3 class="content-box-header bg-blue">
{% trans "Manage PureFTPD" %} <img ng-hide="serviceLoading" src="/static/images/loading.gif">
</h3>
<div class="content-box-wrapper">
<div class="row">
<div style="padding: 2%" class="col-md-12">
<form action="/" id="createPackages" class="form-horizontal bordered-row">
<div class="form-group">
<label class="col-sm-4 control-label">FTP Status</label>
<div class="col-sm-6">
<input type="checkbox" id="serviceStatus" data-toggle="toggle">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="saveStatus('pureftpd')" class="btn btn-primary btn-lg btn-block">{% trans "Save changes." %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="failedToFetch" class="alert alert-danger">
<p>{% trans "Error message: " %} {$ errorMessage $}</p>
</div>
<div ng-hide="changesApplied" class="alert alert-success">
<p>{% trans "Changes successfully applied." %}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect. Please refresh this page." %} </p>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% else %}
<div class="alert alert-danger">
<p>{% trans "Only administrator can manage services." %}</p>
</div>
{% endif %}
</div>
{% endblock %}

View File

@@ -4,6 +4,9 @@ import views
urlpatterns = [ urlpatterns = [
url(r'^managePowerDNS$', views.managePowerDNS, name='managePowerDNS'), url(r'^managePowerDNS$', views.managePowerDNS, name='managePowerDNS'),
url(r'^managePostfix$', views.managePostfix, name='managePostfix'), url(r'^managePostfix$', views.managePostfix, name='managePostfix'),
url(r'^managePureFtpd$', views.managePureFtpd, name='managePureFtpd'),
url(r'^fetchStatus$', views.fetchStatus, name='fetchStatus'), url(r'^fetchStatus$', views.fetchStatus, name='fetchStatus'),
url(r'^saveStatus$', views.saveStatus, name='saveStatus'), url(r'^saveStatus$', views.saveStatus, name='saveStatus'),
] ]

View File

@@ -51,6 +51,23 @@ def managePostfix(request):
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def managePureFtpd(request):
try:
val = request.session['userID']
try:
admin = Administrator.objects.get(pk=val)
if admin.type == 1:
return render(request, 'manageServices/managePureFtpd.html', {"status": 1})
else:
return render(request, 'manageServices/managePureFtpd.html', {"status": 0})
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse("See CyberCP main log file.")
except KeyError:
return redirect(loadLoginPage)
def fetchStatus(request): def fetchStatus(request):
try: try:
@@ -89,7 +106,15 @@ def fetchStatus(request):
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
elif service == 'pureftpd':
if os.path.exists('/home/cyberpanel/pureftpd'):
data_ret = {'status': 1, 'error_message': 'None', 'installCheck': 1}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'status': 1, 'error_message': 'None', 'installCheck': 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg: except BaseException,msg:
data_ret = {'status': 0, 'error_message': str(msg)} data_ret = {'status': 0, 'error_message': str(msg)}
@@ -129,9 +154,15 @@ def saveStatus(request):
writeToFile.close() writeToFile.close()
command = 'sudo systemctl start pdns' command = 'sudo systemctl start pdns'
subprocess.call(shlex.split(command)) subprocess.call(shlex.split(command))
else: else:
command = 'sudo systemctl stop pdns' command = 'sudo systemctl stop pdns'
subprocess.call(shlex.split(command)) subprocess.call(shlex.split(command))
command = 'sudo systemctl disable pdns'
subprocess.call(shlex.split(command))
try: try:
os.remove(servicePath) os.remove(servicePath)
except: except:
@@ -149,6 +180,30 @@ def saveStatus(request):
else: else:
command = 'sudo systemctl stop postfix' command = 'sudo systemctl stop postfix'
subprocess.call(shlex.split(command)) subprocess.call(shlex.split(command))
command = 'sudo systemctl disable postfix'
subprocess.call(shlex.split(command))
try:
os.remove(servicePath)
except:
pass
elif service == 'pureftpd':
servicePath = '/home/cyberpanel/pureftpd'
if status == True:
writeToFile = open(servicePath, 'w+')
writeToFile.close()
command = 'sudo systemctl start pure-ftpd'
subprocess.call(shlex.split(command))
else:
command = 'sudo systemctl stop pure-ftpd'
subprocess.call(shlex.split(command))
command = 'sudo systemctl disable pure-ftpd'
subprocess.call(shlex.split(command))
try: try:
os.remove(servicePath) os.remove(servicePath)
except: except:

View File

@@ -263,5 +263,135 @@ app.controller('postfix', function($scope, $http, $timeout, $window) {
}); });
/* Java script code */
/* Java script code */
app.controller('pureFTPD', function($scope, $http, $timeout, $window) {
$scope.serviceLoading = true;
$scope.failedToFetch = true;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
var serviceStatus = false;
$('#serviceStatus').change(function() {
serviceStatus = $(this).prop('checked');
});
fetchPDNSStatus('pureftpd');
function fetchPDNSStatus(service){
$scope.serviceLoading = false;
$('#serviceStatus').bootstrapToggle('off');
url = "/manageservices/fetchStatus";
var data = {
'service' : service
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.serviceLoading = true;
if(response.data.status === 1){
if (response.data.installCheck === 1) {
$('#serviceStatus').bootstrapToggle('on');
}
}else{
$scope.failedToFetch = false;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.serviceLoading = true;
$scope.failedToFetch = true;
$scope.couldNotConnect = false;
$scope.changesApplied = true;
}
}
$scope.saveStatus = function (service) {
$scope.serviceLoading = false;
$scope.failedToFetch = true;
$scope.couldNotConnect = true;
$scope.changesApplied = true;
url = "/manageservices/saveStatus";
var data = {
status:serviceStatus,
service: service
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.serviceLoading = 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;
}
}
function cantLoadInitialDatas(response) {
$scope.serviceLoading = true;
$scope.failedToFetch = true;
$scope.couldNotConnect = false;
$scope.changesApplied = true;
}
};
});
/* Java script code */ /* Java script code */