Beispiel #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)
Beispiel #2
0
 def autoconfig_pending_dev(self, session_id):
     sql = "SELECT *\n"\
           "FROM `autoconfig_registration`\n"\
           "WHERE `session_id` = %s AND `instance_id` = %s"
     session = self._db.autofetch_row(sql,
                                      (session_id, self._db.instance_id))
     if not session:
         return redirect(url_for('autoconfig_pending'), code=302)
     sql = "SELECT ag.`account_id`, ag.`username`\n"\
           "FROM `settings_pogoauth` ag\n"\
           "LEFT JOIN `settings_device` sd ON sd.`device_id` = ag.`device_id`\n"\
           "WHERE ag.`instance_id` = %s AND (sd.`device_id` IS NULL OR sd.`device_id` = %s)"
     ac_issues = AutoConfIssueGenerator(self._db, self._data_manager,
                                        self._args, self._storage_obj)
     _, issues_critical = ac_issues.get_issues()
     if issues_critical:
         redirect(url_for('autoconfig_pending'), code=302)
     google_addresses = self._db.autofetch_all(
         sql, (self._db.instance_id, session['device_id']))
     devices = self._data_manager.get_root_resource('device')
     uri = "{}/{}".format(url_for('api_autoconf'), session_id)
     redir_uri = url_for('autoconfig_pending')
     return render_template('autoconfig_pending_dev.html',
                            subtab="autoconf_dev",
                            element=session,
                            devices=devices,
                            accounts=google_addresses,
                            uri=uri,
                            redirect=redir_uri,
                            method='POST')
Beispiel #3
0
 def autoconfig_pending(self):
     sql = "SELECT count(*)\n"\
           "FROM `settings_pogoauth` ag\n"\
           "LEFT JOIN `settings_device` sd ON sd.`account_id` = ag.`account_id`\n"\
           "WHERE ag.`instance_id` = %s AND sd.`device_id` IS NULL"
     ac_issues = AutoConfIssueGenerator(self._db, self._data_manager,
                                        self._args, self._storage_obj)
     issues_warning, issues_critical = ac_issues.get_issues()
     pending = {}
     sql = "SELECT ar.`session_id`, ar.`ip`, sd.`device_id`, sd.`name` AS 'origin', ar.`status`"\
           "FROM `autoconfig_registration` ar\n"\
           "LEFT JOIN `settings_device` sd ON sd.`device_id` = ar.`device_id`\n"\
           "WHERE ar.`instance_id` = %s"
     data = self._db.autofetch_all(sql, (self._db.instance_id))
     for row in data:
         if row['status'] == 0:
             row['status_hr'] = 'Pending'
         elif row['status'] == 1:
             row['status_hr'] = 'Accepted'
         elif row['status'] == 2:
             row['status_hr'] = 'In-Progress with errors'
         elif row['status'] == 3:
             row['status_hr'] = 'Completed with errors'
         else:
             row['status_hr'] = 'Rejected'
         pending[row['session_id']] = row
     return render_template('autoconfig_pending.html',
                            subtab="autoconf_dev",
                            pending=pending,
                            issues_warning=issues_warning,
                            issues_critical=issues_critical)
Beispiel #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:
         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)
Beispiel #5
0
 def autoconfig_download_file(self):
     ac_issues = AutoConfIssueGenerator(self._db, self._data_manager,
                                        self._args, self._storage_obj)
     if ac_issues.has_blockers():
         return Response('Basic requirements not met',
                         status=406,
                         headers=ac_issues.get_headers())
     pd_conf = PDConfig(self._db, self._args, self._data_manager)
     config_file = BytesIO()
     info = [pd_conf.contents['post_destination']]
     try:
         if pd_conf.contents['mad_auth'] is not None:
             auth = self._data_manager.get_resource(
                 'auth', pd_conf.contents['mad_auth'])
             info.append(f"{auth['username']}:{auth['password']}")
     except KeyError:
         # No auth defined for RGC so theres probably no auth for the system
         pass
     config_file.write('\n'.join(info).encode('utf-8'))
     config_file.seek(0, 0)
     return send_file(config_file,
                      as_attachment=True,
                      attachment_filename='mad_autoconf.txt',
                      mimetype='text/plain')
Beispiel #6
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)