diff --git a/CyberCP/secMiddleware.py b/CyberCP/secMiddleware.py index 8aa39b79e..9845142af 100755 --- a/CyberCP/secMiddleware.py +++ b/CyberCP/secMiddleware.py @@ -1,12 +1,11 @@ # coding=utf-8 from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging -import json from django.shortcuts import HttpResponse, render +import json import re from loginSystem.models import Administrator class secMiddleware: - HIGH = 0 LOW = 1 @@ -107,7 +106,7 @@ def __call__(self, request): ")") > -1 \ or value.find("'") > -1 or value.find("[") > -1 or value.find("]") > -1 or value.find( "{") > -1 or value.find("}") > -1 \ - or value.find(":") > -1 or value.find("<") > -1 or value.find(">") > -1: + or value.find(":") > -1 or value.find("<") >-1 or value.find(">") > -1: logging.writeToFile(request.body) final_dic = { 'error_message': "Data supplied is not accepted, following characters are not allowed in the input ` $ & ( ) [ ] { } ; : ‘ < >.", diff --git a/baseTemplate/templates/baseTemplate/index.html.bak b/baseTemplate/templates/baseTemplate/index.html.bak deleted file mode 100644 index b84d941e8..000000000 --- a/baseTemplate/templates/baseTemplate/index.html.bak +++ /dev/null @@ -1,1102 +0,0 @@ -{% load i18n %} -{% get_current_language as LANGUAGE_CODE %} - - - - - - - - - - {% block title %}Page Title{% endblock %} - - - - - {% load static %} - - - - - - - {% with version="2.1.2" %} - - - - - - - - - - - - - {% block styles %} - {% endblock %} - - - - - - - {% block header_scripts %} - {% endblock %} - - - - - - - - - - -
-
-
- - -
- - - - -
- -
-
-
- -
-
-
-
-
-
-
- -
- -
-
- -
-
-
-
- - - {% block content %} - {% endblock %} - -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% endwith %} - - - {% block footer_scripts %} - {% endblock %} - - diff --git a/baseTemplate/templates/baseTemplate/versionManagment.html b/baseTemplate/templates/baseTemplate/versionManagment.html index 98dc6a244..a7d15313f 100755 --- a/baseTemplate/templates/baseTemplate/versionManagment.html +++ b/baseTemplate/templates/baseTemplate/versionManagment.html @@ -1,10 +1,36 @@ {% extends "baseTemplate/index.html" %} {% load i18n %} {% block title %}{% trans "Version Management - CyberPanel" %}*{% endblock %} + {% block content %} {% load static %} + +

{% trans "Version Management" %}

@@ -12,7 +38,7 @@

{% trans "Version Management" %}

{% if Notecheck %}
-

{% trans "Note: Latest commit does not match, please upgrade CyberPanel." %}

+

{% trans "Note: Latest commit does not match, please upgrade CyberPanel." %}

{% endif %} @@ -22,59 +48,168 @@

CyberPanel

-
- {% csrf_token %} - -
-
-
- -
+
+ + +
+
+ +
-
-
-
-
-
-

- CyberPanel -

