def get_client_ip(client=None, use_html=False, lan_interface=None):
	"""Generate output of the client IP."""
	theResult = None
	try:
		if lan_interface not in interfaces.INTERFACE_CHOICES:
			lan_interface = interfaces.INTERFACE_CHOICES[0]
		ip_list_txt = utils.extractIPv4(get_client_arp_status_raw(client, lan_interface))
		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 = None
		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'client_status_ips_{}')
				).format(client)
			else:
				theResult = html_generator.gen_html_td(
					html_generator.gen_html_label(u'No IP', html_generator.HTML_LABEL_ROLES[3]),
					str(u'client_status_ips_{}').format(client)
				)
	except Exception as errcrit:
		print(str(errcrit))
		print(str(errcrit.args))
		theResult = None
	return theResult
def get_iface_ip_list(iface=u'lo', use_html=False):
    """Generate output of the iface IP."""
    theResult = None
    temp_buffer = get_iface_status_raw(iface)
    if temp_buffer is None:
        theResult = None
        ip_list_txt = None
    else:
        ip_list_txt_raw = utils.extractIPAddr(get_iface_status_raw(iface))
        ip_list_txt = [x for x in ip_list_txt_raw if not x.endswith(".255")]
        del ip_list_txt_raw
    if use_html is False:
        if ip_list_txt is not None and len(ip_list_txt) > 0:
            theResult = str(ip_list_txt)
        else:
            theResult = None
    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'iface_status_ips_{}').format(iface))
        else:
            theResult = html_generator.gen_html_td(
                html_generator.gen_html_label(
                    u'No IP', html_generator.HTML_LABEL_ROLES[3]),
                str(u'iface_status_ips_{}').format(iface))
    return theResult
def get_client_mac(client=None, use_html=False, lan_interface=None):
	"""Generate output of the client mac."""
	if client is None and use_html is not True:
		return None
	if lan_interface not in interfaces.INTERFACE_CHOICES:
		lan_interface = interfaces.INTERFACE_CHOICES[0]
	theResult = None
	try:
		mac_list_txt = utils.extractMACAddr(get_client_arp_status_raw(client, lan_interface))
		if use_html is not True:
			if (mac_list_txt is not None) and (len(mac_list_txt) > 0):
				theResult = str(mac_list_txt[0])
			else:
				theResult = None
		else:
			if mac_list_txt is not None and len(mac_list_txt) > 0:
				theResult = html_generator.gen_html_td(
					str(mac_list_txt[0]),
					str(u'client_status_macs_{}')
				).format(client)
			else:
				theResult = html_generator.gen_html_td(
					html_generator.gen_html_label(u'No IP', html_generator.HTML_LABEL_ROLES[3]),
					str(u'client_status_macs_{}').format(client)
				)
	except Exception as errcrit:
		print(str(errcrit))
		print(str(errcrit.args))
		theResult = None
	return theResult
def get_user_ttys(user=None, use_html=False):
	"""Generate output of the user ttys."""
	if (user is None) and (use_html is not True):
		return None
	elif (user is None) and (use_html is True):
		return html_generator.gen_html_label(u'UNKNOWN', u'warning')
	# otherwise
	theResult = None
	try:
		raw_data = get_user_work_status_raw(user)
		if raw_data is None:
			return u'UNKNOWN'
		tty_list_txt = utils.extractTTYs(raw_data)
		if use_html is not True:
			if tty_list_txt is not None and len(tty_list_txt) > 0:
				theResult = str(tty_list_txt)
			else:
				theResult = u'console'
		else:
			theResult = html_generator.gen_html_td(
				html_generator.gen_html_ul(tty_list_txt),
				str(u'user_status_tty_{}').format(user)
			)
	except Exception as errcrit:
		if not use_html:
			logs.log(
				str("user_check_status.get_user_ttys: 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 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_iface_mac(iface, use_html=False):
    """Generate output of the iface mac."""
    theResult = None
    tainted_name = interfaces.taint_name(iface)
    mac_list_txt = utils.extractMACAddr(get_iface_status_raw(tainted_name))
    if use_html is False:
        if mac_list_txt is not None and (len(mac_list_txt) > 0):
            theResult = str(mac_list_txt[0])
        else:
            theResult = None
    else:
        if mac_list_txt is not None and (len(mac_list_txt) > 0):
            theResult = html_generator.gen_html_td(
                str(mac_list_txt[0]),
                str(u'iface_status_mac_{}').format(tainted_name))
        else:
            theResult = html_generator.gen_html_td(
                "",
                str(u'iface_status_mac_{}').format(tainted_name))
    return theResult
def get_iface_name(iface_name=None, use_html=False):
    tainted_iface_name = interfaces.taint_name(iface_name)
    if tainted_iface_name is None:
        return None
    if use_html is not True:
        return tainted_iface_name
    else:
        iface = str(get_iface_name(tainted_iface_name, False))
        return html_generator.gen_html_td(
            iface,
            str(u'iface_status_dev_{}').format(iface))
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_name(user_name=None, use_html=False):
	if user_name is None:
		return None
	if use_html is not True:
		temp = get_user_list()
		if utils.literal_str(user_name) in temp:
			temp = None
			del temp
			return utils.literal_str(user_name)
		else:
			temp = None
			del temp
			return None
	else:
		user = utils.literal_str(get_user_name(user_name, False))
		return html_generator.gen_html_td(user, str(u'user_name_{}').format(user))
def get_client_name(client_ip=None, use_html=False, lan_interface=None):
	if lan_interface not in interfaces.INTERFACE_CHOICES:
		lan_interface = interfaces.INTERFACE_CHOICES[0]
	if client_ip is None:
		return None
	if use_html is not True:
		temp_name_raw = get_client_arp_status_raw(client_ip, lan_interface)
		temp_name = None
		if temp_name_raw is not None and len(temp_name_raw) > 0:
			temp_name = temp_name_raw.split(u' ', 1)[0]
		if temp_name is not None and len(temp_name) > 0:
			return temp_name
		else:
			return str("UNKNOWN")
	else:
		client = str(get_client_name(client_ip, False))
		return html_generator.gen_html_td(client, str(u'client_status_{}').format(client))
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