Diffstat (limited to 'core/settings/security/security.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/security/security.cpp | 100 |
1 files changed, 94 insertions, 6 deletions
diff --git a/core/settings/security/security.cpp b/core/settings/security/security.cpp index 1b90121..d7871b3 100644 --- a/core/settings/security/security.cpp +++ b/core/settings/security/security.cpp | |||
@@ -31,30 +31,30 @@ | |||
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qlistview.h> | 33 | #include <qlistview.h> |
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | 35 | ||
36 | Security::Security( QWidget* parent, const char* name, WFlags fl ) | 36 | Security::Security( QWidget* parent, const char* name, WFlags fl ) |
37 | : SecurityBase( parent, name, TRUE, fl ) | 37 | : SecurityBase( parent, name, TRUE, WStyle_ContextHelp ) |
38 | { | 38 | { |
39 | valid=FALSE; | 39 | valid=FALSE; |
40 | Config cfg("Security"); | 40 | Config cfg("Security"); |
41 | cfg.setGroup("Passcode"); | 41 | cfg.setGroup("Passcode"); |
42 | passcode = cfg.readEntry("passcode"); | 42 | passcode = cfg.readEntry("passcode"); |
43 | passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE)); | 43 | passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE)); |
44 | cfg.setGroup("Sync"); | 44 | cfg.setGroup("Sync"); |
45 | int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 | 45 | int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 |
46 | int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); | 46 | int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); |
47 | selectNet(auth_peer,auth_peer_bits); | 47 | selectNet(auth_peer,auth_peer_bits,TRUE); |
48 | |||
48 | connect(syncnet, SIGNAL(textChanged(const QString&)), | 49 | connect(syncnet, SIGNAL(textChanged(const QString&)), |
49 | this, SLOT(setSyncNet(const QString&))); | 50 | this, SLOT(setSyncNet(const QString&))); |
50 | 51 | ||
51 | cfg.setGroup("Sync"); | 52 | cfg.setGroup("Sync"); |
52 | QString sa = cfg.readEntry("syncapp","Qtopia"); | 53 | QString sa = cfg.readEntry("syncapp","Qtopia"); |
53 | 54 | ||
54 | //There must be a better way to do that... | ||
55 | for (int i=0; i<syncapp->count(); i++) { | 55 | for (int i=0; i<syncapp->count(); i++) { |
56 | if ( syncapp->text(i) == sa ) { | 56 | if ( syncapp->text(i) == sa ) { |
57 | syncapp->setCurrentItem(i); | 57 | syncapp->setCurrentItem(i); |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
@@ -83,30 +83,70 @@ | |||
83 | autoLogin=true; | 83 | autoLogin=true; |
84 | } | 84 | } |
85 | 85 | ||
86 | cfg.setGroup("SyncMode"); | 86 | cfg.setGroup("SyncMode"); |
87 | int mode = cfg.readNumEntry("Mode",2); // Default to Sharp | 87 | int mode = cfg.readNumEntry("Mode",2); // Default to Sharp |
88 | syncModeCombo->setCurrentItem( mode - 1 ); | 88 | syncModeCombo->setCurrentItem( mode - 1 ); |
89 | |||
90 | //since nobody knows what this is and it doesn't do anything, i'll hide it # CoreDump | ||
91 | // is this work-in-progress or can it be removed? | ||
92 | syncModeCombo->hide(); | ||
89 | 93 | ||
90 | connect(autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool))); | 94 | connect(autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool))); |
91 | connect(userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int))); | 95 | connect(userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int))); |
92 | connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode())); | 96 | connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode())); |
93 | connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode())); | 97 | connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode())); |
94 | connect(syncapp,SIGNAL(activated(int)), this, SLOT(changeSyncApp())); | 98 | connect(syncapp,SIGNAL(activated(int)), this, SLOT(changeSyncApp())); |
99 | connect(restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults())); | ||
100 | connect(deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry())); | ||
95 | 101 | ||
96 | loadUsers(); | 102 | loadUsers(); |
97 | updateGUI(); | 103 | updateGUI(); |
98 | 104 | ||
99 | dl = new QPEDialogListener(this); | 105 | dl = new QPEDialogListener(this); |
100 | showMaximized(); | 106 | showMaximized(); |
101 | } | 107 | } |
102 | 108 | ||
103 | Security::~Security() | 109 | Security::~Security() |
104 | { | 110 | { |
105 | } | 111 | } |
106 | 112 | ||
113 | void Security::deleteListEntry() | ||
114 | { | ||
115 | syncnet->removeItem(syncnet->currentItem()); | ||
116 | } | ||
117 | |||
118 | void Security::restoreDefaults() | ||
119 | { | ||
120 | QMessageBox unrecbox( | ||
121 | tr("Attention"), | ||
122 | tr("<p>All user-defined net ranges will be lost."), | ||
123 | QMessageBox::Warning, | ||
124 | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, | ||
125 | 0, QString::null, TRUE, WStyle_StaysOnTop); | ||
126 | unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel")); | ||
127 | unrecbox.setButtonText(QMessageBox::Yes, tr("Ok")); | ||
128 | |||
129 | if ( unrecbox.exec() == QMessageBox::Yes) | ||
130 | { | ||
131 | syncnet->clear(); | ||
132 | insertDefaultRanges(); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | void Security::insertDefaultRanges() | ||
137 | { | ||
138 | syncnet->insertItem( tr( "192.168.129.0/24" ) ); | ||
139 | syncnet->insertItem( tr( "192.168.1.0/24" ) ); | ||
140 | syncnet->insertItem( tr( "192.168.0.0/16" ) ); | ||
141 | syncnet->insertItem( tr( "172.16.0.0/12" ) ); | ||
142 | syncnet->insertItem( tr( "10.0.0.0/8" ) ); | ||
143 | syncnet->insertItem( tr( "1.0.0.0/8" ) ); | ||
144 | syncnet->insertItem( tr( "Any" ) ); | ||
145 | syncnet->insertItem( tr( "None" ) ); | ||
146 | } | ||
107 | 147 | ||
108 | void Security::updateGUI() | 148 | void Security::updateGUI() |
109 | { | 149 | { |
110 | bool empty = passcode.isEmpty(); | 150 | bool empty = passcode.isEmpty(); |
111 | 151 | ||
112 | changepasscode->setText( empty ? tr("Set passcode" ) | 152 | changepasscode->setText( empty ? tr("Set passcode" ) |
@@ -155,13 +195,13 @@ void Security::accept() | |||
155 | void Security::done(int r) | 195 | void Security::done(int r) |
156 | { | 196 | { |
157 | QDialog::done(r); | 197 | QDialog::done(r); |
158 | close(); | 198 | close(); |
159 | } | 199 | } |
160 | 200 | ||
161 | void Security::selectNet(int auth_peer,int auth_peer_bits) | 201 | void Security::selectNet(int auth_peer,int auth_peer_bits, bool update) |
162 | { | 202 | { |
163 | QString sn; | 203 | QString sn; |
164 | if ( auth_peer_bits == 0 && auth_peer == 0 ) { | 204 | if ( auth_peer_bits == 0 && auth_peer == 0 ) { |
165 | sn = tr("Any"); | 205 | sn = tr("Any"); |
166 | } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { | 206 | } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { |
167 | sn = tr("None"); | 207 | sn = tr("None"); |
@@ -170,12 +210,50 @@ void Security::selectNet(int auth_peer,int auth_peer_bits) | |||
170 | QString::number((auth_peer>>24)&0xff) + "." | 210 | QString::number((auth_peer>>24)&0xff) + "." |
171 | + QString::number((auth_peer>>16)&0xff) + "." | 211 | + QString::number((auth_peer>>16)&0xff) + "." |
172 | + QString::number((auth_peer>>8)&0xff) + "." | 212 | + QString::number((auth_peer>>8)&0xff) + "." |
173 | + QString::number((auth_peer>>0)&0xff) + "/" | 213 | + QString::number((auth_peer>>0)&0xff) + "/" |
174 | + QString::number(auth_peer_bits); | 214 | + QString::number(auth_peer_bits); |
175 | } | 215 | } |
216 | |||
217 | //insert user-defined list of netranges upon start | ||
218 | if (update) { | ||
219 | //User selected/active netrange first | ||
220 | syncnet->insertItem( tr( sn ) ); | ||
221 | |||
222 | Config cfg("Security"); | ||
223 | cfg.setGroup("Sync"); | ||
224 | |||
225 | //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe | ||
226 | QString test = cfg.readEntry("net0",""); | ||
227 | if (test.isEmpty()) { | ||
228 | insertDefaultRanges(); | ||
229 | } else { | ||
230 | // 10 ought to be enough for everybody... :) | ||
231 | // If you need more, don't forget to edit applySecurity() as well | ||
232 | bool already_there=FALSE; | ||
233 | for (int i=0; i<10; i++) { | ||
234 | QString target, netrange; | ||
235 | target.sprintf("net%d", i); | ||
236 | netrange = cfg.readEntry(target,""); | ||
237 | if (! netrange.isEmpty()){ | ||
238 | //make sure we have no "twin" entries | ||
239 | for (int i=0; i<syncnet->count(); i++) { | ||
240 | if ( syncnet->text(i) == netrange ) { | ||
241 | already_there=TRUE; | ||
242 | } | ||
243 | } | ||
244 | if (! already_there) { | ||
245 | syncnet->insertItem( tr( netrange ) ); | ||
246 | } else { | ||
247 | already_there=FALSE; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | |||
176 | for (int i=0; i<syncnet->count(); i++) { | 254 | for (int i=0; i<syncnet->count(); i++) { |
177 | if ( syncnet->text(i).left(sn.length()) == sn ) { | 255 | if ( syncnet->text(i).left(sn.length()) == sn ) { |
178 | syncnet->setCurrentItem(i); | 256 | syncnet->setCurrentItem(i); |
179 | return; | 257 | return; |
180 | } | 258 | } |
181 | } | 259 | } |
@@ -239,13 +317,13 @@ void Security::toggleAutoLogin(bool val) | |||
239 | 317 | ||
240 | 318 | ||
241 | void Security::setSyncNet(const QString& sn) | 319 | void Security::setSyncNet(const QString& sn) |
242 | { | 320 | { |
243 | int auth_peer,auth_peer_bits; | 321 | int auth_peer,auth_peer_bits; |
244 | parseNet(sn,auth_peer,auth_peer_bits); | 322 | parseNet(sn,auth_peer,auth_peer_bits); |
245 | selectNet(auth_peer,auth_peer_bits); | 323 | selectNet(auth_peer,auth_peer_bits,FALSE); |
246 | } | 324 | } |
247 | 325 | ||
248 | void Security::applySecurity() | 326 | void Security::applySecurity() |
249 | { | 327 | { |
250 | if ( valid ) { | 328 | if ( valid ) { |
251 | Config cfg("Security"); | 329 | Config cfg("Security"); |
@@ -254,14 +332,24 @@ void Security::applySecurity() | |||
254 | cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked()); | 332 | cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked()); |
255 | cfg.setGroup("Sync"); | 333 | cfg.setGroup("Sync"); |
256 | int auth_peer=0; | 334 | int auth_peer=0; |
257 | int auth_peer_bits; | 335 | int auth_peer_bits; |
258 | QString sn = syncnet->currentText(); | 336 | QString sn = syncnet->currentText(); |
259 | parseNet(sn,auth_peer,auth_peer_bits); | 337 | parseNet(sn,auth_peer,auth_peer_bits); |
338 | |||
339 | //this is the *selected* (active) net range | ||
260 | cfg.writeEntry("auth_peer",auth_peer); | 340 | cfg.writeEntry("auth_peer",auth_peer); |
261 | cfg.writeEntry("auth_peer_bits",auth_peer_bits); | 341 | cfg.writeEntry("auth_peer_bits",auth_peer_bits); |
342 | |||
343 | //write back all other net ranges in *cleartext* | ||
344 | for (int i=0; i<10; i++) { | ||
345 | QString target; | ||
346 | target.sprintf("net%d", i); | ||
347 | cfg.writeEntry(target,syncnet->text(i)); | ||
348 | } | ||
349 | |||
262 | cfg.writeEntry("syncapp",syncapp->currentText()); | 350 | cfg.writeEntry("syncapp",syncapp->currentText()); |
263 | 351 | ||
264 | /* | 352 | /* |
265 | cfg.setGroup("Remote"); | 353 | cfg.setGroup("Remote"); |
266 | if ( telnetAvailable() ) | 354 | if ( telnetAvailable() ) |
267 | cfg.writeEntry("allow_telnet",telnet->isChecked()); | 355 | cfg.writeEntry("allow_telnet",telnet->isChecked()); |