2018-03-02 12:51:10 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 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.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
2018-03-17 07:48:05 +01:00
|
|
|
"Server Control"
|
2018-03-02 12:51:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::m::room::id::buf
|
2018-03-05 11:44:03 +01:00
|
|
|
control_room_id
|
|
|
|
{
|
|
|
|
"!control", ircd::my_host()
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room
|
|
|
|
control_room
|
2018-03-02 12:51:10 +01:00
|
|
|
{
|
2018-03-05 11:44:03 +01:00
|
|
|
control_room_id
|
2018-03-02 12:51:10 +01:00
|
|
|
};
|
|
|
|
|
2018-03-05 11:44:03 +01:00
|
|
|
static void
|
|
|
|
_cmd__die(const m::event &event,
|
|
|
|
const string_view &line)
|
|
|
|
{
|
|
|
|
ircd::post([]
|
|
|
|
{
|
|
|
|
ircd::quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
ctx::yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
command_control(const m::event &event)
|
2018-03-26 03:12:17 +02:00
|
|
|
noexcept try
|
2018-03-05 11:44:03 +01:00
|
|
|
{
|
|
|
|
const auto &content
|
|
|
|
{
|
|
|
|
at<"content"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &body
|
|
|
|
{
|
|
|
|
unquote(content.at("body"))
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
token(body, ' ', 0, {})
|
|
|
|
};
|
|
|
|
|
|
|
|
switch(hash(cmd))
|
|
|
|
{
|
2018-04-24 01:39:29 +02:00
|
|
|
case "die"_:
|
2018-03-05 11:44:03 +01:00
|
|
|
return _cmd__die(event, tokens_after(body, ' ', 0));
|
|
|
|
}
|
2018-03-26 03:12:17 +02:00
|
|
|
|
|
|
|
const ircd::module console_module
|
|
|
|
{
|
|
|
|
"console"
|
|
|
|
};
|
|
|
|
|
2018-03-26 09:12:16 +02:00
|
|
|
using prototype = int (std::ostream &, const string_view &, const string_view &);
|
2018-03-26 08:23:30 +02:00
|
|
|
const mods::import<prototype> command
|
2018-03-26 03:12:17 +02:00
|
|
|
{
|
|
|
|
*console_module, "console_command"
|
|
|
|
};
|
|
|
|
|
2018-03-26 08:23:30 +02:00
|
|
|
std::ostringstream out;
|
2018-04-07 07:44:58 +02:00
|
|
|
out.exceptions(out.badbit | out.failbit | out.eofbit);
|
2018-03-26 03:12:17 +02:00
|
|
|
|
2018-03-26 08:23:30 +02:00
|
|
|
out << "<pre>";
|
2018-03-26 09:33:26 +02:00
|
|
|
static const string_view opts{"html"};
|
|
|
|
command(out, body, opts);
|
2018-03-26 08:23:30 +02:00
|
|
|
out << "</pre>";
|
|
|
|
|
2018-04-07 07:44:58 +02:00
|
|
|
const auto str
|
2018-03-26 08:23:30 +02:00
|
|
|
{
|
2018-04-07 07:44:58 +02:00
|
|
|
replace(out.str().substr(0, 48_KiB), '\n', "<br />")
|
2018-03-26 08:23:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const string_view alt //TODO: X
|
|
|
|
{
|
|
|
|
"no alt text"
|
|
|
|
};
|
|
|
|
|
|
|
|
msghtml(control_room, m::me.user_id, str, alt);
|
2018-03-26 03:12:17 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
notice(control_room, e.what());
|
2018-03-05 11:44:03 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 12:51:10 +01:00
|
|
|
const m::hook
|
2018-03-05 11:44:03 +01:00
|
|
|
command_control_hook
|
2018-03-02 12:51:10 +01:00
|
|
|
{
|
2018-03-05 11:44:03 +01:00
|
|
|
command_control,
|
2018-03-02 12:51:10 +01:00
|
|
|
{
|
2018-03-16 21:27:25 +01:00
|
|
|
{ "_site", "vm.notify" },
|
2018-03-03 11:38:05 +01:00
|
|
|
{ "room_id", "!control" },
|
|
|
|
{ "type", "m.room.message" },
|
2018-03-03 08:17:14 +01:00
|
|
|
{ "content",
|
|
|
|
{
|
|
|
|
{ "msgtype", "m.text" }
|
|
|
|
}}
|
|
|
|
}
|
2018-03-02 12:51:10 +01:00
|
|
|
};
|
|
|
|
|
2018-03-05 11:44:03 +01:00
|
|
|
static void
|
|
|
|
create_control_room(const m::event &)
|
|
|
|
{
|
|
|
|
create(control_room_id, m::me.user_id);
|
|
|
|
join(control_room, m::me.user_id);
|
|
|
|
send(control_room, m::me.user_id, "m.room.name", "",
|
|
|
|
{
|
|
|
|
{ "name", "Control Room" }
|
|
|
|
});
|
|
|
|
|
|
|
|
notice(control_room, m::me.user_id, "Welcome to the control room.");
|
|
|
|
notice(control_room, m::me.user_id, "I am the daemon. You can talk to me in this room by highlighting me.");
|
|
|
|
}
|
|
|
|
|
2018-03-02 12:51:10 +01:00
|
|
|
const m::hook
|
2018-03-05 11:44:03 +01:00
|
|
|
create_control_hook
|
2018-03-02 12:51:10 +01:00
|
|
|
{
|
2018-03-05 11:44:03 +01:00
|
|
|
create_control_room,
|
2018-03-02 12:51:10 +01:00
|
|
|
{
|
2018-03-16 21:27:25 +01:00
|
|
|
{ "_site", "vm.notify" },
|
2018-03-03 11:38:05 +01:00
|
|
|
{ "room_id", "!ircd" },
|
|
|
|
{ "type", "m.room.create" },
|
2018-03-03 08:17:14 +01:00
|
|
|
}
|
2018-03-02 12:51:10 +01:00
|
|
|
};
|