portdb: updated to latest live versions after crux.nu server rebuild

* cacher: minor updates for python 3
* index: major updates for PHP 8.x and OOP restructure(ish)
This commit is contained in:
Matt Housh 2024-03-02 14:24:02 -06:00
parent 8798926ff2
commit ce1382a482
Signed by: jaeger
GPG Key ID: F9DE89ED1BFADFD7
9 changed files with 523 additions and 592 deletions

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sqlite3
import subprocess
import sys
import urllib2
import urllib.request
# global config
@ -195,6 +194,7 @@ collections = [
#"z3bra|willy@mailoo.org|httpup|http://dl.z3bra.org/crux/v"+prevver+"/|" #Willy Goiffon - disabled due to many failures
]
## database file on disk
dbfile = '/home/crux/portdb/portdb.db.new'
@ -211,17 +211,19 @@ def getCollection(parts):
if colltype == 'httpup': # for httpup collections we can fetch and parse the REPO file
try:
resp = urllib2.urlopen(url + "REPO")
content = resp.read().strip().split('\n')
repo_url = url + "REPO"
resp = urllib.request.urlopen(repo_url, timeout=30)
content = resp.readlines()
for line in content:
line = line.decode().strip()
if line.find("d:") == 0:
ports.append(line.split(':')[1])
except urllib2.URLError as e:
except Exception as e:
print("Error fetching URL %s: %s" % (url, e))
elif colltype == 'rsync': # for rsync collections we call rsync and process its output
command = "/usr/bin/rsync --timeout 60 --list-only " + url
try:
content = subprocess.check_output(command.split()).strip().split('\n')
content = subprocess.check_output(command.split(), text=True).strip().split('\n')
for line in content:
if line.find("d") == 0:
port = line.split()[4]
@ -272,7 +274,7 @@ cur.execute('''CREATE TABLE IF NOT EXISTS ports (
try:
cur.execute('DELETE FROM ports')
cur.execute('DELETE FROM collections')
cur.execute('VACUUM')
#cur.execute('VACUUM')
except sqlite3.OperationalError as e:
print("Error deleting records from database %s: %s" % (dbfile, e))
sys.exit(1)

View File

@ -1,5 +1,5 @@
</div>
<div class="footer">
<b>DISCLAIMER</b>: the ports not belonging to the core, opt and xorg collections are provided by contributors; there is no guarantee or support by the CRUX team.
<b>DISCLAIMER</b>: the ports not belonging to the core, opt, xorg, and compat-32 collections are provided by contributors; there is no guarantee or support by the CRUX team.
</div>
</body></html>

View File

@ -0,0 +1,28 @@
<?php
class DBHandle {
public $dbfile;
public $dbhandle;
public $sql;
public function __construct($dbfile) {
$this->dbfile = $dbfile;
$this->dbhandle = new SQLite3($this->dbfile);
}
public function doQuery($sql) {
$this->sql = $sql;
$this->dbhandle->exec($this->sql);
$result = $this->dbhandle->query($this->sql);
$rows = array();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
array_push($rows, $row);
}
return $rows;
}
}
?>

View File

@ -0,0 +1,25 @@
<?php
class Duplicate {
public $name;
public $count;
private $out;
public function __construct($dup) {
$this->name = $dup['name'];
$this->count = $dup['count'];
}
public function rowToHTML() {
$this->out = <<<EOD
<tr>
<td>$this->name</td>
<td>Found <a href="?a=search&q={$this->name}&s=true">$this->count in repository</a></td>
</tr>\n
EOD;
return $this->out;
}
}
?>

View File

@ -0,0 +1,61 @@
<?php
class Port {
public $name;
public $repo;
public $type;
public $url;
private $out;
public function __construct($port) {
$this->name = $port['name'];
$this->repo = $port['repo'];
$this->type = $port['type'];
$this->url = $port['url'];
}
public function downloadCmd() {
switch ($this->type) {
case "rsync":
return "rsync -aqz {$this->url}{$this->name}/ {$this->name}";
case "httpup":
return "httpup sync {$this->url}#{$this->name} {$this->name}";
default:
return "Unknown repo type";
}
}
public function filesToHTML() {
$html = "";
if ($this->type == "httpup") {
$base_url = "{$this->url}";
} else {
$base_url = localrepo($this->repo);
}
if ($base_url != "") {
$base_url = chop($base_url, "/");
$html = "<a href=\"{$base_url}/{$this->name}/Pkgfile\">P</a> ";
$html .= "<a href=\"{$base_url}/{$this->name}/.footprint\">F</a> ";
$html .= "<a href=\"{$base_url}/{$this->name}/.signature\">S</a>";
}
return $html;
}
public function rowToHTML() {
$downloadcmd = $this->downloadCmd();
$files = $this->filesToHTML();
$this->out = <<<EOD
<tr>
<td>$this->name</td>
<td><a href="?a=repo&q={$this->repo}">$this->repo</a></td>
<td>$files</td>
<td>$downloadcmd</td>
</tr>\n
EOD;
return $this->out;
}
}
?>

View File

@ -0,0 +1,91 @@
<?php
class Repo {
public $name;
public $numports;
public $type;
public $maintainer;
public $url;
public $pubkey;
private $out;
public function __construct($repo) {
$this->name = $repo['name'];
$this->numports = $repo['numports'];
$this->type = $repo['type'];
$this->maintainer = $repo['maintainer'];
$this->url = $repo['url'];
$this->pubkey = $repo['pubkey'];
}
#public function toString() {
# return "[name=$this->name, numports=$this->numports, type=$this->type, maintainer=$this->maintainer, url=$this->url, pubkey=$this->pubkey]\n";
#}
private function linkURL() {
$url = $this->url;
if ($this->type == 'httpup') {
$url = "<a href=\"{$this->url}\">$this->url</a>";
}
return $url;
}
private function linkPubKey() {
$pubkey = $this->pubkey;
if ($pubkey != '') {
$pubkey = "<a class=\"urllink\" href=\"https://crux.nu/keys/{$this->name}.pub\">$this->pubkey</a>";
}
return $pubkey;
}
private function obfuscate($email) {
$email = preg_replace('/@/', ' at ', $email);
$email = preg_replace('/\./', ' dot ', $email);
return $email;
}
public function rowToHTML() {
$maintainer = $this->obfuscate($this->maintainer);
$url = $this->linkURL();
$pubkey = $this->linkPubKey();
$this->out = <<<EOD
<tr>
<td><a href="?a=repo&q={$this->name}">$this->name</a></td>
<td>$this->numports</td>
<td><a href="?a=getup&q={$this->name}">$this->type</a></td>
<td>$maintainer</td>
<td>$url</td>
<td>$pubkey</td>
</tr>\n
EOD;
return $this->out;
}
public function getSyncFile() {
$maintainer = $this->obfuscate($this->maintainer);
$content = '';
if ($this->type == "httpup") {
$content .= "ROOT_DIR=/usr/ports/" . $this->name . "\n";
$content .= "URL=" . $this->url . "\n";
} else {
$url = explode('::', $this->url);
$content .= "host=" . $url[0] . "\n";
$content .= "collection=" . $url[1] . "\n";
$content .= "destination=/usr/ports/" . $this->name . "\n";
}
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="' . $this->name . '.' . $this->type . '"');
$this->out = <<<EOD
# Collection $this->name, by $maintainer
# File generated by the CRUX portdb https://crux.nu/portdb/
$content
EOD;
return $this->out;
}
}
?>

848
portdb/portdb/index.php Executable file → Normal file
View File

@ -1,596 +1,320 @@
<?php
// some linting fixed - tb 20230909
// replaced md5sum references with signature - jaeger 20200528
// replace http with https for urls - frinnst 20170709
// $dbhandle = "sqlite://///var/www/htdocs/local/portdb.db";
// $dbhandle = "/var/www/htdocs/local/portdb.db";
$dbhandle = "/home/crux/portdb/portdb.db";
function sqlite_open($location)
{
$handle = new SQLite3($location);
return $handle;
}
function sqlite_query($dbhandle,$query)
{
$array['dbhandle'] = $dbhandle;
$array['query'] = $query;
$result = $dbhandle->query($query);
return $result;
}
function sqlite_fetch_array(&$result)
{
// Get Columns
$i = 0;
while ($result->columnName($i))
{
$columns[ ] = $result->columnName($i);
$i++;
}
require_once('includes/dbhandle.inc.php');
require_once('includes/duplicate.inc.php');
require_once('includes/port.inc.php');
require_once('includes/repo.inc.php');
$resx = $result->fetchArray(SQLITE3_ASSOC);
return $resx;
}
$cruxver = '3.7';
$dbfile = '/home/crux/portdb/portdb.db';
function nospam($mail)
{
$mail = preg_replace("/\@/", " at ", $mail);
$mail = preg_replace("/\./", " dot ", $mail);
return htmlspecialchars($mail);
}
function sanitize($str)
{
function sanitize($str) {
return preg_replace("/[^[:alnum:][:space:]_+-\.]/ui", '', $str);
//return $str;
}
}
function localrepo($name)
{
if (is_dir("/home/crux/git-to-rsync-working-copy/crux-3.7/{$name}")) {
return "https://crux.nu/ports/crux-3.7/{$name}/";
function printHeader() {
print file_get_contents('header.html');
}
function printFooter() {
print file_get_contents('footer.html');
}
function localrepo($name) {
global $cruxver;
#if (is_dir("/home/crux/git-to-rsync-working-copy/crux-{$cruxver}/{$name}")) { # old server path
#if (is_dir("/var/www/html/ports/crux-{$cruxver}/{$name}")) { # dev container path
if (is_dir("/home/gitea/srv/ports/crux-{$cruxver}/{$name}")) { # new server path (gitea)
return "https://crux.nu/ports/crux-{$cruxver}/{$name}/";
}
else {
return "";
return "";
}
}
}
class Repo
{
public $name;
public $maintainer;
public $type;
public $url;
public $count;
public $pubkey;
function __construct($row)
{
$this->name = trim($row["collname"]);
$this->maintainer = trim($row["maintainer"]);
$this->type = trim($row["colltype"]);
$this->url = trim($row["url"]);
$this->count = trim($row["tot"]);
$this->pubkey = trim($row["pubkey"]);
}
# main
if (isset($_GET['a'])) { $action = sanitize($_GET['a']); } else $action = null;
if (isset($_GET['q'])) { $query = sanitize($_GET['q']); } else $query = null;
if (isset($_GET['f'])) { $format = sanitize($_GET['f']); } else $format = null;
if (isset($_GET['s'])) { $strict = sanitize($_GET['s']); } else $strict = null;
function toHTML()
{
if (strlen($this->pubkey) > 0) {
return "<td><a href=\"?a=repo&q={$this->name}\">{$this->name}</a></td>
<td>{$this->count}</td>
<td><a href=\"?a=getup&q={$this->name}\">{$this->type}</a></td>
<td>{$this->nospam()}</td>
<td>{$this->urlToHTML()}</td>
<td><a class='urllink' href='https://crux.nu/keys/{$this->name}.pub'>{$this->pubkey}</a></td>";
}
else {
return "<td><a href=\"?a=repo&q={$this->name}\">{$this->name}</a></td>
<td>{$this->count}</td>
<td><a href=\"?a=getup&q={$this->name}\">{$this->type}</a></td>
<td>{$this->nospam()}</td>
<td>{$this->urlToHTML()}</td>
<td></td>";
}
}
switch ($action) {
case "repo":
# individual repo index
$db = new DBHandle($dbfile);
$sql = 'SELECT ports.portname AS name,
collections.collname AS repo,
collections.maintainer AS maintainer,
collections.colltype AS colltype,
collections.url AS url
FROM ports JOIN collections ON collection=repo
WHERE collection = "' . $query . '"
ORDER BY portname';
$rows = $db->doQuery($sql);
function toXML()
{
return "<repo>
<name>{$this->name}</name>
<maintainer>{$this->nospam()}</maintainer>
<type>{$this->type}</type>
<url>{$this->url}</url>
<ports>{$this->count}</ports>
<publickey>{$this->pubkey}</publickey>
</repo>";
}
$ports = array();
foreach($rows as $row) {
$port = new Port(array("name" => $row['name'],
"repo" => $row['repo'],
"type" => $row['colltype'],
"url" => $row['url']));
array_push($ports, $port);
}
function urlToHTML()
{
if ($this->type == "httpup") {
return "<a href=\"{$this->url}\">{$this->url}</a>";
}
else {
return $this->url;
}
}
# header
printHeader();
function nospam()
{
return nospam($this->maintainer);
}
}
# construct content/table
$out = <<<EOD
<h2>Ports in repository $port->repo <a href="?a=getup&q={$port->repo}">(get sync file)</a></h2>
<table class="listing">
<thead>
<tr>
<th>Port</th>
<th>Collection</th>
<th>Files</th>
<th>Download command</th>
</tr>
</thead>
<tbody>\n
EOD;
class Port
{
public $name;
public $repo;
# add ports
foreach ($ports as $port) {
$out .= $port->rowToHTML();
}
function __construct($row)
{
$this->name = trim($row["portname"]);
$this->repo = new Repo($row);
}
# end table
$out .= <<<EOD
</tbody>
</table>
EOD;
function toXML()
{
return "<port>
<name>{$this->name}</name>
<repo>{$this->repo->name}</repo>
{$this->filesToXML()}
<command>{$this->downloadCommand()}</command>
</port>";
print $out;
}
# footer
printFooter();
break;
function toHTML()
{
return "<td>{$this->name}</td>
<td><a href=\"?a=repo&q={$this->repo->name}\">{$this->repo->name}</a></td>
<td>{$this->filesToHTML()}</td>
<td>{$this->downloadCommand()}</td>";
}
function filesToXML()
{
$xml = "";
if ($this->repo->type == "httpup") {
$base_url = "{$this->repo->url}";
}
else {
$base_url = localrepo($this->repo->name);
}
if ($base_url != "") {
$base_url = chop($base_url, "/");
$xml = "<files>";
$xml .= "<pkgfile>{$base_url}/{$this->name}/Pkgfile</pkgfile>";
$xml .= "<footprint>{$base_url}/{$this->name}/.footprint</footprint>";
$xml .= "<signature>{$base_url}/{$this->name}/.signature</signature>";
$xml .= "</files>";
}
return $xml;
}
function filesToHTML()
{
$html = "";
if ($this->repo->type == "httpup") {
$base_url = "{$this->repo->url}";
}
else {
$base_url = localrepo($this->repo->name);
}
if ($base_url != "") {
$base_url = chop($base_url, "/");
$html = "<a href=\"{$base_url}/{$this->name}/Pkgfile\">P</a> ";
$html .= "<a href=\"{$base_url}/{$this->name}/.footprint\">F</a> ";
$html .= "<a href=\"{$base_url}/{$this->name}/.signature\">S</a>";
}
return $html;
}
function downloadCommand()
{
switch ($this->repo->type) {
case "httpup":
return "httpup sync {$this->repo->url}#{$this->name} {$this->name}";
case "rsync":
return "rsync -aqz {$this->repo->url}{$this->name}/ {$this->name}";
default:
return "unknown repo type";
}
}
}
class Duplicate
{
public $name;
public $count;
function __construct($row)
{
$this->name = $row["portname"];
$this->count = $row["dup"];
}
function toHTML()
{
return "<td>{$this->name}</td>
<td>Found <a href=\"?a=search&q={$this->name}&s=true\">{$this->count} in repository</a></td>";
}
function toXML()
{
return "<duplicate>
<name>{$this->name}</name>
<count>{$this->count}</count>
</duplicate>";
}
}
class PortDb
{
public $db;
public $last_result;
public $dbhandle;
function __construct($dbhandle)
{
/*
$this->db =& MDB2::connect($dbhandle);
if (MDB2::isError($this->db)) die ("Can not connect to database " . $dbhandle . "<br />\n" . $this->db->getMessage());
$this->db->setFetchMode(DB_FETCHMODE_ASSOC);
*/
$this->db = new SQLite3($dbhandle);
$this->dbhandle = $dbhandle;
}
function lazy_programmer()
{
die("LAZY PROGRAMMER ERROR");
}
function getQuery()
{
try {
$stm = $this->db->prepare($this->sql);
$args = func_get_args();
$count = 0;
foreach ($args as $value) {
$stm->bindValue($count + 1, $args[$count]);
$count = $count + 1;
}
$res = $stm->execute();
// if (MDB2::isError($res)) die ($res->getUserInfo());
$this->last_result = array();
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
array_push($this->last_result, $row);
}
return $this->last_result;
}
catch (Exception $exception) {
die($exception->getMessage());
}
}
function doQuery()
{
$this->lazy_programmer();
}
function htmlHeader()
{
return file_get_contents("header.html");
}
function htmlFooter()
{
return file_get_contents("footer.html");
}
function toHTML($start, $headers, $items, $ports = -1)
{
$html = $this->htmlHeader();
$html .= $start;
$html .= "<table class=\"listing\">";
$html .= "<thead><tr>";
foreach ($headers as $header) {
$html .= "<th>{$header}</th>";
}
$html .= "</tr></thead>";
foreach ($items as $item) {
$html .= "<tr>" . $item->toHTML() . "</tr>";
}
if ($ports != -1) {
$html .= '<tr><td></td><td>' . $ports . ' (unique)</td><td></td<td></td<td></td><td></td>';
}
$html .= "</table>";
$html .= $this->htmlFooter();
return $html;
}
function toXML($root, $items)
{
header("Content-type: text/xml");
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$xml .= "<{$root}>";
foreach ($items as $item) {
$xml .= $item->toXML();
}
$xml .= "</{$root}>";
return $xml;
}
}
class RepoList extends PortDb
{
public $sql = 'select collname,maintainer,colltype,url,count(*) as tot,pubkey from collections
join ports on collection=collname
group by collname order by collections.collid';
function doQuery()
{
$rows = $this->getQuery();
$repos = array();
foreach($rows as $row) {
$repo = new Repo($row);
array_push($repos, $repo);
}
return $repos;
}
function toXML($repos)
{
return parent::toXML("repos", $repos);
}
function toHTML($repos)
{
$unique = new UniquePorts($this->dbhandle);
$ports = $unique->getQuery();
$ports = $ports[0]['count(portname)'];
$start = "<h2>Overview of available repositories</h2>";
$headers = array("Repo Name", "# ports", "Type", "Maintainer", "Repo URL", "Public Key");
return parent::toHtml($start, $headers, $repos, $ports);
}
}
class PortList extends PortDb
{
public $sql = "select ports.portname as portname,
collections.collname as collname,
collections.maintainer as maintainer,
collections.colltype as colltype,
collections.url as url
from ports join collections on collection=collname
where collection = ? order by portname";
function doQuery($repo)
{
$rows = $this->getQuery($repo);
$ports = array();
foreach ($rows as $row) {
$port = new Port($row);
array_push($ports, $port);
}
return $ports;
}
function toXML($ports)
{
return parent::toXML("ports", $ports);
}
function toHTML($ports)
{
$repo = $ports[0]->repo->name;
$start = "<h2>Ports in repository $repo <a href=\"?a=getup&q={$repo}\">(get sync file)</a></h2>";
$headers = array("Port","Collection","Files","Download command");
return parent::toHTML($start, $headers, $ports);
}
}
class SearchList extends PortList
{
public $strict = false;
public $query = '';
public $sql;
function __construct($dbhandle, $strict)
{
parent::__construct($dbhandle);
if ($strict == "true") { $this->strict = true;
}
$sql = "select ports.portname as portname,
collections.collname as collname,
collections.maintainer as maintainer,
collections.colltype as colltype,
collections.url as url
from ports join collections on collection=collname ";
if ($this->strict) {
$this->sql = $sql . "where portname=? ";
}
else {
$this->sql = $sql . "where portname like ? ";
}
$this->sql .= "order by portname, collection";
}
function htmlHeader()
{
$html = parent::htmlHeader();
$html .= '<h2>Simple port search</h2>
<p>Search for ports by name</p>
<form name="searchform" method="get" action="'.getenv("SCRIPT_NAME").'">
<input name="q" value="'.$this->query.'" />
<input type="hidden" name="a" value="search" />
<input value="search" type="submit" />
</form>';
return $html;
}
function doQuery($query)
{
$this->query = $query;
if ($query) {
if (! $this->strict) { $query = "%{$query}%";
}
return parent::doQuery($query);
}
return array();
}
function toHTML($ports)
{
if ($this->query) {
$start = ""; // <h2>Search results for '{$this->query}'</h2>";
$headers = array("Port","Collection","Files","Download command");
return PortDB::toHTML($start, $headers, $ports);
}
return $this->htmlHeader() . $this->htmlFooter();
}
}
class DuplicateList extends PortDb
{
public $sql = "select portname, count(*) as dup
from ports group by portname
having dup>1
order by dup desc";
function doQuery()
{
$rows = $this->getQuery();
$dups = array();
foreach ($rows as $row) {
$dup = new Duplicate($row);
array_push($dups, $dup);
}
return $dups;
}
function toHTML($duplicates)
{
$start = "<h2>List of duplicate ports</h2>";
$headers = array("Port", "# of duplicates");
return parent::toHTML($start, $headers, $duplicates);
}
function toXML($duplicates)
{
return parent::toXML("duplicates", $duplicates);
}
}
class RegisterPage
{
function toHTML()
{
return PortDB::htmlHeader() . $this->contents() . PortDB::htmlFooter();
}
function contents()
{
return file_get_contents("register.html");
}
}
class GetUp extends PortDb
{
public $sql = "select collname,maintainer,colltype,url
from collections where collname=?";
public $repo;
function doQuery($repo)
{
$rows = $this->getQuery($repo);
if (count($rows) != 1) { die("Could not generate file");
}
return new Repo($rows[0]);
}
function toHTML($repo)
{
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$repo->name.".".$repo->type.'"');
$html = "# Collection ".$repo->name. ", by ".$repo->nospam()."\n";
$html .= "# File generated by the CRUX portdb https://crux.nu/portdb/"."\n\n";
if ($repo->type == "httpup") {
$html .= "ROOT_DIR=/usr/ports/" . $repo->name."\n";
$html .= "URL=" . $repo->url."\n";
case "search":
# port search
if ($query != '') {
$db = new DBHandle($dbfile);
$sql = 'SELECT ports.portname AS name,
collections.collname AS repo,
collections.maintainer AS maintainer,
collections.colltype AS type,
collections.url AS url
FROM ports JOIN collections ON collection = collname';
if ($strict) {
$sql .= ' WHERE portname = ';
$sql .= '"' . $query . '"';
} else {
$ar = explode('::', $repo->url);
$html .= "host=" . $ar[0]."\n";
$html .= "collection=" . $ar[1]."\n";
$html .= "destination=/usr/ports/" . $repo->name."\n";
$sql .= ' WHERE portname LIKE ';
$sql .= '"%' . $query . '%"';
}
return $html;
}
$sql .= ' ORDER BY portname, collection';
$rows = $db->doQuery($sql);
function toXML($repo)
{
return $this->toHTML($repo);
}
}
$ports = array();
foreach($rows as $row) {
$port = new Port($row);
array_push($ports, $port);
}
}
class UniquePorts extends PortDb
{
public $sql = 'select count(portname) from (select distinct portname from ports)';
# header
printHeader();
function toXML($ports)
{
return parent::toXML("NumberUniquePorts", array($ports));
}
# construct content
$script_name = getenv("SCRIPT_NAME");
$out = <<<EOD
<h2>Simple port search</h2>
<p>Search for ports by name</p>
<form name="searchform" method="get" action="$script_name">
<input name="q" value="$query" />
<input type="hidden" name="a" value="search" />
<input value="search" type="submit" />
</form>
EOD;
function toHTML($ports)
{
return '<table><tr><td></td><td>' . $ports . ' (unique)</td><td></td<td></td<td></td>>><td></td></table>';
}
}
# create table if a search was performed
if ($query != '') {
# construct table
$out .= <<<EOD
<table class="listing">
<thead>
<tr>
<th>Port</th>
<th>Collection</th>
<th>Files</th>
<th>Download command</th>
</tr>
</thead>
<tbody>\n
EOD;
# add ports
foreach ($ports as $port) {
$out .= $port->rowToHTML();
}
$action = sanitize($_GET['a']);
$query = sanitize($_GET['q']);
$format = sanitize($_GET['f']);
$strict = sanitize($_GET['s']);
# end table
$out .= <<<EOD
</tbody>
</table>
EOD;
}
switch ($action) {
case "repo":
$portdb = new PortList($dbhandle);
break;
case "search":
$portdb = new SearchList($dbhandle, $strict);
break;
case "dups":
$portdb = new DuplicateList($dbhandle);
break;
case "getup":
$portdb = new GetUp($dbhandle);
break;
case "register":
$portdb = new RegisterPage();
echo $portdb->toHTML();
exit;
default:
$portdb = new RepoList($dbhandle);
}
print $out;
$result = $portdb->doQuery($query);
# footer
printFooter();
break;
switch ($format) {
case "xml":
echo $portdb->toXML($result);
break;
default:
echo $portdb->toHTML($result);
}
case "dups":
# duplicates list
$db = new DBHandle($dbfile);
$sql = 'SELECT portname AS name, count(*) AS count
FROM ports GROUP BY portname
HAVING count > 1
ORDER BY count DESC, name';
$rows = $db->doQuery($sql);
$dups = array();
foreach ($rows as $row) {
$dup = new Duplicate($row);
array_push($dups, $dup);
}
# header
printHeader();
# construct content/table
$out = <<<EOD
<h2>List of duplicate ports</h2>
<table class="listing">
<thead>
<tr>
<th>Port</th>
<th># of duplicates</th>
</tr>
</thead>
<tbody>\n
EOD;
# add duplicates
foreach ($dups as $dup) {
$out .= $dup->rowToHTML();
}
# end table
$out .= <<<EOD
</tbody>
</table>
EOD;
print $out;
# footer
printFooter();
break;
case "getup":
# sync file
$db = new DBHandle($dbfile);
$sql = 'SELECT collname AS name, colltype AS type, maintainer, url, pubkey, count(ports.id) as numports
FROM collections
JOIN ports ON collection=name
WHERE name = "' . $query . '"
GROUP BY name ORDER BY collections.collid';
$rows = $db->doQuery($sql);
$repo = new Repo($rows[0]);
print $repo->getSyncFile();
break;
case "register":
# register page
# header
printHeader();
$out = file_get_contents('register.html');
print $out;
# footer
printFooter();
break;
default:
# main index
$db = new DBHandle($dbfile);
$sql = 'SELECT collname AS name, colltype AS type, maintainer, url, pubkey, count(ports.id) as numports
FROM collections
JOIN ports ON collection=name
GROUP BY name ORDER BY collections.collid';
$rows = $db->doQuery($sql);
$repos = array();
foreach ($rows as $row) {
$repo = new Repo($row);
array_push($repos, $repo);
}
# get unique port count
$sql = 'SELECT count(portname) AS uniquecount FROM (SELECT DISTINCT portname FROM ports)';
$rows = $db->doQuery($sql);
$uniquecount = $rows[0]['uniquecount'];
# header
printHeader();
# construct content/table
$out = <<<EOD
<h2>Overview of available repositories</h2>
<table class="listing">
<thead>
<tr>
<th>Repo Name</th>
<th># ports</th>
<th>Type</th>
<th>Maintainer</th>
<th>Repo URL</th>
<th>Public Key</th>
</tr>
</thead>
<tbody>\n
EOD;
# add repos
foreach ($repos as $repo) {
$out .= $repo->rowToHTML();
}
# add unique count
$out .= <<<EOD
<tr>
<td></td>
<td>$uniquecount (unique)</td>
<td colspan=4></td>
</tr>\n
EOD;
# end table
$out .= <<<EOD
</tbody>
</table>
EOD;
print $out;
# footer
printFooter();
}
?>

View File

@ -1,14 +1,14 @@
/* CRUX custom */
.cruxheader {
text-align: center;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size:12px;
background-color: #FFF;
background-image: url("cruxlogo.png");
background-repeat: no-repeat;
background-position: top;
padding: 70px 0px 10px 10px;
border: 1px solid #DDDDDD;
text-align: center;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size:12px;
background-color: #FFF;
background-image: url("cruxlogo.png");
background-repeat: no-repeat;
background-position: top;
padding: 70px 0px 10px 10px;
border: 1px solid #DDDDDD;
}
.content {
@ -28,15 +28,15 @@
}
div.search {
font-size: 12px;
font-weight: normal;
margin-top: 4px;
margin-right: 8px;
margin-bottom: 4px;
margin-left: 8px;
position: absolute;
top: 36px;
right: 30px;
font-size: 12px;
font-weight: normal;
margin-top: 4px;
margin-right: 8px;
margin-bottom: 4px;
margin-left: 8px;
position: absolute;
top: 36px;
right: 30px;
}
body {
@ -76,8 +76,8 @@ h2 {
}
input {
border: 1px #cccccc solid;
padding: 3px;
border: 1px #cccccc solid;
padding: 3px;
}
input[type=submit], input[type=reset] {
background: #eee;

View File

@ -6,4 +6,4 @@
<li>Your name</li>
<li>Your Email</li>
</ul>
<p>A CRUX team member will put your repository into our database. Please give us some time to do this. Once it is active it is synced once a day. <b>Please do not submit .httpup files, only the URL for the repository. This means the URL to the repository itself, not portspage or other indexes.</b></p>
<p>A CRUX team member will put your repository into our database. Please give us some time to do this. Once it is active it is synced every 6 hours. <b>Please do not submit .httpup files, only the URL for the repository. This means the URL to the repository itself, not portspage or other indexes.</b></p>