2019-12-19 10:34:19 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
|
|
|
|
|
|
|
Command to create Onionr mutli-page sites
|
|
|
|
"""
|
2019-11-04 10:52:38 +00:00
|
|
|
import sys
|
2020-06-13 22:49:16 +00:00
|
|
|
import os
|
2019-11-04 10:52:38 +00:00
|
|
|
import getpass
|
|
|
|
|
2020-09-15 18:12:39 +00:00
|
|
|
from niceware import generate_passphrase
|
|
|
|
|
2019-11-04 10:52:38 +00:00
|
|
|
from httpapi import onionrsitesapi
|
|
|
|
import logger
|
|
|
|
from etc import onionrvalues
|
2019-12-19 10:34:19 +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-11-04 10:52:38 +00:00
|
|
|
|
|
|
|
def create_multipage_site():
|
2019-12-19 10:34:19 +00:00
|
|
|
"""Command to create mutlipage sites with specified dir and password."""
|
2019-11-04 10:52:38 +00:00
|
|
|
error_encountered = False
|
2020-06-13 22:49:16 +00:00
|
|
|
orig_dir = os.getcwd()
|
2019-11-04 10:52:38 +00:00
|
|
|
try:
|
|
|
|
directory = sys.argv[2]
|
2020-06-13 22:49:16 +00:00
|
|
|
os.chdir(directory)
|
|
|
|
directory = '.'
|
2019-11-04 10:52:38 +00:00
|
|
|
except IndexError:
|
|
|
|
directory = '.'
|
|
|
|
try:
|
|
|
|
passphrase = sys.argv[3]
|
|
|
|
except IndexError:
|
|
|
|
logger.warn('''It is critical that this passphrase is long.
|
2019-12-19 10:34:19 +00:00
|
|
|
If you want to update your site later you must remember the passphrase.''',
|
|
|
|
terminal=True)
|
|
|
|
|
2020-09-15 18:12:39 +00:00
|
|
|
passphrase = "-".join(generate_passphrase(32))
|
|
|
|
print("Site restore phrase:", passphrase)
|
2019-11-04 10:52:38 +00:00
|
|
|
|
|
|
|
if len(passphrase) < onionrvalues.PASSWORD_LENGTH:
|
|
|
|
error_encountered = True
|
2019-12-19 10:34:19 +00:00
|
|
|
logger.error(
|
|
|
|
f'Passphrase must be at least {onionrvalues.PASSWORD_LENGTH}' +
|
2020-06-13 22:49:16 +00:00
|
|
|
' characters.', terminal=True)
|
2019-11-04 10:52:38 +00:00
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
if error_encountered:
|
2019-11-04 10:52:38 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
results = onionrsitesapi.sitefiles.create_site(
|
|
|
|
passphrase, directory=directory)
|
2019-11-04 10:52:38 +00:00
|
|
|
results = (results[0].replace('=', ''), results[1])
|
|
|
|
logger.info(f'Site address {results[0]}', terminal=True)
|
|
|
|
logger.info(f'Block for this version {results[1]}', terminal=True)
|
2020-06-13 22:49:16 +00:00
|
|
|
os.chdir(orig_dir)
|
2019-11-04 10:52:38 +00:00
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
|
|
|
|
create_multipage_site.onionr_help = "[directory path " # type: ignore
|
|
|
|
create_multipage_site.onionr_help += "(default relative)] " # type: ignore
|
|
|
|
create_multipage_site.onionr_help += "- packages a whole " # type: ignore
|
|
|
|
create_multipage_site.onionr_help += "directory and makes " # type: ignore
|
|
|
|
create_multipage_site.onionr_help += "it available as " # type: ignore
|
|
|
|
create_multipage_site.onionr_help += "an Onionr site." # type: ignore
|