openbsd.app/openbsd.app.pl

304 lines
12 KiB
Perl
Raw Normal View History

use warnings;
use strict;
use feature 'switch';
2022-09-23 16:45:55 -06:00
use Mojolicious::Lite -signatures;
use Mojo::SQLite;
if ( $^O eq "openbsd" ) {
require OpenBSD::Pledge;
require OpenBSD::Unveil;
OpenBSD::Unveil::unveil( "/", "" ) or die;
OpenBSD::Unveil::unveil( "./current.db", "r" ) or die;
OpenBSD::Unveil::unveil( "./stable.db", "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;
}
helper current => sub { state $sql = Mojo::SQLite->new('sqlite:current.db') };
helper stable => sub { state $sql = Mojo::SQLite->new('sqlite:stable.db') };
2022-09-23 16:45:55 -06:00
my $query = q{
SELECT
FULLPKGNAME,
FULLPKGPATH,
COMMENT,
DESCRIPTION,
highlight(ports_fts, 2, '<b>', '</b>') AS COMMENT_MATCH,
highlight(ports_fts, 3, '<b>', '</b>') AS DESCR_MATCH
FROM ports_fts
WHERE ports_fts MATCH ? ORDER BY rank;
};
my $title = "OpenBSD.app";
my $descr = "OpenBSD package search";
2022-09-23 16:45:55 -06:00
get '/' => sub ($c) {
my $v = $c->validation;
2022-09-23 16:45:55 -06:00
my $search = $c->param('search');
2022-09-23 20:25:02 -06:00
my $current = $c->param('current');
my $format = $c->param('format');
2022-09-23 16:45:55 -06:00
$c->stash( title => $title );
$c->stash( descr => $descr );
2022-09-23 20:25:02 -06:00
if ( defined $search && $search ne "" ) {
2022-09-23 20:25:02 -06:00
my $db = $c->stable->db;
$db = $c->current->db if defined $current;
2022-09-23 16:45:55 -06:00
2022-09-23 20:25:02 -06:00
my $results = $db->query( $query, $search )->hashes;
given ($format) {
when ("json") {
$c->render( json => $results );
}
default {
$c->render(
template => 'results',
search => $search,
results => $results
);
}
}
2022-09-23 16:45:55 -06:00
}
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
);
};
2022-09-23 16:45:55 -06:00
app->start;
__DATA__
@@ layouts/default.html.ep
<!doctype html>
<html class="no-js" lang="">
<head>
<title><%= $title %></title>
2022-09-23 16:45:55 -06:00
<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"
2022-09-25 16:07:17 -06:00
title="<% = $title %>"
href="/openbsd-app-opensearch.xml" />
2022-09-23 16:45:55 -06:00
<style>
body {
font-family: Avenir, 'Open Sans', sans-serif;
2022-09-23 21:45:29 -06:00
background-color: #ffffea;
2022-09-23 16:45:55 -06:00
}
2022-09-23 20:25:02 -06:00
table {
border-collapse:separate;
border:solid black 1px;
border-radius:6px;
2022-09-23 21:45:29 -06:00
background-color: #fff;
2022-09-23 16:45:55 -06:00
}
2022-09-23 20:25:02 -06:00
td, th {
border-left:solid black 1px;
border-top:solid black 1px;
}
2022-09-23 21:45:29 -06:00
2022-09-24 06:51:01 -06:00
th {
white-space: nowrap;
2022-09-24 06:51:55 -06:00
padding: 6px;
2022-09-24 06:51:01 -06:00
}
2022-09-23 21:45:29 -06:00
.search {
padding: 10px;
margin: 10px;
border-radius:6px;
box-shadow: 2px 2px 2px black;
}
2022-09-23 20:25:02 -06:00
2022-09-23 21:45:29 -06:00
th, .search {
2022-09-23 20:25:02 -06:00
border-top: none;
2022-09-23 21:45:29 -06:00
background-color: #eaeaff;
2022-09-23 20:25:02 -06:00
}
td:first-child, th:first-child {
border-left: none;
}
td {
padding: 10px;
2022-09-23 21:45:29 -06:00
text-align: left;
2022-09-23 16:45:55 -06:00
}
2022-09-23 20:25:02 -06:00
.nowrap {
white-space: nowrap;
2022-09-23 16:45:55 -06:00
}
2022-09-23 21:45:29 -06:00
footer, .wrap, .results {
text-align: center;
2022-09-23 16:45:55 -06:00
}
</style>
</head>
<body>
<div class="wrap">
<h3><a href="/">OpenBSD.app - search packages</a></h3>
2022-09-23 16:45:55 -06:00
<div class="search">
%= form_for '/' => begin
%= text_field search => ""
2022-09-24 08:24:38 -06:00
-current
%= check_box 'current'
2022-09-23 16:45:55 -06:00
%= submit_button 'Search...'
% end
</div>
</div>
2022-09-23 21:45:29 -06:00
<div class="results">
<%== content %>
</div>
2022-09-23 16:45:55 -06:00
<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>
2022-09-23 16:45:55 -06:00
</footer>
</body>
</html>
@@ results.html.ep
% layout 'default';
<p>
Found <b><%= @$results %></b> results for '<b><%= $search %></b>'<br />
<a href="/?search=<%= $search %>&format=json">View as JSON</a>
</p>
2022-09-23 21:45:29 -06:00
<table class="results">
2022-09-23 16:45:55 -06:00
<thead>
<tr>
2022-09-23 21:07:13 -06:00
<th>Package Name</th>
2022-09-23 21:45:29 -06:00
<th>Path</th>
2022-09-23 16:45:55 -06:00
<th>Comment</th>
<th>Description</th>
</tr>
</thead>
% foreach my $result (@$results) {
<tr>
2022-09-23 21:07:13 -06:00
<td class="nowrap"><%= $result->{FULLPKGNAME} %></td>
2022-09-23 21:45:29 -06:00
<td class="nowrap"><%= $result->{FULLPKGPATH} %></td>
2022-09-23 20:25:02 -06:00
<td class="nowrap"><%== $result->{COMMENT_MATCH} %></td>
2022-09-23 16:45:55 -06:00
<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 2022-09-23) by toggling the '-current' checkbox.
@@ openbsd-app-opensearch.xml.ep
2022-09-25 09:54:21 -06:00
<?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>
2022-09-25 09:54:21 -06:00
<Url type="text/html" method="GET" template="https://openbsd.app/?search={searchTerms}"/>
<moz:SearchForm>https://openbsd.app/</moz:SearchForm>
</OpenSearchDescription>
2022-09-25 11:01:59 -06:00
@@ 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+XlwDLo6MA16+vAOO7uwDrw8MA+9PTAC9TLwA7XzsAR2tHAFN3UwBf
g18Aa49rAHebdwCDp4MAj7OPAJu/mwCny6cAs9ezAL/jvwDL78sA1/vXAIdvlwCXf6cAp4+3ALOb
wwDDq9MAz7ffANvD6wCLl28Ak6N7AJ+vhwCru5MAt8efAMvbswDX578A4/PLAAtvmwAPe6MAE4ev
ABePtwAbm8MAF6fPABuz2wAjv+cAK8vzADfX/wD/8/8A/+v/AP/f/wD/0/8A/8f/AP+3/wD/o/8A
/5f/AP+D/wD/a/8A/0v/AOcA5wDXANcAwwDH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AcAAAADAAAAAgAAAAMAAABCA
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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