- Tr069TraceService: in-memory Map O(1) lookup, Promise-queue per device for sequential file writes, 10MB rotation (5 files kept) - config/tr069-trace.json: persisted list of traced devices (atomic write) - CwmpLoggerMiddleware: buffers request+response, writes to device log file after next() once ctx.cwmpDeviceId is set by controller - CwmpController: sets ctx.cwmpDeviceId on all code paths (Inform + others) - StateMachineManager: getHashIdForRemote() for non-Inform messages - REST API: GET/POST/DELETE /api/v1/tr069-trace - UI: Tr069Trace Vue page with device search, add/remove tracing - 8 new unit tests (192 total, all passing) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
145 lines
4.9 KiB
TypeScript
145 lines
4.9 KiB
TypeScript
import type { HttpContext } from '@adonisjs/core/http'
|
|
import DeviceService from '#services/device_service'
|
|
import CommandService from '#services/command_service'
|
|
|
|
export default class PagesController {
|
|
private deviceService = new DeviceService()
|
|
private commandService = new CommandService()
|
|
|
|
async home({ inertia }: HttpContext) {
|
|
const { data } = await this.deviceService.getDevices(0, 200)
|
|
return (inertia as any).render('Home', { devices: data, message: '' })
|
|
}
|
|
|
|
async deviceDetail({ params, inertia, response }: HttpContext) {
|
|
const device = await this.deviceService.getDeviceByIdentifier(params.identifier)
|
|
if (!device) {
|
|
return response.status(404).json({ message: 'Device not found' })
|
|
}
|
|
|
|
// Get pending commands (max 5) + last processed command
|
|
const allCommands = await this.commandService.getCommandsByDevice(params.identifier)
|
|
const pending = allCommands
|
|
.filter((c: any) => ['PENDING', 'WAITING', 'SENT'].includes(c.status))
|
|
.slice(0, 5)
|
|
const lastProcessed = allCommands
|
|
.filter((c: any) => ['COMPLETED', 'FAILED'].includes(c.status))
|
|
.sort(
|
|
(a: any, b: any) =>
|
|
new Date(b.updatedAt || b.createdAt).getTime() -
|
|
new Date(a.updatedAt || a.createdAt).getTime()
|
|
)[0]
|
|
const commands = lastProcessed ? [...pending, lastProcessed] : pending
|
|
|
|
return (inertia as any).render('DeviceDetail', { device, commands })
|
|
}
|
|
|
|
async commands({ inertia, request }: HttpContext) {
|
|
const deviceFilter = request.qs().device || ''
|
|
const statusFilter = request.qs().status || ''
|
|
const actionFilter = request.qs().action || ''
|
|
const modeFilter = request.qs().mode || ''
|
|
|
|
let commands: any[] = await this.commandService.getCommands()
|
|
|
|
if (deviceFilter) {
|
|
commands = commands.filter((c: any) => c.deviceIdentifier === deviceFilter)
|
|
}
|
|
if (statusFilter) {
|
|
commands = commands.filter((c: any) => c.status === statusFilter)
|
|
}
|
|
if (actionFilter) {
|
|
commands = commands.filter((c: any) => c.action === actionFilter)
|
|
}
|
|
if (modeFilter) {
|
|
commands = commands.filter((c: any) => c.mode === modeFilter)
|
|
}
|
|
|
|
return (inertia as any).render('Commands', {
|
|
commands,
|
|
filters: {
|
|
device: deviceFilter,
|
|
status: statusFilter,
|
|
action: actionFilter,
|
|
mode: modeFilter,
|
|
},
|
|
})
|
|
}
|
|
|
|
async commandsFleet({ inertia, session }: HttpContext) {
|
|
const devices = (session as any).get('fleetDevices', [])
|
|
const commands = await this.commandService.getCommands()
|
|
return (inertia as any).render('CommandsFleet', { devices, commands })
|
|
}
|
|
|
|
async tr069Trace({ inertia }: HttpContext) {
|
|
return (inertia as any).render('Tr069Trace')
|
|
}
|
|
|
|
async storeFleetDevices({ request, response, session }: HttpContext) {
|
|
const { devices } = request.body()
|
|
;(session as any).put('fleetDevices', devices || [])
|
|
return response.redirect().toPath('/commands/fleet')
|
|
}
|
|
|
|
async refreshDevice({ params, response }: HttpContext) {
|
|
// Create a REFRESH command and send Connection Request to wake the CPE
|
|
await this.deviceService.refreshDevice(params.identifier)
|
|
return response.redirect().back()
|
|
}
|
|
|
|
async getModel({ params, request }: HttpContext) {
|
|
const { modelPath } = request.body()
|
|
await this.deviceService.executeCommand(params.identifier, {
|
|
action: 'GET_PARAMETER_NAMES' as any,
|
|
parameters: { parameterPath: modelPath, nextLevel: true },
|
|
mode: 'I',
|
|
})
|
|
}
|
|
|
|
async storeFleetCommand({ request, response, session }: HttpContext) {
|
|
const { action, parameters, mode, priority, devices } = request.body()
|
|
const deviceList = devices || session.get('fleetDevices', [])
|
|
|
|
for (const deviceIdentifier of deviceList) {
|
|
await this.commandService.createCommand({
|
|
deviceIdentifier,
|
|
action,
|
|
parameters: parameters || {},
|
|
mode,
|
|
priority,
|
|
})
|
|
}
|
|
|
|
return response.redirect().toPath('/commands/fleet')
|
|
}
|
|
|
|
async configurationsList({ inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationsList')
|
|
}
|
|
|
|
async configurationCreate({ inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationCreate')
|
|
}
|
|
|
|
async configurationEdit({ params, inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationEdit', { id: params.id })
|
|
}
|
|
|
|
async configurationDetail({ params, inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationDetail', { id: params.id })
|
|
}
|
|
|
|
async firmwareCatalog({ inertia }: HttpContext) {
|
|
return (inertia as any).render('firmware_catalog/FirmwareCatalog')
|
|
}
|
|
|
|
async firmwareCatalogCreate({ inertia }: HttpContext) {
|
|
return (inertia as any).render('firmware_catalog/FirmwareCatalogCreate')
|
|
}
|
|
|
|
async firmwareCatalogEdit({ params, inertia }: HttpContext) {
|
|
return (inertia as any).render('firmware_catalog/FirmwareCatalogEdit', { id: params.id })
|
|
}
|
|
}
|