ӺhddlZddlZddlZddlZddlZddlmZmZmZddl m Z m Z m Z ddl mZmZmZdZdZdZdZejed ZejeZdd Zd Zd ZdZdZdZ dZ!dZ"dZ#dZ$dS)N)POST_MODIFY_DOMAINPRE_MODIFY_USERPOST_MODIFY_USER) run_commandExternalProgramFailedis_user_present)makedirs_securewrite_file_secureread_file_securez'Unable to find username in hook cmdlinez/usr/sbin/whmapi1z/var/lvetmpTcV|stdd|ddStdddS)a cPanel expects that each custom hook prints two values in the end of the execution: - status, where 1 means success - message, which explains non-1 statuses otherwise nothing really breaks, but logs are full of "script returned invalid response" msgs :param hook_name: name, path or anything else to fill message with in order to understand what exactly failed :param success: is it everything ended successfully? :return: Nothing rzFailed to execute hook zy; you can find logs in /var/log/cloudlinux/hooks/info.log and contact CloudLinux Support if you need help with the issue.r OkN)print) hook_namesuccesss /builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/public_hooks/bundle/cpanel/lib.pyprint_responser sS  a(9((( ) ) ) ) ) actjddgtjtjd5}|\}}|jdkr"t d|j||ddddS#1swxYwYdS)z^ Run lvectl sync-map and log possible stdout|err in case of errors. :return: None lvectlzsync-mapT)stdoutstderrtextrzError during "lvectl sync-map", code: %s, stderr: `%s`, stdout: `%s`. Reseller limits kernel mapping might be not synchronized.Contact CloudLinux Support for help.N) subprocessPopenPIPE communicate returncodeloggererror)procrrs r call_sync_mapr#9s   :      > ))++ ?a   LL"_ff  > > > > > > > > > > > > > > > > > > > > >sABBBc 2|dd}|dd}|s&tttSt jtdd|d|gdt|dd i S) z> Post create account hook of cPanel :return: None userNownercreate --usernamez--ownerCPANEL_RESTORE is_restorer)env) getr warningERR_NO_USER_FOUNDEXIT_NO_USER_FOUNDrcallrstr)datar%r&s rcpanel_postwwwacct_mainr3Ms 88FD ! !D HHWd # #E "()))!! ?(dIu.s488L!#<#<== > @ @ @@rc|dd}|s&tttSt |std|dSt jtdd|gS)z; Pre kill account hook of cPanel :return: None r%Nz1User %s does not present in the system, skip hookrdeleter() r,r r-r.r/rrr0rr2r%s rcpanel_prekillacct_mainr7]s 88FD ! !D "()))!! 4 JDQQQq ?d  rc|dd}|s&tttSt jtdd|gS)z< Post kill account hook of cPanel :return: None r%Nr5r(r,r r-r.r/rr0rr6s rcpanel_postkillacct_mainr:rs[ 88FD ! !D "()))!! ?(d  rcd}tjt|} t |dddd}|d}nB#t t tf$r(tj j dYnwxYw|S)zt Read old domain for modified account :param user: name of user :return: old domain :rtype: str NrF)uidgid exit_on_error write_logz8failed to read old domain for user (pre hook no called?)message) ospathjoinTMP_DIRr IndexErrorOSErrorIOErrorravenbaseRavencaptureException)r%domainfilenamecontents r_read_old_domainrPsFw||GT**H P"8.3444  )PPP  ))N * P P P P PP MsA Post modify account hook of cPanel :return: None r%NnewuserrMrr&OWNERmodifyz-uz --new-ownerz--new-usernamer(z--domainz --new-domainz--include-subdomains)r,rallrr0rPr)r2r%new_userrM exit_code new_ownerargs old_domains rcpanel_postmodifyacct_mainr[s, 88FD ! !Dxx 4((H XXh % %FI$((7"3"344I hd 3D+  ** D( -$("2"2 !8,, &&&I!$''J f 22Z_  lH,d} tdd|ddddg}t|d d }tj|}|d d d d}nB#tt t f$r(tjj dYnwxYw|S)zs Get old domain for modified account :param user: name of user :return: old domain :rtype: str N listacctszsearch=zsearchtype=userzsearchmethod=exactz want=domainz --output=jsonT)return_full_outputr r2acctrrMz-failed to get old domain for user from cpanelr@) WHMAPI1rjsonloadsrrFKeyErrorrIrJrKrL)r%rMcmdstd_outr2s r_get_old_domainrisFc   d      cd;;;A>z'""ff%a(2 !:x 8ccc  ))2a)bbbbbc MsAArvs   ONNNNNNNNNIIIIIIIIII=   ',,w & &  8 $ $2>>>( @ @ @ *    4@   >     r