#49785 Ticket 49783 - UI - add server configuration backend
Closed 3 years ago by spichugi. Opened 5 years ago by mreynolds.
mreynolds/389-ds-base ticket49783  into  master

@@ -130,7 +130,7 @@ 

        <p></p>

      </div>

      <div class="ds-footer">

-       <button id="backend-config-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -239,7 +239,7 @@ 

        </div>

      </div>

      <div class="ds-footer">

-       <button id="save-chaining-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -584,7 +584,7 @@ 

      </div>

  

      <div class="ds-footer">

-       <button id="db-suffix-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  

@@ -302,7 +302,6 @@ 

    max-height: 400px;

    margin: 23px 10px 2px 0px;

    overflow: auto;

-   border-radius: 5px !important;

  }

  

  .ds-monitor-tree {
@@ -317,7 +316,6 @@ 

    max-height: 400px;

    margin: 10px;

    overflow: auto;

-   border-radius: 5px !important;

  }

  

  .ds-treenode {

@@ -172,6 +172,19 @@ 

    popup modals from any action dropdown, or right-click option need to be defined here

    ---------------------------------------- -->

  

+   <div class="modal fade" id="success-form" tabindex="-1" role="dialog" aria-labelledby="success-label" aria-hidden="true">

+     <div class="modal-dialog">

+       <div class="modal-content">

+         <div class="modal-header">

+            <h4 class="modal-title" id="success-label">Success!</h4>

+         </div>

+         <div class="modal-body">

+           <p id="success-msg"><p>

+         </div>

+       </div>

+     </div>

+   </div>

+ 

    <div class="modal fade" id="restore-form" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="restore-label" aria-hidden="true">

      <div class="modal-dialog ds-modal-wide">

        <div class="modal-content">

@@ -1,8 +1,20 @@ 

  var DS_HOME = "/etc/dirsrv/";

  var server_id = "None";

  var dn_regex = new RegExp( "^([A-Za-z]+=.*)" );

- 

- 

+ var config_values = {};

+ //TODO - need "config_values" for all the other pages: SASL, backend, suffix, etc.

+ 

+ // Used for local development testing

+ var DSCONF = "dsconf";

+ var DSCTL = "dsctl";

+ var DSCREATE = "dscreate";

+ var ENV = "";

+ /*

+ var DSCONF = '/home/mareynol/source/ds389/389-ds-base/src/lib389/cli/dsconf';

+ var DSCTL = '/home/mareynol/source/ds389/389-ds-base/src/lib389/cli/dsctl';

+ var DSCREATE = '/home/mareynol/source/ds389/389-ds-base/src/lib389/cli/dscreate';

+ var ENV = "PYTHONPATH=/home/mareynol/source/ds389/389-ds-base/src/lib389";

+ */

  

  // TODO validation functions

  
@@ -57,12 +69,19 @@ 

    });

  }

  

- // POC - REMOVE!!!!!

