9VjY4dZddlZddlZddlZejeZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd efdZdZdZdZdZdZdZdZdZdZdS)a+ CLOS-4642: dedicated per-domain lsphp pools for standalone LiteSpeed (LSWS). Background ---------- On standalone LiteSpeed under cPanel, PHP runs as ONE shared lsphp pool per Linux user (the ``APVH_`` external app), and LiteSpeed multiplexes every vhost of the account over it. CageFS per-website isolation masks sibling docroots with a per-website mount namespace, and a process can live in only ONE namespace at a time -- so a single shared worker cannot serve several isolated docroots correctly (addon vhosts return 500, or nothing is masked). Apache + mod_lsapi is unaffected: it already runs a per-vhost lsphp pool and passes a per-vhost DOCUMENT_ROOT, so the existing startup site-isolation constructor works there. Fix --- Make LiteSpeed run a DEDICATED lsphp pool per isolated domain so each pool enters its own website namespace: * ``DedicatePhpHandler on`` in a per-vhost cPanel *userdata* include (``/etc/apache2/conf.d/userdata/{std,ssl}/2_4///``). cPanel always emits a per-vhost ``Include`` for that directory, so the directive survives every ``httpd.conf`` regeneration (account/domain changes, EA4 updates). * ``DOCUMENT_ROOT=$DOC_ROOT`` in LiteSpeed's global ```` so each dedicated pool receives its own document root at spawn time; the alt-php lsphp startup constructor (CLOS-4506) then re-execs the worker into the matching website namespace. ``$DOC_ROOT`` is expanded per vhost by LiteSpeed. Every public helper here is a strict NO-OP unless the active web server is standalone LiteSpeed on a cPanel server. Nz/usr/local/lsws/bin/lswsctrlz%/usr/local/lsws/conf/httpd_config.xmlz//usr/local/cpanel/scripts/ensure_vhost_includesz/etc/cpanel/ea4/paths.confz/var/cpanel/userdata)z$/etc/apache2/conf.d/userdata/std/2_4z$/etc/apache2/conf.d/userdata/ssl/2_4zcl_siteiso.confz9 DedicatePhpHandler on zDOCUMENT_ROOT=$DOC_ROOTz' DOCUMENT_ROOT=$DOC_ROOT returnc* ddlm}n#t$rYdSwxYw|sdS ttd5}|D])}|drd|vccdddS* dddn #1swxYwYn#t $rYnwxYwdS) a True only on a cPanel server whose ACTIVE web server is standalone LiteSpeed. Apache+mod_lsapi, Plesk and DirectAdmin return False, so every helper below becomes a no-op there. Checking that lswsctrl merely exists is NOT enough: LiteSpeed can be installed but switched out for Apache. cPanel records the active server's control binary in ea4/paths.conf (bin_apachectl -> lswsctrl when LiteSpeed is active, -> apachectl when Apache is), so use that as the source of truth. r) is_cpanelFutf-8encoding bin_apachectllswsctrlN) cldetectlibr ImportErroropenEA4_PATHS_CONF startswithOSError)rfhlines Vopt/cloudlinux/venv/lib/python3.11/site-packages/clcagefslib/webisolation/litespeed.pyis_litespeed_activerFsF))))))) uu 9;;u .7 3 3 3 .r . .???33.%--- . . . . . . . .. . . . . . . . . . . . . . . . .      5sL BA7 B)A7+ B7A;;B>A;?B BBc|d}g}tjt|} tj|}n#t $r|cYSwxYw|D]}|dvs|drtj||}tj|s] t|dd5}|D]u} | dr^| dd d  d} | |kr| |nvd d d n #1swxYwY#t $rYwxYw|S) a Map a document root to the cPanel vhost key(s) that serve it. cPanel stores one userdata file per vhost in ``/var/cpanel/userdata/`` keyed by the vhost ServerName (an addon domain ``foo.com`` is served by a vhost like ``sub.maindomain.com``). The per-vhost include directory is keyed by that same name, so resolve the key by matching ``documentroot:``. /)maincache)z.cache_SSLrreplace)rerrorsz documentroot::N)rstripospathjoinCPANEL_USERDATAlistdirrendswithisfiler rsplitstripappend) user document_roottargetkeysuser_direntriesnamer rrdrs r_vhost_keys_for_docrootr1as ! !# & &F Dw||OT22H*X&&   $ $ $ 6H(I(I $ w||Hd++w~~d##   dWY??? 2D77!ZZQ//288::AA#FF<< KK---                    H  KsHA A"!A"E)A9E E)E E)#E $E)) E76E7c.fdtDS)NcRg|]#}tj|$S)rr r!).0rootr) vhost_keys r z!_include_dirs..s+ S S SDBGLLtY / / S S S)USERDATA_INCLUDE_ROOTS)r)r7s``r _include_dirsr;s" S S S S S`` so every dedicated per-domain pool spawns with its own document root. Idempotent; backs the file up before the first edit. Returns "added" if the env line was inserted (caller should reload), "present" if it was already there, or "failed" if it could not be ensured (read/parse/write error) so callers can avoid creating broken pools. rrNz'LSWS site-isolation: cannot read %s: %sfailedpresentz z0LSWS site-isolation: not found in %s rz .clos4642.bakz .clos4642.tmpr>z)LSWS site-isolation: cannot update %s: %sadded)r LSWS_HTTPD_CONFIGreadrrCrDDOC_ROOT_ENV_MARKERfindDOC_ROOT_ENV_LINElenrr existsrAr) rcontentrFtagidxnl new_contentcutbackuptmps r_ensure_docroot_envrbs  #g 6 6 6 "ggiiG               @BSUXYYYxxxxxg%%y C ,,s  C byyIK\]]]x dC B RxxgrAvg&)::WR!VWW=MM CHHndsdmd*->>N  0F o -C w~~f%% "fcG444 "!!! " " " " " " " " " " " " " " " #sW - - - " HH[ ! ! ! " " " " " " " " " " " " " " " 3)**** BDUWZ[[[xxxxx 7sA9 A=A=A A;!A66A;1HF" H"F&&H)F&*H?G! H!G%%H(G%)H H=!H88H=ctjtrU t jtd|zgddn2#t $r%}td|Yd}~nd}~wwxYw t jtdgdddS#t $r&}td|Yd}~dSd}~wwxYw) zBRe-emit the user's vhost includes and gracefully reload LiteSpeed.z --user=%sFT)checkcapture_outputz5LSWS site-isolation: ensure_vhost_includes failed: %sNreloadz/LSWS site-isolation: lswsctrl reload failed: %s) rr rYENSURE_VHOST_INCLUDES subprocessrunrrCrD LSWS_CTRL)r)rFs r_rebuild_and_reloadrks  w~~+,,Y Y N1;3EF!&t = = = = = Y Y Y NNRTW X X X X X X X X YO 8,E$OOOOOO OOOH#NNNNNNNNNOs/!A A7A22A7;B C %CC c8tsdSt||}|std||dSt dkr#tdt |dS|D]}t||t|dS)a Give the vhost(s) serving ``document_root`` a dedicated lsphp pool so the worker can enter that website's CageFS namespace. No-op unless LSWS active. NOTE: this rebuilds the user's vhost includes and reloads LiteSpeed per call. Enabling many domains for one account in a single command therefore triggers several rebuilds; batching across a bulk enable is a possible future optimization (see CLOS-4642). NzLSWS site-isolation: no cPanel vhost serves docroot %s (user %s); per-site isolation will NOT take effect for it on LiteSpeed until a vhost exists (the worker stays in the shared per-user pool)rNzLSWS site-isolation: cannot ensure DOCUMENT_ROOT env in %s; not creating a dedicated pool for %s -- without it the worker falls back to the primary docroot and 500s addon vhosts) rr1rCrDrberrorrSrGrk)r)r*r,keys renable_dedicated_php_handlerros   "4 7 7D  J 4  ! ! ! ((  ; }  . . . ""tS!!!!r9ctsdSt}|D]'}|r#|t||(d}d}|r@t }|dkr$t dt|d}n|dkrd}|rJ|D]G}dt||D}td|Dst||d}HtD]} tj tj| |} n#t $rYBwxYw| D]} | |vrtj| || t"} tj| rK tj| d}e#t $r&} t d | | Yd} ~ d} ~ wwxYw|rt+|dSdS) a Make the user's dedicated-pool includes match exactly the given set of currently-isolated document roots: add includes for isolated docroots that lack one, and remove includes for vhosts whose docroot is no longer isolated. Robust to full teardown (empty list), docroots shared by several domains (kept while any sibling is still isolated), and docroots that no longer resolve (their stale includes are swept). No-op off standalone LiteSpeed. Reloads LiteSpeed only when something actually changed. NFTrNzyLSWS site-isolation: cannot ensure DOCUMENT_ROOT env in %s; not creating dedicated pools, only removing stale ones for %srRcXg|]'}tj|t(Sr4)rr r!r?)r5ds rr8z4reconcile_dedicated_php_handlers..s)YYY1RW\\!%566YYYr9c3TK|]#}tj|V$dS)N)rr rY)r5ps r z3reconcile_dedicated_php_handlers..s088Qrw~~a((888888r9rI)rsetupdater1rbrCrmrSr;allrGr:rr#r r!rr?rYrJrDrk)r)isolated_docroots keep_keysr0changed add_includes env_statusrnpathsr6vhostsvhostr rFs r reconcile_dedicated_php_handlersrsh  I@@  @   4T2>> ? ? ?GL (**  ! ! LLP!4 ) ) )!LL 7 " "G  CYY dTW@X@XYYYE88%88888 tS)))&[[ Z T4 8 899FF    H  [ [E !!7<<dE3CDDDw~~d## [[IdOOO"GG[[[NN#NPTVYZZZZZZZZ[  [ ["D!!!!!""s*%2D D%$D%8F F?F::F?ctsdSd}tD]}tj||} tj|}n#t $rYDwxYw|D]}}tj||t} tj|d}@#t$rYLt $r&}t d||Yd}~vd}~wwxYw|rt|dSdS)a Remove every dedicated-pool include for a user. Used on full isolation teardown (``--isolates-deny`` / ``--isolates-deny-all`` -> _cleanup_user_isolation), where individual docroots may no longer be resolvable. No-op unless LSWS is active. NFTrI) rr:rr r!r#rr?rJrKrCrDrk)r)removedr6 user_rootrrr rFs r!remove_all_dedicated_php_handlersr5sJ  G&WWGLLt,,  Z **FF    H  W WE7<< 52BCCD W $$    W W WJDRUVVVVVVVV W W"D!!!!!""s/A AA B$$ C0 C9CC)__doc__loggingrrh getLogger__name__rCrjrSrgrr"r:r?rBrUrWboolrr1r;rGrLrbrkrorrr4r9rrs<!!D   8 $ $ * ;I.(%P/>T6   FTTTRRRSSS+++\ O O O@8"8"8"v"""""r9