Curl command > PHP script (SHOW CONFIG)

Hello,

I’m trying use CURL command in a php script to get show configuration (JSON format)

CLI COMMAND :

curl -X POST -F data=‘{“op”: “showConfig”, “path”: }’ -F key=99112200f -k https://192.168.1.16/retrieve

RESULT :

  • “success”:true,
  • “data”:{
    • “interfaces”:{
      • “ethernet”:{
        • “eth0”:{
          • “address”:“dhcp”,
          • “duplex”:“auto”,
          • “hw-id”:“08:00:27:1d:88:6f”,
          • “smp-affinity”:“auto”,
          • “speed”:“auto”},
        • “eth1”:{
          • “address”:“172.16.0.1/24”,
          • “duplex”:“auto”,
          • “hw-id”:“08:00:27:8f:dc:fc”,
          • “smp-affinity”:“auto”,
          • “speed”:“auto”}},
      • “loopback”:{
        • “lo”:{}}},
    • “nat”:{
      • “source”:{
        • “rule”:{
          • “1”:{
            • “outbound-interface”:“eth0”,
            • “source”:{
              • “address”:“172.16.0.0/24”},
            • “translation”:{
              • “address”:“masquerade”}}}}},
    • “service”:{
      • “https”:{
        • “api”:{
          • “keys”:{
            • “id”:{
              • “REST”:{
                • “key”:“99112200f”}}}},
        • “certificates”:{
          • “system-generated-certificate”:{
            • “lifetime”:“65535”}},
        • “listen-address”:{
          • “*”:{}}},
      • “snmp”:{
        • “contact”:“Fabien GRAGLIA”,
        • “description”:“VyOS-VR”,
        • “location”:“FRANCE”,
        • “v3”:{
          • “engineid”:“0x81f998b699aaf8c2cfb9a6bed9da764e60f6”,
          • “group”:{
            • “GV3”:{
              • “mode”:“ro”,
              • “seclevel”:“auth”,
              • “view”:“defaultview”}},
          • “user”:{
            • “V3”:{
              • “auth”:{
                • “encrypted-key”:“0xcd0d4d3f6f6de48cbaac022279aabcf790047757”,
                • “type”:“sha”},
              • “group”:“GV3”,
              • “mode”:“ro”,
              • “privacy”:{
                • “encrypted-key”:“0xcd0d4d3f6f6de48cbaac022279aabcf7”,
                • “type”:“des”}}},
          • “view”:{
            • “defaultview”:{
              • “oid”:{
                • “1”:{}}}}}},
      • “ssh”:{
        • “listen-address”:“192.168.1.16”,
        • “port”:“666”}},
    • “system”:{
      • “config-management”:{
        • “commit-revisions”:“100”},
      • “console”:{
        • “device”:{
          • “ttyS0”:{
            • “speed”:“115200”}}},
      • “host-name”:“vyos”,
      • “login”:{
        • “user”:{
          • “vyos”:{
            • “authentication”:{
              • “encrypted-password”:“$6$O5bbPP.gmb$CBTvZnnNbrt9nQ2NmgCe11rux9XOJS6aWQGTtyyuUALeGsRqpr7N885Wd5UcYCzKYO0MXG8XcxzO1f9MeFUjQ1”,
              • “plaintext-password”:“”},
            • “level”:“admin”}}},
      • “ntp”:{
      • “syslog”:{
        • “global”:{
          • “facility”:{
            • “all”:{
              • “level”:“all”},
            • “protocols”:{
              • “level”:“info”}}}},
      • “time-zone”:“Europe/Paris”}},
  • “error”:null

PHP file TEST :

PHP EXECUTION :

PHP Notice: Array to string conversion in /usr/share/nginx/html/templated-visualize/php/SHOWCMD.php on line 28

echo $info is your issue

https://www.php.net/manual/en/function.curl-getinfo.php

If opt is given, returns its value. Otherwise, returns an associative array with the following elements (which correspond to opt ), or **FALSE** on failure:

It returns an associative array by default, and you’re trying to echo it as a string. Try print_r($info)

2 Likes

Thanks @IZT_crobinson