Centralize credentials and make migration idempotent

- Move all DB credentials to config.asp with DSN/ODBC toggle
- Add Zabbix API URL and token to centralized config
- Update sql.asp, api.asp, apiusb.asp, zabbix.asp to use config
- Add GetConnectionString() and GetEmployeeConnectionString() functions
- Make migration SQL idempotent (safe to run multiple times)
- Add duplicate index cleanup (appname_2) to migration
- Document employee DB access limitation in CLAUDE.md

🤖 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-12 08:11:28 -05:00
parent e0d89f9957
commit 131aaaddbf
9 changed files with 150 additions and 77 deletions

View File

@@ -10,8 +10,17 @@
'=============================================================================
'-----------------------------------------------------------------------------
' Database Configuration
' Database Configuration - ShopDB (primary)
'-----------------------------------------------------------------------------
' Set USE_DSN = True for production (DSN-based), False for dev (direct ODBC)
Const USE_DSN = False
' DSN configuration (production)
Const DB_DSN = "shopdb"
Const DB_DSN_USER = "570005354"
Const DB_DSN_PASSWORD = "570005354"
' Direct ODBC configuration (development)
Const DB_DRIVER = "MySQL ODBC 9.4 Unicode Driver"
Const DB_SERVER = "192.168.122.1"
Const DB_PORT = "3306"
@@ -19,6 +28,25 @@ Const DB_NAME = "shopdb"
Const DB_USER = "570005354"
Const DB_PASSWORD = "570005354"
'-----------------------------------------------------------------------------
' Database Configuration - Employee Database
'-----------------------------------------------------------------------------
' Set USE_EMP_DSN = True for production (DSN-based), False for dev (direct ODBC)
Const USE_EMP_DSN = True
' DSN configuration (production)
Const EMP_DB_DSN = "wjf_employees"
Const EMP_DB_DSN_USER = "root"
Const EMP_DB_DSN_PASSWORD = "WJF11sql"
' Direct ODBC configuration (development) - configure if needed
Const EMP_DB_DRIVER = "MySQL ODBC 9.4 Unicode Driver"
Const EMP_DB_SERVER = "localhost"
Const EMP_DB_PORT = "3306"
Const EMP_DB_NAME = "wjf_employees"
Const EMP_DB_USER = "root"
Const EMP_DB_PASSWORD = "WJF11sql"
'-----------------------------------------------------------------------------
' Application Settings
'-----------------------------------------------------------------------------
@@ -42,11 +70,17 @@ Const DEFAULT_MODEL_ID = 1 ' Default model
Const DEFAULT_OS_ID = 1 ' Default operating system
'-----------------------------------------------------------------------------
' External Services
' External Services - ServiceNow
'-----------------------------------------------------------------------------
Const SNOW_BASE_URL = "https://geit.service-now.com/now/nav/ui/search/"
Const SNOW_TICKET_PREFIXES = "geinc,gechg,gerit,gesct" ' Valid ServiceNow ticket prefixes
'-----------------------------------------------------------------------------
' External Services - Zabbix API
'-----------------------------------------------------------------------------
Const ZABBIX_URL = "http://10.48.130.113:8080/api_jsonrpc.php"
Const ZABBIX_API_TOKEN = "9e60b0544ec77131d94825eaa2f3f1645335539361fd33644aeb8326697aa48d"
'-----------------------------------------------------------------------------
' File Upload
'-----------------------------------------------------------------------------
@@ -59,18 +93,45 @@ Const ALLOWED_EXTENSIONS = "jpg,jpeg,png,gif,pdf"
'-----------------------------------------------------------------------------
' FUNCTION: GetConnectionString
' PURPOSE: Returns the database connection string with all parameters
' RETURNS: Complete ODBC connection string
' PURPOSE: Returns the database connection string based on USE_DSN setting
' RETURNS: DSN connection string (production) or direct ODBC string (dev)
'-----------------------------------------------------------------------------
Function GetConnectionString()
GetConnectionString = "Driver={" & DB_DRIVER & "};" & _
"Server=" & DB_SERVER & ";" & _
"Port=" & DB_PORT & ";" & _
"Database=" & DB_NAME & ";" & _
"User=" & DB_USER & ";" & _
"Password=" & DB_PASSWORD & ";" & _
"Option=3;" & _
"Pooling=True;Max Pool Size=100;"
If USE_DSN Then
' Production: DSN-based connection with pooling
GetConnectionString = "DSN=" & DB_DSN & ";Uid=" & DB_DSN_USER & ";Pwd=" & DB_DSN_PASSWORD & ";Option=3;Pooling=True;Max Pool Size=100;"
Else
' Development: Direct ODBC driver connection
GetConnectionString = "Driver={" & DB_DRIVER & "};" & _
"Server=" & DB_SERVER & ";" & _
"Port=" & DB_PORT & ";" & _
"Database=" & DB_NAME & ";" & _
"User=" & DB_USER & ";" & _
"Password=" & DB_PASSWORD & ";" & _
"Option=3;" & _
"Pooling=True;Max Pool Size=100;"
End If
End Function
'-----------------------------------------------------------------------------
' FUNCTION: GetEmployeeConnectionString
' PURPOSE: Returns the employee database connection string based on USE_EMP_DSN
' RETURNS: DSN connection string (production) or direct ODBC string (dev)
'-----------------------------------------------------------------------------
Function GetEmployeeConnectionString()
If USE_EMP_DSN Then
' Production: DSN-based connection
GetEmployeeConnectionString = "DSN=" & EMP_DB_DSN & ";Uid=" & EMP_DB_DSN_USER & ";Pwd=" & EMP_DB_DSN_PASSWORD
Else
' Development: Direct ODBC driver connection
GetEmployeeConnectionString = "Driver={" & EMP_DB_DRIVER & "};" & _
"Server=" & EMP_DB_SERVER & ";" & _
"Port=" & EMP_DB_PORT & ";" & _
"Database=" & EMP_DB_NAME & ";" & _
"User=" & EMP_DB_USER & ";" & _
"Password=" & EMP_DB_PASSWORD & ";" & _
"Option=3;"
End If
End Function
'-----------------------------------------------------------------------------

