summaryrefslogtreecommitdiffstats
path: root/src/secondaryrealmwizard/secondaryrealmwizard.cpp
blob: a9e25c79cea3db8d046822d8eee533ec95699906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/***************************************************************************
 *   Copyright (C) 2012 by Timothy Pearson                                 *
 *   kb9vqf@pearsoncomputing.net                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <unistd.h>

#include <tqpushbutton.h>
#include <tqlabel.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqfile.h>
#include <tqtimer.h>
#include <tqcursor.h>
#include <tqspinbox.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>

#include <ksimpleconfig.h>
#include <tdeglobal.h>
#include <tdeglobalsettings.h>
#include <kstandarddirs.h>
#include <tdelocale.h>
#include <tdeapplication.h>
#include <tdelistview.h>
#include <krun.h>
#include <tdemessagebox.h>
#include <tdeconfig.h>
#include <knuminput.h>
#include <klineedit.h>
#include <ktextedit.h>
#include <kpassdlg.h>
#include <kurlrequester.h>
#include <ksslcertificate.h>

#include <stdlib.h>

#include <kdebug.h>

#include "realmintropage.h"
#include "realmconfigpage.h"
#include "certconfigpage.h"
#include "realmfinishpage.h"

#include "secondaryrealmwizard.h"
#include "secondaryrealmwizard.moc"

SecondaryRealmWizard::SecondaryRealmWizard(LDAPController* controller, TQString fqdn, LDAPCertConfig certinfo, TQWidget *parent, const char *name)
	: KWizard(parent, name, true), m_controller(controller), m_fqdn(fqdn), m_certconfig(certinfo) {

	setCaption(i18n("Secondary Realm Controller Wizard"));

	intropage = new SecondaryRealmIntroPage(this);
	addPage (intropage, i18n( "Step 1: Introduction" ) );
	setHelpEnabled(TQWizard::page(0), false);

	realmpage = new SecondaryRealmConfigPage(this);
	addPage (realmpage, i18n( "Step 2: Gather Realm Information" ) );
	setHelpEnabled(TQWizard::page(1), false);

	finishpage = new SecondaryRealmFinishPage(this);
	addPage (finishpage, i18n( "Step 3: Initialize New Realm Controller" ) );
	setHelpEnabled(TQWizard::page(2), false);

	// Set up some defaults
	realmpage->txtKDCPort->setValue(88);
	realmpage->txtAdminServerPort->setValue(749);
	realmpage->txtUIDOffset->setValue(5000);
	realmpage->txtGIDOffset->setValue(5000);
	realmpage->txtGIDOffset->setValue(5000);
	TQString domainGuess = m_fqdn;
	int firstDot = domainGuess.find(".");
	if (firstDot >= 0) {
		domainGuess.remove(0, firstDot+1);
	}
	realmpage->txtRealmName->setText(domainGuess);
	realmpage->txtKDC->setText(m_fqdn);
	realmpage->txtAdminServer->setText(m_fqdn);
	realmpage->realmNameChanged();

	// Other setup
	finishpage->ldapAdminRealm->setEnabled(false);

	// Kerberos won't work unless the DNS suffix matches the realm name
	realmpage->txtRealmName->setEnabled(false);

	setFinishEnabled(TQWizard::page(2), true);

	setPosition();
}

SecondaryRealmWizard::~SecondaryRealmWizard() {
}


void SecondaryRealmWizard::next() {
	if (currentPage()==intropage) {
		TQWizard::next();
		realmpage->validateEntries();

		// Focus the first entry field on the new wizard page
		realmpage->txtRealmName->setFocus();
		realmpage->txtRealmName->selectAll();
	}
	else if (currentPage()==realmpage) {
		// Save realm information
		m_realmconfig.name = realmpage->txtRealmName->text();
		m_realmconfig.bonded = false;
		m_realmconfig.uid_offset = realmpage->txtUIDOffset->value();
		m_realmconfig.gid_offset = realmpage->txtGIDOffset->value();
		m_realmconfig.domain_mappings = TQStringList::split("\n", realmpage->txtDomains->text(), FALSE);
		m_realmconfig.kdc = realmpage->txtKDC->text();
		m_realmconfig.kdc_port = realmpage->txtKDCPort->value();
		m_realmconfig.admin_server = realmpage->txtAdminServer->text();
		m_realmconfig.admin_server_port = realmpage->txtAdminServerPort->value();
		m_realmconfig.pkinit_require_eku = realmpage->checkRequireEKU->isChecked();
		m_realmconfig.pkinit_require_krbtgt_otherName = realmpage->checkRequireKrbtgtOtherName->isChecked();
		m_realmconfig.win2k_pkinit = realmpage->checkWin2k->isChecked();
		m_realmconfig.win2k_pkinit_require_binding = realmpage->checkWin2kPkinitRequireBinding->isChecked();

		finishpage->ldapAdminRealm->setText(realmpage->txtRealmName->text());
		TQWizard::next();
		finishpage->validateEntries();

		// Focus the first entry field on the new wizard page
		finishpage->ldapAdminUsername->setFocus();
		finishpage->ldapAdminUsername->selectAll();
	}
	if (currentPage()==finishpage) {
		//
	}
}

void SecondaryRealmWizard::slotNext() {
	TQWizard::next();
}

void SecondaryRealmWizard::back() {
	TQWizard::back();
}

bool SecondaryRealmWizard::askClose(){
	TQString text;
	if (currentPage()==intropage) {
		return true;
	}
	else {
		if ((currentPage()==certpage) || (currentPage()==finishpage)) {
			text = i18n("<p>Are you sure you want to quit the Secondary Realm Controller Wizard?</p>"
				"<p>If yes, click <b>Quit</b> and all changes will be lost."
				"<br>If not, click <b>Cancel</b> to return and finish your setup.</p>");
		}
		else {
			text = i18n("<p>Are you sure you want to quit the Secondary Realm Controller Wizard?</p>"
				"<p>If not, click <b>Cancel</b> to return and finish setup.</p>");
		}
		int status = KMessageBox::warningContinueCancel(this,  text, i18n("All Changes Will Be Lost"), KStdGuiItem::quit());
		if(status==KMessageBox::Continue){
			setDefaults();
			return true;
		} else {
			return false;
		}
	}
}

/** the cancel button is connected to the reject() slot of TQDialog,
 *  so we have to reimplement this here to add a dialogbox to ask if we
 *  really want to quit the wizard.
 */
