| 1 | package Arepa::Web::Public; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'Arepa::Web::Base'; | ||
| 7 | |||
| 8 | use English qw(-no_match_vars); | ||
| 9 | use POSIX qw(strftime); | ||
| 10 | use File::stat; | ||
| 11 | use XML::RSS; | ||
| 12 | use Parse::Debian::PackageDesc; | ||
| 13 | |||
| 14 | use Arepa::PackageDb; | ||
| 15 | |||
| 16 | sub _retarded_escape { | ||
| 17 | my ($self, $value) = @_; | ||
| 18 | |||
| 19 | $value =~ s/&/&/g; | ||
| 20 | $value =~ s/</</g; | ||
| 21 | $value =~ s/>/>/g; | ||
| 22 | return $value; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub rss_queue { | ||
| 26 | my ($self) = @_; | ||
| 27 | |||
| 28 | my $rss = XML::RSS->new(version => '2.0'); | ||
| 29 | $rss->channel( | ||
| 30 | title => "Arepa upload queue", | ||
| 31 | link => "http://search.cpan.org/~opera/", | ||
| 32 | description => "Packages waiting to be approved for your Debian repository", | ||
| 33 | dc => { | ||
| 34 | date => '2010-06-02T09:15+00:00', | ||
| 35 | subject => "Software distribution", | ||
| 36 | creator => 'estebanm@opera.com', | ||
| 37 | language => 'en-us', | ||
| 38 | }, | ||
| 39 | syn => { | ||
| 40 | updatePeriod => "hourly", | ||
| 41 | updateBase => "1901-01-01T00:00+00:00", | ||
| 42 | }, | ||
| 43 | taxo => [ | ||
| 44 | 'http://dmoz.org/Computers/Software/Operating_Systems/Linux/Distributions/Debian/', | ||
| 45 | ] | ||
| 46 | ); | ||
| 47 | |||
| 48 | |||
| 49 | my @changes_files = (); | ||
| 50 | if (opendir D, $self->config->get_key('upload_queue:path')) { | ||
| 51 | @changes_files = grep /\.changes$/, readdir D; | ||
| 52 | closedir D; | ||
| 53 | } | ||
| 54 | my @packages; | ||
| 55 | my $gpg_dir = $self->config->get_key('web_ui:gpg_homedir'); | ||
| 56 | foreach my $changes_file (@changes_files) { | ||
| 57 | my $changes_file_path = $self->config->get_key('upload_queue:path') . | ||
| 58 | "/" . $changes_file; | ||
| 59 | eval { | ||
| 60 | push @packages, | ||
| 61 | Parse::Debian::PackageDesc->new($changes_file_path, | ||
| 62 | gpg_homedir => $gpg_dir); | ||
| 63 | }; | ||
| 64 | if ($EVAL_ERROR) { | ||
| 65 | print STDERR "Error reading changes file '$changes_file_path'\n"; | ||
| 66 | print STDERR $EVAL_ERROR, "\n"; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | my $public_url; | ||
| 71 | if ($self->config->key_exists('web_ui:cgi_base_url')) { | ||
| 72 | $public_url = $self->config->get_key('web_ui:cgi_base_url'); | ||
| 73 | } | ||
| 74 | if ($self->config->key_exists('web_ui:public_url')) { | ||
| 75 | $public_url = $self->config->get_key('web_ui:public_url'); | ||
| 76 | } | ||
| 77 | if (!defined $public_url) { | ||
| 78 | die "Couldn't find configuration keys web_ui:public_url or web_ui:cgi_base_url"; | ||
| 79 | } | ||
| 80 | |||
| 81 | foreach my $pkg (@packages) { | ||
| 82 | my $signature_info = ""; | ||
| 83 | if ($pkg->signature_id) { | ||
| 84 | $signature_info = "It is signed with id " . | ||
| 85 | $pkg->signature_id . "."; | ||
| 86 | if (! $pkg->correct_signature) { | ||
| 87 | $signature_info .= " The signature is <strong>NOT " . | ||
| 88 | "VALID</strong>"; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | else { | ||
| 92 | $signature_info = "It is <strong>NOT SIGNED</strong>."; | ||
| 93 | } | ||
| 94 | |||
| 95 | $rss->add_item( | ||
| 96 | title => $pkg->name . " " . $pkg->version . " for " . | ||
| 97 | $pkg->distribution, | ||
| 98 | link => $public_url, | ||
| 99 | description => $pkg->name . " " . $pkg->version . | ||
| 100 | " was uploaded by " . | ||
| 101 | $self->_retarded_escape($pkg->maintainer) . | ||
| 102 | ".<br/>" . $signature_info, | ||
| 103 | pubDate => strftime("%a, %d %b %Y %H:%M:%S %z", | ||
| 104 | localtime(stat($pkg->path)->mtime)), | ||
| 105 | ); | ||
| 106 | } | ||
| 107 | |||
| 108 | $self->render_text($rss->as_string); | ||
| 109 | } | ||
| 110 | |||
| 111 | sub rss_repository { | ||
| 112 | my ($self) = @_; | ||
| 113 | |||
| 114 | my $rss = XML::RSS->new(version => '2.0'); | ||
| 115 | $rss->channel( | ||
| 116 | title => "Arepa latest packages", | ||
| 117 | link => "http://search.cpan.org/~opera/", | ||
| 118 | description => "Latest packages added to the repository", | ||
| 119 | dc => { | ||
| 120 | date => '2012-01-27T16:20+00:00', | ||
| 121 | subject => "Software distribution", | ||
| 122 | creator => 'estebanm@opera.com', | ||
| 123 | language => 'en-us', | ||
| 124 | }, | ||
| 125 | syn => { | ||
| 126 | updatePeriod => "hourly", | ||
| 127 | updateBase => "1901-01-01T00:00+00:00", | ||
| 128 | }, | ||
| 129 | taxo => [ | ||
| 130 | 'http://dmoz.org/Computers/Software/Operating_Systems/Linux/Distributions/Debian/', | ||
| 131 | ] | ||
| 132 | ); | ||
| 133 | |||
| 134 | |||
| 135 | my $packagedb = | ||
| 136 | Arepa::PackageDb->new($self->config->get_key('package_db')); | ||
| 137 | my @packages = (); | ||
| 138 | my @compilation_queue = $packagedb-> | ||
| 139 | get_compilation_queue(status => 'compiled', | ||
| 140 | order => "compilation_completed_at DESC", | ||
| 141 | limit => 30); | ||
| 142 | foreach my $comp (@compilation_queue) { | ||
| 143 | my %source_pkg_attrs = | ||
| 144 | $packagedb->get_source_package_by_id($comp->{source_package_id}); | ||
| 145 | push @packages, { | ||
| 146 | %$comp, | ||
| 147 | package => { %source_pkg_attrs }, | ||
| 148 | }; | ||
| 149 | } | ||
| 150 | |||
| 151 | my $public_url; | ||
| 152 | if ($self->config->key_exists('web_ui:cgi_base_url')) { | ||
| 153 | $public_url = $self->config->get_key('web_ui:cgi_base_url'); | ||
| 154 | } | ||
| 155 | if ($self->config->key_exists('web_ui:public_url')) { | ||
| 156 | $public_url = $self->config->get_key('web_ui:public_url'); | ||
| 157 | } | ||
| 158 | if (!defined $public_url) { | ||
| 159 | die "Couldn't find configuration keys web_ui:public_url or web_ui:cgi_base_url"; | ||
| 160 | } | ||
| 161 | |||
| 162 | foreach my $pkg (@packages) { | ||
| 163 | $rss->add_item( | ||
| 164 | title => $pkg->{package}->{name} . " " . $pkg->{package}->{full_version} . " (" . | ||
| 165 | $pkg->{distribution} . "/" . $pkg->{architecture} . ")", | ||
| 166 | link => $public_url, | ||
| 167 | description => $pkg->{package}->{name} . " " . $pkg->{package}->{full_version} . | ||
| 168 | "<br/>" . | ||
| 169 | $pkg->{package}->{comments}, | ||
| 170 | pubDate => $pkg->{completed_at}, | ||
| 171 | ); | ||
| 172 | } | ||
| 173 | |||
| 174 | $self->render_text($rss->as_string); | ||
| 175 | } | ||
| 176 | |||
| 177 | 1; |