+ /* Example - remove eventually

+  *

+  * To test a local version of dsconf/lib389 use something like:

+  *

+  *     var cmd = ['/home/mareynol/source/ds389/389-ds-base/src/lib389/cli/dsconf',

+  *               '-j', 'ldapi://%2fvar%2frun%2fslapd-' + server_id + '.socket','config',

+  *               'replace'];

+  *    cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": ["PYTHONPATH=/home/mareynol/source/ds389/389-ds-base/src/lib389"]}).done(function() {

+  */

  function test_json_and_dsconf () {

-     var cmd = ['/home/mareynol/source/ds389/389-ds-base/src/lib389/cli/dsconf',

-                '-j', 'ldapi://%2fvar%2frun%2fslapd-localhost.socket','backend',

-                'list']

-     cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": ["PYTHONPATH=/home/mareynol/source/ds389/389-ds-base/src/lib389"]}).done(function(data) {

+     var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2fslapd-' + server_id + '.socket','backend', 'list']

+     cockpit.spawn(cmd, { superuser: true, "err": "message"}).done(function(data) {

+         console.log(data);

          var obj = JSON.parse(data);

          console.log("backend: " + obj['items']);

      }).fail(function(data) {
@@ -83,7 +102,6 @@ 

  }

  

  function set_no_insts () {

-     console.log("Settign no instance");

      var select = document.getElementById("select-server");

      var el = document.createElement("option");

      el.textContent = "No instances";
@@ -112,7 +130,6 @@ 

  function get_insts() {

    var insts = [];

    var cmd = ["/bin/sh", "-c", "/usr/bin/ls -d " + DS_HOME + "slapd-*"];

- 

    cockpit.spawn(cmd, { superuser: true }).done(function(data) {

      // Parse the output, and skip removed instances and empty lines

      var lines = data.split('\n');
@@ -158,6 +175,7 @@ 

        $("#server-content").show();

        $("#server-config").show();

        server_id = insts[0];

+       get_and_set_config();

      }

  

      $("body").show();
@@ -193,12 +211,31 @@ 

    });

  }

  

- $(function() {

-   $('#select-server').change(function() {

-     server_id = $(this).val();

-     // TODO - reload config - do everything!!!!!

-   });

- });

+ function popup_success(msg) {

+   $('#success-msg').html(msg);

+   $('#success-form').modal('show');

+   setTimeout(function() {$('#success-form').modal('hide');}, 1500);

+ }

+ 

+ // This is called when any Save button is clicked on the main page.  We call

+ // all the save functions for all the pages here.  This is not used for modal forms

+ function save_all () {

+   save_config();  // Server Config Page

+   //

+   // TODO:

+   //   save_chaining();

+   //   save_chaining_suffix();

+   //   save_global_backend();

+   //   save_suffix();

+   //   save_sasl();

+   //   save_security();

+ }

+ 

+ function load_config (){

+   // TODO - set all the pages

+   get_and_set_config(); // cn=config stuff

+ 

+ }

  

  $(window.document).ready(function() {

  
@@ -209,5 +246,7 @@ 

        this.style.setProperty( 'text-shadow', '0 0 0 #000', 'important' );

      });

    }

+ 

+ 

    

  });

@@ -62,7 +62,7 @@ 

  var create_inf_template = 

    "[general]\n" +

    "config_version = 2\n" +

-   "full_machine_name = FQDN\n" +

+   "full_machine_name = FQDN\n\n" +

    "[slapd]\n" +

    "user = USER\n" +

    "group = GROUP\n" +
@@ -159,6 +159,106 @@ 

  }

  

  

+ function get_and_set_config () {

+   var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket','config', 'get'];

+   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(data) {

+     var obj = JSON.parse(data);

+     for (var attr in obj['attrs']) {

+       var val = obj['attrs'][attr][0];

+       attr = attr.toLowerCase();

+       if( $('#' + attr).length ) {

+         // We have  an element that matches, set the html and store the original value

+         $("#" + attr).val(val);  // Always set value, then check if its something else

+         if (val == "on") {

+           $("#" + attr).prop('checked', true);

+           $("#" + attr).trigger('change');

+         } else if (val == "off") {

+           $("#" + attr).prop('checked', false);

+           $("#" + attr).trigger('change');

+         }

+         config_values[attr] = val;

+       }

+     }

+   }).fail(function(data) {

+       console.log("failed: " + data.message);

+   });

+ }

+ 

+ function apply_mods(mods) {

+   var mod = mods.pop();

+ 

+   if (!mod){

+     popup_success("Successfully updated configuration");

+     return; /* all done*/

+   }

+   var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket','config', 'replace'];

+   cmd.push(mod.attr + "=" + mod.val);

+ 

+   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).then(function() {

+     config_values[mod.attr] = mod.val;

+     // Continue with next mods (if any))

+     apply_mods(mods);

+   }, function(ex) {

+      popup_err("Error", "Failed to update attribute: " + mod.attr + "\n\n" +  ex);

+      // Reset HTML for remaining values that have not been processed

+      $("#" + mod.attr).val(config_values[mod.attr]);

+      for (remaining in mods) {

+        $("#" + remaining.attr).val(config_values[remaining.attr]);

+      }

+      return;  // Stop on error

+   });

