Get ppp username from DSL modem

Putting the header there doesn’t make the values magically appear.

You have to refresh that value from the CPE.

Create a vparam called “pppUsername” with this script:

let result = '';

if (declare("Tags.Bridged", {value: 1}).value !== undefined) {
    log('CPE is bridged, setting PPPoE username to null');
} else if ("value" in args[1]) {
    result = args[1].value[0];
} else {
    let keys = [
        'InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.Username',
        'Device.PPP.Interface.*.Username'
    ];

    result = getParameterValue(keys);
}

return {writable: true, value: [result, "xsd:string"]};

function getParameterValue(keys) {
    for (let key of keys) {
        let d = declare(key, {path: Date.now() - (120 * 1000), value: Date.now()});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return '';
}

Then in your default provision put this:

//Refresh the PPPoE username
declare("VirtualParameters.pppUsername", {value: Date.now()});
2 Likes