Ѡg@DddlZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z ddl mZddlmZddlmZmZdZGdd eZGd d eZd ed ede eeffdZdedefdZdeeefdefdZdedefdZdeeefdefdZdeeefdefdZd0dede e ede efdZdZ defdZ!dZ"dZ#ded efd!Z$d"ed#ede efd$Z%d"ede efd%Z&d1d'Z'd(Z(d2d*ed+efd,Z)d0d+efd-Z*d0d+efd.Z+d/Z,dS)3N)Path)UnionIterableOptionalTupleList)Enum)ClPwd)get_rhn_systemid_value is_ubuntuz0/opt/cpvendor/config/cl-manager-ui-settings.jsonceZdZdZdZdZdS) PluginTypez2 Plugin types that are currently detected z object-cachezadvanced-cacheN)__name__ __module__ __qualname____doc__ OBJECT_CACHEADVANCED_CACHE/builddir/build/BUILDROOT/alt-python27-cllib-3.4.22-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/clwpos_lib.pyrrs$"L%NNNrrceZdZdZdZdZdZdS) WpPluginszj Static WP plugin names, that are not detected dynamically from drop-in files, dir names, etc Unknownz WP Rocket AccelerateWPN)rrrrUNKNOWN WP_ROCKET ACCELERATE_WPrrrrr!s)GI"MMMrrlineis_multiline_commentreturnc |r[d|vrdS|d}t|d|d\}}t||dzdd\}}||z|fSd|vr!|d}|d|dfSd|vr!|d}|d|dfSd |vrU|d }t|d|d\}}t||dzdd\}}||z|fS|dfS) z Yep, this bicycle is needed to handle different comment types in .php file https://www.php.net/manual/en/language.basic-syntax.comments.php and ensure that needed line is not under comment z*/)TNTFz//#z/*)find clean_comment)rr pospart1_part2s rr'r'+s; 7 t  8))D//C$T$3$Z66HE1*7S1WXX*N*N 'E'5="66 6 t||iiooDSDz5   d{{iinnDSDz5   t||iioo dsdU33q&3DqND&I&I##u}222 ;rfilec~tj|}tj|SN)ospathrealpathisfile)r, realpath_files r _is_real_filer4Ks+G$$T**M 7>>- ( ((rabs_pathcX tj|d}tj|rt |rdSn#t $rYnwxYwtj|tj}tj|d}tj|d}tj|ot |}tj|o| ot |S)a& WordPress looks for wp-config.php file in the (1) WordPress root and (2) one directory above the root. Check that there is no wp-settings.php file in the second case. This check helps when there is a nested installation, e.g / is WordPress and /wp_path/ is WordPress. wp-config.phpTzwp-settings.php)r/r0joinexistsr4OSErrorpardir)r5 wp_config_phpabs_path_level_upwp_config_php_level_upwp_settings_phpwp_settings_php_existss r_check_wp_config_phprAPs  X?? 7>>- ( ( ]=-I-I 4       Xry99W\\*;_MMgll#46GHHOW^^O<<_A_A_ 7>>0 1 1 1% % 1 / 0 01sAA A A dirc~tj|}tj|Sr.)r/r0r1isdir)rB realpath_dirs r _is_real_dirrFjs+7##C((L 7== & &&rctj|d}dtj|vot |S)z. Check wp-includes exists and is dir. z wp-includes)r/r0r8listdirrF)r5 wp_includess r_check_wp_includesrJos;',,x77K BJx00 0 N\+5N5NNrc tj|sdSn#t$rYdSwxYw t |ot |S#t$rYnwxYwdS)z Checks whether passed directory is a wordpress directory by checking presence of wp-includes folder and wp-config.php file. F)r/r0r9r:rArJ)r5s r is_wp_pathrLws w~~h'' 5  uu #H--N2DX2N2NN       5s$ 22A A! A!doc_rootexcludesc#<Ktj|sdSt|rdVt |D]C}|s|rt||vr+t|r |jVDdS)z Returns folder with wordpress Empty string is wp is in docroot dir :param doc_root: root path to start search from :param excludes: list of paths that must be excluded from search, e.g. subdomains Nr#) r/r0r9rLriterdiris_dirstrname)rMrNr0s r find_wp_pathsrTs 7>>( # #(X&&(({{}}    D X--  d   )OOOrc4tjd|d|d}t|dd5}d} |}|sn7t ||\}}||r d d d dSN d d d n #1swxYwYdS) z8 Looks for defined php variable with true value z^\s*define\s*\(\s*((\'z\')|(\"z\"))\s*,\s*true\s*\)\s*;utf-8ignoreencodingerrorsFTN)recompileopenreadliner'match)varr0rfr r cleaned_lines r_is_php_define_var_foundrds VSVVVVVWWA dWX 6 6 6!$ ::<tEY1Z1Z .L.ww|$$    5sAB ?B  BBwordpress_pathc|d}tj|sdSt d|S)z Detects whether plugin is really enabled, cause not all plugins are enabled 'on load' # https://kevdees.com/what-are-wordpress-drop-in-plugins/ r7FWP_CACHE)joinpathr/r0r9rd)re wp_configs ris_advanced_cache_enabledrjsB ''88I 7>>) $ $u #J : ::rcft|!td|rtjjSdS)z They are advising to check whether WP_ROCKET_ADVANCED_CACHE is defined to ensure plugin is working https://docs.wp-rocket.me/article/134-advanced-cache-error-message NWP_ROCKET_ADVANCED_CACHE)accelerate_wp_pluginrdrrvalue) drop_in_paths rwp_rocket_pluginrps6 L))1 $%? N N2"(( 4rct|dd5}d|vrtjjcdddS dddn #1swxYwYdS)zB Checking if the plugin folder name exists in the drop-in rVrWrXz/clsopN)r]readrrrn)rorbs rrmrms lWX > > >1! qvvxx  *011111111 111111111111111 4s'AAA plugin_typec|d}||d}tj|sdS|tjjkrt|sdS|d}t||p=t|p.t|pt|ptj j}|S)a Looking for object-cache.php or advanced-cache.php in wordpress folder If found - tries to find 'plugin-owner' of <-cache>.php by content comparison If cannot be found -> tries to read <-cache>.php headers looking for Plugin name: z wp-contentz.phpNplugins)rhr/r0r9rrrnrj$get_wp_cache_plugin_by_scanning_dirsget_wp_cache_plugin_by_headerrmrprr)rerswp_content_diractivated_cache plugins_dir plugin_names rget_wp_cache_pluginr|s$,,\::N$--.B.B.BCCO 7>>/ * *tj/555>WXf>g>g5t )))44K6 TT-2?CC-)/::-&o66-&,  ractivated_pluginrzcp|sdS|sdS|}|D]`}t j|D]I\}}}|j|vr:t||jz }||kr |jccSJadS)zT Scanning plugins/* dir and looking for similar .php N)is_filerQ read_bytesrPr/walkrSr)r}rzactivated_plugin_bytespluginrootdirsfilesplugin_object_cache_paths rrvrvs  # # % %t     t-88::%%''''!# ' ' D$$--+/::8H8M+M(+6688 in headers Nz-^.*plugin name:\s*(?P[\w ]+)\s*$rVrWrXr{) r/r0r9r[r\ IGNORECASEr]ranger^searchgroup)r}max_top_lines_countrarbr*rr_s rrwrws, 7>>* + +t CR]SSA  B B B2a*++ 2 2A::<>& ! !  &78 < < < 6688D               z$  88J++// rBBL 66 l " "vg1F'F'F % , ,W 5 5 5 $$sB!&::CB3' C3B77C:B7;C C"!C"c Hg}tjds|dtjds|dtjds|d|rtj}t rgd|z}|dd ingd |z}tj |d d d | }tj d|j |j tjds:tj ddgd d d }tj d|j |j tj gdd d d }tj d|j |j td}|rRtj ddd|ddgd d d }tj d|j |j dSdS)N/usr/bin/cloudlinux-awp-adminz accelerate-wpz /usr/sbin/cloudlinux-ssa-managerz alt-php-ssaz/usr/sbin/cloudlinux-xray-agentz alt-php-xray)zapt-get-yinstallDEBIAN_FRONTENDnoninteractive)yumrrTF)capture_outputtextcheckenvz:Installing AccelerateWP packages captured out: %s, err: %sz/usr/share/clos_ssa/ssa_enabledz enable-ssa)rrrz(Activation SSA captured out: %s, err: %s)z /usr/sbin/cloudlinux-autotracingenablez--allz0Activation autotracing captured out: %s, err: %s system_idz!/usr/sbin/cloudlinux-xray-managerzenable-user-agentz --system_idzID-r#z1Activation xray manager captured out: %s, err: %s)r/r0r9renvironcopyr update subprocessrunloggingdebugstdoutstderrr replace)packagesrinstall_commandprocrs rinstall_accelerate_wpr7s@H 7>>9 : :)((( 7>>< = =' &&& 7>>; < <('''njoo ;; B:::XEO JJ)+;< = = = =666AO~odUZ`cddd RTXT_aealmmm 7>>; < <\~A<P-1EKKK @$+t{[[[ >???     D  MDdkSWS^___&{33Ie~ 02E}V_VgVghmoqVrVr s      I4;X\XcdddddeerFasync_set_suitesourcecttjdrdStjtrt tdd5}t j|}dddn #1swxYwY|diddurtj d dSgd }|d kr| d d g|r-tj |tjtj dStj|ddd}tj d|j|jdS)zh 1. Installs needed packages 2. Enables autotracing 3. Allows AccelerateWP Free for all z8/var/clwpos/admin/allowed_for_all_site_optimization.flagNrarV)rYfeatures_override accelerate_wpFzWActivation AccelerateWP Free skipped: Vendor UI skip the enabling of Accelerate WP Free)r set-suite--allowed-for-all--suitesrBILLING_OVERRIDE--source)rrTrrrz6Activation AccelerateWP Free captured out: %s, err: %s)rr/r0r9VENDOR_UI_CONFIG_PATHr]rloadrrrextendrPopenPIPErrr)rrrbvendor_config_contentcommandrs rconfigure_accelerate_wprbs  w~~PQQ w~~+,, 'w ? ? ? 11$(IaLL ! 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ! $ $%8" = = A A/ R RV[ [ [ Ms t t t F   G ### $67888j ??      ~gT$TRRR NPTP[]a]hiiiiis+B  BBcttjdrdSgd}|dkr|gdt j|ddd}tjd|j |j dS)Nz3/var/clwpos/admin/allowed_for_all_object_cache.flag)rr--visible-for-allraccelerate_wp_premiumrrrz--preserve-user-settingsTrz9Activation AccelerateWP Premium captured out: %s, err: %s rr/r0r9rrrrrrr)rrrs rconfigure_accelerate_wp_premiumrs w~~KLL(((G###SSSTTT >'d N N ND MMt{\`\ghhhhhrcttjdrdSgd}|dkr|ddgt j|ddd}tjd|j |j gd}|dkr|gd t j|ddd}tjd |j |j dS) Nz*/var/clwpos/admin/allowed_for_all_cdn.flag)rrrraccelerate_wp_cdnrrTrz5Activation AccelerateWP CDN captured out: %s, err: %s)rrrraccelerate_wp_cdn_prorz9Activation AccelerateWP CDN PRO captured out: %s, err: %sr)r command_cdnrcommand_cdn_pros rconfigure_accelerate_wp_cdnrs  w~~BCC(((K###J(:;<<< >+T$T R R RD MI4;X\Xcddd000O###[[[\\\ >/dQU V V VD MMt{\`\ghhhhhrc&|sdStjddgdddj}tj|}||dkrdStjddd|dd gddd}t jd |j|jdS) Nrz get-optionsTr upgrade_urlz set-optionsz --upgrade-urlz--suiterzBSetting AccelerateWP Premium upgrade url captured out: %s, err: %s) rrrrrrrrr)r options_jsonoptionsrs rconfigure_upgrade_urlrs >#BM"R#',0"&((()/j&&Ggkk-0000 >:(*&$2 4 !%)-# % % %D MV+t{,,,,,rr.)r)FN)-rr[r/rrpathlibrtypingrrrrrenumr clcommon.clpwdr clcommon.utilsr r rrrrRboolr'r4rArFrJrLrTrdrjrprmr|rvrwrrrrrrrrrrs 99999999999999 <<<<<<<<K&&&&&&&&########4E#t)(SV-6$ ;d ; ; ; ;   3.4dW_`cWd(DXc](%%%%:(e(e(eV%j%jT%j3%j%j%j%jPiiCiiii,!i!i!i!i!i!iH,,,,,r