+ }

+ 

+ function save_config() {

+   // Loop over current config_values check for differences

+   var mod_list = [];

+ 

+   for (var attr in config_values) {

+     var mod = {};

+     if ( $("#" + attr).is(':checkbox')) {

+       // Handle check boxes

+       if ( $("#" + attr).is(":checked")) {

+         if (config_values[attr] != "on") {

+           mod['attr'] = attr;

+           mod['val'] = "on";

+           mod_list.push(mod);

+         }

+       } else {

+         // Not checked

+         if (config_values[attr] != "off") {

+           mod['attr'] = attr;

+           mod['val'] = "off";

+           mod_list.push(mod);

+         }

+       }

+     } else {

+       // Normal input

+       var val = $("#" + attr).val();

+ 

+       // But first check for rootdn-pw changes and check confirm input matches

+       if (attr == "nsslapd-rootpw" && val != config_values[attr]) {

+         // Password change, make sure passwords match

+         if (val != $("#nsslapd-rootpw-confirm").val()){

+           popup_msg("Passwords do not match!", "The Directory Manager passwords do not match, please correct before saving again.");

+           return;

+         }

+       }

+ 

+       if ( val && val != config_values[attr]) {

+         mod['attr'] = attr;

+         mod['val'] = val;

+         mod_list.push(mod);

+       }

+     }

+   }

+ 

+   // Build dsconf commands to apply all the mods

+   if (mod_list.length) {

+     apply_mods(mod_list);

+   } else {

+     // No changes to save, log msg?  popup_msg()

+   }

+ }

  

  // load the server config pages

  $(document).ready( function() {
@@ -167,15 +267,21 @@ 

    // Fill in the server instance dropdown  

    get_insts();

    check_for_389();

+ 

    $("#server-tab").css( 'color', '#228bc0');

  

    $("#server-content").load("servers.html", function () {

-     // Initial page setup

+     // Handle changing instance here

+     $('#select-server').on("change", function() {

+       server_id = $(this).val();

+       load_config();

+     });

+ 

      $('.disk-monitoring').hide();

      $(".all-pages").hide();

      $("#server-content").show();

      $("#server-config").show();

-     

+ 

      // To remove text border on firefox on dropdowns)

      if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {  

        $("select").focus( function() {      
@@ -184,7 +290,12 @@ 

          this.style.setProperty( 'text-shadow', '0 0 0 #000', 'important' );

        });

      }

-     

+ 

+     $(".save-button").on('click', function (){

+       // This is for all pages.  Click Save -> it saves everything

+       save_all();

+     });

+ 

      // Events

      $(".ds-nav-choice").on('click', function (){

        $(".ds-tab-list").css( 'color', '#777');
@@ -197,7 +308,6 @@ 

        $(this).css( 'color', '#228bc0');

      });

  

- 

      $("#server-config-btn").on("click", function() {

        $(".all-pages").hide();

        $("#server-content").show();
@@ -902,8 +1012,8 @@ 

                /* 

                 * Next, create the instance...

                 */

-               cmd = ['dscreate', 'install', setup_file];

-               cockpit.spawn(cmd, { superuser: true, "err": "message" }).fail(function(ex) {

+               cmd = [DSCREATE, 'install', setup_file];

+               cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV] }).fail(function(ex) {

                  // Failed to create the new instance!

                  cockpit.spawn(rm_cmd, { superuser: true });  // Remove Inf file with clear text password

                  $("#create-inst-spinner").hide();

@@ -132,7 +132,7 @@ 

        <p></p>

      </div>

      <div class="ds-footer">

-       <button id="repl-config-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  </div>

@@ -257,7 +257,7 @@ 

        </div>

      </div>

      <div class="ds-footer">

-       <button id="cert-config-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  

@@ -52,9 +52,9 @@ 

          </div>

          <div>

            <label for="nsslapd-disk-monitoring-grace-period" class="ds-config-diskmon-label disk-monitoring" title=

-             "How many minutes to wait to allow an admin to clean up disk space before shutting slapd down. The default is 60 minutes. (nsslapd-disk-monitoring-grace-period)."> 

+             "How many minute to wait to allow an admin to clean up disk space before shutting slapd down. The default is 60 minute. (nsslapd-disk-monitoring-grace-period).">

              Disk Monitoring Grace Period </label><input

-             class="ds-input disk-monitoring" type="text" id="nsslapd-disk-monitoring-grace-period " size="10"/>

+             class="ds-input disk-monitoring" type="text" id="nsslapd-disk-monitoring-grace-period" size="10"/>

          </div>

          <div>

            <input type="checkbox" class="ds-config-diskmon-checkbox disk-monitoring" id="nsslapd-disk-monitoring-logging-critical"><label
@@ -120,8 +120,8 @@ 

       <div>

         <label for="nsslapd-allow-anonymous-access" class="ds-config-label" title="Allow anonymous binds to the server (nsslapd-allow-anonymous-access)."> Allow Anonymous Access</label><select

            class="btn btn-default dropdown" id="nsslapd-allow-anonymous-access">

-             <option>On</option>

-             <option>Off</option>

+             <option>on</option>

+             <option>off</option>

              <option title="Allows anonymous search and read access to search the root DSE itself, but restricts access to all other directory entries. ">rootdse</option>

         </select>

       </div>
@@ -143,7 +143,7 @@ 

         </div>

         <div>

           <label for="nsslapd-rootpw-confirm" class="ds-config-label" title="Confirm directory manager password.">Confirm Password</label><input

-            class="ds-input" type="password" id="nsslapd-rootdn-confirm" size="40"/>

+            class="ds-input" type="password" id="nsslapd-rootpw-confirm" size="40"/>

         </div>

         <div>

           <label for="nsslapd-rootpwstoragescheme" class="ds-config-label" title="Set the Directory Manager password storage scheme (nsslapd-rootpwstoragescheme).">Password Storage Scheme</label><select
@@ -168,7 +168,7 @@ 

      <p></p>

  

      <div class="ds-footer">

-       <button id="server-config-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -193,7 +193,7 @@ 

        </div>

      </div>

      <div class="ds-footer">

-       <button id="server-sasl-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

  

      <h4 class="ds-config-header"><br>SASL Mappings</h4>
@@ -436,7 +436,7 @@ 

            </div>

          </div>

          <div class="ds-footer">

-           <button id="server-pwp-save-btn" class="btn btn-primary">Save</button>

+           <button class="btn btn-primary save-button">Save</button>

          </div>

        </div>

      </div>
@@ -532,11 +532,11 @@ 

            <div>

              <label for="nsslapd-accesslog-logrotationtime" class="ds-config-sub-label" title="Access log rotation time settings (nsslapd-accesslog-logrotationtime).">Create New Log Every...</label><input

                class="ds-input" type="text" id="nsslapd-accesslog-logrotationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-accesslog-logrotationtimeunit">

-                 <option>Minutes</option>

-                 <option>Hours</option>

-                 <option>Days</option>

-                 <option>Weeks</option>

-                 <option>Months</option>

+                 <option>minute</option>

+                 <option>hours</option>

+                 <option>day</option>

+                 <option>week</option>

+                 <option>month</option>

                </select> at <input class="ds-input" type="text"  title="Hour" id="nsslapd-accesslog-logrotationsynchour" placeholder="0" size="1"/> : <input class="ds-input" type="text" placeholder="0"

                  title="Minute" id="nsslapd-accesslog-logrotationsyncminute" size="1"/>

            </div>
@@ -556,9 +556,9 @@ 

            <div>

              <label for="nsslapd-accesslog-logexpirationtime" class="ds-config-sub-label" title="Server deletes an old archived log file when it is older than the specified age. (nsslapd-accesslog-logexpirationtime).">Log File is Older Than... </label><input

                class="ds-input" type="text" id="nsslapd-accesslog-logexpirationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-accesslog-logexpirationtimeunit">

-                 <option>Days</option>

-                 <option>Weeks</option>

-                 <option>Months</option>

+                 <option>day</option>

+                 <option>week</option>

+                 <option>month</option>

                </select>

            </div>

          </div>
@@ -587,7 +587,7 @@ 

          </table>

        </div>

      <div class="ds-footer">

-       <button id="server-access-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -622,11 +622,11 @@ 

          <div>

            <label for="nsslapd-auditlog-logrotationtime" class="ds-config-sub-label" title="Audit log rotation time settings (nsslapd-auditlog-logrotationtime).">Create New Log Every...</label><input

              class="ds-input" type="text" id="nsslapd-auditlog-logrotationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-auditlog-logrotationtimeunit">

-               <option>Minutes</option>

-               <option>Hours</option>

-               <option>Days</option>

-               <option>Weeks</option>

-               <option>Months</option>

+               <option>minute</option>

+               <option>hours</option>

+               <option>day</option>

+               <option>week</option>

+               <option>month</option>

              </select> at <input class="ds-input" type="text"  title="Hour" id="nsslapd-auditlog-logrotationsynchour" placeholder="0" size="1"/> : <input class="ds-input" type="text" placeholder="0"

                title="Minute" id="nsslapd-auditlog-logrotationsyncminute" size="1"/>

          </div>
@@ -646,15 +646,15 @@ 

          <div>

            <label for="nsslapd-auditlog-logexpirationtime" class="ds-config-sub-label" title="Server deletes an old archived log file when it is older than the specified age. (nsslapd-auditlog-logexpirationtime).">Log File is Older Than... </label><input

              class="ds-input" type="text" id="nsslapd-auditlog-logexpirationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-auditlog-logexpirationtimeunit">

-               <option>Days</option>

-               <option>Weeks</option>

-               <option>Months</option>

+               <option>day</option>

+               <option>week</option>

+               <option>month</option>

              </select>

          </div>

        </div>

      </div>

      <div class="ds-footer">

-       <button id="server-audit-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -681,11 +681,11 @@ 

          <div>

            <label for="nsslapd-auditfaillog-logrotationtime" class="ds-config-sub-label" title="Audit failure log rotation time settings (nsslapd-auditlog-logrotationtime).">Create New Log Every...</label><input

              class="ds-input" type="text" id="nsslapd-auditfaillog-logrotationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-auditfaillog-logrotationtimeunit">

-               <option>Minutes</option>

-               <option>Hours</option>

-               <option>Days</option>

-               <option>Weeks</option>

-               <option>Months</option>

+               <option>minute</option>

+               <option>hours</option>

+               <option>day</option>

+               <option>week</option>

+               <option>month</option>

              </select> at <input class="ds-input" type="text"  title="Hour" id="nsslapd-auditfaillog-logrotationsynchour" placeholder="0" size="1"/> : <input class="ds-input" type="text" placeholder="0"

                title="Minute" id="nsslapd-auditfaillog-logrotationsyncminute" size="1"/>

          </div>
@@ -704,15 +704,15 @@ 

          <div>

            <label for="nsslapd-auditfaillog-logexpirationtime" class="ds-config-sub-label" title="Server deletes an old archived log file when it is older than the specified age. (nsslapd-auditfaillog-logexpirationtime).">Log File is Older Than... </label><input

              class="ds-input" type="text" id="nsslapd-auditfaillog-logexpirationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-auditfaillog-logexpirationtimeunit">

-               <option>Days</option>

-               <option>Weeks</option>

-               <option>Months</option>

+               <option>day</option>

+               <option>week</option>

+               <option>month</option>

              </select>

          </div>

        </div>

      </div>

      <div class="ds-footer">

-       <button id="server-auditfail-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -738,11 +738,11 @@ 

          <div>

            <label for="nsslapd-errorlog-logrotationtime" class="ds-config-sub-label" title="Errors log rotation time settings (nsslapd-errorlog-logrotationtime).">Create New Log Every...</label><input

              class="ds-input" type="text" id="nsslapd-errorlog-logrotationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-errorlog-logrotationtimeunit">

-               <option>Minutes</option>

-               <option>Hours</option>

-               <option>Days</option>

-               <option>Weeks</option>

-               <option>Months</option>

+               <option>minute</option>

+               <option>hours</option>

+               <option>day</option>

+               <option>week</option>

+               <option>month</option>

              </select> at <input class="ds-input" type="text"  title="Hour" id="nsslapd-errorlog-logrotationsynchour" placeholder="0" size="1"/> : <input class="ds-input" type="text" placeholder="0"

                title="Minute" id="nsslapd-errorlog-logrotationsyncminute" size="1"/>

          </div>
@@ -762,9 +762,9 @@ 

          <div>

            <label for="nsslapd-errorlog-logexpirationtime" class="ds-config-sub-label" title="Server deletes an old archived log file when it is older than the specified age. (nsslapd-errorlog-logexpirationtime).">Log File is Older Than... </label><input

              class="ds-input" type="text" id="nsslapd-errorlog-logexpirationtime" size="40"/> <select class="btn btn-default dropdown" id="nsslapd-errorlog-logexpirationtimeunit">

-               <option>Days</option>

-               <option>Weeks</option>

-               <option>Months</option>

+               <option>day</option>

+               <option>week</option>

+               <option>month</option>

              </select>

          </div>

        </div>
@@ -843,7 +843,7 @@ 

        </table>

      </div>

      <div class="ds-footer">

-       <button id="server-errors-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -951,7 +951,7 @@ 

        </div>

      </div>

      <div class="ds-footer">

-       <button id="server-tuning-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  
@@ -1007,7 +1007,7 @@ 

        </div>

      </div>

      <div class="ds-footer">

-       <button id="server-ldapi-save-btn" class="btn btn-primary">Save</button>

+       <button class="btn btn-primary save-button">Save</button>

      </div>

    </div>

  

file modified
+1 -1
@@ -123,7 +123,7 @@ 

      except Exception as e:

          log.debug(e, exc_info=True)

          if args and args.json:

-             print(e)

+             sys.stderr.write(str(e))

          else:

              log.error("Error: %s" % str(e))

          result = False

file modified
+12 -16
@@ -2778,15 +2778,14 @@ 

              cmd.append('-E')

  

          try:

-             result = subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding='utf-8')

-             u_result = ensure_str(result)

+             result = subprocess.check_output(cmd, encoding='utf-8')

          except subprocess.CalledProcessError as e:

              self.log.debug("Command: {} failed with the return code {} and the error {}".format(

                             format_cmd_list(cmd), e.returncode, e.output))

              return False

  

          self.log.debug("ldif2db output: BEGIN")

-         for line in u_result.split("\n"):

+         for line in result.split("\n"):

              self.log.debug(line)

          self.log.debug("ldif2db output: END")

  
@@ -2847,15 +2846,14 @@ 

                  ldifname = "/" + self.serverid + "-" + datetime.now().strftime("%Y_%m_%d_%H_%M_%S")

              cmd.append(self.get_ldif_dir() + ldifname)

          try:

-             result = subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding='utf-8')

-             u_result = ensure_str(result)

+             result = subprocess.check_output(cmd, encoding='utf-8')

          except subprocess.CalledProcessError as e:

              self.log.debug("Command: {} failed with the return code {} and the error {}".format(

                             format_cmd_list(cmd), e.returncode, e.output))

              return False

  

          self.log.debug("db2ldif output: BEGIN")

-         for line in u_result.split("\n"):

+         for line in result.split("\n"):

              self.log.debug(line)

          self.log.debug("db2ldif output: END")

  
@@ -2884,15 +2882,14 @@ 

                  'archive2db',

                  '-a', archive_dir,

                  '-D', self.get_config_dir()

-             ], stderr=subprocess.STDOUT, encoding='utf-8')

-             u_result = ensure_str(result)

+             ], encoding='utf-8')

          except subprocess.CalledProcessError as e:

              self.log.debug("Command: {} failed with the return code {} and the error {}".format(

                             format_cmd_list(cmd), e.returncode, e.output))

              return False

  

          self.log.debug("bak2db output: BEGIN")

-         for line in u_result.split("\n"):

+         for line in result.split("\n"):

              self.log.debug(line)

          self.log.debug("bak2db output: END")

  
@@ -2923,14 +2920,14 @@ 

                  'db2archive',

                  '-a', archive_dir,

                  '-D', self.get_config_dir()

-             ], stderr=subprocess.STDOUT, encoding='utf-8')

