Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    On the $config variable

    Scheduled Pinned Locked Moved General pfSense Questions
    5 Posts 2 Posters 1.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sparkvilla
      last edited by

      Hi all. I am running few basic command on the PHP shell. I have few questions on the $config variable:

      1. How can I dump $config variable to a file using php?
      2. Which will be the format of the file that contains the content of the $config variable?  It is not php, it is not xml, so.. what is it?
      3. Would I be able to parse the content of the file with python?

      Thank you.

      1 Reply Last reply Reply Quote 0
      • jimpJ Offline
        jimp Rebel Alliance Developer Netgate
        last edited by

        Why would you want to do that?

        You can just parse /conf/config.xml direcly with XML functions in python if you're just interested in the values.  $config is just a PHP representation of the contents of config.xml.

        If you have to, you could dump it using something like

        file_put_contents("/root/somefile.txt", var_export($config, true));

        Which would be human and PHP readable.

        Or use serialize() for machine readable.

        But seriously… just read the XML directly. Don't bother adding more PHP to the mix.

        Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        1 Reply Last reply Reply Quote 0
        • S Offline
          sparkvilla
          last edited by

          Thank you for the answer. I will use the config.xml file to gether info on the configuration. My idea is to change the configuration file remotely, i.e. through Ansible, interacting with pfSense with php commands (no-web interface).

          1 Reply Last reply Reply Quote 0
          • jimpJ Offline
            jimp Rebel Alliance Developer Netgate
            last edited by

            That won't be quite so simple, lots of other gotchas there (the config.cache, reloading specific areas, etc).

            There are already threads about doing what you propose.

            Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

            Need help fast? Netgate Global Support!

            Do not Chat/PM for help!

            1 Reply Last reply Reply Quote 0
            • S Offline
              sparkvilla
              last edited by

              I'll try..Could you point me to one of those threads? thanks again

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.