From 5413b20bbaf36b534f6ab5640b1f0e5cee0b9dde Mon Sep 17 00:00:00 2001 From: cproudlock Date: Mon, 1 Dec 2025 08:50:45 -0500 Subject: [PATCH] Add FQDN support for network devices and fix printer installer map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Printer Installer Map Fixes - Fixed printer_installer_map.asp to pass printer IDs instead of generated names - Fixed install_printer.asp dictionary key collision by using printerid ## Network Device FQDN Support - Added fqdn column to machines table (migration script included) - Updated device edit pages: deviceaccesspoint.asp, deviceserver.asp, deviceswitch.asp, devicecamera.asp - Updated save_network_device.asp to handle FQDN in INSERT/UPDATE - Updated network_devices.asp to display FQDN for Server, Switch, Camera - Updated vw_network_devices view to include FQDN from machines table - Added FQDN field to machine_edit.asp Network tab - Updated savemachineedit.asp to save FQDN ## Printer Install Path Edit - Added installpath field to displayprinter.asp Edit tab - Updated editprinter.asp to save installpath changes ## Documentation - Added IIS log location to CLAUDE.md ## Production Migration - sql/add_fqdn_to_machines.sql - Run on production to add column and update view πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- CLAUDE.md | 165 +++++++++++++++++++++++++++++++++++ deviceaccesspoint.asp | 21 ++++- devicecamera.asp | 23 ++++- deviceserver.asp | 21 ++++- deviceswitch.asp | 21 ++++- displayprinter.asp | 9 +- editprinter.asp | 8 +- install_printer.asp | 2 +- machine_edit.asp | 13 ++- network_devices.asp | 50 ++++++++--- printer_installer_map.asp | 14 ++- save_network_device.asp | 9 +- savemachineedit.asp | 9 +- sql/add_fqdn_to_machines.sql | 85 ++++++++++++++++++ 14 files changed, 404 insertions(+), 46 deletions(-) create mode 100644 CLAUDE.md create mode 100644 sql/add_fqdn_to_machines.sql diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..ee3676c --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,165 @@ +# ShopDB - Claude Code Instructions + +## Project Overview + +ShopDB is a Classic ASP/VBScript web application for managing manufacturing shop floor infrastructure at GE Aerospace. It tracks machines, PCs, printers, and network devices. + +## Technology Stack + +- **Backend:** Classic ASP (VBScript) +- **Database:** MySQL 5.6 +- **Frontend:** Bootstrap 4.6, jQuery, DataTables +- **Server:** IIS on Windows VM (192.168.122.151:8080) +- **Version Control:** Gitea (localhost:3000) + +## Key Architecture + +### Database Schema (Phase 2 - Current) + +``` +machines table (unified) +β”œβ”€β”€ Equipment (machinetypeid 1-24, pctypeid IS NULL) +β”œβ”€β”€ PCs (machinetypeid 33-35, pctypeid IS NOT NULL) +└── Network Devices (machinetypeid 16-20) + +printers table (separate) +communications table (all network interfaces) +machinerelationships table (PC↔equipment links) +``` + +### Key Queries + +```sql +-- All PCs +SELECT * FROM machines WHERE pctypeid IS NOT NULL; + +-- All Equipment +SELECT * FROM machines WHERE pctypeid IS NULL AND machinetypeid < 16; + +-- Network devices +SELECT * FROM machines WHERE machinetypeid IN (16,17,18,19,20); +``` + +## File Structure + +``` +/home/camp/projects/windows/shopdb/ +β”œβ”€β”€ *.asp # Main ASP pages +β”œβ”€β”€ api.asp # REST API for PowerShell +β”œβ”€β”€ includes/ # Shared includes (header, footer, sql) +β”œβ”€β”€ js/ # JavaScript files +β”œβ”€β”€ css/ # Stylesheets +β”œβ”€β”€ images/ # Images and icons +β”œβ”€β”€ docs/ # Documentation +β”œβ”€β”€ sql/ # SQL scripts +β”‚ β”œβ”€β”€ migration_phase1/ +β”‚ β”œβ”€β”€ migration_phase2/ +β”‚ └── migration_phase3/ +└── logs/ # Application logs +``` + +## Log Locations + +**IIS Logs (Windows VM):** `/home/camp/projects/windows/logs/shopdb/` +- Format: `ex[YYMMDD].log` (e.g., `ex251201.log` for Dec 1, 2025) +- These are synced from the Windows VM via Samba share +- Contains HTTP request logs with status codes and error messages + +**API Logs:** Check `logs/` folder in shopdb directory on IIS + +## Coding Standards + +### ASP/VBScript + +1. **Always use parameterized queries** - Never concatenate user input into SQL +2. **Use HTMLEncode for output** - Prevent XSS attacks +3. **Convert text fields to strings** - Use `& ""` to avoid type mismatch errors +4. **Use Option Explicit** - Declare all variables + +### Example Safe Query + +```vbscript +Dim cmd, rs +Set cmd = Server.CreateObject("ADODB.Command") +cmd.ActiveConnection = objConn +cmd.CommandText = "SELECT * FROM machines WHERE machineid = ?" +cmd.Parameters.Append cmd.CreateParameter("@id", 3, 1, , machineId) +Set rs = cmd.Execute() +``` + +### Example Safe Output + +```vbscript +' Always convert to string and encode +Dim hostname +hostname = "" +If NOT IsNull(rs("hostname")) Then hostname = rs("hostname") & "" +Response.Write(Server.HTMLEncode(hostname)) +``` + +## Common Tasks + +### Reading Files +- Main pages are in project root (*.asp) +- Includes are in /includes/ +- Check docs/ for documentation + +### Making Changes +1. Read the file first +2. Use parameterized queries for any SQL +3. Test on dev server (192.168.122.151:8080) +4. Check IIS logs for errors + +### Database Access +```bash +docker exec -it dev-mysql mysql -u root -prootpassword shopdb +``` + +## Important Notes + +### VBScript Limitations +- No `IIf()` function - use If-Then-Else instead +- No Try-Catch - use On Error Resume Next carefully +- Strings are 1-indexed, not 0-indexed + +### Column Name Gotchas +- `address` not `ipaddress` in communications table +- `machinenotes` not `notes` in machines table +- `machineid` not `pcid` for PCs in machines table + +### PC Identification +PCs are in the machines table, identified by: +- `pctypeid IS NOT NULL` +- `machinetypeid IN (33, 34, 35)` + +## API Endpoints + +**Base URL:** `http://192.168.122.151:8080/api.asp` + +| Action | Method | Description | +|--------|--------|-------------| +| updateCompleteAsset | POST | PC data collection | +| getDashboardData | GET | Health check | +| updatePrinterMapping | POST | Printer assignments | + +## Quick Reference + +### Start Dev Environment +```bash +~/start-dev-env.sh +~/status-dev-env.sh +``` + +### Git Commands +```bash +cd /home/camp/projects/windows/shopdb +git status +git add . +git commit -m "message" +git push +``` + +### Test a Page +```bash +curl -s http://192.168.122.151:8080/pagename.asp | head -50 +``` diff --git a/deviceaccesspoint.asp b/deviceaccesspoint.asp index 7dcc918..f0d9309 100644 --- a/deviceaccesspoint.asp +++ b/deviceaccesspoint.asp @@ -22,18 +22,18 @@ End If ' If editing, fetch existing data - Dim rs, accesspointname, modelid, serialnumber, ipaddress, description, maptop, mapleft, isactive + Dim rs, accesspointname, modelid, serialnumber, ipaddress, fqdn, description, maptop, mapleft, isactive Dim vendorname, modelnumber If Not isNewRecord Then Dim strSQL strSQL = "SELECT mac.machineid, mac.alias AS apname, mac.modelnumberid AS modelid, " & _ - "mac.serialnumber, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ + "mac.serialnumber, mac.fqdn, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ "m.modelnumber, v.vendor, c.address AS ipaddress " & _ "FROM machines mac " & _ "LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _ "LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _ "LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ - "WHERE mac.machineid = " & accesspointid & " AND mac.machinetypeid = 33" + "WHERE mac.machineid = " & accesspointid & " AND mac.machinetypeid = 16" Set rs = objConn.Execute(strSQL) If rs.EOF Then @@ -49,6 +49,7 @@ Else ipaddress = "" End If + If Not IsNull(rs("fqdn")) Then fqdn = rs("fqdn") Else fqdn = "" If Not IsNull(rs("description")) Then description = rs("description") Else description = "" If Not IsNull(rs("maptop")) Then maptop = rs("maptop") Else maptop = "" If Not IsNull(rs("mapleft")) Then mapleft = rs("mapleft") Else mapleft = "" @@ -64,6 +65,7 @@ modelid = "" serialnumber = "" ipaddress = "" + fqdn = "" description = "" maptop = "" mapleft = "" @@ -270,6 +272,19 @@ +
+ +
+ + + Fully Qualified Domain Name (optional) + +
+
+
diff --git a/devicecamera.asp b/devicecamera.asp index 89ca1b4..3859090 100644 --- a/devicecamera.asp +++ b/devicecamera.asp @@ -22,12 +22,12 @@ End If ' If editing, fetch existing data - Dim rs, cameraname, modelid, idfid, serialnumber, macaddress, ipaddress, description, maptop, mapleft, isactive + Dim rs, cameraname, modelid, idfid, serialnumber, macaddress, ipaddress, fqdn, description, maptop, mapleft, isactive Dim vendorname, modelnumber, idfname If Not isNewRecord Then Dim strSQL strSQL = "SELECT mac.machineid, mac.alias AS cameraname, mac.modelnumberid AS modelid, " & _ - "mac.serialnumber, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ + "mac.serialnumber, mac.fqdn, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ "m.modelnumber, v.vendor, c.address AS ipaddress, c.macaddress, " & _ "mr.related_machineid AS idfid, idf.alias AS idfname " & _ "FROM machines mac " & _ @@ -36,8 +36,8 @@ "LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ "LEFT JOIN machinerelationships mr ON mac.machineid = mr.machineid AND mr.relationshiptypeid = " & _ "(SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Connected To' LIMIT 1) " & _ - "LEFT JOIN machines idf ON mr.related_machineid = idf.machineid AND idf.machinetypeid = 34 " & _ - "WHERE mac.machineid = " & cameraid & " AND mac.machinetypeid = 32" + "LEFT JOIN machines idf ON mr.related_machineid = idf.machineid AND idf.machinetypeid = 17 " & _ + "WHERE mac.machineid = " & cameraid & " AND mac.machinetypeid = 18" Set rs = objConn.Execute(strSQL) If rs.EOF Then @@ -63,6 +63,7 @@ Else ipaddress = "" End If + If Not IsNull(rs("fqdn")) Then fqdn = rs("fqdn") Else fqdn = "" If Not IsNull(rs("description")) Then description = rs("description") Else description = "" If Not IsNull(rs("maptop")) Then maptop = rs("maptop") Else maptop = "" If Not IsNull(rs("mapleft")) Then mapleft = rs("mapleft") Else mapleft = "" @@ -85,6 +86,7 @@ serialnumber = "" macaddress = "" ipaddress = "" + fqdn = "" description = "" maptop = "" mapleft = "" @@ -376,6 +378,19 @@
+
+ +
+ + + Fully Qualified Domain Name (optional) + +
+
+
diff --git a/deviceserver.asp b/deviceserver.asp index c1b650d..4502aa1 100644 --- a/deviceserver.asp +++ b/deviceserver.asp @@ -22,18 +22,18 @@ End If ' If editing, fetch existing data - Dim rs, servername, modelid, serialnumber, ipaddress, description, maptop, mapleft, isactive + Dim rs, servername, modelid, serialnumber, ipaddress, fqdn, description, maptop, mapleft, isactive Dim vendorname, modelnumber If Not isNewRecord Then Dim strSQL strSQL = "SELECT mac.machineid, mac.alias AS servername, mac.modelnumberid AS modelid, " & _ - "mac.serialnumber, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ + "mac.serialnumber, mac.fqdn, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ "m.modelnumber, v.vendor, c.address AS ipaddress " & _ "FROM machines mac " & _ "LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _ "LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _ "LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ - "WHERE mac.machineid = " & serverid & " AND mac.machinetypeid = 30" + "WHERE mac.machineid = " & serverid & " AND mac.machinetypeid = 20" Set rs = objConn.Execute(strSQL) If rs.EOF Then @@ -45,6 +45,7 @@ If Not IsNull(rs("modelid")) Then modelid = rs("modelid") Else modelid = "" If Not IsNull(rs("serialnumber")) Then serialnumber = rs("serialnumber") Else serialnumber = "" If Not IsNull(rs("ipaddress")) Then ipaddress = rs("ipaddress") Else ipaddress = "" + If Not IsNull(rs("fqdn")) Then fqdn = rs("fqdn") Else fqdn = "" If Not IsNull(rs("description")) Then description = rs("description") Else description = "" If Not IsNull(rs("maptop")) Then maptop = rs("maptop") Else maptop = "" If Not IsNull(rs("mapleft")) Then mapleft = rs("mapleft") Else mapleft = "" @@ -60,6 +61,7 @@ modelid = "" serialnumber = "" ipaddress = "" + fqdn = "" description = "" maptop = "" mapleft = "" @@ -266,6 +268,19 @@
+
+ +
+ + + Fully Qualified Domain Name (optional) + +
+
+
diff --git a/deviceswitch.asp b/deviceswitch.asp index fa5d7b5..c026990 100644 --- a/deviceswitch.asp +++ b/deviceswitch.asp @@ -22,18 +22,18 @@ End If ' If editing, fetch existing data - Dim rs, switchname, modelid, serialnumber, ipaddress, description, maptop, mapleft, isactive + Dim rs, switchname, modelid, serialnumber, ipaddress, fqdn, description, maptop, mapleft, isactive Dim vendorname, modelnumber If Not isNewRecord Then Dim strSQL strSQL = "SELECT mac.machineid, mac.alias AS switchname, mac.modelnumberid AS modelid, " & _ - "mac.serialnumber, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ + "mac.serialnumber, mac.fqdn, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _ "m.modelnumber, v.vendor, c.address AS ipaddress " & _ "FROM machines mac " & _ "LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _ "LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _ "LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _ - "WHERE mac.machineid = " & switchid & " AND mac.machinetypeid = 31" + "WHERE mac.machineid = " & switchid & " AND mac.machinetypeid = 19" Set rs = objConn.Execute(strSQL) If rs.EOF Then @@ -45,6 +45,7 @@ If Not IsNull(rs("modelid")) Then modelid = rs("modelid") Else modelid = "" If Not IsNull(rs("serialnumber")) Then serialnumber = rs("serialnumber") Else serialnumber = "" If Not IsNull(rs("ipaddress")) Then ipaddress = rs("ipaddress") Else ipaddress = "" + If Not IsNull(rs("fqdn")) Then fqdn = rs("fqdn") Else fqdn = "" If Not IsNull(rs("description")) Then description = rs("description") Else description = "" If Not IsNull(rs("maptop")) Then maptop = rs("maptop") Else maptop = "" If Not IsNull(rs("mapleft")) Then mapleft = rs("mapleft") Else mapleft = "" @@ -60,6 +61,7 @@ modelid = "" serialnumber = "" ipaddress = "" + fqdn = "" description = "" maptop = "" mapleft = "" @@ -266,6 +268,19 @@
+
+ +
+ + + Fully Qualified Domain Name (optional) + +
+
+
diff --git a/displayprinter.asp b/displayprinter.asp index f726583..eabbfa1 100644 --- a/displayprinter.asp +++ b/displayprinter.asp @@ -478,11 +478,18 @@ End If
- +
" placeholder="<%=Server.HTMLEncode(rs("printerwindowsname") & "")%>">
+
+ +
+ " placeholder="e.g., drivers/HP/LJ400.exe"> + Path to specific driver installer (leave blank to use universal driver) +
+
diff --git a/editprinter.asp b/editprinter.asp index aace81c..8175db6 100644 --- a/editprinter.asp +++ b/editprinter.asp @@ -19,7 +19,7 @@ END IF ' Get and validate all inputs - Dim printerid, modelid, serialnumber, ipaddress, fqdn, printercsfname, printerwindowsname, machineid, maptop, mapleft + Dim printerid, modelid, serialnumber, ipaddress, fqdn, printercsfname, printerwindowsname, installpath, machineid, maptop, mapleft printerid = Trim(Request.Querystring("printerid")) modelid = Trim(Request.Form("modelid")) serialnumber = Trim(Request.Form("serialnumber")) @@ -27,6 +27,7 @@ fqdn = Trim(Request.Form("fqdn")) printercsfname = Trim(Request.Form("printercsfname")) printerwindowsname = Trim(Request.Form("printerwindowsname")) + installpath = Trim(Request.Form("installpath")) machineid = Trim(Request.Form("machineid")) maptop = Trim(Request.Form("maptop")) mapleft = Trim(Request.Form("mapleft")) @@ -62,7 +63,7 @@ End If ' Validate field lengths - If Len(serialnumber) > 100 Or Len(fqdn) > 255 Or Len(printercsfname) > 50 Or Len(printerwindowsname) > 255 Then + If Len(serialnumber) > 100 Or Len(fqdn) > 255 Or Len(printercsfname) > 50 Or Len(printerwindowsname) > 255 Or Len(installpath) > 100 Then objConn.Close Response.Redirect("displayprinter.asp?printerid=" & printerid & "&error=FIELD_LENGTH_EXCEEDED") Response.End @@ -190,7 +191,7 @@ ' Update printer using parameterized query Dim strSQL strSQL = "UPDATE printers SET modelid = ?, serialnumber = ?, ipaddress = ?, fqdn = ?, " & _ - "printercsfname = ?, printerwindowsname = ?, machineid = ?, maptop = ?, mapleft = ? " & _ + "printercsfname = ?, printerwindowsname = ?, installpath = ?, machineid = ?, maptop = ?, mapleft = ? " & _ "WHERE printerid = ?" On Error Resume Next @@ -207,6 +208,7 @@ cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@fqdn", 200, 1, 255, fqdn) cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@printercsfname", 200, 1, 50, printercsfname) cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@printerwindowsname", 200, 1, 255, printerwindowsname) + cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@installpath", 200, 1, 100, installpath) cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machineid", 3, 1, , CLng(machineid)) cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@maptop", 3, 1, , maptopValue) cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@mapleft", 3, 1, , mapleftValue) diff --git a/install_printer.asp b/install_printer.asp index 5347992..fbe08f1 100644 --- a/install_printer.asp +++ b/install_printer.asp @@ -156,7 +156,7 @@ If printerIds <> "" Or printerNames <> "" Then printerInfo("address") = printerInfo("ipaddress") End If - printers.Add rs("printerwindowsname"), printerInfo + printers.Add CStr(rs("printerid")), printerInfo rs.MoveNext Wend diff --git a/machine_edit.asp b/machine_edit.asp index 188bbcb..614572a 100644 --- a/machine_edit.asp +++ b/machine_edit.asp @@ -54,7 +54,7 @@ End If ' Store machine data - Dim machinenumber, modelid, businessunitid, alias, machinenotes, mapleft, maptop + Dim machinenumber, modelid, businessunitid, alias, machinenotes, mapleft, maptop, fqdn machinenumber = "" : If NOT IsNull(rsMachine("machinenumber")) Then machinenumber = rsMachine("machinenumber") & "" modelid = "" : If NOT IsNull(rsMachine("modelnumberid")) Then modelid = rsMachine("modelnumberid") businessunitid = "" : If NOT IsNull(rsMachine("businessunitid")) Then businessunitid = rsMachine("businessunitid") @@ -62,6 +62,7 @@ machinenotes = "" : If NOT IsNull(rsMachine("machinenotes")) Then machinenotes = rsMachine("machinenotes") & "" mapleft = "" : If NOT IsNull(rsMachine("mapleft")) Then mapleft = rsMachine("mapleft") maptop = "" : If NOT IsNull(rsMachine("maptop")) Then maptop = rsMachine("maptop") + fqdn = "" : If NOT IsNull(rsMachine("fqdn")) Then fqdn = rsMachine("fqdn") & "" rsMachine.Close Set rsMachine = Nothing @@ -461,6 +462,16 @@
Network Communications

