speedie-aur/packages/index.php

300 lines
12 KiB
PHP

<?php
function getShellString($file, $string) {
$contents = file_get_contents($file);
$output = array();
// Rather lazy, but convenient
exec("./viewer/output_data.sh $file $string", $output);
if (empty($output[0])) {
return NULL;
}
return $output[0];
}
function printHead($self, $pTitle, $title, $desc) {
print "<!DOCTYPE html>\n";
print "<head>\n";
print "\t<meta name=\"description\" content=\"$desc\">\n";
print "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
print "\t<link rel=\"icon\" href=\"/viewer/fav.svg\"/>\n";
print "\t<link type=\"text/css\" rel=\"stylesheet\" href=\"/viewer/index.css\"/>\n";
print "\t<title>$title</title>\n";
print "\t<div class=\"bar\">\n";
print "\t\t\t<span class=\"title\">$pTitle</span>\n";
print "\t\t\t\t<a href=\"$self?action=view\"><img src=\"/viewer/home.svg\" width=\"16\" height=\"16\">Home</a>\n";
print "\t\t\t\t<a href=\"$self?action=all\"><img src=\"/viewer/all.svg\" width=\"16\" height=\"16\">All</a>\n";
print "\t\t\t\t<a href=\"https://git.speedie.site/speedie/speedie-aur/issues/new\"><img src=\"/viewer/report.svg\" width=\"16\" height=\"16\">Report issue</a>\n";
print "\t\t<form method=\"post\" action=\"$self?action=search\"><input type=\"text\" name=\"q\" placeholder=\"search for packages..\"></form>\n";
print "\t</div>\n";
print "</head>\n";
print "<body>\n";
print "\t<div class=\"content\">\n";
}
function printFoot() {
print "\t</div>\n";
print "</body>\n";
print "<footer>\n";
print "\t<div class=\"column\">\n";
print "\t\t<span class=\"links\">\n";
print "\t\t\t<a class=\"links\" href=\"https://git.speedie.site\">Git</a>\n";
print "\t\t\t<a class=\"links\" href=\"https://ls.speedie.site\">Downloads</a>";
print "\t\t\t<a class=\"links\" href=\"https://git.speedie.site/speedie/speedie-aur\">Source code</a>\n";
print "\t\t\t<p class=\"links\">Licensed under the GNU Affero General Public License v3</p>\n";
print "\t\t</span>\n";
print "\t</div>\n";
print "</footer>\n";
print "</html>\n";
}
function main() {
$request = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
$query = isset($_REQUEST['q']) ? $_REQUEST['q'] : '';
$self = $_SERVER['PHP_SELF'];
$packageCount = 0;
$packageFiles = array();
$packageNames = array();
$packageDescs = array();
foreach(scandir(".") as $f) {
$path = pathinfo($f);
if (empty($path['extension'])) {
continue;
}
if ($path['extension'] == "PKGBUILD") {
$packageCount++;
$packageFiles[$packageCount] = $f;
$packageNames[$packageCount] = getShellString($f, "pkgname");
$packageDescs[$packageCount] = getShellString($f, "pkgdesc");
}
}
// Return results
if ($request == "search") {
$validPkgs = 0;
$matches = array();
$matchingDescs = array();
$matchingUrls = array();
for ($i = 1; $i < $packageCount+1; $i++) {
if (preg_match("/$query/i", $packageNames[$i]) == 0) {
continue;
} else if ($packageNames[$i+1] == $packageNames[$i]) {
continue;
}
$matches[$validPkgs] = $packageNames[$i];
$matchingDescs[$validPkgs] = $packageDescs[$i];
$matchingUrls[$validPkgs] = $packageUrls[$i];
$validPkgs++;
}
printHead($self, "speedie-aur", "Found $validPkgs packages matching '$query' in speedie-aur", "Found $validPkgs packages matching search query '$query' in speedie-aur");
print "\t\t\t<p class=\"matches\">$validPkgs packages found matching '$query'..</p>\n";
print "\t\t\t<table>\n";
print "\t\t\t\t<tr>\n";
print "\t\t\t\t\t<td><strong>Package</strong></td>\n";
print "\t\t\t\t\t<td><strong>Description</strong></td>\n";
print "\t\t\t\t</tr>\n";
for ($i = 0; $i < $validPkgs; $i++) {
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t\t<td><a href=\"$self?action=view&q=$matches[$i]\">$matches[$i]</a></td>\n";
print "\t\t\t\t\t\t<td>$matchingDescs[$i]</td>\n";
print "\t\t\t\t</tr>\n";
}
print "\t\t\t</table>\n";
} else if ($request == "all") {
printHead($self, "speedie-aur", "All packages in speedie-aur", "There are $packageCount packages in speedie-aur");
print "\t\t\t<p>Total number of packages: $packageCount</p>\n";
print "\t\t\t<table>\n";
print "\t\t\t\t<tr>\n";
print "\t\t\t\t\t<td><strong>Package</strong></td>\n";
print "\t\t\t\t\t<td><strong>Description</strong></td>\n";
print "\t\t\t\t</tr>\n";
for ($i = 1; $i < $packageCount+1; ++$i) {
if ($packageNames[$i+1] == $packageNames[$i]) {
continue;
}
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t\t<td><a href=\"$self?action=view&q=$packageNames[$i]\">$packageNames[$i]</a></td>\n";
print "\t\t\t\t\t\t<td>$packageDescs[$i]</td>\n";
print "\t\t\t\t</tr>\n";
}
print "\t\t\t</table>\n";
} else if ($request == "archive") {
exec("./viewer/archive.sh", $output);
if (file_exists("packages.tar.gz")) {
header("Location: packages.tar.gz");
}
exit();
} else if ($request == "view" && $query == '') {
printHead($self, "speedie-aur", "speedie-aur", "My unofficial Arch Linux repository containing many useful packages");
print "\t\t<h1>speedie-aur</h1>\n";
print "\t\t\t<p>Welcome to aur.speedie.site. This is just my Arch Linux repository.</p>\n";
print "\t\t<h2>Installation</h2>\n";
print "\t\t\t<p>Add the following lines to <code>/etc/pacman.conf</code> on your Arch Linux based operating system:</p>\n";
print "\t\t\t\t<pre><code>\n";
print "\t[speedie-aur]\n";
print "\tServer = https://aur.speedie.site\n";
print "\t\t\t\t</code></pre>\n";
print "\t\t\t\t<p>Now run <code>pacman-key --recv-keys CEB863B830D1318A && pacman-key --lsign-key CEB863B830D1318A</code> to add my PGP key.</p>\n";
print "\t\t\t\t<p>Then simply <code>pacman -Syu</code> to sync the repositories. Then you can install any of my packages in the same way you install official packages.</p>\n";
print "\t\t<h2>How do I use this site?</h2>\n";
print "\t\t\t<p>You can search for packages using the input box in the navbar. Then you can select a package to view details about it. You can press 'Home' in the navbar to go back to this page, or 'All' to display all available packages.</p>\n";
print "\t\t<h2>Directory listing</h2>\n";
print "\t\t\t<p>See <a href=\"lister.php\">this page</a> for more information.</p>\n";
print "\t\t<h2>Download</h2>\n";
print "\t\t\t<p>If you wish, you can download the full packages/ directory containing all packages, the database and the PHP itself. This may be useful if you want to have a local repository that won't get updated, or you want to contribute back.</p>\n";
print "\t\t\t<p>A tar.gz archive can be found <a href=\"$self?action=archive\">here</a>.</p>\n";
} else if ($request == "view" && $query != '') {
$packageCount = 0;
$packageVersions = array();
$packageUrls = array();
$packageDepends = array();
$packageFilenames = array();
$packageLicenses = array();
$packageSizes = array();
$packageGPG = array();
$packageMD5 = array();
$packageSHA256 = array();
$packageSource = array();
foreach(scandir(".") as $f) {
$path = pathinfo($f);
if (empty($path['extension'])) {
continue;
}
if ($path['extension'] == "PKGBUILD") {
$packageCount++;
$packageFilenames[$packageCount] = getShellString($f, "filename");
$packageVersions[$packageCount] = getShellString($f, "pkgver");
$packageUrls[$packageCount] = getShellString($f, "url");
$packageDepends[$packageCount] = getShellString($f, "depends");
$packageSizes[$packageCount] = getShellString($f, "size");
$packageGPG[$packageCount] = getShellString($f, "gpg");
$packageMD5[$packageCount] = getShellString($f, "md5");
$packageSHA256[$packageCount] = getShellString($f, "sha256");
$packageSources[$packageCount] = getShellString($f, "source");
$packageLicenses[$packageCount] = getShellString($f, "license");
}
}
for ($i = 1; $i < $packageCount+1; $i++) {
if ($query != $packageNames[$i]) {
continue;
}
$pkgName = $packageNames[$i];
$pkgDesc = $packageDescs[$i];
$pkgUrl = $packageUrls[$i];
$pkgVer = $packageVersions[$i];
$pkgSize = $packageSizes[$i];
$pkgDeps = $packageDepends[$i];
$pkgFilename = $packageFilenames[$i];
$pkgFile = $packageFiles[$i];
$pkgGPG = $packageGPG[$i];
$pkgMD5 = $packageMD5[$i];
$pkgSHA256 = $packageSHA256[$i];
$pkgSource = $packageSources[$i];
$pkgLicense = $packageLicenses[$i];
if ($pkgName == $packageNames[$i+1]) {
continue;
}
printHead($self, "speedie-aur", "Viewing package '$pkgName'", "$pkgName from the speedie-aur Arch Linux repository.");
print "\t\t<h1>$pkgName</h1>\n";
print "\t\t\t<table>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Description</th>\n";
print "\t\t\t\t\t\t<td>$pkgDesc</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Version</th>\n";
print "\t\t\t\t\t\t<td>$pkgVer</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>License</th>\n";
print "\t\t\t\t\t\t<td>$pkgLicense</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>URL</th>\n";
print "\t\t\t\t\t\t<td>$pkgUrl</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Dependencies</th>\n";
print "\t\t\t\t\t\t<td>$pkgDeps</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Size</th>\n";
print "\t\t\t\t\t\t<td>$pkgSize</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Installation</th>\n";
print "\t\t\t\t\t\t<td><code>pacman -S $pkgName</code></td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Filename</th>\n";
print "\t\t\t\t\t\t<td><a href=\"$pkgFilename\">$pkgFilename</a></td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>GPG</th>\n";
print "\t\t\t\t\t\t<td><a href=\"$pkgGPG\">$pkgGPG</a></td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>MD5</th>\n";
print "\t\t\t\t\t\t<td>$pkgMD5</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>SHA256</th>\n";
print "\t\t\t\t\t\t<td>$pkgSHA256</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th>Source</th>\n";
print "\t\t\t\t\t\t<td>$pkgSource</td>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t\t\t<tr>\n";
print "\t\t\t\t\t<th><a href=\"$pkgFile\">PKGBUILD</th>\n";
print "\t\t\t\t</tr>\n";
print "\t\t\t</table>\n";
break;
}
}
printFoot();
}
main();