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)
|
|
|
|
{
|
2019-03-27 01:29:50 +01:00
|
|
|
static ios::descriptor descriptor
|
|
|
|
{
|
|
|
|
"s_control die"
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::post(descriptor, []
|
2018-03-05 11:44:03 +01:00
|
|
|
{
|
|
|
|
ircd::quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
ctx::yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-10-07 07:17:46 +02:00
|
|
|
command_control(const m::event &event,
|
|
|
|
m::vm::eval &)
|
2018-03-26 03:12:17 +02:00
|
|
|
noexcept try
|
2018-03-05 11:44:03 +01:00
|
|
|
{
|
2020-04-11 03:03:20 +02:00
|
|
|
if(json::get<"room_id"_>(event) != control_room_id) //TODO: XXX see hook
|
|
|
|
return;
|
|
|
|
|
2018-03-05 11:44:03 +01:00
|
|
|
const auto &content
|
|
|
|
{
|
|
|
|
at<"content"_>(event)
|
|
|
|
};
|
|
|
|
|
2020-04-11 02:23:12 +02:00
|
|
|
const json::string &body
|
2018-03-05 11:44:03 +01:00
|
|
|
{
|
2020-04-11 02:23:12 +02:00
|
|
|
content.at("body")
|
2018-03-05 11:44:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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-09-14 03:02:10 +02:00
|
|
|
mods::import<prototype> command
|
2018-03-26 03:12:17 +02:00
|
|
|
{
|
2018-09-14 03:02:10 +02:00
|
|
|
console_module, "console_command"s
|
2018-03-26 03:12:17 +02:00
|
|
|
};
|
|
|
|
|
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>";
|
2020-04-21 12:08:54 +02:00
|
|
|
static const string_view opts{"html"}; try
|
|
|
|
{
|
|
|
|
command(out, body, opts);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
const ctx::exception_handler eh;
|
|
|
|
notice(control_room, e.what());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-26 08:23:30 +02:00
|
|
|
out << "</pre>";
|
|
|
|
|
2018-05-03 06:48:33 +02:00
|
|
|
std::string str
|
2018-03-26 08:23:30 +02:00
|
|
|
{
|
2018-05-03 06:48:33 +02:00
|
|
|
out.str().substr(0, 32_KiB)
|
2018-03-26 08:23:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const string_view alt //TODO: X
|
|
|
|
{
|
|
|
|
"no alt text"
|
|
|
|
};
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
msghtml(control_room, m::me(), str, alt, "m.notice");
|
2018-03-26 03:12:17 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-29 06:01:42 +01:00
|
|
|
const ctx::exception_handler eh;
|
2018-03-26 03:12:17 +02:00
|
|
|
notice(control_room, e.what());
|
2018-03-05 11:44:03 +01:00
|
|
|
}
|
|
|
|
|
2019-08-10 06:27:12 +02:00
|
|
|
m::hookfn<m::vm::eval &>
|
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-10-07 07:17:46 +02:00
|
|
|
{ "_site", "vm.effect" },
|
2020-04-11 03:03:20 +02:00
|
|
|
// { "room_id", "!control" }, //TODO: XXX
|
2018-03-03 11:38:05 +01:00
|
|
|
{ "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
|
2018-10-07 07:17:46 +02:00
|
|
|
create_control_room(const m::event &,
|
|
|
|
m::vm::eval &)
|
2018-03-05 11:44:03 +01:00
|
|
|
{
|
2019-10-01 05:50:58 +02:00
|
|
|
create(control_room_id, m::me());
|
|
|
|
join(control_room, m::me());
|
|
|
|
send(control_room, m::me(), "m.room.name", "",
|
2018-03-05 11:44:03 +01:00
|
|
|
{
|
|
|
|
{ "name", "Control Room" }
|
|
|
|
});
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
notice(control_room, m::me(), "Welcome to the control room.");
|
|
|
|
notice(control_room, m::me(), "I am the daemon. You can talk to me in this room by highlighting me.");
|
2018-03-05 11:44:03 +01:00
|
|
|
}
|
|
|
|
|
2019-08-10 06:27:12 +02:00
|
|
|
m::hookfn<m::vm::eval &>
|
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-10-07 07:17:46 +02:00
|
|
|
{ "_site", "vm.effect" },
|
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
|
|
|
};
|