Xׯd#ddlZddlZddlZddlZddlZddlmZddlmZm Z ddl Z gZ ej D]8Z e ddkrde zdzZ e e 9e dZe dZe d Ze d dZGd d Zed eeeeZ erBeeeZeeejejdSdS#e$rCZejr ede ene!eYdZ[dSYdZ[dSdZ[wwxYw)N) SocketClient) FileUtilsOSUtils "cteZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdS)CommandProcessorc|d|_d|dd|_||_d|_d|_i|_|j|jd<|j|jd<|j |jd<|j |jd<|j |jd <|j |jd <|j |jd <|j|jd <|j|jd <|j|jd<|j|jd<|j|jd<|j|jd<|j|jd<|j|jvrt+d|jzdS)Nrrr LISTDIRGETFILE GETFILE_LINESGET_FREE_SPACECHECK_DIR_WRITABLECHECK_PATH_EXISTSCREATE_DIRECTORYCREATE_DIRECTORY_RECURSIVEREMOVE_DIRECTORYREMOVE_DIRECTORY_RECURSIVE DELETE_FILE COPY_FILEGET_FILE_OWNEREXECzCommand %s is not supported)_commandjoin_args_client _result_code_result_message _commands_process_listdir_process_getfile_process_getfile_lines_process_get_free_space_process_check_dir_writable_process_check_path_exists_process_create_directory#_process_create_directory_recursive_process_remove_directory#_process_remove_directory_recursive_process_delete_file_process_copy_file_process_get_file_owner _process_exec RuntimeError)selfcommandclients ..\wbadminhelper.py__init__zCommandProcessor.__init__2sM  XXgabbk**  !$($9y!$($9y!*.*E'+/+G'(/3/O+,.2.M*+-1-K)*7;7_34-1-K)*7;7_34(,(A}%&*&={#+/+G'(!%!3v = . . size: Indicates if the returned list should containg the size or not. 0 indicates no, 1 indicates yes. path: The path to the file or folder that will be listed. rr 1N)r!splitrlist_dir_send_to_listener)r5 include_sizepaths r8r&z!CommandProcessor._process_listdirYsH"Z--c155 d$+ 4t/EFFFFFr:c|jdd\}}}dx}}t|}t|}|} t|d}|r||d}|rQ|r ||kr|n|}||} | r*|j| |r ||z }|dkrd}nd}|Q|d S#t$r&} d|_ t| |_ Yd } ~ d Sd } ~ wwxYw) aN Load data from a file and sends it back to the command listener in 64K chunks. Syntax: GETFILE offset: In bytes, indicates the position of the file where the read operation will start. 0 indicates the beggining of the file. size: In bytes, indicates the amount of bytes to be read from the file. 0 indicates the whole file should be read. path: The path to the file that will be read. rr irTrFr N) r!r@intopenseekreadr"sendcloseIOErrorr#reprr$) r5offsetsizerD read_size chunk_size remainingfcontinue_readingdataes r8r'z!CommandProcessor._process_getfileis_"Z--c155d!&& JV4yy % +T3A v $ " -T.89.D.D )Ivvi(( -L%%d+++5$- $9 $>>/4,',$-# -0 GGIIIII + + + !D #'77D  +sBC D!DDc|jdd\}}t|}tj|||jdS)Nrr )r!r@rGrget_file_linesrB)r5skiprDs r8r(z'CommandProcessor._process_getfile_linessFZ%%c1-- d4yy tT-CDDDDDr:ctj|j}|jt |dSN)rget_free_spacer!r"rKstr)r5 free_spaces r8r)z(CommandProcessor._process_get_free_spaces6-dj99  #j//*****r:c|jttj|jdSr\)r"rKr^rcheck_dir_writabler!r<s r8r*z,CommandProcessor._process_check_dir_writables3 #i:4:FFGGHHHHHr:c|jttj|jdSr\)r"rKr^rcheck_path_existsr!r<s r8r+z+CommandProcessor._process_check_path_existss3 #i9$*EEFFGGGGGr:c8tj|jdSr\)rcreate_directoryr!r<s r8r,z*CommandProcessor._process_create_directory"4:.....r:c8tj|jdSr\)rcreate_directory_recursiver!r<s r8r-z4CommandProcessor._process_create_directory_recursive,TZ88888r:c8tj|jdSr\)rremove_directoryr!r<s r8r.z*CommandProcessor._process_remove_directoryrfr:c8tj|jdSr\)rremove_directory_recursiver!r<s r8r/z4CommandProcessor._process_remove_directory_recursiverir:c8tj|jdSr\)r delete_filer!r<s r8r0z%CommandProcessor._process_delete_filesdj)))))r:c||jd}t|dkrtd|d}|d}d}t|dkr|d}|||t j|||dS)N>r z%Invalid call to the COPY_FILE commandrr r)r!r@lenr4stripr copy_file)r5filessrctgt tgt_backups r8r1z#CommandProcessor._process_copy_files   %% u::>>FGG GAhAh u::>>qJ  Cj11111r:c|jttj|jdSr\)r"rKr^rget_file_ownerr!r<s r8r2z(CommandProcessor._process_get_file_owners3 #i6tzBBCCDDDDDr:c:|j|dSr\)r"rK)r5rVs r8rBz"CommandProcessor._send_to_listeners $r:cDtj|j|jdS)z Executes any OS valid command and sends the output to the command listener Syntax: EXEC command: A valid OS command. N)r exec_commandr!rBr<s r8r3zCommandProcessor._process_execs" TZ)?@@@@@r:N)__name__ __module__ __qualname__r9r=r&r'r(r)r*r+r,r-r.r/r0r1r2rBr3r:r8rr1s+NNN4 ( ( (GGG 9+9+9+vEEE +++IIIHHH///999///999***222"EEE   AAAAAr:rz 127.0.0.1)"ossystimestatshlexworkbench.tcp_utilsrworkbench.os_utilsrr subprocess parsedArgsargvargfindappendport handshakedone_keyr6rrGr7start processorr=rLr#r$ ExceptionrW _connectedrNprintrr:r8rs$ ,,,,,,11111111 8C xx}}rCi#oc!} qM a= QRR.rArArArArArArArAl k33t99i B B  ||~~H$$Wf55  Y+Y-FGGGGG HH  QQ     a !     s0ADE 2E  E