-             u_result = ensure_str(result)

+             ], encoding='utf-8')

          except subprocess.CalledProcessError as e:

              self.log.debug("Command: {} failed with the return code {} and the error {}".format(

-                         format_cmd_list(cmd), e.returncode, e.output))

+                            format_cmd_list(cmd), e.returncode, e.output))

+             return False

  

          self.log.debug("db2bak output: BEGIN")

-         for line in u_result.split("\n"):

+         for line in result.split("\n"):

              self.log.debug(line)

          self.log.debug("db2bak output: END")

  
@@ -2986,15 +2983,14 @@ 

              cmd.append(vlvTag)

  

          try:

-             result = subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding='utf-8')

-             u_result = ensure_str(result)

+             result = subprocess.check_output(cmd, encoding='utf-8')

          except subprocess.CalledProcessError as e:

              self.log.debug("Command: {} failed with the return code {} and the error {}".format(

                             format_cmd_list(cmd), e.returncode, e.output))

              return False

  

          self.log.debug("db2index output: BEGIN")

-         for line in u_result.split("\n"):

+         for line in result.split("\n"):

              self.log.debug(line)

          self.log.debug("db2index output: END")

  

@@ -142,7 +142,7 @@ 

      mc = manager_class(inst, basedn)

      if args and args.json:

          o = mc.get(selector, json=True)

