コード例 #1
0
ファイル: dev_types.py プロジェクト: sdocent/djing
 def get_details(self):
     if self.db_instance is None:
         return
     num = safe_int(self.db_instance.snmp_extra)
     if num == 0:
         return
     try:
         status = self.get_item('.1.3.6.1.4.1.3320.101.10.1.1.26.%d' % num)
         signal = safe_float(
             self.get_item('.1.3.6.1.4.1.3320.101.10.5.1.5.%d' % num))
         distance = self.get_item('.1.3.6.1.4.1.3320.101.10.1.1.27.%d' %
                                  num)
         mac = self.get_item('.1.3.6.1.4.1.3320.101.10.1.1.3.%d' % num)
         if mac is not None:
             mac = ':'.join('%x' % i for i in mac)
         # uptime = self.get_item('.1.3.6.1.2.1.2.2.1.9.%d' % num)
         if status is not None and status.isdigit():
             return {
                 'status': status,
                 'signal': signal / 10 if signal else '—',
                 'name': self.get_item('.1.3.6.1.2.1.2.2.1.2.%d' % num),
                 'mac': mac,
                 'distance': distance / 10 if distance else 0
             }
     except EasySNMPTimeoutError as e:
         return {'err': "%s: %s" % (_('ONU not connected'), e)}
コード例 #2
0
    def get_details(self) -> Optional[Dict]:
        if self.db_instance is None:
            return
        snmp_extra = self.db_instance.snmp_extra
        if not snmp_extra:
            return
        try:
            fiber_num, onu_num = snmp_extra.split('.')
            fiber_num, onu_num = int(fiber_num), int(onu_num)
            fiber_addr = '%d.%d' % (fiber_num, onu_num)
            status = self.get_item('.1.3.6.1.4.1.3902.1012.3.50.12.1.1.1.%s.1' % fiber_addr)
            signal = safe_int(self.get_item('.1.3.6.1.4.1.3902.1012.3.50.12.1.1.10.%s.1' % fiber_addr))
            distance = self.get_item('.1.3.6.1.4.1.3902.1012.3.50.12.1.1.18.%s.1' % fiber_addr)
            ip_addr = self.get_item('.1.3.6.1.4.1.3902.1012.3.50.16.1.1.10.%s' % fiber_addr)
            vlans = self.get_item('.1.3.6.1.4.1.3902.1012.3.50.15.100.1.1.7.%s.1.1' % fiber_addr)
            int_name = self.get_item('.1.3.6.1.4.1.3902.1012.3.28.1.1.3.%s' % fiber_addr)
            onu_type = self.get_item('.1.3.6.1.4.1.3902.1012.3.28.1.1.1.%s' % fiber_addr)

            sn = self.get_item('.1.3.6.1.4.1.3902.1012.3.28.1.1.5.%s' % fiber_addr)
            if sn is not None:
                sn = 'ZTEG%s' % ''.join('%.2X' % ord(x) for x in sn[-4:])

            return {
                'status': status,
                'signal': conv_zte_signal(signal),
                'distance': safe_float(distance) / 10,
                'ip_addr': ip_addr,
                'vlans': vlans,
                'serial': sn,
                'int_name': int_name,
                'onu_type': onu_type,
                'mac': sn_to_mac(sn)
            }
        except IndexError:
            pass
コード例 #3
0
ファイル: views.py プロジェクト: sdocent/djing
    def _make_pay(self, data: dict):
        trade_point = lib.safe_int(data.get('TRADE_POINT'))
        receipt_num = lib.safe_int(data.get('RECEIPT_NUM'))
        pay_account = data.get('PAY_ACCOUNT')
        pay_id = data.get('PAY_ID')
        pay_amount = lib.safe_float(data.get('PAY_AMOUNT'))
        abon = Abon.objects.get(username=pay_account)
        pays = AllTimePayLog.objects.filter(pay_id=pay_id)
        if pays.exists():
            return self._bad_ret(-100, 'Pay already exists')

        with transaction.atomic():
            abon.add_ballance(None,
                              pay_amount,
                              comment='%s %.2f' %
                              (self.object.title, pay_amount))
            abon.save(update_fields=('ballance', ))

            AllTimePayLog.objects.create(pay_id=pay_id,
                                         summ=pay_amount,
                                         abon=abon,
                                         trade_point=trade_point,
                                         receipt_num=receipt_num,
                                         pay_gw=self.object)
        return {
            'pay_id': pay_id,
            'service_id': data.get('SERVICE_ID'),
            'amount': round(pay_amount, 2),
            'status_code': 22,
            'time_stamp': self.current_date
        }
