% '============================================================================= ' FILE: displaymachine.asp ' PURPOSE: Display detailed machine information with edit capability ' SECURITY: Parameterized queries, HTML encoding, input validation ' UPDATED: 2025-10-27 - Migrated to secure patterns '============================================================================= %>
<% theme = Request.Cookies("theme") If theme = "" Then theme = "bg-theme1" End If '============================================================================= ' SECURITY: Validate machineid or machinenumber parameter ' NOTE: This handles both database ID and machine number for flexibility '============================================================================= Dim machineid, machinenumber, paramValue ' Accept both machineid and pcid parameters for backwards compatibility machineid = GetSafeInteger("QS", "machineid", 0, 1, 999999) If machineid = 0 Then machineid = GetSafeInteger("QS", "pcid", 0, 1, 999999) ' If machineid not provided, try machinenumber parameter IF machineid = 0 THEN machinenumber = Request.QueryString("machinenumber") IF machinenumber <> "" THEN ' Look up machineid by machinenumber Dim rsLookup, strLookupSQL strLookupSQL = "SELECT machineid FROM machines WHERE machinenumber = ? AND isactive = 1" Set rsLookup = ExecuteParameterizedQuery(objConn, strLookupSQL, Array(machinenumber)) IF NOT rsLookup.EOF THEN machineid = rsLookup("machineid") END IF rsLookup.Close Set rsLookup = Nothing END IF ELSE ' We have a machineid, but it might actually be a machine number ' Try to look it up as a machineid first Dim rsCheck strLookupSQL = "SELECT machineid FROM machines WHERE machineid = ? AND isactive = 1" Set rsCheck = ExecuteParameterizedQuery(objConn, strLookupSQL, Array(machineid)) ' If no machine found with that machineid, try treating it as a machine number IF rsCheck.EOF THEN rsCheck.Close strLookupSQL = "SELECT machineid FROM machines WHERE machinenumber = ? AND isactive = 1" Set rsCheck = ExecuteParameterizedQuery(objConn, strLookupSQL, Array(CStr(machineid))) IF NOT rsCheck.EOF THEN machineid = rsCheck("machineid") ELSE machineid = 0 ' Not found END IF END IF rsCheck.Close Set rsCheck = Nothing END IF IF machineid = 0 THEN objConn.Close Response.Redirect("default.asp") Response.End END IF '============================================================================= ' SECURITY: Use parameterized query to prevent SQL injection ' PHASE 2: Removed pc and networkinterfaces tables (migrated to machines) ' NOTE: Use explicit column names to avoid wildcard conflicts between tables '============================================================================= ' Phase 2: Only query columns that actually exist in machines table strSQL = "SELECT machines.machineid, machines.machinenumber, machines.alias, machines.hostname, " & _ "machines.serialnumber, machines.machinenotes, machines.mapleft, machines.maptop, " & _ "machines.modelnumberid, machines.businessunitid, machines.printerid, machines.pctypeid, " & _ "machines.loggedinuser, machines.osid, machines.machinestatusid, machines.isvnc, machines.iswinrm, " & _ "machines.controllertypeid, machines.controllerosid, machines.requires_manual_machine_config, " & _ "machines.lastupdated, machines.lastboottime, " & _ "DATEDIFF(NOW(), machines.lastboottime) AS uptime_days, " & _ "machinetypes.machinetype, machinetypes.machinetypeid, " & _ "pctype.typename AS pctypename, " & _ "machinestatus.machinestatus, " & _ "models.modelnumber, models.image, models.modelnumberid, " & _ "businessunits.businessunit, businessunits.businessunitid, " & _ "functionalaccounts.functionalaccount, functionalaccounts.functionalaccountid, " & _ "vendors.vendor, vendors.vendorid, " & _ "printers.ipaddress AS printerip, printers.printerid AS printer_id, " & _ "printers.printercsfname, printers.printerwindowsname " & _ "FROM machines " & _ "INNER JOIN models ON machines.modelnumberid = models.modelnumberid " & _ "LEFT JOIN machinetypes ON models.machinetypeid = machinetypes.machinetypeid " & _ "LEFT JOIN machinestatus ON machines.machinestatusid = machinestatus.machinestatusid " & _ "INNER JOIN businessunits ON machines.businessunitid = businessunits.businessunitid " & _ "LEFT JOIN functionalaccounts ON machinetypes.functionalaccountid = functionalaccounts.functionalaccountid " & _ "INNER JOIN vendors ON models.vendorid = vendors.vendorid " & _ "LEFT JOIN printers ON machines.printerid = printers.printerid " & _ "LEFT JOIN pctype ON machines.pctypeid = pctype.pctypeid " & _ "WHERE machines.machineid = " & CLng(machineid) & " AND machines.pctypeid IS NOT NULL" Set rs = objConn.Execute(strSQL) ' Check if machine exists If rs.EOF Then rs.Close Set rs = Nothing objConn.Close Response.Redirect("default.asp") Response.End End If ' Fallback: If PC doesn't have location set, get it from controlled machine Dim pcMapleft, pcMaptop pcMapleft = rs("mapleft") pcMaptop = rs("maptop") If (IsNull(pcMapleft) OR pcMapleft = "" OR pcMapleft = 0) AND (IsNull(pcMaptop) OR pcMaptop = "" OR pcMaptop = 0) Then ' PC has no location, try to get from controlled machine Dim rsControlledMachine Dim controlledSQL controlledSQL = "SELECT m.mapleft, m.maptop, m.machinenumber " & _ "FROM machinerelationships mr " & _ "JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _ "JOIN machines m ON mr.machineid = m.machineid " & _ "WHERE mr.related_machineid = " & CLng(machineid) & " AND rt.relationshiptype = 'Controls' " & _ "AND m.mapleft IS NOT NULL AND m.maptop IS NOT NULL AND m.mapleft > 0 AND m.maptop > 0 " & _ "LIMIT 1" Set rsControlledMachine = objConn.Execute(controlledSQL) If NOT rsControlledMachine.EOF Then ' Use controlled machine's location as fallback If NOT IsNull(rsControlledMachine("mapleft")) AND rsControlledMachine("mapleft") > 0 Then pcMapleft = rsControlledMachine("mapleft") End If If NOT IsNull(rsControlledMachine("maptop")) AND rsControlledMachine("maptop") > 0 Then pcMaptop = rsControlledMachine("maptop") End If End If rsControlledMachine.Close Set rsControlledMachine = Nothing End If %><%=Server.HTMLEncode(rs("machinenotes") & "")%>
Serial Number:
Hostname:
Status:
Location:
Vendor:
Model:
PC Type:
BU:
IP Address:
MAC Address:
VNC:
WinRM:
Uptime:
Controlled Equipment:
Printer:
<%=Server.HTMLEncode(serialNumVal)%>
<%=Server.HTMLEncode(hostnameVal)%>
<%=Server.HTMLEncode(statusVal)%>
<% If machineNumVal <> "N/A" Then ' Use fallback location if PC location is available Dim hasLocation hasLocation = False If NOT IsNull(pcMapleft) AND NOT IsNull(pcMaptop) AND pcMapleft > 0 AND pcMaptop > 0 Then hasLocation = True End If If hasLocation Then %> <%=Server.HTMLEncode(machineNumVal)%> <% Else Response.Write(Server.HTMLEncode(machineNumVal) & " (No location)") End If Else Response.Write("N/A") End If %>
<%=Server.HTMLEncode(vendorValM)%>
<%=Server.HTMLEncode(modelValM)%>
<%=Server.HTMLEncode(pctypeName)%>
<%=Server.HTMLEncode(buVal)%>
<% ' Get primary communication (IP and MAC) from communications table Dim rsPrimaryCom, strPrimaryComSQL, primaryIP, primaryMAC strPrimaryComSQL = "SELECT address, macaddress FROM communications WHERE machineid = ? AND isprimary = 1 AND isactive = 1 LIMIT 1" Set rsPrimaryCom = ExecuteParameterizedQuery(objConn, strPrimaryComSQL, Array(machineid)) If Not rsPrimaryCom.EOF Then primaryIP = rsPrimaryCom("address") & "" primaryMAC = rsPrimaryCom("macaddress") & "" Else ' Try to get first active communication if no primary set rsPrimaryCom.Close strPrimaryComSQL = "SELECT address, macaddress FROM communications WHERE machineid = ? AND isactive = 1 ORDER BY comid LIMIT 1" Set rsPrimaryCom = ExecuteParameterizedQuery(objConn, strPrimaryComSQL, Array(machineid)) If Not rsPrimaryCom.EOF Then primaryIP = rsPrimaryCom("address") & "" primaryMAC = rsPrimaryCom("macaddress") & "" Else primaryIP = "" primaryMAC = "" End If End If rsPrimaryCom.Close Set rsPrimaryCom = Nothing ' Display IP Address If primaryIP <> "" Then Response.Write("" & Server.HTMLEncode(primaryIP) & "
") Else Response.Write("N/A
") End If ' Display MAC Address If primaryMAC <> "" Then Response.Write("" & Server.HTMLEncode(primaryMAC) & "
") Else Response.Write("N/A
") End If ' Display VNC status and link Dim hasVncEnabled, vncHostname hasVncEnabled = False If Not IsNull(rs("isvnc")) Then If rs("isvnc") = True Or rs("isvnc") = 1 Or rs("isvnc") = -1 Then hasVncEnabled = True End If End If ' Check WinRM status Dim hasWinRMEnabled hasWinRMEnabled = False If Not IsNull(rs("iswinrm")) Then If rs("iswinrm") = True Or rs("iswinrm") = 1 Or rs("iswinrm") = -1 Then hasWinRMEnabled = True End If End If ' Use hostname with FQDN for VNC connection vncHostname = "" If hostnameVal <> "N/A" And hostnameVal <> "" Then vncHostname = hostnameVal & ".logon.ds.ge.com" End If If hasVncEnabled And vncHostname <> "" Then Response.Write("" & Server.HTMLEncode(vncHostname) & "
") ElseIf hasVncEnabled And primaryIP <> "" Then ' Fallback to IP address if no hostname Response.Write("" & Server.HTMLEncode(primaryIP) & "
") ElseIf hasVncEnabled Then Response.Write("VNC Enabled (No hostname or IP)
") Else Response.Write("N/A
") End If ' Display WinRM status (text instead of badge) If hasWinRMEnabled Then Response.Write("Enabled
") Else Response.Write("N/A
") End If ' Display uptime If uptimeDays <> "" Then Response.Write("" & Server.HTMLEncode(uptimeDays) & "
") Else Response.Write("N/A
") End If ' Get controlled equipment from relationships - check both directions ' Direction 1: This PC (machineid) controls equipment (related_machineid) ' Direction 2: Equipment (machineid) is controlled by this PC (related_machineid) Dim rsControlledEquip, strControlledEquipSQL, controlledEquipName, controlledEquipID ' First check: This PC controls equipment (standard direction) strControlledEquipSQL = "SELECT m.machineid, m.machinenumber FROM machinerelationships mr " & _ "JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _ "JOIN machines m ON mr.related_machineid = m.machineid " & _ "WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1 " & _ "AND m.pctypeid IS NULL LIMIT 1" Set rsControlledEquip = ExecuteParameterizedQuery(objConn, strControlledEquipSQL, Array(machineid)) If rsControlledEquip.EOF Then rsControlledEquip.Close ' Second check: Equipment has relationship to this PC (reverse direction) strControlledEquipSQL = "SELECT m.machineid, m.machinenumber FROM machinerelationships mr " & _ "JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _ "JOIN machines m ON mr.machineid = m.machineid " & _ "WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1 " & _ "AND m.pctypeid IS NULL LIMIT 1" Set rsControlledEquip = ExecuteParameterizedQuery(objConn, strControlledEquipSQL, Array(machineid)) End If If Not rsControlledEquip.EOF Then controlledEquipName = rsControlledEquip("machinenumber") & "" controlledEquipID = rsControlledEquip("machineid") Response.Write("" & Server.HTMLEncode(controlledEquipName) & "
") Else Response.Write("N/A
") End If rsControlledEquip.Close Set rsControlledEquip = Nothing ' SECURITY: HTML encode printer data to prevent XSS ' Printer data - check if exists (LEFT JOIN may return NULL) If Not IsNull(rs("printerid")) And rs("printerid") <> "" Then Dim printerNameVal printerNameVal = rs("printerwindowsname") & "" If printerNameVal = "" Then printerNameVal = "Printer #" & rs("printerid") Response.Write("" & Server.HTMLEncode(printerNameVal) & "
") Else Response.Write("N/A
") End If %>| Type | IP Address | MAC Address | Interface | Primary | Status |
|---|---|---|---|---|---|
| No network communications configured | |||||
| " & Server.HTMLEncode(rs2("typename") & "") & " | ") Response.Write("" & ipAddr & " | ") Response.Write("" & macAddr & " | ") Response.Write("" & ifaceName & " | ") Response.Write("" & statusBadge & " | ") Response.Write("Active | ") Response.Write("
| Machine Number | Type | Model | Relationship |
|---|---|---|---|
| This PC does not control any machines | |||
| " & Server.HTMLEncode(ctrlMachineNum) & " | ") Response.Write("" & ctrlType & " | ") Response.Write("" & ctrlModel & " | ") Response.Write("" & Server.HTMLEncode(rs2("relationshiptype") & "") & " | ") Response.Write("
Third Party Managed:
Third Party Manager:
OT Asset System:
DoD Asset Device Type:
Compliant:
<%=tpmBadge%>
<%=Server.HTMLEncode(thirdPartyManager)%>
<%=Server.HTMLEncode(otAssetSystem)%>
<%=Server.HTMLEncode(dodAssetDeviceType)%>
<% If Not IsNull(isCompliant) Then If isCompliant Then Response.Write("Yes") Else Response.Write("No") End If Else Response.Write("Not Assessed") End If %>
| Scan Name | Date | Result | Details |
|---|---|---|---|
| No security scans recorded | |||
| " & Server.HTMLEncode(scanName) & " | ") Response.Write("" & Server.HTMLEncode(scanDate) & " | ") Response.Write("" & resultBadge & " | ") Response.Write("" & scanDetails & " | ") Response.Write("
No compliance data available for this machine.
") rs2.Close Set rs2 = Nothing End If %>| " & appDisplay & " |