mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-01 10:56:23 +01:00
Plugin installer
This commit is contained in:
@@ -16,7 +16,7 @@ class secMiddleware:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if key == 'configData' or key == 'rewriteRules' or key == 'modSecRules':
|
if key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'recordContentTXT':
|
||||||
continue
|
continue
|
||||||
if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1:
|
if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1:
|
||||||
logging.writeToFile(request.body)
|
logging.writeToFile(request.body)
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ INSTALLED_APPS = [
|
|||||||
'api',
|
'api',
|
||||||
'filemanager',
|
'filemanager',
|
||||||
'manageServices',
|
'manageServices',
|
||||||
|
'pluginHolder',
|
||||||
'emailPremium',
|
'emailPremium',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -37,4 +37,5 @@ urlpatterns = [
|
|||||||
url(r'^filemanager/',include('filemanager.urls')),
|
url(r'^filemanager/',include('filemanager.urls')),
|
||||||
url(r'^emailPremium/',include('emailPremium.urls')),
|
url(r'^emailPremium/',include('emailPremium.urls')),
|
||||||
url(r'^manageservices/',include('manageServices.urls')),
|
url(r'^manageservices/',include('manageServices.urls')),
|
||||||
|
url(r'^plugins/',include('pluginHolder.urls')),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -583,6 +583,7 @@
|
|||||||
<div class="sidebar-submenu">
|
<div class="sidebar-submenu">
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="{% url 'installed' %}" title="{% trans 'Installed Plugins' %}"><span>{% trans "Installed" %}</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div><!-- .sidebar-submenu -->
|
</div><!-- .sidebar-submenu -->
|
||||||
|
|||||||
190
databases/databaseManager.py
Normal file
190
databases/databaseManager.py
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
#!/usr/local/CyberCP/bin/python2
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
import django
|
||||||
|
sys.path.append('/usr/local/CyberCP')
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
|
from django.shortcuts import render, redirect
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import json
|
||||||
|
from plogical.acl import ACLManager
|
||||||
|
import subprocess, shlex
|
||||||
|
import plogical.CyberCPLogFileWriter as logging
|
||||||
|
from plogical.mysqlUtilities import mysqlUtilities
|
||||||
|
from websiteFunctions.models import Websites
|
||||||
|
from databases.models import Databases
|
||||||
|
|
||||||
|
class DatabaseManager:
|
||||||
|
|
||||||
|
def loadDatabaseHome(self, request = None, userID = None):
|
||||||
|
try:
|
||||||
|
return render(request, 'databases/index.html')
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def createDatabase(self, request = None, userID = None):
|
||||||
|
try:
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createDatabase') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(request, 'databases/createDatabase.html', {'websitesList': websitesName})
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def submitDBCreation(self, userID = None, data = None):
|
||||||
|
try:
|
||||||
|
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createDatabase') == 0:
|
||||||
|
return ACLManager.loadErrorJson('createDBStatus', 0)
|
||||||
|
|
||||||
|
databaseWebsite = data['databaseWebsite']
|
||||||
|
dbName = data['dbName']
|
||||||
|
dbUsername = data['dbUsername']
|
||||||
|
dbPassword = data['dbPassword']
|
||||||
|
webUsername = data['webUserName']
|
||||||
|
|
||||||
|
dbName = webUsername + "_" + dbName
|
||||||
|
dbUsername = webUsername + "_" + dbUsername
|
||||||
|
|
||||||
|
result = mysqlUtilities.submitDBCreation(dbName, dbUsername, dbPassword, databaseWebsite)
|
||||||
|
|
||||||
|
if result[0] == 1:
|
||||||
|
data_ret = {'createDBStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
else:
|
||||||
|
data_ret = {'createDBStatus': 0, 'error_message': result[1]}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'createDBStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def deleteDatabase(self, request = None, userID = None):
|
||||||
|
try:
|
||||||
|
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(request, 'databases/deleteDatabase.html', {'websitesList': websitesName})
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def fetchDatabases(self, userID = None, data = None):
|
||||||
|
try:
|
||||||
|
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
|
||||||
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
databaseWebsite = data['databaseWebsite']
|
||||||
|
|
||||||
|
website = Websites.objects.get(domain=databaseWebsite)
|
||||||
|
databases = Databases.objects.filter(website=website)
|
||||||
|
|
||||||
|
json_data = "["
|
||||||
|
checker = 0
|
||||||
|
|
||||||
|
for items in databases:
|
||||||
|
dic = {'id': items.pk,
|
||||||
|
'dbName': items.dbName,
|
||||||
|
'dbUser': items.dbUser, }
|
||||||
|
|
||||||
|
if checker == 0:
|
||||||
|
json_data = json_data + json.dumps(dic)
|
||||||
|
checker = 1
|
||||||
|
else:
|
||||||
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
|
json_data = json_data + ']'
|
||||||
|
|
||||||
|
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
||||||
|
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
final_json = json.dumps({'fetchStatus': 0, 'error_message': str(msg)})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
def submitDatabaseDeletion(self, userID = None, data = None):
|
||||||
|
try:
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
|
||||||
|
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||||
|
|
||||||
|
dbName = data['dbName']
|
||||||
|
|
||||||
|
result = mysqlUtilities.submitDBDeletion(dbName)
|
||||||
|
|
||||||
|
if result[0] == 1:
|
||||||
|
data_ret = {'deleteStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
else:
|
||||||
|
data_ret = {'deleteStatus': 0, 'error_message': result[1]}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def listDBs(self, request = None, userID = None):
|
||||||
|
try:
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'listDatabases') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(request, 'databases/listDataBases.html', {'websiteList': websitesName})
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def changePassword(self, userID = None, data = None):
|
||||||
|
try:
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'listDatabases') == 0:
|
||||||
|
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
||||||
|
|
||||||
|
userName = data['dbUserName']
|
||||||
|
dbPassword = data['dbPassword']
|
||||||
|
|
||||||
|
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||||
|
|
||||||
|
f = open(passFile)
|
||||||
|
data = f.read()
|
||||||
|
password = data.split('\n', 1)[0]
|
||||||
|
|
||||||
|
passwordCMD = "use mysql;SET PASSWORD FOR '" + userName + "'@'localhost' = PASSWORD('" + dbPassword + "');FLUSH PRIVILEGES;"
|
||||||
|
|
||||||
|
command = 'sudo mysql -u root -p' + password + ' -e "' + passwordCMD + '"'
|
||||||
|
cmd = shlex.split(command)
|
||||||
|
res = subprocess.call(cmd)
|
||||||
|
|
||||||
|
if res == 1:
|
||||||
|
data_ret = {'changePasswordStatus': 0, 'error_message': "Please see CyberPanel main log file."}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
36
databases/pluginManager.py
Normal file
36
databases/pluginManager.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
from signals import *
|
||||||
|
from plogical.pluginManagerGlobal import pluginManagerGlobal
|
||||||
|
|
||||||
|
class pluginManager:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preCreateDatabase(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preCreateDatabase)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postCreateDatabase(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postCreateDatabase, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitDBCreation(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitDBCreation)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitDBCreation(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitDBCreation, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitDatabaseDeletion(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitDatabaseDeletion)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitDatabaseDeletion(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitDatabaseDeletion, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preChangePassword(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preChangePassword)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postChangePassword(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postChangePassword, response)
|
||||||
28
databases/signals.py
Normal file
28
databases/signals.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# The world is a prison for the believer.
|
||||||
|
|
||||||
|
from django.dispatch import Signal
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core load the create database template, this special event is used
|
||||||
|
## to create a beautiful names official plugin. Actual FTP account creation happens with event named preSubmitDBCreation and postSubmitDBCreation.
|
||||||
|
preCreateDatabase = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## See preCreateDatabase
|
||||||
|
postCreateDatabase = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start creation of a database.
|
||||||
|
preSubmitDBCreation = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished creation of a database.
|
||||||
|
postSubmitDBCreation = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start deletion of a database
|
||||||
|
preSubmitDatabaseDeletion = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished deletion of a database.
|
||||||
|
postSubmitDatabaseDeletion = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start to change a database password.
|
||||||
|
preChangePassword = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished changing database password.
|
||||||
|
postChangePassword = Signal(providing_args=["request", "response"])
|
||||||
@@ -1,53 +1,37 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.shortcuts import render,redirect
|
from django.shortcuts import redirect
|
||||||
from django.http import HttpResponse
|
|
||||||
from loginSystem.models import Administrator
|
|
||||||
from websiteFunctions.models import Websites
|
|
||||||
import plogical.CyberCPLogFileWriter as logging
|
|
||||||
from plogical.mysqlUtilities import mysqlUtilities
|
|
||||||
from loginSystem.views import loadLoginPage
|
from loginSystem.views import loadLoginPage
|
||||||
from models import Databases
|
from databaseManager import DatabaseManager
|
||||||
|
from pluginManager import pluginManager
|
||||||
import json
|
import json
|
||||||
import shlex
|
|
||||||
import subprocess
|
|
||||||
from plogical.acl import ACLManager
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def loadDatabaseHome(request):
|
def loadDatabaseHome(request):
|
||||||
try:
|
try:
|
||||||
val = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
dm = DatabaseManager()
|
||||||
return render(request, 'databases/index.html')
|
return dm.loadDatabaseHome(request, userID)
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def createDatabase(request):
|
def createDatabase(request):
|
||||||
try:
|
try:
|
||||||
|
result = pluginManager.preCreateDatabase(request)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
dm = DatabaseManager()
|
||||||
|
coreResult = dm.createDatabase(request, userID)
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
result = pluginManager.postCreateDatabase(request, coreResult)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
return coreResult
|
||||||
pass
|
|
||||||
elif currentACL['createDatabase'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'databases/createDatabase.html', {'websitesList':websitesName})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
@@ -55,228 +39,80 @@ def createDatabase(request):
|
|||||||
def submitDBCreation(request):
|
def submitDBCreation(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
result = pluginManager.preSubmitDBCreation(request)
|
||||||
databaseWebsite = data['databaseWebsite']
|
if result != 200:
|
||||||
dbName = data['dbName']
|
return result
|
||||||
dbUsername = data['dbUsername']
|
|
||||||
dbPassword = data['dbPassword']
|
|
||||||
webUsername = data['webUserName']
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
dm = DatabaseManager()
|
||||||
|
coreResult = dm.submitDBCreation(userID, request.data)
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.postSubmitDBCreation(request, coreResult)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['createDatabase'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('createDBStatus', 0)
|
|
||||||
|
|
||||||
dbName = webUsername+"_"+dbName
|
return coreResult
|
||||||
dbUsername = webUsername+"_"+dbUsername
|
|
||||||
|
|
||||||
result = mysqlUtilities.submitDBCreation(dbName, dbUsername, dbPassword, databaseWebsite)
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
if result[0] == 1:
|
|
||||||
data_ret = {'createDBStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
else:
|
|
||||||
data_ret = {'createDBStatus': 0, 'error_message': result[1]}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'createDBStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'createDBStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def deleteDatabase(request):
|
def deleteDatabase(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
dm = DatabaseManager()
|
||||||
|
return dm.deleteDatabase(request, userID)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['deleteDatabase'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'databases/deleteDatabase.html', {'websitesList':websitesName})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def fetchDatabases(request):
|
def fetchDatabases(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
dm = DatabaseManager()
|
||||||
data = json.loads(request.body)
|
return dm.fetchDatabases(userID, json.loads(request.body))
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['deleteDatabase'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
|
||||||
|
|
||||||
databaseWebsite = data['databaseWebsite']
|
|
||||||
|
|
||||||
website = Websites.objects.get(domain=databaseWebsite)
|
|
||||||
databases = Databases.objects.filter(website=website)
|
|
||||||
|
|
||||||
json_data = "["
|
|
||||||
checker = 0
|
|
||||||
|
|
||||||
for items in databases:
|
|
||||||
dic = { 'id':items.pk,
|
|
||||||
'dbName': items.dbName,
|
|
||||||
'dbUser': items.dbUser,}
|
|
||||||
|
|
||||||
if checker == 0:
|
|
||||||
json_data = json_data + json.dumps(dic)
|
|
||||||
checker = 1
|
|
||||||
else:
|
|
||||||
json_data = json_data + ',' + json.dumps(dic)
|
|
||||||
|
|
||||||
json_data = json_data + ']'
|
|
||||||
|
|
||||||
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
|
||||||
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
final_json = json.dumps({'fetchStatus': 0, 'error_message': str(msg)})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
return redirect(loadLoginPage)
|
||||||
final_json = json.dumps({'fetchStatus': 0, 'error_message': "Not logged in."})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
def submitDatabaseDeletion(request):
|
def submitDatabaseDeletion(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
result = pluginManager.preSubmitDatabaseDeletion(request)
|
||||||
if request.method == 'POST':
|
if result != 200:
|
||||||
data = json.loads(request.body)
|
return result
|
||||||
dbName = data['dbName']
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
dm = DatabaseManager()
|
||||||
|
coreResult = dm.submitDatabaseDeletion(userID, json.loads(request.body))
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.postSubmitDatabaseDeletion(request, coreResult)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['deleteDatabase'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
|
||||||
|
|
||||||
result = mysqlUtilities.submitDBDeletion(dbName)
|
return coreResult
|
||||||
|
except KeyError:
|
||||||
if result[0] == 1:
|
return redirect(loadLoginPage)
|
||||||
data_ret = {'deleteStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
else:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': result[1]}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def listDBs(request):
|
def listDBs(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
dm = DatabaseManager()
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return dm.listDBs(request, userID)
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['listDatabases'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'databases/listDataBases.html', {'websiteList':websitesName})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def changePassword(request):
|
def changePassword(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
result = pluginManager.preChangePassword(request)
|
||||||
userName = data['dbUserName']
|
if result != 200:
|
||||||
dbPassword = data['dbPassword']
|
return result
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
dm = DatabaseManager()
|
||||||
|
coreResult = dm.changePassword(userID, json.loads(request.body))
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.postChangePassword(request, coreResult)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['listDatabases'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
|
||||||
|
|
||||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
return coreResult
|
||||||
|
except KeyError:
|
||||||
f = open(passFile)
|
return redirect(loadLoginPage)
|
||||||
data = f.read()
|
|
||||||
password = data.split('\n', 1)[0]
|
|
||||||
|
|
||||||
|
|
||||||
passwordCMD = "use mysql;SET PASSWORD FOR '" + userName + "'@'localhost' = PASSWORD('" + dbPassword + "');FLUSH PRIVILEGES;"
|
|
||||||
|
|
||||||
command = 'sudo mysql -u root -p' + password + ' -e "' + passwordCMD + '"'
|
|
||||||
cmd = shlex.split(command)
|
|
||||||
res = subprocess.call(cmd)
|
|
||||||
|
|
||||||
if res == 1:
|
|
||||||
data_ret = {'changePasswordStatus': 0, 'error_message': "Please see CyberPanel main log file."}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ class DNSManager:
|
|||||||
if ACLManager.currentContextPermission(currentACL, 'addDeleteRecords') == 0:
|
if ACLManager.currentContextPermission(currentACL, 'addDeleteRecords') == 0:
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
|
||||||
zoneDomain = data['selectedZone']
|
zoneDomain = data['selectedZone']
|
||||||
currentSelection = data['currentSelection']
|
currentSelection = data['currentSelection']
|
||||||
|
|
||||||
@@ -532,7 +533,6 @@ class DNSManager:
|
|||||||
|
|
||||||
delZone = Domains.objects.get(name=zoneDomain)
|
delZone = Domains.objects.get(name=zoneDomain)
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
if currentACL['admin'] == 1:
|
||||||
if delZone.admin != admin:
|
if delZone.admin != admin:
|
||||||
return ACLManager.loadErrorJson()
|
return ACLManager.loadErrorJson()
|
||||||
|
|||||||
15
dns/views.py
15
dns/views.py
@@ -4,6 +4,7 @@ from django.shortcuts import redirect
|
|||||||
from loginSystem.views import loadLoginPage
|
from loginSystem.views import loadLoginPage
|
||||||
from dnsManager import DNSManager
|
from dnsManager import DNSManager
|
||||||
from pluginManager import pluginManager
|
from pluginManager import pluginManager
|
||||||
|
import json
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ def NSCreation(request):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
coreResult = dm.NSCreation(userID, request.body)
|
coreResult = dm.NSCreation(userID, json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postNSCreation(request, coreResult)
|
result = pluginManager.postNSCreation(request, coreResult)
|
||||||
if result != 200:
|
if result != 200:
|
||||||
@@ -59,7 +60,7 @@ def zoneCreation(request):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
coreResult = dm.zoneCreation(userID, request.body)
|
coreResult = dm.zoneCreation(userID, json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postZoneCreation(request, coreResult)
|
result = pluginManager.postZoneCreation(request, coreResult)
|
||||||
if result != 200:
|
if result != 200:
|
||||||
@@ -81,7 +82,7 @@ def getCurrentRecordsForDomain(request):
|
|||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
return dm.getCurrentRecordsForDomain(userID, request.body)
|
return dm.getCurrentRecordsForDomain(userID, json.loads(request.body))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ def addDNSRecord(request):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
coreResult = dm.addDNSRecord(userID, request.body)
|
coreResult = dm.addDNSRecord(userID, json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postAddDNSRecord(request, coreResult)
|
result = pluginManager.postAddDNSRecord(request, coreResult)
|
||||||
if result != 200:
|
if result != 200:
|
||||||
@@ -114,7 +115,7 @@ def deleteDNSRecord(request):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
coreResult = dm.deleteDNSRecord(userID, request.body)
|
coreResult = dm.deleteDNSRecord(userID, json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postDeleteDNSRecord(request, coreResult)
|
result = pluginManager.postDeleteDNSRecord(request, coreResult)
|
||||||
if result != 200:
|
if result != 200:
|
||||||
@@ -128,7 +129,7 @@ def deleteDNSZone(request):
|
|||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
return dm.getCurrentRecordsForDomain(request, userID)
|
return dm.deleteDNSZone(request, userID)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ def submitZoneDeletion(request):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
dm = DNSManager()
|
dm = DNSManager()
|
||||||
coreResult = dm.submitZoneDeletion(userID, request.body)
|
coreResult = dm.submitZoneDeletion(userID, json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postSubmitZoneDeletion(request, coreResult)
|
result = pluginManager.postSubmitZoneDeletion(request, coreResult)
|
||||||
if result != 200:
|
if result != 200:
|
||||||
|
|||||||
252
ftp/ftpManager.py
Normal file
252
ftp/ftpManager.py
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
#!/usr/local/CyberCP/bin/python2
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
import django
|
||||||
|
sys.path.append('/usr/local/CyberCP')
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
|
import json
|
||||||
|
from django.shortcuts import render,redirect
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from models import Users
|
||||||
|
from loginSystem.models import Administrator
|
||||||
|
import plogical.CyberCPLogFileWriter as logging
|
||||||
|
from loginSystem.views import loadLoginPage
|
||||||
|
from websiteFunctions.models import Websites
|
||||||
|
import subprocess
|
||||||
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||||
|
import shlex
|
||||||
|
from plogical.ftpUtilities import FTPUtilities
|
||||||
|
import os
|
||||||
|
from plogical.acl import ACLManager
|
||||||
|
|
||||||
|
class FTPManager:
|
||||||
|
def __init__(self, request):
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
def loadFTPHome(self):
|
||||||
|
try:
|
||||||
|
val = self.request.session['userID']
|
||||||
|
return render(self.request, 'ftp/index.html')
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def createFTPAccount(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createFTPAccount') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
admin = Administrator.objects.get(pk=userID)
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
||||||
|
return render(self.request, "ftp/createFTPAccount.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'ftp/createFTPAccount.html',
|
||||||
|
{'websiteList': websitesName, 'admin': admin.userName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def submitFTPCreation(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createFTPAccount') == 0:
|
||||||
|
return ACLManager.loadErrorJson('creatFTPStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
userName = data['ftpUserName']
|
||||||
|
password = data['ftpPassword']
|
||||||
|
path = data['path']
|
||||||
|
domainName = data['ftpDomain']
|
||||||
|
|
||||||
|
admin = Administrator.objects.get(id=userID)
|
||||||
|
|
||||||
|
if len(path) > 0:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
path = 'None'
|
||||||
|
|
||||||
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/ftpUtilities.py"
|
||||||
|
|
||||||
|
execPath = execPath + " submitFTPCreation --domainName " + domainName + " --userName " + userName \
|
||||||
|
+ " --password " + password + " --path " + path + " --owner " + admin.userName
|
||||||
|
|
||||||
|
output = subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
|
if output.find("1,None") > -1:
|
||||||
|
data_ret = {'creatFTPStatus': 1, 'error_message': 'None'}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
else:
|
||||||
|
data_ret = {'creatFTPStatus': 0, 'error_message': output}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'creatFTPStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def deleteFTPAccount(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteFTPAccount') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
||||||
|
return render(self.request, "ftp/deleteFTPAccount.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'ftp/deleteFTPAccount.html', {'websiteList': websitesName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def fetchFTPAccounts(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteFTPAccount') == 0:
|
||||||
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
domain = data['ftpDomain']
|
||||||
|
|
||||||
|
website = Websites.objects.get(domain=domain)
|
||||||
|
|
||||||
|
ftpAccounts = website.users_set.all()
|
||||||
|
|
||||||
|
json_data = "["
|
||||||
|
checker = 0
|
||||||
|
|
||||||
|
for items in ftpAccounts:
|
||||||
|
dic = {"userName": items.user}
|
||||||
|
|
||||||
|
if checker == 0:
|
||||||
|
json_data = json_data + json.dumps(dic)
|
||||||
|
checker = 1
|
||||||
|
else:
|
||||||
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
|
json_data = json_data + ']'
|
||||||
|
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def submitFTPDelete(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteFTPAccount') == 0:
|
||||||
|
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
ftpUserName = data['ftpUsername']
|
||||||
|
|
||||||
|
FTPUtilities.submitFTPDeletion(ftpUserName)
|
||||||
|
|
||||||
|
final_json = json.dumps({'deleteStatus': 1, 'error_message': "None"})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def listFTPAccounts(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'listFTPAccounts') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
||||||
|
return render(self.request, "ftp/listFTPAccounts.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'ftp/listFTPAccounts.html', {'websiteList': websitesName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def getAllFTPAccounts(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'listFTPAccounts') == 0:
|
||||||
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
selectedDomain = data['selectedDomain']
|
||||||
|
|
||||||
|
domain = Websites.objects.get(domain=selectedDomain)
|
||||||
|
|
||||||
|
records = Users.objects.filter(domain=domain)
|
||||||
|
|
||||||
|
json_data = "["
|
||||||
|
checker = 0
|
||||||
|
|
||||||
|
for items in records:
|
||||||
|
dic = {'id': items.id,
|
||||||
|
'user': items.user,
|
||||||
|
'dir': items.dir,
|
||||||
|
'quotasize': str(items.quotasize) + "MB",
|
||||||
|
}
|
||||||
|
|
||||||
|
if checker == 0:
|
||||||
|
json_data = json_data + json.dumps(dic)
|
||||||
|
checker = 1
|
||||||
|
else:
|
||||||
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
|
json_data = json_data + ']'
|
||||||
|
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
final_dic = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
def changePassword(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'listFTPAccounts') == 0:
|
||||||
|
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
userName = data['ftpUserName']
|
||||||
|
password = data['ftpPassword']
|
||||||
|
|
||||||
|
FTPUtilities.changeFTPPassword(userName, password)
|
||||||
|
|
||||||
|
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
36
ftp/pluginManager.py
Normal file
36
ftp/pluginManager.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
from signals import *
|
||||||
|
from plogical.pluginManagerGlobal import pluginManagerGlobal
|
||||||
|
|
||||||
|
class pluginManager:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preCreateFTPAccount(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preCreateFTPAccount)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postCreateFTPAccount(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postCreateFTPAccount, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitFTPCreation(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitFTPCreation)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitFTPCreation(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitFTPCreation, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitFTPDelete(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitFTPDelete)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitFTPDelete(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitFTPDelete, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preChangePassword(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preChangePassword)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postChangePassword(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postChangePassword, response)
|
||||||
29
ftp/signals.py
Normal file
29
ftp/signals.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# The world is a prison for the believer.
|
||||||
|
## https://www.youtube.com/watch?v=DWfNYztUM1U
|
||||||
|
|
||||||
|
from django.dispatch import Signal
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core load the create ftp template, this special event is used
|
||||||
|
## to create a beautiful names official plugin. Actual FTP account creation happens with event named preSubmitFTPCreation and postSubmitFTPCreation.
|
||||||
|
preCreateFTPAccount = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## See preCreateFTPAccount
|
||||||
|
postCreateFTPAccount = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start creation of a FTP account.
|
||||||
|
preSubmitFTPCreation = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished creation of a FTP account.
|
||||||
|
postSubmitFTPCreation = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start deletion of a FTP account.
|
||||||
|
preSubmitFTPDelete = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished deletion of website
|
||||||
|
postSubmitFTPDelete = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start deletion of child-domain
|
||||||
|
preChangePassword = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished deletion of child-domain
|
||||||
|
postChangePassword = Signal(providing_args=["request", "response"])
|
||||||
325
ftp/views.py
325
ftp/views.py
@@ -1,325 +1,118 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import hashlib
|
from django.shortcuts import redirect
|
||||||
import json
|
from ftpManager import FTPManager
|
||||||
from django.shortcuts import render,redirect
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from models import Users
|
|
||||||
from loginSystem.models import Administrator
|
|
||||||
import plogical.CyberCPLogFileWriter as logging
|
|
||||||
from loginSystem.views import loadLoginPage
|
from loginSystem.views import loadLoginPage
|
||||||
from websiteFunctions.models import Websites
|
from pluginManager import pluginManager
|
||||||
import subprocess
|
|
||||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
|
||||||
import shlex
|
|
||||||
from plogical.ftpUtilities import FTPUtilities
|
|
||||||
import os
|
|
||||||
from plogical.acl import ACLManager
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
def loadFTPHome(request):
|
def loadFTPHome(request):
|
||||||
try:
|
try:
|
||||||
val = request.session['userID']
|
fm = FTPManager(request)
|
||||||
return render(request,'ftp/index.html')
|
return fm.loadFTPHome()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def createFTPAccount(request):
|
def createFTPAccount(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preCreateFTPAccount(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['createFTPAccount'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
|
fm = FTPManager(request)
|
||||||
|
coreResult = fm.createFTPAccount()
|
||||||
|
|
||||||
try:
|
result = pluginManager.postCreateFTPAccount(request, coreResult)
|
||||||
admin = Administrator.objects.get(pk=userID)
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
return coreResult
|
||||||
return render(request, "ftp/createFTPAccount.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'ftp/createFTPAccount.html', {'websiteList':websitesName,'admin':admin.userName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitFTPCreation(request):
|
def submitFTPCreation(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
result = pluginManager.preSubmitFTPCreation(request)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
fm = FTPManager(request)
|
||||||
pass
|
coreResult = fm.submitFTPCreation()
|
||||||
elif currentACL['createFTPAccount'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('creatFTPStatus', 0)
|
|
||||||
|
|
||||||
|
result = pluginManager.postSubmitFTPCreation(request, coreResult)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
data = json.loads(request.body)
|
return coreResult
|
||||||
userName = data['ftpUserName']
|
|
||||||
password = data['ftpPassword']
|
|
||||||
path = data['path']
|
|
||||||
domainName = data['ftpDomain']
|
|
||||||
|
|
||||||
admin = Administrator.objects.get(id=userID)
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
if len(path) > 0:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
path = 'None'
|
|
||||||
|
|
||||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/ftpUtilities.py"
|
|
||||||
|
|
||||||
execPath = execPath + " submitFTPCreation --domainName " + domainName + " --userName " + userName \
|
|
||||||
+ " --password " + password + " --path " + path + " --owner " + admin.userName
|
|
||||||
|
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(execPath))
|
|
||||||
|
|
||||||
if output.find("1,None") > -1:
|
|
||||||
data_ret = {'creatFTPStatus': 1, 'error_message': 'None'}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
else:
|
|
||||||
data_ret = {'creatFTPStatus': 0, 'error_message': output}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'creatFTPStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'creatFTPStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def deleteFTPAccount(request):
|
def deleteFTPAccount(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
fm = FTPManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return fm.deleteFTPAccount()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['deleteFTPAccount'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
|
||||||
return render(request, "ftp/deleteFTPAccount.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'ftp/deleteFTPAccount.html', {'websiteList':websitesName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def fetchFTPAccounts(request):
|
def fetchFTPAccounts(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
fm = FTPManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return fm.fetchFTPAccounts()
|
||||||
|
except KeyError:
|
||||||
if currentACL['admin'] == 1:
|
return redirect(loadLoginPage)
|
||||||
pass
|
|
||||||
elif currentACL['deleteFTPAccount'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
data = json.loads(request.body)
|
|
||||||
domain = data['ftpDomain']
|
|
||||||
|
|
||||||
website = Websites.objects.get(domain=domain)
|
|
||||||
|
|
||||||
ftpAccounts = website.users_set.all()
|
|
||||||
|
|
||||||
json_data = "["
|
|
||||||
checker = 0
|
|
||||||
|
|
||||||
for items in ftpAccounts:
|
|
||||||
dic = {"userName":items.user}
|
|
||||||
|
|
||||||
if checker == 0:
|
|
||||||
json_data = json_data + json.dumps(dic)
|
|
||||||
checker = 1
|
|
||||||
else:
|
|
||||||
json_data = json_data + ',' + json.dumps(dic)
|
|
||||||
|
|
||||||
json_data = json_data + ']'
|
|
||||||
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def submitFTPDelete(request):
|
def submitFTPDelete(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
result = pluginManager.preSubmitFTPDelete(request)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
fm = FTPManager(request)
|
||||||
pass
|
coreResult = fm.submitFTPDelete()
|
||||||
elif currentACL['deleteFTPAccount'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
result = pluginManager.postSubmitFTPDelete(request, coreResult)
|
||||||
ftpUserName = data['ftpUsername']
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
FTPUtilities.submitFTPDeletion(ftpUserName)
|
return coreResult
|
||||||
|
|
||||||
final_json = json.dumps({'deleteStatus': 1, 'error_message': "None"})
|
except KeyError:
|
||||||
return HttpResponse(final_json)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def listFTPAccounts(request):
|
def listFTPAccounts(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
fm = FTPManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return fm.listFTPAccounts()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['listFTPAccounts'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
|
||||||
return render(request, "ftp/listFTPAccounts.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'ftp/listFTPAccounts.html', {'websiteList':websitesName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def getAllFTPAccounts(request):
|
def getAllFTPAccounts(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
fm = FTPManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return fm.getAllFTPAccounts()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['listFTPAccounts'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
|
||||||
selectedDomain = data['selectedDomain']
|
|
||||||
|
|
||||||
domain = Websites.objects.get(domain=selectedDomain)
|
|
||||||
|
|
||||||
records = Users.objects.filter(domain=domain)
|
|
||||||
|
|
||||||
json_data = "["
|
|
||||||
checker = 0
|
|
||||||
|
|
||||||
for items in records:
|
|
||||||
dic = {'id': items.id,
|
|
||||||
'user': items.user,
|
|
||||||
'dir': items.dir,
|
|
||||||
'quotasize': str(items.quotasize)+"MB",
|
|
||||||
}
|
|
||||||
|
|
||||||
if checker == 0:
|
|
||||||
json_data = json_data + json.dumps(dic)
|
|
||||||
checker = 1
|
|
||||||
else:
|
|
||||||
json_data = json_data + ',' + json.dumps(dic)
|
|
||||||
|
|
||||||
|
|
||||||
json_data = json_data + ']'
|
|
||||||
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None","data":json_data})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
final_dic = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
final_dic = {'fetchStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
return redirect(loadLoginPage)
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
def changePassword(request):
|
def changePassword(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['listFTPAccounts'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
result = pluginManager.preChangePassword(request)
|
||||||
userName = data['ftpUserName']
|
if result != 200:
|
||||||
password = data['ftpPassword']
|
return result
|
||||||
|
|
||||||
FTPUtilities.changeFTPPassword(userName, password)
|
fm = FTPManager(request)
|
||||||
|
coreResult = fm.changePassword()
|
||||||
|
|
||||||
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
result = pluginManager.postChangePassword(request, coreResult)
|
||||||
json_data = json.dumps(data_ret)
|
if result != 200:
|
||||||
return HttpResponse(json_data)
|
return result
|
||||||
|
|
||||||
except BaseException,msg:
|
return coreResult
|
||||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
except KeyError:
|
||||||
return HttpResponse(json_data)
|
return redirect(loadLoginPage)
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
@@ -687,7 +687,7 @@ class preFlightsChecks:
|
|||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
while (1):
|
while (1):
|
||||||
command = "wget http://cyberpanel.net/CyberPanel.1.7.2.tar.gz"
|
command = "wget http://cyberpanel.net/CyberPanelTemp.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))
|
||||||
|
|
||||||
@@ -707,7 +707,7 @@ class preFlightsChecks:
|
|||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
while(1):
|
while(1):
|
||||||
command = "tar zxf CyberPanel.1.7.2.tar.gz"
|
command = "tar zxf CyberPanelTemp.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))
|
||||||
|
|||||||
522
mailServer/mailserverManager.py
Normal file
522
mailServer/mailserverManager.py
Normal file
@@ -0,0 +1,522 @@
|
|||||||
|
#!/usr/local/CyberCP/bin/python2
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
import django
|
||||||
|
sys.path.append('/usr/local/CyberCP')
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
|
from django.shortcuts import render,redirect
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from models import Domains,EUsers
|
||||||
|
from loginSystem.views import loadLoginPage
|
||||||
|
import plogical.CyberCPLogFileWriter as logging
|
||||||
|
import json
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||||
|
from plogical.mailUtilities import mailUtilities
|
||||||
|
import thread
|
||||||
|
from dns.models import Domains as dnsDomains
|
||||||
|
from dns.models import Records as dnsRecords
|
||||||
|
from mailServer.models import Forwardings
|
||||||
|
from plogical.acl import ACLManager
|
||||||
|
import os
|
||||||
|
|
||||||
|
class MailServerManager:
|
||||||
|
|
||||||
|
def __init__(self, request = None):
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
def loadEmailHome(self):
|
||||||
|
try:
|
||||||
|
val = self.request.session['userID']
|
||||||
|
return render(self.request, 'mailServer/index.html')
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def createEmailAccount(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createEmail') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/postfix'):
|
||||||
|
return render(self.request, "mailServer/createEmailAccount.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'mailServer/createEmailAccount.html',
|
||||||
|
{'websiteList': websitesName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def submitEmailCreation(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createEmail') == 0:
|
||||||
|
return ACLManager.loadErrorJson('createEmailStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
domainName = data['domain']
|
||||||
|
userName = data['username']
|
||||||
|
password = data['password']
|
||||||
|
|
||||||
|
## Create email entry
|
||||||
|
|
||||||
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||||
|
|
||||||
|
execPath = execPath + " createEmailAccount --domain " + domainName + " --userName " \
|
||||||
|
+ userName + " --password " + password
|
||||||
|
|
||||||
|
output = subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
|
if output.find("1,None") > -1:
|
||||||
|
|
||||||
|
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
else:
|
||||||
|
data_ret = {'createEmailStatus': 0, 'error_message': output}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def deleteEmailAccount(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteEmail') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/postfix'):
|
||||||
|
return render(self.request, "mailServer/deleteEmailAccount.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'mailServer/deleteEmailAccount.html',
|
||||||
|
{'websiteList': websitesName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def getEmailsForDomain(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteEmail') == 0:
|
||||||
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
domain = data['domain']
|
||||||
|
|
||||||
|
try:
|
||||||
|
domain = Domains.objects.get(domain=domain)
|
||||||
|
except:
|
||||||
|
final_dic = {'fetchStatus': 0, 'error_message': "No email accounts exists!"}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
emails = domain.eusers_set.all()
|
||||||
|
|
||||||
|
if emails.count() == 0:
|
||||||
|
final_dic = {'fetchStatus': 0, 'error_message': "No email accounts exists!"}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
json_data = "["
|
||||||
|
checker = 0
|
||||||
|
|
||||||
|
for items in emails:
|
||||||
|
dic = {'email': items.email}
|
||||||
|
|
||||||
|
if checker == 0:
|
||||||
|
json_data = json_data + json.dumps(dic)
|
||||||
|
checker = 1
|
||||||
|
else:
|
||||||
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
|
json_data = json_data + ']'
|
||||||
|
final_dic = {'fetchStatus': 1, 'error_message': "None", "data": json_data}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def submitEmailDeletion(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deleteEmail') == 0:
|
||||||
|
return ACLManager.loadErrorJson('deleteEmailStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
email = data['email']
|
||||||
|
|
||||||
|
mailUtilities.deleteEmailAccount(email)
|
||||||
|
data_ret = {'deleteEmailStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def emailForwarding(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'emailForwarding') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/postfix'):
|
||||||
|
return render(self.request, "mailServer/emailForwarding.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'mailServer/emailForwarding.html', {'websiteList': websitesName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def fetchCurrentForwardings(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'emailForwarding') == 0:
|
||||||
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
emailAddress = data['emailAddress']
|
||||||
|
|
||||||
|
currentForwardings = Forwardings.objects.filter(source=emailAddress)
|
||||||
|
|
||||||
|
json_data = "["
|
||||||
|
checker = 0
|
||||||
|
id = 1
|
||||||
|
for items in currentForwardings:
|
||||||
|
if items.source == items.destination:
|
||||||
|
continue
|
||||||
|
dic = {'id': id,
|
||||||
|
'source': items.source,
|
||||||
|
'destination': items.destination}
|
||||||
|
|
||||||
|
id = id + 1
|
||||||
|
|
||||||
|
if checker == 0:
|
||||||
|
json_data = json_data + json.dumps(dic)
|
||||||
|
checker = 1
|
||||||
|
else:
|
||||||
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
|
json_data = json_data + ']'
|
||||||
|
final_dic = {'fetchStatus': 1, 'error_message': "None", "data": json_data}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def submitForwardDeletion(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'emailForwarding') == 0:
|
||||||
|
return ACLManager.loadErrorJson('deleteForwardingStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
destination = data['destination']
|
||||||
|
source = data['source']
|
||||||
|
|
||||||
|
forwarding = Forwardings.objects.get(destination=destination, source=source)
|
||||||
|
forwarding.delete()
|
||||||
|
|
||||||
|
data_ret = {'deleteForwardingStatus': 1, 'error_message': "None",
|
||||||
|
'successMessage': 'Successfully deleted!'}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'deleteForwardingStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def submitEmailForwardingCreation(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'emailForwarding') == 0:
|
||||||
|
return ACLManager.loadErrorJson('createStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
source = data['source']
|
||||||
|
destination = data['destination']
|
||||||
|
|
||||||
|
if Forwardings.objects.filter(source=source, destination=destination).count() > 0:
|
||||||
|
data_ret = {'createStatus': 0,
|
||||||
|
'error_message': "You have already forwared to this destination."}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
if Forwardings.objects.filter(source=source).count() == 0:
|
||||||
|
forwarding = Forwardings(source=source, destination=source)
|
||||||
|
forwarding.save()
|
||||||
|
|
||||||
|
forwarding = Forwardings(source=source, destination=destination)
|
||||||
|
forwarding.save()
|
||||||
|
|
||||||
|
data_ret = {'createStatus': 1, 'error_message': "None", 'successMessage': 'Successfully Created!'}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'createStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
#######
|
||||||
|
|
||||||
|
def changeEmailAccountPassword(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'changeEmailPassword') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
if not os.path.exists('/home/cyberpanel/postfix'):
|
||||||
|
return render(self.request, "mailServer/changeEmailPassword.html", {"status": 0})
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'mailServer/changeEmailPassword.html',
|
||||||
|
{'websiteList': websitesName, "status": 1})
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def submitPasswordChange(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'changeEmailPassword') == 0:
|
||||||
|
return ACLManager.loadErrorJson('passChangeStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
domain = data['domain']
|
||||||
|
email = data['email']
|
||||||
|
password = data['password']
|
||||||
|
|
||||||
|
emailDB = EUsers.objects.get(email=email)
|
||||||
|
emailDB.delete()
|
||||||
|
|
||||||
|
dom = Domains(domain=domain)
|
||||||
|
|
||||||
|
emailAcct = EUsers(emailOwner=dom, email=email, password=password)
|
||||||
|
emailAcct.save()
|
||||||
|
|
||||||
|
data_ret = {'passChangeStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
#######
|
||||||
|
|
||||||
|
def dkimManager(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
openDKIMInstalled = 0
|
||||||
|
|
||||||
|
if mailUtilities.checkIfDKIMInstalled() == 1:
|
||||||
|
openDKIMInstalled = 1
|
||||||
|
|
||||||
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||||
|
|
||||||
|
return render(self.request, 'mailServer/dkimManager.html',
|
||||||
|
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
|
||||||
|
|
||||||
|
return render(self.request, 'mailServer/dkimManager.html',
|
||||||
|
{'openDKIMInstalled': openDKIMInstalled})
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def fetchDKIMKeys(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
|
||||||
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
domainName = data['domainName']
|
||||||
|
|
||||||
|
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
||||||
|
command = "sudo cat " + path
|
||||||
|
output = subprocess.check_output(shlex.split(command))
|
||||||
|
|
||||||
|
path = "/etc/opendkim/keys/" + domainName + "/default.private"
|
||||||
|
command = "sudo cat " + path
|
||||||
|
privateKey = subprocess.check_output(shlex.split(command))
|
||||||
|
|
||||||
|
data_ret = {'fetchStatus': 1, 'keysAvailable': 1, 'publicKey': output[53:269],
|
||||||
|
'privateKey': privateKey, 'dkimSuccessMessage': 'Keys successfully fetched!',
|
||||||
|
'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def generateDKIMKeys(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
|
||||||
|
return ACLManager.loadErrorJson('generateStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
domainName = data['domainName']
|
||||||
|
|
||||||
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||||
|
execPath = execPath + " generateKeys --domain " + domainName
|
||||||
|
output = subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
|
if output.find("1,None") > -1:
|
||||||
|
|
||||||
|
zone = dnsDomains.objects.get(name=domainName)
|
||||||
|
zone.save()
|
||||||
|
|
||||||
|
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
||||||
|
command = "sudo cat " + path
|
||||||
|
output = subprocess.check_output(shlex.split(command))
|
||||||
|
|
||||||
|
record = dnsRecords(domainOwner=zone,
|
||||||
|
domain_id=zone.id,
|
||||||
|
name="default._domainkey." + domainName,
|
||||||
|
type="TXT",
|
||||||
|
content="v=DKIM1; k=rsa; p=" + output[53:269],
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
data_ret = {'generateStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
else:
|
||||||
|
data_ret = {'generateStatus': 0, 'error_message': output}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def installOpenDKIM(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
|
||||||
|
return ACLManager.loadErrorJson('installOpenDKIM', 0)
|
||||||
|
thread.start_new_thread(mailUtilities.installOpenDKIM, ('Install', 'openDKIM'))
|
||||||
|
final_json = json.dumps({'installOpenDKIM': 1, 'error_message': "None"})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
except BaseException, msg:
|
||||||
|
final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
def installStatusOpenDKIM(self):
|
||||||
|
try:
|
||||||
|
command = "sudo cat " + mailUtilities.installLogPath
|
||||||
|
installStatus = subprocess.check_output(shlex.split(command))
|
||||||
|
|
||||||
|
if installStatus.find("[200]") > -1:
|
||||||
|
|
||||||
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||||
|
|
||||||
|
execPath = execPath + " configureOpenDKIM"
|
||||||
|
|
||||||
|
output = subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
|
if output.find("1,None") > -1:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
final_json = json.dumps({
|
||||||
|
'error_message': "Failed to install OpenDKIM configurations.",
|
||||||
|
'requestStatus': installStatus,
|
||||||
|
'abort': 1,
|
||||||
|
'installed': 0,
|
||||||
|
})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
final_json = json.dumps({
|
||||||
|
'error_message': "None",
|
||||||
|
'requestStatus': installStatus,
|
||||||
|
'abort': 1,
|
||||||
|
'installed': 1,
|
||||||
|
})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
elif installStatus.find("[404]") > -1:
|
||||||
|
|
||||||
|
final_json = json.dumps({
|
||||||
|
'abort': 1,
|
||||||
|
'installed': 0,
|
||||||
|
'error_message': "None",
|
||||||
|
'requestStatus': installStatus,
|
||||||
|
})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
else:
|
||||||
|
final_json = json.dumps({
|
||||||
|
'abort': 0,
|
||||||
|
'error_message': "None",
|
||||||
|
'requestStatus': installStatus,
|
||||||
|
})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
final_dic = {'abort': 1, 'installed': 0, 'error_message': str(msg)}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
52
mailServer/pluginManager.py
Normal file
52
mailServer/pluginManager.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
from signals import *
|
||||||
|
from plogical.pluginManagerGlobal import pluginManagerGlobal
|
||||||
|
|
||||||
|
class pluginManager:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitEmailCreation(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitEmailCreation)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitEmailCreation(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitEmailCreation, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitEmailDeletion(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitEmailDeletion)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitEmailDeletion(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitEmailDeletion, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitForwardDeletion(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitForwardDeletion)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitForwardDeletion(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitForwardDeletion, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitEmailForwardingCreation(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitEmailForwardingCreation)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitEmailForwardingCreation(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitEmailForwardingCreation, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitPasswordChange(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitPasswordChange)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitPasswordChange(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitPasswordChange, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preGenerateDKIMKeys(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preGenerateDKIMKeys)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postGenerateDKIMKeys(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postGenerateDKIMKeys, response)
|
||||||
40
mailServer/signals.py
Normal file
40
mailServer/signals.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# The world is a prison for the believer.
|
||||||
|
## https://www.youtube.com/watch?v=DWfNYztUM1U
|
||||||
|
|
||||||
|
from django.dispatch import Signal
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start creation of an email account.
|
||||||
|
preSubmitEmailCreation = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished creation of an email account.
|
||||||
|
postSubmitEmailCreation = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start deletion of an email account
|
||||||
|
preSubmitEmailDeletion = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished deletion of an email account
|
||||||
|
postSubmitEmailDeletion = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start deletion of email forwarding.
|
||||||
|
preSubmitForwardDeletion = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished deletion of email forwarding.
|
||||||
|
postSubmitForwardDeletion = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start creation of email forwarding.
|
||||||
|
preSubmitEmailForwardingCreation = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished creation of email forwarding.
|
||||||
|
postSubmitEmailForwardingCreation = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start changing password for email account.
|
||||||
|
preSubmitPasswordChange = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished changing password for email account.
|
||||||
|
postSubmitPasswordChange = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start generating dkim keys.
|
||||||
|
preGenerateDKIMKeys = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished generating dkim keys.
|
||||||
|
postGenerateDKIMKeys = Signal(providing_args=["request", "response"])
|
||||||
@@ -1,186 +1,56 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.shortcuts import render,redirect
|
from django.shortcuts import redirect
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from models import Domains,EUsers
|
|
||||||
# Create your views here.
|
|
||||||
from loginSystem.models import Administrator
|
|
||||||
from websiteFunctions.models import Websites
|
|
||||||
from loginSystem.views import loadLoginPage
|
from loginSystem.views import loadLoginPage
|
||||||
import plogical.CyberCPLogFileWriter as logging
|
|
||||||
import json
|
import json
|
||||||
import shlex
|
from mailserverManager import MailServerManager
|
||||||
import subprocess
|
from pluginManager import pluginManager
|
||||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
|
||||||
from plogical.mailUtilities import mailUtilities
|
|
||||||
import thread
|
|
||||||
from dns.models import Domains as dnsDomains
|
|
||||||
from dns.models import Records as dnsRecords
|
|
||||||
from mailServer.models import Forwardings
|
|
||||||
from plogical.acl import ACLManager
|
|
||||||
import os
|
|
||||||
|
|
||||||
def loadEmailHome(request):
|
def loadEmailHome(request):
|
||||||
try:
|
try:
|
||||||
val = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
return render(request, 'mailServer/index.html')
|
return msM.loadEmailHome()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def createEmailAccount(request):
|
def createEmailAccount(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.createEmailAccount()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['createEmail'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/postfix'):
|
|
||||||
return render(request, "mailServer/createEmailAccount.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'mailServer/createEmailAccount.html', {'websiteList':websitesName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitEmailCreation(request):
|
def submitEmailCreation(request):
|
||||||
try:
|
try:
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
userID = request.session['userID']
|
result = pluginManager.preSubmitEmailCreation(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
msM = MailServerManager(request)
|
||||||
pass
|
coreResult = msM.submitEmailCreation()
|
||||||
elif currentACL['createEmail'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('createEmailStatus', 0)
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
result = pluginManager.postSubmitEmailCreation(request, coreResult)
|
||||||
domainName = data['domain']
|
if result != 200:
|
||||||
userName = data['username']
|
return result
|
||||||
password = data['password']
|
|
||||||
|
|
||||||
## Create email entry
|
return coreResult
|
||||||
|
except KeyError:
|
||||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
execPath = execPath + " createEmailAccount --domain " + domainName + " --userName " \
|
|
||||||
+ userName + " --password " + password
|
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(execPath))
|
|
||||||
|
|
||||||
if output.find("1,None") > -1:
|
|
||||||
|
|
||||||
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
else:
|
|
||||||
data_ret = {'createEmailStatus': 0, 'error_message': output}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
## create email entry ends
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException, msg:
|
|
||||||
data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def deleteEmailAccount(request):
|
def deleteEmailAccount(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.deleteEmailAccount()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['deleteEmail'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/postfix'):
|
|
||||||
return render(request, "mailServer/deleteEmailAccount.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'mailServer/deleteEmailAccount.html', {'websiteList':websitesName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def getEmailsForDomain(request):
|
def getEmailsForDomain(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.getEmailsForDomain()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['deleteEmail'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
|
||||||
domain = data['domain']
|
|
||||||
|
|
||||||
try:
|
|
||||||
domain = Domains.objects.get(domain=domain)
|
|
||||||
except:
|
|
||||||
final_dic = {'fetchStatus': 0, 'error_message': "No email accounts exists!"}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
emails = domain.eusers_set.all()
|
|
||||||
|
|
||||||
if emails.count() == 0:
|
|
||||||
final_dic = {'fetchStatus': 0, 'error_message': "No email accounts exists!"}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
json_data = "["
|
|
||||||
checker = 0
|
|
||||||
|
|
||||||
for items in emails:
|
|
||||||
dic = {'email': items.email}
|
|
||||||
|
|
||||||
if checker == 0:
|
|
||||||
json_data = json_data + json.dumps(dic)
|
|
||||||
checker = 1
|
|
||||||
else:
|
|
||||||
json_data = json_data + ',' + json.dumps(dic)
|
|
||||||
|
|
||||||
json_data = json_data + ']'
|
|
||||||
final_dic = {'fetchStatus': 1, 'error_message': "None", "data": json_data}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -188,30 +58,19 @@ def getEmailsForDomain(request):
|
|||||||
|
|
||||||
def submitEmailDeletion(request):
|
def submitEmailDeletion(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preSubmitEmailDeletion(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['deleteEmail'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('deleteEmailStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
msM = MailServerManager(request)
|
||||||
email = data['email']
|
coreResult = msM.submitEmailDeletion()
|
||||||
|
|
||||||
mailUtilities.deleteEmailAccount(email)
|
result = pluginManager.postSubmitEmailDeletion(request, coreResult)
|
||||||
data_ret = {'deleteEmailStatus': 1, 'error_message': "None"}
|
if result != 200:
|
||||||
json_data = json.dumps(data_ret)
|
return result
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
return coreResult
|
||||||
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -219,77 +78,15 @@ def submitEmailDeletion(request):
|
|||||||
|
|
||||||
def emailForwarding(request):
|
def emailForwarding(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.emailForwarding()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['emailForwarding'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/postfix'):
|
|
||||||
return render(request, "mailServer/emailForwarding.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'mailServer/emailForwarding.html', {'websiteList':websitesName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def fetchCurrentForwardings(request):
|
def fetchCurrentForwardings(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.fetchCurrentForwardings()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['emailForwarding'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
|
||||||
emailAddress = data['emailAddress']
|
|
||||||
|
|
||||||
currentForwardings = Forwardings.objects.filter(source=emailAddress)
|
|
||||||
|
|
||||||
json_data = "["
|
|
||||||
checker = 0
|
|
||||||
id = 1
|
|
||||||
for items in currentForwardings:
|
|
||||||
if items.source == items.destination:
|
|
||||||
continue
|
|
||||||
dic = {'id': id,
|
|
||||||
'source': items.source,
|
|
||||||
'destination': items.destination}
|
|
||||||
|
|
||||||
id = id + 1
|
|
||||||
|
|
||||||
if checker == 0:
|
|
||||||
json_data = json_data + json.dumps(dic)
|
|
||||||
checker = 1
|
|
||||||
else:
|
|
||||||
json_data = json_data + ',' + json.dumps(dic)
|
|
||||||
|
|
||||||
json_data = json_data + ']'
|
|
||||||
final_dic = {'fetchStatus': 1, 'error_message': "None", "data": json_data}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -297,33 +94,19 @@ def fetchCurrentForwardings(request):
|
|||||||
|
|
||||||
def submitForwardDeletion(request):
|
def submitForwardDeletion(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preSubmitForwardDeletion(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['emailForwarding'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('deleteForwardingStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
msM = MailServerManager(request)
|
||||||
destination = data['destination']
|
coreResult = msM.submitForwardDeletion()
|
||||||
source = data['source']
|
|
||||||
|
|
||||||
forwarding = Forwardings.objects.get(destination=destination, source=source)
|
result = pluginManager.postSubmitForwardDeletion(request, coreResult)
|
||||||
forwarding.delete()
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
data_ret = {'deleteForwardingStatus': 1, 'error_message': "None", 'successMessage':'Successfully deleted!'}
|
return coreResult
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'deleteForwardingStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -331,44 +114,19 @@ def submitForwardDeletion(request):
|
|||||||
|
|
||||||
def submitEmailForwardingCreation(request):
|
def submitEmailForwardingCreation(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preSubmitEmailForwardingCreation(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['emailForwarding'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('createStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
msM = MailServerManager(request)
|
||||||
source = data['source']
|
coreResult = msM.submitEmailForwardingCreation()
|
||||||
destination = data['destination']
|
|
||||||
|
|
||||||
if Forwardings.objects.filter(source=source, destination=destination).count() > 0:
|
result = pluginManager.postSubmitEmailForwardingCreation(request, coreResult)
|
||||||
data_ret = {'createStatus': 0, 'error_message': "You have already forwared to this destination."}
|
if result != 200:
|
||||||
json_data = json.dumps(data_ret)
|
return result
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
if Forwardings.objects.filter(source=source).count() == 0:
|
return coreResult
|
||||||
forwarding = Forwardings(source=source, destination=source)
|
|
||||||
forwarding.save()
|
|
||||||
|
|
||||||
|
|
||||||
forwarding = Forwardings(source=source, destination=destination)
|
|
||||||
forwarding.save()
|
|
||||||
|
|
||||||
data_ret = {'createStatus': 1, 'error_message': "None", 'successMessage':'Successfully Created!'}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'createStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'createStatus': 0, 'error_message': str(msg)}
|
data_ret = {'createStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -378,65 +136,26 @@ def submitEmailForwardingCreation(request):
|
|||||||
|
|
||||||
def changeEmailAccountPassword(request):
|
def changeEmailAccountPassword(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.changeEmailAccountPassword()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['changeEmailPassword'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists('/home/cyberpanel/postfix'):
|
|
||||||
return render(request, "mailServer/changeEmailPassword.html", {"status": 0})
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'mailServer/changeEmailPassword.html', {'websiteList':websitesName, "status": 1})
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse(str(msg))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitPasswordChange(request):
|
def submitPasswordChange(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preSubmitPasswordChange(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['changeEmailPassword'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('passChangeStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
data = json.loads(request.body)
|
|
||||||
domain = data['domain']
|
|
||||||
email = data['email']
|
|
||||||
password = data['password']
|
|
||||||
|
|
||||||
emailDB = EUsers.objects.get(email=email)
|
msM = MailServerManager(request)
|
||||||
emailDB.delete()
|
coreResult = msM.submitPasswordChange()
|
||||||
|
|
||||||
dom = Domains(domain=domain)
|
result = pluginManager.postSubmitPasswordChange(request, coreResult)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
emailAcct = EUsers(emailOwner=dom, email=email, password=password)
|
return coreResult
|
||||||
emailAcct.save()
|
|
||||||
|
|
||||||
data_ret = {'passChangeStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
|
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -446,74 +165,15 @@ def submitPasswordChange(request):
|
|||||||
|
|
||||||
def dkimManager(request):
|
def dkimManager(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.dkimManager()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['dkimManager'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
openDKIMInstalled = 0
|
|
||||||
|
|
||||||
if mailUtilities.checkIfDKIMInstalled() == 1:
|
|
||||||
openDKIMInstalled = 1
|
|
||||||
|
|
||||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
|
||||||
|
|
||||||
return render(request, 'mailServer/dkimManager.html',
|
|
||||||
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
|
|
||||||
|
|
||||||
return render(request, 'mailServer/dkimManager.html',
|
|
||||||
{'openDKIMInstalled': openDKIMInstalled})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def fetchDKIMKeys(request):
|
def fetchDKIMKeys(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.fetchDKIMKeys()
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['dkimManager'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
|
||||||
domainName = data['domainName']
|
|
||||||
|
|
||||||
try:
|
|
||||||
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
|
||||||
command = "sudo cat " + path
|
|
||||||
output = subprocess.check_output(shlex.split(command))
|
|
||||||
|
|
||||||
path = "/etc/opendkim/keys/" + domainName + "/default.private"
|
|
||||||
command = "sudo cat " + path
|
|
||||||
privateKey = subprocess.check_output(shlex.split(command))
|
|
||||||
|
|
||||||
data_ret = {'fetchStatus': 1, 'keysAvailable': 1, 'publicKey': output[53:269],
|
|
||||||
'privateKey': privateKey, 'dkimSuccessMessage': 'Keys successfully fetched!', 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'fetchStatus': 1, 'keysAvailable': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
except KeyError,msg:
|
||||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -521,58 +181,19 @@ def fetchDKIMKeys(request):
|
|||||||
|
|
||||||
def generateDKIMKeys(request):
|
def generateDKIMKeys(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preGenerateDKIMKeys(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['dkimManager'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('generateStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
data = json.loads(request.body)
|
msM = MailServerManager(request)
|
||||||
domainName = data['domainName']
|
coreResult = msM.generateDKIMKeys()
|
||||||
|
|
||||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
result = pluginManager.postGenerateDKIMKeys(request, coreResult)
|
||||||
execPath = execPath + " generateKeys --domain " + domainName
|
if result != 200:
|
||||||
output = subprocess.check_output(shlex.split(execPath))
|
return result
|
||||||
|
|
||||||
if output.find("1,None") > -1:
|
return coreResult
|
||||||
|
|
||||||
zone = dnsDomains.objects.get(name=domainName)
|
|
||||||
zone.save()
|
|
||||||
|
|
||||||
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
|
||||||
command = "sudo cat " + path
|
|
||||||
output = subprocess.check_output(shlex.split(command))
|
|
||||||
|
|
||||||
record = dnsRecords(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name="default._domainkey." + domainName,
|
|
||||||
type="TXT",
|
|
||||||
content="v=DKIM1; k=rsa; p=" + output[53:269],
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
data_ret = {'generateStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
else:
|
|
||||||
data_ret = {'generateStatus': 0, 'error_message': output}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
|
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -580,24 +201,8 @@ def generateDKIMKeys(request):
|
|||||||
|
|
||||||
def installOpenDKIM(request):
|
def installOpenDKIM(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
msM = MailServerManager(request)
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
return msM.installOpenDKIM()
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['dkimManager'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('installOpenDKIM', 0)
|
|
||||||
|
|
||||||
try:
|
|
||||||
thread.start_new_thread(mailUtilities.installOpenDKIM, ('Install','openDKIM'))
|
|
||||||
final_json = json.dumps({'installOpenDKIM': 1, 'error_message': "None"})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
except BaseException,msg:
|
|
||||||
final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
final_dic = {'installOpenDKIM': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
final_dic = {'installOpenDKIM': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
@@ -605,59 +210,8 @@ def installOpenDKIM(request):
|
|||||||
|
|
||||||
def installStatusOpenDKIM(request):
|
def installStatusOpenDKIM(request):
|
||||||
try:
|
try:
|
||||||
val = request.session['userID']
|
msM = MailServerManager()
|
||||||
try:
|
return msM.installStatusOpenDKIM()
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
command = "sudo cat " + mailUtilities.installLogPath
|
|
||||||
installStatus = subprocess.check_output(shlex.split(command))
|
|
||||||
|
|
||||||
if installStatus.find("[200]")>-1:
|
|
||||||
|
|
||||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
|
||||||
|
|
||||||
execPath = execPath + " configureOpenDKIM"
|
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(execPath))
|
|
||||||
|
|
||||||
if output.find("1,None") > -1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
final_json = json.dumps({
|
|
||||||
'error_message': "Failed to install OpenDKIM configurations.",
|
|
||||||
'requestStatus': installStatus,
|
|
||||||
'abort': 1,
|
|
||||||
'installed': 0,
|
|
||||||
})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
final_json = json.dumps({
|
|
||||||
'error_message': "None",
|
|
||||||
'requestStatus': installStatus,
|
|
||||||
'abort':1,
|
|
||||||
'installed': 1,
|
|
||||||
})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
elif installStatus.find("[404]") > -1:
|
|
||||||
|
|
||||||
final_json = json.dumps({
|
|
||||||
'abort':1,
|
|
||||||
'installed':0,
|
|
||||||
'error_message': "None",
|
|
||||||
'requestStatus': installStatus,
|
|
||||||
})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
else:
|
|
||||||
final_json = json.dumps({
|
|
||||||
'abort':0,
|
|
||||||
'error_message': "None",
|
|
||||||
'requestStatus': installStatus,
|
|
||||||
})
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
except BaseException,msg:
|
|
||||||
final_dic = {'abort':1,'installed':0, 'error_message': str(msg)}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
final_dic = {'abort':1,'installed':0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
final_dic = {'abort':1,'installed':0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
|
|||||||
201
packages/packagesManager.py
Normal file
201
packages/packagesManager.py
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
#!/usr/local/CyberCP/bin/python2
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
import django
|
||||||
|
sys.path.append('/usr/local/CyberCP')
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
|
from django.shortcuts import render,redirect
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from loginSystem.views import loadLoginPage
|
||||||
|
from loginSystem.models import Administrator
|
||||||
|
import json
|
||||||
|
from .models import Package
|
||||||
|
from plogical.acl import ACLManager
|
||||||
|
|
||||||
|
class PackagesManager:
|
||||||
|
def __init__(self, request = None):
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
def packagesHome(self):
|
||||||
|
try:
|
||||||
|
val = self.request.session['userID']
|
||||||
|
return render(self.request, 'packages/index.html', {})
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def createPacakge(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createPackage') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
admin = Administrator.objects.get(pk=userID)
|
||||||
|
return render(self.request, 'packages/createPackage.html', {"admin": admin.userName})
|
||||||
|
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def deletePacakge(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deletePackage') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
packageList = ACLManager.loadPackages(userID, currentACL)
|
||||||
|
return render(self.request, 'packages/deletePackage.html', {"packageList": packageList})
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def submitPackage(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'createPackage') == 0:
|
||||||
|
return ACLManager.loadErrorJson('saveStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
packageName = data['packageName']
|
||||||
|
packageSpace = int(data['diskSpace'])
|
||||||
|
packageBandwidth = int(data['bandwidth'])
|
||||||
|
packageDatabases = int(data['dataBases'])
|
||||||
|
ftpAccounts = int(data['ftpAccounts'])
|
||||||
|
emails = int(data['emails'])
|
||||||
|
allowedDomains = int(data['allowedDomains'])
|
||||||
|
|
||||||
|
if packageSpace < 0 or packageBandwidth < 0 or packageDatabases < 0 or ftpAccounts < 0 or emails < 0 or allowedDomains < 0:
|
||||||
|
data_ret = {'saveStatus': 0, 'error_message': "All values should be positive or 0."}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
admin = Administrator.objects.get(pk=userID)
|
||||||
|
|
||||||
|
packageName = admin.userName + "_" + packageName
|
||||||
|
|
||||||
|
package = Package(admin=admin, packageName=packageName, diskSpace=packageSpace,
|
||||||
|
bandwidth=packageBandwidth, ftpAccounts=ftpAccounts, dataBases=packageDatabases,
|
||||||
|
emailAccounts=emails, allowedDomains=allowedDomains)
|
||||||
|
|
||||||
|
package.save()
|
||||||
|
|
||||||
|
data_ret = {'saveStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'saveStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def submitDelete(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'deletePackage') == 0:
|
||||||
|
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
packageName = data['packageName']
|
||||||
|
|
||||||
|
delPackage = Package.objects.get(packageName=packageName)
|
||||||
|
delPackage.delete()
|
||||||
|
|
||||||
|
data_ret = {'deleteStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def modifyPackage(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'modifyPackage') == 0:
|
||||||
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
packageList = ACLManager.loadPackages(userID, currentACL)
|
||||||
|
return render(self.request, 'packages/modifyPackage.html', {"packList": packageList})
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
|
def submitModify(self):
|
||||||
|
try:
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
packageName = data['packageName']
|
||||||
|
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'modifyPackage') == 0:
|
||||||
|
return ACLManager.loadErrorJson('modifyStatus', 0)
|
||||||
|
|
||||||
|
modifyPack = Package.objects.get(packageName=packageName)
|
||||||
|
|
||||||
|
diskSpace = modifyPack.diskSpace
|
||||||
|
bandwidth = modifyPack.bandwidth
|
||||||
|
ftpAccounts = modifyPack.ftpAccounts
|
||||||
|
dataBases = modifyPack.dataBases
|
||||||
|
emails = modifyPack.emailAccounts
|
||||||
|
|
||||||
|
data_ret = {'emails': emails, 'modifyStatus': 1, 'error_message': "None",
|
||||||
|
"diskSpace": diskSpace, "bandwidth": bandwidth, "ftpAccounts": ftpAccounts,
|
||||||
|
"dataBases": dataBases, "allowedDomains": modifyPack.allowedDomains}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'modifyStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def saveChanges(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
userID = self.request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'modifyPackage') == 0:
|
||||||
|
return ACLManager.loadErrorJson('saveStatus', 0)
|
||||||
|
|
||||||
|
data = json.loads(self.request.body)
|
||||||
|
packageName = data['packageName']
|
||||||
|
|
||||||
|
if data['diskSpace'] < 0 or data['bandwidth'] < 0 or data['ftpAccounts'] < 0 or data[
|
||||||
|
'dataBases'] < 0 or \
|
||||||
|
data['emails'] < 0 or data['allowedDomains'] < 0:
|
||||||
|
data_ret = {'saveStatus': 0, 'error_message': "All values should be positive or 0."}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
modifyPack = Package.objects.get(packageName=packageName)
|
||||||
|
|
||||||
|
modifyPack.diskSpace = data['diskSpace']
|
||||||
|
modifyPack.bandwidth = data['bandwidth']
|
||||||
|
modifyPack.ftpAccounts = data['ftpAccounts']
|
||||||
|
modifyPack.dataBases = data['dataBases']
|
||||||
|
modifyPack.emailAccounts = data['emails']
|
||||||
|
modifyPack.allowedDomains = data['allowedDomains']
|
||||||
|
modifyPack.save()
|
||||||
|
|
||||||
|
data_ret = {'saveStatus': 1, 'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'saveStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
36
packages/pluginManager.py
Normal file
36
packages/pluginManager.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
from signals import *
|
||||||
|
from plogical.pluginManagerGlobal import pluginManagerGlobal
|
||||||
|
|
||||||
|
class pluginManager:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preCreatePacakge(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preCreatePacakge)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postCreatePacakge(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postCreatePacakge, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitPackage(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitPackage)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitPackage(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitPackage, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSubmitDelete(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSubmitDelete)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSubmitDelete(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSubmitDelete, response)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preSaveChanges(request):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, preSaveChanges)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postSaveChanges(request, response):
|
||||||
|
return pluginManagerGlobal.globalPlug(request, postSaveChanges, response)
|
||||||
29
packages/signals.py
Normal file
29
packages/signals.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# The world is a prison for the believer.
|
||||||
|
## https://www.youtube.com/watch?v=DWfNYztUM1U
|
||||||
|
|
||||||
|
from django.dispatch import Signal
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core load the create package template, this special event is used
|
||||||
|
## to create a beautiful names official plugin. Actual package creation happes with event named preSubmitPackage and postSubmitPackage.
|
||||||
|
preCreatePacakge = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## See info for preCreatePacakge
|
||||||
|
postCreatePacakge = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start creation a package.
|
||||||
|
preSubmitPackage = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished creation of a package.
|
||||||
|
postSubmitPackage = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start deletion of a package.
|
||||||
|
preSubmitDelete = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished deletion of a package.
|
||||||
|
postSubmitDelete = Signal(providing_args=["request", "response"])
|
||||||
|
|
||||||
|
## This event is fired before CyberPanel core start to modify a package.
|
||||||
|
preSaveChanges = Signal(providing_args=["request"])
|
||||||
|
|
||||||
|
## This event is fired after CyberPanel core finished modifying a package.
|
||||||
|
postSaveChanges = Signal(providing_args=["request", "response"])
|
||||||
@@ -1,258 +1,110 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.shortcuts import render,redirect
|
from django.shortcuts import redirect
|
||||||
from django.http import HttpResponse
|
|
||||||
from loginSystem.views import loadLoginPage
|
from loginSystem.views import loadLoginPage
|
||||||
from loginSystem.models import Administrator
|
from packagesManager import PackagesManager
|
||||||
import json
|
from pluginManager import pluginManager
|
||||||
from .models import Package
|
|
||||||
import plogical.CyberCPLogFileWriter as logging
|
|
||||||
from plogical.acl import ACLManager
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def packagesHome(request):
|
def packagesHome(request):
|
||||||
try:
|
try:
|
||||||
val = request.session['userID']
|
pm = PackagesManager(request)
|
||||||
|
return pm.packagesHome()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
return render(request,'packages/index.html',{})
|
|
||||||
|
|
||||||
def createPacakge(request):
|
def createPacakge(request):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
admin = Administrator.objects.get(pk=userID)
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preCreatePacakge(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['createPackage'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
return render(request, 'packages/createPackage.html', {"admin": admin.userName})
|
pm = PackagesManager(request)
|
||||||
|
coreResult = pm.createPacakge()
|
||||||
|
|
||||||
|
result = pluginManager.postCreatePacakge(request, coreResult)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
|
return coreResult
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def deletePacakge(request):
|
def deletePacakge(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
pm = PackagesManager(request)
|
||||||
try:
|
return pm.deletePacakge()
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['deletePackage'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
packageList = ACLManager.loadPackages(userID, currentACL)
|
|
||||||
return render(request, 'packages/deletePackage.html', {"packageList": packageList})
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse("Please see CyberCP Main Log File")
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitPackage(request):
|
def submitPackage(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
result = pluginManager.preSubmitPackage(request)
|
||||||
pass
|
if result != 200:
|
||||||
elif currentACL['createPackage'] == 1:
|
return result
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('saveStatus', 0)
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
data = json.loads(request.body)
|
|
||||||
packageName = data['packageName']
|
|
||||||
packageSpace = int(data['diskSpace'])
|
|
||||||
packageBandwidth = int(data['bandwidth'])
|
|
||||||
packageDatabases = int(data['dataBases'])
|
|
||||||
ftpAccounts = int(data['ftpAccounts'])
|
|
||||||
emails = int(data['emails'])
|
|
||||||
allowedDomains = int(data['allowedDomains'])
|
|
||||||
|
|
||||||
|
pm = PackagesManager(request)
|
||||||
|
coreResult = pm.submitPackage()
|
||||||
|
|
||||||
if packageSpace < 0 or packageBandwidth < 0 or packageDatabases < 0 or ftpAccounts < 0 or emails < 0 or allowedDomains < 0:
|
result = pluginManager.postSubmitPackage(request, coreResult)
|
||||||
data_ret = {'saveStatus': 0, 'error_message': "All values should be positive or 0."}
|
if result != 200:
|
||||||
json_data = json.dumps(data_ret)
|
return result
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
admin = Administrator.objects.get(pk=userID)
|
return coreResult
|
||||||
|
|
||||||
packageName = admin.userName + "_" + packageName
|
|
||||||
|
|
||||||
package = Package(admin=admin, packageName=packageName, diskSpace=packageSpace,
|
|
||||||
bandwidth=packageBandwidth, ftpAccounts=ftpAccounts, dataBases=packageDatabases,
|
|
||||||
emailAccounts=emails, allowedDomains=allowedDomains)
|
|
||||||
|
|
||||||
package.save()
|
|
||||||
|
|
||||||
data_ret = {'saveStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'saveStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitDelete(request):
|
def submitDelete(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
try:
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
result = pluginManager.preSubmitDelete(request)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
pm = PackagesManager(request)
|
||||||
pass
|
coreResult = pm.submitDelete()
|
||||||
elif currentACL['deletePackage'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
result = pluginManager.postSubmitDelete(request, coreResult)
|
||||||
data = json.loads(request.body)
|
if result != 200:
|
||||||
packageName = data['packageName']
|
return result
|
||||||
|
|
||||||
delPackage = Package.objects.get(packageName=packageName)
|
return coreResult
|
||||||
delPackage.delete()
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
data_ret = {'deleteStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def modifyPackage(request):
|
def modifyPackage(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
pm = PackagesManager(request)
|
||||||
try:
|
return pm.modifyPackage()
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['modifyPackage'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
|
|
||||||
packageList = ACLManager.loadPackages(userID, currentACL)
|
|
||||||
return render(request, 'packages/modifyPackage.html', {"packList": packageList})
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
||||||
return HttpResponse("Please see CyberCP Main Log File")
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitModify(request):
|
def submitModify(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
pm = PackagesManager(request)
|
||||||
try:
|
return pm.submitModify()
|
||||||
if request.method == 'POST':
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
data = json.loads(request.body)
|
|
||||||
packageName = data['packageName']
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
|
||||||
pass
|
|
||||||
elif currentACL['modifyPackage'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('modifyStatus', 0)
|
|
||||||
|
|
||||||
modifyPack = Package.objects.get(packageName=packageName)
|
|
||||||
|
|
||||||
diskSpace = modifyPack.diskSpace
|
|
||||||
bandwidth = modifyPack.bandwidth
|
|
||||||
ftpAccounts = modifyPack.ftpAccounts
|
|
||||||
dataBases = modifyPack.dataBases
|
|
||||||
emails = modifyPack.emailAccounts
|
|
||||||
|
|
||||||
data_ret = {'emails': emails, 'modifyStatus': 1, 'error_message': "None",
|
|
||||||
"diskSpace": diskSpace, "bandwidth": bandwidth, "ftpAccounts": ftpAccounts,
|
|
||||||
"dataBases": dataBases, "allowedDomains": modifyPack.allowedDomains}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'modifyStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'modifyStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
def saveChanges(request):
|
def saveChanges(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
|
||||||
try:
|
|
||||||
if request.method == 'POST':
|
|
||||||
data = json.loads(request.body)
|
|
||||||
packageName = data['packageName']
|
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
result = pluginManager.preSaveChanges(request)
|
||||||
|
if result != 200:
|
||||||
|
return result
|
||||||
|
|
||||||
if currentACL['admin'] == 1:
|
pm = PackagesManager(request)
|
||||||
pass
|
coreResult = pm.saveChanges()
|
||||||
elif currentACL['modifyPackage'] == 1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return ACLManager.loadErrorJson('saveStatus', 0)
|
|
||||||
|
|
||||||
if data['diskSpace'] < 0 or data['bandwidth'] < 0 or data['ftpAccounts'] < 0 or data['dataBases'] < 0 or \
|
result = pluginManager.postSaveChanges(request, coreResult)
|
||||||
data['emails'] < 0 or data['allowedDomains'] < 0:
|
if result != 200:
|
||||||
data_ret = {'saveStatus': 0, 'error_message': "All values should be positive or 0."}
|
return result
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
modifyPack = Package.objects.get(packageName=packageName)
|
return coreResult
|
||||||
|
except KeyError:
|
||||||
modifyPack.diskSpace = data['diskSpace']
|
return redirect(loadLoginPage)
|
||||||
modifyPack.bandwidth = data['bandwidth']
|
|
||||||
modifyPack.ftpAccounts = data['ftpAccounts']
|
|
||||||
modifyPack.dataBases = data['dataBases']
|
|
||||||
modifyPack.emailAccounts = data['emails']
|
|
||||||
modifyPack.allowedDomains = data['allowedDomains']
|
|
||||||
modifyPack.save()
|
|
||||||
|
|
||||||
data_ret = {'saveStatus': 1, 'error_message': "None"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
data_ret = {'saveStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
except KeyError,msg:
|
|
||||||
data_ret = {'saveStatus': 0, 'error_message': str(msg)}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class BackupManager:
|
|||||||
## /home/example.com/backup/backup-example-06-50-03-Thu-Feb-2018
|
## /home/example.com/backup/backup-example-06-50-03-Thu-Feb-2018
|
||||||
tempStoragePath = os.path.join(backupPath, backupName)
|
tempStoragePath = os.path.join(backupPath, backupName)
|
||||||
|
|
||||||
execPath = "sudo nice -n python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
execPath = "sudo nice -n 10 python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||||
execPath = execPath + " submitBackupCreation --tempStoragePath " + tempStoragePath + " --backupName " \
|
execPath = execPath + " submitBackupCreation --tempStoragePath " + tempStoragePath + " --backupName " \
|
||||||
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain
|
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ class BackupManager:
|
|||||||
else:
|
else:
|
||||||
dir = "CyberPanelRestore"
|
dir = "CyberPanelRestore"
|
||||||
|
|
||||||
execPath = "sudo nice -n python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
execPath = "sudo nice -n 10 python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||||
execPath = execPath + " submitRestore --backupFile " + backupFile + " --dir " + dir
|
execPath = execPath + " submitRestore --backupFile " + backupFile + " --dir " + dir
|
||||||
subprocess.Popen(shlex.split(execPath))
|
subprocess.Popen(shlex.split(execPath))
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
|
|||||||
0
pluginHolder/__init__.py
Normal file
0
pluginHolder/__init__.py
Normal file
6
pluginHolder/admin.py
Normal file
6
pluginHolder/admin.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
8
pluginHolder/apps.py
Normal file
8
pluginHolder/apps.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class PluginholderConfig(AppConfig):
|
||||||
|
name = 'pluginHolder'
|
||||||
0
pluginHolder/migrations/__init__.py
Normal file
0
pluginHolder/migrations/__init__.py
Normal file
6
pluginHolder/models.py
Normal file
6
pluginHolder/models.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
83
pluginHolder/templates/pluginHolder/plugins.html
Normal file
83
pluginHolder/templates/pluginHolder/plugins.html
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
{% extends "baseTemplate/index.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% block title %}Installed Plugin - CyberPanel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
{% get_current_language as LANGUAGE_CODE %}
|
||||||
|
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||||
|
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div id="page-title">
|
||||||
|
<h2 id="domainNamePage">{% trans "Plugins" %}</h2>
|
||||||
|
<p>{% trans "List of installed plugins on your CyberPanel." %}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-body">
|
||||||
|
<h3 class="title-hero">
|
||||||
|
{% trans "Websites" %}
|
||||||
|
</h3>
|
||||||
|
<div ng-controller="listWebsites" class="example-box-wrapper">
|
||||||
|
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="datatable-example">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Name" %}</th>
|
||||||
|
<th>{% trans "Type" %}</th>
|
||||||
|
<th>{% trans "Description" %}</th>
|
||||||
|
<th>{% trans "Version" %}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
{% for plugin in plugins %}
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>{{ plugin.name }}</td>
|
||||||
|
<td>{{ plugin.type }}</td>
|
||||||
|
<td>{{ plugin.desc }}</td>
|
||||||
|
<td >{{ plugin.version }}</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div id="listFail" class="alert alert-danger">
|
||||||
|
<p>{% trans "Cannot list websites. Error message:" %} {$ errorMessage $}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-sm-4 col-sm-offset-8">
|
||||||
|
|
||||||
|
<nav aria-label="Page navigation">
|
||||||
|
<ul class="pagination">
|
||||||
|
|
||||||
|
|
||||||
|
{% for items in pagination %}
|
||||||
|
|
||||||
|
<li ng-click="getFurtherWebsitesFromDB({{ forloop.counter }})" id="webPages"><a href="">{{ forloop.counter }}</a></li>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
6
pluginHolder/tests.py
Normal file
6
pluginHolder/tests.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
8
pluginHolder/urls.py
Normal file
8
pluginHolder/urls.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
from django.conf.urls import url
|
||||||
|
import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
|
||||||
|
url(r'^installed$', views.installed, name='installed'),
|
||||||
|
]
|
||||||
29
pluginHolder/views.py
Normal file
29
pluginHolder/views.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.shortcuts import render
|
||||||
|
from plogical.mailUtilities import mailUtilities
|
||||||
|
import os
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
|
|
||||||
|
def installed(request):
|
||||||
|
|
||||||
|
mailUtilities.checkHome()
|
||||||
|
pluginPath = '/home/cyberpanel/plugins'
|
||||||
|
pluginList = []
|
||||||
|
|
||||||
|
for plugin in os.listdir(pluginPath):
|
||||||
|
data = {}
|
||||||
|
completePath = '/usr/local/CyberCP/' + plugin + '/meta.xml'
|
||||||
|
pluginMetaData = ElementTree.parse(completePath)
|
||||||
|
|
||||||
|
data['name'] = pluginMetaData.find('name').text
|
||||||
|
data['type'] = pluginMetaData.find('type').text
|
||||||
|
data['desc'] = pluginMetaData.find('description').text
|
||||||
|
data['version'] = pluginMetaData.find('version').text
|
||||||
|
|
||||||
|
pluginList.append(data)
|
||||||
|
|
||||||
|
|
||||||
|
return render(request, 'pluginHolder/plugins.html',{'plugins': pluginList})
|
||||||
@@ -46,13 +46,11 @@ class pluginInstaller:
|
|||||||
def upgradingURLs(pluginName):
|
def upgradingURLs(pluginName):
|
||||||
data = open("/usr/local/CyberCP/CyberCP/urls.py", 'r').readlines()
|
data = open("/usr/local/CyberCP/CyberCP/urls.py", 'r').readlines()
|
||||||
writeToFile = open("/usr/local/CyberCP/CyberCP/urls.py", 'w')
|
writeToFile = open("/usr/local/CyberCP/CyberCP/urls.py", 'w')
|
||||||
print('hello world')
|
|
||||||
|
|
||||||
for items in data:
|
for items in data:
|
||||||
if items.find("manageservices") > -1:
|
if items.find("manageservices") > -1:
|
||||||
writeToFile.writelines(items)
|
writeToFile.writelines(items)
|
||||||
writeToFile.writelines(" url(r'^" + pluginName + "/',include('" + pluginName + ".urls')),\n")
|
writeToFile.writelines(" url(r'^" + pluginName + "/',include('" + pluginName + ".urls')),\n")
|
||||||
print('hello world')
|
|
||||||
else:
|
else:
|
||||||
writeToFile.writelines(items)
|
writeToFile.writelines(items)
|
||||||
|
|
||||||
@@ -74,31 +72,80 @@ class pluginInstaller:
|
|||||||
data = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'r').readlines()
|
data = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'r').readlines()
|
||||||
writeToFile = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'w')
|
writeToFile = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'w')
|
||||||
|
|
||||||
pluginCheck = 0
|
|
||||||
|
|
||||||
for items in data:
|
for items in data:
|
||||||
if items.find('<span>{% trans "Plugins" %}</span>') > -1:
|
if items.find("{% url 'installed' %}") > -1:
|
||||||
pluginCheck = 1
|
|
||||||
elif pluginCheck == 1 and items.find('<ul>'):
|
|
||||||
writeToFile.writelines(items)
|
writeToFile.writelines(items)
|
||||||
writeToFile.writelines('<li><a href="{% url \'' + pluginName + '\' %}" title="{% trans \'' + pluginName + '\' %}"><span>{% trans "' + pluginName + '" %}</span></a></li>')
|
writeToFile.writelines(
|
||||||
pluginCheck = 0
|
'<li><a href="{% url \'' + pluginName + '\' %}" title="{% trans \'' + pluginName + '\' %}"><span>{% trans "' + pluginName + '" %}</span></a></li>')
|
||||||
else:
|
else:
|
||||||
writeToFile.writelines(items)
|
writeToFile.writelines(items)
|
||||||
|
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def staticContent():
|
||||||
|
currentDir = os.getcwd()
|
||||||
|
|
||||||
|
command = "rm -rf /usr/local/lscp/cyberpanel/static"
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
os.chdir('/usr/local/CyberCP')
|
||||||
|
|
||||||
|
command = "python manage.py collectstatic --noinput"
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel"
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
|
||||||
|
os.chdir(currentDir)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def preScript(pluginName):
|
||||||
|
pluginHome = '/usr/local/CyberCP/' + pluginName
|
||||||
|
|
||||||
|
if os.path.exists(pluginHome + '/pre_install'):
|
||||||
|
command = 'chmod +x ' + pluginHome + '/pre_install'
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
command = pluginHome + '/pre_install'
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def postScript(pluginName):
|
||||||
|
pluginHome = '/usr/local/CyberCP/' + pluginName
|
||||||
|
|
||||||
|
if os.path.exists(pluginHome + '/post_install'):
|
||||||
|
command = 'chmod +x ' + pluginHome + '/post_install'
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
command = pluginHome + '/post_install'
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def installPlugin(pluginName):
|
def installPlugin(pluginName):
|
||||||
try:
|
try:
|
||||||
##
|
##
|
||||||
|
|
||||||
pluginInstaller.stdOut('Extracting plugin.')
|
pluginInstaller.stdOut('Extracting plugin..')
|
||||||
pluginInstaller.extractPlugin(pluginName)
|
pluginInstaller.extractPlugin(pluginName)
|
||||||
pluginInstaller.stdOut('Plugin extracted.')
|
pluginInstaller.stdOut('Plugin extracted.')
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
pluginInstaller.stdOut('Executing pre_install script..')
|
||||||
|
pluginInstaller.preScript(pluginName)
|
||||||
|
pluginInstaller.stdOut('pre_install executed.')
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
pluginInstaller.stdOut('Executing post_install script..')
|
||||||
|
pluginInstaller.postScript(pluginName)
|
||||||
|
pluginInstaller.stdOut('post_install executed.')
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
pluginInstaller.stdOut('Restoring settings file.')
|
pluginInstaller.stdOut('Restoring settings file.')
|
||||||
pluginInstaller.upgradingSettingsFile(pluginName)
|
pluginInstaller.upgradingSettingsFile(pluginName)
|
||||||
pluginInstaller.stdOut('Settings file restored.')
|
pluginInstaller.stdOut('Settings file restored.')
|
||||||
@@ -125,6 +172,14 @@ class pluginInstaller:
|
|||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
pluginInstaller.stdOut('Upgrading static content..')
|
||||||
|
pluginInstaller.staticContent()
|
||||||
|
pluginInstaller.stdOut('Static content upgraded.')
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
pluginInstaller.restartGunicorn()
|
pluginInstaller.restartGunicorn()
|
||||||
|
|
||||||
pluginInstaller.stdOut('Plugin successfully installed.')
|
pluginInstaller.stdOut('Plugin successfully installed.')
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# The world is a prison for the believer.
|
# The world is a prison for the believer.
|
||||||
|
## https://www.youtube.com/watch?v=DWfNYztUM1U
|
||||||
|
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user