コード例 #4
0
ファイル: views.py プロジェクト: bashmak/djing
    def _make_pay(self, data: dict):
        trade_point = lib.safe_int(data.get('TRADE_POINT'))
        receipt_num = lib.safe_int(data.get('RECEIPT_NUM'))
        pay_account = data.get('PAY_ACCOUNT')
        pay_id = data.get('PAY_ID')
        pay_amount = lib.safe_float(data.get('PAY_AMOUNT'))
        abon = Abon.objects.get(username=pay_account)
        pays = AllTimePayLog.objects.filter(pay_id=pay_id)
        if pays.exists():
            return self._bad_ret(-100, 'Pay already exists')

        abon.add_ballance(
            None, pay_amount,
            comment='%s %.2f' % (self.object.title, pay_amount)
        )
        abon.save(update_fields=('ballance',))

        AllTimePayLog.objects.create(
            pay_id=pay_id,
            summ=pay_amount,
            abon=abon,
            trade_point=trade_point,
            receipt_num=receipt_num,
            pay_gw=self.object
        )
        return {
            'pay_id': pay_id,
            'service_id': data.get('SERVICE_ID'),
            'amount': pay_amount,
            'status_code': 22,
            'time_stamp': self.current_date
        }
コード例 #5
0
 def get_ports(self) -> ListOrError:
     nms = self.get_list('.1.3.6.1.4.1.3320.101.10.1.1.79')
     res = []
     try:
         for nm in nms:
             n = int(nm)
             status = self.get_item('.1.3.6.1.4.1.3320.101.10.1.1.26.%d' % n)
             signal = safe_float(self.get_item('.1.3.6.1.4.1.3320.101.10.5.1.5.%d' % n))
             onu = ONUdev(
                 num=n,
                 name=self.get_item('.1.3.6.1.2.1.2.2.1.2.%d' % n),
                 status=True if status == '3' else False,
                 mac=self.get_item('.1.3.6.1.4.1.3320.101.10.1.1.3.%d' % n),
                 speed=0,
                 signal=signal / 10 if signal else '—',
                 snmp_worker=self)
             res.append(onu)
     except EasySNMPTimeoutError as e:
         return EasySNMPTimeoutError(
             "%s (%s)" % (gettext('wait for a reply from the SNMP Timeout'), e)
         ), res
     return res
コード例 #6
0
ファイル: pay_systems.py プロジェクト: SirPrikol/djing
def allpay(request):
    def bad_ret(err_id, err_description=None):
        now = timezone.now()
        r = {
            'status_code': safe_int(err_id),
            'time_stamp': now.strftime("%d.%m.%Y %H:%M")
        }
        if err_description:
            r.update({'description': err_description})
        return r

    try:
        serv_id = request.GET.get('SERVICE_ID')
        act = safe_int(request.GET.get('ACT'))
        pay_account = request.GET.get('PAY_ACCOUNT')
        pay_id = request.GET.get('PAY_ID')
        pay_amount = safe_float(request.GET.get('PAY_AMOUNT'))
        sign = request.GET.get('SIGN').lower()
        current_date = timezone.now().strftime("%d.%m.%Y %H:%M")

        if act <= 0:
            return bad_ret(-101, 'ACT less than zero')

        # check sign
        md = md5()
        s = '_'.join((str(act), pay_account or '', serv_id
                      or '', pay_id, getattr(settings, 'PAY_SECRET')))
        md.update(bytes(s, 'utf-8'))
        our_sign = md.hexdigest()
        if our_sign != sign:
            return bad_ret(-101)

        if act == 1:
            abon = Abon.objects.get(username=pay_account)
            fio = abon.fio
            ballance = float(abon.ballance)
            return {
                'balance': ballance,
                'name': fio,
                'account': pay_account,
                'service_id': getattr(settings, 'PAY_SERV_ID'),
                'min_amount': 10.0,
                'max_amount': 5000,
                'status_code': 21,
                'time_stamp': current_date
            }
        elif act == 4:
            trade_point = safe_int(request.GET.get('TRADE_POINT'))
            receipt_num = safe_int(request.GET.get('RECEIPT_NUM'))
            abon = Abon.objects.get(username=pay_account)
            pays = AllTimePayLog.objects.filter(pay_id=pay_id)
            if pays.count() > 0:
                return bad_ret(-100)

            abon.add_ballance(None,
                              pay_amount,
                              comment='AllPay %.2f' % pay_amount)
            abon.save(update_fields=('ballance', ))

            AllTimePayLog.objects.create(pay_id=pay_id,
                                         summ=pay_amount,
                                         abon=abon,
                                         trade_point=trade_point,
                                         receipt_num=receipt_num)
            return {
                'pay_id': pay_id,
                'service_id': serv_id,
                'amount': pay_amount,
                'status_code': 22,
                'time_stamp': current_date
            }
        elif act == 7:
            pay = AllTimePayLog.objects.get(pay_id=pay_id)
            return {
                'status_code': 11,
                'time_stamp': current_date,
                'transaction': {
                    'pay_id': pay_id,
                    'service_id': serv_id,
                    'amount': pay.summ,
                    'status': 111,
                    'time_stamp': pay.date_add.strftime("%d.%m.%Y %H:%M")
                }
            }
        else:
            return bad_ret(-101, 'ACT is not passed')

    except Abon.DoesNotExist:
        return bad_ret(-40)
    except DatabaseError:
        return bad_ret(-90)
    except AllTimePayLog.DoesNotExist:
        return bad_ret(-10)
    except AttributeError:
        return bad_ret(-101)