diff options
| author | Jules <jules@asdf.us> | 2015-01-20 14:02:27 -0500 |
|---|---|---|
| committer | Jules <jules@asdf.us> | 2015-01-20 14:02:27 -0500 |
| commit | 255dc9ebf80f7d1259ba26953ff3bc7f30a1eafd (patch) | |
| tree | 5d6d0b5212558f7e4105d94086443a4d247c8229 | |
| parent | a0db93dff9bda5cfd65ff694fbbc73fa6f6d110e (diff) | |
trust certain channels
| -rw-r--r-- | index.html | 28 | ||||
| -rw-r--r-- | xdcc.pl | 109 |
2 files changed, 109 insertions, 28 deletions
@@ -3,10 +3,10 @@ <h1>xdcc.pl</h1> -XDCC script for <tt>irssi</tt>. +XDCC server for <tt>irssi</tt>. <p> -Run a fileserver. People can request DCC sends over CTCP. +Run a fileserver. People can request DCC sends over CTCP. Trusted users can upload files. <p> Download it here! → → → <a href="xdcc.pl" style="color:blue!important"><i>xdcc.pl</i></a> @@ -14,16 +14,19 @@ Download it here! → → → <a href="xdcc.pl" style="color:blue!impor <h2>Usage</h2> -<pre>/XDCC [-add <i>filename</i> <i>description</i>] [-del <i>id</i>] [-list] [-stats] [-enable] [-disable] [-help] +<pre>/XDCC [-add <i>filename</i> <i>description</i>] [-del <i>id</i>] [-list] [-stats] + [-enable] [-disable] [-trust <i>#channel</i>] [-distrust <i>#channel</i>] [-help] --add: Add a file to our XDCC server --del: Remove a file from the offerings --list: Display the XDCC list (default) --reset: Reset the file list and the queue --stats: Statistics for this session --enable: Enable the XDCC server --disable: Disable the XDCC server --help: Display this help.</pre> +-add: Add a file to our XDCC server +-del: Remove a file from the offerings +-list: Display the XDCC list (default) +-reset: Reset the file list and the queue +-stats: Statistics for this session +-enable: Enable the XDCC server +-trust: Trust users from #channel to upload files +-distrust: Stop trusting users on #channel +-disable: Disable the XDCC server +-help: Display this help.</pre> Examples: @@ -31,6 +34,7 @@ Examples: /xdcc -add jollo.mp3 Distant cry of the Jollo, 5:43 am /xdcc -del 1 /xdcc -stats</pre> +/xdcc -trust #sally</pre> <h3>CTCP XDCC Interface</h3> @@ -41,6 +45,8 @@ People can request files from you using these CTCP commands: /ctcp <i>nick</i> XDCC batch 2-4 <i># request multiple files</i> /ctcp <i>nick</i> XDCC remove 3 <i># remove from queue</i> /ctcp <i>nick</i> XDCC cancel <i># cancel file transfer</i> +/ctcp <i>nick</i> XDCC describe 1 <i># change a file description (with permission)</i> +/ctcp <i>nick</i> XDCC delete 1 <i># stop offering a file (with permission)</i> /ctcp <i>nick</i> XDCC queue /ctcp <i>nick</i> XDCC help /ctcp <i>nick</i> XDCC about</pre> @@ -18,6 +18,7 @@ $VERSION = "1.0"; my @files; my @queue; +my @channels; my $queue_max = 99; my $bother_delay = 9999; @@ -45,6 +46,7 @@ Usage: -reset: Reset the file list and the queue -stats: Statistics for this session -enable: Enable/disable the XDCC server +-trust: Trust ops from a channel to upload files. -help: Display this help. Examples: @@ -55,8 +57,7 @@ Examples: For client commands, type: /ctcp <nickname> XDCC help -Only one file will be sent at a time. -Additional requests are added to a queue. +Requests are queued, only one file will be sent at a time. Filenames must not contain spaces. EOF @@ -70,7 +71,14 @@ my $help_remote = <<EOF; /ctcp %nick XDCC %_queue%_ /ctcp %nick XDCC %_help%_ /ctcp %nick XDCC %_about%_ +EOF + +my $help_control = <<EOF; +Since you are opped on %s, you can upload files to the server. +DCC send a file to %nick. +/ctcp %nick XDCC %_describe%_ 5 # Set the description for a file +/ctcp %nick XDCC %_delete%_ 5 # Delete something you uploaded. EOF my $help_about = <<EOF; @@ -134,6 +142,8 @@ my $messages = { sub ctcp_reply { my ($server, $data, $nick, $address, $target) = @_; + xdcc_is_trusted($server, $nick); + my ($ctcp, $cmd, $index) = split (" ", lc($data), 3); if ($disabled || $ctcp ne "xdcc") { return; } @@ -329,6 +339,14 @@ sub xdcc_report { } sub xdcc_stats { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', "xdcc.pl version", $VERSION); + + my @channel_names = map { $->{'name'} } @channels; + if (scalar @channel_names) { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', 'channels', join(' ', @channel_names)); + } + else { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', 'channels', 'none'); + } Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', "files sent", $stats->{files_sent}); Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_hr'); @@ -404,35 +422,92 @@ sub xdcc_reset { $sending = 0; Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_reset'); } +sub xdcc_log { + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', $_[0]); +} + +# Trust ops from certain channels +sub xdcc_trust { + my ($channel_name) = @_; + my $channel = Irssi::channel_find($channel_name); + if ($channel) { + xdcc_log("trusting ops on $channel_name"); + push(@channels, $channel); + } + else { + xdcc_log("couldn't find channel $channel_name"); + } +} +sub xdcc_distrust { + my ($channel_name) = @_; + for (my $i = $#channels; $i >= 0; $i--) { + if ($channels[$i]->{name} == $channel_name) { + my $channel = $channels[$i]; + splice(@channels, $i, 1); + xdcc_log("stopped trusting $channel_name"); + return + } + } + xdcc_log("couldn't find channel $channel_name"); +} +sub xdcc_is_trusted { + my ($server, $nick) = @_; + my $user; + xdcc_log("looking up $nick"); + for my $channel (@channels) { + if ($channel->{server}->{'name'} ne $server->{'name'}) { + # xdcc_log("didnt find $nick on server $server->{name}"); + continue; + } + $user = $channel->nick_find($nick); + if ($user && $user->{op}) { + # xdcc_log("found $nick opped in $channel->{name}"); + return 1; + } + } + # xdcc_log("$nick not found"); + return 0; +} + sub xdcc_help { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_help', $help_local); } - sub xdcc { my ($cmd, $fn, $desc) = split (" ", $_[0], 3); $cmd = lc($cmd); $cmd =~ s/^-//; - if ($cmd eq "add") { xdcc_add($fn, $desc) } - elsif ($cmd eq "del") { xdcc_del($fn) } - elsif ($cmd eq "list") { xdcc_report() } - elsif ($cmd eq "reset") { xdcc_reset() } - elsif ($cmd eq "stats") { xdcc_stats() } - elsif ($cmd eq "enable") { $disabled = 0 } - elsif ($cmd eq "disable") { $disabled = 1 } - elsif ($cmd eq "help") { xdcc_help() } - elsif ($cmd eq "version") { xdcc_version() } - else { xdcc_report() } + if ($cmd eq "add") { xdcc_add($fn, $desc) } + elsif ($cmd eq "del") { xdcc_del($fn) } + elsif ($cmd eq "list") { xdcc_report() } + elsif ($cmd eq "reset") { xdcc_reset() } + elsif ($cmd eq "stats") { xdcc_stats() } + elsif ($cmd eq "enable") { $disabled = 0 } + elsif ($cmd eq "disable") { $disabled = 1 } + elsif ($cmd eq "trust") { xdcc_trust($fn) } + elsif ($cmd eq "distrust") { xdcc_distrust($fn) } + elsif ($cmd eq "help") { xdcc_help() } + elsif ($cmd eq "version") { xdcc_version() } + else { xdcc_report() } } # DCC management sub dcc_created { my ($dcc) = @_; + use Data::Dumper; + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', Dumper($dcc)); # Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc created'); - if ($timeout) { Irssi::timeout_remove($timeout) } - $timeout = Irssi::timeout_add_once($bother_delay, \&xdcc_bother, { dcc => $dcc, times => 1 }); - $current_dcc = $dcc; + if ($dcc->{'type'} eq "send") { + if ($timeout) { Irssi::timeout_remove($timeout) } + $timeout = Irssi::timeout_add_once($bother_delay, \&xdcc_bother, { dcc => $dcc, times => 1 }); + #$current_dcc = $dcc; + } + elsif ($dcc->{'type'} eq "get") { + if (xdcc_is_trusted($dcc->{'nick'})) { + # what... + } + } } sub xdcc_bother { my ($data) = @_; @@ -478,5 +553,5 @@ Irssi::signal_add('dcc rejecting', 'dcc_rejecting'); Irssi::signal_add('dcc closed', 'dcc_closed'); Irssi::signal_add('default ctcp msg', 'ctcp_reply'); Irssi::command_bind('xdcc', 'xdcc'); -Irssi::command_set_options('xdcc','add del list stats enable disable reset help version'); +Irssi::command_set_options('xdcc','add del list stats enable disable reset trust distrust help version'); Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'loaded', $IRSSI{name}, $VERSION, $IRSSI{authors}); |
