示例#1
0
def send_email_main(address,title,cmd,mailtype,intromessage,bodytextlist=[]):
	
	# mailtype option
	# "report"
	# "alert"
	if mailtype=="report":
		starttitle="Report:"
		showtable=True
		showpicture=True
		showlink=True

			
	elif mailtype=="alert":
		starttitle="Alert:"
		showtable=False
		showpicture=False
		showlink=True

	
	
	currentdate=datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
	# got credentials here !
	user=emaildbmod.getaddress()
	pwd=emaildbmod.getpassword()
	recipient=address

	# check IP address
	iplocal=networkmod.get_local_ip()	
	ipext=networkmod.EXTERNALIPADDR
	if ipext=="":
		logger.info('Stored external IP address is empty, try to get it from network')
		ipext=networkmod.get_external_ip()
		
	print "Try to send mail"	
	# subject of the mail
	subject=starttitle +" " + title + "  " + currentdate
	htmlbody=create_htmlopen()
	htmlbody=htmlbody+create_htmlintro(intromessage)+create_htmlbody(bodytextlist)
	
	if showlink:
		if ipext=="":
			print "No external IP address available"
			logger.error('Unable to get external IP address')		
		else:		
			port=str(networkmod.PUBLICPORT)
			if cmd=="mail+info+link":
				htmlbody=htmlbody+create_htmladdresses(ipext, iplocal, port)
	if showtable:
		# table with information
		matrixinfo=sensordbmod.sensorsysinfomatrix()
		htmlbody=htmlbody+create_htmlmatrix(matrixinfo)
		matrixinfo=actuatordbmod.sensorsysinfomatrix()
		htmlbody=htmlbody+create_htmlmatrix(matrixinfo)
	htmlbody=htmlbody+create_htmlclose()
	issent=send_email_html(user, pwd, recipient, subject, htmlbody, showpicture)
	if (issent) and (showlink) and (ipext!=""):
		global IPEXTERNALSENT
		IPEXTERNALSENT=ipext
	return issent
示例#2
0
def send_email_main(address, title, cmd, mailtype, intromessage):

    # mailtype option
    # "report"
    # "alert"
    if mailtype == "report":
        starttitle = "Report:"
        showtable = True
        showpicture = True
        showlink = True

    elif mailtype == "alert":
        starttitle = "Alert:"
        showtable = False
        showpicture = False
        showlink = True

    currentdate = datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
    # got credentials here !
    user = emaildbmod.getaddress()
    pwd = emaildbmod.getpassword()
    recipient = address

    # check IP address
    iplocal = networkmod.get_local_ip()
    ipext = networkmod.get_external_ip()
    if ipext == "":
        print "No external IP address, mail is not sent"
        logger.error('Unable to get external IP address, mail is not sent')
        return False
    else:
        print "Try to send mail"
        # subject of the mail
        subject = starttitle + " " + title + "  " + currentdate
        htmlbody = create_htmlopen()
        htmlbody = htmlbody + create_htmlintro(intromessage)
        if showlink:
            port = str(networkmod.PUBLICPORT)
            if cmd == "mail+info+link":
                htmlbody = htmlbody + create_htmladdresses(
                    ipext, iplocal, port)
        if showtable:
            # table with information
            matrixinfo = sensordbmod.sensorsysinfomatrix()
            htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
            matrixinfo = actuatordbmod.sensorsysinfomatrix()
            htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
        htmlbody = htmlbody + create_htmlclose()
        issent = send_email_html(user, pwd, recipient, subject, htmlbody,
                                 showpicture)
        if issent:
            global IPEXTERNALSENT
            IPEXTERNALSENT = ipext
    return issent
示例#3
0
def network():
    #if not session.get('logged_in'):
    #	return render_template('login.html',error=None, change=False)
    wifilist = []
    savedssid = []
    filenamelist = "wifi networks"

    print("visualizzazione menu network:")

    iplocal = networkmod.get_local_ip()
    iplocallist = networkmod.get_local_ip_list()
    ipext = networkmod.get_external_ip()
    iplocalwifi = networkmod.IPADDRESS
    ipport = networkmod.PUBLICPORT
    hostname = networkmod.gethostname()
    connectedssidlist = networkmod.connectedssid()
    if len(connectedssidlist) > 0:
        connectedssid = connectedssidlist[0]
    else:
        connectedssid = ""

    localwifisystem = networkmod.localwifisystem
    #print " localwifisystem = ", localwifisystem , " connectedssid ", connectedssid
    message = networkmod.networkdbmod.getstoredmessage()

    return render_template('network.html',
                           filenamelist=filenamelist,
                           connectedssid=connectedssid,
                           localwifisystem=localwifisystem,
                           ipext=ipext,
                           iplocallist=iplocallist,
                           iplocal=iplocal,
                           iplocalwifi=iplocalwifi,
                           ipport=ipport,
                           hostname=hostname,
                           message=message)
