00001 #include "headers.h"
00002
00003 const string BasicConfigurationCommand::commandString = "basicConfiguration";
00004
00005
00006 const static string nattedCommandString = "natted";
00007 const static string trustedCommandString = "trusted";
00008 const static string firewalledCommandString = "firewalled";
00009 const static string fastRoutingCommandString = "fastRouting";
00010 const static string avoidCensoredNodesCommandString = "avoidCensoredNodes";
00011 const static string optionsCommandString = "options";
00012 const static string selfNodeCommandString = "selfNode";
00013
00014 string
00015 BasicConfigurationCommand::getCommandString() {
00016 return commandString;
00017 }
00018
00019
00020 void
00021 BasicConfigurationCommand::getHtmlInterface(std::ostream& s) {
00022 UserConfiguration::pageHeading(s);
00023
00024 s << "<h2>Basic Configuration</h2>\n\n";
00025
00026
00027 s << "<h3>Your Computer</h3>";
00028 UserConfiguration::generateNodeHtmlInterface(s, getCommandString(), selfNodeCommandString, GlobalObjects::instance()->getConfig()->getSelf()->getNode());
00029
00030
00031 s << "\n\n";
00032 s << "<h3>Your Options</h3>";
00033 s << "<form action=\"/\" method=get>"
00034 << "<ul>"
00035 << "<input type=hidden name=cmd value=" << getCommandString() << ">"
00036 << "<input type=hidden name=subcmd value=" << optionsCommandString << ">";
00037 generateHtmlCheckbox(s, "Would you like to do fast routing?",
00038 fastRoutingCommandString,
00039 GlobalObjects::instance()->getConfig()->doFastRouting());
00040 generateHtmlCheckbox(s, "Would you like to avoid censored nodes?",
00041 avoidCensoredNodesCommandString,
00042 GlobalObjects::instance()->getConfig()->avoidCensoredNodes());
00043 s << "</ul>\n"
00044 << " <input type=submit value=" << "Set" << "></form>\n";
00045 }
00046
00047
00048 void
00049 BasicConfigurationCommand::run(std::ostream& s) {
00050 if (m_args[1].empty()) {
00051 getHtmlInterface(s);
00052 return;
00053 }
00054 if (m_args[1] == selfNodeCommandString) {
00055 Node* selfNode = GlobalObjects::instance()->getConfig()->getSelf()->getNode();
00056 int port = selfNode->getSocketAddress()->getPort();
00057 if (UserConfiguration::setNode(this, s, selfNode)) {
00058 if (selfNode->getSocketAddress()->getPort() != port) {
00059 GlobalObjects::instance()->getNetworkLayer()->getLli()->changeListeningPortTo(selfNode->getSocketAddress()->getPort());
00060 }
00061 GlobalObjects::instance()->getConfig()->save();
00062 getHtmlInterface(s);
00063 }
00064 else {
00065 s << "Error: failed to change configuration.";
00066 }
00067
00068 }
00069 else if (m_args[1] == optionsCommandString) {
00070
00071 GlobalObjects::instance()->getConfig()->set(Config::DO_FAST_ROUTING_TAG, "false");
00072 GlobalObjects::instance()->getConfig()->set(Config::AVOID_CENSORED_NODES_TAG, "false");
00073
00074
00075 int current = 2;
00076 string nextArg = m_args[current];
00077 while (!nextArg.empty()) {
00078 if (nextArg == fastRoutingCommandString) {
00079 GlobalObjects::instance()->getConfig()->set(Config::DO_FAST_ROUTING_TAG, "true");
00080 }
00081 else if (nextArg == avoidCensoredNodesCommandString) {
00082 GlobalObjects::instance()->getConfig()->set(Config::AVOID_CENSORED_NODES_TAG, "true");
00083 }
00084 current++;
00085 nextArg = m_args[current];
00086 }
00087 GlobalObjects::instance()->getConfig()->save();
00088 getHtmlInterface(s);
00089 }
00090 }
00091
00092
00093
00094