-         log.info(o)

+         print(o)

      else:

          o = mc.get(selector)

          o_str = o.display()
@@ -152,7 +152,7 @@ 

  def _generic_get_entry(inst, basedn, log, manager_class, args=None):

      mc = manager_class(inst, basedn)

      if args and args.json:

-         log.info(mc.get_all_attrs_json())

+         print(mc.get_all_attrs_json())

      else:

          log.info(mc.display())

  
@@ -161,7 +161,7 @@ 

      mc = manager_class(inst, basedn)

      for attr in args.attrs:

          if args and args.json:

-             log.info(mc.get_attr_vals_json(attr))

+             print(mc.get_attr_vals_json(attr))

          else:

              log.info(mc.display_attr(attr).rstrip())

  

@@ -487,8 +487,11 @@ 

          # Change the root password finally

  

          # Initialise ldapi socket information. IPA expects this ....

-         ds_instance.config.set('nsslapd-ldapifilepath', ds_instance.get_ldapi_path())

+         ldapi_path = slapd['run_dir'].replace('dirsrv', 'slapd-' + slapd['instance_name'] + '.socket')

+         ds_instance.config.set('nsslapd-ldapifilepath', ldapi_path)

          ds_instance.config.set('nsslapd-ldapilisten', 'on')

+         ds_instance.config.set('nsslapd-ldapiautobind', 'on')

