Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
piphone-sip
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
piphone
piphone-sip
Commits
afc5535f
Commit
afc5535f
authored
May 04, 2016
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doing a lot of preconfiguration at module loading
parent
871154d1
Pipeline
#26
skipped
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
27 deletions
+42
-27
__init__.py
__init__.py
+0
-0
app.py
app.py
+29
-27
config.ini
config.ini
+13
-0
No files found.
__init__.py
0 → 100644
View file @
afc5535f
app.py
View file @
afc5535f
...
...
@@ -21,30 +21,50 @@ from bottle import request, abort, Bottle, JSONPlugin
from
bottle_sqlite
import
SQLitePlugin
from
daemonize
import
Daemonize
arg_parser
=
argparse
.
ArgumentParser
(
description
=
'Manage the SIP Backend for the piphone'
)
config
=
configparser
.
ConfigParser
()
arg_parser
.
add_argument
(
'-c'
,
'--config'
,
help
=
"Config file"
)
arg_parser
.
parse_args
()
try
:
logging
.
debug
(
"Let's use {} as a config file"
.
config
(
arg_parser
.
config
,))
config
.
read
(
arg_parser
.
config
)
except
AttributeError
:
try
:
if
os
.
path
.
isfile
(
'config.ini'
):
logging
.
debug
(
"Let's use config.ini as a config file"
)
config
.
read
(
'config.ini'
)
elif
os
.
path
.
isfile
(
'/etc/piphone/config.ini'
):
logging
.
debug
(
"Let's use /etc/iphone/config.ini as a config file"
)
config
.
read
(
'/etc/piphone/config.ini'
)
else
:
raise
Exception
(
"No configuration file found (tried ./config.ini and /etc/piphone/config.ini"
)
except
Exception
as
e
:
arg_parser
.
print_help
()
sys
.
exit
(
1
)
application
=
app
=
Bottle
(
autojson
=
False
)
app
.
install
(
SQLitePlugin
(
dbfile
=
'call.db'
))
app
.
install
(
SQLitePlugin
(
dbfile
=
config
[
'piphone'
][
'db'
]
))
app
.
install
(
JSONPlugin
(
json_dumps
=
lambda
s
:
json
.
dumps
(
s
,
cls
=
PiphoneJSONEncoder
)))
threads
=
concurrent
.
futures
.
ThreadPoolExecutor
()
loop
=
asyncio
.
get_event_loop
()
db
=
sqlite3
.
connect
(
'call.db'
)
running
=
False
ws
=
None
debug
=
True
# Loggers
handler
=
logging
.
FileHandler
(
'app.log'
)
handler
=
logging
.
FileHandler
(
config
[
'piphone'
][
'log'
])
verbosity
=
getattr
(
logging
,
config
[
'piphone'
][
'verbosity'
].
upper
())
or
logging
.
DEBUG
phone_logger
=
logging
.
getLogger
(
'piphone'
)
phone_logger
.
addHandler
(
handler
)
phone_logger
.
setLevel
(
logging
.
DEBUG
)
phone_logger
.
setLevel
(
verbosity
)
ws_logger
=
logging
.
getLogger
(
'asterisk'
)
ws_logger
.
addHandler
(
handler
)
ws_logger
.
setLevel
(
logging
.
DEBUG
)
ws_logger
.
setLevel
(
verbosity
)
bottle_logger
=
logging
.
getLogger
(
'bottle'
)
bottle_logger
.
addHandler
(
handler
)
bottle_logger
.
setLevel
(
logging
.
DEBUG
)
bottle_logger
.
setLevel
(
verbosity
)
class
PiphoneJSONEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
obj
):
...
...
@@ -442,26 +462,8 @@ def originate(db, callid=None):
abort
(
400
,
"Missing or incorrect fields, the call cannot be processed"
)
if
__name__
==
'__main__'
:
arg_parser
=
argparse
.
ArgumentParser
(
description
=
'Manage the SIP Backend for the piphone'
)
arg_parser
.
add_argument
(
'-c'
,
'--config'
,
help
=
"Config file"
)
arg_parser
.
parse_args
()
try
:
logging
.
debug
(
"Let's use {} as a config file"
.
config
(
arg_parser
.
config
,))
config
.
read
(
arg_parser
.
config
)
except
AttributeError
:
try
:
if
os
.
path
.
isfile
(
'config.ini'
):
logging
.
debug
(
"Let's use config.ini as a config file"
)
config
.
read
(
'config.ini'
)
elif
os
.
path
.
isfile
(
'/etc/piphone/config.ini'
):
logging
.
debug
(
"Let's use /etc/iphone/config.ini as a config file"
)
config
.
read
(
'/etc/piphone/config.ini'
)
else
:
raise
Exception
(
"No configuration file found (tried ./config.ini and /etc/piphone/config.ini"
)
except
Exception
as
e
:
phone_logger
.
error
(
"Config file cannot be read"
)
arg_parser
.
print_help
()
sys
.
exit
(
1
)
db
=
sqlite3
.
connect
(
config
[
'piphone'
][
'db'
])
phone_logger
.
info
(
"Starting the piphone SIP backend"
)
try
:
start
()
except
:
...
...
config.ini
0 → 100644
View file @
afc5535f
[WebService]
base_url
=
ws://185.34.33.12:8088/ari/events
[asterisk]
server
=
'http://182.34.33.12:8088/ari/'
app
=
piphone
key
=
piphone
password
=
passpiphone
[piphone]
db
=
call.db
log
=
call.log
verbosity
=
debug
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