示例#4
0
        cmd = hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, hwname,
                                     hardwaremod.HW_CTRL_CMD)
        print "mail type ", cmd
        issent = send_email_main(address, title, cmd, mailtype, intromessage,
                                 bodytextlist)
        return issent
    else:
        print "No address specified"
        logger.error('No address specified')
        return False


if __name__ == '__main__':
    """
	prova email
	"""
    currentdate = datetime.datetime.now().strftime("%y-%m-%d,%H:%M")

    user = "******"
    pwd = "hydrosystem"
    recipient = "*****@*****.**"
    subject = "Today update " + currentdate
    body = "sono il testo prova 2"
    #send_email(user, pwd, recipient, subject, body)

    ipext = networkmod.get_external_ip()
    iplocal = networkmod.get_local_ip()
    htmlbody = create_html(ipext, iplocal, "5012")
    print htmlbody
    send_email_html(user, pwd, recipient, subject, htmlbody)
示例#5
0
def send_email_main(address,
                    title,
                    cmd,
                    mailtype,
                    intromessage,
                    bodytextlist=[]):

    # mailtype option
    # "report"
    # "alert"
    if mailtype == "report":
        starttitle = "Report:"
        showtable = True
        showpicture = True
        showlink = True

    elif mailtype == "alert":
        starttitle = "Alert:"
        showtable = False
        showpicture = False
        showlink = True

    elif mailtype == "info":
        starttitle = "Info:"
        showtable = False
        showpicture = False
        showlink = True

    currentdate = datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
    # got credentials here !
    user = emaildbmod.getaddress()
    pwd = emaildbmod.getpassword()
    recipient = address

    # check IP address
    iplocal = networkmod.get_local_ip()
    ipext = networkmod.EXTERNALIPADDR
    if ipext == "":
        logger.info(
            'Stored external IP address is empty, try to get it from network')
        ipext = networkmod.get_external_ip()

    print("Try to send mail")
    # subject of the mail
    subject = starttitle + " " + title + "  " + currentdate
    htmlbody = create_htmlopen()
    htmlbody = htmlbody + create_htmlintro(intromessage) + create_htmlbody(
        bodytextlist)

    if showlink:
        if ipext == "":
            print("No external IP address available")
            logger.error('Unable to get external IP address')
        else:
            port = str(networkmod.PUBLICPORT)
            if cmd == "mail+info+link":
                addresslist = []
                descriptionlist = []
                addresslist.append(iplocal)
                descriptionlist.append("Link for local Access")
                addresslist.append(ipext)
                descriptionlist.append("Link for Remote Access")
                customURL = networkmod.getCUSTOMURL()
                if not customURL == "":
                    addresslist.append(customURL)
                    descriptionlist.append("your Link")
                print("Mail url list ", addresslist)
                htmlbody = htmlbody + create_htmladdresses(
                    descriptionlist, addresslist, port)

    if showtable:
        # table with information
        matrixinfo = sensordbmod.sensorsysinfomatrix()
        htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
        matrixinfo = actuatordbmod.sensorsysinfomatrix()
        htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
    htmlbody = htmlbody + create_htmlclose()
    issent = send_email_html(user, pwd, recipient, subject, htmlbody,
                             showpicture)
    if (issent) and (showlink) and (ipext != ""):
        global IPEXTERNALSENT
        IPEXTERNALSENT = ipext
    return issent
