add web server support to mirror role

This commit is contained in:
Timo Makinen 2019-05-20 23:10:54 +03:00
parent 8ab0c58e21
commit 7c0c59a187
80 changed files with 517 additions and 0 deletions

View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:str="http://exslt.org/strings">
<xsl:strip-space elements="*" />
<xsl:template name="size">
<!-- transform a size in bytes into a human readable representation -->
<xsl:param name="bytes"/>
<xsl:choose>
<xsl:when test="$bytes &lt; 1000"><xsl:value-of select="$bytes" />B</xsl:when>
<xsl:when test="$bytes &lt; 1048576"><xsl:value-of select="format-number($bytes div 1024, '0.0')" />K</xsl:when>
<xsl:when test="$bytes &lt; 1073741824"><xsl:value-of select="format-number($bytes div 1048576, '0.0')" />M</xsl:when>
<xsl:otherwise><xsl:value-of select="format-number(($bytes div 1073741824), '0.00')" />G</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="timestamp">
<!-- transform an ISO 8601 timestamp into a human readable representation -->
<xsl:param name="iso-timestamp" />
<xsl:value-of select="concat(substring($iso-timestamp, 0, 11), ' ', substring($iso-timestamp, 12, 5))" />
</xsl:template>
<xsl:template match="directory">
<tr>
<td><a href="{str:encode-uri(current(),true())}/"><xsl:value-of select="."/></a>/</td>
<td><xsl:call-template name="timestamp"><xsl:with-param name="iso-timestamp" select="@mtime" /></xsl:call-template></td>
<td>-</td>
<td>Directory</td>
</tr>
</xsl:template>
<xsl:template match="file">
<tr>
<td><a href="{str:encode-uri(current(),true())}"><xsl:value-of select="." /></a></td>
<td><xsl:call-template name="timestamp"><xsl:with-param name="iso-timestamp" select="@mtime" /></xsl:call-template></td>
<td><xsl:call-template name="size"><xsl:with-param name="bytes" select="@size" /></xsl:call-template></td>
<td>File</td>
</tr>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<title>mirrors.foo.sh - <xsl:value-of select="$path" /></title>
<link rel="stylesheet" type="text/css" href="/static/mirror.css" />
<link rel="stylesheet" type="text/css" href="/static/icons.css" />
</head>
<body>
<div id="navbar">
<div id="logo">
<a href="https://www.foo.sh/"><img src="/static/logo.png" alt="foo.sh" /></a>
</div>
<div class="mirrorlist">
<button class="mirrorlist-button">Select mirror</button>
<div class="mirrorlist-content">
<a href="/fedora/">Fedora</a><span class="hide"> - </span>
<a href="/fedora-epel/">Fedora EPEL</a><span class="hide"> - </span>
<a href="/openbsd/">OpenBSD</a>
</div>
</div>
</div>
<div id="content">
<h1>Index of <xsl:value-of select="$path" /></h1>
<table>
<tr>
<th>Name</th>
<th>Last Modified</th>
<th>Size</th>
<th>Type</th>
</tr>
<tr>
<td colspan="4"><a href="../">Parent Directory</a></td>
</tr>
<xsl:apply-templates />
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

View file

