Пример #1
0
 def settings_pogoauth(self):
     devices = self._data_manager.get_root_resource('device')
     devs_google: List[Tuple[int, str]] = []
     devs_ptc: List[Tuple[int, str]] = []
     current_id = request.args.get('id', None)
     try:
         identifier = int(current_id)
     except (TypeError, ValueError):
         identifier = None
     for dev_id, dev in PogoAuth.get_avail_devices(
             self._data_manager, auth_id=identifier).items():
         devs_google.append((dev_id, dev['origin']))
     for dev_id, dev in PogoAuth.get_avail_devices(
             self._data_manager, auth_id=identifier).items():
         devs_ptc.append((dev_id, dev['origin']))
     required_data = {
         'identifier': 'id',
         'base_uri': 'api_pogoauth',
         'data_source': 'pogoauth',
         'redirect': 'settings_pogoauth',
         'html_single': 'settings_singlepogoauth.html',
         'html_all': 'settings_pogoauth.html',
         'subtab': 'pogoauth',
         'passthrough': {
             'devices': devices,
             'devs_google': devs_google,
             'devs_ptc': devs_ptc
         },
     }
     return self.process_element(**required_data)
Пример #2
0
    def validate_custom(self) -> Optional[dict]:
        data = self.get_resource(backend=True)
        issues = {
            'invalid': []
        }
        bad_macs = []
        mac_fields = ['mac_address', 'wifi_mac_address']
        for field in mac_fields:
            if field not in data:
                continue
            if data[field] is None:
                continue
            if not re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", data[field].lower()):
                bad_macs.append((field, 'Invalid MAC address'))
                continue
            search = {
                field: data[field]
            }
            in_use = self._data_manager.search('device', params=search)
            for dev_id in in_use.keys():
                if dev_id != self.identifier:
                    bad_macs.append((field, 'MAC in use'))
        if bad_macs:
            issues['invalid'] += bad_macs

        if self['ggl_login'] is not None:
            if self['ggl_login'] not in PogoAuth.get_avail_accounts(self._data_manager,
                                                                    auth_type='google',
                                                                    device_id=self.identifier):
                issues['invalid'].append(('ggl_login', 'Invalid Google Account specified'))
        if self['ptc_login'] is not None:
            invalid_ptc = []
            valid_auth = PogoAuth.get_avail_accounts(self._data_manager, 'ptc', device_id=self.identifier)
            for ptc in self['ptc_login']:
                if int(ptc) not in valid_auth:
                    invalid_ptc.append(ptc)
            if invalid_ptc:
                msg = 'Invalid PogoAuth specified [%s]' % ','.join([str(x) for x in invalid_ptc])
                issues['invalid'].append(('ptc_login', msg))

        if 'origin' in self and any(c in self['origin'] for c in string.whitespace):
            issues['invalid'].append(('origin', 'Origin cannot have whitespaces, please use under_score'))

        if any(issues['invalid']):
            return issues
Пример #3
0
    def validate_custom(self) -> Optional[dict]:
        data = self.get_resource(backend=True)
        issues = {'invalid': []}
        bad_macs = []
        mac_fields = ['mac_address', 'wifi_mac_address']
        for field in mac_fields:
            if field not in data:
                continue
            if data[field] is None:
                continue
            if not re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$",
                            data[field].lower()):
                bad_macs.append((field, 'Invalid MAC address'))
        if bad_macs:
            issues['invalid'] += bad_macs

        if self['ggl_login'] is not None:
            if self['ggl_login'] not in PogoAuth.get_avail_accounts(
                    self._data_manager,
                    auth_type='google',
                    device_id=self.identifier):
                issues['invalid'].append(
                    ('ggl_login', 'Invalid Google Account specified'))
        if self['ptc_login'] is not None:
            invalid_ptc = []
            valid_auth = PogoAuth.get_avail_accounts(self._data_manager,
                                                     'ptc',
                                                     device_id=self.identifier)
            for ptc in self['ptc_login']:
                if int(ptc) not in valid_auth:
                    invalid_ptc.append(ptc)
            if invalid_ptc:
                msg = 'Invalid PogoAuth specified [%s]' % ','.join(
                    [str(x) for x in invalid_ptc])
                issues['invalid'].append(('ptc_login', msg))
        if any(issues['invalid']):
            return issues
Пример #4
0
 def settings_devices(self):
     try:
         identifier = request.args.get('id')
         int(identifier)
     except (TypeError, ValueError):
         pass
     ggl_accounts = PogoAuth.get_avail_accounts(self._data_manager,
                                                'google',
                                                device_id=identifier)
     ptc_accounts = []
     for account_id, account in PogoAuth.get_avail_accounts(self._data_manager,
                                                            'ptc',
                                                            device_id=identifier).items():
         ptc_accounts.append({
             'text': account['username'],
             'id': account_id
         })
     required_data = {
         'identifier': 'id',
         'base_uri': 'api_device',
         'data_source': 'device',
         'redirect': 'settings_devices',
         'html_single': 'settings_singledevice.html',
         'html_all': 'settings_devices.html',
         'subtab': 'device',
         'required_data': {
             'walkers': 'walker',
             'pools': 'devicepool'
         },
         'passthrough': {
             'ggl_accounts': ggl_accounts,
             'ptc_accounts': ptc_accounts,
             'requires_auth': not self._args.autoconfig_no_auth,
             'responsive': str(self._args.madmin_noresponsive).lower()
         }
     }
     return self.process_element(**required_data)