Skip to content

Commit edfcd23

Browse files
committed
[webconsole] added a button to prematurely release a leaseset
Signed-off-by: r4sas <[email protected]>
1 parent f21e1c7 commit edfcd23

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

daemon/HTTPServer.cpp

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ namespace http {
8787
const char HTTP_COMMAND_GET_REG_STRING[] = "get_reg_string";
8888
const char HTTP_COMMAND_SETLANGUAGE[] = "setlanguage";
8989
const char HTTP_COMMAND_RELOAD_CSS[] = "reload_css";
90+
const char HTTP_COMMAND_EXPIRELEASE[] = "expirelease";
9091

9192
static std::string ConvertTime (uint64_t time)
9293
{
@@ -434,12 +435,11 @@ namespace http {
434435
if (dest->IsPublic() && token && !dest->IsEncryptedLeaseSet ())
435436
{
436437
std::string webroot; i2p::config::GetOption("http.webroot", webroot);
437-
auto base32 = dest->GetIdentHash ().ToBase32 ();
438438
s << "<div class='slide'><label for='slide-regaddr'><b>" << tr("Address registration line") << "</b></label>\r\n<input type=\"checkbox\" id=\"slide-regaddr\" />\r\n<div class=\"slidecontent\">\r\n"
439439
"<form method=\"get\" action=\"" << webroot << "\">\r\n"
440440
" <input type=\"hidden\" name=\"cmd\" value=\"" << HTTP_COMMAND_GET_REG_STRING << "\">\r\n"
441441
" <input type=\"hidden\" name=\"token\" value=\"" << token << "\">\r\n"
442-
" <input type=\"hidden\" name=\"b32\" value=\"" << base32 << "\">\r\n"
442+
" <input type=\"hidden\" name=\"b32\" value=\"" << dest->GetIdentHash ().ToBase32 () << "\">\r\n"
443443
" <b>" << tr("Domain") << ":</b>\r\n<input type=\"text\" maxlength=\"67\" name=\"name\" placeholder=\"domain.i2p\" required>\r\n"
444444
" <button type=\"submit\">" << tr("Generate") << "</button>\r\n"
445445
"</form>\r\n<small>" << tr("<b>Note:</b> result string can be used only for registering 2LD domains (example.i2p). For registering subdomains please use i2pd-tools.") << "</small>\r\n</div>\r\n</div>\r\n<br>\r\n";
@@ -448,9 +448,23 @@ namespace http {
448448
if (dest->GetNumRemoteLeaseSets())
449449
{
450450
s << "<div class='slide'><label for='slide-lease'><b>" << tr("LeaseSets") << ":</b> <i>" << dest->GetNumRemoteLeaseSets ()
451-
<< "</i></label>\r\n<input type=\"checkbox\" id=\"slide-lease\" />\r\n<div class=\"slidecontent\">\r\n<table><thead><th>"<< tr("Address") << "</th><th>" << tr("Type") << "</th><th>" << tr("EncType") << "</th></thead><tbody class=\"tableitem\">";
451+
<< "</i></label>\r\n<input type=\"checkbox\" id=\"slide-lease\" />\r\n<div class=\"slidecontent\">\r\n"
452+
<< "<table><thead>"
453+
<< "<th>" << tr("Address") << "</th>"
454+
<< "<th style=\"width:5px;\">&nbsp;</th>" // LeaseSet expiration button column
455+
<< "<th>" << tr("Type") << "</th>"
456+
<< "<th>" << tr("EncType") << "</th>"
457+
<< "</thead><tbody class=\"tableitem\">";
452458
for(auto& it: dest->GetLeaseSets ())
453-
s << "<tr><td>" << it.first.ToBase32 () << "</td><td>" << (int)it.second->GetStoreType () << "</td><td>" << (int)it.second->GetEncryptionType () <<"</td></tr>\r\n";
459+
{
460+
s << "<tr>"
461+
<< "<td>" << it.first.ToBase32 () << "</td>"
462+
<< "<td><a class=\"button\" href=\"/?cmd=" << HTTP_COMMAND_EXPIRELEASE<< "&b32=" << dest->GetIdentHash ().ToBase32 ()
463+
<< "&lease=" << it.first.ToBase32 () << "&token=" << token << "\" title=\"" << tr("Expire LeaseSet") << "\"> &#10008; </a></td>"
464+
<< "<td>" << (int)it.second->GetStoreType () << "</td>"
465+
<< "<td>" << (int)it.second->GetEncryptionType () <<"</td>"
466+
<< "</tr>\r\n";
467+
}
454468
s << "</tbody></table>\r\n</div>\r\n</div>\r\n<br>\r\n";
455469
} else
456470
s << "<b>" << tr("LeaseSets") << ":</b> <i>0</i><br>\r\n<br>\r\n";
@@ -1312,6 +1326,36 @@ namespace http {
13121326
res.add_header("Refresh", redirect.c_str());
13131327
return;
13141328
}
1329+
else if (cmd == HTTP_COMMAND_EXPIRELEASE)
1330+
{
1331+
std::string b32 = params["b32"];
1332+
std::string lease = params["lease"];
1333+
1334+
i2p::data::IdentHash ident, leaseident;
1335+
ident.FromBase32 (b32);
1336+
leaseident.FromBase32 (lease);
1337+
auto dest = i2p::client::context.FindLocalDestination (ident);
1338+
1339+
if (dest)
1340+
{
1341+
auto leaseset = dest->FindLeaseSet (leaseident);
1342+
if (leaseset)
1343+
{
1344+
leaseset->ExpireLease ();
1345+
s << "<b>" << tr("SUCCESS") << "</b>:&nbsp;" << tr("LeaseSet expiration time updated") << "<br>\r\n<br>\r\n";
1346+
}
1347+
else
1348+
s << "<b>" << tr("ERROR") << "</b>:&nbsp;" << tr("LeaseSet is not found or already expired") << "<br>\r\n<br>\r\n";
1349+
}
1350+
else
1351+
s << "<b>" << tr("ERROR") << "</b>:&nbsp;" << tr("Destination not found") << "<br>\r\n<br>\r\n";
1352+
1353+
s << "<a href=\"" << webroot << "?page=local_destination&b32=" << b32 << "\">" << tr("Return to destination page") << "</a><br>\r\n";
1354+
s << "<p>" << tr("You will be redirected in %d seconds", COMMAND_REDIRECT_TIMEOUT) << "</b>";
1355+
redirect = std::to_string(COMMAND_REDIRECT_TIMEOUT) + "; url=" + webroot + "?page=local_destination&b32=" + b32;
1356+
res.add_header("Refresh", redirect.c_str());
1357+
return;
1358+
}
13151359
else if (cmd == HTTP_COMMAND_LIMITTRANSIT)
13161360
{
13171361
uint32_t limit = std::stoul(params["limit"], nullptr);

libi2pd/LeaseSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ namespace data
9696
void Encrypt (const uint8_t * data, uint8_t * encrypted) const;
9797
bool IsDestination () const { return true; };
9898

99+
// used in webconsole
100+
void ExpireLease () { m_ExpirationTime = i2p::util::GetSecondsSinceEpoch (); };
101+
99102
protected:
100103

101104
void UpdateLeasesBegin ();

0 commit comments

Comments
 (0)