HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/plogical/__pycache__/applicationInstaller.cpython-310.pyc
o

��h3��@sbddlZddlZddlZddlZddlZddlZddlmZej�	d�ej
�dd�ddlZe�
�ddlZddlmZddlmZddlmZdd	lmZddlZdd
lmZddlZddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2Z2Gdd�dej3�Z4dd�Z5e6dkr�e5�dSdS)�N)�StringIOz/usr/local/CyberCP�DJANGO_SETTINGS_MODULEzCyberCP.settings)�ApacheVhost)�
Administrator��
PHPManager)�
ACLManager)�CyberCPLogFileWriter)�ChildDomains�Websites�WPSites�	WPStaging�	wpplugins�
WPSitesBackup�RemoteBackupConfig�NormalBackupDests)�randomPassword)�mysqlUtilities)�	Databases��installUtilities)�ProcessUtilities)�randintc@s>eZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
edd
��Zdd�Z
dd�Zdd�Zdd�Zdd�ZdMdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!d9d:�Z"d;d<�Z#d=d>�Z$d?d@�Z%dAdB�Z&dCdD�Z'dEdF�Z(dGdH�Z)dIdJ�Z*dKdL�Z+dS)N�ApplicationInstaller�	localhostr�3306z6.0.3z1.7.8.3cCsFtj�|�||_||_|dkrz|jd|_WnY|j|_dS)N�tempStatusPath)�multi�Thread�__init__�
installApp�	extraArgsr�data)�selfr r!�r$�3/usr/local/CyberCP/plogical/applicationInstaller.pyr)szApplicationInstaller.__init__c
Cs
z�|jdkr
|��WdS|jdkr|��WdS|jdkr%|��WdS|jdkr1|��WdS|jdkr=|��WdS|jdkrI|��WdS|jdkrU|��WdS|jdkra|��WdS|jd	krm|�	�WdS|jd
kry|�
�WdS|jdkr�|��WdS|jdkr�|��WdS|jd
kr�|�
�WdS|jdkr�|��WdS|jdkr�|��WdS|jdkr�|��WdS|jdkr�|��WdS|jdkr�|��WdS|jdkr�|��WdSWdSt�y}zt�t|�d�WYd}~dSd}~ww)N�	wordpress�joomla�
prestashop�magento�convertDomainToSite�
updatePackage�mautic�wordpressInstallNew�
UpdateWPTheme�UpdateWPPlugin�DeleteThemes�
DeletePlugins�ChangeStatusThemes�CreateStagingNow�DeploytoProduction�WPCreateBackup�RestoreWPbackupNow�	UpgradeCP�StartOCRestorez [ApplicationInstaller.run])r �installWordPress�
installJoomla�installPrestaShop�installMagentor*r+�
installMauticr-r.r/r0r1r2r3r4r5r6r7r8�
BaseException�logging�writeToFile�str)r#�msgr$r$r%�run5sX


















� ��zApplicationInstaller.runcCs d|jd�d�}t�|�dS)NzU/usr/local/CyberPanel/bin/python /usr/local/CyberCP/plogical/upgrade.py "SoftUpgrade,�branchSelect�")r"r�executioner)r#�commandr$r$r%r7bszApplicationInstaller.UpgradeCPcCs`tj�d�rt�d�tj�d�s.d}t�|dd�d}t�|dd�d}t�|dd�dSdS)Nzcomposer.shz/usr/bin/composerz&wget https://cyberpanel.sh/composer.sh�rootTzchmod +x composer.shz
./composer.sh)�os�path�exists�removerrF)rGr$r$r%�
setupComposerfs
�z"ApplicationInstaller.setupComposercCs8d}t�|�}|�d�dkrdSt��}t��rZd|�d|�d�}t�|dd	�d
|�d�}t�|dd	�d|�d
�}t�|dd	�d}t�|dd	�d|�d�}t�|dd	�dSd|�d|�d�}t�|dd	�d
|�d�}t�|dd	�d|�d�}t�|dd	�d}t�|dd	�d|�d�}t�|dd	�dS)N�npmz
npm <command>����zwget https://nodejs.org/dist/z/node-z-linux-arm64.tar.xzrHTz
tar -xf node-z-linux-arm64.tar.xz zcp node-z#-linux-arm64/bin/node /usr/bin/nodez.curl -qL https://www.npmjs.com/install.sh | shzrm -rf node-z
-linux-arm64*z-linux-x64.tar.xzz!-linux-x64/bin/node /usr/bin/nodez-linux-x64*)r�outputExecutioner�find�!fetch_latest_lts_version_for_noder�ISARMrF)r#rG�result�nodeVr$r$r%�
InstallNodeJSvs8
�z"ApplicationInstaller.InstallNodeJSc Cs�z�|jd}|jd}|jd}|jd}||_|jd}|jd}|jd}t|d�}|�d	�|��|��d
dlm}	t�	�d
dl
m}
d
|�d�}d}tj
�|�skt|d�}|�d�|��|
�d�tj|d}
tj
�|
�r�t��tjks�t��tjkr�d}nd}t�|�ttjd�}d}d|_zYtjj|d�}|jj}|jj|_|dkr�|jd}|j
� d�d|d}n|j
}|jj!j"|jj#�$��%�kr�nt&d��t|d�}|�d�|��|�'||j�\}}}|j
|_Wn[t(jj|d�}|j}|j|_|dk�r|jd}d|d|d}nd|d}|j!j"|j#�$��%�k�r.nt&d��t|d�}|�d�|��|�'||�\}}}d|j|_Y|�)d�d k�r\t&d!��tj
�|��smd"|}t�||�d#|�d$�}t�||�d#|�d%�}t�||�|�*|||�d
k�r�t&d&��t|d�}|�d'�|��d(}d)}d*|�d+|��}t�+||d�d,|�d-|��}t�+||d�d.|��}t�+||d�t|d�}|�d/�|��t|d�}|�d0�|��|dk�r�|jd}|d|}n|}|�d1|�d2|�d3|�d4|�d5|�d6|�d7|�d8�}t�+||d|�}|�)d9�d k�r,t&|��|�d:�}t�+||d|�t�,�tj-k�r^|�d;�}d<|��}t�||d=�d>|��}t�||d=�d?tj.��}t�|�t/�0�t1�2d@�d?tj.��}t�|�t|d�}|�dA�|��Wd
St&�y}zlttjd�}d|dB}t��tjk�s�t��tjk�r�dC}ndD}tj
�|��s�dE|dF|d+|}t�||�zt3�4||�t5jj|dG�}|�6�WnYt|jd�}|�t7|�dH�|��WYd}~d
Sd}~ww)IN�admin�
domainName�homer�username�password�email�w�Setting up paths,0r)�Upgrade��phpUtilities�/usr/local/lsws/conf/vhosts/�/vhost.confz/usr/local/lsws/lsphp82/bin/phpz#PHP 8.2 missing installing now..,20�82�.confzBdnf install php7.?-bcmath php7.?-imap php8.?-bcmath php8.?-imap -yzeDEBIAN_FRONTEND=noninteractive apt-get install php7.?-bcmath php7.?-imap php8.?-bcmath php8.?-imap -y���domain�0rJ�/�0Maximum database limit reached for this website.�Setting up Database,20�/home/�
/public_html/�/home/%s/public_html�..rO�0Specified path must be inside virtual host home.�	mkdir -p �rm -rf �*z.*�Directory is not empty.zDownloading Mautic Core,30zBhttps://github.com/mautic/mautic/releases/download/6.0.3/6.0.3.zipz/tmp/mautic-6.0.3.zipzwget -O � z	unzip -q z -d �rm -f zExtracting Mautic Core,50zRunning Mautic installer,70z8 -d memory_limit=256M bin/console mautic:install http://zK --db_driver='pdo_mysql' --db_host='localhost' --db_port='3306' --db_name='z
' --db_user='z' --db_password='za' --db_backup_tables='false' --admin_firstname='Admin' --admin_lastname='User' --admin_username='z' --admin_email='z' --admin_password='z	' --forcezInstall completez9 -d memory_limit=256M bin/console  mautic:assets:generatez	.htaccessz7sed -i '/# Fallback for Apache < 2.4/,/<\/IfModule>/d' Tz)sed -i '/# Apache 2.4+/,/<\/IfModule>/d' zsystemctl restart ��Successfully Installed. [200]�/public_html�nobody�nogroup�chown �:��dbName� [404])8r!r�open�
writelines�closerW�plogical.upgrader`rrM�plogical.phpUtilitiesrbrIrJrK�InstallSaidPHPr�configBasePathr�decideDistro�cent8�centosrF�devnull�permPathr
�objects�get�master�externalAppri�masterDomain�rstrip�package�	dataBases�
databases_set�all�countr>�
dbCreationrrR�
dataLossCheckrQ�decideServer�ent�serviceNamer�reStartLiteSpeedSocket�time�sleepr�deleteDatabaser�deleterA) r#rXrYrZrr[r\r]�
statusFiler`rb�vhFile�phpPath�
finalConfPathrG�FNULL�	finalPath�websiter�rJr��dbUser�
dbPassword�	mauticUrl�	mauticZip�finalURLrU�htAccessPathrB�homeDir�	groupName�dbr$r$r%r=�s





























4








 ��z"ApplicationInstaller.installMauticc
CsVz�|jd}ddlm}t|jd�}t��tjks t��tjkrN|dkr=d}|�	t�
|��|��d}|�	t�
|��nd|}|�	t�
|��|��n)t��tj
ks\t��tjkrw|dkrkd	}|�	t�
|��nd
|}|�	t�
|��|��t�|jdd�WdSty�}zddlm}t�|jd
t|�d�WYd}~dSd}~ww)Nr�r)�ServerStatusUtil�ar�z0DEBIAN_FRONTEND=noninteractive apt-get update -yzapt-get upgrade -yz$apt-get install --only-upgrade %s -yz
yum update -yzyum update %s -yz'Package(s) upgraded successfully. [200]rPzFailed. Error: %s. [404])r!�serverStatus.serverStatusUtilr�r��lswsInstallStatusPathrr��ubuntu�ubuntu20�writerQ�flushr�r�r�r?�statusWriterr>rA)r#r�r��frGrBr$r$r%r+�s>