-
+
- -
{{ currentVersion }}
+ +
{{ currentVersion }}
-
- -
{{ build }}
- -
{{ Currentcomt }}
+ +
{{ build }}
+ +
{{ Currentcomt }}
-
- -
{{ latestVersion }}
+ +
{{ latestVersion }}
-
- -
{{ latestBuild }}
- -
{{ latestcomit }}
+ +
{{ latestBuild }}
+ +
{{ latestcomit }}
-
-
- -
+ +
+ +
+ +
+
+ +
+
-{% endblock %} + + +{% endblock %} \ No newline at end of file diff --git a/baseTemplate/urls.py b/baseTemplate/urls.py index 509fbe6c5..ad11d2197 100755 --- a/baseTemplate/urls.py +++ b/baseTemplate/urls.py @@ -6,7 +6,7 @@ url(r'^getSystemStatus$',views.getSystemStatus, name='getSystemInformation'), url(r'^getAdminStatus',views.getAdminStatus, name='getSystemInformation'), url(r'^getLoadAverage',views.getLoadAverage, name='getLoadAverage'), - url(r'^versionManagment',views.versionManagement, name='versionManagment'), + url(r'^versionManagment',views.versionManagment, name='versionManagment'), url(r'^design', views.design, name='design'), url(r'^getthemedata', views.getthemedata, name='getthemedata'), @@ -15,9 +15,4 @@ url(r'^UpgradeStatus',views.upgradeStatus, name='UpgradeStatus'), url(r'^upgradeVersion',views.upgradeVersion, name='upgradeVersion'), - # Add this URL pattern for 'upgrade_cyberpanel' - url(r'upgrade_cyberpanel', views.upgrade_cyberpanel, name='upgrade_cyberpanel'), - url(r'UpgradeStatus', views.upgradeStatus, name='UpgradeStatus'), - url(r'upgradeVersion', views.upgradeVersion, name='upgradeVersion'), - ] \ No newline at end of file diff --git a/baseTemplate/views.py b/baseTemplate/views.py index e88e85bae..4e0595370 100755 --- a/baseTemplate/views.py +++ b/baseTemplate/views.py @@ -1,23 +1,27 @@ # -*- coding: utf-8 -*- from django.shortcuts import render, redirect -from django.http import HttpResponse, JsonResponse +from django.http import HttpResponse +from plogical.getSystemInformation import SystemInformation +import json +from loginSystem.views import loadLoginPage from .models import version import requests import subprocess import shlex import os -import json -from plogical.getSystemInformation import SystemInformation -from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging +import plogical.CyberCPLogFileWriter as logging from plogical.acl import ACLManager from manageServices.models import PDNSStatus from django.views.decorators.csrf import ensure_csrf_cookie from plogical.processUtilities import ProcessUtilities from plogical.httpProc import httpProc +# Create your views here. + VERSION = '2.3' BUILD = 4 + @ensure_csrf_cookie def renderBase(request): template = 'baseTemplate/homePage.html' @@ -27,6 +31,7 @@ def renderBase(request): proc = httpProc(request, template, finaData) return proc.render() + @ensure_csrf_cookie def versionManagement(request): getVersion = requests.get('https://cyberpanel.net/version.txt') @@ -73,14 +78,13 @@ def upgrade_cyberpanel(request): except Exception as e: response_data = {'success': False, 'message': 'An error occurred during the upgrade: ' + str(e)} - return JsonResponse(response_data) -@ensure_csrf_cookie def getAdminStatus(request): try: val = request.session['userID'] currentACL = ACLManager.loadedACL(val) + if os.path.exists('/home/cyberpanel/postfix'): currentACL['emailAsWhole'] = 1 else: @@ -111,6 +115,7 @@ def getAdminStatus(request): except KeyError: return HttpResponse("Can not get admin Status") + def getSystemStatus(request): try: val = request.session['userID'] @@ -121,6 +126,7 @@ def getSystemStatus(request): except KeyError: return HttpResponse("Can not get admin Status") + def getLoadAverage(request): try: val = request.session['userID'] @@ -136,7 +142,53 @@ def getLoadAverage(request): except KeyError: return HttpResponse("Not allowed.") + @ensure_csrf_cookie +def versionManagment(request): + ## Get latest version + + getVersion = requests.get('https://cyberpanel.net/version.txt') + latest = getVersion.json() + latestVersion = latest['version'] + latestBuild = latest['build'] + + ## Get local version + + currentVersion = VERSION + currentBuild = str(BUILD) + + u = "https://api.github.com/repos/usmannasir/cyberpanel/commits?sha=v%s.%s" % (latestVersion, latestBuild) + logging.CyberCPLogFileWriter.writeToFile(u) + r = requests.get(u) + latestcomit = r.json()[0]['sha'] + + command ="git -C /usr/local/CyberCP/ rev-parse HEAD" + output = ProcessUtilities.outputExecutioner(command) + + Currentcomt = output.rstrip("\n") + notechk = True + + # command ="git fetch -C /usr/local/CyberCP/" + # output = ProcessUtilities.outputExecutioner(command) + # + # command ="git -C /usr/local/CyberCP/ log %s..%s --pretty=oneline | wc -l" % ( Currentcomt, latestcomit) + # output = ProcessUtilities.outputExecutioner(command) + # + # numCommits = output.rstrip("\n") + + if(Currentcomt == latestcomit): + notechk = False + + + template = 'baseTemplate/versionManagment.html' + finalData = {'build': currentBuild, 'currentVersion': currentVersion, 'latestVersion': latestVersion, + 'latestBuild': latestBuild, 'latestcomit': latestcomit, "Currentcomt": Currentcomt, "Notecheck" : notechk } + + + proc = httpProc(request, template, finalData, 'versionManagement') + return proc.render() + + def upgrade(request): try: admin = request.session['userID'] @@ -147,28 +199,38 @@ def upgrade(request): pass command = 'wget http://cyberpanel.net/upgrade.py' + cmd = shlex.split(command) + res = subprocess.call(cmd) vers = version.objects.get(pk=1) - from plogical.upgrade import Upgrade + + from upgrade import Upgrade + Upgrade.initiateUpgrade(vers.currentVersion, vers.build) + adminData = {"upgrade": 1} + json_data = json.dumps(adminData) + return HttpResponse(json_data) + except KeyError: adminData = {"upgrade": 1, "error_message": "Please login or refresh this page."} json_data = json.dumps(adminData) return HttpResponse(json_data) -@ensure_csrf_cookie + def upgradeStatus(request): try: val = request.session['userID'] try: if request.method == 'POST': + path = "/usr/local/lscp/logs/upgradeLog" + try: upgradeLog = open(path, "r").read() except: @@ -178,13 +240,16 @@ def upgradeStatus(request): return HttpResponse(final_json) if upgradeLog.find("Upgrade Completed") > -1: + vers = version.objects.get(pk=1) getVersion = requests.get('https://cyberpanel.net/version.txt') latest = getVersion.json() vers.currentVersion = latest['version'] vers.build = latest['build'] vers.save() + os.remove(path) + final_json = json.dumps({'finished': 1, 'upgradeStatus': 1, 'error_message': "None", 'upgradeLog': upgradeLog}) @@ -194,6 +259,8 @@ def upgradeStatus(request): 'error_message': "None", 'upgradeLog': upgradeLog}) return HttpResponse(final_json) + + except BaseException as msg: final_dic = {'upgradeStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) @@ -203,6 +270,7 @@ def upgradeStatus(request): final_json = json.dumps(final_dic) return HttpResponse(final_json) + def upgradeVersion(request): try: vers = version.objects.get(pk=1) @@ -216,8 +284,10 @@ def upgradeVersion(request): logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) + @ensure_csrf_cookie def design(request): + ### Load Custom CSS try: from baseTemplate.models import CyberPanelCosmetic cosmetic = CyberPanelCosmetic.objects.get(pk=1) @@ -241,8 +311,12 @@ def design(request): cosmetic.save() finalData['saved'] = 1 + ####### Fetch sha... + sha_url = "https://api.github.com/repos/usmannasir/CyberPanel-Themes/commits" + sha_res = requests.get(sha_url) + sha = sha_res.json()[0]['sha'] l = "https://api.github.com/repos/usmannasir/CyberPanel-Themes/git/trees/%s" % sha @@ -259,6 +333,7 @@ def design(request): proc = httpProc(request, template, finalData, 'versionManagement') return proc.render() + def getthemedata(request): try: val = request.session['userID'] @@ -270,9 +345,12 @@ def getthemedata(request): else: return ACLManager.loadErrorJson('reboot', 0) + #logging.CyberCPLogFileWriter.writeToFile(str(data) + " [themedata]") + url = "https://raw.githubusercontent.com/usmannasir/CyberPanel-Themes/main/%s/design.css" % data['Themename'] res = requests.get(url) + rsult = res.text final_dic = {'status': 1, 'csscontent': rsult} final_json = json.dumps(final_dic) @@ -281,3 +359,4 @@ def getthemedata(request): final_dic = {'status': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) + diff --git a/phpmyadmin.zip b/phpmyadmin.zip index 65b7e289a..12b767d7f 100644 Binary files a/phpmyadmin.zip and b/phpmyadmin.zip differ