40 lines
1.3 KiB
Ruby
40 lines
1.3 KiB
Ruby
# Copyright (C) 2022 Semisol <hi at semisol dot dev>
|
|
# Copyright (C) 2022 Noisytoot <ron@noisytoot.org>
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
require 'open3'
|
|
module Shell
|
|
def do_shell(evt)
|
|
target, msg = evt.args
|
|
if msg.start_with? shell_prefix and evt.from_oper?
|
|
Thread.new {
|
|
Open3.popen2e("/bin/sh", "-c", msg[shell_prefix.length..]) {|stdin, stdout_and_stderr, wait|
|
|
stdin.close
|
|
stdout_and_stderr.each {|line|
|
|
msg target, line
|
|
}
|
|
status = wait.value
|
|
msg target, underline("Exit code #{status.exitstatus}")
|
|
}
|
|
}
|
|
end
|
|
end
|
|
def listen_for_shell
|
|
on :privmsg, :do_shell
|
|
end
|
|
def self.included(m)
|
|
m.configure :listen_for_shell
|
|
end
|
|
end
|