openwrite 0.10.5.1__tar.gz → 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {openwrite-0.10.5.1/openwrite.egg-info → openwrite-0.12.0}/PKG-INFO +7 -3
  2. {openwrite-0.10.5.1 → openwrite-0.12.0}/README.md +6 -2
  3. openwrite-0.12.0/openwrite/__init__.py +284 -0
  4. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/cli.py +10 -61
  5. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/gemini_multi.py +0 -2
  6. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/gemini_single.py +0 -2
  7. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/admin.py +82 -4
  8. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/auth.py +1 -1
  9. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/blog.py +55 -11
  10. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/dashboard.py +168 -16
  11. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/main.py +12 -3
  12. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/upload.py +1 -1
  13. openwrite-0.12.0/openwrite/static/emoji.json +15627 -0
  14. openwrite-0.12.0/openwrite/static/script/nativeEmoji.js +389 -0
  15. openwrite-0.12.0/openwrite/static/style/nativeEmoji.min.css +1 -0
  16. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/style.css +27 -2
  17. openwrite-0.12.0/openwrite/static/style/themes/cyberpunk.css +391 -0
  18. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/themes/light.css +11 -1
  19. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/themes/stickynote.css +11 -1
  20. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/themes/terminal.css +9 -0
  21. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/themes/warmnight.css +5 -0
  22. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/themes/windows98.css +58 -3
  23. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/admin.html +7 -6
  24. openwrite-0.12.0/openwrite/templates/blog.html +18 -0
  25. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/blog_header.html +16 -1
  26. openwrite-0.12.0/openwrite/templates/blog_preview.html +57 -0
  27. openwrite-0.12.0/openwrite/templates/changepw.html +19 -0
  28. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/create.html +7 -7
  29. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/dashboard.html +11 -11
  30. openwrite-0.12.0/openwrite/templates/discover.html +11 -0
  31. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/edit.html +50 -65
  32. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/footer.html +4 -4
  33. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/header.html +10 -6
  34. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/import.html +7 -7
  35. openwrite-0.12.0/openwrite/templates/index.html +17 -0
  36. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/instances.html +3 -3
  37. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/login.html +2 -2
  38. openwrite-0.12.0/openwrite/templates/new_page.html +218 -0
  39. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/new_post.html +9 -9
  40. openwrite-0.10.5.1/openwrite/templates/blog_preview.html → openwrite-0.12.0/openwrite/templates/page_preview.html +15 -11
  41. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/register.html +5 -5
  42. openwrite-0.12.0/openwrite/templates/settings.html +96 -0
  43. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/stats.html +4 -4
  44. openwrite-0.12.0/openwrite/templates/translations.html +88 -0
  45. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/utils/create_db.py +1 -1
  46. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/utils/i18n.json +3 -5
  47. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/utils/models.py +22 -0
  48. {openwrite-0.10.5.1 → openwrite-0.12.0/openwrite.egg-info}/PKG-INFO +7 -3
  49. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite.egg-info/SOURCES.txt +8 -2
  50. {openwrite-0.10.5.1 → openwrite-0.12.0}/pyproject.toml +1 -1
  51. openwrite-0.10.5.1/openwrite/__init__.py +0 -134
  52. openwrite-0.10.5.1/openwrite/templates/blog.html +0 -16
  53. openwrite-0.10.5.1/openwrite/templates/changepw.html +0 -19
  54. openwrite-0.10.5.1/openwrite/templates/discover.html +0 -11
  55. openwrite-0.10.5.1/openwrite/templates/index.html +0 -9
  56. openwrite-0.10.5.1/openwrite/templates/settings.html +0 -63
  57. openwrite-0.10.5.1/openwrite/utils/translations.py +0 -6
  58. {openwrite-0.10.5.1 → openwrite-0.12.0}/LICENSE +0 -0
  59. {openwrite-0.10.5.1 → openwrite-0.12.0}/MANIFEST.in +0 -0
  60. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/db/__init__.py +0 -0
  61. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/db/base.py +0 -0
  62. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/routes/federation.py +0 -0
  63. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/IBMPlexSans-Regular.ttf +0 -0
  64. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/Merriweather.ttf +0 -0
  65. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/avatar.png +0 -0
  66. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/favicon.ico +0 -0
  67. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/logo.png +0 -0
  68. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/chart.js +0 -0
  69. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/highlight.min.js +0 -0
  70. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/openwrite.js +0 -0
  71. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/papaparse.min.js +0 -0
  72. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/showdown.min.js +0 -0
  73. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/showdown.min.js.map +0 -0
  74. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/site.compat.min.js +0 -0
  75. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/script/site.min.js +0 -0
  76. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/hl.css +0 -0
  77. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/static/style/themes/obscura.css +0 -0
  78. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/blog_footer.html +0 -0
  79. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/post.html +0 -0
  80. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/templates/preview.html +0 -0
  81. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/utils/db.py +0 -0
  82. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite/utils/helpers.py +0 -0
  83. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite.egg-info/dependency_links.txt +0 -0
  84. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite.egg-info/entry_points.txt +0 -0
  85. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite.egg-info/requires.txt +0 -0
  86. {openwrite-0.10.5.1 → openwrite-0.12.0}/openwrite.egg-info/top_level.txt +0 -0
  87. {openwrite-0.10.5.1 → openwrite-0.12.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openwrite
3
- Version: 0.10.5.1
3
+ Version: 0.12.0
4
4
  License: GNU AFFERO GENERAL PUBLIC LICENSE
5
5
  Version 3, 19 November 2007
6
6
 
@@ -690,6 +690,7 @@ Dynamic: license-file
690
690
  ![logo](https://openwrite.io/static/logo.png)
691
691
  openwrite is a minimalist blogging platform built for writing freely, hosting independently, and publishing without noise.
692
692
 
693
+ ![PyPI - Downloads](https://img.shields.io/pypi/dw/openwrite)
693
694
  ![PyPI - Version](https://img.shields.io/pypi/v/openwrite)
694
695
  [![License: AGPL-3.0-or-later](https://img.shields.io/badge/License-AGPL--3.0--or--later-blue.svg)](LICENSE)
695
696
  ![pythonver](https://img.shields.io/badge/python%20version-3.11-blue)
@@ -718,6 +719,9 @@ openwrite is a minimalist blogging platform built for writing freely, hosting in
718
719
  - Blog themes
719
720
  - Gemini protocol
720
721
  - Statistics per post
722
+ - Multilanguage (currently English and Polish)
723
+ - Custom favicon per blog
724
+ - Subpages per blog
721
725
 
722
726
 
723
727
  ## Installation
@@ -734,7 +738,7 @@ pip install openwrite
734
738
  openwrite init
735
739
  ```
736
740
 
737
- 3. Answer few questions about your instance to generate .env, database and create all necessary directories.
741
+ 3. Answer few questions about your instance to generate .env and create all necessary directories.
738
742
  4. Run:
739
743
 
740
744
  ```
@@ -749,7 +753,7 @@ openwrite run -d
749
753
 
750
754
  to run it in background.
751
755
 
752
- 5. Enjoy!
756
+ 5. Default user is `admin` with password `openwrite`. You can (and should!) change it in your dashboard. Enjoy!
753
757
 
754
758
 
755
759
  #### Docker
@@ -1,6 +1,7 @@
1
1
  ![logo](https://openwrite.io/static/logo.png)
2
2
  openwrite is a minimalist blogging platform built for writing freely, hosting independently, and publishing without noise.
3
3
 
4
+ ![PyPI - Downloads](https://img.shields.io/pypi/dw/openwrite)
4
5
  ![PyPI - Version](https://img.shields.io/pypi/v/openwrite)
5
6
  [![License: AGPL-3.0-or-later](https://img.shields.io/badge/License-AGPL--3.0--or--later-blue.svg)](LICENSE)
6
7
  ![pythonver](https://img.shields.io/badge/python%20version-3.11-blue)
@@ -29,6 +30,9 @@ openwrite is a minimalist blogging platform built for writing freely, hosting in
29
30
  - Blog themes
30
31
  - Gemini protocol
31
32
  - Statistics per post
33
+ - Multilanguage (currently English and Polish)
34
+ - Custom favicon per blog
35
+ - Subpages per blog
32
36
 
33
37
 
34
38
  ## Installation
@@ -45,7 +49,7 @@ pip install openwrite
45
49
  openwrite init
46
50
  ```
47
51
 
48
- 3. Answer few questions about your instance to generate .env, database and create all necessary directories.
52
+ 3. Answer few questions about your instance to generate .env and create all necessary directories.
49
53
  4. Run:
50
54
 
51
55
  ```
@@ -60,7 +64,7 @@ openwrite run -d
60
64
 
61
65
  to run it in background.
62
66
 
63
- 5. Enjoy!
67
+ 5. Default user is `admin` with password `openwrite`. You can (and should!) change it in your dashboard. Enjoy!
64
68
 
65
69
 
66
70
  #### Docker
@@ -0,0 +1,284 @@
1
+ from flask import Flask, g
2
+ from dotenv import load_dotenv
3
+ from werkzeug.middleware.proxy_fix import ProxyFix
4
+ from werkzeug.exceptions import HTTPException
5
+ import os
6
+ from .utils.helpers import generate_nonce, get_ip
7
+ import time
8
+ from .utils.models import Settings, Home
9
+ from sqlalchemy import distinct
10
+ import bcrypt
11
+ import json
12
+ from cryptography.hazmat.primitives.asymmetric import rsa
13
+ from cryptography.hazmat.primitives import serialization
14
+ from datetime import datetime, timezone
15
+
16
+ start_time = time.time()
17
+
18
+ def create_app(test_config=None):
19
+ if test_config is None:
20
+ load_dotenv()
21
+ db_type = os.getenv("DB_TYPE", "sqlite")
22
+ db_path = os.getenv("DB_PATH", "db.sqlite")
23
+ else:
24
+ db_type = test_config.get("DB_TYPE", "sqlite")
25
+ db_path = test_config.get("DB_PATH", "data.db")
26
+ load_dotenv(test_config.get("env"), override=True)
27
+
28
+ if not os.path.exists(".initialized") or test_config is not None:
29
+ mode = os.getenv("MODE")
30
+ domain = os.getenv("DOMAIN")
31
+ f_abs_path = os.path.abspath(__file__)
32
+ file_cwd = "/".join(f_abs_path.split("/")[:-1])
33
+ from .utils.create_db import init_db
34
+ init_db(db_type, db_path)
35
+ from .utils.models import User, Blog, Post, Settings, Home, Page
36
+ from .utils.db import init_engine, SessionLocal
37
+ init_engine(db_type, db_path)
38
+ from .utils.db import SessionLocal
39
+ admin_password = os.urandom(16).hex()
40
+ hashed = bcrypt.hashpw("openwrite".encode("utf-8"), bcrypt.gensalt())
41
+ admin_user = User(username="admin", email="", password_hash=hashed.decode("utf-8"), verified=1, admin=1)
42
+ SessionLocal.add(admin_user)
43
+ SessionLocal.commit()
44
+ SessionLocal.close()
45
+
46
+ if mode == "single":
47
+ key = rsa.generate_private_key(
48
+ public_exponent=65537,
49
+ key_size=2048
50
+ )
51
+
52
+ private_pem = key.private_bytes(
53
+ encoding=serialization.Encoding.PEM,
54
+ format=serialization.PrivateFormat.PKCS8,
55
+ encryption_algorithm=serialization.NoEncryption()
56
+ ).decode()
57
+
58
+ public_pem = key.public_key().public_bytes(
59
+ encoding=serialization.Encoding.PEM,
60
+ format=serialization.PublicFormat.SubjectPublicKeyInfo
61
+ ).decode()
62
+
63
+ now = datetime.now(timezone.utc).replace(microsecond=0)
64
+
65
+ new_blog = Blog(
66
+ owner=1,
67
+ name="default",
68
+ title=domain,
69
+ index="on",
70
+ access="domain",
71
+ css="",
72
+ description_raw="x",
73
+ description_html="x",
74
+ pub_key=public_pem,
75
+ priv_key=private_pem,
76
+ theme="default",
77
+ favicon="",
78
+ created=now
79
+ )
80
+ SessionLocal.add(new_blog)
81
+
82
+ new_page = Page(
83
+ blog=1,
84
+ name="Home",
85
+ url="",
86
+ content_raw=f"![hello](https://openwrite.b-cdn.net/hello.jpg =500x258)\n\n# Hello there! 👋\n\nYou can edit your blog home page in [dashboard](https://{domain}/dashboard/page/1/edit)\n\n---\n### Posts\n\n{{posts}}",
87
+ content_html=f"<p><img src=\"https://openwrite.b-cdn.net/hello.jpg\" width=\"500\" height=\"258\"></p><h1>Hello there! 👋</h1><p>You can edit your blog home page in <a href=\"https://{domain}/dashboard/page/1/edit\">dashboard</a></p>\n\n<hr>\n<h3>Posts\n\n{{posts}}",
88
+ show="off"
89
+ )
90
+ SessionLocal.add(new_page)
91
+
92
+ hometext_pl = """
93
+ <h1 class="centered"><span style="color: #f2d2c8">cicha</span> przestrzeń na <span style="color: #5a36bf">głośne</span> myśli.</h1>
94
+
95
+ <article class="main-content" style="text-align: center">
96
+ <p><strong>Openwrite</strong> to lekka, otwartoźródłowa platforma blogowa stworzona z myślą o wolności pisania – bez reklam, trackerów i zbędnego balastu.</p><br>
97
+
98
+ - Pisz w Markdownie<br>
99
+ - Zainstaluj w kilka minut<br>
100
+ - Publikuj do sieci, przez Gemini lub na Mastodonie – jak chcesz<br>
101
+
102
+ <br>
103
+ <p>Bez analityki. Bez ukrytych skryptów.<br>
104
+ Tylko Ty, Twoje myśli i miejsce, w którym możesz je wyrazić.</p>
105
+ <p>Wybierz motyw. Dodaj obrazki. Śledź wyświetlenia.<br>
106
+ Zbuduj bloga po swojemu – minimalistycznego lub z dodatkami.</p>
107
+ <p><strong>To Twoje słowa. Twój blog. Twoje zasady.</strong><br><br>
108
+ Zacznij pisać — i odzyskaj głos.</p>
109
+ </p>
110
+ </article>
111
+ <div class="action-links">
112
+ <a class="btn purple" href="/register">Zarejestruj się tutaj</a>
113
+ <span class="or-separator">lub</span>
114
+ <a class="btn empty" href="https://main.openwrite.io/hosting">Samodzielny hosting</a>
115
+ </div>
116
+ """
117
+
118
+ hometext_en = """
119
+ <h1 class="centered"><span style="color: #f2d2c8">quiet</span> space for <span style="color: #5a36bf">loud</span> thoughts.</h1>
120
+
121
+ <article class="main-content" style="text-align: center">
122
+ <p><strong>Openwrite</strong> is a lightweight, open-source blogging platform built for people who just want to write — without ads, trackers, or bloated nonsense.</p><br>
123
+
124
+ - Write in Markdown<br>
125
+ - Self-host in minutes<br>
126
+ - Publish to the open web, Gemini, or Mastodon — your choice<br>
127
+
128
+ <br>
129
+ <p>There’s no analytics. No hidden scripts. No engagement traps.<br>
130
+ Just you, your thoughts, and an honest place to share them.</p>
131
+ <p>Choose a theme. Add images. Track views.<br>
132
+ Build your blog your way — minimal or feature-rich.</p>
133
+ <p><strong>It’s your voice. Your blog. Your rules.</strong><br><br>
134
+ Start writing — and own your words.</p>
135
+ </article>
136
+ <div class="action-links">
137
+ <a class="btn purple" href="/register">Register Here</a>
138
+ <span class="or-separator">or</span>
139
+ <a class="btn empty" href="https://main.openwrite.io/hosting">Self Host</a>
140
+ </div>
141
+ """
142
+
143
+ with open(f"{file_cwd}/utils/i18n.json", "r", encoding='utf-8') as f:
144
+ data = json.load(f)
145
+
146
+ for lang, entries in data.items():
147
+ for key, value in entries.items():
148
+ SessionLocal.add(Home(language=lang, name=key, type="translation", content=value))
149
+
150
+ new_setting = Settings(name="logo", value="/static/logo.png")
151
+ new_home_pl = Home(language="pl", name="hometext", type="text", content=hometext_pl)
152
+ new_home_en = Home(language="en", name="hometext", type="text", content=hometext_en)
153
+ SessionLocal.add(new_setting)
154
+ SessionLocal.add(new_home_pl)
155
+ SessionLocal.add(new_home_en)
156
+ SessionLocal.commit()
157
+
158
+ if test_config is None:
159
+ with open(".initialized", "w") as f:
160
+ f.write("ok")
161
+
162
+ app = Flask(__name__, template_folder="templates", subdomain_matching=True, static_url_path='/static')
163
+ app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_port=1)
164
+ app.secret_key = os.getenv("SECRET_KEY")
165
+ app.config['SERVER_NAME'] = os.getenv("DOMAIN")
166
+
167
+ from .routes.auth import auth_bp
168
+ from .routes.dashboard import dashboard_bp
169
+ from .routes.blog import blog_bp
170
+ from .routes.admin import admin_bp
171
+ from .routes.main import main_bp
172
+ from .routes.upload import upload_bp
173
+ from .routes.federation import federation_bp
174
+ from .utils.db import init_engine, SessionLocal
175
+ from flask_cors import CORS
176
+
177
+ CORS(app)
178
+
179
+ init_engine(db_type, db_path)
180
+ from .utils.db import SessionLocal
181
+
182
+ app.register_blueprint(auth_bp)
183
+ app.register_blueprint(dashboard_bp)
184
+ app.register_blueprint(blog_bp)
185
+ app.register_blueprint(admin_bp)
186
+ app.register_blueprint(main_bp)
187
+ app.register_blueprint(upload_bp)
188
+ app.register_blueprint(federation_bp)
189
+
190
+ def _(key: str):
191
+ return g.trans.get(key, key)
192
+
193
+ app.jinja_env.globals['_'] = _
194
+
195
+ @app.before_request
196
+ def before():
197
+ from flask import request, session
198
+ from openwrite.utils.models import Home, Settings
199
+ g.db = SessionLocal
200
+ t_query = g.db.query(distinct(Home.language)).all()
201
+ translations = [row[0] for row in t_query]
202
+ lang = request.cookies.get("lang")
203
+ if not lang or lang not in translations:
204
+ accept = request.headers.get("Accept-Language", "")
205
+ for part in accept.split(","):
206
+ code = part.split("-")[0].strip().lower()
207
+ if code in translations:
208
+ lang = code
209
+ break
210
+ if lang not in translations:
211
+ lang = "en"
212
+
213
+ trans = g.db.query(Home).filter(Home.type == "translation", Home.language == lang).all()
214
+
215
+ g.mode = os.getenv("MODE")
216
+ f_abs_path = os.path.abspath(__file__)
217
+ g.mainpath = "/".join(f_abs_path.split("/")[:-1])
218
+ g.trans = {t.name: t.content for t in trans if len(t.content) > 1}
219
+ g.alltrans = translations
220
+ g.lang = lang
221
+ g.main_domain = os.getenv("DOMAIN")
222
+ g.blog_limit = os.getenv("BLOG_LIMIT")
223
+ g.register_enabled = os.getenv("SELF_REGISTER", "no") == "yes"
224
+ g.upload_enabled = os.getenv("MEDIA_UPLOAD", "no") == "yes"
225
+ g.captcha = os.getenv("CAPTCHA_ENABLED", "no") == "yes"
226
+ g.fcaptcha_sitekey = os.getenv("FRIENDLY_CAPTCHA_SITEKEY", "key")
227
+ g.fcaptcha_apikey = os.getenv("FRIENDLY_CAPTCHA_APIKEY", "api_key")
228
+ g.staticdir = app.static_folder
229
+ g.staticurl = app.static_url_path
230
+ g.settings = g.db.query(Settings).all()
231
+
232
+ if session.get("userid") is not None:
233
+ g.user = session.get("userid")
234
+ g.isadmin = session.get("admin")
235
+ else:
236
+ g.user = None
237
+
238
+ g.nonce = generate_nonce()
239
+
240
+ @app.context_processor
241
+ def inject_globals():
242
+ from openwrite.utils.models import Home
243
+ langs = g.db.query(Home).filter_by(name="lang_name").all()
244
+ lang_obj = {}
245
+ for l in langs:
246
+ lang_obj[l.language] = {"name": l.content}
247
+ return {
248
+ 'current_lang': g.lang,
249
+ 'available_languages': lang_obj
250
+ }
251
+
252
+ @app.after_request
253
+ def after(response):
254
+ nonce = g.nonce
255
+ #response.headers["Content-Security-Policy"] = (
256
+ # f"default-src 'none'; "
257
+ # f"script-src 'self' 'nonce-{nonce}' https://cdn.jsdelivr.net http://{g.main_domain}"
258
+ # f"style-src 'self'; "
259
+ # f"style-src-elem 'self' http://{g.main_domain}; "
260
+ # f"style-src-attr 'unsafe-inline';"
261
+ # f"script-src-attr 'unsafe-inline';"
262
+ # f"img-src 'self' data: http://{g.main_domain}; "
263
+ # f"font-src 'self'; "
264
+ # f"connect-src 'self'; "
265
+ # f"base-uri 'none'; "
266
+ # f"form-action 'self'; "
267
+ # f"frame-ancestors 'none';"
268
+ # f"frame-src https://global.frcapi.com ;"
269
+ #)
270
+ return response
271
+
272
+ @app.errorhandler(Exception)
273
+ def handle_exception(e):
274
+ if isinstance(e, HTTPException):
275
+ return e
276
+
277
+ app.logger.exception(f"Unhandled exception! {e}")
278
+ return "Internal Server Error", 500
279
+
280
+ @app.teardown_appcontext
281
+ def shutdown_session(exception=None):
282
+ g.db.remove()
283
+
284
+ return app
@@ -13,6 +13,8 @@ from cryptography.hazmat.primitives.asymmetric import rsa
13
13
  from cryptography.hazmat.primitives import serialization
14
14
  from datetime import datetime, timezone
15
15
  import bcrypt
16
+ import json
17
+ import shutil
16
18
 
17
19
  load_dotenv()
18
20
  f_abs_path = os.path.abspath(__file__)
@@ -87,9 +89,9 @@ def init():
87
89
  os.makedirs(f"{cwd}/gemini/.certs", exist_ok=True)
88
90
  subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:4096", "-keyout", f"{cwd}/gemini/.certs/key.pem", "-out", f"{cwd}/gemini/.certs/cert.pem", "-days", "365", "-nodes", "-subj", f"/CN={domain}"], check=True)
89
91
  if mode == 1:
90
- os.rename(f"{lib_cwd}/gemini_multi.py", f"{cwd}/gemini/mod/10_openwrite.py")
92
+ shutil.copyfile(f"{lib_cwd}/gemini_multi.py", f"{cwd}/gemini/mod/10_openwrite.py")
91
93
  elif mode == 2:
92
- os.rename(f"{lib_cwd}/gemini_single.py", f"{cwd}/gemini/mod/10_openwrite.py")
94
+ shutil.copyfile(f"{lib_cwd}/gemini_single.py", f"{cwd}/gemini/mod/10_openwrite.py")
93
95
 
94
96
  logs_enabled = click.confirm("Enable logging?", default=True)
95
97
  if logs_enabled:
@@ -138,70 +140,15 @@ def init():
138
140
  gem.write(f"modules = {cwd}/gemini/mod\n")
139
141
  f.write(f"LOGS={'yes' if logs_enabled else 'no'}\n")
140
142
  if logs_enabled:
141
- f.write(f"LOGS_DIR={logs_dir}")
143
+ f.write(f"LOGS_DIR={logs_dir}\n")
142
144
  f.write(f"CAPTCHA_ENABLED={'yes' if captcha_enabled else 'no'}\n")
143
145
  if captcha_enabled:
144
146
  f.write(f"FRIENDLY_CAPTCHA_SITEKEY={captcha_sitekey}\n")
145
147
  f.write(f"FRIENDLY_CAPTCHA_APIKEY={captcha_apikey}\n")
146
148
 
147
149
  click.echo("[+] .env file created")
148
- click.echo("[*] Initializing database..")
149
- init_db(dbtype, dbpath)
150
- click.echo("[+] Database initialized")
151
- click.echo("[*] Adding admin user...")
152
- from .utils.models import User, Blog, Post, Settings
153
- from .utils.db import init_engine, SessionLocal
154
- init_engine(dbtype, dbpath)
155
- from .utils.db import SessionLocal
156
- admin_password = os.urandom(16).hex()
157
- hashed = bcrypt.hashpw(admin_password.encode("utf-8"), bcrypt.gensalt())
158
- admin_user = User(username="admin", email="", password_hash=hashed.decode("utf-8"), verified=1, admin=1)
159
- SessionLocal.add(admin_user)
160
- SessionLocal.commit()
161
- SessionLocal.close()
162
- click.echo(f"[+] Admin user added! Your credentials:\n\nLogin: admin\nPassword: {admin_password}")
163
150
  if logs_enabled and not os.path.exists(logs_dir):
164
151
  os.makedirs(logs_dir, exist_ok=True)
165
-
166
- if mode == 2:
167
- key = rsa.generate_private_key(
168
- public_exponent=65537,
169
- key_size=2048
170
- )
171
-
172
- private_pem = key.private_bytes(
173
- encoding=serialization.Encoding.PEM,
174
- format=serialization.PrivateFormat.PKCS8,
175
- encryption_algorithm=serialization.NoEncryption()
176
- ).decode()
177
-
178
- public_pem = key.public_key().public_bytes(
179
- encoding=serialization.Encoding.PEM,
180
- format=serialization.PublicFormat.SubjectPublicKeyInfo
181
- ).decode()
182
-
183
- now = datetime.now(timezone.utc)
184
-
185
- new_blog = Blog(
186
- owner=1,
187
- name="default",
188
- title=domain,
189
- index="on",
190
- access="domain",
191
- description_raw=f"![hello](https://openwrite.b-cdn.net/hello.jpg =500x258)\n\n# Hello there! 👋\n\nYou can edit your blog description in [dashboard](http://{domain}/dashboard/edit/default)",
192
- description_html=f"<p><img src=\"https://openwrite.b-cdn.net/hello.jpg\" width=\"500\" height=\"258\"></p><h1>Hello there! 👋</h1><p>You can edit your blog description in <a href=\"http://{domain}/dashboard/edit/default\">dashboard</a></p>",
193
- css="",
194
- pub_key=public_pem,
195
- priv_key=private_pem,
196
- theme="default",
197
- created=now
198
- )
199
-
200
- new_setting = Settings(name="logo", value="/static/logo.png")
201
-
202
- SessionLocal.add(new_blog)
203
- SessionLocal.add(new_setting)
204
- SessionLocal.commit()
205
152
 
206
153
  @cli.command()
207
154
  @click.option("-d", "--daemon", is_flag=True, help="Run in background (daemon)")
@@ -267,10 +214,12 @@ def run(daemon):
267
214
 
268
215
  try:
269
216
  gunicorn_proc.wait()
270
- gemini_proc.wait()
217
+ if gemini:
218
+ gemini_proc.wait()
271
219
  except KeyboardInterrupt:
272
220
  gunicorn_proc.terminate()
273
- gemini_proc.terminate()
221
+ if gemini:
222
+ gemini_proc.terminate()
274
223
 
275
224
  @cli.command()
276
225
  def debugrun():
@@ -320,7 +269,7 @@ def stop(service):
320
269
  click.echo("[*] Searching Gunicorn processes")
321
270
  try:
322
271
  out = subprocess.check_output(["pgrep", "-f", "gunicorn.*openwrite:create_app"], text=True)
323
- out_gemini = subprocess.check_output(["pgrep", "-f", "gemini\.py"], text=True)
272
+ out_gemini = subprocess.check_output(["pgrep", "-f", "gmcapsuled"], text=True)
324
273
  pids = out.strip().splitlines()
325
274
  pids_gemini = out_gemini.strip().splitlines()
326
275
  for pid in pids:
@@ -113,5 +113,3 @@ def init(capsule):
113
113
  capsule.add("/b/*",
114
114
  blog_index,
115
115
  protocol='gemini')
116
-
117
-
@@ -80,5 +80,3 @@ def init(capsule):
80
80
  capsule.add("/p/*",
81
81
  blog_post,
82
82
  protocol='gemini')
83
-
84
-
@@ -1,10 +1,12 @@
1
- from flask import Blueprint, render_template, redirect, g, request
1
+ from flask import Blueprint, render_template, redirect, g, request, make_response
2
+ import json
2
3
  from openwrite.utils.models import Blog, User, Settings, Home
3
4
  import re
4
5
  import bcrypt
5
6
  from werkzeug.utils import secure_filename
6
7
  from PIL import Image
7
8
  import os
9
+ from collections import defaultdict
8
10
 
9
11
  admin_bp = Blueprint("admin", __name__)
10
12
 
@@ -12,6 +14,9 @@ ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "webp"}
12
14
 
13
15
  @admin_bp.route("/admin")
14
16
  def admin():
17
+ """
18
+ Admin dashboard to manage blogs and users.
19
+ """
15
20
  if g.user is None or g.isadmin == 0 or g.mode == "single":
16
21
  return redirect("/")
17
22
 
@@ -25,6 +30,9 @@ def admin():
25
30
 
26
31
  @admin_bp.route("/admin/delete_blog/<blog>")
27
32
  def admin_delete_blog(blog):
33
+ """
34
+ Delete a blog by its name.
35
+ """
28
36
  if g.user is None or g.isadmin == 0 or g.mode == "single":
29
37
  return redirect("/")
30
38
 
@@ -37,6 +45,9 @@ def admin_delete_blog(blog):
37
45
 
38
46
  @admin_bp.route("/admin/delete_user/<username>")
39
47
  def admin_delete_user(username):
48
+ """
49
+ Delete a user and all their blogs.
50
+ """
40
51
  if g.user is None or g.isadmin == 0 or g.mode == "single":
41
52
  return redirect("/")
42
53
 
@@ -58,6 +69,9 @@ def admin_delete_user(username):
58
69
 
59
70
  @admin_bp.route("/admin/make_admin/<username>")
60
71
  def admin_make_admin(username):
72
+ """
73
+ Grant admin privileges to a user.
74
+ """
61
75
  if g.user is None or g.isadmin == 0 or g.mode == "single":
62
76
  return redirect("/")
63
77
 
@@ -72,6 +86,9 @@ def admin_make_admin(username):
72
86
 
73
87
  @admin_bp.route("/admin/remove_admin/<username>")
74
88
  def admin_remove_admin(username):
89
+ """
90
+ Remove admin privileges from a user.
91
+ """
75
92
  if g.user is None or g.isadmin == 0 or g.mode == "single":
76
93
  return redirect("/")
77
94
 
@@ -89,6 +106,9 @@ def admin_remove_admin(username):
89
106
 
90
107
  @admin_bp.route("/admin/add_user", methods=['GET', 'POST'])
91
108
  def admin_add_user():
109
+ """
110
+ Add a new user to the system.
111
+ """
92
112
  if g.user is None or g.isadmin == 0 or g.mode == "single":
93
113
  return redirect("/")
94
114
  if request.method == "GET":
@@ -121,6 +141,9 @@ def admin_add_user():
121
141
 
122
142
  @admin_bp.route("/admin/settings", methods=['GET', 'POST'])
123
143
  def admin_settings():
144
+ """
145
+ Manage application settings.
146
+ """
124
147
  if g.user is None or g.isadmin == 0 or g.mode == "single":
125
148
  return redirect("/")
126
149
 
@@ -164,7 +187,62 @@ def admin_settings():
164
187
  logo_q.value = f"{g.staticurl}/{filename}"
165
188
  g.db.commit()
166
189
  settings_dict['logo'] = f"{g.staticurl}/{filename}"
167
- for h in hometext:
168
- h.content = hometexts[h.language]
190
+ g.db.query(Home).filter_by(name="hometext").delete()
191
+ for h in hometexts.keys():
192
+ g.db.add(Home(name="hometext", language=h, type="text", content=hometexts[h]))
169
193
  g.db.commit()
170
- return render_template("settings.html", settings=settings_dict, hometext=hometext)
194
+ new_hometexts = g.db.query(Home).filter_by(name="hometext").all()
195
+ return render_template("settings.html", settings=settings_dict, hometext=new_hometexts)
196
+
197
+ @admin_bp.route("/admin/translations", methods=['GET', 'POST'])
198
+ def translations():
199
+ """
200
+ Manage translations for the application.
201
+ Allows viewing, editing, and saving translations.
202
+ (I can't believe I didn't secured it earlier lol)
203
+ """
204
+ if g.user is None or g.isadmin == 0 or g.mode == "single":
205
+ return redirect("/")
206
+
207
+ if request.method == "GET":
208
+ trans = g.db.query(Home).filter_by(type="translation").all()
209
+ grouped = defaultdict(dict)
210
+ for t in trans:
211
+ grouped[t.name][t.language] = t.content
212
+ return render_template("translations.html", trans=grouped, langs=g.alltrans)
213
+
214
+ trans_array = []
215
+ for key, val in request.form.items():
216
+ if key.startswith("val_"):
217
+ _, name, lang = key.split("___", 2)
218
+ trans_array.append({
219
+ "name": name,
220
+ "language": lang,
221
+ "content": val
222
+ })
223
+
224
+ g.db.query(Home).filter(Home.type == "translation").delete()
225
+
226
+ for tr in trans_array:
227
+ g.db.add(Home(name=tr['name'], language=tr['language'], content=tr['content'], type="translation"))
228
+
229
+ g.db.commit()
230
+ return redirect("/admin/translations")
231
+
232
+ @admin_bp.route("/admin/download_translations")
233
+ def download_translations():
234
+ """
235
+ Download all translations as a json file.
236
+ """
237
+ if g.user is None or g.isadmin == 0 or g.mode == "single":
238
+ return redirect("/")
239
+
240
+ translations = g.db.query(Home).filter_by(type="translation").all()
241
+ trans_dict = defaultdict(dict)
242
+ for t in translations:
243
+ trans_dict[t.language][t.name] = t.content
244
+
245
+ response = make_response(json.dumps(dict(trans_dict), ensure_ascii=False))
246
+ response.headers["Content-Disposition"] = "attachment; filename=i18n.json"
247
+ response.headers["Content-Type"] = "application/json"
248
+ return response
@@ -25,7 +25,7 @@ def register():
25
25
  form_password2 = request.form.get('password2')
26
26
 
27
27
  if form_password != form_password2:
28
- return render_template("register.html", error=g.trans['password_dont_match'])
28
+ return render_template("register.html", error=g.trans['passwords_dont_match'])
29
29
 
30
30
  user = g.db.query(User).filter_by(username=form_username).first()
31
31
  if user: