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 | |||
@@ -34,7 +34,7 @@ | |||
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"); |
@@ -44,14 +44,14 @@ | |||
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); |
@@ -86,12 +86,18 @@ | |||
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(); |
@@ -104,6 +110,40 @@ 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 | { |
@@ -158,7 +198,7 @@ void Security::done(int 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 ) { |
@@ -173,6 +213,44 @@ void Security::selectNet(int auth_peer,int auth_peer_bits) | |||
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); |
@@ -242,7 +320,7 @@ 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() |
@@ -257,8 +335,18 @@ void Security::applySecurity() | |||
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 | /* |