329 lines
12 KiB
Perl
329 lines
12 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
use warnings;
|
|
use strict;
|
|
use Time::HiRes qw( time );
|
|
|
|
use feature 'switch';
|
|
|
|
use Mojolicious::Lite -signatures;
|
|
use Mojo::SQLite;
|
|
use Text::Markdown qw{ markdown };
|
|
|
|
my $currentDB = "current.db";
|
|
my $stableDB = "stable.db";
|
|
|
|
if ( $^O eq "openbsd" ) {
|
|
require OpenBSD::Pledge;
|
|
require OpenBSD::Unveil;
|
|
|
|
OpenBSD::Unveil::unveil( "/", "" ) or die;
|
|
OpenBSD::Unveil::unveil( "./$currentDB", "r" ) or die;
|
|
OpenBSD::Unveil::unveil( "./$stableDB", "r" ) or die;
|
|
OpenBSD::Unveil::unveil( "/usr/local", "r" ) or die;
|
|
|
|
# Needed to create the -shm and -wal db files.
|
|
OpenBSD::Unveil::unveil( ".", "rwc" ) or die;
|
|
|
|
OpenBSD::Pledge::pledge(qw( stdio dns inet rpath proc flock wpath cpath ))
|
|
or die;
|
|
}
|
|
|
|
my $mtime = ( stat($currentDB) )[9];
|
|
$mtime = scalar localtime $mtime;
|
|
|
|
helper current => sub { state $sql = Mojo::SQLite->new("sqlite:$currentDB") };
|
|
helper stable => sub { state $sql = Mojo::SQLite->new("sqlite:$stableDB") };
|
|
|
|
my $query = q{
|
|
SELECT
|
|
FULLPKGNAME,
|
|
FULLPKGPATH,
|
|
COMMENT,
|
|
DESCRIPTION,
|
|
highlight(ports_fts, 2, '**', '**') AS COMMENT_MATCH,
|
|
highlight(ports_fts, 3, '**', '**') AS DESCR_MATCH
|
|
FROM ports_fts
|
|
WHERE ports_fts MATCH ? ORDER BY rank;
|
|
};
|
|
|
|
my $title = "OpenBSD.app";
|
|
my $descr = "OpenBSD package search";
|
|
|
|
sub to_md ($results) {
|
|
foreach my $result (@$results) {
|
|
$result->{DESCR_MATCH} = markdown( $result->{DESCR_MATCH} );
|
|
$result->{COMMENT_MATCH} = markdown( $result->{COMMENT_MATCH} );
|
|
}
|
|
|
|
}
|
|
|
|
get '/' => sub ($c) {
|
|
my $v = $c->validation;
|
|
|
|
my $search = $c->param('search');
|
|
|
|
my $current = $c->param('current');
|
|
my $format = $c->param('format');
|
|
|
|
$c->stash( title => $title );
|
|
$c->stash( descr => $descr );
|
|
$c->stash( mtime => $mtime );
|
|
|
|
if ( defined $search && $search ne "" ) {
|
|
my $db = $c->stable->db;
|
|
$db = $c->current->db if defined $current;
|
|
|
|
my $start = time();
|
|
my $results = $db->query( $query, $search )->hashes;
|
|
my $end = time();
|
|
my $elapsed = sprintf( "%2f\n", $end - $start );
|
|
|
|
to_md($results);
|
|
|
|
given ($format) {
|
|
when ("json") {
|
|
$c->render( json => $results );
|
|
}
|
|
default {
|
|
$c->render(
|
|
template => 'results',
|
|
search => $search,
|
|
elapsed => $elapsed,
|
|
results => $results
|
|
);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$c->render( template => 'index' );
|
|
}
|
|
};
|
|
|
|
get '/openbsd-app-opensearch.xml' => sub ($c) {
|
|
$c->res->headers->content_type('application/opensearchdescription+xml');
|
|
$c->render(
|
|
template => 'openbsd-app-opensearch',
|
|
format => 'xml',
|
|
title => $title,
|
|
descr => $descr
|
|
);
|
|
};
|
|
|
|
app->start;
|
|
__DATA__
|
|
@@ layouts/default.html.ep
|
|
<!doctype html>
|
|
<html class="no-js" lang="">
|
|
<head>
|
|
<title><%= $title %></title>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<meta name="description" content="<%= $descr %>">
|
|
<link
|
|
rel="search"
|
|
type="application/opensearchdescription+xml"
|
|
title="<%= $title %>"
|
|
href="/openbsd-app-opensearch.xml" />
|
|
<style>
|
|
body {
|
|
font-family: Avenir, 'Open Sans', sans-serif;
|
|
background-color: #ffffea;
|
|
}
|
|
|
|
table {
|
|
border-collapse:separate;
|
|
border:solid black 1px;
|
|
border-radius:6px;
|
|
background-color: #fff;
|
|
}
|
|
|
|
td, th {
|
|
border-left:solid black 1px;
|
|
border-top:solid black 1px;
|
|
}
|
|
|
|
th {
|
|
white-space: nowrap;
|
|
padding: 6px;
|
|
}
|
|
|
|
.search {
|
|
padding: 10px;
|
|
margin: 10px;
|
|
border-radius:6px;
|
|
box-shadow: 2px 2px 2px black;
|
|
}
|
|
|
|
th, .search {
|
|
border-top: none;
|
|
background-color: #eaeaff;
|
|
}
|
|
|
|
td:first-child, th:first-child {
|
|
border-left: none;
|
|
}
|
|
|
|
td {
|
|
padding: 10px;
|
|
text-align: left;
|
|
}
|
|
|
|
.nowrap {
|
|
white-space: nowrap;
|
|
}
|
|
|
|
footer, .wrap, .results {
|
|
text-align: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<h3><a href="/">OpenBSD.app - search packages</a></h3>
|
|
<div class="search">
|
|
%= form_for '/' => begin
|
|
%= text_field search => ""
|
|
-current
|
|
%= check_box 'current'
|
|
%= submit_button 'Search...'
|
|
% end
|
|
</div>
|
|
</div>
|
|
<div class="results">
|
|
<%== content %>
|
|
</div>
|
|
<hr />
|
|
<footer>
|
|
<p><a href="https://github.com/qbit/openbsd.app">OpenBSD.app</a> © 2022</p>
|
|
<p><a href="https://github.com/qbit/pkg">Prefer CLI?</a></p>
|
|
</footer>
|
|
</body>
|
|
</html>
|
|
|
|
@@ results.html.ep
|
|
% layout 'default';
|
|
<p>
|
|
Found <b><%= @$results %></b> results for '<b><%= $search %></b>' in <%= $elapsed %> seconds.<br />
|
|
<a href="/?search=<%= $search %>&format=json">View as JSON</a>
|
|
</p>
|
|
<table class="results">
|
|
<thead>
|
|
<tr>
|
|
<th>Package Name</th>
|
|
<th>Path</th>
|
|
<th>Comment</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
% foreach my $result (@$results) {
|
|
<tr>
|
|
<td class="nowrap"><%= $result->{FULLPKGNAME} %></td>
|
|
<td class="nowrap"><%= $result->{FULLPKGPATH} %></td>
|
|
<td class="nowrap"><%== $result->{COMMENT_MATCH} %></td>
|
|
<td><%== $result->{DESCR_MATCH} %></td>
|
|
</tr>
|
|
% }
|
|
</table>
|
|
|
|
@@ index.html.ep
|
|
% layout 'default';
|
|
Welcome! Default search queries OpenBSD 7.2 package sets. You can search -current packages (from <i><%= $mtime %></i>) by toggling the '-current' checkbox.
|
|
|
|
@@ openbsd-app-opensearch.xml.ep
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
|
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
|
<ShortName><%= $title %></ShortName>
|
|
<Description><%= $descr %></Description>
|
|
<InputEncoding>UTF-8</InputEncoding>
|
|
<Image width="32" height="32" type="image/x-icon">https://openbsd.org/favicon.ico</Image>
|
|
<Url type="text/html" method="GET" template="https://openbsd.app/?search={searchTerms}"/>
|
|
<moz:SearchForm>https://openbsd.app/</moz:SearchForm>
|
|
</OpenSearchDescription>
|
|
|
|
@@ favicon.ico (base64)
|
|
AAABAAQAICAAAAAAAACoCAAARgAAACAgEAAAAAAA6AIAAO4IAAAQEAAAAAAAAGgFAADWCwAAEBAQ
|
|
AAAAAAAoAQAAPhEAACgAAAAgAAAAQAAAAAEACAAAAAAAgAQAAAAAAAAAAAAAAAEAAAAAAAAAAAAA
|
|
AACAAACAAAAAgIAAgAAAAIAAgACAgAAAwMDAAICAgAAAAP8AAP8AAAD//wD/AAAA/wD/AP//AAD/
|
|
//8AwwAAAM8AAADbAAAA5wAAAPMAAAD/AAAA/xcXAP8vLwD/U1MA/2tnAP9/fwD/i4sA/5eXAP+j
|
|
owD/r68A/7u7AP/HxwD/z8cA/9vbAP/n5wD/8/MA//v3ACsrUwA3N18AQ0NrAE9PdwBXV38AY2OL
|
|
AG9vlwB/f6cAi4uzAJeXvwCnp88As7PbAL+/5wDHx+8Az8/3AFMrKwBfNzcAa0NDAHdPTwCDW1sA
|
|
j2dnAJtzcwCnf38As4uLAL+X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
Z2Zil62tAK2trQDLlwAAAEgAAAAARyj1AACtl5doYpVilpetrQDLl8ut9yaXAAAAAAAAAAAAAAAA
|
|
CEU4lmMAADU7N60AAGZjJwAAAEUIAAAAAAAAAAAAAAAAAACVKDlHN5cm9gD2lmL3AAAAAPYAAAAA
|
|
AAAAAAAAAAAA95cAAAD1lwAAAAAplwAAAAAAAAAAAAAAAAAAAAAAAAAp9gAAAPRIAAAAAAAAAAAA
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////
|
|
/m///+5O7//2BMHf0YABH8AAAD/AAABvwAAAR8AAAAPAAAADwAAAAcAAAADAAAAAgAAAAMAAABCA
|
|
AAAIAAAAAMAAAA+AAAAfAAAAP8AAAB/AAAAPgAAA7xgAAP/wAA5//gEPf/znn//859/////f////
|
|
////////KAAAACAAAABAAAAAAQAEAAAAAACAAgAAAAAAAAAAAAAQAAAAAAAAAAQCBAAMhpwABNL0
|
|
ABxGTAAEqswAHGZ0AIyCfADMxswATEZEAPz+/AAsKiQApJ6cAGxqZABMjpwAXFZMAAAAAAD/////
|
|
//////////////////////////////////////////7////////////////////8j/P/////////
|
|
//////+v+O/0P/P///j/////////UY/+gh+lzuiM/zP/////jvHVFB1Bzq//ioVD/////4jzIiIk
|
|
XKqq+qpRT//////q8SIiIlqoqoylRV8x////6lIiIiJYr6qM4UMfVF///24RERIiJa+oju6KFTWq
|
|
//+BVCJEIiJeZujszzE0+v//UkG3fRIiTGzIjGikFB8//xIk2ZfEIkVszuy6oRRDNf8SIRmZsiIh
|
|
5u7suKRaFBH/0iQU3UIiIYbO7LyhX/Uk/xTNFEQiIiRWbI7IoR//M/FdlxJNVCIkV3uo7IQhr///
|
|
/XZBt3UiJBd76KiEX////1HVJWedIiTbbLtmYf////5REiRXcUIk5u7GZtX/////8SIiJVVCQcyI
|
|
zMhR//////QkIiI1IkXOjMyI/z////8VgSIiIiReyu7oM/////////zlJBQY7qherzX////////6
|
|
5UOGu+oyQ/////////////Ff+NP/8U/////////////z//8///9f////////////////////r///
|
|
////////////////////////////////////////////////////////////////////////////
|
|
/////v////5v///2Zuv/8YQDP8gAAD/IAAB/wAAAT8AAAEfAAAADwAAAC8AAAAXAAAAAwAAAAMAA
|
|
ABjAAAAcgAAAB+AAAB/AAAA/gAAAP+AAAD/gAADfwAAA//gABP/4AA///mOf//733////9//////
|
|
////////////KAAAABAAAAAgAAAAAQAIAAAAAABAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAIAA
|
|
AIAAAACAgACAAAAAgACAAICAAADAwMAAgICAAAAA/wAA/wAAAP//AP8AAAD/AP8A//8AAP///wDD
|
|
AAAAzwAAANsAAADnAAAA8wAAAP8AAAD/FxcA/y8vAP9TUwD/a2cA/39/AP+LiwD/l5cA/6OjAP+v
|
|
rwD/u7sA/8fHAP/PxwD/29sA/+fnAP/z8wD/+/cAKytTADc3XwBDQ2sAT093AFdXfwBjY4sAb2+X
|
|
AH9/pwCLi7MAl5e/AKenzwCzs9sAv7/nAMfH7wDPz/cAUysrAF83NwBrQ0MAd09PAINbWwCPZ2cA
|
|
m3NzAKd/fwCzi4sAv5eXAMujowDXr68A47u7AOvDwwD709MAL1MvADtfOwBHa0cAU3dTAF+DXwBr
|
|
j2sAd5t3AIOngwCPs48Am7+bAKfLpwCz17MAv+O/AMvvywDX+9cAh2+XAJd/pwCnj7cAs5vDAMOr
|
|
0wDPt98A28PrAIuXbwCTo3sAn6+HAKu7kwC3x58Ay9uzANfnvwDj88sAC2+bAA97owATh68AF4+3
|
|
ABubwwAXp88AG7PbACO/5wAry/MAN9f/AP/z/wD/6/8A/9//AP/T/wD/x/8A/7f/AP+j/wD/l/8A
|
|
/4P/AP9r/wD/S/8A5wDnANcA1wDDAMcAtwC3AKMApwCXAJcAiwC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