Import native OS color scheme
This commit is contained in:
parent
db9959b61e
commit
af9f3479ca
|
@ -5,7 +5,7 @@
|
||||||
# ip2e (IP to email) - Create the configuration file. |
|
# ip2e (IP to email) - Create the configuration file. |
|
||||||
# Created by clamsawd (clamsawd@openmailbox.org) |
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 29-10-2015 |
|
# Last update: 30-10-2015 |
|
||||||
# |
|
# |
|
||||||
# Dependences: curl or wget |
|
# Dependences: curl or wget |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# ip2e (IP to email) - Run ip2e daemon. |
|
# ip2e (IP to email) - Run ip2e daemon. |
|
||||||
# Created by clamsawd (clamsawd@openmailbox.org) |
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 29-10-2015 |
|
# Last update: 30-10-2015 |
|
||||||
# |
|
# |
|
||||||
# Dependences: curl or wget |
|
# Dependences: curl or wget |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
|
@ -107,12 +107,24 @@ except:
|
||||||
#Import variables from ip2e-conf.py
|
#Import variables from ip2e-conf.py
|
||||||
exec(open("ip2e-conf.py").read())
|
exec(open("ip2e-conf.py").read())
|
||||||
|
|
||||||
#Import Windows colors scheme
|
#Import native OS color scheme
|
||||||
def GreenColor():
|
def GreenColor():
|
||||||
|
if os.name == "posix":
|
||||||
|
GreenColor = (chr(27)+"[1;32m")
|
||||||
|
print (GreenColor+"", end="")
|
||||||
|
elif os.name == "nt":
|
||||||
os.system("color 2")
|
os.system("color 2")
|
||||||
def RedColor():
|
def RedColor():
|
||||||
|
if os.name == "posix":
|
||||||
|
RedColor = (chr(27)+"[1;31m")
|
||||||
|
print (RedColor+"", end="")
|
||||||
|
elif os.name == "nt":
|
||||||
os.system("color 4")
|
os.system("color 4")
|
||||||
def OrangeColor():
|
def OrangeColor():
|
||||||
|
if os.name == "posix":
|
||||||
|
OrangeColor = (chr(27)+"[1;33m")
|
||||||
|
print (OrangeColor+"", end="")
|
||||||
|
elif os.name == "nt":
|
||||||
os.system("color 6")
|
os.system("color 6")
|
||||||
|
|
||||||
#Check if exists a previous log.file.
|
#Check if exists a previous log.file.
|
||||||
|
@ -125,22 +137,15 @@ createlog.close()
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
editlog=open('ip2e.log','a')
|
editlog=open('ip2e.log','a')
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
|
GreenColor()
|
||||||
|
print ("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["HOME"]+"/.ip2e/ip2e.log")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
GreenColor()
|
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
|
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["HOME"]+"/.ip2e/ip2e.log")
|
|
||||||
elif os.name == "nt":
|
|
||||||
GreenColor()
|
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["USERPROFILE"]+"\.ip2e\\ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["USERPROFILE"]+"\.ip2e\\ip2e.log")
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+"\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+"\n")
|
||||||
if os.name == "posix":
|
OrangeColor()
|
||||||
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...")
|
||||||
elif os.name == "nt":
|
|
||||||
OrangeColor()
|
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...")
|
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...\n")
|
||||||
editlog.close()
|
editlog.close()
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
|
@ -151,9 +156,6 @@ while PublicIP <= 2:
|
||||||
GetCurrentIP = 1
|
GetCurrentIP = 1
|
||||||
while GetCurrentIP <= 2:
|
while GetCurrentIP <= 2:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
|
||||||
elif os.name == "nt":
|
|
||||||
OrangeColor()
|
OrangeColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
||||||
editlog=open('ip2e.log','a')
|
editlog=open('ip2e.log','a')
|
||||||
|
@ -168,10 +170,6 @@ while PublicIP <= 2:
|
||||||
GetCurrentIP += 2
|
GetCurrentIP += 2
|
||||||
else:
|
else:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
|
||||||
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
|
||||||
elif os.name == "nt":
|
|
||||||
RedColor()
|
RedColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
||||||
|
@ -181,17 +179,11 @@ while PublicIP <= 2:
|
||||||
exec(open("current-ip.py").read())
|
exec(open("current-ip.py").read())
|
||||||
if CurrentIP == NewIP:
|
if CurrentIP == NewIP:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
|
|
||||||
elif os.name == "nt":
|
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP has not changed\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP has not changed\n")
|
||||||
else:
|
else:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
|
|
||||||
elif os.name == "nt":
|
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
|
print ("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP+"\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP+"\n")
|
||||||
|
@ -209,10 +201,6 @@ while PublicIP <= 2:
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.login(FromEmailUser,FromEmailPass)
|
server.login(FromEmailUser,FromEmailPass)
|
||||||
except:
|
except:
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
|
||||||
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
|
|
||||||
elif os.name == "nt":
|
|
||||||
RedColor()
|
RedColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
|
||||||
|
@ -225,9 +213,6 @@ while PublicIP <= 2:
|
||||||
server.quit()
|
server.quit()
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Email was sent successfully"
|
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Email was sent successfully"
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;32m"+MailMessage+" ("+ToEmail+")")
|
|
||||||
elif os.name == "nt":
|
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print (MailMessage+" ("+ToEmail+")")
|
print (MailMessage+" ("+ToEmail+")")
|
||||||
editlog.write(MailMessage+" to "+ToEmail+"\n")
|
editlog.write(MailMessage+" to "+ToEmail+"\n")
|
||||||
|
@ -235,10 +220,6 @@ while PublicIP <= 2:
|
||||||
except SMTPException:
|
except SMTPException:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Fail to send email"
|
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Fail to send email"
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;31m"+MailMessage+" ("+ToEmail+")")
|
|
||||||
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
|
||||||
elif os.name == "nt":
|
|
||||||
RedColor()
|
RedColor()
|
||||||
print (MailMessage+" ("+ToEmail+")")
|
print (MailMessage+" ("+ToEmail+")")
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
||||||
|
@ -256,9 +237,6 @@ while PublicIP <= 2:
|
||||||
createNewip2eIPcf()
|
createNewip2eIPcf()
|
||||||
writeNewip2eIPcf()
|
writeNewip2eIPcf()
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
if os.name == "posix":
|
|
||||||
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
|
|
||||||
elif os.name == "nt":
|
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...\n")
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# ip2e (IP to email) - See the log file. |
|
# ip2e (IP to email) - See the log file. |
|
||||||
# Created by clamsawd (clamsawd@openmailbox.org) |
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 29-10-2015 |
|
# Last update: 30-10-2015 |
|
||||||
# |
|
# |
|
||||||
# Dependences: curl or wget |
|
# Dependences: curl or wget |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
|
|
Loading…
Reference in New Issue
Block a user