Changeset 482
- Timestamp:
- 04/02/06 07:19:58
- Files:
-
- trunk/plagger/lib/Plagger.pm (modified) (5 diffs)
- trunk/plagger/lib/Plagger/Plugin.pm (modified) (3 diffs)
- trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger.pm
r475 r482 6 6 use Carp; 7 7 use Data::Dumper; 8 use File::Copy; 8 9 use File::Basename; 9 10 use File::Find::Rule; … … 12 13 13 14 use base qw( Class::Accessor::Fast ); 14 __PACKAGE__->mk_accessors( qw(conf update subscription plugins_path cache ) );15 __PACKAGE__->mk_accessors( qw(conf update subscription plugins_path cache ) ); 15 16 16 17 use Plagger::Cache; … … 40 41 plugins_path => {}, 41 42 plugins => [], 43 rewrite_tasks => [] 42 44 }, $class; 43 45 … … 48 50 $self->{conf} = $config->{global}; 49 51 $self->{conf}->{log} ||= { level => 'debug' }; 52 $self->{config_path} = $opt{config}; 50 53 } else { 51 54 croak "Plagger->bootstrap: $opt{config}: $!"; … … 57 60 $self->load_cache($opt{config}); 58 61 $self->load_plugins(@{ $config->{plugins} || [] }); 62 $self->rewrite_config if @{ $self->{rewrite_tasks} }; 59 63 $self->run(); 64 } 65 66 sub add_rewrite_task { 67 my($self, @stuff) = @_; 68 push @{ $self->{rewrite_tasks} }, \@stuff; 69 } 70 71 sub rewrite_config { 72 my $self = shift; 73 74 open my $fh, $self->{config_path} or $self->error("$self->{config_path}: $!"); 75 my $data = join '', <$fh>; 76 close $fh; 77 78 my $old = $data; 79 my $count; 80 81 # xxx this is a quick hack: It should be a YAML roundtrip maybe 82 for my $task (@{ $self->{rewrite_tasks} }) { 83 my($key, $old_value, $new_value ) = @$task; 84 if ($data =~ s/^(\s+$key:\s+)$old_value\s*$/$1$new_value/m) { 85 $count++; 86 } else { 87 $self->log(error => "$key: $old_value not found in $self->{config_path}"); 88 } 89 } 90 91 if ($count) { 92 File::Copy::copy( $self->{config_path}, $self->{config_path} . ".bak" ); 93 open my $fh, ">", $self->{config_path} or $self->error("$self->{config_path}: $!"); 94 print $fh $data; 95 close $fh; 96 97 $self->log(info => "rewrote $self->{config_path} with encrypting $count config values"); 98 } 60 99 } 61 100 trunk/plagger/lib/Plagger/Plugin.pm
r447 r482 5 5 __PACKAGE__->mk_accessors( qw(conf rule rule_hook cache) ); 6 6 7 use Plagger::Crypt; 7 8 use Plagger::Rule; 8 9 use Plagger::Rules; … … 26 27 sub init { 27 28 my $self = shift; 29 28 30 if (my $rule = $self->{rule}) { 29 31 $rule = [ $rule ] if ref($rule) eq 'HASH'; … … 33 35 $self->{rule} = Plagger::Rule->new({ module => 'Always' }); 34 36 } 37 38 if (my $params = $self->encrypt_config) { 39 $params = [ $params ] unless ref $params; 40 41 for my $key (@$params) { 42 my $config = $self->conf; 43 # support foo/bar/baz 44 while ($key =~ s!^(\w+)/!!) { 45 $config = $config->{$1}; 46 } 47 my $decrypted = Plagger::Crypt->decrypt($config->{$key}); 48 if ($decrypted eq $config->{$key}) { 49 Plagger->context->add_rewrite_task($key, $decrypted, Plagger::Crypt->encrypt($decrypted, 'base64')); 50 } else { 51 $config->{$key} = $decrypted; 52 } 53 } 54 } 35 55 } 56 57 sub encrypt_config { } 36 58 37 59 sub conf { $_[0]->{conf} } trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm
r467 r482 10 10 $self->class_id . '-' . $self->conf->{username}; 11 11 } 12 13 sub encrypt_config { 'password' } 12 14 13 15 sub register {
