def generate_iface_status_html_raw(iface=u'lo', status="UNKNOWN", lable=None):
    """Generates the raw html for interface of given status with the given lable"""
    if lable in html_generator.HTML_LABEL_ROLES:
        theResult = html_generator.gen_html_td(
            html_generator.gen_html_label(str(status), lable),
            str(u'iface_status_value_{}').format(iface))
    else:
        theResult = generate_iface_status_html_raw(
            iface, "UNKNOWN", html_generator.HTML_LABEL_ROLES[0])
    return theResult
def get_client_status(client=None, use_html=False, lan_interface=None):  # noqa C901
	"""Generate the status"""
	theResult = None
	try:
		if lan_interface not in interfaces.INTERFACE_CHOICES:
			lan_interface = interfaces.INTERFACE_CHOICES[0]
		client_mac = get_client_mac(client, False, lan_interface)
		status_txt = get_client_sta_status(client_mac)
		if client_mac is not None:
			status_txt = None
			status_txt = get_client_sta_status(client_mac)
		if use_html is not True and status_txt is not None:
			if (str("disassociated") in status_txt):
				theResult = u'disassociated'
			elif (str("associated") in status_txt):
				theResult = u'associated'
			else:
				theResult = u'UNKNOWN'
		elif status_txt is not None:
			if (str("disassociated") in status_txt):
				theResult = html_generator.gen_html_td(
					html_generator.gen_html_label(u'disassociated', u'danger'),
					str(u'client_status_value_{}').format(client)
				)
			elif (str("associated") in status_txt):
				theResult = html_generator.gen_html_td(
					html_generator.gen_html_label(u'associated', u'success'),
					str(u'client_status_value_{}').format(client)
				)
			else:
				theResult = html_generator.gen_html_td(
					html_generator.gen_html_label(u'UNKNOWN', u'default'),
					str(u'client_status_value_{}').format(client)
				)
	except Exception as errcrit:
		print(str(errcrit))
		print(str(errcrit.args))
		theResult = None
	return theResult
def get_user_ip(user=None, use_html=False):
	"""Generate output of the user IP."""
	theResult = None
	try:
		raw_data = get_user_work_status_raw(user)
		if raw_data is not None:
			ip_list_txt = utils.extractIPv4(raw_data)
			if use_html is not True:
				if (ip_list_txt is not None) and (len(ip_list_txt) > 0):
					theResult = str(ip_list_txt[0])
				else:
					theResult = getLocalhostName()
			else:
				if (ip_list_txt is not None) and (len(ip_list_txt) > 0):
					theResult = html_generator.gen_html_td(
						html_generator.gen_html_ul(ip_list_txt),
						str(u'user_status_ips_{}').format(user)
					)
				else:
					theResult = html_generator.gen_html_td(
						html_generator.gen_html_label(getLocalhostName(), u'disabled'),
						str(u'user_status_ips_{}').format(user)
					)
		else:
			if (use_html is True):
				theResult = html_generator.gen_html_label(u'UNKNOWN', u'warning')
			else:
				theResult = "UNKNOWN"
	except Exception as errcrit:
		if not use_html:
			logs.log(
				str("user_check_status.get_user_ip: ERROR: ACTION will not be completed! ABORT!"),
				"Error"
			)
			logs.log(str(type(errcrit)), "Error")
			logs.log(str(errcrit), "Error")
			logs.log(str((errcrit.args)), "Error")
		theResult = "UNKNOWN"
	return theResult
def get_user_status(user_name=None, use_html=False):  # noqa C901
	"""Generate the status"""
	theResult = None
	try:
		user_tty = None
		status_list = []
		t_user_name = taint_name(user_name)
		if taint_name(user_name) is not None:
			user_tty = get_user_ttys(t_user_name, False)
		status_txt = get_system_work_status_raw(t_user_name)
		if (user_tty is not None) and (str(user_tty).lower() not in str("console")):
			status_txt = get_user_work_status_raw(t_user_name)
			if status_txt is None:
				status_list = ["UNKNOWN"]
			else:
				status_list = utils.compactList(
					[str(
						str(x).split(u' ', 4)[-1]
					) for x in status_txt.split(u'\n') if (x is not None) and (len(x) > 0)]
				)
		elif status_txt is not None:
			if (str("root SYSTEM\n") not in status_txt):
				theWorks = utils.compactList(
					[str(
						str(x).split(u' ', 1)[1:]
					) for x in status_txt.split("""\n""") if (x is not None) and (len(x) > 0)]
				)
				known_work_cases = getKnownProcessesTable()
				for theWork in theWorks:
					temp_txt = "UNKNOWN"
					if ("SYSTEM" in theWork):
						temp_txt = "SYSTEM"
					else:
						for known_case in known_work_cases.keys():
							if (known_case in theWork):
								temp_txt = known_work_cases[known_case]
					status_list.append(str(_util_generate_user_status_lable(temp_txt, use_html)))
				status_list = utils.compactList(status_list)
			else:
				if use_html is True:
					status_list = [str(html_generator.gen_html_label(u'System', u'info'))]
				else:
					status_list = ["SYSTEM"]
		if use_html is not True:
			theResult = status_list
		else:
			theResult = html_generator.gen_html_td(
				html_generator.gen_html_ul(status_list),
				str(u'user_status_what_{}').format(t_user_name)
			)
		status_list = None
		del status_list
		status_txt = None
		del status_txt
		user_tty = None
		del user_tty
	except Exception as errcrit:
		if not use_html:
			logs.log(
				str("user_check_status.get_user_status: ERROR: ACTION will not be completed! ABORT!"),
				"Error"
			)
			logs.log(str(type(errcrit)), "Error")
			logs.log(str(errcrit), "Error")
			logs.log(str((errcrit.args)), "Error")
		theResult = None
	return theResult
def _util_generate_user_status_lable(input_txt, use_html=False):
	_LABEL_KEYS = {
		u'[priv]': html_generator.gen_html_label(u'Admin Task', u'danger'),
		u'AUTOMATION': html_generator.gen_html_label(u'Automation', u'info'),
		u'DEFENSE': html_generator.gen_html_label(u'Defense', u'success'),
		u'OFFENSE': html_generator.gen_html_label(u'Offense', u'primary'),
		u'NETWORK SERVICES': html_generator.gen_html_label(u'Network', u'info'),
		u'LOGGING SERVICES': html_generator.gen_html_label(u'Logging', u'info'),
		u'TIMEKEEPING SERVICES': html_generator.gen_html_label(u'Clock', u'info'),
		u'SYSTEM': html_generator.gen_html_label(u'System', u'info'),
		u'UNKNOWN': html_generator.gen_html_label(u'UNKNOWN', u'warning')
	}
	found_match = False
	if use_html is True:
		for somekey in _LABEL_KEYS.keys():
			if found_match is True:
				continue
			elif (somekey in input_txt):
				found_match = True
				input_txt = _LABEL_KEYS[somekey]
		if found_match is False:
			if u'DNS' in input_txt and u'SERVICES' in input_txt:
				input_txt = html_generator.gen_html_label(u'Local Domain', u'info')
			else:
				input_txt = html_generator.gen_html_label(input_txt, u'disabled')
	return input_txt