yXdZddlZddlmZddlmZddlmZddlm Z ddl m Z d d l m Z mZd d lmZd d lmZd d lmZmZd dlmZGddZdede jdzddfdZdS)z Builder for website isolation jail mount configurations. Collects user docroots and isolation settings, then generates the complete jail mount configuration. N)Path)ClPwd) userdomains) NoPanelUser) write_via_tmp)config jail_utils) MountConfig)IsolatedRootConfig)build_docroot_treeprocess_ordered_mounts) MountTypecZeZdZdZdefdZdeddfdZdeddfdZdeddfd Zdefd Z dS) JailMountsConfigBuilderz Builder for generating jail mount configuration files. Collects docroots and isolation settings, then generates the mount configuration string for the jail.c implementation. userc||_t|_t|_t|_dS)N)rset _all_docroots_isolated_docroots_phpselector_docroots)selfrs `opt/cloudlinux/venv/lib/python3.11/site-packages/clcagefslib/webisolation/jail_config_builder.py__init__z JailMountsConfigBuilder.__init__&s3 '*uu,/EE/2uu"""docrootreturnNc:|j|dS)z%Register a docroot path for the user.N)raddrrs r add_docrootz#JailMountsConfigBuilder.add_docroot,s w'''''rc:|j|dS)z&Mark a docroot as requiring isolation.N)rr r!s renable_isolationz(JailMountsConfigBuilder.enable_isolation0s ##G,,,,,rc:|j|dS)z-Enable per-domain PHP selector for a docroot.N)rr r!s renable_phpselectorz*JailMountsConfigBuilder.enable_phpselector4s "&&w/////rc"t|j}|j}|j|j}}t |j}g}t|j tD] }tj ||}t|d|d} t||||} t||} | | |d} | t$j| | d| D].} | | j| j| j| j/| | | t$jd ||jvr| t$jd d | t$jd d | t$jdtj|d | t$jdtj|d | t$jdtj|d || |d|S)z Generate the complete mount configuration. Returns: Configuration string in jail.c mount syntax. )keyz/homeT) root_pathtarget persistent)active_docroottreeuidgid)r.r/z/.clwpos)mkdir/z/etc/cl.selectorz /usr/selector)sourcer*z/usr/selector.etcz/etc/cl.selector/z/etc/cl.php.d/z /etc/cl.php.dz/var/.cagefs/website/z /var/.cagefs ) rget_pw_by_namerpw_dirpw_uidpw_gidrrsortedrlenr full_website_pathr rr add_overlaymountrBINDtyper2r*options close_overlayr USER_MOUNTSrget_website_idappendrenderjoin)rpwhomedirr.r/r-generated_configsrsplit_storage_base home_overlaydocroot_mounts jail_configawp_pathr<s rbuildzJailMountsConfigBuilder.build8sWW # #DI . .)9biS"$"455d53???D BD BG!+!=gw!O!O -/666wSWL 4&TsN777K  # #L 1 1 1"+++H   y~x: N N N( Z Z""5:u|U\5=YYYY  % %l 3 3 3 OOI13 7 7 7$444N+=* N+=. N+cz?XY`?a?a+c+c- N+`J4000%d++G $[%6%6 7 7 QSWXXX )//11%%G$$$$.** +F3GG    O=v F F F H    )))).,, +F3GG    O=v F F F H  ""7++++ ]]__F!!4e!<<<#&-..4D0E0EvNNNNNs6A00BB CC76C7D##EE)rRr^pathlibrclcommonrclcommon.cpapirclcommon.cpapi.cpapiexceptionsriorr r rLr mount_configr mount_orderingrr mount_typesrrrS UserConfigrhrTrrrssP &&&&&&666666 $$$$$$,,,,,,FFFFFFFF""""""p,p,p,p,p,p,p,p,f3O33OV5F5M3ORV3O3O3O3O3O3Or