<% ' Get form inputs Dim subnetid, vlan, ipstart, cidr, description, subnettypeid, cidrarray, ipend subnetid = Trim(Request.Querystring("subnetid")) vlan = Trim(Request.Form("vlan")) ipstart = Trim(Request.Form("ipstart")) cidr = Trim(Request.Form("cidr")) description = Trim(Request.Form("description")) subnettypeid = Trim(Request.Form("subnettypeid")) ' Validate required ID fields If Not IsNumeric(subnetid) Or CLng(subnetid) < 1 Then Response.Write("Invalid subnet ID") objConn.Close Response.End End If ' Verify the subnet exists Dim checkSQL, rsCheck checkSQL = "SELECT COUNT(*) as cnt FROM subnets WHERE subnetid = " & subnetid Set rsCheck = objConn.Execute(checkSQL) Dim subnetExists subnetExists = False If Not rsCheck.EOF Then If Not IsNull(rsCheck("cnt")) Then If CLng(rsCheck("cnt")) > 0 Then subnetExists = True End If End If End If rsCheck.Close Set rsCheck = Nothing If Not subnetExists Then Response.Redirect("displaysubnets.asp") objConn.Close Response.End End If ' Validate required fields If vlan = "" Or ipstart = "" Or cidr = "" Or subnettypeid = "" Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=REQUIRED_FIELD") objConn.Close Response.End End If ' Validate VLAN is numeric If Not IsNumeric(vlan) Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If ' Basic IP address validation If Len(ipstart) < 7 Or Len(ipstart) > 15 Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_IP") objConn.Close Response.End End If ' Validate subnet type ID If Not IsNumeric(subnettypeid) Or CLng(subnettypeid) < 1 Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_ID") objConn.Close Response.End End If ' Parse CIDR value (expected format: "cidr,ipend") If InStr(cidr, ",") = 0 Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If cidrarray = Split(cidr, ",") If UBound(cidrarray) < 1 Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If ipend = Trim(cidrarray(1)) cidr = Trim(cidrarray(0)) ' Remove leading slash if present (CIDR comes as "/24" format) If Left(cidr, 1) = "/" Then cidr = Mid(cidr, 2) End If ' Validate CIDR is numeric (0-32) If Not IsNumeric(cidr) Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If If CInt(cidr) < 0 Or CInt(cidr) > 32 Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If ' Validate ipend is numeric If Not IsNumeric(ipend) Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If ' Validate description length If Len(description) > 500 Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT") objConn.Close Response.End End If ' Escape quotes description = Replace(description, "'", "''") ipstart = Replace(ipstart, "'", "''") ' Verify subnet type exists checkSQL = "SELECT COUNT(*) as cnt FROM subnettypes WHERE subnettypeid = " & subnettypeid Set rsCheck = objConn.Execute(checkSQL) Dim typeExists typeExists = False If Not rsCheck.EOF Then If Not IsNull(rsCheck("cnt")) Then If CLng(rsCheck("cnt")) > 0 Then typeExists = True End If End If End If rsCheck.Close Set rsCheck = Nothing If Not typeExists Then Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=NOT_FOUND") objConn.Close Response.End End If ' Update Dim strSQL strSQL = "UPDATE subnets SET vlan = " & vlan & ", ipstart = INET_ATON('" & ipstart & "'), ipend = (INET_ATON('" & ipstart & "') + " & ipend & "), cidr = '" & cidr & "', subnettypeid = " & subnettypeid & ", description = '" & description & "' WHERE subnetid = " & subnetid On Error Resume Next objConn.Execute strSQL If Err.Number = 0 Then objConn.Close Response.Redirect("./displaysubnet.asp?subnetid=" & subnetid) Else Response.Write("Error: " & Err.Description) objConn.Close End If %>