9Vje&dZddlZddlmZddlmZddlmZddlm Z ddl m Z d d l m Z mZd d lmZmZd d lmZd d lmZd dlmZmZd 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)validate_docrootvalidate_docroot_no_symlinks) 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_isolation1s ##G,,,,,rc:|j|dS)z-Enable per-domain PHP selector for a docroot.N)rr"r#s renable_phpselectorz*JailMountsConfigBuilder.enable_phpselector5s "&&w/////rct|j}|j}|j|j}}t |j}|d} t||d}n4#t$r'}tj d|j|d}Yd}~nd}~wwxYwg} t|j tD] } tj|| } t#| d|d} t%| ||| } t'|| }|| |r"| 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. z/.clwposTz+Skipping .clwpos bind mount for user %s: %sFN)keyz/home) root_pathtarget persistent)active_docroottreeuidgid)r0r1)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_gidrrr ValueErrorloggingwarningsortedrlenr full_website_pathrrr add_overlaymountrBINDtyper4r,options close_overlayr" USER_MOUNTSrget_website_idappendrenderjoin)rpwhomedirr0r1r/awp_path awp_path_safeexcgenerated_configsrsplit_storage_base home_overlaydocroot_mounts jail_configrAs rbuildzJailMountsConfigBuilder.build9sCWW # #DI . .)9biS"$"455''' " (7 ; ; ; MM " " " O=ty#   "MMMMMM  "d53???D BD BG!+!=gw!O!O -/666wSWL 4&TsN777K  # #L 1 1 1 S""9>8XzRRR( 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&&t,,3I 5 ; ; = =>> . . . W % % % () < < < < . . . OIc   &f------  .)//11%%G$$$$.** +F3GG    O=v F F F H    )))).,, +F3GG    O=v F F F H  ""7++++ ]]__F!!4e!<<<#&-..4D0E0EvNNNNNsNA00BB#D D1 D,,D1*E33FF8GG#"G#)rYr;pathlibrclcommonrclcommon.cpapirclcommon.cpapi.cpapiexceptionsriorr r docroot_validationr r rTr mount_configrmount_orderingrr mount_typesrrrZ UserConfigrpr[rrr|sq &&&&&&666666 NNNNNNNN$$$$$$,,,,,,FFFFFFFF""""""D,D,D,D,D,D,D,D,NMO3MOV5F5MMORVMOMOMOMOMOMOr