示例#6
0
def networksetting():
    #if not session.get('logged_in'):
    #	return render_template('login.html',error=None, change=False)
    error = None

    Fake_password = "******"

    if request.method == 'POST':
        print(" here we are at network setting")
        reqtype = request.form['button']
        if reqtype == "save":
            print("saving network advanced setting")
            gotADDRESS = request.form['IPADDRESS']
            AP_SSID = request.form['AP_SSID']
            AP_PASSWORD = request.form['AP_PASSWORD']
            AP_TIME = request.form['AP_TIME']
            WIFIENDIS = request.form['WIFIENDIS']
            HOSTNAME = request.form['HOSTNAME']

            # Check
            isok1, IPADDRESS = networkmod.IPv4fromString(gotADDRESS)
            isok2 = False
            isok3 = False
            if len(AP_PASSWORD) > 7:
                isok2 = True
            if len(AP_SSID) > 3:
                isok3 = True

            if isok1 and isok2 and isok3:

                # previous paramenters
                IPADDRESSold = networkmod.IPADDRESS
                AP_SSIDold = networkmod.localwifisystem
                AP_TIMEold = str(networkmod.WAITTOCONNECT)
                HOSTNAMEold = networkmod.gethostname()
                WIFIENDISold = networkmod.WIFIENDIS

                print("save in network file in database")
                networkdbmod.changesavesetting('LocalIPaddress', IPADDRESS)
                networkdbmod.changesavesetting('LocalAPSSID', AP_SSID)
                networkdbmod.changesavesetting('APtime', AP_TIME)
                networkdbmod.changesavesetting('WIFIENDIS', WIFIENDIS)

                # save and change values in the HOSTAPD config file
                sysconfigfilemod.hostapdsavechangerow("ssid", AP_SSID)
                if AP_PASSWORD != Fake_password:
                    # change password in the HOSTAPD config file
                    sysconfigfilemod.hostapdsavechangerow(
                        "wpa_passphrase", AP_PASSWORD)
                    print("password changed")
                else:
                    AP_PASSWORD = ""

                if IPADDRESSold != IPADDRESS:
                    # save changes in DHCPCD confign file
                    sysconfigfilemod.modifydhcpcdconfigfile(
                        IPADDRESSold, IPADDRESS)

                    # save changes in DNSMASQ confign file
                    sysconfigfilemod.modifydnsmasqconfigfile(
                        IPADDRESSold, IPADDRESS)

                if HOSTNAME != HOSTNAMEold:
                    networkmod.setnewhostname(HOSTNAME)

                # proceed with changes
                networkmod.applyparameterschange(AP_SSID, AP_PASSWORD,
                                                 IPADDRESS)
                networkmod.WAITTOCONNECT = AP_TIME
                networkmod.WIFIENDIS = WIFIENDIS

                # Change hostapd file first row with HERE
                data = []
                networkdbmod.readdata(data)
                sysconfigfilemod.hostapdsavechangerow_spec(data)

                if WIFIENDISold != WIFIENDIS:
                    if WIFIENDIS == "Disabled":
                        networkmod.Disable_WiFi()
                    else:
                        networkmod.connect_network()

                flash('Network setting Saved')
                return redirect(url_for('network'))
            else:
                if not isok1:
                    flash('please input valid IP address', 'danger')
                if not isok2:
                    flash('please input password longer than 7 characters',
                          'danger')
                if not isok3:
                    flash('please input SSID longer than 3 characters',
                          'danger')
        elif reqtype == "cancel":
            return redirect(url_for('network'))

    HOSTNAME = networkmod.gethostname()
    iplocal = networkmod.get_local_ip()
    IPADDRESS = networkmod.IPADDRESS
    PORT = networkmod.PUBLICPORT
    AP_SSID = networkmod.localwifisystem
    AP_TIME = str(networkmod.WAITTOCONNECT)
    WIFIENDIS = networkmod.WIFIENDIS
    connectedssidlist = networkmod.connectedssid()
    if len(connectedssidlist) > 0:
        connectedssid = connectedssidlist[0]
    else:
        connectedssid = ""
    AP_PASSWORD = Fake_password

    return render_template('networksetting.html',
                           IPADDRESS=IPADDRESS,
                           AP_SSID=AP_SSID,
                           AP_PASSWORD=AP_PASSWORD,
                           AP_TIME=AP_TIME,
                           HOSTNAME=HOSTNAME,
                           WIFIENDIS=WIFIENDIS)
示例#7
0
		return issent
	else:
		print "No address specified"
		logger.error('No address specified')
		return False




if __name__ == '__main__':
	
	"""
	prova email
	"""
	currentdate=datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
	
	user="******"
	pwd="hydrosystem"
	recipient="*****@*****.**"
	subject="Today update " + currentdate
	body="sono il testo prova 2"
	#send_email(user, pwd, recipient, subject, body)
	
	ipext=networkmod.get_external_ip()
	iplocal=networkmod.get_local_ip()
	htmlbody=create_html(ipext, iplocal, "5012")	
	print htmlbody
	send_email_html(user, pwd, recipient, subject, htmlbody)