Compare commits

...

36 Commits

Author SHA1 Message Date
Arinerron
99627e168a
Add PKGBUILD 2019-07-20 13:22:10 -07:00
Arinerron
6a576131f8
Add files 2019-07-20 13:19:24 -07:00
Arinerron
3c593ca316
Add lazypkg files 2019-07-20 10:43:55 -07:00
Arinerron
06b02baf5c
rm test 2019-06-18 09:27:32 -07:00
Arinerron
ac65b316fb
test 2019-06-18 09:27:09 -07:00
Arinerron
282d6ec109
Fix systemd unit file 2019-06-06 17:28:46 -07:00
Arinerron
82c29bfcbe
Give error details instead of just spontaneously quitting 2019-03-30 17:25:07 -07:00
Arinerron
0fe241bea2
chown directory 2019-03-30 16:46:46 -07:00
Arinerron
00d9ae975e
Fix Debian install script 2019-03-30 16:36:50 -07:00
Arinerron
50d0366e47
Run onionr as user instead of system always 2019-03-30 16:21:12 -07:00
Arinerron
5cf082b884
Everthing working. Commits after this use the new script 2019-03-30 16:02:16 -07:00
Arinerron
e5de2cad8c
Remove old debug code 2019-03-29 17:24:04 -07:00
Arinerron
957f250665
Change print to logger functions and provide context 2019-03-29 17:22:52 -07:00
Arinerron
ef93910f98
Add dependencies to PKGBUILD 2019-03-28 23:39:00 -07:00
Arinerron
e70243884a
Note for self for later 2019-03-28 23:24:41 -07:00
Arinerron
d11d64cc50
Fix bugs with arch and debian install scripts 2019-03-28 23:18:25 -07:00
Arinerron
1a155f8668
UI improvements 2019-03-28 22:36:41 -07:00
Arinerron
ad9393805f
Switch order of -y and install 2019-03-28 22:16:30 -07:00
Arinerron
b04c213c32
Fix bugs with release creation script 2019-03-28 21:16:23 -07:00
Arinerron
234f1eed0c
undo what I did 2019-03-28 21:07:04 -07:00
Arinerron
3531b28667
Fix bugs in release creation script 2019-03-28 21:05:15 -07:00
Arinerron
99924a9569
Add release creation script 2019-03-28 21:01:59 -07:00
Arinerron
afd611febe
Correct PKGBUILD's version info 2019-03-28 21:01:38 -07:00
Arinerron
3e789a8650
Fix plugin bug 2019-03-28 20:25:20 -07:00
Arinerron
8bae211a8d
Use ONIONR_HOME or DATA_DIR env vars 2019-03-28 12:08:07 -07:00
Arinerron
9bd5efce1f
Make onionr use dirs from env 2019-03-28 12:03:37 -07:00
Arinerron
66d7dae08f
Default yes in Debian install script 2019-03-28 11:54:55 -07:00
Arinerron
781f2ea421
Add +x to debian install script 2019-03-28 11:38:40 -07:00
Arinerron
74b50cc7f8
Add Debian install script 2019-03-28 11:38:17 -07:00
Arinerron
3b70c9e95e
Reload daemon before enabling onionr on Arch Linux installation script 2019-03-28 11:10:11 -07:00
Arinerron
a9f63b05c7
Add error handing to Arch Linux installation script 2019-03-28 11:08:36 -07:00
Arinerron
2c8bb14508
Add Arch Linux install script and systemd service 2019-03-28 11:01:23 -07:00
Arinerron
8461eed15e
Add log files to gitignore 2019-03-28 10:55:06 -07:00
Arinerron
4f66c874f5
Fix potential future bug with Makefile 2019-03-28 10:54:36 -07:00
Arinerron
81f334667e
Add header command (not in help menu) 2019-03-28 10:53:52 -07:00
Arinerron
0203ec0fd3
Add onionr icon 2019-03-28 09:10:04 -07:00
25 changed files with 530 additions and 65 deletions

8
.gitignore vendored
View File

