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

    Config.xml

    Scheduled Pinned Locked Moved Development
    4 Posts 4 Posters 1.7k 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.
    • E
      efk
      last edited by

      Can someone explain the proper/clean way to update the config.xml file in pfsense? I see some code meant to handle the XML, and i see write_config(), but I'm having a hard time putting it all together. A brief tour of the componants and a quick example would help me out immensely.

      Thanks in advance!

      1 Reply Last reply Reply Quote 0
      • P
        phil.davis
        last edited by

        Use the webGUI - every time you press Save the code there updates config.xml with the settings. Then config.xml is used to generate all the various conf files and pf ruleset… and the "Save" button code will signal or restart whatever is needed to implement the changes on-the-fly.

        As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
        If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

        1 Reply Last reply Reply Quote 0
        • stephenw10S
          stephenw10 Netgate Administrator
          last edited by

          If you need to do it from the cli try:

          /etc/rc.reload_all
          

          Steve

          1 Reply Last reply Reply Quote 0
          • B
            bryan.paradis
            last edited by

            @efk:

            Can someone explain the proper/clean way to update the config.xml file in pfsense? I see some code meant to handle the XML, and i see write_config(), but I'm having a hard time putting it all together. A brief tour of the componants and a quick example would help me out immensely.

            Thanks in advance!

            From what I understand:

            1. conf_mount_rw(); For making nanobsd read/write
            2. global $config; For manipulating the config
            3. $config['installedpackages']['packagename]['a']['b']['something'] = "something"; Array elements
            4. write_config(); To write the config
            5. conf_mount_ro(); For moving nanobsd back to read only

            Example Code

            function create_vnstati_image() {
            	conf_mount_rw();
            	global $config;
            	$iface = $_POST['vnstat_interface'];
            	$ifaces_final = convert_friendly_interface_to_real_interface_name($iface);
            	$config['installedpackages']['vnstat2']['config'][0]['vnstat_interface'] = $ifaces_final;
            	exec("/usr/local/bin/vnstati -i ". $ifaces_final ." -vs -o /tmp/newpicture1.png");
            	exec("/usr/local/bin/vnstati -i ". $ifaces_final ." -m -o /tmp/newpicture2.png");
            	exec("/usr/local/bin/vnstati -i ". $ifaces_final ." -d -o /tmp/newpicture3.png");
            	exec("/usr/local/bin/vnstati -i ". $ifaces_final ." -t -o /tmp/newpicture4.png");
            	write_config();
            	conf_mount_ro();
            }
            

            Matching Example XML

            
             <installedpackages><vnstat2><config><monthrotate>1</monthrotate>
            			<vnstat_interface>em0</vnstat_interface>
            			<vnstat_phpfrontend>on</vnstat_phpfrontend>
            			<vnstat_interface2>em1</vnstat_interface2></config></vnstat2></installedpackages> 
            
            

            I think we multiple tags that are in the same xml hierarchical level you would then use an index element in the array

            $config['installedpackages']['packagename]['testpackage']['config'][0]['something'] = "something in config 0";
            
            $config['installedpackages']['packagename]['testpackage']['config'][1]['something'] = "something in config 1";
            
            $config['installedpackages']['packagename]['testpackage']['config'][2]['something'] = "something in config 2";
            
            
             <installedpackages><testpackage><config><something>something in config 0</something></config> 
            		 <config><something>something in config 1</something></config> 
            		 <config><something>something in config 2</something></config></testpackage></installedpackages> 
            
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.