Skip to content

Commit 7040b3e

Browse files
committed
complete mautic auto installer
1 parent eb93f51 commit 7040b3e

File tree

9 files changed

+780
-8
lines changed

9 files changed

+780
-8
lines changed

plogical/applicationInstaller.py

Lines changed: 206 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from plogical.installUtilities import installUtilities
1818
import shutil
1919
from plogical.processUtilities import ProcessUtilities
20+
from random import randint
2021

2122
class ApplicationInstaller(multi.Thread):
2223

@@ -39,14 +40,6 @@ def run(self):
3940
self.installWordPress()
4041
elif self.installApp == 'joomla':
4142
self.installJoomla()
42-
elif self.installApp == 'git':
43-
self.setupGit()
44-
elif self.installApp == 'pull':
45-
self.gitPull()
46-
elif self.installApp == 'detach':
47-
self.detachRepo()
48-
elif self.installApp == 'changeBranch':
49-
self.changeBranch()
5043
elif self.installApp == 'prestashop':
5144
self.installPrestaShop()
5245
elif self.installApp == 'magento':
@@ -55,10 +48,215 @@ def run(self):
5548
self.convertDomainToSite()
5649
elif self.installApp == 'updatePackage':
5750
self.updatePackage()
51+
elif self.installApp == 'mautic':
52+
self.installMautic()
5853

5954
except BaseException as msg:
6055
logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
6156

