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 websiteFunctions.models import Websites
from CLManager.models import CLPackages
from plogical.httpProc import httpProc
class CLManagerMain(multi.Thread):
@@ -27,29 +27,14 @@ class CLManagerMain(multi.Thread):
self.submitCageFSInstall()
elif self.function == 'enableOrDisable':
self.enableOrDisable()
except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [ContainerManager.run]')
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['CL'] = 0
data['activatedPath'] = 0
data['ipAddress'] = ipAddress
CLPath = '/etc/sysconfig/cloudlinux'
activatedPath = '/home/cyberpanel/cloudlinux'
@@ -60,11 +45,14 @@ class CLManagerMain(multi.Thread):
data['activatedPath'] = 1
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:
return render(self.request, 'CLManager/notAvailable.html', data)
proc = httpProc(self.request, 'CLManager/notAvailable.html', data, 'admin')
return proc.render()
else:
return render(self.request, 'CLManager/cloudLinux.html', data)
proc = httpProc(self.request, 'CLManager/cloudLinux.html', data, 'admin')
return proc.render()
def submitCageFSInstall(self):
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 %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
{% 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>
<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--->
<!--- 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="panel-body">
<h3 class="content-box-header">
{% trans "Available Functions" %}
</h3>
<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="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">
{% trans "Users" %}
</div>
@@ -33,10 +33,11 @@
<i class="fa fa-users"></i>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<a href="{% url 'loadWebsitesHome' %}" title="{% trans 'Website Functions' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'loadWebsitesHome' %}" title="{% trans 'Website Functions' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Websites" %}
</div>
@@ -46,8 +47,9 @@
</a>
</div>
<div class="col-md-4">
<a href="{% url 'packagesHome' %}" title="{% trans 'Add/Modify Packages' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'packagesHome' %}" title="{% trans 'Add/Modify Packages' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Packages" %}
</div>
@@ -55,10 +57,11 @@
<i class="fa fa-cubes"></i>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<a href="{% url 'loadDatabaseHome' %}" title="{% trans 'Database Functions' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'loadDatabaseHome' %}" title="{% trans 'Database Functions' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Databases" %}
</div>
@@ -66,10 +69,11 @@
<i class="fa fa-database"></i>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<a href="{% url 'dnsHome' %}" title="{% trans 'Control DNS' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'dnsHome' %}" title="{% trans 'Control DNS' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "DNS" %}
</div>
@@ -77,10 +81,11 @@
<i class="fa fa-sitemap"></i>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<a href="{% url 'loadFTPHome' %}" title="{% trans 'FTP Functions' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'loadFTPHome' %}" title="{% trans 'FTP Functions' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "FTP" %}
</div>
@@ -90,8 +95,9 @@
</a>
</div>
<div class="col-md-4">
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Back up' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Back up' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Back up" %}
</div>
@@ -99,171 +105,175 @@
<i class="fa fa-clone"></i>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<a href="{% url 'loadEmailHome' %}" title="{% trans 'Emails' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<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">
{% trans "Emails" %}
{% trans "Status" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-envelope"></i>
<i class="fa fa-server"></i>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<a href="{% url 'loadSSLHome' %}" title="{% trans 'SSL' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="col-md-4">
<a href="{% url 'loadPHPHome' %}" title="{% trans 'PHP Configurations' %}"
class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "SSL" %}
{% trans "PHP" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-expeditedssl"></i>
<i class="fa fa-code"></i>
</div>
</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">
<a href="{% url 'serverStatusHome' %}" title="{% trans 'Server Status' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Status" %}
</div>
<div class="tile-content-wrapper">
<i class="fa fa-server"></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>
<div class="col-md-4">
<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 %}
{% endif %}
</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>
{% 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>
{% endif %}
</div>
{% endblock %}

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -5,7 +5,7 @@ from plogical.acl import ACLManager
import plogical.CyberCPLogFileWriter as logging
from serverStatus.serverStatusUtil import ServerStatusUtil
import os, stat
from plogical.httpProc import httpProc
class ContainerManager(multi.Thread):
defaultConf = """group {groupName}{
@@ -84,14 +84,6 @@ class ContainerManager(multi.Thread):
def renderC(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
data = {}
data['OLS'] = 0
data['notInstalled'] = 0
@@ -99,17 +91,20 @@ class ContainerManager(multi.Thread):
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
data['OLS'] = 1
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():
data['OLS'] = 0
data['notInstalled'] = 1
return render(self.request, 'containerization/notAvailable.html', data)
proc = httpProc(self.request, 'containerization/notAvailable.html', data, 'admin')
return proc.render()
else:
if self.data == None:
self.data = {}
self.data['OLS'] = 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):
try:
@@ -165,7 +160,6 @@ class ContainerManager(multi.Thread):
# 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'
#logging.CyberCPLogFileWriter.writeToFile(command)
ProcessUtilities.executioner(command)
self.restartServices()

View File

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

View File

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

View File

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

View File

@@ -2,12 +2,14 @@
from django.shortcuts import render, HttpResponse
import json
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter
class httpProc:
def __init__(self, request, templateName, data = None):
def __init__(self, request, templateName, data = None, function = None):
self.request = request
self.templateName = templateName
self.data = data
self.function = function
def render(self):
@@ -15,19 +17,33 @@ class httpProc:
from loginSystem.models import Administrator
from plogical.acl import ACLManager
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:
self.data = {}
self.data.update(ACLManager.loadedACL(userID))
return render(self.request, self.templateName, self.data)
ipFile = "/etc/cyberpanel/machineIP"
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:
templateName = 'UserManagement/login.html'
return render(self.request, templateName)
templateName = 'baseTemplate/error.html'
return render(self.request, templateName, {'error_message': str(msg)})
def renderPre(self):
if self.data == None:

View File

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