Configure network interfaces for this equipment. You can add up to 3 interfaces.

+ +
+ + + Optional - used for network devices like access points, switches, servers +
+ +
+
diff --git a/network_devices.asp b/network_devices.asp index e6fe10e..3f04276 100644 --- a/network_devices.asp +++ b/network_devices.asp @@ -103,16 +103,17 @@ If filterType = "IDF" Then Response.Write("Name") Response.Write("Description") ElseIf filterType = "Server" Or filterType = "Switch" Then - ' Server/Switch columns: Location, Name, Vendor, Model, Serial, IP Address, Description + ' Server/Switch columns: Location, Name, Vendor, Model, Serial, IP Address, FQDN, Description Response.Write("") Response.Write("Name") Response.Write("Vendor") Response.Write("Model") Response.Write("Serial") Response.Write("IP Address") + Response.Write("FQDN") Response.Write("Description") ElseIf filterType = "Camera" Then - ' Camera columns: Location, Name, IDF, Vendor, Model, MAC Address, IP Address + ' Camera columns: Location, Name, IDF, Vendor, Model, MAC Address, IP Address, FQDN Response.Write("") Response.Write("Name") Response.Write("IDF") @@ -120,6 +121,7 @@ ElseIf filterType = "Camera" Then Response.Write("Model") Response.Write("MAC Address") Response.Write("IP Address") + Response.Write("FQDN") ElseIf filterType = "Access Point" Or filterType = "Printer" Then ' Access Point/Printer columns: Location, Name, Vendor, Model, IP Address, FQDN Response.Write("") @@ -238,9 +240,11 @@ End If If filterType = "IDF" Then ' Description, Actions Response.Write("") - If Not IsNull(rs("description")) And rs("description") <> "" Then + Dim descValue + descValue = rs("description") & "" + If Len(Trim(descValue)) > 0 Then Dim desc - desc = Server.HTMLEncode(rs("description")) + desc = Server.HTMLEncode(Trim(descValue)) If Len(desc) > 100 Then Response.Write(Left(desc, 100) & "...") Else @@ -252,7 +256,7 @@ End If Response.Write("") ElseIf filterType = "Server" Or filterType = "Switch" Then - ' Vendor, Model, Serial, IP Address, Description, Actions + ' Vendor, Model, Serial, IP Address, FQDN, Description, Actions Response.Write("") If Not IsNull(rs("vendor")) Then Response.Write(Server.HTMLEncode(rs("vendor"))) @@ -288,9 +292,19 @@ End If Response.Write("") Response.Write("") - If Not IsNull(rs("description")) And rs("description") <> "" Then + If Not IsNull(rs("fqdn")) And rs("fqdn") <> "" Then + Response.Write(Server.HTMLEncode(rs("fqdn"))) + Else + Response.Write("-") + End If + Response.Write("") + + Response.Write("") + Dim descSvrValue + descSvrValue = rs("description") & "" + If Len(Trim(descSvrValue)) > 0 Then Dim descSvr - descSvr = Server.HTMLEncode(rs("description")) + descSvr = Server.HTMLEncode(Trim(descSvrValue)) If Len(descSvr) > 50 Then Response.Write(Left(descSvr, 50) & "...") Else @@ -302,7 +316,7 @@ End If Response.Write("") ElseIf filterType = "Camera" Then - ' IDF, Vendor, Model, MAC Address, IP Address, Actions + ' IDF, Vendor, Model, MAC Address, IP Address, FQDN, Actions Response.Write("") If Not IsNull(rs("idfname")) Then Response.Write("") @@ -347,6 +361,14 @@ End If End If Response.Write("") + Response.Write("") + If Not IsNull(rs("fqdn")) And rs("fqdn") <> "" Then + Response.Write(Server.HTMLEncode(rs("fqdn"))) + Else + Response.Write("-") + End If + Response.Write("") + ElseIf filterType = "Access Point" Or filterType = "Printer" Then ' Access Point/Printer - Name (already shown), Vendor, Model, IP Address, FQDN, Actions Response.Write("") @@ -420,9 +442,11 @@ End If Response.Write("") Response.Write("") - If Not IsNull(rs("description")) And rs("description") <> "" Then + Dim descAllValue + descAllValue = rs("description") & "" + If Len(Trim(descAllValue)) > 0 Then Dim descAll - descAll = Server.HTMLEncode(rs("description")) + descAll = Server.HTMLEncode(Trim(descAllValue)) If Len(descAll) > 50 Then Response.Write(Left(descAll, 50) & "...") Else @@ -447,13 +471,13 @@ End If colspanCount = "3" Case "Server": noDataMessage = "No servers found." - colspanCount = "7" + colspanCount = "8" Case "Switch": noDataMessage = "No switches found." - colspanCount = "7" + colspanCount = "8" Case "Camera": noDataMessage = "No cameras found." - colspanCount = "7" + colspanCount = "8" Case "Access Point": noDataMessage = "No access points found." colspanCount = "6" diff --git a/printer_installer_map.asp b/printer_installer_map.asp index 3da5fc5..8d9189c 100644 --- a/printer_installer_map.asp +++ b/printer_installer_map.asp @@ -426,21 +426,19 @@ function clearSelection() { } function downloadInstaller() { - var printerNames = []; + var printerIds = []; for (var printerId in selectedPrinters) { - printerNames.push(printerData[printerId].name); + printerIds.push(printerId); } - if (printerNames.length === 0) { + if (printerIds.length === 0) { alert('Please select at least one printer'); return; } - // Pass printer names as comma-separated list for auto-selection - // Single printer: /PRINTER=PrinterName (uses partial matching) - // Multiple printers: /PRINTER=Printer1,Printer2,Printer3 (uses exact matching) - var printerParam = printerNames.join(','); - window.location.href = 'install_printer.asp?printer=' + encodeURIComponent(printerParam); + // Pass printer IDs for reliable lookup (names are generated dynamically and may not match DB) + var printerParam = printerIds.join(','); + window.location.href = 'install_printer.asp?printerid=' + encodeURIComponent(printerParam); } diff --git a/save_network_device.asp b/save_network_device.asp index 389ab56..51c5fc3 100644 --- a/save_network_device.asp +++ b/save_network_device.asp @@ -127,10 +127,11 @@ Else End If ' Get model and serial number (common fields) -Dim modelid, serialnumber, ipaddress, macaddress +Dim modelid, serialnumber, ipaddress, fqdn, macaddress modelid = Trim(Request.Form("modelid")) serialnumber = Trim(Request.Form("serialnumber")) ipaddress = Trim(Request.Form("ipaddress")) +fqdn = Trim(Request.Form("fqdn")) macaddress = Trim(Request.Form("macaddress")) ' Handle new model creation @@ -325,7 +326,7 @@ strSQL = "" If deviceId = "0" Then ' INSERT into machines table - strSQL = "INSERT INTO machines (machinenumber, alias, modelnumberid, machinetypeid, pctypeid, serialnumber, machinenotes, mapleft, maptop, isactive, lastupdated) VALUES (?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, NOW())" + strSQL = "INSERT INTO machines (machinenumber, alias, modelnumberid, machinetypeid, pctypeid, serialnumber, fqdn, machinenotes, mapleft, maptop, isactive, lastupdated) VALUES (?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, NOW())" Set cmdDevice = Server.CreateObject("ADODB.Command") cmdDevice.ActiveConnection = objConn cmdDevice.CommandText = strSQL @@ -335,6 +336,7 @@ If deviceId = "0" Then cmdDevice.Parameters.Append cmdDevice.CreateParameter("@modelnumberid", 3, 1, , modelidValue) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@machinetypeid", 3, 1, , machineTypeId) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@serialnumber", 200, 1, 100, serialnumber) + cmdDevice.Parameters.Append cmdDevice.CreateParameter("@fqdn", 200, 1, 255, fqdn) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@machinenotes", 200, 1, 255, description) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@mapleft", 3, 1, , mapleftValue) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@maptop", 3, 1, , maptopValue) @@ -361,7 +363,7 @@ If deviceId = "0" Then Else ' UPDATE machines table - strSQL = "UPDATE machines SET machinenumber = ?, alias = ?, modelnumberid = ?, serialnumber = ?, machinenotes = ?, mapleft = ?, maptop = ?, isactive = ?, lastupdated = NOW() WHERE machineid = ?" + strSQL = "UPDATE machines SET machinenumber = ?, alias = ?, modelnumberid = ?, serialnumber = ?, fqdn = ?, machinenotes = ?, mapleft = ?, maptop = ?, isactive = ?, lastupdated = NOW() WHERE machineid = ?" Set cmdDevice = Server.CreateObject("ADODB.Command") cmdDevice.ActiveConnection = objConn cmdDevice.CommandText = strSQL @@ -370,6 +372,7 @@ Else cmdDevice.Parameters.Append cmdDevice.CreateParameter("@alias", 200, 1, 100, deviceName) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@modelnumberid", 3, 1, , modelidValue) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@serialnumber", 200, 1, 100, serialnumber) + cmdDevice.Parameters.Append cmdDevice.CreateParameter("@fqdn", 200, 1, 255, fqdn) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@machinenotes", 200, 1, 255, description) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@mapleft", 3, 1, , mapleftValue) cmdDevice.Parameters.Append cmdDevice.CreateParameter("@maptop", 3, 1, , maptopValue) diff --git a/savemachineedit.asp b/savemachineedit.asp index af9a2d6..04d7aec 100644 --- a/savemachineedit.asp +++ b/savemachineedit.asp @@ -17,7 +17,7 @@
<% ' Get and validate all inputs - Dim machineid, modelid, businessunitid, alias, machinenotes, mapleft, maptop + Dim machineid, modelid, businessunitid, alias, machinenotes, mapleft, maptop, fqdn machineid = Trim(Request.Form("machineid")) modelid = Trim(Request.Form("modelid")) businessunitid = Trim(Request.Form("businessunitid")) @@ -25,6 +25,7 @@ machinenotes = Trim(Request.Form("machinenotes")) mapleft = Trim(Request.Form("mapleft")) maptop = Trim(Request.Form("maptop")) + fqdn = Trim(Request.Form("fqdn")) ' Get form inputs for new business unit Dim newbusinessunit @@ -388,13 +389,14 @@ '============================================================================= ' UPDATE MACHINES TABLE '============================================================================= - Dim strSQL, cmdMachine, serialnumberVal, hostnameVal, aliasVal, machinenotesVal + Dim strSQL, cmdMachine, serialnumberVal, hostnameVal, aliasVal, machinenotesVal, fqdnVal If Trim(Request.Form("serialnumber") & "") <> "" Then serialnumberVal = Trim(Request.Form("serialnumber") & "") Else serialnumberVal = Null If Trim(Request.Form("hostname") & "") <> "" Then hostnameVal = Trim(Request.Form("hostname") & "") Else hostnameVal = Null If alias <> "" Then aliasVal = alias Else aliasVal = Null If machinenotes <> "" Then machinenotesVal = machinenotes Else machinenotesVal = Null + If fqdn <> "" Then fqdnVal = fqdn Else fqdnVal = Null - strSQL = "UPDATE machines SET serialnumber = ?, hostname = ?, modelnumberid = ?, businessunitid = ?, alias = ?, machinenotes = ?, mapleft = ?, maptop = ? WHERE machineid = ?" + strSQL = "UPDATE machines SET serialnumber = ?, hostname = ?, fqdn = ?, modelnumberid = ?, businessunitid = ?, alias = ?, machinenotes = ?, mapleft = ?, maptop = ? WHERE machineid = ?" Set cmdMachine = Server.CreateObject("ADODB.Command") cmdMachine.ActiveConnection = objConn @@ -402,6 +404,7 @@ cmdMachine.CommandType = 1 cmdMachine.Parameters.Append cmdMachine.CreateParameter("@serialnumber", 200, 1, 100, serialnumberVal) cmdMachine.Parameters.Append cmdMachine.CreateParameter("@hostname", 200, 1, 255, hostnameVal) + cmdMachine.Parameters.Append cmdMachine.CreateParameter("@fqdn", 200, 1, 255, fqdnVal) cmdMachine.Parameters.Append cmdMachine.CreateParameter("@modelnumberid", 3, 1, , CLng(modelid)) cmdMachine.Parameters.Append cmdMachine.CreateParameter("@businessunitid", 3, 1, , CLng(businessunitid)) cmdMachine.Parameters.Append cmdMachine.CreateParameter("@alias", 200, 1, 50, aliasVal) diff --git a/sql/add_fqdn_to_machines.sql b/sql/add_fqdn_to_machines.sql new file mode 100644 index 0000000..1e52eb4 --- /dev/null +++ b/sql/add_fqdn_to_machines.sql @@ -0,0 +1,85 @@ +-- ============================================================================= +-- Migration: Add FQDN column to machines table +-- Purpose: Allow network devices to store fully qualified domain names +-- Date: 2025-12-01 +-- +-- Run on PRODUCTION: +-- mysql -u root -p shopdb < add_fqdn_to_machines.sql +-- ============================================================================= + +-- Check if column already exists before adding +SET @dbname = DATABASE(); +SET @tablename = 'machines'; +SET @columnname = 'fqdn'; +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = @dbname + AND TABLE_NAME = @tablename + AND COLUMN_NAME = @columnname + ) > 0, + 'SELECT ''Column fqdn already exists in machines table'' AS message;', + 'ALTER TABLE machines ADD COLUMN fqdn VARCHAR(255) NULL AFTER hostname;' +)); + +PREPARE alterIfNotExists FROM @preparedStatement; +EXECUTE alterIfNotExists; +DEALLOCATE PREPARE alterIfNotExists; + +-- Verify the column was added +SELECT 'Column migration complete.' AS status; + +-- ============================================================================= +-- Update vw_network_devices view to include FQDN from machines table +-- ============================================================================= +CREATE OR REPLACE VIEW vw_network_devices AS +-- Printers from printers table +SELECT + 'Printer' AS device_type, + p.printerid AS device_id, + p.printerwindowsname AS device_name, + p.modelid AS modelid, + m.modelnumber AS modelnumber, + v.vendor AS vendor, + p.serialnumber AS serialnumber, + p.ipaddress AS ipaddress, + NULL AS description, + p.maptop AS maptop, + p.mapleft AS mapleft, + p.isactive AS isactive, + NULL AS idfid, + NULL AS idfname, + NULL AS macaddress, + p.fqdn AS fqdn +FROM printers p +LEFT JOIN models m ON p.modelid = m.modelnumberid +LEFT JOIN vendors v ON m.vendorid = v.vendorid + +UNION ALL + +-- Network devices from machines table (machinetypeid 16-20) +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 AS modelnumber, + ve.vendor AS vendor, + ma.serialnumber AS serialnumber, + c.address AS ipaddress, + ma.machinenotes AS description, + ma.maptop AS maptop, + ma.mapleft AS mapleft, + ma.isactive AS isactive, + NULL AS idfid, + NULL AS idfname, + c.macaddress AS macaddress, + ma.fqdn AS fqdn +FROM machines ma +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); + +SELECT 'View vw_network_devices updated to include FQDN from machines table.' AS status;