Xׯdr ddlZddlmZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z ddlZdddiiZGdd eZGd d eZGd d eZGddeZGddeZdS)N) currentThread)wbaOS)OperationCancelledErrorInvalidPasswordErrorUsers sudo_commandz)/usr/bin/sudo -k -S -p EnterPasswordHere ceZdZdDdZdZdEdZdEdZdFdZdFd Ze d Z e d Z e d Z e d Z e dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe d Z e d!Z!e d"Z"e d#Z#e d$Z$e d%Z%e d&Z&e d'Z'd(Z(d)Z)e e(e)Z(e d*Z*d+Z+d,Z,e e+e,Z+d-Z-d.Z.e e-e.Z-d/Z/d0Z0e e/e0Z/d1Z1d2Z2e e1e2Z1d3Z3d4Z4e e3e4Z3d5Z5d6Z6e e5e6Z5d7Z7d8Z8e e7e8Z7d9Z9d:Z:e e9e:Z9d;Z;e d<ZZ>e d?Z?e d@Z@dAZAe dBZBdCS)G ServerProfileFcL||_||_||_d|_d|_dSN)disable_remote_admin_ServerProfile__connection_ServerProfile__settings_ServerProfile__os_specificsexpanded_config_file_path)self connectioninstance_profileforce_remote_admin_offs ..\modules\wb_server_control.py__init__zServerProfile.__init__0s/$:!&*")-&&&c|jSr )rrs rget_settings_objectz!ServerProfile.get_settings_object7s rrc|js|S |jj|}n#t$r|}YnwxYwt|tur t |}n #|}YnxYw||S|Sr )r serverInfoKeyErrortypeintrname default_valuevalues r_int_server_infozServerProfile._int_server_info:s !  "O.t4EE " " "!EEE " ;;c ! ! %5zz %$ =  s --AAc |jj|}n#t$r|}YnwxYwt|tur t |}n #|}YnxYw||S|Sr )r loginInforr r!r"s r_int_login_infozServerProfile._int_login_infoKs "O-d3EE " " "!EEE " ;;c ! ! %5zz %$ =  s $$AArc|js|S |jj|}n#t$r|}YnwxYw||}n;t|tur%t|turt |}|Sr )rrrr strr"s r_str_server_infozServerProfile._str_server_infoZs !  "?-d3EE " " "!EEE " = EE %[[ # #U 3(>(>u::E s  --c |jj|}n#t$r|}YnwxYw||}n;t|tur%t|turt |}|Sr )rr(rr r+r"s r_str_login_infozServerProfile._str_login_infohsy "?,T2EE " " "!EEE " = EE %[[ # #U 3(>(>u::E s  $$c|jjSr )rr#rs rr#zServerProfile.namets %%rc|jSr )rrs rdb_connection_paramsz"ServerProfile.db_connection_paramsxs   rcttdr tjSdtjvr tjSdtjvr tjStjS)Ngetwindowsversioninuxarwin)hasattrsysrwindowsplatformlinuxdarwinunknownrs rhost_oszServerProfile.host_os|sO 3+ , , =  $$; %%< }rcztj} |jjd}n #d}YnxYw|t |t ust |t ur\|d}|dkr tj}n)|dvr tj }nd|vr tj }n|j }|S)Nz sys.systemz r8)r:freebsd opensolarismacos) rr<rrr r+striplowerr8r:r;r=)rretsystems r target_oszServerProfile.target_oss m _/ =FF FFF  $v,,#"5"5f9L9L\\),,2244F""m>>>kV##l,C s!'c,|jtjkSr )r=rr8rs rhost_is_windowszServerProfile.host_is_windowss|u},,rc,|jtjkSr )rFrr8rs rtarget_is_windowszServerProfile.target_is_windowss~..rc>|js|j o|jo|j Sr )uses_sshis_localuses_wmirrs rremote_admin_enabledz"ServerProfile.remote_admin_enableds' Fdm"3"E iPTPiLiirc|jp|jSr )rMrOrs r admin_enabledzServerProfile.admin_enableds}9 99rcgd} |jry|jj}|rk|jjrN|jjjdkr |d|vS|jjjdkrdS|jjjdkrdSndd lm}|d dS) N) localhostr0z 127.0.0.1z::1T MysqlNativehostNameMysqlNativeSocketMysqlNativeSSHFr)NoDriverInConnectionzWorkbench has not found a driver for the connection that is being used by this server instance. Please edit your connection settings and try again.)r1parameterValuesdriverr# wb_commonrY)r local_addrsparamsrYs rrMzServerProfile.is_locals@@@  ( 82B 807 84;@MQQ#)*#5#DD!6=BFYYY#'4!6=BFVVV#(5WCBBBBB22478885rcJd}|jrd}n|jrd}n |jrd}nd}|S)Nwmisshlocalnone)rNrLrMrrDs rconnect_methodzServerProfile.connect_methodsF = CC ] CC}  rcld}|jr*|jjjdkrd}n|jjd}|S)NrWrSrVr1r[r#rZ)r host_names rrhzServerProfile.host_namesE  $ R(/48KKK'  5EjQ rcfd}|jr'|jjjdkr|jjd}|S)Ni rWportrg)rrjs rrjzServerProfile.ports=  $ I(/48KKK0@H rc8|jr|jjdSdS)NuserNamer)r1rZrs rmysql_usernamezServerProfile.mysql_usernames$  $ I,Ahk>Q>YZh>i>usx{"*>::{||rctjjjjd!tjjjjdndS)N sshtimeout rrs r ssh_timeoutzServerProfile.ssh_timeouts2???rcXd}|jr d|jz}n|d}|S)N sc start sys.mysqld.startrNrr,rds rstart_server_cmdzServerProfile.start_server_cmd$s9 = < 55CC''(:;;C rcXd}|jr d|jz}n|d}|S)Nsc stop sys.mysqld.stoprrds rstop_server_cmdzServerProfile.stop_server_cmd-s9 = ;t44CC''(9::C rc,|dS)N sys.usesudorprs ruse_sudozServerProfile.use_sudo6rqrcp|jr|jS|dddS)z path to configuration file (eg my.cnf) may contain path variables that need to be expanded, such as %ProgramPath% zsys.config.pathr )rr,rBrs rconfig_file_pathzServerProfile.config_file_path:s=  ) 21 1$$%6;;AA+NNNrcT|dddS)Nzsys.config.sectionrr)r,rBrs rconfig_file_sectionz!ServerProfile.config_file_sectionDs'$$%92>>DD[QQQrc.|ddSN serverVersionrrs rserver_versionzServerProfile.server_versionIs$$_d;;;rc$||jjd<dSrrr)rversions rset_server_versionz ServerProfile.set_server_versionLs6="?333rc |jsdS|jd}g}|D]N}tjd|}|r5|t |dOt|S)N.z(\d+).*)rsplitrematchappendr!grouptuple)rversion_tokensvertokenrs rserver_version_tuplez"ServerProfile.server_version_tupleQs" 2,22377# 0 0EHZ//E 0 3u{{1~~..///Szzrc,|dSN logOutputrrs r log_outputzServerProfile.log_output^s$$[111rc$||jjd<dSrr)routputs rset_log_outputzServerProfile.set_log_outputas28";///rc,|dSNgeneralLogEnabledrprs rgeneral_log_enabledz!ServerProfile.general_log_enabledgs$$%8999rc$||jjd<dSrrrr%s rset_general_log_enabledz%ServerProfile.set_general_log_enabledjs:?"#6777rc,|dSNslowLogEnabledrprs rslow_log_enabledzServerProfile.slow_log_enabledps$$%5666rc$||jjd<dSrrrs rset_slow_log_enabledz"ServerProfile.set_slow_log_enabledss7<"#3444rc,|dSNgeneralLogFilePathrrs rgeneral_log_file_pathz#ServerProfile.general_log_file_pathys$$%9:::rc$||jjd<dSrrrpaths rset_general_log_file_pathz'ServerProfile.set_general_log_file_path|s;?"#7888rc,|dSNslowLogFilePathrrs rslow_log_file_pathz ServerProfile.slow_log_file_paths$$%6777rc$||jjd<dSrrrs rset_slow_log_file_pathz$ServerProfile.set_slow_log_file_paths8<"#4555rc,|dSNerrorLogFilePathrrs rerror_log_file_pathz!ServerProfile.error_log_file_paths$$%7888rc$||jjd<dSrrrs rset_error_log_file_pathz%ServerProfile.set_error_log_file_paths9="#5666rc,|dSNdatadirrrs rrzServerProfile.datadir$$Y///rc$||jjd<dSrrrs r set_datadirzServerProfile.set_datadir04"9---rc,|dSNbasedirrrs rrzServerProfile.basedirrrc$||jjd<dSrrrs r set_basedirzServerProfile.set_basedirrrc~||jjd<||jjd<||jjd<||jjd<dS)Ndetected_os_typedetected_os_namedetected_os_variantdetected_os_versionr)ros_typeos_name os_variant os_versions rset_os_version_infoz!ServerProfile.set_os_version_infosH9@"#569@"#56>>Xn.@AAN   X 222999*n55J:::@@@#(#68OPP777=== x 02FGG;;;@@@%H%:>>#(#68OPP000555hw ,,G000555hw ,,GGGG >>X>>>X>AAXAAAXAHHXH333  X   rr c.eZdZdZdZdZdZddZdS) PasswordHandlerc"||_i|_dSr )server_profile pwd_store)rrs rrzPasswordHandler.__init__s,rc|j}d}|dkr |jrd}ngd}nd|dkr|jrd}nT|jrd}nJd}nG|dkr|jr |jrd}n0d}n-|dkrd}n$|dkrd}n|d krd }nt d |z|S) NfileUACsudoservice.startstopr` remoteshellsshkeyrarbzUnknown password type: %s)rrJrrLr Exception)r service_typeprofile password_types rget_password_typez!PasswordHandler.get_password_types% 6 ! !( ' % & 0 0 0( ) % #)$*MM$(MM ] * * *%*$,MM$)M U " "!MM X % %$MM W $ $#MM7,FGG GrcP|j}||}|dkrd}|jr d|jvrd}|jr"|dkr|j}nd}d|z}|d|j}nQ|dkr?ddl} |tj d}|sd}n #d}YnxYwd}d|z}d|z}|||fS|dkrdd |j d |j |j fS|d krd d |j z|jfS|dkrdS|dkrdd|jz|jfS|dkrdd|jz|jfSdS)Nrrz%s Password Required@rz %s@localhostrbrzMysql@:r`zWMI Password Requiredzwmi@%srrazSSH Login Password Requiredzssh@%sr z!SSH Private Key Password Requiredzssh_keyfile@%s)rr%rrLrvrypwdgetpwuidosgetuidrhrjrmrrr) rr"r#r$ sudo_typeaccounttitleservicer)s rget_password_parametersz'PasswordHandler.get_password_parameterss %..|<<  F " "I" #vW5H'H'H"  5&&%2GG$G.y8#,99g.B.BC&&JJJ)"%,,ry{{";";A">&-&,G)"($G. 9(947G, , g % %B):):):GLLI7Kab b e # #+X8L-LgNbc c e # #5 e # #18g>R3RT[Thi i h & &79IGO9[]d]qr r4s +0BB"cZ||}||jvr d|j|<dSdSr )r%r)rr"r$s rreset_password_forz"PasswordHandler.reset_password_for8s<..|<< DN * *,0DN= ) ) ) + *rFc  d}||}||jvr|j|d}n |j|S||}|sdS|dkrdS|\}}}tjd|jjzd|d|d|d|d |r)tj ||\} } | r| SdStj ||||\} } | r| sd } | |j|<| Std ) NFTrz%s:get_password_for()zrequest password for "z" => "z", "z" rzPassword input cancelled) r%rr1r log_debug2 __class__rmforms Utilities find_passwordfind_or_ask_for_passwordr) rr" cached_only force_resetr$detailsr/r0r.foundpasswordaccepteds rget_password_forz PasswordHandler.get_password_for?s ..|<< DN * *~m,4" ~m44..|<< 4 e  5")w .1HHH@L@L@LNSNSNSU\U\U\^e^e^eKf g g g  J$.<z,ServerControlBase.__init__..lsmNbNbcgNhNhr)r#helperpassword_delegaterGoutput_handler)r serverProfilerIrJs rrzServerControlBase.__init__fs:$  !2:>:Lhhhrcn||_|jr|jD]}||d|_dSr )rKrG)rhandlerrFs rset_output_handlerz$ServerControlBase.set_output_handlernsL%   ** * *##D))))!rc0||dSr )rK)rtexts rinfozServerControlBase.infous D!!!!!rcdSr rrs rclosezServerControlBase.closexs rctr NotImplementedErrorrfinish_callbacktry_without_passwords r start_asynczServerControlBase.start_async|!###rctr rVrXs r stop_asynczServerControlBase.stop_asyncr\rc |||ddS#t$r*}| |dn|dYd}~dSYd}~dSd}~wt$r.}ddl}|||Yd}~dSd}~wwxYw)Nsuccess need_password bad_passwordr)rr! traceback print_exc)ractionr?rYerrrcs r worker_threadzServerControlBase.worker_threads ! F8    OI & & & & &# 0 0 00000/////////100000 ! ! !        ! ! ! OC  !s  BA  B#A??BrcdSr r)rverboses r get_statuszServerControlBase.get_statusstrNr) rrrrrOrRrTr[r^rgrjrrrrCrCesiii""""""   $$$$$$ ! ! !rrCc8eZdZdZd dZd dZd dZdZdZdS) ServerControlShellc@t||||dS)z' Can also throw OperationCancelledErrorN)rCr)rr#rIrJs rrzServerControlShell.__init__s#""4&:KLLLLLrFc:|jd|S)Nr)r;)rJrA)rrZs r get_passwordzServerControlShell.get_passwords %667JXl6mmmrc&|jjs|ddS|jjr( ||}n#t $rYdSwxYwd}t j|j|j ||f}| dS)NzCommand to start the server is not configured. Please set the command that must be used to start the server in the remote management section of this connections settings.FtargetargsT) r#rrRrror threadingThreadrgstartrunrrYrZr?threads rr[zServerControlShell.start_asyncs|,  IIC D D D5 <   ,,-ABB*   uu H!);4:xYhBijjj tA AAc&|jjs|ddS|jjr( ||}n#t $rYdSwxYwd}t j|j|j ||f}| dS)NzCommand to stop the server is not configured. Please set the command that must be used to stop the server in the remote management section of this connections settings.FrqT) r#rrRrrorrtrurgstoprwrxs rr^zServerControlShell.stop_asyncs|+  IIA B B B5 <   ,,-ABB*   uu H!);49hXgBhiii trzcvd djjzjjr tjn tj}jjj|fd}n)#t$rj dwxYw|rdSdS)$ Can also throw InvalidPasswordErrorStarting server...Executing '%s'cdt|tust|tur|ndpddzS)NzStart server: %sr)rRr r+replace)sr?rs rrHz*ServerControlShell.start..sDIIFXaefgahahloaoaouyz{u|u|ADvDvDZ[Z[LNZWZWX`XfdfhjZkZkGk=l=lras_user user_passwordrKrTF) rRr#rrrADMINCURRENTrIexecute_commandrrJr3)rr?rrs`` rrvzServerControlShell.starts &'''  II&)FF G G G%)\%:Mekk G ++DL,I,32:4l4l4l4l4l,mmAA$     " 5 56I J J J    4us A2B &B2czd fd}jjr tjn tj}djjzjjj||}n)#t$rj dwxYw|rdSdS)r~zStopping server...c|Kt|tust|turdkr|d}nd}dt|zdS)NrzStop server: %s)r r+rrR)rr?rs r strip_pwdz*ServerControlShell.stop..strip_pwdsu%4<<3+>+>$v,,RUBUBU+B!'"!=!=F +CKK788888rrrrTF) rRr#rrrrrrIrrrJr3)rr?rrrs`` rr|zServerControlShell.stops &'''  9 9 9 9 9 9&*\%:Mekk G II&)EE F F F ++DL,H,32:3<,>>AA$     " 5 56I J J J    4us A4B&B4Nr) rrrrror[r^rvr|rrrrlrlsMMMnnnn        (rrlc\eZdZdZdZdZedZdZdZ dZ dZ d Z d d Z d S)ServerControlWMIct||||tjj|_i|_d|_|jj rGd}d}d}| |t||||_| dn,|jj }|jj}|} |j|||pd}||jt#<n<#t$$r/}ddl} | t+d|zd}~wwxYw|jdkrt+ddS)NrzAWorkbench will use cmd shell commands to start/stop this instancerz&Could not initialize WMI interface: %sz"Could not initialize WMI interface)rCrrmodules Workbenchr`wmi_session_idsshellr#rM'check_and_fix_profile_for_local_windowsrlrRrrrowmiOpenSessionrr!rcrd RuntimeError!wmi_session_id_for_current_thread) rr#rIrJuserserverr?sessexcrcs rrzServerControlWMI.__init__sj""4&:KLLL;(! < +DFH  8 8 A A A+GV=NOODJ IIY Z Z Z Z<,D\.F((**H M8**64RHHD48D  1 1 M M M        ! ! !GKLL L M  1Q 6 6CDD D 7 6s4C77 D0*D++D0ch|}|j}d|d<|j}|dkrdx}|d<|d|jdks ||jvrd|z|d<t d |jz|jdks ||jvr!d |z|d <t d |jzdSdS) NrrrMySQLrz]MySQL service was empty. Set to 'MySQL'. Check this in 'Manage Server Instances' from 'Home'.rrz#WMIShell: start command set to '%s'rrz"WMIShell: stop command set to '%s')rrrrRrprintr)rr#settingsrr0s rrz8ServerControlWMI.check_and_fix_profile_for_local_windowss..00( $% =!* b==>E EGj!:; IIu v v v  #r ) )gW=U.U.U-87-BJ) * 78PP Q Q Q  "b ( (WGrs,######  &&&&&&JJJJJJJJJJ D  cccccFcccL MJMJMJMJMJfMJMJMJ`,,,,,,,,^SSSSS*SSSlQQQQQ(QQQQQr