<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <head>
        <link rel="stylesheet" type="text/css" 
              href="https://cdn.privex.io/lib/semanticui/2.4.2/semantic.min.css"
              integrity="sha384-JKIDqM48bt14NZpzl9v0AP36VK2C/X6RuSPfimxpoWdSANUXblZUX1cgdQw8cZUK" 
              crossorigin="anonymous" />
        <link rel="stylesheet" type="text/css" 
              href="https://cdn.privex.io/extras/nginx/cdn.css" />

        <meta http-equiv="onion-location" content="{$onion_location}" />

    </head>
    <body>
        <div class="ui container">
            <div id="logobox" class="ui segment raised" style="margin: 1rem 0;">
                <div class="text-center">
                    <img id="pvxlogo" src="https://cdn.privex.io/privex.io/svg/privex_logo_horizontal.svg" alt="Privex Logo" />
                    <h1><xsl:value-of select="$service_name"/></h1>
                    <small><a href="https://www.privex.io" target="_BLANK">Operated by Privex Inc.</a></small>
                </div>

            </div>
            <div id="fileindex" class="ui segment raised">
                <h3><xsl:value-of select="$service_name"/></h3>
                <h3>Path: <xsl:value-of select="$uri"/></h3>
                <table class="ui table bordered fluid">
                <!-- <tr bgcolor="#9acd32"> -->
                <thead>
                    <tr>
                        <th>name</th>
                        <th>human size</th>
                        <th>size (bytes)</th>
                        <th>date</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><a href="..">[Previous Folder] ..</a></td>
                        <td align="right"></td>
                        <td align="right"></td>
                        <td></td>
                    </tr>
                    <!--
                    file size: @size
                    date / time: @mtime
                    file/folder name: "." / $name
                    -->

                    <xsl:for-each select="list/*">
                    <xsl:sort select="@size"/>

                        <xsl:variable name="name">
                            <xsl:value-of select="."/>
                        </xsl:variable>
                        <xsl:variable name="size">
                            <xsl:value-of select="@size" />
                        </xsl:variable>
                        <xsl:variable name="humansize">
                            <xsl:if test="string-length(@size) &gt; 0">
                                    <xsl:if test="number(@size) &gt; 0">
                                        <xsl:choose>
                                                <xsl:when test="round(@size div 1024) &lt; 1"><xsl:value-of select="@size" /></xsl:when>
                                                <xsl:when test="round(@size div 1048576) &lt; 1"><xsl:value-of select="format-number((@size div 1024), '0.0')" />K</xsl:when>
                                                <xsl:when test="round(@size div 1073741824) &lt; 1"><xsl:value-of select="format-number((@size div 1048576), '0.00')" />M</xsl:when>
                                                <xsl:otherwise><xsl:value-of select="format-number((@size div 1073741824), '0.00')" />G</xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:if>
                            </xsl:if>
                        </xsl:variable>
                        <xsl:variable name="date">
                            <xsl:value-of select="substring(@mtime,0,11)"/><xsl:text> </xsl:text><xsl:value-of select="substring(@mtime,12,8)"/> UTC-0
                        </xsl:variable>

                    <tr>
                        <xsl:if test="string-length(@size) &lt; 1">
                            <td><i class="folder icon"></i> <a href="{$name}"><xsl:value-of select="."/></a></td>
                        </xsl:if>
                        <xsl:if test="string-length(@size) &gt; 0">
                            <td><i class="file outline icon"></i> <a href="{$name}"><xsl:value-of select="."/></a></td>
                        </xsl:if>
                        <!-- <td><a href="{$name}"><xsl:value-of select="."/></a></td> -->
                        <td style="text-align: right"><xsl:value-of select="$humansize"/></td>
                        <td style="text-align: right"><xsl:value-of select="$size"/></td>
                        <td><xsl:value-of select="$date"/></td>
                    </tr>

                    </xsl:for-each>
                </tbody>
                </table>
            </div>
            <div id="pagefooter" class="ui segment raised">
                <div class="footerline">
                    <span>You are being served by:</span>
                    <a href="https://{$server}"><xsl:value-of select="$server"/></a>
                </div>
                <div class="footerline">
                    <strong>Region:</strong>
                    <img class="flag icon" src="https://cdn.privex.io/img/flags/svg/{$country_code}.svg" />
                    
                    <span><xsl:value-of select="$country_name"/></span>
                    <span class="uppercase">(<xsl:value-of select="$country_code"/>)</span>
                </div>
                <div class="ui divider"></div>
                <div class="footerline block-center halfish">
                    <a href="{$onion_location}">
                    <xsl:choose>
                            <xsl:when test="$service_code = 'cdn'">
                                <img src="/img/tor/tor_color.svg" alt="Tor Logo" style="height: 3rem" />
                            </xsl:when>
                            <xsl:when test="$service_code = 'filesrv'">
                                <img src="/cdn/img/tor/tor_color.svg" alt="Tor Logo" style="height: 3rem" />
                            </xsl:when>
                            <xsl:otherwise>
                                <img src="https://cdn.privex.io/img/tor/tor_color.svg" alt="Tor Logo" style="height: 3rem" />
                            </xsl:otherwise>
                    </xsl:choose>
                    </a>
                    <a href="{$onion_location}">
                        View this page on Tor via our Hidden Service
                    </a>
                </div>

                <div class="ui divider"></div>
                <div class="footerline">
                    <span><xsl:text disable-output-escaping="yes"><![CDATA[&copy;]]></xsl:text> Copyright 2021 - Operated and hosted by <a href="https://www.privex.io" target="_BLANK">Privex Inc.</a></span>
                </div>
                <div class="footerline">
                    <div style="display: block; margin: 1em 0 1em 0;">
                    <h4>Legal Disclaimer</h4>
                    <small>
                    Some of the content found on this fileserver is copyrighted material by <a href="https://www.privex.io" target="_BLANK">Privex Inc.</a>,
                    and may or may not be prohibited to sell/redistribute.<br/>
                    
                    However, since the files on this fileserver have been made available to the public internet, this generally means all content may
                    be downloaded for personal use, but some content, such as software (in the form of executables, scripts, or ISO/IMG files), 
                    may require a license to be used for personal and/or commercial use.<br/>
                    
                    If you're unsure about the license that a certain file/folder is made available under, you should 
                    <a href="https://www.privex.io/contact/" target="_BLANK">contact us</a> - so that we can explain the licensing that a specific file/folder
                    is released under.
                    </small>
                    <div class="ui divider"></div>
                    </div>
                </div>
                <div class="footerline">
                    <small>
                    <span>
                    Size Note: The <strong>human size</strong> column is denominated by exponents of 1024, e.g. <br/>
                    </span>
                    <pre>
    1K = 1024 x 1024 (1,048,576) bytes
    1M = 1024 x 1024 x 1024 (1,073,741,824) bytes
    1G = 1024 x 1024 x 1024 x 1024 (1,099,511,627,776) bytes
                    </pre>
                    </small>
                </div>
            </div>
        </div>
    </body>
    </html>
    </xsl:template>
</xsl:stylesheet>