���z"ApplicationInstaller.updatePackagec
Cs|�zddlm}ddl}ddl}|jd}t|jd�}|�d�|��|�	|j
�}|ddksH|ddksH|ddksH|d	dksH|d
dkrLtd��|d}tj
j|d�}|j}	|�}
|
�|jd
d|i�|�d�t|jd�}|�d�|��|
�|jd
|�}|�	|j�d��}	t�d|d�}
|
�d�dkr�n2|
�d�dkr�t|jd�}|�|
dd�|��WdSt|jd�}|�|
�|��|�d�q�t|jd�}|�d�|��d|}t�|�d|	|f}t�|�ddlm}|dd�}|�|�t|jd�}|�d�|��WdSt�y=}zt|jd�}|�t|�d �|��WYd}~dSd}~ww)!Nr��WebsiteManager�requestr^zDeleting domain as child..,20r�rY�
adminEmail�phpSelection�websiteOwnerzPlease provide all values.rh�userID�websiteName�zCreating domain as website..,40zutf-8T�cat r�[200]rO�[404]�
currentStatusz  [404]rPzMoving data..,80zrm -rf  /home/%s/public_htmlzmv %s /home/%s/public_html��FileManagerzSuccessfully converted. [200]r�)�websiteFunctions.websiter��jsonr�r!r�rr�r��loads�bodyr>r
r�r�rJ�submitDomainDeletion�sessionr��submitWebsiteCreation�content�decoderrQrRrF�filemanager.filemanagerr��fixPermissionsrA)r#r�r�r�r�r�r"rY�childDomainrJ�wm�resp�respData�respDataStatusrGr��fmrBr$r$r%r*�sp

$



�





��z(ApplicationInstaller.convertDomainToSitec
Cs\zd}t�|�d}t�|�WdSty-}zt�t|�d�WYd}~dSd}~ww)Nz]wget -O /usr/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharzchmod +x /usr/bin/wpz$ [ApplicationInstaller.installWPCLI])rrFr>r?r@rA�r#rGrBr$r$r%�installWPCLIs
 ��z!ApplicationInstaller.installWPCLINcCsV|dkrt�|�}t|�dkrdSdSd|}t�||d��d�}t|�dkr)dSdS)NryrPrz
ls %s | wc -lT�
)rI�listdir�lenrrQr��int)r#r�r�user�dirFilesrGrUr$r$r%r�s
z"ApplicationInstaller.dataLossCheckc
Csnztj�d�rd}t�|�WdSd}t�|�WdSty6}zt�t|�d�WYd}~dSd}~ww)Nz/etc/lsb-releasezapt -y install gitzyum install git -yz" [ApplicationInstaller.installGit])	rIrJrKrrFr>r?r@rAr�r$r$r%�
installGit+s ��zApplicationInstaller.installGitc
Cs<d}zddl}|�t|d����}|d}|t_dt_|dt_WnYz[t�	�}|}t�	�}	t
jj|d��
�sCt
jj|d��
�rTt|d	�}
|
�d
�|
��WdSt�|||	�}|dkr`nt|d	�}
|
�d�|
��WdSt
|||d�}|��|||	fWSty�}
zt�t|
�d
�WYd}
~
dSd}
~
ww)Nz/etc/cyberpanel/mysqlPasswordr�r�	mysqlhostrP�	mysqlportr�)r�r^z-This database or user is already taken. [404]z"Not able to create database. [404])r�r�r�z [ApplicationInstallerdbCreation])r�r�r��readr�	LOCALHOST�REMOTE�PORTr�
generate_passrr��filterrKr�r�r�createDatabase�saver>r?r@rA)r#rr��passFiler��jsonDatar�r�r�r�r�rUr�rBr$r$r%r�9sR��
�
� ��zApplicationInstaller.dbCreationc!
Cs�
�z�t�d|j���|jd}|jd}|jd}||_|jd}|jd}|jd}|jd}t�d	|�d
|�d|���ttjd�}zd
}	t�|	�}
|
�	d�dksX|�
�Wntjyg|�
�Ynwt|d�}|�
d�|��ddlm}d|�d�}
d|jd}|d|
}t�|�d}	t�|	�d}	t�|	�ddlm}d|�d�}z|�|�}Wnd}Ytj�|�s�t|d�}|�
d�|��|�d�d}d|_z[tjj|d�}|jj}|jj|_ |d k�r|jd!}|j�!d"�d"|d"}n|j}|jj"j#|jj$�%��&�k�rnt'd#��t|d�}|�
d$�|��|�(||j�\}}}|j|_Wnzt'�y�}zmt)jj|d�}|j}|j|_ |d k�ra|jd!}d%|d&|d"}nd%|d&}|�d'�}d(|��}	t�|	|�|j"j#|j$�%��&�k�r�nt'd#��t|d�}|�
d$�|��|�(||�\}}}d)|j|_WYd}~nd}~wwd*|d'}	t�|	|�d}tj�|��s�ddlm}|�d�tj�|��s�|}|�	d+�dk�r�t'd,��d-|}	t�|	|�|�*|||�dk�r�t'd.��t|d�}|�
d/�|��z|�d0|�d1|jd2��}	Wn	d3|��}	Yt�|	|�}tj�tj+��r9t�t,|��|�	d4�dk�rEt'|��t|d�}|�
d5�|��|�d6|�d7|�d8|�d9t-j.�d:t-j/�d;|��
}	t�|	|�}tj�tj+��r�t�t,|��|�	d4�dk�r�t'|��|d k�r�|jd!}|d"|}n|}|�d<|�d=|�d>|�d?|�d@|�dA|��
}	t�|	|�}tj�tj+��r�t�t,|��|�	d4�dk�r�t'|��t|d�}|�
dB�|��|�dC�|}	t�|	|�}tj�tj+��rt�t,|��|�	d4�dk�rt'|��t|d�}|�
dD�|��|�dE�|}	t�|	|�}tj�tj+��r6t�t,|��|�	d4�dk�rBt'|��|�dF�|}	t�|	|�}tj�tj+��r^t�t,|��|�	d4�dk�rjt'|��|�dG�|}	t�|	|�}tj�tj+��r�t�t,|��|�	d4�dk�r�t'|��ze|jdH�r�|jdHdIk�r�|�dJ�|}	t�|	|�}|�	d4�dk�r�t'|��n;|jdHdKk�r�|�dL�|}	t�|	|�}|�	d4�dk�r�t'|��n|�dM�|}	t�|	|�}|�	d4�dk�r�t'|��WnYz�|jdNdOk�r@dP|}	t�|	|�}|�	d4�dk�rt'|��t|d�}|�
dQ�|��dR|}	t�|	|�}|�	d4�dk�r?t'|��nB|jdNdSk�r�dT|}	t�|	|�}|�	d4�dk�r^t'|��t|d�}|�
dU�|��dV|}	t�|	|�}|�	d4�dk�r�t'|��WnYzG|jdWdXk�r�|jdY}t0t1|��D]1}|�dZ�|||f}	t�|	|�}|�	d4�dk�r�t'|��|�d[�|||f}	t�|	|�}�q�Wnt'�y�}zt�d\t,|��WYd}~nd}~wwt|d�}|�
d]�|��WdSt'�yC}z:tj�tj+��s%zt2�3||�t4jj|d^�} | �5�WnYt|jd�}|�
t,|�d_�|��WYd}~dSd}~ww)`Nz)installWordPress started with extraArgs: rYrZr�	blogTitle�	adminUser�
adminPasswordr�zinstallWordPress - domain: z, home: z
, status: r^z	wp --infozWP-CLI root dir:rOr_r��virtualHostUtilitiesrcrdz/usr/local/CyberCP/bin/python z!/plogical/virtualHostUtilities.pyz) changePHP --phpVersion 'PHP 8.3' --path zlsed -i.bak 's/^memory_limit = .*/memory_limit = 256M/' /usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.inizZsed -i.bak 's/^memory_limit = .*/memory_limit = 256M/' /usr/local/lsws/lsphp83/etc/php.iniraz/usr/local/lsws/lsphp83/bin/php�#PHP 8.3 missing installing now..,20�83rgrhrjrJrkrlrmrnro�
index.htmlrxrprtrqrrrsrvzDownloading WordPress Core,30zD -d error_reporting=0 /usr/bin/wp core download --allow-root --path=� --version=�	WPVersionzc/usr/local/lsws/lsphp83/bin/php -d error_reporting=0 /usr/bin/wp core download --allow-root --path=zSuccess:�Configuring the installation,40�7 -d error_reporting=0 /usr/bin/wp core config --dbname=�
 --dbuser=�
 --dbpass=�
 --dbhost=rz --dbprefix=wp_ --path=z= -d error_reporting=0 /usr/bin/wp core install --url="http://z" --title="z" --admin_user="z" --admin_password="z" --admin_email="z	" --path=zInstalling LSCache Plugin,80zU -d error_reporting=0 /usr/bin/wp plugin install litespeed-cache --allow-root --path=zActivating LSCache Plugin,90zV -d error_reporting=0 /usr/bin/wp plugin activate litespeed-cache --allow-root --path=z� -d error_reporting=0 /usr/bin/wp plugin install https://github.com/usmannasir/CyberSMTP/archive/refs/heads/main.zip --allow-root --path=zP -d error_reporting=0 /usr/bin/wp plugin activate CyberSMTP --allow-root --path=�updates�Disabledza -d error_reporting=0 /usr/bin/wp config set WP_AUTO_UPDATE_CORE false --raw --allow-root --path=zMinor and Security Updatesz[ -d error_reporting=0 /usr/bin/wp config set WP_AUTO_UPDATE_CORE minor --allow-root --path=z` -d error_reporting=0 /usr/bin/wp config set WP_AUTO_UPDATE_CORE true --raw --allow-root --path=�appsSetz$WordPress + LSCache + Classic Editorz5wp plugin install classic-editor --allow-root --path=z#Activating Classic Editor Plugin,90z6wp plugin activate classic-editor --allow-root --path=z!WordPress + LSCache + WooCommercez2wp plugin install woocommerce --allow-root --path=z Activating WooCommerce Plugin,90z3wp plugin activate woocommerce --allow-root --path=�SavedPluginsT�AllPluginsListzJ -d error_reporting=0 /usr/bin/wp plugin install %s --allow-root --path=%szK -d error_reporting=0 /usr/bin/wp plugin activate %s --allow-root --path=%sz!Error in istall plugin bucket: %srzr�r�)6r?r@r!rr�rIr�rrQrRr��
subprocess�CalledProcessErrorr�r��plogical.virtualHostUtilitiesr��
cyberPanelrFr�rb�GetPHPVersionFromFilerJrKr�r�r
r�r�r�r�rir�r�r�r�r�r�r�r>r�rr��	debugPathrArr�r��ranger�rr�rr�)!r#rYrZrr�r�r�r�r�rG�outoutr�r��completePathToConfigFile�execPathrbr�r�r�r�r�rJr�r�r�rB�	IndexFile�FinalPHPPathrUr��
AllPluginList�ir�r$r$r%r9hs�







��


















��




0

,



���

�

�
�����

��z%ApplicationInstaller.installWordPressc
Csd�z=|jd}|jd}|jd}|jd}|jd}|jd}|jd}|jd}|jd	}	|jd
}
|
|_ttjd�}t|
d�}|�d�|��d
}
d
|_z[tj	j
|d�}|jj}|jj
|_|dkrw|jd}|j�d�d|d}
n|jd}
|jjj|jj����kr�ntd��t|
d�}|�d�|��|�|
|j�\}}}|j|_WnYtj	j
|d�}|j}|j
|_|dkr�|jd}d|d|d}
nd|d}
|jj|j����kr�ntd��t|
d�}|�d�|��|�|
|�\}}}d|j
|_Y|
�d�dk�rtd��d|
}t�||�|�|
|
|�dk�r)td��d|
d}t�||�ddlm}d |�d!�}|�||�}tj� |��sat|
d�}|�d"�|��|�!d#�t"j#|d$}tj� |��s�t�$�tj%k�r�t|jd�}|�d%�|��WdSt|
d�}|�d&�|��t�&�}d'|�d(|�d)|
��}t�||�d*|
|f|
}t�||�d+|
|
}t�||�t|
d�}|�d,�|��|dk�r�|jd}|}n|}t|
d�}|�d-�|��|�d.�|
d/|d0|d1|d2|d3|d4|d5|d6|d7|	}t�||�d|
d8}t�||�t|
d�}|�d9�|��WdSt�y�}zfd|d:}t�'�tj(k�s]t�'�tj)k�r`d;}nd<}tj� |��s{d=|d>|d.|}t�||�zt*�+||�t,j	j
|d?�}|�-�WnYt|jd�}|�t.|�d@�|��WYd}~dSd}~ww)ANrXrYrZ�shopName�	firstName�lastName�databasePrefixr]r\rr^r_rgrhrjrJrkrlrmrnrorprqrOrrrsrrvrtr�rarcrdr�r�rfz�Your server is currently using OpenLiteSpeed, please switch your website to use Apache otherwise Prestashop installation will not work. [404]z/Downloading and extracting PrestaShop Core..,30z@wget https://github.com/PrestaShop/PrestaShop/releases/download/z/prestashop_z.zip -P z unzip -o %sprestashop_%s.zip -d zunzip -o %sprestashop.zip -d r�z*Installing and configuring PrestaShop..,60rwzinstall/index_cli.php --domain=z! --db_server=localhost --db_name=z --db_user=z --db_password=z	 --name='z' --firstname=z --lastname=z	 --email=z --password=�installrzr{r|r}�	chown -R rr�r�)/r!rr�rIr�r�r�r�r
r�r�r�r�rir�rJr�r�r�r�r�r�r>r�rrRrrFr�r�rbrrKr�rr�r��OLS�fetch_latest_prestashop_versionr�r�r�rr�rr�rA)r#rXrYrZrrrrr]r\rr�r�r�r�r�rJr�r�r�rGrbr�r�r��pVersionr�rBr�r�r�r$r$r%r;�s0































����������������

 ��z&ApplicationInstaller.installPrestaShopcCsdS)Nr):r!rr
r�r�r�r�rir�rJr�r�r�r�r�r�r>r�r�r�r�r�rrrQrRrFr��getpass�getuserrr��hashlib�md5�encode�	hexdigest�MySQLdb.cursors�cursors�MySQLdb�connect�SSCursor�cursor�executer?r@rArIrLr�r�r�rr��printrr�rr�)r#rYr\�prefixrZ�siteNamerr�r�r�rJr�r�r�r�r�rGrUr�
joomlaPath�salt�
password_hashr&�mysql�connr*rBr�r�r�r�r$r$r%r:�sz"ApplicationInstaller.installJoomlacCs��z�t�d|j���t�|jdd�|jdr~t�|jdd�ddl}ddlm}dttd	d
��}d�	|�
d|jd
��dd�ttd	d
��}|�|jd
|jdd|dddddd|d�t|d��
�}|�d�dkr~t�|jdd|�WdSt�|jdd�t�d�|jd}|jd
|jd<dttd	d
��|jd<|jd|jd<|jd|jd<|jd|jd <|jd|jd!<t�d"|jd���t�d#|jd�d$|jd!���|��t�d%�t|jdd��
�}|�d�dk�r||jd<td&|��||jd<t�|jdd'�zJdd(lm}dd)lm}ddl}	|jj|jd
d*�}
|jd =|jd=|jd=|jd
=|jd!=|jd=|jd=|jd+=||
|	�|j�d,�}|��WnYt��tjk�stt��tjk�rwd-}nd.}t|d��
�}
|
�d/�dk�r�t|d0�}|�d1�|��WdSWdSt�y�}z,|jd
|jd2<dd3l m!}|�}|�"d|j�t�|jdd4t|��WYd}~dSd}~ww)5Nz#DeployWordPress started with args: rz$DeployWordPress function started..,5�
createSitezCreating this application..,10rr��/home/cyberpanel/���'rgz	[a-zA-Z]+rir�r]zPHP 8.1rPrX�Defaultr�r�rOz-Failed to create application. Error: %s [404]zInstalling WordPress.,50z'About to call installWordPress functionrY�titler��userNamer�r\r�r�z*Calling installWordPress with domainName: zAdmin user: z	, email: zinstallWordPress call completedz,Failed to install WordPress. Error: %s [404]zCompleted [200].)�
WPDeployments)rrhr)�owner�configz/var/spool/cron/rootz/var/spool/cron/crontabs/rootzWPAutoUpdates.pyr�zV0 12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/WPAutoUpdates.py
r�r�z	%s [404].)#r?r@r!r��rer
r�rAr�join�findall�createVirtualHostr�r�rRr9r>�cloudAPI.modelsr;�websiteFunctions.modelsrr�r�r��dumpsr�rr�r�r�r�r�r�r��submitWebsiteDeletion)r#r>r�rr�rU�currentTempr;rr�r��wpDeploy�
localCronPath�cronDatar@rBr�r�r$r$r%�DeployWordPress)s�
.��

"


 
��(��z$ApplicationInstaller.DeployWordPressc!
Cs��z_|jd}|jd}|jd}|jd}|jd}|jd}|jd}|jd}|jd	}	|jd
}
|jd}||_ttjd�}t|d�}
|
�d
�|
��d}d|_z[tj	j
|d�}|jj}|jj
|_|dkr||jd}|j�d�d|d}n|jd}|jjj|jj����kr�ntd��t|d�}
|
�d�|
��|�||j�\}}}|j|_WnYtj	j
|d�}|j}|j
|_|dkr�|jd}d|d|d}nd|d}|jj|j����kr�ntd��t|d�}
|
�d�|
��|�||�\}}}d|j
|_Yd|j}t�|�|�d�dk�r td��tj�|��s1d|}t�||�|�||�dk�r>td��t|d�}
|
�d�|
��d |	|f}t�||�t|d�}
|
�d!�|
��|dk�rs|jd}|}n|}t|d�}
|
�d"�|
��d#|d$|d%|}t�||�d&|}t�||�d&|}t�||�d'||f}t�||�d(|
|||f}d)||||||f}d*|d+}t�||�t|d�}
|
�d,�|
��z:ddlm}ddl }|j!d-||d.|j"d/�}|�#�}|�$d0||f�|�$d1||f�|�$d2||f�|��Wnt�y5}z
t%�&t'|��WYd}~nd}~wwd3|}t�|�dd4l(m)}|dd�}|�*|j�t|d�}
|
�d5�|
��WdSt�y�}zpd|d6}t�+�tj,k�st�+�tj-k�r�d7}nd8}tj�|��s�d#|d$|d%|}t�||�zt.�/||�t0j	j
|d9�} | �1�WnYd:|j}t�|�t|jd�}
|
�t'|�d;�|
��WYd}~dSd}~ww)<NrXrYrZrrr]r[r\�whmcsinstallerpath�whmcslicensekeyrr^r_rgrhrjrJrkrlrmrnrorpzchmod 755 %srqrOrrrsrrvz#Extracting WHMCS Installer zip..,30zunzip -qq %s -d %sr�z%Installing and configuring WHMCS..,60rrrwz]curl %s/install/install.php?step=2 --insecure --silent --output /dev/null --show-error --failz0mv %s/configuration.php.new %s/configuration.phpa�
            curl %s/install/install.php?step=4"             -H 'Content-Type: application/x-www-form-urlencoded'             --data "licenseKey=%s&databaseHost=localhost&databasePort=&databaseUsername=%s&databasePassword=%s&databaseName=%s"             --compressed             --insecure             --silent             --output /dev/null             --show-error             --fail
            ap
            curl %s/install/install.php?step=5"             -H 'Content-Type: application/x-www-form-urlencoded'             --data "firstName=%s&lastName=%s&email=%s&username=%s&password=%s&confirmPassword=%s"             --compressed             --insecure             --silent             --output /dev/null             --show-error             --fail
            rtrz!Update whmcs urls to siteurl..,70ri�)�hostr��passwd�port�cursorclasszHuse %s;UPDATE tblconfiguration SET value='%s' WHERE setting='SystemURL';zEuse %s;UPDATE tblconfiguration SET value='%s' WHERE setting='Domain';zKuse %s;UPDATE tblconfiguration SET value='%s' WHERE setting='SystemSSLURL';zchmod 400 %s/configuration.phpr�rzr{r|r}r�zchmod 750 %sr�)2r!rr�rIr�r�r�r�r
r�r�r�r�rir�rJr�r�r�r�r�r�r>r�rrrFrRrKr�r%r&r'r(r)r*r+r?r@rAr�r�r�r�r�r�rr�rr�)!r#rXrYrZrrr]r[r\�whmcs_installer�whmcs_licensekeyrr�r�r�r�r�rJr�r�r�rGr�r�r�r&r2r3r*rBr�r�r�r$r$r%�installWhmcs�s,






























��

�

�

�
�
�
���



 

��z!ApplicationInstaller.installWhmcsc
Csn�z�ddlm}ddl}|jd}t|d�}|�d�|��i}|jd}|jd|d<|jd|d<d|d	<|jd
|d
<|jd|d<d|d
<d|d<d|d<d|d<|jd|d<|jd}tj	�
tj�rst
�dt|����zEtjj|dd�}|jdks�|jdkr�d|_|��tjj|jdd�}	t�|j|	|jd�dkr�t|d�}|�d�|��WWdSWn�t�yz}
z�tj	�
tj�r�t
�dt|
����|�}|�||�}|�|j�}
|
ddk�rt|d�}|�d|
d�|��WYd}
~
WdSt
�d|
�|
d}	t|d���}tj	�
tj��r$t
�d |�|�d!�d"k�r-n5|�d#�d"k�rMt|d�}|�d|�|��WYd}
~
WdSt|d�}|�d$�|��t� d%��qt|d�}|�d&�|��WYd}
~
nd}
~
wwd'}g}z-|jd(dk�r�t!jj|jd(d�}|�|j"�}d)}t#t$|��D]
}|�%||��q�Wnt�y�}
zWYd}
~
nd}
~
ww|jd}d*tt&d+d,��|jd<||jd-<||jd.<|�'�	t|jdd���}|�d!�d"k�r�n0|�d#�d"k�rt|d�}|�d/|�|��WdSt|d�}|�d0�|��t� d%��q�t|d�}|�d1�|��tjj|jdd�}|jd2d3k�r`|jd4}d5|jdd6|d7}|jd�d7|��}nd5|jdd6}|jd}t(||jd8|||jd9|jd:|jd;d<�}|��t|d�}|�d=�|��WdSt�y�}
zt
�d>t|
��WYd}
~
dSd}
~
ww)?Nrr�rr^�Creating Website...,10rYr�zPHP 8.3r�r�r�rP�ssl�	dkimCheck�openBasedir�
mailDomain�
apacheBackend�adminIDz&Data passed to wordpressInstallNew is rhzPHP 7.3zPHP 8.2��pk�
currentACLzYou dont own this site.[404]z9Error in finding existing site in wordpressInstallNew is �statusz*Failed to Create Website: error: %s. [404]�errorMessage�Creating website result....%sr�z%Info web creating lastline ....... %sr�rOr�zCreating Website....,20�zInstalling WordPress....,30F�pluginbucketTr5r6r7rrz+Failed to install WordPress: error: %s[404]zInstalling WordPress....,50zWordPress installed..,70rZrjrJrnrorkr�r�Plugins�Themes)r<r9rJ�FinalURL�AutoUpdates�
PluginUpdates�ThemeUpdateszWordPress installed..,[200]z!Error WP web creating  ....... %s))r�r�r�r"r�r�r�r!rIrJrKrr
r?r@rArr�r�r�r�rr�checkOwnershiprir>r�r�r�r�rRr�r�rr=rr��appendrr9r)r#r�r�rr��
DataToPassrF�UserIDr�rXrB�ab�
coreResult�coreResult1�
reutrntempath�lastLinerr�bucktobj�pluginlisttr�webobjrJr��Finalurl�wpobjr$r$r%r-vs





