From 48531c915a61ccad1fbe7d1bb638b8f834f3c31a Mon Sep 17 00:00:00 2001
From: Zlatin Balevsky <zlatinb@gmail.com>
Date: Thu, 26 Aug 2021 14:41:36 +0100
Subject: [PATCH] mac dmg page

---
 i2p2www/downloads.py              | 16 ++++++++-
 i2p2www/legacy.py                 |  1 +
 i2p2www/pages/downloads/list.html |  7 ++++
 i2p2www/pages/downloads/mac.html  | 59 +++++++++++++++++++++++++++++++
 i2p2www/sitemap.py                |  3 ++
 i2p2www/urls.py                   |  1 +
 6 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 i2p2www/pages/downloads/mac.html

diff --git a/i2p2www/downloads.py b/i2p2www/downloads.py
index 2c6c16f9b..419d5ac9c 100644
--- a/i2p2www/downloads.py
+++ b/i2p2www/downloads.py
@@ -104,7 +104,21 @@ def downloads_firefox():
 
 # The Lab
 def downloads_lab():
-    return render_template('downloads/lab.html')
+    # TODO: read mirror list or list of available files
+    if request.headers.get('X-I2P-Desthash') and not request.headers.get('X-Forwarded-Server'):
+        def_mirror = DEFAULT_I2P_MIRROR
+    else:
+        def_mirror = DEFAULT_MIRROR
+    return render_template('downloads/lab.html', def_mirror=def_mirror)
+
+# Mac DMG page
+def downloads_mac():
+    # TODO: read mirror list or list of available files
+    if request.headers.get('X-I2P-Desthash') and not request.headers.get('X-Forwarded-Server'):
+        def_mirror = DEFAULT_I2P_MIRROR
+    else:
+        def_mirror = DEFAULT_MIRROR
+    return render_template('downloads/mac.html', def_mirror=def_mirror)
 
 def downloads_config():
     return render_template('downloads/config.html')
