index.js
function onProcCallGet(method, path, args) {
    // log('onProcCallGet('+JSON.stringify(arguments));
    let pathSplit = path.split('/');
    const serviceid = pathSplit.shift();
    const propname = pathSplit.join('/');

    const bInfo = (args.info === 'true');

    if (serviceid == '') { // access 'admin/' => service list
        let re = {net: {}, server_status: {}};
        if (bInfo) {
            re._info = {leaf: false};
        }
        re.net = ipv4.getMACs();

        re.id = {};
        if (bInfo) {
            re.net._info = {
                leaf: false,
                doc: {short: 'Mac address of recognized network peers'},
            };
            re.server_status._info={
                leaf: true,
                doc: {short: 'Check server memory/swap status'},
            };
            re.id._info = {leaf: true, doc:{short: 'Get unique ID of this PicoGW'}};
        }

        return re;
    }

    if (propname == '') { // access 'admin/serviceid/' => property list
        let ret;
        switch (serviceid) {
        case 'net':
            const macs = ipv4.getMACs();
            // log(JSON.stringify(macs));
            ret = macs;
            for (const [mac, macinfo] of Object.entries(macs)) {
                if (bInfo) {
                    ret[mac]._info = {
                        leaf: true,
                        doc: {short: (macinfo.ip || 'IP:null')},
                    };
                }
            }
            return ret;
        case 'server_status':
            return new Promise((ac, rj)=>{
                exec('vmstat', (err, stdout, stderr) => {
                    if (err) {
                        ac({error: 'Command execution failed.',
                            result: err});
                    } else if (stdout !== null) {
                        ac({success: true, result: stdout.split('\n')});
                    } else {
                        ac({error: 'Command execution failed.',
                            result: stderr});
                    }
                });
            });
        case 'id':
            return {id:exports.getMyID()};
        }
        return {error: 'No such service:'+serviceid};
    }

    switch (serviceid) {
    case 'net':
        const m = ipv4.getMACs()[propname];
        if (m == undefined) {
            return {error: 'No such mac address:'+propname};
        }
        return m;
    }
    return {error: 'No such service:'+serviceid};
}
function onProcCallGet(method, path, args) {
    // log('onProcCallGet('+JSON.stringify(arguments));
    let pathSplit = path.split('/');
    const serviceid = pathSplit.shift();
    const propname = pathSplit.join('/');

    const bInfo = (args.info === 'true');

    if (serviceid == '') { // access 'admin/' => service list
        let re = {net: {}, server_status: {}};
        if (bInfo) {
            re._info = {leaf: false};
        }
        re.net = ipv4.getMACs();

        re.id = {};
        if (bInfo) {
            re.net._info = {
                leaf: false,
                doc: {short: 'Mac address of recognized network peers'},
            };
            re.server_status._info={
                leaf: true,
                doc: {short: 'Check server memory/swap status'},
            };
            re.id._info = {leaf: true, doc:{short: 'Get unique ID of this PicoGW'}};
        }

        return re;
    }

    if (propname == '') { // access 'admin/serviceid/' => property list
        let ret;
        switch (serviceid) {
        case 'net':
            const macs = ipv4.getMACs();
            // log(JSON.stringify(macs));
            ret = macs;
            for (const [mac, macinfo] of Object.entries(macs)) {
                if (bInfo) {
                    ret[mac]._info = {
                        leaf: true,
                        doc: {short: (macinfo.ip || 'IP:null')},
                    };
                }
            }
            return ret;
        case 'server_status':
            return new Promise((ac, rj)=>{
                exec('vmstat', (err, stdout, stderr) => {
                    if (err) {
                        ac({error: 'Command execution failed.',
                            result: err});
                    } else if (stdout !== null) {
                        ac({success: true, result: stdout.split('\n')});
                    } else {
                        ac({error: 'Command execution failed.',
                            result: stderr});
                    }
                });
            });
        case 'id':
            return {id:exports.getMyID()};
        }
        return {error: 'No such service:'+serviceid};
    }

    switch (serviceid) {
    case 'net':
        const m = ipv4.getMACs()[propname];
        if (m == undefined) {
            return {error: 'No such mac address:'+propname};
        }
        return m;
    }
    return {error: 'No such service:'+serviceid};
}
function onProcCallGet ( method , path , args ) { // log('onProcCallGet('+JSON.stringify(arguments)); let pathSplit = path . split ( '/' ) ; const serviceid = pathSplit . shift ( ) ; const propname = pathSplit . join ( '/' ) ; const bInfo = ( args . info === 'true' ) ; if ( serviceid == '' ) { // access 'admin/' => service list let re = { net : { } , server_status : { } } ; if ( bInfo ) { re . _info = { leaf : false } ; } re . net = ipv4 . getMACs ( ) ; re . id = { } ; if ( bInfo ) { re . net . _info = { leaf : false , doc : { short : 'Mac address of recognized network peers' } , } ; re . server_status . _info = { leaf : true , doc : { short : 'Check server memory/swap status' } , } ; re . id . _info = { leaf : true , doc : { short : 'Get unique ID of this PicoGW' } } ; } return re ; } if ( propname == '' ) { // access 'admin/serviceid/' => property list let ret ; switch ( serviceid ) { case 'net' : const macs = ipv4 . getMACs ( ) ; // log(JSON.stringify(macs)); ret = macs ; for ( const [ mac , macinfo ] of Object . entries ( macs ) ) { if ( bInfo ) { ret [ mac ] . _info = { leaf : true , doc : { short : ( macinfo . ip || 'IP:null' ) } , } ; } } return ret ; case 'server_status' : return new Promise ( ( ac , rj ) => { exec ( 'vmstat' , ( err , stdout , stderr ) => { if ( err ) { ac ( { error : 'Command execution failed.' , result : err } ) ; } else if ( stdout !== null ) { ac ( { success : true , result : stdout . split ( '\n' ) } ) ; } else { ac ( { error : 'Command execution failed.' , result : stderr } ) ; } } ) ; } ) ; case 'id' : return { id : exports . getMyID ( ) } ; } return { error : 'No such service:' + serviceid } ; } switch ( serviceid ) { case 'net' : const m = ipv4 . getMACs ( ) [ propname ] ; if ( m == undefined ) { return { error : 'No such mac address:' + propname } ; } return m ; } return { error : 'No such service:' + serviceid } ; }
onCall handler of plugin for GET method
@param {string} method Caller method, accept GET only.
@param {string} path Plugin URL path
@param {object} args parameters of this call
@return {object} Returns a Promise object or object containing the result
onCall handler of plugin for GET method