}Ce2ddlmZddlmZddlmZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZmZmZddlmZmZmZdZd Zd Zd Zejed ZejeZddZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dS))print_function)absolute_import)divisionN)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/lvetmpTcT|stdd|zdStdddS)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 %s; you can find logs in /var/log/cloudlinux/hooks/info.log and contact CloudLinux Support if you need help with the issue.rOkN)print) hook_namesuccesss /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/lib.pyprint_responser$sL  a(+44 5 5 5 5 5 actjddgtjtjd}|\}}|jdkr$t d|j||dSdS)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)prrs r call_sync_mapr&=s (J/ * d T T TA]]__NFF|q vv  7 7 7 7 7rc 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_mainr6Ms 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#r0r1r2r rr3rr5r(s rcpanel_prekillacct_mainr:]s 88FD ! !D "()))!! 4 JDQQQq ?d  rc|dd}|s&tttSt jtdd|gS)z< Post kill account hook of cPanel :return: None r(Nr8r+r/r#r0r1r2rr3rr9s 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_domainrSsFw||GT**H P"8.3444  )PPP  ))N * P P P P PP MsA Post modify account hook of cPanel :return: None r(NnewuserrPrr)OWNERmodifyz-uz --new-ownerz--new-usernamer+z--domainz --new-domainz--include-subdomains)r/rallrr3rSr)r5r(new_userrP 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,z'""ff%a(2 !:x 8ccc  ))2a)bbbbbc MsA&A++r{s&%%%%%&&&&&&   ONNNNNNNNNIIIIIIIIII=   ',,w & &  8 $ $2 7 7 7 @ @ @ *    4@   >     r