2023-03-03 06:15:54 +01:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
namespace ircd::m::admin
|
|
|
|
{
|
2023-03-03 21:49:19 +01:00
|
|
|
static resource::response handle_get_state(client &, const resource::request &, const room::id &);
|
2023-03-03 21:43:00 +01:00
|
|
|
static resource::response handle_get_members(client &, const resource::request &, const room::id &);
|
2023-03-03 06:23:32 +01:00
|
|
|
static resource::response handle_delete_forward_extremis(client &, const resource::request &, const room::id &);
|
2023-03-03 06:15:54 +01:00
|
|
|
static resource::response handle_get_forward_extremis(client &, const resource::request &, const room::id &);
|
2023-03-03 06:23:32 +01:00
|
|
|
static resource::response handle(client &, const resource::request &);
|
2023-03-03 06:15:54 +01:00
|
|
|
|
|
|
|
extern resource::method get_method;
|
2023-03-03 06:23:32 +01:00
|
|
|
extern resource::method delete_method;
|
2023-03-03 06:15:54 +01:00
|
|
|
extern resource rooms_resource;
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Admin (undocumented) :Rooms"
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::admin::rooms_resource)
|
|
|
|
ircd::m::admin::rooms_resource
|
|
|
|
{
|
|
|
|
"/_synapse/admin/v1/rooms/",
|
|
|
|
{
|
|
|
|
"(undocumented) Admin Rooms",
|
|
|
|
resource::DIRECTORY
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::admin::get_method)
|
|
|
|
ircd::m::admin::get_method
|
|
|
|
{
|
2023-03-03 06:23:32 +01:00
|
|
|
rooms_resource, "GET", handle,
|
2023-03-03 06:15:54 +01:00
|
|
|
{
|
|
|
|
get_method.REQUIRES_OPER
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-03 06:23:32 +01:00
|
|
|
decltype(ircd::m::admin::delete_method)
|
|
|
|
ircd::m::admin::delete_method
|
|
|
|
{
|
|
|
|
rooms_resource, "DELETE", handle,
|
|
|
|
{
|
|
|
|
delete_method.REQUIRES_OPER
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-03 06:15:54 +01:00
|
|
|
ircd::m::resource::response
|
2023-03-03 06:23:32 +01:00
|
|
|
ircd::m::admin::handle(client &client,
|
|
|
|
const resource::request &request)
|
2023-03-03 06:15:54 +01:00
|
|
|
{
|
|
|
|
char buf[768];
|
|
|
|
const string_view &room_id_or_alias
|
|
|
|
{
|
|
|
|
request.parv[0]?
|
|
|
|
url::decode(buf, request.parv[0]):
|
|
|
|
string_view{}
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::id::buf room_id
|
|
|
|
{
|
|
|
|
room_id_or_alias?
|
|
|
|
m::room_id(room_id_or_alias):
|
|
|
|
m::room::id::buf{}
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
2023-03-03 06:23:32 +01:00
|
|
|
if(request.head.method == "DELETE" && cmd == "forward_extremities")
|
|
|
|
return handle_delete_forward_extremis(client, request, room_id);
|
|
|
|
|
|
|
|
if(request.head.method == "GET" && cmd == "forward_extremities")
|
2023-03-03 06:15:54 +01:00
|
|
|
return handle_get_forward_extremis(client, request, room_id);
|
|
|
|
|
2023-03-03 21:43:00 +01:00
|
|
|
if(request.head.method == "GET" && cmd == "members")
|
|
|
|
return handle_get_members(client, request, room_id);
|
|
|
|
|
2023-03-03 21:49:19 +01:00
|
|
|
if(request.head.method == "GET" && cmd == "state")
|
|
|
|
return handle_get_state(client, request, room_id);
|
|
|
|
|
2023-03-03 06:15:54 +01:00
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"/admin/rooms command not found"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-03 06:23:32 +01:00
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::admin::handle_delete_forward_extremis(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const room::id &room_id)
|
|
|
|
{
|
|
|
|
const room::head room_head
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, http::OK, json::members
|
|
|
|
{
|
|
|
|
{ "deleted", long(room::head::reset(room_head)) }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-03 06:15:54 +01:00
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::admin::handle_get_forward_extremis(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const room::id &room_id)
|
|
|
|
{
|
|
|
|
const m::room::head room_head
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
m::resource::response::chunked::json response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
response, "count", json::value
|
|
|
|
{
|
|
|
|
long(room_head.count())
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::array results
|
|
|
|
{
|
|
|
|
response, "results"
|
|
|
|
};
|
|
|
|
|
|
|
|
room_head.for_each([&results]
|
|
|
|
(const auto &event_idx, const auto &event_id)
|
|
|
|
{
|
|
|
|
json::stack::object result
|
|
|
|
{
|
|
|
|
results
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
result, "event_id", event_id
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
result, "depth", json::value
|
|
|
|
{
|
|
|
|
m::get(std::nothrow, event_idx, "depth", 0L)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
2023-03-03 21:43:00 +01:00
|
|
|
|
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::admin::handle_get_members(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const room::id &room_id)
|
|
|
|
{
|
|
|
|
const m::room::members members
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
m::resource::response::chunked::json response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
response, "total", json::value
|
|
|
|
{
|
|
|
|
long(members.count("join"))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
response, "members"
|
|
|
|
};
|
|
|
|
|
|
|
|
members.for_each("join", [&array]
|
|
|
|
(const m::id::user &user_id)
|
|
|
|
{
|
|
|
|
array.append(user_id);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
2023-03-03 21:49:19 +01:00
|
|
|
|
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::admin::handle_get_state(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const room::id &room_id)
|
|
|
|
{
|
|
|
|
const m::room::state state
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
m::resource::response::chunked::json response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
response, "state"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::event::fetch event;
|
|
|
|
state.for_each([&array, &event]
|
|
|
|
(const auto &type, const auto &state_key, const auto &event_idx)
|
|
|
|
{
|
|
|
|
if(likely(seek(std::nothrow, event, event_idx)))
|
|
|
|
array.append(event);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|