]> sipb.mit.edu Git - snippets/.git/blob - barnowl/zcrypt.pl
Send messages 'remotely' (to localhost), to work around growl bug #267767
[snippets/.git] / barnowl / zcrypt.pl
1 # BarnOwls older than late September 2008 will segfault on short zcrypt messages.
2 # Besides, the code is sketchy and doesn't belong in core. This perl module
3 # will add :zcrypt and :decrypt commands that use outland's zcrypt binary via
4 # Perl, so a bug in zcrypt can't possibly affect BarnOwl proper. The :zcrypt
5 # command replaces the built-in one.
6 #
7 # To use this code, type
8 #   :perl do '/mit/snippets/barnowl/zcrypt.pl'
9 #
10 # This first line will disable BarnOwl's own zcrypt code, so messages are
11 # encrypted onscreen. Use :decrypt to display them. (Security bugs were later
12 # found in the decryption code, although these probably affect locker zcrypt
13 # too.)
14
15 BarnOwl::command("unset zcrypt");
16
17 use IPC::Open2;
18 BarnOwl::new_command(decrypt => sub {
19    my $msg = BarnOwl::getcurmsg();
20    my $cmd = shift;
21    my @args = @_;
22    if (scalar @args == 0) {
23        @args = ('-c', $msg->class, '-i', $msg->instance);
24    }
25    my ($zo, $zi);
26    my $pid = open2($zo, $zi, '/mit/outland/bin/zcrypt', '-D', @args) or die "Couldn't launch zcrypt\n";
27    my $decrypted;
28    print $zi $msg->body . "\n";
29    close $zi;
30    while (<$zo>) {
31       chomp;
32       last if $_ eq "**END**";
33       $decrypted .= "$_\n";
34    }
35    BarnOwl::popless_ztext($decrypted);
36    waitpid $pid, 0;
37    },
38    {summary => "Decrypt a zcrypted message once",
39     usage => "decrypt [args]",
40     description => "Invokes /mit/outland/bin/zcrypt on the current message,\n
41 using the class and instance to find the crypt key, and pops up the\n
42 decrypted output. If args are specified, they are passed to zcrypt and the\n
43 class and instance are ignored.\n\n
44 SEE ALSO: zcrypt(1)"});
45
46 BarnOwl::new_command(zcrypt => sub {
47    my $cmd = shift;
48    my @args = @_;
49    my $argstring = join ' ', @args;
50    BarnOwl::start_edit_win("/mit/outland/bin/zcrypt $argstring", sub {
51       my $msg = shift;
52       my ($zo, $zi);
53       my $pid = open2($zo, $zi, '/mit/outland/bin/zcrypt', @args);
54       print $zi "$msg\n";
55       close $zi;
56       local $/;
57       BarnOwl::message(<$zo>);
58       waitpid $pid, 0;
59       });
60    },
61    {summary => "Run /mit/outland/bin/zcrypt",
62     usage => "zcrypt -c [class] -i [instance]",
63     description => "Calls /mit/outland/bin/zcrypt on a message you type in.\n\n
64 SEE ALSO: zcrypt(1)"});