Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ConnectionManagerCommand.cpp

Go to the documentation of this file.
00001 #include "headers.h"
00002 
00003 const string ConnectionManagerCommand::commandString = "connectionManager";
00004 const static string disconnectCommandString = "disconnect";
00005 
00006 string
00007 ConnectionManagerCommand::getCommandString() {
00008     return commandString;
00009 } // fn getCommandString
00010 
00011 
00012 void
00013 ConnectionManagerCommand::getHtmlInterface(std::ostream& s) {
00014     UserConfiguration::pageHeading(s);
00015 
00016     s << "<h2>Connection Manager</h2>\n\n";
00017 
00018     s << "Current connections:\n";
00019 
00020     LinkLayerInterface* lli = GlobalObjects::instance()->getNetworkLayer()->getLli();
00021     int numConnections = lli->getNumConnections();
00022     
00023     if (numConnections == 0) {
00024         s << "None.\n";
00025         return;
00026     }
00027 
00028     displayHeaders(s);
00029     for (int i = 0; i < numConnections; ++i) {
00030         Node node;
00031         if (lli->getConnection(i, &node)) {
00032             s << "<tr>";
00033             displayNode(s, &node);
00034             s << "</tr>";
00035         }
00036     }
00037 } // fn getHtmlInterface
00038 
00039 
00040 void 
00041 ConnectionManagerCommand::displayHeaders(std::ostream& s) 
00042 {
00043     s << "<table border bordercolor=blue>";
00044     s << "<tr>";
00045     s << "<th>IP</th>";
00046     s << "<th>Port</th>";
00047     s << "<th>Censored?</th>";
00048     s << "<th>NATed?</th>";
00049     s << "<th>Trusted?</th>";
00050     s << "<th>Disconnect</th>";
00051     s << "</tr>";
00052 } // fn displayHeaders
00053 
00054 
00055 void
00056 ConnectionManagerCommand::displayNode(std::ostream& s, Node* node) {
00057     s << "<td>" << node->getSocketAddress()->getIpAddress() << "</td>";
00058     s << "<td>" << node->getSocketAddress()->getPort() << "</td>";
00059     s << "<td>" << (node->isFirewalled() ? "Yes" : "No") << "</td>";
00060     s << "<td>" << (node->isNatted() ? "Yes" : "No") << "</td>";
00061     s << "<td>" << (node->isTrusted() ? "Yes" : "No") << "</td>";
00062 
00063     s << "<td>";
00064     beginForm(s);
00065     formInput(s, "hidden", "cmd", getCommandString());
00066     formInput(s, "hidden", "subcmd", disconnectCommandString);
00067     formInput(s, "hidden", "arg1", node->getSocketAddress()->getIpAddress().toString());
00068     formInput(s, "submit", "", "Disconnect");
00069     endForm(s);
00070     s << "</td>";
00071 } // fn displayNode
00072 
00073 
00074 void
00075 ConnectionManagerCommand::run(std::ostream& s) {
00076     if (m_args[1].empty()) {
00077         getHtmlInterface(s);
00078         return;
00079     }
00080 
00081     if (m_args[1] == disconnectCommandString) {
00082         // Lookup the node
00083         IpAddress ip(m_args[2]);
00084         Node* node;
00085         if (node = GlobalObjects::instance()->getCatcher()->lookup(ip)) {
00086             // ask LLI to disconnect
00087             if (GlobalObjects::instance()->getNetworkLayer()->getLli()->close(node)) {
00088                 getHtmlInterface(s);
00089             }
00090             else {
00091                 s << "Disconnect failed.";
00092             }
00093         }
00094         else {
00095             s << "Node does not exist";
00096         }
00097     }
00098 } // fn run
00099 
00100 

Generated at Thu Jul 11 13:31:50 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001