IQg=<ddlZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z ddl mZddlmZddlmZGddeZGd d eZd ed ed e eeffdZded efdZdeeefd efdZded efdZdeeefd efdZdeeefd efdZd/dede e ed e efdZdZdefdZdZ dZ!dedefd Z"d!ed"ed e efd#Z#d!ed e efd$Z$d0d&Z%d'Z&d1d)ed*efd+Z'd/d*efd,Z(d/d*efd-Z)d.Z*dS)2N)Path)UnionIterableOptionalTupleList)Enum)ClPwd)get_rhn_systemid_valueceZdZdZdZdZdS) PluginTypez2 Plugin types that are currently detected z object-cachezadvanced-cacheN)__name__ __module__ __qualname____doc__ OBJECT_CACHEADVANCED_CACHEs/builddir/build/BUILD/imunify360-venv-2.5.0/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/clwpos_lib.pyr r s$"L%NNNrr ceZdZdZdZdZdZdS) 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_WPrrrrrs)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)rrpospart1_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_filer3Gs+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.r/joinexistsr3OSErrorpardir)r4 wp_config_phpabs_path_level_upwp_config_php_level_upwp_settings_phpwp_settings_php_existss r_check_wp_config_phpr@Ls  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.r/r0isdir)rA realpath_dirs r _is_real_dirrEfs+7##C((L 7== & &&rctj|d}dtj|vot |S)z. Check wp-includes exists and is dir. z wp-includes)r.r/r7listdirrE)r4 wp_includess r_check_wp_includesrIks;',,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.r/r8r9r@rI)r4s r is_wp_pathrKss 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.r/r8rKriterdiris_dirstrname)rLrMr/s r find_wp_pathsrSs 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)varr/rfrr cleaned_lines r_is_php_define_var_foundrcs 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/ r6FWP_CACHE)joinpathr.r/r8rc)rd wp_configs ris_advanced_cache_enabledrisB ''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_pluginrcrrvalue) drop_in_paths rwp_rocket_pluginros6 L))1 $%? N N2"(( 4rct|dd5}d|vrtjjcdddS dddn #1swxYwYdS)zB Checking if the plugin folder name exists in the drop-in rUrVrWz/clsopN)r\readrrrm)rnras rrlrls 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)rgr.r/r8r rrmri$get_wp_cache_plugin_by_scanning_dirsget_wp_cache_plugin_by_headerrlrorr)rdrrwp_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_pluginrycZ|}tj|sdS|D]`}tj|D]I\}}}|j|vr:t||jz }||kr |jccSJadS)zT Scanning plugins/* dir and looking for similar .php N) read_bytesr.r/r8rOwalkrRr)r|ryactivated_plugin_bytespluginrootdirsfilesplugin_object_cache_paths rrurus.88:: 7>>+ & &t%%''''!# ' ' D$$--+/::8H8M+M(+6688 in headers Nz-^.*plugin name:\s*(?P[\w ]+)\s*$rUrVrWrz) r.r/r8rZr[ IGNORECASEr\ranger]searchgroup)r|max_top_lines_countr`rar)rr^s rrvrvs, 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 g}tjds|dtjds|dtjds|d|r?gd|z}t j|ddd }t jd |j|j tjd s:t jdd gddd }t jd|j|j t jgdddd }t jd|j|j td}|rRt jddd| ddgddd }t jd|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)yuminstallz-yTF)capture_outputtextcheckz:Installing AccelerateWP packages captured out: %s, err: %sz/usr/share/clos_ssa/ssa_enabledz enable-ssaz(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.r/r8r subprocessrunloggingdebugstdoutstderrr replace)packagesinstall_commandprocrs rinstall_accelerate_wpr/sH 7>>9 : :)((( 7>>< = =' &&& 7>>; < <('''n222X=~odUZ[[[ RTXT_aealmmm 7>>; < <\~A<P-1EKKK @$+t{[[[ >???     D  MDdkSWS^___&{33Ie~ 02E}V_VgVghmoqVrVr s      I4;X\XcdddddeerFasync_set_suitesourcectttjdrdSgd}|dkr|ddg|r-t j|t jt jdSt j|ddd}tj d |j |j dS) zh 1. Installs needed packages 2. Enables autotracing 3. Allows AccelerateWP Free for all z8/var/clwpos/admin/allowed_for_all_site_optimization.flagN)r set-suite--allowed-for-all--suites accelerate_wpBILLING_OVERRIDE--source)rrTrrrz6Activation AccelerateWP Free captured out: %s, err: %s) rr.r/r8extendrPopenPIPErrrrr)rrcommandrs rconfigure_accelerate_wprUs  w~~PQQ   G ### $67888j ??      ~gT$TRRR NPTP[]a]hiiiiircttjdrdSgd}|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.r/r8rrrrrrr)rrrs rconfigure_accelerate_wp_premiumrus 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)+rrZr.rrpathlibrtypingrrrrrenumr clcommon.clpwdr clcommon.utilsr r rrQboolr&r3r@rErIrKrSrcrirorlr{rurvrrrrrrrrrrs 99999999999999 111111&&&&&&&&########4E#t)(SV-6$ ;d ; ; ; ;   3. 4 d W_`cWd     DXc](%%%%:#e#e#eLjjTj3jjjj@iiCiiii,!i!i!i!i!i!iH,,,,,r