class LoginData: def __init__(self): self.authentication = Authentication() self.authentication.session_init() if self.authentication.is_logged_in(): if self.authentication.is_admin(): responseMsg = self.authentication.get_name() + ":admin" else: responseMsg = self.authentication.get_name() + ":notadmin" else: responseMsg = self.authentication.get_error() response.setStatus(500) writer = response.getPrintWriter("text/html; charset=UTF-8") writer.println(responseMsg) writer.close()
class DeleteData: def __init__(self): self.authentication = Authentication() self.authentication.session_init() self.writer = response.getPrintWriter("text/html; charset=UTF-8") if self.authentication.is_logged_in() and self.authentication.is_admin(): self.process() else: self.throw_error("Only administrative users can access this feature") def process(self): record = formData.get("record") try: Services.storage.removeObject(record) Services.indexer.remove(record) self.writer.println(record) self.writer.close() except Exception, e: self.throw_error("Error deleting object: " + e.getMessage())
class LoginData: def __init__(self): self.authentication = Authentication() self.authentication.session_init() self.writer = response.getPrintWriter("text/html; charset=UTF-8") if self.authentication.is_logged_in() and self.authentication.is_admin(): self.process() else: self.throw_error("Only administrative users can access this feature") def add_user(self): username = formData.get("field") rolename = formData.get("hidden") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.set_role(username, rolename) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def change_password(self): username = formData.get("username") password = formData.get("password") password_confirm = formData.get("password_confirm") if password != password_confirm: self.throw_error("The confirm password field does not match the password.") else: source = formData.get("source") self.authentication.set_auth_plugin(source) self.authentication.change_password(username, password) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def confirm_message(self): msgId = formData.get("message") hk = Services.getHouseKeepingManager() if msgId is None: self.throw_error("No message ID provided") try: if msgId == "ALL": list = hk.getUserMessages(); for entry in list: if not entry.block: hk.confirmMessage(str(entry.id)); else: hk.confirmMessage(msgId); except: error = sys.exc_info()[1] self.throw_error(error.getMessage()) self.writer.println("ok") self.writer.close() def create_role(self): rolename = formData.get("field") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.create_role(rolename) err = self.authentication.get_error() if err is None: self.writer.println(rolename) self.writer.close() else: self.throw_error(err) def create_user(self): username = formData.get("username") password = formData.get("password") password_confirm = formData.get("password_confirm") if password != password_confirm: self.throw_error("The confirm password field does not match the password.") else: source = formData.get("source") self.authentication.set_auth_plugin(source) self.authentication.create_user(username, password) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def delete_role(self): rolename = formData.get("rolename") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.delete_role(rolename) err = self.authentication.get_error() if err is None: self.writer.println(rolename) self.writer.close() else: self.throw_error(err) def delete_user(self): username = formData.get("username") source = formData.get("source") self.authentication.set_auth_plugin(source) self.authentication.delete_user(username) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def get_current_access(self): record = formData.get("record") roles_list = self.authentication.get_access_roles_list(record) err = self.authentication.get_error() if err is None: # We need a JSON string for javascript plugin_strings = [] for plugin in roles_list.keys(): roles = roles_list[plugin] if len(roles) > 0: plugin_strings.append("'" + plugin + "' : ['" + "','".join(roles) + "']") else: plugin_strings.append("'" + plugin + "' : []") responseMessage = "{" + ",".join(plugin_strings) + "}" self.writer.println(responseMessage) self.writer.close() else: self.throw_error(err) def grant_access(self): record = formData.get("record") role = formData.get("role") source = formData.get("source") self.authentication.set_access_plugin(source) self.authentication.grant_access(record, role) err = self.authentication.get_error() if err is None: self.writer.println(role) self.writer.close() self.reindex_record(record) else: self.throw_error(err) def list_users(self): rolename = formData.get("rolename") source = formData.get("source") self.authentication.set_auth_plugin(source) user_list = self.authentication.list_users(rolename) err = self.authentication.get_error() if err is None: # We need a JSON string for javascript responseMessage = "{['" + "','".join(user_list) + "']}" self.writer.println(responseMessage) self.writer.close() else: self.throw_error(err) def process(self): action = formData.get("verb") switch = { "add-user" : self.add_user, "confirm-message" : self.confirm_message, "create-role" : self.create_role, "create-user" : self.create_user, "delete-role" : self.delete_role, "delete-user" : self.delete_user, "change-password" : self.change_password, "get-current-access" : self.get_current_access, "grant-access" : self.grant_access, "list-users" : self.list_users, "remove-user" : self.remove_user, "revoke-access" : self.revoke_access } switch.get(action, self.unknown_action)() def reindex_record(self, recordId): portalManager = Services.getPortalManager() portalManager.reharvest(recordId) def remove_user(self): username = formData.get("username") rolename = formData.get("rolename") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.remove_role(username, rolename) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def revoke_access(self): record = formData.get("record") role = formData.get("role") source = formData.get("source") self.authentication.set_access_plugin(source) self.authentication.revoke_access(record, role) err = self.authentication.get_error() if err is None: self.writer.println(role) self.writer.close() self.reindex_record(record) else: self.throw_error(err) def throw_error(self, message): response.setStatus(500) self.writer.println("Error: " + message) self.writer.close() def unknown_action(self): self.throw_error("Unknown action requested - '" + formData.get("verb") + "'")
class SettingsActions: def __init__(self): self.authentication = Authentication() self.authentication.session_init() self.writer = response.getPrintWriter("text/html; charset=UTF-8") if self.authentication.is_logged_in() and self.authentication.is_admin(): self.process() else: print " * settings.py : AJAX : Unauthorised access" self.throw_error("Only administrative users can access this feature") def getWatcherFile(self): configFile = FascinatorHome.getPathFile("watcher/config.json") if configFile.exists(): return JsonConfigHelper(configFile) return None def process(self): print " * settings.py: formData=%s" % formData result = "{}" portalManager = Services.getPortalManager() portal = portalManager.get(portalId) func = formData.get("func") if func == "view-update": portal.setDescription(formData.get("view-description")) portal.setQuery(formData.get("view-query")) portal.setSearchQuery(formData.get("view-search-query")) print " *** ", formData.get("view-records-per-page") portal.setRecordsPerPage(int(formData.get("view-records-per-page"))) portal.setFacetCount(int(formData.get("view-facet-count"))) portal.setFacetSort(formData.get("view-facet-sort") is not None) portalManager.save(portal) elif func == "general-update": config = JsonConfig() email = StringUtils.trimToEmpty(formData.get("general-email")) systemEmail = StringUtils.trimToEmpty(config.get("email")) print email, systemEmail if systemEmail != email: config.set("email", formData.get("general-email"), True) config.set("configured", "true", True) config.store(NullWriter(), True) # mark restart Services.getHouseKeepingManager().requestUrgentRestart() else: print " * settings.py: email not updated: did not change" self.throw_error("Email address is the same! No change saved.") elif func == "facets-update": portal.removePath("portal/facet-fields") fields = formData.getValues("field") labels = formData.getValues("label") displays = formData.getValues("display") deletes = formData.getValues("delete") for i in range(0, len(fields)): field = fields[i] if deletes[i] == "false": portal.set("portal/facet-fields/%s/label" % field, labels[i]) portal.set("portal/facet-fields/%s/display" % field, displays[i]) portalManager.save(portal) elif func == "backup-update": pathIds = formData.get("pathIds").split(",") actives = formData.getValues("backup-active") deletes = formData.getValues("backup-delete") if actives is None: actives = [] # renditions = formData.getValues("backup-rendition") # if renditions is None: # renditions = [] queries = formData.getValues("backup-queries") if queries is None: queries = [] paths = HashMap() for pathId in pathIds: if deletes is None or pathId not in deletes: path = formData.get("%s-path" % pathId) pathName = path.replace("/", "_").replace("${user.home}", "") active = str(pathId in actives).lower() # rendition = str(pathId in renditions).lower() query = str(pathId in queries).lower() ignoreFilter = formData.get("%s-ignore" % pathId) json = HashMap() json.put("path", path) json.put("active", active) json.put("include-portal-query", query) json.put("ignoreFilter", ignoreFilter) storage = HashMap() storage.put("type", "file-system") filesystem = HashMap() filesystem.put("home", path) filesystem.put("use-link", "false") storage.put("file-system", filesystem) json.put("storage", storage) paths.put(pathName, json) # reset the path first portal.setMap("portal/backup/paths", HashMap()) portal.setMultiMap("portal/backup/paths", paths) portalManager.save(portal) elif func == "watcher-update": configFile = self.getWatcherFile() if configFile is not None: pathIds = formData.get("pathIds").split(",") actives = formData.getValues("watcher-active") if actives is None: actives = [] deletes = formData.getValues("watcher-delete") if deletes is None: deletes = [] watchDirs = HashMap() for pathId in pathIds: if pathId not in deletes: path = formData.get("%s-path" % pathId) stopped = str(pathId not in actives).lower() watchDir = HashMap() watchDir.put("ignoreFileFilter", formData.get("%s-file" % pathId)) watchDir.put("ignoreDirectories", formData.get("%s-dir" % pathId)) watchDir.put("cxtTags", []) watchDir.put("stopped", stopped) watchDirs.put(path, watchDir) json = JsonConfigHelper(self.getWatcherFile()) json.setMap("watcher/watchDirs", watchDirs) json.store(FileWriter(configFile), True) else: result = "The Watcher is not installed properly." elif func == "restore-default-config": # backup the file JsonConfig.backupSystemFile() # delete the file JsonConfig.getSystemFile().delete() # restore default JsonConfig.getSystemFile() # mark restart Services.getHouseKeepingManager().requestUrgentRestart() elif func == "housekeeping-update": config = JsonConfig() freq = StringUtils.trimToEmpty(formData.get("housekeeping-timeout")) systemFreq = StringUtils.trimToEmpty(config.get("portal/houseKeeping/config/frequency")) result = "House Keeper refreshed" if systemFreq != freq: config.set("portal/houseKeeping/config/frequency", freq, True) config.store(NullWriter(), True) result = "Frequency updated, refreshing House Keeper" # Refresh the HouseKeeper message = JsonConfigHelper() message.set("type", "refresh") Services.getHouseKeepingManager().sendMessage(message.toString()) self.writer.println(result) self.writer.close() def throw_error(self, message): response.setStatus(500) self.writer.println("Error: " + message) self.writer.close()
class LoginData: def __init__(self): self.authentication = Authentication() self.authentication.session_init() self.writer = response.getPrintWriter("text/html") if self.authentication.is_logged_in() and self.authentication.is_admin(): self.process() else: self.throw_error("Only administrative users can access this feature") def add_user(self): username = formData.get("field") rolename = formData.get("hidden") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.set_role(username, rolename) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def change_password(self): username = formData.get("username") password = formData.get("password") password_confirm = formData.get("password_confirm") if password != password_confirm: self.throw_error("The confirm password field does not match the password.") else: source = formData.get("source") self.authentication.set_auth_plugin(source) self.authentication.change_password(username, password) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def create_role(self): rolename = formData.get("field") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.create_role(rolename) err = self.authentication.get_error() if err is None: self.writer.println(rolename) self.writer.close() else: self.throw_error(err) def create_user(self): username = formData.get("username") password = formData.get("password") password_confirm = formData.get("password_confirm") if password != password_confirm: self.throw_error("The confirm password field does not match the password.") else: source = formData.get("source") self.authentication.set_auth_plugin(source) self.authentication.create_user(username, password) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def delete_role(self): rolename = formData.get("rolename") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.delete_role(rolename) err = self.authentication.get_error() if err is None: self.writer.println(rolename) self.writer.close() else: self.throw_error(err) def delete_user(self): username = formData.get("username") source = formData.get("source") self.authentication.set_auth_plugin(source) self.authentication.delete_user(username) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def list_users(self): rolename = formData.get("rolename") source = formData.get("source") self.authentication.set_auth_plugin(source) user_list = self.authentication.list_users(rolename) err = self.authentication.get_error() if err is None: # We need a JSON string for javascript responseMessage = "{['" + "','".join(user_list) + "']}" self.writer.println(responseMessage) self.writer.close() else: self.throw_error(err) def process(self): action = formData.get("verb") switch = { "add-user" : self.add_user, "create-role" : self.create_role, "create-user" : self.create_user, "delete-role" : self.delete_role, "delete-user" : self.delete_user, "change-password" : self.change_password, "list-users" : self.list_users, "remove-user" : self.remove_user } switch.get(action, self.unknown_action)() def remove_user(self): username = formData.get("username") rolename = formData.get("rolename") source = formData.get("source") self.authentication.set_role_plugin(source) self.authentication.remove_role(username, rolename) err = self.authentication.get_error() if err is None: self.writer.println(username) self.writer.close() else: self.throw_error(err) def throw_error(self, message): response.setStatus(500) self.writer.println("Error: " + message) self.writer.close() def unknown_action(self): self.throw_error("Unknown action requested - '" + formData.get("verb") + "'")