Browse Source

Ticket 49783 - UI - add server configuration backend

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 can only pull in strerr messages when things fail,
             so I had to undue a recent change to redirect stderr to stdout.

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

Reviewed by: spichugi & vashirov(Thanks!!)
Mark Reynolds 7 years ago
parent
commit
eafaf473aa

+ 3 - 3
src/cockpit/389-console/backend.html

@@ -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>
 

+ 0 - 2
src/cockpit/389-console/css/ds.css

@@ -302,7 +302,6 @@ td {
   max-height: 400px;
   margin: 23px 10px 2px 0px;
   overflow: auto;
-  border-radius: 5px !important;
 }
 
 .ds-monitor-tree {
@@ -317,7 +316,6 @@ td {
   max-height: 400px;
   margin: 10px;
   overflow: auto;
-  border-radius: 5px !important;
 }
 
 .ds-treenode {

+ 13 - 0
src/cockpit/389-console/index.html

@@ -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">

+ 54 - 15
src/cockpit/389-console/js/ds.js

@@ -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 @@ function set_ports() {
   });
 }
 
-// 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 example() {
 }
 
 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 check_for_389 () {
 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 @@ function get_insts() {
       $("#server-content").show();
       $("#server-config").show();
       server_id = insts[0];
+      get_and_set_config();
     }
 
     $("body").show();
@@ -193,12 +211,31 @@ function popup_msg(title, msg) {
   });
 }
 
-$(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 @@ $(window.document).ready(function() {
       this.style.setProperty( 'text-shadow', '0 0 0 #000', 'important' );
     });
   }
+
+
   
 });

+ 117 - 7
src/cockpit/389-console/js/servers.js

@@ -62,7 +62,7 @@ var create_full_template =
 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 clear_inst_form() {
 }
 
 
+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 @@ $(document).ready( function() {
   // 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 @@ $(document).ready( function() {
         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 @@ $(document).ready( function() {
       $(this).css( 'color', '#228bc0');
     });
 
-
     $("#server-config-btn").on("click", function() {
       $(".all-pages").hide();
       $("#server-content").show();
@@ -902,8 +1012,8 @@ $(document).ready( function() {
               /* 
                * 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();

+ 1 - 1
src/cockpit/389-console/replication.html

@@ -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>

+ 1 - 1
src/cockpit/389-console/security.html

@@ -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>
 

+ 46 - 46
src/cockpit/389-console/servers.html

@@ -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>
 

+ 1 - 1
src/lib389/cli/dsconf

@@ -123,7 +123,7 @@ if __name__ == '__main__':
     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

+ 12 - 16
src/lib389/lib389/__init__.py

@@ -2778,15 +2778,14 @@ class DirSrv(SimpleLDAPObject, object):
             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 @@ class DirSrv(SimpleLDAPObject, object):
                 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 @@ class DirSrv(SimpleLDAPObject, object):
                 '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 @@ class DirSrv(SimpleLDAPObject, object):
                 '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 @@ class DirSrv(SimpleLDAPObject, object):
             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")
 

+ 3 - 3
src/lib389/lib389/cli_base/__init__.py

@@ -142,7 +142,7 @@ def _generic_get(inst, basedn, log, manager_class, selector, args=None):
     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(inst, basedn, log, manager_class, selector, args=None):
 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 @@ def _generic_get_attr(inst, basedn, log, manager_class, args=None):
     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())
 

+ 4 - 1
src/lib389/lib389/instance/setup.py

@@ -487,8 +487,11 @@ class SetupDs(object):
         # 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',