forked from infobyte/faraday
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
130 lines (69 loc) · 5.53 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
#!/usr/bin/env python
'''
Faraday Penetration Test IDE - Community Version
Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/)
See the file 'doc/LICENSE' for the license information
'''
"""
Main module for application
"""
import sys
import os
if (sys.platform == "darwin"):
print "[+] Forcing path for %s" % sys.platform
sys.path.append("/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/")
import time
import optparse
from config.configuration import getInstanceConfiguration
from model.application import MainApplication
try:
from utils.profilehooks import profile
except ImportError:
def profile(fn, *args, **kwargs):
return fn
sys.path.insert(0, os.path.dirname(__file__))
def checkDependencies():
"""
before starting checks that all is needed is installed
"""
if not os.path.exists("/bin/bash"):
print "/bin/bash not present in the system!"
return False
return True
def setupOptions(parser):
parser.add_option('-n', '--hostname', action="store", dest="host", default=False, help="Sets the hostname where api XMLRPCServe will listen. Default = localhost")
parser.add_option('-p', '--port', action="store", dest="port", default=9876, help="Sets the port where api XMLRPCServer will listen. Default = 9876")
parser.add_option('-d', '--debug', action="store_true", dest="debug", default=False, help="Enables debug mode. Default = disabled")
parser.add_option('--profile', action="store_true", dest="profile", default=False, help="Enables application profiling. When this option is used --profile-output and --profile-depth can also be used. Default = disabled")
parser.add_option('--profile-output', action="store", dest="profile_output", default=None, help="Sets the profile output filename. If no value is provided, standard output will be used")
parser.add_option('--profile-depth', action="store", dest="profile_depth", default=500, help="Sets the profile number of entries (depth). Default = 500")
parser.add_option('--disable-excepthook', action="store_true", dest="disableexcepthook", default=False, help="Disable the application Exception hook that allows to send error reports to developers.")
parser.add_option('--disable-login', action="store_true", dest="disablelogin", default=False, help="Disable the auth splash screen.")
def main(args):
parser = optparse.OptionParser()
setupOptions(parser)
options, args = parser.parse_args(args[1:])
if checkDependencies():
CONF = getInstanceConfiguration()
CONF.setDebugStatus(False)
if options.debug:
CONF.setDebugStatus(True)
if options.host and options.port:
CONF.setApiConInfo(options.host, int(options.port))
print "[+] setting api_conn_info = ", CONF.getApiConInfo()
main_app = MainApplication()
if options.disablelogin:
CONF.setAuth(False)
if not options.disableexcepthook:
main_app.enableExceptHook()
if options.profile:
print "%s will be started with a profiler attached. Performance may be affected." % CONF.getAppname()
start = profile(main_app.start, filename=options.profile_output, entries=int(options.profile_depth))
else:
start = main_app.start
exit_status = start()
os._exit(exit_status)
else:
print "%s cannot start!\nDependecies are not met." % CONF.getAppname()
if __name__ == '__main__':
main(sys.argv)