Browse Source

* HTTPServer.cpp: protect SAM pages if disabled

pull/489/head
hagen 9 years ago
parent
commit
75db2867dc
  1. 43
      HTTPServer.cpp

43
HTTPServer.cpp

@ -573,51 +573,48 @@ namespace http {
void ShowSAMSessions (std::stringstream& s) void ShowSAMSessions (std::stringstream& s)
{ {
s << "<b>SAM Sessions:</b><br>\r\n<br>\r\n";
auto sam = i2p::client::context.GetSAMBridge (); auto sam = i2p::client::context.GetSAMBridge ();
if (sam) if (!sam) {
{ ShowError(s, "SAM disabled");
return;
}
s << "<b>SAM Sessions:</b><br>\r\n<br>\r\n";
for (auto& it: sam->GetSessions ()) for (auto& it: sam->GetSessions ())
{ {
s << "<a href=/?page=" << HTTP_PAGE_SAM_SESSION << "&sam_id=" << it.first << ">"; s << "<a href=/?page=" << HTTP_PAGE_SAM_SESSION << "&sam_id=" << it.first << ">";
s << it.first << "</a><br>\r\n" << std::endl; s << it.first << "</a><br>\r\n" << std::endl;
} }
} }
}
void ShowSAMSession (std::stringstream& s, const std::string& id) void ShowSAMSession (std::stringstream& s, const std::string& id)
{ {
s << "<b>SAM Session:</b><br>\r\n<br>\r\n"; s << "<b>SAM Session:</b><br>\r\n<br>\r\n";
auto sam = i2p::client::context.GetSAMBridge (); auto sam = i2p::client::context.GetSAMBridge ();
if (sam) if (!sam) {
{ ShowError(s, "SAM disabled");
return;
}
auto session = sam->FindSession (id); auto session = sam->FindSession (id);
if (session) if (!session) {
{ ShowError(s, "SAM session not found");
return;
}
auto& ident = session->localDestination->GetIdentHash(); auto& ident = session->localDestination->GetIdentHash();
s << "<a href=/?page=" << HTTP_PAGE_LOCAL_DESTINATION << "&b32=" << ident.ToBase32 () << ">"; s << "<a href=/?page=" << HTTP_PAGE_LOCAL_DESTINATION << "&b32=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>\r\n" << std::endl; s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "</a><br>\r\n";
s << "<br>\r\n";
s << "<b>Streams:</b><br>\r\n"; s << "<b>Streams:</b><br>\r\n";
for (auto it: session->ListSockets()) for (auto it: session->ListSockets())
{ {
switch (it->GetSocketType ()) switch (it->GetSocketType ())
{ {
case i2p::client::eSAMSocketTypeSession: case i2p::client::eSAMSocketTypeSession : s << "session"; break;
s << "session"; case i2p::client::eSAMSocketTypeStream : s << "stream"; break;
break; case i2p::client::eSAMSocketTypeAcceptor : s << "acceptor"; break;
case i2p::client::eSAMSocketTypeStream: default: s << "unknown"; break;
s << "stream";
break;
case i2p::client::eSAMSocketTypeAcceptor:
s << "acceptor";
break;
default:
s << "unknown";
} }
s << " [" << it->GetSocket ().remote_endpoint() << "]"; s << " [" << it->GetSocket ().remote_endpoint() << "]";
s << "<br>\r\n" << std::endl; s << "<br>\r\n";
}
}
} }
} }

Loading…
Cancel
Save