updated for better encryption handling.

This commit is contained in:
Discsearcher
2026-08-28 17:36:07 -04:00
parent e67b4a43bd
commit 4b99ffc448
5 changed files with 44 additions and 13 deletions
+31 -3
View File
@@ -20,6 +20,8 @@ from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.backends import default_backend
import base64
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
app = Flask(__name__)
app.secret_key = os.environ.get('FLASK_SECRET_KEY', 'dev-secret-key-change-in-production')
@@ -221,10 +223,15 @@ def build_directory_tree():
# Add file to current level
if '_files' not in current:
current['_files'] = []
# Check if file is protected
is_protected = is_file_protected(str(rel_path))
current['_files'].append({
'name': filename,
'path': str(rel_path),
'encrypted': is_enc
'encrypted': is_enc,
'protected': is_protected
})
logger.info(f"Built tree for {CONTENT_DIR}: found {file_count} markdown files")
@@ -535,10 +542,31 @@ def status():
'timestamp': datetime.now().isoformat()
})
def setup_scheduler():
"""Set up background scheduler for periodic content scanning."""
scheduler = BackgroundScheduler()
scheduler.add_job(
func=update_search_index,
trigger=IntervalTrigger(seconds=60),
id='update_search_index',
name='Update search index every 60 seconds',
replace_existing=True
)
scheduler.start()
logger.info("Scheduler started: content directory will be scanned every 60 seconds")
return scheduler
if __name__ == '__main__':
# Perform initial index build
logger.info("Initializing markmywords")
update_search_index()
# Start Flask app
app.run(host='0.0.0.0', port=5000, debug=False)
# Start background scheduler for periodic content scanning
scheduler = setup_scheduler()
try:
# Start Flask app
app.run(host='0.0.0.0', port=5000, debug=False)
finally:
# Shut down scheduler on exit
scheduler.shutdown()
+1 -1
View File
@@ -1,7 +1,7 @@
services:
markmywords:
build: .
container_name: markmywords
container_name: markmywords_test
ports:
- "5000:5000"
volumes:
+9 -7
View File
@@ -162,7 +162,9 @@ def encrypt(filepath, password):
os.remove(filepath)
# Update password database with encryption AND protection (same password)
file_key = get_file_key(enc_filepath)
# Normalize file_key to relative path (without CONTENT_DIR prefix)
display_path = enc_filepath.replace(CONTENT_DIR + '/', '')
file_key = get_file_key(display_path)
passwords = load_passwords()
passwords[file_key] = {
@@ -175,7 +177,6 @@ def encrypt(filepath, password):
save_passwords(passwords)
display_path = enc_filepath.replace(CONTENT_DIR + '/', '')
print(f"✓ Encrypted & protected: {filepath} → {display_path}")
return True
@@ -282,7 +283,9 @@ def unprotect(filepath):
if not filepath.startswith(CONTENT_DIR):
filepath = os.path.join(CONTENT_DIR, filepath)
file_key = get_file_key(filepath)
# Normalize file_key to relative path (without CONTENT_DIR prefix)
display_path = filepath.replace(CONTENT_DIR + '/', '')
file_key = get_file_key(display_path)
passwords = load_passwords()
if file_key not in passwords:
@@ -298,7 +301,6 @@ def unprotect(filepath):
del passwords[file_key]['created_at']
if save_passwords(passwords):
display_path = filepath.replace(CONTENT_DIR + '/', '')
print(f"✓ Unprotected: {display_path} (file stays encrypted, viewable in browser)")
return True
else:
@@ -381,14 +383,14 @@ def status(filepath):
if not filepath.startswith(CONTENT_DIR):
filepath = os.path.join(CONTENT_DIR, filepath)
file_key = get_file_key(filepath)
# Normalize file_key to relative path (without CONTENT_DIR prefix)
display_path = filepath.replace(CONTENT_DIR + '/', '')
file_key = get_file_key(display_path)
passwords = load_passwords()
is_encrypted = filepath.endswith('.enc')
is_protected = file_key in passwords and passwords[file_key].get('protected', False)
display_path = filepath.replace(CONTENT_DIR + '/', '')
print(f"\nFile: {display_path}")
print(f"Encrypted: {'Yes' if is_encrypted else 'No'}")
print(f"Protected: {'Yes' if is_protected else 'No'}")
+1
View File
@@ -2,3 +2,4 @@ Flask==3.0.0
markdown==3.5.2
Whoosh==2.7.4
cryptography==41.0.7
APScheduler==3.10.4
+2 -2
View File
@@ -19,8 +19,8 @@
{% if '_files' in tree_dict %}
{% for file in tree_dict['_files'] %}
<li class="tree-file">
<a href="/view/{{ repo_name }}/{{ file.path }}" class="file-link">
📄 {{ file.name }}
<a href="/view/{{ file.path }}" class="file-link">
📄 {{ file.name }}{% if file.protected %} 🔒{% endif %}
</a>
</li>
{% endfor %}