From 471637f62ae96f30a8e669d0056843284e694b3f Mon Sep 17 00:00:00 2001 From: Hassan Hashmi <75794688+hassanhashmey@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:18:49 -0700 Subject: [PATCH] scanwpsite --- .../websiteFunctions/websiteFunctions.js | 59 +++++++++++++++++++ .../websiteFunctions/WPsitesList.html | 38 +++++++++++- websiteFunctions/urls.py | 1 + websiteFunctions/views.py | 21 +++++++ websiteFunctions/website.py | 44 ++++++++++++++ 5 files changed, 162 insertions(+), 1 deletion(-) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 7542b08a8..3fea84603 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -2640,6 +2640,65 @@ app.controller('listWebsites', function ($scope, $http) { }; + $scope.ScanWordpressSite = function () { + + $('#cyberPanelLoading').show(); + + + var url = "/websites/ScanWordpressSite"; + + var data = { + + } + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $('#cyberPanelLoading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#cyberPanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; + }); diff --git a/websiteFunctions/templates/websiteFunctions/WPsitesList.html b/websiteFunctions/templates/websiteFunctions/WPsitesList.html index 47d60824b..5fd531d2e 100644 --- a/websiteFunctions/templates/websiteFunctions/WPsitesList.html +++ b/websiteFunctions/templates/websiteFunctions/WPsitesList.html @@ -90,8 +90,12 @@

{% trans "List WordPress Websites" %} {% trans "Create WordPress Website" %} + {% trans "Scan WordPress " %}

- +

{% trans "On this page you can launch, list, modify and delete Wordpress Sites from your server." %}

@@ -190,6 +194,38 @@ + + + + + {% endblock %} diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 6a97fe0df..64ace1aa8 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -53,6 +53,7 @@ urlpatterns = [ url(r'^SaveBackupSchedule', views.SaveBackupSchedule, name='SaveBackupSchedule'), url(r'^AddWPsiteforRemoteBackup', views.AddWPsiteforRemoteBackup, name='AddWPsiteforRemoteBackup'), url(r'^UpdateRemoteschedules', views.UpdateRemoteschedules, name='UpdateRemoteschedules'), + url(r'^ScanWordpressSite', views.ScanWordpressSite, name='ScanWordpressSite'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 7c93504c0..a9fec9bbf 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -523,6 +523,27 @@ def UpdateRemoteschedules(request): return redirect(loadLoginPage) +def ScanWordpressSite(request): + try: + userID = request.session['userID'] + + result = pluginManager.preWebsiteCreation(request) + if result != 200: + return result + + wm = WebsiteManager() + coreResult = wm.ScanWordpressSite(userID, json.loads(request.body)) + + result = pluginManager.postWebsiteCreation(request, coreResult) + if result != 200: + return result + + return coreResult + + except KeyError: + return redirect(loadLoginPage) + + def installwpcore(request): try: userID = request.session['userID'] diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index ac3951d40..28f2ed8db 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -1353,6 +1353,50 @@ class WebsiteManager: return HttpResponse(json_data) + def ScanWordpressSite(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + allweb = Websites.objects.all() + + childdomain = ChildDomains.objects.all() + + for web in allweb: + webpath = "/home/%s/public_html" % web.domain + command = "cat %s/wp-config.php" % webpath + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 1: + wpobj = WPSites(owner=web, title=web.domain, path=webpath, FinalURL=web.domain, + AutoUpdates="Enabled", PluginUpdates="Enabled", + ThemeUpdates="Enabled", ) + wpobj.save() + + for chlid in childdomain: + command = "cat %s/wp-config.php"%chlid.path + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 1: + wpobj = WPSites(owner=chlid.master, title=chlid.domain, path=chlid.path, FinalURL=chlid.domain, + AutoUpdates="Enabled", PluginUpdates="Enabled", + ThemeUpdates="Enabled", ) + wpobj.save() + + + + + data_ret = {'status': 1, 'error_message': 'None',} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def installwpcore(self, userID=None, data=None): try: