6 # Hack to work on merkel where suexec is in place
8 if ($ENV{HTTP_HOST} eq 'merkel.debian.org') {
9 unshift @INC, qw(/home/don/perl/usr/share/perl5 /home/don/perl/usr/lib/perl5 /home/don/source);
10 $ENV{DEBBUGS_CONFIG_FILE}="/home/don/config_internal";
17 use CGI::Alert 'don@donarmstrong.com';
20 use Debbugs::Config qw(:config);
21 use Debbugs::Estraier;
22 use Debbugs::CGI qw(htmlize_packagelinks html_escape);
23 use HTML::Entities qw(encode_entities);
25 my $q = new CGI::Simple;
27 #my %var_defaults = (attr => 1,);
29 my %cgi_var = cgi_parameters($q);
31 $cgi_var{phrase} = '' if not defined $cgi_var{phrase};
32 $cgi_var{max_results} = 10 if not defined $cgi_var{max_results};
33 $cgi_var{attribute} = parse_attribute(\%cgi_var) || [];
34 $cgi_var{skip} = 0 if not defined $cgi_var{skip};
38 if (defined $cgi_var{next}) {
40 $cgi_var{skip} += $cgi_var{max_results};
42 elsif (defined $cgi_var{prev}) {
44 $cgi_var{skip} -= $cgi_var{max_results};
45 $cgi_var{skip} = 0 if $cgi_var{skip} < 0;
49 if (defined $cgi_var{search} and length $cgi_var{phrase}) {
50 # connect to a node if we need to
51 my $node = new Search::Estraier::Node (url => $config{search_estraier}{url},
52 user => $config{search_estraier}{user},
53 passwd => $config{search_estraier}{pass},
55 ) or die "Unable to connect to the node";
56 my $cond = new Search::Estraier::Condition;
57 $cond->set_phrase($cgi_var{phrase});
58 if (defined $cgi_var{order_field} and length $cgi_var{order_field} and
59 defined $cgi_var{order_operator} and length $cgi_var{order_operator}) {
60 $cond->set_order($cgi_var{order_field}.' '.$cgi_var{order_operator});
62 foreach my $attribute (@{$cgi_var{attribute}}) {
63 if (defined $$attribute{field} and defined $$attribute{value} and
64 defined $$attribute{operator} and length $$attribute{value}) {
65 $cond->add_attr(join(' ',map {$$attribute{$_}} qw(field operator value)));
68 $cond->set_skip($cgi_var{skip}) if defined $cgi_var{skip} and $cgi_var{skip} =~ /(\d+)/;
69 $cond->set_max($cgi_var{max_results}) if defined $cgi_var{max_results} and $cgi_var{max_results} =~ /^\d+$/;
70 print STDERR "skip: ".$cond->skip()."\n";
71 print STDERR $node->cond_to_query($cond),qq(\n);
72 $nres = $node->search($cond,0) or
73 die "Unable to search for condition";
76 elsif (defined $cgi_var{add_attribute} and length $cgi_var{add_attribute}) {
77 push @{$cgi_var{attribute}}, {value => ''};
79 elsif (grep /^delete_attribute_\d+$/, keys %cgi_var) {
80 foreach my $delete_key (sort {$b <=> $a} map {/^delete_attribute_(\d+)$/?($1):()} keys %cgi_var) {
81 splice @{$cgi_var{attribute}},$delete_key,1;
85 my $url = 'http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=';
88 Content-Type: text/html
91 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
92 <HTML><HEAD><TITLE>BTS Search</TITLE>
93 <link rel="stylesheet" href="http://bugs.debian.org/css/bugs.css" type="text/css">
99 <p>Phrase: <input type="text" name="phrase" value="$cgi_var{phrase}" size="80" id="phrase" title="Input some words for full-text search" tabindex="1" accesskey="a" />
100 <input type="submit" name="search" value="search" title="Perform the search" tabindex="8" accesskey="f" />
101 <input type="hidden" name="skip" value="$cgi_var{skip}"></p>
106 # NUMEQ : is equal to the number or date
107 # NUMNE : is not equal to the number or date
108 # NUMGT : is greater than the number or date
109 # NUMGE : is greater than or equal to the number or date
110 # NUMLT : is less than the number or date
111 # NUMLE : is less than or equal to the number or date
112 # NUMBT : is between the two numbers or dates
113 my @num_operators = (NUMEQ => 'equal to',
114 NUMNE => 'not equal to',
115 NUMGT => 'greater than',
116 NUMGE => 'greater than or equal to',
117 NUMLT => 'less than',
118 NUMLE => 'less than or equal to',
122 # STREQ : is equal to the string
123 # STRNE : is not equal to the string
124 # STRINC : includes the string
125 # STRBW : begins with the string
126 # STREW : ends with the string
127 # STRAND : includes all tokens in the string
128 # STROR : includes at least one token in the string
129 # STROREQ : is equal to at least one token in the string
130 # STRRX : matches regular expressions of the string
131 my @str_operators = (STREQ => 'equal to',
132 STRNE => 'not equal to',
133 STRINC => 'includes',
134 STRBW => 'begins with',
135 STREW => 'ends with',
136 STRAND => 'includes all tokens',
137 STROR => 'includes at least one token',
138 STROREQ => 'is equal to at least one token',
139 STRRX => 'matches regular expression',
142 my @attributes_order = ('@cdate','@title','@author',
143 qw(status subject date submitter package tags severity),
145 my %attributes = ('@cdate' => {name => 'Date',
148 '@title' => {name => 'Message subject',
151 '@author' => {name => 'Author',
154 status => {name => 'Status',
157 subject => {name => 'Bug Title',
160 date => {name => 'Submission date',
163 submitter => {name => 'Bug Submitter',
166 package => {name => 'Package',
169 tags => {name => 'Tags',
172 severity => {name => 'Severity',
177 print qq(<p>Attributes:</p>\n);
178 for my $attribute (@{$cgi_var{attribute}}) {
179 print qq(<select name="attribute_field">\n);
180 foreach my $attr (keys %attributes) {
181 my $selected = (defined $$attribute{field} and $$attribute{field} eq $attr) ? ' selected' : '';
182 print qq(<option value="$attr"$selected>$attributes{$attr}{name}</option>\n);
184 print qq(</select>\n);
185 print qq(<select name="attribute_operator">\n);
188 my @tmp_array = (@num_operators,@str_operators);
189 while (($operator,$name) = splice(@tmp_array,0,2)) {
190 my $type = $operator =~ /^NUM/ ? 'Number' : 'String';
191 my $selected = (defined $$attribute{operator} and $$attribute{operator} eq $operator) ? 'selected' : '';
192 print qq(<option value="$operator"$selected>$name ($type)</option>\n);
194 print qq(</select>\n);
195 $$attribute{value}='' if not defined $$attribute{value};
196 print qq(<input type="text" name="attribute_value" value="$$attribute{value}"><input type="submit" name="delete_attribute_$attr_num" value="Delete"><br/>\n);
200 print qq(<input type="submit" name="add_attribute" value="Add Attribute"><br/>);
204 # STRA : ascending by string
205 # STRD : descending by string
206 # NUMA : ascending by number or date
207 # NUMD : descending by number or date
209 my @order_operators = (STRA => 'ascending (string)',
210 STRD => 'descending (string)',
211 NUMA => 'ascending (number or date)',
212 NUMD => 'descending (number or date)',
215 print qq(<p>Order by: <select name="order_field">\n);
216 print qq(<option value="">Default</option>);
217 foreach my $attr (keys %attributes) {
218 my $selected = (defined $cgi_var{order_field} and $cgi_var{order_field} eq $attr) ? ' selected' : '';
219 print qq(<option value="$attr"$selected>$attributes{$attr}{name}</option>\n);
221 print qq(</select>\n);
222 print qq(<select name="order_operator">\n);
225 my @tmp_array = (@order_operators);
226 while (($operator,$name) = splice(@tmp_array,0,2)) {
227 my $selected = (defined $cgi_var{order_field} and $cgi_var{order_operator} eq $operator) ? ' selected' : '';
228 print qq(<option value="$operator"$selected>$name</option>\n);
230 print qq(</select></p>\n);
234 print qq(<p>Max results: <select name="max_results">\n);
235 for my $max_results (qw(10 25 50 100 150 200)) {
236 my $selected = (defined $cgi_var{max_results} and $cgi_var{max_results} eq $max_results) ? ' selected' : '';
237 print qq(<option value="$max_results"$selected>$max_results</option>\n);
239 print qq(</select></p>\n);
241 print qq(</tr></table>\n);
246 print "<h2> Results</h2>\n";
247 my $hits = $nres->hits();
248 print "<p>Hits: ".$hits;
249 if (($cgi_var{skip} > 0)) {
250 print q(<input type="submit" name="prev" value="Prev">);
252 if ($hits > ($cgi_var{skip}+$cgi_var{max_results})) {
253 print q(<input type="submit" name="next" value="Next">);
256 print qq(<ul class="msgreceived">\n);
257 for my $rdoc (map {$nres->get_doc($_)} 0.. ($nres->doc_num-1)) {
258 my ($bugnum,$msgnum) = split m#/#,$rdoc->attr('@uri');
259 my %attr = map {($_,$rdoc->attr($_))} $rdoc->attr_names;
260 # initialize any missing variables
261 for my $var ('@title','@author','@cdate','package','severity') {
262 $attr{$var} = '' if not defined $attr{$var};
265 $showseverity = "Severity: <em>$attr{severity}</em>;\n";
267 <li><a href="$url${bugnum}#${msgnum}">#${bugnum}: $attr{'@title'}</a> @{[htmlize_packagelinks($attr{package})]}<br/>
269 Sent by: @{[encode_entities($attr{'@author'})]} at $attr{'@cdate'}<br/>
271 # Deal with the snippet
272 # make the things that match bits of the phrase bold, the rest normal.
273 my $snippet_mod = html_escape($attr{snippet});
274 $snippet_mod =~ s/\n\n/ . . . /g;
275 for my $phrase_bits (split /\s+/,$cgi_var{phrase}) {
276 $snippet_mod =~ s{\n(\Q$phrase_bits\E)(?:\s+\Q$phrase_bits\E\n)}{'<b>'.$1.'</b>'}gei;
278 print "<p>$snippet_mod</p>\n";
281 if (($cgi_var{skip} > 0)) {
282 print q(<input type="submit" name="prev" value="Prev">);
284 if ($hits > ($cgi_var{skip}+$cgi_var{max_results})) {
285 print q(<input type="submit" name="next" value="Next">);
293 # This CGI should make an abstract method of displaying information
294 # about specific bugs and their messages; the information should be
295 # fairly similar to the way that pkgreport.cgi works, with the
296 # addition of snippit information and links to ajavapureapi/overview-summary.html specific message
299 # For now we'll brute force the display, but methods to display a bug
300 # or a particular bug message should be made common between the two
304 sub parse_attribute {
308 if (ref $$cgi_var{attribute_operator}) {
309 for my $elem (0 ... $#{$$cgi_var{attribute_operator}}) {
310 push @attributes,{map {($_,$$cgi_var{"attribute_$_"}[$elem]);} qw(value field operator)};
313 elsif (defined $$cgi_var{attribute_operator}) {
314 push @attributes,{map {($_,$$cgi_var{"attribute_$_"});} qw(value field operator)};
324 foreach my $paramname ($q->param) {
325 my @value = $q->param($paramname);
326 $param{$paramname} = @value > 1 ? [@value] : $value[0];