Add eDNC-Fix API endpoints and displaypc.asp integration
API endpoints: - logDNCEvent: Log events from eDNC-Fix PowerShell script - getDNCStats: Get all eDNC installations and stats Database tables (sql/ednc_tables.sql): - ednc_logs: Event log entries - ednc_installations: Per-hostname tracking displaypc.asp: - Shows eDNC-Fix stats in Applications tab if installed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
153
api.asp
153
api.asp
@@ -49,6 +49,10 @@ Select Case action
|
||||
GetRecordedIP()
|
||||
Case "updateMachinePositions"
|
||||
UpdateMachinePositions()
|
||||
Case "logDNCEvent"
|
||||
LogDNCEvent()
|
||||
Case "getDNCStats"
|
||||
GetDNCStats()
|
||||
Case Else
|
||||
SendError "Invalid action: " & action
|
||||
End Select
|
||||
@@ -2541,4 +2545,153 @@ Sub UpdateMachinePositions()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
' ============================================================================
|
||||
' eDNC SPECIAL CHARACTER FIX - LOGGING
|
||||
' ============================================================================
|
||||
|
||||
Sub LogDNCEvent()
|
||||
On Error Resume Next
|
||||
|
||||
' Get parameters
|
||||
Dim hostname, filename, eventAction, bytesRemoved, version, message, watchFolder, fileFilter
|
||||
hostname = Trim(Request.Form("hostname") & "")
|
||||
filename = Trim(Request.Form("filename") & "")
|
||||
eventAction = Trim(Request.Form("eventType") & "")
|
||||
bytesRemoved = Request.Form("bytesRemoved")
|
||||
version = Trim(Request.Form("version") & "")
|
||||
message = Trim(Request.Form("message") & "")
|
||||
watchFolder = Trim(Request.Form("watchFolder") & "")
|
||||
fileFilter = Trim(Request.Form("fileFilter") & "")
|
||||
|
||||
' Validate required fields
|
||||
If hostname = "" Or eventAction = "" Then
|
||||
SendError "hostname and eventType are required"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Sanitize inputs
|
||||
Dim safeHostname, safeFilename, safeAction, safeVersion, safeMessage, safeWatchFolder, safeFileFilter
|
||||
safeHostname = Replace(hostname, "'", "''")
|
||||
safeFilename = Replace(filename, "'", "''")
|
||||
safeAction = Replace(eventAction, "'", "''")
|
||||
safeVersion = Replace(version, "'", "''")
|
||||
safeMessage = Replace(message, "'", "''")
|
||||
safeWatchFolder = Replace(watchFolder, "'", "''")
|
||||
safeFileFilter = Replace(fileFilter, "'", "''")
|
||||
|
||||
' Default bytesRemoved to 0 if not numeric
|
||||
If Not IsNumeric(bytesRemoved) Or bytesRemoved = "" Then bytesRemoved = 0
|
||||
|
||||
' Insert log entry
|
||||
Dim insertSQL
|
||||
insertSQL = "INSERT INTO ednc_logs (hostname, filename, action, bytes_removed, version, message) " & _
|
||||
"VALUES ('" & safeHostname & "', '" & safeFilename & "', '" & safeAction & "', " & _
|
||||
CLng(bytesRemoved) & ", '" & safeVersion & "', '" & safeMessage & "')"
|
||||
objConn.Execute insertSQL
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
SendError "Failed to log event: " & Err.Description
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Update or insert installation record
|
||||
Dim checkSQL, rsCheck
|
||||
checkSQL = "SELECT installid, total_cleaned, total_failed FROM ednc_installations WHERE hostname = '" & safeHostname & "'"
|
||||
Set rsCheck = objConn.Execute(checkSQL)
|
||||
|
||||
If rsCheck.EOF Then
|
||||
' New installation - INSERT
|
||||
Dim installSQL
|
||||
installSQL = "INSERT INTO ednc_installations (hostname, version, watch_folder, file_filter, total_cleaned, total_failed) " & _
|
||||
"VALUES ('" & safeHostname & "', '" & safeVersion & "', '" & safeWatchFolder & "', '" & safeFileFilter & "', "
|
||||
If eventAction = "cleaned" Then
|
||||
installSQL = installSQL & "1, 0)"
|
||||
ElseIf eventAction = "failed" Or eventAction = "error" Then
|
||||
installSQL = installSQL & "0, 1)"
|
||||
Else
|
||||
installSQL = installSQL & "0, 0)"
|
||||
End If
|
||||
objConn.Execute installSQL
|
||||
Else
|
||||
' Existing installation - UPDATE
|
||||
Dim totalCleaned, totalFailed, updateSQL
|
||||
totalCleaned = CLng(rsCheck("total_cleaned"))
|
||||
totalFailed = CLng(rsCheck("total_failed"))
|
||||
|
||||
If eventAction = "cleaned" Then
|
||||
totalCleaned = totalCleaned + 1
|
||||
ElseIf eventAction = "failed" Or eventAction = "error" Then
|
||||
totalFailed = totalFailed + 1
|
||||
End If
|
||||
|
||||
updateSQL = "UPDATE ednc_installations SET " & _
|
||||
"version = '" & safeVersion & "', " & _
|
||||
"last_seen = NOW(), " & _
|
||||
"total_cleaned = " & totalCleaned & ", " & _
|
||||
"total_failed = " & totalFailed
|
||||
If safeWatchFolder <> "" Then
|
||||
updateSQL = updateSQL & ", watch_folder = '" & safeWatchFolder & "'"
|
||||
End If
|
||||
If safeFileFilter <> "" Then
|
||||
updateSQL = updateSQL & ", file_filter = '" & safeFileFilter & "'"
|
||||
End If
|
||||
updateSQL = updateSQL & " WHERE hostname = '" & safeHostname & "'"
|
||||
objConn.Execute updateSQL
|
||||
End If
|
||||
rsCheck.Close
|
||||
Set rsCheck = Nothing
|
||||
|
||||
' Send success response
|
||||
Response.Write "{""success"":true,""message"":""Event logged""}"
|
||||
End Sub
|
||||
|
||||
Sub GetDNCStats()
|
||||
On Error Resume Next
|
||||
|
||||
' Get installations with recent activity
|
||||
Dim sql, rs
|
||||
sql = "SELECT i.hostname, i.version, i.watch_folder, i.file_filter, " & _
|
||||
"i.first_seen, i.last_seen, i.is_active, i.total_cleaned, i.total_failed, " & _
|
||||
"(SELECT COUNT(*) FROM ednc_logs l WHERE l.hostname = i.hostname AND l.created > DATE_SUB(NOW(), INTERVAL 24 HOUR)) AS events_24h " & _
|
||||
"FROM ednc_installations i ORDER BY i.last_seen DESC"
|
||||
|
||||
Set rs = objConn.Execute(sql)
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
SendError "Database error: " & Err.Description
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Build JSON response
|
||||
Dim json, first
|
||||
json = "{""success"":true,""installations"":["
|
||||
first = True
|
||||
|
||||
Do While Not rs.EOF
|
||||
If Not first Then json = json & ","
|
||||
first = False
|
||||
|
||||
json = json & "{" & _
|
||||
"""hostname"":""" & (rs("hostname") & "") & """," & _
|
||||
"""version"":""" & (rs("version") & "") & """," & _
|
||||
"""watchFolder"":""" & Replace(rs("watch_folder") & "", "\", "\\") & """," & _
|
||||
"""fileFilter"":""" & (rs("file_filter") & "") & """," & _
|
||||
"""firstSeen"":""" & (rs("first_seen") & "") & """," & _
|
||||
"""lastSeen"":""" & (rs("last_seen") & "") & """," & _
|
||||
"""isActive"":" & rs("is_active") & "," & _
|
||||
"""totalCleaned"":" & rs("total_cleaned") & "," & _
|
||||
"""totalFailed"":" & rs("total_failed") & "," & _
|
||||
"""events24h"":" & rs("events_24h") & _
|
||||
"}"
|
||||
rs.MoveNext
|
||||
Loop
|
||||
|
||||
json = json & "]}"
|
||||
|
||||
rs.Close
|
||||
Set rs = Nothing
|
||||
|
||||
Response.Write json
|
||||
End Sub
|
||||
|
||||
%>
|
||||
|
||||
Reference in New Issue
Block a user