��

�




�

��*���






�



�

��z(ApplicationInstaller.wordpressInstallNewc	
Cs�z_|jd}|jd}|jd}|jddkr&d|||f}t�|�}WdS|jddkrMd}|jd	D]}d
||f}q4d||||f}t�|�}WdSd|||jd|f}t�|�}WdSty{}zt�dt|��WYd}~d
Sd}~ww)Nr�VhuserrJ�Themer��hsudo -u %s %s -d error_reporting=0 /usr/bin/wp theme update --all --skip-plugins --skip-themes --path=%s�selectedrg�
Themearray�%s %s�esudo -u %s %s -d error_reporting=0 /usr/bin/wp theme update %s --skip-plugins --skip-themes --path=%s�!Error WP UpdateWPTheme ....... %sr�r"rrQr>r?r@rA)	r#rrwrJrG�	stdoutput�	ThemeList�pluginrBr$r$r%r.
s4


�����z"ApplicationInstaller.UpdateWPThemec	
Cs�z_|jd}|jd}|jd}|jddkr&d|||f}t�|�}WdS|jddkrMd}|jd	D]}d
||f}q4d||||f}t�|�}WdSd|||jd|f}t�|�}WdSty{}zt�d
t|��WYd}~dSd}~ww)NrrwrJr�r�ryrzrg�pluginarrayr|zfsudo -u %s %s -d error_reporting=0 /usr/bin/wp plugin update %s --skip-plugins --skip-themes --path=%sr}r~rr)	r#rrwrJrGr��pluginsList�plugrBr$r$r%r/,s4


�����z#ApplicationInstaller.UpdateWPPluginc	
Cs�zI|jd}|jd}|jd}|jddkr7d}|jdD]}d||f}qd	||||f}t�|�}WdSd	|||jd|f}t�|�}WdStye}zt�d
t|��WYd}~dSd}~ww)NrrwrJrxrzrgr{r|zesudo -u %s %s -d error_reporting=0 /usr/bin/wp theme delete %s --skip-plugins --skip-themes --path=%sz Error WP DeleteThemes ....... %srr)	r#rrwrJr�r�rGr�rBr$r$r%r0Ms*


����z!ApplicationInstaller.DeleteThemesc
Cs�zJ|jd}|jd}|jd}|jd}|jd}|dkr;d}|D]}d||f}d	||||f}t�|�}	q"WdSd	||||f}t�|�}	WdStyf}
zt�d
t|
��WYd}
~
dSd}
~
ww)NrrwrJr�r�rzrgr|zfsudo -u %s %s -d error_reporting=0 /usr/bin/wp plugin delete %s --skip-plugins --skip-themes --path=%sz!Error WP DeletePlugins ....... %srr)r#rrwrJr�r�r�r�rGr�rBr$r$r%r1fs0




�����z"ApplicationInstaller.DeletePluginsc
Cs�zH|jd}|jd}|jd}|jd}d||||f}t�|�}|�d�dkr9d||||f}t�|�}WdSd	||||f}t�|�}WdStyd}zt�d
t|��WYd}~dSd}~ww)NrrwrJrxzesudo -u %s %s -d error_reporting=0 /usr/bin/wp theme status %s --skip-plugins --skip-themes --path=%szStatus: ActiverOzisudo -u %s %s -d error_reporting=0 /usr/bin/wp theme deactivate %s --skip-plugins --skip-themes --path=%szgsudo -u %s %s -d error_reporting=0 /usr/bin/wp theme activate %s --skip-plugins --skip-themes --path=%sz&Error WP ChangeStatusThemes ....... %sr)r"rrQrRr>r?r@rA)r#rrwrJrxrGr�rBr$r$r%r2�s.



�
����z'ApplicationInstaller.ChangeStatusThemesc	Cs�t�|jj�}d|}|j}|�d|�d�}t�||jj�}|�d�}t	�
d|�t��ddt
tdd	��f}d
|��}t�|�d|jj�d|jj�d
|��}t�|�|||fS)zDInitialize staging creation process and set up temporary directories�/usr/local/lsws/lsphp%s/bin/phpz* -d error_reporting=0 /usr/bin/wp --path='z+' core version --skip-plugins --skip-themesr�zOld site wp version:%s�%s/%s�/usr/local/CyberCP/tmpr6r7rsrrrw)r�getPHPStringr<r�rJrrQr�r�r?r@r�CreateSecureDirrArrF)	r#rv�phpr�path_to_wordpressrG�
Wp_version�old_wp_version�tempPathr$r$r%�_initializeStagingCreation�s




