From fff2b7b18f2371b5f54919b435c874afa17eaaca Mon Sep 17 00:00:00 2001 From: Arinerron Date: Mon, 22 Jul 2019 16:59:48 -0700 Subject: [PATCH] master <- easy-releases --- .onionr.yml | 57 ++++ PKGBUILD | 66 ++++- install/build.sh | 4 + install/create_release.py | 52 ++++ install/install_arch.sh | 22 +- install/install_debian.sh | 22 +- install/onionr | 23 +- install/onionr.service | 10 +- install/post_build.sh | 3 + install/post_install.sh | 5 + install/pre_install.sh | 3 + onionr.install | 48 ++++ onionr/PKGBUILD | 0 onionr/config.py | 1 + onionr/core.py | 2 +- onionr/logger.py | 250 ++++++++++++++++++ onionr/netcontroller/netcontrol.py | 1 + onionr/onionr.py | 18 ++ onionr/onionrcommands/__init__.py | 2 +- onionr/onionrcommands/onionrstatistics.py | 6 +- onionr/onionrplugins.py | 6 +- .../static-data/default-plugins/cliui/main.py | 4 +- 22 files changed, 560 insertions(+), 45 deletions(-) create mode 100644 .onionr.yml create mode 100755 install/build.sh create mode 100755 install/create_release.py create mode 100644 install/post_build.sh create mode 100755 install/post_install.sh create mode 100755 install/pre_install.sh create mode 100644 onionr.install create mode 100644 onionr/PKGBUILD create mode 100755 onionr/logger.py diff --git a/.onionr.yml b/.onionr.yml new file mode 100644 index 00000000..7e93ff8d --- /dev/null +++ b/.onionr.yml @@ -0,0 +1,57 @@ +# lazypkg config + +name: onionr +version: 0.1 +release: 1 +summary: anonymous P2P communication platform +description: Onionr is a decentralized, peer-to-peer communication network, designed + to be anonymous and resistant to (meta)data analysis, spam, and corruption. +license: GPL +website: https://onionr.net/ +contact: contact@onionr.net +maintainer: Aaron Esau +maintainer-contact: aur@aaronesau.com + +relationships: +- conflicts: onionr2 + +sources: +- git: https://gitlab.com/beardog/onionr.git + branch: master + +dependencies: +- deb: git + required: true +- deb: curl + required: true +- deb: tor + required: true +- deb: python3.7 + pkgbuild: python + build: true + required: true +- deb: python3-setuptools + pkgbuild: python-setuptools + build: true + required: true +- deb: python3-pip + pkgbuild: python-pip + build: true + required: true + +movements: +- install/onionr: /usr/bin/ + chown: root:root + chmod: 755 +- install/onionr.service: /etc/systemd/system/ + chown: root:root + chmod: 644 +- '.': /usr/share/onionr + chown: root:root + chmod: 755 + +scripts: +- build: install/build.sh +- pre_install: install/pre_install.sh +- post_install: install/post_install.sh + diff --git a/PKGBUILD b/PKGBUILD index c94ca729..ab75bd0b 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,20 +1,60 @@ -url="https://onionr.net/" +# Maintainer: Aaron Esau pkgname="onionr" -pkgver=0.0 -pkgrel=1 -pkgdesc="P2P anonymous storage network" -arch=("x86_64") -license=('GPL') -source=("onionr-${pkgver}::git+https://gitlab.com/beardog/onionr.git#branch=master") -md5sums=('SKIP') -makedepends=('git', 'python3-pip') +pkgver="0.1" +pkgrel="1" +conflicts=("onionr2") +license=("GPL") +arch=("i686" "x86_64") +md5sums=("SKIP") +url="https://onionr.net/" +pkgdesc="anonymous P2P communication platform" +source=("${pkgname}-${pkgver}::git+https://gitlab.com/beardog/onionr.git#branch=master") +makedepends=("python" "python-setuptools" "python-pip") +depends=("git" "curl" "tor") + +rinstall() { + if [ -f "$1" ]; then + install -D "$1" "$2/" "$3" "$4" + return 0 + fi + + for file in $(find "$1" -type f -printf '%P\n'); do + install -D "$1/$file" "$2/$file" "$3" "$4" + done + + return 0 +} + +prepare() { + # pre_build + + cd "${srcdir}/${pkgname}-${pkgver}" + +} build() { - cd "$pkgname-${pkgver}" - make + # build + + cd "${srcdir}/${pkgname}-${pkgver}" + sh install/build.sh +} + +check() { + # post_build + + cd "${srcdir}/${pkgname}-${pkgver}" + } package() { - cd "$pkgname-${pkgver}" - # make install + # "movements" + # ensure target directories exist + mkdir -p "$pkgdir//usr/bin/" + mkdir -p "$pkgdir//etc/systemd/system/" + mkdir -p "$pkgdir//usr/share/onionr" + + # copy files over and change perms + rinstall "${srcdir}/${pkgname}-${pkgver}/install/onionr" "${pkgdir}//usr/bin/" --mode=755 --owner="root" --group="root" + rinstall "${srcdir}/${pkgname}-${pkgver}/install/onionr.service" "${pkgdir}//etc/systemd/system/" --mode=644 --owner="root" --group="root" + rinstall "${srcdir}/${pkgname}-${pkgver}/." "${pkgdir}//usr/share/onionr" --mode=755 --owner="root" --group="root" } diff --git a/install/build.sh b/install/build.sh new file mode 100755 index 00000000..1d316773 --- /dev/null +++ b/install/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +make plugins-reset +find . -name '__pycache__' -type d | xargs rm -rf diff --git a/install/create_release.py b/install/create_release.py new file mode 100755 index 00000000..7c8e2bd4 --- /dev/null +++ b/install/create_release.py @@ -0,0 +1,52 @@ +import os + +version = '' +contents = '' + +with open('../onionr/onionr.py', 'r') as f: + contents = f.read() + version = contents.split("ONIONR_VERSION = '")[1].split("'")[0] + +print('Current Onionr release version is %s (MAJOR.MINOR.VERSION)\n' % version) + +new_version = input('Enter new version: ') + +try: + int(new_version.replace('.', '')) +except: + print('Invalid version number, try again.') + exit(1337) + +confirm = input('Please confirm the version change from %s to %s (y/N): ' % (version, new_version)) + +print('\n------\n') + +if confirm.lower().startswith('y'): + print('- Updating version in onionr.py') + + with open('../onionr/onionr.py', 'w+') as f: + f.write(contents.replace("ONIONR_VERSION = '%s'" % version, "ONIONR_VERSION = '%s'" % new_version)) + + print('- Updating version in PKGBUILD') + + with open('../onionr/PKGBUILD', 'w+') as f: + f.write(f.read().replace("pkgver=%s" % version, "pkgver=%s" % new_version)) + + print('- Committing changes') + + os.system('cd ..; git add onionr/onionr.py; git commit -m "Increment Onionr version to %s"' % new_version) + + print('- Adding tag') + + os.system('cd ..; git tag %s' % new_version) + + print('- Pushing changes') + + # os.system('cd ..; git push origin --tags') + + print('\n------\n\nAll done. Create a merge request into master at this link:\n\nhttps://gitlab.com/beardog/Onionr/merge_requests/new?merge_request%5Bsource_project_id%5D=5020889&merge_request%5Btarget_branch%5D=master&merge_request%5Btarget_project_id%5D=5020889') + + print('\nNOTE: The default configuration file was not changed. Please make sure it is not in dev mode, and that log.verbosity is "error".') +else: + print('Change cancelled. No action has been taken.') + diff --git a/install/install_arch.sh b/install/install_arch.sh index acd3fb1e..15bd698d 100755 --- a/install/install_arch.sh +++ b/install/install_arch.sh @@ -22,27 +22,31 @@ fi # install basic dependencies -pacman --needed --noconfirm -S git curl python python-pip tor +echo -e "\033[0;32mInstalling pacman dependencies...\033[0m" + +! ((pacman --needed --noconfirm -S git curl python python-pip tor > /dev/null) 2>&1 | grep -v warning 1>&2) | grep . # get the repository +echo -e "\033[0;32mCloning Onionr repository...\033[0m" + rm -rf "$OUTPUT_DIR" "$DATA_DIR" "$LOG_DIR" -git clone https://gitlab.com/beardog/onionr "$OUTPUT_DIR" +git clone --quiet https://gitlab.com/beardog/onionr "$OUTPUT_DIR" > /dev/null cd "$OUTPUT_DIR" -git checkout "$BRANCH" +git checkout -q "$BRANCH" > /dev/null # install python dependencies -pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes +echo -e "\033[0;32mInstalling pip dependencies...\033[0m" -# create nologin onionr user if not exists +pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null -id -u onionr &>/dev/null || useradd -r -s /sbin/nologin onionr +# set permissions on Onionr directory chmod 755 "$OUTPUT_DIR" -chown -R onionr:onionr "$OUTPUT_DIR" +chown -R root:root "$OUTPUT_DIR" # create directories @@ -50,7 +54,7 @@ mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR" mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR" chmod -R 750 "$DATA_DIR" "$LOG_DIR" -chown -R onionr:onionr "$DATA_DIR" "$LOG_DIR" +chown -R root:root "$DATA_DIR" "$LOG_DIR" # create executable @@ -61,6 +65,8 @@ chown root:root "$EXECUTABLE" # create systemd service +echo -e "\033[0;32mCreating systemd unit...\033[0m" + SERVICE='/etc/systemd/system/onionr.service' cp "$OUTPUT_DIR/install/onionr.service" "$SERVICE" diff --git a/install/install_debian.sh b/install/install_debian.sh index 4f37f56f..52b4cb24 100755 --- a/install/install_debian.sh +++ b/install/install_debian.sh @@ -22,27 +22,31 @@ fi # install basic dependencies -apt -y install git curl python3.7 python3-pip python3-setuptools tor +echo -e "\033[0;32mInstalling apt dependencies...\033[0m" + +apt-get install -y git curl python3.7 python3-pip python3-setuptools tor > /dev/null # get the repository +echo -e "\033[0;32mCloning Onionr repository...\033[0m" + rm -rf "$OUTPUT_DIR" "$DATA_DIR" "$LOG_DIR" -git clone https://gitlab.com/beardog/onionr "$OUTPUT_DIR" +git clone --quiet https://gitlab.com/beardog/onionr "$OUTPUT_DIR" > /dev/null cd "$OUTPUT_DIR" -git checkout "$BRANCH" +git checkout -q "$BRANCH" > /dev/null # install python dependencies -python3.7 -m pip install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes +echo -e "\033[0;32mInstalling pip dependencies...\033[0m" -# create nologin onionr user if not exists +python3.7 -m pip install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null -id -u onionr &>/dev/null || useradd -r -s /sbin/nologin onionr +# set permissions on Onionr directory chmod 755 "$OUTPUT_DIR" -chown -R onionr:onionr "$OUTPUT_DIR" +chown -R root:root "$OUTPUT_DIR" # create directories @@ -50,7 +54,7 @@ mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR" mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR" chmod -R 750 "$DATA_DIR" "$LOG_DIR" -chown -R onionr:onionr "$DATA_DIR" "$LOG_DIR" +chown -R root:root "$DATA_DIR" "$LOG_DIR" # create executable @@ -61,6 +65,8 @@ chown root:root "$EXECUTABLE" # create systemd service +echo -e "\033[0;32mCreating systemd unit...\033[0m" + SERVICE='/etc/systemd/system/onionr.service' cp "$OUTPUT_DIR/install/onionr.service" "$SERVICE" diff --git a/install/onionr b/install/onionr index 31fd58cc..c50335fa 100755 --- a/install/onionr +++ b/install/onionr @@ -2,11 +2,22 @@ set -e -[ "root" != "$USER" ] && exec sudo $0 "$@" - export OUTPUT_DIR=${OUTPUT_DIR:=/usr/share/onionr} -export ONIONR_HOME=${ONIONR_HOME:=/etc/onionr} -export LOG_DIR=${LOG_DIR:=/var/log/onionr} -cd "$OUTPUT_DIR" -exec su onionr -s /bin/sh -c "./onionr.sh ""$@""" +if [ -n "$HOME" ]; then + export XDG_DATA_HOME=${XDG_DATA_HOME:=$HOME/.local/share/onionr} + + export ONIONR_HOME=${ONIONR_HOME:=$XDG_DATA_HOME} + export LOG_DIR=${LOG_DIR:=$XDG_DATA_HOME/logs} +else + export ONIONR_HOME=${ONIONR_HOME:=/etc/onionr} + export LOG_DIR=${LOG_DIR:=/var/log/onionr} +fi + +mkdir -p "$ONIONR_HOME" "$LOG_DIR" + +chmod -R 700 "$ONIONR_HOME" "$LOG_DIR" +chown -R $USER:$USER "$ONIONR_HOME" "$LOG_DIR" + +cd "$OUTPUT_DIR/onionr" +exec python3.7 onionr.py "$@" diff --git a/install/onionr.service b/install/onionr.service index 0f2a42b6..daaa5c05 100755 --- a/install/onionr.service +++ b/install/onionr.service @@ -1,15 +1,21 @@ [Unit] Description=Onionr Daemon -Requires=network.target tor.service +Documentation=https://onionr.net/docs/ After=network.target tor.service +Requires=network.target tor.service systemd-networkd-wait-online.service [Service] Environment="DATA_DIR=/usr/share/onionr" Environment="LOG_DIR=/var/log/onionr/" + ExecStart=/usr/bin/onionr --start ExecStop=/usr/bin/onionr --stop + +KillMode=mixed +KillSignal=SIGQUIT +TimeoutStopSec=5s Type=simple -Restart=always +Restart=on-abnormal [Install] WantedBy=tor.service diff --git a/install/post_build.sh b/install/post_build.sh new file mode 100644 index 00000000..01289b66 --- /dev/null +++ b/install/post_build.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sh run_tests.sh diff --git a/install/post_install.sh b/install/post_install.sh new file mode 100755 index 00000000..afcf1489 --- /dev/null +++ b/install/post_install.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +systemctl daemon-reload +systemctl enable onionr +systemctl start onionr diff --git a/install/pre_install.sh b/install/pre_install.sh new file mode 100755 index 00000000..f7f5ccbc --- /dev/null +++ b/install/pre_install.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null diff --git a/onionr.install b/onionr.install new file mode 100644 index 00000000..0e3b38db --- /dev/null +++ b/onionr.install @@ -0,0 +1,48 @@ + +pre_install { + # pre_install + + cd "${srcdir}/${pkgname}-${pkgver}" + sh install/pre_install.sh + +} + +post_install { + # post_install + + cd "${srcdir}/${pkgname}-${pkgver}" + sh install/post_install.sh + +} + +pre_upgrade { + # pre_upgrade + + cd "${srcdir}/${pkgname}-${pkgver}" + + +} + +post_upgrade { + # post_upgrade + + cd "${srcdir}/${pkgname}-${pkgver}" + + +} + +pre_remove { + # pre_remove + + cd "${srcdir}/${pkgname}-${pkgver}" + + +} + +post_remove { + # post_remove + + cd "${srcdir}/${pkgname}-${pkgver}" + + +} diff --git a/onionr/PKGBUILD b/onionr/PKGBUILD new file mode 100644 index 00000000..e69de29b diff --git a/onionr/config.py b/onionr/config.py index 98085828..89298e40 100755 --- a/onionr/config.py +++ b/onionr/config.py @@ -20,6 +20,7 @@ import os, json, logger from utils import identifyhome + # set data dir dataDir = identifyhome.identify_home() diff --git a/onionr/core.py b/onionr/core.py index b523c5ff..8d4a8eb3 100755 --- a/onionr/core.py +++ b/onionr/core.py @@ -458,4 +458,4 @@ class Core: self.daemonQueueAdd('announceNode') logger.info('Introduction command will be processed.', terminal=True) else: - logger.warn('No running node detected. Cannot introduce.', terminal=True) \ No newline at end of file + logger.warn('No running node detected. Cannot introduce.', terminal=True) diff --git a/onionr/logger.py b/onionr/logger.py new file mode 100755 index 00000000..34dc4d06 --- /dev/null +++ b/onionr/logger.py @@ -0,0 +1,250 @@ +''' + Onionr - P2P Microblogging Platform & Social network + + This file handles all operations involving logging +''' +''' + 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 . +''' + +import re, sys, time, traceback, os + +class colors: + ''' + This class allows you to set the color if ANSI codes are supported + ''' + reset='\033[0m' + bold='\033[01m' + disable='\033[02m' + underline='\033[04m' + reverse='\033[07m' + strikethrough='\033[09m' + invisible='\033[08m' + italics='\033[3m' + class fg: + black='\033[30m' + red='\033[31m' + green='\033[32m' + orange='\033[33m' + blue='\033[34m' + purple='\033[35m' + cyan='\033[36m' + lightgrey='\033[37m' + darkgrey='\033[90m' + lightred='\033[91m' + lightgreen='\033[92m' + yellow='\033[93m' + lightblue='\033[94m' + pink='\033[95m' + lightcyan='\033[96m' + class bg: + black='\033[40m' + red='\033[41m' + green='\033[42m' + orange='\033[43m' + blue='\033[44m' + purple='\033[45m' + cyan='\033[46m' + lightgrey='\033[47m' + @staticmethod + def filter(data): + return re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]').sub('', str(data)) + +''' + Use the bitwise operators to merge these settings +''' +USE_ANSI = 0b100 +if os.name == 'nt': + USE_ANSI = 0b000 +OUTPUT_TO_CONSOLE = 0b010 +OUTPUT_TO_FILE = 0b001 + +LEVEL_DEBUG = 1 +LEVEL_INFO = 2 +LEVEL_WARN = 3 +LEVEL_ERROR = 4 +LEVEL_FATAL = 5 +LEVEL_IMPORTANT = 6 + +_type = OUTPUT_TO_CONSOLE | USE_ANSI # the default settings for logging +_level = LEVEL_DEBUG # the lowest level to log +_outputfile = 'data/onionr.log' # the file to log to + +def set_settings(type): + ''' + Set the settings for the logger using bitwise operators + ''' + + global _type + _type = type + +def get_settings(): + ''' + Get settings from the logger + ''' + + return _type + +def set_level(level): + ''' + Set the lowest log level to output + ''' + + global _level + _level = level + +def get_level(): + ''' + Get the lowest log level currently being outputted + ''' + + return _level + +def set_file(outputfile): + ''' + Set the file to output to, if enabled + ''' + + global _outputfile + _outputfile = outputfile + +def get_file(): + ''' + Get the file to output to + ''' + + return _outputfile + +def raw(data, fd = sys.stdout, sensitive = False): + ''' + Outputs raw data to console without formatting + ''' + + if get_settings() & OUTPUT_TO_CONSOLE: + ts = fd.write('%s\n' % data) + if get_settings() & OUTPUT_TO_FILE and not sensitive: + try: + with open(_outputfile, "a+") as f: + f.write(colors.filter(data) + '\n') + except OSError: + pass + +def log(prefix, data, color = '', timestamp=True, fd = sys.stdout, prompt = True, sensitive = False): + ''' + Logs the data + prefix : The prefix to the output + data : The actual data to output + color : The color to output before the data + ''' + curTime = '' + if timestamp: + curTime = time.strftime("%m-%d %H:%M:%S") + ' ' + + output = colors.reset + str(color) + ('[' + colors.bold + str(prefix) + colors.reset + str(color) + '] ' if prompt is True else '') + curTime + str(data) + colors.reset + if not get_settings() & USE_ANSI: + output = colors.filter(output) + + raw(output, fd = fd, sensitive = sensitive) + +def readline(message = ''): + ''' + Takes in input from the console, not stored in logs + message: The message to display before taking input + ''' + + color = colors.fg.green + colors.bold + output = colors.reset + str(color) + '... ' + colors.reset + str(message) + colors.reset + + if not get_settings() & USE_ANSI: + output = colors.filter(output) + + sys.stdout.write(output) + + return input() + +def confirm(default = 'y', message = 'Are you sure %s? '): + ''' + Displays an "Are you sure" message, returns True for Y and False for N + message: The confirmation message, use %s for (y/n) + default: which to prefer-- y or n + ''' + + color = colors.fg.green + colors.bold + + default = default.lower() + confirm = colors.bold + if default.startswith('y'): + confirm += '(Y/n)' + else: + confirm += '(y/N)' + confirm += colors.reset + color + + output = colors.reset + str(color) + '... ' + colors.reset + str(message) + colors.reset + + if not get_settings() & USE_ANSI: + output = colors.filter(output) + + sys.stdout.write(output.replace('%s', confirm)) + + inp = input().lower() + + if 'y' in inp: + return True + if 'n' in inp: + return False + else: + return default == 'y' + +# debug: when there is info that could be useful for debugging purposes only +def debug(data, error = None, timestamp = True, prompt = True, sensitive = False, level = LEVEL_DEBUG): + if get_level() <= level: + log('/', data, timestamp = timestamp, prompt = prompt, sensitive = sensitive) + if not error is None: + debug('Error: ' + str(error) + parse_error()) + +# info: when there is something to notify the user of, such as the success of a process +def info(data, timestamp = False, prompt = True, sensitive = False, level = LEVEL_INFO): + if get_level() <= level: + log('+', data, colors.fg.green, timestamp = timestamp, prompt = prompt, sensitive = sensitive) + +# warn: when there is a potential for something bad to happen +def warn(data, error = None, timestamp = True, prompt = True, sensitive = False, level = LEVEL_WARN): + if not error is None: + debug('Error: ' + str(error) + parse_error()) + if get_level() <= level: + log('!', data, colors.fg.orange, timestamp = timestamp, prompt = prompt, sensitive = sensitive) + +# error: when only one function, module, or process of the program encountered a problem and must stop +def error(data, error = None, timestamp = True, prompt = True, sensitive = False, level = LEVEL_ERROR): + if get_level() <= level: + log('-', data, colors.fg.red, timestamp = timestamp, fd = sys.stderr, prompt = prompt, sensitive = sensitive) + if not error is None: + debug('Error: ' + str(error) + parse_error()) + +# fatal: when the something so bad has happened that the program must stop +def fatal(data, error = None, timestamp=True, prompt = True, sensitive = False, level = LEVEL_FATAL): + if not error is None: + debug('Error: ' + str(error) + parse_error(), sensitive = sensitive) + if get_level() <= level: + log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp = timestamp, fd = sys.stderr, prompt = prompt, sensitive = sensitive) + +# returns a formatted error message +def parse_error(): + details = traceback.extract_tb(sys.exc_info()[2]) + output = '' + + for line in details: + output += '\n ... module %s in %s:%i' % (line[2], line[0], line[1]) + + return output diff --git a/onionr/netcontroller/netcontrol.py b/onionr/netcontroller/netcontrol.py index e0b54804..7aed5a9b 100644 --- a/onionr/netcontroller/netcontrol.py +++ b/onionr/netcontroller/netcontrol.py @@ -133,6 +133,7 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) return False logger.info('Finished starting Tor.', terminal=True) + self.readyState = True try: diff --git a/onionr/onionr.py b/onionr/onionr.py index f9b361ab..2d5bf847 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -157,6 +157,12 @@ class Onionr: else: self.header(None) + def cmdHeader(self): + if len(sys.argv) >= 3: + self.header(logger.colors.fg.pink + sys.argv[2].replace('Onionr', logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink)) + else: + self.header(None) + def header(self, message = logger.colors.fg.pink + logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink + ' has started.'): if os.path.exists('static-data/header.txt') and logger.get_level() <= logger.LEVEL_INFO: with open('static-data/header.txt', 'rb') as file: @@ -166,6 +172,17 @@ class Onionr: if not message is None: logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', terminal=True) + def doExport(self, bHash): + exportDir = self.dataDir + 'block-export/' + if not os.path.exists(exportDir): + if os.path.exists(self.dataDir): + os.mkdir(exportDir) + else: + logger.error('Onionr Not initialized') + data = onionrstorage.getData(self.onionrCore, bHash) + with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile: + exportFile.write(data) + def deleteRunFiles(self): try: os.remove(self.onionrCore.publicApiHostFile) @@ -299,6 +316,7 @@ class Onionr: function(ONIONR_TAGLINE, terminal=True) if verbosity >= 2: function('Running on %s %s' % (platform.platform(), platform.release()), terminal=True) + function('Onionr data dir: %s' % self.dataDir) def doPEX(self): '''make communicator do pex''' diff --git a/onionr/onionrcommands/__init__.py b/onionr/onionrcommands/__init__.py index 59c9d6bc..08a47a99 100755 --- a/onionr/onionrcommands/__init__.py +++ b/onionr/onionrcommands/__init__.py @@ -164,4 +164,4 @@ cmd_help = { 'change-id': 'Change active ID', 'open-home': 'Open your node\'s home/info screen', 'reset-tor': 'Delete the Tor data directory. Only do this if Tor never starts.' - } +} diff --git a/onionr/onionrcommands/onionrstatistics.py b/onionr/onionrcommands/onionrstatistics.py index c01c5e1b..47bc7452 100755 --- a/onionr/onionrcommands/onionrstatistics.py +++ b/onionr/onionrcommands/onionrstatistics.py @@ -109,7 +109,7 @@ def show_peers(o_inst): if peers == 'none': print('No current outgoing connections.') else: - print(peers) + logger.info('Peers: %s' % peers) else: - print('Daemon probably not running. Unable to list connected peers.') - break \ No newline at end of file + logger.warn('Daemon probably not running. Unable to list connected peers.') + break diff --git a/onionr/onionrplugins.py b/onionr/onionrplugins.py index a76fc92b..4045dfcf 100755 --- a/onionr/onionrplugins.py +++ b/onionr/onionrplugins.py @@ -20,6 +20,7 @@ import os, re, importlib import onionrevents as events, config, logger from utils import identifyhome + # set data dir dataDir = identifyhome.identify_home() @@ -67,9 +68,10 @@ def enable(name, onionr = None, start_event = True): if not name in enabled_plugins: try: events.call(get_plugin(name), 'enable', onionr) - except ImportError: # Was getting import error on Gitlab CI test "data" + except ImportError as e: # Was getting import error on Gitlab CI test "data" # NOTE: If you are experiencing issues with plugins not being enabled, it might be this resulting from an error in the module # can happen inconsistently (especially between versions) + logger.debug('Failed to enable module; Import error: %s' % e) return False else: enabled_plugins.append(name) @@ -82,6 +84,7 @@ def enable(name, onionr = None, start_event = True): return False else: logger.error('Failed to enable plugin \"%s\", disabling plugin.' % name, terminal=True) + logger.debug('Plugins folder not found: %s' % get_plugins_folder(str(name).lower())) disable(name) return False @@ -169,6 +172,7 @@ def import_module_from_file(full_path_to_module): module_name, module_ext = os.path.splitext(module_file) module_name = module_dir # Module name must be unique otherwise it will get written in other imports + # Get module "spec" from filename spec = importlib.util.spec_from_file_location(module_name,full_path_to_module) diff --git a/onionr/static-data/default-plugins/cliui/main.py b/onionr/static-data/default-plugins/cliui/main.py index c65917c8..d87adeb7 100755 --- a/onionr/static-data/default-plugins/cliui/main.py +++ b/onionr/static-data/default-plugins/cliui/main.py @@ -81,12 +81,12 @@ class OnionrCLIUI: if self.flow_enabled: self.subCommand("flow") else: - print('Plugin not enabled') + logger.warn('flow plugin is not enabled') elif choice in ("2", "mail"): if self.mail_enabled: self.subCommand("mail") else: - print('Plugin not enabled') + logger.warn('mail plugin not enabled') elif choice in ("3", "file sharing", "file"): try: filename = input("Enter full path to file: ").strip()