Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted by voron ( 13 years ago )
#!/usr/bin/python2.6
#
#
#
import smtplib
import grab
import email
import os
from email.mime.text import MIMEText
import sys
import os
from subprocess import call
import getpass
import re
#
#
#


#
#
#
#Glogal variables:
#
mail_files=[]

f=open("r2r.list","r")

r2r_list=f.readlines()

file_names=[]

vccnumber_o=""

hostname_o=""

mail_list=[]

your_email=""
#
#
#
#
#



#
#
#
##WARNING !!!! look below
##In 'regards' variable you must create string which contains only your email address
##This email address will use to notify users where they must send reply email.
##WARNING !!!! look above
#
#
#
regards="""

BR,

Marat Saldakov

Linux/Unix technician

PAG
LLC "Volvo Cars"
Dept. 61377
Goteborg
Sweden
+46-31-590000

[email protected]
www.volvocars.com
"""
#
#
#


###
###Confirm signatures
###
print "---------------------------------------"
print regards
print "---------------------------------------"
print "     You can change it in script`s body"
print "\n"
if((raw_input("Confirm signatures ? yes / no:"))=="no"):
    exit()
###
###
###

#
#
#
#Getting email from 'regards' variable
#
for string in (regards.split("\n")):
    if((string.find("@")>=1)):
        print "Your email %s" % (string)
        your_email="Please reply me to this email : "+ string

#
#
#
#
#


#
#
#
#$ autentification
#
#password=""
#login=""
##
##Getting info
##
#login=raw_input("Enter VCC Login:")

#pw = getpass.getpass()
#for r2r in r2r_list:
#    from grab import Grab
#    url_distruct=r2r.split("=")
#    file_names.append(str((url_distruct[1])[0:-1]))
#    g = Grab(log_file=str(file_names.pop()))
#    file_names.append(str((url_distruct[1])[0:-1]))
#    g.go(r2r)
#    g.set_input('cdsid', str(login))
#    g.set_input('pw', str(pw))
#    g.submit()
##
##end
##
##file_names - contains web page retrieved with this r2r url
file_names=['0440fcfc-eb24-4cba-b7f3-ccc3ab8e1d16', '08ca8290-1f5d-40bc-ae09-8c9a53d1bef5', '4e8bf02f-1214-4ebe-883c-484c384b46fd', '556c4906-8d8b-4835-9a85-285af2edcb3a', '582048e0-0457-4b6d-98b2-54f9c3836e8d', '5beac686-eb39-428f-ae0a-65280ab93b36', '817a1b90-d5f6-45aa-bd98-d5c9674280d0', '87dead01-6b48-464c-8a89-62e6867ffb4e', '88cc89de-2bd0-4869-82dc-19c280fb648f', '987e8aaf-7fa1-4501-8dcb-23b2aa2ee46a', '9f510a73-8c8c-41d9-8ab9-7e225f315c13', 'b3fa731a-b2ac-4839-b664-3fc2c5b16453', 'b91763b9-abca-4b13-b7fc-f744ac2106a3', 'bd8b23ee-e454-411b-a345-b3076bcb1980', 'c55067ae-6ac0-4163-aeab-1c182a6c999e', 'e3b9daa4-4e15-4c83-a385-8b8a0c8a2fda', 'ffdb63a1-abf3-43ea-b585-0bb882371e72']
##remove 'file_names' after debug up
for file_name in file_names:
    f=open(file_name,"r")
    for string in f.readlines():
        ##
        ##VCC number resolving
        ##
        if((string.find('pdate, SLA Confirmation of request'))>=5):
                vcc=(((string.split(" ")).pop()).split("<"))
                vccnumber_o=vcc[0]
        ##
        ##end
        ##
        ##
        ##Hostname resolving
        ##
        if(string.find("Hostname:")>=0):
                offset_start=string.find("Hostname:")
                offset_stop=string.find("Management net hostname:")
                hostname_nc=string[offset_start:offset_stop]
                offset_span_start=hostname_nc.find("<span>")
                offset_span_stop=hostname_nc.find("</span>")
                hostname_o=hostname_nc[int(offset_span_start+6):int(offset_span_stop-5)]
        ##
        ##end
        ##
        ##
        ##CD SID Resolving
        ##Technical contact:
        ##CIA Rating:
        if(string.find("Technical contact:")>=0):
                offset_start=string.find("Technical contact:")
                offset_stop=string.find("CIA Rating:")
                cdsid_nc=string[offset_start:offset_stop]
                offset_span_start=cdsid_nc.find("<span>")
                offset_span_stop=cdsid_nc.find("</span>")
                mail_list.append(cdsid_nc[int(offset_span_start+6):int(offset_span_stop-5)])
        ##
        ##Two top CDSID resolving
        ##
        if(string.find("@volvocars.com</td>")>=0):
                cdsid_nc=(string.split(">"))

                mail_list.append((cdsid_nc[1]).split("<")[0])

        ###
        ###Preparing email message
        ###
    mail_file=file_name+".mail"
    m=open(mail_file,"wt")
    m.writelines("; ".join(mail_list))
    m.write("")
    m.write("\n")
    string="""Hi
The server (listed below)  are at the final step in R2R before going into production. Before server turns into production status we need to secure that we have the correct server contacts OR VAPS ID documented. You are recieveing this mail since you are defined as either Customer, Application owner or Technical contact within current R2R server install order.
Thanks
"""
    m.write(string)
    m.write("\n")
    m.write("---servers list----------------------------------------------------------------------------------------")
    m.write("\n")
    m.write("\n")
    m.writelines(vccnumber_o+"            "+hostname_o)
    m.write("\n")
    m.write("\n")
    m.write("---end servers list------------------------------------------------------------------------------------")
    m.write("\n\n")
    m.write(your_email)
    m.write("\n\n")
    m.write(regards) ### This variable is defined above
    m.write("\n")
    mail_files.append(mail_file)
    m.close
    vccnumber_o=""
    hostname_o=""
    mail_list=[]
    #file_names=[]

################################################################################################################
        ###
        ###Sending email
        ###
for mail_file in mail_files:
    hostname_to_subject=""
    #####temp_file=str(mail_file)+".tmp"
    fp = open(mail_file, 'rb')
        # Create a text/plain message
    msg = MIMEText(fp.read())
    fp.close()
    mess=(msg.as_string()).split("\n")
    ##
    ##Select hostname
    ##
    for string in mess:
        if (string.startswith("VCC")):
            info=string.split("            ")
            hostname_to_subject=info[1]
    ##
    ##
    ##

    msg['Subject'] = 'Asset update for %s ' % (hostname_to_subject)
    msg['From'] = '[email protected]'
    msg['To'] = '[email protected]'

        # Send the message via our own SMTP server, but don't include the
        # envelope header.
    s = smtplib.SMTP('localhost')
    mails=open(mail_file,"r").readline()
    mails_from_file=mails.split(" ")
    print mails_from_file
    s.sendmail('[email protected]', '[email protected]', msg.as_string())
    s.quit()

##################################################################################################################

 

Revise this Paste

Your Name: Code Language: