[Jifty-commit] r6992 - wifty/trunk/lib/Wifty/Action

Jifty commits jifty-commit at lists.jifty.org
Tue May 12 02:19:19 EDT 2009


Author: ruz
Date: Tue May 12 02:19:18 2009
New Revision: 6992

Added:
   wifty/trunk/lib/Wifty/Action/
   wifty/trunk/lib/Wifty/Action/EditIPsBlackList.pm

Log:
* add EditIPsBlackList action

Added: wifty/trunk/lib/Wifty/Action/EditIPsBlackList.pm
==============================================================================
--- (empty file)
+++ wifty/trunk/lib/Wifty/Action/EditIPsBlackList.pm	Tue May 12 02:19:18 2009
@@ -0,0 +1,82 @@
+use strict;
+use warnings;
+
+=head1 NAME
+
+Wifty::Action::EditIPsBlackList
+
+=cut
+
+package Wifty::Action::EditIPsBlackList;
+use base qw/Wifty::Action Jifty::Action/;
+
+use Regexp::Common qw(RE_net_IPv4);
+my $re_ip = $RE{net}{IPv4};
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+    param 'ips' =>
+        label is 'Block IPs',
+        render as 'Textarea',
+        default is defer {
+            my $list = Jifty->app_class('Model::BlackListCollection')->new;
+            $list->limit( column => 'type', value => 'IP' );
+            $list->order_by({ column => 'value', order => 'asc' });
+            return join "\n", map $_->value, @$list;
+        },
+    ;
+};
+
+sub canonicalize_ips {
+    my $self = shift;
+    my $ips = shift;
+
+    my @ips;
+    my @not_ips;
+
+    foreach my $part ( grep /\S/, split /[^0-9.]+/, $ips ) {
+        unless ( $part =~ /^$re_ip$/ ) {
+            push @not_ips, $part;
+        } else {
+            push @ips, $part;
+        }
+    }
+    
+    $self->canonicalization_note('ips' => "Some values have been dropped as don't look like IP")
+        if @not_ips;
+
+    return \@ips;
+}
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+    my $self = shift;
+
+    my $ips = $self->argument_value('ips');
+
+    my ($status, $msg) = Jifty->app_class('Model::BlackList')->new->update_list(
+        type   => 'IP',
+        values => $ips,
+    );
+    Jifty->log->error("$status $msg");
+    return $self->result->error( $msg )
+        unless $status;
+
+    return $self->report_success;
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+    my $self = shift;
+    # Your success message here
+    $self->result->message('Success');
+}
+
+1;
+


More information about the Jifty-commit mailing list