2015-10-27 12:25:17 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# --------------------------------------------------------------
|
|
|
|
# ip2e (IP to email) - Create the configuration file. |
|
|
|
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
|
|
|
# Licensed by GPL v.3 |
|
2016-02-16 15:53:39 +01:00
|
|
|
# Last update: 16-02-2016 |
|
2015-10-27 12:25:17 +01:00
|
|
|
# |
|
|
|
|
# Compatible with Python 3.x |
|
|
|
|
# --------------------------------------------------------------
|
2015-12-01 19:07:37 +01:00
|
|
|
version="1.3.1"
|
2015-10-27 12:25:17 +01:00
|
|
|
|
|
|
|
#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 ("")
|
2015-11-15 16:42:14 +01:00
|
|
|
exit()
|
2015-10-27 12:25:17 +01:00
|
|
|
|
|
|
|
#Function to clear screen
|
|
|
|
def ClearScreen():
|
2015-10-31 19:14:48 +01:00
|
|
|
if sys.platform == "cygwin":
|
|
|
|
print (300 * "\n")
|
|
|
|
elif os.name == "posix":
|
2015-10-27 12:25:17 +01:00
|
|
|
os.system("clear")
|
|
|
|
elif os.name == "nt":
|
|
|
|
os.system("cls")
|
|
|
|
else:
|
|
|
|
print ("Error: Unable clear screen")
|
|
|
|
|
|
|
|
#Detect system & PATH of user folder
|
2016-02-16 15:53:39 +01:00
|
|
|
if os.path.exists("/storage/sdcard0"):
|
|
|
|
HOMESCARD0="/storage/sdcard0/Android/data"
|
|
|
|
os.chdir(HOMESCARD0)
|
|
|
|
print ("Android (Posix) detected")
|
|
|
|
elif os.name == "posix":
|
2015-10-27 12:25:17 +01:00
|
|
|
os.chdir(os.environ["HOME"])
|
2016-02-16 15:53:39 +01:00
|
|
|
print ("Unix (Posix) detected")
|
2015-10-27 12:25:17 +01:00
|
|
|
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")
|
|
|
|
|
2015-11-09 11:01:40 +01:00
|
|
|
if os.path.isfile("ip2e.conf"):
|
2015-11-09 10:42:40 +01:00
|
|
|
ClearScreen()
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("** ip2e-config v"+version+" **")
|
2015-11-09 10:42:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print (" - Detected a previous configuration file.")
|
|
|
|
print (" - Do you want to overwrite or check the current configuration?")
|
2015-11-09 10:42:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print (" * (o) - overwrite (create new configuration)")
|
|
|
|
print (" * (c) - check and test the current configuration")
|
2015-11-09 10:42:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
OverWriteOrCheck=input("- [Default: check and test] Choose an option; ")
|
2015-11-09 10:42:40 +01:00
|
|
|
if OverWriteOrCheck == "o" or OverWriteOrCheck == "O":
|
|
|
|
print ("Create new configuration")
|
|
|
|
else:
|
2015-11-09 11:01:40 +01:00
|
|
|
exec(open("ip2e.conf").read())
|
2015-11-09 10:42:40 +01:00
|
|
|
#Import smtplib
|
|
|
|
import smtplib
|
|
|
|
try:
|
|
|
|
server = smtplib.SMTP(SmtpFromEmail)
|
|
|
|
server.ehlo()
|
|
|
|
server.starttls()
|
|
|
|
server.ehlo()
|
|
|
|
server.login(FromEmailUser,FromEmailPass)
|
|
|
|
server.quit()
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("* Test OK")
|
2015-11-09 10:42:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
PauseExit=input("+ Press ENTER to exit ")
|
2015-11-09 10:42:40 +01:00
|
|
|
except:
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("* Failed to connect ("+SmtpFromEmail+")")
|
2015-11-09 10:42:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
PauseExit=input("+ Press ENTER to exit ")
|
2015-11-15 16:42:14 +01:00
|
|
|
exit()
|
2015-11-09 10:42:40 +01:00
|
|
|
|
2015-11-09 11:01:40 +01:00
|
|
|
#Set variables of 'ip2e.conf'
|
2015-10-27 12:25:17 +01:00
|
|
|
ClearScreen()
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("** ip2e-config v"+version+" - Create config.file **")
|
2015-10-27 12:25:17 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
FromEmail=input("- Type the email sender: ")
|
|
|
|
FromEmailUser=input("- Type the user of email sender: ")
|
|
|
|
FromEmailPass=input("- Type the pass of email sender: ")
|
2016-02-16 16:15:04 +01:00
|
|
|
SmtpFromEmail=input("- Type the server STMP (STARTTLS) of email sender: ")
|
2015-12-01 19:06:02 +01:00
|
|
|
ToEmail=input("- Type the email receiver: ")
|
2015-10-27 12:25:17 +01:00
|
|
|
|
2015-11-09 11:01:40 +01:00
|
|
|
#Create 'ip2e.conf'
|
|
|
|
if os.path.isfile("ip2e.conf"):
|
|
|
|
os.remove("ip2e.conf")
|
|
|
|
ip2ecf=open('ip2e.conf','w')
|
2015-11-01 12:56:13 +01:00
|
|
|
ip2ecf.close()
|
2015-11-09 11:01:40 +01:00
|
|
|
ip2ecf=open('ip2e.conf','a')
|
2015-11-01 12:56:13 +01:00
|
|
|
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()
|
2015-10-27 12:25:17 +01:00
|
|
|
|
|
|
|
#Show the configuration
|
|
|
|
ClearScreen()
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("** ip2e-config v"+version+" - Current config.file **")
|
2015-10-27 12:25:17 +01:00
|
|
|
print ("")
|
2015-11-09 11:01:40 +01:00
|
|
|
readfile=open('ip2e.conf', 'r')
|
2015-10-29 18:02:23 +01:00
|
|
|
print(readfile.read())
|
|
|
|
readfile.close()
|
2015-11-01 15:17:40 +01:00
|
|
|
|
|
|
|
#Test connection with your configuration
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
TestConnection=input("- [Default: y] Test connection with your configuration (y/n): ")
|
2015-11-09 10:42:40 +01:00
|
|
|
if TestConnection == "n":
|
|
|
|
print ("Exiting...")
|
2015-11-15 16:42:14 +01:00
|
|
|
exit()
|
2015-11-09 10:42:40 +01:00
|
|
|
else:
|
2015-11-09 11:01:40 +01:00
|
|
|
exec(open("ip2e.conf").read())
|
2015-11-01 15:17:40 +01:00
|
|
|
#Import smtplib
|
|
|
|
import smtplib
|
|
|
|
try:
|
|
|
|
server = smtplib.SMTP(SmtpFromEmail)
|
|
|
|
server.ehlo()
|
|
|
|
server.starttls()
|
|
|
|
server.ehlo()
|
|
|
|
server.login(FromEmailUser,FromEmailPass)
|
|
|
|
server.quit()
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("* Test OK")
|
2015-11-01 15:17:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
PauseExit=input("+ Press ENTER to exit ")
|
2015-11-01 15:17:40 +01:00
|
|
|
except:
|
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
print ("* Failed to connect ("+SmtpFromEmail+")")
|
2015-11-01 15:17:40 +01:00
|
|
|
print ("")
|
2015-12-01 19:06:02 +01:00
|
|
|
PauseExit=input("+ Press ENTER to exit ")
|