def view_log(request, module_name):
	"""
	Parses and shows log contents for a given module.

	@param request HTTP request
	@param string name of module
	@return string log contents for a given module
	"""
		
	must_have_permission(request.user, User, "can_manage_users")

	log_content = ""
	found_group = ""
	module_log_path = get_module_log_path(module_name)
	try:
		# Reads the Nth last lines from the log file
		module_log = get_log_chunk(open(module_log_path), LOG_N_BYTES_SIZE)  #open(module_log_path).read().splitlines()[-LOG_N_LAST_LINES:]
		for i, line in enumerate(module_log):
			while re.search("\[(.*?)\]", line):
				found_group = re.search("\[(.*?)\]", line).group(0)
				log_content += "<font color=\"%s\"><strong>%s</strong></font>" % (str(LOG_HEADER_COLOR), str(found_group))
				line = line.replace(found_group, "")
			log_content += line + "<br/>"
	except Exception as e:
		log_content = "Not enough permissions to view %s log" % str(module_name).capitalize()

	return simple.direct_to_template(
		request,
		template=TEMPLATE_PATH+"/log.html",
		extra_context={
			"log_content": log_content,
		},
	)
def remove_log(request, module_name, option):
	"""
	Clears log contents for a given module.

	@param request HTTP request
	@param string name of module
	@return redirection back to the administration home
	"""
		
	must_have_permission(request.user, User, "can_manage_users")

	module_log_path = get_module_log_path(module_name)
	try:
		if option == "preserve":
			import datetime
			now = datetime.datetime.now()
			timestamp = "%s-%s-%s_%s:%s:%s" % (now.year, now.month, now.day, now.hour, now.minute, now.second)
			p = subprocess.Popen(["mv",module_log_path,
								"%s.%s" % (module_log_path, timestamp)], 
				stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = p.communicate()
		elif option == "clear":
			p = subprocess.Popen(["rm",module_log_path], 
				stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = p.communicate()
		# New log file is created regardless of chosen option
		if option:
			p = subprocess.Popen(["touch",module_log_path], 
				stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = p.communicate()
	except:
		pass

	return HttpResponseRedirect(reverse("administration_home"))
Beispiel #3
0
def view_log(request, module_name):
	"""
	Parses and shows log contents for a given module.

	@param request HTTP request
	@param string name of module
	@return string log contents for a given module
	"""
		
	must_have_permission(request.user, User, "can_manage_users")

	log_content = ""
	found_group = ""
	module_log_path = get_module_log_path(module_name)
	try:
		# Reads the Nth last lines from the log file
		module_log = get_log_chunk(open(module_log_path), LOG_N_BYTES_SIZE)  #open(module_log_path).read().splitlines()[-LOG_N_LAST_LINES:]
		for i, line in enumerate(module_log):
			while re.search("\[(.*?)\]", line):
				found_group = re.search("\[(.*?)\]", line).group(0)
				log_content += "<font color=\"%s\"><strong>%s</strong></font>" % (str(LOG_HEADER_COLOR), str(found_group))
				line = line.replace(found_group, "")
			log_content += line + "<br/>"
	except Exception as e:
		log_content = "Not enough permissions to view %s log" % str(module_name).capitalize()

	return simple.direct_to_template(
		request,
		template=TEMPLATE_PATH+"/log.html",
		extra_context={
			"log_content": log_content,
		},
	)
Beispiel #4
0
def home(request):
	"""
	Shows the Expedient administration panel.

	@param request HTTP request
	@return string template for administration panel
	"""
	must_have_permission(request.user, User, "can_manage_users")

	# Iterate over each plugin to get its administration data
	plugin_administration_methods = []
	for plugin in PluginLoader.plugin_settings:
		try:
			plugin_administration_methods.append([str(plugin.capitalize()), reverse("%s_administration" % str(plugin))])
		except:
			pass
#		except Exception as e:
#			print "[ERROR] Problem loading plugin administration methods inside administration module. Details: %s" % str(e)

	return simple.direct_to_template(
		request,
		template=TEMPLATE_PATH+"/index.html",
		extra_context={
			"breadcrumbs": (
				("Home", reverse("home")),
				("Administration", reverse("administration_home")),
			),
			"plugin_administration_methods": plugin_administration_methods,
			"logs_location":LOGS_LOCATION,
		},
	)
Beispiel #5
0
def remove_log(request, module_name, option):
	"""
	Clears log contents for a given module.

	@param request HTTP request
	@param string name of module
	@return redirection back to the administration home
	"""
		
	must_have_permission(request.user, User, "can_manage_users")

	module_log_path = get_module_log_path(module_name)
	try:
		if option == "preserve":
			import datetime
			now = datetime.datetime.now()
			timestamp = "%s-%s-%s_%s:%s:%s" % (now.year, now.month, now.day, now.hour, now.minute, now.second)
			p = subprocess.Popen(["mv",module_log_path,
								"%s.%s" % (module_log_path, timestamp)], 
				stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = p.communicate()
		elif option == "clear":
			p = subprocess.Popen(["rm",module_log_path], 
				stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = p.communicate()
		# New log file is created regardless of chosen option
		if option:
			p = subprocess.Popen(["touch",module_log_path], 
				stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = p.communicate()
	except:
		pass

	return HttpResponseRedirect(reverse("administration_home"))
Beispiel #6
0
def home(request):
    """
	Shows the Expedient administration panel.

	@param request HTTP request
	@return string template for administration panel
	"""
    must_have_permission(request.user, User, "can_manage_users")

    # Iterate over each plugin to get its administration data
    plugin_administration_methods = []
    # Load plug-in settings, if needed
    if not PluginLoader.plugin_settings:
        PluginLoader.load_settings()
    for plugin in PluginLoader.plugin_settings:
        try:
            plugin_administration_methods.append([
                str(plugin.capitalize()),
                reverse("%s_administration" % str(plugin))
            ])
        except:
            pass


#		except Exception as e:
#			print "[ERROR] Problem loading plugin administration methods inside administration module. Details: %s" % str(e)
    extra_context = {
        "breadcrumbs": (
            ("Home", reverse("home")),
            ("Administration", reverse("administration_home")),
        ),
        "plugin_administration_methods":
        plugin_administration_methods,
        "logs_location":
        LOGS_LOCATION,
    }
    # CBAS-related data
    try:
        cbas_variables = ["CBAS_HOST_NAME", "CBAS_HOST_IP", "CBAS_HOST_PORT"]
        from django.conf import settings
        [getattr(settings, cbas_var) for cbas_var in cbas_variables]
    except:
        from expedient.clearinghouse.defaultsettings import cbas as settings
    cbas_context = {
        "CBAS_STATUS": is_cbas_server_active(),
        "CBAS_NAME": settings.CBAS_HOST_NAME,
        "CBAS_IP_ADDR": settings.CBAS_HOST_IP,
        "CBAS_PORT": settings.CBAS_HOST_PORT
    }
    extra_context.update(cbas_context)
    return simple.direct_to_template(request,
                                     template=TEMPLATE_PATH + "/index.html",
                                     extra_context=extra_context)
def home(request):
	"""
	Shows the Expedient administration panel.

	@param request HTTP request
	@return string template for administration panel
	"""
	must_have_permission(request.user, User, "can_manage_users")

	# Iterate over each plugin to get its administration data
	plugin_administration_methods = []
	# Load plug-in settings, if needed
	if not PluginLoader.plugin_settings:
		PluginLoader.load_settings()
	for plugin in PluginLoader.plugin_settings:
		try:
			plugin_administration_methods.append([str(plugin.capitalize()), reverse("%s_administration" % str(plugin))])
		except:
			pass
#		except Exception as e:
#			print "[ERROR] Problem loading plugin administration methods inside administration module. Details: %s" % str(e)
	extra_context = {
	                "breadcrumbs": (
	                        ("Home", reverse("home")),
	                        ("Administration", reverse("administration_home")),
	                ),
	                "plugin_administration_methods": plugin_administration_methods,
	                "logs_location":LOGS_LOCATION,
	        }
	# CBAS-related data
        try:
            cbas_variables = ["CBAS_HOST_NAME", "CBAS_HOST_IP", "CBAS_HOST_PORT"]
            from django.conf import settings
            [ getattr(settings, cbas_var) for cbas_var in cbas_variables ]
        except:
            from expedient.clearinghouse.defaultsettings import cbas as settings
	cbas_context = {"CBAS_STATUS": is_cbas_server_active(),
	                "CBAS_NAME": settings.CBAS_HOST_NAME,
	                "CBAS_IP_ADDR": settings.CBAS_HOST_IP,
	                "CBAS_PORT": settings.CBAS_HOST_PORT}
        extra_context.update(cbas_context)
	return simple.direct_to_template(
		request,
		template=TEMPLATE_PATH+"/index.html",
		extra_context=extra_context
	)