Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Penguidom
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domotika
Penguidom
Commits
cafdb270
Commit
cafdb270
authored
Jan 05, 2018
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add base files for ikap protocol
parent
abc27238
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
949 additions
and
0 deletions
+949
-0
.gitignore
.gitignore
+15
-0
clean.sh
clean.sh
+27
-0
penguidomd.conf
conf/defaults/penguidomd.conf
+159
-0
init.sh
init.sh
+51
-0
ikap.py
penguidom/ikap.py
+425
-0
penguidom.py
penguidom/penguidom.py
+114
-0
__init__.py
penguidom/singleton/__init__.py
+23
-0
penguidomd
penguidomd
+135
-0
No files found.
.gitignore
0 → 100644
View file @
cafdb270
*.py[cod]
# C extensions
*.so
# Installer logs
pip-log.txt
*.log
conf/*.conf
ssl/*.key
logs/*
run/*
clean.sh
0 → 100755
View file @
cafdb270
#!/bin/bash
###########################################################################
# Copyright (c) 2018- Franco (nextime) Lanza <franco@unixmedia.it>
#
# Penguidom System Controller Daemon "penguidomd"
#
# This file is part of penguidomd.
#
# penguidomd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
rm
-f
`
find
.
-name
'*.pyc'
`
rm
-f
`
find
.
-name
'*~'
`
rm
-f
log/
*
.log
rm
-f
run/
*
.pid
conf/defaults/penguidomd.conf
0 → 100644
View file @
cafdb270
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
Copyright
(
c
)
2011
-
2014
Unixmedia
S
.
r
.
l
. <
info
@
unixmedia
.
it
>
;
Copyright
(
c
)
2011
-
2014
Franco
(
nextime
)
Lanza
<
franco
@
unixmedia
.
it
>
;
;
Domotika
System
Controller
Daemon
"domotikad"
[
http
://
trac
.
unixmedia
.
it
]
;
;
This
file
is
part
of
domotikad
.
;
;
domotikad
is
free
software
:
you
can
redistribute
it
and
/
or
modify
;
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
;
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
; (
at
your
option
)
any
later
version
.
;
;
This
program
is
distributed
in
the
hope
that
it
will
be
useful
,
;
but
WITHOUT
ANY
WARRANTY
;
without
even
the
implied
warranty
of
;
MERCHANTABILITY
or
FITNESS
FOR
A
PARTICULAR
PURPOSE
.
See
the
;
GNU
General
Public
License
for
more
details
.
;
;
You
should
have
received
a
copy
of
the
GNU
General
Public
License
;
along
with
this
program
.
If
not
,
see
<
http
://
www
.
gnu
.
org
/
licenses
/>.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[
general
]
loglevel
:
info
timeserver
:
yes
timeinterval
:
480
action_status_timer
:
2
remove_old_status
:
1800
autodetect
:
no
boards_syspwd
:
domotika
devices_admpwd
:
domotika
notify_expiretime
:
604800
language
:
it
[
geo
]
latitude
:
45
.
5967710
;
milan
->
45
.
4636889
longitude
:
8
.
7547400
;
milan
->
9
.
1881408
elevation
:
205
.
000000
;
milan
->
122
.
246513
location
:
Lonate
Pozzolo
,
it
openweathermap_appid
:
7
c9892bf8419193b5ea234f5cf6ad87d
[
ikapserver
]
enable
=
yes
interface
:
0
.
0
.
0
.
0
ethdev
:
eth0
port
:
6654
notifyport
:
6654
tcpenable
:
yes
tcpport
:
6654
tcpinterface
:
127
.
0
.
0
.
1
loglevel
:
error
timeupdates
:
1
rollingupdates
:
yes
rollinnum
:
5
timeoffline
:
15
timecheckoffline
:
5
[
proxy
]
loglevel
:
info
localproxypaths
:
phpmyadmin
,
domotika
,
admin
,
daemons
,
plugins
localproxyhosts
:
none
localproxypathsnologin
:
none
localproxyhostsnologin
:
none
localproxyport
:
80
[
protocol
]
loglevel
:
info
timecheck
:
yes
tollerance
:
10
netpwd
:
[
web
]
enable
:
yes
enableusergui
:
yes
enablesqlgui
:
yes
enablemysqlgui
:
yes
enableajaxgui
:
yes
enablerestgui
:
yes
enablemediagui
:
yes
logintheme
:
theme_dmblack
interface
:
0
.
0
.
0
.
0
sslport
:
443
port
:
81
defaultpath
: /
lowp
/
home
nologinpaths
:
resources
/
js
privkey
:
ssl
/
privkey
.
key
cacert
:
ssl
/
cacert
.
crt
loglevel
:
info
nologindefaultuser
:
guest
nologindefaultpass
:
guest
nologinips
:
none
cookie_aeskey
:
CHANGE_ME_PLEASE
[
media
]
loglevel
:
info
localtranscode
:
15
local_only
:
yes
transcode
:
ffmpeg
,
vlc
transcode_h264
:
vlc
transcode_webm
:
ffmpeg
transcode_raw
:
ffmpeg
[
upnp
]
enable
:
yes
ethdev
:
eth0
loglevel
:
info
[
database
]
loglevel
:
info
dbtype
:
mysql
dbhost
:
localhost
dmdbname
:
domotika
dbuser
:
domotika
dbpass
:
dmdbpwdmsql
[
smtp
]
enable
:
yes
interface
:
127
.
0
.
0
.
1
port
:
27
loglevel
:
info
[
asterisk
]
loglevel
:
info
manager_enable
:
yes
manager_ip
:
127
.
0
.
0
.
1
manager_port
:
5038
manager_user
:
domotika
manager_pass
:
dmastpwd
fagi_enable
:
yes
fagi_timeout
:
50
fagi_iface
:
127
.
0
.
0
.
1
fagi_port
:
4573
sip_localnet
:
192
.
168
.
0
.
0
/
16
sip_externaddr
:
sip_externhost
:
[
voiceui
]
loglevel
:
debug
triggerword
:
domotica
stopword
:
basta
cosi
domotica
grazie
stopcommand
:
silenzio
domotica
useoutput
:
no
[
dns
]
ns1
:
8
.
8
.
8
.
8
ns2
:
8
.
8
.
9
.
9
host
:
q
.
unixmedia
.
net
ip
:
auto
[
messenger
]
app_secret
:
verify_token
:
page_token
:
auth_host
:
https
://[
YOURHOST
]/
botauth
/
messenger
/
auth_img
:
https
://[
YOURHOST
]/
img
/
logo_login
.
png
auth_title
:
Nexlab
'
s
domotika
init.sh
View file @
cafdb270
#!/bin/bash
###########################################################################
# Copyright (c) 2011-2014 Unixmedia S.r.l. <info@unixmedia.it>
# Copyright (c) 2011-2014 Franco (nextime) Lanza <franco@unixmedia.it>
#
# Domotika System Controller Daemon "domotikad" [http://trac.unixmedia.it]
#
# This file is part of domotikad.
#
# domotikad is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
### BEGIN INIT INFO
# Provides: domotikad
# Required-Start: $syslog $remote_fs mysql
# Required-Stop: $syslog $remote_fs
# X-Interactive: yes
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop Domotika
# Description: Domotika is an home automation system
### END INIT INFO
#if [ -f /usr/lib/bindhack.so ] ; then
# export LD_PRELOAD=/usr/lib/bindhack.so
# export BIND_SRC=192.168.181.1
#fi
cd
/home/domotika
./domotikad
$@
if
[
x
"
$1
"
=
x
"stop"
]
;
then
chk
=
$(
pgrep
"domotikad"
)
if
[
x
"
$chk
"
!=
x
""
]
;
then
kill
-9
$chk
>
/dev/null 2>&1
fi
fi
exit
0
penguidom/ikap.py
0 → 100644
View file @
cafdb270
This diff is collapsed.
Click to expand it.
penguidom/penguidom.py
View file @
cafdb270
###########################################################################
# Copyright (c) 2018- Franco (nextime) Lanza <franco@unixmedia.it>
#
# Penguidom System Controller Daemon "penguidomd"
#
# This file is part of penguidomd.
#
# penguidomd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
twisted.application
import
service
from
twisted.internet
import
defer
,
reactor
,
task
,
protocol
,
threads
from
nexlibs.utils.genutils
import
configFile
,
FakeObject
,
ConvenienceCaller
from
nexlibs.utils
import
genutils
import
logging
,
sys
,
os
import
subprocess
import
time
,
copy
from
twisted.web
import
microdom
as
xml
from
nexlibs.utils
import
webutils
as
wu
from
dmlib
import
constants
as
C
import
time
from
txscheduling
import
task
as
txcron
from
txscheduling.cron
import
CronSchedule
,
parseCronLine
from
txscheduling.interfaces
import
ISchedule
from
netifaces
import
interfaces
,
ifaddresses
,
AF_INET
import
struct
from
dmlib
import
dmdomain
from
singleton
import
Singleton
import
ikap
try
:
import
hashlib
md5
=
hashlib
md5
.
new
=
hashlib
.
md5
sha1
=
hashlib
.
sha1
except
:
import
md5
import
sha1
ALLIP
=
C
.
IKAP_BROADCAST
ACTION_STATUS
=
{}
log
=
logging
.
getLogger
(
'Core'
)
class
penguidomService
(
service
.
Service
):
initialized
=
False
udp
=
False
tcp
=
False
def
__init__
(
self
,
*
args
,
**
kwargs
):
log
.
info
(
'Initializing Core'
)
self
.
curdir
=
kwargs
[
'curdir'
]
self
.
config
=
kwargs
[
'config'
]
sys
.
path
.
append
(
self
.
curdir
+
"/penguidom"
)
log
.
debug
(
'Current dir: '
+
self
.
curdir
)
if
self
.
parent
:
self
.
parent
.
__new__
(
self
.
parent
,
self
,
*
args
)
def
_callback
(
self
,
who
,
cmd
,
*
args
,
**
kwargs
):
"""
The callback that try to find an appropriate method exported
to a higher level object by the ConvenienceCaller metaclass.
This isn't intended to be called by the user directly, instead pass it
to the instance of the higher level object initialization or by
setting it using the abstraction of the ConvenienceCaller metaclass
"""
try
:
f
=
getattr
(
self
,
who
+
'_on_'
+
cmd
)
if
f
and
callable
(
f
):
return
f
except
:
raise
AttributeError
(
" "
.
join
([
cmd
,
'doesn
\'
t exists'
]))
def
isStarted
(
self
):
log
.
debug
(
"isStarted() called"
)
self
.
isConfigured
()
def
isConfigured
(
self
):
self
.
initialized
=
True
log
.
debug
(
"isConfigured() called"
)
def
getIkapUDP
(
self
):
caller
=
ConvenienceCaller
(
lambda
c
:
self
.
_callback
(
'ikap'
,
c
))
self
.
udp
=
ikap
.
DomIkaUDP
(
caller
)
return
self
.
udp
def
getIkapTCP
(
self
):
caller
=
ConvenienceCaller
(
lambda
c
:
self
.
_callback
(
'ikap'
,
c
))
self
.
tcp
=
ikap
.
DomIkaServerFactory
(
caller
)
return
self
.
tcp
penguidom/singleton/__init__.py
0 → 100644
View file @
cafdb270
###########################################################################
# Copyright (c) 2018- Franco (nextime) Lanza <franco@unixmedia.it>
#
# Penguidom System Controller Daemon "penguidomd"
#
# This file is part of penguidomd.
#
# penguidomd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
nexlibs.singleton
import
*
penguidomd
View file @
cafdb270
#!/usr/bin/env python
###########################################################################
# Copyright (c) 2018- Franco (nextime) Lanza <franco@unixmedia.it>
#
# Penguidom System Controller Daemon "penguidomd"
#
# This file is part of penguidomd.
#
# penguidomd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
twisted.internet
import
epollreactor
epollreactor
.
install
()
from
twisted.internet
import
reactor
,
ssl
,
protocol
,
endpoints
from
twisted.application
import
service
,
internet
,
app
,
reactors
from
twisted.web
import
server
import
logging
,
time
,
sys
,
os
from
nexlibs.daemonizer
import
Daemonizer
from
penguidom
import
penguidom
from
nexlibs.utils.genutils
import
configFile
from
logging
import
handlers
as
loghandlers
try
:
import
setproctitle
setproctitle
.
setproctitle
(
'penguidomd'
)
print
'Setting process title to'
,
sys
.
argv
[
0
]
except
:
pass
loglevels
=
{
'info'
:
logging
.
INFO
,
'warning'
:
logging
.
WARNING
,
'error'
:
logging
.
ERROR
,
'critical'
:
logging
.
CRITICAL
,
'debug'
:
logging
.
DEBUG
}
#LOGLEN=104857600 # 100 mega
#LOGLEN=10485760 # 10 mega
LOGLEN
=
26214400
# 25 mega
class
penguidomDaemon
(
Daemonizer
):
def
__init__
(
self
):
self
.
curdir
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
log
.
debug
(
"Reading daemon Config file"
)
self
.
daemoncfg
=
configFile
(
self
.
curdir
+
'/conf/penguidomd.conf'
)
self
.
daemoncfg
.
readConfig
()
log
.
debug
(
"Daemonizing process"
)
Daemonizer
.
__init__
(
self
,
self
.
curdir
+
'/run/penguidom.pid'
)
def
main_loop
(
self
):
log
.
debug
(
"Main loop called"
)
application
=
service
.
Application
(
"penguidomd"
)
PENGUIDOMServerService
=
penguidom
.
penguidomService
(
'penguidomd'
,
curdir
=
self
.
curdir
,
config
=
self
.
daemoncfg
)
serviceCollection
=
service
.
IServiceCollection
(
application
)
PENGUIDOMServerService
.
setServiceParent
(
serviceCollection
)
IkapServerUDP
=
PENGUIDOMServerService
.
getIkapUDP
()
IkapServerTCP
=
PENGUIDOMServerService
.
getIkapTCP
()
if
str
(
self
.
daemoncfg
.
get
(
'ikap'
,
'enable'
))
.
lower
()
in
[
'yes'
,
'1'
,
'y'
,
'true'
]:
reactor
.
listenUDP
(
int
(
self
.
daemoncfg
.
get
(
'ikap'
,
'port'
)),
IkapServerUDP
,
interface
=
str
(
self
.
daemoncfg
.
get
(
'ikap'
,
'interface'
)))
if
self
.
daemoncfg
.
get
(
'ikap'
,
'port'
)
!=
self
.
daemoncfg
.
get
(
'ikap'
,
'notifyport'
):
reactor
.
listenUDP
(
int
(
self
.
daemoncfg
.
get
(
'ikap'
,
'notifyport'
)),
IkapServerUDP
,
interface
=
str
(
self
.
daemoncfg
.
get
(
'ikap'
,
'interface'
)))
if
str
(
self
.
daemoncfg
.
get
(
'ikap'
,
'tcpenable'
))
.
lower
()
in
[
'yes'
,
'1'
,
'y'
,
'true'
]:
reactor
.
listenTCP
(
int
(
self
.
daemoncfg
.
get
(
'ikap'
,
'tcpport'
)),
IkapServerTCP
,
interface
=
str
(
self
.
daemoncfg
.
get
(
'ikap'
,
'tcpinterface'
)))
log
.
debug
(
"Running reactor"
)
reactor
.
callWhenRunning
(
PENGUIDOMServerService
.
isStarted
)
reactor
.
run
()
if
__name__
==
"__main__"
:
# Starting all loggers
# file di log da 100 mega, per 5 rotazioni
formatter
=
logging
.
Formatter
(
'
%(asctime)
s =>
%(name)-12
s:
%(levelname)-8
s
%(message)
s'
)
logdict
=
{
"corelog"
:
{
"file"
:
"penguidom.log"
,
"name"
:[(
"Core"
,
"general"
)]},
"protocollog"
:
{
"file"
:
"ikap.log"
,
"name"
:
[(
"IKAProtocol"
,
"ikap"
),(
"IKAPServer"
,
"ikap"
),(
"DMDomain"
,
"ikap"
)]},
}
for
l
in
logdict
.
keys
():
logdict
[
l
][
"handler"
]
=
loghandlers
.
RotatingFileHandler
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
+
'/logs/'
+
logdict
[
l
][
"file"
],
'a'
,
LOGLEN
,
5
)
logdict
[
l
][
"handler"
]
.
setLevel
(
logging
.
DEBUG
)
logdict
[
l
][
"handler"
]
.
setFormatter
(
formatter
)
logging
.
basicConfig
()
log
=
logging
.
getLogger
(
'DaemonStarter'
)
log
.
addHandler
(
logdict
[
"corelog"
][
"handler"
])
log
.
setLevel
(
logging
.
INFO
)
curdir
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
daemoncfg
=
configFile
(
curdir
+
'/conf/penguidomd.conf'
)
daemoncfg
.
readConfig
()
for
l
in
logdict
.
keys
():
for
n
in
logdict
[
l
][
"name"
]:
lh
=
logging
.
getLogger
(
n
[
0
])
lh
.
setLevel
(
loglevels
[
daemoncfg
.
get
(
n
[
1
],
'loglevel'
)]
)
lh
.
addHandler
(
logdict
[
l
][
"handler"
]
)
logging
.
basicConfig
()
# staring the application
if
len
(
sys
.
argv
)
>
1
:
log
.
debug
(
"Starting daemon with option "
+
sys
.
argv
[
1
])
penguidomDaemon
()
.
process_command_line
(
sys
.
argv
)
else
:
print
'Please specify start, stop or debug option'
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