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

    Add apply button on 2.3 pkg xml framework

    Scheduled Pinned Locked Moved Development
    1 Posts 1 Posters 535 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.
    • marcellocM
      marcelloc
      last edited by

      Hi,

      Since dansguardian package on 2.x, I've implemented the 'apply changes' on packages using pkg framework.

      After bootstrap move on 2.3, in order to get the same functionality I've started using functions mark_subsystem_dirty, check_subsystem_drity, etc.

      The procedure below shows how to add this function to any package gui based on pkg framework.

      On each package xml file, add a function call to check dirty state.

      
              <custom_php_resync_config_command>sync_package_e2guardian();</custom_php_resync_config_command> 
      
             <custom_php_command_before_form>e2guardian_check_config();</custom_php_command_before_form> 
      
      

      On package.inc file, create the check config state function

      
      function e2guardian_check_config() {
              global $savemsg, $config;
      
              if (!isset($config['installedpackages']['e2guardian']['config'][0]['enable'])) {
                      return 1;
              }
      
              if (isset($_REQUEST['apply'])) {
                      e2guardian_start("no", false, true);
                      return;
              }
              if (is_subsystem_dirty('e2guardian')) {
                      $savemsg  = gettext("E2guardian configuration has been changed.") . "
      " . gettext("The changes must be applied for them to take effect.");
                      $savemsg .= "<a>  </a>";
             }
      
              return 0;
      }
      
      **On the place you call the code to write files and/or restart the service, replace it with mark_subsystem_dirty('your_package')**
      

      function sync_package_e2guardian($via_rpc = "no", $install_process = false) {
              global $config, $g;
      .
      .  /all code stuff and checks.../
      .
      //mark config changes
      mark_subsystem_dirty('e2guardian');
      }

      
      **Under the function you created to separate save from apply changes on your package inc file, clean the 'dirty' state**
      

      function e2guardian_start($via_rpc = "no", $install_process = false, $force_start = false) {
              global $g, $config, $savemsg;

      clear_subsystem_dirty('e2guardian');
      .
      .
      .

      
      The image attached shows the result.
      ![e2guardian_apply_button.PNG_thumb](/public/_imported_attachments_/1/e2guardian_apply_button.PNG_thumb)
      ![e2guardian_apply_button.PNG](/public/_imported_attachments_/1/e2guardian_apply_button.PNG)
      

      Treinamentos de Elite: http://sys-squad.com

      Help a community developer! ;D

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