PHP code example of cis-bv / netconf

1. Go to this page and download the library: Download cis-bv/netconf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cis-bv / netconf example snippets


$netConf = new NetConf(
    "192.168.0.100",
    new NetConfAuthPassword(
        [
            "username" => "lamoni",
            "password" => "phpsux"
        ]
    )
);

echo $netConf->sendRPC(
    "<get-config>".
        "<source>".
            "<running/>".
        "</source>".
    "</get-config>"
);

use CisBv\Netconf\NetConfConfigClient;

$netConf = new NetConfConfigClient(
    "192.168.0.100",
    new NetConfAuthPassword(
        [
            "username" => "lamoni",
            "password" => "phpsux"
        ]
    )
);

$editConfig = $netConf->editConfig(
    configString: "<configuration>
        <interfaces>
            <interface>
                <name>fe-0/0/0</name>
                <description>Testing netconf</description>
            </interface>
        </interfaces>
    </configuration>",
    dataStore: 'candidate',
    customParameters: ['custom-param' => 'custom-value']
);


if ($editConfig === false) {
    echo "Something went completely wrong. The config could not be edited."
} else {
    $commit = $netConf->commit();
    if ($commit === false || !$commit->isRpcReplyOk()) {
        echo "Commit failed.";
        if ($commit instanceof NetConfMessageReceiveRpc) {
            var_dump($commit->getRpcReplyError());
        }
    } else {
        echo "Successfully committed, dude!";
    }
}

$getUsersNames = $netConf->getConfig(
    [
       "configuration/system/login/user" => [
           [
               "name"=>"user"
           ]
       ]
    ]
);