void SecondaryRealmWizard::reject() {
	if (askClose()){
		done(-1);
	}
}

void SecondaryRealmWizard::closeEvent(TQCloseEvent* e){
	if ( askClose() )
		done(0);
	else
		e->ignore();
}

/** maybe call a dialog that the wizard has finished. */
void SecondaryRealmWizard::accept() {
	// Validate entries
	if (finishpage->ldapAdminPassword->password() == "") {
		KMessageBox::error(this, i18n("<qt><b>Password required!</b><p>Please enter the administration account password</qt>"), i18n("Input Error"));
		return;
	}

	// Try to create realm
	TQString errorString;
	// FIXME
	// root account should not be locked to "admin"!
	// when fixing, please fix the other instance of locked "admin" in ldapcontroller.cpp ::load()
	backButton()->setEnabled(false);
	nextButton()->setEnabled(false);
	finishButton()->setEnabled(false);
	cancelButton()->setEnabled(false);
	finishpage->setEnabled(false);

	if (m_controller->createNewSecondaryController(this, m_realmconfig, finishpage->ldapAdminUsername->text(), finishpage->ldapAdminPassword->password().utf8(), finishpage->ldapAdminRealm->text(), &errorString) == 0) {
		done(0);
	}
	else {
		KMessageBox::error(this, i18n("<qt><b>Unable to add new secondary realm controller!</b><p>Details: %1</qt>").arg(errorString), i18n("Unable to add new secondary realm controller"));
	}

	finishpage->setEnabled(true);
	backButton()->setEnabled(true);
	finishButton()->setEnabled(true);
	cancelButton()->setEnabled(true);
}

/** calls all save functions after resetting all features/ OS/ theme selections to Trinity default */
void SecondaryRealmWizard::setDefaults() {
// 	if(realm_dirty)
// 		realmpage->save(false);
}

/** there seems to be a bug in TQWizard, that makes this evil hack necessary */
void SecondaryRealmWizard::setPosition() {
	TQSize hint = intropage->sizeHint();
	TQSize realm_size = realmpage->sizeHint();
	TQSize finish_size = finishpage->sizeHint();

	// get the width of the broadest child-widget
	if ( hint.width() < realm_size.width() )
		hint.setWidth(realm_size.width());
	if ( hint.width() < finish_size.width() )
		hint.setWidth(finish_size.width());

	// get the height of the highest child-widget
	if ( hint.height() < realm_size.height() )
		hint.setHeight(realm_size.height());
	if ( hint.height() < finish_size.height() )
		hint.setHeight(finish_size.height());

	// set the position
	TQRect rect = TDEGlobalSettings::desktopGeometry(TQCursor::pos());
	int w = rect.x() + (rect.width() - hint.width())/2 - 9;
	int h = rect.y() + (rect.height() - hint.height())/2;
	move(w, h);
}