コード例 #1
0
ファイル: b2bua_radius.py プロジェクト: ttof80/b2bua
 def rDone(self, results):
     # Check that we got necessary result from Radius
     if len(results) != 2 or results[1] != 0:
         if isinstance(self.uaA.state, UasStateTrying):
             if self.challenge != None:
                 event = CCEventFail((401, 'Unauthorized'))
                 event.extra_header = self.challenge
             else:
                 event = CCEventFail((403, 'Auth Failed'))
             self.uaA.recvEvent(event)
             self.state = CCStateDead
         return
     if self.global_config['acct_enable']:
         self.acctA = RadiusAccounting(self.global_config, 'answer', \
           send_start = self.global_config['start_acct_enable'], lperiod = \
           self.global_config.getdefault('alive_acct_int', None))
         self.acctA.ms_precision = self.global_config.getdefault(
             'precise_acct', False)
         self.acctA.setParams(self.username, self.cli, self.cld, self.cGUID,
                              self.cId, self.remote_ip)
     else:
         self.acctA = FakeAccounting()
     # Check that uaA is still in a valid state, send acct stop
     if not isinstance(self.uaA.state, UasStateTrying):
         self.acctA.disc(self.uaA, MonoTime(), 'caller')
         return
     cli = [
         x[1][4:] for x in results[0]
         if x[0] == 'h323-ivr-in' and x[1].startswith('CLI:')
     ]
     if len(cli) > 0:
         self.cli = cli[0]
         if len(self.cli) == 0:
             self.cli = None
     caller_name = [
         x[1][5:] for x in results[0]
         if x[0] == 'h323-ivr-in' and x[1].startswith('CNAM:')
     ]
     if len(caller_name) > 0:
         self.caller_name = caller_name[0]
         if len(self.caller_name) == 0:
             self.caller_name = None
     credit_time = [x for x in results[0] if x[0] == 'h323-credit-time']
     if len(credit_time) > 0:
         credit_time = int(credit_time[0][1])
     else:
         credit_time = None
     if not '_static_route' in self.global_config:
         routing = [
             x for x in results[0]
             if x[0] == 'h323-ivr-in' and x[1].startswith('Routing:')
         ]
         if len(routing) == 0:
             self.uaA.recvEvent(
                 CCEventFail((500, 'Internal Server Error (2)')))
             self.state = CCStateDead
             return
         routing = [B2BRoute(x[1][8:]) for x in routing]
     else:
         routing = [
             self.global_config['_static_route'].getCopy(),
         ]
     rnum = 0
     for oroute in routing:
         rnum += 1
         max_credit_time = self.global_config.getdefault(
             'max_credit_time', None)
         oroute.customize(rnum, self.cld, self.cli, credit_time, self.pass_headers, \
           max_credit_time)
         if oroute.credit_time == 0 or oroute.expires == 0:
             continue
         self.routes.append(oroute)
         #print 'Got route:', oroute.hostport, oroute.cld
     if len(self.routes) == 0:
         self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (3)')))
         self.state = CCStateDead
         return
     self.state = CCStateARComplete
     self.placeOriginate(self.routes.pop(0))
