Files
adam-acs/app/protocol/common/cwmp_message_builder.ts
T
Kevin L'HereecandCopilot d1c65dbf1e chore: initial commit — AdonisJS v7 TR-069 ACS
- Docker infrastructure (Dockerfile, docker-compose.yml, genieacs-sim)
- AdonisJS v7 app with Inertia.js + Vue 3
- MongoDB integration
- CWMP/TR-069 state machine engine
- Configuration engine with compliance tracking
- Branding: ADAM ACS (favicon, navbar, locales)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-29 16:46:37 +02:00

151 lines
5.5 KiB
TypeScript

import { buildSoapEnvelope } from '../soap.js'
export class CWMPMessageBuilder {
static informResponse(cwmpId?: string): string {
const body = `<cwmp:InformResponse>
<MaxEnvelopes>1</MaxEnvelopes>
</cwmp:InformResponse>`
return buildSoapEnvelope(cwmpId, body)
}
static getParameterNames(cwmpId: string | undefined, parameterPath: string, nextLevel: boolean = true): string {
const body = `<cwmp:GetParameterNames>
<ParameterPath>${parameterPath}</ParameterPath>
<NextLevel>${nextLevel ? '1' : '0'}</NextLevel>
</cwmp:GetParameterNames>`
return buildSoapEnvelope(cwmpId, body)
}
static getParameterValues(cwmpId: string | undefined, parameterNames: string[]): string {
const names = parameterNames.map((n) => `<string>${n}</string>`).join('\n ')
const body = `<cwmp:GetParameterValues>
<ParameterNames soap-enc:arrayType="xsd:string[${parameterNames.length}]">
${names}
</ParameterNames>
</cwmp:GetParameterValues>`
return buildSoapEnvelope(cwmpId, body)
}
static setParameterValues(cwmpId: string | undefined, parameters: { name: string; value: string; type: string }[]): string {
const params = parameters
.map(
(p) => `<ParameterValueStruct>
<Name>${p.name}</Name>
<Value xsi:type="${p.type}">${p.value}</Value>
</ParameterValueStruct>`
)
.join('\n ')
const body = `<cwmp:SetParameterValues>
<ParameterList soap-enc:arrayType="cwmp:ParameterValueStruct[${parameters.length}]">
${params}
</ParameterList>
<ParameterKey>papaye-v2</ParameterKey>
</cwmp:SetParameterValues>`
return buildSoapEnvelope(cwmpId, body)
}
static download(
cwmpId: string | undefined,
params: {
commandKey?: string
fileType?: string
url: string
username?: string
password?: string
fileSize?: number
targetFileName?: string
delaySeconds?: number
successUrl?: string
failureUrl?: string
}
): string {
const body = `<cwmp:Download>
<CommandKey>${params.commandKey || ''}</CommandKey>
<FileType>${params.fileType || '1 Firmware Upgrade Image'}</FileType>
<URL>${params.url}</URL>
<Username>${params.username || ''}</Username>
<Password>${params.password || ''}</Password>
<FileSize>${params.fileSize || 0}</FileSize>
<TargetFileName>${params.targetFileName || ''}</TargetFileName>
<DelaySeconds>${params.delaySeconds || 0}</DelaySeconds>
<SuccessURL>${params.successUrl || ''}</SuccessURL>
<FailureURL>${params.failureUrl || ''}</FailureURL>
</cwmp:Download>`
return buildSoapEnvelope(cwmpId, body)
}
static upload(
cwmpId: string | undefined,
params: { commandKey?: string; fileType?: string; url: string; username?: string; password?: string; delaySeconds?: number }
): string {
const body = `<cwmp:Upload>
<CommandKey>${params.commandKey || ''}</CommandKey>
<FileType>${params.fileType || '3 Vendor Configuration File'}</FileType>
<URL>${params.url}</URL>
<Username>${params.username || ''}</Username>
<Password>${params.password || ''}</Password>
<DelaySeconds>${params.delaySeconds || 0}</DelaySeconds>
</cwmp:Upload>`
return buildSoapEnvelope(cwmpId, body)
}
static reboot(cwmpId?: string, commandKey?: string): string {
const body = `<cwmp:Reboot>
<CommandKey>${commandKey || ''}</CommandKey>
</cwmp:Reboot>`
return buildSoapEnvelope(cwmpId, body)
}
static factoryReset(cwmpId?: string): string {
const body = `<cwmp:FactoryReset></cwmp:FactoryReset>`
return buildSoapEnvelope(cwmpId, body)
}
static scheduleInform(cwmpId: string | undefined, delaySeconds: number, commandKey?: string): string {
const body = `<cwmp:ScheduleInform>
<DelaySeconds>${delaySeconds}</DelaySeconds>
<CommandKey>${commandKey || ''}</CommandKey>
</cwmp:ScheduleInform>`
return buildSoapEnvelope(cwmpId, body)
}
static getParameterAttributes(cwmpId: string | undefined, parameterNames: string[]): string {
const names = parameterNames.map((n) => `<string>${n}</string>`).join('\n ')
const body = `<cwmp:GetParameterAttributes>
<ParameterNames soap-enc:arrayType="xsd:string[${parameterNames.length}]">
${names}
</ParameterNames>
</cwmp:GetParameterAttributes>`
return buildSoapEnvelope(cwmpId, body)
}
static setParameterAttributes(
cwmpId: string | undefined,
attributes: { name: string; notificationChange: boolean; notification: number; accessListChange: boolean; accessList: string[] }[]
): string {
const attrs = attributes
.map(
(a) => `<SetParameterAttributesStruct>
<Name>${a.name}</Name>
<NotificationChange>${a.notificationChange ? '1' : '0'}</NotificationChange>
<Notification>${a.notification}</Notification>
<AccessListChange>${a.accessListChange ? '1' : '0'}</AccessListChange>
<AccessList soap-enc:arrayType="xsd:string[${a.accessList.length}]">
${a.accessList.map((s) => `<string>${s}</string>`).join('')}
</AccessList>
</SetParameterAttributesStruct>`
)
.join('')
const body = `<cwmp:SetParameterAttributes>
<ParameterList soap-enc:arrayType="cwmp:SetParameterAttributesStruct[${attributes.length}]">
${attrs}
</ParameterList>
</cwmp:SetParameterAttributes>`
return buildSoapEnvelope(cwmpId, body)
}
static emptyResponse(): string {
return ''
}
}