def checkPlugins(self): navPath = xbmc.getInfoLabel("Container.FolderPath") if 'plugin://' not in navPath: # No Plugin currently set self.lastPluginChecked = "" return # Check if we are in a plugin location pluginName = xbmc.getInfoLabel("Container.FolderName") if pluginName in [None, "", self.lastPluginChecked]: # No Plugin currently set or this is a Plugin that has already been checked return # If we reach here we have aPlugin that we need to check log("NavigationRestrictions: Checking access to view Plugin: %s" % pluginName) self.lastPluginChecked = pluginName # Check for the case where the user does not want to check plugins # but the Pin Sentry plugin is selected, we always need to check this # as it is how permissions are set if (not Settings.isActivePlugins()) and ('PinSentry' not in pluginName): return securityLevel = 0 # Check to see if the user should have access to this plugin pinDB = PinSentryDB() securityLevel = pinDB.getPluginSecurityLevel(pluginName) if securityLevel < 1: # Check for the special case that we are accessing ourself # in which case we have a minimum security level if 'PinSentry' in pluginName: securityLevel = Settings.getSettingsSecurityLevel() else: log("NavigationRestrictions: No security enabled for plugin %s" % pluginName) return del pinDB # Check if we have already cached the pin number and at which level if PinSentry.getCachedPinLevel() >= securityLevel: log("NavigationRestrictions: Already cached pin at level %d, allowing access" % PinSentry.getCachedPinLevel()) return # Prompt the user for the pin, returns True if they knew it if PinSentry.promptUserForPin(securityLevel): log("NavigationRestrictions: Allowed access to plugin %s" % pluginName) else: log("NavigationRestrictions: Not allowed access to plugin %s which has security level %d" % (pluginName, securityLevel)) # Move back to the Video plugin Screen as they are not allowed where they are at the moment xbmc.executebuiltin("ActivateWindow(Video,addons://sources/video/)", True) # Clear the previous plugin as we will want to prompt for the pin again if the # user navigates there again self.lastPluginChecked = "" PinSentry.displayInvalidPinMessage(securityLevel)
def checkSystemSettings(self): # Check if the system restriction is enabled if not Settings.isActiveSystemSettings(): return # Check to see if the main system settings has been selected systemSettings = xbmc.getCondVisibility("Window.IsActive(10004)") addonBrowser = xbmc.getCondVisibility("Window.IsActive(10040)") profiles = xbmc.getCondVisibility("Window.IsActive(10034)") # Check if we are in any of the restricted sections if not systemSettings and not addonBrowser and not profiles: log("NavigationRestrictions: Not is restricted system settings") return # If we have already allowed the user to change settings, no need to check again # Check if we are still in the allowed time limit to edit if int(time.time()) < self.canChangeSettings: return # Need to make sure this user has access to change the settings pinDB = PinSentryDB() securityLevel = pinDB.getPluginSecurityLevel('PinSentry') del pinDB if securityLevel < 1: # If the user hasn't reset the permissions, then set it to the highest # security level available securityLevel = Settings.getSettingsSecurityLevel() log("NavigationRestrictions: Settings screen requires security level %d" % securityLevel) # Check if we have already cached the pin number and at which level if PinSentry.getCachedPinLevel() >= securityLevel: log("NavigationRestrictions: Already cached pin at level %d, allowing access" % PinSentry.getCachedPinLevel()) return # Before we prompt the user we need to close the dialog, otherwise the pin # dialog will appear behind it xbmc.executebuiltin("Dialog.Close(all, true)", True) # Prompt the user for the pin, returns True if they knew it if PinSentry.promptUserForPin(securityLevel): log("NavigationRestrictions: Allowed access to settings") # Allow the user 5 minutes to change the settings self.canChangeSettings = int(time.time()) + 300 xbmcgui.Dialog().notification(__addon__.getLocalizedString(32001).encode('utf-8'), __addon__.getLocalizedString(32110).encode('utf-8'), __icon__, 3000, False) else: log("NavigationRestrictions: Not allowed access to settings which has security level %d" % securityLevel) self.canChangeSettings = False PinSentry.displayInvalidPinMessage(securityLevel) # Return the user to the home page as they should not be here xbmc.executebuiltin("ActivateWindow(home)", True)
def checkSettings(self): # Check if we are in the Addon Information page (which can be used to disable the addon) # or the actual setting page addonSettings = xbmc.getCondVisibility("Window.IsActive(10140)") addonInformation = xbmc.getCondVisibility("Window.IsActive(10146)") if not addonSettings and not addonInformation: self.canChangeSettings = False return # If we have already allowed the user to change settings, no need to check again if self.canChangeSettings: return # Check if the addon is the PinSentry addon addonId = xbmc.getInfoLabel("ListItem.Property(Addon.ID)") if 'script.pinsentry' not in addonId: return # Need to make sure this user has access to change the settings pinDB = PinSentryDB() securityLevel = pinDB.getPluginSecurityLevel('PinSentry') del pinDB if securityLevel < 1: securityLevel = 1 # Check if we have already cached the pin number and at which level if PinSentry.getCachedPinLevel() >= securityLevel: log("NavigationRestrictions: Already cached pin at level %d, allowing access" % PinSentry.getCachedPinLevel()) return # Before we prompt the user we need to close the dialog, otherwise the pin # dialog will appear behind it xbmc.executebuiltin("Dialog.Close(all, true)", True) # Prompt the user for the pin, returns True if they knew it if PinSentry.promptUserForPin(): log("NavigationRestrictions: Allowed access to settings") self.canChangeSettings = True # Open the dialogs that should be shown if addonInformation: # Open the addon Information dialog xbmc.executebuiltin("ActivateWindow(10146)", True) elif addonSettings: # Open the addon settings dialog xbmc.executebuiltin("Addon.OpenSettings(script.pinsentry)", True) else: log("NavigationRestrictions: Not allowed access to settings which has security level %d" % securityLevel) self.canChangeSettings = False PinSentry.displayInvalidPinMessage()
def checkSettings(self): # Check if we are in the Addon Information page (which can be used to disable the addon) # or the actual setting page addonSettings = xbmc.getCondVisibility("Window.IsActive(10140)") addonInformation = xbmc.getCondVisibility("Window.IsActive(10146)") if not addonSettings and not addonInformation: # If not looking at an info or settings page, and the time for # allowed edits has ended, then reset it if self.canChangeSettings > 0: # If we have reached the home page, reset the timer if xbmc.getCondVisibility("Window.IsVisible(home)"): self.canChangeSettings = 0 elif time.time() > self.canChangeSettings: self.canChangeSettings = 0 return # Check if the addon is the PinSentry addon addonId = xbmc.getInfoLabel("ListItem.Property(Addon.ID)") if 'script.pinsentry' not in addonId: self.canChangeSettings = 0 return # If we have already allowed the user to change settings, no need to check again # Check if we are still in the allowed time limit to edit if int(time.time()) < self.canChangeSettings: return # Need to make sure this user has access to change the settings pinDB = PinSentryDB() securityLevel = pinDB.getPluginSecurityLevel('PinSentry') del pinDB if securityLevel < 1: # If the user hasn't reset the permissions, then set it to the highest # security level available securityLevel = Settings.getSettingsSecurityLevel() log("NavigationRestrictions: Settings screen requires security level %d" % securityLevel) # Check if we have already cached the pin number and at which level if PinSentry.getCachedPinLevel() >= securityLevel: log("NavigationRestrictions: Already cached pin at level %d, allowing access" % PinSentry.getCachedPinLevel()) return # Before we prompt the user we need to close the dialog, otherwise the pin # dialog will appear behind it xbmc.executebuiltin("Dialog.Close(all, true)", True) # Prompt the user for the pin, returns True if they knew it if PinSentry.promptUserForPin(securityLevel): log("NavigationRestrictions: Allowed access to settings") # Allow the user 5 minutes to change the settings self.canChangeSettings = int(time.time()) + 300 xbmcgui.Dialog().notification(__addon__.getLocalizedString(32001).encode('utf-8'), __addon__.getLocalizedString(32110).encode('utf-8'), __icon__, 3000, False) # Open the dialogs that should be shown, we don't reopen the Information dialog # as if we do the Close Dialog will not close it and the pin screen will not show correctly if addonSettings: # Open the addon settings dialog xbmc.executebuiltin("Addon.OpenSettings(script.pinsentry)", False) else: log("NavigationRestrictions: Not allowed access to settings which has security level %d" % securityLevel) self.canChangeSettings = False PinSentry.displayInvalidPinMessage(securityLevel)