Apply changes (for Archiving and Retention rules)

Issue #79 resolved
Jack Zielke created an issue

After changing the archival rules you have to tell piler to re-read the config. Normally I ssh to the server to do that. I added a quick and dirty button that does this work from the web interface.

webui/controller/policy/apply.php

<?php
/*
/etc/sudoers:
www-data ALL=NOPASSWD: /usr/bin/pkill -1 -o piler
*/

system('sudo -n pkill -1 -o piler', $val);

if ($val === 0) {
  echo 'Applied';
} else {
  echo 'Error';
}
?>

To the top of webui/view/theme/default/templates/policy/archiving.tpl and webui/view/theme/default/templates/policy/retention.tpl

<div style="float: right; text-align: center;">
    <input type="button" onclick="$('#applyChangesOutput').load('/controller/policy/apply.php');" value="Apply" /><br />
    <span id="applyChangesOutput"></span>
</div>

I installed sudo and then added 1 line to /etc/sudoers

www-data ALL=NOPASSWD: /usr/bin/pkill -1 -o piler

Comments (10)

  1. Jack Zielke reporter

    I don't know if it is worth the effort or not but php can use 'sudo -l' to see if www-data can run that command before showing the button, or the apply.php page could test for that if the pkill command fails and provide a more useful error message than just 'Error'.

  2. Jack Zielke reporter

    Right after echo 'Error';

    <?php
    
      // was the problem with sudo or pkill?
      system('sudo -n -l /usr/bin/pkill -1 -o piler' . " >/dev/null", $val);
      if ($val !== 0) {
        echo '<br />Add the following to /etc/sudoers:<br />www-data ALL=NOPASSWD: /usr/bin/pkill -1 -o piler';
      }
    
  3. Janos SUTO repo owner

    I pushed the modifications to the master branch. Please try it, and let's see whether it works.

    Note that I decided to extend rc.piler script to have a reload feature, so be sure to update it, too.

  4. Jack Zielke reporter

    I have over 50 rules so I have to scroll down to the bottom of the page. Since the applyChangesOutput span is empty it does not render. When I press the apply button the status appears below it and the page gets longer. The status is below the viewable region of the screen. If I put a non-breaking space in that span when I scroll to the bottom of the page to hit apply the status appears on screen.

  5. Janos SUTO repo owner

    I actually modified it, and now it uses a modal screen to give feedback. Check out the latest master branch.

  6. Log in to comment