}Ce ddlmZddlmZddlmZddlZddlmZddlZddlZddl Z ddl m Z m Z ej e dZdZed gd Zeed zd d deedzd ddeedzd ddeedzd ddeedzd ddeedzdddfZe jeZdZdZdZdZefdZefdZdS))absolute_import)division)print_functionN) namedtuple)CLOUDLINUX_HOOKSCONTACT_SUPPORT_MESSAGE_FOOTERzcpanel/"/usr/local/cpanel/bin/manage_hooksHook)pathcategoryeventstage postwwwacctWhostmgrzAccounts::Createpost postkillacctzAccounts::Remove prekillacctprepostmodifyacctzAccounts::Modify premodifyacctpostrestoreacctPkgAcctRestorect||||}|rtd|||dStd||| t jt dd|dt|dt|dt|d g tjd }td | dS#ttj f$r}t|tj r|j d }nt|}td tj||t||Yd}~dSd}~wwxYw)Nz>Hook for %s:%s:%s action is already installed; skip installingTz Registering %s:%s:%s action hookaddscript --category--event--stage--manualstderrtextz3Register hook ended successfully; tool output: `%s` zDCan't install hook `%s` to category: `%s` event: `%s`; message: `%s`F)_is_hook_installedloggerinfodebug subprocess check_output MANAGE_HOOKstrSTDOUTrstripOSErrorCalledProcessError isinstanceoutputerrorosr basename) hook_pathr r r is_installedr2emessages /builddir/build/BUILDROOT/alt-python27-cllib-3.3.7-2.el7.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/public_hooks/bundle/cpanel/manager.py _install_hookr;$s%eXy%HHL <eU , , ,t LL3XueLLL( ) #h-- s5zz s5zz: * #$ 000  I6==??[[[t Z2 3 a6 7 7 hood++GG!ffG \W%%i00(CJJ Q Q QuuuuusACF/B FFct}|dS |||D]}|d|kr|d|krdSn#t$rYdSwxYwdS)zd Check if hook with given parameters is installed in control panel :return: boolean NhookrTF)_get_hooks_configKeyError)r r hook_script_pathr all_hooksis r:r%r%As "##It8$U+  Ay,,,7u1D1Dtt  uu 5s)AA AAcn tjgdd}nL#ttjf$r3}tdt |Yd}~dSd}~wwxYw tj|}n8#ttf$r$t dtYdSwxYw|S)z& Reads main hooks config file )r listz --output=JSONT)r#z>Unable to load list of already installed hooks. Reason is `%s`NzDReceived list of installed hooks is malformed and not valid JSON. %s) r)r*r/r0r&r3r,jsonloads ValueError TypeError exceptionr)streamr8rAs r:r>r>Ss( K K K    Z2 3 ?@CA H H Httttt Jv&&  "?7 9 9 9tt  s&A$(AA$(A==1B21B2ct||||durtd|||dStd||| t jt dd|dt|dt|d t|d g tjd }td | dS#ttj f$r}t|tj r|j d }nt|}td|t||tYd}~dSd}~wwxYw)z5 Delete hook script and unregister in cPanel Fz8Hook for %s:%s:%s action is not installed; skip removingTz"Unregistering %s:%s:%s action hookdeleterrrrr r!z5Unregister hook ended successfully; tool output: `%s`r$zBCan't delete hook with category:`%s` event:`%s`; message: `%s`. %sN)r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r)r@r r rr2r8r9s r:_delete_hook_scriptrMkss %+;UCCuLL 6eU , , ,t LL5xNNN( 8-= #h-- s5zz s5zz: * #$ 000  KV]]__]]]t Z2 3 a6 7 7 hood++GG!ffG Zs5zz74R T T TuuuuusACE./A4E))E.cdd}|D]*}t|j|j|j|jo|}+|SNT)r;r r r rhookssuccessr=s r: install_hooksrSsKGJJ It}dj$*>>JBI  Ncdd}|D]*}t|j|j|j|jo|}+|SrO)rMr r r rrPs r: remove_hooksrVsKGJJ% It}dj$*>>JBI  NrT) __future__rrrr) collectionsrr4rEloggingclcommon.public_hooksrrr joinBIN_DIRr+r HOOKS getLogger__name__r&r;r%r>rMrSrVrTr:ras'&&&&&%%%%%%"""""" RRRRRRRR ',,' 3 32 z&@@@AA D= *.@&IID> !:/A6JJD= *.@%HHD# #Z1CVLLD? "J0BEJJD$ $iFCC    8 $ $:$0BrT