@Qc@shddlZddlZddlZddlZddlZddlZddlZddlZddlZdZ ddl m Z m Z m Z ddlmZddl mZmZmZddlmZmZmZmZmZmZejjeZdefdYZd Z d Z!e j"d Z#d efd YZ$e j%e&e e&dZ'e j%e&e&e&dZ(ej)dkre(Z*ne'Z*e j%e&dZ+gZ,defdYZ-de-fdYZ.e,j/e.de-fdYZ0e,j/e0de-fdYZ1e,j/e1dZ2dZ3dZ4dZ5dZ6dZ7d e-fd!YZ8e,j/e8d"e8fd#YZ9e,j/e9gZ:d$efd%YZ;e:j/e;d&efd'YZ<e:j/e<d(e<fd)YZ=e:j/e=d*efd+YZ>e:j/e>d,e>fd-YZ?e:j/e?d.efd/YZ@dS(0iNs"/usr/bin/sudo -p EnterPasswordHere(t splitpathtUserstsanitize_sudo_output(t WbAdminSSH(tInvalidPasswordErrortPermissionDeniedErrortjoinpath(tlog_infot log_errort log_warningt log_debugt log_debug2t log_debug3twbaOScBs)eZdZdZdZdZdZRS(tunknowntwindowstlinuxtdarwincCs tdS(N(tNotImplementedError(tselftnametvalue((s"..\modules\wb_server_management.pyt __setattr__+s(t__name__t __module__RRRRR(((s"..\modules\wb_server_management.pyR %s cCs3|jdrd|dSd|jddSdS(Ns~/s~/"%s"is"%s"t"s\"(t startswithtreplace(tpath((s"..\modules\wb_server_management.pyt quote_path.s cCs d|jddjddS(Ns"%s"t/s\Rs\"(R(R((s"..\modules\wb_server_management.pytquote_path_win5scCs|stdn|s$t}n|tjkr|tjkrad|}|jd|}nd|ksyd|kr|d|jddjd d jd d d }q|d |jddjd d jd d d }n|S(Ns)Empty command passed to execution routines sudo -u %stsudos/bin/shs /bin/bashs "s\s\\Rs\"t$s\$s /bin/sh -c "(t Exceptiontdefault_sudo_prefixRtCURRENTtADMINR(tcommandt sudo_prefixtas_usert sudo_user((s"..\modules\wb_server_management.pyt wrap_for_sudo9s  99tSSHcBsGeZdZdZdZdZejdddddZ RS(cCs#tj|_|j||dS(N(t threadingtLocktmtxtwrapped_connect(Rtprofiletpassword_delegate((s"..\modules\wb_server_management.pyt__init__UscCsttd|jdS(NsClosing SSH connection (R t _this_filetclose(R((s"..\modules\wb_server_management.pyt__del__Ys cCs8|jjztj||}Wd|jjX|S(N(R.tacquireRt get_contentstrelease(Rtfilenametret((s"..\modules\wb_server_management.pyR7]s  cCs;|jjztj|||}Wd|jjX|S(N(R.R6Rt set_contentsR8(RR9tdataR:((s"..\modules\wb_server_management.pyR;es  ic Csd}d}|jjttd|jj|t|fzWtj ||d|d|d|d|d|\}}ttd|jj|fWd|jj X||fS(Ns%s:exec_cmd(cmd="%s", sudo=%s) R(t user_passwordtoutput_handlert read_sizetget_channel_cbs%s:exec_cmd(): Done cmd="%s" ( tNoneR.R6R R3t __class__RtstrRtexec_cmdR8( RtcmdR(R=R>R?R@toutputtretcode((s"..\modules\wb_server_management.pyRDms &!N( RRR2R5R7R;RR$RARD(((s"..\modules\wb_server_management.pyR+Ts     c Csddl}|tjkr0t|||}n|jd}|dks]t|dkradS|}tj}|d|j }d} t } |j dd|g} |tjkrya| j ddd | j std nt} |dk r | j|n | jd Wq|jk rW|dk rG| j|q| jd q|jk r|r|| jjd d nttd|qXn| j rt } x| r| j ry| jdd} | r| jdrt } | d} n|tjkr[| jddkr[y| jWnnX|jtdn|rz|| jd d nWq|jk rq|jk rt} qXqWn| j} | r| jdrt } | d} n| r |r || jd d n| j|j}|j|jd}|dkrft||djd} nttd|t | f| S(Nit is ; echo CMDRESULT$? >> s /bin/bashs-ctasswordttimeouti s expect diedts s s=local_run_cmd_linux(): Pipe from sudo is closed. script = %s iitHereitEnterPasswordHeresIncorrect password for sudot CMDRESULTi s s-local_run_cmd_linux(): script="%s", ret="%s" (!tpexpectRR$R*tstripRAtlenttempfiletNamedTemporaryFileRtFalsetspawntexpecttisaliveR"tTruetsendlinetTIMEOUTtEOFtbeforeRR R3tread_nonblockingRtfindR4RtreadtrfindtintR RC(R&R(R=R'R>ROtscriptt script_to_logt temp_filetresulttwaiting_rest_of_password_prompttchildtshould_quit_read_loopt current_textttexttidx((s"..\modules\wb_server_management.pytlocal_run_cmd_linuxs       $         c Cs d}d}|tjkrfd|}yddlm}m}m} ddlm} m} m } ||| | | | | | } |j d}|d}|d }dddd |fdd|fddf}| d| j f|}|}d}|dkrd}n7|dkr't td|nt td||f|SWqddl}|jqXnyztj|dtjdtjdtjdt}x0t|jjdD]}|r||qqW|j|j}Wn9tk r}ddl}|jd}d|}nX|S(NRKis cmd.exe /C i(tc_intt WINFUNCTYPEtwindll(tHWNDtLPCSTRtUINTRHiithwndt operationtrunastfiletparamstdirtshowcmdt ShellExecuteAi s6local_run_cmd_windows(): Out of memory executing "%s" s1local_run_cmd_windows(): Error %i executing "%s" tstdintstdouttstderrtshellsInternal error: %s(iRsi(iRtRu(isdirN(iRyi(RR$tctypesRmRnRotctypes.wintypesRpRqRrt partitionRAtshell32RR3t tracebackt print_exct subprocesstPopentPIPEtSTDOUTRXtiterR|treadlinetwaitt returncodeR"(R&R(R=R'R>tout_strRGRmRnRoRpRqRrt prototypet scriptpartstcmdnamet cmdparamst paramflagst SHellExecuteR:Rtprocesstlinetexc((s"..\modules\wb_server_management.pytlocal_run_cmd_windowssJ   *     0    tWindowsc CsLg}|d}td|d|d|ddd|}dj||fS(NcSs |j|S(N(tappend(Rtl((s"..\modules\wb_server_management.pytsR&R(R=R'R>s (t local_run_cmdRAtjoin(R&R(R=RFR>trc((s"..\modules\wb_server_management.pytlocal_get_cmd_outputs 'tProcessOpsBasecBs;eZdZdZdZdZejddZ RS(RKcKsdS(N((Rtkwargs((s"..\modules\wb_server_management.pyR2-scCsdS(N((R((s"..\modules\wb_server_management.pyt post_init0scCs|S(N((RR((s"..\modules\wb_server_management.pytexpand_path_variables3scCs=g}|d}|j||||}dj||fS(NcSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyR8ss (RDR(RR&R(R=RFR>R((s"..\modules\wb_server_management.pytget_cmd_output6s N( RRtcmd_output_encodingR2RRRR$RAR(((s"..\modules\wb_server_management.pyR*s    tProcessOpsNopecBsGeZedZdZejdddZejddZ RS(cCs|\}}}|dkS(Ntnone((tclst.1thostttargettconnect((s"..\modules\wb_server_management.pytmatch>s cCs|S(N((RR((s"..\modules\wb_server_management.pyRBscCsdS(N(RA(RR&R(R=R>((s"..\modules\wb_server_management.pyRDEscCsdS(NRK(RKN(RA(RR&R(R=((s"..\modules\wb_server_management.pyRHsN( RRt classmethodRRRR$RARDR(((s"..\modules\wb_server_management.pyR=s tProcessOpsLinuxLocalcBs5eZedZdZejdddZRS(cCsI|\}}}|dkoH|tjtjfkoH|tjtjfkS(Ntlocal(R RR(RRRRR((s"..\modules\wb_server_management.pyROs cKs)tj|||jdt|_dS(NR'(RR2tgetR#R'(RR((s"..\modules\wb_server_management.pyR2SscCst||||j|S(N(RlR'(RR&R(R=R>((s"..\modules\wb_server_management.pyRDWsN( RRRRR2RR$RARD(((s"..\modules\wb_server_management.pyRNs tProcessOpsLinuxRemotecBs5eZedZdZejdddZRS(cCs1|\}}}|dko0|tjtjfkS(Ntssh(R RR(RRRRR((s"..\modules\wb_server_management.pyR^s cKs6tj|||jdt|_|d|_dS(NR'R(RR2RR#R'R(RR((s"..\modules\wb_server_management.pyR2cscs|tjkr't||j|}nd|rK|fd}nd}|jr|jj|d|d|d|\}}n+d}|r|dndGHttd|S( NcSs~ddl}t}xe|ryy>|jd}|dk rR|dkrR||nt}Wq|jk rut}qXqWdS(NiiRK(tsocketRXtrecvRARTRJ(t ssh_channelthandlerRtlooptchunk((s"..\modules\wb_server_management.pytssh_output_handlerps    cs ||S(N((tchanth(R(s"..\modules\wb_server_management.pyR~sR(R=R>isNo SSH connection is activesNo SSH connection is active ( RR$R*R'RARRDRR3(RR&R(R=R>Rt dummy_textR:((Rs"..\modules\wb_server_management.pyRDis      N( RRRRR2RR$RARD(((s"..\modules\wb_server_management.pyR]s sMreg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v "ProgramFilesDir"sSreg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v "ProgramFilesDir (x86)"s%ProgramFiles%s%ProgramFiles(x86)%s%ProgramW6432%s %ProgramData%tProcessOpsWindowsLocalcBsGeZedZdZdZddZdZdZ RS(cCs7|\}}}|tjko6|tjko6|dkS(NtwmiR(Rslocal(R R(RRRRR((s"..\modules\wb_server_management.pyRs cKstj||i|_dS(N(RR2ttarget_shell_variables(RR((s"..\modules\wb_server_management.pyR2scCs|jdS(N(tfetch_windows_shell_info(R((s"..\modules\wb_server_management.pyRscCst|||d|S(N(RRA(RR&R(R=R>((s"..\modules\wb_server_management.pyRDscCs6x/|jjD]\}}|j||}qW|S(s Expand some special variables in the path, such as %ProgramFiles% and %ProgramFiles(x86)% in Windows. Uses self.target_shell_variables for the substitutions, which should have been filled when the ssh connection to the remote host was made. (Rt iteritemsR(RRtktv((s"..\modules\wb_server_management.pyRscCs|jd\}}|dkr_|jdj}t|dkrd|d|_qn,d|GHttd|jjt |f|jd\}}|r|j}nd}d}|d krt }t }nQ|jd \}}|r|j}n|d kr!t }t }n t }t }|jd |\}}|dkr|jd |jd<|dkr|jd |j|eZedZdZdZejdddZ RS(cCs(|\}}}|tjko'|dkS(NR(R R(RRRRR((s"..\modules\wb_server_management.pyRs cKs!tj|||d|_dS(NR(RR2R(RR((s"..\modules\wb_server_management.pyR2scCs|jr|jndS(N(RR(R((s"..\modules\wb_server_management.pyRs cszd|}|js"tdnd|rF|fd}nd}|jj|d|d|d|\}}|S(Ns cmd.exe /c sNo SSH session activecSs~ddl}t}xe|ryy>|jd}|dk rR|dkrR||nt}Wq|jk rut}qXqWdS(NiiRK(RRXRRARTRJ(RRRRR((s"..\modules\wb_server_management.pyRs    cs ||S(N((RR(R(s"..\modules\wb_server_management.pyRsR(R=R>(RR"RARD(RR&R(R=R>RRR:((Rs"..\modules\wb_server_management.pyRD s    N( RRRRR2RRR$RARD(((s"..\modules\wb_server_management.pyRs  t FileOpsNopecBseZedZd d dZejd dZejd dZ ejd dZ ejd dZ ejd dZ ejd dZ ejd dZejd d Zejd d Zejd d Zd ZRS(cCs |dkS(NR((Rt target_ostconnection_method((s"..\modules\wb_server_management.pyR4scCsdS(N((Rt process_opsRR((s"..\modules\wb_server_management.pyR28scCsdS(N((RR9tcontentR(R=((s"..\modules\wb_server_management.pytsave_file_content;scCsdS(N((RR9Rtbackup_extensionR(R=((s"..\modules\wb_server_management.pytsave_file_content_and_backup>scCsdS(NRK((RR9R(R=((s"..\modules\wb_server_management.pytget_file_contentAscCsdS(N((RtsourcetdestR(R=((s"..\modules\wb_server_management.pyt _copy_fileDscCstS(N(RT(RRR(R=((s"..\modules\wb_server_management.pytcheck_dir_writableGscCstS(N(RT(RRR(R=((s"..\modules\wb_server_management.pyt file_existsJscCstS(N(RT(RRR(R=((s"..\modules\wb_server_management.pytget_file_ownerMscCsdS(N((RRR(R=((s"..\modules\wb_server_management.pytcreate_directoryPscCstS(N(RT(RRR(R=((s"..\modules\wb_server_management.pytget_available_spaceSscCsgS(N((RRR(R=((s"..\modules\wb_server_management.pytlistdirWscCsgS(N((RR((s"..\modules\wb_server_management.pyt get_ownerZsN(RRRRRAR2RR$RRRRRRRRRRR(((s"..\modules\wb_server_management.pyR3stFileOpsLocalUnixcBseZedZdZdddZejddZ ejddZ ejddZ ejddZ ejddZ ejddZejddZejdd Zejdd Zejdd Zejdd Zejdd ZRS(cCs"|dko!|tjtjfkS(NR(R RR(RRR((s"..\modules\wb_server_management.pyRoscCs+||_||_tjjd|_dS(Nt~(RRtosRt expanduserttempdir(RRRR((s"..\modules\wb_server_management.pyR2ts  cCs5|jjdt|||dd}|dkS(Nstest -e R>cSsdS(N(RA(R((s"..\modules\wb_server_management.pyR}si(RRDR(RR9R(R=tres((s"..\modules\wb_server_management.pyRys  cCstj}|jjdt|||d|j}t|jj}d}|r|jddjj}d|d|df}n|S( Ns df -Ph %sR>sCould not determines is%s of %s availableii( tStringIORRDRtwriteRtgetvalueRPR(RRR(R=t output_textRt availablettokens((s"..\modules\wb_server_management.pyRs  cCsr|jtjkrd}nd}g}|t|}|jj|||d|ddj|j}|S(Ns stat -c %U sstat -f "%Su" R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRss (RR RRRRDRRP(RRR(R=R&RFR((s"..\modules\wb_server_management.pyRs   cCs|j||d||dS(N(RRA(RR9RR(R=((s"..\modules\wb_server_management.pyRsc Cs@ttd|jj||f|tjkrtj}|j}yDttd|jj|f|j ||j |rt j j |rttd|jj|||f|jd|d||d|d|nttd|jj||f|jd|d|dtjd||tjkrf|jjd |t|fdtjd|nttd |jj|jWq<tk r}ttd |jjt|f|r|jnq<Xnbt|d } t j j | s2ttd |jj| fttjd| ny|j| Wn?tk r} ttd|jj| | ftdnXt j j |r|rttd|jj|f|j|||nyt|d} Wn>tk r$} | jtjkrtd|n| nX| j || jdS(Ns-%s: Saving file "%s" with backup (sudo="%s") s+%s: Writing file contents to tmp file "%s" s$%s: Creating backup of "%s" to "%s" RRR(R=sA%s: Copying over tmp file to final filename using sudo: %s -> %s s chown %s %ss%s: Copying file done s%s: Exception caught: %s is)%s: Target directory "%s" does not exist sThe directory %s does not exists.%s: Target directory "%s" is not writable: %s s Cannot write to target directorys-%s: Target file "%s" exists, creating backup tws"Could not open file %s for writing( R R3RBRRR$RRRSRRtflushRRtexistsRR%RRDRR4R"RRCRtIOErrorterrnotENOENTRRtopentOSErrortEACCES( RR9RRR(R=ttmpttmp_nameRt target_dirtetfterr((s"..\modules\wb_server_management.pyRsZ     $ %  #     c Csg}|tjkrtj}td|||d|jjd|j|j}d|krt}t j |_ |n|Syt |d}WnDtt fk r}|j t j krtd|n|nX|j}|j|S(Nscat %sR'R>sNo such file or directorytrsCan't open file '%s'(RR$RRlRR'RRRRRRRRRR_R4( RR9R(R=tcontRFterrorRR((s"..\modules\wb_server_management.pyRs& )        c Cs|tjkrjytj|Wqttfk rf}|jtjkr]td|n|qXndg}|j j dt |d|d|d|d}|dkrdj |}t |ndS( NsCould not create directory %ss /bin/mkdir R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyR sis (RR$RtmkdirRRRRRRRDRRt RuntimeError(RRR(R=RRFR((s"..\modules\wb_server_management.pyRs  c Cs|tjkrjytj|Wqttfk rf}|jtjkr]td|n|qXndg}|j j dt |d|d|d|d}|dkrdj |}t |ndS( NsCould not remove directory %ss /bin/rmdir R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyR!sis (RR$RtrmdirRRRRRRRDRRR(RRR(R=RRFR((s"..\modules\wb_server_management.pytremove_directorys  c Cs|tjkrjytj|Wqttfk rf}|jtjkr]td|n|qXndg}|j j dt |d|d|d|d}|dkrdj |}t |ndS( NsCould not delete file %ss/bin/rm R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyR5sis (RR$RtremoveRRRRRRRDRRR(RRR(R=RRFR((s"..\modules\wb_server_management.pyt delete_file(s  c Cs|tjkrpytj||Wqttfk rl}|jtjkrftd||fnqXng}|j j dt |dt |d|d|d|d}|dkrd j |}|j d d krtd ||fqd |G|G|GHndS(NsCan't copy %s to %ss/bin/cp RHR(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRIsis sPermission deniedis"Permission denied copying %s to %ssfile copy as %s failed: (RR$tshutiltcopyRRRRRRRDRRR^(RRRR(R=RRFR((s"..\modules\wb_server_management.pyR<s" ' cCs t|d}g}|jjdt|||d|d}|dkr{|jjdt|||ddntdj|j}d}d |krtd }t j |_ n7d |krt d }t j |_ nt d |}||dkS(Ns.wb_write_teststouch R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyR_sis/bin/rm cSsdS(N(RA(R((s"..\modules\wb_server_management.pyRdss sNo such file or directorysThe directory does not existsPermission deniedsPermission denied for writings*Unable to verify directory is writable: %s(RRRDRRRRPRARRRRRR"(RRR(R=R9RFRR((s"..\modules\wb_server_management.pyRVs,      c Csg}|tjkry|}tj|}x|D]}tjj||}tj|j}tj|r|j d|dq4tj |stj |r4|j |q4q4WWnAt tfk r} | jtjkrtd|nnX|Stj} |jjdt|||d| j} t| j} | dkrd| krvtd|nt| n&g| jdD]} | j^qSdS(NiRsPermission denied accessing %ss/bin/ls -1 -p R>sPermission denieds (RR$RRRRtstattst_modetS_ISDIRtinserttS_ISREGtS_ISLNKRRRRRRRRRDRRRRRRRP( RRR(R=tdirlistt_pathtdlisttitemt item_statRRFRts((s"..\modules\wb_server_management.pyRws8     N(RRRRRARR2RR$RRRRRRRRRRRR(((s"..\modules\wb_server_management.pyRnsA!tFileOpsLocalWindowscBseZedZd d dZejd dZejd dZ ejd dZ ejd dZ ejd dZ ejd dZ ejd dZejd d Zejd d Zejd d Zejd d ZRS(cCs|dko|tjkS(NRR(slocalswmi(R R(RRR((s"..\modules\wb_server_management.pyRscCsVtj|||||jjd\}}|rR|jrR|j|_ndS(Ns echo %temp%(RR2RRRPR(RRRRRR((s"..\modules\wb_server_management.pyR2sc Csdt|}g}|jj|||d|dd}xK|D]C}|j}|t|d|krE|t|d}qEqEW|S(Ns dir /q %s*R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRsRKii(RRRDRRQ( RRR(R=R&RFRRt line_data((s"..\modules\wb_server_management.pyRs    cCst|d}g}|jjdt|||d|d}|dkr{|jjdt|||ddnudj|}d}d |krtd }tj|_n3d |krt d }tj |_n t d }||dkS(Ns.wb_write_tests echo "tst" > R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRsisdel cSsdS(N(RA(R((s"..\modules\wb_server_management.pyRss s)The system cannot find the path specifiedsThe directory does not existsAccess is deniedsPermission denied for writings&Unable to verify directory is writable( RRRDRRRARRRRRR"(RRR(R=R9RFRR((s"..\modules\wb_server_management.pyRs,       cCsKdt|}|jjdt|d|d|dd}|dkS(Nsexist sdir R(R=R>cSsdS(N(RA(R((s"..\modules\wb_server_management.pyRsi(RRRD(RR9R(R=R&R((s"..\modules\wb_server_management.pyRs  c Csg}|jjdt|||d|d}d}|dkrt|rdddd d g}|d jj}t|d jd d} d} x6| t|kr| dkr| d} | d} qWd| || f}n|S(Nsdir %sR>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRssCould not determineitBtKBtMBtGBtTBiit,RKiis%.2f %s available(RRDRRQRPRtfloatR( RRR(R=toutRRtmeasuresRttotaltindex((s"..\modules\wb_server_management.pyRs ! c CsAttd|jj|t|f|tjkr!tjddt }|j }y|ttd|jj|f|j ||j |rXt jj|rXdt|t||t|t|f}ttd|jj|fg} |jj|d|d|d | d } | d krd j| } td || fqnBttd|jj||f|jd|d|d|d|ttd|jj|fttd|jjWq=tk r} ttd|jjt| f|r|j nq=Xntj||||||dS(Ns-%s: Saving file "%s" with backup (sudo="%s") sw+btdeletes+%s: Writing file contents to tmp file "%s" scopy /Y %s %s && copy /Y %s %ss1%s: Creating backup and commiting tmp file: "%s" R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRsis s)Error while executing '%s'. Output = '%s'sA%s: Copying over tmp file to final filename using sudo: %s -> %s RRs%s: Delete tmp file "%s" s %s: Done. s%s: Exception caught: %s (R R3RBRRCRR$RRRSRTRRR4RRRRRRDRRRR"RRR( RR9RRR(R=RRRbRFRR((s"..\modules\wb_server_management.pyRs<&     "#  cCs|tjkrtj}tdt|tj|ddd|j|j}d|kr}t }t j |_ |n|St j ||||SdS(Nstype %sR'R>sNo such file or directory(RR$RRRR%RARRRRRRR(RR9R(R=RFR((s"..\modules\wb_server_management.pyR;s ,     c Cs|tjkrpytj||Wqttfk rl}|jtjkrftd||fnqXng}|j j dt |dt |d|d|d|d}|dkrd j |}t d |||jfndS( NsCan't copy %s to %sscopy /Y RHR(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRWsis sError copying file %s to %s %s(RR$RtcopyfileRRRRRRRDRRRRP(RRRR(R=RRFR((s"..\modules\wb_server_management.pyRJs ' c Cs|tjkrjytj|Wqttfk rf}|jtjkr]td|n|qXndg}|j j dt |d|d|d|d}|dkrdj |}t |ndS( NsCould not create directory %ssmkdir R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRksis (RR$RRRRRRRRRDRRR(RRR(R=RRFR((s"..\modules\wb_server_management.pyR^s  c Cs|tjkrjytj|Wqttfk rf}|jtjkr]td|n|qXndg}|j j dt |d|d|d|d}|dkrdj |}t |ndS( NsCould not remove directory %ssrmdir R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRsis (RR$RRRRRRRRRDRRR(RRR(R=RRFR((s"..\modules\wb_server_management.pyRrs  c Cs|tjkrjytj|Wqttfk rf}|jtjkr]td|n|qXnjg}|j j dt |d|d|d|d}|dkrdj |}t |jndS( NsCould not delete file %ssdel R(R=R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRsis (RR$RRRRRRRRRDRRRRP(RRR(R=RRFR((s"..\modules\wb_server_management.pyRs  cCs|tjkrtj||Stj}|jjdt|d|d|d|j}|dkr|j j }d|krt t j |nt|n,g|j jdD]}|j ^qSdS(Nsdir /B R(R=R>isFile not founds (RR$RRRRRDRRRRPRRRRR(RRR(R=RFRR((s"..\modules\wb_server_management.pyRs    N(RRRRRAR2RR$RRRRRRRRRRR(((s"..\modules\wb_server_management.pyRs! 5tFileOpsRemoteUnixcBseZedZd dZejd dZejd dZ ejd dZ ejd dZ ejd dZ ejd dZ ejd dZejd d Zejd d Zejd d Zejd d ZRS(cCs"|dko!|tjtjfkS(NR(R RR(RRR((s"..\modules\wb_server_management.pyRscCs||_||_||_dS(N(RRR(RRRR((s"..\modules\wb_server_management.pyR2s  c Css|jr1ttd|jj|tjkr4ddn|tjkrIdn|df|tjkrtdt ||j j |}|jj |||\}}|dkrt d ntSy|jj|SWqotk r-}|jtjkrtd |n|jtjkr'tSqoXn>d GHttd |jjd dl}|jtdtS(Ns%s: %s sChecking if file "%s" exists sas adminsas the tregulars userstest -e isIncorrect password for sudos,Permission denied attempting to read file %ss/Attempt to read remote file with no ssh sessions4%s: Attempt to read remote file with no ssh session is.Cannot read remote file without an SSH sessionsas the regular(RR R3RBRRR%R$R*RRR'RDRRXRRRRRRRTRRt print_stackR"( RR9R(R=R&RR:RR((s"..\modules\wb_server_management.pyRs0 $"     cCstj}|jjdt|||d|j}t|jj}d}|r|jddjj}d|d|df}n|S( Ns df -Ph %sR>sCould not determines is%s of %s availableii( RRRDRRRRRPR(RRR(R=RRRR((s"..\modules\wb_server_management.pyRs  cCs|jr|jtjkr$d}nd}|t|}|tjkrdt||jj |}n|jj |||\}}|dkrt dn|j SdGHt td|jjddl}|jtdtS( Ns stat -c %U sstat -f "%Su" isIncorrect password for sudos/Attempt to read remote file with no ssh sessions4%s: Attempt to read remote file with no ssh session is.Cannot read remote file without an SSH session(RRR RRRR$R*RR'RDRRPRR3RBRRR&R"RT(RR9R(R=R&RR:R((s"..\modules\wb_server_management.pyRs"       c Cs|tjkrmy|jj|Wqttfk ri}|jtjkr`td|n|qXnag}t dt ||j j |}|jj |||\}}|dkrt|ndS(NsCould not create directory %ss /bin/mkdir i(RR$RRRRRRRR*RRR'RDR( RRR(R=RRFR&RR:((s"..\modules\wb_server_management.pyRs " c Cs|tjkrmy|jj|Wqttfk ri}|jtjkr`td|n|qXnag}t dt ||j j |}|jj |||\}}|dkrt|ndS(NsCould not remove directory %ss /bin/rmdir i(RR$RRRRRRRR*RRR'RDR( RRR(R=RRFR&RR:((s"..\modules\wb_server_management.pyRs " c Cs|tjkrmy|jj|Wqttfk ri}|jtjkr`td|n|qXnag}t dt ||j j |}|jj |||\}}|dkrt|ndS(NsCould not delete file %ss/bin/rm i(RR$RRRRRRRR*RRR'RDR( RRR(R=RRFR&RR:((s"..\modules\wb_server_management.pyR's " c Csc|jr!|tjkrtd||jj|}|jj|||\}}|dkrd|krt}tj |_|qt d|n|j dr|j dd\}}n|Sy|jj |SWq_ttfk r} | jtjkrtd|qq_Xn>d GHttd |jjd dl} | jt d dS( Nscat %sisNo such file or directorys-Error executing "%s" via SSH in remote serverRMs is,Permission denied attempting to read file %ss/Attempt to read remote file with no ssh sessions4%s: Attempt to read remote file with no ssh session is.Cannot read remote file without an SSH session(RRR$R*RR'RDRRRR"RRR7RRRRR3RBRRR&RA( RR9R(R=R&RR:Rt_RR((s"..\modules\wb_server_management.pyR7s0         cCs|j||d||dS(N(RRA(RR9RR(R=((s"..\modules\wb_server_management.pyRXscCst|\}}|tjkrby|j|jdWqbtk r^td|qbXn|jdk r|j j d\}} t |t kr|j d}nt |tkr|jd}nd}ttd|jj|f|s tdn|d} ttd|jj| fttd |jj|f|jj| ||rttd |jj|fd t|d t||} |j j| ||nd t| d t|} d t| } ttd|jj| f|j j| tj||tjkrc|j jd|t|fdtjd|nttd|jj| f|j j| n tddS(Ns sCannot write to directory %ssecho ~tutf8s%s: Got home dir: "%s" s,Unable to get path for remote home directorys /.wba.temps5%s: Remotely writing contents to temporary file "%s" s%s: %s s%s: Backing up %s s/bin/cp RHs/bin/rm s,%s: Copying file to final destination: "%s" s chown %s %sR(R=s%s: Deleting tmp file: "%s" s0No SSH session active, cannot save file remotely(RRR$RRPR"RRRARRttypetunicodetencodeRCR R3RBRR R R;RRDR%(RRRRR(R=tdirnameR9thomedirtstatust tmpfilenamet backup_cmdt copy_to_destt delete_tmp((s"..\modules\wb_server_management.pyR\sF  "  cCst|d}g}|jjdt|||d|d}|dkr{|jjdt|||ddnydj|}d}d |krttjd }n=d |krt d }tj |_nt d |j }||dkS(Ns.wb_write_teststouch R>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRsis/bin/rm cSsdS(N(RA(R((s"..\modules\wb_server_management.pyRss sNo such file or directorysThe directory does not existsPermission deniedsPermission denied for writings*Unable to verify directory is writable: %s( RRRDRRRARRRRRR"RP(RRR(R=R9RFRR((s"..\modules\wb_server_management.pyRs*     c Csg}|jdk r|tjkr|jjd|\}}|dkr~|jd}xA|D]6}|ddkr|jd|qb|j|qbWq~qtj}|j jdt |d|d|d|j } |j }| dkrPd |krt tjd |q~d |kr;td |q~t|jqg|jjdD]} | j^qf}n td |S(Ns/bin/ls -1 -p %sis iRR(R=R>sNo such file or directorysDirectory %s does not existsPermission denieds%Permission denied for reading from %ss7No SSH session active, cannot get remote directory list(RRARR$RDRR RRRRRRRRRRR"RP( RRR(R=RRFR.traw_listRRR((s"..\modules\wb_server_management.pyRs2        1 N(RRRRRAR2RR$RRRRRRRRRRR(((s"..\modules\wb_server_management.pyR$s !9 tFileOpsRemoteWindowscBseZedZdZejd dZejd dZ ejd dZ ejd dZ ejd dZ ejd dZ ejd dZejd d Zejd d ZRS( cCs|dko|tjkS(NR(R R(RRR((s"..\modules\wb_server_management.pyRscCs,tj||||||_||_dS(N(R$R2RR(RRRR((s"..\modules\wb_server_management.pyR2s cCs{|jr9y|jj|SWqwtk r5}qwXn>dGHttd|jjddl}|jt dt S(Ns/Attempt to read remote file with no ssh sessions4%s: Attempt to read remote file with no ssh session is.Cannot read remote file without an SSH session( RRRRR3RBRRR&R"RT(RR9R(R=RR((s"..\modules\wb_server_management.pyRs     c Csg}|jjdt|||d|d}d}|dkrt|rdddd d g}|djjd d jj}t|d jdd} d} x6| t|kr| dkr| d} | d} qWd| || f}n|S(Nsdir %sR>cSs |j|S(N(R(RR((s"..\modules\wb_server_management.pyRssCould not determineiRRRRRs iiRRKiis%.2f %s available(RRDRRQRPRRR( RRR(R=RRRRRR R!((s"..\modules\wb_server_management.pyRs )! c Cs|tjkrgy|jj|Wqtk rc}|jtjkrZtd|n|qXnag}tdt ||j j |}|jj |||\}}|dkrt |ndS(NsCould not create directory %ssmkdir i(RR$RRRRRRR*RRR'RDR( RRR(R=RRFR&RR:((s"..\modules\wb_server_management.pyRs " c Cs|tjkrgy|jj|Wqtk rc}|jtjkrZtd|n|qXnag}tdt ||j j |}|jj |||\}}|dkrt |ndS(NsCould not remove directory %ssrmdir i(RR$RRRRRRR*RRR'RDR( RRR(R=RRFR&RR:((s"..\modules\wb_server_management.pyR!s " c Cs|tjkrgy|jj|Wqtk rc}|jtjkrZtd|n|qXnag}tdt ||j j |}|jj |||\}}|dkrt |ndS(NsCould not delete file %ssdel i(RR$RRRRRRR*RRR'RDR( RRR(R=RRFR&RR:((s"..\modules\wb_server_management.pyR0s " cCst|\}}|tjkriy|j|jdWqitk re}|GHtd|qiXn|jdk r|j j d\} } t | t kr| j d} nt | tkr5| jd} | ddkr| d} n#ttd|jj| fd} ttd |jj| fnd} | sJ|} n| d } ttd |jj| fttd |jj|f|jj| ||rRttd |jj|fdt|dt||} |j j | \} }|dkrR| GdG| GHttd|jj| d| ftd| qRndt| dt|}dt| }ttd|jj|f|j j |\} }|dkr |GdG| GHttd|jj| | |ftd| | |fnttd|jj|f|j j |\} }|dkrd| | fGHttd|jj| | fqn tddS(Ns sCannot write to directory %ss echo %temp%R(it:isl%s: Temp directory path "%s" is not in expected form. The expected form is something like "C:\Windows\Temp" s%s: Got temp dir: "%s" s\workbench-temp-file.inis5%s: Remotely writing contents to temporary file "%s" s%s: %s s%s: Backing up "%s" scopy /y RHis->s%s: Error backing up file: %s sError backing up file: %ssdel s,%s: Copying file to final destination: "%s" sD%s: Error copying temporary file over destination file: %s %s to %s s?Error copying temporary file over destination file: %s %s to %ss%s: Deleting tmp file: "%s" s&Could not delete temporary file %s: %ss-%s: Could not delete temporary file "%s": %s s0No SSH session active, cannot save file remotely(RRR$RRPR"RRRARRR)R*R+RCR R3RBRR R R;RRRR(RRRRR(R=R,R9RttmpdirR.R/R0tmsgRR1R2((s"..\modules\wb_server_management.pyR?s^    "  %  # &cCs|jr[y|jj|SWqtk rW}|jtjkrXtd|qXqXn'dGHddl}|jtddS(Ns,Permission denied attempting to read file %ss/Attempt to read remote file with no ssh sessionis.Cannot read remote file without an SSH session( RR7RRRRRR&R"(RR9R(R=RR((s"..\modules\wb_server_management.pyR}s   cCse|jjdt|d\}}|dk}|ra|jjdt|d\}}n|S(Ns echo 1 > s/wba_tmp_file.bakisdel (RRR(RRR(R=R7RR:((s"..\modules\wb_server_management.pyRs & )c Cs`|jj}|j|\}}g}x|D]}|j|dq1Wt|t|S(NR(RtgetftptlsRttupletlist( RRR(R=tsftptdirstfilesR:td((s"..\modules\wb_server_management.pyRs  N(RRRRR2RR$RARRRRRRRRR(((s"..\modules\wb_server_management.pyR4s >tServerManagementHelpercBseZdZedZejddZejddZ ejddZ ejddZ ejddZ ejddZ ejddZd Zejdd Zejdd Zejdd Zejdd ZejdddZRS(cCsxg|_||_d}|j|j|jf}x'tD]}|j|r7|}Pq7q7W|r|j}|sxt }n|jt j krd|kr|j dd}n|d|d||_ |j jntdt|d}x0tD](}|j|j|jr|}PqqW|rL||j d|d|j|_n(tdt|jt|jfdS( Ns -k R ssudo -k R'Rs*Unsupported administration target type: %sRs-Unsupported administration target type: %s:%s(t tmp_filesR0RAthost_osRtconnect_methodt_process_ops_classesRR'R#R RRR~RR"RCt_file_ops_classesRv(RR0Rtklasst match_tupleRR'((s"..\modules\wb_server_management.pyR2s2      $cCs|jr|jjSdS(NRK(R~R(R((s"..\modules\wb_server_management.pyRs  cCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs tdS(N(R(R((s"..\modules\wb_server_management.pytmake_local_tmpfilescCs|jj|d|d|S(NR(R=(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCs|jj||d|d|S(NR(R=(RvR(RRtcontentsR(R=((s"..\modules\wb_server_management.pytset_file_contentscCs|jj|||S(N(RvR(RRR(R=((s"..\modules\wb_server_management.pyRscCsFt|tkr$|jd}n|jj|||d|d|S(NR(R(R=(R)R*R+RvR(RRRIRR(R=((s"..\modules\wb_server_management.pytset_file_content_and_backupscCs|jj||||S(N(R~RD(RR&R(R=R>((s"..\modules\wb_server_management.pytexecute_command sN(RRR2tpropertyRRR$RARRRRRRRRHRRJRRKRL(((s"..\modules\wb_server_management.pyR@s ) (ARtplatformRRR,R RRRRR#t wb_commonRRRt wb_admin_sshRRRRtgrtRRR R R R Rtbasenamet__file__R3tobjectR RRR%R*R+R$RARlRtsystemRRRDRRRRRtWIN_REG_QUERY_PROGRAMFILEStWIN_REG_QUERY_PROGRAMFILES_x86RRRRRRRERRRR$R4R@(((s"..\modules\wb_server_management.pytst         .  /a4    4 V 2 ) +  "