centralize acl control

This commit is contained in:
Usman Nasir
2021-02-23 23:38:58 +05:00
parent 72ae933042
commit 07b5b278b5
11 changed files with 900 additions and 826 deletions

View File

@@ -10,7 +10,7 @@ from django.shortcuts import HttpResponse
from math import ceil from math import ceil
from websiteFunctions.models import Websites from websiteFunctions.models import Websites
from CLManager.models import CLPackages from CLManager.models import CLPackages
from plogical.httpProc import httpProc
class CLManagerMain(multi.Thread): class CLManagerMain(multi.Thread):
@@ -27,29 +27,14 @@ class CLManagerMain(multi.Thread):
self.submitCageFSInstall() self.submitCageFSInstall()
elif self.function == 'enableOrDisable': elif self.function == 'enableOrDisable':
self.enableOrDisable() self.enableOrDisable()
except BaseException as msg: except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [ContainerManager.run]') logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [ContainerManager.run]')
def renderC(self): def renderC(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
data = {} data = {}
data['CL'] = 0 data['CL'] = 0
data['activatedPath'] = 0 data['activatedPath'] = 0
data['ipAddress'] = ipAddress
CLPath = '/etc/sysconfig/cloudlinux' CLPath = '/etc/sysconfig/cloudlinux'
activatedPath = '/home/cyberpanel/cloudlinux' activatedPath = '/home/cyberpanel/cloudlinux'
@@ -60,11 +45,14 @@ class CLManagerMain(multi.Thread):
data['activatedPath'] = 1 data['activatedPath'] = 1
if data['CL'] == 0: if data['CL'] == 0:
return render(self.request, 'CLManager/notAvailable.html', data) proc = httpProc(self.request, 'CLManager/notAvailable.html', data, 'admin')
return proc.render()
elif data['activatedPath'] == 0: elif data['activatedPath'] == 0:
return render(self.request, 'CLManager/notAvailable.html', data) proc = httpProc(self.request, 'CLManager/notAvailable.html', data, 'admin')
return proc.render()
else: else:
return render(self.request, 'CLManager/cloudLinux.html', data) proc = httpProc(self.request, 'CLManager/cloudLinux.html', data, 'admin')
return proc.render()
def submitCageFSInstall(self): def submitCageFSInstall(self):
try: try:

View File

@@ -0,0 +1,42 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Home - CyberPanel" %}{% endblock %}
{% block content %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Home" %}</h2>
<p>{% trans "Use the tabs to navigate through the control panel." %}</p>
</div>
<!--- Hide statistics for non-admins--->
<div class="mx-10 col-lg-9 panel col-md-push-50">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Something went wrong..." %}
</h3>
<div class="example-box-wrapper mt-5">
<div class="alert alert-danger">
<h4 class="alert-title">Error</h4>
<p>Error: {{ error_message }}</p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -4,28 +4,28 @@
{% block content %} {% block content %}
{% get_current_language as LANGUAGE_CODE %} {% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} --> <!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container"> <div class="container">
<div id="page-title"> <div id="page-title">
<h2>{% trans "Home" %}</h2> <h2>{% trans "Home" %}</h2>
<p>{% trans "Use the tabs to navigate through the control panel." %}</p> <p>{% trans "Use the tabs to navigate through the control panel." %}</p>
</div> </div>
<!--- Hide statistics for non-admins---> <!--- Hide statistics for non-admins--->
<div class="mx-10 col-lg-9 panel col-md-push-50">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Available Functions" %}
</h3>
<div class="mx-10 col-lg-9 panel col-md-push-50"> <div class="example-box-wrapper mt-5">
<div class="panel-body"> <div class="row mx-5">
<h3 class="content-box-header"> <div class="col-md-4">
{% trans "Available Functions" %} <a href="{% url 'loadUsersHome' %}" title="{% trans 'User Functions' %}"
</h3> class="tile-box tile-box-shortcut btn-primary">
<div class="example-box-wrapper mt-5">
<div class="row mx-5">
<div class="col-md-4">
<a href="{% url 'loadUsersHome' %}" title="{% trans 'User Functions' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "Users" %} {% trans "Users" %}
</div> </div>
@@ -33,10 +33,11 @@
<i class="fa fa-users"></i> <i class="fa fa-users"></i>
</div> </div>
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'loadWebsitesHome' %}" title="{% trans 'Website Functions' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'loadWebsitesHome' %}" title="{% trans 'Website Functions' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "Websites" %} {% trans "Websites" %}
</div> </div>
@@ -46,8 +47,9 @@
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'packagesHome' %}" title="{% trans 'Add/Modify Packages' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'packagesHome' %}" title="{% trans 'Add/Modify Packages' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "Packages" %} {% trans "Packages" %}
</div> </div>
@@ -55,10 +57,11 @@
<i class="fa fa-cubes"></i> <i class="fa fa-cubes"></i>
</div> </div>
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'loadDatabaseHome' %}" title="{% trans 'Database Functions' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'loadDatabaseHome' %}" title="{% trans 'Database Functions' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "Databases" %} {% trans "Databases" %}
</div> </div>
@@ -66,10 +69,11 @@
<i class="fa fa-database"></i> <i class="fa fa-database"></i>
</div> </div>
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'dnsHome' %}" title="{% trans 'Control DNS' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'dnsHome' %}" title="{% trans 'Control DNS' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "DNS" %} {% trans "DNS" %}
</div> </div>
@@ -77,10 +81,11 @@
<i class="fa fa-sitemap"></i> <i class="fa fa-sitemap"></i>
</div> </div>
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'loadFTPHome' %}" title="{% trans 'FTP Functions' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'loadFTPHome' %}" title="{% trans 'FTP Functions' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "FTP" %} {% trans "FTP" %}
</div> </div>
@@ -90,8 +95,9 @@
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Back up' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'loadBackupHome' %}" title="{% trans 'Back up' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "Back up" %} {% trans "Back up" %}
</div> </div>
@@ -99,171 +105,175 @@
<i class="fa fa-clone"></i> <i class="fa fa-clone"></i>
</div> </div>
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'loadEmailHome' %}" title="{% trans 'Emails' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'loadEmailHome' %}" title="{% trans 'Emails' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Emails" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-envelope"></i>
</div>
</a>
</div>
<div class="col-md-4">
<a href="{% url 'loadSSLHome' %}" title="{% trans 'SSL' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "SSL" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-expeditedssl"></i>
</div>
</a>
</div>
{% if admin %}
<div class="col-md-4">
<a href="{% url 'serverStatusHome' %}" title="{% trans 'Server Status' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "Emails" %} {% trans "Status" %}
</div> </div>
<div class="tile-content-wrapper"> <div class="tile-content-wrapper">
<i class="fa fa-envelope"></i> <i class="fa fa-server"></i>
</div> </div>
</a> </a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'loadSSLHome' %}" title="{% trans 'SSL' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'loadPHPHome' %}" title="{% trans 'PHP Configurations' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header"> <div class="tile-header">
{% trans "SSL" %} {% trans "PHP" %}
</div> </div>
<div class="tile-content-wrapper"> <div class="tile-content-wrapper">
<i class="fa fa-expeditedssl"></i> <i class="fa fa-code"></i>
</div> </div>
</a> </a>
</div> </div>
{% if admin %} <div class="col-md-4">
<a href="{% url 'logsHome' %}" title="{% trans 'Logs' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Logs" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-file"></i>
</div>
</a>
</div>
<div class="col-md-4"> <div class="col-md-4">
<a href="{% url 'serverStatusHome' %}" title="{% trans 'Server Status' %}" class="tile-box tile-box-shortcut btn-primary"> <a href="{% url 'securityHome' %}" title="{% trans 'Security' %}"
<div class="tile-header"> class="tile-box tile-box-shortcut btn-primary">
{% trans "Status" %} <div class="tile-header">
</div> {% trans "Security" %}
<div class="tile-content-wrapper"> </div>
<i class="fa fa-server"></i> <div class="tile-content-wrapper">
</div> <i class="fa fa-shield"></i>
</a> </div>
</div> </a>
</div>
<div class="col-md-4"> {% endif %}
<a href="{% url 'loadPHPHome' %}" title="{% trans 'PHP Configurations' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "PHP" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-code"></i>
</div>
</a>
</div>
<div class="col-md-4">
<a href="{% url 'logsHome' %}" title="{% trans 'Logs' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Logs" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-file"></i>
</div>
</a>
</div>
<div class="col-md-4">
<a href="{% url 'securityHome' %}" title="{% trans 'Security' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Security" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-shield"></i>
</div>
</a>
</div>
{% endif %}
</div> </div>
</div>
</div> </div>
</div>
</div>
{% if admin %}
<div ng-controller="homePageStatus" class="">
<div class="mx-10 col-md-2 panel panel-body col-md-pull-50">
<h3 class="content-box-header">
{% trans "Resources" %}
</h3>
<div class="example-box-wrapper">
<div class="row mx-5">
<div class="">
<div class="mb-10">
<h3 class="title-hero clearfix text-center text-muted">
{% trans "CPU Usage" %}
</h3>
<div class="content-box-wrapper">
<div class="row flex">
<div class="align-center">
<div id="redcircle" class="c100 red cpu">
<span>{$ cpuUsage $}%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="mb-10">
<h3 class="title-hero clearfix text-center text-muted">
{% trans "Ram Usage" %}
</h3>
<div class="content-box-wrapper">
<div class="row flex">
<div class="align-center">
<div id="greencircle" class="c100 p0 green ram">
<span>{$ ramUsage $}%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="mb-10">
<h3 class="title-hero clearfix text-center text-muted">
{% trans "Disk Usage '/'" %}
</h3>
<div class="content-box-wrapper">
<div class="row flex">
<div class="align-center">
<div id="pinkcircle" class="c100 pink disk">
<span>{$ diskUsage $}%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
{% if admin %}
<div ng-controller="homePageStatus" class="">
<div class="mx-10 col-md-2 panel panel-body col-md-pull-50">
<h3 class="content-box-header">
{% trans "Resources" %}
</h3>
<div class="example-box-wrapper">
<div class="row mx-5">
<div class="">
<div class="mb-10">
<h3 class="title-hero clearfix text-center text-muted">
{% trans "CPU Usage" %}
</h3>
<div class="content-box-wrapper">
<div class="row flex">
<div class="align-center">
<div id="redcircle" class="c100 red cpu">
<span>{$ cpuUsage $}%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="mb-10">
<h3 class="title-hero clearfix text-center text-muted">
{% trans "Ram Usage" %}
</h3>
<div class="content-box-wrapper">
<div class="row flex">
<div class="align-center">
<div id="greencircle" class="c100 p0 green ram">
<span>{$ ramUsage $}%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="mb-10">
<h3 class="title-hero clearfix text-center text-muted">
{% trans "Disk Usage '/'" %}
</h3>
<div class="content-box-wrapper">
<div class="row flex">
<div class="align-center">
<div id="pinkcircle" class="c100 pink disk">
<span>{$ diskUsage $}%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div> </div>
{% endif %}
</div>
{% endblock %} {% endblock %}

File diff suppressed because it is too large Load Diff

View File

@@ -88,38 +88,26 @@ def getLoadAverage(request):
@ensure_csrf_cookie @ensure_csrf_cookie
def versionManagment(request): def versionManagment(request):
try: ## Get latest version
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1: getVersion = requests.get('https://cyberpanel.net/version.txt')
pass
elif currentACL['versionManagement'] == 1:
pass
else:
return ACLManager.loadError()
## Get latest version latest = getVersion.json()
getVersion = requests.get('https://cyberpanel.net/version.txt') latestVersion = latest['version']
latestBuild = latest['build']
latest = getVersion.json() ## Get local version
latestVersion = latest['version'] currentVersion = VERSION
latestBuild = latest['build'] currentBuild = str(BUILD)
## Get local version template = 'baseTemplate/versionManagment.html'
finalData = {'build': currentBuild, 'currentVersion': currentVersion, 'latestVersion': latestVersion,
'latestBuild': latestBuild}
currentVersion = VERSION proc = httpProc(request, template, finalData, 'versionManagement')
currentBuild = str(BUILD) return proc.render()
return render(request, 'baseTemplate/versionManagment.html', {'build': currentBuild,
'currentVersion': currentVersion,
'latestVersion': latestVersion,
'latestBuild': latestBuild})
except KeyError:
return redirect(loadLoginPage)
def upgrade(request): def upgrade(request):
try: try:

View File

@@ -5,7 +5,7 @@ from plogical.acl import ACLManager
import plogical.CyberCPLogFileWriter as logging import plogical.CyberCPLogFileWriter as logging
from serverStatus.serverStatusUtil import ServerStatusUtil from serverStatus.serverStatusUtil import ServerStatusUtil
import os, stat import os, stat
from plogical.httpProc import httpProc
class ContainerManager(multi.Thread): class ContainerManager(multi.Thread):
defaultConf = """group {groupName}{ defaultConf = """group {groupName}{
@@ -84,14 +84,6 @@ class ContainerManager(multi.Thread):
def renderC(self): def renderC(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
data = {} data = {}
data['OLS'] = 0 data['OLS'] = 0
data['notInstalled'] = 0 data['notInstalled'] = 0
@@ -99,17 +91,20 @@ class ContainerManager(multi.Thread):
if ProcessUtilities.decideServer() == ProcessUtilities.OLS: if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
data['OLS'] = 1 data['OLS'] = 1
data['notInstalled'] = 0 data['notInstalled'] = 0
return render(self.request, 'containerization/notAvailable.html', data) proc = httpProc(self.request, 'containerization/notAvailable.html', data, 'admin')
return proc.render()
elif not ProcessUtilities.containerCheck(): elif not ProcessUtilities.containerCheck():
data['OLS'] = 0 data['OLS'] = 0
data['notInstalled'] = 1 data['notInstalled'] = 1
return render(self.request, 'containerization/notAvailable.html', data) proc = httpProc(self.request, 'containerization/notAvailable.html', data, 'admin')
return proc.render()
else: else:
if self.data == None: if self.data == None:
self.data = {} self.data = {}
self.data['OLS'] = 0 self.data['OLS'] = 0
self.data['notInstalled'] = 0 self.data['notInstalled'] = 0
return render(self.request, self.templateName, self.data) proc = httpProc(self.request, self.templateName, data, 'admin')
return proc.render()
def submitContainerInstall(self): def submitContainerInstall(self):
try: try:
@@ -165,7 +160,6 @@ class ContainerManager(multi.Thread):
# self.data['classID']) + ' protocol ip prio 10 handle 1: cgroup' # self.data['classID']) + ' protocol ip prio 10 handle 1: cgroup'
command = 'sudo tc filter add dev eth0 parent 10: protocol ip prio 10 handle 1: cgroup' command = 'sudo tc filter add dev eth0 parent 10: protocol ip prio 10 handle 1: cgroup'
#logging.CyberCPLogFileWriter.writeToFile(command)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
self.restartServices() self.restartServices()

View File

@@ -5,7 +5,6 @@ import django
sys.path.append('/usr/local/CyberCP') sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup() django.setup()
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
import json import json
from plogical.acl import ACLManager from plogical.acl import ACLManager
@@ -16,34 +15,28 @@ from databases.models import Databases, DBMeta
import argparse import argparse
from loginSystem.models import Administrator from loginSystem.models import Administrator
import plogical.randomPassword as randomPassword import plogical.randomPassword as randomPassword
from plogical.httpProc import httpProc
class DatabaseManager: class DatabaseManager:
REMOTE_ACCESS = 'remote_access' REMOTE_ACCESS = 'remote_access'
def loadDatabaseHome(self, request = None, userID = None): def loadDatabaseHome(self, request = None, userID = None):
try: template = 'databases/index.html'
return render(request, 'databases/index.html') proc = httpProc(request, template, None, 'createDatabase')
except BaseException as msg: return proc.render()
return HttpResponse(str(msg))
def phpMyAdmin(self, request = None, userID = None): def phpMyAdmin(self, request = None, userID = None):
try: template = 'databases/phpMyAdmin.html'
return render(request, 'databases/phpMyAdmin.html') proc = httpProc(request, template, None, 'createDatabase')
except BaseException as msg: return proc.render()
return HttpResponse(str(msg))
def createDatabase(self, request = None, userID = None): def createDatabase(self, request = None, userID = None):
try: currentACL = ACLManager.loadedACL(userID)
currentACL = ACLManager.loadedACL(userID) websitesName = ACLManager.findAllSites(currentACL, userID)
if ACLManager.currentContextPermission(currentACL, 'createDatabase') == 0: template = 'databases/createDatabase.html'
return ACLManager.loadError() proc = httpProc(request, template, {'websitesList': websitesName}, 'createDatabase')
return proc.render()
websitesName = ACLManager.findAllSites(currentACL, userID)
return render(request, 'databases/createDatabase.html', {'websitesList': websitesName})
except BaseException as msg:
return HttpResponse(str(msg))
def submitDBCreation(self, userID = None, data = None, rAPI = None): def submitDBCreation(self, userID = None, data = None, rAPI = None):
try: try:
@@ -84,18 +77,11 @@ class DatabaseManager:
return HttpResponse(json_data) return HttpResponse(json_data)
def deleteDatabase(self, request = None, userID = None): def deleteDatabase(self, request = None, userID = None):
try: currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
currentACL = ACLManager.loadedACL(userID) template = 'databases/deleteDatabase.html'
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0: proc = httpProc(request, template, {'websitesList': websitesName}, 'deleteDatabase')
return ACLManager.loadError() return proc.render()
websitesName = ACLManager.findAllSites(currentACL, userID)
return render(request, 'databases/deleteDatabase.html', {'websitesList': websitesName})
except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg))
def fetchDatabases(self, userID = None, data = None): def fetchDatabases(self, userID = None, data = None):
try: try:
@@ -171,16 +157,11 @@ class DatabaseManager:
return HttpResponse(json_data) return HttpResponse(json_data)
def listDBs(self, request = None, userID = None): def listDBs(self, request = None, userID = None):
try: currentACL = ACLManager.loadedACL(userID)
currentACL = ACLManager.loadedACL(userID) websitesName = ACLManager.findAllSites(currentACL, userID)
if ACLManager.currentContextPermission(currentACL, 'listDatabases') == 0: template = 'databases/listDataBases.html'
return ACLManager.loadError() proc = httpProc(request, template, {'websitesList': websitesName}, 'listDatabases')
return proc.render()
websitesName = ACLManager.findAllSites(currentACL, userID)
return render(request, 'databases/listDataBases.html', {'websiteList': websitesName})
except BaseException as msg:
return HttpResponse(str(msg))
def changePassword(self, userID = None, data = None): def changePassword(self, userID = None, data = None):
try: try:

View File

@@ -4,10 +4,10 @@ import errno
import os.path import os.path
import sys import sys
import django import django
sys.path.append('/usr/local/CyberCP') sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup() django.setup()
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
import json import json
try: try:
@@ -24,6 +24,7 @@ import CloudFlare
import re import re
import plogical.CyberCPLogFileWriter as logging import plogical.CyberCPLogFileWriter as logging
from plogical.processUtilities import ProcessUtilities from plogical.processUtilities import ProcessUtilities
from plogical.httpProc import httpProc
class DNSManager: class DNSManager:
defaultNameServersPath = '/home/cyberpanel/defaultNameservers' defaultNameServersPath = '/home/cyberpanel/defaultNameservers'
@@ -37,29 +38,23 @@ class DNSManager:
self.email = data[0].rstrip('\n') self.email = data[0].rstrip('\n')
self.key = data[1].rstrip('\n') self.key = data[1].rstrip('\n')
def loadDNSHome(self, request = None, userID = None): def loadDNSHome(self, request = None, userID = None):
try: admin = Administrator.objects.get(pk=userID)
admin = Administrator.objects.get(pk=userID) template = 'dns/index.html'
return render(request, 'dns/index.html', {"type": admin.type}) proc = httpProc(request, template, {"type": admin.type}, 'createDNSZone')
except BaseException as msg: return proc.render()
return HttpResponse(str(msg))
def createNameserver(self, request = None, userID = None): def createNameserver(self, request = None, userID = None):
try: mailUtilities.checkHome()
currentACL = ACLManager.loadedACL(userID)
if ACLManager.currentContextPermission(currentACL, 'createNameServer') == 0:
return ACLManager.loadError()
mailUtilities.checkHome() if os.path.exists('/home/cyberpanel/powerdns'):
finalData = {"status": 1}
else:
finalData = {"status": 0}
if os.path.exists('/home/cyberpanel/powerdns'): template = 'dns/createNameServer.html'
return render(request, "dns/createNameServer.html", {"status": 1}) proc = httpProc(request, template, finalData, 'createNameServer')
else: return proc.render()
return render(request, "dns/createNameServer.html", {"status": 0})
except BaseException as msg:
return HttpResponse(str(msg))
def NSCreation(self, userID = None, data = None): def NSCreation(self, userID = None, data = None):
try: try:
@@ -118,17 +113,13 @@ class DNSManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def createDNSZone(self, request = None, userID = None): def createDNSZone(self, request = None, userID = None):
try: if os.path.exists('/home/cyberpanel/powerdns'):
currentACL = ACLManager.loadedACL(userID) finalData = {'status': 1}
if ACLManager.currentContextPermission(currentACL, 'createDNSZone') == 0: else:
return ACLManager.loadError() finalData = {'status': 0}
template = 'dns/createDNSZone.html'
if os.path.exists('/home/cyberpanel/powerdns'): proc = httpProc(request, template, finalData, 'createDNSZone')
return render(request, 'dns/createDNSZone.html', {"status": 1}) return proc.render()
else:
return render(request, 'dns/createDNSZone.html', {"status": 0})
except BaseException as msg:
return HttpResponse(str(msg))
def zoneCreation(self, userID = None, data = None): def zoneCreation(self, userID = None, data = None):
try: try:
@@ -166,21 +157,16 @@ class DNSManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def addDeleteDNSRecords(self, request = None, userID = None): def addDeleteDNSRecords(self, request = None, userID = None):
try: currentACL = ACLManager.loadedACL(userID)
if not os.path.exists('/home/cyberpanel/powerdns'):
finalData = {"status": 0}
else:
finalData = {"status": 1}
currentACL = ACLManager.loadedACL(userID) finalData['domainsList'] = ACLManager.findAllDomains(currentACL, userID)
if ACLManager.currentContextPermission(currentACL, 'addDeleteRecords') == 0: template = 'dns/addDeleteDNSRecords.html'
return ACLManager.loadError() proc = httpProc(request, template, finalData, 'addDeleteRecords')
return proc.render()
if not os.path.exists('/home/cyberpanel/powerdns'):
return render(request, 'dns/addDeleteDNSRecords.html', {"status": 0})
domainsList = ACLManager.findAllDomains(currentACL, userID)
return render(request, 'dns/addDeleteDNSRecords.html', {"domainsList": domainsList, "status": 1})
except BaseException as msg:
return HttpResponse(str(msg))
def getCurrentRecordsForDomain(self, userID = None, data = None): def getCurrentRecordsForDomain(self, userID = None, data = None):
try: try:
@@ -499,22 +485,16 @@ class DNSManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def deleteDNSZone(self, request = None, userID = None): def deleteDNSZone(self, request = None, userID = None):
currentACL = ACLManager.loadedACL(userID)
if not os.path.exists('/home/cyberpanel/powerdns'):
finalData = {"status": 0}
else:
finalData = {"status": 1}
try: finalData['domainsList'] = ACLManager.findAllDomains(currentACL, userID)
currentACL = ACLManager.loadedACL(userID) template = 'dns/deleteDNSZone.html'
proc = httpProc(request, template, finalData, 'deleteZone')
if ACLManager.currentContextPermission(currentACL, 'deleteZone') == 0: return proc.render()
return ACLManager.loadError()
if not os.path.exists('/home/cyberpanel/powerdns'):
return render(request, 'dns/addDeleteDNSRecords.html', {"status": 0})
domainsList = ACLManager.findAllDomains(currentACL, userID)
return render(request, 'dns/deleteDNSZone.html', {"domainsList": domainsList, "status": 1})
except BaseException as msg:
return HttpResponse(str(msg))
def submitZoneDeletion(self, userID = None, data = None): def submitZoneDeletion(self, userID = None, data = None):
try: try:
@@ -549,46 +529,36 @@ class DNSManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def configureDefaultNameServers(self, request=None, userID=None): def configureDefaultNameServers(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
try: if not os.path.exists('/home/cyberpanel/powerdns'):
currentACL = ACLManager.loadedACL(userID) data = {"status": 0}
else:
data = {"status": 1}
if currentACL['admin'] == 1: data['domainsList'] = ACLManager.findAllDomains(currentACL, userID)
if os.path.exists(DNSManager.defaultNameServersPath):
nsData = open(DNSManager.defaultNameServersPath, 'r').readlines()
try:
data['firstNS'] = nsData[0].rstrip('\n')
except:
pass
try:
data['secondNS'] = nsData[1].rstrip('\n')
except:
pass
try:
data['thirdNS'] = nsData[2].rstrip('\n')
except:
pass
try:
data['forthNS'] = nsData[3].rstrip('\n')
except:
pass pass
else:
return ACLManager.loadError()
if not os.path.exists('/home/cyberpanel/powerdns'):
return render(request, 'dns/addDeleteDNSRecords.html', {"status": 0})
data = {}
data['domainsList'] = ACLManager.findAllDomains(currentACL, userID)
data['status'] = 1
if os.path.exists(DNSManager.defaultNameServersPath):
nsData = open(DNSManager.defaultNameServersPath, 'r').readlines()
try:
data['firstNS'] = nsData[0].rstrip('\n')
except:
pass
try:
data['secondNS'] = nsData[1].rstrip('\n')
except:
pass
try:
data['thirdNS'] = nsData[2].rstrip('\n')
except:
pass
try:
data['forthNS'] = nsData[3].rstrip('\n')
except:
pass
return render(request, 'dns/configureDefaultNameServers.html', data)
except BaseException as msg:
return HttpResponse(str(msg))
template = 'dns/configureDefaultNameServers.html'
proc = httpProc(request, template, data, 'admin')
return proc.render()
def saveNSConfigurations(self, userID = None, data = None): def saveNSConfigurations(self, userID = None, data = None):
try: try:
@@ -615,7 +585,6 @@ class DNSManager:
except: except:
pass pass
writeToFile = open(DNSManager.defaultNameServersPath, 'w') writeToFile = open(DNSManager.defaultNameServersPath, 'w')
writeToFile.write(nsContent.rstrip('\n')) writeToFile.write(nsContent.rstrip('\n'))
writeToFile.close() writeToFile.close()
@@ -631,35 +600,30 @@ class DNSManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def addDeleteDNSRecordsCloudFlare(self, request = None, userID = None): def addDeleteDNSRecordsCloudFlare(self, request = None, userID = None):
try: currentACL = ACLManager.loadedACL(userID)
if not os.path.exists('/home/cyberpanel/powerdns'):
status = 0
else:
status = 1
admin = Administrator.objects.get(pk=userID)
currentACL = ACLManager.loadedACL(userID) CloudFlare = 0
if ACLManager.currentContextPermission(currentACL, 'addDeleteRecords') == 0:
return ACLManager.loadError()
if not os.path.exists('/home/cyberpanel/powerdns'): cfPath = '%s%s' % (DNS.CFPath, admin.userName)
return render(request, 'dns/addDeleteDNSRecordsCloudFlare.html', {"status": 0})
admin = Administrator.objects.get(pk=userID) if os.path.exists(cfPath):
CloudFlare = 1
domainsList = ACLManager.findAllDomains(currentACL, userID)
self.admin = admin
self.loadCFKeys()
data = {"domainsList": domainsList, "status": status, 'CloudFlare': CloudFlare, 'cfEmail': self.email,
'cfToken': self.key}
else:
data = {"status": status, 'CloudFlare': CloudFlare}
CloudFlare = 0 template = 'dns/addDeleteDNSRecordsCloudFlare.html'
proc = httpProc(request, template, data, 'addDeleteRecords')
cfPath = '%s%s' %(DNS.CFPath, admin.userName) return proc.render()
if os.path.exists(cfPath):
CloudFlare = 1
domainsList = ACLManager.findAllDomains(currentACL, userID)
self.admin = admin
self.loadCFKeys()
return render(request, 'dns/addDeleteDNSRecordsCloudFlare.html',
{"domainsList": domainsList, "status": 1, 'CloudFlare': CloudFlare, 'cfEmail': self.email, 'cfToken': self.key})
else:
return render(request, 'dns/addDeleteDNSRecordsCloudFlare.html', {"status": 1, 'CloudFlare': CloudFlare})
except BaseException as msg:
return HttpResponse(str(msg))
def saveCFConfigs(self, userID = None, data = None): def saveCFConfigs(self, userID = None, data = None):
try: try:

View File

@@ -71,14 +71,12 @@ class ACLManager:
finalResponse['serverIPAddress'] = serverIPAddress finalResponse['serverIPAddress'] = serverIPAddress
finalResponse['adminName'] = admin.firstName finalResponse['adminName'] = admin.firstName
if admin.acl.adminStatus == 1: config = json.loads(admin.acl.config)
if config['adminStatus']:
finalResponse['admin'] = 1 finalResponse['admin'] = 1
else: else:
finalResponse['admin'] = 0 finalResponse['admin'] = 0
config = json.loads(admin.acl.config)
acl = ACL.objects.get(name=admin.acl.name)
finalResponse['versionManagement'] = config['versionManagement'] finalResponse['versionManagement'] = config['versionManagement']
## User Management ## User Management

View File

@@ -2,12 +2,14 @@
from django.shortcuts import render, HttpResponse from django.shortcuts import render, HttpResponse
import json import json
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter
class httpProc: class httpProc:
def __init__(self, request, templateName, data = None): def __init__(self, request, templateName, data = None, function = None):
self.request = request self.request = request
self.templateName = templateName self.templateName = templateName
self.data = data self.data = data
self.function = function
def render(self): def render(self):
@@ -15,19 +17,33 @@ class httpProc:
from loginSystem.models import Administrator from loginSystem.models import Administrator
from plogical.acl import ACLManager from plogical.acl import ACLManager
userID = self.request.session['userID'] userID = self.request.session['userID']
admin = Administrator.objects.get(pk=userID) currentACL = ACLManager.loadedACL(userID)
### Permissions Check
if self.function != None:
if not currentACL['admin']:
if not currentACL[self.function]:
templateName = 'baseTemplate/error.html'
return render(self.request, templateName, {'error_message': 'You are not authorized to access %s' % (self.function)})
### ###
if self.data == None: if self.data == None:
self.data = {} self.data = {}
self.data.update(ACLManager.loadedACL(userID)) ipFile = "/etc/cyberpanel/machineIP"
return render(self.request, self.templateName, self.data) f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
self.data['ipAddress'] = ipAddress
self.data.update(currentACL)
return render(self.request, self.templateName, self.data)
except BaseException as msg: except BaseException as msg:
templateName = 'UserManagement/login.html' templateName = 'baseTemplate/error.html'
return render(self.request, templateName) return render(self.request, templateName, {'error_message': str(msg)})
def renderPre(self): def renderPre(self):
if self.data == None: if self.data == None:

View File

@@ -458,6 +458,7 @@ app.controller('deleteUser', function ($scope, $http) {
/* Java script code to create acl */ /* Java script code to create acl */
app.controller('createACLCTRL', function ($scope, $http) { app.controller('createACLCTRL', function ($scope, $http) {
$scope.aclLoading = true; $scope.aclLoading = true;
@@ -520,11 +521,13 @@ app.controller('createACLCTRL', function ($scope, $http) {
// Backup Management // Backup Management
$scope.createBackup = true; $scope.createBackup = true;
$scope.googleDriveBackups = true;
$scope.restoreBackup = false; $scope.restoreBackup = false;
$scope.addDeleteDestinations = false; $scope.addDeleteDestinations = false;
$scope.scheDuleBackups = false; $scope.scheDuleBackups = false;
$scope.remoteBackups = false; $scope.remoteBackups = false;
// SSL Management // SSL Management
$scope.manageSSL = true; $scope.manageSSL = true;
@@ -599,6 +602,7 @@ app.controller('createACLCTRL', function ($scope, $http) {
// Backup Management // Backup Management
createBackup: $scope.createBackup, createBackup: $scope.createBackup,
googleDriveBackups: $scope.googleDriveBackups,
restoreBackup: $scope.restoreBackup, restoreBackup: $scope.restoreBackup,
addDeleteDestinations: $scope.addDeleteDestinations, addDeleteDestinations: $scope.addDeleteDestinations,
scheDuleBackups: $scope.scheDuleBackups, scheDuleBackups: $scope.scheDuleBackups,
@@ -976,6 +980,7 @@ app.controller('modifyACLCtrl', function ($scope, $http) {
// Backup Management // Backup Management
$scope.createBackup = Boolean(response.data.createBackup); $scope.createBackup = Boolean(response.data.createBackup);
$scope.googleDriveBackups = Boolean(response.data.googleDriveBackups);
$scope.restoreBackup = Boolean(response.data.restoreBackup); $scope.restoreBackup = Boolean(response.data.restoreBackup);
$scope.addDeleteDestinations = Boolean(response.data.addDeleteDestinations); $scope.addDeleteDestinations = Boolean(response.data.addDeleteDestinations);
$scope.scheDuleBackups = Boolean(response.data.scheDuleBackups); $scope.scheDuleBackups = Boolean(response.data.scheDuleBackups);
@@ -1076,6 +1081,7 @@ app.controller('modifyACLCtrl', function ($scope, $http) {
// Backup Management // Backup Management
createBackup: $scope.createBackup, createBackup: $scope.createBackup,
googleDriveBackups: $scope.googleDriveBackups,
restoreBackup: $scope.restoreBackup, restoreBackup: $scope.restoreBackup,
addDeleteDestinations: $scope.addDeleteDestinations, addDeleteDestinations: $scope.addDeleteDestinations,
scheDuleBackups: $scope.scheDuleBackups, scheDuleBackups: $scope.scheDuleBackups,