2019-07-30 05:19:22 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-02-06 22:00:19 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-07-30 05:19:22 +00:00
|
|
|
|
2020-02-06 22:00:19 +00:00
|
|
|
This file initializes Onionr when ran to be a daemon or with commands
|
2019-07-30 05:19:22 +00:00
|
|
|
|
2020-02-06 22:00:19 +00:00
|
|
|
Run with 'help' for usage.
|
2019-12-13 18:24:29 +00:00
|
|
|
"""
|
|
|
|
"""
|
2019-07-30 05:19:22 +00:00
|
|
|
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/>.
|
2019-12-13 18:24:29 +00:00
|
|
|
"""
|
2019-09-09 00:21:36 +00:00
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
# Set the user's locale for encoding reasons
|
2020-02-06 22:00:19 +00:00
|
|
|
import locale # noqa
|
|
|
|
locale.setlocale(locale.LC_ALL, '') # noqa
|
2019-07-30 05:19:22 +00:00
|
|
|
|
2019-10-19 08:47:24 +00:00
|
|
|
ran_as_script = False
|
|
|
|
if __name__ == "__main__": ran_as_script = True
|
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
# Import standard libraries
|
2020-02-06 22:00:19 +00:00
|
|
|
import sys # noqa
|
2019-07-30 05:19:22 +00:00
|
|
|
|
|
|
|
try:
|
2020-02-06 22:00:19 +00:00
|
|
|
from etc import dependencycheck # noqa
|
2019-11-20 10:52:50 +00:00
|
|
|
except ModuleNotFoundError as e:
|
|
|
|
print('Onionr needs ' + str(e) + ' installed')
|
2019-07-30 05:19:22 +00:00
|
|
|
|
2020-02-06 10:11:39 +00:00
|
|
|
# Import 3rd party libraries
|
|
|
|
|
|
|
|
from filenuke import nuke # noqa
|
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
# Onionr imports
|
2019-12-13 18:24:29 +00:00
|
|
|
|
|
|
|
# For different Onionr related constants such as versions
|
2020-02-06 22:00:19 +00:00
|
|
|
from etc import onionrvalues # noqa
|
2019-12-13 18:24:29 +00:00
|
|
|
|
2020-02-06 22:00:19 +00:00
|
|
|
import onionrexceptions # noqa
|
|
|
|
import onionrsetup as setup # noqa
|
2019-07-30 05:19:22 +00:00
|
|
|
|
2019-11-20 10:52:50 +00:00
|
|
|
min_ver = onionrvalues.MIN_PY_VERSION
|
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
# Ensure we have at least the minimum python version
|
2019-11-20 10:52:50 +00:00
|
|
|
if sys.version_info[0] == 2 or sys.version_info[1] < min_ver:
|
2020-02-06 22:00:19 +00:00
|
|
|
sys.stderr.write(
|
|
|
|
'Error, Onionr requires Python 3.' + str(min_ver) + '\n')
|
2019-07-30 05:19:22 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Create Onionr data directories, must be done before most imports
|
|
|
|
from utils import createdirs
|
|
|
|
createdirs.create_dirs()
|
|
|
|
|
2020-02-06 22:00:19 +00:00
|
|
|
import bigbrother # noqa
|
|
|
|
from onionrcommands import parser # noqa
|
|
|
|
from onionrplugins import onionrevents as events # noqa
|
2020-01-10 09:42:04 +00:00
|
|
|
from onionrblocks.deleteplaintext import delete_plaintext_no_blacklist # noqa
|
2019-07-30 18:13:10 +00:00
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
setup.setup_config()
|
2019-12-13 18:24:29 +00:00
|
|
|
|
2020-02-06 22:00:19 +00:00
|
|
|
import config # noqa
|
|
|
|
from utils import identifyhome # noqa
|
2020-02-08 09:07:07 +00:00
|
|
|
import filepaths # noqa
|
2019-12-13 18:24:29 +00:00
|
|
|
|
|
|
|
if config.get('advanced.security_auditing', True):
|
|
|
|
try:
|
|
|
|
bigbrother.enable_ministries()
|
|
|
|
except onionrexceptions.PythonVersion:
|
|
|
|
pass
|
|
|
|
|
2020-01-10 09:42:04 +00:00
|
|
|
if not config.get('general.store_plaintext_blocks', True):
|
|
|
|
delete_plaintext_no_blacklist()
|
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
setup.setup_default_plugins()
|
|
|
|
|
2019-11-20 10:52:50 +00:00
|
|
|
|
2019-07-30 05:19:22 +00:00
|
|
|
def onionr_main():
|
2019-11-12 05:32:18 +00:00
|
|
|
"""Onionr entrypoint, start command processor"""
|
2019-07-30 18:13:10 +00:00
|
|
|
parser.register()
|
2019-07-30 05:19:22 +00:00
|
|
|
|
2019-11-20 10:52:50 +00:00
|
|
|
|
2019-10-19 08:47:24 +00:00
|
|
|
if ran_as_script:
|
2019-09-11 02:08:35 +00:00
|
|
|
onionr_main()
|
2019-09-29 04:57:29 +00:00
|
|
|
|
2020-02-02 08:48:23 +00:00
|
|
|
config.reload()
|
|
|
|
|
2020-02-06 22:00:19 +00:00
|
|
|
# If the setting is there, shred log file on exit
|
2020-02-06 10:11:39 +00:00
|
|
|
if config.get('log.file.remove_on_exit', True):
|
2020-02-08 09:07:07 +00:00
|
|
|
try:
|
|
|
|
nuke.clean(filepaths.log_file)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2020-02-06 10:11:39 +00:00
|
|
|
|
2019-09-29 20:39:03 +00:00
|
|
|
# Cleanup standard out/err because Python refuses to do it itsself
|
2019-09-29 04:57:29 +00:00
|
|
|
try:
|
|
|
|
sys.stderr.close()
|
2019-11-20 10:52:50 +00:00
|
|
|
except (IOError, BrokenPipeError):
|
2019-09-29 04:57:29 +00:00
|
|
|
pass
|
|
|
|
try:
|
|
|
|
sys.stdout.close()
|
2019-11-20 10:52:50 +00:00
|
|
|
except (IOError, BrokenPipeError):
|
2019-09-29 04:57:29 +00:00
|
|
|
pass
|