コード例 #2
0
ファイル: b2bua_radius.py プロジェクト: radicaldrew/b2bua
 def rDone(self, results):
     # Check that we got necessary result from Radius
     if len(results) != 2 or results[1] != 0:
         if isinstance(self.uaA.state, UasStateTrying):
             if self.challenge != None:
                 event = CCEventFail((401, 'Unauthorized'))
                 event.extra_header = self.challenge
             else:
                 event = CCEventFail((403, 'Auth Failed'))
             self.uaA.recvEvent(event)
             self.state = CCStateDead
         return
     if self.global_config['acct_enable']:
         self.acctA = RadiusAccounting(self.global_config, 'answer', \
           send_start = self.global_config['start_acct_enable'], lperiod = \
           self.global_config.getdefault('alive_acct_int', None))
         self.acctA.ms_precision = self.global_config.getdefault('precise_acct', False)
         self.acctA.setParams(self.username, self.cli, self.cld, self.cGUID, self.cId, self.remote_ip)
     else:
         self.acctA = FakeAccounting()
     # Check that uaA is still in a valid state, send acct stop
     if not isinstance(self.uaA.state, UasStateTrying):
         self.acctA.disc(self.uaA, time(), 'caller')
         return
     cli = [x[1][4:] for x in results[0] if x[0] == 'h323-ivr-in' and x[1].startswith('CLI:')]
     if len(cli) > 0:
         self.cli = cli[0]
         if len(self.cli) == 0:
             self.cli = None
     caller_name = [x[1][5:] for x in results[0] if x[0] == 'h323-ivr-in' and x[1].startswith('CNAM:')]
     if len(caller_name) > 0:
         self.caller_name = caller_name[0]
         if len(self.caller_name) == 0:
             self.caller_name = None
     credit_time = [x for x in results[0] if x[0] == 'h323-credit-time']
     if len(credit_time) > 0:
         global_credit_time = int(credit_time[0][1])
     else:
         global_credit_time = None
     if not self.global_config.has_key('static_route'):
         routing = [x for x in results[0] if x[0] == 'h323-ivr-in' and x[1].startswith('Routing:')]
         if len(routing) == 0:
             self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (2)')))
             self.state = CCStateDead
             return
         routing = [x[1][8:].split(';') for x in routing]
     else:
         routing = [self.global_config['static_route'].split(';')]
     rnum = 0
     for route in routing:
         rnum += 1
         if route[0].find('@') != -1:
             cld, host = route[0].split('@', 1)
             if len(cld) == 0:
                 # Allow CLD to be forcefully removed by sending `Routing:@host' entry,
                 # as opposed to the Routing:host, which means that CLD should be obtained
                 # from the incoming call leg.
                 cld = None
         else:
             cld = self.cld
             host = route[0]
         credit_time = global_credit_time
         expires = None
         no_progress_expires = None
         forward_on_fail = False
         user = None
         passw = None
         cli = self.cli
         parameters = {}
         parameters['extra_headers'] = self.pass_headers[:]
         for a, v in [x.split('=', 1) for x in route[1:]]:
             if a == 'credit-time':
                 credit_time = int(v)
                 if credit_time < 0:
                     credit_time = None
             elif a == 'expires':
                 expires = int(v)
                 if expires < 0:
                     expires = None
             elif a == 'hs_scodes':
                 parameters['huntstop_scodes'] = tuple([int(x) for x in v.split(',') if len(x.strip()) > 0])
             elif a == 'np_expires':
                 no_progress_expires = int(v)
                 if no_progress_expires < 0:
                     no_progress_expires = None
             elif a == 'forward_on_fail':
                 forward_on_fail = True
             elif a == 'auth':
                 user, passw = v.split(':', 1)
             elif a == 'cli':
                 cli = v
                 if len(cli) == 0:
                     cli = None
             elif a == 'cnam':
                 caller_name = unquote(v)
                 if len(caller_name) == 0:
                     caller_name = None
                 parameters['caller_name'] = caller_name
             elif a == 'ash':
                 ash = SipHeader(unquote(v))
                 parameters['extra_headers'].append(ash)
             elif a == 'rtpp':
                 parameters['rtpp'] = (int(v) != 0)
             elif a == 'gt':
                 timeout, skip = v.split(',', 1)
                 parameters['group_timeout'] = (int(timeout), rnum + int(skip))
             elif a == 'op':
                 host_port = v.split(':', 1)
                 if len(host_port) == 1:
                     parameters['outbound_proxy'] = (v, 5060)
                 else:
                     parameters['outbound_proxy'] = (host_port[0], int(host_port[1]))
             else:
                 parameters[a] = v
         if self.global_config.has_key('max_credit_time'):
             if credit_time == None or credit_time > self.global_config['max_credit_time']:
                 credit_time = self.global_config['max_credit_time']
         if credit_time == 0 or expires == 0:
             continue
         self.routes.append((rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, \
           passw, cli, parameters))
         #print 'Got route:', host, cld
     if len(self.routes) == 0:
         self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (3)')))
         self.state = CCStateDead
         return
     self.state = CCStateARComplete
     self.placeOriginate(self.routes.pop(0))