def MachineBox(mach): """mach could be an IP address, a machine name, None, "localhost" etc...""" if lib_util.is_local_address(mach): the_machine_box = gUriGen else: the_machine_box = RemoteBox(mach) return the_machine_box
def Main(): # This can process remote hosts because it does not call any script, just shows them. cgiEnv = lib_common.ScriptEnvironment( can_process_remote=True, parameters={lib_util.paramkeyShowAll: False}) entity_id = cgiEnv.m_entity_id entity_host = cgiEnv.GetHost() flag_show_all = int(cgiEnv.get_parameters(lib_util.paramkeyShowAll)) name_space, entity_type = cgiEnv.get_namespace_type() if lib_util.is_local_address(entity_host): entity_host = "" logging.debug("entity: entity_host=%s entity_type=%s entity_id=%s", entity_host, entity_type, entity_id) grph = cgiEnv.GetGraph() root_node = lib_util.RootUri() if entity_id != "" or entity_type == "": def callback_grph_add(tripl, depth_call): grph.add(tripl) recursive_walk_on_scripts(callback_grph_add, root_node, entity_type, entity_id, entity_host, flag_show_all) cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_directory, pc.property_script])
def Main(): cgiEnv = lib_common.ScriptEnvironment() hostname = cgiEnv.GetId() node_host = lib_uris.gUriGen.HostnameUri(hostname) grph = cgiEnv.GetGraph() try: lib_win32.WNetAddConnect(hostname) except Exception as exc: lib_common.ErrorMessageHtml("NetUserEnum:" + str(exc)) # This could be a parameter. Hard-coded value for the moment. if lib_util.is_local_address(hostname): level = 2 # 1,2 else: level = 2 # 1,2 logging.debug("hostname=%s level=%d", hostname, level) resume_handle = 0 while True: try: # Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. # The command also controls persistent net connections. Used without parameters, net use retrieves a list of network connections. # net use [{DeviceName | *}] [\\ComputerName\ShareName[\volume]] [{Password | *}]] [/user:[DomainName\]UserName] # [/user:[DottedDomainName\]UserName] [/user: [UserName@DottedDomainName] [/savecred] [/smartcard] [{/delete | /persistent:{yes | no}}] # https://mail.python.org/pipermail/python-win32/2003-April/000961.html lst_users, total, resume_handle = win32net.NetUserEnum( hostname, level, win32netcon.FILTER_NORMAL_ACCOUNT, resume_handle) except Exception as exc: lib_common.ErrorMessageHtml("NetUserEnum:" + str(exc)) for usr_elt in lst_users: # {'comment': u'Built-in account for administering the computer/domain', 'workstations': u'', 'country_code': 0L, 'last_logon': 1426 # 729970L, 'full_name': u'', 'parms': u'', 'code_page': 0L, 'priv': 2L, 'auth_flags': 0L, 'logon_server': u'\\\\*', 'home_dir': u'', ' # usr_comment': u'', 'acct_expires': 4294967295L, 'bad_pw_count': 0L, 'logon_hours': '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff # \xff\xff\xff\xff\xff\xff\xff\xff\xff', 'password': None, 'units_per_week': 168L, 'last_logoff': 0L, 'name': u'Administrator', 'max_s # torage': 4294967295L, 'num_logons': 11L, 'password_age': 191184801L, 'flags': 66083L, 'script_path': u''}, user_name = usr_elt['name'] node_user = survol_Win32_UserAccount.MakeUri(user_name, hostname) grph.add((node_host, pc.property_user, node_user)) try: txt_comment = usr_elt['comment'] grph.add((node_user, pc.property_information, lib_util.NodeLiteral(txt_comment))) except KeyError: pass if resume_handle == 0: break cgiEnv.OutCgiRdf()
def test_remote_if_possible(self,can_process_remote): # This is probably too generous to indicate a local host. if can_process_remote or self.m_entity_host is None: return if lib_util.is_local_address(self.m_entity_host): return ErrorMessageHtml("Script %s cannot handle remote hosts on host=%s" % (sys.argv[0], self.m_entity_host))
def Main(): cgiEnv = lib_common.ScriptEnvironment() hostname = cgiEnv.GetId() nodeHost = lib_uris.gUriGen.HostnameUri(hostname) grph = cgiEnv.GetGraph() # Loop over the shares. shareresume = 0 while 1: try: # If running on the local machine, pass the host as None otherwise authorization is checked # just like a remote machine, which means User Account Control (UAC) disabling, # and maybe setting LocalAccountTokenFilterPolicy=1 if lib_util.is_local_address(hostname): hostname_or_None = None level = 2 # 1,2 else: hostname_or_None = hostname level = 1 # 1,2 sharedata, total, shareresume = win32net.NetShareEnum( hostname_or_None, level, shareresume) except Exception as exc: # "Access is denied." lib_common.ErrorMessageHtml("Hostname=" + hostname + ". Exception:" + str(exc)) for share in sharedata: logging.debug("share=%s", str(share)) # share={'remark': 'Remote Admin', 'passwd': None, 'current_uses': 0, 'netname': 'ADMIN$', 'max_uses': 4294967295, 'path': 'C:\\\\Windows', 'type': 2147483648, 'permissions': 0} share_netname = share['netname'] try: share_path = share['path'] share_remark = share['remark'] except: share_path = "" share_remark = "" shareNode = lib_uris.MachineBox(hostname).SmbShareUri( share_netname) grph.add((nodeHost, pc.property_smbshare, shareNode)) if share_path: mountNode = lib_uris.gUriGen.FileUri(share_path) grph.add((shareNode, pc.property_smbmount, mountNode)) if share_remark: grph.add((shareNode, pc.property_information, lib_util.NodeLiteral(share_remark))) if not shareresume: break cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) try: # Exception if local machine. host_name = cgiEnv.m_entity_id_dict["Domain"] except KeyError: host_name = None if lib_util.is_local_address(host_name): server_box = lib_uris.gUriGen serv_name_or_none = None else: server_box = lib_common.RemoteBox(host_name) serv_name_or_none = host_name try: lib_win32.WNetAddConnect(host_name) except Exception as exc: lib_common.ErrorMessageHtml("Error WNetAddConnect %s:%s" % (host_name, str(exc))) user_name = cgiEnv.m_entity_id_dict["Name"] logging.debug("host_name=%s user_name=%s", host_name, user_name) grph = cgiEnv.GetGraph() node_user = survol_Win32_UserAccount.MakeUri(user_name, host_name) # TODO: And NetUserGetGroups ?? # [(group_name, attribute), ...] = NetUserGetGroups(serverName, user_name ) try: resu_list = win32net.NetUserGetLocalGroups(serv_name_or_none, user_name) except Exception as exc: lib_common.ErrorMessageHtml("Error:user_name=" + user_name + ":serv_name_or_none=" + str(serv_name_or_none) + ":" + str(exc)) for group_name in resu_list: node_group = survol_Win32_Group.MakeUri(group_name, host_name) grph.add((node_user, pc.property_group, node_group)) if host_name: node_group_remote = server_box.node_from_dict( "Win32_Group", { "Name": group_name, "Domain": host_name }) # TODO: Instead, both object must have the same universal alias grph.add((node_group, pc.property_alias, node_group_remote)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) machine_name = cgiEnv.GetId() grph = cgiEnv.GetGraph() if lib_util.is_local_address(machine_name): mach_name_or_none = None server_box = lib_uris.gUriGen else: mach_name_or_none = machine_name server_box = lib_uris.RemoteBox(machine_name) try: login_implicit = False # IF FACT, WHY SHOULD IT BE SET ???????? if login_implicit or mach_name_or_none is None: cnnct = wmi.WMI(machine_name) else: # persistent net connection # This works: # >>> c = wmi.WMI(wmi=wmi.connect_server(server='Titi', namespace="/root/cimv2", user='******', password='******')) logging.debug("Explicit WMI connection machine_name=%s", machine_name) cnnct = lib_wmi.WmiConnect(machine_name, "/root/cimv2") except Exception as exc: lib_common.ErrorMessageHtml("WMI " + machine_name + " partitions:" + str(exc)) for physical_disk in cnnct.Win32_DiskDrive(): node_disk = server_box.DiskUri(physical_disk.Name.replace('\\', '/')) grph.add((node_disk, pc.property_information, lib_util.NodeLiteral(physical_disk.MediaType))) for partition in physical_disk.associators( "Win32_DiskDriveToDiskPartition"): for logical_disk in partition.associators( "Win32_LogicalDiskToPartition"): # BEWARE: What we call partition is in fact a logical disk. # This is not really important for this application, # as long as there are two levels in a disk description. node_partition = server_box.DiskPartitionUri(logical_disk.Name) grph.add((node_partition, pc.property_information, lib_util.NodeLiteral(logical_disk.Description))) grph.add((node_partition, pc.property_file_system_type, lib_util.NodeLiteral(logical_disk.FileSystem))) # The logical disk name is the same as the mount point. grph.add((node_partition, pc.property_partition, node_disk)) grph.add((server_box.DirectoryUri(logical_disk.Name), pc.property_mount, node_partition)) cgiEnv.OutCgiRdf()
def test_is_local_address(self): """ This tests if a local address is correctly detected. """ self.assertTrue(lib_util.is_local_address(None)) self.assertTrue(lib_util.is_local_address("localhost")) self.assertTrue(lib_util.is_local_address("127.0.0.1")) self.assertTrue(lib_util.is_local_address(socket.gethostname())) self.assertFalse(lib_util.is_local_address("1.2.3.4")) self.assertFalse(lib_util.is_local_address("www.google.com"))
def AddrUri(self, addr, socket_port, transport="tcp"): # The standard id encodes the port as an integer. # But addr.EntityName() displays it with getservbyport try: socket_port_number = socket.getservbyname(socket_port) except: socket_port_number = int(socket_port) # addr could be "LOCALHOST" if lib_util.is_local_address(addr): # TODO: Should use the actual IP address. addr = "127.0.0.1" url = "%s:%d" % (addr, socket_port_number) if transport != 'tcp': # This will happen rarely. url += ":" + transport # TODO: THIS IS WHERE WE SHOULD MAYBE ALWAYS USE A RemoteBox(). return self.node_from_args("addr", url)
def _known_script_to_title(fil_script, uri_mode, entity_host=None, entity_suffix=None): """Extra information depending on the script.""" # Special display if MIME URL if fil_script == "entity_mime.py": if not entity_suffix: entity_suffix = "None" # The Mime type is embedded into the mode, after a "mime:" prefix. entity_label = entity_suffix + " (" + lib_mime.mode_to_mime_type(uri_mode) + ")" return entity_label # The label is a Survol module name which is a class (With an EntityOntology() function), # or a namespace. So we give the right title. if fil_script == "class_type_all.py": moduOntology = lib_util.OntologyClassKeys(entity_suffix) if moduOntology: entity_label = entity_suffix + " (Class)" else: entity_label = entity_suffix + " (Domain)" return entity_label try: entity_label = _scripts_to_titles[fil_script] except KeyError: entity_label = fil_script + "..." if entity_suffix: if entity_label: entity_label = entity_suffix + " (" + entity_label + ")" else: entity_label = entity_suffix # Maybe hostname is a CIMOM address (For WBEM) or a machine name. if entity_host: if not lib_util.is_local_address(entity_host): # If this is a CIMOM, make it shorter: "http://vps516494.ovh.net:5988" or ""https://vps516494.ovh.net:5989" host_only = lib_util.EntHostToIp(entity_host) entity_label += " at " + host_only # TODO: Add the host name in the title. return entity_label
def _calc_label(entity_host, entity_type, entity_id, force_entity_ip_addr, fil_script): """ This calculates the label of an instance, also taking into account the script. """ nam_spac, entity_type_no_ns = lib_util.parse_namespace_type(entity_type) if not force_entity_ip_addr and not lib_util.is_local_address(entity_host): entity_label = "Unset entity_label" if fil_script == "entity_wbem.py": import lib_wbem # Because of WBEM, entity_host is a CIMOM url, like "http://vps516494.ovh.net:5988" entity_label = lib_wbem.EntityToLabelWbem(nam_spac, entity_type_no_ns, entity_id, entity_host) if not entity_label: # Fallback to Survol label. actual_host = lib_util.EntHostToIp(entity_host) entity_label = entity_to_label(entity_type_no_ns, entity_id, actual_host) elif fil_script == "entity_wmi.py": import lib_wmi # For WMI, the hostname is a NETBIOS machine name. entity_label = lib_wmi.EntityToLabelWmi(nam_spac, entity_type_no_ns, entity_id, entity_host) if not entity_label: # Fallback to Survol label. actual_host = lib_util.EntHostToIp(entity_host) entity_label = entity_to_label(entity_type_no_ns, entity_id, actual_host) else: # filScript in [ "class_type_all.py", "entity.py" ], or if no result from WMI or WBEM. entity_label = entity_to_label(entity_type_no_ns, entity_id, entity_host) elif entity_type_no_ns or entity_id: entity_label = entity_to_label(entity_type_no_ns, entity_id, force_entity_ip_addr) else: # Only possibility to print something meaningful. entity_label = nam_spac # Some corner cases: "http://127.0.0.1/Survol/survol/entity.py?xid=CIM_ComputerSystem.Name=" if not entity_label: entity_label = entity_type return entity_label
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) try: # Exception if local machine. host_name = cgiEnv.m_entity_id_dict["Domain"] except KeyError: host_name = None if lib_util.is_local_address(host_name): serv_name_or_none = None else: serv_name_or_none = host_name user_name = cgiEnv.m_entity_id_dict["Name"] grph = cgiEnv.GetGraph() node_user = survol_Win32_UserAccount.MakeUri(user_name, host_name) try: info_list = win32net.NetUserGetInfo(serv_name_or_none, user_name, 2) except Exception as exc: lib_common.ErrorMessageHtml("Error:" + str(exc)) for info_key in info_list: try: info_val = info_list[info_key] grph.add((node_user, lib_common.MakeProp(info_key), lib_util.NodeLiteral(info_val))) except Exception as exc: txt_disp = str(exc) grph.add((node_user, lib_common.MakeProp(info_key), lib_util.NodeLiteral(txt_disp))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() machine_name = cgiEnv.GetId() if lib_util.is_local_address(machine_name): machine_name = None if not lib_util.isPlatformWindows: lib_common.ErrorMessageHtml("win32 Python library only on Windows platforms") try: import win32com.client import win32net import pywintypes except ImportError: lib_common.ErrorMessageHtml("win32 Python library not installed") grph = cgiEnv.GetGraph() try: # Parameters: # Name of remote server on which the function is to execute. If None, local computer. # Domain name. If None, name of the domain controller for the primary domain. # If machine_name="LONW00052257.EURO.NET.INTRA", then it must be truncated to "LONW00052257" # Maybe this is a Netbios machine name ?? No idea, just make it work, for the moment. if machine_name == None: mach_split = None else: mach_split = machine_name.split('.')[0] logging.warning("machine_name:%s mach_split:%s", machine_name, mach_split) domain_controller = win32net.NetGetDCName(mach_split, None) except pywintypes.error as exc: lib_common.ErrorMessageHtml("NetGetDCName:mach_split=%s %s" % (mach_split, str(exc))) # This returns the domain name, for example "EURO". domain_name = win32net.NetUserModalsGet(domain_controller, 2)['domain_name'] logging.debug("Domain name:%s", domain_name) logging.debug("Domaine Controller:%s", domain_controller) logging.debug("Info=%s", str(win32net.NetUserModalsGet(domain_controller, 2))) node_domain = lib_uris.gUriGen.SmbDomainUri(domain_name) node_controller = lib_uris.gUriGen.HostnameUri(domain_controller) grph.add((node_domain, pc.property_controller, node_controller)) cnt = 0 # Sounds like these are the machines in the domain... adsi = win32com.client.Dispatch("ADsNameSpaces") nt = adsi.GetObject("", "WinNT:") result = nt.OpenDSObject("WinNT://%s" % domain_name, "", "", 0) result.Filter = ["computer"] for machine in result: if machine.Name[0] == '$': continue logging.debug("machine_name=%s", machine.Name) node_machine = lib_uris.gUriGen.HostnameUri(machine.Name) grph.add((node_domain, pc.property_domain, node_machine)) cnt += 1 # TODO: It works fine until 1000 nodes, but after that takes ages to run. What can we do ????? # HARDCODE_LIMIT if cnt > 1000: logging.warning("COULD NOT RUN IT TILL THE END") break cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() # Usernames have the syntax user@host # Example: [email protected] user_name = cgiEnv.m_entity_id_dict["Name"] try: # Exception if local machine. user_host = cgiEnv.m_entity_id_dict["Domain"] except KeyError: user_host = lib_util.currentHostname if user_host: if not lib_util.is_local_address(user_host): # TODO: Should interrogate other host with "finger" protocol. # Cannot get user properties on different host:mymachine than mymachine.home lib_common.ErrorMessageHtml( "Cannot get user properties on different host:%s than %s" % (user_host, lib_util.currentHostname)) grph = cgiEnv.GetGraph() # It will be possible to transform this into a Json tree by # selecting only the RDF predicate property_ppid. # This will be done in a gui cgi script which takes as input # parameter a CGI script, visible by SLP, stored in a bookmark page # or anything else. # See http://stackoverflow.com/questions/17967686/retrieving-specific-rdf-graph-triples-based-on-predicate-nodes # on how to select triples on a given predicate only. # But in the general case, we cannot know if the RDF graph will be a tree, # something similar to a CSV file (That is, flat) or a general graph. # So we might have to process the resulting graph on the fly, to see # which visualising methods are applicable. # Also, in the case of a tree, we must find ourselves what is its root. for proc in psutil.process_iter(): proc_username = CIM_Process.PsutilProcToUser(proc) # proc_username=EURO\\UK936025 user_name=UK936025 # proc_username=NT AUTHORITY\\NETWORK SERVICE # proc_username=NT AUTHORITY\\SYSTEM # proc_username=EURO\\UK936025 # proc_username=NT AUTHORITY\\SYSTEM if proc_username != user_name: # On Windows, second chance with only the second part of the user. try: user_short = proc_username.split('\\')[1] except IndexError: user_short = proc_username if user_short != user_name: continue pid = proc.pid parent_pid = proc.ppid() # Built the same way in other RDF documents. node_process = lib_uris.gUriGen.PidUri(pid) parent_node_process = lib_uris.gUriGen.PidUri(parent_pid) # We avoid duplicating the edges. Why would the RFD merge do? grph.add((node_process, pc.property_ppid, parent_node_process)) grph.add((node_process, pc.property_pid, lib_util.NodeLiteral(pid))) # grph.add((node_process, pc.property_information, lib_util.NodeLiteral(proc_username))) # We avoid duplicating the edges. Why would the RFD merge do? ############ grph.add((node_process, pc.property_ppid, parent_node_process)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) machine_name = cgiEnv.GetId() grph = cgiEnv.GetGraph() # If running on the local machine, pass the host as None otherwise authorization is checked # just like a remote machine, which means User Account Control (UAC) disabling, # and maybe setting LocalAccountTokenFilterPolicy=1 if lib_util.is_local_address(machine_name): mach_name_not_none = lib_util.currentHostname server_box = lib_uris.gUriGen else: mach_name_not_none = machine_name server_box = lib_uris.RemoteBox(machine_name) try: logging.debug("Explicit WMI connection machine_name=%s", mach_name_not_none) cnnct = lib_wmi.WmiConnect(mach_name_not_none, "/root/cimv2") except Exception as exc: lib_common.ErrorMessageHtml("WMI " + machine_name + " processes. Caught:" + str(exc)) # With a dictionary so node are created once only. Main.dictPidToNode = {} def PidToNode(procId): try: return Main.dictPidToNode[procId] except KeyError: node = server_box.PidUri(procId) Main.dictPidToNode[procId] = node return node for processProperties in cnnct.Win32_Process(): node_process = PidToNode(processProperties.ProcessId) parent_node_process = PidToNode(processProperties.ParentProcessId) grph.add((node_process, pc.property_ppid, parent_node_process)) #grph.add( ( node_process, pc.property_pid, lib_util.NodeLiteral(processProperties.ProcessId) ) ) # >>> lp = cnnct.Win32_Process () # >>> lp[0] # <_wmi_object: \\TITI\root\cimv2:Win32_Process.Handle="0"> # >>> str(lp[0]) # '\ninstance of Win32_Process\n{\n\tCaption = "System Idle Process";\n\tCreationClassName = "Win32_Process";\n\tCreationDate = "20161 # 215105022.381553+000";\n\tCSCreationClassName = "Win32_ComputerSystem";\n\tCSName = "TITI";\n\tDescription = "System Idle Process";\ # n\tHandle = "0";\n\tHandleCount = 0;\n\tKernelModeTime = "23403826406250";\n\tName = "System Idle Process";\n\tOSCreationClassName = # "Win32_OperatingSystem";\n\tOSName = "Microsoft Windows 8.1|C:\\\\Windows|\\\\Device\\\\Harddisk0\\\\Partition4";\n\tOtherOperation # Count = "0";\n\tOtherTransferCount = "0";\n\tPageFaults = 1;\n\tPageFileUsage = 0;\n\tParentProcessId = 0;\n\tPeakPageFileUsage = 0; # \n\tPeakVirtualSize = "65536";\n\tPeakWorkingSetSize = 4;\n\tPriority = 0;\n\tPrivatePageCount = "0";\n\tProcessId = 0;\n\tQuotaNonP # agedPoolUsage = 0;\n\tQuotaPagedPoolUsage = 0;\n\tQuotaPeakNonPagedPoolUsage = 0;\n\tQuotaPeakPagedPoolUsage = 0;\n\tReadOperationCo # unt = "0";\n\tReadTransferCount = "0";\n\tSessionId = 0;\n\tThreadCount = 4;\n\tUserModeTime = "0";\n\tVirtualSize = "65536";\n\tWin # dowsVersion = "6.3.9600";\n\tWorkingSetSize = "4096";\n\tWriteOperationCount = "0";\n\tWriteTransferCount = "0";\n};\n' grph.add((node_process, pc.property_information, lib_util.NodeLiteral(processProperties.Caption))) if processProperties.Caption != processProperties.Description: grph.add((node_process, lib_common.MakeProp("Description"), lib_util.NodeLiteral(processProperties.Description))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote = True) server = cgiEnv.m_entity_id_dict["Domain"] group_name = cgiEnv.m_entity_id_dict["Name"] grph = cgiEnv.GetGraph() try: lib_win32.WNetAddConnect(server) except Exception as exc: lib_common.ErrorMessageHtml("Server=%s Caught:%s" % (server, str(exc))) if lib_util.is_local_address(server): serv_name_or_none = None # So it is compatible with WMI: ".home" removal. serv_name_not_none = lib_uris.TruncateHostname(lib_util.currentHostname) else: serv_name_or_none = server serv_name_not_none = server server_box = lib_uris.MachineBox(server) node_group = survol_Win32_Group.MakeUri(group_name, serv_name_not_none) try: memberresume = 0 while True: member_data, total, member_resume = win32net.NetLocalGroupGetMembers( serv_name_or_none, group_name, 2, memberresume) prop_sid_usage = lib_common.MakeProp("SID Usage") prop_security_identifier = lib_common.MakeProp("Security Identifier") for member in member_data: sid_usage = member['sidusage'] # Converts Sid to username try: member_name, domain, type = win32security.LookupAccountSid(server, member['sid']) except Exception as exc: logging.error("Server=%s Caught:%s", server, str(exc)) continue logging.debug("Member: %s:", str(member)) logging.debug("Lookup: %s: %s", member_name, member['domainandname']) member_node = _member_name_to_node(sid_usage, member_name, serv_name_not_none) grph.add((member_node, pc.property_group, node_group)) grph.add((member_node, prop_sid_usage, lib_util.NodeLiteral(_sid_usage_to_string(sid_usage)))) grph.add((member_node, prop_security_identifier, lib_util.NodeLiteral(member['sid']))) if serv_name_or_none: node_member_remote = serv_name_or_none(sid_usage, member_name, serv_name_or_none, server_box) # TODO: Instead, both object must have the same universal alias grph.add((member_node, pc.property_alias, node_member_remote)) if member_resume == 0: break except Exception as exc: lib_common.ErrorMessageHtml("win32 local groups:" + str(exc)) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) server = cgiEnv.GetId() grph = cgiEnv.GetGraph() if lib_util.is_local_address(server): serv_name_or_none = None server_node = lib_common.nodeMachine else: serv_name_or_none = server server_node = lib_uris.gUriGen.HostnameUri(server) try: lib_win32.WNetAddConnect(serv_name_or_none) except Exception as exc: # Maybe the machine is not online. lib_common.ErrorMessageHtml(str(exc)) resume = 0 num_members = 0 try: while True: data, total, resume = win32net.NetLocalGroupEnum( serv_name_or_none, 1, resume) for group in data: logging.debug("Group %(name)s:%(comment)s", group) # TODO: Not sure about the groupname syntax. group_name = group['name'] logging.debug("group_name=%s", group_name) node_group = survol_Win32_Group.MakeUri(group_name, server) grph.add((node_group, pc.property_host, server_node)) group_comment = group['comment'] logging.debug("group_comment=%s", group_comment) if group_comment != "": group_comment_max_width = max(80, len(group_name)) if len(group_comment) > group_comment_max_width: group_comment = group_comment[: group_comment_max_width] + "..." grph.add((node_group, pc.property_information, lib_util.NodeLiteral(group_comment))) memberresume = 0 while True: member_data, total, member_resume = win32net.NetLocalGroupGetMembers( serv_name_or_none, group_name, 2, memberresume) for member in member_data: # Converts Sid to username num_members = num_members + 1 try: user_name, domain, the_type = win32security.LookupAccountSid( server, member['sid']) except Exception as exc: logging.warning( "Server=%s LookupAccountSid Caught:%s", server, str(exc)) continue logging.debug("Member: %s: %s server=%s", user_name, member['domainandname'], server) # node_user = serverBox.UserUri( user_name ) node_user = survol_Win32_UserAccount.MakeUri( user_name, server) # TODO: Not sure about the property. # TODO: Not sure about the username syntax. grph.add((node_user, pc.property_group, node_group)) if memberresume == 0: break if not resume: break except Exception as exc: lib_common.ErrorMessageHtml("win32 local groups:" + str(exc)) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")