View File

@@ -1,18 +1,9 @@
<!--#include file="config.asp"-->
<%
' objConn - script-global connection object (no Dim for global scope)
Session.Timeout=15
Set objConn=Server.CreateObject("ADODB.Connection")
' Old DSN connection:
' objConn.ConnectionString="DSN=shopdb;Uid=root;Pwd=WJF11sql"
' Direct MySQL ODBC connection with pooling enabled:
objConn.ConnectionString="Driver={MySQL ODBC 9.4 Unicode Driver};" & _
"Server=192.168.122.1;" & _
"Port=3306;" & _
"Database=shopdb;" & _
"User=570005354;" & _
"Password=570005354;" & _
"Option=3;" & _
"Pooling=True;Max Pool Size=100;"
Session.Timeout = APP_SESSION_TIMEOUT
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = GetConnectionString()
objConn.Open
set rs = server.createobject("ADODB.Recordset")
Set rs = Server.CreateObject("ADODB.Recordset")
%>

View File

@@ -1,8 +1,10 @@
<!--#include file="config.asp"-->
<%
' Employee database connection - uses centralized config
Dim objConn
Session.Timeout=15
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="DSN=wjf_employees;Uid=root;Pwd=WJF11sql"
objConn.Open
set rs = server.createobject("ADODB.Recordset")
Session.Timeout = APP_SESSION_TIMEOUT
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = GetEmployeeConnectionString()
objConn.Open
Set rs = Server.CreateObject("ADODB.Recordset")
%>

View File

@@ -1,7 +1,6 @@
<!--#include file="config.asp"-->
<%
' Zabbix API Configuration
Const ZABBIX_URL = "http://10.48.130.113:8080/api_jsonrpc.php"
Const ZABBIX_API_TOKEN = "9e60b0544ec77131d94825eaa2f3f1645335539361fd33644aeb8326697aa48d"
' Zabbix API Configuration - uses ZABBIX_URL and ZABBIX_API_TOKEN from config.asp
' Function to make HTTP POST request to Zabbix API with Bearer token
Function ZabbixAPICall(jsonRequest)