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
|
|
|
|
import getpass
|
|
|
|
|
|
|
|
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
|
|
|
|
try:
|
|
|
|
directory = sys.argv[2]
|
|
|
|
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)
|
|
|
|
|
|
|
|
passphrase = getpass.getpass(
|
|
|
|
'Please enter a site passphrase of at least ' +
|
2020-01-29 21:44:44 +00:00
|
|
|
str(onionrvalues.PASSWORD_LENGTH) + ' characters.')
|
2019-12-19 10:34:19 +00:00
|
|
|
|
2019-11-05 11:29:15 +00:00
|
|
|
confirm = getpass.getpass('Confirm passphrase:')
|
2019-11-04 10:52:38 +00:00
|
|
|
if passphrase != confirm:
|
|
|
|
logger.error('Passphrases do not match', terminal=True)
|
|
|
|
error_encountered = True
|
|
|
|
|
|
|
|
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}' +
|
|
|
|
'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)
|
|
|
|
|
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
|