complete the onboarding function

This commit is contained in:
usmannasir
2024-01-25 10:44:06 +05:00
parent c9392bef93
commit a4b6cbf40f
10 changed files with 641 additions and 184 deletions

View File

@@ -5,7 +5,6 @@
/* Utilities */
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
@@ -576,8 +575,6 @@ app.controller('versionManagment', function ($scope, $http, $timeout) {
};
url = "/base/upgrade";
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
@@ -717,3 +714,156 @@ app.controller('designtheme', function ($scope, $http, $timeout) {
});
app.controller('OnboardingCP', function ($scope, $http, $timeout, $window) {
$scope.cyberpanelLoading = true;
$scope.ExecutionStatus = true;
$scope.ReportStatus = true;
$scope.OnboardineDone = true;
function statusFunc() {
$scope.cyberpanelLoading = false;
$scope.ExecutionStatus = false;
var url = "/emailPremium/statusFunc";
var data = {
statusFile: statusFile
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
if (response.data.status === 1) {
if (response.data.abort === 1) {
$scope.functionProgress = {"width": "100%"};
$scope.functionStatus = response.data.currentStatus;
$scope.cyberpanelLoading = true;
$scope.OnboardineDone = false;
$timeout.cancel();
} else {
$scope.functionProgress = {"width": response.data.installationProgress + "%"};
$scope.functionStatus = response.data.currentStatus;
$timeout(statusFunc, 3000);
}
} else {
$scope.cyberpanelLoading = true;
$scope.functionStatus = response.data.error_message;
$scope.functionProgress = {"width": response.data.installationProgress + "%"};
$timeout.cancel();
}
}
function cantLoadInitialData(response) {
$scope.functionProgress = {"width": response.data.installationProgress + "%"};
$scope.functionStatus = 'Could not connect to server, please refresh this page.';
$timeout.cancel();
}
}
$scope.RunOnboarding = function () {
$scope.cyberpanelLoading = false;
$scope.OnboardineDone = true;
var url = "/base/runonboarding";
var data = {
hostname: $scope.hostname,
rDNSCheck: $scope.rDNSCheck
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
statusFile = response.data.tempStatusPath;
statusFunc();
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialData(response) {
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Error',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
$scope.RestartCyberPanel = function () {
$scope.cyberpanelLoading = false;
var url = "/base/RestartCyberPanel";
var data = {
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Success',
text: 'Refresh your browser after 3 seconds to fetch new SSL.',
type: 'success'
});
function ListInitialData(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialData(response) {
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Error',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
});

View File

@@ -1120,7 +1120,13 @@
<div id="page-content-wrapper">
<div id="page-content">
{% if onboarding == 0 %}
<div ng-hide="success" class="alert alert-info">
<p>{{ onboardingError | safe }}</p>
</div>
{% elif onboarding == 3 %}
<p>Looks like something is wrong with your initial setup, please double check on <a href="/base/onboarding">Setup Wizard.</a> </p>
{% endif %}
{% block content %}
{% endblock %}
@@ -1156,9 +1162,9 @@
<script src="{% static 'containerization/containerization.js' %}?ver={{ version }}"></script>
<script src="{% static 'CLManager/CLManager.js' %}?ver={{ version }}"></script>
<script src="{% static 'IncBackups/IncBackups.js' %}?ver={{ version }}"></script>
<script src="{% static 'WebTerminal/term.js' %}?ver={{ version }}"></script>
<script src="{% static 'WebTerminal/ws.js' %}?ver={{ version }}"></script>
<script src="{% static 'WebTerminal/main.js' %}?ver={{ version }}"></script>
{# <script src="{% static 'WebTerminal/term.js' %}?ver={{ version }}"></script>#}
{# <script src="{% static 'WebTerminal/ws.js' %}?ver={{ version }}"></script>#}
{# <script src="{% static 'WebTerminal/main.js' %}?ver={{ version }}"></script>#}
{% endwith %}

View File

@@ -0,0 +1,115 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Configure Hostname and other default Settings - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Initial Configurations" %}- <a target="_blank" href="https://go.cyberpanel.net/setup-wizard"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "Learn More" %}</span></a></h2>
<p>{% trans "Configure Hostname and other default Settings for CyberPanel" %}</p>
</div>
<div ng-controller="OnboardingCP" class="panel">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Initial Configurations" %} <img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row panel-body">
<div ng-hide="success" class="alert alert-info">
<ul>
<li><strong>Choose this wisely, if you are not going to use email service on this server, skip rDNS checks.</strong> Ensure that the hostname you provide below is set as rDNS (reverse DNS, also called PTR record) against your
IP address. (Only required if you want to use email services on the same server)
</li>
<li>Make sure that the provided hostname also has an A record pointing to your server's
IP address.
</li>
<li>If the above conditions fail, your server may not function as expected, especially
for email services.
</li>
</ul>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Hostname" %}</label>
<div class="col-sm-6">
<input name="dom" type="text" class="form-control"
ng-model="hostname" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Additional Features" %}</label>
<div class="col-sm-9">
<div class="checkbox">
<label>
<input ng-model="rDNSCheck" type="checkbox" value="">
Skip rDNS/PTR Check (If you don't want to use email service on this server)
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="RunOnboarding()"
class="btn btn-primary btn-lg btn-block">{% trans "Start Configurations" %}</button>
</div>
</div>
<div ng-hide="OnboardineDone" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="RestartCyberPanel()"
class="btn btn-primary btn-lg btn-block">{% trans "Restart CyberPanel" %}</button>
</div>
</div>
</form>
</div>
<div ng-hide="ExecutionStatus" class="row">
<div class="col-md-12">
<div class="form-group">
<p>Note: once configurations are completed, click Restart CyberPanel above, after clicking Restart CyberPanel refresh page to fetch new SSL from the browser.</p>
<h4 style="margin-top: 2%; margin-bottom: 2%"> {$ functionStatus $} <img
ng-hide="cyberpanelLoading" src="{% static 'images/loading.gif' %}">
</h4>
<div class="progress">
<div ng-style="functionProgress"
class="progress-bar progress-bar-striped bg-info"
role="progressbar"
aria-valuenow="50" aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</div>
</div>
</div> <!-- end row -->
</div>
</div>
</div>
{% endblock %}

View File

@@ -11,6 +11,9 @@ urlpatterns = [
url(r'^getthemedata', views.getthemedata, name='getthemedata'),
url(r'^upgrade',views.upgrade, name='upgrade'),
url(r'^onboarding$', views.onboarding, name='onboarding'),
url(r'^RestartCyberPanel$', views.RestartCyberPanel, name='RestartCyberPanel'),
url(r'^runonboarding', views.runonboarding, name='runonboarding'),
url(r'^UpgradeStatus',views.upgradeStatus, name='UpgradeStatus'),
url(r'^upgradeVersion',views.upgradeVersion, name='upgradeVersion'),

View File

@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from random import randint
from django.shortcuts import render, redirect
from django.http import HttpResponse
from plogical.getSystemInformation import SystemInformation
@@ -56,25 +58,28 @@ def versionManagement(request):
if Currentcomt == latestcomit:
notechk = False
template = 'baseTemplate/versionManagment.html'
finalData = {'build': currentBuild, 'currentVersion': currentVersion, 'latestVersion': latestVersion,
'latestBuild': latestBuild, 'latestcomit': latestcomit, "Currentcomt": Currentcomt, "Notecheck": notechk}
'latestBuild': latestBuild, 'latestcomit': latestcomit, "Currentcomt": Currentcomt,
"Notecheck": notechk}
proc = httpProc(request, template, finalData, 'versionManagement')
return proc.render()
@ensure_csrf_cookie
def upgrade_cyberpanel(request):
if request.method == 'POST':
try:
upgrade_command = 'sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh)'
result = subprocess.run(upgrade_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
result = subprocess.run(upgrade_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
text=True)
if result.returncode == 0:
response_data = {'success': True, 'message': 'CyberPanel upgrade completed successfully.'}
else:
response_data = {'success': False, 'message': 'CyberPanel upgrade failed. Error output: ' + result.stderr}
response_data = {'success': False,
'message': 'CyberPanel upgrade failed. Error output: ' + result.stderr}
except Exception as e:
response_data = {'success': False, 'message': 'An error occurred during the upgrade: ' + str(e)}
@@ -84,7 +89,6 @@ def getAdminStatus(request):
val = request.session['userID']
currentACL = ACLManager.loadedACL(val)
if os.path.exists('/home/cyberpanel/postfix'):
currentACL['emailAsWhole'] = 1
else:
@@ -179,11 +183,10 @@ def versionManagment(request):
if (Currentcomt == latestcomit):
notechk = False
template = 'baseTemplate/versionManagment.html'
finalData = {'build': currentBuild, 'currentVersion': currentVersion, 'latestVersion': latestVersion,
'latestBuild': latestBuild, 'latestcomit': latestcomit, "Currentcomt": Currentcomt, "Notecheck" : notechk }
'latestBuild': latestBuild, 'latestcomit': latestcomit, "Currentcomt": Currentcomt,
"Notecheck": notechk}
proc = httpProc(request, template, finalData, 'versionManagement')
return proc.render()
@@ -350,3 +353,71 @@ def getthemedata(request):
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def onboarding(request):
template = 'baseTemplate/onboarding.html'
proc = httpProc(request, template, None, 'admin')
return proc.render()
def runonboarding(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()
data = json.loads(request.body)
hostname = data['hostname']
try:
rDNSCheck = str(int(data['rDNSCheck']))
except:
rDNSCheck = 0
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
WriteToFile = open(tempStatusPath, 'w')
WriteToFile.write('Starting')
WriteToFile.close()
command = f'/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/virtualHostUtilities.py OnBoardingHostName --virtualHostName {hostname} --path {tempStatusPath} --rdns {rDNSCheck}'
ProcessUtilities.popenExecutioner(command)
dic = {'status': 1, 'tempStatusPath': tempStatusPath}
json_data = json.dumps(dic)
return HttpResponse(json_data)
except BaseException as msg:
dic = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(dic)
return HttpResponse(json_data)
def RestartCyberPanel(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()
command = 'systemctl restart lscpd'
ProcessUtilities.popenExecutioner(command)
dic = {'status': 1}
json_data = json.dumps(dic)
return HttpResponse(json_data)
except BaseException as msg:
dic = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(dic)
return HttpResponse(json_data)

View File

@@ -8,19 +8,27 @@
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div class="container" xmlns="http://www.w3.org/1999/html">
<div id="page-title">
<h2>{% trans "Issue SSL For Hostname" %} - <a target="_blank" href="http://go.cyberpanel.net/hostname-ssl" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "SSL Docs" %}</span></a></h2>
<h2>{% trans "Issue SSL For Hostname" %} - <a target="_blank" href="http://go.cyberpanel.net/hostname-ssl"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "SSL Docs" %}</span></a></h2>
<p>{% trans "Lets Encrypt SSL for hostname to access CyberPanel on verified SSL." %}</p>
</div>
<div ng-controller="sslIssueForHostNameCtrl" class="panel">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Issue SSL For Hostname" %} <img ng-hide="manageSSLLoading" src="{% static 'images/loading.gif' %}">
{% trans "Issue SSL For Hostname" %} <img ng-hide="manageSSLLoading"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<div ng-hide="success" class="alert alert-info">
<p>Note: This feature is deprecated in favour of <a href="/base/onboarding">setup-wizard</a>.</p>
</div>
<form action="/" class="form-horizontal bordered-row panel-body">
@@ -39,7 +47,8 @@
<div ng-hide="issueSSLBtn" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="issueSSL()" class="btn btn-primary btn-lg">{% trans "Issue SSL" %}</button>
<button type="button" ng-click="issueSSL()"
class="btn btn-primary btn-lg">{% trans "Issue SSL" %}</button>
</div>
</div>
@@ -53,23 +62,23 @@
</div>
<div ng-hide="sslIssued" class="alert alert-success">
<p>{% trans "SSL Issued. You can now access CyberPanel at:" %} <strong>https://{$ sslDomain $}:8090</strong></p>
<p>{% trans "SSL Issued. You can now access CyberPanel at:" %}
<strong>https://{$ sslDomain $}:8090</strong></p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-success">
<p>{% trans "SSL Issued. You can now access CyberPanel at:" %} <strong>https://"domain":8090</strong></p>
<p>{% trans "SSL Issued. You can now access CyberPanel at:" %} <strong>https://"domain":8090</strong>
</p>
</div>
</div>
</div>
</form>
</div>
</div>
</div>

View File

@@ -10,17 +10,27 @@
<div class="container">
<div id="page-title">
<h2>{% trans "Issue SSL For MailServer" %} - <a target="_blank" href="http://go.cyberpanel.net/mailserver-ssl" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "SSL Docs" %}</span></a></h2>
<h2>{% trans "Issue SSL For MailServer" %} - <a target="_blank"
href="http://go.cyberpanel.net/mailserver-ssl"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "SSL Docs" %}</span></a></h2>
<p>{% trans "Lets Encrypt SSL for MailServer (Postfix/Dovecot)." %}</p>
</div>
<div ng-controller="sslIssueForMailServer" class="panel">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Issue SSL For MailServer" %} <img ng-hide="manageSSLLoading" src="{% static 'images/loading.gif' %}">
{% trans "Issue SSL For MailServer" %} <img ng-hide="manageSSLLoading"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<div ng-hide="success" class="alert alert-info">
<p>Note: This feature is deprecated in favour of <a href="/base/onboarding">setup-wizard</a>.
</p>
</div>
<form action="/" class="form-horizontal bordered-row panel-body">
<div class="form-group">
@@ -37,7 +47,8 @@
<div ng-hide="issueSSLBtn" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="issueSSL()" class="btn btn-primary btn-lg btn-block">{% trans "Issue SSL" %}</button>
<button type="button" ng-click="issueSSL()"
class="btn btn-primary btn-lg btn-block">{% trans "Issue SSL" %}</button>
</div>
</div>
@@ -60,14 +71,12 @@
</div>
</div>
</form>
</div>
</div>
</div>

View File

@@ -1479,6 +1479,25 @@ Automatic Backupv2 failed for %s on %s.
print("Error: [v2Backups]: %s" % str(msg))
logging.writeToFile('%s. [v2Backups]' % (str(msg)))
@staticmethod
def CheckHostName():
try:
from loginSystem.models import Administrator
admin = Administrator.objects.get(pk=1)
config = json.loads(admin.config)
### probably need to add temporary dns resolver nameserver here - pending
try:
CurrentHostName = config['hostname']
skipRDNSCheck = config['skipRDNSCheck']
except:
CurrentHostName = ''
skipRDNSCheck = 1
virtualHostUtilities.OnBoardingHostName(CurrentHostName, '/home/cyberpanel/onboarding_temp_path', skipRDNSCheck)
except BaseException as msg:
logging.writeToFile(f'{str(msg)}. [Cron.CheckHostName]')
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')
@@ -1524,6 +1543,7 @@ def main():
IncScheduler.checkDiskUsage()
IncScheduler.startNormalBackups(args.function)
IncScheduler.runAWSBackups(args.function)
IncScheduler.CheckHostName()
ib.join()

View File

@@ -31,11 +31,31 @@ class httpProc:
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 = {}
### Onboarding checks
if currentACL['admin']:
try:
admin = Administrator.objects.get(userName='admin')
config = json.loads(admin.config)
self.data['onboarding'] = config['onboarding']
except:
self.data['onboarding'] = 0
self.data['onboardingError'] = """
Please launch the <a href="/base/onboarding">set-up wizard</a> to get maximum out of your CyberPanel installation.
"""
else:
self.data['onboarding'] = 2
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()

View File

@@ -2,6 +2,8 @@
import os
import os.path
import sys
import time
import django
# PACKAGE_PARENT = '..'
@@ -56,7 +58,7 @@ class virtualHostUtilities:
@staticmethod
def OnBoardingHostName(Domain, tempStatusPath):
def OnBoardingHostName(Domain, tempStatusPath, skipRDNSCheck):
import json
import OpenSSL
@@ -76,9 +78,18 @@ class virtualHostUtilities:
PostFixHostname = mailUtilities.FetchPostfixHostname()
serverIP = ACLManager.fetchIP()
### if skipRDNSCheck == 1, it means we need to skip checking for rDNS
if skipRDNSCheck:
### so if skipRDNSCheck is 1 means we need to skip checking for rDNS so lets set current as rDNS because no checking is required
rDNS = CurrentHostName
else:
rDNS = mailUtilities.reverse_dns_lookup(serverIP)
time.sleep(3)
if os.path.exists(ProcessUtilities.debugPath):
print(f'Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {rDNS}')
logging.CyberCPLogFileWriter.writeToFile(f'Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {rDNS}, rDNS check {skipRDNSCheck}')
### Case 1 if hostname already exists check if same hostname in postfix and rdns
filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (PostFixHostname)
@@ -122,10 +133,20 @@ class virtualHostUtilities:
message = 'Hostname SSL was already issued, and same hostname was used in mail server SSL, rDNS was also configured but we found invalid SSL. However, we tried to issue SSL and it failed. [404]'
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)
logging.CyberCPLogFileWriter.writeToFile(message)
config['hostname'] = Domain
config['onboarding'] = 3
config['skipRDNSCheck'] = skipRDNSCheck
admin.config = json.dumps(config)
admin.save()
return 0
else:
message = "It looks like your current hostname is already the mail server hostname and rDNS is also set and there is a valid SSL, nothing needed to do."
print(message)
config['hostname'] = Domain
config['onboarding'] = 1
config['skipRDNSCheck'] = skipRDNSCheck
admin.config = json.dumps(config)
admin.save()
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)
logging.CyberCPLogFileWriter.writeToFile(message)
@@ -137,13 +158,28 @@ class virtualHostUtilities:
### Case 2 where postfix hostname either does not exist or does not match with server hostname or
### hostname does not exists at all
### if skipRDNSCheck == 1, it means we need to skip checking for rDNS
if skipRDNSCheck:
### so if skipRDNSCheck is 1 means we need to skip checking for rDNS so lets set current domain as rDNS because no checking is required
rDNS = Domain
if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile(
f'Second if: Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {rDNS}, rDNS check {skipRDNSCheck}')
#first check if hostname is already configured as rDNS, if not return error
if Domain != rDNS:
message = 'Domain that you have provided is not configured as rDNS for your server IP. [404]'
print(message)
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)
logging.CyberCPLogFileWriter.writeToFile(message)
config['hostname'] = Domain
config['onboarding'] = 3
config['skipRDNSCheck'] = skipRDNSCheck
admin.config = json.dumps(config)
admin.save()
return 0
### now issue hostname ssl
@@ -157,7 +193,7 @@ class virtualHostUtilities:
filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (Domain)
virtualHostUtilities.issueSSLForHostName(Domain, path)
virtualHostUtilities.issueSSLForHostName(Domain, path, 1)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(filePath, 'r').read())
SSLProvider = x509.get_issuer().get_components()[1][1].decode('utf-8')
@@ -166,6 +202,11 @@ class virtualHostUtilities:
message = 'Failed to issue Hostname SSL, either its DNS record is not propagated or the domain ie behind Cloudflare. [404]'
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)
logging.CyberCPLogFileWriter.writeToFile(message)
config['hostname'] = Domain
config['onboarding'] = 3
config['skipRDNSCheck'] = skipRDNSCheck
admin.config = json.dumps(config)
admin.save()
return 0
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Hostname SSL issued,50')
@@ -180,13 +221,18 @@ class virtualHostUtilities:
message = 'Failed to issue Mail server SSL, either its DNS record is not propagated or the domain ie behind Cloudflare. [404]'
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)
logging.CyberCPLogFileWriter.writeToFile(message)
return 0
else:
config['hostname'] = Domain
config['onboarding'] = 3
config['skipRDNSCheck'] = skipRDNSCheck
admin.config = json.dumps(config)
admin.save()
return 0
else:
config['hostname'] = Domain
config['onboarding'] = 1
config['skipRDNSCheck'] = skipRDNSCheck
admin.config = json.dumps(config)
admin.save()
command = 'systemctl restart postfix && systemctl restart dovecot && postmap -F hash:/etc/postfix/vmail_ssl.map'
ProcessUtilities.executioner(command, 'root', True)
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Completed. [200]')
@@ -641,7 +687,7 @@ class virtualHostUtilities:
print("0," + str(msg))
@staticmethod
def issueSSLForHostName(virtualHost, path):
def issueSSLForHostName(virtualHost, path, skipLSCPDRestart=0):
try:
destPrivKey = "/usr/local/lscp/conf/key.pem"
@@ -705,6 +751,10 @@ class virtualHostUtilities:
command = 'ln -s %s %s' % (pathToStoreSSLPrivKey, destPrivKey)
ProcessUtilities.executioner(command)
if skipLSCPDRestart:
pass
else:
command = 'systemctl restart lscpd'
cmd = shlex.split(command)
subprocess.call(cmd)
@@ -1687,6 +1737,10 @@ def main():
parser.add_argument('--DeleteDocRoot', help='Doc root deletion for child domain.')
### for onboarding
parser.add_argument('--rdns', help='Doc root deletion for child domain.')
args = parser.parse_args()
if args.function == "createVirtualHost":
@@ -1793,7 +1847,7 @@ def main():
elif args.function == 'OnBoardingHostName':
# in virtualHostName pass domain for which hostname should be set up
# in path pass temporary path where status of the function will be stored
virtualHostUtilities.OnBoardingHostName(args.virtualHostName, args.path)
virtualHostUtilities.OnBoardingHostName(args.virtualHostName, args.path, int(args.rdns))
if __name__ == "__main__":