def autoconf_config_rgc(self): conf = RGCConfig(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_rgc(self): config = RGCConfig(self._db, self._args, self._data_manager) auths = self._data_manager.get_root_resource('auth') uri = url_for('api_autoconf_rgc') return render_template('autoconfig_config_editor.html', subtab="autoconf_rgc", config_name='Remote GPS Controller', config_element=config, auths=auths, uri=uri)
def autoconf_delete_rgc(self): RGCConfig(self.dbc, self._args, self._data_manager).delete() return (None, 200)