2023-08-27 20:30:05 +02:00
< ? php
function getShellString ( $file , $string ) {
$contents = file_get_contents ( $file );
$output = array ();
// Rather lazy, but convenient
2023-08-27 21:45:32 +02:00
exec ( " ./viewer/output_data.sh $file $string " , $output );
2023-08-27 20:30:05 +02:00
if ( empty ( $output [ 0 ])) {
return NULL ;
}
return $output [ 0 ];
}
2023-08-28 12:25:41 +02:00
function printHead ( $self , $pTitle , $title , $desc ) {
2023-08-27 20:30:05 +02:00
print " <!DOCTYPE html> \n " ;
print " <head> \n " ;
2023-08-27 21:45:32 +02:00
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 " ;
2023-08-27 22:01:39 +02:00
print " \t \t \t <span class= \" title \" > $pTitle </span> \n " ;
2023-08-27 21:45:32 +02:00
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 " ;
2023-09-06 19:57:43 +02:00
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 " ;
2023-08-27 21:45:32 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
print " </head> \n " ;
print " <body> \n " ;
print " \t <div class= \" content \" > \n " ;
}
function printFoot () {
print " \t </div> \n " ;
print " </body> \n " ;
2023-08-27 22:01:39 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
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 );
2023-08-28 12:35:38 +02:00
if ( empty ( $path [ 'extension' ])) {
continue ;
}
2023-08-27 20:30:05 +02:00
if ( $path [ 'extension' ] == " PKGBUILD " ) {
$packageCount ++ ;
$packageFiles [ $packageCount ] = $f ;
$packageNames [ $packageCount ] = getShellString ( $f , " pkgname " );
$packageDescs [ $packageCount ] = getShellString ( $f , " pkgdesc " );
}
}
// Return results
2023-08-27 21:45:32 +02:00
if ( $request == " search " ) {
2023-08-27 20:30:05 +02:00
$validPkgs = 0 ;
$matches = array ();
$matchingDescs = array ();
$matchingUrls = array ();
for ( $i = 1 ; $i < $packageCount + 1 ; $i ++ ) {
if ( preg_match ( " / $query /i " , $packageNames [ $i ]) == 0 ) {
continue ;
2023-09-16 15:46:36 +02:00
} else if ( $matches [ $i + 1 ] == $matches [ $i ]) {
continue ;
2023-08-27 20:30:05 +02:00
}
$matches [ $validPkgs ] = $packageNames [ $i ];
$matchingDescs [ $validPkgs ] = $packageDescs [ $i ];
$matchingUrls [ $validPkgs ] = $packageUrls [ $i ];
$validPkgs ++ ;
}
2023-08-28 12:25:41 +02:00
printHead ( $self , " speedie-aur " , " Found $validPkgs packages matching ' $query ' in speedie-aur " , " Found $validPkgs packages matching search query ' $query ' in speedie-aur " );
2023-08-27 21:58:33 +02:00
2023-08-27 20:30:05 +02:00
print " \t \t \t <p class= \" matches \" > $validPkgs packages found matching ' $query '..</p> \n " ;
2023-08-28 12:44:50 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
for ( $i = 0 ; $i < $validPkgs ; $i ++ ) {
2023-08-28 12:44:50 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
}
2023-08-28 12:44:50 +02:00
print " \t \t \t </table> \n " ;
2023-08-27 21:45:32 +02:00
} else if ( $request == " all " ) {
2023-08-28 12:25:41 +02:00
printHead ( $self , " speedie-aur " , " All packages in speedie-aur " , " There are $packageCount packages in speedie-aur " );
2023-08-27 21:58:33 +02:00
2023-08-27 20:30:05 +02:00
print " \t \t \t <p>Total number of packages: $packageCount </p> \n " ;
2023-08-28 12:25:41 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
for ( $i = 1 ; $i < $packageCount + 1 ; ++ $i ) {
2023-09-16 15:44:19 +02:00
if ( $packageNames [ $i + 1 ] == $packageNames [ $i ]) {
continue ;
}
2023-08-28 12:25:41 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
}
2023-08-28 12:25:41 +02:00
print " \t \t \t </table> \n " ;
2023-08-27 21:45:32 +02:00
} else if ( $request == " view " && $query == '' ) {
2023-08-28 12:25:41 +02:00
printHead ( $self , " speedie-aur " , " speedie-aur " , " My unofficial Arch Linux repository containing many useful packages " );
2023-08-27 21:58:33 +02:00
2023-08-27 21:45:32 +02:00
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 " \t Server = 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 " ;
2023-09-06 19:57:43 +02:00
print " \t \t <h2>FAQ</h2> \n " ;
print " \t \t \t <ul class= \" faq \" > \n " ;
print " \t \t \t \t <li>What distros does this support? \n " ;
print " \t \t \t \t <li>speedie-aur has only been tested on upstream Arch Linux, but should work on almost if not all Arch based GNU/Linux distributions.</li></li> \n " ;
print " \t \t \t </ul> \n " ;
2023-08-27 20:30:05 +02:00
} else if ( $request == " view " && $query != '' ) {
$packageCount = 0 ;
$packageVersions = array ();
$packageUrls = array ();
$packageDepends = array ();
$packageFilenames = array ();
2023-08-27 21:45:32 +02:00
$packageLicenses = array ();
2023-08-27 20:30:05 +02:00
$packageSizes = array ();
$packageGPG = array ();
$packageMD5 = array ();
$packageSHA256 = array ();
$packageSource = array ();
foreach ( scandir ( " . " ) as $f ) {
$path = pathinfo ( $f );
2023-08-28 12:35:38 +02:00
if ( empty ( $path [ 'extension' ])) {
continue ;
}
2023-08-27 20:30:05 +02:00
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 " );
2023-08-27 21:45:32 +02:00
$packageLicenses [ $packageCount ] = getShellString ( $f , " license " );
2023-08-27 20:30:05 +02:00
}
}
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 ];
2023-08-27 21:45:32 +02:00
$pkgLicense = $packageLicenses [ $i ];
2023-08-27 20:30:05 +02:00
2023-09-16 15:35:01 +02:00
if ( $pkgName == $packageNames [ $i + 1 ]) {
continue ;
}
2023-08-28 12:25:41 +02:00
printHead ( $self , " speedie-aur " , " Viewing package ' $pkgName ' " , " $pkgName from the speedie-aur Arch Linux repository. " );
2023-08-27 21:58:33 +02:00
2023-08-27 20:30:05 +02:00
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 " ;
2023-08-27 21:45:32 +02:00
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 " ;
2023-08-27 20:30:05 +02:00
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 " ;
2023-08-28 12:35:38 +02:00
print " \t \t \t \t \t \t <td><a href= \" $pkgFilename\ " > $pkgFilename </ a ></ td > \n " ;
2023-08-27 20:30:05 +02:00
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 " ;
2023-08-28 12:35:38 +02:00
print " \t \t \t \t \t \t <td><a href= \" $pkgGPG\ " > $pkgGPG </ a ></ td > \n " ;
2023-08-27 20:30:05 +02:00
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 " ;
2023-09-16 15:35:01 +02:00
break ;
2023-08-27 20:30:05 +02:00
}
}
printFoot ();
}
main ();