+         ds_instance.config.set('nsslapd-ldapimaprootdn', slapd['root_dn'])

  

          # Complete.

          ds_instance.config.set('nsslapd-rootpw',

Description: This patch pulls in all the cn=config values and poplues the UI.
it also allows you to save values to the server.

         Also cockpit and ony pull in stenerr messages when things fail,
         so I had to undue a recent change to redirect strderr to stdout.

https://pagure.io/389-ds-base/issue/49783

Reviewed by: ?

rebased onto a42aa7ccecf8ee7943c5978442f4d6684bb342e5

5 years ago

rebased onto 0b716d9d9474b642ac407e19f90531455cd2fb39

5 years ago

Hey Mark, I'm having issues trying this change. I noticed that by default instance is created with nsslapd-ldapifilepath: /var/run/ldapi, but in Cockpit you talk to the server using path /var/run/slapd-INSTANCE.socket.

Also, if I change the path to socket to an expected value, I'm getting:

failed: {'desc': 'Inappropriate authentication', 'info': 'SASL EXTERNAL bind requires an SSL connection'}

Do I need a special setup before trying this?

Hey Mark, I'm having issues trying this change. I noticed that by default instance is created with nsslapd-ldapifilepath: /var/run/ldapi, but in Cockpit you talk to the server using path /var/run/slapd-INSTANCE.socket.

This is a bug in the installer...

Also, if I change the path to socket to an expected value, I'm getting:
failed: {'desc': 'Inappropriate authentication', 'info': 'SASL EXTERNAL bind requires an SSL connection'}

Related, I think is because we do not set nsslapd-ldapiautobind to on in the installer either.

I'll fix that in this PR.

rebased onto 8917cb35e79c2fd93f1fde7922f4688d24db7923

5 years ago

I fixed the installer. Now instances by default are fully configured for ldapi/autobind(for root dn)

rebased onto f568e910876a687c8a7bcb60be466270283d69db

5 years ago

rebased onto ad760d7384e7758f9c1e3b6f1c70da9f3d7b6b88

5 years ago

Somehow this doesn't work for me:
In JS console:

failed: {'desc': "Can't contact LDAP server", 'errno': 111, 'info': 'Connection refused'}

In the error log I see that it still listens on /var/run/ldapi:

[28/Jun/2018:21:32:52.130145807 +0000] - INFO - slapd_daemon - Listening on /var/run/ldapi for LDAPI requests

But I also see that the other socket is created.

[root@server ds]# ll /var/run/slapd-test.socket 
srw-rw-rw-. 1 root root 0 Jun 28 21:27 /var/run/slapd-test.socket

I'm creating instance using WebUI, if that matters...

rebased onto 1631bfbdbde72bef9252c623c379e971568955de

5 years ago

Somehow this doesn't work for me:
In JS console:
failed: {'desc': "Can't contact LDAP server", 'errno': 111, 'info': 'Connection refused'}

In the error log I see that it still listens on /var/run/ldapi:
[28/Jun/2018:21:32:52.130145807 +0000] - INFO - slapd_daemon - Listening on /var/run/ldapi for LDAPI requests

I reproduced the problem, but its not a bug. Its the environment. Its pulling in the wrong python-lib389 package (PYTHONPATH). So its something with your test environment. I did make a change in ds.js where you can specify your custom python path etc. So you could build the rpms and install everything from scratch, or set variables at the top of src/cockpit/389-console/js/ds.js and it should work.

You're right! I had lib389 installed from the repo without changes in PR and system lib389 installed from rpms generated from this PR. Now I got this working: values are fetched from the server and I can change them.

One last minor thing: we have /var/run/dirsrv where we store .stats and .pid for each instance. I think we create ldapi sockets there as well. The rest LGTM.

One last minor thing: we have /var/run/dirsrv where we store .stats and .pid for each instance. I think we create ldapi sockets there as well.

The docs use this example:

/var/run/slapd-example.socket

This is the same format I used in this fix. I did a little poking around online and this seems to be the normal convention, but I don't think its a requirement. I'd prefer to stay consistent with the docs

As I said, it's a minor thing. It would be nice to consolidate all dirsrv temporary files in one place. But that's just my OCD talking :)

                                  As I said, it's a minor thing. It would be nice to consolidate all dirsrv temporary files in one place. But that's just my OCD talking :)

I agree it would be nice, but I don't want to stray from the docs. Anyway thanks for the review I get this merged shortly, then I will try rebasing my other branches :-o <wish me luck>

rebased onto eafaf47

5 years ago

Pull-Request has been merged by mreynolds

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/2844

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago