mihakralj / opnsense-cli

OPNsense CLI is a command-line utility for FreeBSD, Linux, MacOS and Windows that empowers administrators and power users to manage, configure, and monitor OPNsense firewall systems.
Apache License 2.0
25 stars 2 forks source link

Possible to view / edit interface configuration? #6

Open dbjungle opened 1 month ago

dbjungle commented 1 month ago

I've noticed when I try to view a specific interface it seems to have no effect. I receive more details if I output to yaml, but I'm still unable to do a specific interface. Further more changing one of these aspects (dhcphostname on wan for example) seems to have no effect.

root@DE1FW01:~ # opnsense show interfaces 
   opnsense: {
       interfaces: {
           wan: {…}
           lan: {…}
           lo0: {…}
       }
   }

root@DE1FW01:~ # opnsense show interfaces wan
   opnsense: {
       interfaces: {
           wan: {…}
           lan: {…}
           lo0: {…}
       }
   }

root@DE1FW01:~ # opnsense -y show interfaces wan
opnsense:
    interfaces:
        lan:
            enable: "1"
            if: vtnet1
            ipaddr: 10.1.4.2
            ipaddrv6: track6
            media: ""
            mediaopt: ""
            subnet: "24"
            subnetv6: "64"
            track6-interface: wan
            track6-prefix-id: "0"
        lo0:
            descr: Loopback
            enable: "1"
            if: lo0
            internal_dynamic: "1"
            ipaddr: 127.0.0.1
            ipaddrv6: ::1
            subnet: "8"
            subnetv6: "128"
            type: none
            virtual: "1"
        wan:
            dhcp6-ia-pd-len: "0"
            dhcphostname: DE1FW01
            enable: "1"
            gateway: WAN_GW
            if: vtnet0
            ipaddr: dhcp
            ipaddrv6: dhcp6
            media: ""
            mediaopt: ""

root@DE1FW01:~ # 

Is there something I'm doing wrong?

mihakralj commented 1 month ago

looks like your conf/config.xml has something oddly encoded for interfaces branch. Can you check the XML output of opnsense CLI for interfaces branch, and compare it with your actual interfaces branch in conf/config.xml?

My expectation is that these two won't match - that the parser in opnsense CLI doesn't understand something you have in config.xml.

mihakralj commented 1 month ago

btw, I am really delighted that you discovered this project and actually gave it a try; I abandoned further development of CLI when there was zero traction/interest to get opnsense CLI tool to manage the firewall.

rhaido commented 1 month ago

btw, I am really delighted that you discovered this project and actually gave it a try; I abandoned further development of CLI when there was zero traction/interest to get opnsense CLI tool to manage the firewall.

Is the project completely abandoned? I'm thinking about writing some extensions, in order to build a bridge for ansible automation. I've actually written a small patch to save the JSON output in the file - are you interested in merging it it?

Thanks!

mihakralj commented 1 month ago

Sure, happy to contribute. This project might get more attention this summer again - my vacation tinkering. 😊

rhaido commented 1 month ago

Sure, happy to contribute. This project might get more attention this summer again - my vacation tinkering. 😊

I've just opened a merge request, as discussed.

dbjungle commented 1 month ago

looks like your conf/config.xml has something oddly encoded for interfaces branch. Can you check the XML output of opnsense CLI for interfaces branch, and compare it with your actual interfaces branch in conf/config.xml?

My expectation is that these two won't match - that the parser in opnsense CLI doesn't understand something you have in config.xml.

Sorry for the late response. I have been quite busy with work lately. The interfaces look normal in the XML and it matches the yaml output. Everything looks correct in the XML output of the opnsense CLI as well, but it just can't display any further than the top level of interfaces.

dbjungle commented 1 month ago

btw, I am really delighted that you discovered this project and actually gave it a try; I abandoned further development of CLI when there was zero traction/interest to get opnsense CLI tool to manage the firewall.

I saw on reddit there were a lot of CLI tools so i tried the best looking one (this one). Then I tried the others. I'm guessing most people just modify the XML directly or have gotten used to the FreeBSD commands.