def perform_ping(started, server=DEFAULT_SERVER_URL): url = urljoin(server, "/api/v1/pingback") instance, _ = InstanceIDModel.get_or_create_current_instance() language = get_device_setting("language_id", "") try: timezone = get_current_timezone().zone except Exception: timezone = "" data = { "instance_id": instance.id, "version": kolibri.__version__, "mode": conf.OPTIONS["Deployment"]["RUN_MODE"], "platform": instance.platform, "sysversion": instance.sysversion, "database_id": instance.database.id, "system_id": instance.system_id, "node_id": instance.node_id, "language": language, "timezone": timezone, "uptime": int( (datetime.datetime.now() - started).total_seconds() / 60), "timestamp": localtime(), "installer": installation_type(), } logger.debug("Pingback data: {}".format(data)) jsondata = dump_zipped_json(data) response = requests.post(url, data=jsondata, timeout=60) response.raise_for_status() return json.loads(response.content.decode() or "{}")
def plugin_data(self): return { "allowGuestAccess": get_device_setting("allow_guest_access"), "allowLearnerUnassignedResourceAccess": allow_learner_unassigned_resource_access(), }
def plugin_data(self): return { "allowGuestAccess": get_device_setting("allow_guest_access"), "allowLearnerUnassignedResourceAccess": allow_learner_unassigned_resource_access(), "enableCustomChannelNav": conf.OPTIONS["Learn"]["ENABLE_CUSTOM_CHANNEL_NAV"], }
def get_device_info(): """Returns metadata information about the device""" instance_model = InstanceIDModel.get_or_create_current_instance()[0] try: device_name = get_device_setting("name") subset_of_users_device = get_device_setting("subset_of_users_device") # When Koliri starts at the first time, and device hasn't been created except DeviceNotProvisioned: device_name = instance_model.hostname subset_of_users_device = False info = { "application": "kolibri", "kolibri_version": kolibri.__version__, "instance_id": instance_model.id, "device_name": device_name, "operating_system": platform.system(), "subset_of_users_device": subset_of_users_device, } return info
def plugin_data(self): from kolibri.core.auth.models import FacilityUser def sanitize_users(user): return { "id": user.id, "username": user.username, "facility_id": user.facility_id, "is_learner": len(user.get_roles_for_user(user)) == 0, "needs_password": (user.password == "NOT_SPECIFIED" or not user.password), } return { "oidcProviderEnabled": OIDCProviderHook.is_enabled(), "allowGuestAccess": get_device_setting("allow_guest_access"), "deviceUsers": list(map(sanitize_users, FacilityUser.objects.all())), }
def plugin_data(self): return { "oidcProviderEnabled": OIDCProviderHook.is_enabled(), "allowGuestAccess": get_device_setting("allow_guest_access"), }
def get_device_language(): language_id = get_device_setting("language_id", None) try: return get_supported_language_variant(language_id) except LookupError: return None
def plugin_data(self): return {"allowGuestAccess": get_device_setting("allow_guest_access")}
def add_service(self, zeroconf, type, name): timeout = 10000 info = zeroconf.get_service_info(type, name, timeout=timeout) if info is None: logger.warn( "Zeroconf network service information could not be retrieved within {} seconds" .format(str(timeout / 1000.0))) return id = _id_from_name(name) ip = socket.inet_ntoa(info.address) base_url = "http://{ip}:{port}/".format(ip=ip, port=info.port) zeroconf_service = ZEROCONF_STATE.get("service") is_self = zeroconf_service and zeroconf_service.id == id instance = { "id": id, "ip": ip, "local": ip in get_all_addresses(), "port": info.port, "host": info.server.strip("."), "base_url": base_url, "self": is_self, } device_info = parse_device_info(info) instance.update(device_info) self.instances[id] = instance if not is_self: try: DynamicNetworkLocation.objects.update_or_create(dict( base_url=base_url, **device_info), id=id) logger.info( "Kolibri instance '%s' joined zeroconf network; service info: %s" % (id, self.instances[id])) except ValidationError: import traceback logger.warn( """ A new Kolibri instance '%s' was seen on the zeroconf network, but we had trouble getting the information we needed about it. Service info: %s The following exception was raised: %s """ % (id, self.instances[id], traceback.format_exc(limit=1))) finally: connection.close() if ("subset_of_users_device" in device_info): # discards previous versions of Kolibri if get_device_setting("subset_of_users_device", False) and not device_info.get( "subset_of_users_device", False): server = base_url[:-1] # removes ending slash for user in FacilityUser.objects.all().values("id"): begin_request_soud_sync(server=server, user=user["id"])