a tU~hiã@sîdZddlZddlZddlmZddlmZmZmZddl m Z m Z ddl Z ddl Z ddlmZddlmZddlmZdd lmZmZdd lmZed œd d „Zdd„Zeedœdd„Zeedœdd„Zeeedœdd„ZedkrêeƒdS)zMain logic for fixpermséN)Úpartial)ÚrunÚPIPEÚCalledProcessError)ÚProcessPoolExecutorÚ as_completed)Ú CpanelPermMap)Ú CwpPermMap)Ú WP3PermMap)Ú parse_argsÚArgs)ÚIDCache)ÚrolecCs¸tjdkrdS|dvrdSttdtdd}|dkrZ|dd gƒj}t d |¡sPdSd }d }n0|d dgƒj}d|vrtdS|dd gƒj}d}d}d|vsšd|vrždSt  d|›d|›¡dS)z2Check if DSO is installed and modruid2 is disabledZsharedN)ÚCWPÚcPanelzUTF-8F)ÚencodingÚstdoutZcheckrz/usr/local/apache/bin/httpdz-Mz php\d+_modulezmod_ruid2 or mod_mpm_itkz7http://wiki.centos-webpanel.com/dso-php-handler-for-cwpz%/usr/local/cpanel/bin/rebuild_phpconfz --currentz SAPI: dsoz/usr/sbin/httpdz0ea-apache24-mod_ruid2 or ea-apache24-mod_mpm_itkzhttps://go.cpanel.net/EA4RecDSOzruid2_module (shared)zmpm_itk_module (shared)aPlease install the modruid2 Apache module. fixperms detected a security issue and exited. PHP DSO runs as the nobody user by default. In a shared hosting environment, this is a security issue. We strongly recommend that you install either the z¿ Apache module unless you have single-user system. If you use suPHP, you will add some security, but may experience performance issues on your server. For more information, see: ) ÚradsZIMH_ROLErrrrÚreÚsearchÚsysÚexit)rZrun_cmdZmodsZ good_modsZkb_urlZphp©rú#./usr/lib/fixperms/fixperms_main.pyÚcheck_dso_without_modruid2s8  ÿû ÷ÿrc CsŽtƒ}zt|jƒ}Wn<tyP}z$|j d|¡t d¡WYd}~n d}~00t|jƒt |j ƒdkr€|j dkr€t ||ƒn t ||ƒdS)z;Main program logic: iterate over each user and run fixpermsz%s. Cannot continue.éN)r r rÚKeyErrorÚloggerZcriticalrrrÚlenÚusersÚprocsÚparallel_executeÚserial_execute)ÚargsÚidsÚexcrrrÚmain9s   r&)r#r$c CsTd}t|jd"}g}|jD]Š}zt|||ƒ}Wn^ty}zFt|tƒs\|j t   ¡¡|j  t |ƒ¡d}WYd}~qWYd}~n d}~00|  |j¡}| |¡qt|ƒD]r}z | ¡Wq²ty"}zFt|tƒsî|j t   ¡¡|j  t |ƒ¡d}WYd}~q²WYd}~q²d}~00q²Wdƒn1s<0Yt |¡dS)z"Fork processes to handle each userr)Ú max_workersrN)rr rÚ get_perm_mapÚ ExceptionÚ isinstancerrÚdebugÚ tracebackÚ format_excÚerrorÚstrZsubmitrÚappendrÚresultrr) r#r$Ú exit_codeZpoolZfuturesÚuserZperm_mapr%Zfuturerrrr!Hs0  "     Dr!c Cs’d}|jD]x}zt|||ƒ ¡Wq ty€}zFt|tƒsL|j t  ¡¡|j  t |ƒ¡d}WYd}~q WYd}~q d}~00q t   |¡dS)z$Handle each user in the main processrrN)rr(rr)r*rrr+r,r-r.r/rr)r#r$r2r3r%rrrr"ds  $r"©r#r$r3cCsV|jdkrt|||ƒS|jdkr,t|||ƒS|jdkr@t||ƒSt d|j›¡dS)z Return a PermMap subclass objectrrZWP3z!BUG in get_perm_map(): args.role=N)rr rr rrr4rrrr(ss      r(Ú__main__) Ú__doc__rrÚ functoolsrÚ subprocessrrrÚconcurrent.futuresrrr,rZfixperms_cpanelrZ fixperms_cwpr Z fixperms_wp3r Z fixperms_clir r Z fixperms_idsr r/rr&r!r"r(Ú__name__rrrrÚs&     )