-
Notifications
You must be signed in to change notification settings - Fork 2
/
opensusemaintainer
executable file
·348 lines (330 loc) · 15.3 KB
/
opensusemaintainer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/usr/bin/perl -w
# SPDX-License-Identifier: GPL-2.0-only
# see COPYING for details
# by Bernhard M. Wiedemann
# with contributions from Sasi Olin
use strict;
use CGI qw":form :cgi a li start_html end_html br hr"; # "head" would collide with LWP:Simple
use URI::Escape; # perl-URI / liburi-perl
use XML::Simple;
use JSON::XS;
# needs libcrypt-ssleay-perl for HTTPS
use DB_File;
use Fcntl;
use Time::HiRes qw"gettimeofday tv_interval";
our $debug=1;
our $factory="openSUSE:Factory";
our $dbdir="/home/aw/html/db.suse";
our $cachedir="$dbdir/xml/";
our $expiry=31*24*60*60;
our $html;
our $data={};
sub isfresh($)
{
my $cachefile=shift;
my $mtime=(stat($cachefile))[9];
my $factor=1;
$factor=3 if($cachefile=~m/source,openSUSE:Factory,.*,_meta/);
return 0 unless $mtime;
return($mtime>time-$expiry*$factor);
}
sub get($)
{
open(my $pipe, "-|", qw"curl -s", $_[0]) or return "error $!";
local $/;
return scalar <$pipe>;
}
sub cachedget
{
my $urlbase='https://api.opensuse.org/public';
my $cachefile=$cachedir.join(',', @_);
my $url=$urlbase."/".join("/", @_);
my $xmldata;
if(isfresh($cachefile)) {
open(my $f, "<", $cachefile) or die "could not read cachefile: $!";
local $/;
$xmldata=<$f>;
close $f;
} else {
my $t=[gettimeofday];
$xmldata=get($url);
$html .= "<span class='text-success'>OBS API request took ".tv_interval($t)." seconds</span>\n".br if($debug);
return unless $xmldata;
open(my $f, ">", "$cachefile.new") or warn "could not write cachefile: $!";
print $f $xmldata;
close $f;
rename("$cachefile.new", "$cachefile") or warn "could not rename cachefile";
}
return $xmldata;
}
sub suseapi
{
my $xml=cachedget(@_);
return unless $xml;
return eval{XMLin($xml, ForceArray => ["person", "repository", "path", "arch", "globalrole", "enable", "disable"])}||undef;
}
sub lookupdbm($$)
{
my ($db,$key)=@_;
my %dbmap;
my $result;
tie %dbmap, "DB_File", "$dbdir/$db.dbm", O_RDONLY;
$result=$dbmap{$key};
untie %dbmap;
return $result;
}
our %seen=();
sub printusers($)
{ my $userdata=shift;
my $ps;
unless ($userdata && ($ps=$userdata->{person})) {
$html .= "No persons associated with this package<br/>\n";
return;
} else {
$html .= "<div class='userlist'><ul>";
foreach my $p (@$ps) {
my $user=$p->{userid};
if($user eq "--separatordummy--") { $html .= hr; next;}
next if $seen{$user.$p->{role}}++;
my $r=$p->{role};
if($r eq "bugowner") {$r=CGI::strong($r)}
$html .= qq{<li>$r: <a href="https://build.opensuse.org/users/$user">$user</a>\n</li>};
}
$html .= "</ul></div>\n";
}
}
sub entrylist($@)
{
my $type=shift;
my @a=@_;
if(@a>1) {
$html .= "<div class='text-warning'>found more than one package that provides this: <ol>";
foreach(@a) {
my $u = uri_escape($_);
$html .= li(a({href=>"?pkg=$u&type=$type"},$_));
}
$html .= "</ol></div>";
}
}
sub lookupfilepkg($)
{
my $in=shift;
my $p=lookupdbm("filepkg", $in);
return split("\000", $p||"");
}
sub get_distro_versions($)
{
my $pkg=shift;
my %ver;
for my $d (qw"opensuse gentoo alpinelinux archlinux voidlinux altlinux nixos guix centos fedora mageia pclinuxos solus debian ubuntu slackware") {
$ver{$d} = lookupdbm("${d}src", $pkg);
}
return \%ver;
}
sub selftest()
{
lookupdbm("filepkg", "/usr/bin/zgrep") eq "gzip" or die "filepkg selftest failed";
lookupdbm("pkgsrc", "Mesa-32bit") eq "Mesa" or die "pkgsrc selftest failed";
lookupdbm("provides", "Mesa(x86-64)") eq "Mesa" or die "provides selftest failed";
}
# main
$html = header("text/html"). start_html(-title=>"package finder tool",
#-style=>"//www.zq1.de/code/css/pure-min.css",
-head=>[qq{<link rel="stylesheet" href="//static.opensuse.org/chameleon-3.0/dist/css/chameleon.css" />},
qq{<style type="text/css">
.distri {font-weight: bold}
.version {color: var(--pink)}
</style>},
qq{<script type="text/javascript" defer="defer" src="//static.opensuse.org/chameleon-3.0/dist/js/jquery.slim.js"></script>},
qq{<script type="text/javascript" defer="defer" src="//static.opensuse.org/chameleon-3.0/dist/js/bootstrap.bundle.js"></script>},
qq{<script type="text/javascript" defer="defer" src="//static.opensuse.org/chameleon-3.0/dist/js/chameleon.js"></script>},
qq{<script type="text/javascript" src="//www.zq1.de/js/bmwajax.js"></script>},
qq{<link type="image/vnd.microsoft.icon" rel="icon" href="/favicon.ico" />},
qq{<link rel="shortcut icon" href="/favicon.ico" />},
qq{<meta name="viewport" content="width=400px, initial-scale=1" />}
]
);
my $input1=$ENV{PATH_INFO}||""; $input1=~s{^/}{}; param("pkg", $input1) if $input1 and not param("pkg");
$input1=param("pkg") || "";
$input1=~s/[<>"'&]//g; # sanitize
if($input1 eq "robots.txt") {
exit 0;
}
if($input1 eq "favicon.ico") {
print header("image/x-icon").`cat /home/aw/html/maintainerfavicon.ico`;
exit 0;
}
my %typeselect=(
"auto" => "anywhere",
"srcpkg" => "source package name (e.g. Mesa)",
"binpkg" => "binary package name (e.g. Mesa-32bit)",
"provides" => "a package's provides (e.g. Mesa(x86-64))",
"fullpath" => "full path/filename (e.g. /etc/rsyncd.conf)",
"command" => "command/executable (e.g. cat)");
if(1) {
$html .= "<div class='navbar navbar-expand-md'><a class='navbar-brand' href='/'><img src='//static.opensuse.org/favicon.svg' class='d-inline-block align-top' alt='openSUSE' title='openSUSE' width='30' height='30' /><span class='navbar-title'>Maintainer</span></a><button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbar-collapse'><svg width='1em' height='1em' viewBox='0 0 16 16' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' d='M2.5 11.5A.5.5 0 0 1 3 11h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4A.5.5 0 0 1 3 3h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z'></path></svg></button><div class='collapse navbar-collapse' id='navbar-collapse'><ul class='nav navbar-nav mr-auto flex-md-shrink-0'><li class='nav-item'><a class='nav-link' href='https://github.com/bmwiedemann/susepkginfo/blob/master/userhelp.md'>Help</a></li><li class='nav-item dropdown'><a class='nav-link dropdown-toggle' href='#' id='cat-menu-link' data-toggle='dropdown'>Similar tools</a><div class='dropdown-menu'><a class='dropdown-item' href='http://sophie.zarb.org/'>Sophie</a></div></li></ul></div><button class='navbar-toggler megamenu-toggler' type='button' data-toggle='collapse' data-target='#megamenu'><svg class='bi bi-grid' width='1em' height='1em' viewBox='0 0 16 16' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' d='M1 2.5A1.5 1.5 0 0 1 2.5 1h3A1.5 1.5 0 0 1 7 2.5v3A1.5 1.5 0 0 1 5.5 7h-3A1.5 1.5 0 0 1 1 5.5v-3zM2.5 2a.5.5 0 0 0-.5.5v3a.5.5 0 0 0 .5.5h3a.5.5 0 0 0 .5-.5v-3a.5.5 0 0 0-.5-.5h-3zm6.5.5A1.5 1.5 0 0 1 10.5 1h3A1.5 1.5 0 0 1 15 2.5v3A1.5 1.5 0 0 1 13.5 7h-3A1.5 1.5 0 0 1 9 5.5v-3zm1.5-.5a.5.5 0 0 0-.5.5v3a.5.5 0 0 0 .5.5h3a.5.5 0 0 0 .5-.5v-3a.5.5 0 0 0-.5-.5h-3zM1 10.5A1.5 1.5 0 0 1 2.5 9h3A1.5 1.5 0 0 1 7 10.5v3A1.5 1.5 0 0 1 5.5 15h-3A1.5 1.5 0 0 1 1 13.5v-3zm1.5-.5a.5.5 0 0 0-.5.5v3a.5.5 0 0 0 .5.5h3a.5.5 0 0 0 .5-.5v-3a.5.5 0 0 0-.5-.5h-3zm6.5.5A1.5 1.5 0 0 1 10.5 9h3a1.5 1.5 0 0 1 1.5 1.5v3a1.5 1.5 0 0 1-1.5 1.5h-3A1.5 1.5 0 0 1 9 13.5v-3zm1.5-.5a.5.5 0 0 0-.5.5v3a.5.5 0 0 0 .5.5h3a.5.5 0 0 0 .5-.5v-3a.5.5 0 0 0-.5-.5h-3z'></path></svg></button></div><div id='megamenu' class='megamenu collapse'></div><div class='page-content flex-fill'><div class='container my-4'>".
start_form(-name=>"form", -method=>"get", -class=>"pure-form").
"<p class='text-center'>Find details about openSUSE packages (e.g. maintainer and development project)</p>
<p><fieldset class='form-inline justify-content-center'>".
textfield(-name=>'pkg', -class=>'form-control mr-1', -placeholder=>"Search", -accesskey=>"c", -id=>"searchtext", -onchange=>"formsearch()", -oninput=>"formsearch()").
" in ".popup_menu(-name=>'type',-default=>"auto", -class=>'custom-select mr-1', -values=>[sort keys %typeselect], -labels=>\%typeselect)." ".
submit(-label=>"Search", -class=>'btn btn-primary')."</fieldset></p>". end_form.
'<div id="replace"></div>'.
qq'<script language="javascript" type="text/javascript">
document.form.pkg.focus();
document.form.pkg.select();'.
qq{
URLs = [
"https://packages.ubuntu.com/search?keywords=ARG", "Ubuntu",
"https://packages.debian.org/search?keywords=ARG", "Debian",
"https://koji.fedoraproject.org/koji/search?match=glob&type=package&terms=ARG*", "Fedora(koji)",
"https://src.fedoraproject.org/rpms/ARG", "Fedora(git)",
"https://packages.fedoraproject.org/search?query=ARG", "Fedora",
"https://madb.mageia.org/package/list/application/0/t_search/ARG", "Mageia",
"https://svnweb.mageia.org/packages/cauldron/ARG/current/SPECS/", "MageiaSrc",
"https://pkgs.alpinelinux.org/packages?name=ARG&arch=x86_64", "Alpine",
"https://packages.altlinux.org/en/search?branch=sisyphus&name=ARG", "ALTLinux",
"https://aur.archlinux.org/packages/?K=ARG", "AUR",
"https://www.archlinux.org/packages/?q=ARG", "Arch Linux",
"https://guix.gnu.org/packages/LETTER/#ARG", "Guix",
"https://nixos.org/nixos/packages.html?query=ARG", "NixOS",
"https://www.freebsd.org/cgi/ports.cgi?query=ARG", "FreeBSD",
"https://packages.gentoo.org/packages/search?q=ARG", "Gentoo",
"https://pmbs.links2linux.de/search?package=1&name=1&search_text=ARG", "Packman",
"https://build.opensuse.org/search?package=1&name=1&search_text=ARG", "OBS",
"https://scc.suse.com/packages?name=SUSE%20Linux%20Enterprise%20Server&version=15.1&arch=x86_64&query=ARG", "SLE",
"https://software.opensuse.org/search?q=ARG", "openSUSE",
"https://release-monitoring.org/projects/search/?pattern=ARG", "release-monitoring",
"https://pkgs.org/search/?q=ARG", "pkgs.org",
"https://repology.org/metapackage/ARG/information", "repology"
];
function mysearch(val) {
var x=document.getElementById("replace");
if(val.indexOf("/") > -1) {x.innerHTML=""; return;} // be smart and dont search for pathnames
HTML="You can also search for <strong>"+val+"</strong> in ";
for (var i = URLs.length-1; i>=0; i-=2) {
HTML+="<a href='"+URLs[i-1].replace("ARG",val).replace("LETTER",val[0].toUpperCase())+"'>"+URLs[i]+"</a> ";
}
if(val == '') {HTML='';}
x.innerHTML=HTML;
}
function do_formsearch(val) {
window.location.href = "#"+val;
mysearch(val);
}
seen={};
function formsearch() {
var val=document.getElementById("searchtext").value;
do_formsearch(val);
// trigger async cache fetch
if(seen[val]) return;
/*Ab("//"+window.location.host+window.location.pathname+"?ajax=1&pkg="+val, function(c,s) {
return; // ignore result
}, 0);
seen[val]=1;
*/
}
window.onload = function () {
var h=window.location.hash;
if(h.length>1) {
var v=h.replace("#","");
document.getElementById("searchtext").value=v;
mysearch(v);
} else {
do_formsearch(document.getElementById("searchtext").value);
}
};
</script>}.br.
"";
}
if(param) {
my %output;
my $type=param('type') || "auto";
$type="fullpath" if $input1=~m{/};
if($type ne "auto") {
$output{$type}=$input1;
} else {
$input1=~s/\s//g; # drop spaces to better work with copy-pasted strings
for my $t ("srcpkg", "binpkg", "command", "provides") {
$output{$t}=$input1;
}
}
if($output{"provides"}) {
my $p=lookupdbm("provides", $output{"provides"});
if($p) {
my @a=split("\000", $p);
$output{binpkg}=$a[0];
entrylist("binpkg", @a);
} else {
$html .= "provides not found" unless $type eq "auto";
$output{"provides"}="";
}
}
if($output{"command"}) {
foreach my $path (qw"/xbin /bin /sbin /usr/bin /usr/sbin") {
my $fp=$path."/".$output{"command"};
my @a=lookupfilepkg($fp);
if(@a) {
$output{"fullpath"}=$fp;
}
}
}
if($output{"fullpath"}) {
$output{"fullpath"}=~s!/$!!; # drop trailing slash
my @a=lookupfilepkg($output{"fullpath"});
if(@a) {
$output{binpkg}=$a[0];
entrylist("binpkg", @a);
} else {
$html .= "file not found".br;
}
}
if($output{binpkg}) {
my $p=lookupdbm("pkgsrc", $output{binpkg});
$output{srcpkg}=$p if $p;
$html .= "binary package not found".br unless $p || $type eq "auto";
}
if(my $pkgname=$output{srcpkg}) {
my $ver=get_distro_versions($output{srcpkg});
$data->{distroversion}=$ver;
$data->{name}=$pkgname;
for my $d (sort(keys(%$ver))) {
my $v = $ver->{$d};
if($v) {
$html .= "<div class='d-inline-block'>found $output{srcpkg}-<span class='version'>$v</span> in <span class='distri'>$d</span> ; </div> ";
}
}
$html .= "<br/>";
if($ver->{opensuse}) {
my $devel=lookupdbm("develproject", $pkgname);
if($devel) {
my @a=split("\000", $devel);
$devel={project=>$a[0], package=>$a[1]};
my @extrainfo;
if($output{fullpath}) {push @extrainfo, "<strong>Path:</strong> $output{fullpath}".br}
if($output{provides}) {push @extrainfo, "<strong>Provides:</strong> $output{provides}".br}
if($output{binpkg}) {push @extrainfo, "<strong>Binary-Package:</strong> $output{binpkg}".br}
$html .= join("",@extrainfo).qq!<strong>Source-Package:</strong> <a href="https://build.opensuse.org/package/show/$devel->{project}/$devel->{package}">$pkgname</a> (<a href="https://code.opensuse.org/package/$pkgname">git</a>) $ver->{opensuse}
<a href="https://build.opensuse.org/package/view_file/$devel->{project}/$devel->{package}/$pkgname.changes?expand=1">changes</a>!.br.
qq!<strong>devel-project:</strong> <a href="https://build.opensuse.org/project/show/$devel->{project}">$devel->{project}</a>!.br.
"<strong>Package-Maintainers:</strong>\n";
my $obsdata=suseapi("source", $devel->{project}, $devel->{package}, "_meta");
$data->{obs}{pkg}=$obsdata;
printusers($obsdata);
$html .= hr."<strong>Project-Maintainers:</strong>";
$obsdata=suseapi("source", $devel->{project}, "_meta");
$data->{obs}{prj}=$obsdata;
printusers($obsdata);
} else { $html .= "Bad package on $factory ⇒ <a href=\"https://software.opensuse.org/search?q=$output{srcpkg}\">search</a>" }
}
}
}
selftest;
$html .= "</div></div><div class='footer'><div class='container'><div class='d-flex justify-content-between'><div class='footer-copyright'>© 2022 openSUSE contributors</div><div>To report issues, contribute or run your own, please <a href='https://github.com/bmwiedemann/susepkginfo'>use the github repo</a></div></div></div></div>".
end_html;
if(!param("ajax")) {
print $html;
} else {
print header("application/json").
JSON::XS->new->pretty->canonical->encode($data);
}