-
Notifications
You must be signed in to change notification settings - Fork 345
/
Output.py
119 lines (106 loc) · 3.42 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/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 'server' in self.args: server = self.args['server']
else: server = "Unknown"
if 'port' in self.args: port = self.args['port']
else: port = "port"
formatMesg = '\n[{0}] {1}: {2}'.format(self.titlePos,'({0}:{1})'.format(server,port),m.decode())
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.decode())
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.decode())
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.decode())
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.decode())
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.decode())
if self.noColor == True or TERMCOLOR_AVAILABLE == False: print(formatMesg)
else : print(colored(formatMesg, 'yellow',attrs=['bold']))
def printImportantNotice(self,m):
'''
print important notice
'''
m = m.encode(encoding='UTF-8',errors='ignore')
formatMesg = '[!] Notice: {0}'.format(m.decode())
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').decode())
def getColoredString(self, string, color, attrs=[]):
'''
'''
if self.noColor == True or TERMCOLOR_AVAILABLE == False: return string
else : return colored(string, color, attrs=attrs)
def printMessage (self, m):
'''
print a message
'''
formatMesg = '[+] {0}'.format(m)
if self.noColor == True or TERMCOLOR_AVAILABLE == False:
print(formatMesg)
else :
print (colored(formatMesg, 'white',attrs=['bold']))