2018-07-23 02:09:33 +05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.shortcuts import HttpResponse, redirect
|
|
|
|
|
import plogical.CyberCPLogFileWriter as logging
|
|
|
|
|
from loginSystem.views import loadLoginPage
|
|
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
from plogical.mailUtilities import mailUtilities
|
|
|
|
|
import subprocess, shlex
|
2018-08-18 00:39:10 +05:00
|
|
|
from plogical.acl import ACLManager
|
2019-02-04 01:03:18 +05:00
|
|
|
from models import PDNSStatus
|
|
|
|
|
from .serviceManager import ServiceManager
|
2018-07-23 02:09:33 +05:00
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def managePowerDNS(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-07-23 02:09:33 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
|
|
|
|
try:
|
|
|
|
|
return render(request, 'manageServices/managePowerDNS.html', {"status": 1})
|
2018-08-21 13:10:40 +05:00
|
|
|
|
2018-07-23 02:09:33 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
return HttpResponse("See CyberCP main log file.")
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2018-07-23 16:41:59 +05:00
|
|
|
def managePostfix(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2018-07-23 16:41:59 +05:00
|
|
|
try:
|
|
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
return render(request, 'manageServices/managePostfix.html', {"status": 1})
|
2018-07-23 16:41:59 +05:00
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
return HttpResponse("See CyberCP main log file.")
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2018-07-23 22:11:42 +05:00
|
|
|
def managePureFtpd(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-07-23 22:11:42 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
|
|
|
|
try:
|
|
|
|
|
return render(request, 'manageServices/managePureFtpd.html', {"status": 1})
|
2018-07-23 22:11:42 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
return HttpResponse("See CyberCP main log file.")
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
2018-07-23 02:09:33 +05:00
|
|
|
|
|
|
|
|
def fetchStatus(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson()
|
2018-07-23 02:09:33 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
mailUtilities.checkHome()
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
service = data['service']
|
|
|
|
|
|
|
|
|
|
if service == 'powerdns':
|
2019-02-04 01:03:18 +05:00
|
|
|
data_ret = {}
|
|
|
|
|
data_ret['status'] = 1
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
pdns = PDNSStatus.objects.get(pk=1)
|
|
|
|
|
data_ret['installCheck'] = pdns.serverStatus
|
|
|
|
|
data_ret['slaveIPData'] = pdns.also_notify
|
|
|
|
|
except:
|
|
|
|
|
PDNSStatus(serverStatus=1).save()
|
2019-02-05 12:21:37 +05:00
|
|
|
data_ret['installCheck'] = 1
|
2019-02-04 01:03:18 +05:00
|
|
|
data_ret['slaveIPData'] = ''
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
2018-07-23 02:09:33 +05:00
|
|
|
|
2018-07-23 16:41:59 +05:00
|
|
|
elif service == 'postfix':
|
|
|
|
|
if os.path.exists('/home/cyberpanel/postfix'):
|
|
|
|
|
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)
|
|
|
|
|
|
2018-07-23 22:11:42 +05:00
|
|
|
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)
|
2018-07-23 02:09:33 +05:00
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except KeyError,msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
def saveStatus(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson()
|
2018-07-23 02:09:33 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
|
|
|
|
|
status = data['status']
|
|
|
|
|
service = data['service']
|
|
|
|
|
|
|
|
|
|
mailUtilities.checkHome()
|
|
|
|
|
|
|
|
|
|
if service == 'powerdns':
|
2018-07-23 16:41:59 +05:00
|
|
|
|
2018-07-23 02:09:33 +05:00
|
|
|
if status == True:
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
pdns = PDNSStatus.objects.get(pk=1)
|
|
|
|
|
pdns.serverStatus = 1
|
|
|
|
|
pdns.allow_axfr_ips = data['slaveIPData'].replace(',', '/32,')
|
|
|
|
|
pdns.also_notify = data['slaveIPData']
|
|
|
|
|
pdns.type = data['dnsMode']
|
|
|
|
|
pdns.save()
|
|
|
|
|
|
|
|
|
|
extraArgs = {}
|
|
|
|
|
extraArgs['type'] = data['dnsMode']
|
|
|
|
|
extraArgs['slaveIPData'] = data['slaveIPData']
|
|
|
|
|
|
|
|
|
|
sm = ServiceManager(extraArgs)
|
|
|
|
|
sm.managePDNS()
|
|
|
|
|
|
2019-02-05 12:21:37 +05:00
|
|
|
command = 'sudo systemctl enable pdns'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
2019-02-05 12:21:37 +05:00
|
|
|
command = 'sudo systemctl restart pdns'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
2018-07-23 02:09:33 +05:00
|
|
|
else:
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
pdns = PDNSStatus.objects.get(pk=1)
|
|
|
|
|
pdns.serverStatus = 0
|
|
|
|
|
pdns.save()
|
|
|
|
|
|
2018-07-23 02:09:33 +05:00
|
|
|
command = 'sudo systemctl stop pdns'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
|
|
|
|
command = 'sudo systemctl disable pdns'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
2018-07-23 16:41:59 +05:00
|
|
|
|
|
|
|
|
elif service == 'postfix':
|
|
|
|
|
|
|
|
|
|
servicePath = '/home/cyberpanel/postfix'
|
|
|
|
|
if status == True:
|
|
|
|
|
writeToFile = open(servicePath, 'w+')
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
command = 'sudo systemctl start postfix'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 16:41:59 +05:00
|
|
|
else:
|
|
|
|
|
command = 'sudo systemctl stop postfix'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
|
|
|
|
command = 'sudo systemctl disable postfix'
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
os.remove(servicePath)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
elif service == 'pureftpd':
|
2018-11-08 12:11:42 +05:00
|
|
|
if os.path.exists("/etc/lsb-release"):
|
|
|
|
|
serviceName = 'pure-ftpd-mysql'
|
|
|
|
|
else:
|
|
|
|
|
serviceName = 'pure-ftpd'
|
2018-07-23 22:11:42 +05:00
|
|
|
|
|
|
|
|
servicePath = '/home/cyberpanel/pureftpd'
|
|
|
|
|
if status == True:
|
|
|
|
|
writeToFile = open(servicePath, 'w+')
|
|
|
|
|
writeToFile.close()
|
2018-11-08 12:11:42 +05:00
|
|
|
command = 'sudo systemctl start ' + serviceName
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
else:
|
2018-11-08 12:11:42 +05:00
|
|
|
command = 'sudo systemctl stop ' + serviceName
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
2018-11-08 12:11:42 +05:00
|
|
|
command = 'sudo systemctl disable ' + serviceName
|
2019-03-21 23:26:42 +05:00
|
|
|
ProcessUtilities.executioner(shlex.split(command))
|
2018-07-23 22:11:42 +05:00
|
|
|
|
2018-07-23 16:41:59 +05:00
|
|
|
try:
|
|
|
|
|
os.remove(servicePath)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
data_ret = {'status': 1, 'error_message': "None"}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
2018-07-23 02:09:33 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except KeyError,msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|