Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
domotikad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
domotika
domotikad
Commits
894ff02a
Commit
894ff02a
authored
11 years ago
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
send a SETTIME when an invalid packet is received
parent
ddf5881a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
domotika.py
domotika/domotika.py
+7
-3
ikapserver.py
domotika/ikapserver.py
+6
-2
No files found.
domotika/domotika.py
View file @
894ff02a
...
...
@@ -302,9 +302,10 @@ class domotikaService(service.Service):
self
.
sendCommand
(
str
(
st
),
msgtype
=
C
.
IKAP_MSG_ACTION
,
ctx
=
C
.
IKAP_CTX_STATUS
,
act
=
C
.
IKAP_ACT_CHANGE
,
ipdst
=
ipdst
)
def
broadcastTime
(
self
):
log
.
debug
(
"Broadcasting Time..."
)
self
.
sendCommand
(
"SETTIME"
,
arg
=
struct
.
pack
(
"<L"
,
int
(
time
.
time
())),
act
=
C
.
IKAP_ACT_BOARD
,
ctx
=
C
.
IKAP_CTX_SYSTEM
,
msgtype
=
C
.
IKAP_MSG_ACTION
)
def
broadcastTime
(
self
,
ipdst
=
"255.255.255.255"
):
if
self
.
config
.
get
(
"general"
,
"timeserver"
)
.
lower
()
in
[
'yes'
,
'y'
,
'1'
,
'true'
,
'on'
]:
log
.
debug
(
"Broadcasting Time to "
+
str
(
ipdst
))
self
.
sendCommand
(
"SETTIME"
,
arg
=
struct
.
pack
(
"<L"
,
int
(
time
.
time
())),
act
=
C
.
IKAP_ACT_BOARD
,
ctx
=
C
.
IKAP_CTX_SYSTEM
,
msgtype
=
C
.
IKAP_MSG_ACTION
,
ipdst
=
ipdst
)
def
initializePlugins
(
self
):
...
...
@@ -2357,6 +2358,9 @@ class domotikaService(service.Service):
def
plugin_on_execute
(
cmd
):
self
.
executeAction
(
cmd
)
def
domika_on_broadcastTime
(
self
,
ipdst
=
"255.255.255.255"
):
self
.
broadcastTime
(
ipdst
)
def
domika_on_updateWebPort
(
self
,
src
,
host
,
webport
,
port
,
ptype
):
return
dmdb
.
updateWebPort
(
src
,
host
,
webport
)
...
...
This diff is collapsed.
Click to expand it.
domotika/ikapserver.py
View file @
894ff02a
...
...
@@ -194,7 +194,8 @@ class DomIkaBaseProtocol(object):
if
dst
.
startswith
(
"DEBUG.INPUT.CHANGED.TO"
)
or
dst
.
startswith
(
"DEBUG.RELAY.CHANGED.TO"
):
arg
=
struct
.
unpack
(
'B'
,
arg
[
0
])[
0
]
elif
self
.
ikahdr
.
msgtype
==
C
.
IKAP_MSG_NOTIFY
and
dst
.
startswith
(
"BOOTED."
):
self
.
sendCommand
(
"SETTIME"
,
arg
=
struct
.
pack
(
"<L"
,
int
(
time
.
time
())),
act
=
C
.
IKAP_ACT_BOARD
,
ctx
=
C
.
IKAP_CTX_SYSTEM
,
msgtype
=
C
.
IKAP_MSG_ACTION
,
ipdst
=
host
)
self
.
core
.
broadcastTime
(
host
)
#self.sendCommand("SETTIME", arg=struct.pack("<L", int(time.time())), act=C.IKAP_ACT_BOARD, ctx=C.IKAP_CTX_SYSTEM, msgtype=C.IKAP_MSG_ACTION, ipdst=host)
elif
self
.
ikahdr
.
msgtype
==
C
.
IKAP_MSG_NOTIFY
and
self
.
ikahdr
.
ctx
==
C
.
IKAP_CTX_SYSTEM
and
dst
==
'RELAY.AMPERE.LIMIT'
:
try
:
log
.
info
(
"Relay "
+
str
(
struct
.
unpack
(
"<B"
,
arg
[
1
])[
0
])
+
" has gone in overrun at "
+
str
(
float
(
struct
.
unpack
(
"<B"
,
arg
[
0
])[
0
])
/
10.0
)
+
" Ampere"
)
...
...
@@ -356,6 +357,8 @@ class DomIkaBaseProtocol(object):
self
.
core
.
manageIncomingPacket
(
self
.
ikahdr
,
src
,
dst
,
arg
,
host
,
port
,
ptype
,
argdict
,
data
)
else
:
log
.
error
(
"INVALID PACKET TIME FROM "
+
str
(
host
)
+
" - packet time: "
+
str
(
self
.
ikahdr
.
epoch
)
+
" now: "
+
str
(
time
.
time
()))
# XXX Set a min time between resend the time broadcasting to avoid DoS?
self
.
core
.
broadcastTime
(
host
)
self
.
invalidPacket
()
else
:
log
.
error
(
"INVALID PACKET (second check) FROM "
+
str
(
host
))
...
...
@@ -448,7 +451,8 @@ class DomIkaTCP(Int8StringReceiver, DomIkaBaseProtocol):
self
.
disconnected
=
False
self
.
sendCommand
(
"IOSTATUS.NOW"
,
arg
=
C
.
IKAP_BROADCAST
,
act
=
C
.
IKAP_ACT_BOARD
,
ctx
=
C
.
IKAP_CTX_SYSTEM
,
msgtype
=
C
.
IKAP_MSG_REQUESTCONF
)
self
.
sendCommand
(
"SETTIME"
,
arg
=
struct
.
pack
(
"<L"
,
int
(
time
.
time
())),
act
=
C
.
IKAP_ACT_BOARD
,
ctx
=
C
.
IKAP_CTX_SYSTEM
,
msgtype
=
C
.
IKAP_MSG_ACTION
)
#self.sendCommand("SETTIME", arg=struct.pack("<L", int(time.time())), act=C.IKAP_ACT_BOARD, ctx=C.IKAP_CTX_SYSTEM, msgtype=C.IKAP_MSG_ACTION)
self
.
core
.
broadcastTime
()
def
invalidPacket
(
self
):
try
:
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment