diff --git a/websiteFunctions/models.py b/websiteFunctions/models.py index 9e4c8fe82..9f58f118d 100755 --- a/websiteFunctions/models.py +++ b/websiteFunctions/models.py @@ -102,7 +102,7 @@ class NormalBackupJobLogs(models.Model): class wpplugins(models.Model): - owner = models.ForeignKey(Websites, on_delete=models.CASCADE) + owner = models.ForeignKey(Administrator, on_delete=models.CASCADE) Name = models.CharField(max_length=255, default='') config = models.TextField() diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 644bb9c53..bf4966f2e 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -19,10 +19,11 @@ function getCookie(name) { } return cookieValue; } + var arry = [] -function selectpluginJs(val) { - $('#mysearch').hide() +function selectpluginJs(val) { + $('#mysearch').hide() arry.push(val) // console.log(arry) @@ -37,18 +38,29 @@ function selectpluginJs(val) { } -app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window) { - $scope.SearchPluginName = function () { +var DeletePluginURL; +function DeletePluginBuucket(url) { + DeletePluginURL = url; +} + +function FinalDeletePluginBuucket() { + window.location.href = DeletePluginURL; +} + +var SPVal; +app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window, $compile) { + + $scope.SearchPluginName = function (val) { + SPVal = val; url = "/websites/SearchOnkeyupPlugin"; var searchcontent = $scope.searchcontent; - var data = { - pluginname : searchcontent + pluginname: searchcontent }; var config = { @@ -63,23 +75,35 @@ app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window) { function ListInitialDatas(response) { if (response.data.status === 1) { - // console.log(response.data); + if (SPVal == 'add') { + $('#mysearch').show() + document.getElementById('mysearch').innerHTML = ""; + var res = response.data.plugns.plugins + // console.log(res); + for (i = 0; i <= res.length; i++) { + // + var tml = '
'; + $('#mysearch').append(tml); + } + } else if (SPVal == 'eidt') { + $('#mysearch').show() + document.getElementById('mysearch').innerHTML = ""; + var res = response.data.plugns.plugins + // console.log(res); + for (i = 0; i <= res.length; i++) { + // + var tml = '
'; + var temp = $compile(tml)($scope) + angular.element(document.getElementById('mysearch')).append(temp); + } + + } - $('#mysearch').show() - document.getElementById('mysearch').innerHTML = ""; - var res = response.data.plugns.plugins - // console.log(res); - for (i = 0; i <= res.length; i++) { - // - var tml = '
'; - $('#mysearch').append(tml); - - } } else { // $scope.errorMessage = response.data.error_message; - alert("Status not = 1: Error..."+response.data.error_message) + alert("Status not = 1: Error..." + response.data.error_message) } @@ -87,11 +111,136 @@ app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window) { function cantLoadInitialDatas(response) { - alert("Error..."+response) + alert("Error..." + response) } } + $scope.AddNewplugin = function () { + + url = "/websites/AddNewpluginAjax"; + + var bucketname = $scope.PluginbucketName + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + var data = { + config: arry, + Name: bucketname + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + alert("added.........."); + location.reload(); + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + } + + $scope.deletesPlgin = function (val) { + + url = "/websites/deletesPlgin"; + + + var data = { + pluginname: val, + pluginbBucketID: $('#pluginbID').html() + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + location.reload(); + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + } + + $scope.Addplugin = function (slug) { + $('#mysearch').hide() + + url = "/websites/Addplugineidt"; + + + var data = { + pluginname: slug, + pluginbBucketID: $('#pluginbID').html() + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + location.reload(); + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + + } + }); @@ -774,8 +923,9 @@ app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { } + var DeleteDomain; - $scope.deleteDomainInit = function (childDomainForDeletion){ + $scope.deleteDomainInit = function (childDomainForDeletion) { DeleteDomain = childDomainForDeletion; }; @@ -2118,7 +2268,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { var statusFile; - $scope.WebsiteSelection = function (){ + $scope.WebsiteSelection = function () { $scope.DomainCreateForm = false; }; @@ -2804,7 +2954,7 @@ RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] ### End CyberPanel Generated Rules. `; - + const WWWToNonWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator RewriteEngine On @@ -2831,8 +2981,7 @@ RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] $scope.rewriteRules = httpToHTTPS + $scope.rewriteRules; } else if ($scope.rewriteTemplate === "Force NON-WWW -> WWW") { $scope.rewriteRules = nonWWWToWWW + $scope.rewriteRules; - } - else if ($scope.rewriteTemplate === "Force WWW -> NON-WWW") { + } else if ($scope.rewriteTemplate === "Force WWW -> NON-WWW") { $scope.rewriteRules = WWWToNonWWW + $scope.rewriteRules; } }; diff --git a/websiteFunctions/templates/websiteFunctions/WPAddNewPlugin.html b/websiteFunctions/templates/websiteFunctions/WPAddNewPlugin.html index 577080151..3cf925426 100644 --- a/websiteFunctions/templates/websiteFunctions/WPAddNewPlugin.html +++ b/websiteFunctions/templates/websiteFunctions/WPAddNewPlugin.html @@ -32,7 +32,7 @@ @@ -56,7 +56,7 @@
diff --git a/websiteFunctions/templates/websiteFunctions/WPConfigurePlugins.html b/websiteFunctions/templates/websiteFunctions/WPConfigurePlugins.html index 0b600d38c..63e28be6a 100644 --- a/websiteFunctions/templates/websiteFunctions/WPConfigurePlugins.html +++ b/websiteFunctions/templates/websiteFunctions/WPConfigurePlugins.html @@ -11,11 +11,93 @@

{% trans "Configure Plugins" %}

{% trans "Add New Plugin" %} -
+

List of Saved Plugins Bucket

+ + + + + + + + + + + + + + {% for sub in Selectedplugins %} + + + + + + + + + {% endfor %} + + + + + + + + + {% endblock %} diff --git a/websiteFunctions/templates/websiteFunctions/WPEidtPlugin.html b/websiteFunctions/templates/websiteFunctions/WPEidtPlugin.html new file mode 100644 index 000000000..4aa300366 --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/WPEidtPlugin.html @@ -0,0 +1,81 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "plugin - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + +
+ +
+

{% trans "Eidt Plugin Bucket" %} + +

+
+
+
+
+ +
+ + + + + + + + + + + + + + + +

Selected Plugin

+
+ {% for plugin in Selectedplugins %} +
+ {{plugin}} + + +
+     + {% endfor %} + + +
+ +
+
+ +
+ + +
+
+ +
+
+
+ + + +{% endblock %} diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 6b3f7fbd1..1b47c5da0 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -22,9 +22,13 @@ urlpatterns = [ #### AddPlugin url(r'^ConfigurePlugins$', views.ConfigurePlugins, name='ConfigurePlugins'), url(r'^Addnewplugin$', views.Addnewplugin, name='Addnewplugin'), + url(r'^EidtPlugin$', views.EidtPlugin, name='EidtPlugin'), ## AddPlugin Ajax url(r'^SearchOnkeyupPlugin$', views.SearchOnkeyupPlugin, name='SearchOnkeyupPlugin'), + url(r'^AddNewpluginAjax$', views.AddNewpluginAjax, name='AddNewpluginAjax'), + url(r'^deletesPlgin', views.deletesPlgin, name='deletesPlgin'), + url(r'^Addplugineidt', views.Addplugineidt, name='Addplugineidt'), # Website modification url diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index b8ed4b321..d550c0830 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -10,6 +10,7 @@ import plogical.CyberCPLogFileWriter as logging from plogical.httpProc import httpProc +from websiteFunctions.models import wpplugins from websiteFunctions.website import WebsiteManager from websiteFunctions.pluginManager import pluginManager from django.views.decorators.csrf import csrf_exempt @@ -38,6 +39,16 @@ def WPCreate(request): def ConfigurePlugins(request): try: userID = request.session['userID'] + userobj = Administrator.objects.get(pk=userID) + DeleteFileID = request.GET.get('delete', None) + if DeleteFileID != None: + try: + jobobj = wpplugins.objects.get(pk=DeleteFileID, owner=userobj) + jobobj.delete() + Deleted = 1 + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile("DeleteFileID ....... %s....msg.....%s" % (DeleteFileID,msg)) + Deleted = 0 wm = WebsiteManager() return wm.ConfigurePlugins(request, userID) except KeyError: @@ -73,6 +84,84 @@ def SearchOnkeyupPlugin(request): return redirect(loadLoginPage) +def AddNewpluginAjax(request): + try: + userID = request.session['userID'] + + result = pluginManager.preWebsiteCreation(request) + + if result != 200: + return result + + wm = WebsiteManager() + coreResult = wm.AddNewpluginAjax(userID, json.loads(request.body)) + + result = pluginManager.postWebsiteCreation(request, coreResult) + if result != 200: + return result + + return coreResult + + except KeyError: + return redirect(loadLoginPage) + + +def EidtPlugin(request): + try: + userID = request.session['userID'] + + pluginbID = request.GET.get('ID') + wm = WebsiteManager() + return wm.EidtPlugin(request, userID, pluginbID) + except KeyError: + return redirect(loadLoginPage) + + +def deletesPlgin(request): + try: + userID = request.session['userID'] + + result = pluginManager.preWebsiteCreation(request) + + if result != 200: + return result + + wm = WebsiteManager() + coreResult = wm.deletesPlgin(userID, json.loads(request.body)) + + result = pluginManager.postWebsiteCreation(request, coreResult) + if result != 200: + return result + + return coreResult + + except KeyError: + return redirect(loadLoginPage) + + +def Addplugineidt(request): + try: + userID = request.session['userID'] + + result = pluginManager.preWebsiteCreation(request) + + if result != 200: + return result + + wm = WebsiteManager() + coreResult = wm.Addplugineidt(userID, json.loads(request.body)) + + result = pluginManager.postWebsiteCreation(request, coreResult) + if result != 200: + return result + + return coreResult + + except KeyError: + return redirect(loadLoginPage) + + + def modifyWebsite(request): try: userID = request.session['userID'] diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index c86a2f350..ca423bc42 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -12,7 +12,7 @@ django.setup() import json from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging -from websiteFunctions.models import Websites, ChildDomains, GitLogs +from websiteFunctions.models import Websites, ChildDomains, GitLogs, wpplugins from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex @@ -89,12 +89,21 @@ class WebsiteManager: return proc.render() def ConfigurePlugins(self, request=None, userID=None, data=None): + + DataPass ={} currentACL = ACLManager.loadedACL(userID) adminNames = ACLManager.loadAllUsers(userID) packagesName = ACLManager.loadPackages(userID, currentACL) phps = PHPManager.findPHPVersions() + userobj = Administrator.objects.get(pk=userID) - Data = {'packageList': packagesName, "owernList": adminNames, 'phps': phps} + + + + Selectedplugins = wpplugins.objects.filter(owner = userobj) + #data['Selectedplugins'] = wpplugins.objects.filter(ProjectOwner=HostingCompany) + + Data = {'packageList': packagesName, "owernList": adminNames, 'phps': phps, 'Selectedplugins' : Selectedplugins,} proc = httpProc(request, 'websiteFunctions/WPConfigurePlugins.html', Data, 'createWebsite') return proc.render() @@ -137,6 +146,113 @@ class WebsiteManager: return HttpResponse(json_data) + def AddNewpluginAjax(self, userID=None, data=None): + try: + currentACL = ACLManager.loadedACL(userID) + + userobj = Administrator.objects.get(pk=userID) + + config = data['config'] + Name = data['Name'] + # pluginname = data['pluginname'] + # logging.CyberCPLogFileWriter.writeToFile("config ....... %s"%config) + # logging.CyberCPLogFileWriter.writeToFile(" Name ....... %s"%Name) + + + addpl = wpplugins(Name=Name, config=json.dumps(config), owner=userobj) + addpl.save() + + data_ret = {'status': 1} + + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + data_ret = {'status': 0, 'AddNewpluginAjax': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + def EidtPlugin(self,request=None, userID=None, pluginbID=None): + Data ={} + currentACL = ACLManager.loadedACL(userID) + pluginobj = wpplugins.objects.get(pk=pluginbID) + lmo = json.loads(pluginobj.config) + Data['Selectedplugins'] = lmo + Data['pluginbID'] = pluginbID + + + proc = httpProc(request, 'websiteFunctions/WPEidtPlugin.html', + Data, 'createWebsite') + return proc.render() + + + def deletesPlgin(self, userID=None, data=None,): + try: + currentACL = ACLManager.loadedACL(userID) + + userobj = Administrator.objects.get(pk=userID) + pluginname = data['pluginname'] + pluginbBucketID = data['pluginbBucketID'] + # logging.CyberCPLogFileWriter.writeToFile("pluginbID ....... %s" % pluginbBucketID) + # logging.CyberCPLogFileWriter.writeToFile("pluginname ....... %s" % pluginname) + + + + obj = wpplugins.objects.get(pk=pluginbBucketID, owner=userobj) + ab = [] + ab = json.loads(obj.config) + ab.remove(pluginname) + obj.config = json.dumps(ab) + obj.save() + + data_ret = {'status': 1} + + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'status': 0, 'deletesPlgin': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + def Addplugineidt(self, userID=None, data=None,): + try: + currentACL = ACLManager.loadedACL(userID) + + userobj = Administrator.objects.get(pk=userID) + pluginname = data['pluginname'] + pluginbBucketID = data['pluginbBucketID'] + + #logging.CyberCPLogFileWriter.writeToFile("pluginbID ....... %s" % pluginbBucketID) + #logging.CyberCPLogFileWriter.writeToFile("pluginname ....... %s" % pluginname) + + pObj = wpplugins.objects.get(pk=pluginbBucketID, owner=userobj) + listofplugin = json.loads(pObj.config) + try: + index = listofplugin.index(pluginname) + print('index.....%s' % index) + if (index >= 0): + data_ret = {'status': 0, 'deletesPlgin': 0, 'error_message': str('Already Save in your Plugin lis')} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except: + ab = [] + ab = json.loads(pObj.config) + ab.append(pluginname) + pObj.config = json.dumps(ab) + pObj.save() + + + data_ret = {'status': 1} + + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'status': 0, 'deletesPlgin': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) def modifyWebsite(self, request=None, userID=None, data=None):