Deploy nginx to new mirror server
This commit is contained in:
parent
31c208ca9b
commit
9bb273aed2
|
@ -3,6 +3,7 @@
|
|||
imports = [
|
||||
./hardware-configuration.nix
|
||||
./networking.nix
|
||||
./mirror/default.nix"
|
||||
];
|
||||
|
||||
variables.hostName = "new";
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
./xslt_template.nix
|
||||
];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts."mirror.lewd.wtf" = {
|
||||
serverName = "${config.variables.hostName}.${config.variables.domain}";
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
root = "/var/www/mirror/mirror/";
|
||||
locations = {
|
||||
"/" = {
|
||||
extraConfig = ''
|
||||
if ($arg_format = "json") {
|
||||
rewrite ^ /json$request_uri last;
|
||||
}
|
||||
autoindex on;
|
||||
autoindex_format xml;
|
||||
xslt_stylesheet /etc/nginx/mirror.xslt dirname='$1';
|
||||
'';
|
||||
};
|
||||
"/json/" = {
|
||||
alias = "/var/www/mirror/mirror/";
|
||||
extraConfig = ''
|
||||
autoindex on;
|
||||
autoindex_format json;
|
||||
'';
|
||||
};
|
||||
"/private/" = {
|
||||
alias = "/var/www/mirror/private/";
|
||||
extraConfig = ''
|
||||
autoindex off;
|
||||
'';
|
||||
};
|
||||
"~ \.xml$" = {
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
environment.etc = {
|
||||
"nginx/mirror.xslt" = {
|
||||
source = ./xslt_template.xslt;
|
||||
mode = "0444";
|
||||
};
|
||||
};
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:template name="string-replace-all">
|
||||
<xsl:param name="text" />
|
||||
<xsl:param name="replace" />
|
||||
<xsl:param name="by" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="$text = '' or $replace = ''or not($replace)" >
|
||||
<!-- Prevent this routine from hanging -->
|
||||
<xsl:value-of select="$text" />
|
||||
</xsl:when>
|
||||
<xsl:when test="contains($text, $replace)">
|
||||
<xsl:value-of select="substring-before($text,$replace)" />
|
||||
<xsl:value-of select="$by" />
|
||||
<xsl:call-template name="string-replace-all">
|
||||
<xsl:with-param name="text" select="substring-after($text,$replace)" />
|
||||
<xsl:with-param name="replace" select="$replace" />
|
||||
<xsl:with-param name="by" select="$by" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$text" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
<xsl:template match="/">
|
||||
<html>
|
||||
<head>
|
||||
<link href="/private/asset/icons.css" rel="stylesheet" />
|
||||
<link href="/private/asset/style.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h3>Lewd.wtf Mirror Service</h3>
|
||||
<p>Welcome to the mirror service of lewd.wtf! I provide this service free of charge to projects that could benefit from it.</p>
|
||||
<p>Want to get your files hosted here? Please contact me at <b>mirror_request@lewd.wtf</b> and provide details regarding your projects.</p>
|
||||
<h1>Proud Sineater and Sin's Cove Hater!</h1>
|
||||
<p>If you come here from Sin's Cove, please close this page. This site is hosted by Ecchibitionist, the person you constantly harass.</p>
|
||||
<p>You claim I bullied the original developer of EmuSAK, even though that's a blatant lie (and you know it).</p>
|
||||
</header>
|
||||
<main>
|
||||
<h4>
|
||||
<xsl:value-of select="$dirname"/>
|
||||
</h4>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Size</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href=".."><span class="material-icons back_folder_icon">drive_file_move_rtl</span>../</a></td>
|
||||
<td align="right"></td>
|
||||
</tr>
|
||||
<xsl:for-each select="list/*">
|
||||
<xsl:sort select="@name"/>
|
||||
<xsl:variable name="name">
|
||||
<xsl:call-template name="string-replace-all">
|
||||
<xsl:with-param name="text" select="." />
|
||||
<xsl:with-param name="replace" select="'%'" />
|
||||
<xsl:with-param name="by" select="'%25'" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="size">
|
||||
<xsl:if test="string-length(@size) > 0">
|
||||
<xsl:if test="number(@size) > 0">
|
||||
<xsl:choose>
|
||||
<xsl:when test="round(@size div 1024) < 1"><xsl:value-of select="@size" />B</xsl:when>
|
||||
<xsl:when test="round(@size div 1048576) < 1"><xsl:value-of select="format-number((@size div 1024), '0.0')" />KiB</xsl:when>
|
||||
<xsl:otherwise><xsl:value-of select="format-number((@size div 1048576), '0.00')" />MiB</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
</xsl:variable>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{$name}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length(@size)=0"><span class="material-icons folder">folder</span></xsl:when>
|
||||
<xsl:when test="'.zip' = substring($name, string-length($name) - 3)"><span class="material-icons folder_zip"> folder_zip </span></xsl:when>
|
||||
<xsl:when test="'.rar' = substring($name, string-length($name) - 3)"><span class="material-icons folder_zip"> folder_zip </span></xsl:when>
|
||||
<xsl:otherwise><span class="material-icons file"> insert_drive_file </span></xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:value-of select="."/>
|
||||
</a>
|
||||
</td>
|
||||
<td align="right"><xsl:value-of select="$size"/></td>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</main>
|
||||
<footer>
|
||||
<p>In case this mirror is hosting files that you believe shouldn't be here, please send a message to <a href="mailto:abuse@lewd.wtf">abuse@lewd.wtf</a> and we'll remove it as soon as possible.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
Loading…
Reference in New Issue