mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-02 11:26:28 +01:00
Example Plugin
This commit is contained in:
@@ -575,6 +575,19 @@
|
||||
</div><!-- .sidebar-submenu -->
|
||||
</li>
|
||||
|
||||
<li class="serverACL">
|
||||
<a href="#" title="{% trans 'Plugins' %}">
|
||||
<i class="glyph-icon icon-linecons-fire"></i>
|
||||
<span>{% trans "Plugins" %}</span>
|
||||
</a>
|
||||
<div class="sidebar-submenu">
|
||||
|
||||
<ul>
|
||||
</ul>
|
||||
|
||||
</div><!-- .sidebar-submenu -->
|
||||
</li>
|
||||
|
||||
</ul><!-- #sidebar-menu -->
|
||||
|
||||
</div>
|
||||
|
||||
1
examplePlugin/__init__.py
Normal file
1
examplePlugin/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
default_app_config = 'examplePlugin.apps.ExamplepluginConfig'
|
||||
6
examplePlugin/admin.py
Normal file
6
examplePlugin/admin.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
11
examplePlugin/apps.py
Normal file
11
examplePlugin/apps.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ExamplepluginConfig(AppConfig):
|
||||
name = 'examplePlugin'
|
||||
|
||||
def ready(self):
|
||||
import signals
|
||||
0
examplePlugin/migrations/__init__.py
Normal file
0
examplePlugin/migrations/__init__.py
Normal file
6
examplePlugin/models.py
Normal file
6
examplePlugin/models.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
16
examplePlugin/signals.py
Normal file
16
examplePlugin/signals.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from django.dispatch import receiver
|
||||
from django.http import HttpResponse
|
||||
from websiteFunctions.signals import postWebsiteDeletion
|
||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
|
||||
# This plugin respond to an event after CyberPanel core finished deleting a website.
|
||||
# Original request object is passed, body can be accessed with request.body.
|
||||
|
||||
# If any Event handler returns a response object, CyberPanel will stop further processing and returns your response to browser.
|
||||
# To continue processing just return 200 from your events handlers.
|
||||
|
||||
@receiver(postWebsiteDeletion)
|
||||
def rcvr(sender, **kwargs):
|
||||
request = kwargs['request']
|
||||
logging.writeToFile('Hello World from Example Plugin.')
|
||||
return HttpResponse('Hello World from Example Plugin.')
|
||||
6
examplePlugin/tests.py
Normal file
6
examplePlugin/tests.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
examplePlugin/urls.py
Normal file
7
examplePlugin/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.conf.urls import url
|
||||
import views
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
url(r'^$', views.examplePlugin, name='examplePlugin'),
|
||||
]
|
||||
9
examplePlugin/views.py
Normal file
9
examplePlugin/views.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render, HttpResponse
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def examplePlugin(request):
|
||||
return HttpResponse('This is homepage of an example plugin.')
|
||||
0
pluginInstaller/__init__.py
Normal file
0
pluginInstaller/__init__.py
Normal file
BIN
pluginInstaller/examplePlugin.zip
Normal file
BIN
pluginInstaller/examplePlugin.zip
Normal file
Binary file not shown.
253
pluginInstaller/pluginInstaller.py
Normal file
253
pluginInstaller/pluginInstaller.py
Normal file
@@ -0,0 +1,253 @@
|
||||
import subprocess
|
||||
import shlex
|
||||
import argparse
|
||||
import os
|
||||
import tarfile
|
||||
import shutil
|
||||
import time
|
||||
|
||||
class pluginInstaller:
|
||||
installLogPath = "/home/cyberpanel/modSecInstallLog"
|
||||
tempRulesFile = "/home/cyberpanel/tempModSecRules"
|
||||
mirrorPath = "cyberpanel.net"
|
||||
|
||||
@staticmethod
|
||||
def stdOut(message):
|
||||
print("\n\n")
|
||||
print ("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n")
|
||||
print("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + message + "\n")
|
||||
print ("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n")
|
||||
|
||||
### Functions Related to plugin installation.
|
||||
|
||||
@staticmethod
|
||||
def extractPlugin(pluginName):
|
||||
pathToPlugin = pluginName + '.zip'
|
||||
command = 'unzip ' + pathToPlugin + ' -d /usr/local/CyberCP'
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
@staticmethod
|
||||
def upgradingSettingsFile(pluginName):
|
||||
data = open("/usr/local/CyberCP/CyberCP/settings.py", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/CyberCP/settings.py", 'w')
|
||||
|
||||
for items in data:
|
||||
if items.find("'emailPremium',") > -1:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.writelines(" '" + pluginName + "',\n")
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
writeToFile.close()
|
||||
|
||||
@staticmethod
|
||||
def upgradingURLs(pluginName):
|
||||
data = open("/usr/local/CyberCP/CyberCP/urls.py", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/CyberCP/urls.py", 'w')
|
||||
print('hello world')
|
||||
|
||||
for items in data:
|
||||
if items.find("manageservices") > -1:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.writelines(" url(r'^" + pluginName + "/',include('" + pluginName + ".urls')),\n")
|
||||
print('hello world')
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
writeToFile.close()
|
||||
|
||||
@staticmethod
|
||||
def informCyberPanel(pluginName):
|
||||
pluginPath = '/home/cyberpanel/plugins'
|
||||
|
||||
if not os.path.exists(pluginPath):
|
||||
os.mkdir(pluginPath)
|
||||
|
||||
pluginFile = pluginPath + '/' + pluginName
|
||||
command = 'touch ' + pluginFile
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
@staticmethod
|
||||
def addInterfaceLink(pluginName):
|
||||
data = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'w')
|
||||
|
||||
pluginCheck = 0
|
||||
|
||||
for items in data:
|
||||
if items.find('<span>{% trans "Plugins" %}</span>') > -1:
|
||||
pluginCheck = 1
|
||||
elif pluginCheck == 1 and items.find('<ul>'):
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.writelines('<li><a href="{% url \'' + pluginName + '\' %}" title="{% trans \'' + pluginName + '\' %}"><span>{% trans "' + pluginName + '" %}</span></a></li>')
|
||||
pluginCheck = 0
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
writeToFile.close()
|
||||
|
||||
@staticmethod
|
||||
def installPlugin(pluginName):
|
||||
try:
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Extracting plugin.')
|
||||
pluginInstaller.extractPlugin(pluginName)
|
||||
pluginInstaller.stdOut('Plugin extracted.')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Restoring settings file.')
|
||||
pluginInstaller.upgradingSettingsFile(pluginName)
|
||||
pluginInstaller.stdOut('Settings file restored.')
|
||||
|
||||
###
|
||||
|
||||
pluginInstaller.stdOut('Upgrading URLs')
|
||||
pluginInstaller.upgradingURLs(pluginName)
|
||||
pluginInstaller.stdOut('URLs upgraded.')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Informing CyberPanel about plugin.')
|
||||
pluginInstaller.informCyberPanel(pluginName)
|
||||
pluginInstaller.stdOut('CyberPanel core informed about the plugin.')
|
||||
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Adding interface link..')
|
||||
pluginInstaller.addInterfaceLink(pluginName)
|
||||
pluginInstaller.stdOut('Interface link added.')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.restartGunicorn()
|
||||
|
||||
pluginInstaller.stdOut('Plugin successfully installed.')
|
||||
|
||||
except BaseException, msg:
|
||||
pluginInstaller.stdOut(str(msg))
|
||||
|
||||
### Functions Related to plugin installation.
|
||||
|
||||
@staticmethod
|
||||
def removeFiles(pluginName):
|
||||
pluginPath = '/usr/local/CyberCP/' + pluginName
|
||||
if os.path.exists(pluginPath):
|
||||
shutil.rmtree(pluginPath)
|
||||
|
||||
@staticmethod
|
||||
def removeFromSettings(pluginName):
|
||||
data = open("/usr/local/CyberCP/CyberCP/settings.py", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/CyberCP/settings.py", 'w')
|
||||
|
||||
for items in data:
|
||||
if items.find(pluginName) > -1:
|
||||
continue
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.close()
|
||||
|
||||
@staticmethod
|
||||
def removeFromURLs(pluginName):
|
||||
data = open("/usr/local/CyberCP/CyberCP/urls.py", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/CyberCP/urls.py", 'w')
|
||||
|
||||
for items in data:
|
||||
if items.find(pluginName) > -1:
|
||||
continue
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
writeToFile.close()
|
||||
|
||||
@staticmethod
|
||||
def informCyberPanelRemoval(pluginName):
|
||||
pluginPath = '/home/cyberpanel/plugins'
|
||||
pluginFile = pluginPath + '/' + pluginName
|
||||
if os.path.exists(pluginFile):
|
||||
os.remove(pluginFile)
|
||||
|
||||
@staticmethod
|
||||
def removeInterfaceLink(pluginName):
|
||||
data = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'r').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'w')
|
||||
|
||||
for items in data:
|
||||
if items.find(pluginName) > -1 and items.find('<li>') > -1:
|
||||
continue
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.close()
|
||||
|
||||
@staticmethod
|
||||
def removePlugin(pluginName):
|
||||
try:
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Removing files..')
|
||||
pluginInstaller.removeFiles(pluginName)
|
||||
pluginInstaller.stdOut('Files removed..')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Restoring settings file.')
|
||||
pluginInstaller.removeFromSettings(pluginName)
|
||||
pluginInstaller.stdOut('Settings file restored.')
|
||||
|
||||
###
|
||||
|
||||
pluginInstaller.stdOut('Upgrading URLs')
|
||||
pluginInstaller.removeFromURLs(pluginName)
|
||||
pluginInstaller.stdOut('URLs upgraded.')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Informing CyberPanel about plugin removal.')
|
||||
pluginInstaller.informCyberPanelRemoval(pluginName)
|
||||
pluginInstaller.stdOut('CyberPanel core informed about the plugin removal.')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.stdOut('Remove interface link..')
|
||||
pluginInstaller.removeInterfaceLink(pluginName)
|
||||
pluginInstaller.stdOut('Interface link removed.')
|
||||
|
||||
##
|
||||
|
||||
pluginInstaller.restartGunicorn()
|
||||
|
||||
pluginInstaller.stdOut('Plugin successfully removed.')
|
||||
|
||||
except BaseException, msg:
|
||||
pluginInstaller.stdOut(str(msg))
|
||||
|
||||
####
|
||||
|
||||
@staticmethod
|
||||
def restartGunicorn():
|
||||
command = 'systemctl restart gunicorn.socket'
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||
parser.add_argument('function', help='Specify a function to call!')
|
||||
|
||||
parser.add_argument('--pluginName', help='Temporary path to configurations data!')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.function == 'install':
|
||||
pluginInstaller.installPlugin(args.pluginName)
|
||||
else:
|
||||
pluginInstaller.removePlugin(args.pluginName)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1 +0,0 @@
|
||||
default_app_config = 'userManagment.apps.UsermanagmentConfig'
|
||||
@@ -6,6 +6,3 @@ from django.apps import AppConfig
|
||||
|
||||
class UsermanagmentConfig(AppConfig):
|
||||
name = 'userManagment'
|
||||
|
||||
def ready(self):
|
||||
import signals
|
||||
|
||||
@@ -71,11 +71,6 @@ urlpatterns = [
|
||||
## Openbasedir
|
||||
url(r'^changeOpenBasedir$',views.changeOpenBasedir,name="changeOpenBasedir"),
|
||||
|
||||
|
||||
## Application Installer
|
||||
|
||||
url(r'^applicationInstaller$',views.applicationInstaller,name="applicationInstaller"),
|
||||
|
||||
## WP Install
|
||||
|
||||
url(r'^(?P<domain>([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/wordpressInstall$', views.wordpressInstall, name='wordpressInstall'),
|
||||
|
||||
Reference in New Issue
Block a user