Security fixes and schema cleanup

- Fix SQL injection in displayprofile.asp (parameterized query)
- Add HTMLEncode to XSS-vulnerable output in 5 display pages
- Add Option Explicit to computers.asp, displaymachines.asp, displaypcs.asp, displayapplication.asp, displayprofile.asp
- Update STANDARDS.md with test script reference, secrets management, column naming gotchas
- Fix equipment type ranges in CLAUDE.md and QUICK_REFERENCE.md (1-15, 21-25)
- Add migration SQL to cleanup redundant PC machinetypes (34-46)

🤖 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 07:22:16 -05:00
parent 693789138d
commit e0d89f9957
9 changed files with 258 additions and 57 deletions

View File

@@ -0,0 +1,110 @@
-- ============================================================================
-- ShopDB Database Migration: Cleanup Redundant PC Machinetypes
-- Date: 2025-12-12
-- Purpose: Remove redundant PC machinetypes (34-46) since pctypeid handles categorization
-- ============================================================================
--
-- CHANGES:
-- 1. Add primary key to installedapps table
-- 2. Migrate machines using PC-specific machinetypes to generic PC (33) + pctypeid
-- 3. Update models to use generic PC machinetype
-- 4. Remove unused PC machinetypes (34-43, 45-46), keep USB Device (44)
--
-- RUN ON: Production database
-- BACKUP FIRST: mysqldump -u root -p shopdb > shopdb_backup_$(date +%Y%m%d).sql
-- ============================================================================
-- Start transaction for safety
START TRANSACTION;
-- ============================================================================
-- 1. ADD PRIMARY KEY TO INSTALLEDAPPS TABLE
-- ============================================================================
ALTER TABLE installedapps
ADD COLUMN installedappid INT AUTO_INCREMENT PRIMARY KEY FIRST;
SELECT 'Added PK to installedapps' AS status;
-- ============================================================================
-- 2. MIGRATE MACHINES FROM PC-SPECIFIC TYPES TO GENERIC PC (33) + PCTYPEID
-- ============================================================================
-- PC - Standard (36) → machinetypeid=33, pctypeid=1 (Standard)
UPDATE machines
SET machinetypeid = 33, pctypeid = 1
WHERE machinetypeid = 36;
SELECT CONCAT('Migrated ', ROW_COUNT(), ' PC-Standard machines') AS status;
-- PC - CMM (41) → machinetypeid=33, pctypeid=5 (CMM)
UPDATE machines
SET machinetypeid = 33, pctypeid = 5
WHERE machinetypeid = 41;
SELECT CONCAT('Migrated ', ROW_COUNT(), ' PC-CMM machines') AS status;
-- Handle any other PC types that might exist in production
-- PC - Shopfloor (37) → machinetypeid=33, pctypeid=3 (Shopfloor)
UPDATE machines
SET machinetypeid = 33, pctypeid = 3
WHERE machinetypeid = 37 AND pctypeid IS NULL;
-- PC - Engineer (38) → machinetypeid=33, pctypeid=2 (Engineer)
UPDATE machines
SET machinetypeid = 33, pctypeid = 2
WHERE machinetypeid = 38 AND pctypeid IS NULL;
-- PC - Wax Trace (42) → machinetypeid=33, pctypeid=6 (Wax / Trace)
UPDATE machines
SET machinetypeid = 33, pctypeid = 6
WHERE machinetypeid = 42 AND pctypeid IS NULL;
-- Catch-all: Any remaining 34-46 → machinetypeid=33, pctypeid=4 (Uncategorized)
UPDATE machines
SET machinetypeid = 33, pctypeid = 4
WHERE machinetypeid BETWEEN 34 AND 46 AND pctypeid IS NULL;
SELECT CONCAT('Total machines now using machinetypeid 34-46: ',
(SELECT COUNT(*) FROM machines WHERE machinetypeid BETWEEN 34 AND 46)) AS status;
-- ============================================================================
-- 3. UPDATE MODELS TO USE GENERIC PC MACHINETYPE (33)
-- ============================================================================
UPDATE models
SET machinetypeid = 33
WHERE machinetypeid BETWEEN 34 AND 46;
SELECT CONCAT('Updated ', ROW_COUNT(), ' models to generic PC type') AS status;
-- ============================================================================
-- 4. DELETE REDUNDANT MACHINETYPES
-- ============================================================================
-- Keep 33 (PC) and 44 (USB Device), remove 34-43 and 45-46
DELETE FROM machinetypes WHERE machinetypeid BETWEEN 34 AND 43;
SELECT CONCAT('Deleted ', ROW_COUNT(), ' machinetypes (34-43)') AS status;
DELETE FROM machinetypes WHERE machinetypeid BETWEEN 45 AND 46;
SELECT CONCAT('Deleted ', ROW_COUNT(), ' machinetypes (45-46)') AS status;
-- ============================================================================
-- VERIFICATION
-- ============================================================================
SELECT 'VERIFICATION - Remaining machinetypes >= 33:' AS info;
SELECT machinetypeid, machinetype FROM machinetypes WHERE machinetypeid >= 33;
SELECT 'VERIFICATION - Machines by pctypeid:' AS info;
SELECT pt.typename, COUNT(*) as count
FROM machines m
JOIN pctype pt ON m.pctypeid = pt.pctypeid
WHERE m.pctypeid IS NOT NULL
GROUP BY m.pctypeid
ORDER BY count DESC;
-- ============================================================================
-- COMMIT (uncomment when ready to apply)
-- ============================================================================
COMMIT;
-- ROLLBACK; -- Use this instead if something looks wrong
SELECT 'Migration completed successfully!' AS status;