@ -0,0 +1,307 @@
#content a[href]:before {
content: url(icons/none.png);
}
#content a[href$="/"]:before {
content: url(icons/folder.png);
}
/** Checksums **/
#content a[href~="MD5"]:before,
#content a[href~="SHA1"]:before,
#content a[href~="SHA256"]:before {
content: url(icons/lock.png);
}
#content a[href$=".md5"]:before,
#content a[href$=".sha1"]:before,
#content a[href$=".sha256"]:before {
content: url(icons/lock2.png);
}
#content a[href$=".pgp"]:before,
#content a[href$=".asc"]:before,
#content a[href$=".sig"]:before {
content: url(icons/lock3.png);
}
/** Compressed **/
#content a[href$=".7z"]:before {
content: url(icons/7z.png);
}
#content a[href$=".bin"]:before,
#content a[href$=".cue"]:before {
content: url(icons/bin.png);
}
#content a[href$=".deb"]:before {
content: url(icons/deb.png);
}
#content a[href$=".iso"]:before {
content: url(icons/iso.png);
}
#content a[href$=".rar"]:before {
content: url(icons/rar.png);
}
#content a[href$=".rpm"]:before {
content: url(icons/rpm.png);
}
#content a[href$=".tar"]:before,
#content a[href$=".tar.gz"]:before {
content: url(icons/tar.png);
}
#content a[href$=".tgz"]:before {
content: url(icons/tgz.png);
}
#content a[href$=".zip"]:before {
content: url(icons/zip.png);
}
#content a[href$=".bz2"]:before {
content: url(icons/bz2.png);
}
/** Data Storage **/
#content a[href$=".csv"]:before {
content: url(icons/csv.png);
}
#content a[href$=".ini"]:before {
content: url(icons/ini.png);
}
#content a[href$=".json"]:before {
content: url(icons/json.png);
}
#content a[href$=".sql"]:before {
content: url(icons/sql.png);
}
#content a[href$=".sqlite"]:before {
content: url(icons/sqlite.png);
}
#content a[href$=".reg"]:before {
content: url(icons/reg.png);
}
#content a[href$=".xml"]:before {
content: url(icons/xml.png);
}
#content a[href$=".yaml"]:before,
#content a[href$=".yml"]:before {
content: url(icons/yaml.png);
}
/** Documents **/
#content a[href$=".chm"]:before {
content: url(icons/chm.png);
}
#content a[href$=".djvu"]:before {
content: url(icons/djvu.png);
}
#content a[href$=".mobi"]:before {
content: url(icons/mobi.png);
}
#content a[href$=".pdf"]:before {
content: url(icons/pdf.png);
}
#content a[href$=".txt"]:before {
content: url(icons/text.png);
}
#content a[href$=".rtf"]:before {
content: url(icons/rtf.png);
}
#content a[href$=".doc"]:before {
content: url(icons/doc.png);
}
#content a[href$=".epub"]:before {
content: url(icons/epub.png);
}
/** Information **/
#content a[href~="README"]:before {
content: url(icons/readme.png);
}
#content a[href~="CHANGELOG"]:before {
content: url(icons/changelog.png);
}
#content a[href~="INSTALL"]:before {
content: url(icons/install.png);
}
#content a[href~="LICENSE"]:before {
content: url(icons/license.png);
}
#content a[href~="COPYING"]:before {
content: url(icons/copying.png);
}
#content a[href$=".nfo"]:before,
#content a[href$=".diz"]:before {
content: url(icons/nfo.png);
}
/** Media Files **/
#content a[href$=".flac"]:before {
content: url(icons/flac.png);
}
#content a[href$=".mp3"]:before {
content: url(icons/mp3.png);
}
#content a[href$=".wav"]:before {
content: url(icons/wav.png);
}
#content a[href$=".bmp"]:before {
content: url(icons/bmp.png);
}
#content a[href$=".gif"]:before {
content: url(icons/gif.png);
}
#content a[href$=".jpg"]:before,
#content a[href$=".jpeg"]:before {
content: url(icons/jpg.png);
}
#content a[href$=".png"]:before {
content: url(icons/png.png);
}
#content a[href$=".psd"]:before {
content: url(icons/psd.png);
}
#content a[href$=".ra"]:before,
#content a[href$=".rv"]:before {
content: url(icons/rp.png);
}
#content a[href$=".avi"]:before {
content: url(icons/avi.png);
}
#content a[href$=".flv"]:before {
content: url(icons/flv.png);
}
#content a[href$=".mkv"]:before {
content: url(icons/mkv.png);
}
#content a[href$=".mov"]:before {
content: url(icons/mov.png);
}
#content a[href$=".mp4"]:before {
content: url(icons/mp4.png);
}
/** Source Code **/
#content a[href$=".sh"]:before {
content: url(icons/bash.png);
}
#content a[href$=".cpp"]:before {
content: url(icons/cpp.png);
}
#content a[href$=".h"]:before {
content: url(icons/header.png);
}
#content a[href$=".c"]:before {
content: url(icons/c-lang.png);
}
#content a[href$=".go"]:before {
content: url(icons/go-lang.png);
}
#content a[href$=".html"]:before,
#content a[href$=".htm"]:before {
content: url(icons/html.png);
}
#content a[href$=".java"]:before,
#content a[href$=".class"]:before {
content: url(icons/java.png);
}
#content a[href$=".lua"]:before {
content: url(icons/lua.png);
}
#content a[href$=".nim"]:before {
content: url(icons/nim.png);
}
#content a[href$=".js"]:before {
content: url(icons/javascript.png);
}
#content a[href$=".php"]:before {
content: url(icons/php.png);
}
#content a[href$=".pl"]:before {
content: url(icons/perl.png);
}
#content a[href$=".py"]:before {
content: url(icons/python.png);
}
#content a[href$=".rb"]:before {
content: url(icons/ruby.png);
}
#content a[href$=".rs"]:before,
#content a[href$=".rlib"]:before {
content: url(icons/rust.png);
}
#content a[href$=".css"]:before {
content: url(icons/css.png);
}
#content a[href$=".less"]:before {
content: url(icons/less.png);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 807 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 883 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 690 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 991 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 883 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 853 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

