-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmodule_shared.py
103 lines (93 loc) · 4.75 KB
/
module_shared.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
import sys
import os
import ast
import ConfigParser
import util_locator as ul
APP_DIR = ul.module_path()
CONFIGFILE = os.path.join(APP_DIR, 'inventory.cfg')
def get_settings():
cc = ConfigParser.RawConfigParser()
if os.path.isfile(CONFIGFILE):
cc.readfp(open(CONFIGFILE,"r"))
else:
print '\n[!] Cannot find config file. Exiting...'
sys.exit()
# modules
mod_linux = cc.getboolean('modules', 'linux')
mod_solaris = cc.getboolean('modules', 'solaris')
mod_mac = cc.getboolean('modules', 'mac')
mod_bsd = cc.getboolean('modules', 'bsd')
mod_aix = cc.getboolean('modules', 'aix')
# settings ------------------------------------------------------------------------
base_url = cc.get('settings', 'base_url')
username = cc.get('settings', 'username')
secret = cc.get('settings', 'secret')
#targets ------------------------------------------------------------------------
targets = cc.get('targets', 'targets')
# credentials --------------------------------------------------------------------
use_key_file = cc.getboolean('credentials', 'use_key_file')
key_file = cc.get('credentials', 'key_file')
credentials = cc.get('credentials', 'credentials')
#ssh settings ------------------------------------------------------------------
ssh_port = cc.get('ssh_settings', 'ssh_port')
timeout = cc.get('ssh_settings', 'timeout')
#options ------------------------------------------------------------------------
get_serial_info = cc.getboolean('options', 'get_serial_info')
get_hardware_info = cc.getboolean('options', 'get_hardware_info')
get_os_details = cc.getboolean('options', 'get_os_details')
get_cpu_info = cc.getboolean('options', 'get_cpu_info')
get_memory_info = cc.getboolean('options', 'get_memory_info')
get_uptime = cc.getboolean('options', 'get_uptime')
get_net_listen = cc.getboolean('options', 'get_net_listen')
get_net_connections = cc.getboolean('options', 'get_net_connections')
ignore_domain = cc.getboolean('options', 'ignore_domain')
upload_ipv6 = cc.getboolean('options', 'upload_ipv6')
debug = cc.getboolean('options', 'debug')
threads = cc.get('options', 'threads')
dict_output = cc.getboolean('options', 'dict_output')
return mod_linux, mod_solaris, mod_mac, mod_bsd, mod_aix, base_url, username, secret, targets, \
use_key_file, key_file, credentials, ssh_port, timeout, get_serial_info, \
get_hardware_info, get_os_details, get_cpu_info, get_memory_info, get_uptime, \
ignore_domain, upload_ipv6, debug, threads, dict_output
caller = os.path.basename(sys._getframe().f_back.f_code.co_filename)
print caller
if caller == 'main.py':
MOD_LINUX, MOD_SOLARIS, MOD_MAC, MOD_BSD, MOD_AIX, BASE_URL, \
USERNAME, SECRET, TARGETS, USE_KEY_FILE, KEY_FILE, \
CREDENTIALS, SSH_PORT, TIMEOUT, GET_SERIAL_INFO, \
GET_HARDWARE_INFO, GET_OS_DETAILS, GET_CPU_INFO, \
GET_MEMORY_INFO, GET_UPTIME, IGNORE_DOMAIN, UPLOAD_IPV6, DEBUG, THREADS, \
DICT_OUTPUT = get_settings()
SSH_PORT = int(SSH_PORT)
TIMEOUT = int(TIMEOUT)
else:
if len(sys.argv) == 5:
MOD_LINUX, MOD_SOLARIS, MOD_MAC, MOD_BSD, MOD_AIX, BASE_URL, \
USERNAME, SECRET, xTARGETS, xUSE_KEY_FILE, xKEY_FILE, \
xCREDENTIALS, SSH_PORT, TIMEOUT, GET_SERIAL_INFO, \
GET_HARDWARE_INFO, GET_OS_DETAILS, GET_CPU_INFO, \
GET_MEMORY_INFO, GET_UPTIME, IGNORE_DOMAIN, UPLOAD_IPV6, DEBUG, THREADS, \
DICT_OUTPUT = get_settings()
SSH_PORT = int(SSH_PORT)
TIMEOUT = int(TIMEOUT)
TARGETS = sys.argv[1].strip()
USE_KEY_FILE = ast.literal_eval(sys.argv[2].strip().capitalize())
KF = sys.argv[3].strip()
if KF.lower() in ('none', 'false', 'true'):
KEY_FILE = ast.literal_eval(KF.capitalize())
else:
KEY_FILE = KF
if not os.path.exists(KEY_FILE):
print '[!] Cannot find key file: "%s"' % KEY_FILE
print '[!] Exiting...'
sys.exit()
CR = sys.argv[4].strip()
if CR.lower() in ('none', 'false', 'true'):
CREDENTIALS = ast.literal_eval(CR)
else:
CREDENTIALS = CR
else:
print '\n[!] Wrong number of args. '
print ' '.join(sys.argv[1:])
print '[-] main.py TARGET USE_KEY_FILE KEY_FILE CREDENTIALS'
sys.exit()