renamed onionr dir and bugfixes/linting progress

This commit is contained in:
Kevin Froman 2019-11-20 04:52:50 -06:00
parent 2b996da17f
commit 720efe4fca
226 changed files with 179 additions and 142 deletions

View file

@ -0,0 +1,3 @@
from . import defaultpluginsetup, setupconfig
setup_default_plugins = defaultpluginsetup.setup_default_plugins
setup_config = setupconfig.setup_config

183
src/onionrsetup/dbcreator.py Executable file
View file

@ -0,0 +1,183 @@
'''
Onionr - Private P2P Communication
DBCreator, creates sqlite3 databases used by Onionr
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import sqlite3, os
from coredb import dbfiles
import filepaths
def createAddressDB():
'''
Generate the address database
types:
1: I2P b32 address
2: Tor v2 (like facebookcorewwwi.onion)
3: Tor v3
'''
if os.path.exists(dbfiles.address_info_db):
raise FileExistsError("Address database already exists")
conn = sqlite3.connect(dbfiles.address_info_db)
c = conn.cursor()
c.execute('''CREATE TABLE adders(
address text,
type int,
knownPeer text,
speed int,
success int,
powValue text,
failure int,
lastConnect int,
lastConnectAttempt int,
trust int,
introduced int
);
''')
conn.commit()
conn.close()
def createPeerDB():
'''
Generate the peer sqlite3 database and populate it with the peers table.
'''
if os.path.exists(dbfiles.user_id_info_db):
raise FileExistsError("User database already exists")
# generate the peer database
conn = sqlite3.connect(dbfiles.user_id_info_db)
c = conn.cursor()
c.execute('''CREATE TABLE peers(
ID text not null,
name text,
adders text,
dateSeen not null,
trust int,
hashID text);
''')
c.execute('''CREATE TABLE forwardKeys(
peerKey text not null,
forwardKey text not null,
date int not null,
expire int not null
);''')
conn.commit()
conn.close()
return
def createBlockDB():
'''
Create a database for blocks
hash - the hash of a block
dateReceived - the date the block was recieved, not necessarily when it was created
decrypted - if we can successfully decrypt the block (does not describe its current state)
dataType - data type of the block
dataFound - if the data has been found for the block
dataSaved - if the data has been saved for the block
sig - optional signature by the author (not optional if author is specified)
author - multi-round partial sha3-256 hash of authors public key
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
expire int - block expire date in epoch
'''
if os.path.exists(dbfiles.block_meta_db):
raise FileExistsError("Block database already exists")
conn = sqlite3.connect(dbfiles.block_meta_db)
c = conn.cursor()
c.execute('''CREATE TABLE hashes(
hash text not null,
dateReceived int,
decrypted int,
dataType text,
dataFound int,
dataSaved int,
sig text,
author text,
dateClaimed int,
expire int
);
''')
conn.commit()
conn.close()
return
def createBlockDataDB():
if os.path.exists(dbfiles.block_data_db):
raise FileExistsError("Block data database already exists")
else:
if not os.path.exists(filepaths.block_data_location):
os.mkdir(filepaths.block_data_location)
conn = sqlite3.connect(dbfiles.block_data_db)
c = conn.cursor()
c.execute('''CREATE TABLE blockData(
hash text not null,
data blob not null
);
''')
conn.commit()
conn.close()
def createForwardKeyDB():
'''
Create the forward secrecy key db (*for *OUR* keys*)
'''
if os.path.exists(dbfiles.forward_keys_db):
raise FileExistsError("Block database already exists")
conn = sqlite3.connect(dbfiles.forward_keys_db)
c = conn.cursor()
c.execute('''CREATE TABLE myForwardKeys(
peer text not null,
publickey text not null,
privatekey text not null,
date int not null,
expire int not null
);
''')
conn.commit()
conn.close()
return
def createDaemonDB():
'''
Create the daemon queue database
'''
if os.path.exists(dbfiles.daemon_queue_db):
raise FileExistsError("Daemon queue db already exists")
conn = sqlite3.connect(dbfiles.daemon_queue_db, timeout=10)
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE commands (id integer primary key autoincrement, command text, data text, date text, responseID text)''')
conn.commit()
conn.close()
def create_blacklist_db():
if os.path.exists(dbfiles.blacklist_db):
raise FileExistsError("Blacklist db already exists")
conn = sqlite3.connect(dbfiles.blacklist_db, timeout=10)
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE blacklist(
hash text primary key not null,
dataType int,
blacklistDate int,
expire int
);
''')
conn.commit()
conn.close()
create_funcs = [createAddressDB, createPeerDB, createBlockDB, createBlockDataDB, createForwardKeyDB, createDaemonDB, create_blacklist_db]

View file

@ -0,0 +1,44 @@
"""
Onionr - Private P2P Communication
Installs default plugins
"""
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os, shutil
import onionrplugins as plugins
import logger
import filepaths
def setup_default_plugins():
# Copy default plugins into plugins folder
if not os.path.exists(plugins.get_plugins_folder()):
if os.path.exists('../static-data/default-plugins/'):
names = [f for f in os.listdir("../static-data/default-plugins/")]
shutil.copytree('../static-data/default-plugins/', plugins.get_plugins_folder())
# Enable plugins
for name in names:
if not name in plugins.get_enabled_plugins():
plugins.enable(name)
for name in plugins.get_enabled_plugins():
if not os.path.exists(plugins.get_plugin_data_folder(name)):
try:
os.mkdir(plugins.get_plugin_data_folder(name))
except Exception as e:
#logger.warn('Error enabling plugin: ' + str(e), terminal=True)
plugins.disable(name, stop_event = False)

85
src/onionrsetup/setupconfig.py Executable file
View file

@ -0,0 +1,85 @@
'''
Onionr - Private P2P Communication
Initialize Onionr configuration
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import os, json, base64
import config, logger, netcontroller
from etc import onionrvalues
from logger.settings import *
from utils import readstatic
def setup_config():
if not os.path.exists(config._configfile):
# this is the default config, it will be overwritten if a config file already exists. Else, it saves it
conf_data = readstatic.read_static('default_config.json', ret_bin=False)
config.set_config(json.loads(conf_data))
config.save()
config.reload()
settings = 0b000
if config.get('log.console.color', True):
settings = settings | USE_ANSI
if config.get('log.console.output', True):
settings = settings | OUTPUT_TO_CONSOLE
if config.get('log.file.output', True):
settings = settings | OUTPUT_TO_FILE
set_settings(settings)
verbosity = str(config.get('log.verbosity', 'default')).lower().strip()
if not verbosity in ['default', 'null', 'none', 'nil']:
map = {
str(LEVEL_DEBUG) : LEVEL_DEBUG,
'verbose' : LEVEL_DEBUG,
'debug' : LEVEL_DEBUG,
str(LEVEL_INFO) : LEVEL_INFO,
'info' : LEVEL_INFO,
'information' : LEVEL_INFO,
str(LEVEL_WARN) : LEVEL_WARN,
'warn' : LEVEL_WARN,
'warning' : LEVEL_WARN,
'warnings' : LEVEL_WARN,
str(LEVEL_ERROR) : LEVEL_ERROR,
'err' : LEVEL_ERROR,
'error' : LEVEL_ERROR,
'errors' : LEVEL_ERROR,
str(LEVEL_FATAL) : LEVEL_FATAL,
'fatal' : LEVEL_FATAL,
str(LEVEL_IMPORTANT) : LEVEL_IMPORTANT,
'silent' : LEVEL_IMPORTANT,
'quiet' : LEVEL_IMPORTANT,
'important' : LEVEL_IMPORTANT
}
if verbosity in map:
set_level(map[verbosity])
else:
logger.warn('Verbosity level %s is not valid, using default verbosity.' % verbosity)
if type(config.get('client.webpassword')) is type(None):
config.set('client.webpassword', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
if type(config.get('client.client.port')) is type(None):
randomPort = netcontroller.get_open_port()
config.set('client.client.port', randomPort, savefile=True)
if type(config.get('client.public.port')) is type(None):
randomPort = netcontroller.get_open_port()
config.set('client.public.port', randomPort, savefile=True)
if type(config.get('client.api_version')) is type(None):
config.set('client.api_version', onionrvalues.API_VERSION, savefile=True)