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 | |||
@@ -36,3 +36,3 @@ | |||
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 | { |
@@ -46,3 +46,4 @@ | |||
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&)), |
@@ -53,3 +54,2 @@ | |||
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++) { |
@@ -88,2 +88,6 @@ | |||
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 | ||
@@ -94,2 +98,4 @@ | |||
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 | ||
@@ -106,2 +112,36 @@ Security::~Security() | |||
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 | ||
@@ -160,3 +200,3 @@ void Security::done(int r) | |||
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 | { |
@@ -175,2 +215,40 @@ void Security::selectNet(int auth_peer,int 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++) { |
@@ -244,3 +322,3 @@ void Security::setSyncNet(const QString& sn) | |||
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 | } |
@@ -259,4 +337,14 @@ void Security::applySecurity() | |||
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()); |