source: src-qt4/pc-adsldap/adsldap.cpp @ 0cfe72f

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 0cfe72f was 0cfe72f, checked in by Kris Moore <kris@…>, 16 months ago

Add all the changes for related using of split pcbsd-utils libs

  • Property mode set to 100644
File size: 9.3 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include <QTextStream>
13#include <QTextBlock>
14#include <QString>
15#include <QDebug>
16#include <QSettings>
17#include <pcbsd-utils.h>
18#include "adsldap.h"
19
20#define ADCONF QString("/usr/local/etc/pc-activedirectory.conf")
21#define LDCONF QString("/usr/local/etc/pc-ldap.conf")
22
23void pcADSLDAP::programInit()
24{
25  connect(pushClose, SIGNAL(clicked()), this, SLOT(slotClose()));
26  connect(pushSave, SIGNAL(clicked()), this, SLOT(slotSave()));
27
28  loadSettings();
29}
30
31void pcADSLDAP::slotClose()
32{
33   saveSettings();
34   close();
35}
36
37void pcADSLDAP::slotSave()
38{
39   saveSettings();
40   exportSettings();
41}
42
43void pcADSLDAP::saveSettings()
44{
45   // Save ADS settings
46   QSettings settings("PCBSD", "ADS");
47   settings.setValue("Enabled", groupADS->isChecked());
48
49   settings.setValue("DomainName", lineADSDomainName->text());
50   settings.setValue("NetBIOS", lineADSNetBIOS->text());
51   settings.setValue("Workgroup", lineADSWorkgroup->text());
52   settings.setValue("TrustedDomains", checkADSTrustedDomains->isChecked());
53   settings.setValue("AdminName", lineADSAdminName->text());
54   settings.setValue("AdminPW", lineADSAdminPW->text());
55
56   QSettings settings2("PCBSD", "LDAP");
57   settings2.setValue("Enabled", groupLDAP->isChecked());
58   settings2.setValue("AnonBinding", checkLDAnonBinding->isChecked());
59   settings2.setValue("EncMode", comboLDEncMode->currentIndex());
60   settings2.setValue("PWEnc", comboLDPWEnc->currentIndex());
61   settings2.setValue("BaseDN", lineLDBaseDN->text());
62   settings2.setValue("GroupSuffix", lineLDGroupSuffix->text());
63   settings2.setValue("Hostname", lineLDHostname->text());
64   settings2.setValue("MachineSuffix", lineLDMachineSuffix->text());
65   settings2.setValue("PWSuffix", lineLDPWSuffix->text());
66   settings2.setValue("RootBindDN", lineLDRootBindDN->text());
67   settings2.setValue("RootBindPW", lineLDRootBindPW->text());
68   settings2.setValue("SelfSignedCert", lineLDSelfSignedCert->text());
69   settings2.setValue("UserSuffix", lineLDUserSuffix->text());
70   settings2.setValue("Aux", textLDAux->toPlainText());
71
72
73   
74}
75
76void pcADSLDAP::loadSettings()
77{
78  QSettings settings("PCBSD", "ADS");
79  QString tmp = pcbsd::Utils::getConfFileValue("/etc/rc.conf", "pc_activedirectory_enable=", 1) ;
80  if ( tmp == "YES" ) 
81    groupADS->setChecked(true);
82  else
83    groupADS->setChecked(false);
84
85  lineADSDomainName->setText(settings.value("DomainName", QString()).toString());
86  lineADSNetBIOS->setText(settings.value("NetBIOS", QString()).toString());
87  lineADSWorkgroup->setText(settings.value("Workgroup", QString()).toString());
88  checkADSTrustedDomains->setChecked(settings.value("TrustedDomains", false).toBool());
89  lineADSAdminName->setText(settings.value("AdminName", QString()).toString());
90  lineADSAdminPW->setText(settings.value("AdminPW", QString()).toString());
91  lineADSAdminPW2->setText(settings.value("AdminPW", QString()).toString());
92
93  QSettings settings2("PCBSD", "LDAP");
94  groupLDAP->setChecked(settings2.value("Enabled", false).toBool());
95  checkLDAnonBinding->setChecked(settings2.value("AnonBinding", false).toBool());
96  comboLDEncMode->setCurrentIndex(settings2.value("EncMode", 0).toInt());
97  comboLDPWEnc->setCurrentIndex(settings2.value("PWEnc", 0).toInt());
98  lineLDBaseDN->setText(settings2.value("BaseDN", QString()).toString());
99  lineLDGroupSuffix->setText(settings2.value("GroupSuffix", QString()).toString());
100  lineLDHostname->setText(settings2.value("Hostname", QString()).toString());
101  lineLDMachineSuffix->setText(settings2.value("MachineSuffix", QString()).toString());
102  lineLDPWSuffix->setText(settings2.value("PWSuffix", QString()).toString());
103  lineLDRootBindDN->setText(settings2.value("RootBindDN", QString()).toString());
104  lineLDRootBindPW->setText(settings2.value("RootBindPW", QString()).toString());
105  lineLDSelfSignedCert->setText(settings2.value("SelfSignedCert", QString()).toString());
106  lineLDUserSuffix->setText(settings2.value("UserSuffix", QString()).toString());
107  textLDAux->insertPlainText(settings2.value("Aux", QString()).toString());
108
109}
110
111void pcADSLDAP::exportAD()
112{
113  // Validate that passwords match
114  if ( lineADSAdminPW->text() != lineADSAdminPW2->text() )
115  {
116     QMessageBox::warning(this, tr("Active Directory Configuration"),
117                                tr("The Active Directory passwords specified do not match!"),
118                                QMessageBox::Ok,
119                                QMessageBox::Ok);
120      return;
121  }
122
123  QString tmp;
124
125  // Now write ADCONF values
126  pcbsd::Utils::setConfFileValue(ADCONF, "ad_domainname =", "ad_domainname = " + lineADSDomainName->text(), -1);
127  pcbsd::Utils::setConfFileValue(ADCONF, "ad_adminname =", "ad_adminname = " + lineADSAdminName->text(), -1);
128  pcbsd::Utils::setConfFileValue(ADCONF, "ad_adminpw =", "ad_adminpw = " + lineADSAdminPW->text(), -1);
129  pcbsd::Utils::setConfFileValue(ADCONF, "ad_workgroup =", "ad_workgroup = " + lineADSWorkgroup->text().toUpper(), -1);
130  pcbsd::Utils::setConfFileValue(ADCONF, "ad_netbiosname =", "ad_netbiosname = " + lineADSNetBIOS->text().toUpper(), -1);
131 
132  if ( checkADSTrustedDomains->isChecked() )
133    pcbsd::Utils::setConfFileValue(ADCONF, "ad_allow_trusted_doms =", "ad_allow_trusted_doms = yes", -1);
134  else
135    pcbsd::Utils::setConfFileValue(ADCONF, "ad_allow_trusted_doms =", "ad_allow_trusted_doms = no", -1);
136
137}
138
139void pcADSLDAP::exportLDAP()
140{
141  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_hostname =", "ldap_hostname = " + lineLDHostname->text(), -1);
142  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_basedn =", "ldap_basedn = " + lineLDBaseDN->text(), -1);
143  if ( checkLDAnonBinding->isChecked() )
144     pcbsd::Utils::setConfFileValue(LDCONF, "ldap_anonbind =", "ldap_anonbind = yes", -1);
145  else
146     pcbsd::Utils::setConfFileValue(LDCONF, "ldap_anonbind =", "ldap_anonbind = no", -1);
147  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_rootbasedn =", "ldap_rootbasedn = " + lineLDRootBindDN->text(), -1);
148  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_rootbindpw =", "ldap_rootbindpw = " + lineLDRootBindPW->text(), -1);
149  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_rootbindpw =", "ldap_rootbindpw = " + lineLDRootBindPW->text(), -1);
150  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_pwencryption =", "ldap_pwencryption = " + comboLDPWEnc->currentText(), -1);
151  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_usersuffix =", "ldap_usersuffix = " + lineLDUserSuffix->text(), -1);
152  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_groupsuffix =", "ldap_groupsuffix = " + lineLDGroupSuffix->text(), -1);
153  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_passwordstuff =", "ldap_passwordstuff = " + lineLDPWSuffix->text(), -1);
154  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_machinesuffix =", "ldap_machinesuffix = " + lineLDMachineSuffix->text(), -1);
155  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_encryption_mode =", "ldap_encryption_mode = " + comboLDEncMode->currentText().toLower(), -1);
156  pcbsd::Utils::setConfFileValue(LDCONF, "ldap_tls_cacertfile =", "ldap_tls_cacertfile = " + lineLDSelfSignedCert->text(), -1);
157
158  // Remove old opts
159  QString optName, optVal;
160  pcbsd::Utils::setConfFileValue(LDCONF, "opt_", "", -1);
161  for ( int i = 0; i < textLDAux->document()->lineCount(); ++i)
162  { 
163
164     // Make sure we have a value and key
165     if ( textLDAux->document()->findBlockByLineNumber(i).text().section('=', 0, 0).isEmpty() )
166       continue;
167     if ( textLDAux->document()->findBlockByLineNumber(i).text().section('=', 1).isEmpty() ) 
168       continue;
169
170     optName = "opt_" + textLDAux->document()->findBlockByLineNumber(i).text().section('=', 0, 0).simplified();
171
172     optVal = textLDAux->document()->findBlockByLineNumber(i).text().section('=', 1).simplified();
173
174     qDebug() << textLDAux->document()->findBlockByLineNumber(i).text() << optName << optVal;
175
176     // Save the config
177     pcbsd::Utils::setConfFileValue(LDCONF, optName + " =", optName + " = " + optVal, -1);
178  }
179}
180
181void pcADSLDAP::exportSettings()
182{
183  // Start adding AD.conf values
184  if ( groupADS->isChecked() ) {
185    exportAD();
186    // Restart AD service if enabled   
187    qDebug() << "Enabling AD";
188    pcbsd::Utils::setConfFileValue("/etc/rc.conf", "pc_activedirectory_enable=", "pc_activedirectory_enable=\"YES\"", -1);
189    pcbsd::Utils::runShellCommand("/usr/local/bin/pc-adctl start");
190  } else {
191     qDebug() << "Disabling AD";
192     pcbsd::Utils::runShellCommand("/usr/local/bin/pc-adctl stop");
193     pcbsd::Utils::setConfFileValue("/etc/rc.conf", "pc_activedirectory_enable=", "pc_activedirectory_enable=\"NO\"", -1);
194  }
195 
196  // Enable the LDAP service
197  if ( groupLDAP->isChecked() ) {
198    exportLDAP();
199     pcbsd::Utils::setConfFileValue("/etc/rc.conf", "pc_ldap_enable=", "pc_ldap_enable=\"YES\"", -1);
200     pcbsd::Utils::runShellCommand("/usr/local/bin/pc-ldapctl start");
201  } else {
202     qDebug() << "Disabling LDAP";
203     pcbsd::Utils::runShellCommand("/usr/local/bin/pc-ldapctl stop");
204     pcbsd::Utils::setConfFileValue("/etc/rc.conf", "pc_ldap_enable=", "pc_ldap_enable=\"NO\"", -1);
205  }
206}
Note: See TracBrowser for help on using the repository browser.