mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Persist-key now works on VM-based code-factoids
This commit is contained in:
parent
5062dc0be9
commit
807bfbf235
@ -60,7 +60,7 @@ sub execute_module {
|
||||
my $module = $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{action};
|
||||
my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir');
|
||||
|
||||
$self->{pbot}->{logger}->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: Executing module $module $arguments\n");
|
||||
$self->{pbot}->{logger}->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: Executing module [$command] $module $arguments\n");
|
||||
|
||||
$arguments =~ s/\$nick/$nick/g;
|
||||
$arguments =~ s/\$channel/$from/g;
|
||||
@ -160,6 +160,8 @@ sub execute_module {
|
||||
}
|
||||
|
||||
if ($command eq 'code-factoid') {
|
||||
$text =~ s/\s+$//g;
|
||||
$self->{pbot}->{logger}->log("No text result from code-factoid.\n") and exit 0 if not length $text;
|
||||
$text = $self->{pbot}->{factoids}->handle_action($nick, $user, $host, $from, $root_channel, $root_keyword, $root_keyword, $arguments, $text, $tonick, 0, $referenced, undef, $root_keyword);
|
||||
}
|
||||
|
||||
|
@ -663,6 +663,11 @@ sub execute_code_factoid_using_vm {
|
||||
}
|
||||
|
||||
my %h = (nick => $nick, channel => $from, lang => $lang, code => $code, arguments => $arguments, factoid => "$chan:$keyword");
|
||||
|
||||
if (exists $self->{factoids}->hash->{$chan}->{$keyword}->{'persist-key'}) {
|
||||
$h{'persist-key'} = $self->{factoids}->hash->{$chan}->{$keyword}->{'persist-key'};
|
||||
}
|
||||
|
||||
my $json = encode_json \%h;
|
||||
$self->{pbot}->{factoids}->{factoidmodulelauncher}->execute_module($from, $tonick, $nick, $user, $host, 'code-factoid', $chan, $root_keyword, "compiler", $json, 0);
|
||||
return "";
|
||||
|
@ -40,7 +40,9 @@ sub vm_start {
|
||||
}
|
||||
|
||||
sub vm_reset {
|
||||
system("virsh detach-disk $DOMAIN_NAME vdb");
|
||||
system("virsh snapshot-revert $DOMAIN_NAME 1");
|
||||
system("virsh attach-disk $DOMAIN_NAME --source /var/lib/libvirt/images/factdata.qcow2 --target vdb");
|
||||
print "Reset vm\n";
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ use warnings;
|
||||
use strict;
|
||||
|
||||
use File::Basename;
|
||||
use POSIX;
|
||||
use JSON;
|
||||
|
||||
my $USERNAME = 'compiler';
|
||||
@ -84,8 +83,19 @@ sub run_server {
|
||||
exit;
|
||||
}
|
||||
|
||||
POSIX::setgid($gid);
|
||||
POSIX::setuid($uid);
|
||||
if ($compile_in->{'persist-key'}) {
|
||||
system("mount /dev/vdb1 /root/factdata");
|
||||
system("mkdir /root/factdata/$compile_in->{'persist-key'}");
|
||||
system("cp -R -p /root/factdata/$compile_in->{'persist-key'}/* /home/compiler/");
|
||||
}
|
||||
|
||||
system("chown -R compiler /home/compiler/*");
|
||||
system("chgrp -R compiler /home/compiler/*");
|
||||
system("chmod -R 755 /home/compiler");
|
||||
system("rm -rf /home/compiler/prog*");
|
||||
|
||||
$( = $gid;
|
||||
$< = $uid;
|
||||
|
||||
my $result = interpret(%$compile_in);
|
||||
|
||||
@ -95,6 +105,16 @@ sub run_server {
|
||||
print "Done compiling; result: [$result] [$json]\n";
|
||||
print $output "result:$json\n";
|
||||
print $output "result:end\n";
|
||||
|
||||
$( = 0;
|
||||
$< = 0;
|
||||
|
||||
if ($compile_in->{'persist-key'}) {
|
||||
system("id");
|
||||
system("cp -R -p /home/compiler/* /root/factdata/$compile_in->{'persist-key'}/");
|
||||
system("umount /root/factdata");
|
||||
}
|
||||
|
||||
exit;
|
||||
} else {
|
||||
waitpid $pid, 0;
|
||||
@ -126,8 +146,7 @@ sub interpret {
|
||||
|
||||
$h{lang} = '_default' if not exists $languages{$h{lang}};
|
||||
|
||||
system("chmod -R 755 /home/compiler");
|
||||
system("rm -rf /home/compiler/prog*");
|
||||
chdir("/home/compiler");
|
||||
|
||||
my $mod = $h{lang}->new(%h);
|
||||
|
||||
@ -136,9 +155,13 @@ sub interpret {
|
||||
$mod->postprocess if not $mod->{error} and not $mod->{done};
|
||||
|
||||
if (exists $mod->{no_output} or not length $mod->{output}) {
|
||||
$mod->{output} .= "\n" if length $mod->{output};
|
||||
$mod->{output} .= "Success (no output).\n" if not $mod->{error};
|
||||
$mod->{output} .= "Success (exit code $mod->{error}).\n" if $mod->{error};
|
||||
if ($h{factoid}) {
|
||||
$mod->{output} = "";
|
||||
} else {
|
||||
$mod->{output} .= "\n" if length $mod->{output};
|
||||
$mod->{output} .= "Success (no output).\n" if not $mod->{error};
|
||||
$mod->{output} .= "Success (exit code $mod->{error}).\n" if $mod->{error};
|
||||
}
|
||||
}
|
||||
|
||||
return $mod->{output};
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
$self->{max_history} = $conf{max_history} // 10000;
|
||||
$self->{arguments} = $conf{arguments};
|
||||
$self->{factoid} = $conf{factoid};
|
||||
$self->{'persist-key'} = $conf{'persist-key'};
|
||||
|
||||
$self->{default_options} = '';
|
||||
$self->{cmdline} = 'echo Hello, world!';
|
||||
@ -374,6 +375,10 @@ sub execute {
|
||||
|
||||
my $compile_in = { lang => $self->{lang}, sourcefile => $self->{sourcefile}, execfile => $self->{execfile},
|
||||
cmdline => $cmdline, input => $input, date => $date, arguments => $self->{arguments}, code => $pretty_code };
|
||||
|
||||
$compile_in->{'factoid'} = $self->{'factoid'} if length $self->{'factoid'};
|
||||
$compile_in->{'persist-key'} = $self->{'persist-key'} if length $self->{'persist-key'};
|
||||
|
||||
my $compile_json = encode_json($compile_in);
|
||||
|
||||
#print STDERR "Sending [$compile_json] to vm_server\n";
|
||||
|
@ -25,6 +25,7 @@ sub new {
|
||||
$self->{date} = $conf{date};
|
||||
$self->{arguments} = $conf{arguments};
|
||||
$self->{factoid} = $conf{factoid};
|
||||
$self->{'persist-key'} = $conf{'persist-key'};
|
||||
|
||||
$self->initialize(%conf);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user