Ajout des script pour asterisk
This commit is contained in:
parent
e9bae60ef9
commit
124d4a83e1
12 changed files with 286 additions and 0 deletions
60
sip/asterisk_reload_conf.py
Executable file
60
sip/asterisk_reload_conf.py
Executable file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import socket
|
||||
import time
|
||||
import sys
|
||||
|
||||
timeout=10
|
||||
server="asterisk.adm.crans.org"
|
||||
port=5038
|
||||
|
||||
user="django"
|
||||
password="HLWkzyITZAmBk"
|
||||
|
||||
reload_srv={
|
||||
'sip':['chan_sip'],
|
||||
'voicemail':['app_voicemail'],
|
||||
'dialplan':['pbx_config'],
|
||||
'all':['chan_sip','app_voicemail','pbx_config'],
|
||||
}
|
||||
|
||||
def reload_config(config):
|
||||
if not config in reload_srv.keys():
|
||||
print >> sys.stderr, "Reload config from : \n * %s" % ('\n * '.join( reload_srv.keys()))
|
||||
return
|
||||
sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
|
||||
def send(str):
|
||||
msg='%s\r\n' % (str)
|
||||
sock.send (msg)
|
||||
sock.settimeout(timeout)
|
||||
sock.connect ( ( server, port ) )
|
||||
send ( 'ACTION: LOGIN')
|
||||
send ( 'USERNAME: %s' % user)
|
||||
send ( 'SECRET: %s' % password)
|
||||
send ( '')
|
||||
for module in reload_srv[config]:
|
||||
send ( 'ACTION: RELOAD')
|
||||
send ( 'MODULE: %s' % module)
|
||||
send ( 'ActionID: %s' % time.time())
|
||||
send ( '')
|
||||
send ( 'ACTION: LOGOFF')
|
||||
send ( '')
|
||||
data=[]
|
||||
while True:
|
||||
data.extend(sock.recv( 4096 ).split('\r\n'))
|
||||
if data==['']:
|
||||
sock.close()
|
||||
return
|
||||
while len(data)>0:
|
||||
del data[0]
|
||||
|
||||
sock.close()
|
||||
|
||||
|
||||
if __name__ == '__main__' :
|
||||
if len(sys.argv)<2:
|
||||
print >> sys.stderr, "Usage %s [%s]" %(sys.argv[0],'|'.join(reload_srv.keys()))
|
||||
print >> sys.stderr, "Reload config from : \n * %s" % ('\n * '.join(reload_srv.keys()))
|
||||
exit(1)
|
||||
reload_config(sys.argv[1])
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue