Commit 03bfa340 authored by Alyx's avatar Alyx
Browse files

cleaned up for GitHub

parent 077955e8
Loading
Loading
Loading
Loading
+3 −79
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ def download_iso(file_url, filename):

@app.route('/', methods=['GET', 'POST'])
def index():
    with open("index.template.html", "r") as file:
        template = file.read()
    if request.method == 'POST':
        file_url = request.form.get('file_url')
        if not file_url:
@@ -64,67 +66,7 @@ def index():

        return redirect(url_for('index'))

    return render_template_string('''
        <!doctype html>
<title>alyx's cool ipmi network file hosting</title>
<h1>alyx's cool ipmi network file hosting</h1>
<style>
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }

    td {
        padding: 4px
    }
</style>

<p>enter the URL of a file on the internet. it will be downloaded to this and served for use within the IPMI network.
    files will expire and be automatically removed after 3 days.</p>
    <p><b>files uploaded here will be available to anyone on the IPMI network. do not use this to serve sensitive information</b></p>
<form method="post">
    <input type="text" name="file_url" placeholder="Enter URL" required>
    <button type="submit">Download</button>
</form>
<h3>Available Files:</h3>
<table>
    <thead>
    <td>
        <b>Filename</b>
    </td>
    <td>
        <b>Size</b>
    </td>
    <td>
        <b>Status</b>
    </td>
    <td>
        <b>Expiry</b>
    </td>
    <td>
        <b>SHA256 Checksum</b>
    </td>
    </thead>
    <tbody id="file-list">
    </tbody>
</table>
<!--<a href='/iso/{filename}'>{filename}</a> ({round(size / 1000000)}MB) - {status} - Expires in {hours_left}h {minutes_left}m - SHA256: {sha256_hash}-->
<p>for comments, questions and complaints, contact alyx</p>
<h3>other services available</h3>
<ul>
    <!--<li>downloads.dell.com HTTP proxy (port 3355)-->
</ul>
<script>
    function fetchFileList() {
        fetch('/files').then(response => response.text()).then(data => {
            document.getElementById('file-list').innerHTML = data;
        });
    }

    setInterval(fetchFileList, 750);
    fetchFileList();
</script>
    ''')
    return render_template_string(template)


@app.route('/files')
@@ -151,23 +93,5 @@ def file_list():
    return "".join(file_list)


@app.route('/iso/<filename>')
def serve_iso(filename):
    file_path = os.path.join(DOWNLOAD_FOLDER, filename)
    if not os.path.exists(file_path):
        return "File not found", 404

    def generate():
        with open(file_path, "rb") as f:
            while chunk := f.read(8192):
                yield chunk

    return Response(generate(), headers={
        "Content-Disposition": f"attachment; filename={filename}",
        "Accept-Ranges": "bytes",
        "Content-Type": "application/octet-stream"
    })


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=8081)

index.template.html

0 → 100644
+68 −0
Original line number Diff line number Diff line
<!doctype html>
<title>IPMI Network File Server</title>
<h1>IPMI Network File Server</h1>
<style>
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }

    td {
        padding: 4px
    }
</style>
<div>
    <p>This utility is to help serve external files within an otherwise isolated IPMI network, for use by BMCs to pull
        updates or mount virtual media. This bastion host acts as a jump box or bastion, and has external network
        access, and can download and serve .iso files from the internet within the local network. This is useful for
        things like Virtual Media on BMCs like HP's ILO or Dell's IDRAC which can allow mounting an ISO from a web
        server, which tends to be more performant than uploading a file through the virtual KVM interface.</p>
    <p>This service is accessible to anyone on the IPMI network, and should never be used to store or transfer sensitive
        information.</p>
</div>
<div>
    <form method="post">
        <input type="text" name="file_url" placeholder="Enter URL" required>
        <button type="submit">Download</button>
    </form>
</div>
<div>
    <h3>Available Files:</h3>
    <table>
        <tr>
            <td>
                <b>Filename</b>
            </td>
            <td>
                <b>Size</b>
            </td>
            <td>
                <b>Status</b>
            </td>
            <td>
                <b>Expiry</b>
            </td>
            <td>
                <b>SHA256 Checksum</b>
            </td>
        </tr>
        <tbody id="file-list">
        </tbody>
    </table>
</div>
<!--<a href='/iso/{filename}'>{filename}</a> ({round(size / 1000000)}MB) - {status} - Expires in {hours_left}h {minutes_left}m - SHA256: {sha256_hash}-->

<h3>other services available</h3>
<ul>
    <!--<li>downloads.dell.com HTTP proxy (port 3355)-->
</ul>
<script>
    function fetchFileList() {
        fetch('/files').then(response => response.text()).then(data => {
            document.getElementById('file-list').innerHTML = data;
        });
    }
    //refresh page every 1s
    setInterval(fetchFileList, 1000);
    fetchFileList();
</script>
 No newline at end of file

wsgi.py

0 → 100644
+4 −0
Original line number Diff line number Diff line
from app import app

if __name__ == "__main__":
    app.run()
 No newline at end of file