Changeset 549
- Timestamp:
- 04/01/06 07:46:27 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 5 modified
-
config/serversettings.cpp (modified) (3 diffs)
-
config/serversettings.h (modified) (1 diff)
-
gui/config/serverpage.cpp (modified) (7 diffs)
-
gui/config/serverpage.h (modified) (2 diffs)
-
gui/config/serverpage.ui (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/config/serversettings.cpp
r449 r549 51 51 #define SETTING_SERVER_CONTACT "Server/"SERVER_CONTACTINFO 52 52 #define SETTING_SERVER_EXITPOLICY "Server/"SERVER_EXITPOLICY 53 #define SETTING_SERVER_OVERRIDE "Server/OverrideDefault" 53 54 54 55 /* Default server configuration */ … … 63 64 #define DEFAULT_SERVER_ADDRESS net_local_address().toString() 64 65 #define DEFAULT_SERVER_EXITPOLICY (ExitPolicy().toString()) 65 66 #define DEFAULT_SERVER_OVERRIDE false 66 67 67 68 /** Constructor. … … 387 388 } 388 389 390 /** Sets whether we override the default exit policy */ 391 void 392 ServerSettings::setOverridePolicy(bool override) 393 { 394 setValue(SETTING_SERVER_OVERRIDE, override); 395 } 396 397 /** Returns whether we override the default exit policy */ 398 bool 399 ServerSettings::getOverridePolicy() 400 { 401 return value(SETTING_SERVER_OVERRIDE, DEFAULT_SERVER_OVERRIDE).toBool(); 402 } 403 -
trunk/src/config/serversettings.h
r449 r549 93 93 ExitPolicy getExitPolicy(); 94 94 95 /** Sets whether we override the default exit policy */ 96 void setOverridePolicy(bool override); 97 /** Gets whether we override the default exit policy */ 98 bool getOverridePolicy(); 99 95 100 private: 96 101 /** Sets a value indicating that the server settings have changed since -
trunk/src/gui/config/serverpage.cpp
r535 r549 33 33 #include "portvalidator.h" 34 34 35 /* Default Exit Policy */ 36 #define DEFAULT_POLICY Policy(AcceptAll) 35 37 /* Columns of the Exit Policy list */ 36 38 #define COL_ACTION 0 … … 95 97 _settings->setAddress(ui.lineServerAddress->text()); 96 98 _settings->setContactInfo(ui.lineServerContact->text()); 99 _settings->setOverridePolicy(ui.chkExitOverride->isChecked()); 100 101 /* Remove/Add necessary default exit rule */ 102 setDefaultRule(); 103 104 /* Save exit polices */ 105 ExitPolicy exitPolicy; 106 for (int i = 0; i < ui.lstExitPolicies->topLevelItemCount(); ++i) { 107 savePolicy(ui.lstExitPolicies->topLevelItem(i), exitPolicy); 108 } 109 _settings->setExitPolicy(exitPolicy); 110 97 111 bool success = (_torControl->isConnected() ? _settings->apply(&errmsg) : true); 98 112 if (!success) { … … 109 123 ui.chkMirrorDirectory->setChecked(_settings->isDirectoryMirror()); 110 124 ui.chkMiddleMan->setChecked(_settings->isMiddleman()); 125 111 126 ui.lineServerNickname->setText(_settings->getNickname()); 112 127 ui.lineServerPort->setText(QString::number(_settings->getORPort())); … … 114 129 ui.lineServerAddress->setText(_settings->getAddress()); 115 130 ui.lineServerContact->setText(_settings->getContactInfo()); 116 131 ui.chkExitOverride->setChecked(_settings->getOverridePolicy()); 132 133 /* Load the exit policies into the list */ 134 ui.lstExitPolicies->clear(); 135 136 foreach (Policy policy, _settings->getExitPolicy().policyList()) { 137 addPolicyItem(policy); 138 } 139 117 140 ui.frmServer->setVisible(ui.chkEnableServer->isChecked()); 141 } 142 143 /** Adds the exit policy contained in item to the exitPolicy */ 144 void 145 ServerPage::savePolicy(QTreeWidgetItem *item, ExitPolicy &exitPolicy) 146 { 147 /* Build policy string */ 148 QString policyString = item->text(COL_ACTION) + " "; 149 policyString += item->text(COL_ADDRESS) + ":" + item->text(COL_PORT); 150 151 /* Add policy to ServerSettings */ 152 exitPolicy.addPolicy(Policy(policyString)); 153 } 154 155 /** Moves or appends the correct default exit rule to the policy list */ 156 void 157 ServerPage::setDefaultRule() 158 { 159 bool override = ui.chkExitOverride->isChecked(); 160 Policy::SpecialPolicy action; 161 QString actionString; 162 QList<QTreeWidgetItem *> list; 163 bool found = false; 164 165 if (override) { 166 action = Policy::RejectAll; 167 actionString = "reject"; 168 } else { 169 action = Policy::AcceptAll; 170 actionString = "accept"; 171 } 172 173 /* Search for the policy, if exists: move to bottom else: append it */ 174 /* Remove any of the opposite default exit policy */ 175 list = ui.lstExitPolicies->findItems("0.0.0.0", Qt::MatchExactly, COL_ADDRESS); 176 177 foreach (QTreeWidgetItem *item, list) { 178 if (item->text(COL_PORT) == "*") { 179 int index = ui.lstExitPolicies->indexOfTopLevelItem(item); 180 181 /* Found target so move to bottom of list */ 182 if (item->text(COL_ACTION) == actionString) { 183 ui.lstExitPolicies->addTopLevelItem(ui.lstExitPolicies-> 184 takeTopLevelItem(index)); 185 found = true; 186 187 /* Found the opposite so remove */ 188 } else { 189 ui.lstExitPolicies->takeTopLevelItem(index); 190 } 191 } 192 } 193 194 /* Search failed so just append the necessary policy */ 195 if (!found) addPolicyItem(Policy(action)); 118 196 } 119 197 … … 127 205 } 128 206 129 QTreeWidgetItem *newPolicy = new QTreeWidgetItem(); 130 131 /* Add new policy's action */ 132 newPolicy->setText(COL_ACTION, ui.cmboExitAction->currentText()); 133 newPolicy->setTextAlignment(COL_ACTION, Qt::AlignCenter); 134 135 /* Add new policy's ip address */ 136 QString address = ui.lineExitAddress->text(); 137 if (!ui.lineExitMask->text().isEmpty()) { 138 address += ":" + ui.lineExitMask->text(); 139 } 140 newPolicy->setText(COL_ADDRESS, address); 141 newPolicy->setTextAlignment(COL_ADDRESS, Qt::AlignCenter); 142 143 /* Add new policy's port or port range */ 144 QString portRange = ui.lineExitFromPort->text(); 145 if (!portRange.isEmpty()) { 146 QString toPort = ui.lineExitToPort->text(); 147 if (!toPort.isEmpty() && portRange != "*") { 148 portRange += "-" + ui.lineExitToPort->text(); 149 } 150 } 151 newPolicy->setText(COL_PORT, portRange); 152 newPolicy->setTextAlignment(COL_PORT, Qt::AlignCenter); 153 154 /* Add new policy to list */ 155 ui.lstExitPolicies->addTopLevelItem(newPolicy); 207 /* Add the policy to the list */ 208 addPolicyItem(ui.cmboExitAction->currentText(), ui.lineExitAddress->text(), 209 ui.lineExitMask->text(), ui.lineExitFromPort->text(), 210 ui.lineExitToPort->text()); 156 211 157 212 /* Clear input text boxes */ … … 162 217 } 163 218 219 /* Adds a new QTreeWidget item to the exit policy list */ 220 void 221 ServerPage::addPolicyItem(Policy policy) 222 { 223 /* Convert to strings */ 224 QString action = (policy.action() == Policy::Accept ? "accept" : "reject"); 225 QHostAddress address = policy.address(); 226 QString addr = (address.isNull() ? "*" : address.toString()); 227 QString mask = (policy.mask() ? QString::number(policy.mask()) : ""); 228 int port = policy.fromPort(); 229 QString fromPort = (port ? QString::number(port) : ""); 230 port = policy.toPort(); 231 QString toPort = (port ? QString::number(port) : ""); 232 233 /* Add to list */ 234 addPolicyItem(action, addr, mask, fromPort, toPort); 235 } 236 237 /* Adds a new QTreeWidget item to the exit policy list */ 238 void 239 ServerPage::addPolicyItem(QString action, QString address, QString mask, 240 QString fromPort, QString toPort) 241 { 242 QTreeWidgetItem *newPolicy = new QTreeWidgetItem(); 243 244 newPolicy->setText(COL_ACTION, action); 245 newPolicy->setTextAlignment(COL_ACTION, Qt::AlignCenter); 246 247 if (!mask.isEmpty()) { 248 address += "/" + mask; 249 } 250 newPolicy->setText(COL_ADDRESS, address); 251 newPolicy->setTextAlignment(COL_ADDRESS, Qt::AlignCenter); 252 253 if (!fromPort.isEmpty()) { 254 if (!toPort.isEmpty() && fromPort != "*") { 255 fromPort += "-" + toPort; 256 } 257 } else { 258 fromPort = "*"; 259 } 260 261 newPolicy->setText(COL_PORT, fromPort); 262 newPolicy->setTextAlignment(COL_PORT, Qt::AlignCenter); 263 264 ui.lstExitPolicies->addTopLevelItem(newPolicy); 265 } 266 164 267 /** Removes selected exit policy from the user's configuration */ 165 268 void … … 202 305 ServerPage::selectedIndex() 203 306 { 307 if (ui.lstExitPolicies->selectedItems().isEmpty()) return -1; 308 204 309 /* This list only contains one element so take it */ 205 310 QTreeWidgetItem *selectedItem = ui.lstExitPolicies->selectedItems()[0]; 206 207 if (selectedItem) { 208 return ui.lstExitPolicies->indexOfTopLevelItem(selectedItem); 209 } 210 return -1; 311 return ui.lstExitPolicies->indexOfTopLevelItem(selectedItem); 211 312 } 212 313 -
trunk/src/gui/config/serverpage.h
r535 r549 31 31 #include <control/torcontrol.h> 32 32 #include <config/serversettings.h> 33 #include <config/exitpolicy.h> 33 34 #include "../help/browser/helpbrowser.h" 34 35 … … 69 70 /** Returns the index of the selected item in lstExitPolicies */ 70 71 int selectedIndex(); 71 72 /** Adds a new exit policy to the exit policy list */ 73 void addPolicyItem(QString action, QString address, QString mask, 74 QString fromPort, QString toPort); 75 void addPolicyItem(Policy policy); 76 /** Saves the policy specified in item to the exitPolicy */ 77 void savePolicy(QTreeWidgetItem *item, ExitPolicy &exitPolicy); 78 /** Moves or appends the necessary default rule as specified by the user */ 79 void setDefaultRule(); 80 72 81 /** A TorControl object used to talk to Tor */ 73 82 TorControl* _torControl; -
trunk/src/gui/config/serverpage.ui
r526 r549 1062 1062 <item> 1063 1063 <property name="text" > 1064 <string> Accept</string>1064 <string>accept</string> 1065 1065 </property> 1066 1066 </item> 1067 1067 <item> 1068 1068 <property name="text" > 1069 <string> Reject</string>1069 <string>reject</string> 1070 1070 </property> 1071 1071 </item> … … 1088 1088 </item> 1089 1089 <item row="2" column="0" colspan="3" > 1090 <widget class="QCheckBox" name="checkBox" > 1090 <widget class="QCheckBox" name="chkExitOverride" > 1091 <property name="contextMenuPolicy" > 1092 <enum>Qt::NoContextMenu</enum> 1093 </property> 1091 1094 <property name="toolTip" > 1092 1095 <string>If enabled, appends 'reject *.*' to the end of the policy</string>
