Xׯd ddlZddlZddlmZmZddlZddlmZmZm Z m Z ddlZddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZmZmZddlmZmZmZddlmZdd lmZdd lmZm Z m!Z!m"Z"m#Z#ed d d Z$Gdde%Z&gZ'GddZ(dZ)dZ*e$+ej,dZ-e j.Z'e$+ej/j0ej/j1dZ2e$+ej/j0ej/j1dZ3e$+ej,ej/j1dZ4e$+ej5ej6dZ7e$+ej5ej/j1ej/j0dZ8Gddej9Z:e$+ej,ej/j1dZ;e$+ej,ej5dZdZ?e$+ej5ej5ej/j1ej/j0d Z@e$+ej6ej/j0d!ZAe$+ej5ej/j0d"ZBe$Cd#d$ejDejEgd%&e$+ej,ej/jFej5d'ZG ddlHZHe$Cd(d$ejDejEgd%&e$+ej,ej/jFej5d)ZIn #eJ$rYnwxYwe$Cd*d$ejDgd+&e$+ej,ej/jFd,ZKe$Cd-d$ejDgd.&e$+ej,ej/jFd/ZLdS)0N) DefineModulewbinputs) Utilities newButtonnewLabelnewBox)PasswordHandler) ServerProfile)MySQLConnection MySQLErrorescape_sql_string)OperationCancelledErrorInvalidPasswordErrorNoDriverInConnection)Version)NotificationCenter)log_info log_warning log_error log_debug log_debug2WbAdminz Oracle Corp.z2.0)nameauthorversionceZdZdS)DBErrorN)__name__ __module__ __qualname__..\modules\wb_admin_grt.pyrrOsDr"rceZdZdZdZedZedZdZdZ dZ dZ dd Z d Z d Zd ZdZdZddZdZddZdZdZdS)AdministratorContexta# An instance of the WBA, associated to a SQL Editor. This is created when a GRNSQLEditorOpened notification is received. Initially, only the different sections of the WBA are added to the sidebar and the GUI itself is not initialized until the user enters each section. c||_|jj|_d|_i|_i|_i|_i|_d|_d|_d|_ d|_ tj |j |_ |j |jdddgfdddgfdddgfg|_d|_t$D]}||||dS)N Management MANAGEMENTInstanceINSTANCE Performance PERFORMANCEF)editor connectionserver_profile admin_pagespage_instances page_titlesdisabled_pages admin_tab error_boxctrl_beadmin_access_statusmformsfromgrtsidebaradd_on_section_command_callback_sidebar_entry_clickedsidebar_sectionsshown_in_sidebarwba_page_modules wba_register_check_instance_profileshow_in_sidebar)selfr-mods r#__init__zAdministratorContext.__init__`s) +0"   #' ~fn55  44T5PQQQ". lB!OR\^hjtvxQy}JLY[hjl|m!n %# # #C   T " " " " $$&&& r"cjtjjjjD]}|j|jkr|cSdSN)grtrootwb rdbmsMgmtstoredInstancesr.)rCinstances r#instance_profilez%AdministratorContext.instance_profiles> -=  H"do556tr"c|jdkSrG)rNrCs r#instance_management_enabledz0AdministratorContext.instance_management_enableds$,,r"c|jtjjjjd<d|_d|_d|_i|_ |j d|_ dS)N(Administrator:sidebar_collapsed_sections) r:get_collapse_statesrHrIrJoptionsr4r6r7r1clear_selectionr5rPs r# handle_closez!AdministratorContext.handle_closeseRVR^RrRrRtRt #$NO #'   $$&&&r"cL|jr|jddSdS)Nserver_started)r6event_from_mainrPs r#handle_reconnectz%AdministratorContext.handle_reconnects3 < ; L ( ()9 : : : : : ; ;r"ct|j|jd|_|j|jjrZt |jrDt jdd|jjzt|j|jd|_dSdSt|jrFt jdd|jjzt|j|jd|_dSdSdS)NFAdminz0Auto-created instance profile for connection %s z=Auto-created dummy instance profile for remote connection %s ) r r.rNr/is_localautoDetectLocalInstancerHrrautoDetectRemoteInstancerPs r#rAz,AdministratorContext._check_instance_profiles+DOT=RTYZZ  (  ) a&t77 al7$WZ^ZiZn$nooo$1$/4CXZ_$`$`d!!! a a (88 al7$dgkgvg{${|||$1$/4CXZ_$`$`d!!! ) ( a ar"cr|s d|_dS tjd|jtjddS#t$rF}d|_tjd|zYd}~dSd}~wt$ru}d|z|_tj dd |zd d d tj krYd}~tjd Yd}~dSd}~wt$r}ddl}|d|z|_tjd tj dt!|jd|dd d tj kr)t$jj|jYd}~dSd}~wwxYw)Nz&Remote management settings are invalidTz-Acquiring management access to target host...z8Management support for target host enabled successfully.zVRemote management capabilities are currently unavailable. SSH connection was cancelledzCancelled SSH connection (%s)zoRemote management capabilities are currently unavailable. Could not acquire management access to the server %sz6Could not acquire management access for administrationz%sRetryCancelCould not Open WB Adminr: z Settings...)_validate_remote_admin_settingsr7r8Appgetset_status_textr6acquire_admin_accessrrr show_errorResultOk Exception traceback print_exctyperrHmodules WorkbenchshowInstanceManagerForr.)rCexcros r#_acquire_admin_accessz*AdministratorContext._acquire_admin_accesss3355 'OD $ F     001`aaa 11333   001klllt*   ,E(   001PQT1TUUUttttt'   ,`cf,f('(`bfilblnuwBDEEIOIXXXHHHH   001JKKKttttt       ##%%%,`cf,f(   001JKKK'(`nrsvnwnwoAoAoACFCFcGIVX`bdeeioixxxK)@@QQQttttt s7A;B H6';C(( H653E%.1E%% H62B9H11H6Fc.|s|rdS|jstjd|_|jdtj|j}|tj|j |dd|j |jn|j |jdS|jr&|j |jd|_dS)NT2F)rvr5r8r set_paddingrr7 set_style BigBoldStyleaddr4add_page select_page remove_page)rCignore_failure error_labels r#rkz)AdministratorContext.acquire_admin_accesss))++  t> ;!'t!4!4**2...$od.FGG %%f&9:::"";t<<<''7777**4>:::5~ &**4>:::!%4r"cz|j}|sdSd}d}d}||jd|d||jd|ddS)NFc~||vr||||dSdS|tjd|ddd|||dS)NzWB AdministratorOKrd)r show_warning)settingsoptionnorm_cbmsgs r#validate_settingzNAdministratorContext._validate_remote_admin_settings..validate_settingsl!!&GHf-----'&?*+=sD"bQQQ&)))))r"cBd}||vr||}|dkrd}nd}|||<dSNrr!)rrvalues r#norm_to_switchzLAdministratorContext._validate_remote_admin_settings..norm_to_switchsAE!! (199EEE$HV   r"c||vrd||<dSdS)Nrdr!)rrs r#make_str_existingzOAdministratorContext._validate_remote_admin_settings..make_str_existings%X%%#%   &%r"z sys.usesudozsys.usesudostatusT)rN serverInfo)rCserver_instancerrrs r#rgz4AdministratorContext._validate_remote_admin_settingss/ 5 * * * % % % & & & 3]NTXYYY35H.Z^___tr"ctj} tj|j|jd|_|jtj |j|j||j|_ nP#t$r\}t|r-tjd|jzt|ddd|dYd}~dSd}~wt$$r#}|d|zYd}~dSd}~wt&$rE}tjdt|ddd|dYd}~dSd}~wt($rg}d dl}|tjd t/|jd |ddd|dYd}~dSd}~wwxYwtj|jj}||j dd ||j |j d |j S) NT connect_sqlz%Error Connecting to MySQL Server (%s)rrdrezCancelled (%s)zMissing connection driverrz&Error Starting Workbench Administratorrf Administrator)r8rhriwb_admin_controlWbAdminControlr/r-r6init wb_admin_mainAdministratorTabr4r strrrllocationrjrrrnrorprqrr9 dockingPoint dock_view select_view set_title)rCapprurodps r#_dock_admin_tabz$AdministratorContext._dock_admin_tabstjnn +:4;NPTP[imnnnDL L     *;DL$J]_ceiepqqDNN   3xx u$%Ls|%[]`ad]e]egkmoqsttt    9 : : :44444&       0 4 5 5 544444#     !A*B GAC-- G:D G%:E%% G2AGGcvtj|jj}||jdSrG)r8r9r-rrr4)rCrs r#become_active_tabz&AdministratorContext.become_active_tab!s0 ^DK4 5 5 t~&&&&&r"c|dkrt|jdS||jvr0tj|j||j|ddddS||dS)N configurerrd)openConnectionSettingsr-r3rrlr2open_into_sectionrCentry_ids r#r<z+AdministratorContext._sidebar_entry_clicked&s { " " "4; / / / / /4...$T%5h%?%)%8%B%)2r333  " "8 , , , , ,r"ct|jD]L}|jr|jr|jjs |jjs)|j|=|j|dMdSNT)listr3keysr/r^remote_admin_enabledr:set_section_entry_enabled)rCidents r#refresh_admin_linksz(AdministratorContext.refresh_admin_links1s$-224455 D DE' DD,? DH[Hd DmqnAnV D'. 66udCCCC  D Dr"cJ|j|d\}}|dS|j|sdS|j|}|so|s|dkr'|jjs||dksdS||j|j|j}||j|<|j ||j D]6\}}}} | D],\} } } } | |kr|j d| zn-7|j |dS)N)NNadmin_server_statuszAdministration - %s) r0rir4rr1r6admin_access_availablerkr/r}r=set_content_labelr~)rCr select_item page_classneeds_remote_accesspagesnamesanamestitlesitemsrianametitle icon_paths r#rz&AdministratorContext.open_into_section9sl*.*:*>*>x*V*V' '   F > !'')) "&&x00 *# x3H'H'HRVR^Ru'H00=R1RSSF:dlD,?PPD,0D  ) N # #D ) ) )-1-B   )E66639  /vuiH$$N445JU5RSSSE% ""4(((((r"ctfd|jDs |j||gfdSdS)Nc30K|]}|dkVdS)rNr!).0xrs r# z3AdministratorContext.add_section..Ws+??A1Q44<??????r")anyr=append)rCraccessibilityNamers ` r# add_sectionz AdministratorContext.add_sectionVs_????)>????? O  ! ( ($0A5")M N N N N N O Or"c6|sd}||j|<||f|j|<|dz}|jD];\}}} } ||kr.| ||||fdSz8AdministratorContext.show_in_sidebar..~s?w_w_w_CDwz{|w}w}w_w_w_r"rSrd)r>r- serverVersionrr9r3r=r8TaskSectionShowConfigButtonTaskSectionPlainr:radd_section_entryTaskEntryAlwaysActiveLinkr0rir/r^rgetattr#is_supported_mysql_version_at_leastrjoinrset_collapse_statesrHrIrJrU)rCserver_versionrrrrflagsrrititlerrDrequires_remote_accessenableds r#rBz$AdministratorContext.show_in_sidebarhs^$ ~{( &!(1J!K!K!%$(D !"$D 151F K K-vvv>Cz>Q>Q::W]Wn ((FFF8> K K4E669L225%QZ\b\|}}}262B2F2Ful2[2[/C/"G-`t7J`tOb`kok~lH`QUQdQy`"'6t+E22 &:DAA`)`2d.2dfif|2}`&+G9jmpmumuw_w_HKH^w_w_w_n`n`:`D/6L::5'JJJJ K L , ,SX[-@-H-L-LMwy{-|-| } } } } }3 ~ ~r"c6|j|SrG)r1rirs r# page_with_idz!AdministratorContext.page_with_ids"&&x000r"N)F)rrr __doc__rEpropertyrNrQrWr[rArvrkrgrrr<rrrrrBrr!r"r#r%r%Xsb@X --X-   ;;; a a a:(   DD''' - - -DDD)))):OOO    ~~~811111r"r%c|jr\t|tj|jd<|jdkr(t jdfd}~dSdSdS)N adminContextrg?c0ddS)NrT)r)contextsr#z#attachToSQLEditor..sw?X?XYnpt?u?ur") r.r%rHtogrt customData isConnectedr8r add_timeout)rsenderargsignorers @r#attachToSQLEditorrs} 'v..,/Ig,>,>.)   " "%11#7u7u7u7uvvF # "r"ctj|jd}|r|dr|dSdSdS)Nr connected)rHr9rr[)rrrrs r#handleReconnectrsYk&+N;<tj dkr||d }|rm|j|d |jdddg}|D]-}tj|r ||jd<n.ndtj vr|d }|rr||}|j||jdddg}|D]-}tj|r ||jd<n.d|jd<d|jd<d|jd<d |jd<tj d r*t&jt&j}nd}|dz|jd<tjjj|_tjjjj|tjj|S) zCCreate a Instance profile for the local server from the connection.T setupPendingrNrctjd}|sItjd}|st dgS|dz }t j|pd}dtj|D}g}g}|D]}tj tj ||}|rd|vr}|d|krq| |t j|d}|j|jks|j|jkr| ||r|S|S) Nzmysql.profilesrdz"Could not find mysql.profiles dir z/mysql.profilesz5.6c<g|]}|d|S)z.xml)endswith)rfs r#rzEautoDetectLocalInstance..get_profiles_for..s)CCCq 60B0BCCCCr"z sys.systemr)r8rhriget_resource_pathrrfromstroslistdirrH unserializepathrr majorNumber minorNumber) systemrr filesprofilesmatched_profilesrdataprofile_versions r#get_profiles_forz1autoDetectLocalInstance..get_profiles_forsrz~~112BCC &:>>##55b99D ?@@@ % %D/'"2U33CCBJt,,CCC 2 2A?27<<a#8#899D 2 ,,l1Cv1M1M%%%")/$((?2K2K"L"L&/*EEEI\`o`{I{I{$++D111  $# #r"c|dS)Nrr!)rs r#pick_suitable_linux_profilez.pick_suitable_linux_profiles {r"winWindowscHg|]}|ddk|S)rN)ri)rprofrs r#rz+autoDetectLocalInstance..s3dddT/SW9X9X\c9c9cD9c9c9cr"rr windowsAdmindarwinmacOSzsys.config.pathz /etc/my.cnfz/etc/mysql/my.cnflinuxLinuxrdz ssh.hostName3306z ssh.localPortmysqlz ssh.userNamez ssh.useKey~z/.ssh/ssh_private_keyzssh.key) rHclassesdb_mgmt_ServerInstancer.rrparameterValuesrirsplitsysplatformlower startswithupdaterr exists loginInfor8rget_special_folderApplicationDatarIrJrKownerrLrrrrs saveInstances) r.rMrrrpossible_pathspprofilehomedirrs @r#r_r_sg{1133H$HOHM*.H'(,,_dCCG3((7==--bqb1220 |&&u--##Iw77  8 eddddXddd 8#**8A;777./N++      ) )##GW55     & &x{ 3 3 3&1556GHH-YlmN#  7>>!$$=>H'(9:E CL&&(( ( (##GW55  11(;;G   & &w / / /&1556GHH-YlmN#  7>>!$$=>H'(9:E*,H~&*0H')0H~&'(H|$ |&&u--"55f6LMM$+.E$EHy!X[*HNHK)00:::K''))) Or"cTtj}||_|j|_d|jd<tjjj|_ tjjjj |tj j |S)zCreate an Instance profile for the remove server from the connection. Remote admin will be left disabled, to be filled by the user.Tr)rHr#r$r.rrrIrJrKr0rLrrrrsr1)r.rMs r#r`r`s} {1133H$HOHM*.H'X[*HNHK)00:::K''))) Or"cd}tjjjjD]}|j|kr|}nt ||}|jp|jSrG) rHrIrJrKrLr.r r^r)conn the_instancerMr4s r#checkConnectionForRemoteAdminr:s_LHK)9  $ & &#L E 'D,//G   ;w;;r"c*tj|SrG)wb_admin_utilslist_windows_servicesrs r#listWindowsServicesr?s  / @ @@r"cft||}tj|t|SrG)r wba_ssh_uiremote_file_selectorr )r.serverInstancer4s r#openRemoteFileSelectorrDs,J77G  *7OG4L4L M MMr"ceZdZdZdZdS)PasswordExpiredDialogc  tj|d||_|jdd|_ tj|j|_ n#d|_ YnxYw| dtj d}| d| d|jd}td|d|jd d d }|tj||dd tj}| d |d|d|d|dtj d }| dtj}|tjd||dd ||d d ||dd tjtj|_|j d|tdd dd dd tj!tj"z||jd ddd tj!tj#ztjtj|_$|j$ d|tdd dd d dtj!tj"z||j$d dd dtj!tj#ztjtj|_%|j% d|tdd dd ddtj!tj"z||j%d dddtj!tj#ztj&|_'|j'(d|j rO|j')|j *dd |j'+dn|j'+d ||j'tj!tj"ztd }| dtY|_-|j-(dtY|_.|j.(dtj/0||j-|j.|1|dd |2||3dd |4dS)!NrzPassword ExpiredFuserNamezPassword for MySQL account 'z'@zMysql@rdz% expired. Please pick a new password:Trr z wb_lock.pngz Old Passwordz Old Password:rz New Passwordz New Password:zConfirm PasswordzConfirm:zThis server version is < 5.7rrcii,)5r8FormrE_connr%ri versionstrrrrrrry set_spacingrhostIdentifierreplacerz BoldStyler|newTable set_row_countset_column_countset_column_spacingset_row_spacing newImageBox set_imagerhr newTextEntry PasswordEntry old_passwordset_name HFillFlag VFillFlag HExpandFlagpasswordconfirm newCheckBoxlegacyset_text set_activershowrokcancelradd_end_ok_cancel_buttonsadd_end set_contentset_sizecenter) rCr8vboxuserlboxhboxiconbboxs r#rEzPasswordExpiredDialog.__init__%si T4((( .22?DII "?4?;;DLL DLLL )***}U##  #J/ Hcgcgcgimi|jEjEFNPRjSjSjSjST U U F$%%% E4   o  ! Q q!!! A}T"" !## vz~~''99-HHIII ud### dD!!! ud###"/0DEE "">222 $//Aq!V=MfN^=^___ !1aAv/?@R/RSSS+F,@AA  ~... $//Aq!V=MfN^=^___  q!Q6+;F>$'4; / / }--//4<3P3P3R3RRR ++,<?BDHJLNPQQQxxzz!*))++C=>C  9 :{%%'' }1PSdeierfDfDfFfFTGTG2G#I..1FIZ[_[h[y[y[{[{I|I|1|#I.EFd.?.P.P.R.RSSSA FWXXX /0Mq~OmOvx|yFyWyWyYyYZZZZ   #../?QRZ\^__cicrrr E F F F;c!ffDEEEEEEEE F "xxzz!Mqs&A)G I  AH I !II N)rrr rErr!r"r#rFrF$s6JJJZ!!!!!r"rFcHt|}|SrG)rFr)r8dlgs r#handleExpiredPasswordrs  % %C 7799r"c^ddl}|ddl}|jddSr) wb_admin_testrr'exit)whatrr's r#testAdministratorrs=JJJ CHQKKK 1r"cL|D] }|d|zkrdS!dS)Nz[%s]TF)strip) config_filesectionlines r# check_if_config_file_has_sectionrs9 ::<<6'> ) )44 * 5r"c td|d|jdt||}|dkrtrdat d|jz t j|dddattj d nq#t$ra}td t|zd dl}td |d t|zcYd}~Sd}~wYdSxYw tnp#t$rc}td t|zd dl}td |zd t|zcYd}~Sd}~wwxYwt}|r2|\}}} } t d|z||jkr d|jd|Snt)ddSdS|dkr trdadS|dkrdS|dvr|j} t-d| z tj| sd| zSt-dn#t2$rd| zcYSwxYw|dkrdS|j} d} t-d| d|  tj| } nA#t$r4}d dl}|d t|zcYd}~Sd}~wwxYwd!| zd"z| vrdSd#| d$| S|d%vr|j} t j|dd&| } t-d'| zt>j !| rt-d(nd| zS|d)krdS|j} t-d*| d+| tEtG| d,| rt-d-| zdSd.| d/| S|d0krdS|d1kr|j$}d}|%d2r>|&d }tj|sd3|zS|j'}|%d2rD|&d }||kr$tj|sd3|zSdS|d4kr|j$}d}|%d2r>|&d }t>j !|sd3|zS|j'}|%d2rD|&d }||kr$t>j !|sd3|zSdSd5S)6NzTest z in  connect_to_hostz Instance test: Connecting to %s FT)r test_onlyz connected.zException: %s rzBacktrace was: zERROR ERRORz3Instance test: detected remote OS: %s (%s), %s, %s z8ERROR Wrong Remote OS configured for connection. Set to z, but was detected as z:Instance test: could not determine OS version information z+ERROR Could not determine remote OS detailsr disconnectcheck_privileges)find_config_filecheck_config_pathcheck_config_sectionz!Check if %s exists in remote hostzERROR File %s doesn't existz#File was found in expected locationz3ERROR Could not verify the existence of the file %srrdz Check if z section exists in )r []zERROR Couldn't find section z in the remote config file )zfind_config_file/localcheck_config_path/localzcheck_config_section/localrzCheck if %s can be accessedz'File was found at the expected locationrzCheck if section for instance z exists in rz([%s] section found in configuration filezERROR Couldn't find section [z] in the config file find_error_filescheck_admin_commands/zERROR %s is invalidzcheck_admin_commands/localzERROR bad command)(rrr test_ssh_connectionr ssh_hostnamerrrrH send_infornrrror format_stackrkdetect_operating_system_version target_osrconfig_file_pathrssh fileExistsIOErrorconfig_file_section server_helperget_file_contentrpexpand_path_variablesrr r,ropenstart_server_cmdr*r&stop_server_cmd)rr.rr4ruroos_infoos_typeos_name os_variant os_versionrrcfg_file_contentr  cmd_startcmds r#testInstanceSettingByNamersI4449:::J88G     '"& 4w7KKLLL "2"A'4]bnr"s"s"s   $ $ & & & M, ' ' ' ' % % % '#c((2 3 3 3     ()*@*@*B*B C C CCHH$ $ $ $ $ $ $ 77 %  4 4 6 6 6 6 % % % '#c((2 3 3 3     (9+A+A+C+CC D D DCHH$ $ $ $ $ $ $  %&EEGG  A7> 4GWj* KwW X X X'++++ovpApApACJCJKK, U V V V@@t     '"& t # # #w R R R.  1K?@@@ W&*55kBB =4{BB;<<<< W W WH;V V V V W & & &4- GGG[[IJJJ %2@QQWbQcc   % % %        ! ! !CHH$ $ $ $ $ $ $ % 'MC $4 4 44 5PWPWPWYdYdee d d d. &5gtQVWWWmmnyzz  +k9::: 7>>+ & & ? ; < < < <0;> > , , ,4- ++VWWW +Dc,B,BG L L  >),, 4,t33& ??3   4**,,q/Cis(;(;,t33t  suAB D$AD:DD D&& F0AFFF.#I"I""I43I4 J?? K= )K82K=8K=ciSrGr!r>s r#detectInstanceSettingsr?s Ir"c^td|j|}td|j||S)Nrr)rr.)rerrors r#testInstanceSettingsrIs2 %&79SUd e eElO,FXXX Lr"zwb.admin.open_into standalonez Open Into)rqinputrctj|jd}|r||ddSt ddSNrTz8No context found for editor in call to openAdminSection rHr9rrrr-rrs r#openAdminSectionrRsUk&+N;<rs. %%%%%%%% :99999999999 ------++++++MMMMMMMMMMYYYYYYYYYY######666666RQQQQQQQQQQQQQ@\y O O O      i    m1m1m1m1m1m1m1m1d ###  37   4=355 3;5s{7UVVPPWVPf 3;5s{7UVV  WV " 37CK:;;<<<;< 3:sx((AA)(A 3:s{=s{?abbNNcbN oooooFKooof 37CK:;;<;  37CJ''  (' !% 3:sz3;+I3;KmnnKKonK\ 38S[?@@A@ 3:s{ABBCB 'lC\8C\C^C^`o`h`o`q`qBrGRSS 37CK7DDOOEDSSO  NNN.\Jc(JcJeJegvgogvgxgxIyNYZZsw ;SZHHSSIHZZSS    D  &\B[(B[B]B]A^r|}} 37CK788&&98~}& 2NghNgNiNiMjUVV 37CK788 ~ ~98VV ~ ~ ~sA3N88O?O