2014-05-04 17:26:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import ed25519
|
|
|
|
|
2016-01-05 16:14:57 +00:00
|
|
|
from oml.pdict import pdict
|
|
|
|
from oml.utils import get_user_id
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
|
|
|
|
static_path = os.path.join(base_dir, 'static')
|
2014-08-05 09:47:16 +00:00
|
|
|
updates_path = os.path.normpath(os.path.join(base_dir, '..', 'updates'))
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
oml_config_path = os.path.join(base_dir, 'config.json')
|
|
|
|
|
2014-08-07 09:46:23 +00:00
|
|
|
config_path = os.path.normpath(os.path.join(base_dir, '..', 'config'))
|
|
|
|
if not os.path.exists(config_path):
|
|
|
|
os.makedirs(config_path)
|
2014-05-04 17:26:43 +00:00
|
|
|
|
2014-08-07 09:46:23 +00:00
|
|
|
db_path = os.path.join(config_path, 'data.db')
|
2015-03-07 13:47:12 +00:00
|
|
|
log_path = os.path.join(config_path, 'debug.log')
|
2014-08-07 09:46:23 +00:00
|
|
|
icons_db_path = os.path.join(config_path, 'icons.db')
|
|
|
|
key_path = os.path.join(config_path, 'node.key')
|
|
|
|
ssl_cert_path = os.path.join(config_path, 'node.ssl.crt')
|
2015-11-26 00:26:10 +00:00
|
|
|
ssl_key_path = os.path.join(config_path, 'tor', 'private_key')
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(oml_config_path):
|
|
|
|
with open(oml_config_path) as fd:
|
|
|
|
config = json.load(fd)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
|
2014-08-07 09:46:23 +00:00
|
|
|
preferences = pdict(os.path.join(config_path, 'preferences.json'), config['user']['preferences'])
|
|
|
|
ui = pdict(os.path.join(config_path, 'ui.json'), config['user']['ui'])
|
2016-01-05 16:14:57 +00:00
|
|
|
list_cache = pdict(os.path.join(config_path, 'list_cache.json'), {})
|
2014-05-04 17:26:43 +00:00
|
|
|
|
2014-08-07 09:46:23 +00:00
|
|
|
server = pdict(os.path.join(config_path, 'server.json'))
|
2014-05-04 17:26:43 +00:00
|
|
|
server_defaults = {
|
|
|
|
'port': 9842,
|
2015-02-22 11:23:06 +00:00
|
|
|
'address': '127.0.0.1',
|
2014-05-04 17:26:43 +00:00
|
|
|
'node_port': 9851,
|
2014-05-12 12:57:47 +00:00
|
|
|
'node_address': '',
|
2014-05-04 17:26:43 +00:00
|
|
|
'extract_text': True,
|
2014-05-14 23:28:49 +00:00
|
|
|
'localnode_discovery': True,
|
2014-05-04 17:26:43 +00:00
|
|
|
'directory_service': 'http://[2a01:4f8:120:3201::3]:25519',
|
2014-05-22 09:06:30 +00:00
|
|
|
'meta_service': 'http://meta.openmedialibrary.com/api/',
|
2014-12-13 17:05:00 +00:00
|
|
|
'release_url': 'http://downloads.openmedialibrary.com/release.json',
|
2014-05-04 17:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for key in server_defaults:
|
|
|
|
if key not in server:
|
|
|
|
server[key] = server_defaults[key]
|
|
|
|
|
2014-08-07 09:46:23 +00:00
|
|
|
release = pdict(os.path.join(config_path, 'release.json'))
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
if os.path.exists(key_path):
|
2014-09-02 22:32:44 +00:00
|
|
|
with open(key_path, 'rb') as fd:
|
2014-05-04 17:26:43 +00:00
|
|
|
sk = ed25519.SigningKey(fd.read())
|
|
|
|
vk = sk.get_verifying_key()
|
|
|
|
else:
|
|
|
|
sk, vk = ed25519.create_keypair()
|
2014-09-02 22:32:44 +00:00
|
|
|
with open(key_path, 'wb') as fd:
|
|
|
|
os.chmod(key_path, 0o600)
|
2014-05-04 17:26:43 +00:00
|
|
|
fd.write(sk.to_bytes())
|
2014-09-02 22:32:44 +00:00
|
|
|
os.chmod(key_path, 0o400)
|
2014-05-04 17:26:43 +00:00
|
|
|
|
2015-11-26 00:26:10 +00:00
|
|
|
USER_ID = get_user_id(ssl_key_path, ssl_cert_path)
|
|
|
|
OLD_USER_ID = vk.to_ascii(encoding='base64').decode()
|
|
|
|
|
2014-08-05 09:47:16 +00:00
|
|
|
OML_UPDATE_KEY='K55EZpPYbP3X+3mA66cztlw1sSaUMqGwfTDKQyP2qOU'
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
if 'modules' in release and 'openmedialibrary' in release['modules']:
|
2014-05-21 22:41:29 +00:00
|
|
|
MINOR_VERSION = release['modules']['openmedialibrary']['version']
|
2014-05-04 17:26:43 +00:00
|
|
|
else:
|
2014-05-21 22:41:29 +00:00
|
|
|
MINOR_VERSION = 'git'
|
|
|
|
|
2016-01-08 17:49:00 +00:00
|
|
|
NODE_PROTOCOL="0.3"
|
2014-05-21 22:41:29 +00:00
|
|
|
VERSION="%s.%s" % (NODE_PROTOCOL, MINOR_VERSION)
|
|
|
|
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
|
2015-11-29 16:07:01 +00:00
|
|
|
|
|
|
|
DEBUG_HTTP = server.get('debug_http', False)
|