mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-10-26 07:46:35 +01:00
Plugin installer
This commit is contained in:
@@ -16,7 +16,7 @@ class secMiddleware:
|
||||
pass
|
||||
else:
|
||||
continue
|
||||
if key == 'configData' or key == 'rewriteRules' or key == 'modSecRules':
|
||||
if key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'recordContentTXT':
|
||||
continue
|
||||
if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1:
|
||||
logging.writeToFile(request.body)
|
||||
|
||||
@@ -59,6 +59,7 @@ INSTALLED_APPS = [
|
||||
'api',
|
||||
'filemanager',
|
||||
'manageServices',
|
||||
'pluginHolder',
|
||||
'emailPremium',
|
||||
]
|
||||
|
||||
|
||||
@@ -37,4 +37,5 @@ urlpatterns = [
|
||||
url(r'^filemanager/',include('filemanager.urls')),
|
||||
url(r'^emailPremium/',include('emailPremium.urls')),
|
||||
url(r'^manageservices/',include('manageServices.urls')),
|
||||
url(r'^plugins/',include('pluginHolder.urls')),
|
||||
]
|
||||
|
||||
@@ -583,6 +583,7 @@
|
||||
<div class="sidebar-submenu">
|
||||
|
||||
<ul>
|
||||
<li><a href="{% url 'installed' %}" title="{% trans 'Installed Plugins' %}"><span>{% trans "Installed" %}</span></a></li>
|
||||
</ul>
|
||||
|
||||
</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 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render,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 django.shortcuts import redirect
|
||||
from loginSystem.views import loadLoginPage
|
||||
from models import Databases
|
||||
from databaseManager import DatabaseManager
|
||||
from pluginManager import pluginManager
|
||||
import json
|
||||
import shlex
|
||||
import subprocess
|
||||
from plogical.acl import ACLManager
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def loadDatabaseHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
return render(request, 'databases/index.html')
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.loadDatabaseHome(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def createDatabase(request):
|
||||
try:
|
||||
result = pluginManager.preCreateDatabase(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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:
|
||||
pass
|
||||
elif currentACL['createDatabase'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
return coreResult
|
||||
|
||||
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:
|
||||
return redirect(loadLoginPage)
|
||||
@@ -55,228 +39,80 @@ def createDatabase(request):
|
||||
def submitDBCreation(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
data = json.loads(request.body)
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
dbName = data['dbName']
|
||||
dbUsername = data['dbUsername']
|
||||
dbPassword = data['dbPassword']
|
||||
webUsername = data['webUserName']
|
||||
result = pluginManager.preSubmitDBCreation(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.submitDBCreation(userID, request.data)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['createDatabase'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('createDBStatus', 0)
|
||||
result = pluginManager.postSubmitDBCreation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
dbName = webUsername+"_"+dbName
|
||||
dbUsername = webUsername+"_"+dbUsername
|
||||
return coreResult
|
||||
|
||||
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)
|
||||
except KeyError,msg:
|
||||
data_ret = {'createDBStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deleteDatabase(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
|
||||
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))
|
||||
|
||||
dm = DatabaseManager()
|
||||
return dm.deleteDatabase(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchDatabases(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
data = 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)
|
||||
|
||||
dm = DatabaseManager()
|
||||
return dm.fetchDatabases(userID, json.loads(request.body))
|
||||
except KeyError:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
final_json = json.dumps({'fetchStatus': 0, 'error_message': "Not logged in."})
|
||||
return HttpResponse(final_json)
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitDatabaseDeletion(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
data = json.loads(request.body)
|
||||
dbName = data['dbName']
|
||||
result = pluginManager.preSubmitDatabaseDeletion(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.submitDatabaseDeletion(userID, json.loads(request.body))
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['deleteDatabase'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||
result = pluginManager.postSubmitDatabaseDeletion(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
except KeyError,msg:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def listDBs(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(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))
|
||||
|
||||
dm = DatabaseManager()
|
||||
return dm.listDBs(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def changePassword(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
data = json.loads(request.body)
|
||||
userName = data['dbUserName']
|
||||
dbPassword = data['dbPassword']
|
||||
result = pluginManager.preChangePassword(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.changePassword(userID, json.loads(request.body))
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['listDatabases'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
||||
result = pluginManager.postChangePassword(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
except KeyError,msg:
|
||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
@@ -258,6 +258,7 @@ class DNSManager:
|
||||
if ACLManager.currentContextPermission(currentACL, 'addDeleteRecords') == 0:
|
||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||
|
||||
|
||||
zoneDomain = data['selectedZone']
|
||||
currentSelection = data['currentSelection']
|
||||
|
||||
@@ -532,7 +533,6 @@ class DNSManager:
|
||||
|
||||
delZone = Domains.objects.get(name=zoneDomain)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
if delZone.admin != admin:
|
||||
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 dnsManager import DNSManager
|
||||
from pluginManager import pluginManager
|
||||
import json
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@@ -32,7 +33,7 @@ def NSCreation(request):
|
||||
return result
|
||||
|
||||
dm = DNSManager()
|
||||
coreResult = dm.NSCreation(userID, request.body)
|
||||
coreResult = dm.NSCreation(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postNSCreation(request, coreResult)
|
||||
if result != 200:
|
||||
@@ -59,7 +60,7 @@ def zoneCreation(request):
|
||||
return result
|
||||
|
||||
dm = DNSManager()
|
||||
coreResult = dm.zoneCreation(userID, request.body)
|
||||
coreResult = dm.zoneCreation(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postZoneCreation(request, coreResult)
|
||||
if result != 200:
|
||||
@@ -81,7 +82,7 @@ def getCurrentRecordsForDomain(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DNSManager()
|
||||
return dm.getCurrentRecordsForDomain(userID, request.body)
|
||||
return dm.getCurrentRecordsForDomain(userID, json.loads(request.body))
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
@@ -94,7 +95,7 @@ def addDNSRecord(request):
|
||||
return result
|
||||
|
||||
dm = DNSManager()
|
||||
coreResult = dm.addDNSRecord(userID, request.body)
|
||||
coreResult = dm.addDNSRecord(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postAddDNSRecord(request, coreResult)
|
||||
if result != 200:
|
||||
@@ -114,7 +115,7 @@ def deleteDNSRecord(request):
|
||||
return result
|
||||
|
||||
dm = DNSManager()
|
||||
coreResult = dm.deleteDNSRecord(userID, request.body)
|
||||
coreResult = dm.deleteDNSRecord(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postDeleteDNSRecord(request, coreResult)
|
||||
if result != 200:
|
||||
@@ -128,7 +129,7 @@ def deleteDNSZone(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DNSManager()
|
||||
return dm.getCurrentRecordsForDomain(request, userID)
|
||||
return dm.deleteDNSZone(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
@@ -140,7 +141,7 @@ def submitZoneDeletion(request):
|
||||
return result
|
||||
|
||||
dm = DNSManager()
|
||||
coreResult = dm.submitZoneDeletion(userID, request.body)
|
||||
coreResult = dm.submitZoneDeletion(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postSubmitZoneDeletion(request, coreResult)
|
||||
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 -*-
|
||||
from __future__ import unicode_literals
|
||||
import hashlib
|
||||
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 django.shortcuts import redirect
|
||||
from ftpManager import FTPManager
|
||||
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
|
||||
from pluginManager import pluginManager
|
||||
# Create your views here.
|
||||
|
||||
def loadFTPHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
return render(request,'ftp/index.html')
|
||||
fm = FTPManager(request)
|
||||
return fm.loadFTPHome()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def createFTPAccount(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['createFTPAccount'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
result = pluginManager.preCreateFTPAccount(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
fm = FTPManager(request)
|
||||
coreResult = fm.createFTPAccount()
|
||||
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
result = pluginManager.postCreateFTPAccount(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
||||
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))
|
||||
return coreResult
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitFTPCreation(request):
|
||||
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:
|
||||
pass
|
||||
elif currentACL['createFTPAccount'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('creatFTPStatus', 0)
|
||||
fm = FTPManager(request)
|
||||
coreResult = fm.submitFTPCreation()
|
||||
|
||||
result = pluginManager.postSubmitFTPCreation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
data = json.loads(request.body)
|
||||
userName = data['ftpUserName']
|
||||
password = data['ftpPassword']
|
||||
path = data['path']
|
||||
domainName = data['ftpDomain']
|
||||
return coreResult
|
||||
|
||||
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)
|
||||
except KeyError,msg:
|
||||
data_ret = {'creatFTPStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deleteFTPAccount(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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))
|
||||
|
||||
fm = FTPManager(request)
|
||||
return fm.deleteFTPAccount()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchFTPAccounts(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
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)
|
||||
fm = FTPManager(request)
|
||||
return fm.fetchFTPAccounts()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitFTPDelete(request):
|
||||
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:
|
||||
pass
|
||||
elif currentACL['deleteFTPAccount'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||
fm = FTPManager(request)
|
||||
coreResult = fm.submitFTPDelete()
|
||||
|
||||
data = json.loads(request.body)
|
||||
ftpUserName = data['ftpUsername']
|
||||
result = pluginManager.postSubmitFTPDelete(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
FTPUtilities.submitFTPDeletion(ftpUserName)
|
||||
return coreResult
|
||||
|
||||
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)
|
||||
except KeyError,msg:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def listFTPAccounts(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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))
|
||||
|
||||
fm = FTPManager(request)
|
||||
return fm.listFTPAccounts()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def getAllFTPAccounts(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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)
|
||||
fm = FTPManager(request)
|
||||
return fm.getAllFTPAccounts()
|
||||
except KeyError:
|
||||
final_dic = {'fetchStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def changePassword(request):
|
||||
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)
|
||||
userName = data['ftpUserName']
|
||||
password = data['ftpPassword']
|
||||
result = pluginManager.preChangePassword(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
FTPUtilities.changeFTPPassword(userName, password)
|
||||
fm = FTPManager(request)
|
||||
coreResult = fm.changePassword()
|
||||
|
||||
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
result = pluginManager.postChangePassword(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
return coreResult
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
@@ -687,7 +687,7 @@ class preFlightsChecks:
|
||||
|
||||
count = 0
|
||||
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"
|
||||
res = subprocess.call(shlex.split(command))
|
||||
|
||||
@@ -707,7 +707,7 @@ class preFlightsChecks:
|
||||
|
||||
count = 0
|
||||
while(1):
|
||||
command = "tar zxf CyberPanel.1.7.2.tar.gz"
|
||||
command = "tar zxf CyberPanelTemp.tar.gz"
|
||||
#command = "tar zxf CyberPanelTemp.tar.gz"
|
||||
|
||||
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 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render,redirect
|
||||
from django.shortcuts import redirect
|
||||
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
|
||||
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
|
||||
from mailserverManager import MailServerManager
|
||||
from pluginManager import pluginManager
|
||||
|
||||
def loadEmailHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
return render(request, 'mailServer/index.html')
|
||||
msM = MailServerManager(request)
|
||||
return msM.loadEmailHome()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def createEmailAccount(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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))
|
||||
|
||||
msM = MailServerManager(request)
|
||||
return msM.createEmailAccount()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitEmailCreation(request):
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
result = pluginManager.preSubmitEmailCreation(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['createEmail'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('createEmailStatus', 0)
|
||||
msM = MailServerManager(request)
|
||||
coreResult = msM.submitEmailCreation()
|
||||
|
||||
data = json.loads(request.body)
|
||||
domainName = data['domain']
|
||||
userName = data['username']
|
||||
password = data['password']
|
||||
result = pluginManager.postSubmitEmailCreation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
## 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)
|
||||
|
||||
## 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)
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deleteEmailAccount(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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))
|
||||
|
||||
msM = MailServerManager(request)
|
||||
return msM.deleteEmailAccount()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def getEmailsForDomain(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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)
|
||||
msM = MailServerManager(request)
|
||||
return msM.getEmailsForDomain()
|
||||
except KeyError,msg:
|
||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -188,30 +58,19 @@ def getEmailsForDomain(request):
|
||||
|
||||
def submitEmailDeletion(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['deleteEmail'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('deleteEmailStatus', 0)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
result = pluginManager.preSubmitEmailDeletion(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
data = json.loads(request.body)
|
||||
email = data['email']
|
||||
msM = MailServerManager(request)
|
||||
coreResult = msM.submitEmailDeletion()
|
||||
|
||||
mailUtilities.deleteEmailAccount(email)
|
||||
data_ret = {'deleteEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
result = pluginManager.postSubmitEmailDeletion(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
except BaseException,msg:
|
||||
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return coreResult
|
||||
except KeyError,msg:
|
||||
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -219,77 +78,15 @@ def submitEmailDeletion(request):
|
||||
|
||||
def emailForwarding(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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))
|
||||
|
||||
msM = MailServerManager(request)
|
||||
return msM.emailForwarding()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchCurrentForwardings(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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)
|
||||
msM = MailServerManager(request)
|
||||
return msM.fetchCurrentForwardings()
|
||||
except KeyError,msg:
|
||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -297,33 +94,19 @@ def fetchCurrentForwardings(request):
|
||||
|
||||
def submitForwardDeletion(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['emailForwarding'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('deleteForwardingStatus', 0)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
result = pluginManager.preSubmitForwardDeletion(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
data = json.loads(request.body)
|
||||
destination = data['destination']
|
||||
source = data['source']
|
||||
msM = MailServerManager(request)
|
||||
coreResult = msM.submitForwardDeletion()
|
||||
|
||||
forwarding = Forwardings.objects.get(destination=destination, source=source)
|
||||
forwarding.delete()
|
||||
result = pluginManager.postSubmitForwardDeletion(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
return coreResult
|
||||
except KeyError,msg:
|
||||
data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -331,44 +114,19 @@ def submitForwardDeletion(request):
|
||||
|
||||
def submitEmailForwardingCreation(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['emailForwarding'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('createStatus', 0)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
result = pluginManager.preSubmitEmailForwardingCreation(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
data = json.loads(request.body)
|
||||
source = data['source']
|
||||
destination = data['destination']
|
||||
msM = MailServerManager(request)
|
||||
coreResult = msM.submitEmailForwardingCreation()
|
||||
|
||||
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)
|
||||
result = pluginManager.postSubmitEmailForwardingCreation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
return coreResult
|
||||
except KeyError,msg:
|
||||
data_ret = {'createStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -378,65 +136,26 @@ def submitEmailForwardingCreation(request):
|
||||
|
||||
def changeEmailAccountPassword(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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))
|
||||
|
||||
msM = MailServerManager(request)
|
||||
return msM.changeEmailAccountPassword()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitPasswordChange(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['changeEmailPassword'] == 1:
|
||||
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']
|
||||
result = pluginManager.preSubmitPasswordChange(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
emailDB = EUsers.objects.get(email=email)
|
||||
emailDB.delete()
|
||||
msM = MailServerManager(request)
|
||||
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)
|
||||
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)
|
||||
return coreResult
|
||||
except KeyError,msg:
|
||||
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -446,74 +165,15 @@ def submitPasswordChange(request):
|
||||
|
||||
def dkimManager(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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})
|
||||
|
||||
|
||||
|
||||
msM = MailServerManager(request)
|
||||
return msM.dkimManager()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchDKIMKeys(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
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)
|
||||
msM = MailServerManager(request)
|
||||
return msM.fetchDKIMKeys()
|
||||
except KeyError,msg:
|
||||
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -521,58 +181,19 @@ def fetchDKIMKeys(request):
|
||||
|
||||
def generateDKIMKeys(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['dkimManager'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('generateStatus', 0)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
result = pluginManager.preGenerateDKIMKeys(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
data = json.loads(request.body)
|
||||
domainName = data['domainName']
|
||||
msM = MailServerManager(request)
|
||||
coreResult = msM.generateDKIMKeys()
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||
execPath = execPath + " generateKeys --domain " + domainName
|
||||
output = subprocess.check_output(shlex.split(execPath))
|
||||
result = pluginManager.postGenerateDKIMKeys(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
return coreResult
|
||||
except BaseException, msg:
|
||||
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -580,24 +201,8 @@ def generateDKIMKeys(request):
|
||||
|
||||
def installOpenDKIM(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
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)
|
||||
msM = MailServerManager(request)
|
||||
return msM.installOpenDKIM()
|
||||
except KeyError:
|
||||
final_dic = {'installOpenDKIM': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||
final_json = json.dumps(final_dic)
|
||||
@@ -605,59 +210,8 @@ def installOpenDKIM(request):
|
||||
|
||||
def installStatusOpenDKIM(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
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)
|
||||
msM = MailServerManager()
|
||||
return msM.installStatusOpenDKIM()
|
||||
except KeyError:
|
||||
final_dic = {'abort':1,'installed':0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||
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 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render,redirect
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from loginSystem.views import loadLoginPage
|
||||
from loginSystem.models import Administrator
|
||||
import json
|
||||
from .models import Package
|
||||
import plogical.CyberCPLogFileWriter as logging
|
||||
from plogical.acl import ACLManager
|
||||
from packagesManager import PackagesManager
|
||||
from pluginManager import pluginManager
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def packagesHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
pm = PackagesManager(request)
|
||||
return pm.packagesHome()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
return render(request,'packages/index.html',{})
|
||||
|
||||
def createPacakge(request):
|
||||
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['createPackage'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
result = pluginManager.preCreatePacakge(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deletePacakge(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
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")
|
||||
pm = PackagesManager(request)
|
||||
return pm.deletePacakge()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitPackage(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['createPackage'] == 1:
|
||||
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'])
|
||||
result = pluginManager.preSubmitPackage(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
pm = PackagesManager(request)
|
||||
coreResult = pm.submitPackage()
|
||||
|
||||
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)
|
||||
result = pluginManager.postSubmitPackage(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitDelete(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
result = pluginManager.preSubmitDelete(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
elif currentACL['deletePackage'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||
pm = PackagesManager(request)
|
||||
coreResult = pm.submitDelete()
|
||||
|
||||
if request.method == 'POST':
|
||||
data = json.loads(request.body)
|
||||
packageName = data['packageName']
|
||||
result = pluginManager.postSubmitDelete(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
except KeyError,msg:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def modifyPackage(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
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")
|
||||
pm = PackagesManager(request)
|
||||
return pm.modifyPackage()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitModify(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
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)
|
||||
pm = PackagesManager(request)
|
||||
return pm.submitModify()
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def saveChanges(request):
|
||||
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:
|
||||
pass
|
||||
elif currentACL['modifyPackage'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('saveStatus', 0)
|
||||
pm = PackagesManager(request)
|
||||
coreResult = pm.saveChanges()
|
||||
|
||||
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)
|
||||
result = pluginManager.postSaveChanges(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
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)
|
||||
|
||||
except KeyError,msg:
|
||||
data_ret = {'saveStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
@@ -140,7 +140,7 @@ class BackupManager:
|
||||
## /home/example.com/backup/backup-example-06-50-03-Thu-Feb-2018
|
||||
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 " \
|
||||
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain
|
||||
|
||||
@@ -290,7 +290,7 @@ class BackupManager:
|
||||
else:
|
||||
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
|
||||
subprocess.Popen(shlex.split(execPath))
|
||||
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):
|
||||
data = open("/usr/local/CyberCP/CyberCP/urls.py", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/CyberCP/urls.py", 'w')
|
||||
print('hello world')
|
||||
|
||||
for items in data:
|
||||
if items.find("manageservices") > -1:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.writelines(" url(r'^" + pluginName + "/',include('" + pluginName + ".urls')),\n")
|
||||
print('hello world')
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
@@ -74,31 +72,80 @@ class pluginInstaller:
|
||||
data = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'w')
|
||||
|
||||
pluginCheck = 0
|
||||
|
||||
for items in data:
|
||||
if items.find('<span>{% trans "Plugins" %}</span>') > -1:
|
||||
pluginCheck = 1
|
||||
elif pluginCheck == 1 and items.find('<ul>'):
|
||||
if items.find("{% url 'installed' %}") > -1:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.writelines('<li><a href="{% url \'' + pluginName + '\' %}" title="{% trans \'' + pluginName + '\' %}"><span>{% trans "' + pluginName + '" %}</span></a></li>')
|
||||
pluginCheck = 0
|
||||
writeToFile.writelines(
|
||||
'<li><a href="{% url \'' + pluginName + '\' %}" title="{% trans \'' + pluginName + '\' %}"><span>{% trans "' + pluginName + '" %}</span></a></li>')
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
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
|
||||
def installPlugin(pluginName):
|
||||
try:
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Extracting plugin.')
|
||||
pluginInstaller.stdOut('Extracting plugin..')
|
||||
pluginInstaller.extractPlugin(pluginName)
|
||||
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.upgradingSettingsFile(pluginName)
|
||||
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.stdOut('Plugin successfully installed.')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# The world is a prison for the believer.
|
||||
## https://www.youtube.com/watch?v=DWfNYztUM1U
|
||||
|
||||
from django.dispatch import Signal
|
||||
|
||||
|
||||
Reference in New Issue
Block a user