}Ce +$ddlmZddlmZddlmZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z mZmZddlmZddlmZdd lmZGd d eZGd d eZdededeeeffdZdedefdZde ee fdefdZdedefdZde ee fdefdZde ee fdefdZd+dede eede efdZ dZ!de fdZ"d Z#d!Z$de d"efd#Z%d$e d%e de efd&Z&d$e de efd'Z'd,d)Z(d*Z)dS)-)print_function)absolute_import)divisionN)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_CACHE/builddir/build/BUILDROOT/alt-python27-cllib-3.3.7-2.el7.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_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)r!r"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_filer6Is+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)r1r2joinexistsr6OSErrorpardir)r7 wp_config_phpabs_path_level_upwp_config_php_level_upwp_settings_phpwp_settings_php_existss r_check_wp_config_phprCNs  X?? 7>>- ( ( ]=-I-I 4       Xry99W\\*;_MMgll#46GHHOW^^O<<_A_A_ 7>>0 1 1 1% % 1 / 0 01sAA A A dirc~tj|}tj|Sr0)r1r2r3isdir)rD realpath_dirs r _is_real_dirrHhs+7##C((L 7== & &&rctj|d}dtj|vot |S)z. Check wp-includes exists and is dir. z wp-includes)r1r2r:listdirrH)r7 wp_includess r_check_wp_includesrLms;',,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)r1r2r;r<rCrL)r7s r is_wp_pathrNus 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%) r1r2r;rNriterdiris_dirstrname)rOrPr2s r find_wp_pathsrVs 7>>( # #(X&&(({{}}    D X--  d   )OOOrc2tjd|d|d}t|d5}d} |}|sn7t ||\}}||r ddddSN dddn #1swxYwYdS) z8 Looks for defined php variable with true value z^\s*define\s*\(\s*((\'z\')|(\"z\"))\s*,\s*true\s*\)\s*;ignoreerrorsFTN)recompileopenreadliner)match)varr2rfr"r! cleaned_lines r_is_php_define_var_foundrds VSVVVVVWWA d8 $ $ $$ ::<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/ r9FWP_CACHE)joinpathr1r2r;rd)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|d5}d|vrtjjcdddS dddn #1swxYwYdS)zB Checking if the plugin folder name exists in the drop-in rXrYz/clsopN)r]readrr rn)rorbs rrmrms l8 , , ,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)rhr1r2r;rrrnrj$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_pluginrzcDtj|sdS|D]i}t |d|j}|r;|d}||kr |jcSjdS)zT Scanning plugins/* dir and looking for similar .php Nz**/r)r1r2r;rRlistglobrU read_bytes)r}rzpluginplugin_object_caches rrvrvs 7>>+ & &t%%''##"6;;/L5E5J/L/L#M#MNN  #"5a"8 "--//3C3N3N3P3PPP{""" 4rctj|sdSd}tjdtj}t |d5}t|D]P}|}| |}|#| dccdddSQ dddn #1swxYwYdS)zS Looking for Plugin name: in headers Nz-^.*plugin name:\s*(?P[\w ]+)\s*$rXrYr{) r1r2r;r[r\ IGNORECASEr]ranger^searchgroup)r}max_top_lines_countrarbr,r!r_s rrwrws* 7>>* + +t CR]SSA x 0 0 02A*++ 2 2A::<>& ! !  & * * * a6688D               z$  88J++// rBBL 66 l " "vg1F'F'F % , ,W 5 5 5 $$sB!&::CB2& C2B66C9B6:C C! C!c g}tjds|dtjds|dtjds|d|rgd|z}t j|tjdst jgd d tjd st jdd gt jgdt d}|r.t jddd|ddgdSdS)zh 1. Installs needed packages 2. Allows AccelerateWP Free for all 3. Enables autotracing /usr/bin/cloudlinux-awp-adminz accelerate-wpz /usr/sbin/cloudlinux-ssa-managerz alt-php-ssaz/usr/sbin/cloudlinux-xray-agentz alt-php-xray)yuminstallz-yz8/var/clwpos/admin/allowed_for_all_site_optimization.flag)rz set-suitez--allowed-for-allz--suites accelerate_wpT)checkz/usr/share/clos_ssa/ssa_enabledz enable-ssa)z /usr/sbin/cloudlinux-autotracingenablez--all system_idz!/usr/sbin/cloudlinux-xray-managerzenable-user-agentz --system_idzID-r%N)r1r2r;r subprocessrunrreplace)packagesinstall_commandrs rconfigure_accelerate_wpr/sH 7>>9 : :)((( 7>>< = =' &&& 7>>; < <('''(222X=''' 7>>T U U7***26  7 7 7 7 7>>; < <K:LIJJJNJJJKKK&{33I7;=PR_!))%446 7 7 7 7 777rr0)r)* __future__rrrrr[r1rpathlibrtypingrrr r r enumr clcommon.clpwdr clcommon.utilsrrrrTboolr)r6rCrHrLrNrVrdrjrprmr|rvrwrrrrrrsQ&%%%%%&&&&&& 99999999999999 111111&&&&&&&&########4E#t)(SV-6$ ;d ; ; ; ;   3. 4 d W_`cWd    DXc](%%%%8#7#7#7#7#7r