/opt/dedrads/cms_tools/__pycache__
NameSizeModeActions
cms.cpython-313.pyc226940644editdlrm
common.cpython-313.pyc51370644editdlrm
db.cpython-313.pyc210570644editdlrm
helpers.cpython-313.pyc239580644editdlrm
__init__.cpython-313.pyc1310644editdlrm
Edit: /opt/dedrads/cms_tools/__pycache__/helpers.cpython-313.pyc (23958B)
}j?SjSrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJr SSK r SSK r SSK r SSK J r Jr \R"\5rS!Sjr0r0rSrSrSrS rS rS rS rS rSrSrSrS"Sjr S\ RB4Sjr"Sr#S\$S\$S\$4Sjr%S#Sjr&S#Sjr'Sr(Sr)Sr*Sr+Sr,S r-g)$z%Helper functions for CMS manipulationN)datetimetimezone)cpapi2whmapi1cUcSnSnOeSU;a SnUS:XaSnOTSU;a S nUS:XaS nOCS U;a S nUS:XaS nO2SU;a SnUS:XaSnO!SU;a SnUS:XaSnOSU;a SnUS:XaSn[SU-5 [5nUbUS:XaU$[R"X5bU$[SSS9 US:Xa[SU-5 OUc [SSS9 O [U5 [S5 M![a [S5 gf=f)a1 Prompt to request a string, and require it to match a regex. If string fails to match, give a hint, which by default is just the regex. If no matching string is obtained, return None. If empty string is entered, return default if any exists. Defined filters: alpha, digits, email, cpuser, database, url Nz.*z Sorry, that should have matched.alphaz [a-zA-Z0-9]+$regexz%Must be only alphanumeric characters.digitsz[0-9.]+zMust be only digits.emailz<[a-z0-9._-]+@[a-z0-9._-]+\.([a-z]{2,15}|xn--[a-z0-9]{2,30})$zMust be a valid email address.cpuserz[a-z0-9]{1,14}$zFMust be a valid cPanel user: letters and numbers, under 14 characters.databasez[a-z0-9]{1,8}_[a-z0-9]{1,12}$zFMust be a valid database user: letters and numbers, single underscore.urlz{([a-z]{3,}://)?([a-z0-9_-]+.){1,}([a-z]{2,15}|xn--[a-z0-9]{2,30})(:[0-9]+)?((/[a-zA-Z0-9/.%_-]*)(\?[a-zA-Z0-9/.%=;_-]+)?)?$zMust be a valid URL.z%s z Cancelledz Invalid answer.  )endz# String must match the patter: /%s/z Try again. )printinputKeyboardInterruptrematch)prompt string_filterhintdefaultchoices !/opt/dedrads/cms_tools/helpers.pycommon_get_stringrsm 1 M !' 7?:D ] "! 7?)D M ! 5  7?3D ] ") 7?>  } $7 7?<  -  @  7?)D  fvo WF  6R<N 88M * 6M ", 7? 8=H I \ #3  $K n-  !  -  s> C11D D ch[[R"S55S:aG[SSU05nSUSS:Xa[R SUUSS 5 g US S SS nO?[[R"SU-55S:Xa[R SU5 g SnSUSU3nU$)z$Return home directory of cPanel userz/home*/accountsummaryuserrmetadataresultz0WHM API could not find home directory for %s: %sreasonNdataacct partitionz/var/cpanel/users/%sz-%s does not appear to be a valid cPanel user.home/)lenglobrLOGGERerror)r r#r'docroots r get_cp_homer/ts 499Y  1$)FF+;< z"8, , LLBz"8,  6N6*1-k: tyy/&89 :a ? LL?  )AfX&G NcUc+[RS5 [R"S5 SU;aZUn[R "SU5nUc,[RSU5 [R"S5 UR S5nOUnSn[U5nUcgUS:XaU$[R"XA5c[RSUUU5 g[RRU5(aU$[S U-5 g) z. Find start path from for user or path given. NzNo user or path specifiedrr)z/home[^/]*/([^/]+)z&Could not find a username in path '%s'rz6Path given (%s) is not part of %s's document root (%s)zPath given does not exist: '%s') r,r-sysexitrsearchgroupr/rospathisdirr) user_pathrequested_pathrusernamer.s rfind_start_pathr<s  01   i" /; = LL8.  HHQK;;q>(#G xx(0 D      ww}}^$$ +n <= r0c[RRU5(d[R SU5 g[ R "[R5RS5nUSU3n[RRU5(d.[R SX5 [R"X5 U$[SS5HjnSRXU5n[RRU5(aM;[R SX5 [R"X5 Us $ [R%S U5 g ![ a#n[R#S UUU5 SnA g SnAff=f) z5 Find an unused filename and make a backup of a file z File %s does not exist to backupN%Y-%m-%dz.cms_tools.file.bak.zCopying %s -> %srz{}.cms_tools.file.bak.{}.{}z-File copy failed. Could not copy %s to %s: %sF.There are already too many backup files for %s)r6r7isfiler,infornowrutcstrftimeexistsshutilcopy2rangeformatcopyfileOSErrorr-warning)filename date_todaynew_filenumr-s r backup_filerRs. 77>>( # # 6Ahll+44Z@J/ |>( # # &; X(Q{077 # ww~~h'' KK*H ? 3O'* NNCXN   C   s&E F#FFc2[RRU5(d[R SU5 g[ R "X5 [RSX5 g![a"n[RSUUU5 SnAgSnAff=f)zA Replace destination file with source file, removing source file z'File %s does not exist. Cannot restore.FzRestored %s from %sz3File restore failed. Could not restore %s to %s: %sNT) r6r7rAr,rMrGmoverBrLr-) source_filedestination_filer-s r restore_filerWs 77>>+ & &@+N   K2 )+;I    A        s,A** B4BBcB[RSU5 [RR U5(a'[ USS9nUR 5nUsSSS5 $g![a [RS5 SSS5 gf=f!,(df  g=f)z7 Read data from a file or report error and return None zReading from %sutf-8encodingNzError reading file) r,debugr6r7rFopenreadrLr-)rN file_handle file_datas rreadfileras  LL"H- ww~~h (W - ',,.  . -   12 . -  . - s*BA##B B B  B BcSULagSULag[R"U[R5nURU5nS[ U5:XagUS$)z6 Return the last regex match in a set of data or None Nr)rcompileMfindallr*)r r% regex_objectr#s r lastmatchrhsW  t| u}::eRTT*L  ! !$ 'FCK ":r0cf[R"SSU5n[R"SSU5nU$)z* Return data minus any PHP style comments z\s+//.*rz/\*(.*\n)*?.*?\*/)rsub)r%s rstrip_php_commentsrk-s0 66*b$ 'D 66&D 1D Kr0c [SU-U5$)z@ Find the last instance of const_name being defined in php data z0define\( *["\']%s["\']\s*,\s*["\']([^"\']+)["\']rh) const_namer%s rfind_php_definero>s ;jH$ r0c [SU-U5$)z? Find the last instance of var_name being assigned in php data z\$%s\s*=\s*["\']([^"\']+)["\']rm)var_namer%s r find_php_varrrJs 6A4 HHr0c *[USS9nUR5nSSS5 [USSS9nWH4nUR[R"SU-SUSUS3U55 M6 SSS5 g !,(df  N]=f!,(df  g =f) zX Change all instances in filename where const_name is defined, and redefine it to value rYrZNwz2define\( *["\']%s["\'] *, *["\']([^"\']+)["\'] *\)zdefine('z','z')Tr] readlineswriterrj)rnvaluerNsourceslineslines r php_re_definer|Ts h )W!!# * hg .'D MM13=>zl#eWB7   /  * ) . . A3;B3 B Bc *[USS9nUR5nSSS5 [USSS9nWH4nUR[R"SU-SUSUS3U55 M6 SSS5 g!,(df  N]=f!,(df  g=f) zW Change all instances in filename where var_name is assigned, and reassign it to value rYrZNrtz\$%s *= *["\']([^"\']+)["\']$z = ''ru)rqrxrNryrzr{s r php_re_assignrms h )W!!# * hg .'D MM3h>zeWA.  / . * ) . .r}c Sn[RSU5 US:XaU[;a [U$[[R 55n[ SUS9nSUSS;a5[R S USSS 5 [R"S 5 USSH nXFS - nM OU[;a [U$[[R 55n[ SUS9nSUSS;a5[R S USSS 5 [R"S 5 USSH nXFS- nM USU-/-nSn[R"SSUR55n[R"SU5R5n [U 5S:aU nOT[R"SU5R5n [U 5S:aU nO[R"SSU5nUSSnSR!U[R"SS[U5- -U5RS55n X;aSnU(dS[U5[U5-:a[#S SS[U5- [U5- -5H`n[%S U-5 S!R!U[R"SS[U5- -U5RS5U5n X;dM^Sn O U(d[#[USS[U5- S - 5S S"5HnUSUn [#S SS[U5- [U 5- -S - 5HRnS!R!U[R"SS[U5- -U 5RS5U5n X;dMPSn O U(dM O U(a2[RS#X+5 US:Xa U [U'U $U [U'U $[R'S$U5 g)%zG Find a valid replacement database name. Typce can be database or user zFinding new name for: %sr MysqlFE::listdbsr!r# cpanelresultr%'cPanel API could not list databases: %sr$rdbz#cPanel API could not list users: %sr!z%s_Fz [^a-z0-9_]rz[^_]*$z^[^_]*z [^a-z0-9]Nz{}_{}z^[a-z0-9]{1,%d}rT z name base: %sz{}_{}{}rczFound new name: %s -> %sz&I give up! You find a new name for %s!)r,r\DB_CONVERSIONSlistvaluesrr-r2r3DB_USER_CONVERSIONSrrjlowerr4r5r*rJrIrcritical) r prefix current_name name_type used_namesr#iis_set name_base last_section first_sectionnew_nametmp_bases rmake_valid_db_namers J LL+\:J > )!,/ /.//12 *8 vn-f5 5 LL9~&v.x8  HHQK'/A D' !J0 . .&|4 4-4467 *8 vn-f5 5 LL5~&v.x8  HHQK'/A F) #J0uv~..J F|R););)=>I99Xy1779L <1  (I6<<> }  !%I{B :I!"1 I~~ #rCK'78)DJJ1MH !  Vs9~- .1rb3v;&6Y&GHJo 12$++II)R#f+-=> eAh -!FK s9%=S[(81(<>?BGA !}H1rb3v;&6X&FG!KM$++II)R#f+-=>eAh -!FNvH" /H  "+3N< (19  - OO(  = (' v =(s &&c B[RRU5(d[R SX25 g[ S5 [ R"SXUS9nUR5n[R"SS5 [RSX25 URS 5 UR5H)unURS URS S 5-5 M+ S S S 5 S S S 5 [#XX#5(d[R%SU5 g[R&"U5 g!,(df  NU=f!,(df  N^=f![ Ra.n[!U5up[R SX(U 5 S nAgS nAff=f)z5 Restore database from dump file, removing dump file z*File %s does not exist. Cannot restore %s.FzAttempting to remove tables localhost)hostr!passwordr ignorezUnknown table.*z!Reading from %s to import into %sz SHOW TABLESzDROP TABLE `%s``z``Nz%Error removing tables from %s. %s: %szCould not restore %sT)r6r7rAr,rMrpymysqlconnectcursorwarningsfilterwarningsr\executefetchallreplaceErrorr import_dbrremove) dbuserrdbname dump_fileconnr table_namerrsterrors r restore_dbr sF 77>>) $ $ 8)  '( __6v &''2CD 7}-%+__%6MZNN)J,>,>sD,II&7  * Vv 9 9.7IIi /   ==&s+ 3VG  sOEE /A>) $ $2I> i $  NN!8V< (+ !))!   LL;VO  ,,  LLSZZ)<BBD E     s0 D ;B&&D:8C?2D?DD Dc US:waSU-n[RRU5(d[R SX5 g[ R "[R5RS5nSHUn[RRUUUSUUS35n[RRU5(aMSUs $ [R SU5 g) z6 Find a non-existent file into which to dump the a db r.z!Path %s does not exist to dump %sFr>)rz.1z.2z.3z.sqlr@) r6r7r8r,rMrrCrrDrEjoinrF)r dump_path add_to_namerOrQrPs rfind_dump_filerNs bK' 77== # #:INhll+44Z@J&77<< h{m1ZLT :  ww~~h''O& NNCVL r0c 6[X#U5nU(dg[USSS9n[RSU5 SSSS UU/n[R "US U0U[R SS S S 9RR5nU(d![RSX%5 UsSSS5 $[RSX%U5 SSS5 g![Ra(n [RSX)5 Sn A SSS5 gSn A ff=f!,(df  g=f)z$ Export MySQL database as a backup. Fzw+rYrZzAttempting dump to %s mysqldumpz--add-drop-tablez --routinesz-urrT)rrrr[errorsrzDumped %s to %sNzUnable to dump %s to %s: %szError attempting dump of %s: %s) rr]r,rBrrrrrr-r) rrrrrrfhandlecmdrr-s rdump_dbrks  v+>I  i 0G ,i8         ^^ (+!  fUUW  -vA - 1 0. LL-v& 5 1 08,,  LL:F J= 1 08 9 1 0s6D A C *C  DD5D DD  Dc[SUS9nSUSS;a5[RSUSSS5 [R"S5 USSH nXS :XdM g g )  Check for existance of dbname rrr#rr%rr$rrTFrr,r-r2r3r rr#rs r db_existsrsw &V 4F6.)&11 5 > "6 *8 4   N #F + tW , r0c[SUS9nSUSS;a5[RSUSSS5 [R"S5 USSH nXS :XdM g g ) rrrr#rr%z,cPanel API could not list database users: %sr$rr!TFrrs rdb_user_existsrsw &V 4F6.)&11 : > "6 *8 4   N #F + vY , r0c[SUSU0S9nSUSS;a6[RSUSSS5 [R"S 5 g g ) # Create database dbname for cpuser zMysqlFE::createdbrr!rr#rr%z(cPanel API could not create database: %sr$rNr)r rr#s r create_dbrs\ 'fD&> JF6.)&11 6 > "6 *8 4   2r0c[SUXS.S9nSUSS;a6[RSUSSS5 [R"S 5 g g ) rzMysqlFE::createdbuserrrrr#rr%z-cPanel API could not create database user: %sr$rNrr rrr#s rcreate_db_userrsa   5F 6.)&11 ; > "6 *8 4   2r0cv[SUXS.S9nSUSS;a [RSUSSS5 g g ) rzMysqlFE::changedbuserpasswordrrr#rr%6cPanel API could not change database user password: %sr$FT)rr,r-rs rchange_db_passrsW '  5F 6.)&11 D > "6 *8 4  r0c[SUSXS.S9nSUSS;a6[RSUSSS 5 [R"S 5 g g ) rzMysqlFE::setdbuserprivilegeszALL PRIVILEGES) privilegesrrrr#rr%rr$rNr)r rrr#s rassociate_db_userrsc & ,F MF 6.)&11 D > "6 *8 4   2r0)z[a-zA-Z0-9._/-]+$r N)r )r).__doc__r2r6rrrrrrr+rGrcpapisrr getLogger__name__r,rrrr/r<rRrWrarhrkrorrr|rrrrrrrrrrrrrrrrr0rrs+ ' "   8 $GKNj 8+\)X.(0 "I2,|~w}}(VcS#2:'Z*( &*r0