This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ip2e-config.py
executable file
·150 lines (139 loc) · 4.28 KB
/
ip2e-config.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# --------------------------------------------------------------
# ip2e (IP to email) - Create the configuration file. |
# Created by q3aql (q3aql@protonmail.ch) |
# Licensed by GPL v.3 |
# Last update: 03-04-2021 |
# |
# Compatible with Python 3.x |
# --------------------------------------------------------------
version="1.3.2"
#Import python-modules
import os
import sys
#Check if your system use Python 3.x
if sys.version_info<(3,0):
print ("")
print ("* You need python 3.x to run this program.")
print ("")
exit()
#Function to clear screen
def ClearScreen():
if sys.platform == "cygwin":
print (300 * "\n")
elif os.name == "posix":
os.system("clear")
elif os.name == "nt":
os.system("cls")
else:
print ("* Error: Unable clear screen")
#Detect system & PATH of user folder
if os.path.exists("/storage/sdcard0"):
HOMESCARD0="/storage/sdcard0/Android/data"
os.chdir(HOMESCARD0)
print ("Android (Posix) detected")
elif os.name == "posix":
os.chdir(os.environ["HOME"])
print ("Unix (Posix) detected")
elif os.name == "nt":
os.chdir(os.environ["USERPROFILE"])
print ("Windows detected")
if not os.path.exists(".ip2e"):
os.makedirs(".ip2e")
os.chdir(".ip2e")
if os.path.exists(".ip2e"):
os.chdir(".ip2e")
if os.path.isfile("ip2e.conf"):
ClearScreen()
print ("")
print ("** ip2e-config v"+version+" **")
print ("")
print (" - Detected a previous configuration file.")
print (" - Do you want to overwrite or check the current configuration?")
print ("")
print (" * (o) - overwrite (create new configuration)")
print (" * (c) - check and test the current configuration")
print ("")
OverWriteOrCheck=input("- [Default: check and test] Choose an option; ")
if OverWriteOrCheck == "o" or OverWriteOrCheck == "O":
print ("Create new configuration")
else:
exec(open("ip2e.conf").read())
#Import smtplib
import smtplib
try:
server = smtplib.SMTP(SmtpFromEmail)
server.ehlo()
server.starttls()
server.ehlo()
server.login(FromEmailUser,FromEmailPass)
server.quit()
print ("")
print ("* Test OK")
print ("")
PauseExit=input("+ Press ENTER to exit ")
except:
print ("")
print ("* Failed to connect ("+SmtpFromEmail+")")
print ("")
PauseExit=input("+ Press ENTER to exit ")
exit()
#Set variables of 'ip2e.conf'
ClearScreen()
print ("")
print ("** ip2e-config v"+version+" - Create config.file **")
print ("")
FromEmail=input("- Type the email sender: ")
FromEmailUser=input("- Type the user of email sender: ")
FromEmailPass=input("- Type the pass of email sender: ")
SmtpFromEmail=input("- Type the server STMP (STARTTLS) of email sender: ")
ToEmail=input("- Type the email receiver: ")
#Create 'ip2e.conf'
if os.path.isfile("ip2e.conf"):
os.remove("ip2e.conf")
ip2ecf=open('ip2e.conf','w')
ip2ecf.close()
ip2ecf=open('ip2e.conf','a')
ip2ecf.write('# sample configuration file of ip2e\n')
ip2ecf.write('\n')
ip2ecf.write('FromEmail="'+FromEmail+'"\n')
ip2ecf.write('FromEmailUser="'+FromEmailUser+'"\n')
ip2ecf.write('FromEmailPass="'+FromEmailPass+'"\n')
ip2ecf.write('SmtpFromEmail="'+SmtpFromEmail+'"\n')
ip2ecf.write('ToEmail="'+ToEmail+'"\n')
ip2ecf.close()
#Show the configuration
ClearScreen()
print ("")
print ("** ip2e-config v"+version+" - Current config.file **")
print ("")
readfile=open('ip2e.conf', 'r')
print(readfile.read())
readfile.close()
#Test connection with your configuration
print ("")
TestConnection=input("- [Default: y] Test connection with your configuration (y/n): ")
if TestConnection == "n":
print ("Exiting...")
exit()
else:
exec(open("ip2e.conf").read())
#Import smtplib
import smtplib
try:
server = smtplib.SMTP(SmtpFromEmail)
server.ehlo()
server.starttls()
server.ehlo()
server.login(FromEmailUser,FromEmailPass)
server.quit()
print ("")
print ("* Test OK")
print ("")
PauseExit=input("+ Press ENTER to exit ")
except:
print ("")
print ("* Failed to connect ("+SmtpFromEmail+")")
print ("")
PauseExit=input("+ Press ENTER to exit ")