work on onboarding and pep8 compliance. re-worded about
This commit is contained in:
parent
a4a0d240ac
commit
ee5f4409af
@ -1,3 +1,10 @@
|
||||
"""Flask WSGI apps for the public and private API servers
|
||||
|
||||
Public is net-facing server meant for other nodes
|
||||
Private is meant for controlling and accessing this node
|
||||
"""
|
||||
|
||||
from . import public, private
|
||||
|
||||
PublicAPI = public.PublicAPI
|
||||
ClientAPI = private.PrivateAPI
|
||||
ClientAPI = private.PrivateAPI
|
||||
|
@ -3,6 +3,21 @@
|
||||
|
||||
This file handles all incoming http requests to the client, using Flask
|
||||
'''
|
||||
import base64
|
||||
import os
|
||||
|
||||
import flask
|
||||
from gevent.pywsgi import WSGIServer
|
||||
|
||||
from onionrutils import epoch
|
||||
import httpapi
|
||||
from filepaths import private_API_host_file
|
||||
import logger
|
||||
|
||||
from etc import waitforsetvar
|
||||
from . import register_private_blueprints
|
||||
import config
|
||||
from .. import public
|
||||
'''
|
||||
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
|
||||
@ -17,39 +32,33 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import base64, os, time
|
||||
import flask
|
||||
from gevent.pywsgi import WSGIServer
|
||||
from onionrutils import epoch
|
||||
import httpapi, filepaths, logger
|
||||
from . import register_private_blueprints
|
||||
from etc import waitforsetvar
|
||||
import serializeddata, config
|
||||
from .. import public
|
||||
|
||||
|
||||
class PrivateAPI:
|
||||
'''
|
||||
Client HTTP api
|
||||
'''
|
||||
|
||||
callbacks = {'public' : {}, 'private' : {}}
|
||||
callbacks = {'public': {}, 'private': {}}
|
||||
|
||||
def __init__(self):
|
||||
'''
|
||||
Initialize the api server, preping variables for later use
|
||||
|
||||
This initialization defines all of the API entry points and handlers for the endpoints and errors
|
||||
This initialization defines all of the API entry points
|
||||
and handlers for the endpoints and errors
|
||||
This also saves the used host (random localhost IP address) to the data folder in host.txt
|
||||
'''
|
||||
self.config = config
|
||||
|
||||
self.startTime = epoch.get_epoch()
|
||||
app = flask.Flask(__name__)
|
||||
bindPort = int(config.get('client.client.port', 59496))
|
||||
self.bindPort = bindPort
|
||||
bind_port = int(config.get('client.client.port', 59496))
|
||||
self.bindPort = bind_port
|
||||
|
||||
self.clientToken = config.get('client.webpassword')
|
||||
self.timeBypassToken = base64.b16encode(os.urandom(32)).decode()
|
||||
|
||||
self.host = httpapi.apiutils.setbindip.set_bind_IP(filepaths.private_API_host_file)
|
||||
self.host = httpapi.apiutils.setbindip.set_bind_IP(private_API_host_file)
|
||||
logger.info('Running api on %s:%s' % (self.host, self.bindPort))
|
||||
self.httpServer = ''
|
||||
|
||||
@ -58,7 +67,7 @@ class PrivateAPI:
|
||||
register_private_blueprints.register_private_blueprints(self, app)
|
||||
httpapi.load_plugin_blueprints(app)
|
||||
self.app = app
|
||||
|
||||
|
||||
def start(self):
|
||||
waitforsetvar.wait_for_set_var(self, "_too_many")
|
||||
self.publicAPI = self._too_many.get(public.PublicAPI)
|
||||
|
@ -3,6 +3,20 @@
|
||||
|
||||
Download blocks using the communicator instance
|
||||
'''
|
||||
import onionrexceptions
|
||||
import logger
|
||||
import onionrpeers
|
||||
import communicator
|
||||
from communicator import peeraction
|
||||
from communicator import onlinepeers
|
||||
from onionrutils import blockmetadata
|
||||
from onionrutils import validatemetadata
|
||||
from coredb import blockmetadb
|
||||
import onionrcrypto
|
||||
import onionrstorage
|
||||
from onionrblocks import onionrblacklist
|
||||
from onionrblocks import storagecounter
|
||||
from . import shoulddownload
|
||||
'''
|
||||
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
|
||||
@ -17,17 +31,10 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import communicator, onionrexceptions
|
||||
import logger, onionrpeers
|
||||
from onionrutils import blockmetadata, stringvalidators, validatemetadata
|
||||
from coredb import blockmetadb
|
||||
from . import shoulddownload
|
||||
from communicator import peeraction, onlinepeers
|
||||
import onionrcrypto, onionrstorage
|
||||
from onionrblocks import onionrblacklist, storagecounter
|
||||
def download_blocks_from_communicator(comm_inst):
|
||||
'''Use Onionr communicator instance to download blocks in the communicator's queue'''
|
||||
assert isinstance(comm_inst, communicator.OnionrCommunicatorDaemon)
|
||||
|
||||
|
||||
def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
|
||||
'''Use communicator instance to download blocks in the comms's queue'''
|
||||
blacklist = onionrblacklist.OnionrBlackList()
|
||||
storage_counter = storagecounter.StorageCounter()
|
||||
LOG_SKIP_COUNT = 50 # for how many iterations we skip logging the counter
|
||||
@ -53,7 +60,6 @@ def download_blocks_from_communicator(comm_inst):
|
||||
break
|
||||
# Do not download blocks being downloaded
|
||||
if blockHash in comm_inst.currentDownloading:
|
||||
#logger.debug('Already downloading block %s...' % blockHash)
|
||||
continue
|
||||
|
||||
comm_inst.currentDownloading.append(blockHash) # So we can avoid concurrent downloading in other threads of same block
|
||||
@ -130,4 +136,4 @@ def download_blocks_from_communicator(comm_inst):
|
||||
except KeyError:
|
||||
pass
|
||||
comm_inst.currentDownloading.remove(blockHash)
|
||||
comm_inst.decrementThreadCount('getBlocks')
|
||||
comm_inst.decrementThreadCount('getBlocks')
|
||||
|
34
src/config/onboarding.py
Normal file
34
src/config/onboarding.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
Setup config from onboarding choices
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
from filepaths import onboarding_mark_file
|
||||
import onionrtypes
|
||||
"""
|
||||
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/>.
|
||||
"""
|
||||
|
||||
|
||||
def set_config_from_onboarding(config_settings: onionrtypes.OnboardingConfig):
|
||||
return
|
||||
|
||||
def set_onboarding_finished():
|
||||
"""Create the onboarding completed setting file"""
|
||||
Path(onboarding_mark_file).touch()
|
||||
|
||||
def is_onboarding_finished() -> bool:
|
||||
return True
|
@ -28,4 +28,6 @@ run_check_file = home + '.runcheck'
|
||||
|
||||
data_nonce_file = home + 'block-nonces.dat'
|
||||
|
||||
keys_file = home + 'keys.txt'
|
||||
keys_file = home + 'keys.txt'
|
||||
|
||||
onboarding_mark_file = home + 'onboarding-completed'
|
||||
|
@ -3,6 +3,14 @@
|
||||
|
||||
Accept block uploads to the public API server
|
||||
'''
|
||||
import sys
|
||||
from flask import Response
|
||||
from flask import abort
|
||||
|
||||
from onionrblocks import blockimporter
|
||||
import onionrexceptions
|
||||
import logger
|
||||
|
||||
'''
|
||||
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
|
||||
@ -17,18 +25,15 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sys
|
||||
from flask import Response, abort
|
||||
|
||||
from onionrblocks import blockimporter
|
||||
import onionrexceptions, logger
|
||||
|
||||
def accept_upload(request):
|
||||
"""Accept uploaded blocks to our public Onionr protocol API server"""
|
||||
resp = 'failure'
|
||||
data = request.get_data()
|
||||
if sys.getsizeof(data) < 100000000:
|
||||
try:
|
||||
if blockimporter.importBlockFromData(data):
|
||||
if blockimporter.import_block_from_data(data):
|
||||
resp = 'success'
|
||||
else:
|
||||
resp = 'failure'
|
||||
|
@ -3,6 +3,17 @@
|
||||
|
||||
Import block data and save it
|
||||
'''
|
||||
from onionrexceptions import BlacklistedBlock
|
||||
from onionrexceptions import DiskAllocationReached
|
||||
from onionrexceptions import InvalidProof
|
||||
import logger
|
||||
from onionrutils import validatemetadata
|
||||
from onionrutils import blockmetadata
|
||||
from coredb import blockmetadb
|
||||
import onionrstorage
|
||||
import onionrcrypto as crypto
|
||||
from . import onionrblacklist
|
||||
|
||||
'''
|
||||
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
|
||||
@ -17,39 +28,41 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import onionrexceptions, logger
|
||||
from onionrutils import validatemetadata, blockmetadata
|
||||
from coredb import blockmetadb
|
||||
from . import onionrblacklist
|
||||
import onionrstorage
|
||||
import onionrcrypto as crypto
|
||||
def importBlockFromData(content):
|
||||
|
||||
|
||||
def import_block_from_data(content):
|
||||
blacklist = onionrblacklist.OnionrBlackList()
|
||||
retData = False
|
||||
ret_data = False
|
||||
|
||||
try:
|
||||
content = content.encode()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
dataHash = crypto.hashers.sha3_hash(content)
|
||||
data_hash = crypto.hashers.sha3_hash(content)
|
||||
|
||||
if blacklist.inBlacklist(dataHash):
|
||||
raise onionrexceptions.BlacklistedBlock('%s is a blacklisted block' % (dataHash,))
|
||||
if blacklist.inBlacklist(data_hash):
|
||||
raise BlacklistedBlock(f'%s is a blacklisted block {data_hash}')
|
||||
|
||||
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
||||
# returns tuple(metadata, meta), meta is also in metadata
|
||||
metas = blockmetadata.get_block_metadata_from_data(content)
|
||||
metadata = metas[0]
|
||||
if validatemetadata.validate_metadata(metadata, metas[2]): # check if metadata is valid
|
||||
if crypto.cryptoutils.verify_POW(content): # check if POW is enough/correct
|
||||
logger.info('Imported block passed proof, saving.', terminal=True)
|
||||
|
||||
# check if metadata is valid
|
||||
if validatemetadata.validate_metadata(metadata, metas[2]):
|
||||
# check if POW is enough/correct
|
||||
if crypto.cryptoutils.verify_POW(content):
|
||||
logger.info(f'Imported block passed proof, saving: {data_hash}.',
|
||||
terminal=True)
|
||||
try:
|
||||
blockHash = onionrstorage.set_data(content)
|
||||
except onionrexceptions.DiskAllocationReached:
|
||||
except DiskAllocationReached:
|
||||
logger.warn('Failed to save block due to full disk allocation')
|
||||
else:
|
||||
blockmetadb.add_to_block_DB(blockHash, dataSaved=True)
|
||||
blockmetadata.process_block_metadata(blockHash) # caches block metadata values to block database
|
||||
retData = True
|
||||
# caches block metadata values to block database
|
||||
blockmetadata.process_block_metadata(blockHash)
|
||||
ret_data = True
|
||||
else:
|
||||
raise onionrexceptions.InvalidProof
|
||||
return retData
|
||||
raise InvalidProof
|
||||
return ret_data
|
||||
|
@ -6,3 +6,5 @@ UserIDSecretKey = NewType('UserIDSecretKey', str)
|
||||
DeterministicKeyPassphrase = NewType('DeterministicKeyPassphrase', str)
|
||||
|
||||
BlockHash = NewType('BlockHash', str)
|
||||
|
||||
OnboardingConfig = NewType('OnboardingConfig', str)
|
||||
|
13
static-data/www/onboarding/donate-modal.css
Normal file
13
static-data/www/onboarding/donate-modal.css
Normal file
@ -0,0 +1,13 @@
|
||||
.donateHeader{
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.donateFinished{
|
||||
display: block;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.donateBody p{
|
||||
padding-top: 1em;
|
||||
text-align: justify;
|
||||
}
|
17
static-data/www/onboarding/donate-modal.html
Normal file
17
static-data/www/onboarding/donate-modal.html
Normal file
@ -0,0 +1,17 @@
|
||||
<b class='donateHeader'>Donate</b>
|
||||
|
||||
<br><br>
|
||||
|
||||
<p>Onionr is a volunteer-driven project, and infrastructure is paid for out of pocket.
|
||||
</p>
|
||||
<p>
|
||||
Please donate the price of a cup of coffee to sustain development.
|
||||
</p>
|
||||
|
||||
<br>
|
||||
|
||||
Paypal/Card: <a href="https://ko-fi.com/beardogkf" target="_blank" rel="noopener">Ko-fi</a>
|
||||
<br>
|
||||
Bitcoin: <a href="bitcoin:1onion55FXzm6h8KQw3zFw2igpHcV7LPq">1onion55FXzm6h8KQw3zFw2igpHcV7LPq</a>
|
||||
|
||||
<button class="button donateFinished is-success">Done</button>
|
45
static-data/www/onboarding/donate.js
Normal file
45
static-data/www/onboarding/donate.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
Handles onboarding donations for Onionr
|
||||
|
||||
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/>
|
||||
*/
|
||||
|
||||
|
||||
let donateFinishedButtons = document.getElementsByClassName('donateFinished')
|
||||
configInfo = {}
|
||||
|
||||
let openDonateModal = function(newConfigInfo){
|
||||
fetch('donate-modal.html')
|
||||
.then((resp) => resp.text())
|
||||
.then(function(resp) {
|
||||
document.getElementsByClassName('donateModal')[0].classList.add('is-active')
|
||||
|
||||
// Load the donate modal html and display it
|
||||
let donateBody = document.getElementsByClassName('donateBody')[0]
|
||||
|
||||
donateBody.innerHTML = resp
|
||||
|
||||
let donateFinishedButton = document.getElementsByClassName('donateFinished')[0]
|
||||
|
||||
for (i = 0; i < donateFinishedButtons.length; i++){
|
||||
donateFinishedButtons[i].onclick = function(){
|
||||
document.getElementsByClassName('donateModal')[0].classList.remove('is-active')
|
||||
sendConfig(configInfo)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
@ -12,11 +12,13 @@
|
||||
<link rel="stylesheet" href="/private/main.css">
|
||||
<link rel="stylesheet" href="/shared/fontawesome-free-5.10.2/css/all.min.css">
|
||||
<link rel="stylesheet" href="/gettheme">
|
||||
<link rel="stylesheet" href="donate-modal.css">
|
||||
<link rel="stylesheet" href="onboarding.css">
|
||||
<script defer src='/shared/navbar.js'></script>
|
||||
<script defer src='/shared/loadabout.js'></script>
|
||||
<script defer src='/shared/misc.js'></script>
|
||||
<script defer src='/private/js/console.js'></script>
|
||||
<script defer src='donate.js'></script>
|
||||
<script defer src='onboarding.js'></script>
|
||||
<script>alert("Content security policy appears to not be working. Your browser security is weak!")</script>
|
||||
</head>
|
||||
@ -65,8 +67,20 @@
|
||||
|
||||
<br>
|
||||
|
||||
<div class="modal donateModal">
|
||||
<div class="modal-background"></div>
|
||||
<div class="modal-card">
|
||||
<header class="modal-card-head">
|
||||
<button class="closeAboutModal delete" aria-label="close"></button>
|
||||
</header>
|
||||
<section class="modal-card-body donateBody">
|
||||
Loading... <i class="fas fa-spinner fa-spin"></i>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="onboarding">
|
||||
<noscript><h1>Unforuntately, this requires JavaScript. Don't worry, all scripts are open source and locally loaded.</h1></noscript>
|
||||
<noscript><h1>Unfortunately, this requires JavaScript. Don't worry, all scripts are open source and locally loaded.</h1></noscript>
|
||||
<p>Welcome. There are just a few questions for you to answer before you get started.</p>
|
||||
<br>
|
||||
<form method='post' id="onboardingForm">
|
||||
@ -94,11 +108,13 @@
|
||||
<div>
|
||||
I want to...
|
||||
</div>
|
||||
<i class="icon fas fa-user"></i> <input type="checkbox" name="useDeterministic"> <label for="useDeterministic">Use a seed to re(generate) an ID</label>
|
||||
<i class="icon fas fa-user"></i> <input type="checkbox" name="useDeterministic"> <label for="useDeterministic">Use a seed to re(generate) a user ID</label>
|
||||
<br>
|
||||
<i class="icon fas fa-envelope"></i> <input type="checkbox" name="useMail" checked> <label for="useMail">Use OnionrMail</label>
|
||||
<br>
|
||||
<i class="icon fas fa-comments"></i> <input type="checkbox" name="useCircles" checked> <label for="useMail">Use Circles (message board system)</label>
|
||||
<br>
|
||||
<i class="icon fas fa-palette"></i> <input type="checkbox" name="useDarkTheme" checked> <label for="useDark">Use Dark Theme</label>
|
||||
|
||||
<br>
|
||||
</div>
|
||||
|
@ -16,11 +16,12 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
fetch('/getnewkeys', {
|
||||
headers: {
|
||||
"token": webpass
|
||||
}})
|
||||
.then((resp) => resp.text()) // Transform the data into text
|
||||
.then((resp) => resp.text())
|
||||
.then(function(resp) {
|
||||
keys = resp.split('')
|
||||
})
|
||||
@ -29,6 +30,19 @@ function getCheckValue(elName){
|
||||
return document.getElementsByName(elName)[0].checked
|
||||
}
|
||||
|
||||
function sendConfig(configInfo){
|
||||
fetch('/setonboarding', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"token": webpass,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({configInfo})
|
||||
}).then(function(data) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
document.getElementById('onboardingForm').onsubmit = function(e){
|
||||
submitInfo = {}
|
||||
submitInfo.massSurveil = getCheckValue('state')
|
||||
@ -39,6 +53,14 @@ document.getElementById('onboardingForm').onsubmit = function(e){
|
||||
submitInfo.donate = getCheckValue('donate')
|
||||
submitInfo.deterministic = getCheckValue('useDeterministic')
|
||||
submitInfo.mail = getCheckValue('useMail')
|
||||
submitInfo.circles = getCheckValue('useCircles')
|
||||
|
||||
if (submitInfo.donate){
|
||||
openDonateModal(submitInfo)
|
||||
return false
|
||||
}
|
||||
|
||||
sendConfig(submitInfo)
|
||||
|
||||
e.preventDefault()
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
|
||||
<b>Contributors:</b>
|
||||
<ul>
|
||||
<li><a href="https://invisamage.com/">Travis Kipp</a> web UI and CSS</li>
|
||||
<li><a href="https://invisamage.com/">Travis Kipp</a> CSS help</li>
|
||||
<li><a href="https://k7dxs.net/">Duncan Simpson</a> packaging help</li>
|
||||
<li><a href="https://www.siue.edu/~njohnag/">Nicholas Johnson</a> bug fixes</li>
|
||||
</ul>
|
||||
|
16
tests/test_config.py
Normal file
16
tests/test_config.py
Normal file
@ -0,0 +1,16 @@
|
||||
import sys, os
|
||||
sys.path.append(".")
|
||||
sys.path.append("src/")
|
||||
import unittest, uuid, json
|
||||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||
print("Test directory:", TEST_DIR)
|
||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||
import onionrblocks
|
||||
from utils import createdirs
|
||||
from utils import readstatic
|
||||
createdirs.create_dirs()
|
||||
class OnionrConfigTest(unittest.TestCase):
|
||||
def test_security_value(self):
|
||||
return
|
||||
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user