def autoconf_config_pd(self): conf = PDConfig(self.dbc, self._args, self._data_manager) try: conf.save_config(self.api_req.data) except AutoConfIssue as err: return (err.issues, 400) return (None, 200)
def autoconfig_get_config(self, *args, **kwargs) -> Response: session_id: Optional[int] = kwargs.get('session_id', None) operation: Optional[str] = kwargs.get('operation', None) try: sql = "SELECT sd.`name`\n"\ "FROM `settings_device` sd\n"\ "INNER JOIN `autoconfig_registration` ar ON ar.`device_id` = sd.`device_id`\n"\ "WHERE ar.`session_id` = %s AND ar.`instance_id` = %s" origin = self._db_wrapper.autofetch_value(sql, (session_id, self._db_wrapper.instance_id)) if operation in ['pd', 'rgc']: if operation == 'pd': config = PDConfig(self._db_wrapper, self.__application_args, self.__data_manager) else: config = RGCConfig(self._db_wrapper, self.__application_args, self.__data_manager) return send_file(config.generate_config(origin), as_attachment=True, attachment_filename='conf.xml', mimetype='application/xml') elif operation in ['google']: sql = "SELECT ag.`username`, ag.`password`\n"\ "FROM `settings_pogoauth` ag\n"\ "INNER JOIN `settings_device` sd ON sd.`account_id` = ag.`account_id`\n"\ "INNER JOIN `autoconfig_registration` ar ON ar.`device_id` = sd.`device_id`\n"\ "WHERE ar.`session_id` = %s and ag.`instance_id` = %s" login = self._db_wrapper.autofetch_row(sql, (session_id, self._db_wrapper.instance_id)) if login: return Response(status=200, response='\n'.join([login['username'], login['password']])) else: return Response(status=404, response='') elif operation == 'origin': return Response(status=200, response=origin) except Exception: logger.opt(exception=True).critical('Unable to process autoconfig') return Response(status=406, response="")
def get_config(self, conf_type: str): data: dict = {} if conf_type == 'rgc': data = RGCConfig(self.dbc, self._args, self._data_manager).contents elif conf_type == 'pd': data = PDConfig(self.dbc, self._args, self._data_manager).contents else: return (None, 404) return (data, 200)
def autoconf_pd(self): config = PDConfig(self._db, self._args, self._data_manager) auths = self._data_manager.get_root_resource('auth') uri = url_for('api_autoconf_pd') return render_template('autoconfig_config_editor.html', subtab="autoconf_pd", config_name='PogoDroid', config_element=config, auths=auths, uri=uri)
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')
def autoconf_delete_pd(self): PDConfig(self.dbc, self._args, self._data_manager).delete() return (None, 200)