z/ApplicationInstaller._initializeStagingCreationcCs^ddlm}ddl}t|d�}|�d�|��i}|jd|d<|jj|d<|jj	|d	<|jj
j|d
<d|d<d
|d<d|d<d|d<d|d<|�}	|	�||�}
|�
|
j�}tj�d�rdt�d|�|d}	t|d���}
|
�d�dkrxn-|
�d�dkr�t|d�}|�d|
�|��dSt|d�}|�d�|��t�d�qitjj|jdd�S)zCreate the staging websiterr�Nr^rT�
StagingDomainrYr�r�r�r8r�rPrUrVrWrXz/usr/local/CyberCP/debugr`rr�r�rOr�z(Failed to Create Website: error: %s[404]zCreating Website....,15rarh)r�r�r�r�r�r�r"r<r�r�rXr:r�r�r�rIrJrKr?r@r�rRr�r�rr�r�)r#rvrlrFrr�r�r�rkrmrnrorprqr$r$r%�_createStagingWebsite�sH





�z*ApplicationInstaller._createStagingWebsitec

Cs�|j}t�|�}d|}	d|j�d�}
t|d�}|�d�|��|	�d|
�d|��}t�||j	�dkr8t
d	��|	�d
|�d|�d|�d
tj�dtj
�d|
��
}t�||j	�dkr]t
d��|	|
fS)z%Download and configure WordPress corer�rnr{r^zDownloading WordPress...,40z7 -d error_reporting=0 /usr/bin/wp core download --path=r�rz!Failed to download wp core. [404]r�rrrr� --path=z#WP Core congiruations failed. [404])r�rr�rir�r�r�rrFr�r>rr�r�)
r#r�r��
dbNameRestorer�r�rF�
PHPVersionr�r�StagingPathr�rGr$r$r%�_setupWordPressCore�s


0z(ApplicationInstaller._setupWordPressCorec
Cs|�d|��}t�||jj��d�}t|d�}|�d�|��|�d|�d|�d�}t�||jj�dkr9t	d	��t|d�}|�d
�|��|�d|��}t�||jj��
�d�d
d�}	d|	�d|�d�}t�||jj�dkrut	d��d|�d|�d�}t�||jj�dkr�t�
d�|S)z1Export database and copy content from source sitez^ -d error_reporting=0 /usr/bin/wp config get table_prefix --skip-plugins --skip-themes --path=r�r^zExporting Database...,55�S -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path=� db export �/dbexport-stage.sqlrz1Failed to export database from master site. [404]zCopying Files...,65�^ -d error_reporting=0 /usr/bin/wp theme path --skip-plugins --skip-themes --allow-root --path=rO�themesrg�cp -R rwrkz;Failed to copy wp-content from master to temp folder. [404]�cp -f �/.htaccess �2While staging creation .htaccess file did not copy)rrQr<r�r�r�r�r�rFr>�
splitlines�replacer?r@)
r#rvrJr�rrFrG�TablePrefixr��
WpContentPathr$r$r%�_exportAndCopyContent�s(



 
z*ApplicationInstaller._exportAndCopyContentc	CsZ|�d|�d|��}t�||j�dkrtd��d|j�d|j�d|��}t�|�t|d�}|�d	�|��|�d
|�d|�d�}t�||j�dkrOtd
��z
d|}t�||j�WnYt|d�}|�d�|��d|�d�}t�||j�d|�d|�d�}t�||j�dkr�td��d|�d|�d�}t�||j�dkr�t�d�dSdS)z,Import database and setup staging site filesz: -d error_reporting=0 /usr/bin/wp config set table_prefix r�rz1Failed to set table prefix on staging site. [404]rrrwr^zImporting Database...,75r�� --quiet db import r�z0Failed to import database on staging site. [404]�rm -f %s/dbexport-stage.sqlzMoving Files...,85rtz/wp-contentzmv z/wp-content rkz:Failed to copy wp-content from temp to staging site. [404]r�r�r�N)	rrFr�r>r�r�r�r?r@)	r#r�r�r�rr�rFrGr�r$r$r%�_importAndSetupStaging 	s8




�z+ApplicationInstaller._importAndSetupStagingc	Cs�t|d�}|�d�|��|�d|�d|j�d|�d�}t�||j�dkr*td��|�d|�d	|j�d|�d�}t�||j�dkrFtd
��|�d|�d|�d|�d�}t�||j�dkratd
��dS)z$Update URLs in staging site databaser^zUpdating URLs...,95�U -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=� "�" "rEr�search-replace failed 1. [404]� "www.�search-replace failed 2. [404]�
 "https://�
" "http://�search-replace failed 3. [404]N)r�r�r�rerrFr�r>)	r#rvr�r�rrirFr�rGr$r$r%�_updateStagingUrlsL	s

�z'ApplicationInstaller._updateStagingUrlsc
Cs�z�tjj|jdd�}|jd}||_|jd}|jd}|jd}|�|�\}}}||_|�||||�}	|	dur<WdSt	|d�}
|
�
d�|
��|�||	�\}}}
|�
|	||||
|�\}}|j}|�|||||�}|�|	|||||�|�||	||||�dd	lm}|��t|	|jd
d|jdd|jdd
�}|��d|��}t�|�t||d���t	|d�}
|
�
d�|
��WdSty�}z&d|j��}t�|�t	|jd�}
|
�
t|��d��|
��WYd}~dSd}~ww)N�WPidr[rrZr�rr^zCreating Database...,25r�StagingNamerpz%s)r<r9rJrert)�wpsiter<z+Staging site created successfully!,100[200]r�)rr�r�r"rr!r�r�r�r�r�r�r�r�rJr�r�r��plogical.installUtilitiesr�reStartLiteSpeedr�rrFr
r>rA)r#rvrrFrlrirr�r�r�r�r�r�r�r�rJr�rr�rGrBr$r$r%r3_	s^





���




��z%ApplicationInstaller.CreateStagingNowc
Cs��z�|jd|_|jd|_|jd|_tjj|jd�}tjj|jd�}t��ddt	t
dd��f|_d	|j��}t�
|�d
|jj�d|jj�d|j��}t�
|�d
dlm}|�|jj�}d|}t�|jd�|�d|j�d|j�d�}t�
||jj�d
kr�td��|�d|j��}t�||jj���d�dd�}t�|jd�d|j�d|j�d�}t�
||jj�d
kr�td��d|j�d|j�d�}t�
||jj�d
|jj�d|jj�d|j��}t�
|�t�|jd �|�d|j�d!|j�d�}t�
||jj�d
k�r
td"��zd#|j}t�
|�WnYt�|jd$�d|j�d%|��}t�
||jj�d
k�r:td&��|�d'|j�d(|j�d)|j�d*�}t�
||jj�d
k�rZtd+��|�d'|j�d,|j�d)|j�d*�}t�
||jj�d
k�rztd-��|�d'|j�d.|j�d/|j�d*�}t�
||jj�d
k�r�td0��d
d1lm}|��d2|j��}t�
|�t�|jd3�Wd
St�y�}	zd2|j��}t�
|�d4t	|	�}
t�|j|
�WYd}	~	dSd}	~	ww)5Nr�
statgingIDr�r[r�r�r6r7rsrrrwrrr�zCreating database backup..,10r�r�r�z7Failed to create database backup of staging site. [404]r�rOr�rgz Moving staging site content..,20r�z
/wp-content/ rkz9Failed copy wp-content from staging to temp folder. [404]r�r�zImporting database..,60r�z8Failed to import database backup into master site. [404]r�zMoving content..,80z/wp-content/* z/Failed to copy wp-content to master site. [404]r�r�r�rEr�r�r�r�r�r�rrt�Completed.[200]z	%s. [404])r!rr�r�rr�r�rr�rArr�rrFr<r��managePHP.phpManagerrr�r�r?r�rJr>rQr�r�rer�rr�)r#�StagingSite�WPSiterGrr�rr�rrB�mesgr$r$r%r4�	s�
 
�� 

"""

��z'ApplicationInstaller.DeploytoProductionc 
Csv�z�ddlm}ddl}|jd|_t�|jd�tjj	|jdd�}t
jj	|jdd�}|jd}z|jd	}|jd
}Wnd}d}Yddlm}d
|j
j�d�}	|j
}
|�|	�}|
j}|j}
|
j}|�|�}d|}|dk�rQt�|jd�d|�d|�d|
��}t|�t�|dddd�\}}t|�|�d�dkr�|�d�}nt|��d|�d|�d|
��}t�|dddd�\}}|�d�dkr�|�d�}nt|��tj�tj�r�t�d|���t��tt dd��}dd|f|_!d|j!��}t�|dddd�\}}|dk�rt|��d |j
j�d!|j
j�d|j!��}t�|dddd�\}}|dk�r0t|��t�|jd"�d|�d#|j!�d$�}t�|dddd�\}}|dk�rUt|��i}|j"|d%<|j#|d&<|j$|d'<|j%|d(<|j&|d)<|j'|d*<|j|d+<||d,<||d-<||d.<||d/<|
j(|d0<|
j)|d1<|
j*|d2<|
j+|d3<|
j|d4<|
j,|d5<|
j-|d6<d7|d8t.�/d9�|d:<d;|d<||d	<||d<<|j0|d=d>�}d?tt dd��}t1|d@�}|�2|�|�3�t�4|dA�dB|�d|j!��}t�|dddd�\}}|dk�rt|��dC|��}t�|dddd�\}}|dk�r t|��t�|jdD�dE||
|j!f}t�|dddd�\}}|dk�rCt|��tj�tj��rPt�|�dF||
|j!f}t�|dddd�\}}|dk�rlt|��tj�tj��ryt�|�t�|jdG�tj�tj��r�t�dH|���dI|||
|j!|f}tj�tj��r�t�|�t�|dddd�\}}|dk�r�t|��tj�tj��r�t�|�t�|jdJ�dK}t�|dddd�\}}|dk�r�t|��dL|d:�dM|j!��}t�|dddd�\}}|dk�rt|��t5||j6|
j6|dN�}|�7�dO|j!��}|dk�r!t|��dP|d:�dQ�}t�|dddd�\}}|dk�r=t|��t�|jdR�ddS|d:�dQ�|j6fWS|dTk�r�t��tt dd��}dd|f|_!d|j!��}t�|dddd�\}}|dk�r�t|��d |j
j�d!|j
j�d|j!��}t�|dddd�\}}|dk�r�t|��t�|jd"�d|j!�d$�}t�||ddd�\}}|dk�r�t|��i}|j"|d%<|j#|d&<|j$|d'<|j%|d(<|j&|d)<|j'|d*<|j|d+<dU|d,<dU|d-<||d.<||d/<|
j(|d0<|
j)|d1<|
j*|d2<|
j+|d3<|
j|d4<|
j,|d5<|
j-|d6<d7|d8t.�/d9�|d:<dV|d<||d	<||d<<|j0|d=d>�}d?tt dd��}t1|d@�}|�2|�|�3�t�4|dA�dB|�d|j!��}t�|dddd�\}}|dk�rzt|��dC|��}t�|dddd�\}}|dk�r�t|��t�|jdD�dE||
|j!f}t�|dddd�\}}|dk�r�t|��tj�tj��r�t�|�dF||
|j!f}t�|dddd�\}}|dk�r�t|��tj�tj��r�t�|�t�|jdJ�dW|}dK}t�|dddd�\}}|dk�r
t|��dL|d:�dM|j!��}t�|dddd�\}}|dk�r,t|��t5||j6|
j6|dN�}|�7�tj�tj��rGt�|�dO|j!��}t�|dddd�\}}|dk�rat|��dP|d:�dQ�}t�|dddd�\}}|dk�r}t|��t�|jdR�ddS|d:�dQ�|j6fWSt�|jd�d|�d|�dX|
��}t�|dddd�\}}|�d�dk�r�|�d�}nt|��tj�tj��r�t�d|���d|�d|�dY|
��}t�|dddd�\}}|�d�dk�r�|�d�}nt|��t��tt dd��}dd|f|_!d|j!��}t�|dddd�\}}|dk�r$t|��d |j
j�d!|j
j�d|j!��}t�|dddd�\}}|dk�rHt|��t�|jd"�i}|j"|d%<|j#|d&<|j$|d'<|j%|d(<|j&|d)<|j'|d*<|j|d+<||d,<||d-<||d.<||d/<|
j(|d0<|
j)|d1<|
j*|d2<|
j+|d3<|
j|d4<|
j,|d5<|
j-|d6<d7|d8t.�/d9�|d:<dZ|d<||d	<||d<<|j0|d=d>�}d?tt dd��}t1|d@�}|�2|�|�3�t�4|dA�dB|�d|j!��}t�8|�dk�r�td[��dC|��}t�8|�dk�r
td\��t�|jd]�tj�tj��r!t�d^|���dI|||
|j!|f}tj�tj��r8t�|�t�|dddd�\}}|dk�rLt|��tj�tj��rYt�|�t�|jdJ�dK}t�|dddd�\}}|dk�rvt|��dL|d:�dM|j!��}t�|dddd�\}}|dk�r�t|��t5||j6|
j6|dN�}|�7�tj�tj��r�t�|�dO|j!��}t�|dddd�\}}|dk�r�t|��dP|d:�dQ�}t�|dddd�\}}|dk�r�t|��t�|jdR�ddS|d:�dQ�|j6fWSt�y:}z4t�d_t|��z
dO|j!��}t�8|�WnYt�|jt|��d`��dt|�dfWYd}~Sd}~ww)aNrrrzCreating BackUp...,10r�r[rZ�
Backuptype�BackupDestination�SFTPID�Localrarcrdr��1zGetting database...,20�sudo -u rwzZ -d error_reporting=0 /usr/bin/wp config get DB_NAME  --skip-plugins --skip-themes --path=rP�Error:rOr�zZ -d error_reporting=0 /usr/bin/wp config get DB_USER  --skip-plugins --skip-themes --path=z	DB Name: r6r7r�r�rsrrzCreating Backup Directory...,40z
 mkdir -p r{�WPtitle�
WPAutoUpdates�
WPFinalURL�WPPluginUpdates�WPThemeUpdates�
WPowner_id�
WPsitepath�DatabaseName�DatabaseUser�
RandomPath�	WebDomain�
WebadminEmail�WebphpSelection�Webssl�Webstate�	WebVHuser�
Webpackage_id�Webadmin_idzbackup-�-z%m.%d.%Y_%H-%M-%S�namezBoth Website and DataBase�SFTP_ID�)�indentr5r^i�r�zrm -r zCopying website data.....,50z#sudo -u %s cp -R %s* %s/public_htmlz)sudo -u %s cp -R %s.[^.]* %s/public_html/zCopying database.....,70zDB Name Dump: z�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path=%s db export %s/%s.sqlz Compressing backup files.....,80zmkdir -p /home/backup/ztar -czvf /home/backup/z.tar.gz -P )r<�WPSiteID�	WebsiteIDr=rtzchmod 600 /home/backup/�.tar.gzr��
/home/backup/�2zNot availabe�Website Backupz/home/%sz� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_NAME  --skip-plugins --skip-themes --path=z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_USER  --skip-plugins --skip-themes --path=�DataBase Backupz(Failed to copy config file to temp path.z"Failed to remove config temp file.zCopying DataBase.....,70zDB Name MySQL Dump: zError WPCreateBackup ....... %s�. [404])9r�rr�r!rr?r�rr�r�rr�rbr<ri�,WrapGetPHPVersionFromFileToGetVersionWithPHPr�rJr�r,rrQrRr�r>rIrKr
r@rr�rArr�r9rfrergrh�owner_idr�r�rU�state�
package_id�admin_idr��strftimerDr�r�r��chmodr�idr�rF) r#rr�r��Adminobjr�r�r�rbr�r��
PhpVersion�VHuserr��
websitedomainr�rrG�	retStatusr��DataBaseName�DataBaseUserr�rU�stdoutr=�json_object�
configPath�file�	backupobj�websitepathrBr$r$r%r5

s�





 
























�








 


























�



 

















�







��z#ApplicationInstaller.WPCreateBackupc^
Cs&�
z�ddl}ddlm}ddlm}ddlm}ddl}tj	�
tj�r-t
�d|jd�|jd|_t
�|jd�|jd	}|jd
}|jd}|jd}	tjj|d�}
|�|
j�}|d
}|d}
|d}|d}|d}z|jj|dd�}Wn|jjdd�}Y|j}tjj|dd�}|j}|d}|d}|d}tj	�
tj�r�t
�dt|����|dk�rtjj|d�}|�|j�}|d}|d}|d}|d}tj	�
tj�r�t
�dt|����ddl}|��}|�|���|j |||d �tj	�
tj��r	t
�d!�d"} |�!| �\}!}"}#tj	�
tj��r t
�d#�d$}$d%}%d&|%��} |�!| �\}!}"}#|"�"��#��$�}&tj	�
tj��rIt
�d'|&���d(|&�d)�}'t�%|'d*d+�d,}'t�%|'d*d+�d-}'t�&|'d*d+�}(tj	�
tj��rxt
�d.|(���|�'�})t
�|jd/�d0|}*d1||f}+t
�d2�dd3l(m)},|,�*�d4|$�d5t|,j+��d6|+�d7t,�-��d8|*��
}'|�!|'�\}!}"}#|"�"��#��$�}-|#�"��#��$�}.tj	�
tj��r�t
�d9|'���|.�r�t
�d:|.���nt
�d;|-���|)�r�|)�.�|�r�|�.�d<|*}'t�%|'�n�|d=k�r�|d>}/|d?}0tjj|d�}|�|j�}|d@}1|1dAk�r.|dB}2n|1dCk�r6dD}2n|1dEk�r=dF}2|dG}3|dH}4|j/�0�}5|5j1dI|2|3|4dJdK�}6d0|/}7z	|6�2|0|/|7�Wnt3�y}}8zt
�dLt|8��WYd}8~8nd}8~8wwd<|7}'t�%|'�tj	�
tj��r�t
�dM|���t,�4�tt5dNdO��}9dPdQ|9f|_6dR|j6��}'t�&|'ddddS�\}:}"|:dk�r�t3|"��dT||j6f}'t�&|'ddddS�\}:}"|:dk�r�t3|"��tj	�
tj��rtj	�
dU|����rt
�dVt|"����t
�dWt|j6����t
�|jdX�dY|j6}'t�&|'ddddS�\}:}"|:dk�r%t3|"��dZ|j6||j6f}'t�&|'ddddS�\}:}"|:dk�rBt3|"��tj	�
tj��rxt
�d[t|"����d\|j6�d]�}'t�&|'ddddS�\}:}"tj	�
tj��rxt
�d^t|"����|d_k�r�|d`k�r�t7|jd	�dak�r�t8jj|d�};|;j9j:}<|;j9j;}=|;j	}>|;j<}?ddbl=m>}@dc|;j9j?�dd�}A|@�@|A|;j9j?�}Bde|j6|
|f}Cdf|<|B|>|Cf}'t�&|'ddddS�\}:}"|:dk�r�t3|"��t
�|jdg�t
�|jdh�di|B�dj�|<|>||?f}'t�&|'ddddS�\}:}"|"�Adk�dak�rt3|"��di|B�dl�|<|>|?|?f}'t�&|'ddddS�\}:}"|"�Adk�dak�r/t3|"��di|B�dm�|<|>|?|?f}'t�&|'ddddS�\}:}"|"�Adk�dak�rRt3|"��dn|<�d6|B�do|>��}'t�&|'ddddS�dp|j6��}'t�&|'ddddS�\}:}"|:dk�r�t3|"��ddqlBmC}D|D�D��	n|drk�r6|d`k�r�t7|jd	�dak�r�t8jj|d�};tEjj|;jFd�}Et8jjG|Eds��H�}F|Fdk�r�dt|Ej?||�Adu�d�f}Gz/t8jj|G|Edv�}H|;j9j:}<|Hj9j;}=|Hj	}>|>}Iddbl=m>}@dc|;j9j?�dd�}A|@�@|A|;j9j?�}B|G}JWn$|;j<}J|;j	}I|;j9j:}<ddbl=m>}@dc|;j9j?�dd�}A|@�@|A|;j9j?�}BYdw|j6|
f}Kdx|<|K|If}'t�&|'ddddS�\}:}"|:dk�rAt3|"��dy|<|K|If}'t�&|'ddddS�\}:}"|:dk�r\t3|"��dn|<�d6|B�do|I��}'t�&|'ddddS�dp|j6��}'t�&|'ddddS�\}:}"|:dk�r�t3|"���n|d`k�r4t7|jd	�dak�r4i}L|dz|Ld{<||Ld|<d}|Ld~<|d|Ld�<|d�|Ld�<|d�|Ld�<|d�|Ld�<|d�|Ld�<|d�|Ld�<||Ld�<||Ld�<z|d�}M|M�Idu�}N|Nd�}Od�}PWnt3�y�}8zd�}PWYd}8~8nd}8~8ww|jd�d`k�r	|}?n	dP||jd�f}?|jd�|Ld�<|jd�|Ld�<|�}Q|Q�J|	|L�}R|�|RjK�}St
�d�|S�|Sd}T	tL|Td���"�}Ut
�d�|U�|U�Ad��dak�rRn"|U�Ad��dak�rft
�|jd�|U�WdSt
�|jd��tM�Nd���q;t
�|jd��t8jj|?d��}V|Vj9j:}<|Vj9j;}=|Vj	}>|�O|=�}Wd�|W}Bt,�4�tt5dNdO��}9dPdQ|9f|_6dR|j6��}'t�&|'ddddS�\}:}"|:dk�r�t3|"��d�|Vj9j:�d8|Vj9j:�d6|j6��}'t�&|'ddddS�\}:}"|:dk�r�t3|"��t
�|jd��d�|<||j6f}'t�&|'ddddS�\}:}"|:dk�r	t3|"��d�|<|j6f}'t�&|'ddddS�\}:}"|:dk�r$t3|"��d�|<�d8|<�d6|j6�du|�d��	}'t�&|'ddddS�\}:}"|:dk�rHt3|"��d�|<|j6||j6f}'t�&|'ddddS�\}:}"|:dk�rft3|"��t
�|jd��|Pd�k�rzdw|j6|
f}Knd�|j6|
f}Kdx|<|K|>f}'t�&|'ddddS�\}:}"|:dk�r�t3|"��dy|<|K|>f}'t�&|'ddddS�\}:}"|:dk�r�t3|"��t
�|jdh�d�|<|>||?f}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��d�|<|>|?|?f}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��dn|<�d�|>��}'t�&|'ddddS�dp|j6��}'t�&|'ddddS�\}:}"|"�Adk�dak�r*t3|"��ddqlBmC}D|D�D��no|d`k�
r�t7|jd	�dak�
r�t8jj|d�};tEjj|;jFd�}Et8jjG|Eds��H�}F|Fdk�
r�dt|Ej?||�Adu�d�f}Gz+t8jj|G|Edv�}H|;j9j:}<|Hj	}>|>}I|G}Jddbl=m>}@dc|;j9j?�dd�}A|@�@|A|;j9j?�}BWn&|;j<}J|;j	}I|I}>|;j9j:}<ddbl=m>}@dc|;j9j?�dd�}A|@�@|A|;j9j?�}BYtj	�
tj��r�t
�d�|>���dn|<�d6|B�d��|>}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��|"�Pd��}Xdn|<�d6|B�d��|>}'t�&|'ddddS�\}:}"|"�Adk�dak�	rt3|"��|"�Pd��}Ydn|<�d6|B�d��|>}'t�&|'ddddS�\}:}"|"�Adk�dak�	rBt3|"��|"�Pd��}Zdw|j6|
f}Kdx|<|K|If}'t�&|'ddddS�\}:}"|:dk�	rit3|"��dy|<|K|If}'t�&|'ddddS�\}:}"|:dk�	r�t3|"��d�|Y�d�|I�d��}'t�&|'|<dddS�\}:}"|:dk�	r�t3|"��d�|X�d�|I�d��}'t�&|'|<dddS�\}:}"|:dk�	r�t3|"��d�|Z�d�|I�d��}'t�&|'ddddS�\}:}"|:dk�	r�t3|"��de|j6|
|f}[dn|<�d6|B�d��|>|[f}'t�&|'ddddS�\}:}"|:dk�
rt3|"��t
�|jd��t
�|jdh�dn|<�d6|B�d��|I||Jf}'t�&|'ddddS�\}:}"|"�Adk�dak�
r7t3|"��dn|<�d6|B�dm�|I|J|Jf}'t�&|'ddddS�\}:}"|"�Adk�dak�
r\t3|"��dn|<�d6|B�do|I��}'t�&|'ddddS�tj	�
tj��
s�dp|j6��}'t�&|'ddddS�\}:}"|:dk�
r�t3|"���n|d`k�
r�t7|jd	�dak�
r�i}L|dz|Ld{<||Ld|<d}|Ld~<|d|Ld�<|d�|Ld�<|d�|Ld�<|d�|Ld�<|d�|Ld�<|d�|Ld�<||Ld�<||Ld�<d|Ld�<z|d�}M|M�Idu�}N|Nd�}Od�}PWnt3�y	}8zd�}PWYd}8~8nd}8~8ww|jd�d`k�r|}?n	dP||jd�f}?|jd�|Ld�<|jd�|Ld�<|�}Q|Q�J|	|L�}R|�|RjK�}St
�d�|S�|Sd}T	tL|Td���"�}Ut
�d�|U�|U�Ad��dak�r^n"|U�Ad��dak�rrt
�|jd�|U�WdSt
�|jd��tM�Nd���qGt
�|jd��t8jj|?d��}V|Vj9j:}<|Vj9j;}=|Vj	}>dd�lQmR}\dc|Vj9j?�dd�}Ad�}]|]d�|d��d��|A}]t�S|]�ddbl=m>}@dc|Vj9j?�dd�}A|@�@|A|Vj9j?�}Bd�|<|B|>f}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��|"�Pd��}Xd�|<|B|>f}'t�&|'ddddS�\}:}"|"�Adk�dak�rt3|"��|"�Pd��}Yd�|<|B|>f}'t�&|'ddddS�\}:}"|"�Adk�dak�r4t3|"��|"�Pd��}Zt
�|jd��|Pd�k�rMdw|j6|
f}Knd�|j6|
f}Kdx|<|K|>f}'t�&|'ddddS�\}:}"|:dk�rot3|"��dy|<|K|>f}'t�&|'ddddS�\}:}"|:dk�r�t3|"��d�|<|B|X|>f}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��d�|<|B|Y|>f}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��d�|<|B|Z|>f}'t�&|'ddddS�\}:}"|"�Adk�dak�r�t3|"��de|j6|
|f}[t
�|jdád�|<|B|>|[f}'t�&|'ddddS�\}:}"|"�Adk�dak�
rt3|"��t
�|jdh�di|B�dj�|<|>||?f}'t�&|'ddddS�\}:}"|"�Adk�dak�
r?t3|"��di|B�dm�|<|>|?|?f}'t�&|'ddddS�\}:}"|"�Adk�dak�
rbt3|"��dn|<�d6|B�do|>��}'t�&|'ddddS�tj	�
tj��
s�dp|j6��}'t�&|'ddddS�\}:}"|"�Adk�dak�
r�t3|"��ddqlBmC}D|D�D�tj	�
tj��
s�|dk�
s�|d=k�
r�d�|*��}'t�%|'�t
�|jdơWdSt3�y}8z;t
�d�t|8��ztj	�
tj��
s�dp|j6��}'t�%|'�WnYt
�|jt|8��dȝ�dt|8�fWYd}8~8Sd}8~8ww)�Nrrr�)�Packagez&Restore WP backup Now ....... start:%s�DomainrzRestoring backup...,10�	DesSiteID�backupidrZr[r�r�r�z.sqlr�r�r8)�packageNamer�r�r�r�zStarting sftp download �SFTP�Hostname�Username�Password�PathzMaking sftp connection to )r[r\�SFTP Connected successfully..�=ssh-keygen -t rsa -b 2048 -f ~/.ssh/cyberpanelbackup -q -N ''�SSH key generated..�~/.ssh/cyberpanelbackup�~/.ssh/cyberpanelbackup.pubr��Key from remote server �echo "�" >> ~/.ssh/authorized_keysrHT�Qawk '!seen[$0]++' ~/.ssh/authorized_keys > temp && mv temp ~/.ssh/authorized_keys�cat ~/.ssh/authorized_keys�'Updated content of authorized key file �Downloading Backups...,15z/home/cyberpanel/%s.tar.gzz%s/%s.tar.gz�Downloading start��	SSHServer�#scp -o StrictHostKeyChecking=no -i � -P rw� root@r� Command used to retrieve backup �(Error in scp command to retrieve backup �*Success in scp command to retrieve backup zmv %s /home/backup/�S3�uploadfilename�
BucketName�Provider�	Backblaze�EndUrl�Amazonz"https://s3.us-east-1.amazonaws.com�Wasabizhttps://s3.wasabisys.com�	AccessKey�	SecertKey�s3F)�endpoint_url�aws_access_key_id�aws_secret_access_key�verifyzError in downloadfile: ..%sz
Backup type: r6r7r�r�rsrPzcp -R /home/backup/%s* %sr�z&Backup file is present and downloaded zExtracting to  zExtracting Backup File...,30zmkdir %s/abz$sudo tar -xvf  %s/%s.tar.gz -C %s/abzOutput of archive zls -lh z/abzListing files r�rgrOrarcrdz!%s/ab/usr/local/CyberCP/tmp/%s/%sz�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path=%s --quiet db import %szRestoreing Data Base...,70zReplacing URLs...,90zsudo -u %s z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"r�z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "https://%s" "http://%s"z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"r�zl -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp litespeed-purge all --path=rtrr�)r<z%s%srk)rer<z+%s/ab/usr/local/CyberCP/tmp/%s/public_html/zsudo -u %s cp -R %s* %szsudo -u %s cp -R %s.[^.]* %sr�r9riz6.0r�r�r�r��Emailr��PasswordByPassr��AutomaticUpdatesr�rcr�rdr�r�r�r�rjr�rJrZz WP Creating website result....%sr�z%Error WP creating lastline ....... %sr�r�z,Failed to Create WordPress: error: %s. [404]zCreating WordPress....,20razRestoring site ....,30)rer�rzExtracting Backup File...,40z$sudo -u %s cp -R /home/backup/%s* %szsudo -u %s mkdir %s/abr~r�z*sudo -u %s tar -xvf  %s/%s.tar.gz -C %s/abzCopying Data File...,60z7%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/z�sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"z�sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"z] /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path=z$WP Path where things are happening: z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_NAME  --skip-plugins --skip-themes --path=%sr�z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_USER  --skip-plugins --skip-themes --path=%sz� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_PASSWORD  --skip-plugins --skip-themes --path=%sz9sed -i "s/define( 'DB_USER', '.*' );/define( 'DB_USER', 'z' );/" z
wp-config.phpz9sed -i "s/define( 'DB_NAME', '.*' );/define( 'DB_NAME', 'zAsed -i "s/define( 'DB_PASSWORD', '.*' );/define( 'DB_PASSWORD', 'z� -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path=%s --quiet db import %szRestoring Database...,70za -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"rY)�vhostzQ/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/virtualHostUtilities.pyz changePHP --phpVersion 'r�z
'  --path z�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_NAME  --skip-plugins --skip-themes --path=%sz�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_USER  --skip-plugins --skip-themes --path=%sz�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config get DB_PASSWORD  --skip-plugins --skip-themes --path=%sz�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%sz�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%sz�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%szRestoring Data Base...,80z�sudo -u %s %s -d error_reporting=0 -d memory_limit=350M -d max_execution_time=400 /usr/bin/wp --skip-plugins --skip-themes --path=%s db import %szrm -rf /home/backup/r�z#Error RestoreWPbackupNow ....... %sr�)Tr�r�rr�r��packages.modelsr��boto3rIrJrKrr
r?r@r!rr�rr�r�r�r=r�rr:rAr�paramiko�	SSHClient�set_missing_host_key_policy�
AutoAddPolicyr(�exec_commandr�r��striprFrQ�	open_sftp�WebTerminal.CPWebSocketr�findSSHPort�DEFAULT_PORTr�fetchIPr�r��Session�client�
download_filer>r�rr�r�rr<r�r�rer�rbrirrRr�rr�rr�r�r��split�submitWorpressCreationr�r�r�r�r�r��plogical.vhostr*�popenExecutioner)^r#r�rr�r�r,r�r��
DomainNamer�r�r=�BackUpFileName�oldtemppath�DatabaseNameold�DumpFileName�oldurl�packgobj�packegs�WebOwnerobj�WebOwner�
BackupTyper��RemoteBackupID�RemoteBackupOBJ�RemoteBackupconf�HostNamerrrr-�ssh�ssh_keygen_command�stdinr��stderr�remote_private_key�remote_public_key�public_key_contentrG�updatedAuth�sftp�	loaclpath�
remotepathr�
successRet�errorRetrr�provider�EndURlr r!r�r9�FinalZipPathrBr�rUr�r�r��	newWPpath�newurlrbr�r�unzippathdbrrt�ag�finalurl�WPobj�WPpath�Newurl�	unzippathrk�oldpath�abc�newpath�oldhomermrnrorprq�	NewWPsiter��Finaldbname�Finaldbuser�
Finaldbpasswd�
unzippath2r*rr$r$r%r6s�








,
n




���
V





#�

�
�
�
�

3


�
���
�


 


 
�

�

���
�
�
�





���
����
�
���
�
�
�
�

�

����
�
�


���z'ApplicationInstaller.RestoreWPbackupNowcCs8||d}t|jd�}|�t|��d��|��dS)N�dr^z/% of file is downloaded from remote server..,50)r�rr�r�r�)r#�transferred�total�
percentager�r$r$r%�UpdateDownloadStatus�sz)ApplicationInstaller.UpdateDownloadStatusc#
Cs>�z�|jd}|jd}|jd}|jd}|jd}||_t|d�}|�d�|��dd	lm}|jj|d
�}t	jj|j
d�}	t�|	j
�d}
t��}|�t���d
}t�d|����d�}
t|
�}tj�|�}|j|
|j
|d�tj�tj�r�t�d�d}|�|�\}}}tj�tj�r�t�d�d}d}d|��}|�|�\}}}|� ��!��"�}t#|�dkr�t|d�}|�d�|��WdStj�tj�r�t�d|���d|�d�}t�$|dd�d}t�$|dd�d}t�|dd�}tj�tj��rt�d|���|�%�}t�&|jd �d!|��}d"|�d#|��}t�d$�dd%l'm(}|�)�d&|�d't*|j+��d(|�d)t,�-��d*|��
}|�|�\}}}|� ��!��"�}|� ��!��"�}tj�tj��r�t�d+|���|�r�t�d,|���t|d�}|�d,|�d-��|��z|jd"|�d#|��d!|��|j.d.�Wn<t/�y�}z't�d/t*|��d0��t|d�}|�d/t*|��d0��|��WYd}~WdSd}~wwt�d1|���|�r�|��|�r�|��tj�d2��s�d3}t�$|�d4|�d5|��}t�$|�dd6l0m1} | �}!|!�2d7|i|�}"t|d�}|�d8�|��t3�4d9�t�|"j5�d:dk�rTt|d�}|�d;t�|"j5�d<�d=��|��d>|��}t�$|�WdStj�tj��rdt�d?|���	|!�6d7|i�}"t�|"j5�}"tj�tj��r�t�d@t*|"����|"dAdBk�r�|"dCdDk�r�t|d�}|�dE�|��d>|��}t�$|�WdS|"dAdBk�r�|"dCdFk�r�t|d�}|�d;t*|"dG��d=��|��d>|��}t�$|�WdSt|d�}|�|"dG�dH��|��t3�4dI��qet/�y}zt|jd�}|�t*|�d0�|��WYd}~dSd}~ww)JNr��folder�
backupfilerr�r^zDownload started..,30r)�OneClickBackupsr[)r��ipz/root/.ssh/cyberpanelr�r�)r[�pkeyrrrrr�
z*Failed to get content of public key. [404]rr	r
rHTrrr
rr5z
cpbackups/rkrrrrrwrrrr�.)�callbackzFailed to download file r�rz/home/backupzmkdir /home/backupzmv /home/cyberpanel/z /home/backup/)�
BackupManager�
backupFilezDownload finished..,60��
restoreStatusz Failed to restore backup. Error �
error_messager�zrm -f /home/backup/z(Name of  of the backup file downloaded: zResponce from status function: �abortrP�running�	CompletedzSuccessfully Restored. [200]�Errorr^z,60ry)7r!rr�r�r��IncBackups.modelsrwr�r�r�sftpUserr�r�r=r-r.r/r0rrQr�r�RSAKey�from_private_keyr(rIrJrKr
r?r@r1r�r�r2r�rFr3r�r4rr5rAr6rr7rtr>�backup.backupManagerr}�
submitRestorer�r�r�r�)#r#r�rurvrr�r�rw�ocb�nbdrxrN�private_key_path�key_content�key_file�keyrOrPr�rQrRrSrTrGrUrVrWrXrrYrZrBr}r�r�r$r$r%r8�s













,

�
��












�



���z#ApplicationInstaller.StartOCRestore)N),�__name__�
__module__�__qualname__r�r�r��
MauticVersion�
PrestaVersionrrCr7�staticmethodrMrWr=r+r*r�r�r�r�r9r;r:rJrSr-r.r/r0r1r2r�r�r�r�r�r�r3r4r5r6rtr8r$r$r$r%r"s�-
,p+R
/sDck"!0",Hc}p	rcCs�tjdd�}|jddd�|jddd�|jddd�|jd	dd�|jd
dd�|jddd�|jddd�|jd
dd�|jddd�|jddd�|jddd�|jddd�|jddd�|jddd�|��}|jdkr�i}|j|d<|j|d<|j|d<|j|d<|j	|d<|j
|d<|j|d<|j|d<|j
|d<|j|d<|j|d<t|j�|d <|jdkr�|j|d!<d"|d#<nd$|d#<td|�}|��dSdS)%Nz CyberPanel Application Installer)�description�functionzSpecify a function to call!)�helpz--tempStatusPathrgz	--appsSetz--domainz--emailz
--passwordz--pluginUpdatesz--themeUpdatesz--titlez	--updatesz
--userNamez	--versionz--pathz--createSiterJrirrr]r\�
pluginUpdates�themeUpdatesr9rr:�versionr4rJrjrZr�)�argparse�ArgumentParser�add_argument�
parse_argsr�rirrr]r\r�r�r9rr:r�r�r4rJrrJ)�parser�argsr!�air$r$r%�main�sJ















�r��__main__)7r�r�rI�sys�shutilr��iorrJrj�environ�
setdefault�django�setupr-�ApachController.ApacheVhostsr�loginSystem.modelsrr�r�plogical.aclr�	threadingr�plogical.CyberCPLogFileWriterr	r?rrCr
rrr
rrrr�plogicalr�plogical.mysqlUtilitiesr�databases.modelsrr�r�plogical.processUtilitiesr�randomrr!rrr�r�r$r$r$r%�<module>s�(M-
