def main_func(): try: opts, args = getopt.getopt(sys.argv[1:], 'fl:p:n:L:') except getopt.GetoptError: print( 'usage: b2bua.py [-l addr] [-p port] [-n addr] [-f] [-L logfile]') sys.exit(1) laddr = None lport = None logfile = '/var/log/sippy.log' global_config = {'nh_addr': ['192.168.0.102', 5060]} foreground = False for o, a in opts: if o == '-f': foreground = True continue if o == '-l': laddr = a continue if o == '-p': lport = int(a) continue if o == '-L': logfile = a if o == '-n': if a.startswith('['): parts = a.split(']', 1) global_config['nh_addr'] = [parts[0] + ']', 5060] parts = parts[1].split(':', 1) else: parts = a.split(':', 1) global_config['nh_addr'] = [parts[0], 5060] if len(parts) == 2: global_config['nh_addr'][1] = int(parts[1]) continue global_config['nh_addr'] = tuple(global_config['nh_addr']) if not foreground: daemonize(logfile) SipConf.my_uaname = 'Sippy B2BUA (Simple)' SipConf.allow_formats = (0, 8, 18, 100, 101) global_config['_sip_address'] = SipConf.my_address global_config['_sip_port'] = SipConf.my_port if laddr != None: global_config['_sip_address'] = laddr if lport != None: global_config['_sip_port'] = lport global_config['_sip_logger'] = SipLogger('b2bua') cmap = CallMap(global_config) global_config['_sip_tm'] = SipTransactionManager(global_config, cmap.recvRequest) reactor.run(installSignalHandlers=True)
def main_func(): global_config = MyConfigParser() global_config['digest_auth'] = True global_config['start_acct_enable'] = False global_config['keepalive_ans'] = 0 global_config['keepalive_orig'] = 0 global_config['auth_enable'] = True global_config['acct_enable'] = True global_config['_pass_headers'] = [] global_config['_orig_argv'] = sys.argv[:] global_config['_orig_cwd'] = os.getcwd() try: opts, args = getopt.getopt( sys.argv[1:], 'fDl:p:d:P:L:s:a:t:T:k:m:A:ur:F:R:h:c:M:HC:W:', global_config.get_longopts()) except getopt.GetoptError: usage(global_config) global_config['foreground'] = False global_config['pidfile'] = '/var/run/b2bua.pid' global_config['logfile'] = '/var/log/b2bua.log' global_config['b2bua_socket'] = '/var/run/b2bua.sock' global_config['_sip_address'] = SipConf.my_address global_config['_sip_port'] = SipConf.my_port global_config['_my_pid'] = os.getpid() rtp_proxy_clients = [] writeconf = None for o, a in opts: if o == '-f': global_config['foreground'] = True continue if o == '-l': global_config.check_and_set('sip_address', a) continue if o == '-p': global_config.check_and_set('sip_port', a) continue if o == '-P': global_config.check_and_set('pidfile', a) continue if o == '-L': global_config.check_and_set('logfile', a) continue if o == '-s': global_config.check_and_set('static_route', a) continue if o == '-a': global_config.check_and_set('accept_ips', a) continue if o == '-D': global_config['digest_auth'] = False continue if o == '-A': acct_level = int(a.strip()) if acct_level == 0: global_config['acct_enable'] = False global_config['start_acct_enable'] = False elif acct_level == 1: global_config['acct_enable'] = True global_config['start_acct_enable'] = False elif acct_level == 2: global_config['acct_enable'] = True global_config['start_acct_enable'] = True else: sys.__stderr__.write( 'ERROR: -A argument not in the range 0-2\n') usage(global_config, True) continue if o == '-t': global_config.check_and_set('static_tr_in', a) continue if o == '-T': global_config.check_and_set('static_tr_out', a) continue if o == '-k': ka_level = int(a.strip()) if ka_level == 0: pass elif ka_level == 1: global_config['keepalive_ans'] = 32 elif ka_level == 2: global_config['keepalive_orig'] = 32 elif ka_level == 3: global_config['keepalive_ans'] = 32 global_config['keepalive_orig'] = 32 else: sys.__stderr__.write( 'ERROR: -k argument not in the range 0-3\n') usage(global_config, True) if o == '-m': global_config.check_and_set('max_credit_time', a) continue if o == '-u': global_config['auth_enable'] = False continue if o == '-r': global_config.check_and_set('rtp_proxy_client', a) continue if o == '-F': global_config.check_and_set('allowed_pts', a) continue if o == '-R': global_config.check_and_set('radiusclient.conf', a) continue if o == '-h': for a in a.split(','): global_config.check_and_set('pass_header', a) continue if o == '-c': global_config.check_and_set('b2bua_socket', a) continue if o == '-M': global_config.check_and_set('max_radiusclients', a) continue if o == '-H': global_config['hide_call_id'] = True continue if o in ('-C', '--config'): global_config.read(a.strip()) continue if o.startswith('--'): global_config.check_and_set(o[2:], a) continue if o == '-W': writeconf = a.strip() continue if '_rtp_proxy_clients' in global_config: for a in global_config['_rtp_proxy_clients']: rtp_proxy_clients.append(a) if 'static_route' in global_config: global_config['_static_route'] = B2BRoute( global_config['static_route']) elif not global_config['auth_enable']: sys.__stderr__.write( 'ERROR: static route should be specified when Radius auth is disabled\n' ) usage(global_config, True) if writeconf != None: global_config.write(open(writeconf, 'w')) if not global_config['foreground']: daemonize(logfile=global_config['logfile']) global_config['_sip_logger'] = SipLogger('b2bua') if len(rtp_proxy_clients) > 0: global_config['_rtp_proxy_clients'] = [] for address in rtp_proxy_clients: global_config['_rtp_proxy_clients'].append( Rtp_proxy_client(global_config, spath=address)) if global_config['auth_enable'] or global_config['acct_enable']: global_config['_radius_client'] = RadiusAuthorisation(global_config) global_config['_uaname'] = 'Sippy B2BUA (RADIUS)' global_config['_cmap'] = CallMap(global_config) if 'sip_proxy' in global_config: host_port = global_config['sip_proxy'].split(':', 1) if len(host_port) == 1: global_config['_sip_proxy'] = (host_port[0], 5060) else: global_config['_sip_proxy'] = (host_port[0], int(host_port[1])) global_config['_cmap'].proxy = StatefulProxy( global_config, global_config['_sip_proxy']) if global_config.getdefault('xmpp_b2bua_id', None) != None: global_config['_xmpp_mode'] = True global_config['_sip_tm'] = SipTransactionManager( global_config, global_config['_cmap'].recvRequest) global_config['_sip_tm'].nat_traversal = global_config.getdefault( 'nat_traversal', False) cmdfile = global_config['b2bua_socket'] if cmdfile.startswith('unix:'): cmdfile = cmdfile[5:] cli_server = CLIConnectionManager(global_config['_cmap'].recvCommand, cmdfile) if not global_config['foreground']: open(global_config['pidfile'], 'w').write(str(os.getpid()) + '\n') Signal(SIGUSR1, reopen, SIGUSR1, global_config['logfile']) ED2.loop()
if o == '-n': nh_address4 = a.split(':', 1) nh_address4[1] = int(nh_address4[1]) tcfg.nh_address4 = tuple(nh_address4) continue if o == '-N': nh_address6 = a.rsplit(':', 1) nh_address6[1] = int(nh_address6[1]) tcfg.nh_address6 = tuple(nh_address6) continue if o == '-w': pre_wait = float(a) continue if len(ttype) > 0: tcfg.ttype = tuple(ttype) tcfg.body = MsgBody(body_txt) tcfg.body.parse() sl = SipLogger('alice_ua') global_config['_sip_logger'] = sl from a_test1 import a_test if pre_wait != None: sleep(pre_wait) acore = a_test(tcfg) ED2.loop() sys.exit(acore.rval)
opts, args = getopt.getopt(sys.argv[1:], 'p:l:P:T:') except getopt.GetoptError: usage(global_config) portrange = PortRange('12000-15000') for o, a in opts: if o == '-p': portrange = PortRange(a.strip()) continue if o == '-l': global_config['_sip_address'] = a.strip() continue if o == '-P': global_config['_sip_port'] = int(a) continue if o == '-T': test_timeout = int(a) continue bodys = [MsgBody(x) for x in BODIES_ALL] for body in bodys: body.parse() sl = SipLogger('bob_ua') global_config['_sip_logger'] = sl from b_test1 import b_test bcore = b_test(global_config, tuple(bodys), portrange, test_timeout) reactor.run(installSignalHandlers=True) sys.exit(bcore.rval)
os.dup2(fd, sys.__stderr__.fileno()) def terminate(): ED2.breakLoop() if __name__ == '__main__': global_config = {} try: opts, args = getopt.getopt(sys.argv[1:], 'fP:c:L:s:o:dD') except getopt.GetoptError: usage() sip_logger = SipLogger('rtp_cluster') sip_logger.write('Starting up...') foreground = False dry_run = False debug_threads = False pidfile = '/var/run/rtp_cluster.pid' logfile = '/var/log/rtp_cluster.log' csockfile = '/var/run/rtp_cluster.sock' global_config['conffile'] = '/usr/local/etc/rtp_cluster.xml' global_config['_sip_address'] = MyAddress() for o, a in opts: if o == '-f': foreground = True continue
os._exit(0) # Create new session os.setsid() if os.fork() != 0: os._exit(0) os.chdir('/') fd = os.open('/dev/null', os.O_RDONLY) os.dup2(fd, sys.__stdin__.fileno()) os.close(fd) fd = os.open(global_config['logfile'], os.O_WRONLY | os.O_CREAT | os.O_APPEND) os.dup2(fd, sys.__stdout__.fileno()) os.dup2(fd, sys.__stderr__.fileno()) os.close(fd) global_config['_sip_logger'] = SipLogger('b2bua') if len(rtp_proxy_clients) > 0: global_config['_rtp_proxy_clients'] = [] for address in rtp_proxy_clients: global_config['_rtp_proxy_clients'].append( Rtp_proxy_client(global_config, address)) if global_config['auth_enable'] or global_config['acct_enable']: global_config['_radius_client'] = RadiusAuthorisation(global_config) SipConf.my_uaname = 'Sippy B2BUA (RADIUS)' global_config['_cmap'] = CallMap(global_config) global_config['_sip_tm'] = SipTransactionManager( global_config, global_config['_cmap'].recvRequest)
xml += ' </rtp_cluster>\n\n' xml += '</rtp_cluster_config>\n' return xml if __name__ == '__main__': import sys, traceback sys.path.append('sippy') from sippy.SipLogger import SipLogger global_config = {} global_config['_sip_logger'] = SipLogger('Rtp_cluster_config::selftest') try: global_config['_sip_logger'].write('Reading config...') f = open('rtp_cluster.xml') config = read_cluster_config(global_config, f.read(), True) global_config['_sip_logger'].write('Generating config...') config = gen_cluster_config(config) global_config['_sip_logger'].write('Reading generated config...') config = read_cluster_config(global_config, config, True) except Exception, detail: global_config['_sip_logger'].write('error: %s' % detail) traceback.print_exc(file=sys.stderr)
authpass = a elif o == '-i': pidfile = a if not foreground: daemonize(logfile) if logfile == '-': lfile = sys.stdout else: lfile = open(logfile, 'a') if pidfile != None: open(pidfile, 'w').write('%d' % os.getpid()) global_config['_sip_address'] = SipConf.my_address global_config['_sip_port'] = SipConf.my_port if laddr != None: global_config['_sip_address'] = laddr if lport != None: global_config['_sip_port'] = lport global_config['_sip_logger'] = SipLogger('pel_collect') iua = IoTUAS(global_config, authname, authpass) #pio = PELIO(lfile) #if sdev != None: # pio.sdev = sdev #pio.sstart_cb = pua.sess_started #pio.send_cb = pua.sess_ended #pio.start() ED2.loop()
def LogSignal(sip_logger, signum, signal_cb, *cb_params): sip_logger.write('Registering signal %d to handler %s' % (signum, str(signal_cb))) return Signal(signum, log_signal, signum, sip_logger, signal_cb, cb_params) if __name__ == '__main__': from signal import SIGHUP, SIGURG, SIGTERM from os import kill, getpid def test(arguments): arguments['test'] = not arguments['test'] ED2.breakLoop() arguments = {'test':False} s = Signal(SIGURG, test, arguments) kill(getpid(), SIGURG) ED2.loop() assert(arguments['test']) s.cancel() Signal(SIGHUP, test, arguments) kill(getpid(), SIGURG) kill(getpid(), SIGHUP) ED2.loop() assert(not arguments['test']) from sippy.SipLogger import SipLogger sip_logger = SipLogger('Signal::selftest') LogSignal(sip_logger, SIGTERM, test, arguments) kill(getpid(), SIGTERM) ED2.loop() assert(arguments['test'])
if not foreground: daemonize(logfile) if logfile == '-': lfile = sys.stdout else: lfile = open(logfile, 'a') if pidfile != None: open(pidfile, 'w').write('%d' % os.getpid()) global_config['_sip_address'] = SipConf.my_address global_config['_sip_port'] = SipConf.my_port if laddr != None: global_config['_sip_address'] = laddr if lport != None: global_config['_sip_port'] = lport global_config['_sip_logger'] = SipLogger('pel_read') pua = IoTUAC(global_config) if authname != None: pua.authname = authname pua.authpass = authpass pio = PELIO(lfile) if sdev != None: pio.sdev = sdev pio.sstart_cb = pua.sess_started pio.send_cb = pua.sess_ended pio.start() ED2.loop()
def main_func(): try: opts, args = getopt.getopt(sys.argv[1:], 'fl:p:n:L:') except getopt.GetoptError: print( 'usage: b2bua.py [-l addr] [-p port] [-n addr] [-f] [-L logfile]') sys.exit(1) laddr = None lport = None logfile = '/var/log/sippy.log' global_config = {'nh_addr': ['127.0.0.1', 5060]} foreground = False for o, a in opts: if o == '-f': foreground = True continue if o == '-l': laddr = a continue if o == '-p': lport = int(a) continue if o == '-L': logfile = a if o == '-n': if a.startswith('['): parts = a.split(']', 1) global_config['nh_addr'] = [parts[0] + ']', 5060] parts = parts[1].split(':', 1) else: parts = a.split(':', 1) global_config['nh_addr'] = [parts[0], 5060] if len(parts) == 2: global_config['nh_addr'][1] = int(parts[1]) continue global_config['nh_addr'] = tuple(global_config['nh_addr']) if not foreground: daemonize(logfile) SipConf.my_uaname = 'vos 2.1.10' SipConf.allow_formats = (0, 8, 18, 100, 101) global_config['_sip_address'] = SipConf.my_address global_config['_sip_port'] = SipConf.my_port if laddr != None: global_config['_sip_address'] = laddr if lport != None: global_config['_sip_port'] = lport global_config['_sip_logger'] = SipLogger('b2bua') # global_config['_invite_session'] = FuturesSession(max_workers=200) global_config['_request_session'] = FuturesSession(max_workers=200) global_config['_sip_logger'].write(global_config['_sip_address'], ":", global_config['_sip_port']) cmap = CallMap(global_config) global_config['_sip_tm'] = SipTransactionManager(global_config, cmap.recvRequest) ED2.loop()