Exemple #1
0
    def render(self, request):
        request.setHeader('Content-type', 'application/xhtml+xml')
        request.setHeader('charset', 'UTF-8')
        try:
            wol_active = config.plugins.wolconfig.activate.value
            wol_location = config.plugins.wolconfig.location.value
        except KeyError:
            return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>WOLSetup plugin is not installed or your STB does not support WOL</e2statetext></e2simplexmlresult>'

        if len(request.args):
            config_changed = False
            if "wol" in request.args:
                wol_state = str(request.args["wol"][0]).lower()
                if wol_state in ('true', '1', 'enabled', 'enable', 'active'):
                    config.plugins.wolconfig.activate.value = True
                elif wol_state in ('false', '0', 'disabled', 'disable',
                                   'inactive'):
                    config.plugins.wolconfig.activate.value = False
                if wol_active != config.plugins.wolconfig.activate.value:
                    config_changed = True
            elif "location" in request.args:
                location = request.args["location"][0]
                if not location in config.plugins.wolconfig.location.choices:
                    location = wol_location
                if location != config.plugins.wolconfig.location.value:
                    config.plugins.wolconfig.location.value = location
                    config_changed = True
            elif "wolstandby" in request.args:
                wol_standby = str(request.args["wolstandby"][0]).lower()
                if wol_standby in ('true', '1', 'enabled', 'enable', 'active'):
                    try:
                        from Plugins.SystemPlugins.WOLSetup.plugin import WOLSetup, _deviseWOL, _flagForceEnable, _flagSupportWol, _tryQuitTable, _ethDevice
                        from Screens.Standby import TryQuitMainloop
                    except ImportError:
                        return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>WOLSetup plugin is not installed or your STB does not support WOL</e2statetext></e2simplexmlresult>'
                    WOLSetup.ActivateWOL(self.session, writeDevice=True)
                    self.session.open(TryQuitMainloop,
                                      _tryQuitTable["deepstandby"])
            if config_changed:
                config.plugins.wolconfig.save()

        locations = ""
        for location_available in config.plugins.wolconfig.location.choices:
            locations += location_available + ", "
        locations = locations.rstrip(', ')

        return """<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
				<e2configs>
					<e2config>
						<e2configname>wol_active</e2configname>
						<e2configvalue>%s</e2configvalue>
					</e2config>
					<e2config>
						<e2configname>wol_location</e2configname>
						<e2configchoices>%s</e2configchoices>
						<e2configvalue>%s</e2configvalue>
					</e2config>
				</e2configs>""" % (str(config.plugins.wolconfig.activate.value), locations,
                       str(config.plugins.wolconfig.location.value))
Exemple #2
0
	def render(self, request):
		request.setHeader('Content-type', 'application/xhtml+xml')
		request.setHeader('charset', 'UTF-8')
		try:
			wol_active = config.plugins.wolconfig.activate.value
			wol_location = config.plugins.wolconfig.location.value
		except:  # nosec # noqa: E722
			return createResult(False, b"WOLSetup plugin is not installed or your STB does not support WOL")

		if len(request.args):
			config_changed = False
			wol_state = getUrlArg(request, "wol")
			location = getUrlArg(request, "location")
			wol_standby = getUrlArg(request, "wolstandby")
			if wol_state != None:
				wol_state = str(wol_state).lower()
				if wol_state in ('true', '1', 'enabled', 'enable', 'active'):
					config.plugins.wolconfig.activate.value = True
				elif wol_state in ('false', '0', 'disabled', 'disable', 'inactive'):
					config.plugins.wolconfig.activate.value = False
				if wol_active != config.plugins.wolconfig.activate.value:
					config_changed = True
			elif location != None:
				if location not in config.plugins.wolconfig.location.choices:
					location = wol_location
				if location != config.plugins.wolconfig.location.value:
					config.plugins.wolconfig.location.value = location
					config_changed = True
			elif wol_standby != None:
				wol_standby = str(wol_standby).lower()
				if wol_standby in ('true', '1', 'enabled', 'enable', 'active'):
					try:
						from Plugins.SystemPlugins.WOLSetup.plugin import WOLSetup, _deviseWOL, _flagForceEnable, _flagSupportWol, _tryQuitTable, _ethDevice  # noqa: F401
						from Screens.Standby import TryQuitMainloop
					except ImportError:
						return createResult(False, b"WOLSetup plugin is not installed or your STB does not support WOL")
					WOLSetup.ActivateWOL(self.session, writeDevice=True)
					self.session.open(TryQuitMainloop, _tryQuitTable["deepstandby"])
			if config_changed:
				config.plugins.wolconfig.save()

		locations = ""
		for location_available in config.plugins.wolconfig.location.choices:
			locations += location_available + ", "
		locations = locations.rstrip(', ')

		return ensure_binary("""<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
				<e2configs>
					<e2config>
						<e2configname>wol_active</e2configname>
						<e2configvalue>%s</e2configvalue>
					</e2config>
					<e2config>
						<e2configname>wol_location</e2configname>
						<e2configchoices>%s</e2configchoices>
						<e2configvalue>%s</e2configvalue>
					</e2config>
				</e2configs>""" % (str(config.plugins.wolconfig.activate.value), locations, str(config.plugins.wolconfig.location.value)))