-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
924 lines (777 loc) · 28.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# coded by lagcleaner
# email: lagcleaner@gmail.com
from io import BytesIO
import sys
from typing import Callable, Union
from datetime import datetime, date as Date
# pylint: disable=unused-import
from tfprotocol_client.misc.constants import (
KEY_LEN_INTERVAL,
RESPONSE_LOGGER,
SECFS_ALL_PERMISSIONS,
)
# pylint: disable=unused-import
from tfprotocol_client.models.keepalive_options import (
KeepAliveMechanismType,
KeepAliveOptions,
)
from tfprotocol_client.tfprotocol import TfProtocol
from tfprotocol_client.models.status_info import StatusInfo
from tfprotocol_client.models.file_stat import FileStat, FileStatTypeEnum
from tfprotocol_client.connection.protocol_client import ProtocolClient
from tfprotocol_client.models.putget_commands import PutGetCommandEnum
from tfprotocol_client.models.transfer_state import TransferStatus
from tfprotocol_client.connection.codes_sender_recvr import CodesSenderRecvr
def get_publickey() -> str:
"""extract public key from the keyfile"""
with open('public.key', mode='r', encoding='utf8') as f:
public_key = f.read()
return public_key
class MyHandler:
"""My handler
Args:
SuperProtoHandler ([type]): [description]
"""
def mkdir_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def ftod_callback(self, timestamp: int, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
'timestamp:(',
timestamp,
')',
)
def datef_callback(self, date: datetime, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
'date:(',
date,
')',
)
def del_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def rmdir_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def copy_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def touch_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def fupd_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def date_callback(self, timestamp: int, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
'timestamp:(',
timestamp,
')',
status.status.name.ljust(8, ' '),
)
def dtof_callback(self, _: Date, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def fstat_callback(self, _: FileStatTypeEnum, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def cpdir_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def xcopy_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def xdel_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def xrmdir_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def xcpdir_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def lock_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def sendfile_callback(
self,
is_overriten: bool,
path: str,
status: StatusInfo,
payload: Union[bytes, bytearray],
):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def rcvfile_callback(
self, delete_after: bool, path: str, status: StatusInfo, sink: BytesIO = None
):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
len(status.payload),
sep=' ',
)
# if len(status.payload) > 21588:
# print('-------')
# print(status.payload)
# print('-------')
if sink is None:
print(
"CLIENT-HANDLER: ",
sys._getframe()
.f_code.co_name.replace('_callback', '', 1)
.ljust(10, ' '),
status.status.name.ljust(8, ' '),
' ',
'NO-SINK-PASSED',
)
return
if sink.writable() and status.payload:
sink.write(status.payload)
def ls_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def lsr_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.message,
)
def renam_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def keepalive_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def login_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def chmod_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def chown_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def getcan_callback(
self,
status: StatusInfo,
_: ProtocolClient,
transfer_status: TransferStatus,
):
if transfer_status is not None:
if transfer_status.handling_canpt:
# transfer_status.dummy = PutGetCommandEnum.HPFCANCEL.value
pass
elif transfer_status.client_command in (
PutGetCommandEnum.HPFCANCEL.value,
PutGetCommandEnum.HPFEND.value,
):
print(
"CLIENT-HANDLER: ",
sys._getframe()
.f_code.co_name.replace('_callback', '', 1)
.ljust(10, ' '),
'-'.ljust(8, '-'),
'finished',
)
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' ')
if status is not None
else '-'.ljust(8, '-'),
transfer_status,
)
def putcan_callback(
self,
status: StatusInfo,
_: ProtocolClient,
transfer_status: TransferStatus,
):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' ')
if status is not None
else '-'.ljust(8, '-'),
transfer_status,
)
def sha256_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def prockey_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def freesp_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def udate_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def ndate_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def getstatus_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.code,
)
def get_callback(self, codes: CodesSenderRecvr):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
codes.last_header,
)
# sleep(0.3)
# codes.send_get(PutGetCommandEnum.HPFCANCEL.value)
def put_callback(self, codes: CodesSenderRecvr):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
'-'.ljust(8, '-'),
codes.last_header,
)
def putstatus_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def nigma_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
'NewSessionKey:(',
status.payload,
')',
)
def rmsecuredirectory_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def injail_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def tlb_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def sdown_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def sup_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def fsize_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.code,
)
def fsizels_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.code,
)
def lsv2_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def lsrv2_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def ftype_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def ftypels_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.code,
status.payload,
)
def fstatls_callback(self, file_stat: FileStat):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
'-'.ljust(8, '-'),
file_stat,
)
def addntfy_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
'-'.ljust(8, '-'),
)
def notification_callback(
self,
status: StatusInfo,
send_ok: Callable,
send_del: Callable,
):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
'-'.ljust(8, '-'),
)
# The handler always have to end with send_ok() or send_del() and should be
# called once per notification.
send_del()
def intread_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.code,
)
def intwrite_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.code,
)
def netlock_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def netunlock_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def netlocktry_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def netmutacqtry_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def netmutrel_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def setfsid_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def setfsperm_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def remfsperm_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def getfsperm_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def issecfs_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def locksystem_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
status.payload,
)
def echo_callback(self, value: str):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
'-'.ljust(8, ' '),
'ServerSays:("',
value,
'")',
)
print(f'Server: {value}')
def status_server(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def response_server_callback(self, status: StatusInfo):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1).ljust(10, ' '),
status.status.name.ljust(8, ' '),
)
def instance_tfprotocol(self, instance: any):
print(
"CLIENT-HANDLER: ",
sys._getframe().f_code.co_name.replace('_callback', '', 1),
)
def test_updown_tinyfiles(proto: TfProtocol):
# DONE
with open('test2.java', 'rb') as f:
proto.sndfile_command(True, 'test2.java', f)
with open('test2-rec.java', 'wb') as f:
proto.rcvfile_command(False, 'test2.java', f)
proto.fstat_command('test2.java')
def test_supsdown_files(proto: TfProtocol):
# DONE
with open('test2.java', 'rb') as f:
proto.sup_command('test2.2.java', f, 5)
with open('test2.2-rec.java', 'wb') as f:
proto.sdown_command('test2.2.java', f, 10)
proto.fstat_command('test2.2.java')
def test_putcangetcan_files(proto: TfProtocol):
# DONE
with open('test2.java', 'rb') as f:
proto.putcan_command(f, 'test2.3.java', 0, 1024, 1)
with open('test2.3-rec.java', 'wb') as f:
proto.getcan_command(f, 'test2.3.java', 0, 1024, 2)
proto.fstat_command('test2.3.java')
def test_putget_files(proto: TfProtocol):
# DONE
with open('test2.java', 'rb') as f:
proto.put_command(f, 'test2.4.java', 0, 48)
with open('test2.4-rec.java', 'wb') as f:
proto.get_command(f, 'test2.4.java', 0, 48)
proto.fstat_command('test2.4.java')
def test_folders_commands(proto: TfProtocol):
# DONE
proto.rmdir_command('py_test')
proto.mkdir_command('py_test')
# proto.mkdir_command('py_test/pattern')
# proto.mkdir_command('py_test/214pattern')
proto.mkdir_command('py_test/test1')
proto.mkdir_command('py_test/test2')
proto.mkdir_command('py_test/test2/test21')
# proto.mkdir_command('py_test/test2/test22')
proto.mkdir_command('py_test/test3')
proto.touch_command('py_test/test2/test.java')
proto.lsr_command('/py_test')
proto.rmdir_command('/py_test/test1')
proto.renam_command('/py_test/test3', '/py_test/test3new')
proto.lsr_command('/py_test')
proto.rmdir_command('/py_test/test3new')
proto.cpdir_command('/py_test/test2', '/py_test/test2cpdir')
proto.lsr_command('/py_test')
proto.mkdir_command('py_test/pattern')
proto.xcpdir_command('testxcpdir', '/py_test/test2', 'pattern')
proto.lsr_command('/py_test')
proto.mkdir_command('/py_test/test2copy')
proto.copy_command('py_test/test2/test.java', 'py_test/test2copy/test.java')
proto.lsr_command('/py_test')
proto.rmdir_command('/py_test/test2copy')
proto.xcopy_command(
'test_xcopy.java',
'/py_test/test2/test.java',
'/test21',
)
proto.lsr_command('/py_test')
proto.rmdir_command('/py_test/pattern')
proto.xdel_command('/py_test', 'test.java')
proto.lsr_command('/py_test')
proto.xrmdir_command('/py_test', 'test2')
proto.lsr_command('/py_test')
proto.touch_command('/py_test/file_touch.txt')
proto.lsr_command('/py_test')
proto.lsrv2_command('/py_test', '/py_test/testrls.txt')
proto.lsv2_command('/py_test', '/py_test/testls.txt')
proto.fsize_command('/py_test/testls.txt')
proto.fsizels_command('/py_test/testls.txt')
proto.fstatls_command(
'/py_test/testls.txt', response_handler=MyHandler().fstatls_callback
)
proto.ftypels_command(
'/py_test/testls.txt', response_handler=MyHandler().ftypels_callback
)
proto.rmdir_command('py_test')
def test_files_modification_commands(proto: TfProtocol):
proto.rmdir_command('/py_test')
proto.mkdir_command('/py_test')
proto.touch_command('/py_test/file_touch.txt')
proto.fstat_command('/py_test/file_touch.txt')
proto.chmod_command('/py_test/file_touch.txt', '600')
proto.fstat_command('/py_test/file_touch.txt')
# proto.chown_command('/py_test/file_touch.txt', '', '')
# proto.fstat_command('/py_test/file_touch.txt')
proto.fupd_command('/py_test/file_touch.txt')
proto.fstat_command('/py_test/file_touch.txt')
def test_notify_system_commands(proto: TfProtocol):
proto.addntfy_command('test', '')
proto.startnfy_command(3)
def test_integrity_rw_commands(proto: TfProtocol):
checksum: str = None
def _handler_callback(status: StatusInfo):
nonlocal checksum
checksum = status.message
print("CLIENT-HANDLER: ", status)
with open('test.java', 'rb') as f:
proto.sup_command('test2.java', f, 5)
with open('test2-rec.java', 'wb') as f:
proto.intread_command('test2.java', f, response_handler=_handler_callback)
if checksum is not None:
with open('test2.java', 'rb') as f:
proto.intwrite_command(
'test2.java',
f,
checksum,
response_handler=MyHandler().intwrite_callback,
)
def test_netsecurity_commands(proto: TfProtocol):
myhandler = MyHandler()
lock_id: str = None
def _handler_callback(status: StatusInfo):
nonlocal lock_id
lock_id = status.message
print("CLIENT-HANDLER: ", status)
proto.touch_command('testlaglock', response_handler=myhandler.touch_callback)
proto.netlock_command(5, 'testlaglock', response_handler=_handler_callback)
proto.netlocktry_command(
5,
'testlaglock',
response_handler=myhandler.netlocktry_callback,
)
proto.netunlock_command(lock_id)
proto.touch_command('test.mut')
proto.netmutacqtry_command(
'test.mut',
'testtoken',
response_handler=myhandler.netmutacqtry_callback,
)
proto.netmutrel_command(
'test.mut',
'testtoken',
response_handler=myhandler.netmutrel_callback,
)
proto.setfsid_command('secid', response_handler=myhandler.setfsid_callback)
proto.mkdir_command('testlag')
proto.setfsperm_command(
'secid',
SECFS_ALL_PERMISSIONS,
'testlag',
response_handler=myhandler.setfsperm_callback,
)
proto.issecfs_command(
'testlag',
response_handler=myhandler.issecfs_callback,
)
proto.getfsperm_command(
'secid',
'testlag',
response_handler=myhandler.getfsperm_callback,
)
proto.remfsperm_command(
'secid',
'testlag',
response_handler=myhandler.remfsperm_callback,
)
proto.mkdir_command(
'/py_test_sys',
response_handler=myhandler.mkdir_callback,
)
proto.locksys_command(
'/py_test_sys',
response_handler=myhandler.locksystem_callback,
)
proto.touch_command(
'/py_test_sys/file_touch.txt',
response_handler=myhandler.touch_callback,
)
def test_regular_commands(proto: TfProtocol):
proto.echo_command('Hola mundo')
proto.echo_command(
'Hola despues de cambiar el cerrojo', response_handler=RESPONSE_LOGGER
)
proto.date_command(response_handler=MyHandler().date_callback)
proto.nigma_command(16, response_handler=MyHandler().nigma_callback)
proto.datef_command()
proto.dtof_command(datetime.timestamp(datetime.now()))
proto.ftod_command('1999-12-10 12:12:0')
proto.udate_command()
proto.freesp_command()
proto.prockey_command()
proto.sha256_command('test2.java')
proto.end_command()
def main():
# ADDRESS = '192.168.0.128'
ADDRESS = 'tfproto.expresscuba.com'
PORT = 10345
proto = TfProtocol(
'0.0',
get_publickey(),
'testhash',
ADDRESS,
PORT,
verbosity_mode=True,
)
proto.connect(
# keepalive_options=KeepAliveOptions(KeepAliveMechanismType.TCP_NATIVE, 1, 5, 3)
)
# proto.prockey_command()
# sleep(20)
# proto.echo_command('sacamos cuela')
# test_updown_tinyfiles(proto)
# test_supsdown_files(proto)
# test_putget_files(proto)
# test_putcangetcan_files(proto)
# test_folders_commands(proto)
# test_files_modification_commands(proto)
test_regular_commands(proto)
# test_notify_system_commands(proto)
# test_integrity_rw_commands(proto)
# test_netsecurity_commands(proto)
# proto.rmdir_command('prueba.sd')
# proto.tlb_command()
if __name__ == '__main__':
main()