forked from quentinhardy/odat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Output.py
100 lines (89 loc) · 2.82 KB
/
Output.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#PYTHON_TERMCOLOR_OK
try:
from termcolor import colored
TERMCOLOR_AVAILABLE = True
except ImportError:
TERMCOLOR_AVAILABLE = False
class Output ():
'''
All output except log used this object
'''
def __init__(self, args):
'''
CONSTRUCTOR
'''
self.args = args
self.noColor = args['no-color']
self.titlePos = 0
self.subTitlePos = 0
self.subSubTitlePos = 0
def title (self, m):
'''
print a title
'''
server, port = "", ""
m = m.encode(encoding='UTF-8',errors='ignore')
self.titlePos += 1
self.subTitlePos = 0
if self.args.has_key('server'): server = self.args['server']
else: server = "Unknown"
if self.args.has_key('port'): port = self.args['port']
else: port = "port"
formatMesg = '\n[{0}] {1}: {2}'.format(self.titlePos,'({0}:{1})'.format(server,port),m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print formatMesg
else : print colored(formatMesg, 'white',attrs=['bold'])
def subtitle (self, m):
'''
print a subtitle
'''
m = m.encode(encoding='UTF-8',errors='ignore')
self.subTitlePos += 1
self.subSubTitlePos += 0
formatMesg = '[{0}.{1}] {2}'.format(self.titlePos, self.subTitlePos, m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print formatMesg
else : print colored(formatMesg, 'white',attrs=['bold'])
def subsubtitle (self, m):
'''
print a sub-subtitle
'''
m = m.encode(encoding='UTF-8',errors='ignore')
self.subSubTitlePos += 1
formatMesg = '[{0}.{1}.{2}] {3}'.format(self.titlePos, self.subTitlePos, self.subSubTitlePos, m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print formatMesg
else : print colored(formatMesg, 'white',attrs=['bold'])
def badNews (self, m):
'''
print a stop message
'''
m = m.encode(encoding='UTF-8',errors='ignore')
formatMesg = '[-] {0}'.format(m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print formatMesg
else : print colored(formatMesg, 'red',attrs=['bold'])
def goodNews(self,m):
'''
print good news
'''
m = m.encode(encoding='UTF-8',errors='ignore')
formatMesg = '[+] {0}'.format(m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print formatMesg
else : print colored(formatMesg, 'green',attrs=['bold'])
def unknownNews(self,m):
'''
print unknow news
'''
m = m.encode(encoding='UTF-8',errors='ignore')
formatMesg = '[+] {0}'.format(m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print formatMesg
else : print colored(formatMesg, 'yellow',attrs=['bold'])
def printOSCmdOutput(self,m):
'''
print the output of a OS command
'''
print m.encode(encoding='UTF-8',errors='ignore')
def getColoredString(self, string, color, attrs=[]):
'''
'''
if self.noColor == True or TERMCOLOR_AVAILABLE == False: return string
else : return colored(string, color, attrs=attrs)