@ -18,6 +18,14 @@ core
venv/*
onionr/fs*
# log files
output.log
*.log
onionr/output.log
onionr/*.log
onionr/data/output.log
onionr/data/*.log
# package files
onionr-*.pkg.tar.gz
pkg/

View File

@ -32,7 +32,7 @@ reset:
@echo "Hard-resetting Onionr..."
rm -rf onionr/$(ONIONR_HOME)/ | true > /dev/null 2>&1
cd onionr/static-data/www/ui/; rm -rf ./dist; python compile.py
#@./onionr.sh.sh version | grep -v "Failed" --color=always
#@./onionr.sh version | grep -v "Failed" --color=always
plugins-reset:
@echo "Resetting plugins..."

View File

@ -1,20 +1,60 @@
url="https://onionr.net/"
# Maintainer: Kevin Froman <contact@onionr.net>
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"
}

BIN
docs/onionr-icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

4
install/build.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
make plugins-reset
find . -name '__pycache__' -type d | xargs rm -rf

52
install/create_release.py Executable file
View File

@ -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.')

89
install/install_arch.sh Executable file
View File

@ -0,0 +1,89 @@
#!/bin/bash
EXECUTABLE='/usr/bin/onionr'
OUTPUT_DIR='/usr/share/onionr'
DATA_DIR='/etc/onionr'
LOG_DIR='/var/log/onionr'
BRANCH='easy-releases'
# setup error handlers
set -e
trap "echo -e '\033[31mOnionr installation failed.\033[0m' >&2; exit 1337" ERR INT TERM
# require root permissions
if ! [ $(id -u) = 0 ]; then
echo 'This script must be run as root.' >&2
exit 1337
fi
# install basic dependencies
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 --quiet https://gitlab.com/beardog/onionr "$OUTPUT_DIR" > /dev/null
cd "$OUTPUT_DIR"
git checkout -q "$BRANCH" > /dev/null
# install python dependencies
echo -e "\033[0;32mInstalling pip dependencies...\033[0m"
pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null
# set permissions on Onionr directory
chmod 755 "$OUTPUT_DIR"
chown -R root:root "$OUTPUT_DIR"
# create directories
mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR"
mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR"
chmod -R 750 "$DATA_DIR" "$LOG_DIR"
chown -R root:root "$DATA_DIR" "$LOG_DIR"
# create executable
cp "$OUTPUT_DIR/install/onionr" "$EXECUTABLE"
chmod 755 "$EXECUTABLE"
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"
chmod 644 "$SERVICE"
chown root:root "$SERVICE"
systemctl daemon-reload
systemctl enable onionr
systemctl start onionr
# pretty header thing
"$EXECUTABLE" --header 'Onionr successfully installed.'
# and we're good!
trap - ERR
exit 0

89
install/install_debian.sh Executable file
View File

@ -0,0 +1,89 @@
#!/bin/bash
EXECUTABLE='/usr/bin/onionr'
OUTPUT_DIR='/usr/share/onionr'
DATA_DIR='/etc/onionr'
LOG_DIR='/var/log/onionr'
BRANCH='easy-releases'
# setup error handlers
set -e
trap "echo -e '\033[31mOnionr installation failed.\033[0m' >&2; exit 1337" ERR INT TERM
# require root permissions
if ! [ $(id -u) = 0 ]; then
echo 'This script must be run as root.' >&2
exit 1337
fi
# install basic dependencies
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 --quiet https://gitlab.com/beardog/onionr "$OUTPUT_DIR" > /dev/null
cd "$OUTPUT_DIR"
git checkout -q "$BRANCH" > /dev/null
# install python dependencies
echo -e "\033[0;32mInstalling pip dependencies...\033[0m"
python3.7 -m pip install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null
# set permissions on Onionr directory
chmod 755 "$OUTPUT_DIR"
chown -R root:root "$OUTPUT_DIR"
# create directories
mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR"
mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR"
chmod -R 750 "$DATA_DIR" "$LOG_DIR"
chown -R root:root "$DATA_DIR" "$LOG_DIR"
# create executable
cp "$OUTPUT_DIR/install/onionr" "$EXECUTABLE"
chmod 755 "$EXECUTABLE"
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"
chmod 644 "$SERVICE"
chown root:root "$SERVICE"
systemctl daemon-reload
systemctl enable onionr
systemctl start onionr
# pretty header thing
"$EXECUTABLE" --header 'Onionr successfully installed.'
# and we're good!
trap - ERR
exit 0

23
install/onionr Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
set -e
export OUTPUT_DIR=${OUTPUT_DIR:=/usr/share/onionr}
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 "$@"

22
install/onionr.service Normal file
View File

@ -0,0 +1,22 @@
[Unit]
Description=Onionr Daemon
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=on-abnormal
[Install]
WantedBy=tor.service

3
install/post_build.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
sh run_tests.sh

5
install/post_install.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
systemctl daemon-reload
systemctl enable onionr
systemctl start onionr

3
install/pre_install.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null

48
onionr.install Normal file
View File

@ -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}"
}

54
onionr.yml Normal file
View File

@ -0,0 +1,54 @@
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: Kevin Froman
relationships:
- conflicts: onionr2
sources:
- git: https://gitlab.com/beardog/onionr.git
branch: easy-releases
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

0
onionr/PKGBUILD Normal file
View File

View File

@ -20,13 +20,11 @@
import os, json, logger
try:
dataDir = os.environ['ONIONR_HOME']
if not dataDir.endswith('/'):
dataDir += '/'
except KeyError:
dataDir = 'data/'
# set data dir
dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not dataDir.endswith('/'):
dataDir += '/'
_configfile = os.path.abspath(dataDir + 'config.json')
_config = {}

View File

@ -39,12 +39,10 @@ class Core:
Initialize Core Onionr library
'''
try:
self.dataDir = os.environ['ONIONR_HOME']
if not self.dataDir.endswith('/'):
self.dataDir += '/'
except KeyError:
self.dataDir = 'data/'
# set data dir
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not self.dataDir.endswith('/'):
self.dataDir += '/'
try:
self.onionrInst = None

View File

@ -64,10 +64,9 @@ class colors:
'''
Use the bitwise operators to merge these settings
'''
USE_ANSI = 0b100
if os.name == 'nt':
USE_ANSI = 0b000
else:
USE_ANSI = 0b100
OUTPUT_TO_CONSOLE = 0b010
OUTPUT_TO_FILE = 0b001
@ -80,7 +79,7 @@ LEVEL_IMPORTANT = 6
_type = OUTPUT_TO_CONSOLE | USE_ANSI # the default settings for logging
_level = LEVEL_DEBUG # the lowest level to log
_outputfile = './output.log' # the file to log to
_outputfile = 'data/onionr.log' # the file to log to
def set_settings(type):
'''

View File

@ -46,12 +46,10 @@ class NetController:
'''
def __init__(self, hsPort, apiServerIP='127.0.0.1'):
try:
self.dataDir = os.environ['ONIONR_HOME']
if not self.dataDir.endswith('/'):
self.dataDir += '/'
except KeyError:
self.dataDir = 'data/'
# set data dir
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not self.dataDir.endswith('/'):
self.dataDir += '/'
self.torConfigLocation = self.dataDir + 'torrc'
self.readyState = False
@ -165,7 +163,7 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort)
except KeyboardInterrupt:
logger.fatal('Got keyboard interrupt.', timestamp = False, level = logger.LEVEL_IMPORTANT)
return False
logger.debug('Finished starting Tor.', timestamp=True)
self.readyState = True

View File

@ -62,12 +62,13 @@ class Onionr:
except FileNotFoundError:
pass
try:
self.dataDir = os.environ['ONIONR_HOME']
if not self.dataDir.endswith('/'):
self.dataDir += '/'
except KeyError:
self.dataDir = 'data/'
# set data dir
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not self.dataDir.endswith('/'):
self.dataDir += '/'
# set log file
logger.set_file(os.environ.get('LOG_DIR', 'data') + '/onionr.log')
# Load global configuration data
data_exists = Onionr.setupConfig(self.dataDir, self = self)
@ -122,7 +123,6 @@ class Onionr:
config.set('client.client.port', randomPort, savefile=True)
if type(config.get('client.public.port')) is type(None):
randomPort = netcontroller.getOpenPort()
print(randomPort)
config.set('client.public.port', randomPort, savefile=True)
if type(config.get('client.participate')) is type(None):
config.set('client.participate', True, savefile=True)
@ -144,19 +144,27 @@ class Onionr:
self.execute(command)
return
def exitSigterm(self, signum, frame):
self.killed = True
def setupConfig(dataDir, self = None):
setupconfig.setup_config(dataDir, self)
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:
# only to stdout, not file or log or anything
sys.stderr.write(file.read().decode().replace('P', logger.colors.fg.pink).replace('W', logger.colors.reset + logger.colors.bold).replace('G', logger.colors.fg.green).replace('\n', logger.colors.reset + '\n').replace('B', logger.colors.bold).replace('A', '%s' % API_VERSION).replace('V', ONIONR_VERSION))
logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', sensitive=True)
if not message is None:
logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', sensitive=True)
def doExport(self, bHash):
exportDir = self.dataDir + 'block-export/'
@ -220,13 +228,13 @@ class Onionr:
def showDetails(self):
commands.onionrstatistics.show_details(self)
def openHome(self):
commands.open_home(self)
def addID(self):
commands.pubkeymanager.add_ID(self)
def changeID(self):
commands.pubkeymanager.change_ID(self)
@ -326,6 +334,7 @@ class Onionr:
function(ONIONR_TAGLINE)
if verbosity >= 2:
function('Running on %s %s' % (platform.platform(), platform.release()))
function('Onionr data dir: %s' % self.dataDir)
def doPEX(self):
'''make communicator do pex'''
@ -385,7 +394,7 @@ class Onionr:
'''
Displays a message suggesting help
'''
if __name__ == '__main__':
if __name__ == '__main__':
logger.info('Do ' + logger.colors.bold + sys.argv[0] + ' --help' + logger.colors.reset + logger.colors.fg.green + ' for Onionr help.')
def start(self, input = False, override = False):

View File

@ -46,13 +46,14 @@ def open_home(o_inst):
logger.error('Onionr seems to not be running (could not get api host)')
else:
url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword'))
print('If Onionr does not open automatically, use this URL:', url)
logger.info('If Onionr does not open automatically, use this URL:\n\n%s' % url)
webbrowser.open_new_tab(url)
def get_commands(onionr_inst):
return {'': onionr_inst.showHelpSuggestion,
'help': onionr_inst.showHelp,
'version': onionr_inst.version,
'header': onionr_inst.cmdHeader,
'config': onionr_inst.configure,
'start': onionr_inst.start,
'stop': onionr_inst.killDaemon,
@ -168,4 +169,4 @@ cmd_help = {
'add-id': 'Generate a new ID (key pair)',
'change-id': 'Change active ID',
'open-home': 'Open your node\'s home/info screen'
}
}

View File

@ -104,7 +104,7 @@ def show_peers(o_inst):
if not type(peers) is None:
if peers not in ('', 'failure', None):
if peers != False:
print(peers)
logger.info('Peers: %s' % peers)
else:
print('Daemon probably not running. Unable to list connected peers.')
break
logger.warn('Daemon probably not running. Unable to list connected peers.')
break

View File

@ -21,12 +21,10 @@
import os, re, importlib, config, logger
import onionrevents as events
try:
dataDir = os.environ['ONIONR_HOME']
if not dataDir.endswith('/'):
dataDir += '/'
except KeyError:
dataDir = 'data/'
# set data dir
dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
if not dataDir.endswith('/'):
dataDir += '/'
_pluginsfolder = dataDir + 'plugins/'
_instances = dict()
@ -71,9 +69,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 inconsistenly (especially between versions)
logger.debug('Failed to enable module; Import error: %s' % e)
return False
else:
enabled_plugins.append(name)
@ -85,7 +84,8 @@ def enable(name, onionr = None, start_event = True):
else:
return False
else:
logger.error('Failed to enable plugin \"%s\", disabling plugin.' % name)
logger.error('Failed to enable plugin \"%s\" (disabling plugin).' % name)
logger.debug('Plugins folder not found: %s' % get_plugins_folder(str(name).lower()))
disable(name)
return False
@ -157,6 +157,28 @@ def stop(name, onionr = None):
return None
# credit: https://stackoverflow.com/a/29589414
def import_module_from_file(full_path_to_module):
"""
Import a module given the full path/filename of the .py file
Python 3.4
"""
module = None
# Get module name and path from full path
module_dir, module_file = os.path.split(full_path_to_module)
module_name, module_ext = os.path.splitext(module_file)
# Get module "spec" from filename
spec = importlib.util.spec_from_file_location(module_name,full_path_to_module)
module = spec.loader.load_module()
return module
def get_plugin(name):
'''
Returns the instance of a module
@ -167,7 +189,7 @@ def get_plugin(name):
if str(name).lower() in _instances:
return _instances[str(name).lower()]
else:
_instances[str(name).lower()] = importlib.import_module(get_plugins_folder(name, False).replace('/', '.') + 'main')
_instances[str(name).lower()] = import_module_from_file(get_plugins_folder(name, False) + 'main.py')
return get_plugin(name)
def get_plugins():

View File

@ -82,12 +82,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"):
filename = input("Enter full path to file: ").strip()
self.subCommand("addfile", filename)