VULN_CHECK_I913V6 Pdb h ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZmZddlmZddlmZddlmZddlm Z m!Z!m"Z"m#Z#ddl$m%Z%ddl&Z&dd lm'Z'dd l(m)Z)m*Z*dd l+m,Z,dd l-m-Z-m.Z.m/Z/dd lm0Z0m1Z1m2Z2m3Z3m4Z4ddl5Z5ddl6m7Z7m8Z8ddl9m:Z:ddl;mm?Z?ddl@mAZAmBZBddlCmDZDmEZEddlFmGZGmHZHddlImJZJmKZKddlLmMZMddlNmOZOmPZPmQZQmRZRmSZSmTZTddlUmVZVmWZWmXZXddlYmZmZZZddl[m\Z\m]Z]m^Z^m_Z_m`Z`ddlambZbddlcmdZdmeZeddlfmgZgddlNmhZhddlimjZjd d!lkmlZldd"lmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|d d#l}m~Z~mZd d$lmZdd%lmZejrdd&lmZdad'ZGd(d)ejZdd+ed,efd-Zdd+ed.ed/efd0Zdd+ed2efd3Zd4efd5Zd6efd7Zd4efd8Zd9ejfd:Zd;ZddZdd?d.func_wrapper|s >"8,,F M4.t...v.. .     4=9)(++           4 4 4!/00 $q!!!!  ####$9 aiXXHy 0&'i# 4=( 3 3 3 3 3 3 3 3 3 M M M   Q    4=bCFF*K*K L L L L L L L L L Ms- * E(A"" E/BC:: E?E  E)rlrns` rm catch_errorrpws) MMMMM2 c(eZdZdZfdZdZxZS)ExtendedJSONEncoderzz Makes it easier to use ENUMs and DATACLASSes in program, automatically converting them when json is printed. c Dd|d<tjdi|dS)NF ensure_asciiro)super__init__)rgri __class__s rmrwzExtendedJSONEncoder.__init__s0!&~""6"""""rqct|tr|jSt|tjtjfr|St|t rt|Stj |rtj |Stj ||SN)rcrvaluedatetimedate isoformatrrf dataclasses is_dataclassrjson JSONEncoderdefault)rgobjs rmrzExtendedJSONEncoder.defaults c4  +9  hmX->? @ @ +==?? " W % % +s88O  %c * * +%c** *''c222rq)r^ __module__ __qualname____doc__rwr __classcell__)rxs@rmrsrssQ##### 3 3 3 3 3 3 3rqrsFis_json is_prettyc|rY|r,ttj|ddtdSttj|dtdSt|dS)z Print specified dictionary :param data_dict: data dictionary to print :param is_json: True - print in JSON, False - in text :param is_pretty: True - pretty json print, False - none (default) :return: None T)indent sort_keyscls)rrN)printrdumpsrs) data_dictrrs rm_print_dictionaryrsy  R $*YqDFYZZZ [ [ [ [ [ $*Y$r=WPOSrorqrmis_wpos_supportedrs &gl 3 33rquser_pwctj|jt}tj|st |ddSdS)z@ Creates {homedir}/.clwpos directory if it's not exists i)modeN)rpathjoinpw_dirrBisdirr )r clwpos_dirs rmcreate_clwpos_dir_if_not_existsrsTgnm<6 E E E X-;@ X Xk X X X E|( E El.> E E E I~* I I0B I I I R|( R Rl.> R R R R A{' A AKO A A A K+ K K0E K K K Q 6 8 8rqwp_config_pathctj|}tj|st |tj|s t tdd|idS)z Check that wp-config.php exists inside Wordpress directory. :param wp_config_path: absolute path to Wordpress config file :raises: WposError z)Wordpress config file %(file)s is missingfilerarXN)rrdirnameexistsr8isfiler5r )rwp_paths rmcheck_wp_config_existancer#s goon--G 7>>' " "#'""" 7>>. ) ):(S T T!' 8::: :::rq abs_wp_pathcttj|}t|t dtdt ffd } tj|}tt||}td ||ddS#ttf$r}t||d}~wwxYw)z Clear cloudlinux section with redis object cach config from docroot's wp-config.php :param abs_wp_path: Absolute path to WordPress :raises: WposError linerc|vod|vS)zn Filter function that should delete CL config options from the `redis_cache_config_section()` r ro)r&lines_to_filters rm__config_filterz1clear_redis_cache_config..__config_filters?*L/@/LLrqN)rfr4rr#rboolreadlistfilterrrrrr9)r$rr)wp_config_linescleared_wp_configrjr(s @rmclear_redis_cache_configr2s  4455Nn---022OMcMdMMMMMM 5#.55 !I!IJJ(9 : :NERRRRR W 555!.!4445sAB,,C=C  Ccbtst|ntjS)z Run code under user's privileges if we are root; otherwise do nothing. Used by cleanup/migration routines which should not perform filesystem writes as root. )rr contextlib nullcontextrs rm _drop_to_userr6s+ ->,?,? ]?8 $ $ $ZE[E]E]]rqcttj|}t| dtD}tj|}t d|D }g}|D]^fd|D}|s|sdSt fdtDs|_|dgt|dd}td ||d dS#ttf$r}t||d}~wwxYw) z Create config for redis-cache. Updates wp-config.php by inserting CloudLinux redis-cache section when needed. :param abs_wp_path: absolute path to WordPress :raises: WposError c(i|]}|j|jSro)rr).0constants rm z-create_redis_cache_config..s___HHM8<___rqc3K|]}d|vV dS)WP_REDIS_IGNORED_GROUPSNro)r9r&s rm z,create_redis_cache_config..s(#b#b$$=$E#b#b#b#b#b#brqc,i|]\}}d|dv ||S)r'ro)r9kvr&s rmr;z-create_redis_cache_config..s3iiiA_XY___dhMhMh1MhMhMhrqNc32K|]}d|jdvVdS)rr@Nr)r9redis_constantr&s rmr>z,create_redis_cache_config..s7nn^8."5888D@nnnnnnrqrr@r*r+)rfr4rr#rEr-anyitemsappendrrrrrr9) r$rabsent_constantsr0add_cli_directive cleaned_linesupdated_configrjr&s @rmcreate_redis_cache_configrLs 4455Nn---5__H^___#.55 ##b#bRa#b#b#b b bb # + +Diiii1A1G1G1I1Iiii # ,= nnnnWmnnnnn +$$T*** !  ' ) ) 122    7 7OOOOO W 555!.!4445sA*DA;DE-D==Ec  tptjt}dx}}ddlm}m}ddlm}|D]} d||D}n.#t$r!}| d||Yd}~@d}~wwxYwt|} |D]} t|5t|| | } dddn #1swxYwYn/#t$r"}| d| ||Yd}~md}~wwxYw| D]} | d vrd n| } t| ts|d z }&tj| s2tj| d r|d z }|d | || tj| | d} tt/j| }|d}tj|s t|5tj|r\tj|tj| tjzst5d|tj|dddn #1swxYwY|d z }#t$r'}|d z }|d||Yd}~ d}~wwxYw t9j|j}n'#t>$r| d|Y#wxYw|r%|dkstj|s|d||gtj|t@dd} t|5tj|s dddtj!|}tEj#|j$rtKj&|ntj|dddn #1swxYwY;#tN$r8}|j(tPj)kr|d|||Yd}~xd}~wt$r#}|d|||Yd}~d}~wwxYw|*d||dS)z Cleanup for old customers: - Remove legacy backups created next to wp-config.php (docroot): /wp-config.php.backup - Remove old per-user backup directory: /.clwpos/backups/wp-config r)cpusers userdomains) find_wp_pathscg|]\}}|Sroro)r9_rs rm z4cleanup_legacy_wp_config_backups..s>>>uq">>>rqz>legacy wp-config backup cleanup: can't get docroots for %s: %sN)excludeszAlegacy wp-config backup cleanup: can't scan docroot %s for %s: %s)r*.z./r*r@z..zLlegacy wp-config backup cleanup: suspicious wp_rel=%r for user=%s docroot=%srz.backupz"refuse to delete outside docroot: z.legacy wp-config backup cleanup failed: %s: %sz:legacy wp-config backup cleanup: can't resolve home for %sz8legacy wp-config backup cleanup: invalid home for %s: %rbackupsz wp-configz;legacy wp-config backup cleanup: can't remove %s for %s: %sz;legacy wp-config backup cleanup done: removed=%d skipped=%d)+r]logging getLoggerr^clcommon.cpapirNrOclcommon.clwpos_librPredebugr.r6rcrfrrisabsnormpathrr[rrstripr4lexistsseprunlinkrrrrrBlstatstatS_ISDIRst_modeshutilrmtreererrnoENOENTinfo)_logremovedskippedrNrOrPrdocrootsrjrT docroot_pathwp_pathswp_relr$r legacy_backuphometargetsts rm cleanup_legacy_wp_config_backupsrvs  0W&x00DGg33333333111111GIIImIm >> H(=(=>>>HH    JJWYacd e e e HHHH >>$' e' eL "8,,TT#MM,$R$R$RSSHTTTTTTTTTTTTTTT    ^)8Q888  # e e%88f!&#..qLG7==((BG,<,.wrapperDs2 '$&& &tT$V$$$rq)r)rlrys` rmcheck_license_decoratorrz@s5 4[[%%%%[% Nrqrc t|\}}||fS#t$r!ttdd|iwxYw)z Validates domain, determines it's owner and docroot or exit with error :param domain: Domain name to check :return: Tuple (username, docroot) zNo such domain: %(domain)s.rr)r+rr5r )r document_rootowners rm check_domainr~Nse d&v um## ddd(E F FQY[aPbccccds +Arattemptsctj}||tjz} t|d}t |pdD]O} tj||n@#t$rtj dYLwxYwttdn*#t$rttdwxYw|S)zE Try to take lock on file with specified number of attempts. Nza+r@g333333?zwAnother utility instance is already running. Try again later or contact system administrator in case if issue persists.z%IO error happened while getting lock.) fcntlLOCK_EXLOCK_NBopenrangeflockfilenorrsleepLockFailedExceptionr r)rr lock_typelock_fdrRs rm lock_filer\s IU]"  TtT""x}1%% M MA  GNN,,i888    3 &g/K'L'LMM M  TTT!'*Q"R"RSSST Ns/#B-'A,*B-,B  B- B  B--'Ccd}d}tj|}tj|}|s!|st|dt did}|rW t jddgddd }|jpd |jpd z}d |vrd}n"#tt j tf$rYnwxYwd}|rtjd }|s#|s#t|dt didSdSdS)zb Validate that MAx Cache is installed and its module is loaded (Apache and/or nginx). z!/opt/cloudlinux/maxcache/.versionz'/opt/cloudlinux/maxcache/.nginx-versionrYzMAx Cache is not installed.F apachectlz-MT)capture_outputtexttimeoutr*maxcache_modulez0/etc/nginx/conf.d/modules/ea-nginx-maxcache.confz;MAx Cache module is not enabled (neither Apache nor nginx).N) rrr!r_rR subprocessrunstdoutstderrrSubprocessErrorr) rapache_version_pathnginx_version_pathapache_installednginx_installedapache_module_okprocoutputnginx_module_oks rmensure_maxcache_availablerust >Bw~~&9::gnn%788O NONw1-J+K+K LMMM  >d## D k'RDK,=2>F F**#' !:#=wG    D O '.. >    O   qVWW X         s+3BB>=B>ceZdZdZdS)rz, Exception when failed to take lock N)r^rrrrorqrmrrs Drqr resource_pathc#VKt|dz|}dVt|dS)z Lock a file, than do something. Make specified number of attempts to acquire the lock, if attempts is None, wait until the lock is released. Usage: with acquire_lock(path, attempts=1): ... do something with files ... z.lockN)r release_lock)rrrs rm acquire_lockrs9 /::G EEErqc tj|tjn#t$rYnwxYw|dS)z Releases lock file N)rrrLOCK_UNrclose) descriptors rmrrsd  J%%''7777      s14 AA php_versionrUcd}d|jkr5||r"ttdd|idSdS)zX Ensures wp-cli is compatible, e.g some php modules may prevent stable work snuffleupaguszea-php74zSeems like ea-php74 %(module)s module is enabled. It may cause instabilities while managing Object Caching. Disable it and try againmodulerN) identifieris_extension_loadedr7r )rdangerous_modules rmwp_cli_compatibility_checkrsw '[+++//0@AA,'9c1d1d2:;K0LNNN N,+++rqhidecvddtjddd|iiidg}tt|\}}||fS)zf Call cloudlinux-config utility to hide/show WPOS icon in user's control panel interface. setz--dataoptions uiSettingshideAccelerateWPAppz--json)rrr1rD)rparams returncoders rmset_wpos_icon_visibilityrsS  I /Dd.KLMNN F &&6??J v rqrcFt|dS)zP Check the current state of WPOS icon in user's control panel interface r)r: get_param icon_names rmis_ui_icon_hiddenrs ::   < 8 88rqchttjt|gS)z[ 1. xray utility exists = alt-php-xray package installed 2. feature is visible )allrrr rO)feature_visibles rmshould_xray_user_agent_enabledrs/ 344! " ""rqcttjttjt t dgS)z 1. xray utility exists = alt-php-xray installed 2. xray socket exists 3. end-user plugin was not enabled by admin = hidden in UI hideXrayAppr)rrrr rOrPrrorqrmshould_xray_user_agent_disabledrsP 344GNN#344% >>>@ A AArqcleZdZUeeZeeed<eeZ eeed<dS)WHMCSServerWideOptionsdefault_factoryallowed_suitesvisible_suitesN) r^rrrr.rrr__annotations__rrorqrmrrsT%*U4%@%@%@NHTN@@@%*U4%@%@%@NHTN@@@@@rqrcneZdZUdZeed<eed<eed<eed<eed<eed<eeZ eed <d Z e eed <d Z e eed <d Z e eed <d Ze eed<d Ze eed<d Ze eed<ddZedZedZedZedZd S)ServerWideOptionsz Options holder representing server-wide option available for reading for any user on server. Only can be changed by root. show_iconrrsupported_suitessupported_featureshidden_featuresr whmcs_optionsNr"disable_smart_advice_notifications%disable_smart_advice_wordpress_plugindisable_smart_advice_reminders upgrade_urlupgrade_url_cdn object_cachec  ddlm mi fd jDfdjD}||vrdSd}| jvr|jdS|j}|jvr|jdS|j}|dSt t|}tt|d}| t|||tdd||d t||d<t|S) z Append some needed arguments to upgrade url to make it specific for user. Please pay attention that we add *customer_name* instead of system user, that may be different on plesk. r) PremiumSuite CDNSuiteProc i|] }|j Sror)r9featurers rmr;z>ServerWideOptions.get_upgrade_url_for_user..!sWWWgw )WWWrqc i|] }|j Sror)r9rrs rmr;z>ServerWideOptions.get_upgrade_url_for_user.."sUUUWw (UUUrqNrcloudlinux_advantage provisioning)rr server_ipmactionsuite)clwpos.feature_suitesrrprimary_featuresrrr.r rr rr,r-r r ) rgrrrfeature_to_suite target_url url_partsqueryrrs @@rmget_upgrade_url_for_userz*ServerWideOptions.get_upgrade_url_for_usersd DCCCCCCC  WWWW9VWWW UUUU 8TUUU  * * *4 l3 3 3't)J k2 2 2#+t-J  4*--.. Yy|,,-- (6::&'$%g.      !'' ! )$$$rqcttt|jt|jjzSrz)r.rrrrs rmallowed_suites_listz%ServerWideOptions.allowed_suites_listE6CT011D9K9Z4[4[[\\]]]rqcttt|jt|jjzSrz)r.rrrrs rmvisible_suites_listz%ServerWideOptions.visible_suites_listIrrqcddlm}t}jD].}|fd||jD/|S)Nr@ ALL_SUITESc&h|] }|jv |Srorr9rrgs rm z5ServerWideOptions.allowed_features..S3&M&M&M')0D4K)K)K'.)K)K)Krq)feature_suitesrrrr feature_set)rgr_allowed_featuresrs` rmallowed_featuresz"ServerWideOptions.allowed_featuresMs /.....EE- N NE  $ $&M&M&M&MZ=N=Z&M&M&M N N N N  rqcddlm}t}jD].}|fd||jD/|S)Nr@rc&h|] }|jv |Srorrs rmrz5ServerWideOptions.visible_features..\rrq)rrrrrr)rgr_visible_featuresrs` rmvisible_featuresz"ServerWideOptions.visible_featuresWs......EE- N NE  $ $&M&M&M&MZ=N=Z&M&M&M N N N N  rq)r)r^rrrr,rrrrrrrrrrrrfrrpropertyrrrrrorqrmrrs OOO,1EBX,Y,Y,YM)YYY37 (4.7779=&===<@)8D>@@@59"HTN999!%K#%%%%)OXc]))).%.%.%.%`^^X^^^X^!!X!!!X!!!rqr)maxsizecddlm} td|ji}|d|d}}n#t$rd\}}YnwxYw||fS)Nr WposDaemoncommandaccelerate_wp_premiumaccelerate_wp_cdnFF) clwpos.daemonr r&DAEMON_GET_SUPPORTED_SUITES_BY_LICENSEr5)r suites_statuses_by_licenseawp_premium_statusawp_cdn_statuss rm.get_suites_status_from_license_daemon_fallbackras(((((( :%7:L & & " /II`.a.HI\.]+ :::-9*NNN: ~ --s&/AAcddlm}m}m}t jst \}}nt\}}|j||j||j|i |dS)Nr)rrCDNSuiteT) rrrrrrget_suites_status_from_licenserrr)rrrrrrs rmis_feature_supported_by_licenserrsIIIIIIIIII :<<^-K-M-M*NN-[-]-]*N- ~.  c% rqcddlm}t}|D]:\}}|jD]-}|jrt |r||.;|S)Nr@r)rrrrFfeatures IS_BILLABLEradd)rr suite_name suite_item suite_features rmget_supported_featuresr~s******","2"2"4"466 J'0 6 6M , 60OPZ0[0[ 6"&&}555 6 rqc ddlm}m}m}m}m}t dd}g}g}|j|j|j|jfD]W}tj t|s-| || |Xt| ||t|tt!gS)zw Return default content of /opt/clwpos/public_config.json. This file is accessible by all users on server. r@)AWPSuiterrrSUPPORTED_SUITESrr)rrrrrr)rr!rrrr"r:rrrrr!rNrGrr.r) r!rrrr"is_icon_hiddenrrrs rmget_default_server_wide_optionsr$s `_____________ZZ))*?NNNNN #X]HM;CST%%w~~nU344  e$$$e$$$$ $$%%.// 6 8 899    rqcddlm}m}m}m}t \}}t j||||gdd||g}d|DS)zY Get list of supported suites taking into account license and status on CLN. r@)r!rrrTcg|] }|j Sror)r9rs rmrSz(get_supported_suites..s + + +5EJ + + +rq)rr!rrrr itertoolscompress)r!rrris_awp_premium_allowedis_awp_cdn_allowedsuitess rmget_supported_suitesr,s 2P1Q1Q..   <;7 t');<F , +F + + ++rqctdx}}tjtrM t }n#t $rYdSwxYw|d|}|d|}||fS)NTrr r)r*)rrrr r&_get_jwt_payloadr#r)r)r*jwts rmrrs2Fd2S2S2SS/ w~~())O "$$CC&   << "%)ACY!Z!Z WW%9;MNN !#5 55sA AActt} t|d}n,#t$r}t dtd|d}~wwxYw|S)z1 Read jwt, verify it and return payload. T) verify_expz)Unable to detect edition from jwt token: z-. Please, make sure it is not broken, error: N)r$r&r%r(r#)tokenr/rjs rmr.r.s ' ( (EY4000 YYY%'XRd'X'XTU'X'XYY YY Js( AA  Acft|jtr|jStdi|jS)Nro)rcrr)server_wide_optionss rmget_whcms_server_wide_optionsr5s:%35KLL1"00 ! F F$7$E F FFrqcb ddlm}t}tjt s|Sdh tt d5}|} tj |}dD]}||vr| |}t||}ttt|tt|t|z}t#||||j fd|Dt+||_ t/} |jddD] } | | vr|j| !n#t4$r d|_YnwxYw|cdddS#tjj$r8} t;t=dt?| d t i d} ~ wwxYw#1swxYwYdS) zL Gets server wide options which apply as defaults for all users r@rrr)rrrc$i|] \}}|v || Sroro)r9rArBnon_overridable_fieldss rmr;z+get_server_wide_options..s7-Q-Q-Qda019O0O0O./0O0O0OrqNzZFile is corrupted: Please, delete file %(config_file)s or fix the line provided in details config_filer) rrr$rrr!rMrr-rloadsrgetattrr.sortedr intersectionsetattr__dict__rrFr5rr,rremovePermissionErrordecoderJSONDecodeErrorr5rRrf) rdefault_optionsfcontent configurationoption_to_mergesuites_from_configsuites_from_defaults merged_valuesserver_suites_allowedrerrr9s @rmrrs +*****577O 7>>. ) )23 nc " "*9a&&((' 9"&*W"5"5M$\ I I"-77%2%6%6%G%G"'.'P'P$!%VC0DtC&M(M((4 S__(E(EHGHG1G-H-H&I&I!J!J -HHHH  $ + +-Q-Q-Q-Qm>Q>Q>S>S-Q-Q-Q R R R,I/,Z,ZO ) G(<(>(>% -=aaa@GGE$999'8??FFFG # 8 8 848000 8#I*9*9*9*9*9*9*9*9J|+ 9 9 9ABBC&7 999 9 9K*9*9*9*9*9*9*9*9*9*9sUH$*DG1F0?1G0GGGGH!)3HH!!H$$H(+H(c#Ktjtst dtdt }|Vt t5ttd5}tj t||dddn #1swxYwYddddS#1swxYwYdS)z1Set icon visibility in clwpos public options filez6Can't write public options as configuration directory z does not existwN) rrr rHrrrrMrrdumpr)public_config_datarFs rmwrite_public_optionsrSsH 7>>. ) )  d^ d d d   122  n % %11  % %1)* &+,,a000111111111111111111111111111111111s6%C;#B* C*B. .C1B. 2CC Cc t}d|vr |r ||dd<tjdt|t|dt st tjsHtj |fddddttj tjd|Stj dkr tt!d |z t#|trt$d z|z}n t$d g|z}tj |fttj tjddddd |S)z Wrapper for subprocess to enter cagefs do not enter cagefs if: - CloudLinux Solo - if process already started as user in cagefs envLANG*Executing command: %s with environment: %sTzutf-8replace)rrencodingrb preexec_fnrzInternal error: command %s must not be run as root. Please contact support if you have questions: https://cloudlinux.zendesk.comraz --no-io-and-memory-limit --no-io-and-memory-limit)rZrrrYrb)r?rWrjrfrr;r>r=CAGEFSrrr3rrgetegidr5r rcrG)r rilocalewith_cagefs_enters rmrun_in_cagefs_if_neededra&s$ % %F 6 &u f L=WVZZ&&''))){{(4W^DD(~g(#'-1'.%.)/ bjll)K)K (( !' (( ( :<<1  G-M%N%NPW%XYYY Y gs # # Z 14P PSZ Z  !24N ORY Y ~/()/ bjll)K)K#'-1'.%. (( !' (( (rqcr t|S#tj$rYdSwxYw)z Returns uid for user N)rget_uidNoSuchUserExceptionrs rm uid_by_namereOsBwwt$$$  $tts #66cD t|S#t$rYdSwxYwrz)rre)uids rm name_by_uidrhXs7"3''' tts  c eZdZdZddZdZdZdedeefdZ dd Z dd Z dd Z ded e efdZdZdedeed efdZedZddZdZdedeed efdZdede ed efdZdede ed efdZdS) PhpIniConfigz> Helper class to update extensions in php .ini files. Nc4||_tjd|_tjd|_tjd|_|pt jt|_ td|jj df|_ dS)Nz-^;\s*extension\s*=\s*(?P\w+)\.soz,^\s*extension\s*=\s*(?P\w+)\.soz1^\s*;?\s*extension\s*=\s*(?P\w+)\.soz/var/cagefs/*/*/etc/cl.php.d/c8|ddS)Nrr)split)rs rmz'PhpIniConfig.__init__..ms4::c??1#5rq)ruser) rrecompiledisabled_patternenabled_pattern extensionrWrXr^r]rrwildcard_ini_user_locations)rgr custom_loggers rmrwzPhpIniConfig.__init__cs& " +[ \ \!z*YZZ$XYY#Bw'8'B'B  Sd6F6QSS55 7 7 7, (((rqc |ddddS#t$r4}|jd|t |Yd}~dSd}~wwxYw)z- Parse .so extensions safely =r@z.sorz4Cannot parse extension name from line: %s, error: %sN)rmrer]r[rf)rgr&rjs rm_parse_extension_namez"PhpIniConfig._parse_extension_nameps ::c??1%++E2215 5    K   V $ #A ( ( (44444  s36 A4)A//A4cztj|jj|}tj|sgSt |5}|}dddn #1swxYwYg}|D]/}||}|s| |0|Srz) rrrrdirr r readlinesryrG)rgini_path full_pathrF ini_contentmodulesextraw_module_names rmget_ini_contentzPhpIniConfig.get_ini_content|sGLL!1!5x@@ w~~i(( I )__ (++--K ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( , ,C"88==O"  NN? + + + +sA<<BBrrctj|jj|}tj|s|||ddS|||dS)NFr )rrrrr{r _write_modulesenable_modules)rgrrr~s rmcreate_custom_inizPhpIniConfig.create_custom_inistGLL!1!5t<< w~~i(( /    75  A A A A A   g . . . . .rqc.|rztj|jj|}tj|r1|jd|tj|| dgddS)NzCustom ini to be removed: zacceleratewp.iniT)rA) rrrrr{r r]r[raupdate_user_ini)rgrall_inir~s rmremove_custom_inizPhpIniConfig.remove_custom_inis  % T%5%94@@Iw~~i(( % !!"Jy"J"JKKK )$$$ /DAAAAArqFc |jD]`}t|d}|D]F} ||||||#t$r|jdYCwxYwadS)Nrz&Error updating single acceleratewp.ini)rur_update_single_inirer]rd)rg ini_filenamerrAlocation cagefs_pathsdir_paths rmrzPhpIniConfig.update_user_inis8  H &!122L(  ++HhW]^^^^ K))*RSSSH   s>$A%$A%c |d|}tj||}t|5t 5|rOtj|r/|jd|tj|n5| ||tj|dddn #1swxYwYddddS#1swxYwYdS)Nroz#Custom user ini: %s will be removedr) rrrrrr r]r[rar)rgrrrrrArrs rmrzPhpIniConfig._update_single_inis#8F#H--w||Hl33 X & & P P P P P7>>$''$K%%&KTRRRIdOOO##D'"'..:N:N#OOO P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P Ps7C;BC# C;#C' 'C;*C' +C;;C?C?rctt|d5}fd|DcdddS#1swxYwYdS)zU Return enabled modules. :param path: full path to .ini file r7ch|]I}j|j|dJSN module_namersmatchgroupr9r&rgs rmrz0PhpIniConfig._enabled_modules..s[EEEd+11$77C(..t44::=IICCCrqNrrgrrFs` rm_enabled_moduleszPhpIniConfig._enabled_moduless $__ EEEEEVWEEE E E E E E E E E E E E E E E E E E E -11ctt|d5}fd|DcdddS#1swxYwYdS)Nr7ch|]I}j|j|dJSr)rtrrrs rmrz0PhpIniConfig._extensions_list..sV???~++D11=N((..44]CC===rqrrs` rm_extensions_listzPhpIniConfig._extensions_lists $__ ?????PQ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rc$tj|jj|}tj|sdS|jd|t|}|r| ||dS)z Enable specified modules in .ini php file. :param path: path to .ini file related to php directory :param modules: list of modules that should be enabled FzEnable such extensions: T) rrrrr{r r]r[rr)rgrrr~modules_to_enables rmrzPhpIniConfig.enable_moduless GLL!1!5t<< w~~i(( 5 >W>>???LL  >    +< = = =trqcd|dS)z- redis -> extension=redis.so z extension=z.so ro)rs rm_format_as_ini_extzPhpIniConfig._format_as_ini_exts *F))))rqTc  g}jd||rt|}t|5}|D]U t fd|Dr"jd d|d@| V dddn #1swxYwYt|}d|vr|d|D]I} |}jd |||J|rEjd |td ||d d dSdS)Nz,Such extensions are required to be enabled: c3FK|]}|vVdSrz)r)r9rr&rgs rmr>z.PhpIniConfig._write_modules..s6]]C4223774?]]]]]]rqzSkip z, z will be added furtherredisc,|dSNr)endswith)xs rmrnz-PhpIniConfig._write_modules..sajj.A.ArqkeyzAppending lines to be written: zPath to write: r*T) copy_owner) r]r[rrr|rErGr=sortrrr) rgr~rr  new_ini_linesrFsorted_modulesrextension_liner&s ` @rmrzPhpIniConfig._write_moduless  \IZ\\]]]  / #$5 6 6 i /AKKMM//D]]]]]K\]]]]]! ))*c$*c*c:K*c*c*cddd !((.... / / / / / / / / / / / / / / / / 122 n $ $   $A$A  B B B$ 1 1F!44V<B>c tj|jj|}tj|sgSt ||}|j d|d||S)zH Reads .ini file and loads all required extensions zRequired extensions for z are: ) rrrrr{r r.rr]r[)rgrr~required_moduless rmget_required_modulesz!PhpIniConfig.get_required_modulessGLL!1!5t<< w~~i(( I 5 5i @ @AA STSSAQSSTTTrqctjjj|}tj|sdSt ||zrlt|5}fd| D}dddn #1swxYwYtd||ddS)z Disable specified modules in .ini php file. :param path: path to .ini file related to php directory :param modules: list of modules that should be disabled Fc<g|]}|Sro)_disable_module)r9r&modules_to_disablergs rmrSz0PhpIniConfig.disable_modules..s:!<!<!<%)"&!5!5dr=r]rr5r rFrargvr;r<rrGr?rWrjrfrPopenrr communicaterr)rocmdrUps rm_run_clwpos_as_user_in_cagefsr-sI &gn 5 5    <G1%%  %)x|$&)hqrrl3[[/Y[[AAA "<=H  )++ ,C L=s3xxSRRRSZsy  " " "AMMOOOHQ\rqcZeZdZdZdeddfdZd dZd dZdefdZ e de fd Z dS) RedisConfigurePidFilezm Helper class that provides methods to work with pid files of php redis configuration processes. php_prefixrNcX|d|_tt|j|_dS)Nz-cloudlinux.pid)_pid_file_namerrHr)rgrs rmrwzRedisConfigurePidFile.__init__Us+!+<<<)<== rqc|jd5}|tt jddddS#1swxYwYdS)NrP)rrwriterfrgetpidrgrFs rmcreatezRedisConfigurePidFile.createYs Y^^C  &A GGC $$ % % % & & & & & & & & & & & & & & & & & &s4AA #A cn|jr|jdSdSrz)ris_filerars rmrAzRedisConfigurePidFile.remove]s< 9      I         rqc4|jSrz)rrrs rmr zRedisConfigurePidFile.existsasy  """rqc6|sdS|j5} t|cdddS#t $rYnwxYw dddn #1swxYwYdS)N)r rrintr-striprrs rmpidzRedisConfigurePidFile.pidds{{}} 2 Y^^    16688>>++,,                             rs.B2A11 A>;B=A>>BBBrN) r^rrrrfrwrrAr,r rrrrorqrmrrOs >3>4>>>>&&&&#####SXrqrrc#Kt|} |dV|dS#|wxYw)za Context manager for creating pid file of current process. Removes pid file on exit. N)rrrA)rpid_files rmcreate_pid_filerps_ %Z00H s AAct|}tjdkr|S t j|j}d|vS#ttj f$rYdSwxYw)z Find out if PHP redis configuration process is running. Based on looking for presence of pid files. For root also checks process existence. r enable_redisF) rrrr psutilProcessrrr NoSuchProcess)rrprocesss rm"is_php_redis_configuration_runningr~s %Z00H z||q   ...// , -uus.A++BBc*ttS)zE Find out if alt-PHP redis configuration process is running. )rrIrorqrm&is_alt_php_redis_configuration_runningrs .n = ==rqc*ttSzD Find out if ea-PHP redis configuration process is running. )rrJrorqrm%is_ea_php_redis_configuration_runningrs .m < < ? ??rqcVtptp tS)za Find out if redis configuration process is running for any PHP (ea-php or alt-php). )rrrrorqrmis_redis_configuration_runningrs. 2 3 3 6 0 2 2 6 3 5 56rqnew_userold_userctj5}|}dddn #1swxYwYfd|D}td|jddS)z; Replace user's wpos directory path in redis.conf. NcPg|]"}|jj#Sro)rXrr9r&rrs rmrSz%update_redis_conf..s:?C X&(9::rqr*r+)rrr|rr)rrrFredis_conf_lines updated_liness`` rmupdate_redis_confrs h! " ")a;;==)))))))))))))))GWMBGGM22H4GOOOOOs 8<<c2 tj|}n9#t$r,}td|d|tjYd}~dSd}~wwxYwfd|D}t d|tj|ddS)z< Replace user's redis socket path in wp-config.php. z=Error occurred during opening wp-config.php located in path "z": )rNcfg|]-}j|vr |jjn|.Sro)rrXrs rmrSz$update_wp_config..sU   D ( ( X*H,ABBB.2rqr*r+) r4r-rrrrrrr)r$rrr0rjrs `` rmupdate_wp_configrs#.55  6"-662366")++ & &D 99;;rqcDtgdd\}}}|dkrdSdS)z` Detect CL WPOS daemon presence in system :return: True - daemon works / False - No ) /sbin/serviceclwpos_monitoringstatusTreturn_full_outputrFr2)rrRs rm_is_monitoring_daemon_existsrs8##S#S#ShlmmmJ1Qu 4rqctjd|tgdd\}}}|stddgd\}}}|||fS)z5 Update systemd unit file and reload systemd //usr/share/cloudlinux/clwpos_monitoring.service)/usr/bin/systemctlenable --no-reloadclwpos_monitoring.serviceTrr  daemon-reload)rfcopyr2)systemd_unit_fileretcoderrs rm$_update_clwpos_daemon_config_systemdrsx KACTUUU)*v*v*v=ACCCGVV p"-/C_.Ujn"o"o"o FF ""rqctj}t|d5tfddD]}|| dddn #1swxYwY|S)Nrbc.dS)Ni)r-)rFsrmrnz_sha256_file..s!&&"5"5rqrq)hashlibsha256riterr hexdigest)rhchunkrFs @rm _sha256_filersA dD  Q5555s;;  E HHUOOOO  ;;==s,AA"%A"path_apath_bc tj|}tj|}|j|jkrdSt|t|kS#t$rYdSwxYw)z Best-effort content comparison. We use it to decide whether shipped systemd unit needs to be copied into /etc (and thus requires daemon-reload). F)rrcst_sizerr)rrst_ast_bs rm_files_identicalr$sr wvwv <4< ' '5F##|F';';;; uus8AA A*)A* service_namec>tdd|gd\}}}|dkS)Nr z is-enabledTrrr)r%rrRs rm_systemd_service_is_enabledr's3!5|\ R37999MGQ a<rq unit_namec$tdddd|gd\}}}|dkrdS|}|d krdSd |vr-|d d \}}|}|}|d krdS|d kS) z Returns: - True/False if systemd reports it explicitly - None if the property is unsupported/unknown (depends on systemd version) r showz-pNeedDaemonReloadTrrNr*rxr@yes)r2rrmlower)r(rrrRr{rhss rm!_systemd_unit_needs_daemon_reloadr/ s % vt-?KGVQ!||t LLNNE {{t e||S!$$3  KKMME {{t E>rqris_module_allowed_on_servercd\}}}dtjvrtgdd\}}}n|rt|\}}}|stgdd\}}}|||fS)z4 Install WPOS daemon to system and start it )rNNel6)z/sbin/chkconfigz--addrTr)rrstart)platformreleaser2r)rr0rrrs rm_install_daemon_internalr6(s,GVV  """""-._._._AE#G#G#G ' ^'KK\&]&] #GVV G"-.].].]AE#G#G#G FF ""rqctptjt}d}d}tj|rd}t|| }t| }t|}|p|du}|duo| } t} | d| |||| d\} } } |r)| dt|\} } } ny|r/| d |td d d |gd \} } } | s/|r-| dtd dgd \} } } n| r| d| r| | | fStrdSt||S)a Install WPOS daemon to server if need: - if daemon already present - do nothing; - on CL Shared Pro install daemon if module allowed On solo and if /etc/systemd/system/clwpos_monitoring.service present it will be updated always We do not need restart installed daemon here, it's done in rpm_posttrans.sh :param is_module_allowed_on_server: True/False z-/etc/systemd/system/clwpos_monitoring.servicer rTNzinstall_monitoring_daemon: unit_exists=1 daemon_exists=%s needs_unit_update=%s needs_enable=%s need_daemon_reload=%s need_daemon_reload_unknown=%s)rr*r*zPinstall_monitoring_daemon: updating unit file from shipped and reloading systemdz2install_monitoring_daemon: enabling %s (no-reload)r r r rzQinstall_monitoring_daemon: running systemctl daemon-reload (NeedDaemonReload=yes)rzXinstall_monitoring_daemon: skipping daemon-reload (NeedDaemonReload unsupported/unknown))r]rWrXr^rrr r$r'r/rrjrr2r6)r0rkrshipped_unit_filer(needs_unit_update needs_enableneed_reload_flagneeds_daemon_reloadneeds_daemon_reload_unknown daemon_existsrrrs rminstall_monitoring_daemonr?;s  0W&x00DGI w~~'(()+/ 01BDU V VV6yAAA &XGXCX#466   R     '   #,  v IIh i i i&JK\&]&] #GVVV  NPYZZZ*5)8]IN'++++' v2 v mnnn*5)?;'++++'- v tuuu  +FF* *#%%y #$57R S SSrqcdd|di} t|}n#t$rYdSwxYw|dS)Nr zget-z-statusFr)rr5r)servicecommand_get_service_status_dict daemon_results rmget_status_from_daemonrDysd'02I2I2I2I&J#*+JKK uu   X & &&s  ((c tdSrrDrorqrmredis_is_runningrG !' * **rqc tdS)N litespeedrFrorqrmlitespeed_is_runningrKs !+ . ..rqc tdS)NnginxrFrorqrmnginx_is_runningrNrHrqc tdS)N apache2nginxrFrorqrmapache2nginx_is_runningrQs !. 1 11rq attributecddlm}|t}tj|d} t |5}tj||cdddS#1swxYwYdS#ttj f$r6}tj d|ttdd}~wt$rttdwxYw)z7 Return attribute's value from info.json file. r)get_admin_config_directoryz info.jsonNz,Error during reading of "info.json" file: %szFailed to retrieve data about php version which is currently used. Daemon is not available and cache data is malformed, please try again and contact your administrator if the issue persists.zFailed to retrieve data about php version which is currently used. Daemon is not available and cache data is not available. Contact your administrator if the issue persists.)rrTrrrrrrloadrrDrWrdr5rRr)rRrTadmin_config_dir info_jsonrFrjs rm_get_data_from_info_jsonrXsmA@@@@@11(**== -{;;I P )__ +9Q<< * + + + + + + + + + + + + + + + + + + d* +QQQJANNNOPPQQ Q PPPNOOPP PPs;BA5( B5A99B<A9=BC31C  *C3cdt}tjr tj}||Srz)rrrr4r5)rrXs rmdrop_permissions_if_neededrZs/G z||)( 78  rqrrrcddlm}|||vrdnd} t|j|dd}n#t $rd}YnwxYw|rd}|S)Nrractiveno)r rpendingF)rr rr!DAEMON_GET_UPGRADE_ATTEMPT_STATUSr5)rrrr subscription_status is_pendings rmget_subscription_statusrbs((((((&-1A1E1Ee1L1L&L&L((RV '!C) )       (' sA AAc\d\}}} tt}n4#ttf$r ddtdfcYSwxYw t |nG#t j$r d\}}}Yn0t j$r d\}}}Ynt j $r d\}}}YnwxYw|||fS)z JWT token check. Mostly copied from cllib, but with some accelerate-wp tunes, including: - clsolo, cladmin tokens are now valid - no need to check for shared, because our tools just don't work on shared )TOKNFzJWT file {} read errorN)FzJWT token issuer is invalidN)FzJWT token expiredN)FzJWT token format errorN) r$r'rrformatr%r)InvalidIssuerErrorExpiredSignatureErrorr() success_flag error_message token_strings rmjwt_token_checkrks 1A-L-W 9:: W WWW.556OPPRVVVVVWZ<     (___4^1 m\\\  +UUU4T1 m\\\  ZZZ4Y1 m\\\Z  44s-.A AA""B&9B&B&%B&cd}tj|sdSt|5}|cdddS#1swxYwYdS)Nz+/usr/share/cloudlinux/accelerate-wp.version)rrr rr-r) version_filerFs rmget_accelerate_wp_versionrns@L 7>>, ' 't l   qvvxx~~                  s&A&&A*-A*c|stjdkr-t|ddd}t| St |S)zE Returns True/False whether target user is owned by reseller r)reseller)cpuserkeyls)rrr.r/)is_user_owned_by_reseller_daemon_fallback)r force_as_root user_owners rmis_user_owned_by_resellerrvsX C ))8=AAA!DQG J''''8BBBrqc@ddlm}|ftj} t j|j}n#t$rd}YnwxYw||kr ttdd|i td|j id}n#t$rYdSwxYw|S) NrrzpRefusing to resolve reseller ownership for user %(username)s: a non-root caller may only query its own identity.rrr is_owned_by_resellerT) rr rrrrrrr5r r DAEMON_IS_USER_OWNED_BY_RESELLER)rr  caller_uid requested_uidrxs rmrsrss(((((( Z\\  !L229MM ! ! ! MMM ! J & &!cdd#X.  1:F    !  " tt s!7 AA0B BBctjdkrt|St|}i}|D]}|j||j<t|d}|D]'tfd|Dr |cS(tj |jS)Nrc,|dS)Nr)count)ds rmrnz%get_username_by_uid..!sQWWS\\rqrc3TK|]"}|k|dzV#dS)rN)r)r9rs main_homes rmr>z&get_username_by_uid..$s>aatW`O`O`4??9s?33O`O`O`O`aarq) rrr0r get_pw_by_uidrrr=rrErgetpwuid)rgpwd_list home_dirsuser_pwd sorted_dirsrs @rmrrs z||q',,,77((--   : :H)1)9Iho & &Y^^--3I3IJJJ $ , ,Iaaaa aaaaa , ++++ ,|C  ((rqcddlm}tjdkr |Sddlm} t d|jidS#t$rYdSwxYw)Nr)is_wp2_environmentrr is_wp2F) rYrrrrr rDAEMON_IS_WP2_ENVIRONMENTr5)rr s rmis_wp2_environment_safer)s111111 z||q!!###,,,,,, %y*2V&WXXYab b   55 sA AAr )r@)rrzr)r)rrU)rr) __future__rr4rr|rhr'rrWrrprfrcrrrrrtypingrrrrrrglobrenumrr rR urllib.parser r r r packaging.versionrrr functoolsrrpathlibrrrrrrrrrr4secureiorrclcommon.cpapi.cpapiexceptionsrclcommon.clpwdrrclcommon.clcaptainr clcommon.lib.cleditionr"r#clcommon.lib.jwt_tokenr$r%clcommon.lib.constsr&r'r/r(r) cllicenselibr*rYr+r,r-r.r/r0clcommon.utilsr1r2r3clwposr4clwpos.cl_wpos_exceptionsr5r6r7r8r9clcommon.ui_configr:clcommon.clcagefsr;r<clcommon.constr=r>rZr?logsetuprAclwpos.constantsrBrCrDrErFrGrHrIrJrKrLrMrNrOrP socket_utilsrQrRuser.website_check.errorsrSclwpos.scoped_cacherT TYPE_CHECKINGclwpos.php.baserUr]rprrsr,rrrr_rrrr struct_passwdrrrfrrrrrrrr#r2r6rLrvrzr~rrrerrrrrrrrrrrrrr$r,rr.r5rrSrarerhrjrrrrrrrrrrrrrrr$r'r/r6r?rDrGrKrNrQrXrZrbrkrnrvrsrrrorqrmrs'&&&&&  0000000000  &%%%%% %%%%%%&&&&&&&&//////////==============;;;;;;;;33333311111111$$$$$$87777777MMMMMMMM&&&&&&&&&&&&&&=<<<<<<<<<%%%%%%%%(''''';;;;;;;;""""""555555666666######$XWWWWWWW888888////// $###### B33333$*333*$4&D4S* 5 5 5D 5 5 5 54     444444&S->&&&&)))&sc 3!%,,,#,,,,,#&&&&&&&*__(4.____B8DI8888D :c :d : : : :5#5$55550^C^^^^#53#54#5#5#5#5L\\\\~    d dsCx d d d dC8C=2' t' ' ' ' T     )      x}        N N N N 4 E#s(O    99$9999 """AAA AAAAAAA A  `!`!`!`!`!`!`! `!F 4 . . .   ):>,,,( 6 6 6   G:PGGGG 69!269696969r1n->?1111"&(&(&(R LLLLLLLL^DB      3 4     >>>>>=t====@$@@@@66666 P PH P P P P PX#XXXXRVXXXX& d     #uS#s]?S # # # #ss S # $    cd $6##RV#[`adfiknan[o####&;T4;TE#sTW-DX;T;T;T;T|'''+$++++/d////+$++++22222PPPPPP.d3,555.    4CCCCCC 4     <)))" 4     rq