-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchissy.py
executable file
·107 lines (72 loc) · 2.29 KB
/
chissy.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
#!/bin/env python3
from chissy.core.controller import Controller
import chissy
import os
import sys
import json
name = sys.argv[0]
helpers = """
Chissy {version} -- Fake SSH Server
Developed by {author}
Usage: {name} start|get-log|remove-log|version|help|install [option]
Arguments:
start
starting a fake ssh server.
get-log [options]
show the logs create. You can specify the get-log options.
remove-log [options]
remove the logs. You can specify the get-log options.
version
get the version of {name}.
help
show this helps.
Options:
get-log:
-a --address ADDRESS
specify the IP address
-f --from-date DATE
get only the logs before the date specified. DATE format yyyy-mm-dd.
-t --to-date DATE
get only the logs after the date specified. Use the same DATE format to -f.
remove-log:
-f --from-date DATE
delete the logs before the date specified. Use the same DATE format to get-log options.
-t --to-date DATE
delete the logs after the date specified. Use the same DATE format to get-log options.
Examples:
{name} start
{name} get-log -a 127.0.0.1
"""
helpers = helpers.format(name=sys.argv[0], version=chissy.__version__, author=chissy.__author__)
def show_help():
print(helpers)
sys.exit(0)
def show_version():
print('Chessy {version} - Fake SSH server - Developed by {author}'.
format(version=chissy.__version__, author=chissy.__author__))
sys.exit(0)
def install():
os.system('./install.py')
return
def exec_controller():
with open('conf/server.json') as file:
conf_server = json.load(file)
with open('conf/log.json') as file:
conf_log = json.load(file)
ctrl = Controller(command, conf_server, conf_log)
ctrl.execute()
if __name__ == '__main__':
if len(sys.argv) < 2:
print('[!!] Chissy need a argument')
print(helpers)
sys.exit(-1)
command = sys.argv[1]
# switcher to show help or version and install chissy
# to default execute controller
switcher = {
'help': show_help,
'version': show_version,
'install': install
}
exc = switcher.get(command, exec_controller)
exc()