a ‡ei@sdZddlZddlZddlmZddlmZmZmZddl m Z m Z ddl Z ddl Z ddlmZddlmZddlmZdd lmZmZdd lmZed d d ZddZeedddZeedddZeeedddZedkredS)zMain logic for fixpermsN)partial)runPIPECalledProcessError)ProcessPoolExecutor as_completed) CpanelPermMap) CwpPermMap) WP3PermMap) parse_argsArgs)IDCache)rolecCstjdkrdS|dvrdSttdtdd}|dkrZ|dd gj}td |sPdSd }d }n0|d dgj}d|vrtdS|dd gj}d}d}d|vsd|vrdSt d|d|dS)z2Check if DSO is installed and modruid2 is disabledZsharedN)CWPcPanelzUTF-8F)encodingstdoutZcheckrz/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_ROLErrrrresearchsysexit)rZrun_cmdZmodsZ good_modsZkb_urlZphpr#./usr/lib/fixperms/fixperms_main.pycheck_dso_without_modruid2s8   rc Cst}zt|j}Wn<tyP}z$|jd|tdWYd}~n d}~00t|jt |j dkr|j dkrt ||n t ||dS)z;Main program logic: iterate over each user and run fixpermsz%s. Cannot continue.N)r r rKeyErrorloggerZcriticalrrrlenusersprocsparallel_executeserial_execute)argsidsexcrrrmain9s   r&)r#r$c CsTd}t|jd"}g}|jD]}zt|||}Wn^ty}zFt|ts\|jt |j t |d}WYd}~qWYd}~n d}~00| |j}||qt|D]r}z |Wqty"}zFt|ts|jt |j t |d}WYd}~qWYd}~qd}~00qWdn1s<0Yt|dS)z"Fork processes to handle each userr) max_workersrN)rr r get_perm_map Exception isinstancerrdebug traceback format_excerrorstrZsubmitrappendrresultrr) r#r$ exit_codeZpoolZfuturesuserZperm_mapr%Zfuturerrrr!Hs0  "     Dr!c Csd}|jD]x}zt|||Wq ty}zFt|tsL|jt |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||Std|jdS)z Return a PermMap subclass objectrrZWP3z!BUG in get_perm_map(): args.role=N)rr rr rrr4rrrr(ss      r(__main__) __doc__rr functoolsr subprocessrrrconcurrent.futuresrrr,rZfixperms_cpanelrZ fixperms_cwpr Z fixperms_wp3r Z fixperms_clir r Z fixperms_idsr r/rr&r!r"r(__name__rrrrs&     )