57+
def installMautic(self):
58+
try:
59+
60+
admin = self.extraArgs['admin']
61+
domainName = self.extraArgs['domainName']
62+
home = self.extraArgs['home']
63+
tempStatusPath = self.extraArgs['tempStatusPath']
64+
self.tempStatusPath = tempStatusPath
65+
username = self.extraArgs['username']
66+
password = self.extraArgs['password']
67+
email = self.extraArgs['email']
68+
69+
FNULL = open(os.devnull, 'w')
70+
71+
## Open Status File
72+
73+
statusFile = open(tempStatusPath, 'w')
74+
statusFile.writelines('Setting up paths,0')
75+
statusFile.close()
76+
77+
finalPath = ''
78+
self.permPath = ''
79+
80+
try:
81+
website = ChildDomains.objects.get(domain=domainName)
82+
externalApp = website.master.externalApp
83+
self.masterDomain = website.master.domain
84+
85+
if home == '0':
86+
path = self.extraArgs['path']
87+
finalPath = website.path.rstrip('/') + "/" + path + "/"
88+
else:
89+
finalPath = website.path
90+
91+
if website.master.package.dataBases > website.master.databases_set.all().count():
92+
pass
93+
else:
94+
raise BaseException("Maximum database limit reached for this website.")
95+
96+
statusFile = open(tempStatusPath, 'w')
97+
statusFile.writelines('Setting up Database,20')
98+
statusFile.close()
99+
100+
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master)
101+
self.permPath = website.path
102+
103+
except:
104+
website = Websites.objects.get(domain=domainName)
105+
externalApp = website.externalApp
106+
self.masterDomain = website.domain
107+
108+
if home == '0':
109+
path = self.extraArgs['path']
110+
finalPath = "/home/" + domainName + "/public_html/" + path + "/"
111+
else:
112+
finalPath = "/home/" + domainName + "/public_html/"
113+
114+
if website.package.dataBases > website.databases_set.all().count():
115+
pass
116+
else:
117+
raise BaseException("Maximum database limit reached for this website.")
118+
119+
statusFile = open(tempStatusPath, 'w')
120+
statusFile.writelines('Setting up Database,20')
121+
statusFile.close()
122+
123+
dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website)
124+
self.permPath = '/home/%s/public_html' % (website.domain)
125+
126+
## Security Check
127+
128+
command = 'chmod 755 %s' % (self.permPath)
129+
ProcessUtilities.executioner(command)
130+
131+
if finalPath.find("..") > -1:
132+
raise BaseException("Specified path must be inside virtual host home.")
133+
134+
if not os.path.exists(finalPath):
135+
command = 'mkdir -p ' + finalPath
136+
ProcessUtilities.executioner(command, externalApp)
137+
138+
## checking for directories/files
139+
140+
if self.dataLossCheck(finalPath, tempStatusPath) == 0:
141+
raise BaseException('Directory is not empty.')
142+
143+
####
144+
145+
statusFile = open(tempStatusPath, 'w')
146+
statusFile.writelines('Downloading Mautic Core,30')
147+
statusFile.close()
148+
149+
command = "wget https://github.com/mautic/mautic/releases/download/3.1.0/3.1.0.zip"
150+
ProcessUtilities.outputExecutioner(command, externalApp, None, finalPath)
151+
152+
statusFile = open(tempStatusPath, 'w')
153+
statusFile.writelines('Extracting Mautic Core,50')
154+
statusFile.close()
155+
156+
command = "unzip 3.1.0.zip"
157+
ProcessUtilities.outputExecutioner(command, externalApp, None, finalPath)
158+
159+
##
160+
161+
statusFile = open(tempStatusPath, 'w')
162+
statusFile.writelines('Running Mautic installer,70')
163+
statusFile.close()
164+
165+
if home == '0':
166+
path = self.extraArgs['path']
167+
finalURL = domainName + '/' + path
168+
else:
169+
finalURL = domainName
170+
171+
localDB = "/home/cyberpanel/" + str(randint(1000, 9999))
172+
173+
localDBContent = """<?php
174+
// Example local.php to test install (to adapt of course)
175+
$parameters = array(
176+
// Do not set db_driver and mailer_from_name as they are used to assume Mautic is installed
177+
'db_host' => 'localhost',
178+
'db_table_prefix' => null,
179+
'db_port' => 3306,
180+
'db_name' => '%s',
181+
'db_user' => '%s',
182+
'db_password' => '%s',
183+
'db_backup_tables' => true,
184+
'db_backup_prefix' => 'bak_',
185+
'admin_email' => '%s',
186+
'admin_password' => '%s',
187+
'mailer_transport' => null,
188+
'mailer_host' => null,
189+
'mailer_port' => null,
190+
'mailer_user' => null,
191+
'mailer_password' => null,
192+
'mailer_api_key' => null,
193+
'mailer_encryption' => null,
194+
'mailer_auth_mode' => null,
195+
);""" % (dbName, dbUser, dbPassword, email, password)
196+
197+
writeToFile = open(localDB, 'w')
198+
writeToFile.write(localDBContent)
199+
writeToFile.close()
200+
201+
command = 'rm -rf %s/app/config/local.php' % (finalPath)
202+
ProcessUtilities.executioner(command)
203+
204+
command = 'mv %s %s/app/config/local.php' % (localDB, finalPath)
205+
ProcessUtilities.executioner(command)
206+
207+
command = "/usr/local/lsws/lsphp72/bin/php bin/console mautic:install http://%s" % (finalURL)
208+
result = ProcessUtilities.outputExecutioner(command, 'root', None, finalPath)
209+
210+
if result.find('Install complete') == -1:
211+
raise BaseException(result)
212+
213+
214+
##
215+
216+
from filemanager.filemanager import FileManager
217+
218+
fm = FileManager(None, None)
219+
fm.fixPermissions(self.masterDomain)
220+
221+
installUtilities.reStartLiteSpeedSocket()
222+
223+
statusFile = open(tempStatusPath, 'w')
224+
statusFile.writelines("Successfully Installed. [200]")
225+
statusFile.close()
226+
return 0
227+
228+
229+
except BaseException as msg:
230+
# remove the downloaded files
231+
FNULL = open(os.devnull, 'w')
232+
233+
homeDir = "/home/" + domainName + "/public_html"
234+
235+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
236+
groupName = 'nobody'
237+
else:
238+
groupName = 'nogroup'
239+
240+
if not os.path.exists(homeDir):
241+
command = "chown " + externalApp + ":" + groupName + " " + homeDir
242+
ProcessUtilities.executioner(command, externalApp)
243+
244+
try:
245+
mysqlUtilities.deleteDatabase(dbName, dbUser)
246+
db = Databases.objects.get(dbName=dbName)
247+
db.delete()
248+
except:
249+
pass
250+
251+
command = 'chmod 750 %s' % (self.permPath)
252+
ProcessUtilities.executioner(command)
253+
254+
255+
statusFile = open(self.tempStatusPath, 'w')
256+
statusFile.writelines(str(msg) + " [404]")
257+
statusFile.close()
258+
return 0
259+
62260
def updatePackage(self):
63261
try:
64262

static/images/icons/mautic.png

21.4 KB
Loading

0 commit comments

Comments
 (0)