g vdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZdd lmZdd lmZdd lmZejeZe dZGd d ejZGddZGddeZGddeZGddZ de!de!de!de!fdZ"de!fdZ#ddddd Z$de!fd!Z%e ed"d#d$e$j&%e ed&d'd(ee"dd)%fZ'e ed*d+ed,e%fd-e#%e ed.d/d0ee(d1%e ed2d3d4e)%e ed5d3d6e)%fe'zZ*du  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see N)suppress)partial)chain)Callable)SqliteDatabase TextField) LocalConfig) im360_present)PleskSdk)find_revisium_dbcTeZdZdZeZeZGddZdS)KeyValuez#ex-Revisium settings database modelceZdZdZdS) KeyValue.MetaFN)__name__ __module__ __qualname__ primary_keyV/opt/imunify360/venv/lib/python3.11/site-packages/imav/migrations/004_plesk_configs.pyMetar0s rrN)rrr__doc__rkeyvaluerrrrrr*sX-- )++C IKKErrc$eZdZdZdZdZdZdS)SettingsExtractorz8Base class for ex-Revisium and Plesk settings extractorsc"||_||_dSN)rdefault)selfrr s r__init__zSettingsExtractor.__init__7s rctr)NotImplementedErrorr!s r_getzSettingsExtractor._get;s!!rc0 |}n?#t$r2}td|j||jcYd}~Sd}~wwxYwt t5tj|}dddn #1swxYwY|S)NzFail to get %r value: %r) r& Exceptionloggerwarningrr rjsonloads)r!res rgetzSettingsExtractor.get>s IIKKEE   NN5tx C C C<       i  & &Ju%%E & & & & & & & & & & & & & & & s, A'AAA*B  BBN)rrrrr"r&r.rrrrr4sGBB"""     rrceZdZdZdZdS)Revisiumz'ex-Revisium database settings extractorcfttj|jkjSr)rr.rrr%s rr&z Revisium._getNs ||HLDH455;;rNrrrrr&rrrr0r0Ks)11<<<<>>>>rr4cXeZdZdZdeeedfzdeeedfzdefdZdZ dS) ConfigMappingz Transform a single or multiple dependent ex-Revisium settings parameters to a single ImunifyAV/360 config value and map it to a single or multiple config keys source.target converterct|ts|f}t|ts|f}||_||_||_dS)z :param source: settings extractor(s) for ex-Revisium / Plesk :param target: name(s) of target config parameter(s) for ImunifyAV/360 :param converter: a callable to convert source value(s) to a target one N) isinstancetupler9r:r;)r!r9r:r;s rr"zConfigMapping.__init__`sO&%(( YF&%(( YF  "rc  d|jD} |j|}n:#t$r-}td|j||Yd}~dSd}~wwxYwt t |j|ft|jzS)z@Get target value from source value(s) and assign it to target(s)c6g|]}|Sr)r.).0r9s r z)ConfigMapping.convert..ws @@@&@@@rz$Fail to convert %r value(s) (%r): %rNr) r9r;r(r)r*r>zipr:len)r! source_values target_valuer-s rconvertzConfigMapping.convertus@@DK@@@  )4>=9LL    NN6      22222 S|oDK8H8H&HIIJJJs  A"AAN) rrrrrr>strrr"rGrrrr8r8Ys #!E*;S*@$AA#eCHo%#  ####*KKKKKrr8minimummaximumrreturnc>t|t||S)z. Ensure that a value is within limits )maxmin)rIrJrs rclamprOs wE7++ , ,,rcd}tt5||z|z}dddn #1swxYwYtdd|S)zK Calculate ImunifyAV/360 CPU intensity based on a value in a range N)rZeroDivisionErrorrO)r max_value intensitys r intensity_cpurWsI # $ $33%2 333333333333333 Ay ! !!s ,00nonedayweekmonth)neverdailyweeklymonthlycNttjpddzdS)z-A half of available CPUs/cores (at least one)rR)rMos cpu_countrrrget_max_possible_cpurds"  #!)1 - --rra_auto_scan_periodr_zMALWARE_SCAN_SCHEDULE.interval)r;ra_hour_auto_scanrQzMALWARE_SCAN_SCHEDULE.hourra_max_worker_countrRra_max_possible_worker_count)zMALWARE_SCAN_INTENSITY.cpuz$MALWARE_SCAN_INTENSITY.user_scan_cpura_keep_backups_daysrSz(MALWARE_CLEANUP.keep_original_files_daysra ra_trim_filesTz,MALWARE_CLEANUP.trim_file_instead_of_removalra_use_ignore_list_by_userzPERMISSIONS.user_ignore_listc2t|i}trtnt}t jd|DD]?\}}|}|d^}}|D]}||i}|||<@|S)Nc3>K|]}|VdSr)rG)rAms r z.migrate_imav4plesk_settings..s*,K,KQQYY[[,K,K,K,K,K,Kr.) dbinitr scan_time_mapping_only all_mappingsr from_iterablesplit setdefault) databaseconfigmappingsr:rdpathparamrs rmigrate_imav4plesk_settingsrsGGHF)6J%%lH,,K,K(,K,K,KKK  ||C(( u & &C S"%%AA% MrFc :|rdSt}|tddS t|x}r%t |ddSdS#t $r&}td|Yd}~dSd}~wwxYw)Nz/No legacy ImunifyAV database found. Skipping...F) normalizez2Failed to migrate ImunifyAV for Plesk settings: %r)r r)inforr dict_to_configr(r*)migratorryfakekwargsrevisium_db_pathmigrated_configr-s rmigraters ')) EFFFP9:JKK K? K MM ( (E ( J J J J J K K PPPKQOOOOOOOOOPs4A** B4BBc dSrr)rryrrs rrollbackrsDr__main__r)F)/rr+loggingrb contextlibr functoolsr itertoolsrtypingrpeeweerr defence360agent.contracts.configr imav.migration_utils.otherr imav.migration_utils.plesk_sdkr imav.migration_utils.revisiumr getLoggerrr)rrModelrrr0r4r8intrOrWschedule_interval_mappingrd __getitem__rtrMboolrurrrprintrrrrs0*  ,,,,,,,,888888444444333333::::::  8 $ $^Drx.<<<<< <<<>>>>> >>>+K+K+K+K+K+K+K+K\-3--S-S----"s""""  .c....M #Y//(+7 M !1%%$'%B'' M E' + + E02F2F2H2H I I      M $a((2'#q// M ot$$6 M-t44&-67 <     P P P P      z E % %&6&6&8&8 9 9:::::r