mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	path to document file is now configurable, flask secret is now also taken from configuration
This commit is contained in:
		| @@ -1,3 +1,10 @@ | |||||||
|  | [Document] | ||||||
|  | documentPath=demo.ncdb | ||||||
|  |  | ||||||
|  | [Security] | ||||||
|  | # run python generate-secret-key.py and paste the result below | ||||||
|  | flaskSecretKey= | ||||||
|  |  | ||||||
| [Network] | [Network] | ||||||
| port=5000 | port=5000 | ||||||
| certPath=cert.crt | certPath=cert.crt | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								generate-secret-key.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								generate-secret-key.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | #!/usr/bin/python | ||||||
|  | import os | ||||||
|  | import base64 | ||||||
|  |  | ||||||
|  | print(base64.b64encode(os.urandom(24))) | ||||||
							
								
								
									
										5
									
								
								run.sh
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								run.sh
									
									
									
									
									
								
							| @@ -1,6 +1,3 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
|  |  | ||||||
| export FLASK_DEBUG=0 | python src/app.py | ||||||
| export FLASK_APP=src/app.py |  | ||||||
|  |  | ||||||
| flask run |  | ||||||
							
								
								
									
										22
									
								
								src/app.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/app.py
									
									
									
									
									
								
							| @@ -1,22 +1,27 @@ | |||||||
|  | import os | ||||||
|  |  | ||||||
| import bcrypt | import bcrypt | ||||||
| import configparser | import configparser | ||||||
| import os |  | ||||||
| from flask import Flask, request, send_from_directory | from flask import Flask, request, send_from_directory | ||||||
| from flask import render_template, redirect | from flask import render_template, redirect | ||||||
| from flask_cors import CORS | from flask_cors import CORS | ||||||
| from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user | from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user | ||||||
| from flask_restful import Api | from flask_restful import Api | ||||||
|  |  | ||||||
|  | from expanded_note import ExpandedNote | ||||||
| from move_after_note import MoveAfterNote | from move_after_note import MoveAfterNote | ||||||
|  | from move_before_note import MoveBeforeNote | ||||||
| from move_to_note import MoveToNote | from move_to_note import MoveToNote | ||||||
| from notes import Notes | from notes import Notes | ||||||
| from notes_children import NotesChildren | from notes_children import NotesChildren | ||||||
|  | from sql import connect | ||||||
| from expanded_note import ExpandedNote |  | ||||||
| from move_before_note import MoveBeforeNote |  | ||||||
| from tree import Tree | from tree import Tree | ||||||
|  |  | ||||||
|  | config = configparser.ConfigParser() | ||||||
|  | config.read('config.ini') | ||||||
|  |  | ||||||
| app = Flask(__name__) | app = Flask(__name__) | ||||||
| app.secret_key = 'dshjkjsdhfk9832fsdlhf' | app.secret_key = config['Security']['flaskSecretKey'] | ||||||
|  |  | ||||||
| class User(UserMixin): | class User(UserMixin): | ||||||
|     pass |     pass | ||||||
| @@ -36,9 +41,6 @@ def logout(): | |||||||
|     logout_user() |     logout_user() | ||||||
|     return redirect('login') |     return redirect('login') | ||||||
|  |  | ||||||
| config = configparser.ConfigParser() |  | ||||||
| config.read('config.ini') |  | ||||||
|  |  | ||||||
| user = User() | user = User() | ||||||
| user.id = config['Login']['username'] | user.id = config['Login']['username'] | ||||||
|  |  | ||||||
| @@ -46,6 +48,10 @@ port = config['Network']['port'] | |||||||
| certPath = config['Network']['certPath'] | certPath = config['Network']['certPath'] | ||||||
| certKeyPath = config['Network']['certKeyPath'] | certKeyPath = config['Network']['certKeyPath'] | ||||||
|  |  | ||||||
|  | documentPath = config['Document']['documentPath'] | ||||||
|  |  | ||||||
|  | connect(documentPath) | ||||||
|  |  | ||||||
| hashedPassword = config['Login']['password-hash'].encode('utf-8') | hashedPassword = config['Login']['password-hash'].encode('utf-8') | ||||||
|  |  | ||||||
| @app.route('/login', methods=['POST']) | @app.route('/login', methods=['POST']) | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import sqlite3 |  | ||||||
| import base64 | import base64 | ||||||
|  | import sqlite3 | ||||||
|  |  | ||||||
| def dict_factory(cursor, row): | def dict_factory(cursor, row): | ||||||
|     d = {} |     d = {} | ||||||
| @@ -11,8 +11,10 @@ def dict_factory(cursor, row): | |||||||
|  |  | ||||||
|     return d |     return d | ||||||
|  |  | ||||||
| conn = sqlite3.connect('demo.ncdb') | def connect(documentPath): | ||||||
| conn.row_factory = dict_factory |     global conn | ||||||
|  |     conn = sqlite3.connect(documentPath) | ||||||
|  |     conn.row_factory = dict_factory | ||||||
|  |  | ||||||
| def insert(tablename, rec): | def insert(tablename, rec): | ||||||
|     keys = ','.join(rec.keys()) |     keys = ','.join(rec.keys()) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user