diff --git a/i2p2www/legacy.py b/i2p2www/legacy.py
index 715d27eb9..4f5b9d0f9 100644
--- a/i2p2www/legacy.py
+++ b/i2p2www/legacy.py
@@ -19,6 +19,7 @@ LEGACY_FUNCTIONS_MAP={
     'debian':        {'function': 'downloads_debian', 'params': {}},
     'firefox':        {'function': 'downloads_firefox', 'params': {}},
     'lab':           {'function': 'downloads_lab',    'params': {}},
+    'mac':           {'function': 'downloads_mac',    'params': {}},
     'download':      {'function': 'downloads_list',   'params': {}},
     'installation':  {'function': 'downloads_list',   'params': {}},
     'meetings':      {'function': 'meetings_index',   'params': {}},
diff --git a/i2p2www/pages/downloads/list.html b/i2p2www/pages/downloads/list.html
index db73a6087..d6f2a9416 100644
--- a/i2p2www/pages/downloads/list.html
+++ b/i2p2www/pages/downloads/list.html
@@ -128,6 +128,13 @@ I2P connections.</p>
     <code>java -jar i2pinstall_{{ i2pversion }}.jar -console</code> to follow
     the install procedure in your terminal.
     {%- endtrans %}
+
+    <h3>{% trans %}DMG Bundle (BETA){% endtrans %}</h3>
+    If you do not want to use the installer or do not have a Java Runtime Environment available
+    on your Mac, you can try our latest DMG bundle.
+    <div class="file">
+        <a class="default" href="{{ get_url('downloads_mac') }}">{% trans %}Mac OS DMG Bundle (BETA){% endtrans %}</a>
+    </div>
 {% endcall %}
 
     <h5>{%- trans %}I2P for Linux{%- endtrans %}</h5>
diff --git a/i2p2www/pages/downloads/mac.html b/i2p2www/pages/downloads/mac.html
new file mode 100644
index 000000000..7b3b0b4d8
--- /dev/null
+++ b/i2p2www/pages/downloads/mac.html
@@ -0,0 +1,59 @@
+{% extends "global/layout.html" %}
+{%- from "downloads/macros" import package_outer with context -%}
+{% block title %}Mac OS DMG Bundle (BETA){% endblock %}
+{% block content %}
+
+<h1>{{ _('Mac OS DMG Bundle (BETA)') }}</h1>
+<p>{% trans -%}
+We are excited to offer you a DMG bundle for Mac OS.  It installs and behaves the same way many other Mac OS applications do and does not require a Java Runtime Environment to be available.
+{%- endtrans %}</p>
+<h2>{{ _('How do I use it?') }}</h2>
+<p>{% trans -%}
+I2P behaves like any other Mac application.  When you launch I2P, the I2P icon will appear on the Dock and a few seconds later a browser will open with the I2P console page, inviting you to complete the setup wizard.
+{%- endtrans %}</p>
+<p>{% trans -%}
+If you want to browse hidden websites ('eepsites') on the I2P network, you need to configure your browser.
+{%- endtrans %}</p>
+
+{%- set name     = 'Windows' -%}
+{%- set icon     = 'images/download/mac-osx.png' -%}
+{%- set filename = 'I2P-%s.dmg' -%}
+{%- set hash     = '07c729c26fc8a31c0e74fe7b4de7be1f8e390d018748322ada35b29de9d' -%}
+
+{% call package_outer('osx', name, icon) %}
+    <div class = "file">
+	    <a class = "default" href="{{ url_for('downloads_redirect', version=ver(), net=def_mirror.net, protocol=def_mirror.protocol, domain=def_mirror.domain, file=ver(filename) )}}">
+		    <span class = "name">{{ ver(filename) }}</span><br/>
+		    <span class="mirror">{{ _('Mirror:') }} <img src="{{ url_for('static', filename='images/flags/'+def_mirror.country+'.png') }}" /> {{ def_mirror.org }}</span>
+	    </a>
+	    <a class="mirrors" href="{{ get_url('downloads_select', version=ver(), file=ver(filename)) }}">{{ _('select alternate mirror') }}</a>
+    </div>
+    <div class="meta">
+	    <div class="hash">
+		    <code>{{ hash }}</code>
+	    </div>
+    </div>
+    <p>{% trans -%}
+Download that file and double-click on it.  Accept the License Agreement, then drag the <code>I2P</code> icon on top of the <code>Applications</code> icon.  Launch I2P from Finder.
+    {%- endtrans %}</p>
+{% endcall %}
+
+<h2>{{ _('Limitations') }}</h2>
+<p>{% trans -%}
+I2P will not install any launch agents on your Mac.  If you want I2P to start on system startup, you need to configure a launch agent yourself.  You can configure I2P to launch when your user logs in by right-clicking on the I2P Dock icon.
+{%- endtrans %}</p>
+<h3>{{ _('Source Code and Issue Tracking') }}</h3>
+<div>{% trans -%}
+If you would like to examine the source code for individual components, you may
+find it on i2pgit.org.  
+{%- endtrans %}</div>
+<div><a href="https://i2pgit.org/i2p-hackers/i2p-jpackage-mac">{% trans -%}Gitlab Repository{%- endtrans %}</a></div>
+<div>{% trans -%}
+If you wish to file an issue about the DMG Bundle, please use Gitlab to
+contact us. For security-sensitive issues, please remember to check the
+"This issue is confidential and should only be visible to team members with at least Reporter access"
+option when filing the issue.
+{%- endtrans %}</div>
+<div><a href="https://i2pgit.org/i2p-hackers/i2p-jpackage-mac/issues">{% trans -%}Gitlab Repository{%- endtrans %}</a></div>
+
+{% endblock %}
diff --git a/i2p2www/sitemap.py b/i2p2www/sitemap.py
index 355eb9211..77202a041 100644
--- a/i2p2www/sitemap.py
+++ b/i2p2www/sitemap.py
@@ -115,6 +115,9 @@ def render_sitemap():
     urls.append({
         'path': '/download/lab',
         })
+    urls.append({
+        'path': '/download/mac',
+        })
 
     # Render and return the sitemap
     response = make_response(render_template('global/sitemap.xml', url_root=url_root, langs=LANG_FRAGS,
diff --git a/i2p2www/urls.py b/i2p2www/urls.py
index aee5f2bb5..37fbc46bb 100644
--- a/i2p2www/urls.py
+++ b/i2p2www/urls.py
@@ -95,6 +95,7 @@ url('/<lang:lang>/download/windows', 'downloads.downloads_windows')
 url('/<lang:lang>/download/firefox', 'downloads.downloads_firefox')
 url('/<lang:lang>/download/config', 'downloads.downloads_config')
 url('/<lang:lang>/download/lab', 'downloads.downloads_lab')
+url('/<lang:lang>/download/mac', 'downloads.downloads_mac')
 url('/<lang:lang>/download/<string:version>/<path:file>/mirrors', 'downloads.downloads_select')
 url('/<lang:lang>/download/<string:version>/<string:net>/any/<path:file>/download', 'downloads.downloads_redirect', defaults={'protocol': None, 'domain': None})
 url('/<lang:lang>/download/<string:version>/<string:net>/<string:protocol>/any/<path:file>/download', 'downloads.downloads_redirect', defaults={'domain': None})
-- 
GitLab