Update displaysubnet.asp to match displaypc.asp style, add email API helper

- Rewrite displaysubnet.asp with two-column layout and profile card
- Add Details, Devices, and Edit tabs matching other display pages
- Use parameterized queries and HTML encoding for security
- Fix device queries to use machines/communications tables
- Add includes/email.asp helper for Python Email API integration
- Update api.asp GetShopfloorPCs to include all PC types with 10.134.* IPs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-29 17:44:44 -05:00
parent 8a50f5c7b4
commit b0b300babd
3 changed files with 538 additions and 136 deletions

171
includes/email.asp Normal file
View File

@@ -0,0 +1,171 @@
<%
'=============================================================================
' FILE: includes/email.asp
' PURPOSE: Helper functions for sending emails via the Python Email API
' USAGE: Include this file, then call SendEmail() or SendEmailToGroup()
'
' REQUIREMENTS: Python Email API must be running on EMAIL_API_URL
'=============================================================================
' Configuration - adjust if API runs on different host/port
Const EMAIL_API_URL = "http://localhost:5000"
Const EMAIL_API_KEY = "" ' Set if API requires authentication
'-----------------------------------------------------------------------------
' SendEmail - Send an email via the Email API
'
' Parameters:
' toAddress - Email address or comma-separated list
' subject - Email subject
' message - Email body (plain text or HTML)
' isHtml - True if message is HTML (optional, default False)
'
' Returns: True on success, False on failure
'-----------------------------------------------------------------------------
Function SendEmail(toAddress, subject, message, isHtml)
On Error Resume Next
Dim http, url, jsonBody, response
' Build JSON body
jsonBody = "{" & _
"""to"": """ & EscapeJson(toAddress) & """," & _
"""subject"": """ & EscapeJson(subject) & """," & _
"""message"": """ & EscapeJson(message) & """," & _
"""html"": " & LCase(CStr(isHtml)) & _
"}"
url = EMAIL_API_URL & "/api/send"
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.setTimeouts 5000, 5000, 10000, 30000 ' resolve, connect, send, receive
http.open "POST", url, False
http.setRequestHeader "Content-Type", "application/json"
If EMAIL_API_KEY <> "" Then
http.setRequestHeader "X-API-Key", EMAIL_API_KEY
End If
http.send jsonBody
If Err.Number <> 0 Then
SendEmail = False
Exit Function
End If
' Check response
If http.status = 200 Then
SendEmail = True
Else
SendEmail = False
End If
Set http = Nothing
End Function
'-----------------------------------------------------------------------------
' SendEmailToGroup - Send email to a distribution group
'
' Parameters:
' groupId - Distribution group ID from database
' subject - Email subject
' message - Email body
' isHtml - True if message is HTML (optional)
'
' Returns: True on success, False on failure
'-----------------------------------------------------------------------------
Function SendEmailToGroup(groupId, subject, message, isHtml)
On Error Resume Next
Dim http, url, jsonBody
jsonBody = "{" & _
"""group_id"": " & CInt(groupId) & "," & _
"""subject"": """ & EscapeJson(subject) & """," & _
"""message"": """ & EscapeJson(message) & """," & _
"""html"": " & LCase(CStr(isHtml)) & _
"}"
url = EMAIL_API_URL & "/api/send-to-group"
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.setTimeouts 5000, 5000, 10000, 30000
http.open "POST", url, False
http.setRequestHeader "Content-Type", "application/json"
If EMAIL_API_KEY <> "" Then
http.setRequestHeader "X-API-Key", EMAIL_API_KEY
End If
http.send jsonBody
If Err.Number <> 0 Then
SendEmailToGroup = False
Exit Function
End If
If http.status = 200 Then
SendEmailToGroup = True
Else
SendEmailToGroup = False
End If
Set http = Nothing
End Function
'-----------------------------------------------------------------------------
' SendEmailToGroupByName - Send email to a distribution group by name
'-----------------------------------------------------------------------------
Function SendEmailToGroupByName(groupName, subject, message, isHtml)
On Error Resume Next
Dim http, url, jsonBody
jsonBody = "{" & _
"""group_name"": """ & EscapeJson(groupName) & """," & _
"""subject"": """ & EscapeJson(subject) & """," & _
"""message"": """ & EscapeJson(message) & """," & _
"""html"": " & LCase(CStr(isHtml)) & _
"}"
url = EMAIL_API_URL & "/api/send-to-group"
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.setTimeouts 5000, 5000, 10000, 30000
http.open "POST", url, False
http.setRequestHeader "Content-Type", "application/json"
If EMAIL_API_KEY <> "" Then
http.setRequestHeader "X-API-Key", EMAIL_API_KEY
End If
http.send jsonBody
If Err.Number <> 0 Then
SendEmailToGroupByName = False
Exit Function
End If
If http.status = 200 Then
SendEmailToGroupByName = True
Else
SendEmailToGroupByName = False
End If
Set http = Nothing
End Function
'-----------------------------------------------------------------------------
' EscapeJson - Escape special characters for JSON
'-----------------------------------------------------------------------------
Function EscapeJson(str)
Dim result
result = str
result = Replace(result, "\", "\\")
result = Replace(result, """", "\""")
result = Replace(result, vbCr, "\r")
result = Replace(result, vbLf, "\n")
result = Replace(result, vbTab, "\t")
EscapeJson = result
End Function
%>