summaryrefslogtreecommitdiff
path: root/Utilities/server.py
blob: 9da38025996a88696ffbb840c2c304005c39a54f (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import msvcrt
import random
import time
import os

from PIL import ImageFont, Image, ImageDraw, ImageOps
from colorama import Fore, Style


def set_module_ports(values):
	ports = []
	for value in values:
		try:
			port = int(value)
			if port > 65000 or port < 1000:
				raise Exception('Something went wrong')
			ports.append(port)
		except:
			ports.append(random.randint(1000, 65000))
	while True:
		if len(ports) < 5:
			ports.append(random.randint(1000, 65000))		
		else:
			break
	return ports


def set_username(value):
	if value is None:
		try:
			return os.environ['USERNAME'].capitalize()
		except:
			return 'Anonymous'
	elif len(value) < 15 and len(value) > 0:
		return value.capitalize()


def set_theme(value):
	if len(value) > 0:
		if value == 'light':
			return [Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, Fore.LIGHTCYAN_EX, Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, 'light'] 
		elif value == 'dark':
			return [Fore.BLACK, Fore.LIGHTRED_EX, Fore.LIGHTCYAN_EX, Fore.BLACK, Fore.LIGHTRED_EX, 'dark']
		elif value == 'shade':
			return [Fore.LIGHTBLACK_EX, Fore.RED, Fore.CYAN, Fore.LIGHTBLACK_EX, Fore.LIGHTRED_EX, 'shade']
		elif value == 'star':
			return [Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, Fore.LIGHTYELLOW_EX, Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, 'star']
		elif value == 'diamond':
			return [Fore.LIGHTWHITE_EX, Fore.LIGHTYELLOW_EX, Fore.LIGHTBLUE_EX, Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, 'diamond']
		elif value == 'blood':
			return [Fore.LIGHTWHITE_EX, Fore.LIGHTYELLOW_EX, Fore.LIGHTRED_EX, Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, 'blood']
		elif value == 'sky':
			return [Fore.LIGHTWHITE_EX, Fore.LIGHTMAGENTA_EX, Fore.LIGHTBLUE_EX, Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, 'sky']
		elif value == 'hacker':
			return [Fore.LIGHTWHITE_EX, Fore.GREEN, Fore.GREEN, Fore.LIGHTWHITE_EX, Fore.LIGHTRED_EX, 'hacker']


def set_encoding(value):
	if len(value) < 15 and len(value) > 0:
		return value


def set_bool(value):
	if value is True:
		return True
	else:
		return False


def set_email(value):
	self_email_list = []

	try:
		if value[0].lower() == 'true':
			self_email_list.append(True)
		else:
			raise Exception('Something went wrong.')
	except:
		self_email_list.append(False)

	try:
		if '@' in value[1]:
			self_email_list.append(value[1])
		else:
			raise Exception('Something went wrong.')
	except:
		self_email_list.append(None)

	try:
		if value[2] != '' and value[2] != 'None':
			self_email_list.append(value[2])
		else:
			raise Exception('Something went wrong.')
	except:
		self_email_list.append(None)
	
	try:
		if len(value) > 3:
			for email in value[3:]:
				if '@' in email:
					continue
				else:
					value.remove(email)
			self_email_list.append(value[3:])
		else:
			raise Exception('Something went wrong.')
	except:
		self_email_list.append([])

	return self_email_list


def setup_directory(directories):
	for directory in directories:
		if os.path.isdir(directory) is False:
			os.mkdir(directory)


def clear_screen():
	os.system('clear || cls')


def banner(theme):
	print(f'''{theme[2]}{' ' * 84}///,        ////{Style.RESET_ALL}
{theme[1]}{'_' * 35}Created by{'_' * 34}{' ' * 5}{Style.RESET_ALL}{theme[2]}\  /,      /  >.{Style.RESET_ALL}
{theme[2]}{' ' * 84} \  /,   _/  /.{Style.RESET_ALL}
{theme[2]}//       //        //{Style.RESET_ALL}{theme[3]}        // // //    // // //    // // //    //    // // //{Style.RESET_ALL}{theme[2]}       \_  /_/   /.
{theme[2]} //     // //     // {Style.RESET_ALL}{theme[3]}      //     //    //    //    //          //    //{Style.RESET_ALL}{theme[2]}               \__/_   <
{theme[2]}  //   //   //   //  {Style.RESET_ALL}{theme[3]}    // //// //    //    //    // // //    //    // // //{Style.RESET_ALL}{theme[2]}          /<<< \_\_
{theme[2]}   // //     // //   {Style.RESET_ALL}{theme[3]}  //       //    //    //          //    //    //{Style.RESET_ALL}{theme[2]}                /,)^>>_._ \\
{theme[2]}     //        //    {Style.RESET_ALL}{theme[3]}//        //    //    //    // // //    //    //  // //{Style.RESET_ALL}{theme[2]}          (/   \\\\ /\\\\\\
{theme[1]}{'_' * 79}{' ' * 12}{Style.RESET_ALL}{theme[2]}// ````{Style.RESET_ALL}
{theme[2]}{' ' * 90}((`{Style.RESET_ALL}''')


def timer():
	return time.strftime("%Y-%m-%d %H:%M")


def text_image(text):
	PIXEL_ON = 255
	PIXEL_OFF = 0

	grayscale = 'L'
	lines = tuple(l.rstrip() for l in text.split('\n'))

	large_font = 40
	font_path = 'cour.ttf'

	try:
		font = ImageFont.truetype(font_path, size=large_font)
	except IOError:
		font = ImageFont.load_default()

	pt2px = lambda pt: int(round(pt * 96.0 / 72))
	max_width_line = max(lines, key=lambda s: font.getsize(s)[0])
	test_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	max_height = pt2px(font.getsize(test_string)[1])
	max_width = pt2px(font.getsize(max_width_line)[0])
	height = max_height * len(lines)
	width = int(round(max_width + 40))
	image = Image.new(grayscale, (width, height), color=PIXEL_OFF)
	draw = ImageDraw.Draw(image)

	vertical_position = 5
	horizontal_position = 5
	line_spacing = int(round(max_height * 0.8))
	for line in lines:
		draw.text((horizontal_position, vertical_position), line, fill=PIXEL_ON, font=font)
		vertical_position += line_spacing
	c_box = ImageOps.invert(image).getbbox()
	image = image.crop(c_box)
	return image


def readInput(encoding, timeout):
	start_time = time.time()
	inputData = ''

	while True:
		if msvcrt.kbhit():
			character = msvcrt.getwch()

			if character == '\b' and len(inputData) == 0:
				continue
			elif chr(ord(character)) == 'à':
				sub = msvcrt.getwch()
				if sub == 'K' or sub == 'M' or sub == 'P' or sub == 'H':
					pass
				continue

			print(character, end='', flush=True)

			if character == '\r':
				break
			elif character == '\b':
				inputData = inputData[:-1]
				print(' \b', end='', flush=True)			
			else:
				inputData += character
		
		if timeout is True:
			pass
		elif len(inputData) == 0 and (time.time() - start_time) > timeout:
			break
		time.sleep(0.01)

	print()
	if len(inputData) > 0:
		return inputData
	else:
		raise TimeoutError('Timeout')