l#ghddlZddlZddlZddlmcmcmZddl m Z ddl m Z ddl mZddlmZmZddlmZmZmZe eZeegZGddZd Zd Zd Zd Zd ZdZdZ dZ!dZ"dS)N) getLogger)config) update_config)update_users_protection MyImunify)MU_PLUGIN_INSTALLATIONADVICE_EMAIL_NOTIFICATIONWordPressMuPluginc"eZdZdZdZdZdZdS) WhmcsConfz read/write data passed by whmcs Internal use, for commands called from whcms only it saves ALL data came from whcms w/o any validation deliberately in order to simplify compatability with current installed whmcs plugin z/var/imunify360/whmcs_data.jsonctj|jsiS t|jd5}|}dddn #1swxYwYnA#t $r4}t dt|icYd}~Sd}~wwxYw tj |}n9#tj tf$r t d|icYSwxYw|S)Nrz"Failed to read whmcs data file: %sz"Malformed file with whmcs data: %s) ospathexistsopenreadIOErrorloggererrorstrjsonloadsJSONDecodeError ValueError)selffraw_dataedatas P/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/whmcs.pyrzWhmcsConf.read!s=w~~di(( I di%% $6688 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $    LL=s1vv F F FIIIIII  :h''DD$j1    LL=x H H HIII  sRA*A A*A""A*%A"&A** B(4)B#B(#B(,C3C76C7cd|}|| t|jd5}t j||dddddS#1swxYwYdS#t $r3}tdt|Yd}~dSd}~wwxYw)z Saves ALL data passed by WHMCS it should not have any validations deliberately to be as compatible as possible with current installed WHMCS plugin w)indentNz&Failed to write whmcs data to file: %s) rupdaterrrdumprrrr)rr current_datafilers r!savezWhmcsConf.save4s yy{{ D!!! Kdi%% 8 ,Q7777 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 K K K LLA3q66 J J J J J J J J J Ks;A2A% A2%A))A2,A)-A22 B/<(B**B/N)__name__ __module__ __qualname____doc__rrr*r!r r sH -D&KKKKKr0r cpK|tj}t||d{VSN)getrMY_IMUNIFY_KEY mi_update)sinkr my_imunify_updatess r!sync_billing_datar8Es>&"7884!344 4 4 4 4 4 44r0cj|dkr dddd|fS|dkr dddd|fS|dkrd |fS||fS) zf Convert several keys to config key, otherwise just return same key any key is acceptable statusenableTF)activeinactive protection)enableddisabledmu_plugin_installationsmart_advice_allowedr/keyvalues r!convert_to_config_key_valuerFJs  h !        !      ( ( (%u,, :r0cV|dkrd|rdndfS|dkrd|rdndfS|dkrd |fS||fS) zk Convert several keys from config format, otherwise just return same key any key is acceptable r;r:r<r=r>r?r@rBrAr/rCs r!convert_from_config_key_valuerHdsa  he;((<<  5@iijAA & & &'.. :r0c\Ktjd{VSr2)hp HostingPanel get_usersr/r0r!rLrLrs2"",,.. . . . . . ..r0c \K|stddS|d}|r6td|dit ||d{Vt ||t|dstgd{VStd{V|dgp}fd|D}|rZtdt|t||td|ddd{Vntd t|d{VS) z Updates supported parameters if passed, otherwise does nothing updates 2 config parameters (if specified): status and purchase_page_url updates protection status for users (if specified) zNothing to update for MyimunifyNr:r>userscg|]}|v| Sr/r/).0user all_userss r! zmi_update..s*):):):):):r0z'Updating protection status for users=%sz!No users to update protection for)rinfor3r r*update_configsr "prepare_for_mu_plugin_installationrget_current_whmcs_datarLrrrFwarning)r6requested_myimunify_datawhmcs_activation_status target_usersfiltered_passed_usersrRs @r!r5r5vs  $ 56666::8DDM ($<$@$@$J$JKLLL 7 8 88888888:: $$%;<< $ ' ' 5 50+B/////////kk!!!!!!I+//<<I L% < 5 % & &   &  ! '6|D              :;;;'(=>> > > > > > >>r0cKtjrdgnddgtfd|D}td|D}i}|r||tj<|r||d<|r@t dt|t||d{VdSdS)Npurchase_page_urlr:c3FK|]\}}|v t||VdSr2)rF)rPparamrEmi_config_parameterss r! z!update_configs..sI E5 ( ( ( $E511 ( ( ( (r0c3NK|] \}}|tvt||V!dSr2)MU_PLUGIN_KEYSrFrPrarEs r!rcz!update_configs..sG E5 N " " $E511 " " " "r0 CONTROL_PANELzUpdating config with data: %s) ris_mi_freemium_licensedictitemsr4rrUrr)r6rZmi_config_datamu_plugin_data config_dictrbs @r!rVrVs1  ( * * - !8 , 4::<<N 4::<<N K<-; F)*6'5 O$/ 3S5E5EFFFD+...........//r0cK|rUtjtj|n$tj}d|DS)zp Returns information from database based on passed users if no users passed - returns for all users cXg|]'}|dtd|ddd(S)rQr>rT)rQr>rH)rPitems r!rSz"get_users_info..sW     L7d<0     r0)rselectwhererQin_dicts)rNresults r!get_users_inforws  (   !3!3E!:!:;;AACCC     % % ' '      r0cKtj}td|tjiD}|d}td|dd|t<|t|t<t|d{V|d<|S)z Returns the current configuration and user protection status. {MY_IMUNIFY: {'status': 'active/inactive', 'purchase_page_url': 'SOMEURL', 'protection': []}} c3<K|]\}}t||VdSr2rprfs r!rcz)get_current_whmcs_data..sD E5 &eU33r0rgrBrTNr>) r ConfigFileconfig_to_dictrir3r4rjrHrr rw)rN conf_datacurrent_configcp_datas r!rXrXs !##2244I%MM&*?DDJJLLN mmO,,G-J ,B C C... N)*18 !11N,-*8)>)>#>#>#>#>#>#>N< r0c tjjddztjddd||tj dz}|S)N/z/?cloudlinux_advantage provisioningmy_imunify_account_protection)mactionsuiteusernamedomain server_ip) rMyImunifyConfigPURCHASE_PAGE_URLrstripurllibparse urlencoderJrK get_server_ip)rrpurchase_url_links r!get_upgrade_url_linkrsx077<<   , +(8$ _..<<>>      r0)#rr urllib.parser+defence360agent.subsys.panels.hosting_panelsubsyspanels hosting_panelrJloggingrdefence360agent.contractsrdefence360agent.utils.configrdefence360agent.myimunify.modelrr)defence360agent.utils.wordpress_mu_pluginrr r r+rrer r8rFrHrLr5rVrwrXrr/r0r!rs 888888888888,,,,,,666666NNNNNNNN 8  (*CD+K+K+K+K+K+K+K+K\555 4   ///-?-?-?`///B*.r0