import { buildSoapEnvelope } from '../soap.js'
export class CWMPMessageBuilder {
static informResponse(cwmpId?: string): string {
const body = `
1
`
return buildSoapEnvelope(cwmpId, body)
}
static getParameterNames(cwmpId: string | undefined, parameterPath: string, nextLevel: boolean = true): string {
const body = `
${parameterPath}
${nextLevel ? '1' : '0'}
`
return buildSoapEnvelope(cwmpId, body)
}
static getParameterValues(cwmpId: string | undefined, parameterNames: string[]): string {
const names = parameterNames.map((n) => `${n}`).join('\n ')
const body = `
${names}
`
return buildSoapEnvelope(cwmpId, body)
}
static setParameterValues(cwmpId: string | undefined, parameters: { name: string; value: string; type: string }[]): string {
const params = parameters
.map(
(p) => `
${p.name}
${p.value}
`
)
.join('\n ')
const body = `
${params}
papaye-v2
`
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 = `
${params.commandKey || ''}
${params.fileType || '1 Firmware Upgrade Image'}
${params.url}
${params.username || ''}
${params.password || ''}
${params.fileSize || 0}
${params.targetFileName || ''}
${params.delaySeconds || 0}
${params.successUrl || ''}
${params.failureUrl || ''}
`
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 = `
${params.commandKey || ''}
${params.fileType || '3 Vendor Configuration File'}
${params.url}
${params.username || ''}
${params.password || ''}
${params.delaySeconds || 0}
`
return buildSoapEnvelope(cwmpId, body)
}
static reboot(cwmpId?: string, commandKey?: string): string {
const body = `
${commandKey || ''}
`
return buildSoapEnvelope(cwmpId, body)
}
static factoryReset(cwmpId?: string): string {
const body = ``
return buildSoapEnvelope(cwmpId, body)
}
static scheduleInform(cwmpId: string | undefined, delaySeconds: number, commandKey?: string): string {
const body = `
${delaySeconds}
${commandKey || ''}
`
return buildSoapEnvelope(cwmpId, body)
}
static getParameterAttributes(cwmpId: string | undefined, parameterNames: string[]): string {
const names = parameterNames.map((n) => `${n}`).join('\n ')
const body = `
${names}
`
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) => `
${a.name}
${a.notificationChange ? '1' : '0'}
${a.notification}
${a.accessListChange ? '1' : '0'}
${a.accessList.map((s) => `${s}`).join('')}
`
)
.join('')
const body = `
${attrs}
`
return buildSoapEnvelope(cwmpId, body)
}
static emptyResponse(): string {
return ''
}
}