% '============================================================================= ' FILE: displaypc.asp ' PURPOSE: Display detailed PC 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 PC ID input Dim pcid pcid = GetSafeInteger("QS", "pcid", 0, 1, 999999) IF pcid = 0 THEN objConn.Close Response.Redirect("displaypcs.asp") Response.End END IF ' SECURITY: Use parameterized query Dim strSQL, rs strSQL = "SELECT pc.*,vendors.*,models.*,pc_network_interfaces.*,machines.machineid,machines.machinenumber as machine_number,machines.alias,machine_models.machinetypeid,machinetypes.machinetype,machines.businessunitid,businessunits.businessunit,machines.printerid,printers.printerwindowsname,pctype.typename,functionalaccounts.functionalaccount,functionalaccounts.description as functionalaccount_description " & _ "FROM pc " & _ "LEFT JOIN models ON pc.modelnumberid=models.modelnumberid " & _ "LEFT JOIN vendors ON models.vendorid=vendors.vendorid " & _ "LEFT JOIN pc_network_interfaces ON pc_network_interfaces.pcid=pc.pcid " & _ "LEFT JOIN machines ON pc.machinenumber = machines.machinenumber " & _ "LEFT JOIN models AS machine_models ON machines.modelnumberid = machine_models.modelnumberid " & _ "LEFT JOIN machinetypes ON machine_models.machinetypeid = machinetypes.machinetypeid " & _ "LEFT JOIN businessunits ON machines.businessunitid = businessunits.businessunitid " & _ "LEFT JOIN printers ON machines.printerid = printers.printerid " & _ "LEFT JOIN pctype ON pc.pctypeid = pctype.pctypeid " & _ "LEFT JOIN functionalaccounts ON pctype.functionalaccountid = functionalaccounts.functionalaccountid " & _ "WHERE pc.isactive=1 AND pc.pcid=?" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(pcid)) ' Check if PC exists IF rs.EOF THEN Call CleanupResources() Response.Redirect("displaypcs.asp") Response.End END IF ' Get machine ID if it exists Dim machineid IF NOT rs.EOF THEN IF NOT IsNull(rs("machineid")) THEN machineid = CLng(rs("machineid")) ELSE machineid = 0 END IF END IF %>
Vendor:
Model:
Serial:
Hostname:
Location:
IP:
Functional Account:
<%=Server.HTMLEncode(vendorValPC)%>
<%=Server.HTMLEncode(modelValPC)%>
<%=Server.HTMLEncode(serialValPC)%>
<% If hostnameValPC <> "N/A" And ipValPC <> "N/A" Then Response.Write("" & Server.HTMLEncode(hostnameValPC) & "") Else Response.Write(Server.HTMLEncode(hostnameValPC)) End If %>
<% IF machineid > 0 THEN Dim locationDisplay ' Use alias if available, otherwise machine_number IF NOT IsNull(rs("alias")) AND rs("alias") <> "" THEN locationDisplay = Server.HTMLEncode(rs("alias") & "") ELSE locationDisplay = Server.HTMLEncode(rs("machine_number") & "") END IF Response.Write("" & locationDisplay & "") ELSE Response.Write("Not assigned") END IF %>
<% IF NOT IsNull(rs("ipaddress")) AND rs("ipaddress") <> "" THEN Response.Write(Server.HTMLEncode(rs("ipaddress") & "")) ELSE Response.Write("N/A") END IF %>
<% IF NOT IsNull(rs("functionalaccount")) AND rs("functionalaccount") <> "" THEN Dim accountDisplay, descDisplay, extractedAccount Dim pcTypeName pcTypeName = "" IF NOT IsNull(rs("typename")) THEN pcTypeName = UCase(Trim(rs("typename") & "")) END IF ' Check if loggedinuser exists and should be used Dim useLoggedInUser useLoggedInUser = False IF NOT IsNull(rs("LoggedInUser")) AND rs("LoggedInUser") <> "" THEN ' Use loggedinuser for Standard, Engineer, or TBD types IF pcTypeName = "STANDARD" OR pcTypeName = "ENGINEER" OR rs("functionalaccount") = "TBD" OR rs("functionalaccount") = "1" THEN useLoggedInUser = True END IF END IF IF useLoggedInUser THEN accountDisplay = Server.HTMLEncode(rs("LoggedInUser") & "") ' Try to extract the account number from loggedinuser (format: lg[account]sd) Dim loggedUser loggedUser = rs("LoggedInUser") & "" IF Left(loggedUser, 2) = "lg" AND Right(loggedUser, 2) = "sd" AND Len(loggedUser) > 4 THEN extractedAccount = Mid(loggedUser, 3, Len(loggedUser) - 4) ELSE extractedAccount = "" END IF ELSE accountDisplay = Server.HTMLEncode("lg" & rs("functionalaccount") & "sd") extractedAccount = "" END IF ' Determine what description to show Dim descField descField = "" ' If showing plain SSO (not lg[account]sd format), label it as "SSO" IF useLoggedInUser AND extractedAccount = "" THEN descField = "SSO" ' If we extracted an account from loggedinuser, look up its description ELSEIF extractedAccount <> "" THEN ' SECURITY: Use parameterized query for functional account lookup Dim rsDesc, sqlDesc sqlDesc = "SELECT description FROM functionalaccounts WHERE functionalaccount = ? AND isactive = 1" Set rsDesc = ExecuteParameterizedQuery(objConn, sqlDesc, Array(extractedAccount)) IF NOT rsDesc.EOF THEN IF NOT IsNull(rsDesc("description")) AND rsDesc("description") <> "" THEN descField = Server.HTMLEncode(rsDesc("description") & "") END IF END IF rsDesc.Close Set rsDesc = Nothing ' Otherwise use functional account description from the query ELSE On Error Resume Next descField = Server.HTMLEncode(rs("functionalaccount_description") & "") If descField = "" Then descField = Server.HTMLEncode(rs("description") & "") End If On Error Goto 0 END IF IF descField <> "" AND NOT IsNull(descField) THEN descDisplay = " - " & descField ELSE descDisplay = "" END IF Response.Write(accountDisplay & descDisplay) ELSE Response.Write("N/A") END IF %>
Status:
End Date:
Days Remaining:
Service Level:
Last Checked:
<%=warrantyBadge%>
<% If Not IsNull(rs("warrantyenddate")) And warrantyEndDate <> "" And warrantyEndDate <> "0000-00-00" Then Response.Write(Server.HTMLEncode(warrantyEndDate)) Else Response.Write("Not available") End If %>
<% If Not IsNull(warrantyDaysRemaining) And IsNumeric(warrantyDaysRemaining) Then If warrantyDaysRemaining < 0 Then Response.Write("" & Abs(warrantyDaysRemaining) & " days overdue") ElseIf warrantyDaysRemaining < 30 Then Response.Write("" & warrantyDaysRemaining & " days") Else Response.Write(warrantyDaysRemaining & " days") End If Else Response.Write("Not available") End If %>
<% If Not IsNull(rs("warrantyservicelevel")) And warrantyServiceLevel <> "" Then Response.Write(Server.HTMLEncode(warrantyServiceLevel)) Else Response.Write("Not available") End If %>
<% If Not IsNull(rs("warrantylastchecked")) And warrantyLastChecked <> "" Then Response.Write(Server.HTMLEncode(warrantyLastChecked)) Else Response.Write("Never checked") End If %>
| Machine Number | Equipment Type | Vendor | Model | Location |
|---|---|---|---|---|
| This PC does not control any equipment | ||||
| " & Server.HTMLEncode(equipMachineNum) & " | ") Response.Write("" & equipType & " | ") Response.Write("" & equipVendor & " | ") Response.Write("" & equipModel & " | ") Response.Write("" & Server.HTMLEncode(equipLocation) & " | ") Response.Write("
| No machine assigned to this PC | ||||
| " & Server.HTMLEncode(rs2("appname") & "") & " |
| No machine assigned - cannot display installed applications |