示例#1
0
 def autoconf_set_status(self, session_id: int):
     status = 2
     try:
         if self.api_req.data['status']:
             status = 1
     except KeyError:
         return (None, 400)
     update = {
         'status': status
     }
     device = None
     if status == 1:
         is_hopper = False
         ac_issues = AutoConfIssueGenerator(self.dbc, self._data_manager, self._args, self.storage_obj)
         if ac_issues.has_blockers():
             return ac_issues.get_issues(), 406, {"headers": ac_issues.get_headers()}
         # Set the device id.  If it was not requested use the origin hopper to create one
         try:
             dev_id = self.api_req.data['device_id'].split('/')[-1]
             try:
                 self._data_manager.get_resource('device', dev_id)
                 update['device_id'] = dev_id
             except UnknownIdentifier:
                 return ('Unknown device ID', 400)
         except (AttributeError, KeyError):
             hopper_name = 'madrom'
             hopper_response = origin_generator(self._data_manager, self.dbc, OriginBase=hopper_name)
             if type(hopper_response) != tuple:
                 return hopper_response
             else:
                 update['device_id'] = hopper_response[1]
                 is_hopper = True
         search = {
             'device_id': update['device_id']
         }
         has_auth = self._data_manager.search('pogoauth', params=search)
         if not self._args.autoconfig_no_auth and (not has_auth):
             device = self._data_manager.get_resource('device', update['device_id'])
             try:
                 auth_type = device['settings']['logintype']
             except KeyError:
                 auth_type = 'google'
             # Find one that matches authtype
             sql = "SELECT ag.`account_id`\n"\
                   "FROM `settings_pogoauth` ag\n"\
                   "WHERE ag.`device_id` IS NULL AND ag.`instance_id` = %s AND ag.`login_type` = %s"
             account_id = self.dbc.autofetch_value(sql, (self.dbc.instance_id, auth_type))
             if account_id is None:
                 return ('No configured emails', 400)
             auth = self._data_manager.get_resource('pogoauth', account_id)
             auth['device_id'] = device.identifier
             if is_hopper and auth_type != 'google':
                 auth['login_type'] = auth_type
             auth.save()
     where = {
         'session_id': session_id,
         'instance_id': self.dbc.instance_id
     }
     self.dbc.autoexec_update('autoconfig_registration', update, where_keyvals=where)
     return (None, 200)
示例#2
0
 def autoconf_set_status(self, session_id: int):
     status = 2
     try:
         if self.api_req.data['status']:
             status = 1
     except KeyError:
         return (None, 400)
     update = {'status': status}
     device = None
     if status == 1:
         ac_issues = AutoConfIssueGenerator(self.dbc, self._data_manager,
                                            self._args, self.storage_obj)
         if ac_issues.has_blockers():
             return ac_issues.get_issues(), 406, {
                 "headers": ac_issues.get_headers()
             }
         # Set the device id.  If it was not requested use the origin hopper to create one
         try:
             dev_id = self.api_req.data['device_id'].split('/')[-1]
             try:
                 self._data_manager.get_resource('device', dev_id)
                 update['device_id'] = dev_id
             except UnknownIdentifier:
                 return ('Unknown device ID', 400)
         except (AttributeError, KeyError):
             hopper_name = 'madrom'
             hopper_response = origin_generator(self._data_manager,
                                                self.dbc,
                                                OriginBase=hopper_name)
             if type(hopper_response) != tuple:
                 return hopper_response
             else:
                 update['device_id'] = hopper_response[1]
         device = self._data_manager.get_resource('device',
                                                  update['device_id'])
         try:
             has_ptc = device['settings']['ptc_login']
         except KeyError:
             has_ptc = False
         if not self._args.autoconfig_no_auth and (
                 device['account_id'] is None and not has_ptc):
             # Auto-assign a google account as one was not specified
             sql = "SELECT ag.`account_id`\n"\
                   "FROM `settings_pogoauth` ag\n"\
                   "LEFT JOIN `settings_device` sd ON sd.`account_id` = ag.`account_id`\n"\
                   "WHERE sd.`device_id` IS NULL AND ag.`instance_id` = %s AND ag.`login_type` = %s"
             account_id = self.dbc.autofetch_value(
                 sql, (self.dbc.instance_id, 'google'))
             if account_id is None:
                 return ('No configured emails', 400)
             device['account_id'] = account_id
             device.save()
     where = {'session_id': session_id, 'instance_id': self.dbc.instance_id}
     self.dbc.autoexec_update('autoconfig_registration',
                              update,
                              where_keyvals=where)
     return (None, 200)
示例#3
0
文件: MITMReceiver.py 项目: cecpk/MAD
 def origin_generator_endpoint(self, *args, **kwargs):
     return origin_generator(self.__data_manager, self._db_wrapper,
                             **kwargs)
示例#4
0
 def autoconf_set_status(self, session_id: int):
     status = 2
     try:
         if self.api_req.data['status']:
             status = 1
     except KeyError:
         return (None, 400)
     update = {'status': status}
     device = None
     if status == 1:
         is_hopper = False
         ac_issues = AutoConfIssueGenerator(self.dbc, self._data_manager,
                                            self._args, self.storage_obj)
         if ac_issues.has_blockers():
             return ac_issues.get_issues(), 406, {
                 "headers": ac_issues.get_headers()
             }
         # Set the device id.  If it was not requested use the origin hopper to create one
         try:
             dev_id = self.api_req.data['device_id'].split('/')[-1]
             try:
                 self._data_manager.get_resource('device', dev_id)
                 update['device_id'] = dev_id
             except UnknownIdentifier:
                 return ('Unknown device ID', 400)
         except (AttributeError, KeyError):
             hopper_name = 'madrom'
             hopper_response = origin_generator(self._data_manager,
                                                self.dbc,
                                                OriginBase=hopper_name)
             if type(hopper_response) != tuple:
                 return hopper_response
             else:
                 update['device_id'] = hopper_response[1]
                 is_hopper = True
         search = {'device_id': update['device_id']}
         has_auth = self._data_manager.search('pogoauth', params=search)
         if not self._args.autoconfig_no_auth and (not has_auth):
             device = self._data_manager.get_resource(
                 'device', update['device_id'])
             try:
                 auth_type = device['settings']['logintype']
             except KeyError:
                 login = get_available_login(self.dbc)
                 try:
                     auth_type = login['login_type']
                 except KeyError:
                     return ('No available logins for auto-config', 400)
                 else:
                     account_id = login['account_id']
             else:
                 login = get_available_login(self.dbc, auth_type)
                 try:
                     account_id = login['account_id']
                 except KeyError:
                     return ('No available logins for {}'.format(auth_type),
                             400)
             if account_id is None:
                 if is_hopper:
                     device = self._data_manager.get_resource(
                         'device', update['device_id'])
                     device.delete()
                 return ('No configured Pogoauth', 400)
             else:
                 device["logintype"] = auth_type
                 device.save()
             auth = self._data_manager.get_resource('pogoauth', account_id)
             auth['device_id'] = device.identifier
             if is_hopper and auth_type != 'google':
                 auth['login_type'] = auth_type
             auth.save()
     where = {'session_id': session_id, 'instance_id': self.dbc.instance_id}
     self.dbc.autoexec_update('autoconfig_registration',
                              update,
                              where_keyvals=where)
     return (None, 200)