diff --git a/data/sites.json b/data/sites.json index 023fe8e..e9100f8 100644 --- a/data/sites.json +++ b/data/sites.json @@ -3,7 +3,8 @@ "url": "https://nathan3dprinting.au", "img": "/assets/img/external/nathan3dprinting.webp", "name": "Nathan 3D Printing", - "description": "Offering 3D Printing and CAD modelling services to the Canberra region" + "description": "Offering 3D Printing and CAD modelling services to the Canberra region", + "enabled": false }, { "url": "https://domains.hns.au", @@ -46,5 +47,17 @@ "img": "/favicon.png", "name": "LINKR/", "description": "A free link shortener with a Handshake TLD and using DNS for authentication" + }, + { + "url": "https://faucet.woodburn.au", + "img": "/favicon.png", + "name": "HNS Domain Faucet", + "description": "A service providing free Handshake TLDs to allow for quick testing for new users" + }, + { + "url":"https://hnsdoh.com", + "img": "/assets/img/external/HNS.png", + "name": "HNS DoH", + "description": "A DNS over HTTPS resolver for Handshake domains" } ] \ No newline at end of file diff --git a/server.py b/server.py index 9af4534..1ffecc5 100644 --- a/server.py +++ b/server.py @@ -24,6 +24,12 @@ sites = [] if os.path.isfile('data/sites.json'): with open('data/sites.json') as file: sites = json.load(file) + # Remove any sites that are not enabled + sites = [site for site in sites if 'enabled' not in site or site['enabled'] == True] + +projects = [] +projectsUpdated = 0 + def getAddress(): global address @@ -37,7 +43,19 @@ def send_report(path): if path.endswith('.json'): return send_from_directory('templates/assets', path, mimetype='application/json') - return send_from_directory('templates/assets', path) + if os.path.isfile('templates/assets/' + path): + return send_from_directory('templates/assets', path) + + # Try looking in one of the directories + filename:str = path.split('/')[-1] + if filename.endswith('.png') or filename.endswith('.jpg') \ + or filename.endswith('.jpeg') or filename.endswith('.svg'): + if os.path.isfile('templates/assets/img/' + filename): + return send_from_directory('templates/assets/img', filename) + if os.path.isfile('templates/assets/img/favicon/' + filename): + return send_from_directory('templates/assets/img/favicon', filename) + + return render_template('404.html'), 404 # Special routes @@ -117,7 +135,21 @@ def nostr(): }) -# Main routes +@app.route('/manifest.json') +def manifest(): + host = request.host + if host == 'nathan.woodburn.au': + return send_from_directory('templates', 'manifest.json') + + # Read as json + with open('templates/manifest.json') as file: + manifest = json.load(file) + scheme = request.scheme + manifest['start_url'] = f'{scheme}://{host}/' + return jsonify(manifest) + + +# region Main routes @app.route('/') def index(): # Check if host if podcast.woodburn.au @@ -141,8 +173,11 @@ def index(): global address global handshake_scripts + global projects + try: - git=requests.get('https://git.woodburn.au/api/v1/users/nathanwoodburn/activities/feeds?only-performed-by=true&limit=1&token=' + os.getenv('git_token')) + git=requests.get('https://git.woodburn.au/api/v1/users/nathanwoodburn/activities/feeds?only-performed-by=true&limit=1', + headers={'Authorization': os.getenv('git_token')}) git = git.json() git = git[0] repo_name=git['repo']['name'] @@ -152,8 +187,39 @@ def index(): repo_name = "nathanwoodburn.github.io" repo_description = "Personal website" git = {'repo': {'html_url': 'https://nathan.woodburn.au', 'name': 'nathanwoodburn.github.io', 'description': 'Personal website'}} + print("Error getting git data") custom = "" + # Get only repo names for the newest updates + if projects == [] or projectsUpdated < datetime.datetime.now() - datetime.timedelta(hours=2): + projectsreq = requests.get('https://git.woodburn.au/api/v1/users/nathanwoodburn/repos') + + projects = projectsreq.json() + + # Check for next page + pageNum = 1 + while 'rel="next"' in projectsreq.headers['link']: + projectsreq = requests.get('https://git.woodburn.au/api/v1/users/nathanwoodburn/repos?page=' + str(pageNum)) + projects += projectsreq.json() + pageNum += 1 + + + for project in projects: + if project['avatar_url'] == 'https://git.woodburn.au/': + project['avatar_url'] = '/favicon.png' + project['name'] = project['name'].replace('_', ' ').replace('-', ' ') + # Sort by last updated + projectsList = sorted(projects, key=lambda x: x['updated_at'], reverse=True) + projects = [] + projectNames = [] + projectNum = 0 + while len(projects) < 3: + if projectsList[projectNum]['name'] not in projectNames: + projects.append(projectsList[projectNum]) + projectNames.append(projectsList[projectNum]['name']) + projectNum += 1 + projectsUpdated = datetime.datetime.now() + # Check for downtime uptime = requests.get('https://uptime.woodburn.au/api/status-page/main/badge') uptime = uptime.content.count(b'Up') > 1 @@ -173,14 +239,20 @@ def index(): handshake_scripts = "" if request.cookies.get('HNS'): - resp = make_response(render_template('index.html', handshake_scripts=handshake_scripts, HNS=request.cookies.get('HNS'), repo=repo, repo_description=repo_description, custom=custom,sites=sites), 200, {'Content-Type': 'text/html'}) + resp = make_response(render_template('index.html', handshake_scripts=handshake_scripts, + HNS=request.cookies.get('HNS'), repo=repo, + repo_description=repo_description, + custom=custom,sites=sites, projects=projects), 200, {'Content-Type': 'text/html'}) resp.set_cookie('loaded', 'true', max_age=604800) return resp if address == '': address = getAddress() # Set cookie - resp = make_response(render_template('index.html', handshake_scripts=handshake_scripts, HNS=address, repo=repo, repo_description=repo_description, custom=custom,sites=sites), 200, {'Content-Type': 'text/html'}) + resp = make_response(render_template('index.html', handshake_scripts=handshake_scripts, + HNS=address, repo=repo, + repo_description=repo_description, + custom=custom,sites=sites,projects=projects), 200, {'Content-Type': 'text/html'}) # Cookie should last 1 week resp.set_cookie('HNS', address, max_age=604800) @@ -189,6 +261,8 @@ def index(): return resp + +# region Now Pages @app.route('/now') @app.route('/now/') def now(): @@ -261,6 +335,7 @@ def now_old(): html += '' return render_template('now/old.html', handshake_scripts=handshake_scripts,now_pages=html) +# endregion @app.route('/donate') @@ -405,30 +480,19 @@ def catch_all(path): return render_template('404.html'), 404 # If file exists, load it if os.path.isfile('templates/' + path): - return render_template(path, handshake_scripts=handshake_scripts) + return render_template(path, handshake_scripts=handshake_scripts,sites=sites) # Try with .html if os.path.isfile('templates/' + path + '.html'): - return render_template(path + '.html', handshake_scripts=handshake_scripts) + return render_template(path + '.html', handshake_scripts=handshake_scripts,sites=sites) if os.path.isfile('templates/' + path.strip('/') + '.html'): - return render_template(path.strip('/') + '.html', handshake_scripts=handshake_scripts) + return render_template(path.strip('/') + '.html', handshake_scripts=handshake_scripts,sites=sites) return render_template('404.html'), 404 +# endregion -@app.route('/manifest.json') -def manifest(): - host = request.host - if host == 'nathan.woodburn.au': - return send_from_directory('templates', 'manifest.json') - - # Read as json - with open('templates/manifest.json') as file: - manifest = json.load(file) - scheme = request.scheme - manifest['start_url'] = f'{scheme}://{host}/' - return jsonify(manifest) - +#region ACME @app.route('/hnsdoh-acme', methods=['POST']) def hnsdoh_acme(): # Get the TXT record from the request @@ -459,7 +523,9 @@ def hnsdoh_acme(): record = cf.zones.dns_records.post(zone_id, data={'type': 'TXT', 'name': '_acme-challenge', 'content': txt}) print(record) return jsonify({'status': 'success'}) +#endregion +#region Podcast @app.route('/ID1') def ID1(): # Proxy to ID1 url @@ -488,13 +554,15 @@ def ID1_xml(): def podsync(): req = requests.get('https://id1.woodburn.au/podsync.opml') return make_response(req.content, 200, {'Content-Type': req.headers['Content-Type']}) +#endregion - +#region Error Catching # 404 catch all @app.errorhandler(404) def not_found(e): return render_template('404.html'), 404 +#endregion if __name__ == '__main__': app.run(debug=True, port=5000, host='0.0.0.0') \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index b0e693b..28d2eeb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -98,24 +98,18 @@ Check them out here! - My Websites + Some recent projects - - -{% for site in sites %} - - + {% for project in projects %} + + - {{ site.name }} - {{ site.description }} + {{ project.name }} + {{ project.description }} + {% if project.actions %} + + {% endif %} diff --git a/templates/projects.html b/templates/projects.html index e745ef3..b605fda 100644 --- a/templates/projects.html +++ b/templates/projects.html @@ -40,17 +40,18 @@ - - Nathan.Woodburn/ + + Nathan.Woodburn/ Home - Projects + Projects + Now - + @@ -61,61 +62,17 @@ height="0" width="0" style="display:none;visibility:hidden"> - - Check out my Git for all my projects + - - - ShakeCities - A single page website creator where each user's page on their free HNS domainMore Info - - - Woodburn Faucet - A service providing free Handshake TLDs to allow for quick testing for new usersMore Info - - - - - Linkr - A shortlinks service on the Handshake domain Linkr/More Info - - - HNSDoh - A DNS server with support for Handshake domains using multiple upstream providers to provide as little downtime as possible.More Info - - - - - FireWallet - The Handshake wallet that is Fire.A new frontend to HSD or Bob WalletMore Info - - - HNS HOSting - A hosting service for Handshake domainsMore Info - - - - - HNS AU - The home of Australians using the decentralized web, built on Handshake.More Info - - - HNS Proxy - A Proxy to access Handshake domains over SSL.More Info - - - - - Woodburn Registry - Selling SLDs off domains secured on the Handshake blockchain.More Info - - - HSD Batcher - A GUI to send transaction batches to the Handshake chain.More Info - - + {% for site in sites %} + + {{site.name}} + {{site.description}}More Info + +{% endfor %} + Check out my Git for all my projects
{{ site.description }}
{{ project.description }}
Check out my Git for all my projects
A single page website creator where each user's page on their free HNS domain
A service providing free Handshake TLDs to allow for quick testing for new users
A shortlinks service on the Handshake domain Linkr/
A DNS server with support for Handshake domains using multiple upstream providers to provide as little downtime as possible.
The Handshake wallet that is Fire.A new frontend to HSD or Bob Wallet
A hosting service for Handshake domains
The home of Australians using the decentralized web, built on Handshake.
A Proxy to access Handshake domains over SSL.
Selling SLDs off domains secured on the Handshake blockchain.
A GUI to send transaction batches to the Handshake chain.
{{site.description}}