Consolidate documentation: archive 45+ historical docs
- Move completed migration docs to docs/archive/ - Move session summaries to docs/archive/sessions/ - Rename API_ASP_DOCUMENTATION.md to docs/API.md - Archive redundant Claude reference files - Update docs/README.md as simplified index - Reduce active docs from 45+ files to 8 essential files Remaining docs: - CLAUDE.md (AI context) - TODO.md (task tracking) - docs/README.md, API.md, QUICK_REFERENCE.md - docs/ASP_DEVELOPMENT_GUIDE.md, STANDARDS.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:
827
docs/API.md
Normal file
827
docs/API.md
Normal file
@@ -0,0 +1,827 @@
|
||||
# ShopDB API (ASP) - PowerShell Data Collection Endpoint
|
||||
|
||||
**File:** `api.asp`
|
||||
**Created:** 2025-11-13
|
||||
**Purpose:** Receive PC asset data from PowerShell scripts and store in Phase 2 schema
|
||||
**Schema:** Phase 2 (machines, communications, machinerelationships)
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
This ASP API replaces the PHP api.php and provides the same functionality but runs on IIS with the ShopDB ASP application. It's designed to work with Phase 2 schema from day one.
|
||||
|
||||
**Key Features:**
|
||||
- Uses Phase 2 schema (machines, communications)
|
||||
- Parameterized queries (SQL injection protection)
|
||||
- JSON request/response handling
|
||||
- Automatic vendor/model/pctype creation
|
||||
- PC-to-equipment relationship management
|
||||
- Network interface tracking
|
||||
- DNC configuration storage
|
||||
- Warranty data management
|
||||
- Application tracking
|
||||
|
||||
---
|
||||
|
||||
## Endpoints
|
||||
|
||||
### 1. `updateCompleteAsset`
|
||||
|
||||
**Purpose:** Main endpoint for PowerShell data collection
|
||||
|
||||
**Method:** POST
|
||||
|
||||
**Parameters:**
|
||||
|
||||
**Basic PC Info (Required):**
|
||||
- `hostname` - PC hostname
|
||||
- `serialNumber` - Serial number
|
||||
- `manufacturer` - Manufacturer (e.g., "Dell", "HP")
|
||||
- `model` - Model name
|
||||
- `pcType` - PC type ("Engineer", "Shopfloor", "Standard")
|
||||
|
||||
**Basic PC Info (Optional):**
|
||||
- `loggedInUser` - Current logged in user
|
||||
- `machineNo` - Machine number (for shopfloor PCs)
|
||||
- `osVersion` - Operating system version
|
||||
|
||||
**Warranty Info (Optional):**
|
||||
- `warrantyEndDate` - Warranty end date (YYYY-MM-DD)
|
||||
- `warrantyStatus` - Status ("Active", "Expired", etc.)
|
||||
- `warrantyServiceLevel` - Service level description
|
||||
- `warrantyDaysRemaining` - Days until warranty expires
|
||||
|
||||
**Shopfloor Data (Optional):**
|
||||
- `networkInterfaces` - JSON array of network interfaces
|
||||
- `commConfigs` - JSON array of serial port configs
|
||||
- `dncConfig` - JSON object with DNC configuration
|
||||
|
||||
**DNC/GE Registry Data (Optional):**
|
||||
- `dncDualPathEnabled` - Boolean (true/false)
|
||||
- `dncPath1Name` - Path 1 name
|
||||
- `dncPath2Name` - Path 2 name
|
||||
- `dncGeRegistry32Bit` - Boolean for 32-bit registry
|
||||
- `dncGeRegistry64Bit` - Boolean for 64-bit registry
|
||||
- `dncGeRegistryNotes` - Registry notes
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "PC asset data updated successfully",
|
||||
"machineid": 123,
|
||||
"hostname": "PC-NAME",
|
||||
"operation": "complete",
|
||||
"data": {
|
||||
"networkInterfaces": 3,
|
||||
"commConfigs": 2,
|
||||
"dncConfig": true,
|
||||
"relationshipCreated": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Database Operations:**
|
||||
1. Insert/update record in `machines` table with `pctypeid IS NOT NULL`
|
||||
2. Clear old network interfaces from `communications`
|
||||
3. Insert new network interfaces to `communications` with `comstypeid = 1`
|
||||
4. Clear old serial port configs from `pc_comm_config`
|
||||
5. Insert new serial port configs to `pc_comm_config`
|
||||
6. Clear old DNC config from `pc_dnc_config`
|
||||
7. Insert new DNC config to `pc_dnc_config`
|
||||
8. Create PC-to-equipment relationship in `machinerelationships` if `machineNo` provided
|
||||
9. Update warranty data in `warranties` table
|
||||
|
||||
---
|
||||
|
||||
### 2. `updatePrinterMapping`
|
||||
|
||||
**Purpose:** Map a PC to its default printer
|
||||
|
||||
**Method:** POST
|
||||
|
||||
**Parameters:**
|
||||
- `hostname` - PC hostname
|
||||
- `printerFQDN` - Printer FQDN or IP address
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Printer mapping updated",
|
||||
"data": {
|
||||
"printerId": 45,
|
||||
"machinesUpdated": 1,
|
||||
"matchMethod": "ip"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Database Operations:**
|
||||
1. Find PC by hostname in `machines` table
|
||||
2. Find printer by FQDN (tries name match, then IP match)
|
||||
3. Update `machines.printerid` to link PC to printer
|
||||
|
||||
---
|
||||
|
||||
### 3. `updateInstalledApps`
|
||||
|
||||
**Purpose:** Update installed applications for a PC
|
||||
|
||||
**Method:** POST
|
||||
|
||||
**Parameters:**
|
||||
- `hostname` - PC hostname
|
||||
- `installedApps` - JSON array of applications
|
||||
|
||||
**installedApps Format:**
|
||||
```json
|
||||
[
|
||||
{"Name": "SolidWorks 2024", "Version": "32.1.0"},
|
||||
{"Name": "AutoCAD", "Version": "2024.1"},
|
||||
{"Name": "Microsoft Office", "Version": "16.0"}
|
||||
]
|
||||
```
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Installed applications updated",
|
||||
"data": {
|
||||
"appsProcessed": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Database Operations:**
|
||||
1. Find PC by hostname in `machines` table
|
||||
2. Delete existing app mappings from `machineapplications`
|
||||
3. Create applications in `applications` table if they don't exist
|
||||
4. Insert new app mappings to `machineapplications`
|
||||
|
||||
---
|
||||
|
||||
### 4. `getDashboardData`
|
||||
|
||||
**Purpose:** Health check / connection test
|
||||
|
||||
**Method:** GET or POST
|
||||
|
||||
**Parameters:** None
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "ShopDB API is online",
|
||||
"version": "1.0",
|
||||
"schema": "Phase 2"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## JSON Formats
|
||||
|
||||
### Network Interfaces Format
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"IPAddress": "10.48.130.100",
|
||||
"MACAddress": "00:1A:2B:3C:4D:5E",
|
||||
"SubnetMask": "255.255.255.0",
|
||||
"DefaultGateway": "10.48.130.1",
|
||||
"InterfaceName": "Ethernet",
|
||||
"IsMachineNetwork": false
|
||||
},
|
||||
{
|
||||
"IPAddress": "192.168.1.100",
|
||||
"MACAddress": "00:1A:2B:3C:4D:5F",
|
||||
"SubnetMask": "255.255.255.0",
|
||||
"DefaultGateway": "192.168.1.1",
|
||||
"InterfaceName": "Machine Network",
|
||||
"IsMachineNetwork": true
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
**Stored in:** `communications` table
|
||||
- `comstypeid = 1` (Network Interface)
|
||||
- First interface with valid IP marked as `isprimary = 1`
|
||||
|
||||
---
|
||||
|
||||
### Communication Configs Format (Serial Ports)
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"PortName": "COM1",
|
||||
"BaudRate": 9600,
|
||||
"DataBits": 8,
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"FlowControl": "None"
|
||||
},
|
||||
{
|
||||
"PortName": "COM2",
|
||||
"BaudRate": 19200,
|
||||
"DataBits": 8,
|
||||
"Parity": "Even",
|
||||
"StopBits": "One",
|
||||
"FlowControl": "Hardware"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
**Stored in:** `pc_comm_config` table
|
||||
|
||||
---
|
||||
|
||||
### DNC Config Format
|
||||
|
||||
```json
|
||||
{
|
||||
"Site": "West Jefferson",
|
||||
"CNC": "FANUC",
|
||||
"NCIF": "eFOCAS",
|
||||
"MachineNumber": "2001",
|
||||
"HostType": "Control",
|
||||
"FTPHostPrimary": "192.168.1.100",
|
||||
"FTPHostSecondary": "192.168.1.101",
|
||||
"FTPAccount": "dnc_user",
|
||||
"Debug": "Off",
|
||||
"Uploads": "C:\\DNC\\Uploads",
|
||||
"Scanner": "On",
|
||||
"DripFeed": "Off",
|
||||
"AdditionalSettings": "timeout=30"
|
||||
}
|
||||
```
|
||||
|
||||
**Stored in:** `pc_dnc_config` table
|
||||
|
||||
**Additional DNC fields sent as separate parameters:**
|
||||
- `dncDualPathEnabled` - true/false
|
||||
- `dncPath1Name` - Path 1 name
|
||||
- `dncPath2Name` - Path 2 name
|
||||
- `dncGeRegistry32Bit` - true/false
|
||||
- `dncGeRegistry64Bit` - true/false
|
||||
- `dncGeRegistryNotes` - Text notes
|
||||
|
||||
---
|
||||
|
||||
## Database Schema
|
||||
|
||||
### Tables Used
|
||||
|
||||
#### machines (Main PC Storage)
|
||||
```sql
|
||||
CREATE TABLE machines (
|
||||
machineid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
hostname VARCHAR(100),
|
||||
serialnumber VARCHAR(50),
|
||||
modelnumberid INT(11),
|
||||
pctypeid INT(11), -- NOT NULL = PC, NULL = Equipment
|
||||
machinetypeid INT(11), -- 28-32 for PC types
|
||||
loggedinuser VARCHAR(100),
|
||||
machinenumber VARCHAR(50), -- For shopfloor PCs
|
||||
osid INT(11),
|
||||
machinestatusid INT(11),
|
||||
machinenotes TEXT,
|
||||
printerid INT(11), -- Default printer
|
||||
isactive TINYINT(1),
|
||||
lastupdated DATETIME
|
||||
);
|
||||
```
|
||||
|
||||
#### communications (Network Interfaces)
|
||||
```sql
|
||||
CREATE TABLE communications (
|
||||
comid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT(11),
|
||||
comstypeid INT(11), -- 1 = Network Interface
|
||||
address VARCHAR(45), -- IP address
|
||||
macaddress VARCHAR(17),
|
||||
subnetmask VARCHAR(45),
|
||||
gateway VARCHAR(45),
|
||||
interfacename VARCHAR(50),
|
||||
isprimary TINYINT(1),
|
||||
isactive TINYINT(1)
|
||||
);
|
||||
```
|
||||
|
||||
#### pc_comm_config (Serial Port Configs)
|
||||
```sql
|
||||
CREATE TABLE pc_comm_config (
|
||||
commconfigid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT(11), -- Changed from pcid
|
||||
portname VARCHAR(50),
|
||||
baudrate INT(11),
|
||||
databits INT(11),
|
||||
parity VARCHAR(20),
|
||||
stopbits VARCHAR(20),
|
||||
flowcontrol VARCHAR(50)
|
||||
);
|
||||
```
|
||||
|
||||
#### pc_dnc_config (DNC Configuration)
|
||||
```sql
|
||||
CREATE TABLE pc_dnc_config (
|
||||
dncconfigid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT(11), -- Changed from pcid
|
||||
site VARCHAR(50),
|
||||
cnc VARCHAR(50),
|
||||
ncif VARCHAR(50),
|
||||
machinenumber VARCHAR(50),
|
||||
hosttype VARCHAR(50),
|
||||
ftphostprimary VARCHAR(100),
|
||||
ftphostsecondary VARCHAR(100),
|
||||
ftpaccount VARCHAR(100),
|
||||
debug VARCHAR(50),
|
||||
uploads VARCHAR(100),
|
||||
scanner VARCHAR(50),
|
||||
dripfeed VARCHAR(50),
|
||||
additionalsettings VARCHAR(255),
|
||||
dualpath_enabled TINYINT(1),
|
||||
path1_name VARCHAR(100),
|
||||
path2_name VARCHAR(100),
|
||||
ge_registry_32bit TINYINT(1),
|
||||
ge_registry_64bit TINYINT(1),
|
||||
ge_registry_notes VARCHAR(255),
|
||||
lastupdated DATETIME
|
||||
);
|
||||
```
|
||||
|
||||
#### machinerelationships (PC-to-Equipment Links)
|
||||
```sql
|
||||
CREATE TABLE machinerelationships (
|
||||
relationshipid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT(11), -- Equipment ID
|
||||
related_machineid INT(11), -- PC ID
|
||||
relationshiptypeid INT(11), -- 3 = Controls
|
||||
isactive TINYINT(1)
|
||||
);
|
||||
```
|
||||
|
||||
#### warranties (Warranty Tracking)
|
||||
```sql
|
||||
CREATE TABLE warranties (
|
||||
warrantyid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT(11),
|
||||
enddate DATE,
|
||||
servicelevel VARCHAR(100),
|
||||
status VARCHAR(50),
|
||||
daysremaining INT(11),
|
||||
lastcheckeddate DATETIME
|
||||
);
|
||||
```
|
||||
|
||||
#### machineapplications (Installed Applications)
|
||||
```sql
|
||||
CREATE TABLE machineapplications (
|
||||
machineappid INT(11) PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT(11),
|
||||
applicationid INT(11)
|
||||
);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Automatic Lookups
|
||||
|
||||
The API automatically creates records in these tables if they don't exist:
|
||||
|
||||
### vendors
|
||||
- Created when new manufacturer is encountered
|
||||
- Lookup: `SELECT vendorid FROM vendors WHERE vendor = ?`
|
||||
- Create: `INSERT INTO vendors (vendor) VALUES (?)`
|
||||
|
||||
### models
|
||||
- Created when new model is encountered for a vendor
|
||||
- Lookup: `SELECT modelnumberid FROM models WHERE modelnumber = ? AND vendorid = ?`
|
||||
- Create: `INSERT INTO models (modelnumber, vendorid, notes, isactive) VALUES (?, ?, 'Auto-imported via PowerShell', 1)`
|
||||
|
||||
### pctype
|
||||
- Created when new PC type is encountered
|
||||
- Lookup: `SELECT pctypeid FROM pctype WHERE typename = ?`
|
||||
- Create: `INSERT INTO pctype (typename) VALUES (?)`
|
||||
|
||||
### operatingsystems
|
||||
- Created when new OS version is encountered
|
||||
- Lookup: `SELECT osid FROM operatingsystems WHERE osname = ?`
|
||||
- Create: `INSERT INTO operatingsystems (osname) VALUES (?)`
|
||||
|
||||
### applications
|
||||
- Created when new application is encountered
|
||||
- Lookup: `SELECT applicationid FROM applications WHERE applicationname = ?`
|
||||
- Create: `INSERT INTO applications (applicationname, version) VALUES (?, ?)`
|
||||
|
||||
---
|
||||
|
||||
## PC Type to Machine Type Mapping
|
||||
|
||||
When creating PCs, `machinetypeid` is automatically determined from `pctypeid`:
|
||||
|
||||
| PC Type Name | pctypeid | machinetypeid | Machine Type |
|
||||
|--------------|----------|---------------|--------------|
|
||||
| Engineer | varies | 30 | Workstation |
|
||||
| Shopfloor | varies | 28 | Desktop PC |
|
||||
| Standard | varies | 28 | Desktop PC |
|
||||
| Laptop | varies | 29 | Laptop |
|
||||
| Thin Client | varies | 31 | Thin Client |
|
||||
| Server | varies | 32 | Server |
|
||||
|
||||
This mapping allows:
|
||||
- PCs to be filtered with `WHERE pctypeid IS NOT NULL`
|
||||
- PC-specific queries to join to `machinetypes` table
|
||||
- Unified reporting across PCs and equipment
|
||||
|
||||
---
|
||||
|
||||
## Error Responses
|
||||
|
||||
All errors return HTTP 200 with JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"error": "Error message here"
|
||||
}
|
||||
```
|
||||
|
||||
**Common Errors:**
|
||||
- `"hostname and serialNumber are required"` - Missing required fields
|
||||
- `"PC not found: HOSTNAME"` - PC doesn't exist in database
|
||||
- `"Printer not found: FQDN"` - Printer not found by FQDN or IP
|
||||
- `"Failed to insert/update PC: SQL error"` - Database error
|
||||
- `"Invalid action: ACTION"` - Unknown action parameter
|
||||
|
||||
---
|
||||
|
||||
## Security Features
|
||||
|
||||
### SQL Injection Protection
|
||||
All queries use parameterized commands:
|
||||
```asp
|
||||
Set cmd = Server.CreateObject("ADODB.Command")
|
||||
cmd.ActiveConnection = objConn
|
||||
cmd.CommandText = "SELECT machineid FROM machines WHERE hostname = ?"
|
||||
cmd.Parameters.Append cmd.CreateParameter("@hostname", 200, 1, 100, hostname)
|
||||
Set rsResult = cmd.Execute
|
||||
```
|
||||
|
||||
### Input Validation
|
||||
- Required field checks
|
||||
- Numeric validation for IDs
|
||||
- Boolean conversion for true/false values
|
||||
- String length limits enforced
|
||||
|
||||
### HTML/JSON Escaping
|
||||
- All JSON output properly escaped
|
||||
- Special characters handled: `\`, `"`, CR, LF, TAB
|
||||
|
||||
---
|
||||
|
||||
## Logging
|
||||
|
||||
API logs to: `/logs/api.log`
|
||||
|
||||
**Log Format:** `YYYY-MM-DD HH:MM:SS - Message`
|
||||
|
||||
**Logged Events:**
|
||||
- New requests with hostname/serial/pctype
|
||||
- Vendor/Model/PCType ID lookups
|
||||
- Record creation (machineid)
|
||||
- Network interface insertion counts
|
||||
- Comm config insertion counts
|
||||
- DNC config insertion success
|
||||
- PC-Machine relationship creation
|
||||
- Errors with full error descriptions
|
||||
|
||||
**Log Directory:** Must exist and be writable by IIS process
|
||||
|
||||
---
|
||||
|
||||
## PowerShell Integration
|
||||
|
||||
### Default URL Configuration
|
||||
|
||||
PowerShell scripts should use:
|
||||
```powershell
|
||||
$DashboardURL = "http://192.168.122.151:8080/api.asp"
|
||||
```
|
||||
|
||||
### Example PowerShell Call
|
||||
|
||||
```powershell
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = $env:COMPUTERNAME
|
||||
serialNumber = $serialNumber
|
||||
manufacturer = $manufacturer
|
||||
model = $model
|
||||
pcType = "Shopfloor"
|
||||
loggedInUser = $env:USERNAME
|
||||
machineNo = "2001"
|
||||
osVersion = $osVersion
|
||||
networkInterfaces = $networkInterfacesJSON
|
||||
commConfigs = $commConfigsJSON
|
||||
dncConfig = $dncConfigJSON
|
||||
dncDualPathEnabled = $true
|
||||
dncPath1Name = "Path1"
|
||||
dncPath2Name = "Path2"
|
||||
}
|
||||
|
||||
$response = Invoke-RestMethod -Uri $DashboardURL -Method Post -Body $postData
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Testing
|
||||
|
||||
### Test 1: Health Check
|
||||
```bash
|
||||
curl "http://192.168.122.151:8080/api.asp?action=getDashboardData"
|
||||
```
|
||||
|
||||
**Expected:**
|
||||
```json
|
||||
{"success":true,"message":"ShopDB API is online","version":"1.0","schema":"Phase 2"}
|
||||
```
|
||||
|
||||
### Test 2: Create New PC
|
||||
```powershell
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = 'TEST-PC-01'
|
||||
serialNumber = 'ABC123456'
|
||||
manufacturer = 'Dell'
|
||||
model = 'OptiPlex 7090'
|
||||
pcType = 'Standard'
|
||||
osVersion = 'Windows 11 Pro'
|
||||
}
|
||||
|
||||
Invoke-RestMethod -Uri "http://192.168.122.151:8080/api.asp" -Method Post -Body $postData
|
||||
```
|
||||
|
||||
**Verify in Database:**
|
||||
```sql
|
||||
SELECT machineid, hostname, serialnumber, pctypeid, machinetypeid
|
||||
FROM machines
|
||||
WHERE hostname = 'TEST-PC-01' AND pctypeid IS NOT NULL;
|
||||
```
|
||||
|
||||
### Test 3: Update Existing PC with Network Interfaces
|
||||
```powershell
|
||||
$networkInterfaces = @(
|
||||
@{
|
||||
IPAddress = '10.48.130.100'
|
||||
MACAddress = '00:1A:2B:3C:4D:5E'
|
||||
SubnetMask = '255.255.255.0'
|
||||
DefaultGateway = '10.48.130.1'
|
||||
InterfaceName = 'Ethernet'
|
||||
}
|
||||
) | ConvertTo-Json
|
||||
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = 'TEST-PC-01'
|
||||
serialNumber = 'ABC123456'
|
||||
manufacturer = 'Dell'
|
||||
model = 'OptiPlex 7090'
|
||||
pcType = 'Standard'
|
||||
networkInterfaces = $networkInterfaces
|
||||
}
|
||||
|
||||
Invoke-RestMethod -Uri "http://192.168.122.151:8080/api.asp" -Method Post -Body $postData
|
||||
```
|
||||
|
||||
**Verify in Database:**
|
||||
```sql
|
||||
SELECT c.comid, c.address, c.macaddress, c.isprimary
|
||||
FROM communications c
|
||||
JOIN machines m ON c.machineid = m.machineid
|
||||
WHERE m.hostname = 'TEST-PC-01' AND c.comstypeid = 1;
|
||||
```
|
||||
|
||||
### Test 4: Shopfloor PC with Machine Relationship
|
||||
```powershell
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = 'SHOPFLOOR-PC'
|
||||
serialNumber = 'XYZ789'
|
||||
manufacturer = 'HP'
|
||||
model = 'EliteDesk 800'
|
||||
pcType = 'Shopfloor'
|
||||
machineNo = '2001'
|
||||
}
|
||||
|
||||
Invoke-RestMethod -Uri "http://192.168.122.151:8080/api.asp" -Method Post -Body $postData
|
||||
```
|
||||
|
||||
**Verify Relationship:**
|
||||
```sql
|
||||
SELECT
|
||||
equipment.machinenumber AS equipment,
|
||||
pc.hostname AS controlling_pc
|
||||
FROM machinerelationships mr
|
||||
JOIN machines equipment ON mr.machineid = equipment.machineid
|
||||
JOIN machines pc ON mr.related_machineid = pc.machineid
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE equipment.machinenumber = '2001' AND rt.relationshiptype = 'Controls';
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Deployment
|
||||
|
||||
### Step 1: Database Schema Update
|
||||
|
||||
Run the migration script:
|
||||
```bash
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < sql/migration_phase2/08_update_schema_for_api.sql
|
||||
```
|
||||
|
||||
This renames `pcid` → `machineid` in:
|
||||
- `pc_comm_config`
|
||||
- `pc_dnc_config`
|
||||
|
||||
### Step 2: Deploy api.asp
|
||||
|
||||
Copy `api.asp` to ShopDB root directory:
|
||||
```bash
|
||||
cp api.asp /home/camp/projects/windows/shopdb/
|
||||
```
|
||||
|
||||
### Step 3: Create Logs Directory
|
||||
|
||||
Ensure logs directory exists and is writable:
|
||||
```bash
|
||||
mkdir -p /home/camp/projects/windows/shopdb/logs
|
||||
chmod 755 /home/camp/projects/windows/shopdb/logs
|
||||
```
|
||||
|
||||
### Step 4: Update PowerShell Scripts
|
||||
|
||||
Change default dashboard URL in `Update-PC-CompleteAsset.ps1`:
|
||||
```powershell
|
||||
# OLD:
|
||||
[string]$DashboardURL = "http://10.48.130.197/dashboard-v2/api.php"
|
||||
|
||||
# NEW:
|
||||
[string]$DashboardURL = "http://192.168.122.151:8080/api.asp"
|
||||
```
|
||||
|
||||
### Step 5: Test
|
||||
|
||||
Run PowerShell script on one test PC:
|
||||
```powershell
|
||||
.\Update-PC-CompleteAsset.ps1
|
||||
```
|
||||
|
||||
Check logs:
|
||||
```bash
|
||||
tail -f /home/camp/projects/windows/shopdb/logs/api.log
|
||||
```
|
||||
|
||||
Verify in ShopDB:
|
||||
```
|
||||
http://192.168.122.151:8080/displaypcs.asp
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Issue: "Object required" error
|
||||
|
||||
**Cause:** RegExp object not created properly
|
||||
|
||||
**Fix:** Check that VBScript RegExp is enabled:
|
||||
```asp
|
||||
Dim regex
|
||||
Set regex = New RegExp
|
||||
```
|
||||
|
||||
### Issue: "ADO error" when inserting
|
||||
|
||||
**Cause:** Parameter type mismatch
|
||||
|
||||
**Fix:** Verify parameter types match database column types:
|
||||
- VARCHAR: `200` (adVarChar)
|
||||
- INT: `3` (adInteger)
|
||||
- DATE: `135` (adDBDate)
|
||||
- TINYINT: `16` (adTinyInt)
|
||||
|
||||
### Issue: Network interfaces not appearing
|
||||
|
||||
**Cause:** `comstypeid` not set correctly
|
||||
|
||||
**Fix:** Ensure `comstypeid = 1` for network interfaces
|
||||
|
||||
### Issue: PC relationships not created
|
||||
|
||||
**Cause:** Equipment with matching machine number doesn't exist
|
||||
|
||||
**Fix:** Ensure equipment record exists with `pctypeid IS NULL` and matching `machinenumber`
|
||||
|
||||
### Issue: Logs not writing
|
||||
|
||||
**Cause:** Logs directory doesn't exist or isn't writable
|
||||
|
||||
**Fix:**
|
||||
```bash
|
||||
mkdir -p /home/camp/projects/windows/shopdb/logs
|
||||
chmod 755 /home/camp/projects/windows/shopdb/logs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
### Indexes Required
|
||||
|
||||
Ensure these indexes exist for optimal performance:
|
||||
|
||||
```sql
|
||||
-- machines table
|
||||
ALTER TABLE machines ADD INDEX idx_hostname (hostname);
|
||||
ALTER TABLE machines ADD INDEX idx_pctypeid (pctypeid);
|
||||
ALTER TABLE machines ADD INDEX idx_machinenumber (machinenumber);
|
||||
|
||||
-- communications table
|
||||
ALTER TABLE communications ADD INDEX idx_machineid (machineid);
|
||||
ALTER TABLE communications ADD INDEX idx_comstypeid (comstypeid);
|
||||
|
||||
-- pc_comm_config table
|
||||
ALTER TABLE pc_comm_config ADD INDEX idx_machineid (machineid);
|
||||
|
||||
-- pc_dnc_config table
|
||||
ALTER TABLE pc_dnc_config ADD INDEX idx_machineid (machineid);
|
||||
|
||||
-- machinerelationships table
|
||||
ALTER TABLE machinerelationships ADD INDEX idx_machineid (machineid);
|
||||
ALTER TABLE machinerelationships ADD INDEX idx_related_machineid (related_machineid);
|
||||
```
|
||||
|
||||
### Query Optimization
|
||||
|
||||
- Uses parameterized queries for all SELECT/INSERT/UPDATE operations
|
||||
- Deletes old records before inserting new (avoids duplicate detection overhead)
|
||||
- Single transaction per request (faster than individual commits)
|
||||
- Lookup caching could be added for frequently accessed vendor/model/pctype IDs
|
||||
|
||||
---
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Log Rotation
|
||||
|
||||
Recommend setting up log rotation for `/logs/api.log`:
|
||||
|
||||
**Windows Task Scheduler:**
|
||||
```powershell
|
||||
# Rotate logs weekly
|
||||
Get-Content "C:\inetpub\wwwroot\shopdb\logs\api.log" |
|
||||
Set-Content "C:\inetpub\wwwroot\shopdb\logs\api_$(Get-Date -Format 'yyyyMMdd').log"
|
||||
Clear-Content "C:\inetpub\wwwroot\shopdb\logs\api.log"
|
||||
```
|
||||
|
||||
### Monitoring
|
||||
|
||||
Monitor these metrics:
|
||||
- Request count per hour
|
||||
- Error rate (failed requests / total requests)
|
||||
- Average response time
|
||||
- Database connection pool usage
|
||||
- Disk space for logs directory
|
||||
|
||||
---
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
### Planned Features:
|
||||
1. **Batch Processing**: Accept arrays of PCs in single request
|
||||
2. **Delta Updates**: Only update changed fields (reduces write load)
|
||||
3. **Webhook Callbacks**: Notify on successful PC creation
|
||||
4. **API Key Authentication**: Secure API access
|
||||
5. **Rate Limiting**: Prevent abuse
|
||||
6. **Caching Layer**: Cache vendor/model/pctype lookups
|
||||
7. **Async Processing**: Queue large updates for background processing
|
||||
|
||||
### Nice to Have:
|
||||
- GraphQL endpoint for flexible queries
|
||||
- WebSocket support for real-time updates
|
||||
- OpenAPI/Swagger documentation
|
||||
- Postman collection for testing
|
||||
- Health metrics endpoint (uptime, request count, error rate)
|
||||
|
||||
---
|
||||
|
||||
**Version:** 1.0
|
||||
**Last Updated:** 2025-11-13
|
||||
**Maintained By:** ShopDB Development Team
|
||||
**Support:** Review `/logs/api.log` for troubleshooting
|
||||
199
docs/README.md
199
docs/README.md
@@ -1,121 +1,38 @@
|
||||
# ShopDB Documentation
|
||||
|
||||
**Last Updated:** 2025-11-25
|
||||
**Current Status:** Phase 2 Complete, Phase 3 Planned
|
||||
**Last Updated:** 2025-12-11
|
||||
**Current Status:** Database Migration Complete
|
||||
|
||||
---
|
||||
|
||||
## Project Status Overview
|
||||
## Quick Links
|
||||
|
||||
### Migration Progress
|
||||
| Document | Purpose |
|
||||
|----------|---------|
|
||||
| [CLAUDE.md](../CLAUDE.md) | AI assistant context (start here) |
|
||||
| [QUICK_REFERENCE.md](QUICK_REFERENCE.md) | Cheat sheets, common queries |
|
||||
| [ASP_DEVELOPMENT_GUIDE.md](ASP_DEVELOPMENT_GUIDE.md) | Dev setup, VBScript patterns |
|
||||
| [STANDARDS.md](STANDARDS.md) | Coding standards, security |
|
||||
| [API.md](API.md) | REST API documentation |
|
||||
|
||||
| Phase | Status | Description | Completed |
|
||||
|-------|--------|-------------|-----------|
|
||||
| **Phase 1** | COMPLETE | Schema changes - new tables, columns, indexes | Nov 6, 2025 |
|
||||
| **Phase 2** | COMPLETE | PC migration to unified machines table | Nov 10, 2025 |
|
||||
| **Phase 3** | PLANNED | Network devices migration (servers, switches, cameras) | TBD |
|
||||
---
|
||||
|
||||
### Current Architecture
|
||||
## Current Architecture
|
||||
|
||||
```
|
||||
machines table (unified)
|
||||
├── Equipment (machinetypeid 1-24, pctypeid IS NULL)
|
||||
└── PCs (machinetypeid 25-29, pctypeid IS NOT NULL)
|
||||
├── Equipment (machinetypeid 1-15, pctypeid IS NULL)
|
||||
├── PCs (machinetypeid 33-35, pctypeid IS NOT NULL)
|
||||
└── Network Devices (machinetypeid 16-20)
|
||||
|
||||
printers table (separate - by design)
|
||||
|
||||
Network devices (Phase 3 will migrate):
|
||||
- servers, switches, cameras, accesspoints, idfs
|
||||
- Will become machinetypeid 30-36 in machines table
|
||||
```
|
||||
|
||||
### Key Accomplishments (Oct-Nov 2025)
|
||||
|
||||
- Consolidated PCs into unified `machines` table (277 PCs migrated)
|
||||
- Created `communications` table for all network interfaces (705+ records)
|
||||
- Created `machinerelationships` table for PC/equipment relationships
|
||||
- Modernized all PC pages (displaypcs, displaypc, editpc)
|
||||
- Fixed 36+ API bugs for PowerShell data collection
|
||||
- Added compliance and warranty tracking infrastructure
|
||||
- Implemented network map for all device types
|
||||
|
||||
---
|
||||
|
||||
## Documentation Overview
|
||||
|
||||
### For New Team Members
|
||||
|
||||
**Start here in this order:**
|
||||
|
||||
1. **[QUICK_REFERENCE.md](QUICK_REFERENCE.md)** - Quick facts, common tasks, cheat sheets (15 min)
|
||||
|
||||
2. **[ASP_DEVELOPMENT_GUIDE.md](ASP_DEVELOPMENT_GUIDE.md)** - Dev environment setup, VBScript patterns (30 min)
|
||||
|
||||
3. **[STANDARDS.md](STANDARDS.md)** - Coding standards, security requirements (45 min)
|
||||
|
||||
4. **[DEEP_DIVE_REPORT.md](DEEP_DIVE_REPORT.md)** - Complete database/architecture docs (reference)
|
||||
|
||||
5. **[NESTED_ENTITY_CREATION.md](NESTED_ENTITY_CREATION.md)** - Complex forms, inline entity creation (20 min)
|
||||
|
||||
---
|
||||
|
||||
## Migration Documentation
|
||||
|
||||
### Phase 1 & 2 (Complete)
|
||||
|
||||
| Document | Description |
|
||||
|----------|-------------|
|
||||
| [DATABASE_MIGRATION_FINAL_DESIGN.md](DATABASE_MIGRATION_FINAL_DESIGN.md) | Complete Phase 1 specification |
|
||||
| [MIGRATION_QUICK_REFERENCE.md](MIGRATION_QUICK_REFERENCE.md) | Quick lookup for migration |
|
||||
| [PC_MACHINES_CONSOLIDATION_PLAN.md](PC_MACHINES_CONSOLIDATION_PLAN.md) | Phase 2 PC migration plan |
|
||||
| [MACHINE_RELATIONSHIPS_EXAMPLES.md](MACHINE_RELATIONSHIPS_EXAMPLES.md) | Relationship query patterns |
|
||||
|
||||
### Phase 3 (Planned)
|
||||
|
||||
| Document | Description |
|
||||
|----------|-------------|
|
||||
| [PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md](PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md) | Network devices migration plan |
|
||||
|
||||
---
|
||||
|
||||
## Core Documentation
|
||||
|
||||
### Standards & Development
|
||||
|
||||
| Document | Purpose | Status |
|
||||
|----------|---------|--------|
|
||||
| [STANDARDS.md](STANDARDS.md) | Coding standards, security | Current |
|
||||
| [ASP_DEVELOPMENT_GUIDE.md](ASP_DEVELOPMENT_GUIDE.md) | Dev setup, patterns | Current |
|
||||
| [QUICK_REFERENCE.md](QUICK_REFERENCE.md) | Cheat sheets | Current |
|
||||
| [NESTED_ENTITY_CREATION.md](NESTED_ENTITY_CREATION.md) | Complex forms | Current |
|
||||
|
||||
### Architecture & Design
|
||||
|
||||
| Document | Purpose | Status |
|
||||
|----------|---------|--------|
|
||||
| [DEEP_DIVE_REPORT.md](DEEP_DIVE_REPORT.md) | Complete system documentation | Current |
|
||||
| [INFRASTRUCTURE_FINAL_ARCHITECTURE.md](INFRASTRUCTURE_FINAL_ARCHITECTURE.md) | Infrastructure design | Current |
|
||||
| [NETWORK_DEVICES_UNIFIED_DESIGN.md](NETWORK_DEVICES_UNIFIED_DESIGN.md) | Network unification design | Current |
|
||||
|
||||
---
|
||||
|
||||
## SQL Migration Scripts
|
||||
|
||||
All migration scripts are in `/sql/migration_phase*/` folders:
|
||||
|
||||
```
|
||||
sql/
|
||||
├── migration_phase1/ # Schema changes (8 scripts + rollbacks)
|
||||
├── migration_phase2/ # PC data migration (8 scripts)
|
||||
├── migration_phase3/ # Network devices (planned)
|
||||
└── *.sql # Utility scripts
|
||||
printers table (separate)
|
||||
communications table (all network interfaces)
|
||||
machinerelationships table (PC↔equipment links)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Dev Environment
|
||||
## Dev Environment
|
||||
|
||||
```bash
|
||||
# Start dev environment
|
||||
@@ -126,86 +43,36 @@ sql/
|
||||
|
||||
# Access application
|
||||
http://192.168.122.151:8080
|
||||
```
|
||||
|
||||
### Git (Gitea)
|
||||
|
||||
```bash
|
||||
# Gitea web UI
|
||||
http://localhost:3000
|
||||
|
||||
# Clone repo
|
||||
git clone ssh://git@localhost:2222/cproudlock/shopdb.git
|
||||
```
|
||||
|
||||
### Database
|
||||
|
||||
```bash
|
||||
# Connect to MySQL
|
||||
docker exec -it dev-mysql mysql -u root -prootpassword shopdb
|
||||
|
||||
# Quick queries
|
||||
SELECT COUNT(*) FROM machines WHERE pctypeid IS NOT NULL; -- PCs
|
||||
SELECT COUNT(*) FROM machines WHERE pctypeid IS NULL; -- Equipment
|
||||
SELECT COUNT(*) FROM printers WHERE isactive = 1; -- Printers
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Key Database Tables
|
||||
## Database Views
|
||||
|
||||
### Core Tables (Phase 2 Schema)
|
||||
|
||||
| Table | Purpose | Records |
|
||||
|-------|---------|---------|
|
||||
| `machines` | All equipment + PCs | 500+ |
|
||||
| `communications` | Network interfaces | 700+ |
|
||||
| `machinerelationships` | PC/equipment links | 50+ |
|
||||
| `printers` | Printers (separate) | 200+ |
|
||||
| `warranties` | Warranty tracking | var |
|
||||
| `compliance` | Compliance data | var |
|
||||
|
||||
### Key Views
|
||||
All views are defined in `sql/view_consolidation.sql`:
|
||||
|
||||
| View | Purpose |
|
||||
|------|---------|
|
||||
| `vw_network_devices` | All network devices unified |
|
||||
| `vw_active_pcs` | Active PCs with details |
|
||||
| `vw_machine_relationships` | Relationship summary |
|
||||
| `vw_equipment_list` | Equipment with details |
|
||||
| `vw_pc_list` | PCs with OS/model info |
|
||||
| `vw_printer_list` | Active printers |
|
||||
| `vw_network_devices` | Network devices (APs, switches, etc.) |
|
||||
| `vw_machine_detail` | Full machine info for detail pages |
|
||||
| `vw_active_notifications` | Current notifications |
|
||||
| `vw_warranty_status` | Warranty tracking |
|
||||
|
||||
---
|
||||
|
||||
## Recent Session Summaries
|
||||
## Archive
|
||||
|
||||
Located in project root:
|
||||
|
||||
| File | Date | Focus |
|
||||
|------|------|-------|
|
||||
| SESSION_SUMMARY_2025-11-13.md | Nov 13 | Phase 2 testing, network_map fixes |
|
||||
| SESSION_SUMMARY_2025-11-10.md | Nov 10 | Relationship fixes, Phase 3 planning |
|
||||
|
||||
---
|
||||
|
||||
## Getting Help
|
||||
|
||||
1. Check [QUICK_REFERENCE.md](QUICK_REFERENCE.md) first
|
||||
2. Search [DEEP_DIVE_REPORT.md](DEEP_DIVE_REPORT.md)
|
||||
3. Review [STANDARDS.md](STANDARDS.md) for coding questions
|
||||
4. Check session summaries for recent changes
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| v2.0 | 2025-11-25 | Updated for Phase 2 completion, cleanup |
|
||||
| v1.3 | 2025-10-20 | Added Git workflow documentation |
|
||||
| v1.2 | 2025-10-20 | Added DEEP_DIVE_REPORT, QUICK_REFERENCE |
|
||||
| v1.1 | 2025-10-10 | Added STANDARDS, NESTED_ENTITY_CREATION |
|
||||
| v1.0 | 2025-10-09 | Initial ASP_DEVELOPMENT_GUIDE |
|
||||
Historical documentation from completed migrations is in `archive/`:
|
||||
- Phase 1-4 migration plans and summaries
|
||||
- Bug fix records
|
||||
- Session summaries
|
||||
|
||||
---
|
||||
|
||||
**Maintained By:** Development Team
|
||||
**Last Updated:** 2025-11-25
|
||||
|
||||
433
docs/archive/ADD_EDIT_MACHINE_UPDATES.md
Normal file
433
docs/archive/ADD_EDIT_MACHINE_UPDATES.md
Normal file
@@ -0,0 +1,433 @@
|
||||
# Add/Edit Machine Form Updates - Summary
|
||||
|
||||
## Overview
|
||||
Updated machine add/edit forms to support all Phase 2 migration data including network communications, machine relationships, and compliance information.
|
||||
|
||||
---
|
||||
|
||||
## Files Modified
|
||||
|
||||
### 1. addmachine.asp
|
||||
**Location:** `/home/camp/projects/windows/shopdb/addmachine.asp`
|
||||
|
||||
#### New Form Sections Added:
|
||||
|
||||
**A. Network Communications Section**
|
||||
```html
|
||||
<h6>Network Communications (Optional)</h6>
|
||||
```
|
||||
Tab-based layout with support for up to 3 network interfaces:
|
||||
|
||||
**Interface 1 (Primary)**
|
||||
- **IP Address** - Text input with IPv4 validation pattern (field: ip1)
|
||||
- **MAC Address** - Text input with MAC address validation pattern (field: mac1)
|
||||
- Marked as primary interface (isprimary=1)
|
||||
|
||||
**Interface 2 (Optional)**
|
||||
- **IP Address** - Text input with IPv4 validation pattern (field: ip2)
|
||||
- **MAC Address** - Text input with MAC address validation pattern (field: mac2)
|
||||
- Secondary interface (isprimary=0)
|
||||
|
||||
**Interface 3 (Optional)**
|
||||
- **IP Address** - Text input with IPv4 validation pattern (field: ip3)
|
||||
- **MAC Address** - Text input with MAC address validation pattern (field: mac3)
|
||||
- Secondary interface (isprimary=0)
|
||||
|
||||
**B. Machine Relationships Section**
|
||||
```html
|
||||
<h6>Machine Relationships (Optional)</h6>
|
||||
```
|
||||
New Fields:
|
||||
- **Controlling PC** - Dropdown populated with all PCs from machines table (WHERE pctypeid IS NOT NULL)
|
||||
- **Dualpath / Redundant Machine** - Dropdown populated with all equipment (WHERE pctypeid IS NULL)
|
||||
|
||||
**C. Compliance & Security Section**
|
||||
```html
|
||||
<h6>Compliance & Security (Optional)</h6>
|
||||
```
|
||||
New Fields:
|
||||
- **Third Party Managed** - Dropdown (N/A, Yes, No)
|
||||
- **Third Party Vendor** - Dropdown populated from vendors table
|
||||
- **OT Asset System** - Text input for operational technology classification
|
||||
- **DoD Asset Device Type** - Text input for Department of Defense asset classification
|
||||
|
||||
---
|
||||
|
||||
### 2. savemachine_direct.asp
|
||||
**Location:** `/home/camp/projects/windows/shopdb/savemachine_direct.asp`
|
||||
|
||||
#### New Data Handling Added:
|
||||
|
||||
**A. Network Communications Save**
|
||||
- Retrieves form fields: `ip1`, `mac1`, `ip2`, `mac2`, `ip3`, `mac3`
|
||||
- Looks up `Network_Interface` communication type ID
|
||||
- Inserts up to 3 records into `communications` table
|
||||
- Sets `isprimary = 1` for Interface 1 only (Interfaces 2-3 have isprimary=0)
|
||||
- Only inserts if IP or MAC provided for each interface
|
||||
- Interface names: "Interface 1", "Interface 2", "Interface 3"
|
||||
|
||||
**B. Machine Relationships Save**
|
||||
- Retrieves form fields: `controllingpc`, `dualpathid`
|
||||
- Looks up relationship type IDs for 'Controls' and 'Dualpath'
|
||||
|
||||
**Controls Relationship:**
|
||||
- Creates one-way relationship: PC (machineid) → Equipment (related_machineid)
|
||||
- Relationship type: 'Controls'
|
||||
|
||||
**Dualpath Relationship:**
|
||||
- Creates **bidirectional** relationship
|
||||
- Direction 1: New Machine → Dualpath Machine
|
||||
- Direction 2: Dualpath Machine → New Machine
|
||||
- Both records use 'Dualpath' relationship type
|
||||
|
||||
**C. Compliance Data Save**
|
||||
- Retrieves form fields: `thirdpartymanaged`, `thirdpartyvendorid`, `otassetsystem`, `dodassettype`
|
||||
- Inserts record into `compliance` table
|
||||
- Maps third party managed to ENUM: 'Yes', 'No', or 'NA'
|
||||
- Stores third party vendor as foreign key to vendors table (third_party_vendorid)
|
||||
|
||||
---
|
||||
|
||||
### 3. displaymachines.asp
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaymachines.asp`
|
||||
|
||||
#### Query Filter Updated:
|
||||
|
||||
**Before:**
|
||||
```sql
|
||||
machines.isactive = 1 AND islocationonly=0
|
||||
```
|
||||
|
||||
**After:**
|
||||
```sql
|
||||
machines.isactive = 1 AND islocationonly=0 AND machines.pctypeid IS NULL
|
||||
```
|
||||
|
||||
**Purpose:** Exclude PCs from equipment list - PCs should only appear in displaypcs.asp
|
||||
|
||||
---
|
||||
|
||||
### 4. displaymachine.asp
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaymachine.asp`
|
||||
|
||||
#### Fixed Issues:
|
||||
- Changed INNER JOIN to LEFT JOIN for `machinetypes` and `functionalaccounts`
|
||||
- Allows machines with NULL machinetypeid to still display (fixes redirect to homepage)
|
||||
- Updated Settings tab to show IP/MAC from communications table instead of old PC tables
|
||||
- Shows controlling PC from relationships table
|
||||
|
||||
---
|
||||
|
||||
## Database Tables Used
|
||||
|
||||
### New Tables Created in Phase 2:
|
||||
|
||||
#### communications
|
||||
```sql
|
||||
CREATE TABLE communications (
|
||||
comid INT PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT NOT NULL,
|
||||
comstypeid INT NOT NULL,
|
||||
address VARCHAR(50), -- IP address
|
||||
macaddress VARCHAR(50),
|
||||
interfacename VARCHAR(50),
|
||||
isprimary TINYINT(1) DEFAULT 0,
|
||||
isactive TINYINT(1) DEFAULT 1,
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid),
|
||||
FOREIGN KEY (comstypeid) REFERENCES comstypes(comstypeid)
|
||||
)
|
||||
```
|
||||
|
||||
#### machinerelationships
|
||||
```sql
|
||||
CREATE TABLE machinerelationships (
|
||||
relationshipid INT PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT NOT NULL,
|
||||
related_machineid INT NOT NULL,
|
||||
relationshiptypeid INT NOT NULL,
|
||||
isactive TINYINT(1) DEFAULT 1,
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid),
|
||||
FOREIGN KEY (related_machineid) REFERENCES machines(machineid),
|
||||
FOREIGN KEY (relationshiptypeid) REFERENCES relationshiptypes(relationshiptypeid)
|
||||
)
|
||||
```
|
||||
|
||||
#### relationshiptypes
|
||||
```sql
|
||||
CREATE TABLE relationshiptypes (
|
||||
relationshiptypeid INT PRIMARY KEY AUTO_INCREMENT,
|
||||
relationshiptype VARCHAR(50) NOT NULL, -- 'Controls', 'Dualpath'
|
||||
isactive TINYINT(1) DEFAULT 1
|
||||
)
|
||||
```
|
||||
|
||||
#### compliance
|
||||
```sql
|
||||
CREATE TABLE compliance (
|
||||
complianceid INT PRIMARY KEY AUTO_INCREMENT,
|
||||
machineid INT NOT NULL,
|
||||
is_third_party_managed ENUM('Yes', 'No', 'NA'),
|
||||
third_party_manager VARCHAR(100),
|
||||
ot_asset_system VARCHAR(100),
|
||||
ot_asset_device_type VARCHAR(100),
|
||||
is_compliant TINYINT(1),
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid)
|
||||
)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Form Validation
|
||||
|
||||
### Client-Side Validation (HTML5):
|
||||
|
||||
**IP Address:**
|
||||
```html
|
||||
pattern="^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$"
|
||||
```
|
||||
|
||||
**MAC Address:**
|
||||
```html
|
||||
pattern="^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"
|
||||
```
|
||||
|
||||
### Server-Side Validation:
|
||||
|
||||
All inputs are:
|
||||
- Trimmed of whitespace
|
||||
- Checked for empty values before INSERT
|
||||
- Passed through parameterized queries (SQL injection protection)
|
||||
- Used with `IIf()` to convert empty strings to NULL
|
||||
|
||||
---
|
||||
|
||||
## Workflow Examples
|
||||
|
||||
### Adding a New CNC Machine with Full Data:
|
||||
|
||||
1. **Basic Info** (existing fields):
|
||||
- Machine Number: 4500
|
||||
- Model: Okuma LB 3000
|
||||
- Business Unit: Production
|
||||
- Alias: "Main Turning Center"
|
||||
|
||||
2. **Network** (new fields):
|
||||
- Interface 1 IP: 192.168.10.50
|
||||
- Interface 1 MAC: 00:1A:2B:3C:4D:5E
|
||||
- Interface 2 IP: 192.168.10.51
|
||||
- Interface 2 MAC: 00:1A:2B:3C:4D:5F
|
||||
- Interface 3: (left blank)
|
||||
|
||||
3. **Relationships** (new fields):
|
||||
- Controlling PC: PC-SHOP-045
|
||||
- Dualpath Machine: Machine 4501 (backup)
|
||||
|
||||
4. **Compliance** (new fields):
|
||||
- Third Party Managed: No
|
||||
- OT Asset System: Production Control
|
||||
- DoD Asset Type: CNC Lathe
|
||||
|
||||
**Result:**
|
||||
- Machine inserted into `machines` table
|
||||
- Two communication records inserted into `communications` table:
|
||||
- Interface 1: 192.168.10.50 (isprimary=1)
|
||||
- Interface 2: 192.168.10.51 (isprimary=0)
|
||||
- Controls relationship: PC-SHOP-045 → Machine 4500
|
||||
- Dualpath relationships: 4500 ↔ 4501 (bidirectional)
|
||||
- Compliance record inserted into `compliance` table
|
||||
- Redirects to displaymachine.asp?machineid=[newid]
|
||||
|
||||
---
|
||||
|
||||
## Security Features
|
||||
|
||||
### Parameterized Queries:
|
||||
All database operations use `ADODB.Command` with parameters:
|
||||
```asp
|
||||
Set cmd = Server.CreateObject("ADODB.Command")
|
||||
cmd.ActiveConnection = objConn
|
||||
cmd.CommandText = "INSERT INTO communications (...) VALUES (?, ?, ?, ?, ?)"
|
||||
cmd.Parameters.Append cmd.CreateParameter("@machineid", 3, 1, , machineid)
|
||||
...
|
||||
cmd.Execute
|
||||
```
|
||||
|
||||
### HTML Encoding:
|
||||
All user input displayed in dropdowns uses `Server.HTMLEncode()`:
|
||||
```asp
|
||||
Response.Write("<option value='" & id & "'>" & Server.HTMLEncode(displayText) & "</option>")
|
||||
```
|
||||
|
||||
### Input Validation:
|
||||
- Required fields checked server-side
|
||||
- Numeric fields validated with `IsNumeric()`
|
||||
- String length limits enforced
|
||||
- NULL handling with `IIf()`
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Graceful Failures:
|
||||
```asp
|
||||
On Error Resume Next
|
||||
cmd.Execute
|
||||
Set cmd = Nothing
|
||||
On Error Goto 0
|
||||
```
|
||||
|
||||
All Phase 2 data inserts use error suppression to allow partial success:
|
||||
- Machine can be created even if communication insert fails
|
||||
- Relationship creation failures don't block machine creation
|
||||
- Compliance data is optional
|
||||
|
||||
### User Feedback:
|
||||
- Success: Redirects to displaymachine.asp with new machine
|
||||
- Failure: Shows error message with "Go back" link
|
||||
- Duplicate machine number: Prevented with validation check
|
||||
|
||||
---
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
- [ ] Add machine with all new fields populated
|
||||
- [ ] Add machine with only required fields (Phase 2 fields empty)
|
||||
- [ ] Verify IP address validation (invalid format rejected)
|
||||
- [ ] Verify MAC address validation (invalid format rejected)
|
||||
- [ ] Verify controlling PC creates correct relationship
|
||||
- [ ] Verify dualpath creates bidirectional relationships
|
||||
- [ ] Verify compliance data saves correctly
|
||||
- [ ] Test with special characters in text fields
|
||||
- [ ] Verify displaymachines.asp no longer shows PCs
|
||||
- [ ] Verify machines with NULL machinetypeid still display
|
||||
- [ ] Test redirect after successful machine creation
|
||||
- [ ] Verify Settings tab shows data from communications table
|
||||
|
||||
---
|
||||
|
||||
## Known Limitations
|
||||
|
||||
1. **No Relationship Editing**
|
||||
- Cannot modify relationships after creation
|
||||
- Must edit relationships via database or future edit form
|
||||
- Future enhancement: Edit relationships on machine edit page
|
||||
|
||||
2. **No Communication Editing**
|
||||
- Cannot modify IP/MAC after creation
|
||||
- Must edit via database or future edit form
|
||||
- Future enhancement: Edit communications on machine edit page
|
||||
|
||||
3. **PC Filter Assumption**
|
||||
- Assumes all PCs have `pctypeid IS NOT NULL`
|
||||
- Legacy PCs may not have pctypeid set
|
||||
- Migration should ensure all PCs have pctypeid
|
||||
|
||||
---
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
### For editmacine.asp (Edit Page):
|
||||
|
||||
1. **Network Communications Management**
|
||||
- List all existing interfaces
|
||||
- Add new interfaces
|
||||
- Edit existing interfaces
|
||||
- Delete interfaces
|
||||
- Set primary interface
|
||||
|
||||
2. **Relationship Management**
|
||||
- View all relationships
|
||||
- Add new relationships
|
||||
- Remove relationships
|
||||
- Edit relationship types
|
||||
|
||||
3. **Compliance Management**
|
||||
- Edit all compliance fields
|
||||
- Add security scan records
|
||||
- View scan history
|
||||
- Update compliance status
|
||||
|
||||
4. **Bulk Operations**
|
||||
- Assign same PC to multiple machines
|
||||
- Create multiple dualpath links at once
|
||||
- Bulk update compliance data
|
||||
|
||||
---
|
||||
|
||||
## Migration Notes
|
||||
|
||||
### Data Already Imported:
|
||||
- 308 equipment with network communications
|
||||
- 144 PC control relationships
|
||||
- 62 dualpath relationships
|
||||
- 164 machines with compliance data
|
||||
- 68 security scans
|
||||
|
||||
### What This Form Adds:
|
||||
- Ability to create NEW machines with Phase 2 data
|
||||
- Ensures all new machines have proper network configuration
|
||||
- Establishes relationships at creation time
|
||||
- Records compliance data from day one
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Machine redirects to homepage:
|
||||
- Check if model has NULL machinetypeid
|
||||
- Run: `UPDATE models SET machinetypeid = X WHERE modelnumberid = Y`
|
||||
- Or use LEFT JOIN fix in displaymachine.asp
|
||||
|
||||
### IP address not showing:
|
||||
- Check if communication record was created
|
||||
- Verify `isprimary = 1` is set
|
||||
- Check Settings tab query for communications join
|
||||
|
||||
### Relationship not created:
|
||||
- Verify relationship types exist in database
|
||||
- Check for duplicate relationships (prevents re-insert)
|
||||
- Verify both machines have valid machineids
|
||||
|
||||
### PC still showing in equipment list:
|
||||
- Verify PC has `pctypeid IS NOT NULL`
|
||||
- Check displaymachines.asp WHERE clause includes PC filter
|
||||
- Clear browser cache
|
||||
|
||||
---
|
||||
|
||||
## Contact / Support
|
||||
|
||||
For questions about these changes:
|
||||
- See `/home/camp/projects/windows/shopdb/sql/migration_phase2/` for migration scripts
|
||||
- See `/home/camp/projects/windows/shopdb/DISPLAY_PAGES_UPDATE_SUMMARY.md` for display page changes
|
||||
- Review import logs in `/tmp/inventory_import_final.log`
|
||||
|
||||
---
|
||||
|
||||
## Change Log
|
||||
|
||||
**Date:** 2025-11-07
|
||||
|
||||
**Files Modified:**
|
||||
- /home/camp/projects/windows/shopdb/addmachine.asp
|
||||
- /home/camp/projects/windows/shopdb/savemachine_direct.asp
|
||||
- /home/camp/projects/windows/shopdb/displaymachines.asp
|
||||
- /home/camp/projects/windows/shopdb/displaymachine.asp
|
||||
|
||||
**Changes:**
|
||||
- Redesigned addmachine.asp with Bootstrap tabs (Basic Info, Network, Relationships, Compliance, Location)
|
||||
- Added support for up to 3 network interfaces on add machine form
|
||||
- Added machine relationship fields (controlling PC, dualpath)
|
||||
- Added compliance data fields with third-party vendor dropdown
|
||||
- Updated save handler to insert Phase 2 data (multiple interfaces, relationships, compliance)
|
||||
- Fixed displaymachines.asp to exclude PCs (pctypeid IS NULL filter)
|
||||
- Fixed displaymachine.asp LEFT JOIN for NULL machinetypes
|
||||
- Updated Settings tab to show communications data
|
||||
- Fixed NULL handling in controlling PC dropdown (Server.HTMLEncode type mismatch)
|
||||
- Changed third_party_manager from text field to third_party_vendorid foreign key
|
||||
|
||||
**Database Impact:**
|
||||
- New records created in: communications (up to 3 per machine), machinerelationships, compliance
|
||||
- Added third_party_vendorid column to compliance table
|
||||
- All changes backward compatible
|
||||
|
||||
455
docs/archive/BUG_FIXES_2025-11-14.md
Normal file
455
docs/archive/BUG_FIXES_2025-11-14.md
Normal file
@@ -0,0 +1,455 @@
|
||||
# Critical Bug Fixes - November 14, 2025
|
||||
|
||||
## Summary
|
||||
|
||||
Fixed multiple critical bugs in `api.asp` that prevented PowerShell data collection scripts from properly updating PC records and creating machine relationships. All issues stemmed from using VB6/VBA functions not available in Classic ASP VBScript.
|
||||
|
||||
---
|
||||
|
||||
## Bugs Fixed
|
||||
|
||||
### 1. **PC UPDATE Bug (InsertOrUpdatePC)**
|
||||
**Lines:** 451-495
|
||||
**Symptom:** PC records could be inserted but not updated
|
||||
**Error:** `"Variable is undefined"`
|
||||
**Root Cause:** Used `IIf()` function in UPDATE SQL statement
|
||||
**Impact:** HIGH - Prevented regular PC inventory updates
|
||||
|
||||
**Fix:** Replaced all `IIf()` calls with proper IF-THEN-ELSE statements:
|
||||
```vbscript
|
||||
' BEFORE (BROKEN):
|
||||
"modelnumberid = " & IIf(modelId > 0, CLng(modelId), "NULL") & ", " & _
|
||||
|
||||
' AFTER (FIXED):
|
||||
Dim sqlModelId
|
||||
If modelId > 0 Then
|
||||
sqlModelId = CLng(modelId)
|
||||
Else
|
||||
sqlModelId = "NULL"
|
||||
End If
|
||||
"modelnumberid = " & sqlModelId & ", " & _
|
||||
```
|
||||
|
||||
**Test Result:** Both INSERT and UPDATE now working correctly
|
||||
|
||||
---
|
||||
|
||||
### 2. **PC→Machine Relationship Bug (CreatePCMachineRelationship)**
|
||||
**Lines:** 849-984
|
||||
**Symptom:** PowerShell scripts couldn't create PC→Machine relationships
|
||||
**Errors:** Multiple issues found and fixed
|
||||
|
||||
#### Issue A: Parameter Order Reversed
|
||||
**Lines:** 916-918
|
||||
**Problem:** Relationship created backwards (Equipment→PC instead of PC→Equipment)
|
||||
```vbscript
|
||||
' BEFORE (WRONG):
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@equipmentid", 3, 1, , CLng(equipmentMachineid))
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
|
||||
' Created: Equipment (machineid) → Controls → PC (related_machineid)
|
||||
|
||||
' AFTER (CORRECT):
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@equipmentid", 3, 1, , CLng(equipmentMachineid))
|
||||
' Creates: PC (machineid) → Controls → Equipment (related_machineid)
|
||||
```
|
||||
|
||||
#### Issue B: Phase 1 Schema Query
|
||||
**Line:** 859
|
||||
**Problem:** Query used Phase 1 schema field `pctypeid IS NULL`
|
||||
```vbscript
|
||||
' BEFORE (Phase 1):
|
||||
"SELECT machineid FROM machines WHERE machinenumber = ? AND pctypeid IS NULL"
|
||||
|
||||
' AFTER (Phase 2):
|
||||
"SELECT machineid FROM machines WHERE machinenumber = '...' AND machinetypeid NOT IN (33,34,35)"
|
||||
```
|
||||
|
||||
#### Issue C: ExecuteParameterizedQuery Not Returning Data
|
||||
**Problem:** Parameterized query helper function wasn't returning `machineid` value
|
||||
**Fix:** Switched to direct SQL execution with proper string sanitization
|
||||
|
||||
**Test Result:** PC→Machine relationships now created correctly
|
||||
```
|
||||
PC 5459 (FINAL-TEST-PC) → Controls → Equipment 136 (machine 2021)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. **Network Interface Storage Bug (InsertNetworkInterfaces)**
|
||||
**Lines:** 695-698
|
||||
**Symptom:** Would fail when storing network interface data
|
||||
**Error:** `"Variable is undefined"`
|
||||
**Root Cause:** 4 `IIf()` calls for parameter values
|
||||
**Impact:** MEDIUM - Network/IP data collection would fail
|
||||
|
||||
**Fix:** Replaced IIf() with IF-THEN-ELSE:
|
||||
```vbscript
|
||||
' Prepare parameter values (VBScript doesn't have IIf)
|
||||
Dim paramAddress, paramMacAddress, paramSubnet, paramGateway
|
||||
If ipAddress <> "" Then paramAddress = ipAddress Else paramAddress = Null
|
||||
If macAddress <> "" Then paramMacAddress = macAddress Else paramMacAddress = Null
|
||||
If subnetMask <> "" Then paramSubnet = subnetMask Else paramSubnet = Null
|
||||
If gateway <> "" Then paramGateway = gateway Else paramGateway = Null
|
||||
```
|
||||
|
||||
**Status:** Already working (705 network interfaces stored), but now bug-proof
|
||||
|
||||
---
|
||||
|
||||
### 4. **Serial Port Config Bug (InsertCommConfigs)**
|
||||
**Lines:** 751-755
|
||||
**Symptom:** Would fail when storing serial port configurations
|
||||
**Error:** `"Variable is undefined"`
|
||||
**Root Cause:** 5 `IIf()` calls for parameter values
|
||||
**Impact:** LOW - Only affects shopfloor PCs with serial communication
|
||||
|
||||
**Fix:** Replaced 5 IIf() calls with proper IF-THEN-ELSE statements
|
||||
|
||||
---
|
||||
|
||||
### 5. **DNC Config Bug (InsertDNCConfig)**
|
||||
**Lines:** 830-848
|
||||
**Symptom:** Would fail when storing DNC configuration data
|
||||
**Error:** `"Variable is undefined"`
|
||||
**Root Cause:** **19 `IIf()` calls** - the largest concentration of bugs!
|
||||
**Impact:** HIGH - DNC config critical for shopfloor PCs
|
||||
|
||||
**Fix:** Replaced all 19 IIf() calls with proper variable preparation:
|
||||
```vbscript
|
||||
' Prepare parameter values (VBScript doesn't have IIf)
|
||||
Dim pSite, pCnc, pNcif, pMachineNum, pHostType, pFtpPri, pFtpSec, pFtpAcct
|
||||
Dim pDebug, pUploads, pScanner, pDripFeed, pAddSet, pDualPath, pPath1, pPath2, pGe32, pGe64, pGeNotes
|
||||
|
||||
If site <> "" Then pSite = site Else pSite = Null
|
||||
If cnc <> "" Then pCnc = cnc Else pCnc = Null
|
||||
[... 17 more similar statements ...]
|
||||
```
|
||||
|
||||
**Data Stored:**
|
||||
- DNC General config (Site, CNC, NCIF, MachineNo, HostType)
|
||||
- FTP settings (Primary, Secondary, Account)
|
||||
- DNC settings (Debug, Uploads, Scanner, DripFeed)
|
||||
- DualPath config (enabled, Path1Name, Path2Name)
|
||||
- GE Registry architecture (32-bit, 64-bit flags)
|
||||
|
||||
---
|
||||
|
||||
### 6. **Warranty Data Bug (UpdateWarrantyData)**
|
||||
**Lines:** 1012-1014, 1032-1034
|
||||
**Symptom:** Would fail when storing warranty information
|
||||
**Error:** `"Variable is undefined"`
|
||||
**Root Cause:** 6 `IIf()` calls (3 in UPDATE, 3 in INSERT)
|
||||
**Impact:** LOW - Warranty lookups disabled by default
|
||||
|
||||
**Fix:** Replaced IIf() calls in both UPDATE and INSERT paths
|
||||
|
||||
---
|
||||
|
||||
### 7. **Application Version Bug (GetOrCreateApplication)**
|
||||
**Line:** 1301
|
||||
**Symptom:** Would fail when storing application with version
|
||||
**Error:** `"Variable is undefined"`
|
||||
**Root Cause:** 1 `IIf()` call for version parameter
|
||||
**Impact:** LOW - Application tracking still works if version empty
|
||||
|
||||
**Fix:** Simple IF-THEN-ELSE replacement
|
||||
|
||||
---
|
||||
|
||||
## Total Bugs Fixed
|
||||
|
||||
| Function | IIf() Bugs | Status |
|
||||
|----------|-----------|--------|
|
||||
| InsertOrUpdatePC | 5 | Fixed |
|
||||
| InsertNetworkInterfaces | 4 | Fixed |
|
||||
| InsertCommConfigs | 5 | Fixed |
|
||||
| InsertDNCConfig | 19 | Fixed |
|
||||
| UpdateWarrantyData (UPDATE) | 3 | Fixed |
|
||||
| UpdateWarrantyData (INSERT) | 3 | Fixed |
|
||||
| GetOrCreateApplication | 1 | Fixed |
|
||||
| CreatePCMachineRelationship (logic) | N/A | Fixed |
|
||||
| **TOTAL** | **33 + 3 logic bugs** | ** ALL FIXED** |
|
||||
|
||||
---
|
||||
|
||||
## Data Collection Status
|
||||
|
||||
### **Working Correctly**
|
||||
|
||||
1. **PC Records**
|
||||
- INSERT new PCs: Working
|
||||
- UPDATE existing PCs: Working (FIXED)
|
||||
- Phase 2 schema (machinetypeid 33/34/35): Working
|
||||
|
||||
2. **PC→Machine Relationships**
|
||||
- Automatic creation from PowerShell: Working (FIXED)
|
||||
- Correct relationship direction: Working (FIXED)
|
||||
- Phase 2 schema compatibility: Working (FIXED)
|
||||
- Database: 705+ relationships active
|
||||
|
||||
3. **Network/IP Information**
|
||||
- Stored in `communications` table: Working
|
||||
- 705 network interfaces collected
|
||||
- Data: IP, MAC, subnet, gateway, DHCP status, interface name
|
||||
- Uses comstypeid=3 (Network_Interface): Correct
|
||||
|
||||
4. **Installed Applications**
|
||||
- Stored in `installedapps` table: Working
|
||||
- 331 application entries
|
||||
- Linked via machineid and appid: Correct
|
||||
|
||||
5. **DNC Configuration**
|
||||
- Stored in `pc_dnc_config` table: Working (FIXED)
|
||||
- DualPath detection: Working (FIXED)
|
||||
- GE Registry architecture tracking: Working (FIXED)
|
||||
- Path names (LEFT/RIGHT): Working (FIXED)
|
||||
|
||||
6. **Serial Port Configs**
|
||||
- Stored in `pc_comm_config` table: Working (FIXED)
|
||||
- Baud rate, data bits, parity, stop bits: Working
|
||||
|
||||
7. **Warranty Data**
|
||||
- Stored in `warranties` table: Working (FIXED)
|
||||
- End date, service level, status, days remaining: Working
|
||||
|
||||
---
|
||||
|
||||
## Testing Results
|
||||
|
||||
### Test 1: Basic PC INSERT
|
||||
```bash
|
||||
curl -X POST "http://192.168.122.151:8080/api.asp" \
|
||||
-d "action=updateCompleteAsset" \
|
||||
-d "hostname=FINAL-TEST-PC" \
|
||||
-d "serialNumber=FINAL-TEST-001" \
|
||||
-d "manufacturer=Dell" \
|
||||
-d "model=OptiPlex 7060" \
|
||||
-d "pcType=Shopfloor" \
|
||||
-d "machineNo=2021"
|
||||
```
|
||||
|
||||
**Result:** SUCCESS
|
||||
- PC created: machineid=5459
|
||||
- Relationship created: PC 5459 → Controls → Equipment 136
|
||||
|
||||
### Test 2: PC UPDATE
|
||||
```bash
|
||||
# Same hostname, different serial
|
||||
curl -X POST "..." -d "hostname=FINAL-TEST-PC" -d "serialNumber=UPDATED-SERIAL"
|
||||
```
|
||||
|
||||
**Result:** SUCCESS (Previously would FAIL with "Variable is undefined")
|
||||
|
||||
### Test 3: API Health Check
|
||||
```bash
|
||||
curl "http://192.168.122.151:8080/api.asp?action=getDashboardData"
|
||||
```
|
||||
|
||||
**Result:** SUCCESS
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "ShopDB API is online",
|
||||
"version": 1.0,
|
||||
"schema": "Phase 2"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## PowerShell Scripts Status
|
||||
|
||||
### **Ready to Use**
|
||||
|
||||
**Update-PC-CompleteAsset.ps1**
|
||||
- Default API URL: `http://192.168.122.151:8080/api.asp`
|
||||
- Data collection: Hardware, OS, Network, DNC, Serial, Applications
|
||||
- API communication: All endpoints working
|
||||
- Phase 2 schema: Compatible
|
||||
|
||||
**Invoke-RemoteAssetCollection.ps1**
|
||||
- Remote execution via WinRM: Ready
|
||||
- Default URL: Still points to old PHP API
|
||||
- **Recommendation:** Update default or use `-DashboardURL` parameter
|
||||
|
||||
---
|
||||
|
||||
## What Changed
|
||||
|
||||
### Files Modified
|
||||
- `/home/camp/projects/windows/shopdb/api.asp` - 36 bugs fixed
|
||||
|
||||
### Lines Changed
|
||||
- **InsertOrUpdatePC:** Lines 451-495
|
||||
- **CreatePCMachineRelationship:** Lines 849-984
|
||||
- **InsertNetworkInterfaces:** Lines 693-708
|
||||
- **InsertCommConfigs:** Lines 749-763
|
||||
- **InsertDNCConfig:** Lines 829-872
|
||||
- **UpdateWarrantyData:** Lines 1011-1021, 1036-1046
|
||||
- **GetOrCreateApplication:** Lines 1296-1306
|
||||
|
||||
---
|
||||
|
||||
## Why This Happened
|
||||
|
||||
### VBScript vs VB6/VBA
|
||||
|
||||
Classic ASP uses **VBScript**, which is a **subset** of Visual Basic. VBScript does NOT include:
|
||||
- `IIf()` - Inline If function
|
||||
- Many other VB6/VBA convenience functions
|
||||
|
||||
**Common Mistake:**
|
||||
```vbscript
|
||||
' This works in VB6/VBA but NOT in VBScript:
|
||||
value = IIf(condition, trueValue, falseValue)
|
||||
|
||||
' VBScript sees "IIf" as a variable name, throws "Variable is undefined"
|
||||
```
|
||||
|
||||
**Correct VBScript:**
|
||||
```vbscript
|
||||
If condition Then
|
||||
value = trueValue
|
||||
Else
|
||||
value = falseValue
|
||||
End If
|
||||
```
|
||||
|
||||
### Why It Wasn't Caught Earlier
|
||||
- INSERT operations worked fine (used direct SQL with sanitization)
|
||||
- UPDATE operations were less frequently used during testing
|
||||
- Some functions (DNC, Serial, Warranty) rarely triggered in development
|
||||
- Errors were silent due to `On Error Resume Next`
|
||||
|
||||
---
|
||||
|
||||
## Best Practices Going Forward
|
||||
|
||||
### 1. **Never Use IIf() in Classic ASP**
|
||||
Always use explicit IF-THEN-ELSE statements
|
||||
|
||||
### 2. **Test Both Code Paths**
|
||||
- Test INSERT **and** UPDATE operations
|
||||
- Test all optional data paths (DNC, Network, Serial, Warranty)
|
||||
|
||||
### 3. **Avoid `On Error Resume Next` Without Logging**
|
||||
Current code has good logging - maintain it!
|
||||
|
||||
### 4. **Phase 2 Schema Reminders**
|
||||
```sql
|
||||
-- PCs identified by machinetypeid (NOT pctypeid)
|
||||
WHERE machinetypeid IN (33, 34, 35) -- PCs
|
||||
WHERE machinetypeid NOT IN (33, 34, 35) -- Equipment
|
||||
|
||||
-- Relationships in machinerelationships table
|
||||
PC (machineid) → Controls → Equipment (related_machineid)
|
||||
```
|
||||
|
||||
### 5. **Parameter Validation**
|
||||
Direct SQL is faster than parameterized queries in this case, but:
|
||||
- **Always sanitize:** `Replace(value, "'", "''")`
|
||||
- **Always log SQL:** Helps debugging
|
||||
- **Always check types:** Use `CLng()` for integers
|
||||
|
||||
---
|
||||
|
||||
## Migration Notes
|
||||
|
||||
### From Phase 1 to Phase 2
|
||||
|
||||
**Schema Changes:**
|
||||
- `pc` table → `machines` table (machinetypeid 33-35)
|
||||
- `pctypeid` field → removed
|
||||
- `machinetypeid` field → used for ALL machines
|
||||
- Relationships → `machinerelationships` table
|
||||
|
||||
**Machine Type IDs:**
|
||||
- 1-32: Equipment (CNC, Printer, Network Device, etc.)
|
||||
- 33: Standard PC
|
||||
- 34: Engineering PC
|
||||
- 35: Shopfloor PC
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
### 1. **Update PowerShell Default URL** (Optional)
|
||||
```powershell
|
||||
# Invoke-RemoteAssetCollection.ps1 line 97
|
||||
[string]$DashboardURL = "http://192.168.122.151:8080/api.asp"
|
||||
```
|
||||
|
||||
### 2. **Deploy to Production**
|
||||
- All critical bugs fixed
|
||||
- All data collection working
|
||||
- Phase 2 schema fully supported
|
||||
- Ready for shopfloor deployment
|
||||
|
||||
### 3. **Monitor Logs**
|
||||
Watch `/home/camp/projects/windows/shopdb/logs/api.log` for:
|
||||
- Successful PC updates
|
||||
- Relationship creation
|
||||
- Any unexpected errors
|
||||
|
||||
### 4. **Test on Real Shopfloor PCs**
|
||||
- DNC configuration detection
|
||||
- Network interface collection (192.168.*.* detection)
|
||||
- Serial port configuration
|
||||
- Machine number extraction
|
||||
|
||||
---
|
||||
|
||||
## Documentation Created
|
||||
|
||||
1. **POWERSHELL_API_FIX_2025-11-14.md** - IIf() bug fix and testing
|
||||
2. **DUALPATH_DETECTION_GUIDE.md** - How DualPath detection works
|
||||
3. **BUG_FIXES_2025-11-14.md** - This comprehensive summary (YOU ARE HERE)
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
### API Endpoints
|
||||
|
||||
**Main Endpoint:**
|
||||
```
|
||||
POST http://192.168.122.151:8080/api.asp
|
||||
```
|
||||
|
||||
**Actions:**
|
||||
- `updateCompleteAsset` - PC data collection ( FIXED)
|
||||
- `updatePrinterMapping` - Printer assignments ( Working)
|
||||
- `updateInstalledApps` - Application tracking ( Working)
|
||||
- `getDashboardData` - Health check ( Working)
|
||||
|
||||
### Test Script
|
||||
|
||||
Created comprehensive test script:
|
||||
```powershell
|
||||
/home/camp/projects/powershell/Test-API-Connection.ps1
|
||||
```
|
||||
|
||||
Runs all test scenarios:
|
||||
- API connectivity
|
||||
- INSERT operations
|
||||
- UPDATE operations
|
||||
- Network interface data
|
||||
- Shopfloor PC with machine number
|
||||
|
||||
---
|
||||
|
||||
**Status:** ALL BUGS FIXED AND TESTED
|
||||
**Date:** 2025-11-14
|
||||
**Tested By:** Claude Code (AI Assistant)
|
||||
**Production Ready:** YES
|
||||
|
||||
---
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
1. **VBScript ≠ VB6** - Always check function compatibility
|
||||
2. **Test EVERYTHING** - Don't assume one code path = all paths
|
||||
3. **Logging Saves Time** - The detailed logging made debugging 10x faster
|
||||
4. **Small Helpers Break Things** - ExecuteParameterizedQuery had subtle bugs
|
||||
5. **Direct SQL Often Better** - Simpler, faster, easier to debug (when properly sanitized)
|
||||
76
docs/archive/CLAUDE_PROJECT_INSTRUCTIONS.md
Normal file
76
docs/archive/CLAUDE_PROJECT_INSTRUCTIONS.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Claude.ai Project Instructions for ShopDB
|
||||
|
||||
Copy this into your Claude.ai project's "Instructions" field.
|
||||
|
||||
---
|
||||
|
||||
## Project Instructions (Copy Below This Line)
|
||||
|
||||
You are helping maintain ShopDB, a Classic ASP/VBScript web application for GE Aerospace shop floor infrastructure management.
|
||||
|
||||
### Technology Context
|
||||
- **Language:** Classic ASP with VBScript (NOT .NET)
|
||||
- **Database:** MySQL 5.6 (NOT SQL Server)
|
||||
- **Frontend:** Bootstrap 4.6, jQuery, DataTables
|
||||
|
||||
### Critical VBScript Rules
|
||||
1. **No IIf() function** - VBScript doesn't have it. Use If-Then-Else:
|
||||
```vbscript
|
||||
' WRONG: value = IIf(condition, "yes", "no")
|
||||
' RIGHT:
|
||||
If condition Then
|
||||
value = "yes"
|
||||
Else
|
||||
value = "no"
|
||||
End If
|
||||
```
|
||||
|
||||
2. **Always use parameterized queries** - Never concatenate user input:
|
||||
```vbscript
|
||||
cmd.CommandText = "SELECT * FROM machines WHERE machineid = ?"
|
||||
cmd.Parameters.Append cmd.CreateParameter("@id", 3, 1, , machineId)
|
||||
```
|
||||
|
||||
3. **Convert text fields to strings** with `& ""` to avoid Null errors:
|
||||
```vbscript
|
||||
hostname = rs("hostname") & ""
|
||||
```
|
||||
|
||||
4. **HTMLEncode all output** to prevent XSS:
|
||||
```vbscript
|
||||
Response.Write(Server.HTMLEncode(value))
|
||||
```
|
||||
|
||||
### Database Schema (Current)
|
||||
- `machines` table contains Equipment, PCs, and Network Devices
|
||||
- PCs identified by: `pctypeid IS NOT NULL` or `machinetypeid IN (33,34,35)`
|
||||
- Equipment identified by: `pctypeid IS NULL`
|
||||
- Network interfaces in `communications` table (use `address` not `ipaddress`)
|
||||
- Relationships in `machinerelationships` table
|
||||
- Printers stay in separate `printers` table
|
||||
|
||||
### File Naming Conventions
|
||||
- `display*.asp` - View/list pages (read-only)
|
||||
- `add*.asp` - Forms for adding new records
|
||||
- `edit*.asp` - Forms for editing existing records
|
||||
- `save*.asp` - Backend handlers for form submissions
|
||||
- `update*.asp` - Backend handlers for updates
|
||||
|
||||
### Common Patterns
|
||||
When asked to modify ASP code:
|
||||
1. Check for existing similar code patterns in the file
|
||||
2. Follow the existing error handling style
|
||||
3. Use the same SQL helper functions (ExecuteQuery, etc.)
|
||||
4. Maintain consistent indentation (tabs or spaces matching file)
|
||||
|
||||
### When Debugging
|
||||
- Check for Null handling issues first
|
||||
- Look for missing `& ""` on string fields
|
||||
- Verify column names match current schema
|
||||
- Check if using old `pc` table references (should use `machines`)
|
||||
|
||||
### Response Style
|
||||
- Be concise - this is a legacy codebase, not a greenfield project
|
||||
- Match existing code style when making changes
|
||||
- Don't add unnecessary comments or refactoring
|
||||
- Focus on the specific task requested
|
||||
198
docs/archive/CLAUDE_REFERENCE.md
Normal file
198
docs/archive/CLAUDE_REFERENCE.md
Normal file
@@ -0,0 +1,198 @@
|
||||
# ShopDB Quick Reference for Claude.ai
|
||||
|
||||
## Database Tables
|
||||
|
||||
### machines (unified - all devices)
|
||||
| Column | Type | Notes |
|
||||
|--------|------|-------|
|
||||
| machineid | INT | Primary key |
|
||||
| machinetypeid | INT | FK to machinetypes |
|
||||
| machinenumber | VARCHAR | Equipment number or hostname |
|
||||
| hostname | VARCHAR | PC hostname |
|
||||
| serialnumber | VARCHAR | Serial number |
|
||||
| alias | VARCHAR | Friendly name |
|
||||
| pctypeid | INT | NOT NULL = PC, NULL = equipment |
|
||||
| osid | INT | FK to operatingsystems (PCs) |
|
||||
| modelnumberid | INT | FK to models |
|
||||
| businessunitid | INT | FK to businessunits |
|
||||
| machinestatusid | INT | FK to machinestatus |
|
||||
| isactive | TINYINT | 1=active, 0=inactive |
|
||||
| lastupdated | DATETIME | Auto-updated |
|
||||
|
||||
### communications (network interfaces)
|
||||
| Column | Type | Notes |
|
||||
|--------|------|-------|
|
||||
| communicationid | INT | Primary key |
|
||||
| machineid | INT | FK to machines |
|
||||
| comstypeid | INT | FK to comstypes (1=IP, 2=Serial) |
|
||||
| address | VARCHAR | IP address or COM port |
|
||||
| macaddress | VARCHAR | MAC address |
|
||||
| port | INT | Port number |
|
||||
| isprimary | TINYINT | Primary interface flag |
|
||||
|
||||
### machinerelationships
|
||||
| Column | Type | Notes |
|
||||
|--------|------|-------|
|
||||
| relationshipid | INT | Primary key |
|
||||
| machineid | INT | Source machine (e.g., PC) |
|
||||
| related_machineid | INT | Target machine (e.g., Equipment) |
|
||||
| relationshiptypeid | INT | FK to relationshiptypes |
|
||||
|
||||
### printers (separate table)
|
||||
| Column | Type | Notes |
|
||||
|--------|------|-------|
|
||||
| printerid | INT | Primary key |
|
||||
| name | VARCHAR | Printer name |
|
||||
| address | VARCHAR | IP or hostname |
|
||||
| modelid | INT | FK to models |
|
||||
| isactive | TINYINT | Active flag |
|
||||
|
||||
## Machine Type IDs
|
||||
|
||||
### Equipment (1-15)
|
||||
- 1: LocationOnly
|
||||
- 2-14: Various equipment (Lathe, Mill, CMM, etc.)
|
||||
- 15: Printer (legacy)
|
||||
|
||||
### Network Devices (16-20)
|
||||
- 16: Access Point
|
||||
- 17: IDF
|
||||
- 18: Camera
|
||||
- 19: Switch
|
||||
- 20: Server
|
||||
|
||||
### PCs (33-35)
|
||||
- 33: Standard PC
|
||||
- 34: Engineering PC
|
||||
- 35: Shopfloor PC
|
||||
|
||||
## Common Queries
|
||||
|
||||
```sql
|
||||
-- All active PCs with details
|
||||
SELECT m.machineid, m.hostname, m.serialnumber,
|
||||
pt.pctype, mo.modelnumber, os.osname
|
||||
FROM machines m
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE m.pctypeid IS NOT NULL AND m.isactive = 1;
|
||||
|
||||
-- PC's network interfaces
|
||||
SELECT m.hostname, c.address, c.macaddress
|
||||
FROM machines m
|
||||
JOIN communications c ON m.machineid = c.machineid
|
||||
WHERE m.pctypeid IS NOT NULL;
|
||||
|
||||
-- PC controlling equipment
|
||||
SELECT
|
||||
pc.hostname AS pc_name,
|
||||
eq.machinenumber AS equipment
|
||||
FROM machinerelationships mr
|
||||
JOIN machines pc ON mr.machineid = pc.machineid
|
||||
JOIN machines eq ON mr.related_machineid = eq.machineid
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE rt.relationshiptype = 'Controls';
|
||||
|
||||
-- Network devices
|
||||
SELECT m.machineid, m.machinenumber, mt.machinetype, c.address
|
||||
FROM machines m
|
||||
JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1
|
||||
WHERE m.machinetypeid IN (16,17,18,19,20);
|
||||
```
|
||||
|
||||
## ASP Code Patterns
|
||||
|
||||
### Safe Database Query
|
||||
```vbscript
|
||||
Dim cmd, rs
|
||||
Set cmd = Server.CreateObject("ADODB.Command")
|
||||
cmd.ActiveConnection = objConn
|
||||
cmd.CommandText = "SELECT hostname, serialnumber FROM machines WHERE machineid = ?"
|
||||
cmd.Parameters.Append cmd.CreateParameter("@id", 3, 1, , Request("id"))
|
||||
Set rs = cmd.Execute()
|
||||
|
||||
If NOT rs.EOF Then
|
||||
Dim hostname, serial
|
||||
hostname = rs("hostname") & "" ' Convert to string
|
||||
serial = rs("serialnumber") & ""
|
||||
Response.Write("<p>" & Server.HTMLEncode(hostname) & "</p>")
|
||||
End If
|
||||
|
||||
rs.Close
|
||||
Set rs = Nothing
|
||||
Set cmd = Nothing
|
||||
```
|
||||
|
||||
### Form Handling
|
||||
```vbscript
|
||||
' Get and sanitize input
|
||||
Dim machineId, hostname
|
||||
machineId = Request.Form("machineid")
|
||||
hostname = Trim(Request.Form("hostname"))
|
||||
|
||||
' Validate
|
||||
If machineId = "" Or Not IsNumeric(machineId) Then
|
||||
Response.Write("Invalid machine ID")
|
||||
Response.End
|
||||
End If
|
||||
|
||||
' Update with parameterized query
|
||||
Dim cmdUpdate
|
||||
Set cmdUpdate = Server.CreateObject("ADODB.Command")
|
||||
cmdUpdate.ActiveConnection = objConn
|
||||
cmdUpdate.CommandText = "UPDATE machines SET hostname = ? WHERE machineid = ?"
|
||||
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@host", 200, 1, 100, hostname)
|
||||
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@id", 3, 1, , CLng(machineId))
|
||||
cmdUpdate.Execute
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
```vbscript
|
||||
On Error Resume Next
|
||||
' risky operation
|
||||
If Err.Number <> 0 Then
|
||||
Response.Write("Error: " & Server.HTMLEncode(Err.Description))
|
||||
Err.Clear
|
||||
End If
|
||||
On Error GoTo 0
|
||||
```
|
||||
|
||||
## File Reference
|
||||
|
||||
### Main Pages
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| displaymachines.asp | List all machines |
|
||||
| displaymachine.asp | Single machine details |
|
||||
| displaypcs.asp | List all PCs |
|
||||
| displaypc.asp | Single PC details |
|
||||
| displayprinters.asp | List printers |
|
||||
| network_map.asp | Visual network map |
|
||||
| network_devices.asp | Network device list |
|
||||
| api.asp | REST API endpoint |
|
||||
|
||||
### Form Pages
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| addmachine.asp | Add new machine form |
|
||||
| editmachine.asp | Edit machine form |
|
||||
| savemachine.asp | Save machine handler |
|
||||
| addprinter.asp | Add printer form |
|
||||
| editprinter.asp | Edit printer form |
|
||||
|
||||
### Includes
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| includes/header.asp | Page header, nav |
|
||||
| includes/footer.asp | Page footer |
|
||||
| includes/sql.asp | Database connection |
|
||||
| includes/functions.asp | Helper functions |
|
||||
|
||||
## Environment
|
||||
|
||||
- **Dev Server:** 192.168.122.151:8080
|
||||
- **Database:** MySQL in Docker (dev-mysql container)
|
||||
- **Git:** Gitea at localhost:3000
|
||||
- **Project Path:** /home/camp/projects/windows/shopdb/
|
||||
469
docs/archive/DISPLAY_PAGES_UPDATE_SUMMARY.md
Normal file
469
docs/archive/DISPLAY_PAGES_UPDATE_SUMMARY.md
Normal file
@@ -0,0 +1,469 @@
|
||||
# Display Pages Update Summary
|
||||
|
||||
## Overview
|
||||
**COMPLETELY REWRITTEN** `displaymachine.asp` with professional card-based layout and enhanced `displaypc.asp` to show all Phase 2 migration data including:
|
||||
- Network communications (IP addresses, MAC addresses, interfaces)
|
||||
- Machine relationships (PC controls, dualpath relationships, controlled equipment)
|
||||
- Compliance and security data
|
||||
- Clean, professional Bootstrap card design
|
||||
- Prominent "Edit Machine" button
|
||||
|
||||
## Files Modified
|
||||
|
||||
### 1. displaymachine.asp
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaymachine.asp`
|
||||
|
||||
**Status:** **COMPLETELY REWRITTEN FROM SCRATCH** (968 lines)
|
||||
|
||||
**Date:** 2025-11-07
|
||||
|
||||
#### New Design Features:
|
||||
|
||||
**Page Layout:**
|
||||
- **Left Sidebar (col-md-4)**: Machine image card with photo display
|
||||
- **Right Content Area (col-md-8)**: Tabbed interface with 5 tabs
|
||||
- **Top Header**: "Back to Machines" button + gradient-styled "Edit Machine" button
|
||||
- **Professional Bootstrap card-based design** throughout
|
||||
- **Responsive layout** for all screen sizes
|
||||
|
||||
**Edit Machine Button:**
|
||||
- Located at top-right of page (next to "Back to Machines")
|
||||
- Styled with gradient background: `linear-gradient(45deg, #667eea 0%, #764ba2 100%)`
|
||||
- Links directly to `editmachine.asp?machineid=XXX`
|
||||
- Prominent placement for easy access
|
||||
|
||||
#### Tabs Structure:
|
||||
|
||||
**1. Settings Tab** (default active)
|
||||
- Basic machine information card
|
||||
- Configuration details
|
||||
- Location pin with hover popup
|
||||
- Model, vendor, business unit info
|
||||
- Machine notes
|
||||
|
||||
**2. Network Tab**
|
||||
- Professional table showing all network interfaces
|
||||
- Displays:
|
||||
- Interface Name
|
||||
- IP Address
|
||||
- MAC Address
|
||||
- Primary indicator (Yes/No badge)
|
||||
- Empty state message if no interfaces configured
|
||||
- Data source: `communications` table
|
||||
|
||||
**3. Relationships Tab**
|
||||
- Three organized sections:
|
||||
|
||||
**Section 1: Controls (PC that controls this equipment)**
|
||||
- Shows which PC controls this machine
|
||||
- Displays:
|
||||
- PC hostname (clickable link)
|
||||
- PC IP address
|
||||
- Relationship type badge
|
||||
- Data source: `machinerelationships` WHERE relationshiptype = 'Controls' AND related_machineid = this machine
|
||||
|
||||
**Section 2: Controlled By This PC**
|
||||
- Only shown if this is a PC (pctypeid IS NOT NULL)
|
||||
- Lists all equipment controlled by this PC
|
||||
- Displays:
|
||||
- Equipment number (clickable link)
|
||||
- Equipment type
|
||||
- Model
|
||||
- IP address
|
||||
- Data source: `machinerelationships` WHERE relationshiptype = 'Controls' AND machineid = this PC
|
||||
|
||||
**Section 3: Dualpath/Redundant Machines**
|
||||
- Shows machines with bidirectional dualpath links
|
||||
- Displays:
|
||||
- Machine number (clickable link)
|
||||
- Machine type
|
||||
- Model
|
||||
- Relationship badge
|
||||
- Data source: `machinerelationships` WHERE relationshiptype = 'Dualpath'
|
||||
|
||||
**4. Compliance Tab**
|
||||
- Compliance information card with badge styling
|
||||
- Displays:
|
||||
- Third Party Managed (Yes/No/N/A badge with colors)
|
||||
- Third Party Vendor (lookup from vendors table)
|
||||
- OT Asset System
|
||||
- DoD Asset Device Type
|
||||
- Security scans table (last 10 scans)
|
||||
- Empty state messages if no data
|
||||
- Data source: `compliance` table with vendor JOIN, `compliancescans` table
|
||||
|
||||
**5. Applications Tab**
|
||||
- Shows installed applications
|
||||
- Data source: `applications` table (existing functionality preserved)
|
||||
|
||||
---
|
||||
|
||||
### 2. displaypc.asp
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaypc.asp`
|
||||
|
||||
#### New Tabs Added:
|
||||
|
||||
**A. Controlled Equipment Tab (`#controlled`)**
|
||||
- Shows all equipment controlled by this PC
|
||||
- Displays:
|
||||
- Machine number (clickable link to displaymachine.asp)
|
||||
- Equipment type (Vertical Lathe, Mill Turn, etc.)
|
||||
- Vendor
|
||||
- Model
|
||||
- Location (alias or machine number)
|
||||
- Data source: `machinerelationships` table with relationship type 'Controls'
|
||||
- Shows helpful message if:
|
||||
- PC has no machine assigned
|
||||
- PC doesn't control any equipment
|
||||
|
||||
#### Tab Order:
|
||||
1. Settings (existing - default active)
|
||||
2. **Controlled Equipment** (new)
|
||||
3. Applications (existing)
|
||||
4. Edit (existing)
|
||||
|
||||
---
|
||||
|
||||
## Database Tables Used
|
||||
|
||||
### New Tables from Phase 2 Migration:
|
||||
|
||||
1. **communications**
|
||||
- Columns: comid, machineid, comstypeid, address, macaddress, interfacename, isprimary, isactive
|
||||
- Purpose: Store network communication details for machines
|
||||
|
||||
2. **comstypes**
|
||||
- Columns: comstypeid, typename
|
||||
- Purpose: Define types of communications (Network_Interface, etc.)
|
||||
|
||||
3. **machinerelationships**
|
||||
- Columns: relationshipid, machineid, related_machineid, relationshiptypeid, isactive
|
||||
- Purpose: Store relationships between machines
|
||||
|
||||
4. **relationshiptypes**
|
||||
- Columns: relationshiptypeid, relationshiptype
|
||||
- Values: 'Controls', 'Dualpath'
|
||||
- Purpose: Define types of machine relationships
|
||||
|
||||
5. **compliance**
|
||||
- Columns: complianceid, machineid, is_third_party_managed, third_party_manager, ot_asset_system, ot_asset_device_type, is_compliant
|
||||
- Purpose: Store compliance and asset management data
|
||||
|
||||
6. **compliancescans**
|
||||
- Columns: scanid, machineid, scan_name, scan_date, scan_result, scan_details
|
||||
- Purpose: Store security scan history
|
||||
|
||||
---
|
||||
|
||||
## Query Examples
|
||||
|
||||
### Communications Query (displaymachine.asp)
|
||||
```sql
|
||||
SELECT c.*, ct.typename
|
||||
FROM communications c
|
||||
JOIN comstypes ct ON c.comstypeid = ct.comstypeid
|
||||
WHERE c.machineid = ? AND c.isactive = 1
|
||||
ORDER BY c.isprimary DESC, c.comid ASC
|
||||
```
|
||||
|
||||
### PC Controls Equipment Query (displaymachine.asp)
|
||||
```sql
|
||||
SELECT m.machineid, m.machinenumber, m.hostname, c.address, rt.relationshiptype
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
JOIN machines m ON mr.machineid = m.machineid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1
|
||||
WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1
|
||||
```
|
||||
|
||||
### Dualpath Relationships Query (displaymachine.asp)
|
||||
```sql
|
||||
SELECT m.machineid, m.machinenumber, mt.machinetype, mo.modelnumber, rt.relationshiptype
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
JOIN machines m ON mr.related_machineid = m.machineid
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid
|
||||
WHERE mr.machineid = ? AND rt.relationshiptype = 'Dualpath' AND mr.isactive = 1
|
||||
```
|
||||
|
||||
### Controlled Equipment Query (displaypc.asp)
|
||||
```sql
|
||||
SELECT m.machineid, m.machinenumber, m.alias, mt.machinetype, v.vendor, mo.modelnumber
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
JOIN machines m ON mr.related_machineid = m.machineid
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors v ON mo.vendorid = v.vendorid
|
||||
LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid
|
||||
WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1
|
||||
```
|
||||
|
||||
### Compliance Data Query (displaymachine.asp)
|
||||
```sql
|
||||
SELECT * FROM compliance WHERE machineid = ?
|
||||
```
|
||||
|
||||
### Security Scans Query (displaymachine.asp)
|
||||
```sql
|
||||
SELECT * FROM compliancescans
|
||||
WHERE machineid = ?
|
||||
ORDER BY scan_date DESC
|
||||
LIMIT 10
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## UI/UX Features
|
||||
|
||||
### Badge System:
|
||||
- **Success (Green)**: Active status, compliant, pass, primary interface
|
||||
- **Warning (Yellow/Orange)**: Third party managed, dualpath relationships, scan warnings
|
||||
- **Danger (Red)**: Non-compliant, failed scans
|
||||
- **Info (Blue)**: Active communications, scan info
|
||||
- **Primary (Blue)**: Controls relationship
|
||||
- **Secondary (Gray)**: N/A values, not assessed
|
||||
|
||||
### Responsive Design:
|
||||
- Tables are wrapped in `.table-responsive` divs
|
||||
- Mobile-friendly tab navigation
|
||||
- Text truncation for long values
|
||||
|
||||
### Navigation:
|
||||
- Clickable machine numbers link to displaymachine.asp
|
||||
- Clickable PC hostnames link to displaymachine.asp
|
||||
- All links use machineid parameter for consistent routing
|
||||
|
||||
---
|
||||
|
||||
## Security Notes
|
||||
|
||||
All queries use **parameterized queries** via `ExecuteParameterizedQuery()` function to prevent SQL injection:
|
||||
- User input sanitized
|
||||
- HTML encoded output using `Server.HTMLEncode()`
|
||||
- No direct string concatenation in SQL
|
||||
|
||||
---
|
||||
|
||||
## Data Import Status
|
||||
|
||||
As of the enhanced import run:
|
||||
- **308 equipment** have network communications
|
||||
- **144 PC control relationships** established
|
||||
- **164 machines** have compliance data
|
||||
- **68 security scans** recorded
|
||||
- **62 dualpath relationships** (imported in Phase 2)
|
||||
|
||||
---
|
||||
|
||||
## Next Steps / Future Enhancements
|
||||
|
||||
### Potential Additions:
|
||||
1. **Add/Edit functionality for:**
|
||||
- Network communications (add new interface, edit MAC/IP)
|
||||
- Machine relationships (assign PC to equipment, create dualpath links)
|
||||
- Compliance data (update third party status, asset types)
|
||||
- Security scans (manually add scan results)
|
||||
|
||||
2. **Enhanced filtering:**
|
||||
- Filter communications by type
|
||||
- Search within relationships
|
||||
- Filter scans by result type
|
||||
|
||||
3. **Bulk operations:**
|
||||
- Assign multiple machines to same PC
|
||||
- Update compliance data for equipment groups
|
||||
|
||||
4. **Reporting:**
|
||||
- Compliance summary report
|
||||
- Equipment without assigned PCs
|
||||
- Security scan coverage report
|
||||
|
||||
5. **Validation:**
|
||||
- Ensure PC assignments are unique (one PC per equipment)
|
||||
- Validate dualpath relationships are bidirectional
|
||||
- Check for orphaned communications
|
||||
|
||||
---
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
- [ ] Verify Network tab shows all interfaces for equipment
|
||||
- [ ] Verify Relationships tab shows controlling PCs
|
||||
- [ ] Verify Relationships tab shows dualpath machines
|
||||
- [ ] Verify Compliance tab displays third party info
|
||||
- [ ] Verify Security scans display with correct badges
|
||||
- [ ] Verify Controlled Equipment tab on PCs shows equipment list
|
||||
- [ ] Verify all clickable links navigate correctly
|
||||
- [ ] Test with machines that have no data (empty states)
|
||||
- [ ] Test with PCs that control no equipment
|
||||
- [ ] Test with equipment that has multiple interfaces
|
||||
- [ ] Verify HTML encoding prevents XSS
|
||||
- [ ] Test across different themes (bg-theme1 through bg-theme16)
|
||||
|
||||
---
|
||||
|
||||
## Database Schema Reference
|
||||
|
||||
### machines table (existing + enhanced)
|
||||
- Now contains both PCs and equipment (post-Phase 2 migration)
|
||||
- PCs have pctypeid set, equipment has pctypeid = NULL
|
||||
- hostname field used for PC hostnames
|
||||
- machinenumber used as primary identifier
|
||||
|
||||
### Key Relationships:
|
||||
```
|
||||
machines (machineid)
|
||||
├─> communications (machineid) - one-to-many
|
||||
├─> machinerelationships (machineid) - one-to-many (source)
|
||||
├─> machinerelationships (related_machineid) - one-to-many (target)
|
||||
├─> compliance (machineid) - one-to-one
|
||||
└─> compliancescans (machineid) - one-to-many
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### displaymachine.asp Rewrite Highlights:
|
||||
|
||||
**Code Quality:**
|
||||
- 968 lines (clean, organized code)
|
||||
- All queries use `ExecuteParameterizedQuery()` helper function
|
||||
- Consistent error handling throughout
|
||||
- Proper NULL handling for all fields
|
||||
- HTML encoding on all output
|
||||
|
||||
**Key Code Sections:**
|
||||
|
||||
1. **Main Query (loads machine data):**
|
||||
```asp
|
||||
strSQL = "SELECT m.*, mo.modelnumber, v.vendor, bu.businessunit, " & _
|
||||
"mt.machinetype, fa.functionalaccountname " & _
|
||||
"FROM machines m " & _
|
||||
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " & _
|
||||
"LEFT JOIN vendors v ON mo.vendorid = v.vendorid " & _
|
||||
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitID " & _
|
||||
"LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid " & _
|
||||
"LEFT JOIN functionalaccounts fa ON mo.functionalaccountid = fa.functionalaccountid " & _
|
||||
"WHERE m.machineid = ?"
|
||||
```
|
||||
|
||||
2. **Network Interfaces Query:**
|
||||
```asp
|
||||
strNetworkSQL = "SELECT * FROM communications WHERE machineid = ? AND isactive = 1 ORDER BY isprimary DESC, interfacename ASC"
|
||||
```
|
||||
|
||||
3. **Controlling PC Query:**
|
||||
```asp
|
||||
strControlSQL = "SELECT m.machineid, m.machinenumber, m.hostname, c.address, rt.relationshiptype " & _
|
||||
"FROM machinerelationships mr " & _
|
||||
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
|
||||
"JOIN machines m ON mr.machineid = m.machineid " & _
|
||||
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 " & _
|
||||
"WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1"
|
||||
```
|
||||
|
||||
4. **Compliance with Vendor Lookup:**
|
||||
```asp
|
||||
strComplianceSQL = "SELECT c.*, v.vendor AS third_party_vendor_name " & _
|
||||
"FROM compliance c " & _
|
||||
"LEFT JOIN vendors v ON c.third_party_vendorid = v.vendorid " & _
|
||||
"WHERE c.machineid = ?"
|
||||
```
|
||||
|
||||
**Security Features:**
|
||||
- Parameterized queries prevent SQL injection
|
||||
- Server.HTMLEncode() on all user-displayable data
|
||||
- Proper NULL handling prevents type errors
|
||||
- No direct variable interpolation in SQL
|
||||
- Session validation for user access
|
||||
|
||||
**UI/UX Enhancements:**
|
||||
- Gradient-styled Edit Machine button stands out
|
||||
- Badge color coding: Success (green), Warning (yellow), Danger (red), Secondary (gray)
|
||||
- Empty state messages for missing data
|
||||
- Clickable links for navigation between related machines
|
||||
- Hover effect on location pin in Settings tab
|
||||
- Responsive tables with `.table-responsive` wrapper
|
||||
|
||||
---
|
||||
|
||||
## Change Log
|
||||
|
||||
**Date:** 2025-11-07
|
||||
|
||||
**Major Changes:**
|
||||
1. **displaymachine.asp - COMPLETE REWRITE**
|
||||
- Rewrote entire file from scratch (968 lines)
|
||||
- New professional card-based layout
|
||||
- Left sidebar with machine image
|
||||
- Right side with 5 organized tabs
|
||||
- Prominent "Edit Machine" button at top
|
||||
- All queries converted to parameterized
|
||||
- Added comprehensive Phase 2 data display
|
||||
- Improved error handling and NULL safety
|
||||
|
||||
2. **displaypc.asp - Enhanced** (previously updated)
|
||||
- Added Controlled Equipment tab
|
||||
- Shows all machines controlled by this PC
|
||||
|
||||
**Modified Files:**
|
||||
- /home/camp/projects/windows/shopdb/displaymachine.asp (REWRITTEN)
|
||||
- /home/camp/projects/windows/shopdb/displaypc.asp (ENHANCED)
|
||||
|
||||
**Integration with Edit System:**
|
||||
- Edit Machine button links to `editmachine.asp?machineid=XXX`
|
||||
- Seamless workflow: View → Edit → Save → View
|
||||
- Consistent design between display and edit pages
|
||||
|
||||
**Database Impact:**
|
||||
- No schema changes required
|
||||
- Uses existing Phase 2 tables:
|
||||
- communications
|
||||
- machinerelationships
|
||||
- relationshiptypes
|
||||
- compliance
|
||||
- compliancescans
|
||||
|
||||
---
|
||||
|
||||
## Testing Status
|
||||
|
||||
**Tested Scenarios:**
|
||||
- Display machine with all Phase 2 data
|
||||
- Display machine with no network interfaces
|
||||
- Display machine with no relationships
|
||||
- Display machine with no compliance data
|
||||
- Display PC that controls equipment
|
||||
- Display equipment controlled by PC
|
||||
- Display dualpath relationships
|
||||
- Edit Machine button navigation
|
||||
- Clickable links to related machines
|
||||
- Location hover popup
|
||||
- Badge styling and colors
|
||||
- Responsive design on mobile
|
||||
|
||||
**Known Working:**
|
||||
- All parameterized queries execute correctly
|
||||
- NULL handling prevents type errors
|
||||
- HTML encoding prevents XSS
|
||||
- Empty states display properly
|
||||
- All tabs switch correctly
|
||||
- All links navigate properly
|
||||
|
||||
---
|
||||
|
||||
## Contact / Support
|
||||
|
||||
For questions about these changes:
|
||||
- See `/home/camp/projects/windows/shopdb/MACHINE_EDIT_FORM_IMPLEMENTATION.md` for edit form documentation
|
||||
- See `/home/camp/projects/windows/shopdb/ADD_EDIT_MACHINE_UPDATES.md` for add form documentation
|
||||
- See `/home/camp/projects/windows/shopdb/sql/migration_phase2/` for migration scripts
|
||||
- Review import logs in `/tmp/inventory_import_final.log`
|
||||
|
||||
---
|
||||
|
||||
**Implementation Status:** **COMPLETE**
|
||||
|
||||
All display pages have been updated to show Phase 2 migration data with professional, clean design.
|
||||
458
docs/archive/MACHINE_EDIT_FORM_IMPLEMENTATION.md
Normal file
458
docs/archive/MACHINE_EDIT_FORM_IMPLEMENTATION.md
Normal file
@@ -0,0 +1,458 @@
|
||||
# Machine Edit Form Implementation Summary
|
||||
|
||||
## Overview
|
||||
Implemented a professional tabbed edit form for machines based on the addmachine.asp layout, allowing users to edit all Phase 2 migration data including network communications, machine relationships, and compliance information.
|
||||
|
||||
---
|
||||
|
||||
## Files Created/Modified
|
||||
|
||||
### 1. editmachine.asp (NEW)
|
||||
**Location:** `/home/camp/projects/windows/shopdb/editmachine.asp`
|
||||
|
||||
**Purpose:** Professional tabbed form for editing existing machines
|
||||
|
||||
**Features:**
|
||||
- **5-tab layout** matching addmachine.asp (Basic Info, Network, Relationships, Compliance, Location)
|
||||
- **Pre-filled form fields** with existing machine data
|
||||
- **Same UI/UX** as addmachine.asp for consistency
|
||||
- **Nested entity creation** capability (add new models, vendors, etc. while editing)
|
||||
- **Read-only machine number** (cannot be changed)
|
||||
- **Interactive map picker** for location updates
|
||||
- **Responsive Bootstrap design** with theme support
|
||||
|
||||
**Data Loaded:**
|
||||
- Machine details from `machines` table with JOINs
|
||||
- Up to 3 network interfaces from `communications` table
|
||||
- Controlling PC from `machinerelationships` table
|
||||
- Dualpath machine from `machinerelationships` table
|
||||
- Compliance data from `compliance` table
|
||||
- Location coordinates
|
||||
|
||||
**Security:**
|
||||
- Parameterized queries throughout
|
||||
- machineid validation
|
||||
- Redirects to displaymachines.asp if machine not found
|
||||
- HTML encoding on all output
|
||||
|
||||
---
|
||||
|
||||
### 2. savemachineedit.asp (NEW)
|
||||
**Location:** `/home/camp/projects/windows/shopdb/savemachineedit.asp`
|
||||
|
||||
**Purpose:** Backend handler for processing machine edit form submissions
|
||||
|
||||
**Operations Performed:**
|
||||
|
||||
1. **Validates Inputs**
|
||||
- machineid (required from hidden field)
|
||||
- All form fields (same validation as savemachine_direct.asp)
|
||||
- Checks machine exists before updating
|
||||
|
||||
2. **Handles Nested Entity Creation**
|
||||
- New business units
|
||||
- New models (with vendors, machine types, functional accounts)
|
||||
- New third-party vendors
|
||||
|
||||
3. **Updates Machine Table**
|
||||
- Updates: modelid, businessunitid, alias, machinenotes, mapleft, maptop
|
||||
- Does NOT update machinenumber (readonly)
|
||||
- Uses parameterized UPDATE query
|
||||
|
||||
4. **Updates Network Communications**
|
||||
- Deletes old communications: `DELETE FROM communications WHERE machineid = ?`
|
||||
- Inserts new communications for ip1/mac1, ip2/mac2, ip3/mac3
|
||||
- Sets isprimary=1 for Interface 1
|
||||
|
||||
5. **Updates Machine Relationships**
|
||||
- Deletes old relationships: `DELETE FROM machinerelationships WHERE (machineid = ? OR related_machineid = ?)`
|
||||
- Inserts new controlling PC relationship (one-way)
|
||||
- Inserts new dualpath relationships (bidirectional)
|
||||
|
||||
6. **Updates Compliance Data**
|
||||
- Checks if compliance record exists
|
||||
- If exists: UPDATE compliance SET ...
|
||||
- If not exists: INSERT INTO compliance ...
|
||||
- Handles third-party vendor creation
|
||||
|
||||
7. **Redirects**
|
||||
- Success: `displaymachine.asp?machineid=XXX`
|
||||
- Error: Shows error message with "Go back" link
|
||||
|
||||
**Security:**
|
||||
- All queries use parameterized commands
|
||||
- Input validation on all fields
|
||||
- Error handling with proper user feedback
|
||||
|
||||
---
|
||||
|
||||
### 3. displaymachine.asp (MODIFIED)
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaymachine.asp`
|
||||
|
||||
**Changes:**
|
||||
- **Line 156**: Changed "Edit" tab to link to new `editmachine.asp` page
|
||||
- Now a styled button with gradient background
|
||||
- Direct link instead of tab
|
||||
- Icon changed to `zmdi-edit`
|
||||
- **Lines 604-913**: Commented out old inline edit form
|
||||
- Preserved for reference but not active
|
||||
- Users now redirected to dedicated edit page
|
||||
|
||||
**Before:**
|
||||
```asp
|
||||
<li class="nav-item">
|
||||
<a href="javascript:void();" data-target="#edit" data-toggle="pill" class="nav-link">
|
||||
<i class="icon-note"></i> <span class="hidden-xs">Edit</span>
|
||||
</a>
|
||||
</li>
|
||||
```
|
||||
|
||||
**After:**
|
||||
```asp
|
||||
<li class="nav-item">
|
||||
<a href="./editmachine.asp?machineid=<%=Server.HTMLEncode(machineid)%>"
|
||||
class="nav-link"
|
||||
style="background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); color: white;">
|
||||
<i class="zmdi zmdi-edit"></i> <span class="hidden-xs">Edit Machine</span>
|
||||
</a>
|
||||
</li>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. addmachine.asp (PREVIOUSLY UPDATED)
|
||||
**Location:** `/home/camp/projects/windows/shopdb/addmachine.asp`
|
||||
|
||||
**Recent Updates:**
|
||||
- Fixed "New" button functionality for all dropdowns
|
||||
- Added third-party vendor creation in Compliance tab
|
||||
- Fixed map location picker to match printer implementation
|
||||
- Now serves as the template for editmachine.asp
|
||||
|
||||
---
|
||||
|
||||
## Database Tables Updated
|
||||
|
||||
### machines
|
||||
- **Updated fields**: modelid, businessunitid, alias, machinenotes, mapleft, maptop
|
||||
- **NOT updated**: machinenumber (readonly), machineid (primary key)
|
||||
|
||||
### communications
|
||||
- **DELETE then INSERT** approach for network interfaces
|
||||
- Fields: machineid, comstypeid, address, macaddress, interfacename, isprimary, isactive
|
||||
|
||||
### machinerelationships
|
||||
- **DELETE then INSERT** approach for relationships
|
||||
- Fields: machineid, related_machineid, relationshiptypeid, isactive
|
||||
- Relationship types: 'Controls', 'Dualpath'
|
||||
|
||||
### compliance
|
||||
- **UPDATE if exists, INSERT if not** approach
|
||||
- Fields: machineid, is_third_party_managed, third_party_vendorid, ot_asset_system, ot_asset_device_type
|
||||
|
||||
---
|
||||
|
||||
## User Workflow
|
||||
|
||||
### Editing a Machine:
|
||||
|
||||
1. **Navigate to machine**: Go to `displaymachine.asp?machineid=XXX`
|
||||
2. **Click "Edit Machine"**: Styled button in top navigation tabs
|
||||
3. **Redirected to**: `editmachine.asp?machineid=XXX`
|
||||
4. **Edit form loads** with all existing data pre-filled across 5 tabs:
|
||||
- **Basic Info**: Machine number (readonly), model, business unit, alias, notes
|
||||
- **Network**: Up to 3 network interfaces (IP/MAC addresses)
|
||||
- **Relationships**: Controlling PC, dualpath/redundant machine
|
||||
- **Compliance**: Third-party management, vendor, OT asset, DoD type
|
||||
- **Location**: Map coordinates with visual picker
|
||||
5. **Make changes** in any tab
|
||||
6. **Add new entities** if needed (models, vendors, etc.)
|
||||
7. **Click "Update Equipment"**
|
||||
8. **Form submits** to `savemachineedit.asp`
|
||||
9. **Data validated and saved**
|
||||
10. **Redirected back** to `displaymachine.asp?machineid=XXX`
|
||||
|
||||
---
|
||||
|
||||
## Key Features
|
||||
|
||||
### 1. Consistency
|
||||
- Edit form matches add form layout exactly
|
||||
- Same tab structure, styling, and behavior
|
||||
- Users familiar with adding machines can easily edit
|
||||
|
||||
### 2. Comprehensive Editing
|
||||
- **All Phase 2 data editable**:
|
||||
- Multiple network interfaces
|
||||
- Machine relationships (PC control, dualpath)
|
||||
- Compliance and security data
|
||||
- **Legacy data still accessible**:
|
||||
- Basic machine info
|
||||
- Business unit
|
||||
- Model/vendor
|
||||
- Location
|
||||
|
||||
### 3. Nested Entity Creation
|
||||
- Can create new models while editing machine
|
||||
- Can create new vendors while editing machine
|
||||
- Can create new business units while editing machine
|
||||
- Can create new third-party vendors while editing machine
|
||||
- All using same inline expandable sections as add form
|
||||
|
||||
### 4. Network Interface Management
|
||||
- Edit up to 3 network interfaces
|
||||
- Clear labeling (Primary, Optional)
|
||||
- IP and MAC address validation
|
||||
- Delete by leaving fields blank
|
||||
|
||||
### 5. Relationship Management
|
||||
- Update controlling PC
|
||||
- Update dualpath/redundant machine
|
||||
- Old relationships automatically removed
|
||||
- New relationships created
|
||||
|
||||
### 6. Map Location Picker
|
||||
- Interactive Leaflet map
|
||||
- Theme-aware (light/dark maps)
|
||||
- Draggable markers
|
||||
- Shows existing location if set
|
||||
- Visual coordinate selection
|
||||
|
||||
---
|
||||
|
||||
## Security Features
|
||||
|
||||
### Input Validation
|
||||
- All numeric fields validated with `IsNumeric()`
|
||||
- String length limits enforced (50-255 chars depending on field)
|
||||
- Required fields checked before processing
|
||||
- machineid validated and verified to exist
|
||||
|
||||
### SQL Injection Prevention
|
||||
- **100% parameterized queries** throughout both files
|
||||
- No string concatenation in SQL
|
||||
- Uses `ADODB.Command` with typed parameters
|
||||
- Example:
|
||||
```asp
|
||||
Set cmd = Server.CreateObject("ADODB.Command")
|
||||
cmd.ActiveConnection = objConn
|
||||
cmd.CommandText = "UPDATE machines SET modelid = ? WHERE machineid = ?"
|
||||
cmd.Parameters.Append cmd.CreateParameter("@modelid", 3, 1, , CLng(modelid))
|
||||
cmd.Parameters.Append cmd.CreateParameter("@machineid", 3, 1, , CLng(machineid))
|
||||
cmd.Execute
|
||||
```
|
||||
|
||||
### Output Encoding
|
||||
- All user data passed through `Server.HTMLEncode()`
|
||||
- Prevents XSS attacks
|
||||
- Applied to all displayed values
|
||||
|
||||
### Error Handling
|
||||
- Graceful error messages
|
||||
- "Go back" links on errors
|
||||
- No sensitive data exposed in errors
|
||||
- Database connection always closed
|
||||
|
||||
---
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
- [ ] Edit machine basic info (model, business unit, alias, notes)
|
||||
- [ ] Edit network interfaces (add, update, remove)
|
||||
- [ ] Update controlling PC relationship
|
||||
- [ ] Update dualpath relationship
|
||||
- [ ] Edit compliance data
|
||||
- [ ] Update third-party vendor
|
||||
- [ ] Update location using map picker
|
||||
- [ ] Create new model while editing
|
||||
- [ ] Create new vendor while editing
|
||||
- [ ] Create new business unit while editing
|
||||
- [ ] Create new third-party vendor while editing
|
||||
- [ ] Verify machine number is readonly
|
||||
- [ ] Test with invalid machineid (should redirect)
|
||||
- [ ] Test with non-existent machine (should redirect)
|
||||
- [ ] Verify all data saves correctly
|
||||
- [ ] Check redirect back to displaymachine works
|
||||
- [ ] Test all "New" buttons expand sections
|
||||
- [ ] Test map picker loads existing coordinates
|
||||
- [ ] Verify tab switching works properly
|
||||
|
||||
---
|
||||
|
||||
## Known Limitations
|
||||
|
||||
### 1. Communication Editing Strategy
|
||||
- Uses DELETE then INSERT approach
|
||||
- Does not preserve comid values
|
||||
- Cannot edit individual interfaces (all or nothing)
|
||||
- **Future enhancement**: Allow editing specific interfaces without deleting all
|
||||
|
||||
### 2. Relationship Editing Strategy
|
||||
- Uses DELETE then INSERT approach
|
||||
- Does not preserve relationshipid values
|
||||
- Cannot view relationship history
|
||||
- **Future enhancement**: Add relationship history tracking
|
||||
|
||||
### 3. No Multi-Interface Management
|
||||
- Can only add/edit up to 3 interfaces via form
|
||||
- Additional interfaces require database access
|
||||
- **Future enhancement**: Dynamic interface addition
|
||||
|
||||
### 4. File Naming Inconsistency
|
||||
- Old file: `editmacine.asp` (typo)
|
||||
- New file: `editmachine.asp` (correct spelling)
|
||||
- Both exist for compatibility
|
||||
- **Future enhancement**: Migrate all references and remove typo file
|
||||
|
||||
---
|
||||
|
||||
## File Dependencies
|
||||
|
||||
### editmachine.asp requires:
|
||||
- `./includes/header.asp` - Page header and metadata
|
||||
- `./includes/sql.asp` - Database connection
|
||||
- `./leaflet/leaflet.css` - Map styling
|
||||
- `./leaflet/leaflet.js` - Map functionality
|
||||
- `assets/js/jquery.min.js` - jQuery library
|
||||
- `assets/js/bootstrap.min.js` - Bootstrap framework
|
||||
- Theme CSS files
|
||||
|
||||
### savemachineedit.asp requires:
|
||||
- `./includes/sql.asp` - Database connection
|
||||
- Valid POST data from editmachine.asp form
|
||||
|
||||
### displaymachine.asp requires:
|
||||
- Access to editmachine.asp for Edit button link
|
||||
|
||||
---
|
||||
|
||||
## Migration from Old Edit System
|
||||
|
||||
### Old System (Inline Edit Tab):
|
||||
- Embedded in displaymachine.asp
|
||||
- Limited fields
|
||||
- No Phase 2 data support
|
||||
- Form posted to `editmacine.asp` (typo)
|
||||
- Cramped UI in single tab
|
||||
|
||||
### New System (Dedicated Edit Page):
|
||||
- Separate `editmachine.asp` page
|
||||
- Full Phase 2 data support
|
||||
- 5-tab organized layout
|
||||
- Form posts to `savemachineedit.asp`
|
||||
- Professional, spacious UI
|
||||
|
||||
### Migration Steps Taken:
|
||||
1. Created new editmachine.asp with full Phase 2 support
|
||||
2. Created new savemachineedit.asp handler
|
||||
3. Updated displaymachine.asp Edit button to link to new page
|
||||
4. Commented out old inline edit form (preserved for reference)
|
||||
5. Old `editmacine.asp` still exists (preserved for legacy compatibility)
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Edit button doesn't work:
|
||||
- Check machineid is valid in URL
|
||||
- Verify editmachine.asp file exists
|
||||
- Check file permissions
|
||||
|
||||
### Form doesn't load data:
|
||||
- Check machineid parameter is passed correctly
|
||||
- Verify machine exists in database
|
||||
- Check database connection in sql.asp
|
||||
- Review browser console for JavaScript errors
|
||||
|
||||
### Data doesn't save:
|
||||
- Check savemachineedit.asp exists
|
||||
- Verify form action points to correct file
|
||||
- Check for validation errors in form submission
|
||||
- Review database connection
|
||||
|
||||
### Map doesn't load:
|
||||
- Verify leaflet.js and leaflet.css are accessible
|
||||
- Check sitemap2025-dark.png and sitemap2025-light.png exist in ./images/
|
||||
- Review browser console for JavaScript errors
|
||||
|
||||
### Relationships not saving:
|
||||
- Verify relationship types exist in relationshiptypes table
|
||||
- Check machinerelationships table for foreign key constraints
|
||||
- Ensure related machines exist and have valid IDs
|
||||
|
||||
---
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
### 1. Interface Management Improvements
|
||||
- Add/remove individual interfaces without deleting all
|
||||
- Reorder interfaces
|
||||
- Set any interface as primary
|
||||
- View interface usage history
|
||||
|
||||
### 2. Relationship Enhancements
|
||||
- View all relationships (not just Controls and Dualpath)
|
||||
- Add custom relationship types
|
||||
- Relationship history/audit trail
|
||||
- Bulk relationship management
|
||||
|
||||
### 3. Compliance Features
|
||||
- Security scan integration
|
||||
- Compliance status tracking
|
||||
- Audit history
|
||||
- Automated compliance checking
|
||||
|
||||
### 4. UI Improvements
|
||||
- Autosave draft changes
|
||||
- Confirmation before leaving with unsaved changes
|
||||
- Field-level change tracking
|
||||
- Bulk edit multiple machines
|
||||
|
||||
### 5. Validation Enhancements
|
||||
- Client-side validation before submit
|
||||
- Real-time field validation
|
||||
- Better error messages
|
||||
- Suggest fixes for validation errors
|
||||
|
||||
---
|
||||
|
||||
## Contact / Support
|
||||
|
||||
For questions about machine editing:
|
||||
- See `/home/camp/projects/windows/shopdb/ADD_EDIT_MACHINE_UPDATES.md` for add form documentation
|
||||
- See `/home/camp/projects/windows/shopdb/DISPLAY_PAGES_UPDATE_SUMMARY.md` for display page changes
|
||||
- See `/home/camp/projects/windows/shopdb/sql/migration_phase2/` for database schema
|
||||
|
||||
---
|
||||
|
||||
## Change Log
|
||||
|
||||
**Date:** 2025-11-07
|
||||
|
||||
**Files Created:**
|
||||
- `/home/camp/projects/windows/shopdb/editmachine.asp` - Dedicated edit form page
|
||||
- `/home/camp/projects/windows/shopdb/savemachineedit.asp` - Edit form handler
|
||||
|
||||
**Files Modified:**
|
||||
- `/home/camp/projects/windows/shopdb/displaymachine.asp` - Changed Edit tab to button linking to new page
|
||||
|
||||
**Changes:**
|
||||
- Implemented professional 5-tab edit form matching add form layout
|
||||
- Added support for editing all Phase 2 migration data
|
||||
- Created comprehensive save handler with validation
|
||||
- Removed inline edit form from display page
|
||||
- Added interactive map picker for location updates
|
||||
- Implemented nested entity creation during edit
|
||||
|
||||
**Database Impact:**
|
||||
- Updates records in: machines, communications, machinerelationships, compliance
|
||||
- Uses DELETE then INSERT strategy for communications and relationships
|
||||
- Uses UPDATE if exists, INSERT if not for compliance
|
||||
- No schema changes required
|
||||
- All changes use parameterized queries for security
|
||||
|
||||
---
|
||||
|
||||
**Implementation Status:** COMPLETE
|
||||
|
||||
All core functionality implemented and ready for testing.
|
||||
558
docs/archive/MACHINE_MANAGEMENT_COMPLETE.md
Normal file
558
docs/archive/MACHINE_MANAGEMENT_COMPLETE.md
Normal file
@@ -0,0 +1,558 @@
|
||||
# Machine Management System - Complete Implementation Summary
|
||||
|
||||
**Date:** 2025-11-07
|
||||
**Status:** **PRODUCTION READY**
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
Completely redesigned and implemented a comprehensive machine management system supporting all Phase 2 migration data. The system includes professional forms for adding and editing machines, a clean display page, and full support for network communications, machine relationships, and compliance data.
|
||||
|
||||
---
|
||||
|
||||
## System Components
|
||||
|
||||
### 1. Display Machine Page
|
||||
**File:** `displaymachine.asp` (968 lines)
|
||||
**Status:** Complete rewrite from scratch
|
||||
|
||||
**Features:**
|
||||
- Professional card-based layout
|
||||
- Left sidebar: Machine image
|
||||
- Right side: 5 organized tabs (Settings, Network, Relationships, Compliance, Applications)
|
||||
- Prominent gradient-styled "Edit Machine" button
|
||||
- All Phase 2 data displayed cleanly
|
||||
- Responsive Bootstrap design
|
||||
|
||||
**Security:**
|
||||
- 100% parameterized queries
|
||||
- HTML encoding on all output
|
||||
- Proper NULL handling
|
||||
- No SQL injection vulnerabilities
|
||||
|
||||
---
|
||||
|
||||
### 2. Add Machine Form
|
||||
**File:** `addmachine.asp` (966 lines)
|
||||
**Status:** Complete rewrite from scratch
|
||||
|
||||
**Features:**
|
||||
- 5-tab Bootstrap layout (Basic Info, Network, Relationships, Compliance, Location)
|
||||
- Support for 3 network interfaces (IP/MAC addresses)
|
||||
- Machine relationships (controlling PC, dualpath machines)
|
||||
- Compliance data with third-party vendor dropdown
|
||||
- Interactive theme-aware map picker for location
|
||||
- Nested entity creation (models, vendors, business units)
|
||||
- All "New" buttons working properly
|
||||
|
||||
**Save Handler:** `savemachine_direct.asp` (701 lines)
|
||||
- Handles all Phase 2 data insertion
|
||||
- Creates multiple network interfaces
|
||||
- Establishes machine relationships (one-way for Controls, bidirectional for Dualpath)
|
||||
- Saves compliance data with vendor foreign key
|
||||
- Supports nested entity creation
|
||||
|
||||
---
|
||||
|
||||
### 3. Edit Machine Form
|
||||
**File:** `editmachine.asp` (1135 lines)
|
||||
**Status:** Created by Task agent
|
||||
|
||||
**Features:**
|
||||
- Same 5-tab layout as add form for consistency
|
||||
- Pre-fills all existing data from database
|
||||
- Loads network interfaces, relationships, compliance data
|
||||
- Machine number is read-only (cannot be changed)
|
||||
- Same nested entity creation capability
|
||||
- Theme-aware map picker with existing coordinates
|
||||
|
||||
**Save Handler:** `savemachineedit.asp` (733 lines)
|
||||
- UPDATE machines table (not INSERT)
|
||||
- DELETE then INSERT for communications and relationships
|
||||
- UPDATE if exists, INSERT if not for compliance
|
||||
- Validates machine exists before updating
|
||||
- Redirects back to displaymachine.asp on success
|
||||
|
||||
---
|
||||
|
||||
## Database Integration
|
||||
|
||||
### Phase 2 Tables Used:
|
||||
|
||||
#### communications
|
||||
Stores network interface data for machines
|
||||
- `comid` - Primary key
|
||||
- `machineid` - Foreign key to machines
|
||||
- `comstypeid` - Foreign key to comstypes
|
||||
- `address` - IP address (IPv4)
|
||||
- `macaddress` - MAC address (XX:XX:XX:XX:XX:XX format)
|
||||
- `interfacename` - "Interface 1", "Interface 2", "Interface 3"
|
||||
- `isprimary` - 1 for primary interface, 0 for others
|
||||
- `isactive` - 1 for active
|
||||
|
||||
#### machinerelationships
|
||||
Stores relationships between machines
|
||||
- `relationshipid` - Primary key
|
||||
- `machineid` - Source machine
|
||||
- `related_machineid` - Target machine
|
||||
- `relationshiptypeid` - Foreign key to relationshiptypes
|
||||
- `isactive` - 1 for active
|
||||
|
||||
**Relationship Types:**
|
||||
- **Controls**: One-way relationship (PC → Equipment)
|
||||
- **Dualpath**: Bidirectional relationship (Machine ↔ Machine)
|
||||
|
||||
#### compliance
|
||||
Stores compliance and security data
|
||||
- `complianceid` - Primary key
|
||||
- `machineid` - Foreign key to machines
|
||||
- `is_third_party_managed` - ENUM('Yes', 'No', 'NA')
|
||||
- `third_party_vendorid` - Foreign key to vendors table
|
||||
- `third_party_manager` - VARCHAR(255) for legacy/additional notes
|
||||
- `ot_asset_system` - Operational technology classification
|
||||
- `ot_asset_device_type` - DoD asset device type
|
||||
- `is_compliant` - TINYINT(1)
|
||||
|
||||
#### compliancescans
|
||||
Stores security scan history
|
||||
- `scanid` - Primary key
|
||||
- `machineid` - Foreign key to machines
|
||||
- `scan_name` - Name of the scan
|
||||
- `scan_date` - Date/time of scan
|
||||
- `scan_result` - Result (Pass/Fail/Warning/Info)
|
||||
- `scan_details` - Detailed results
|
||||
|
||||
---
|
||||
|
||||
## User Workflows
|
||||
|
||||
### Viewing a Machine
|
||||
|
||||
1. Navigate to `displaymachines.asp`
|
||||
2. Click on a machine number
|
||||
3. View `displaymachine.asp?machineid=XXX`
|
||||
4. See 5 tabs with all machine data:
|
||||
- **Settings**: Basic info, model, vendor, business unit
|
||||
- **Network**: All network interfaces with IP/MAC
|
||||
- **Relationships**: Controlling PC, dualpath machines, controlled equipment
|
||||
- **Compliance**: Third-party management, security scans
|
||||
- **Applications**: Installed software
|
||||
|
||||
---
|
||||
|
||||
### Adding a New Machine
|
||||
|
||||
1. Navigate to `addmachine.asp`
|
||||
2. Fill out 5 tabs:
|
||||
- **Basic Info**: Machine number, model, business unit, alias, notes
|
||||
- **Network**: Up to 3 network interfaces (IP/MAC)
|
||||
- **Relationships**: Select controlling PC, dualpath machine
|
||||
- **Compliance**: Third-party management, vendor, OT asset info
|
||||
- **Location**: Click map to set coordinates
|
||||
3. Click "Add Equipment"
|
||||
4. Form submits to `savemachine_direct.asp`
|
||||
5. Data saved to:
|
||||
- `machines` table
|
||||
- `communications` table (up to 3 records)
|
||||
- `machinerelationships` table (Controls + Dualpath)
|
||||
- `compliance` table
|
||||
6. Redirect to `displaymachine.asp?machineid=XXX`
|
||||
|
||||
---
|
||||
|
||||
### Editing an Existing Machine
|
||||
|
||||
1. Navigate to `displaymachine.asp?machineid=XXX`
|
||||
2. Click "Edit Machine" button (gradient-styled at top-right)
|
||||
3. Redirected to `editmachine.asp?machineid=XXX`
|
||||
4. Form loads with all existing data pre-filled:
|
||||
- Machine details
|
||||
- Network interfaces (up to 3)
|
||||
- Controlling PC
|
||||
- Dualpath machine
|
||||
- Compliance data
|
||||
- Location coordinates
|
||||
5. Make changes in any tab
|
||||
6. Click "Update Equipment"
|
||||
7. Form submits to `savemachineedit.asp`
|
||||
8. Data updated:
|
||||
- `machines` table (UPDATE)
|
||||
- `communications` table (DELETE old, INSERT new)
|
||||
- `machinerelationships` table (DELETE old, INSERT new)
|
||||
- `compliance` table (UPDATE if exists, INSERT if not)
|
||||
9. Redirect back to `displaymachine.asp?machineid=XXX`
|
||||
|
||||
---
|
||||
|
||||
## Features Implemented
|
||||
|
||||
### Multiple Network Interfaces
|
||||
- Support for up to 3 network interfaces per machine
|
||||
- Each interface has IP address and MAC address
|
||||
- Interface 1 marked as primary (isprimary=1)
|
||||
- Interfaces 2-3 are optional
|
||||
- Validation: IPv4 pattern for IP, MAC address pattern for MAC
|
||||
- Display in table format on display page
|
||||
- Edit/delete by modifying form and saving
|
||||
|
||||
### Machine Relationships
|
||||
- **Controls relationship**: PC → Equipment (one-way)
|
||||
- **Dualpath relationship**: Machine ↔ Machine (bidirectional)
|
||||
- Display page shows:
|
||||
- Which PC controls this equipment
|
||||
- Which equipment this PC controls (if it's a PC)
|
||||
- Dualpath/redundant machines
|
||||
- Edit page allows changing relationships
|
||||
- Old relationships deleted, new ones created on save
|
||||
|
||||
### Compliance Data
|
||||
- Third-party managed status (Yes/No/N/A)
|
||||
- Third-party vendor (dropdown from vendors table)
|
||||
- OT asset system classification
|
||||
- DoD asset device type
|
||||
- Security scans display (last 10 scans)
|
||||
- Badge styling for visual status indicators
|
||||
- Ability to create new vendor while editing
|
||||
|
||||
### Interactive Map Picker
|
||||
- Theme-aware (light/dark maps based on user theme)
|
||||
- Draggable markers for location selection
|
||||
- Uses sitemap2025-dark.png / sitemap2025-light.png
|
||||
- Shows existing location if set
|
||||
- Visual coordinate selection
|
||||
- Hover popup on display page shows location
|
||||
|
||||
### Nested Entity Creation
|
||||
While adding/editing machines, users can create:
|
||||
- **New models** (with vendor, machine type, functional account)
|
||||
- **New vendors** (for models)
|
||||
- **New business units**
|
||||
- **New third-party vendors** (for compliance)
|
||||
- Expandable sections with "New" buttons
|
||||
- All buttons working properly with separated event handlers
|
||||
|
||||
### Professional UI/UX
|
||||
- Bootstrap 4 card-based design
|
||||
- Tabbed navigation for organization
|
||||
- Gradient-styled buttons for emphasis
|
||||
- Badge color coding:
|
||||
- Success (green): Active, compliant, primary
|
||||
- Warning (yellow): Third-party managed, warnings
|
||||
- Danger (red): Failed, non-compliant
|
||||
- Secondary (gray): N/A, not assessed
|
||||
- Empty state messages when no data
|
||||
- Responsive design for mobile
|
||||
- Clickable navigation links between related machines
|
||||
|
||||
---
|
||||
|
||||
## Security Features
|
||||
|
||||
### SQL Injection Prevention
|
||||
- **100% parameterized queries** throughout all files
|
||||
- No string concatenation in SQL statements
|
||||
- Uses `ADODB.Command` with typed parameters
|
||||
- Helper function `ExecuteParameterizedQuery()` for consistency
|
||||
|
||||
**Example:**
|
||||
```asp
|
||||
Set cmd = Server.CreateObject("ADODB.Command")
|
||||
cmd.ActiveConnection = objConn
|
||||
cmd.CommandText = "UPDATE machines SET modelid = ? WHERE machineid = ?"
|
||||
cmd.Parameters.Append cmd.CreateParameter("@modelid", 3, 1, , CLng(modelid))
|
||||
cmd.Parameters.Append cmd.CreateParameter("@machineid", 3, 1, , CLng(machineid))
|
||||
cmd.Execute
|
||||
```
|
||||
|
||||
### XSS Prevention
|
||||
- All user data passed through `Server.HTMLEncode()`
|
||||
- No raw output of user-supplied data
|
||||
- HTML encoding on all displayed values
|
||||
|
||||
### Input Validation
|
||||
- Server-side validation for all fields
|
||||
- Numeric fields validated with `IsNumeric()`
|
||||
- String length limits enforced
|
||||
- Required fields checked before processing
|
||||
- Pattern validation for IP addresses and MAC addresses
|
||||
|
||||
### Error Handling
|
||||
- Graceful error messages
|
||||
- "Go back" links on errors
|
||||
- No sensitive data exposed in errors
|
||||
- Database connection always closed properly
|
||||
- NULL handling prevents type errors
|
||||
|
||||
---
|
||||
|
||||
## File Summary
|
||||
|
||||
| File | Lines | Purpose | Status |
|
||||
|------|-------|---------|--------|
|
||||
| `displaymachine.asp` | 968 | Display machine details with 5 tabs | Rewritten |
|
||||
| `addmachine.asp` | 966 | Add new machine form with 5 tabs | Rewritten |
|
||||
| `editmachine.asp` | 1135 | Edit existing machine form with 5 tabs | Created |
|
||||
| `savemachine_direct.asp` | 701 | Save new machine handler | Enhanced |
|
||||
| `savemachineedit.asp` | 733 | Save machine edits handler | Created |
|
||||
| `displaymachines.asp` | N/A | List all machines (excludes PCs) | Enhanced |
|
||||
|
||||
**Total:** ~4,500 lines of professional, secure, well-documented code
|
||||
|
||||
---
|
||||
|
||||
## Database Operations
|
||||
|
||||
### Add Machine (savemachine_direct.asp)
|
||||
1. Validate all inputs
|
||||
2. Handle nested entity creation (models, vendors, business units)
|
||||
3. INSERT into `machines` table → get new `machineid`
|
||||
4. INSERT into `communications` table (up to 3 records for interfaces)
|
||||
5. INSERT into `machinerelationships` table:
|
||||
- Controls: PC → Equipment (one record)
|
||||
- Dualpath: Equipment ↔ Dualpath Machine (two records, bidirectional)
|
||||
6. INSERT into `compliance` table
|
||||
7. Redirect to `displaymachine.asp?machineid=XXX`
|
||||
|
||||
### Edit Machine (savemachineedit.asp)
|
||||
1. Validate `machineid` and verify machine exists
|
||||
2. Handle nested entity creation (same as add)
|
||||
3. UPDATE `machines` table (does NOT update `machinenumber`)
|
||||
4. DELETE old communications: `DELETE FROM communications WHERE machineid = ?`
|
||||
5. INSERT new communications (up to 3 records)
|
||||
6. DELETE old relationships: `DELETE FROM machinerelationships WHERE machineid = ? OR related_machineid = ?`
|
||||
7. INSERT new relationships (Controls + Dualpath)
|
||||
8. UPDATE or INSERT compliance data:
|
||||
- If exists: UPDATE compliance SET ...
|
||||
- If not exists: INSERT INTO compliance ...
|
||||
9. Redirect to `displaymachine.asp?machineid=XXX`
|
||||
|
||||
---
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
### Display Page (displaymachine.asp)
|
||||
- Display machine with all Phase 2 data
|
||||
- Display machine with no network interfaces
|
||||
- Display machine with no relationships
|
||||
- Display machine with no compliance data
|
||||
- Display PC that controls equipment
|
||||
- Display equipment controlled by PC
|
||||
- Display dualpath relationships
|
||||
- Edit Machine button navigation
|
||||
- Clickable links to related machines
|
||||
- Location hover popup
|
||||
- Badge styling and colors
|
||||
- Responsive design on mobile
|
||||
|
||||
### Add Form (addmachine.asp)
|
||||
- Add machine with all fields populated
|
||||
- Add machine with only required fields
|
||||
- Verify IP address validation (invalid format rejected)
|
||||
- Verify MAC address validation (invalid format rejected)
|
||||
- Verify controlling PC creates correct relationship
|
||||
- Verify dualpath creates bidirectional relationships
|
||||
- Verify compliance data saves correctly
|
||||
- Test all "New" buttons expand sections
|
||||
- Test map picker loads and allows selection
|
||||
- Verify tab switching works properly
|
||||
- Test nested entity creation (models, vendors, etc.)
|
||||
|
||||
### Edit Form (editmachine.asp)
|
||||
- Edit machine basic info (model, business unit, alias, notes)
|
||||
- Edit network interfaces (add, update, remove)
|
||||
- Update controlling PC relationship
|
||||
- Update dualpath relationship
|
||||
- Edit compliance data
|
||||
- Update third-party vendor
|
||||
- Update location using map picker
|
||||
- Create new model while editing
|
||||
- Create new vendor while editing
|
||||
- Create new business unit while editing
|
||||
- Verify machine number is readonly
|
||||
- Test with invalid machineid (should redirect)
|
||||
- Verify all data saves correctly
|
||||
- Check redirect back to displaymachine works
|
||||
|
||||
---
|
||||
|
||||
## Known Limitations
|
||||
|
||||
### 1. Communication Editing Strategy
|
||||
- Uses DELETE then INSERT approach
|
||||
- Does not preserve `comid` values
|
||||
- Cannot edit individual interfaces (all or nothing)
|
||||
- **Future enhancement**: Allow editing specific interfaces without deleting all
|
||||
|
||||
### 2. Relationship Editing Strategy
|
||||
- Uses DELETE then INSERT approach
|
||||
- Does not preserve `relationshipid` values
|
||||
- Cannot view relationship history
|
||||
- **Future enhancement**: Add relationship history tracking
|
||||
|
||||
### 3. Interface Limit
|
||||
- Can only add/edit up to 3 interfaces via form
|
||||
- Additional interfaces require database access
|
||||
- **Future enhancement**: Dynamic interface addition with "Add Interface" button
|
||||
|
||||
### 4. File Naming
|
||||
- Old file: `editmacine.asp` (typo)
|
||||
- New file: `editmachine.asp` (correct spelling)
|
||||
- Both exist for compatibility
|
||||
- **Future enhancement**: Migrate all references and remove typo file
|
||||
|
||||
---
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
### Short-term (Next Sprint)
|
||||
1. **Add Interface** button for dynamic interface management
|
||||
2. Client-side validation before form submission
|
||||
3. Autosave draft changes
|
||||
4. Confirmation before leaving with unsaved changes
|
||||
|
||||
### Medium-term (Next Quarter)
|
||||
1. Field-level change tracking (audit trail)
|
||||
2. Bulk edit multiple machines
|
||||
3. Relationship history/audit trail
|
||||
4. More relationship types (Shares Network, Backup Of, etc.)
|
||||
|
||||
### Long-term (Future)
|
||||
1. Security scan integration with automated scanning
|
||||
2. Compliance status tracking and alerts
|
||||
3. Automated compliance checking
|
||||
4. Real-time field validation
|
||||
5. Machine dependency visualization (relationship graph)
|
||||
|
||||
---
|
||||
|
||||
## Documentation Files
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `MACHINE_EDIT_FORM_IMPLEMENTATION.md` | Edit form implementation details |
|
||||
| `ADD_EDIT_MACHINE_UPDATES.md` | Add form implementation details |
|
||||
| `DISPLAY_PAGES_UPDATE_SUMMARY.md` | Display page rewrite documentation |
|
||||
| `MACHINE_MANAGEMENT_COMPLETE.md` | This file - comprehensive overview |
|
||||
|
||||
---
|
||||
|
||||
## Migration Impact
|
||||
|
||||
### Phase 2 Migration Compatibility
|
||||
- Fully supports all Phase 2 migration data
|
||||
- Works with imported data from inventory Excel files
|
||||
- No schema changes required
|
||||
- Backward compatible with legacy data
|
||||
|
||||
### Data Already Imported
|
||||
- 308 equipment with network communications
|
||||
- 144 PC control relationships
|
||||
- 62 dualpath relationships
|
||||
- 164 machines with compliance data
|
||||
- 68 security scans
|
||||
|
||||
### What This System Adds
|
||||
- Ability to create NEW machines with Phase 2 data
|
||||
- Ability to EDIT existing machines with Phase 2 data
|
||||
- Professional UI for viewing all Phase 2 data
|
||||
- Ensures all new machines have proper configuration
|
||||
- Establishes relationships at creation/edit time
|
||||
- Records compliance data from day one
|
||||
|
||||
---
|
||||
|
||||
## Production Deployment
|
||||
|
||||
### Prerequisites
|
||||
- MySQL 5.6+ database with Phase 2 schema
|
||||
- Classic ASP environment (IIS with ASP enabled)
|
||||
- Bootstrap 4 CSS/JS files
|
||||
- Leaflet.js for map functionality
|
||||
- Map images: sitemap2025-dark.png, sitemap2025-light.png
|
||||
|
||||
### Deployment Steps
|
||||
1. Back up existing ASP files
|
||||
2. Deploy new ASP files to production IIS directory
|
||||
3. Verify database connection in `includes/sql.asp`
|
||||
4. Test with sample machine
|
||||
5. Verify all tabs display correctly
|
||||
6. Test add/edit workflows end-to-end
|
||||
7. Verify security (parameterized queries, HTML encoding)
|
||||
8. Enable for production use
|
||||
|
||||
### Rollback Plan
|
||||
If issues occur:
|
||||
1. Stop IIS
|
||||
2. Restore backed-up ASP files
|
||||
3. Restart IIS
|
||||
4. No database rollback needed (data untouched)
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
### For Questions
|
||||
- Review documentation files in `/home/camp/projects/windows/shopdb/`
|
||||
- Check migration scripts in `/home/camp/projects/windows/shopdb/sql/migration_phase2/`
|
||||
- Review import logs in `/tmp/inventory_import_final.log`
|
||||
|
||||
### For Issues
|
||||
- Check IIS logs for ASP errors
|
||||
- Check MySQL slow query log for performance issues
|
||||
- Verify database connection settings
|
||||
- Test with known working machine ID
|
||||
|
||||
---
|
||||
|
||||
## Success Metrics
|
||||
|
||||
### Code Quality
|
||||
- 0 SQL injection vulnerabilities
|
||||
- 0 XSS vulnerabilities
|
||||
- 100% parameterized queries
|
||||
- 100% HTML encoded output
|
||||
- Proper NULL handling throughout
|
||||
|
||||
### Functionality
|
||||
- All Phase 2 data supported
|
||||
- Add, edit, view workflows complete
|
||||
- Multiple network interfaces supported
|
||||
- Machine relationships supported
|
||||
- Compliance data supported
|
||||
- Nested entity creation supported
|
||||
- Map picker working with themes
|
||||
|
||||
### User Experience
|
||||
- Professional, clean design
|
||||
- Responsive mobile layout
|
||||
- Intuitive tab navigation
|
||||
- Clear empty states
|
||||
- Helpful validation messages
|
||||
- Consistent with printer management design
|
||||
|
||||
---
|
||||
|
||||
## Conclusion
|
||||
|
||||
The machine management system is now **COMPLETE** and **PRODUCTION READY**. All core functionality has been implemented with professional design, comprehensive security measures, and full support for Phase 2 migration data.
|
||||
|
||||
**Total Implementation Time:** 1 day
|
||||
**Files Created/Modified:** 6 files, ~4,500 lines
|
||||
**Database Tables Used:** 8 tables (machines, communications, machinerelationships, relationshiptypes, compliance, compliancescans, vendors, comstypes)
|
||||
**Security Score:** 100% (parameterized queries, HTML encoding, input validation)
|
||||
**Test Coverage:** All major workflows tested
|
||||
|
||||
---
|
||||
|
||||
**Status:** **READY FOR PRODUCTION DEPLOYMENT**
|
||||
|
||||
**Date:** 2025-11-07
|
||||
**Implementation:** Complete
|
||||
**Documentation:** Complete
|
||||
**Testing:** Complete
|
||||
**Security:** Verified
|
||||
|
||||
---
|
||||
|
||||
*For additional details, see the individual documentation files listed above.*
|
||||
289
docs/archive/MACHINE_PAGES_FIXES_SUMMARY.md
Normal file
289
docs/archive/MACHINE_PAGES_FIXES_SUMMARY.md
Normal file
@@ -0,0 +1,289 @@
|
||||
# Machine Pages Phase 2 Migration - Fixes Summary
|
||||
|
||||
**Date:** 2025-11-07
|
||||
**Status:** COMPLETE
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Successfully migrated all machine management pages from Phase 1 schema (separate `pc` and `machines` tables) to Phase 2 schema (consolidated `machines` table). These fixes serve as templates for upcoming PC page migration.
|
||||
|
||||
---
|
||||
|
||||
## Files Fixed
|
||||
|
||||
### 1. displaymachine.asp
|
||||
**Purpose:** Individual machine view page with 5 tabs
|
||||
**Status:** Working
|
||||
|
||||
**Changes:**
|
||||
- Updated SQL to query `machines` table only (equipment = `pctypeid IS NULL`)
|
||||
- Fixed column names: `vlan`, `machinedescription` → removed (don't exist)
|
||||
- Fixed column names: `notes` → `machinenotes`
|
||||
- Updated network query from `pc_network_interfaces` → `communications`
|
||||
- Fixed: `ipaddress` → `address` in communications table
|
||||
- Removed inline edit form (310 lines)
|
||||
- Added link to `machine_edit.asp`
|
||||
|
||||
### 2. machine_edit.asp (formerly editmachine.asp)
|
||||
**Purpose:** Machine edit form
|
||||
**Status:** Working
|
||||
|
||||
**Changes:**
|
||||
- Renamed from `editmachine.asp` due to IIS caching issue (HTTP 414)
|
||||
- Updated SQL to query `machines` table
|
||||
- Fixed communications query: `ipaddress` → `address`
|
||||
- Fixed compliance columns:
|
||||
- `thirdpartymanaged` → `is_third_party_managed`
|
||||
- `thirdpartyvendorid` → `third_party_manager`
|
||||
- `otassetsystem` → `ot_asset_system`
|
||||
- `dodassettype` → `ot_asset_device_type`
|
||||
- Fixed controlling PC query direction (Lines 107-118)
|
||||
- Added string conversion with `& ""` for all text fields (Lines 58, 61, 62)
|
||||
|
||||
### 3. displaymachine.asp link update
|
||||
**Change:** Updated edit link to point to `machine_edit.asp`
|
||||
|
||||
---
|
||||
|
||||
## Critical Fixes Applied
|
||||
|
||||
### Fix 1: Column Name Corrections
|
||||
**Files:** displaymachine.asp, machine_edit.asp
|
||||
|
||||
```asp
|
||||
' WRONG
|
||||
rs("ipaddress") -- communications table
|
||||
rs("notes") -- machines table
|
||||
rs("function") -- functionalaccounts table
|
||||
|
||||
' CORRECT
|
||||
rs("address") -- communications table
|
||||
rs("machinenotes") -- machines table
|
||||
rs("functionalaccount") -- functionalaccounts table
|
||||
```
|
||||
|
||||
### Fix 2: Type Conversion for HTMLEncode
|
||||
**File:** machine_edit.asp (Line 58, 61, 62)
|
||||
**Issue:** Type mismatch error when text fields contain special characters
|
||||
**Solution:** Explicitly convert to string with `& ""`
|
||||
|
||||
```asp
|
||||
' WRONG - causes Type_mismatch error
|
||||
machinenumber = rsMachine("machinenumber")
|
||||
alias = rsMachine("alias")
|
||||
machinenotes = rsMachine("machinenotes")
|
||||
|
||||
' CORRECT - explicitly convert to string
|
||||
machinenumber = "" : If NOT IsNull(rsMachine("machinenumber")) Then machinenumber = rsMachine("machinenumber") & ""
|
||||
alias = "" : If NOT IsNull(rsMachine("alias")) Then alias = rsMachine("alias") & ""
|
||||
machinenotes = "" : If NOT IsNull(rsMachine("machinenotes")) Then machinenotes = rsMachine("machinenotes") & ""
|
||||
```
|
||||
|
||||
**Example:** Machine 142 has notes with pipe characters: `Auto-discovered | Connected PCs: ... | PC Count: 1`
|
||||
|
||||
### Fix 3: Relationship Query Direction
|
||||
**File:** machine_edit.asp (Line 107-118)
|
||||
**Issue:** Controls relationship query was backwards
|
||||
**Solution:** Reverse WHERE clause for correct direction
|
||||
|
||||
```asp
|
||||
' WRONG - looks for equipment controlled BY this equipment
|
||||
WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls'
|
||||
SELECT related_machineid
|
||||
|
||||
' CORRECT - looks for PC that controls THIS equipment
|
||||
WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls'
|
||||
SELECT mr.machineid AS controlpcid
|
||||
```
|
||||
|
||||
**Relationship Direction:**
|
||||
- Controls: PC → Equipment (one-way)
|
||||
- Equipment page shows: Which PC controls me?
|
||||
- PC page shows: Which equipment do I control?
|
||||
|
||||
### Fix 4: Include ID Columns in SELECT
|
||||
**File:** displaymachine.asp (Line 79-97)
|
||||
**Issue:** Dropdowns failed because only names selected, not IDs
|
||||
**Solution:** Include all ID columns
|
||||
|
||||
```asp
|
||||
' WRONG
|
||||
SELECT vendor, modelnumber, businessunit
|
||||
|
||||
' CORRECT
|
||||
SELECT v.vendor, v.vendorid,
|
||||
mo.modelnumber, mo.modelnumberid,
|
||||
bu.businessunit, bu.businessunitid
|
||||
```
|
||||
|
||||
### Fix 5: LEFT JOIN for Optional Tables
|
||||
**Files:** displaymachine.asp, machine_edit.asp
|
||||
**Issue:** INNER JOIN fails when optional relationship is NULL
|
||||
**Solution:** Use LEFT JOIN
|
||||
|
||||
```asp
|
||||
' Required relationships (INNER JOIN)
|
||||
INNER JOIN models ON ...
|
||||
INNER JOIN vendors ON ...
|
||||
INNER JOIN businessunits ON ...
|
||||
|
||||
' Optional relationships (LEFT JOIN)
|
||||
LEFT JOIN machinetypes ON ...
|
||||
LEFT JOIN functionalaccounts ON ...
|
||||
LEFT JOIN printers ON ...
|
||||
```
|
||||
|
||||
### Fix 6: IIS Caching Workaround
|
||||
**File:** editmachine.asp → machine_edit.asp
|
||||
**Issue:** HTTP 414 "URL Too Long" error persisted after fixes
|
||||
**Solution:** Renamed file to bypass IIS cache corruption
|
||||
|
||||
---
|
||||
|
||||
## Testing Results
|
||||
|
||||
### Verified Working:
|
||||
- Machine list (displaymachines.asp)
|
||||
- Machine view (displaymachine.asp)
|
||||
- All 5 tabs load correctly
|
||||
- Network interfaces display from communications table
|
||||
- Relationships display correctly
|
||||
- Compliance data loads
|
||||
- Applications display
|
||||
- Machine edit (machine_edit.asp)
|
||||
- Form loads with all data
|
||||
- Controlling PC pre-fills correctly (verified: PC 5295 controls equipment 194)
|
||||
- Network interfaces pre-fill (up to 3)
|
||||
- Compliance data pre-fills
|
||||
- Map location selector works
|
||||
|
||||
### Test Cases Passed:
|
||||
- Machine 194: Has controlling PC relationship
|
||||
- Machine 142: Has special characters in notes (pipe |)
|
||||
- Machine 43: Standard machine
|
||||
|
||||
---
|
||||
|
||||
## Schema Reference
|
||||
|
||||
### machines Table (Consolidated)
|
||||
```sql
|
||||
-- Equipment: pctypeid IS NULL
|
||||
-- PCs: pctypeid IS NOT NULL
|
||||
|
||||
Key columns:
|
||||
- machineid (PK)
|
||||
- machinenumber (equipment number)
|
||||
- alias (friendly name)
|
||||
- hostname (for PCs)
|
||||
- serialnumber
|
||||
- machinenotes (was 'notes')
|
||||
- pctypeid (NULL = equipment, NOT NULL = PC)
|
||||
- modelnumberid (FK)
|
||||
- businessunitid (FK)
|
||||
- osid (FK)
|
||||
- printerid (FK)
|
||||
- machinestatusid (FK)
|
||||
```
|
||||
|
||||
### communications Table
|
||||
```sql
|
||||
-- Replaces: pc_network_interfaces
|
||||
|
||||
Key columns:
|
||||
- comid (PK, was interfaceid)
|
||||
- machineid (FK, was pcid)
|
||||
- address (was ipaddress) ← CRITICAL
|
||||
- macaddress
|
||||
- interfacename
|
||||
- isprimary
|
||||
- comstypeid (FK)
|
||||
```
|
||||
|
||||
### machinerelationships Table
|
||||
```sql
|
||||
-- Replaces: pc_dualpath_assignments
|
||||
|
||||
Key columns:
|
||||
- relationshipid (PK)
|
||||
- machineid (FK - first machine)
|
||||
- related_machineid (FK - second machine)
|
||||
- relationshiptypeid (FK)
|
||||
- isactive
|
||||
|
||||
Relationship Types:
|
||||
- Controls: PC → Equipment (one-way)
|
||||
- Dualpath: PC ↔ PC (bidirectional)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
### 1. Always Verify Column Names
|
||||
Check actual database schema before assuming column names. Don't trust documentation or old code.
|
||||
|
||||
**Method:**
|
||||
```sql
|
||||
DESCRIBE machines;
|
||||
DESCRIBE communications;
|
||||
DESCRIBE compliance;
|
||||
```
|
||||
|
||||
### 2. String Conversion is Critical
|
||||
All text fields passed to `Server.HTMLEncode()` must be explicitly converted to strings.
|
||||
|
||||
**Rule:** Use `& ""` for all text fields loaded from database
|
||||
|
||||
### 3. Relationship Direction Matters
|
||||
Understand one-way vs bidirectional relationships.
|
||||
|
||||
**Controls:** PC → Equipment (query differently for PC vs Equipment pages)
|
||||
**Dualpath:** PC ↔ PC (same query for both)
|
||||
|
||||
### 4. Include All Required Columns
|
||||
Don't assume `SELECT *` will work. Explicitly list all columns needed, including IDs.
|
||||
|
||||
### 5. Use LEFT JOIN for Optional Data
|
||||
Any table that might have NULL relationships should use LEFT JOIN.
|
||||
|
||||
### 6. Test with Edge Cases
|
||||
- Special characters in text fields
|
||||
- NULL values
|
||||
- Missing relationships
|
||||
- Multiple relationships
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
Use these fixes as templates for PC page migration:
|
||||
|
||||
1. **displaypcs.asp** - Mirror displaymachines.asp logic
|
||||
2. **displaypc.asp** - Mirror displaymachine.asp logic (change WHERE clause for PCs)
|
||||
3. **pc_edit.asp** - Mirror machine_edit.asp logic (reverse relationship queries)
|
||||
|
||||
**Key Difference for PC Pages:**
|
||||
- WHERE clause: `pctypeid IS NOT NULL` (instead of IS NULL)
|
||||
- Relationships: Show controlled equipment (instead of controlling PC)
|
||||
- May have PC-specific fields (pctype, etc.)
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- `/home/camp/projects/windows/shopdb/BUGFIX_2025-11-07.md` - Detailed bug fix log
|
||||
- `/home/camp/projects/windows/shopdb/PHASE2_PC_MIGRATION_TODO.md` - PC migration guide
|
||||
- `/home/camp/projects/windows/shopdb/MACHINE_MANAGEMENT_COMPLETE.md` - Original implementation
|
||||
- `/home/camp/projects/windows/shopdb/sql/migration_phase2/` - Phase 2 SQL scripts
|
||||
|
||||
---
|
||||
|
||||
**Completion Date:** 2025-11-07
|
||||
**Total Time:** ~4 hours
|
||||
**Files Modified:** 2 (displaymachine.asp, machine_edit.asp)
|
||||
**Files Created:** 1 (machine_edit.asp - renamed from editmachine.asp)
|
||||
**Database Changes:** None (query-only changes)
|
||||
**Status:** PRODUCTION READY
|
||||
337
docs/archive/MACHINE_QUICK_REFERENCE.md
Normal file
337
docs/archive/MACHINE_QUICK_REFERENCE.md
Normal file
@@ -0,0 +1,337 @@
|
||||
# Machine Management - Quick Reference Guide
|
||||
|
||||
**Last Updated:** 2025-11-07
|
||||
|
||||
---
|
||||
|
||||
## Quick Links
|
||||
|
||||
| Page | URL | Purpose |
|
||||
|------|-----|---------|
|
||||
| **View All Machines** | `displaymachines.asp` | List of all equipment (excludes PCs) |
|
||||
| **View Machine** | `displaymachine.asp?machineid=XXX` | Display single machine details |
|
||||
| **Add Machine** | `addmachine.asp` | Create new machine |
|
||||
| **Edit Machine** | `editmachine.asp?machineid=XXX` | Edit existing machine |
|
||||
|
||||
---
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
/home/camp/projects/windows/shopdb/
|
||||
├── displaymachines.asp # List all machines (equipment only, no PCs)
|
||||
├── displaymachine.asp # Display single machine (5 tabs)
|
||||
├── addmachine.asp # Add new machine form (5 tabs)
|
||||
├── editmachine.asp # Edit machine form (5 tabs)
|
||||
├── savemachine_direct.asp # Save new machine handler
|
||||
├── savemachineedit.asp # Save machine edits handler
|
||||
└── docs/
|
||||
├── MACHINE_MANAGEMENT_COMPLETE.md # Comprehensive overview
|
||||
├── MACHINE_EDIT_FORM_IMPLEMENTATION.md # Edit form details
|
||||
├── ADD_EDIT_MACHINE_UPDATES.md # Add form details
|
||||
└── DISPLAY_PAGES_UPDATE_SUMMARY.md # Display page details
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Database Tables
|
||||
|
||||
### machines
|
||||
Primary table for all equipment and PCs
|
||||
- `machineid` - Primary key
|
||||
- `machinenumber` - Equipment number (unique, required)
|
||||
- `modelnumberid` - Foreign key to models
|
||||
- `businessunitid` - Foreign key to businessunits
|
||||
- `pctypeid` - NULL for equipment, NOT NULL for PCs
|
||||
- `alias` - Friendly name
|
||||
- `machinenotes` - Notes
|
||||
- `mapleft`, `maptop` - Location coordinates
|
||||
|
||||
### communications
|
||||
Network interface data (up to 3 per machine)
|
||||
- `comid` - Primary key
|
||||
- `machineid` - Foreign key to machines
|
||||
- `address` - IP address
|
||||
- `macaddress` - MAC address
|
||||
- `interfacename` - "Interface 1", "Interface 2", "Interface 3"
|
||||
- `isprimary` - 1 for primary, 0 for secondary
|
||||
|
||||
### machinerelationships
|
||||
Relationships between machines
|
||||
- `relationshipid` - Primary key
|
||||
- `machineid` - Source machine
|
||||
- `related_machineid` - Target machine
|
||||
- `relationshiptypeid` - Foreign key to relationshiptypes
|
||||
|
||||
**Relationship Types:**
|
||||
- **Controls** (one-way): PC → Equipment
|
||||
- **Dualpath** (bidirectional): Machine ↔ Machine
|
||||
|
||||
### compliance
|
||||
Compliance and security data
|
||||
- `complianceid` - Primary key
|
||||
- `machineid` - Foreign key to machines
|
||||
- `is_third_party_managed` - ENUM('Yes', 'No', 'NA')
|
||||
- `third_party_vendorid` - Foreign key to vendors
|
||||
- `ot_asset_system` - OT classification
|
||||
- `ot_asset_device_type` - DoD classification
|
||||
|
||||
---
|
||||
|
||||
## Common Queries
|
||||
|
||||
### Get Machine with All Data
|
||||
```sql
|
||||
SELECT m.*, mo.modelnumber, v.vendor, bu.businessunit, mt.machinetype
|
||||
FROM machines m
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors v ON mo.vendorid = v.vendorid
|
||||
LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitID
|
||||
LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid
|
||||
WHERE m.machineid = ?
|
||||
```
|
||||
|
||||
### Get Network Interfaces
|
||||
```sql
|
||||
SELECT * FROM communications
|
||||
WHERE machineid = ? AND isactive = 1
|
||||
ORDER BY isprimary DESC, interfacename ASC
|
||||
```
|
||||
|
||||
### Get Controlling PC
|
||||
```sql
|
||||
SELECT m.machineid, m.hostname, c.address
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
JOIN machines m ON mr.machineid = m.machineid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1
|
||||
WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls'
|
||||
```
|
||||
|
||||
### Get Dualpath Machines
|
||||
```sql
|
||||
SELECT m.machineid, m.machinenumber, mt.machinetype, mo.modelnumber
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
JOIN machines m ON mr.related_machineid = m.machineid
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid
|
||||
WHERE mr.machineid = ? AND rt.relationshiptype = 'Dualpath'
|
||||
```
|
||||
|
||||
### Get Compliance Data
|
||||
```sql
|
||||
SELECT c.*, v.vendor AS third_party_vendor_name
|
||||
FROM compliance c
|
||||
LEFT JOIN vendors v ON c.third_party_vendorid = v.vendorid
|
||||
WHERE c.machineid = ?
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Form Field Reference
|
||||
|
||||
### Basic Info Tab
|
||||
- `machinenumber` - Equipment number (required, unique, readonly on edit)
|
||||
- `modelid` - Model dropdown (required)
|
||||
- `businessunitid` - Business unit dropdown (required)
|
||||
- `alias` - Friendly name (optional)
|
||||
- `machinenotes` - Notes (optional)
|
||||
|
||||
### Network Tab
|
||||
- `ip1`, `mac1` - Primary interface (Interface 1)
|
||||
- `ip2`, `mac2` - Optional interface (Interface 2)
|
||||
- `ip3`, `mac3` - Optional interface (Interface 3)
|
||||
|
||||
### Relationships Tab
|
||||
- `controllingpc` - PC dropdown (WHERE pctypeid IS NOT NULL)
|
||||
- `dualpathid` - Machine dropdown (WHERE pctypeid IS NULL)
|
||||
|
||||
### Compliance Tab
|
||||
- `thirdpartymanaged` - Dropdown (N/A, Yes, No)
|
||||
- `thirdpartyvendorid` - Vendor dropdown
|
||||
- `otassetsystem` - Text input (100 chars)
|
||||
- `dodassettype` - Text input (100 chars)
|
||||
|
||||
### Location Tab
|
||||
- `mapleft` - X coordinate (from map picker)
|
||||
- `maptop` - Y coordinate (from map picker)
|
||||
|
||||
---
|
||||
|
||||
## Code Patterns
|
||||
|
||||
### Parameterized Query Example
|
||||
```asp
|
||||
Dim strSQL, rsResult
|
||||
strSQL = "SELECT * FROM machines WHERE machineid = ?"
|
||||
Set rsResult = ExecuteParameterizedQuery(objConn, strSQL, Array(machineid))
|
||||
If Not rsResult.EOF Then
|
||||
' Process results
|
||||
End If
|
||||
rsResult.Close
|
||||
Set rsResult = Nothing
|
||||
```
|
||||
|
||||
### HTML Encoding Pattern
|
||||
```asp
|
||||
Response.Write("<td>" & Server.HTMLEncode(rsData("fieldname") & "") & "</td>")
|
||||
```
|
||||
|
||||
### NULL Handling Pattern
|
||||
```asp
|
||||
' Force to string to prevent NULL errors
|
||||
Dim displayValue
|
||||
displayValue = rsData("fieldname") & "" ' Converts NULL to empty string
|
||||
|
||||
' Use IIf for database inserts
|
||||
cmd.Parameters.Append cmd.CreateParameter("@param", 200, 1, 50, IIf(value <> "", value, Null))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Common Tasks
|
||||
|
||||
### Adding a New Machine
|
||||
1. Navigate to `addmachine.asp`
|
||||
2. Fill Basic Info tab (machine number, model, business unit)
|
||||
3. Fill Network tab (at least one IP/MAC)
|
||||
4. Select relationships (optional)
|
||||
5. Fill compliance data (optional)
|
||||
6. Click map to set location (optional)
|
||||
7. Click "Add Equipment"
|
||||
|
||||
### Editing a Machine
|
||||
1. Navigate to `displaymachine.asp?machineid=XXX`
|
||||
2. Click "Edit Machine" button
|
||||
3. Update any tab
|
||||
4. Click "Update Equipment"
|
||||
|
||||
### Viewing Machine Relationships
|
||||
1. Navigate to `displaymachine.asp?machineid=XXX`
|
||||
2. Click "Relationships" tab
|
||||
3. See three sections:
|
||||
- Controls (PC that controls this)
|
||||
- Controlled By This PC (if it's a PC)
|
||||
- Dualpath (redundant machines)
|
||||
|
||||
### Viewing Network Interfaces
|
||||
1. Navigate to `displaymachine.asp?machineid=XXX`
|
||||
2. Click "Network" tab
|
||||
3. See all interfaces in table format
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Machine redirects to homepage
|
||||
**Cause:** NULL machinetypeid in model
|
||||
**Fix:** Use LEFT JOIN instead of INNER JOIN for machinetypes
|
||||
|
||||
### Edit button doesn't work
|
||||
**Cause:** Invalid machineid or file doesn't exist
|
||||
**Fix:** Check URL parameter, verify editmachine.asp exists
|
||||
|
||||
### Data doesn't save
|
||||
**Cause:** Validation error or database connection issue
|
||||
**Fix:** Check error message, review logs in `/home/camp/projects/windows/logs/`
|
||||
|
||||
### Map doesn't load
|
||||
**Cause:** Missing Leaflet.js or map images
|
||||
**Fix:** Verify leaflet.js, sitemap2025-dark.png, sitemap2025-light.png exist
|
||||
|
||||
### "New" button doesn't work
|
||||
**Cause:** JavaScript event handler issue
|
||||
**Fix:** Check browser console for errors, verify jQuery loaded
|
||||
|
||||
### Relationships not saving
|
||||
**Cause:** Relationship types don't exist or invalid machine IDs
|
||||
**Fix:** Verify relationshiptypes table has 'Controls' and 'Dualpath'
|
||||
|
||||
---
|
||||
|
||||
## Security Checklist
|
||||
|
||||
- All queries use parameterized commands
|
||||
- All output uses Server.HTMLEncode()
|
||||
- All numeric inputs validated with IsNumeric()
|
||||
- All string inputs have length limits
|
||||
- NULL values handled properly
|
||||
- No direct variable interpolation in SQL
|
||||
- Error messages don't expose sensitive data
|
||||
- Database connections always closed
|
||||
|
||||
---
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
**Display Page:**
|
||||
- [ ] View machine with full data
|
||||
- [ ] View machine with no network interfaces
|
||||
- [ ] View machine with no relationships
|
||||
- [ ] Click "Edit Machine" button
|
||||
- [ ] Click related machine links
|
||||
|
||||
**Add Form:**
|
||||
- [ ] Add machine with all fields
|
||||
- [ ] Add machine with only required fields
|
||||
- [ ] Test IP/MAC validation
|
||||
- [ ] Create new model
|
||||
- [ ] Create new vendor
|
||||
- [ ] Use map picker
|
||||
|
||||
**Edit Form:**
|
||||
- [ ] Edit basic info
|
||||
- [ ] Add/remove network interfaces
|
||||
- [ ] Change controlling PC
|
||||
- [ ] Change dualpath machine
|
||||
- [ ] Update compliance data
|
||||
- [ ] Move location on map
|
||||
|
||||
---
|
||||
|
||||
## Quick Command Reference
|
||||
|
||||
### View Logs
|
||||
```bash
|
||||
tail -f /home/camp/projects/windows/logs/*.log
|
||||
```
|
||||
|
||||
### Check Database
|
||||
```bash
|
||||
mysql -u root -p shopdb -e "SELECT COUNT(*) FROM machines WHERE pctypeid IS NULL"
|
||||
mysql -u root -p shopdb -e "SELECT COUNT(*) FROM communications"
|
||||
mysql -u root -p shopdb -e "SELECT COUNT(*) FROM machinerelationships"
|
||||
```
|
||||
|
||||
### Find Machine by Number
|
||||
```sql
|
||||
SELECT machineid FROM machines WHERE machinenumber = '4500'
|
||||
```
|
||||
|
||||
### List All Relationships
|
||||
```sql
|
||||
SELECT m1.machinenumber AS source, m2.machinenumber AS target, rt.relationshiptype
|
||||
FROM machinerelationships mr
|
||||
JOIN machines m1 ON mr.machineid = m1.machineid
|
||||
JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE mr.isactive = 1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Support Resources
|
||||
|
||||
- **Full Documentation:** `MACHINE_MANAGEMENT_COMPLETE.md`
|
||||
- **Edit Form Details:** `MACHINE_EDIT_FORM_IMPLEMENTATION.md`
|
||||
- **Add Form Details:** `ADD_EDIT_MACHINE_UPDATES.md`
|
||||
- **Display Page Details:** `DISPLAY_PAGES_UPDATE_SUMMARY.md`
|
||||
- **Migration Scripts:** `/home/camp/projects/windows/shopdb/sql/migration_phase2/`
|
||||
- **Import Logs:** `/tmp/inventory_import_final.log`
|
||||
|
||||
---
|
||||
|
||||
**Last Updated:** 2025-11-07
|
||||
**Version:** 1.0
|
||||
**Status:** Production Ready
|
||||
721
docs/archive/PHASE2_DEV_MIGRATION_NOTES.md
Normal file
721
docs/archive/PHASE2_DEV_MIGRATION_NOTES.md
Normal file
@@ -0,0 +1,721 @@
|
||||
# Phase 2 PC Migration - DEV Server Actual Execution Notes
|
||||
|
||||
**Environment:** Development Server (IIS Express on Windows 11 VM + MySQL 5.6 in Docker)
|
||||
**Date Executed:** November 13, 2025
|
||||
**Status:** COMPLETE
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
Phase 2 PC Migration was successfully completed on the DEV server. This document records the **actual steps taken**, including manual interventions required beyond the original migration scripts.
|
||||
|
||||
**Key Results:**
|
||||
- 224 PCs migrated from `pc` table → `machines` table
|
||||
- 705 network interfaces migrated to `communications` table
|
||||
- 221 PC-to-machine ID mappings created
|
||||
- 11 ASP page files updated to use Phase 2 schema
|
||||
- All PC functionality verified working
|
||||
|
||||
---
|
||||
|
||||
## Pre-Migration State
|
||||
|
||||
### Database Schema Issues Found
|
||||
|
||||
The dev database was in an incomplete state:
|
||||
- `communications` table existed but was **EMPTY** (0 records)
|
||||
- `machines` table **MISSING** critical PC-related columns:
|
||||
- `pctypeid` column did not exist
|
||||
- `loggedinuser` column did not exist
|
||||
- `machinestatusid` column did not exist
|
||||
- `lastupdated` column did not exist
|
||||
- 276 PCs still in old `pc` table
|
||||
- Phase 1 scripts had been partially run but not completed
|
||||
|
||||
### ASP Page Status
|
||||
|
||||
Many PC pages had already been updated to expect Phase 2 schema:
|
||||
- `displaypcs.asp` - Already querying `machines WHERE pctypeid IS NOT NULL`
|
||||
- `displaypc.asp` - Already using Phase 2 schema
|
||||
- `editpc.asp` - Already using Phase 2 schema
|
||||
- But database didn't match the code expectations!
|
||||
|
||||
---
|
||||
|
||||
## Migration Steps Actually Performed
|
||||
|
||||
### Step 1: Add Missing Columns to machines Table
|
||||
|
||||
**Issue:** Phase 2 migration script expected these columns to exist, but they didn't.
|
||||
|
||||
**Manual SQL executed:**
|
||||
|
||||
```sql
|
||||
-- Add pctypeid column (critical for identifying PCs vs equipment)
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN pctypeid INT(11) AFTER machinetypeid;
|
||||
|
||||
-- Add loggedinuser column
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN loggedinuser VARCHAR(100) AFTER hostname;
|
||||
|
||||
-- Add machinestatusid column
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN machinestatusid INT(11) AFTER osid;
|
||||
|
||||
-- Add lastupdated column (replaces dateadded)
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN lastupdated DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
|
||||
```
|
||||
|
||||
**Note:** User explicitly requested NOT to add `dateadded` column, only `lastupdated`.
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
DESCRIBE machines;
|
||||
-- Confirmed all 4 columns added successfully
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 2: Run Phase 1 Infrastructure Scripts
|
||||
|
||||
Since Phase 1 was incomplete, ran these scripts:
|
||||
|
||||
```bash
|
||||
cd /home/camp/projects/windows/shopdb/sql/migration_phase1/
|
||||
|
||||
# Create communications infrastructure
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 01_create_communications_infrastructure.sql
|
||||
|
||||
# Create PC machine types (28-32)
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 03_create_pc_machine_types.sql
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- `comstypes` table: 8 communication types created
|
||||
- `communications` table: Structure created (still empty)
|
||||
- PC machine types 28-32 created in `machinetypes` table
|
||||
|
||||
---
|
||||
|
||||
### Step 3: Run Phase 2 PC Migration Script
|
||||
|
||||
```bash
|
||||
cd /home/camp/projects/windows/shopdb/sql/migration_phase2/
|
||||
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 01_migrate_pcs_to_machines.sql
|
||||
```
|
||||
|
||||
**Error Encountered:**
|
||||
```
|
||||
Unknown column 'pctypeid' in 'where clause'
|
||||
Unknown column 'lastupdated' in 'field list'
|
||||
```
|
||||
|
||||
**Resolution:** Already fixed in Step 1 (added missing columns). Re-ran script successfully.
|
||||
|
||||
**Results:**
|
||||
- 224 PCs migrated from `pc` → `machines`
|
||||
- All PCs now have `pctypeid IS NOT NULL`
|
||||
- `pc_to_machine_id_mapping` table created (but was EMPTY!)
|
||||
|
||||
---
|
||||
|
||||
### Step 4: Fix Empty Mapping Table
|
||||
|
||||
**Issue:** Script created `pc_to_machine_id_mapping` table but it had 0 records!
|
||||
|
||||
**Root Cause:** Migration script Step 7 tried to insert mappings but failed silently due to duplicate hostnames.
|
||||
|
||||
**Manual Fix:**
|
||||
|
||||
```sql
|
||||
-- Populate mapping table (handles duplicates with MIN)
|
||||
INSERT INTO pc_to_machine_id_mapping (pcid, old_hostname, new_machineid, new_machinenumber)
|
||||
SELECT p.pcid,
|
||||
p.hostname,
|
||||
MIN(m.machineid) AS new_machineid,
|
||||
MIN(m.machinenumber) AS new_machinenumber
|
||||
FROM pc p
|
||||
JOIN machines m ON m.hostname = p.hostname
|
||||
WHERE p.isactive = 1 AND m.pctypeid IS NOT NULL
|
||||
GROUP BY p.pcid, p.hostname;
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- 221 mappings created (out of 224 PCs)
|
||||
- 3 PCs couldn't be mapped (duplicate hostname issue: pcid 59 & 164 both had "G5G9S624ESF")
|
||||
- Used `MIN(machineid)` to select first match for duplicates
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM pc_to_machine_id_mapping;
|
||||
-- Result: 221 rows
|
||||
|
||||
SELECT COUNT(*) FROM machines WHERE pctypeid IS NOT NULL;
|
||||
-- Result: 224 rows
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 5: Migrate Network Interfaces
|
||||
|
||||
```bash
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 02_migrate_network_interfaces_to_communications.sql
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- 705 network interfaces migrated to `communications` table
|
||||
- Used `pc_to_machine_id_mapping` to link old pcid to new machineid
|
||||
- `comstypeid` set to 1 (Network_Interface type)
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM communications WHERE comstypeid = 1;
|
||||
-- Result: 705 rows
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 5.5: Migrate PC-to-Machine Relationships
|
||||
|
||||
**Issue:** The `machinerelationships` table was empty. Phase 2 script 05 (dualpath) wasn't sufficient.
|
||||
|
||||
**Discovery:** The old `pc` table has a `machinenumber` column that stores which equipment each PC controls!
|
||||
|
||||
**Manual SQL executed:**
|
||||
|
||||
```sql
|
||||
-- Create Controls relationships from old pc.machinenumber
|
||||
INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive)
|
||||
SELECT DISTINCT
|
||||
equipment.machineid AS equipment_machineid,
|
||||
pc_migrated.machineid AS pc_machineid,
|
||||
3 AS relationshiptypeid, -- 'Controls' relationship
|
||||
1 AS isactive
|
||||
FROM pc old_pc
|
||||
JOIN machines equipment ON equipment.machinenumber = old_pc.machinenumber
|
||||
JOIN machines pc_migrated ON pc_migrated.hostname = old_pc.hostname
|
||||
WHERE old_pc.isactive = 1
|
||||
AND old_pc.machinenumber IS NOT NULL
|
||||
AND old_pc.machinenumber != ''
|
||||
AND equipment.pctypeid IS NULL -- Equipment only
|
||||
AND pc_migrated.pctypeid IS NOT NULL -- PCs only
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships mr
|
||||
WHERE mr.machineid = equipment.machineid
|
||||
AND mr.related_machineid = pc_migrated.machineid
|
||||
AND mr.relationshiptypeid = 3
|
||||
);
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- 142 PC-to-equipment "Controls" relationships created
|
||||
- Plus 6 from hostname matching = **148 total relationships**
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM machinerelationships;
|
||||
-- Result: 148 rows
|
||||
|
||||
-- Example: Machine 130 controlled by PC 390
|
||||
SELECT
|
||||
equipment.machinenumber AS equipment,
|
||||
pc.hostname AS controlling_pc
|
||||
FROM machinerelationships mr
|
||||
JOIN machines equipment ON mr.machineid = equipment.machineid
|
||||
JOIN machines pc ON mr.related_machineid = pc.machineid
|
||||
WHERE equipment.machineid = 130;
|
||||
-- Result: 2001 | GB07T5X3ESF
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 5.6: Migrate Dualpath Relationships
|
||||
|
||||
**Date:** November 13, 2025
|
||||
|
||||
**Issue:** The `machinerelationships` table had 0 dualpath relationships, but `pc_dualpath_assignments` table contained 33 dualpath assignments.
|
||||
|
||||
**Script Used:**
|
||||
```bash
|
||||
mysql -u570005354 -p shopdb < sql/migration_phase2/05_migrate_dualpath_assignments.sql
|
||||
```
|
||||
|
||||
**What the script does:**
|
||||
- Reads `pc_dualpath_assignments` table (33 dualpath pairs)
|
||||
- Creates bidirectional relationships in `machinerelationships`:
|
||||
- primary_machine → secondary_machine (relationshiptypeid = 1)
|
||||
- secondary_machine → primary_machine (relationshiptypeid = 1)
|
||||
- Uses `pc_to_machine_id_mapping` to link old pcid to new machineid
|
||||
|
||||
**Results:**
|
||||
- 31 dualpath relationships created (direction 1)
|
||||
- 31 dualpath relationships created (direction 2)
|
||||
- **Total: 62 dualpath relationships** (31 pairs)
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT rt.relationshiptype, COUNT(*) as count
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE mr.isactive = 1
|
||||
GROUP BY rt.relationshiptype;
|
||||
-- Result: Controls: 148, Dualpath: 62
|
||||
|
||||
-- Example dualpath pair: Machines 2003 and 2004
|
||||
SELECT m1.machinenumber, m2.machinenumber, rt.relationshiptype
|
||||
FROM machinerelationships mr
|
||||
JOIN machines m1 ON mr.machineid = m1.machineid
|
||||
JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE m1.machinenumber IN ('2003', '2004') AND rt.relationshiptype = 'Dualpath';
|
||||
-- Result shows bidirectional: 2003→2004 and 2004→2003
|
||||
```
|
||||
|
||||
**Note:** Backup created in `pc_dualpath_assignments_backup_phase2` table.
|
||||
|
||||
---
|
||||
|
||||
### Step 6: Update ASP Pages
|
||||
|
||||
**Files Still Using Old `pc` Table:**
|
||||
|
||||
Found 7 files that still referenced the old `pc` table and needed updating:
|
||||
|
||||
#### 6.1 Warranty Checking Files (3 files)
|
||||
|
||||
**Files Updated:**
|
||||
- `check_all_warranties.asp`
|
||||
- `check_all_warranties_clean.asp`
|
||||
- `check_warranties_v2.asp`
|
||||
|
||||
**Changes Made:**
|
||||
```asp
|
||||
' OLD: Query pc table
|
||||
SELECT pcid, hostname, serialnumber FROM pc WHERE isactive = 1
|
||||
|
||||
' NEW: Query machines table with pctypeid filter
|
||||
SELECT machineid, hostname, serialnumber FROM machines
|
||||
WHERE pctypeid IS NOT NULL AND isactive = 1
|
||||
|
||||
' OLD: Update warranty in pc table
|
||||
UPDATE pc SET warrantyenddate = ?, warrantyservicelevel = ? WHERE pcid = ?
|
||||
|
||||
' NEW: Insert into warranties table
|
||||
INSERT INTO warranties (machineid, enddate, servicelevel, lastcheckeddate)
|
||||
VALUES (?, ?, ?, NOW())
|
||||
ON DUPLICATE KEY UPDATE enddate = VALUES(enddate), servicelevel = VALUES(servicelevel)
|
||||
```
|
||||
|
||||
#### 6.2 Device Management Files (4 files)
|
||||
|
||||
**Files Updated:**
|
||||
- `editdevice.asp`
|
||||
- `savedevice.asp`
|
||||
- `savedevice_direct.asp`
|
||||
- `updatepc_direct.asp`
|
||||
|
||||
**Changes Made:**
|
||||
```asp
|
||||
' OLD: Check if device exists in pc table
|
||||
SELECT COUNT(*) FROM pc WHERE pcid = ?
|
||||
|
||||
' NEW: Check if device exists in machines table
|
||||
SELECT COUNT(*) FROM machines WHERE machineid = ? AND pctypeid IS NOT NULL
|
||||
|
||||
' OLD: Insert into pc table
|
||||
INSERT INTO pc (serialnumber, ...) VALUES (?, ...)
|
||||
|
||||
' NEW: Insert into machines table with pctypeid
|
||||
INSERT INTO machines (serialnumber, pctypeid, machinetypeid, ...)
|
||||
VALUES (?, 1, 28, ...)
|
||||
|
||||
' OLD: Update pc table
|
||||
UPDATE pc SET ... WHERE pcid = ?
|
||||
|
||||
' NEW: Update machines table
|
||||
UPDATE machines SET ... WHERE machineid = ? AND pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
**Key Pattern:** All queries now filter with `pctypeid IS NOT NULL` to distinguish PCs from equipment.
|
||||
|
||||
---
|
||||
|
||||
### Step 7: Fix Additional Pages
|
||||
|
||||
**Files with Other Issues Found:**
|
||||
|
||||
#### 7.1 displaypcs.asp
|
||||
**Issue:** Referenced non-existent `dateadded` column
|
||||
**Fix:** Changed to `lastupdated`
|
||||
```asp
|
||||
' OLD: SELECT machines.dateadded
|
||||
' NEW: SELECT machines.lastupdated
|
||||
```
|
||||
|
||||
#### 7.2 displaypc.asp
|
||||
**Issue:** Referenced non-existent `dateadded` column
|
||||
**Fix:** Removed from SELECT query entirely (not displayed)
|
||||
|
||||
#### 7.3 displaymachine.asp
|
||||
**Issue:** Referenced non-existent `dateadded` column
|
||||
**Fix:** Removed from SELECT query
|
||||
```asp
|
||||
' OLD: "machines.lastupdated, machines.dateadded, " & _
|
||||
' NEW: "machines.lastupdated, " & _
|
||||
```
|
||||
|
||||
#### 7.4 displaysubnet.asp
|
||||
**Issue:** Queried old `pc_network_interfaces` table
|
||||
**Fix:** Changed to query `communications` table
|
||||
```asp
|
||||
' OLD: SELECT pcid FROM pc_network_interfaces WHERE ipaddress = ?
|
||||
' NEW: SELECT c.machineid FROM communications c
|
||||
' JOIN machines m ON c.machineid = m.machineid
|
||||
' WHERE c.address = ? AND m.pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
#### 7.5 network_map.asp
|
||||
**Issue:** Expected Phase 3 network devices (not yet migrated)
|
||||
**Fix:** Removed broken UNION query for network devices, kept only printers
|
||||
```asp
|
||||
' Removed: UNION query for network devices from machines table
|
||||
' Kept: SELECT from printers table (37 printers)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files Modified Summary
|
||||
|
||||
### Total Files Updated: 11
|
||||
|
||||
| File | Type | Changes |
|
||||
|------|------|---------|
|
||||
| check_all_warranties.asp | Utility | machines table, warranties table |
|
||||
| check_all_warranties_clean.asp | Utility | machines table, warranties table |
|
||||
| check_warranties_v2.asp | Utility | machines table, warranties table |
|
||||
| editdevice.asp | Form | machines table queries |
|
||||
| savedevice.asp | Processor | machines table INSERT |
|
||||
| savedevice_direct.asp | Processor | machines table INSERT |
|
||||
| updatepc_direct.asp | Processor | machines table UPDATE |
|
||||
| displaypcs.asp | Display | dateadded → lastupdated |
|
||||
| displaypc.asp | Display | dateadded removed |
|
||||
| displaymachine.asp | Display | dateadded removed |
|
||||
| displaysubnet.asp | Utility | communications table |
|
||||
| network_map.asp | Display | Phase 3 query removed |
|
||||
|
||||
---
|
||||
|
||||
## Manual Database Changes Summary
|
||||
|
||||
### Tables Created
|
||||
- `pc_to_machine_id_mapping` (221 records)
|
||||
|
||||
### Tables Populated
|
||||
- `machines` (+224 PC records)
|
||||
- `communications` (+705 network interface records)
|
||||
- `comstypes` (8 communication types)
|
||||
- `machinetypes` (+5 PC types: 28-32)
|
||||
|
||||
### Columns Added to machines Table
|
||||
```sql
|
||||
ALTER TABLE machines ADD COLUMN pctypeid INT(11);
|
||||
ALTER TABLE machines ADD COLUMN loggedinuser VARCHAR(100);
|
||||
ALTER TABLE machines ADD COLUMN machinestatusid INT(11);
|
||||
ALTER TABLE machines ADD COLUMN lastupdated DATETIME;
|
||||
```
|
||||
|
||||
### Columns NOT Added (User Decision)
|
||||
- `dateadded` - User requested NOT to add this column
|
||||
|
||||
---
|
||||
|
||||
## Verification Results
|
||||
|
||||
### Database Verification
|
||||
|
||||
```sql
|
||||
-- PCs in machines table
|
||||
SELECT COUNT(*) FROM machines WHERE pctypeid IS NOT NULL;
|
||||
-- Result: 224 PCs
|
||||
|
||||
-- Network interfaces in communications
|
||||
SELECT COUNT(*) FROM communications WHERE comstypeid = 1;
|
||||
-- Result: 705 interfaces
|
||||
|
||||
-- PC-to-machine mappings
|
||||
SELECT COUNT(*) FROM pc_to_machine_id_mapping;
|
||||
-- Result: 221 mappings
|
||||
|
||||
-- Old pc table (should still have records - not deleted)
|
||||
SELECT COUNT(*) FROM pc WHERE isactive = 1;
|
||||
-- Result: 276 PCs (preserved as backup)
|
||||
```
|
||||
|
||||
### Page Verification (from logs)
|
||||
|
||||
All pages tested and working:
|
||||
- displaypcs.asp - HTTP 200 (18:52:35)
|
||||
- displaypc.asp - HTTP 200 (18:52:42)
|
||||
- displaymachines.asp - HTTP 200 (18:32:48)
|
||||
- displaymachine.asp - HTTP 200 (after dateadded fix)
|
||||
- network_map.asp - HTTP 200 (17:57:57)
|
||||
|
||||
---
|
||||
|
||||
## Issues Encountered and Resolutions
|
||||
|
||||
### Issue 1: Missing pctypeid Column
|
||||
**Error:** `Unknown column 'machines.pctypeid' in 'where clause'`
|
||||
**Resolution:** Added column manually with `ALTER TABLE`
|
||||
**Root Cause:** Phase 1 script 02_extend_machines_table.sql not run on dev
|
||||
|
||||
### Issue 2: Missing dateadded Column References
|
||||
**Error:** `Unknown column 'machines.dateadded' in 'field list'`
|
||||
**Resolution:** Changed all references to `lastupdated` or removed
|
||||
**Root Cause:** User decided not to add dateadded column, only lastupdated
|
||||
|
||||
### Issue 3: Empty Mapping Table
|
||||
**Error:** Network interface migration found 0 mappings
|
||||
**Resolution:** Manually populated pc_to_machine_id_mapping table
|
||||
**Root Cause:** Duplicate hostnames prevented automatic mapping
|
||||
|
||||
### Issue 4: Duplicate Hostnames
|
||||
**Error:** pcid 59 and 164 both had hostname "G5G9S624ESF"
|
||||
**Resolution:** Used MIN(machineid) to select first match
|
||||
**Impact:** 3 PCs unmapped (224 migrated but only 221 mapped)
|
||||
|
||||
---
|
||||
|
||||
## Production Migration Recommendations
|
||||
|
||||
### Before Running on Production:
|
||||
|
||||
1. **Update Phase 1 Script 02:**
|
||||
- Ensure `02_extend_machines_table.sql` adds these columns:
|
||||
- pctypeid
|
||||
- loggedinuser
|
||||
- machinestatusid
|
||||
- lastupdated (NOT dateadded)
|
||||
|
||||
2. **Update Phase 2 Script 01:**
|
||||
- Add validation check for duplicate hostnames
|
||||
- Add error handling for mapping table population
|
||||
- Consider adding UNIQUE constraint on hostname (if business rules allow)
|
||||
|
||||
3. **Pre-Migration Validation:**
|
||||
```sql
|
||||
-- Check for duplicate hostnames
|
||||
SELECT hostname, COUNT(*)
|
||||
FROM pc
|
||||
WHERE isactive = 1
|
||||
GROUP BY hostname
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
-- Should return 0 rows, or document exceptions
|
||||
```
|
||||
|
||||
4. **Update All 11 ASP Files** on production:
|
||||
- Use the updated versions from dev
|
||||
- Test each file after deployment
|
||||
- Monitor logs for errors
|
||||
|
||||
5. **Plan for Rollback:**
|
||||
- Keep `pc` and `pc_network_interfaces` tables for 30 days
|
||||
- Take full database backup before migration
|
||||
- Document rollback procedure
|
||||
|
||||
---
|
||||
|
||||
## Scripts That Need Updates for Production
|
||||
|
||||
### /sql/migration_phase1/02_extend_machines_table.sql
|
||||
|
||||
**Add these columns:**
|
||||
```sql
|
||||
-- Add PC-specific columns
|
||||
ALTER TABLE machines ADD COLUMN pctypeid INT(11) AFTER machinetypeid;
|
||||
ALTER TABLE machines ADD COLUMN loggedinuser VARCHAR(100) AFTER hostname;
|
||||
ALTER TABLE machines ADD COLUMN machinestatusid INT(11) AFTER osid;
|
||||
ALTER TABLE machines ADD COLUMN lastupdated DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
ON UPDATE CURRENT_TIMESTAMP;
|
||||
|
||||
-- Add indexes for performance
|
||||
ALTER TABLE machines ADD INDEX idx_pctypeid (pctypeid);
|
||||
ALTER TABLE machines ADD INDEX idx_machinestatusid (machinestatusid);
|
||||
```
|
||||
|
||||
### NEW: /sql/migration_phase2/05b_migrate_pc_controls_relationships.sql
|
||||
|
||||
**Create this new script to migrate PC-to-equipment relationships:**
|
||||
|
||||
```sql
|
||||
-- =====================================================
|
||||
-- SCRIPT 05b: Migrate PC Controls Relationships
|
||||
-- =====================================================
|
||||
-- Purpose: Create Controls relationships from pc.machinenumber
|
||||
-- =====================================================
|
||||
|
||||
USE shopdb;
|
||||
|
||||
-- Create Controls relationships
|
||||
INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive)
|
||||
SELECT DISTINCT
|
||||
equipment.machineid AS equipment_machineid,
|
||||
pc_migrated.machineid AS pc_machineid,
|
||||
3 AS relationshiptypeid, -- 'Controls' relationship
|
||||
1 AS isactive
|
||||
FROM pc old_pc
|
||||
JOIN machines equipment ON equipment.machinenumber = old_pc.machinenumber
|
||||
JOIN machines pc_migrated ON pc_migrated.hostname = old_pc.hostname
|
||||
WHERE old_pc.isactive = 1
|
||||
AND old_pc.machinenumber IS NOT NULL
|
||||
AND old_pc.machinenumber != ''
|
||||
AND equipment.pctypeid IS NULL -- Equipment only
|
||||
AND pc_migrated.pctypeid IS NOT NULL -- PCs only
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships mr
|
||||
WHERE mr.machineid = equipment.machineid
|
||||
AND mr.related_machineid = pc_migrated.machineid
|
||||
AND mr.relationshiptypeid = 3
|
||||
);
|
||||
|
||||
-- Verification
|
||||
SELECT CONCAT('Created ', ROW_COUNT(), ' Controls relationships') AS result;
|
||||
|
||||
SELECT COUNT(*) AS total_relationships FROM machinerelationships;
|
||||
```
|
||||
|
||||
**This script should be run AFTER 01_migrate_pcs_to_machines.sql**
|
||||
|
||||
### /sql/migration_phase2/01_migrate_pcs_to_machines.sql
|
||||
|
||||
**Fix Step 7 - Mapping Table Population:**
|
||||
```sql
|
||||
-- Enhanced mapping with duplicate handling
|
||||
INSERT INTO pc_to_machine_id_mapping (pcid, old_hostname, new_machineid, new_machinenumber)
|
||||
SELECT p.pcid,
|
||||
p.hostname,
|
||||
MIN(m.machineid) AS new_machineid, -- Handle duplicates
|
||||
MIN(m.machinenumber) AS new_machinenumber
|
||||
FROM pc p
|
||||
JOIN machines m ON m.hostname = p.hostname
|
||||
WHERE p.isactive = 1
|
||||
AND m.pctypeid IS NOT NULL
|
||||
GROUP BY p.pcid, p.hostname;
|
||||
|
||||
-- Validate mapping
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM pc WHERE isactive = 1) AS pcs_to_migrate,
|
||||
(SELECT COUNT(*) FROM pc_to_machine_id_mapping) AS pcs_mapped,
|
||||
(SELECT COUNT(*) FROM pc WHERE isactive = 1) -
|
||||
(SELECT COUNT(*) FROM pc_to_machine_id_mapping) AS unmapped_count;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Timeline - Actual
|
||||
|
||||
| Phase | Estimated | Actual | Notes |
|
||||
|-------|-----------|--------|-------|
|
||||
| Pre-migration analysis | 1 hour | 1.5 hours | Found schema discrepancies |
|
||||
| Add missing columns | 5 min | 15 min | Manual ALTER TABLE statements |
|
||||
| Run Phase 1 scripts | 5 min | 10 min | Partial re-run required |
|
||||
| Run Phase 2 script 01 | 10 min | 20 min | Mapping table fix required |
|
||||
| Run Phase 2 script 02 | 5 min | 5 min | Successful |
|
||||
| Update ASP pages | 2 hours | 3 hours | Found 7 additional files |
|
||||
| Testing and fixes | 1 hour | 1.5 hours | Fixed dateadded issues |
|
||||
| **Total** | **4-5 hours** | **~7 hours** | Manual interventions added time |
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria - All Met
|
||||
|
||||
- All 224 PCs migrated to machines table
|
||||
- All 705 network interfaces in communications table
|
||||
- PC list page displays correctly
|
||||
- Individual PC pages load without errors
|
||||
- Network interfaces show properly (IP and MAC addresses)
|
||||
- No "Item cannot be found" errors
|
||||
- All functionality matches machine pages
|
||||
- Security maintained (parameterized queries)
|
||||
- No data loss
|
||||
- Old tables preserved as backup
|
||||
|
||||
---
|
||||
|
||||
## Step 8: Cleanup Migration Tables
|
||||
|
||||
**Date:** November 13, 2025
|
||||
|
||||
**Purpose:** Remove unused backup and mapping tables to clean up database after successful migration.
|
||||
|
||||
**Script Used:**
|
||||
```bash
|
||||
mysql -u570005354 -p shopdb < sql/migration_phase2/07_cleanup_migration_tables.sql
|
||||
```
|
||||
|
||||
**Tables Dropped:**
|
||||
|
||||
1. **Backup Tables** (created during migration for rollback):
|
||||
- `pc_backup_phase2` (276 rows, 0.08 MB)
|
||||
- `pc_network_interfaces_backup_phase2` (705 rows, 0.08 MB)
|
||||
- `pc_comm_config_backup_phase2` (502 rows, 0.34 MB)
|
||||
- `pc_dualpath_assignments_backup_phase2` (33 rows, 0.02 MB)
|
||||
- `pc_model_backup` (206 rows, 0.02 MB)
|
||||
|
||||
2. **Helper/Mapping Tables** (no longer needed):
|
||||
- `pc_to_machine_id_mapping` (221 rows, 0.03 MB) - Used during migration to track old pcid → new machineid
|
||||
- `machine_pc_relationships` (0 rows, 0.06 MB) - Never used, replaced by `machinerelationships`
|
||||
|
||||
**Total Space Freed:** ~0.63 MB
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
-- Confirmed essential tables still exist
|
||||
SELECT COUNT(*) FROM machines; -- 483 records (224 PCs + 259 equipment)
|
||||
SELECT COUNT(*) FROM communications; -- 705 records
|
||||
SELECT COUNT(*) FROM machinerelationships; -- 210 records (148 Controls + 62 Dualpath)
|
||||
```
|
||||
|
||||
**Tables Retained** (may still have historical value):
|
||||
- `pc` - Original PC table (kept for historical queries if needed)
|
||||
- `pc_network_interfaces` - Old network config
|
||||
- `pc_comm_config` - Old communication config
|
||||
- `pc_dualpath_assignments` - Old dualpath data
|
||||
- `pc_dnc_config` - DNC configuration (still in use)
|
||||
- `pctype` - PC type reference table (still in use)
|
||||
|
||||
**Note:** The old `pc` and related tables can be dropped in a future cleanup once we confirm no historical queries need them.
|
||||
|
||||
---
|
||||
|
||||
## Next Steps for Production
|
||||
|
||||
1. **Update migration scripts** based on lessons learned
|
||||
2. **Test updated scripts** on dev backup database
|
||||
3. **Create production deployment plan** with maintenance window
|
||||
4. **Prepare rollback procedure** with tested commands
|
||||
5. **Schedule production migration** (estimated 1-2 hours downtime)
|
||||
6. **Deploy updated ASP pages** immediately after migration
|
||||
7. **Monitor logs** for 24-48 hours post-migration
|
||||
8. **Document any production-specific issues**
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- `/home/camp/projects/windows/shopdb/PHASE2_PC_MIGRATION_COMPLETE.md` - Completion summary
|
||||
- `/home/camp/projects/windows/shopdb/sql/migration_phase1/README.md` - Phase 1 scripts
|
||||
- `/home/camp/projects/windows/shopdb/sql/migration_phase2/README.md` - Phase 2 scripts
|
||||
- `/home/camp/projects/ENVIRONMENT_DOCUMENTATION.md` - Dev environment setup
|
||||
|
||||
---
|
||||
|
||||
**Created:** 2025-11-13
|
||||
**Author:** Claude Code + Human
|
||||
**Status:** DEV MIGRATION COMPLETE
|
||||
**Production Status:** PENDING - Scripts need updates based on dev lessons learned
|
||||
444
docs/archive/PHASE2_PC_MIGRATION_COMPLETE.md
Normal file
444
docs/archive/PHASE2_PC_MIGRATION_COMPLETE.md
Normal file
@@ -0,0 +1,444 @@
|
||||
# Phase 2 PC Migration - COMPLETE
|
||||
|
||||
**Status:** **COMPLETED**
|
||||
**Completion Date:** November 10, 2025
|
||||
**Environment:** Development Server
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
All PC-related pages have been successfully migrated from the old `pc` and `pc_network_interfaces` tables to the Phase 2 consolidated schema using `machines` and `communications` tables.
|
||||
|
||||
---
|
||||
|
||||
## Migrated Files
|
||||
|
||||
### 1. displaypcs.asp - PC List Page
|
||||
**Status:** COMPLETE
|
||||
**Last Updated:** 2025-11-10 14:40
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaypcs.asp`
|
||||
|
||||
**Changes Applied:**
|
||||
- Uses `FROM machines` with `pctypeid IS NOT NULL` filter
|
||||
- Joins to `communications` table for network info
|
||||
- Uses proper column name `address` (not `ipaddress`)
|
||||
- Includes all required columns (vendorid, modelnumberid, etc.)
|
||||
- LEFT JOIN for optional relationships
|
||||
- Parameterized queries for security
|
||||
- Shows PC types, vendors, models, business units
|
||||
|
||||
**Key Query:**
|
||||
```sql
|
||||
FROM machines m
|
||||
LEFT JOIN models ON m.modelnumberid = models.modelnumberid
|
||||
LEFT JOIN vendors ON models.vendorid = vendors.vendorid
|
||||
LEFT JOIN pctype ON m.pctypeid = pctype.pctypeid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1
|
||||
WHERE m.pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2. displaypc.asp - Individual PC View
|
||||
**Status:** COMPLETE
|
||||
**Last Updated:** November 10, 2025
|
||||
**Location:** `/home/camp/projects/windows/shopdb/displaypc.asp`
|
||||
|
||||
**Changes Applied:**
|
||||
- Main query uses `FROM machines WHERE pctypeid IS NOT NULL`
|
||||
- Network interfaces from `communications` table
|
||||
- Accepts `?pcid=X` parameter (mapped to machineid)
|
||||
- All text fields converted to strings with `& ""`
|
||||
- Uses `address` column (not `ipaddress`)
|
||||
- Relationships use `machinerelationships` table
|
||||
- Profile card with PC information
|
||||
- Tabbed interface (Settings, Network, etc.)
|
||||
|
||||
**Main Query:**
|
||||
```sql
|
||||
SELECT m.*,
|
||||
mo.modelnumber, mo.vendorid AS modelvendorid, mo.machinetypeid, mo.image AS modelimage,
|
||||
v.vendor,
|
||||
bu.businessunit,
|
||||
mt.machinetype
|
||||
FROM machines m
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors v ON mo.vendorid = v.vendorid
|
||||
LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid
|
||||
LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid
|
||||
WHERE m.machineid = ? AND m.pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
**Network Query:**
|
||||
```sql
|
||||
SELECT address, macaddress
|
||||
FROM communications
|
||||
WHERE machineid = ? AND isactive = 1
|
||||
ORDER BY isprimary DESC
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. editpc.asp - PC Edit Form
|
||||
**Status:** COMPLETE
|
||||
**Last Updated:** November 10, 2025
|
||||
**Location:** `/home/camp/projects/windows/shopdb/editpc.asp`
|
||||
|
||||
**Changes Applied:**
|
||||
- Loads data from `machines WHERE pctypeid IS NOT NULL`
|
||||
- Network interfaces from `communications` table
|
||||
- All text fields converted to strings with `& ""`
|
||||
- Uses `address` and `macaddress` columns correctly
|
||||
- Parameterized queries throughout
|
||||
- Proper NULL handling
|
||||
- Edit form with all PC-specific fields
|
||||
- Dualpath and controlled equipment relationships
|
||||
|
||||
**Load Query:**
|
||||
```sql
|
||||
SELECT m.*,
|
||||
mo.modelnumber, mo.vendorid AS modelvendorid, mo.machinetypeid, mo.image AS modelimage,
|
||||
v.vendor,
|
||||
bu.businessunit,
|
||||
mt.machinetype
|
||||
FROM machines m
|
||||
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors v ON mo.vendorid = v.vendorid
|
||||
LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid
|
||||
LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid
|
||||
WHERE m.machineid = ? AND m.pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
**Communications Query:**
|
||||
```sql
|
||||
SELECT address, macaddress
|
||||
FROM communications
|
||||
WHERE machineid = ? AND isactive = 1
|
||||
ORDER BY isprimary DESC
|
||||
```
|
||||
|
||||
**Controlled Equipment Query:**
|
||||
```sql
|
||||
SELECT machineid, machinenumber, alias
|
||||
FROM machines
|
||||
WHERE pctypeid IS NULL AND isactive = 1
|
||||
ORDER BY machinenumber ASC
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Schema Verification
|
||||
|
||||
### Old Schema (Phase 1) - DEPRECATED
|
||||
```
|
||||
pc
|
||||
├── pcid
|
||||
├── hostname
|
||||
├── notes <- renamed to machinenotes
|
||||
└── ...
|
||||
|
||||
pc_network_interfaces
|
||||
├── interfaceid
|
||||
├── pcid
|
||||
├── ipaddress <- renamed to address
|
||||
├── macaddress
|
||||
└── ...
|
||||
|
||||
pc_dualpath_assignments
|
||||
├── assignmentid
|
||||
├── pcid
|
||||
├── dualpath_pcid
|
||||
└── ...
|
||||
```
|
||||
|
||||
### New Schema (Phase 2) - ACTIVE
|
||||
```
|
||||
machines
|
||||
├── machineid
|
||||
├── hostname
|
||||
├── machinenotes <- was 'notes'
|
||||
├── pctypeid <- IS NOT NULL identifies PCs
|
||||
└── ...
|
||||
|
||||
communications
|
||||
├── comid
|
||||
├── machineid
|
||||
├── address <- was 'ipaddress'
|
||||
├── macaddress
|
||||
└── ...
|
||||
|
||||
machinerelationships
|
||||
├── relationshipid
|
||||
├── machineid
|
||||
├── related_machineid
|
||||
├── relationshiptypeid
|
||||
└── ...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Column Mapping Reference
|
||||
|
||||
### PC Table → Machines Table
|
||||
| Old Column | New Column | Notes |
|
||||
|------------|-----------|-------|
|
||||
| `pcid` | `machineid` | Primary key |
|
||||
| `hostname` | `hostname` | Same |
|
||||
| `notes` | `machinenotes` | **RENAMED** |
|
||||
| `pctypeid` | `pctypeid` | **Must be NOT NULL for PCs** |
|
||||
| `serialnumber` | `serialnumber` | Same |
|
||||
| `alias` | `alias` | Same |
|
||||
| `modelnumberid` | `modelnumberid` | Same |
|
||||
| `businessunitid` | `businessunitid` | Same |
|
||||
|
||||
### Network Interfaces Table → Communications Table
|
||||
| Old Column | New Column | Notes |
|
||||
|------------|-----------|-------|
|
||||
| `interfaceid` | `comid` | Primary key renamed |
|
||||
| `pcid` | `machineid` | Foreign key renamed |
|
||||
| `ipaddress` | `address` | **RENAMED** |
|
||||
| `macaddress` | `macaddress` | Same |
|
||||
| `isprimary` | `isprimary` | Same |
|
||||
|
||||
---
|
||||
|
||||
## Critical Fixes Applied
|
||||
|
||||
### 1. Column Name Corrections
|
||||
- `ipaddress` → `address` in communications table
|
||||
- `notes` → `machinenotes` in machines table
|
||||
- `pcid` → `machineid` throughout
|
||||
|
||||
### 2. Type Conversion for HTMLEncode
|
||||
**Problem:** Type mismatch errors with Server.HTMLEncode()
|
||||
**Solution:** All text fields converted to strings with `& ""`
|
||||
|
||||
```asp
|
||||
' CORRECT implementation in all files
|
||||
hostname = "" : If NOT IsNull(rsMachine("hostname")) Then hostname = rsMachine("hostname") & ""
|
||||
alias = "" : If NOT IsNull(rsMachine("alias")) Then alias = rsMachine("alias") & ""
|
||||
machinenotes = "" : If NOT IsNull(rsMachine("machinenotes")) Then machinenotes = rsMachine("machinenotes") & ""
|
||||
```
|
||||
|
||||
### 3. Relationship Direction
|
||||
**Controls Relationship (PC → Equipment):**
|
||||
```sql
|
||||
-- For PC page - find controlled equipment
|
||||
WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls'
|
||||
SELECT mr.related_machineid -- Returns equipment controlled by this PC
|
||||
```
|
||||
|
||||
**Dualpath Relationship (PC ↔ PC):**
|
||||
```sql
|
||||
-- Bidirectional
|
||||
WHERE mr.machineid = ? AND rt.relationshiptype = 'Dualpath'
|
||||
SELECT mr.related_machineid
|
||||
```
|
||||
|
||||
### 4. Proper JOIN Types
|
||||
- LEFT JOIN for optional relationships (pctypes, models, etc.)
|
||||
- INNER JOIN for required relationships
|
||||
- Proper NULL handling throughout
|
||||
|
||||
---
|
||||
|
||||
## Testing Results
|
||||
|
||||
### All Tests Passed
|
||||
|
||||
#### displaypcs.asp
|
||||
- Page loads without errors (HTTP 200)
|
||||
- PC list displays correctly
|
||||
- All columns populated (hostname, alias, IP, MAC, type, vendor, model)
|
||||
- Filter dropdowns work (PC type, status, recent)
|
||||
- Links to displaypc.asp work correctly
|
||||
|
||||
#### displaypc.asp
|
||||
- Page loads with `?pcid=X` parameter
|
||||
- All PC data displays correctly
|
||||
- Network interfaces show properly (IP and MAC addresses)
|
||||
- No "Item cannot be found" errors
|
||||
- Tabs functional (if present)
|
||||
- Special characters handled correctly (no HTMLEncode errors)
|
||||
- Relationships display correctly
|
||||
|
||||
#### editpc.asp
|
||||
- Page loads with existing PC data
|
||||
- Edit form pre-filled correctly
|
||||
- Network interfaces editable (up to 3)
|
||||
- Controlled equipment dropdown works
|
||||
- Form submission successful
|
||||
- Data saves correctly
|
||||
- No validation errors
|
||||
|
||||
#### Integration Testing
|
||||
- displaypcs.asp → displaypc.asp navigation works
|
||||
- displaypc.asp → editpc.asp navigation works
|
||||
- editpc.asp saves and redirects correctly
|
||||
- All parameterized queries working
|
||||
- No SQL injection vulnerabilities
|
||||
- Proper error handling
|
||||
|
||||
---
|
||||
|
||||
## Migration Pattern Success
|
||||
|
||||
This migration followed the same proven pattern as the Machine pages migration (completed Nov 7, 2025):
|
||||
|
||||
1. Update SQL queries to use `machines` table
|
||||
2. Add `WHERE pctypeid IS NOT NULL` filter
|
||||
3. Update column references (`notes` → `machinenotes`, `ipaddress` → `address`)
|
||||
4. Convert text fields to strings with `& ""`
|
||||
5. Use `communications` table for network info
|
||||
6. Use `machinerelationships` for PC relationships
|
||||
7. Implement parameterized queries
|
||||
8. Test thoroughly with real data
|
||||
|
||||
---
|
||||
|
||||
## Benefits Achieved
|
||||
|
||||
### 1. Data Consolidation
|
||||
- Single source of truth for all infrastructure (machines table)
|
||||
- Unified network information (communications table)
|
||||
- Unified relationships (machinerelationships table)
|
||||
|
||||
### 2. Code Consistency
|
||||
- PC pages now match machine pages architecture
|
||||
- Consistent security patterns (parameterized queries)
|
||||
- Consistent error handling
|
||||
- Consistent UI/UX
|
||||
|
||||
### 3. Query Flexibility
|
||||
```sql
|
||||
-- All PCs
|
||||
SELECT * FROM machines WHERE pctypeid IS NOT NULL;
|
||||
|
||||
-- All Equipment
|
||||
SELECT * FROM machines WHERE pctypeid IS NULL;
|
||||
|
||||
-- All infrastructure (PCs + Equipment)
|
||||
SELECT * FROM machines;
|
||||
|
||||
-- Cross-entity queries now possible
|
||||
SELECT m1.hostname AS pc_name, m2.machinenumber AS equipment_name
|
||||
FROM machinerelationships mr
|
||||
JOIN machines m1 ON mr.machineid = m1.machineid
|
||||
JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
WHERE m1.pctypeid IS NOT NULL; -- PC controls equipment
|
||||
```
|
||||
|
||||
### 4. Maintenance Simplification
|
||||
- Less code duplication
|
||||
- Easier to add features (apply to one table instead of multiple)
|
||||
- Consistent backup/restore procedures
|
||||
- Better performance (fewer tables to join)
|
||||
|
||||
---
|
||||
|
||||
## Files That Can Be Archived
|
||||
|
||||
The following old files are **NO LONGER NEEDED** but kept for reference:
|
||||
|
||||
### Backup Files (Can be deleted after 30 days):
|
||||
- `displaypc.asp.backup-20251027`
|
||||
- `displaypc.asp.phase1_backup`
|
||||
- `displaypcs.asp.phase1_backup`
|
||||
- `pc_edit.asp.broken`
|
||||
|
||||
### Migration Reference:
|
||||
- `PHASE2_PC_MIGRATION_TODO.md` - Reference document (marked complete by this file)
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
### Phase 2 Complete - What's Next?
|
||||
|
||||
#### Phase 1: Equipment Migration (COMPLETE)
|
||||
- Machines table created
|
||||
- Equipment pages working
|
||||
|
||||
#### Phase 2: PC Migration (COMPLETE - This Document)
|
||||
- PCs consolidated into machines table
|
||||
- All PC pages updated
|
||||
- Network interfaces in communications table
|
||||
- Relationships working
|
||||
|
||||
#### Phase 3: Network Devices Migration (PLANNED)
|
||||
See: `/home/camp/projects/windows/shopdb/docs/PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md`
|
||||
|
||||
**Devices to Migrate:**
|
||||
- Servers → machinetypeid 30
|
||||
- Switches → machinetypeid 31
|
||||
- Cameras → machinetypeid 32
|
||||
- Access Points → machinetypeid 33
|
||||
- IDFs → machinetypeid 34
|
||||
- Routers → machinetypeid 35
|
||||
- Firewalls → machinetypeid 36
|
||||
|
||||
**Timeline:** 10-15 hours estimated
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria - ALL MET
|
||||
|
||||
- All three PC pages load without errors
|
||||
- PC list displays correctly
|
||||
- Individual PC view shows all data
|
||||
- PC edit form loads and saves correctly
|
||||
- Network interfaces display correctly
|
||||
- Dualpath relationships display correctly
|
||||
- Controlling equipment relationships work
|
||||
- No references to `pc` or `pc_network_interfaces` tables remain in active code
|
||||
- All functionality matches machine pages
|
||||
- Security maintained (parameterized queries)
|
||||
- Performance acceptable
|
||||
- No data loss
|
||||
|
||||
---
|
||||
|
||||
## Timeline - Actual
|
||||
|
||||
- **Planning:** 2 hours (Nov 7, 2025)
|
||||
- **Implementation:** 3-4 hours (Nov 10, 2025)
|
||||
- **Testing:** 1 hour (Nov 10, 2025)
|
||||
- **Total:** ~6-7 hours
|
||||
|
||||
**Original Estimate:** 4-6 hours
|
||||
**Actual:** 6-7 hours
|
||||
**Variance:** On target
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- `/home/camp/projects/windows/shopdb/MACHINE_MANAGEMENT_COMPLETE.md` - Machine pages (Phase 1)
|
||||
- `/home/camp/projects/windows/shopdb/BUGFIX_2025-11-07.md` - Machine migration fixes
|
||||
- `/home/camp/projects/windows/shopdb/docs/PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md` - Next phase
|
||||
- `/home/camp/projects/windows/shopdb/SESSION_SUMMARY_2025-11-10.md` - Session notes
|
||||
|
||||
---
|
||||
|
||||
## Key Contributors
|
||||
|
||||
- Development: Claude Code + Human
|
||||
- Testing: Dev environment (shopdb on IIS Express)
|
||||
- Planning: PHASE2_PC_MIGRATION_TODO.md (Nov 7, 2025)
|
||||
- Execution: Nov 10, 2025
|
||||
- Documentation: This file (Nov 13, 2025)
|
||||
|
||||
---
|
||||
|
||||
**Status:** **MIGRATION COMPLETE AND VERIFIED**
|
||||
|
||||
**Ready for Production:** YES (after thorough testing)
|
||||
|
||||
**Rollback Plan:** Keep old `pc` and `pc_network_interfaces` tables for 30 days as backup
|
||||
|
||||
---
|
||||
|
||||
**Created:** 2025-11-13
|
||||
**Environment:** Development Server
|
||||
**Production Deployment:** Pending approval
|
||||
230
docs/archive/PHASE2_TESTING_SUMMARY.md
Normal file
230
docs/archive/PHASE2_TESTING_SUMMARY.md
Normal file
@@ -0,0 +1,230 @@
|
||||
# Phase 2 PC Migration - Testing Summary
|
||||
|
||||
**Date:** 2025-11-13
|
||||
**Environment:** DEV Server (http://192.168.122.151:8080/)
|
||||
**Tested By:** Claude Code (automated testing agents)
|
||||
**Total Pages Tested:** 15 out of 123 ASP files
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
**Major Issues Fixed:**
|
||||
- editdevice.asp - Undefined variable bug
|
||||
- updatedevice.asp - Phase 2 schema migration complete
|
||||
- updatedevice_direct.asp - Phase 2 schema migration complete
|
||||
- displaymachine.asp - Multiple relationship query bugs fixed
|
||||
- displaypc.asp - Dualpath section removed, queries optimized
|
||||
- network_map.asp - Now shows all network device types
|
||||
|
||||
**Remaining Issues:**
|
||||
- displaysubnet.asp - Runtime error (subscript out of range)
|
||||
- 3 warranty pages in v2 directory need Phase 2 updates
|
||||
- v2 directory has ODBC configuration issues
|
||||
|
||||
---
|
||||
|
||||
## Critical Bugs Fixed
|
||||
|
||||
### 1. editdevice.asp (Line 95)
|
||||
**Issue:** Undefined variable `pcid`
|
||||
**Fix:** Changed to `machineid`
|
||||
**Status:** Fixed
|
||||
|
||||
### 2. updatedevice.asp
|
||||
**Issue:** Used old `pc` table instead of `machines` table
|
||||
**Changes Made:**
|
||||
- Line 64: `UPDATE pc` → `UPDATE machines`
|
||||
- Line 11: `pcstatusid` → `machinestatusid`
|
||||
- Line 31: `RecordExists("pc", "pcid")` → `RecordExists("machines", "machineid")`
|
||||
- Line 118: `WHERE pcid = ?` → `WHERE machineid = ? AND pctypeid IS NOT NULL`
|
||||
**Status:** Fixed
|
||||
|
||||
### 3. updatedevice_direct.asp
|
||||
**Issue:** Used old `pc` table instead of `machines` table
|
||||
**Changes Made:**
|
||||
- Line 176: `UPDATE pc SET pcstatusid` → `UPDATE machines SET machinestatusid`
|
||||
- Line 176: `WHERE pcid = ?` → `WHERE machineid = ? AND pctypeid IS NOT NULL`
|
||||
- Line 12: `pcstatusid` → `machinestatusid`
|
||||
- Line 181: Parameter renamed from `@pcstatusid` to `@machinestatusid`
|
||||
- Line 212: Parameter renamed from `@pcid` to `@machineid`
|
||||
**Status:** Fixed
|
||||
|
||||
### 4. displaymachine.asp
|
||||
**Issue:** Duplicate PCs shown, wrong relationship directions
|
||||
**Fixes Applied:**
|
||||
- Dualpath query: Added NOT EXISTS clause to prevent duplicates
|
||||
- Controlled By PC query: Used GROUP_CONCAT to combine multiple IPs
|
||||
- All relationship queries: Fixed JOIN directions for correct data
|
||||
**Status:** Fixed
|
||||
|
||||
### 5. displaypc.asp
|
||||
**Issue:** Dualpath section redundant
|
||||
**Fix:** Removed entire dualpath section, now shown in "Machines Controlled" with badge
|
||||
**Status:** Fixed
|
||||
|
||||
### 6. network_map.asp
|
||||
**Issue:** Only showing printers, not other network device types
|
||||
**Fix:** Expanded SQL query to UNION ALL device types (servers, switches, cameras, access points, IDFs)
|
||||
**Changes Made:**
|
||||
- Line 240-248: Added servers query
|
||||
- Line 252-260: Added switches query
|
||||
- Line 264-272: Added cameras query
|
||||
- Line 276-284: Added access points query (fixed column name from accesspointid to apid)
|
||||
- Line 288-296: Added IDFs query
|
||||
- Line 420-430: Updated detail URL routing for all device types
|
||||
**Status:** Fixed
|
||||
**Note:** Currently only 37 printers are visible on map because other device types don't have mapleft/maptop coordinates set yet
|
||||
|
||||
---
|
||||
|
||||
## Test Results by Category
|
||||
|
||||
### PASSED - Display Pages (Read-Only)
|
||||
|
||||
| Page | Test Date | Status | Notes |
|
||||
|------|-----------|--------|-------|
|
||||
| displaypcs.asp | 2025-11-13 | 200 OK | Lists 224 PCs from machines table |
|
||||
| displaypc.asp | 2025-11-13 | 200 OK | Shows PC details, relationships working |
|
||||
| displaymachines.asp | 2025-11-13 | 200 OK | Lists equipment (pctypeid IS NULL) |
|
||||
| displaymachine.asp | 2025-11-13 | 200 OK | Shows equipment with PC relationships |
|
||||
| default.asp | 2025-11-13 | 200 OK | Homepage loads correctly |
|
||||
| network_map.asp | 2025-11-13 | 200 OK | Now shows all device types (printers, servers, switches, cameras, access points, IDFs) |
|
||||
| network_devices.asp | 2025-11-13 | 200 OK | Uses vw_network_devices view |
|
||||
|
||||
### PASSED - Add/Save Pages
|
||||
|
||||
| Page | Test Date | Status | Notes |
|
||||
|------|-----------|--------|-------|
|
||||
| adddevice.asp | 2025-11-13 | PASS | Form only, no DB dependencies |
|
||||
| savedevice.asp | 2025-11-13 | PASS | Inserts into machines table correctly |
|
||||
| savedevice_direct.asp | 2025-11-13 | PASS | Uses Phase 2 schema, parameterized queries |
|
||||
|
||||
### PASSED - Edit/Update Pages (After Fixes)
|
||||
|
||||
| Page | Test Date | Status | Notes |
|
||||
|------|-----------|--------|-------|
|
||||
| editdevice.asp | 2025-11-13 | PASS | Fixed undefined variable bug |
|
||||
| updatedevice.asp | 2025-11-13 | PASS | Migrated to machines table |
|
||||
| updatedevice_direct.asp | 2025-11-13 | PASS | Migrated to machines table |
|
||||
|
||||
### PASSED - Warranty Pages (Root Directory)
|
||||
|
||||
| Page | Test Date | Status | Notes |
|
||||
|------|-----------|--------|-------|
|
||||
| check_all_warranties.asp | 2025-11-13 | PASS | Uses machines + warranties tables |
|
||||
| check_all_warranties_clean.asp | 2025-11-13 | PASS | Uses machines + warranties tables |
|
||||
|
||||
### FAILED - Pages Needing Fixes
|
||||
|
||||
| Page | Issue | Priority | Notes |
|
||||
|------|-------|----------|-------|
|
||||
| displaysubnet.asp | Runtime error (subscript out of range) | Medium | Phase 2 tables used correctly, logic bug |
|
||||
| v2/check_warranties_v2.asp | Uses old pc table | Low | v2 directory |
|
||||
| v2/check_all_warranties.asp | Uses old pc table | Low | v2 directory |
|
||||
| v2/check_all_warranties_clean.asp | Uses old pc table | Low | v2 directory |
|
||||
| All v2/*.asp pages | ODBC configuration missing | Low | v2 directory |
|
||||
|
||||
---
|
||||
|
||||
## Error Log Analysis
|
||||
|
||||
### Errors Found in IIS Logs (/home/camp/projects/windows/logs/shopdb/ex251113.log)
|
||||
|
||||
**Timeline of Migration:**
|
||||
- 17:10:22 - Before migration: "Table 'shopdb.communications' doesn't exist"
|
||||
- 17:36:44 - After migration: Pages working with Phase 2 schema
|
||||
- **Migration window: 17:10-17:36** (26 minutes)
|
||||
|
||||
**Fixed Errors:**
|
||||
- 18:13:08 - displaymachines.asp: Unknown column 'machines.pctypeid' → Fixed
|
||||
- 18:32:57 - displaymachine.asp: Unknown column 'machines.dateadded' → Fixed
|
||||
- 19:16-19:38 - displaymachine.asp: Compliance column errors → Fixed
|
||||
- 20:39:29 - displaypc.asp: Item not found (relationshiptype) → Fixed
|
||||
|
||||
**Remaining Errors:**
|
||||
- 23:00:10 - displaysubnet.asp: Subscript out of range (error code 44)
|
||||
- 23:00:32 - v2/*.asp: ODBC configuration missing
|
||||
|
||||
---
|
||||
|
||||
## Phase 2 Compliance Status
|
||||
|
||||
### Tables Migrated:
|
||||
- `pc` → `machines WHERE pctypeid IS NOT NULL`
|
||||
- `pc.pcid` → `machines.machineid`
|
||||
- `pc.pcstatusid` → `machines.machinestatusid`
|
||||
- `pc_network_interfaces` → `communications`
|
||||
- `pc_dualpath_assignments` → `machinerelationships`
|
||||
|
||||
### Files Updated for Phase 2:
|
||||
1. displaypcs.asp
|
||||
2. displaypc.asp
|
||||
3. editdevice.asp
|
||||
4. savedevice.asp
|
||||
5. savedevice_direct.asp
|
||||
6. updatedevice.asp
|
||||
7. updatedevice_direct.asp
|
||||
8. displaymachine.asp
|
||||
9. displaymachines.asp
|
||||
10. check_all_warranties.asp
|
||||
11. check_all_warranties_clean.asp
|
||||
12. displaysubnet.asp (tables correct, logic bug)
|
||||
13. network_map.asp
|
||||
14. network_devices.asp
|
||||
|
||||
### Files NOT Updated (v2 directory):
|
||||
1. v2/check_warranties_v2.asp
|
||||
2. v2/check_all_warranties.asp
|
||||
3. v2/check_all_warranties_clean.asp
|
||||
4. v2/displaysubnet.asp
|
||||
|
||||
---
|
||||
|
||||
## Recommendations
|
||||
|
||||
### Immediate Actions:
|
||||
1. COMPLETED: Fix editdevice.asp undefined variable
|
||||
2. COMPLETED: Migrate updatedevice.asp to Phase 2 schema
|
||||
3. COMPLETED: Migrate updatedevice_direct.asp to Phase 2 schema
|
||||
4. TODO: Fix displaysubnet.asp subscript out of range error
|
||||
5. TODO: Update or deprecate v2 directory
|
||||
|
||||
### Future Cleanup:
|
||||
1. Drop old `pc`, `pc_network_interfaces`, `pc_comm_config`, `pc_dualpath_assignments` tables after confirming no dependencies
|
||||
2. Decide on v2 directory - update or remove
|
||||
3. Continue testing remaining 108 ASP pages
|
||||
4. Test POST operations (create/update) with real data
|
||||
|
||||
---
|
||||
|
||||
## Security Assessment
|
||||
|
||||
**All tested pages use parameterized queries**
|
||||
- No SQL injection vulnerabilities found
|
||||
- Proper input validation on all save/update pages
|
||||
- HTML encoding used for output
|
||||
|
||||
---
|
||||
|
||||
## Performance Notes
|
||||
|
||||
- displaymachine.asp: Uses GROUP_CONCAT for multiple IPs (efficient)
|
||||
- Relationship queries: Use proper JOINs and indexes
|
||||
- No N+1 query issues observed
|
||||
|
||||
---
|
||||
|
||||
## Next Steps for Production
|
||||
|
||||
1. **Run full test suite** on production backup database
|
||||
2. **Test all create/edit/delete operations** manually
|
||||
3. **Monitor IIS logs** for 48 hours after deployment
|
||||
4. **Create rollback plan** with tested SQL scripts
|
||||
5. **Schedule maintenance window** for production migration
|
||||
|
||||
---
|
||||
|
||||
**Status:** Core PC functionality Phase 2 compliant
|
||||
**Production Ready:** After fixing displaysubnet.asp and testing remaining pages
|
||||
**Risk Level:** Low - All critical paths tested and working
|
||||
283
docs/archive/PRINTER_INSTALLER_FIX_2025-11-20.md
Normal file
283
docs/archive/PRINTER_INSTALLER_FIX_2025-11-20.md
Normal file
@@ -0,0 +1,283 @@
|
||||
# Printer Installer Batch File Fix
|
||||
|
||||
**Date:** 2025-11-20
|
||||
**Issue:** Batch file download from displayprinters/displayprinter pages fails with PowerShell command errors
|
||||
**Status:** FIXED
|
||||
|
||||
---
|
||||
|
||||
## Problem Description
|
||||
|
||||
When downloading the printer installer batch file (e.g., `Install_CSF08-LaserJet-4001.bat`) from the displayprinters or displayprinter pages, the batch file would error out with messages like:
|
||||
|
||||
```
|
||||
'Write-Host' is not recognized as an internal or external command,
|
||||
operable program or batch file.
|
||||
'$printerName' is not recognized as an internal or external command,
|
||||
operable program or batch file.
|
||||
```
|
||||
|
||||
### Root Cause
|
||||
|
||||
The ASP code was generating a PowerShell command split across multiple lines in the batch file:
|
||||
|
||||
```batch
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "
|
||||
Write-Host 'Installing printer with universal driver...' -ForegroundColor Cyan;
|
||||
|
||||
$printerName = 'CSF08-LaserJet-4001';
|
||||
$address = 'Printer-10-80-92-58.printer.geaerospace.net';
|
||||
...
|
||||
"
|
||||
```
|
||||
|
||||
The CMD batch file interpreter doesn't support multi-line PowerShell commands in this format. It would try to execute the PowerShell code as batch commands, resulting in errors.
|
||||
|
||||
---
|
||||
|
||||
## Solution
|
||||
|
||||
The PowerShell command is now built as a **single line** with semicolons separating statements:
|
||||
|
||||
```batch
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Installing printer with universal driver...' -ForegroundColor Cyan; $printerName = 'CSF08-LaserJet-4001'; $address = 'Printer-10-80-92-58.printer.geaerospace.net'; $driverName = 'HP Universal Printing PCL 6'; $portName = 'IP_' + $address; $driver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue; if (-not $driver) { Write-Host 'ERROR: Universal driver not found!' -ForegroundColor Red; Write-Host 'Please install ' $driverName ' from Windows Update or driver package' -ForegroundColor Yellow; exit 1; }; $port = Get-PrinterPort -Name $portName -ErrorAction SilentlyContinue; if (-not $port) { Write-Host 'Creating printer port...' -ForegroundColor Yellow; Add-PrinterPort -Name $portName -PrinterHostAddress $address -ErrorAction Stop; Write-Host 'Port created successfully' -ForegroundColor Green; } else { Write-Host 'Port already exists' -ForegroundColor Green; }; $existingPrinter = Get-Printer -Name $printerName -ErrorAction SilentlyContinue; if (-not $existingPrinter) { Write-Host 'Adding printer...' -ForegroundColor Yellow; Add-Printer -Name $printerName -DriverName $driverName -PortName $portName -ErrorAction Stop; Write-Host 'Printer installed successfully!' -ForegroundColor Green; } else { Write-Host 'Printer already exists' -ForegroundColor Green; }"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files Modified
|
||||
|
||||
### 1. `/home/camp/projects/windows/shopdb/install_printer.asp`
|
||||
**Lines:** 180-223
|
||||
**Changes:**
|
||||
- Added `Dim psCommand` variable declaration
|
||||
- Built PowerShell command as a single concatenated string
|
||||
- All PowerShell statements joined with semicolons
|
||||
- Single `Response.Write()` call to output the complete command
|
||||
|
||||
### 2. `/home/camp/projects/windows/shopdb/v2/install_printer.asp`
|
||||
**Lines:** 180-223
|
||||
**Changes:**
|
||||
- Same fix applied to v2 version
|
||||
|
||||
---
|
||||
|
||||
## Code Changes Summary
|
||||
|
||||
**Before (Lines 181-224):**
|
||||
```vbscript
|
||||
' Generate PowerShell script to install printer
|
||||
Response.Write("powershell -NoProfile -ExecutionPolicy Bypass -Command """ & vbCrLf)
|
||||
Response.Write(" Write-Host 'Installing printer with universal driver...' -ForegroundColor Cyan;" & vbCrLf)
|
||||
Response.Write(" " & vbCrLf)
|
||||
Response.Write(" $printerName = '" & Replace(printer("name"), "'", "''") & "';" & vbCrLf)
|
||||
' ... 40+ more lines of multi-line output ...
|
||||
```
|
||||
|
||||
**After (Lines 180-223):**
|
||||
```vbscript
|
||||
' Build PowerShell command as single line
|
||||
Dim psCommand
|
||||
psCommand = "Write-Host 'Installing printer with universal driver...' -ForegroundColor Cyan; "
|
||||
psCommand = psCommand & "$printerName = '" & Replace(printer("name"), "'", "''") & "'; "
|
||||
psCommand = psCommand & "$address = '" & Replace(printer("address"), "'", "''") & "'; "
|
||||
' ... build complete command as single string ...
|
||||
|
||||
' Write PowerShell command as single line
|
||||
Response.Write("powershell -NoProfile -ExecutionPolicy Bypass -Command """ & psCommand & """" & vbCrLf)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Testing Instructions
|
||||
|
||||
### Test 1: Download from displayprinters.asp
|
||||
1. Navigate to `http://192.168.122.151:8080/displayprinters.asp`
|
||||
2. Find any HP printer (e.g., CSF08-LaserJet-4001)
|
||||
3. Click the download installer button
|
||||
4. Save the `.bat` file to Downloads
|
||||
5. Open CMD and run the batch file
|
||||
6. **Expected:** PowerShell commands execute successfully, printer installs
|
||||
|
||||
### Test 2: Download from displayprinter.asp
|
||||
1. Navigate to `http://192.168.122.151:8080/displayprinter.asp?printerid=X`
|
||||
2. Click the download installer button
|
||||
3. Save the `.bat` file to Downloads
|
||||
4. Open CMD and run the batch file
|
||||
5. **Expected:** PowerShell commands execute successfully, printer installs
|
||||
|
||||
### Test 3: Verify Universal Driver Detection
|
||||
**For HP Printers:**
|
||||
- Should use "HP Universal Printing PCL 6"
|
||||
- Checks if driver exists before proceeding
|
||||
- Errors with clear message if driver not installed
|
||||
|
||||
**For Xerox Printers:**
|
||||
- Should use "Xerox Global Print Driver PCL6"
|
||||
|
||||
**For Generic/Unknown:**
|
||||
- Should use "Generic / Text Only"
|
||||
|
||||
---
|
||||
|
||||
## Expected Output
|
||||
|
||||
### Successful Installation
|
||||
```
|
||||
========================================
|
||||
GE Aerospace Printer Installer
|
||||
========================================
|
||||
|
||||
Installing 1 printer(s)...
|
||||
|
||||
----------------------------------------
|
||||
Installing: CSF08-LaserJet-4001
|
||||
CSF Name: CSF08
|
||||
Model: LaserJet Pro 4001n
|
||||
Address: Printer-10-80-92-58.printer.geaerospace.net
|
||||
----------------------------------------
|
||||
|
||||
Using universal driver: HP Universal Printing PCL 6
|
||||
|
||||
Installing printer with universal driver...
|
||||
Port already exists
|
||||
Printer already exists
|
||||
|
||||
========================================
|
||||
Installation Complete!
|
||||
========================================
|
||||
|
||||
Press any key to continue . . .
|
||||
```
|
||||
|
||||
### Driver Not Found
|
||||
```
|
||||
ERROR: Universal driver not found!
|
||||
Please install HP Universal Printing PCL 6 from Windows Update or driver package
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Related Issues
|
||||
|
||||
### Issue Type
|
||||
- Bug Fix
|
||||
- Batch File Generation
|
||||
- PowerShell Integration
|
||||
|
||||
### Affected Functionality
|
||||
- Printer installer downloads (universal driver method)
|
||||
- Printers without custom `installpath` in database
|
||||
|
||||
### Not Affected
|
||||
- Printers with custom `installpath` (uses different code path)
|
||||
- Manual printer installation
|
||||
- Printer display/search functionality
|
||||
|
||||
---
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Why Single-Line PowerShell?
|
||||
|
||||
When using `powershell.exe -Command "..."`, the command must be:
|
||||
1. A single line, OR
|
||||
2. Use proper batch line continuation with `^`, OR
|
||||
3. Use `-File` with a .ps1 script
|
||||
|
||||
The original code attempted multi-line without proper continuation, causing the batch interpreter to misinterpret PowerShell code as batch commands.
|
||||
|
||||
### Alternative Solutions Considered
|
||||
|
||||
**Option 1:** Use caret (^) for line continuation
|
||||
```batch
|
||||
powershell -Command "Write-Host 'Test'; ^
|
||||
$var = 'value'; ^
|
||||
Do-Something"
|
||||
```
|
||||
**Rejected:** More complex escaping, harder to maintain
|
||||
|
||||
**Option 2:** Generate temporary .ps1 file
|
||||
```batch
|
||||
echo $printerName = 'Test' > %TEMP%\install.ps1
|
||||
echo Add-Printer ... >> %TEMP%\install.ps1
|
||||
powershell -File %TEMP%\install.ps1
|
||||
```
|
||||
**Rejected:** More file I/O, cleanup required, potential security issues
|
||||
|
||||
**Option 3:** Single-line command (CHOSEN)
|
||||
```batch
|
||||
powershell -Command "Write-Host 'Test'; $var = 'value'; Do-Something"
|
||||
```
|
||||
**Selected:** Simplest, most reliable, no temp files needed
|
||||
|
||||
---
|
||||
|
||||
## Validation
|
||||
|
||||
### Code Review Checklist
|
||||
- Both install_printer.asp files updated (main and v2)
|
||||
- PowerShell command built as single string
|
||||
- All statements joined with semicolons
|
||||
- Single quotes properly escaped with Replace()
|
||||
- Error handling preserved
|
||||
- Driver detection logic maintained
|
||||
- Port creation logic maintained
|
||||
- Printer installation logic maintained
|
||||
|
||||
### Testing Checklist
|
||||
- Test HP printer download and install
|
||||
- Test Xerox printer download and install
|
||||
- Test printer without universal driver
|
||||
- Test printer already installed scenario
|
||||
- Test port already exists scenario
|
||||
- Verify error messages display correctly
|
||||
- Verify batch file self-deletes after execution
|
||||
|
||||
---
|
||||
|
||||
## Deployment
|
||||
|
||||
### Deployment Status
|
||||
- Code changes complete
|
||||
- Both files (main and v2) updated
|
||||
- Testing pending
|
||||
- Production deployment pending
|
||||
|
||||
### Rollback Plan
|
||||
If issues arise, revert to previous version:
|
||||
```bash
|
||||
git checkout HEAD~1 install_printer.asp
|
||||
git checkout HEAD~1 v2/install_printer.asp
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Additional Notes
|
||||
|
||||
### Printers with Custom Installers
|
||||
Printers with a value in the `installpath` database field use a **different code path** and are NOT affected by this bug. They download and execute a custom .exe installer.
|
||||
|
||||
### Universal Driver Availability
|
||||
The universal drivers must be installed on the target PC:
|
||||
- **HP Universal Printing PCL 6** - Available via Windows Update
|
||||
- **Xerox Global Print Driver PCL6** - Requires vendor download
|
||||
|
||||
If the driver is not installed, the script will error with clear instructions.
|
||||
|
||||
---
|
||||
|
||||
**Author:** Claude Code
|
||||
**Reviewed By:** Pending
|
||||
**Status:** Ready for Testing
|
||||
**Production Ready:** After successful testing
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference
|
||||
|
||||
**Bug:** Multi-line PowerShell commands in batch file
|
||||
**Fix:** Build PowerShell command as single line with semicolons
|
||||
**Impact:** Universal driver printer installations
|
||||
**Files:** install_printer.asp (both main and v2)
|
||||
**Testing:** Download .bat file from printer pages and execute
|
||||
213
docs/archive/PRINTER_PAGES_MODERNIZATION_2025-11-10.md
Normal file
213
docs/archive/PRINTER_PAGES_MODERNIZATION_2025-11-10.md
Normal file
@@ -0,0 +1,213 @@
|
||||
# Printer Pages Modernization Summary
|
||||
|
||||
**Date:** 2025-11-10
|
||||
**Status:** COMPLETED
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Modernized printer management pages to match the look and feel of machine/PC pages with Bootstrap theme, improved error handling, and consistent UI/UX.
|
||||
|
||||
---
|
||||
|
||||
## Pages Reviewed
|
||||
|
||||
### 1. **displayprinters.asp** - Printer List Page
|
||||
**Status:** Already Modern
|
||||
- Already using Bootstrap theme
|
||||
- Modern card layout
|
||||
- Responsive table
|
||||
- "Add Printer" button with icon
|
||||
- Location and attachment icons
|
||||
|
||||
### 2. **displayprinter.asp** - Individual Printer View
|
||||
**Status:** Already Modern
|
||||
- Bootstrap theme with modern includes
|
||||
- Tabbed interface:
|
||||
- Settings tab (view mode)
|
||||
- Edit tab (inline edit form)
|
||||
- Profile card with printer image
|
||||
- Nested entity creation (vendor, model)
|
||||
- Clean, modern layout
|
||||
|
||||
### 3. **editprinter.asp** - Backend Processor
|
||||
**Status:** Modernized (This Session)
|
||||
**Changes Made:**
|
||||
- Replaced old HTML/CSS with Bootstrap theme
|
||||
- Updated DOCTYPE to HTML5
|
||||
- Added modern includes (header.asp, sql.asp)
|
||||
- Improved error handling (redirects instead of inline HTML errors)
|
||||
- Added fallback page with Bootstrap styling
|
||||
- Kept all security features (parameterized queries, validation)
|
||||
|
||||
---
|
||||
|
||||
## Changes Made to editprinter.asp
|
||||
|
||||
### Before (Old Style):
|
||||
```asp
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="./style.css" type="text/css">
|
||||
```
|
||||
|
||||
### After (Modern):
|
||||
```asp
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!--#include file="./includes/header.asp"-->
|
||||
<!--#include file="./includes/sql.asp"-->
|
||||
</head>
|
||||
```
|
||||
|
||||
### Error Handling Improvements:
|
||||
|
||||
**Before:**
|
||||
```asp
|
||||
Response.Write("<div class='alert alert-danger'>Error: Invalid printer ID.</div>")
|
||||
Response.Write("<a href='displayprinters.asp'>Go back</a>")
|
||||
```
|
||||
|
||||
**After:**
|
||||
```asp
|
||||
Response.Redirect("displayprinters.asp?error=INVALID_PRINTER_ID")
|
||||
```
|
||||
|
||||
All errors now redirect with error codes:
|
||||
- `INVALID_PRINTER_ID`
|
||||
- `INVALID_MODEL_ID`
|
||||
- `INVALID_MACHINE_ID`
|
||||
- `FIELD_LENGTH_EXCEEDED`
|
||||
- `MODEL_REQUIRED`
|
||||
- `VENDOR_REQUIRED`
|
||||
- `MODEL_FIELD_LENGTH_EXCEEDED`
|
||||
- `VENDOR_NAME_REQUIRED`
|
||||
- `VENDOR_NAME_TOO_LONG`
|
||||
- `VENDOR_CREATE_FAILED`
|
||||
- `MODEL_CREATE_FAILED`
|
||||
- `UPDATE_FAILED`
|
||||
|
||||
### Success Handling:
|
||||
- Redirects to `displayprinter.asp?printerid=X&success=1`
|
||||
- Falls back to Bootstrap-styled redirect page if meta refresh fails
|
||||
|
||||
---
|
||||
|
||||
## Security Features Preserved
|
||||
|
||||
**All security features maintained:**
|
||||
1. Parameterized queries throughout
|
||||
2. Input validation (numeric checks, length checks)
|
||||
3. HTML encoding for all output
|
||||
4. SQL injection prevention
|
||||
5. XSS prevention
|
||||
6. Nested entity creation (vendor → model → printer)
|
||||
|
||||
---
|
||||
|
||||
## UI/UX Consistency
|
||||
|
||||
### Common Elements Across All Pages:
|
||||
- Bootstrap 4 theme
|
||||
- Modern includes (header.asp, sql.asp)
|
||||
- Responsive design
|
||||
- Consistent icons (zmdi font)
|
||||
- Tabbed interfaces where appropriate
|
||||
- Card-based layouts
|
||||
- Loading spinner (pageloader-overlay)
|
||||
- Left sidebar navigation
|
||||
- Top bar header
|
||||
|
||||
---
|
||||
|
||||
## Testing Results
|
||||
|
||||
### displayprinters.asp
|
||||
- HTTP 200 - Loads successfully
|
||||
- Bootstrap theme applied
|
||||
- Table renders correctly
|
||||
- Icons display properly
|
||||
|
||||
### displayprinter.asp
|
||||
- HTTP 200 - Loads successfully
|
||||
- Bootstrap theme applied
|
||||
- Tabs functional (Settings, Edit)
|
||||
- Edit form accessible
|
||||
|
||||
### editprinter.asp
|
||||
- Modernized with Bootstrap theme
|
||||
- Error handling via redirects
|
||||
- Parameterized queries functional
|
||||
- Nested entity creation working
|
||||
|
||||
---
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
/home/camp/projects/windows/shopdb/
|
||||
├── displayprinters.asp (List page - Already modern)
|
||||
├── displayprinter.asp (View page - Already modern)
|
||||
├── editprinter.asp (Backend processor - MODERNIZED)
|
||||
├── saveprinter.asp (Alternate save endpoint)
|
||||
├── addprinter.asp (Add new printer page)
|
||||
└── includes/
|
||||
├── header.asp (Bootstrap theme includes)
|
||||
├── sql.asp (Database connection)
|
||||
├── leftsidebar.asp (Navigation)
|
||||
└── topbarheader.asp (Top navigation)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Related Work (This Session)
|
||||
|
||||
In addition to printer page modernization, this session also included:
|
||||
|
||||
1. **Machine Relationship Fixes:**
|
||||
- Fixed bidirectional relationship display in `displaymachine.asp`
|
||||
- Added "Machines Controlled by This Machine" section
|
||||
- Fixed machine type display (using `machines.machinetypeid` instead of `models.machinetypeid`)
|
||||
- Fixed controlling PC IP address display (filter by comstypeid for IP-based communications)
|
||||
|
||||
2. **Files Modified:**
|
||||
- `displaymachine.asp` - Relationships and machine type fixes
|
||||
- `editprinter.asp` - Complete modernization
|
||||
|
||||
---
|
||||
|
||||
## Next Steps (Optional)
|
||||
|
||||
If further modernization is desired:
|
||||
|
||||
1. **Network Devices Unified Page:**
|
||||
- Create single `network_devices.asp` for servers, switches, cameras
|
||||
- Use existing `vw_network_devices` view
|
||||
- Implement tabs for filtering by device type
|
||||
|
||||
2. **Add Printer Page:**
|
||||
- Review `addprinter.asp` for modern styling
|
||||
- Ensure consistency with machine/PC add pages
|
||||
|
||||
3. **Printer API Pages:**
|
||||
- Review `api_printers.asp` for any needed updates
|
||||
- Check `printer_installer_map.asp` for modernization
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
**All printer pages now use modern Bootstrap theme**
|
||||
**Consistent UI/UX with machine/PC pages**
|
||||
**All security features preserved**
|
||||
**Error handling improved**
|
||||
**Testing completed successfully**
|
||||
|
||||
The printer management interface now matches the quality and consistency of the recently migrated machine/PC pages.
|
||||
|
||||
---
|
||||
|
||||
**Completed by:** Claude Code
|
||||
**Date:** 2025-11-10
|
||||
291
docs/archive/SCHEMA_COMPARISON_REPORT_2025-11-20.md
Normal file
291
docs/archive/SCHEMA_COMPARISON_REPORT_2025-11-20.md
Normal file
@@ -0,0 +1,291 @@
|
||||
# Database Schema Comparison Report
|
||||
|
||||
**Date:** 2025-11-20
|
||||
**Comparison:** database-backup-11-20-25-eod-with-drop.sql vs Current Dev Database
|
||||
**Dev Backup Created:** /home/camp/projects/windows/shopdb/sql/dev-backup-20251120-105614.sql
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
The backup file contains **Phase 1 schema** (pre-migration) with 63 tables, while the current dev database contains **Phase 2 schema** (post-migration) with 30 tables.
|
||||
|
||||
**Key Findings:**
|
||||
- **4 tables have schema changes** (businessunits, controllertypes, machine_overrides, machines)
|
||||
- **8 new Phase 2 tables** exist in dev but not in backup
|
||||
- **41 legacy tables** exist in backup but not in dev (deprecated/views)
|
||||
|
||||
---
|
||||
|
||||
## Tables Requiring DROP and Recreate
|
||||
|
||||
### 1. Tables with Schema Changes (4 tables)
|
||||
|
||||
These tables exist in both files but have different column structures. They should be **dropped and recreated** from the backup file if you want to revert to the backup schema.
|
||||
|
||||
#### `machines` (CRITICAL - Most Changes)
|
||||
|
||||
**Columns Removed in Dev (exist in backup):**
|
||||
- `ipaddress1` - Removed (now in communications table)
|
||||
- `ipaddress2` - Removed (now in communications table)
|
||||
|
||||
**Columns Added in Dev (not in backup):**
|
||||
- `hostname` - For PC hostnames
|
||||
- `serialnumber` - Equipment serial numbers
|
||||
- `loggedinuser` - Current logged-in user (PCs)
|
||||
- `pctypeid` - Identifies PCs (NULL = equipment, NOT NULL = PC)
|
||||
- `osid` - Foreign key to operatingsystems (PC OS)
|
||||
- `controllertypeid` - Foreign key to controllertypes
|
||||
- `controllerosid` - Controller OS (for CNCs)
|
||||
- `controllermodelid` - Controller model reference
|
||||
- `machinestatusid` - Replaces pcstatusid
|
||||
- `lastupdated` - Auto-updated timestamp
|
||||
- `requires_manual_machine_config` - Configuration flag
|
||||
|
||||
**Impact:** This is the core table for Phase 2 migration. Reverting will break all PC and network device functionality.
|
||||
|
||||
---
|
||||
|
||||
#### `businessunits`
|
||||
|
||||
**Columns Added in Dev (not in backup):**
|
||||
- `liaisonname` - Liaison contact name
|
||||
- `liaisonsso` - Liaison SSO
|
||||
- `facility_id` - Facility identifier
|
||||
- `dt_lead` - DT Lead name
|
||||
- `dt_lead_sso` - DT Lead SSO
|
||||
|
||||
**Impact:** Minor. These are additional metadata fields that don't affect core functionality.
|
||||
|
||||
---
|
||||
|
||||
#### `controllertypes`
|
||||
|
||||
**Columns Added in Dev (not in backup):**
|
||||
- `vendorid` - Foreign key to vendors
|
||||
- `controllermodel` - Controller model name
|
||||
- `controller_os` - Controller OS name
|
||||
- `controllernotes` - Additional notes
|
||||
|
||||
**Impact:** Minor. Enhanced metadata for CNC controllers.
|
||||
|
||||
---
|
||||
|
||||
#### `machine_overrides`
|
||||
|
||||
**Issue:** Same columns but definition differences (likely data types or constraints changed)
|
||||
|
||||
**Impact:** Unknown without detailed field-by-field comparison.
|
||||
|
||||
---
|
||||
|
||||
## New Tables in Dev (Phase 2 Migration)
|
||||
|
||||
These 8 tables exist in the current dev database but NOT in the backup file. They are **Phase 2 migration tables** and should be **preserved**.
|
||||
|
||||
### Phase 2 Tables (DO NOT DROP)
|
||||
|
||||
1. **`communications`** - Unified network interface storage (replaces pc_network_interfaces, printer IPs)
|
||||
2. **`comstypes`** - Communication types (IP, Serial, USB, etc.)
|
||||
3. **`compliance`** - Compliance tracking data
|
||||
4. **`compliancescans`** - Compliance scan history
|
||||
5. **`machinerelationships`** - Machine-to-machine relationships (dualpath, controls)
|
||||
6. **`relationshiptypes`** - Relationship type definitions
|
||||
7. **`machinestatus`** - Replaces pcstatus with broader scope
|
||||
8. **`warranties`** - Warranty tracking
|
||||
|
||||
**These tables are critical for Phase 2 functionality and should NOT be dropped.**
|
||||
|
||||
---
|
||||
|
||||
## Legacy Tables in Backup (Not in Dev)
|
||||
|
||||
These 41 tables exist in the backup file but NOT in the current dev database. Most are **deprecated** or **views**.
|
||||
|
||||
### Deprecated PC Tables (Replaced by machines + communications)
|
||||
|
||||
- `pc` - **DEPRECATED** → Replaced by machines WHERE pctypeid IS NOT NULL
|
||||
- `pc_network_interfaces` - **DEPRECATED** → Replaced by communications
|
||||
- `pc_comm_config` - **DEPRECATED** → Replaced by communications
|
||||
- `pc_dnc_config` - **DEPRECATED** → Integrated into machine relationships
|
||||
- `pc_dualpath_assignments` - **DEPRECATED** → Replaced by machinerelationships
|
||||
- `pctype` - **DEPRECATED** → Now stored in machines.pctypeid
|
||||
- `pcstatus` - **DEPRECATED** → Replaced by machinestatus
|
||||
|
||||
### Deprecated Network Device Tables (Replaced by machines)
|
||||
|
||||
- `accesspoints` - **DEPRECATED** → Replaced by machines WHERE machinetypeid = 16
|
||||
- `cameras` - **DEPRECATED** → Replaced by machines WHERE machinetypeid = 18
|
||||
- `switches` - **DEPRECATED** → Replaced by machines WHERE machinetypeid = 19
|
||||
- `servers` - **DEPRECATED** → Replaced by machines WHERE machinetypeid = 20
|
||||
- `idfs` - **DEPRECATED** → Replaced by machines WHERE machinetypeid = 17
|
||||
|
||||
### Legacy Relationship Table
|
||||
|
||||
- `machine_pc_relationships` - **DEPRECATED** → Replaced by machinerelationships
|
||||
|
||||
### Backup Table
|
||||
|
||||
- `pc_model_backup` - Backup table (can be dropped)
|
||||
|
||||
### Views (33 views)
|
||||
|
||||
All views with `vw_` prefix are query views, not base tables:
|
||||
|
||||
- `vw_active_pcs`
|
||||
- `vw_dnc_config`
|
||||
- `vw_dualpath_management`
|
||||
- `vw_engineer_pcs`
|
||||
- `vw_ge_machines`
|
||||
- `vw_idf_inventory`
|
||||
- `vw_infrastructure_summary`
|
||||
- `vw_machine_assignments`
|
||||
- `vw_machine_assignment_status`
|
||||
- `vw_machinetype_comparison`
|
||||
- `vw_machine_type_stats`
|
||||
- `vw_multi_pc_machines`
|
||||
- `vw_network_devices`
|
||||
- `vw_pc_network_summary`
|
||||
- `vw_pc_resolved_machines`
|
||||
- `vw_pcs_by_hardware`
|
||||
- `vw_pc_summary`
|
||||
- `vw_pctype_config`
|
||||
- `vw_recent_updates`
|
||||
- `vw_shopfloor_applications_summary`
|
||||
- `vw_shopfloor_comm_config`
|
||||
- `vw_shopfloor_pcs`
|
||||
- `vw_standard_pcs`
|
||||
- `vw_unmapped_machines`
|
||||
- `vw_vendor_summary`
|
||||
- `vw_warranties_expiring`
|
||||
- `vw_warranty_status`
|
||||
|
||||
**Note:** Views need to be recreated to match Phase 2 schema.
|
||||
|
||||
---
|
||||
|
||||
## Recommendation: What to Drop and Recreate
|
||||
|
||||
### CRITICAL WARNING
|
||||
|
||||
**DO NOT apply the backup file schema if you want to keep Phase 2 functionality!**
|
||||
|
||||
The backup file represents the **OLD Phase 1 schema** before the major PC migration work completed on Nov 17, 2025. Applying it would:
|
||||
|
||||
1. Lose all Phase 2 migration work (20+ days of development)
|
||||
2. Break all PC pages (displaypcs.asp, displaypc.asp, editpc.asp, etc.)
|
||||
3. Break network device display (network_map.asp, network_devices.asp)
|
||||
4. Lose unified communications table
|
||||
5. Lose machine relationships functionality
|
||||
6. Lose compliance tracking
|
||||
7. Lose warranty management
|
||||
|
||||
### If You Must Revert to Backup Schema
|
||||
|
||||
**Tables to DROP and recreate from backup:**
|
||||
|
||||
1. `machines` - DROP and recreate (loses Phase 2 columns)
|
||||
2. `businessunits` - DROP and recreate (loses liaison/facility fields)
|
||||
3. `controllertypes` - DROP and recreate (loses enhanced metadata)
|
||||
4. `machine_overrides` - DROP and recreate (definition changes)
|
||||
|
||||
**Tables to DROP from dev (Phase 2 tables):**
|
||||
|
||||
5. `communications` - DROP (then recreate from backup if needed)
|
||||
6. `comstypes` - DROP
|
||||
7. `compliance` - DROP
|
||||
8. `compliancescans` - DROP
|
||||
9. `machinerelationships` - DROP
|
||||
10. `relationshiptypes` - DROP
|
||||
11. `machinestatus` - DROP (will recreate `pcstatus` from backup)
|
||||
12. `warranties` - DROP
|
||||
|
||||
**Tables to ADD from backup (legacy tables):**
|
||||
|
||||
13. ➕ `pc` - CREATE from backup
|
||||
14. ➕ `pc_network_interfaces` - CREATE from backup
|
||||
15. ➕ `pc_comm_config` - CREATE from backup
|
||||
16. ➕ `pc_dnc_config` - CREATE from backup
|
||||
17. ➕ `pc_dualpath_assignments` - CREATE from backup
|
||||
18. ➕ `pctype` - CREATE from backup
|
||||
19. ➕ `pcstatus` - CREATE from backup
|
||||
20. ➕ `accesspoints` - CREATE from backup (if needed)
|
||||
21. ➕ `cameras` - CREATE from backup (if needed)
|
||||
22. ➕ `switches` - CREATE from backup (if needed)
|
||||
23. ➕ `servers` - CREATE from backup (if needed)
|
||||
24. ➕ `idfs` - CREATE from backup (if needed)
|
||||
25. ➕ `machine_pc_relationships` - CREATE from backup
|
||||
|
||||
**Views to recreate (33 views):** All `vw_*` views need to be dropped and recreated from backup.
|
||||
|
||||
---
|
||||
|
||||
## Recommended Action Plan
|
||||
|
||||
### Option 1: Keep Phase 2 Schema (RECOMMENDED)
|
||||
|
||||
**DO NOTHING.** Your current dev database is the latest Phase 2 schema with all improvements.
|
||||
|
||||
The backup file is outdated and should not be applied unless you need to revert Phase 2 changes.
|
||||
|
||||
### Option 2: Sync Backup File to Match Dev
|
||||
|
||||
If the backup file is supposed to be the "source of truth", then UPDATE the backup file to include Phase 2 schema:
|
||||
|
||||
1. Export current dev schema: `mysqldump shopdb > new-phase2-backup.sql`
|
||||
2. Replace old backup file with Phase 2 schema
|
||||
3. Use Phase 2 schema for future deployments
|
||||
|
||||
### Option 3: Revert to Backup Schema (NOT RECOMMENDED)
|
||||
|
||||
If you absolutely must revert to Phase 1 schema:
|
||||
|
||||
1. Backup current dev database (already done: dev-backup-20251120-105614.sql)
|
||||
2. Drop Phase 2 tables: communications, compliance, machinerelationships, etc.
|
||||
3. Restore machines, businessunits, controllertypes to backup versions
|
||||
4. Restore all legacy tables (pc, pc_network_interfaces, etc.)
|
||||
5. Recreate all views
|
||||
6. **Accept that all Phase 2 functionality will be lost**
|
||||
|
||||
---
|
||||
|
||||
## Table Count Summary
|
||||
|
||||
| Category | Backup File | Dev Database | Difference |
|
||||
|----------|-------------|--------------|------------|
|
||||
| **Total Tables** | 63 | 30 | -33 |
|
||||
| **Base Tables** | 36 | 30 | -6 |
|
||||
| **Views** | 27 | 0 | -27 |
|
||||
| **Schema Changes** | - | 4 | - |
|
||||
| **New in Dev** | - | 8 | +8 |
|
||||
| **Missing in Dev** | 41 | - | - |
|
||||
|
||||
---
|
||||
|
||||
## Files Generated
|
||||
|
||||
1. **Current Dev Backup:** `/home/camp/projects/windows/shopdb/sql/dev-backup-20251120-105614.sql` (464 KB)
|
||||
2. **This Report:** `/home/camp/projects/windows/shopdb/SCHEMA_COMPARISON_REPORT_2025-11-20.md`
|
||||
|
||||
---
|
||||
|
||||
## Conclusion
|
||||
|
||||
**The backup file (database-backup-11-20-25-eod-with-drop.sql) is from BEFORE Phase 2 migration.**
|
||||
|
||||
Your current dev database has the **Phase 2 schema** with significant improvements:
|
||||
- Unified machines table for all infrastructure
|
||||
- Consolidated communications table
|
||||
- Machine relationships tracking
|
||||
- Compliance management
|
||||
- Warranty tracking
|
||||
|
||||
**Recommendation:** Do NOT apply the backup file schema. Keep your current Phase 2 dev schema.
|
||||
|
||||
If production needs updating, use your current dev schema as the source, not the backup file.
|
||||
|
||||
---
|
||||
|
||||
**Generated:** 2025-11-20 10:56
|
||||
**Analyst:** Claude Code
|
||||
**Status:** Analysis Complete
|
||||
417
docs/archive/sessions/SESSION_SUMMARY_2025-11-10.md
Normal file
417
docs/archive/sessions/SESSION_SUMMARY_2025-11-10.md
Normal file
@@ -0,0 +1,417 @@
|
||||
# Session Summary - 2025-11-10
|
||||
|
||||
**Session Focus:** Machine Relationships Fixes + Printer Modernization + Phase 3 Planning
|
||||
|
||||
---
|
||||
|
||||
## Work Completed
|
||||
|
||||
### 1. **Fixed Machine Relationship Display Issues**
|
||||
|
||||
**Problem:** Machine 195 showed relationship to 5274, but 5274 didn't show relationship back to 195.
|
||||
|
||||
**Root Cause:**
|
||||
- displaymachine.asp only showed ONE direction of relationships
|
||||
- Missing reverse lookup for "machines this machine controls"
|
||||
|
||||
**Files Modified:**
|
||||
- `/home/camp/projects/windows/shopdb/displaymachine.asp`
|
||||
|
||||
**Changes Made:**
|
||||
1. Added new section "Machines Controlled by This Machine" (lines 416-467)
|
||||
- Shows which machines THIS machine controls (reverse relationship)
|
||||
- Query: `WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls'`
|
||||
|
||||
2. Updated "Controlled By PC" section (line 386)
|
||||
- Now handles both 'Controls' and 'Controlled By' relationship types
|
||||
- Query: `WHERE mr.related_machineid = ? AND (rt.relationshiptype = 'Controls' OR rt.relationshiptype = 'Controlled By')`
|
||||
|
||||
3. Fixed machine type display (lines 436, 489)
|
||||
- Changed JOIN from `models.machinetypeid` to `machines.machinetypeid`
|
||||
- Now correctly shows "Vertical Lathe" instead of "N/A"
|
||||
|
||||
4. Fixed controlling PC IP address display (line 385)
|
||||
- Added filter: `c.comstypeid IN (1, 3)` for IP-based communications only
|
||||
- Removed `isprimary = 1` filter
|
||||
- Added `GROUP BY` to avoid duplicates
|
||||
|
||||
**Testing Results:**
|
||||
- Machine 195 shows: "Controlled by 5274 (GJBJC724ESF)" with IP 192.168.1.2
|
||||
- Machine 5274 shows: "Controls 195 (2014)" and "Controls 133 (2013)"
|
||||
- Machine types display correctly as "Vertical Lathe"
|
||||
- Bidirectional relationships working
|
||||
|
||||
---
|
||||
|
||||
### 2. **Modernized Printer Management Pages**
|
||||
|
||||
**Goal:** Match printer pages to machine/PC pages' look and feel
|
||||
|
||||
**Pages Reviewed:**
|
||||
|
||||
#### displayprinters.asp (List Page)
|
||||
- **Status:** Already modern
|
||||
- Bootstrap theme, responsive table, modern icons
|
||||
|
||||
#### displayprinter.asp (View Page)
|
||||
- **Status:** Already modern
|
||||
- Tabbed interface (Settings, Edit)
|
||||
- Profile card with printer image
|
||||
- Nested entity creation (vendor, model)
|
||||
|
||||
#### editprinter.asp (Backend Processor)
|
||||
- **Status:** MODERNIZED THIS SESSION
|
||||
|
||||
**Changes to editprinter.asp:**
|
||||
|
||||
**Before (Old Style):**
|
||||
```asp
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="./style.css" type="text/css">
|
||||
Response.Write("<div class='alert alert-danger'>Error</div>")
|
||||
Response.Write("<a href='...'>Go back</a>")
|
||||
```
|
||||
|
||||
**After (Modern):**
|
||||
```asp
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!--#include file="./includes/header.asp"-->
|
||||
<!--#include file="./includes/sql.asp"-->
|
||||
Response.Redirect("displayprinter.asp?printerid=X&error=CODE")
|
||||
```
|
||||
|
||||
**Improvements:**
|
||||
1. Bootstrap theme with modern includes
|
||||
2. HTML5 DOCTYPE
|
||||
3. Error handling via redirects (not inline HTML)
|
||||
4. Success redirect with `?success=1` parameter
|
||||
5. Fallback page with Bootstrap styling
|
||||
6. All security features preserved (parameterized queries, validation)
|
||||
|
||||
**Error Codes Added:**
|
||||
- `INVALID_PRINTER_ID`
|
||||
- `INVALID_MODEL_ID`
|
||||
- `INVALID_MACHINE_ID`
|
||||
- `FIELD_LENGTH_EXCEEDED`
|
||||
- `MODEL_REQUIRED`
|
||||
- `VENDOR_REQUIRED`
|
||||
- `MODEL_FIELD_LENGTH_EXCEEDED`
|
||||
- `VENDOR_NAME_REQUIRED`
|
||||
- `VENDOR_NAME_TOO_LONG`
|
||||
- `VENDOR_CREATE_FAILED`
|
||||
- `MODEL_CREATE_FAILED`
|
||||
- `UPDATE_FAILED`
|
||||
|
||||
**Testing:**
|
||||
- displayprinters.asp - HTTP 200
|
||||
- displayprinter.asp - HTTP 200, tabs functional
|
||||
- editprinter.asp - Modernized and working
|
||||
|
||||
---
|
||||
|
||||
### 3. **Phase 3 Migration Planning**
|
||||
|
||||
**Decision:** Consolidate ALL network devices into `machines` table (except printers)
|
||||
|
||||
#### Devices to Migrate:
|
||||
- Servers → machinetypeid 30
|
||||
- Switches → machinetypeid 31
|
||||
- Cameras → machinetypeid 32
|
||||
- Access Points → machinetypeid 33
|
||||
- IDFs → machinetypeid 34
|
||||
- Routers → machinetypeid 35
|
||||
- Firewalls → machinetypeid 36
|
||||
|
||||
#### Keep Separate:
|
||||
- Printers (unique fields, workflows, APIs)
|
||||
|
||||
#### Why This Architecture?
|
||||
|
||||
**machines table will contain:**
|
||||
```
|
||||
├── Equipment (machinetypeid 1-24, pctypeid IS NULL)
|
||||
├── PCs (machinetypeid 25-29, pctypeid IS NOT NULL)
|
||||
└── Network Devices (machinetypeid 30-36, pctypeid IS NULL)
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
1. Single source of truth for all infrastructure
|
||||
2. Unified relationships (Camera → Switch → IDF using machinerelationships)
|
||||
3. Unified communications (all IPs in one table)
|
||||
4. Consistent UI (one set of pages for all devices)
|
||||
5. Powerful queries (cross-device reports, topology mapping)
|
||||
6. Better compliance tracking
|
||||
|
||||
#### Example Relationship Structure:
|
||||
```
|
||||
IDF-Building-A (machinetypeid 34)
|
||||
└── Connected To: Switch-Core-01 (machinetypeid 31)
|
||||
├── Connected To: Camera-Shop-01 (machinetypeid 32)
|
||||
├── Connected To: Camera-Shop-02 (machinetypeid 32)
|
||||
├── Connected To: Server-01 (machinetypeid 30)
|
||||
└── Connected To: PC-5274 (machinetypeid 29)
|
||||
└── Controls: Machine-2001 (machinetypeid 8)
|
||||
```
|
||||
|
||||
**All using the SAME machinerelationships table!**
|
||||
|
||||
---
|
||||
|
||||
## Documents Created
|
||||
|
||||
1. **PRINTER_PAGES_MODERNIZATION_2025-11-10.md**
|
||||
- Complete summary of printer page modernization
|
||||
- Before/after comparisons
|
||||
- Testing results
|
||||
|
||||
2. **PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md**
|
||||
- Comprehensive migration plan
|
||||
- Architecture design
|
||||
- Data mapping
|
||||
- Risk assessment
|
||||
- Timeline estimate (10-15 hours total work)
|
||||
|
||||
3. **SESSION_SUMMARY_2025-11-10.md** (this document)
|
||||
- Complete session overview
|
||||
- All changes and decisions documented
|
||||
|
||||
---
|
||||
|
||||
## Migration Scripts Started
|
||||
|
||||
Created directory structure:
|
||||
```
|
||||
/home/camp/projects/windows/shopdb/sql/migration_phase3/
|
||||
├── 01_create_network_machinetypes.sql CREATED
|
||||
├── 02_migrate_servers_to_machines.sql (next)
|
||||
├── 03_migrate_switches_to_machines.sql (next)
|
||||
├── 04_migrate_cameras_to_machines.sql (next)
|
||||
├── 05_migrate_accesspoints_to_machines.sql (next)
|
||||
├── 06_migrate_idfs_to_machines.sql (next)
|
||||
├── 07_migrate_network_communications.sql (next)
|
||||
├── 08_create_network_relationships.sql (next)
|
||||
├── 09_update_views_for_network_devices.sql (next)
|
||||
├── 10_update_vendor_flags.sql (next)
|
||||
├── VERIFY_PHASE3_MIGRATION.sql (next)
|
||||
├── RUN_ALL_PHASE3_SCRIPTS.sql (next)
|
||||
└── ROLLBACK_PHASE3.sql (next)
|
||||
```
|
||||
|
||||
**Script 01 Created:**
|
||||
- Adds machinetypes 30-36 for network devices
|
||||
- Includes verification queries
|
||||
- Shows machine type structure
|
||||
|
||||
---
|
||||
|
||||
## New Relationship Types Planned
|
||||
|
||||
```sql
|
||||
-- Existing
|
||||
('Dualpath', 'Machines sharing the same controller', 1)
|
||||
('Controls', 'PC controls this machine', 0)
|
||||
|
||||
-- Planned for Phase 3
|
||||
('Connected To', 'Device physically connected to infrastructure', 0)
|
||||
('Powered By', 'Device powered by this power source', 0)
|
||||
('Mounted In', 'Device mounted in rack/cabinet', 0)
|
||||
('Feeds Video To', 'Camera feeds video to this server/NVR', 0)
|
||||
('Provides Network', 'Infrastructure provides network to device', 0)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Filtering Strategy After Phase 3
|
||||
|
||||
```sql
|
||||
-- All PCs
|
||||
SELECT * FROM machines WHERE pctypeid IS NOT NULL;
|
||||
|
||||
-- All Equipment
|
||||
SELECT * FROM machines
|
||||
WHERE pctypeid IS NULL AND machinetypeid BETWEEN 1 AND 24;
|
||||
|
||||
-- All Network Devices
|
||||
SELECT * FROM machines
|
||||
WHERE pctypeid IS NULL AND machinetypeid BETWEEN 30 AND 36;
|
||||
|
||||
-- Specific types
|
||||
SELECT * FROM machines WHERE machinetypeid = 30; -- Servers
|
||||
SELECT * FROM machines WHERE machinetypeid = 31; -- Switches
|
||||
SELECT * FROM machines WHERE machinetypeid = 32; -- Cameras
|
||||
|
||||
-- All infrastructure (everything except printers)
|
||||
SELECT * FROM machines;
|
||||
|
||||
-- Cross-device query example
|
||||
SELECT m.*, mt.machinetype, c.address AS ipaddress
|
||||
FROM machines m
|
||||
JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid
|
||||
WHERE c.address LIKE '192.168.1.%'
|
||||
ORDER BY mt.category, m.machinenumber;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Code Updates Required (Post-Migration)
|
||||
|
||||
### Pages to Update:
|
||||
1. **displaymachines.asp** - Add network device filter tabs
|
||||
2. **machine_edit.asp** - Already supports all types
|
||||
3. **displaymachine.asp** - Already supports all types
|
||||
4. **adddevice.asp** - Add network device types
|
||||
|
||||
### Pages to Deprecate:
|
||||
1. **displayservers.asp** → Redirect to displaymachines.asp?type=server
|
||||
2. **displayswitches.asp** → Redirect to displaymachines.asp?type=switch
|
||||
3. **displaycameras.asp** → Redirect to displaymachines.asp?type=camera
|
||||
4. **network_devices.asp** → Redirect to displaymachines.asp?category=network
|
||||
|
||||
---
|
||||
|
||||
## Timeline Estimate for Phase 3
|
||||
|
||||
- **Planning & Plan Document:** 2 hours (COMPLETED)
|
||||
- **Script 01 Creation:** 30 minutes (COMPLETED)
|
||||
- **Remaining Scripts:** 1.5 hours
|
||||
- **Testing on Backup:** 1-2 hours
|
||||
- **Production Migration:** 30-45 minutes
|
||||
- **Verification:** 1 hour
|
||||
- **Code Updates:** 3-4 hours
|
||||
- **Testing & Bug Fixes:** 2-3 hours
|
||||
|
||||
**Total:** ~10-15 hours (2-3 hours completed)
|
||||
|
||||
---
|
||||
|
||||
## Risk Assessment
|
||||
|
||||
### Low Risk:
|
||||
- Pattern proven with Phase 2 PC migration (successful)
|
||||
- Can be rolled back easily
|
||||
- Old tables kept temporarily
|
||||
- Comprehensive verification planned
|
||||
|
||||
### Mitigation:
|
||||
- Test on backup database first
|
||||
- Migrate one device type at a time
|
||||
- Verify after each migration
|
||||
- Keep old tables for 30 days
|
||||
- Update code incrementally
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
### Immediate (Next Session):
|
||||
1. ⏭ Complete remaining migration scripts (02-10)
|
||||
2. ⏭ Create VERIFY_PHASE3_MIGRATION.sql
|
||||
3. ⏭ Create RUN_ALL_PHASE3_SCRIPTS.sql
|
||||
4. ⏭ Create ROLLBACK_PHASE3.sql
|
||||
5. ⏭ Test scripts on backup database
|
||||
|
||||
### After Testing:
|
||||
1. ⏭ Review and approve migration
|
||||
2. ⏭ Schedule maintenance window
|
||||
3. ⏭ Execute Phase 3 migration
|
||||
4. ⏭ Verify data integrity
|
||||
5. ⏭ Update UI code
|
||||
6. ⏭ Test all device types
|
||||
7. ⏭ Monitor for 30 days
|
||||
8. ⏭ Drop old tables (if stable)
|
||||
|
||||
---
|
||||
|
||||
## Success Metrics
|
||||
|
||||
### Completed This Session:
|
||||
- Machine relationships fixed (bidirectional display)
|
||||
- Machine type display fixed
|
||||
- PC IP address display fixed
|
||||
- Printer pages modernized
|
||||
- Phase 3 migration plan created
|
||||
- Script 01 created (machinetypes)
|
||||
|
||||
### Phase 3 Success Criteria:
|
||||
1. All network device records migrated (counts match)
|
||||
2. All IP addresses in communications table
|
||||
3. All relationships preserved
|
||||
4. Camera → IDF relationships working
|
||||
5. UI displays all device types correctly
|
||||
6. No data loss
|
||||
7. Rollback tested
|
||||
8. Performance acceptable
|
||||
|
||||
---
|
||||
|
||||
## Key Decisions Made
|
||||
|
||||
1. **Consolidate network devices into machines table**
|
||||
- Rationale: Unified data model, better relationships, less code duplication
|
||||
|
||||
2. **Keep printers separate**
|
||||
- Rationale: Unique fields (toner, drivers, CSF names), special APIs, different workflow
|
||||
|
||||
3. **Use machinetypeid 30-36 for network devices**
|
||||
- Rationale: Clear separation, easy filtering, extensible
|
||||
|
||||
4. **Use machinerelationships for ALL device relationships**
|
||||
- Rationale: Camera → Switch → IDF, unified topology, powerful queries
|
||||
|
||||
5. **Follow Phase 2 migration pattern**
|
||||
- Rationale: Proven successful, well-tested, documented
|
||||
|
||||
---
|
||||
|
||||
## Questions Answered
|
||||
|
||||
**Q:** "Should we just use machines for all types of devices besides printer?"
|
||||
**A:** YES! Excellent idea. Consolidate servers, switches, cameras, access points, IDFs into machines. Keep printers separate (too unique).
|
||||
|
||||
**Q:** "Can't we use the same table that machines use to define what pc they're associated with?"
|
||||
**A:** YES! Use the SAME `machinerelationships` table for Camera → IDF relationships using 'Connected To' relationship type.
|
||||
|
||||
---
|
||||
|
||||
## Files Modified This Session
|
||||
|
||||
1. `/home/camp/projects/windows/shopdb/displaymachine.asp`
|
||||
- Added "Machines Controlled by This Machine" section
|
||||
- Fixed machine type display
|
||||
- Fixed PC IP address display
|
||||
|
||||
2. `/home/camp/projects/windows/shopdb/editprinter.asp`
|
||||
- Complete modernization with Bootstrap theme
|
||||
- Improved error handling
|
||||
- Modern includes
|
||||
|
||||
3. `/home/camp/projects/windows/shopdb/docs/PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md`
|
||||
- New file - comprehensive migration plan
|
||||
|
||||
4. `/home/camp/projects/windows/shopdb/docs/PRINTER_PAGES_MODERNIZATION_2025-11-10.md`
|
||||
- New file - printer modernization summary
|
||||
|
||||
5. `/home/camp/projects/windows/shopdb/sql/migration_phase3/01_create_network_machinetypes.sql`
|
||||
- New file - adds machinetypes 30-36
|
||||
|
||||
---
|
||||
|
||||
## Session Statistics
|
||||
|
||||
- **Duration:** ~3 hours
|
||||
- **Files Modified:** 2
|
||||
- **Files Created:** 5 (3 docs + 1 SQL script + 1 directory)
|
||||
- **Bugs Fixed:** 4 (relationships, machine type, IP display, printer backend)
|
||||
- **Features Added:** 1 (reverse relationship display)
|
||||
- **Planning Documents:** 2
|
||||
- **Migration Scripts:** 1 of 13 created
|
||||
|
||||
---
|
||||
|
||||
**Status:** Session complete. Ready to continue with remaining Phase 3 migration scripts in next session.
|
||||
|
||||
**Recommendation:** Test Script 01 on backup database before proceeding with Scripts 02-10.
|
||||
686
docs/archive/sessions/SESSION_SUMMARY_2025-11-13.md
Normal file
686
docs/archive/sessions/SESSION_SUMMARY_2025-11-13.md
Normal file
@@ -0,0 +1,686 @@
|
||||
# Development Session Summary - November 13, 2025
|
||||
|
||||
**Date:** 2025-11-13
|
||||
**Session Duration:** Multiple hours
|
||||
**Environment:** DEV Server (http://192.168.122.151:8080/)
|
||||
**Primary Focus:** Phase 2 testing continuation, network_map.asp updates, network device infrastructure
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
This session was a continuation of Phase 2 PC migration testing. The main accomplishments were:
|
||||
1. Completed Phase 2 testing and bug fixes
|
||||
2. Enhanced network_map.asp to show all network device types
|
||||
3. Updated vw_network_devices view to support both separate tables and machines table
|
||||
4. Created and tested sample network infrastructure data
|
||||
5. Simplified displaypcs.asp table columns
|
||||
|
||||
---
|
||||
|
||||
## 1. Phase 2 Testing Completion
|
||||
|
||||
### Context
|
||||
- Continued from previous session where Phase 2 PC migration had been completed
|
||||
- User requested comprehensive testing of all pages, including edit and add pages
|
||||
- Total of 123 ASP files needed testing
|
||||
|
||||
### Testing Results
|
||||
|
||||
**Pages Tested:** 15 out of 123
|
||||
|
||||
** PASSED - Critical PC Pages:**
|
||||
- displaypcs.asp
|
||||
- displaypc.asp
|
||||
- displaymachines.asp
|
||||
- displaymachine.asp
|
||||
- adddevice.asp
|
||||
- savedevice.asp
|
||||
- savedevice_direct.asp
|
||||
- editdevice.asp (after fix)
|
||||
- updatedevice.asp (after migration)
|
||||
- updatedevice_direct.asp (after migration)
|
||||
- check_all_warranties.asp
|
||||
- check_all_warranties_clean.asp
|
||||
- network_map.asp (after enhancements)
|
||||
- network_devices.asp
|
||||
|
||||
** Issues Found:**
|
||||
- displaysubnet.asp - Runtime error (subscript out of range) - NOT FIXED
|
||||
- 3 warranty pages in v2 directory using old schema - NOT FIXED
|
||||
|
||||
### Bugs Fixed During Session
|
||||
|
||||
#### Bug 1: editdevice.asp - Undefined Variable (Line 95)
|
||||
**File:** editdevice.asp
|
||||
**Issue:** Used undefined variable `pcid`
|
||||
**Fix:** Changed to `machineid`
|
||||
|
||||
```asp
|
||||
' OLD (line 95):
|
||||
<input type="hidden" name="pcid" value="<%=pcid%>">
|
||||
|
||||
' NEW:
|
||||
<input type="hidden" name="pcid" value="<%=machineid%>">
|
||||
```
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
#### Bug 2: updatedevice.asp - Phase 2 Schema Migration
|
||||
**File:** updatedevice.asp
|
||||
**Issue:** Still using old `pc` table instead of Phase 2 `machines` table
|
||||
**Changes Made:**
|
||||
|
||||
```asp
|
||||
' Variable declaration (line 11):
|
||||
' OLD: Dim pcid, pcstatusid, pctypeid, ...
|
||||
' NEW: Dim pcid, machinestatusid, pctypeid, ...
|
||||
|
||||
' Form data retrieval (line 14):
|
||||
' OLD: pcstatusid = Trim(Request.Form("pcstatusid"))
|
||||
' NEW: machinestatusid = Trim(Request.Form("machinestatusid"))
|
||||
|
||||
' Validation (line 26):
|
||||
' OLD: If Not ValidateID(pcstatusid) Then
|
||||
' NEW: If Not ValidateID(machinestatusid) Then
|
||||
|
||||
' Record exists check (line 31):
|
||||
' OLD: If Not RecordExists(objConn, "pc", "pcid", pcid) Then
|
||||
' NEW: If Not RecordExists(objConn, "machines", "machineid", pcid) Then
|
||||
|
||||
' UPDATE query (line 64):
|
||||
' OLD: updateSQL = "UPDATE pc SET pcstatusid = ?, isactive = ?, "
|
||||
' NEW: updateSQL = "UPDATE machines SET machinestatusid = ?, isactive = ?, "
|
||||
|
||||
' WHERE clause (line 118):
|
||||
' OLD: updateSQL = updateSQL & "lastupdated = NOW() WHERE pcid = ?"
|
||||
' NEW: updateSQL = updateSQL & "lastupdated = NOW() WHERE machineid = ? AND pctypeid IS NOT NULL"
|
||||
```
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
#### Bug 3: updatedevice_direct.asp - Phase 2 Schema Migration
|
||||
**File:** updatedevice_direct.asp
|
||||
**Issue:** Still using old `pc` table instead of Phase 2 `machines` table
|
||||
**Changes Made:**
|
||||
|
||||
```asp
|
||||
' Variable declaration (line 12):
|
||||
' OLD: Dim pcid, pcstatusid, pctypeid, ...
|
||||
' NEW: Dim pcid, machinestatusid, pctypeid, ...
|
||||
|
||||
' Form data (line 15):
|
||||
' OLD: pcstatusid = Trim(Request.Form("pcstatusid"))
|
||||
' NEW: machinestatusid = Trim(Request.Form("machinestatusid"))
|
||||
|
||||
' Validation (line 38):
|
||||
' OLD: If Not IsNumeric(pcstatusid) Or CLng(pcstatusid) < 1 Then
|
||||
' NEW: If Not IsNumeric(machinestatusid) Or CLng(machinestatusid) < 1 Then
|
||||
|
||||
' UPDATE query (line 176):
|
||||
' OLD: updateSQL = "UPDATE pc SET pcstatusid = ?, ... WHERE pcid = ?"
|
||||
' NEW: updateSQL = "UPDATE machines SET machinestatusid = ?, ... WHERE machineid = ? AND pctypeid IS NOT NULL"
|
||||
|
||||
' Parameters (line 181):
|
||||
' OLD: cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@pcstatusid", 3, 1, , CLng(pcstatusid))
|
||||
' NEW: cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machinestatusid", 3, 1, , CLng(machinestatusid))
|
||||
|
||||
' Final parameter (line 212):
|
||||
' OLD: cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@pcid", 3, 1, , CLng(pcid))
|
||||
' NEW: cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machineid", 3, 1, , CLng(pcid))
|
||||
```
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
---
|
||||
|
||||
## 2. Network Map Enhancement
|
||||
|
||||
### Issue Reported
|
||||
User reported: "it's not showing the other types of network devices, just printers"
|
||||
|
||||
### Investigation
|
||||
- Initially investigated separate tables (servers, switches, cameras, accesspoints, idfs)
|
||||
- Found these tables were EMPTY (0 records)
|
||||
- Discovered network devices are stored in `machines` table with specific `machinetypeid` values:
|
||||
- Access Point: machinetypeid = 16
|
||||
- IDF: machinetypeid = 17
|
||||
- Camera: machinetypeid = 18
|
||||
- Switch: machinetypeid = 19
|
||||
- Server: machinetypeid = 20
|
||||
|
||||
### Fix Applied: network_map.asp
|
||||
|
||||
**File:** network_map.asp (lines 223-255)
|
||||
|
||||
**OLD Query:** Only queried separate empty tables for each device type
|
||||
|
||||
**NEW Query:** Replaced all separate table queries with single unified query from machines table
|
||||
|
||||
```asp
|
||||
strSQL = "SELECT printers.printerid AS id, machines.machinenumber AS name, machines.alias, " &_
|
||||
"printers.mapleft, printers.maptop, printers.ipaddress, NULL AS machinetypeid, " &_
|
||||
"'Printer' AS type, models.modelnumber, vendors.vendor, 'printers' AS source " &_
|
||||
"FROM printers " &_
|
||||
"INNER JOIN machines ON printers.machineid = machines.machineid " &_
|
||||
"LEFT JOIN models ON printers.modelid = models.modelnumberid " &_
|
||||
"LEFT JOIN vendors ON models.vendorid = vendors.vendorid " &_
|
||||
"WHERE printers.isactive = 1 " &_
|
||||
"AND printers.mapleft IS NOT NULL " &_
|
||||
"AND printers.maptop IS NOT NULL " &_
|
||||
"" &_
|
||||
"UNION ALL " &_
|
||||
"" &_
|
||||
"SELECT m.machineid AS id, m.machinenumber AS name, m.alias, " &_
|
||||
"m.mapleft, m.maptop, c.address AS ipaddress, m.machinetypeid, " &_
|
||||
"mt.machinetype AS type, mo.modelnumber, v.vendor, 'machines' AS source " &_
|
||||
"FROM machines m " &_
|
||||
"INNER JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid " &_
|
||||
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " &_
|
||||
"LEFT JOIN vendors v ON mo.vendorid = v.vendorid " &_
|
||||
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " &_
|
||||
"WHERE mt.machinetypeid IN (16, 17, 18, 19, 20) " &_
|
||||
"AND m.isactive = 1 " &_
|
||||
"AND m.mapleft IS NOT NULL " &_
|
||||
"AND m.maptop IS NOT NULL " &_
|
||||
"" &_
|
||||
"ORDER BY type, name ASC"
|
||||
```
|
||||
|
||||
**Key Changes:**
|
||||
1. Removed separate queries for servers, switches, cameras, accesspoints, idfs tables
|
||||
2. Added single UNION ALL query for machines table filtering by machinetypeid IN (16,17,18,19,20)
|
||||
3. Fixed column name: `accesspoints.accesspointid` → `accesspoints.apid` (was causing SQL error)
|
||||
4. Updated detail URL routing (lines 420-430) to handle all device types from machines table
|
||||
|
||||
**Also Updated:** Detail page URL routing
|
||||
|
||||
```javascript
|
||||
// OLD:
|
||||
if (sourceTable === 'printers') {
|
||||
detailUrl = './displayprinter.asp?printerid=' + machineId;
|
||||
} else if (sourceTable === 'machines') {
|
||||
detailUrl = './displaymachine.asp?machineid=' + machineId;
|
||||
} else {
|
||||
detailUrl = './network_devices.asp';
|
||||
}
|
||||
|
||||
// NEW:
|
||||
if (sourceTable === 'printers') {
|
||||
detailUrl = './displayprinter.asp?printerid=' + machineId;
|
||||
} else if (sourceTable === 'machines') {
|
||||
detailUrl = './displaymachine.asp?machineid=' + machineId;
|
||||
} else if (sourceTable === 'servers') {
|
||||
detailUrl = './displayserver.asp?id=' + machineId;
|
||||
} else if (sourceTable === 'switches') {
|
||||
detailUrl = './displayswitch.asp?id=' + machineId;
|
||||
} else if (sourceTable === 'cameras') {
|
||||
detailUrl = './displaycamera.asp?id=' + machineId;
|
||||
} else if (sourceTable === 'accesspoints') {
|
||||
detailUrl = './displayaccesspoint.asp?id=' + machineId;
|
||||
} else if (sourceTable === 'idfs') {
|
||||
detailUrl = './displayidf.asp?id=' + machineId;
|
||||
} else {
|
||||
detailUrl = './network_devices.asp';
|
||||
}
|
||||
```
|
||||
|
||||
**Result:** Network map now correctly queries and displays network devices from machines table
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
---
|
||||
|
||||
## 3. Database View Update - vw_network_devices
|
||||
|
||||
### Issue
|
||||
User reported: "I don't see any of these devices popping up in network devices lists"
|
||||
|
||||
### Root Cause
|
||||
The `vw_network_devices` view only queried separate empty tables, not the machines table where network devices with machinetypeid 16-20 are stored.
|
||||
|
||||
### Fix Applied
|
||||
|
||||
**File Created:** `/home/camp/projects/windows/shopdb/sql/update_vw_network_devices_view.sql`
|
||||
|
||||
**Changes:**
|
||||
- Dropped and recreated `vw_network_devices` view
|
||||
- Added UNION ALL query to include devices from machines table with machinetypeid IN (16,17,18,19,20)
|
||||
- Now view queries BOTH separate tables AND machines table
|
||||
|
||||
**New View Structure:**
|
||||
```sql
|
||||
CREATE VIEW vw_network_devices AS
|
||||
-- IDFs from separate table
|
||||
SELECT 'IDF' AS device_type, ...
|
||||
FROM idfs
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Servers from separate table
|
||||
SELECT 'Server' AS device_type, ...
|
||||
FROM servers
|
||||
LEFT JOIN models...
|
||||
LEFT JOIN vendors...
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Switches from separate table
|
||||
SELECT 'Switch' AS device_type, ...
|
||||
FROM switches
|
||||
LEFT JOIN models...
|
||||
LEFT JOIN vendors...
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Cameras from separate table
|
||||
SELECT 'Camera' AS device_type, ...
|
||||
FROM cameras
|
||||
LEFT JOIN models...
|
||||
LEFT JOIN vendors...
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Access Points from separate table
|
||||
SELECT 'Access Point' AS device_type, ...
|
||||
FROM accesspoints
|
||||
LEFT JOIN models...
|
||||
LEFT JOIN vendors...
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Printers from separate table
|
||||
SELECT 'Printer' AS device_type, ...
|
||||
FROM printers
|
||||
LEFT JOIN models...
|
||||
LEFT JOIN vendors...
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Network devices from machines table (NEW!)
|
||||
SELECT
|
||||
mt.machinetype AS device_type,
|
||||
ma.machineid AS device_id,
|
||||
COALESCE(ma.alias, ma.machinenumber) AS device_name,
|
||||
ma.modelnumberid AS modelid,
|
||||
mo.modelnumber,
|
||||
ve.vendor,
|
||||
ma.serialnumber,
|
||||
c.address AS ipaddress,
|
||||
NULL AS description,
|
||||
ma.maptop,
|
||||
ma.mapleft,
|
||||
ma.isactive,
|
||||
NULL AS idfid,
|
||||
NULL AS idfname,
|
||||
NULL AS macaddress
|
||||
FROM machines ma
|
||||
INNER JOIN machinetypes mt ON ma.machinetypeid = mt.machinetypeid
|
||||
LEFT JOIN models mo ON ma.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors ve ON mo.vendorid = ve.vendorid
|
||||
LEFT JOIN communications c ON ma.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1
|
||||
WHERE mt.machinetypeid IN (16, 17, 18, 19, 20);
|
||||
```
|
||||
|
||||
**Result:**
|
||||
- network_devices.asp now shows devices from both separate tables AND machines table
|
||||
- Supports future addition of network devices in either location
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
---
|
||||
|
||||
## 4. Sample Network Device Creation & Removal
|
||||
|
||||
### Purpose
|
||||
User requested: "i need example switches, idf, cameras"
|
||||
|
||||
### Created Sample Data
|
||||
|
||||
**File Created:** `/home/camp/projects/windows/shopdb/sql/create_sample_network_devices.sql`
|
||||
|
||||
**Devices Created (25 total):**
|
||||
|
||||
**Switches (5):**
|
||||
- SW-CORE-01 (Core Switch 1) - 1200, 800
|
||||
- SW-DIST-01 (Distribution Switch 1) - 1400, 900
|
||||
- SW-ACCESS-01 (Access Switch 1) - 1600, 1000
|
||||
- SW-ACCESS-02 (Access Switch 2) - 800, 1200
|
||||
- SW-OFFICE-01 (Office Switch) - 1800, 1500
|
||||
|
||||
**Servers (5):**
|
||||
- SRV-DC-01 (Domain Controller 1) - 1100, 700
|
||||
- SRV-SQL-01 (SQL Database Server) - 1300, 750
|
||||
- SRV-FILE-01 (File Server) - 1500, 800
|
||||
- SRV-WEB-01 (Web Application Server) - 1700, 850
|
||||
- SRV-BACKUP-01 (Backup Server) - 900, 650
|
||||
|
||||
**Cameras (6):**
|
||||
- CAM-ENTRY-01 (Main Entry Camera) - 600, 1800
|
||||
- CAM-SHIPPING-01 (Shipping Dock Camera) - 2000, 600
|
||||
- CAM-FLOOR-01 (Shop Floor Camera 1) - 1500, 1200
|
||||
- CAM-FLOOR-02 (Shop Floor Camera 2) - 1800, 1400
|
||||
- CAM-OFFICE-01 (Office Area Camera) - 1200, 1900
|
||||
- CAM-PARKING-01 (Parking Lot Camera) - 400, 2000
|
||||
|
||||
**Access Points (5):**
|
||||
- AP-OFFICE-01 (Office Access Point 1) - 1100, 1800
|
||||
- AP-OFFICE-02 (Office Access Point 2) - 1700, 1800
|
||||
- AP-SHOP-01 (Shop Floor AP 1) - 1200, 1100
|
||||
- AP-SHOP-02 (Shop Floor AP 2) - 1600, 1300
|
||||
- AP-WAREHOUSE-01 (Warehouse Access Point) - 2100, 800
|
||||
|
||||
**IDFs (4):**
|
||||
- IDF-MAIN (Main IDF Room) - 1150, 750
|
||||
- IDF-EAST (East Wing IDF) - 1900, 1200
|
||||
- IDF-WEST (West Wing IDF) - 700, 1300
|
||||
- IDF-SHOP (Shop Floor IDF) - 1500, 1000
|
||||
|
||||
**IP Addresses Added:**
|
||||
- SW-CORE-01: 10.80.1.1
|
||||
- SRV-DC-01: 10.80.1.10
|
||||
- SRV-SQL-01: 10.80.1.11
|
||||
- CAM-ENTRY-01: 10.80.2.50
|
||||
- AP-OFFICE-01: 10.80.3.100
|
||||
|
||||
**Verification:**
|
||||
- All 25 devices appeared in network_devices.asp
|
||||
- All 25 devices appeared on network_map.asp with colored markers
|
||||
- Total markers on map: 62 (37 printers + 25 network devices)
|
||||
|
||||
### Sample Data Removal
|
||||
|
||||
**File Created:** `/home/camp/projects/windows/shopdb/sql/remove_sample_network_devices.sql`
|
||||
|
||||
**User Request:** "much better, can we remove these test devices now?"
|
||||
|
||||
**Removal Process:**
|
||||
1. Deleted communications entries for sample devices
|
||||
2. Deleted all 25 sample machines by machinenumber
|
||||
|
||||
**Result:**
|
||||
- Database returned to original state
|
||||
- Only 38 printers remain in vw_network_devices
|
||||
- System proven ready for real network device data
|
||||
|
||||
**Status:** Created, Tested, and Removed
|
||||
|
||||
---
|
||||
|
||||
## 5. UI Simplification - displaypcs.asp
|
||||
|
||||
### User Request
|
||||
"displaypcs.asp shows an ip column, can we delete that along with Machines column"
|
||||
|
||||
### Changes Made
|
||||
|
||||
**File:** displaypcs.asp
|
||||
|
||||
**Table Header (lines 103-110):**
|
||||
```asp
|
||||
' OLD:
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Hostname</th>
|
||||
<th scope="col">Serial</th>
|
||||
<th scope="col">IP</th> <!-- REMOVED -->
|
||||
<th scope="col">Model</th>
|
||||
<th scope="col">OS</th>
|
||||
<th scope="col">Machine</th> <!-- REMOVED -->
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
' NEW:
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Hostname</th>
|
||||
<th scope="col">Serial</th>
|
||||
<th scope="col">Model</th>
|
||||
<th scope="col">OS</th>
|
||||
</tr>
|
||||
</thead>
|
||||
```
|
||||
|
||||
**Table Data Rows (lines 163-175):**
|
||||
```asp
|
||||
' OLD:
|
||||
<tr>
|
||||
<td><a href="..."><%displayName%></a></td>
|
||||
<td><%serialnumber%></td>
|
||||
<td><%ipaddress%></td> <!-- REMOVED -->
|
||||
<td><%modelnumber%></td>
|
||||
<td><%operatingsystem%></td>
|
||||
<td><a href="..."><%machinenumber%></td> <!-- REMOVED -->
|
||||
</tr>
|
||||
|
||||
' NEW:
|
||||
<tr>
|
||||
<td><a href="..."><%displayName%></a></td>
|
||||
<td><%serialnumber%></td>
|
||||
<td><%modelnumber%></td>
|
||||
<td><%operatingsystem%></td>
|
||||
</tr>
|
||||
```
|
||||
|
||||
**Issue Encountered:**
|
||||
- After edit, page returned 404 errors
|
||||
- Root cause: IIS Express had cached the old compiled ASP
|
||||
- Resolution: Environment restart cleared ASP cache
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
---
|
||||
|
||||
## 6. Documentation & Debugging Tools Created
|
||||
|
||||
### network_map_debug.asp
|
||||
**File Created:** `/home/camp/projects/windows/shopdb/network_map_debug.asp`
|
||||
|
||||
**Purpose:** Debug page to show all printers with map coordinates
|
||||
|
||||
**Features:**
|
||||
- Lists all printers with mapleft/maptop coordinates
|
||||
- Shows IP addresses
|
||||
- Displays total count
|
||||
- Confirms map bounds validation
|
||||
|
||||
**Status:** Created (for troubleshooting)
|
||||
|
||||
### SQL Scripts Created
|
||||
|
||||
1. **assign_random_map_coordinates.sql**
|
||||
- Attempted to assign random coordinates to separate table devices
|
||||
- Not used (tables were empty)
|
||||
|
||||
2. **create_sample_network_devices.sql**
|
||||
- Creates 25 sample network devices in machines table
|
||||
- Assigns map coordinates
|
||||
- Adds IP addresses to communications table
|
||||
|
||||
3. **remove_sample_network_devices.sql**
|
||||
- Removes all 25 sample devices
|
||||
- Cleans up communications entries
|
||||
|
||||
4. **update_vw_network_devices_view.sql**
|
||||
- Drops and recreates vw_network_devices view
|
||||
- Adds machines table query for network devices
|
||||
|
||||
---
|
||||
|
||||
## 7. Testing Summary Updates
|
||||
|
||||
### File Updated
|
||||
`PHASE2_TESTING_SUMMARY.md`
|
||||
|
||||
**Updates Made:**
|
||||
1. Added network_map.asp to critical bugs fixed section
|
||||
2. Updated display pages status
|
||||
3. Added Bug #6 documentation for network_map.asp
|
||||
4. Updated executive summary with network_map.asp fix
|
||||
|
||||
**Current Status:**
|
||||
- **Total Pages Tested:** 15 out of 123
|
||||
- **Pages Passed:** 15
|
||||
- **Critical Bugs Fixed:** 6
|
||||
- **Remaining Issues:** 2 (displaysubnet.asp, v2 directory pages)
|
||||
|
||||
---
|
||||
|
||||
## Database Schema Notes
|
||||
|
||||
### Network Device Storage Architecture
|
||||
|
||||
**Current System Uses TWO Approaches:**
|
||||
|
||||
1. **Separate Tables** (Legacy/Specialized Devices):
|
||||
- `servers` table
|
||||
- `switches` table
|
||||
- `cameras` table
|
||||
- `accesspoints` table (column: `apid`, NOT `accesspointid`)
|
||||
- `idfs` table
|
||||
- `printers` table
|
||||
|
||||
2. **Unified Machines Table** (New/Phase 2 Approach):
|
||||
- Network devices stored in `machines` table
|
||||
- Identified by `machinetypeid`:
|
||||
- 16 = Access Point
|
||||
- 17 = IDF
|
||||
- 18 = Camera
|
||||
- 19 = Switch
|
||||
- 20 = Server
|
||||
- PCs also in machines table: `pctypeid IS NOT NULL`
|
||||
|
||||
**View: vw_network_devices**
|
||||
- UNION ALL query combining both approaches
|
||||
- Supports gradual migration from separate tables to unified machines table
|
||||
- Allows flexibility in where devices are stored
|
||||
|
||||
**Map Coordinates:**
|
||||
- Stored as `mapleft` and `maptop` (integer)
|
||||
- Map bounds: X: 0-3300, Y: 0-2550
|
||||
- Required for devices to appear on network_map.asp
|
||||
|
||||
---
|
||||
|
||||
## Files Modified
|
||||
|
||||
### ASP Pages
|
||||
1. `/home/camp/projects/windows/shopdb/editdevice.asp` - Fixed undefined variable
|
||||
2. `/home/camp/projects/windows/shopdb/updatedevice.asp` - Migrated to Phase 2 schema
|
||||
3. `/home/camp/projects/windows/shopdb/updatedevice_direct.asp` - Migrated to Phase 2 schema
|
||||
4. `/home/camp/projects/windows/shopdb/network_map.asp` - Enhanced to show all device types
|
||||
5. `/home/camp/projects/windows/shopdb/displaypcs.asp` - Removed IP and Machine columns
|
||||
|
||||
### SQL Scripts Created
|
||||
1. `/home/camp/projects/windows/shopdb/sql/assign_random_map_coordinates.sql`
|
||||
2. `/home/camp/projects/windows/shopdb/sql/create_sample_network_devices.sql`
|
||||
3. `/home/camp/projects/windows/shopdb/sql/remove_sample_network_devices.sql`
|
||||
4. `/home/camp/projects/windows/shopdb/sql/update_vw_network_devices_view.sql`
|
||||
|
||||
### Debug Tools Created
|
||||
1. `/home/camp/projects/windows/shopdb/network_map_debug.asp`
|
||||
|
||||
### Documentation Updated
|
||||
1. `/home/camp/projects/windows/shopdb/PHASE2_TESTING_SUMMARY.md`
|
||||
|
||||
### Documentation Created
|
||||
1. `/home/camp/projects/windows/shopdb/SESSION_SUMMARY_2025-11-13.md` (this file)
|
||||
|
||||
---
|
||||
|
||||
## Outstanding Issues
|
||||
|
||||
### High Priority
|
||||
None - all critical Phase 2 PC functionality working
|
||||
|
||||
### Medium Priority
|
||||
1. **displaysubnet.asp** - Runtime error (subscript out of range)
|
||||
- Phase 2 tables used correctly
|
||||
- Logic bug in recordset handling
|
||||
- Not blocking production
|
||||
|
||||
### Low Priority
|
||||
1. **v2 directory warranty pages** - Using old schema
|
||||
- v2/check_warranties_v2.asp
|
||||
- v2/check_all_warranties.asp
|
||||
- v2/check_all_warranties_clean.asp
|
||||
- v2 appears to be legacy directory
|
||||
- Decision needed: update or deprecate?
|
||||
|
||||
---
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
1. **ASP Cache Issues:**
|
||||
- IIS Express caches compiled ASP pages
|
||||
- Syntax errors can cause 404 responses instead of error messages
|
||||
- Environment restart clears cache (but should ask user first!)
|
||||
|
||||
2. **Network Device Architecture:**
|
||||
- System uses both separate tables AND machines table
|
||||
- machinetypeid values critical for identifying device types
|
||||
- vw_network_devices view must query both sources
|
||||
|
||||
3. **Column Name Gotchas:**
|
||||
- accesspoints table uses `apid` not `accesspointid`
|
||||
- Always verify column names before writing queries
|
||||
|
||||
4. **Map Coordinate Requirements:**
|
||||
- Devices need mapleft/maptop to appear on network_map.asp
|
||||
- Empty separate tables caused confusion about where devices are stored
|
||||
|
||||
---
|
||||
|
||||
## Production Readiness
|
||||
|
||||
### Ready for Production
|
||||
- All PC functionality (display, add, edit, update, save)
|
||||
- Phase 2 schema migration complete for critical paths
|
||||
- network_map.asp showing all device types
|
||||
- network_devices.asp unified view working
|
||||
- Security: All pages use parameterized queries
|
||||
|
||||
### Before Production Deployment
|
||||
1. Test remaining 108 ASP pages
|
||||
2. Fix displaysubnet.asp runtime error
|
||||
3. Decide on v2 directory (update or remove)
|
||||
4. Manual testing of all create/update/delete operations
|
||||
5. Monitor IIS logs for 48 hours after deployment
|
||||
6. Create rollback plan
|
||||
|
||||
### Current Test Coverage
|
||||
- **Pages Tested:** 15 / 123 (12%)
|
||||
- **Critical Pages:** 15 / 15 (100%)
|
||||
- **Phase 2 Migration:** Complete for PC pages
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. Continue systematic testing of remaining pages
|
||||
2. Create real network infrastructure devices when ready
|
||||
3. Fix displaysubnet.asp logic bug
|
||||
4. Test POST operations with production-like data
|
||||
5. Consider batch testing strategy for remaining 108 pages
|
||||
|
||||
---
|
||||
|
||||
## Environment Notes
|
||||
|
||||
- **Windows VM:** 192.168.122.151
|
||||
- **IIS Express:** Port 8080
|
||||
- **MySQL:** dev-mysql container (Docker)
|
||||
- **Database:** shopdb
|
||||
- **MySQL User:** root (password: rootpassword)
|
||||
- **Map Image:** /images/sitemap2025-dark.png (or -light.png based on theme)
|
||||
|
||||
---
|
||||
|
||||
## Conclusion
|
||||
|
||||
This was a highly productive session with 6 critical bugs fixed, major enhancements to network device display functionality, and comprehensive documentation. The system is now ready to handle network infrastructure devices in the machines table with proper display on both network_map.asp and network_devices.asp.
|
||||
|
||||
All Phase 2 critical PC functionality is working and tested. The unified architecture allows flexible device storage in either separate tables or the machines table, with the view layer handling the abstraction.
|
||||
|
||||
**Status:** Session Objectives Met
|
||||
**Production Readiness:** 85% (core functionality complete, full testing pending)
|
||||
Reference in New Issue
Block a user