Commit fb36fa66 authored by nextime's avatar nextime

Add source variable to action for email

parent 180c5712
...@@ -1160,7 +1160,7 @@ class domotikaService(service.Service): ...@@ -1160,7 +1160,7 @@ class domotikaService(service.Service):
if 'status' in args.keys(): if 'status' in args.keys():
status=args['status'] status=args['status']
def executeAction(self, command): def executeAction(self, command, src='internal'):
def multipleInsertNotify(dbres, nsrc, expire, msg): def multipleInsertNotify(dbres, nsrc, expire, msg):
if dbres: if dbres:
for ue in dbres: for ue in dbres:
...@@ -1171,7 +1171,7 @@ class domotikaService(service.Service): ...@@ -1171,7 +1171,7 @@ class domotikaService(service.Service):
log.debug(command) log.debug(command)
command=command[7:] command=command[7:]
subprocess.Popen( subprocess.Popen(
command.replace("\r\n", " "), command.replace("\r\n", " ").replace('[[SRC]]', src),
shell=True, preexec_fn = os.setsid) shell=True, preexec_fn = os.setsid)
elif command.startswith("IOCONF ") or command.startswith("IOCONF:"): elif command.startswith("IOCONF ") or command.startswith("IOCONF:"):
command=command[7:] command=command[7:]
...@@ -1195,7 +1195,7 @@ class domotikaService(service.Service): ...@@ -1195,7 +1195,7 @@ class domotikaService(service.Service):
dmdb.updateNetStatus(nst).addCallback(self.sendNetStatus, True) dmdb.updateNetStatus(nst).addCallback(self.sendNetStatus, True)
elif command.startswith("EMAIL ") or command.startswith("EMAIL:"): elif command.startswith("EMAIL ") or command.startswith("EMAIL:"):
mname=command[6:] mname=command[6:]
email.sendEmailByName(mname) email.sendEmailByName(mname, sval=src)
elif command.startswith("NOTIFY ") or command.startswith("NOTIFY:"): elif command.startswith("NOTIFY ") or command.startswith("NOTIFY:"):
expire=time.time()+float(self.config.get("general", "notify_expiretime")) expire=time.time()+float(self.config.get("general", "notify_expiretime"))
...@@ -1395,7 +1395,7 @@ class domotikaService(service.Service): ...@@ -1395,7 +1395,7 @@ class domotikaService(service.Service):
def parseAction(self, res, restype="action"): def parseAction(self, res, restype="action", s='internal'):
if restype=="action": if restype=="action":
try: try:
timedict=parseCronLine( timedict=parseCronLine(
...@@ -1423,7 +1423,7 @@ class domotikaService(service.Service): ...@@ -1423,7 +1423,7 @@ class domotikaService(service.Service):
return return
if genutils.isTrue(res.execute): if genutils.isTrue(res.execute):
self.executeAction(res.command) self.executeAction(res.command, src=s)
if genutils.isTrue(res.ikapacket): if genutils.isTrue(res.ikapacket):
self.sendCommand(res.ikap_dst, act=res.ikap_act, ctx=res.ikap_ctx, msgtype=res.ikap_msgtype, self.sendCommand(res.ikap_dst, act=res.ikap_act, ctx=res.ikap_ctx, msgtype=res.ikap_msgtype,
arg=res.ikap_arg, src=res.ikap_src, ipdst=str(res.ipdest)) arg=res.ikap_arg, src=res.ikap_src, ipdst=str(res.ipdest))
...@@ -1990,16 +1990,16 @@ class domotikaService(service.Service): ...@@ -1990,16 +1990,16 @@ class domotikaService(service.Service):
return False return False
return True return True
def manageRecvPkt(self, res, argdict): def manageRecvPkt(self, res, argdict, src='internal'):
# XXX Usiamo un generator o reactor.callLater? # XXX Usiamo un generator o reactor.callLater?
if res: if res:
log.debug("ManageRcvPkt "+str(res)) log.debug("ManageRcvPkt "+str(res))
for r in res: for r in res:
if genutils.isTrue(r.use_rcv_arg): if genutils.isTrue(r.use_rcv_arg):
if argdict and self.checkRcvArg(r.rcv_arg, argdict): if argdict and self.checkRcvArg(r.rcv_arg, argdict):
self.parseAction(r) self.parseAction(r, s=src)
else: else:
self.parseAction(r) self.parseAction(r, s=src)
def on_callback(self, who, cmd, *args, **kwargs): def on_callback(self, who, cmd, *args, **kwargs):
f=getattr(self, who+'_on_'+cmd, None) f=getattr(self, who+'_on_'+cmd, None)
...@@ -2699,7 +2699,7 @@ class domotikaService(service.Service): ...@@ -2699,7 +2699,7 @@ class domotikaService(service.Service):
dmdb.matchIncomingPacket(dst, src, dmdb.matchIncomingPacket(dst, src,
ikahdr.msgtype, ikahdr.ctx, ikahdr.msgtype, ikahdr.ctx,
ikahdr.act, islocal=islocal).addCallback( ikahdr.act, islocal=islocal).addCallback(
self.manageRecvPkt, argdict self.manageRecvPkt, argdict, src
) )
events.postEvent(events.NetworkEvent(dst, src, ikahdr, arg, host)) events.postEvent(events.NetworkEvent(dst, src, ikahdr, arg, host))
if arg: if arg:
......
...@@ -135,7 +135,7 @@ class DMEmail(object): ...@@ -135,7 +135,7 @@ class DMEmail(object):
return d.addCallbacks(self.end) return d.addCallbacks(self.end)
def _realSendMime(ser, res): def _realSendMime(ser, res, sval='internal'):
if ser: if ser:
for s in ser: for s in ser:
e=DMEmail() e=DMEmail()
...@@ -154,19 +154,19 @@ def _realSendMime(ser, res): ...@@ -154,19 +154,19 @@ def _realSendMime(ser, res):
e.setFrom(m.sender) e.setFrom(m.sender)
e.setTo(m.to.split(',')) e.setTo(m.to.split(','))
e.setSubject(m.subject) e.setSubject(m.subject)
e.setMessage(m.message) e.setMessage(m.message.replace('[[SRCVAL]]', sval))
e.send() e.send()
def _sendEmailMime(res): def _sendEmailMime(res, sval='internal'):
if res: if res:
dmdb.EmailConf.find().addCallback(_realSendMime, res) dmdb.EmailConf.find().addCallback(_realSendMime, res, sval)
def _realSendMail(ser, sender, recipient, message): def _realSendMail(ser, sender, recipient, message, sval='internal'):
if ser: if ser:
e=DMEmail() e=DMEmail()
e.setFrom(sender) e.setFrom(sender)
e.setTo(recipient.split(',')) e.setTo(recipient.split(','))
e.setMessage(message) e.setMessage(message.replace('[[SRCVAL]]', sval) )
for s in ser: for s in ser:
e.setServer(s.server, s.port) e.setServer(s.server, s.port)
...@@ -188,12 +188,12 @@ def sendMail(sender, recipient, message): ...@@ -188,12 +188,12 @@ def sendMail(sender, recipient, message):
return dmdb.EmailConf.find().addCallback(_realSendMail, sender, recipient, message) return dmdb.EmailConf.find().addCallback(_realSendMail, sender, recipient, message)
def sendEmailByName(name): def sendEmailByName(name, sval='internal'):
dmdb.Email.find(where=["name=?", name]).addCallback(_sendEmailMime) dmdb.Email.find(where=["name=?", name]).addCallback(_sendEmailMime, sval)
def sendEmailById(mailid): def sendEmailById(mailid, sval='internal'):
dbdb.Email.find(where=["id=?", mailid]).addCallback(_sendEmailMime) dbdb.Email.find(where=["id=?", mailid]).addCallback(_sendEmailMime, sval)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment