diff --git a/api.asp b/api.asp index 6025c98..7f83b79 100644 --- a/api.asp +++ b/api.asp @@ -828,22 +828,27 @@ Sub GetDashboardData() End Sub Sub GetShopfloorPCs() - ' Returns list of all active shopfloor PCs for remote management + ' Returns list of all active PCs with shop floor IPs (10.134.*) for remote management + ' This includes all PC types: Shopfloor, CMM, Wax Trace, Keyence, etc. + ' PCs are identified by machinetypeid >= 33, pctypeid can be NULL On Error Resume Next Dim rsPC, strSQL, pcList, pcCount, pcData - ' Query active shopfloor PCs only (pctype = 'Shopfloor') - ' Include hostname, machineid, machinenumber (equipment), IP address, last updated + ' Query all active PCs with shop floor IP addresses (10.134.*) + ' - machinetypeid >= 33 ensures we only get PCs (not equipment) + ' - LEFT JOIN pctype to include PCs with NULL pctypeid + ' - EXISTS subquery finds any PC with a 10.134.* address strSQL = "SELECT m.machineid, m.hostname, m.machinenumber, m.serialnumber, " & _ "m.loggedinuser, m.lastupdated, " & _ "c.address AS ipaddress, " & _ - "pt.typename AS pctype " & _ + "COALESCE(pt.typename, 'Uncategorized') AS pctype " & _ "FROM machines m " & _ "LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ - "INNER JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _ + "LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _ "WHERE m.isactive = 1 " & _ - "AND pt.typename = 'Shopfloor' " & _ + "AND m.machinetypeid >= 33 " & _ + "AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') " & _ "ORDER BY m.hostname ASC" Set rsPC = objConn.Execute(strSQL) @@ -1300,15 +1305,13 @@ Function InsertNetworkInterfaces(machineid, networkInterfacesJSON) If interfaceName = "" Then interfaceName = "Interface " & (i + 1) - ' Determine if primary - 10.134.*.* is always primary for shopfloor PCs - Dim isPrimary, isPrimaryFromJson - isPrimary = 0 - isPrimaryFromJson = GetJSONValue(interfacesArray(i), "IsPrimary") - If isPrimaryFromJson = True Or isPrimaryFromJson = "true" Or isPrimaryFromJson = "True" Then - isPrimary = 1 - ElseIf Left(ipAddress, 7) = "10.134." Then - ' Fallback: 10.134.*.* is always primary + ' Determine if primary - 10.134.*.* is ALWAYS primary for shopfloor PCs + ' Ignore JSON value, enforce by IP address pattern + Dim isPrimary + If Left(ipAddress, 7) = "10.134." Then isPrimary = 1 + Else + isPrimary = 0 End If ' Insert into communications table diff --git a/displaysubnet.asp b/displaysubnet.asp index 6e7db67..b97a848 100644 --- a/displaysubnet.asp +++ b/displaysubnet.asp @@ -1,58 +1,127 @@ - +<% +'============================================================================= +' 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" + theme = "bg-theme1" END IF - search = Request.Querystring("search") + '============================================================================= + ' SMART REDIRECT: Check if search param is a printer or PC IP address + '============================================================================= + Dim search + search = Trim(Request.QueryString("search") & "") -'----------------------------------------------------Is this the IP address of a printer??? ---------------------------------------------- + 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 - IF search <> "" THEN - strSQL = "Select printerid FROM printers where ipaddress='" &search &"'" - set rs = objconn.Execute(strSQL) - IF NOT rs.EOF THEN - printerid = rs("printerid") - objConn.Close - Response.Redirect "./displayprinter.asp?printerid="&printerid - END IF - END IF -'-------------------------------------------------------Is this the IP address of a PC--------------------------------------------------- - IF search <> "" THEN - ' PHASE 2: Query communications table instead of networkinterfaces - strSQL = "SELECT c.machineid FROM communications c JOIN machines m ON c.machineid = m.machineid WHERE c.address='" &search &"' AND m.pctypeid IS NOT NULL LIMIT 1" - set rs = objconn.Execute(strSQL) - IF NOT rs.EOF THEN - machineid = rs("machineid") - objConn.Close - Response.Redirect "./displaypc.asp?machineid="&machineid - END IF - END IF + ' Check if this IP belongs to a PC + Dim rsPCCheck, strPCSQL + strPCSQL = "SELECT pcid FROM pc_network_interfaces WHERE ipaddress = ?" + Set rsPCCheck = ExecuteParameterizedQuery(objConn, strPCSQL, Array(search)) + IF NOT rsPCCheck.EOF THEN + Dim pcRedirectId + pcRedirectId = rsPCCheck("pcid") + rsPCCheck.Close + Set rsPCCheck = Nothing + objConn.Close + Response.Redirect("./displaypc.asp?pcid=" & 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) - subnetid = Request.Querystring("subnetid") - strSQL = "SELECT *,INET_NTOA(ipstart) AS subnetstart FROM subnets,subnettypes WHERE subnets.subnettypeid=subnettypes.subnettypeid AND subnets.isactive=1 AND subnetid="&subnetid - set rs = objconn.Execute(strSQL) - ipdiff = rs("ipend")-rs("ipstart") - 'response.write(ipdiff) + 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 | -Description | -
|---|---|---|---|---|
Total devices: <%=deviceCount%>
+