00001 #include "headers.h"
00002 const static string nattedCommandString = "natted";
00003 const static string trustedCommandString = "trusted";
00004 const static string firewalledCommandString = "firewalled";
00005
00010
00011
00016 void
00017 UserConfiguration::generateMenu(std::ostream& s) {
00018 s << "<a href=\"/?cmd=" << SummaryScreenCommand::commandString << "\">" << "Summary Screen" << "</a>";
00019 s << " ";
00020 s << "<a href=\"/?cmd=" << BasicConfigurationCommand::commandString << "\">" << "Basic Configuration" << "</a>";
00021 s << " ";
00022 s << "<a href=\"/?cmd=" << AdvancedConfigurationCommand::commandString << "\">" << "Advanced Configuration" << "</a>";
00023 s << " ";
00024 s << "<a href=\"/?cmd=" << ConnectionManagerCommand::commandString << "\">" << "Connection Manager" << "</a>";
00025 s << " ";
00026 s << "<a href=\"/?cmd=" << NodeManagerCommand::commandString << "\">" << "Node Manager" << "</a>";
00027 s << " ";
00028 #ifdef TEST
00029 s << "<a href=\"/?cmd=" << HttpTestPageCommand::httpTestPageCommandString << "\">" << "Developer Testing Interface" << "</a>";
00030 #endif
00031 }
00032
00033
00034 void
00035 UserConfiguration::pageHeading(std::ostream& s) {
00036 s << "<h1>Configure Peekabooty (Version " << PEEK_A_BOOTY_VERSION << ")</h1>";
00037 s << "\n\n";
00038 generateMenu(s);
00039 s << "\n\n";
00040 }
00041
00042
00043 void
00044 UserConfiguration::generateHtmlCheckbox(std::ostream& out, string description, string value, bool isChecked) {
00045 out << description << " <input type=checkbox name=arg value=" << value << " "
00046 << (isChecked ? "CHECKED" : "" ) << ">";
00047 }
00048
00049
00050 void
00051 UserConfiguration::generateNodeHtmlInterface(std::ostream& s, string command, string subcommand, Node* node) {
00052 SocketAddress* tmpSocketAddress = node->getSocketAddress();
00053 IpAddress tmpIpAddress = tmpSocketAddress->getIpAddress();
00054
00055 s << "<form action=\"/\" method=get>"
00056 << "<ul>"
00057 << "<input type=hidden name=cmd value=" << command << ">"
00058 << "<input type=hidden name=subcmd value=" << subcommand << ">"
00059
00060 << "<li>IP Address: "
00061 << "<input type=text name=arg1 value=" << tmpIpAddress << ">\n"
00062
00063 << "<li>Port: "
00064 << "<input type=text name=arg2 value=" << tmpSocketAddress->getPort() << ">\n";
00065
00066 s << "<li>";
00067 generateHtmlCheckbox(s, "Behind a NAT?", "natted", node->isNatted());
00068 s << "<li>";
00069 generateHtmlCheckbox(s, "Censored?", "firewalled", node->isFirewalled());
00070 s << "<li>";
00071 generateHtmlCheckbox(s, "Trusted?", "trusted", node->isTrusted());
00072 s << "</ul>\n"
00073 << " <input type=submit value=" << "Set" << "></form>\n";
00074 }
00075
00076
00080 bool
00081 UserConfiguration::setNode(Command* command, std::ostream& s, Node* node) {
00082 SocketAddress socketAddress(IpAddress((unsigned long)0), DEFAULT_PORT);
00083
00084
00085 socketAddress.setIpAddress(command->getArg(2).c_str());
00086
00087
00088 if (!command->getArg(3).empty()) {
00089 socketAddress.setPort(command->getArg(3).c_str());
00090 }
00091
00092
00093 if (socketAddress.isZero() || (socketAddress.getIpAddress().equals((unsigned long)INADDR_ANY))) {
00094 s << "IP address or port is in error.";
00095 return false;
00096 }
00097
00098
00099 node->setSocketAddress(&socketAddress);
00100
00101
00102 node->setIsNatted(false);
00103 node->setIsFirewalled(false);
00104 node->setIsTrusted(false);
00105
00106
00107 int current = 4;
00108 string nextArg = command->getArg(current);
00109 while (!nextArg.empty()) {
00110 if (nextArg == nattedCommandString) {
00111 node->setIsNatted(true);
00112 }
00113 else if (nextArg == firewalledCommandString) {
00114 node->setIsFirewalled(true);
00115 }
00116 else if (nextArg == trustedCommandString) {
00117 node->setIsTrusted(true);
00118 }
00119 current++;
00120 nextArg = command->getArg(current);
00121 }
00122
00123 return true;
00124 }
00125
00126