% '============================================================================= ' FILE: displaysubnet.asp ' PURPOSE: Display detailed subnet information with edit capability ' SECURITY: Parameterized queries, HTML encoding, input validation ' UPDATED: 2025-12-29 - Migrated to match displaypc.asp style '============================================================================= %>
<% theme = Request.Cookies("theme") IF theme = "" THEN theme = "bg-theme1" END IF '============================================================================= ' SMART REDIRECT: Check if search param is a printer or PC IP address '============================================================================= Dim search search = Trim(Request.QueryString("search") & "") IF search <> "" THEN ' Check if this IP belongs to a printer Dim rsPrinterCheck, strPrinterSQL strPrinterSQL = "SELECT printerid FROM printers WHERE ipaddress = ?" Set rsPrinterCheck = ExecuteParameterizedQuery(objConn, strPrinterSQL, Array(search)) IF NOT rsPrinterCheck.EOF THEN Dim printerRedirectId printerRedirectId = rsPrinterCheck("printerid") rsPrinterCheck.Close Set rsPrinterCheck = Nothing objConn.Close Response.Redirect("./displayprinter.asp?printerid=" & printerRedirectId) Response.End END IF rsPrinterCheck.Close Set rsPrinterCheck = Nothing ' Check if this IP belongs to a PC (Phase 2: uses communications table) Dim rsPCCheck, strPCSQL strPCSQL = "SELECT m.machineid FROM machines m " & _ "INNER JOIN communications c ON m.machineid = c.machineid " & _ "WHERE c.address = ? AND m.pctypeid IS NOT NULL AND c.isactive = 1" Set rsPCCheck = ExecuteParameterizedQuery(objConn, strPCSQL, Array(search)) IF NOT rsPCCheck.EOF THEN Dim pcRedirectId pcRedirectId = rsPCCheck("machineid") rsPCCheck.Close Set rsPCCheck = Nothing objConn.Close Response.Redirect("./displaypc.asp?machineid=" & pcRedirectId) Response.End END IF rsPCCheck.Close Set rsPCCheck = Nothing END IF '============================================================================= ' SECURITY: Validate subnet ID input '============================================================================= Dim subnetid subnetid = GetSafeInteger("QS", "subnetid", 0, 1, 999999) IF subnetid = 0 THEN objConn.Close Response.Redirect("displaysubnets.asp") Response.End END IF '============================================================================= ' SECURITY: Use parameterized query to prevent SQL injection '============================================================================= Dim strSQL, rs strSQL = "SELECT subnets.*, subnettypes.subnettype, " & _ "INET_NTOA(subnets.ipstart) AS subnetstart, " & _ "INET_NTOA(subnets.ipend) AS subnetend " & _ "FROM subnets " & _ "LEFT JOIN subnettypes ON subnets.subnettypeid = subnettypes.subnettypeid " & _ "WHERE subnets.isactive = 1 AND subnets.subnetid = ?" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(subnetid)) ' Check if subnet exists IF rs.EOF THEN objConn.Close Response.Redirect("displaysubnets.asp") Response.End END IF ' Store values for use in page Dim vlanVal, zoneVal, networkVal, networkEndVal, cidrVal, descVal, ipStartInt, ipEndInt vlanVal = rs("vlan") & "" zoneVal = rs("subnettype") & "" networkVal = rs("subnetstart") & "" networkEndVal = rs("subnetend") & "" cidrVal = rs("cidr") & "" descVal = rs("description") & "" ipStartInt = rs("ipstart") ipEndInt = rs("ipend") If vlanVal = "" Then vlanVal = "N/A" If zoneVal = "" Then zoneVal = "Unknown" If networkVal = "" Then networkVal = "N/A" If cidrVal = "" Then cidrVal = "" If descVal = "" Then descVal = "No description" ' Calculate usable IPs Dim usableIPs If IsNumeric(ipStartInt) And IsNumeric(ipEndInt) Then usableIPs = CLng(ipEndInt) - CLng(ipStartInt) Else usableIPs = 0 End If %>
VLAN <%=Server.HTMLEncode(vlanVal)%>
<%=Server.HTMLEncode(zoneVal)%>
VLAN:
Zone:
Network:
CIDR:
IP Range:
Usable IPs:
Description:
<%=Server.HTMLEncode(vlanVal)%>
<%=Server.HTMLEncode(zoneVal)%>
<%=Server.HTMLEncode(networkVal)%>
<%=Server.HTMLEncode(cidrVal)%>
<%=Server.HTMLEncode(networkVal)%> - <%=Server.HTMLEncode(networkEndVal)%>
<%=Server.HTMLEncode(CStr(usableIPs))%>
<%=Server.HTMLEncode(descVal)%>
| Type | Name | IP Address |
|---|---|---|
| PC | <%=Server.HTMLEncode(pcDeviceName)%> | <%=Server.HTMLEncode(pcDeviceIP)%> |
| Printer | <%=Server.HTMLEncode(prtName)%> | <%=Server.HTMLEncode(prtIP)%> |
| No devices found on this subnet | ||
Total devices: <%=deviceCount%>