@ -0,0 +1,84 @@
body {
margin: 0;
font-family: Arial,sans-serif;
color: #172B4D;
position: absolute;
left: 0px;
right: 0px;
background: #f2f2f2;
}
#navbar {
padding-top: 15px;
background-color: #000;
}
.mirrorlist-button {
background-color: #000;
color: #fff;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.mirrorlist {
position: absolute;
top: 10px;
right: 100px;
display: inline-block;
float: right;
}
.mirrorlist-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.mirrorlist-content a {
display: block;
padding: 10px 10px;
}
.mirrorlist:hover .mirrorlist-content {
display: block;
}
.hide {
display: none;
}
// directory listings
#content {
margin: 50px;
}
h1 {
font-size: 20px;
padding: 0px 50px;
}
table {
padding: 0px 50px;
}
a {
text-decoration: none;
color: #172b4d;
}
a:hover {
text-decoration: underline;
}
td, th {
padding: 5px 60px;
padding-left: 0;
text-align: left;
}
hr {
border: 1px solid #172b4d;
}

View file

@ -0,0 +1,4 @@
---
dependencies:
- {role: nginx/server}

View file

@ -85,3 +85,28 @@
minute: 10
job: "find /var/log/sync-mirrors/ -xdev -type f -mtime +30 -name '*.log' -execdir rm {} \\+"
user: mirror
- name: copy static web content
synchronize:
dest: "/srv/web/{{ inventory_hostname }}/"
delete: yes
recursive: yes
src: static
- name: install nginx xslt config
copy:
dest: /etc/nginx/mirror.xslt
src: mirror.xslt
mode: 0644
owner: root
group: root
notify: restart nginx
- name: create nginx mirror config
template:
dest: "/etc/nginx/conf.d/{{ inventory_hostname }}/mirror.conf"
src: mirror.conf.j2
mode: 0644
owner: root
group: root
notify: restart nginx

View file

@ -0,0 +1,6 @@
location / {
autoindex on;
autoindex_format xml;
xslt_stylesheet /etc/nginx/mirror.xslt path="$uri";
}

View file

@ -15,3 +15,11 @@
mode: 0755
owner: mirror
group: mirror
- name: link target directory to web
file:
path: "/srv/web/{{ inventory_hostname }}/{{ label }}"
src: "/srv/mirrors/{{ label }}"
state: link
owner: mirror
group: mirror