work on board plugin and api

This commit is contained in:
Kevin Froman 2018-12-26 23:27:46 -06:00
parent 2289171b0f
commit c0fe0896ee
4 changed files with 78 additions and 14 deletions

View File

@ -222,7 +222,6 @@ class API:
This also saves the used host (random localhost IP address) to the data folder in host.txt This also saves the used host (random localhost IP address) to the data folder in host.txt
''' '''
# assert isinstance(onionrInst, onionr.Onionr) # assert isinstance(onionrInst, onionr.Onionr)
print(type(onionrInst))
# configure logger and stuff # configure logger and stuff
onionr.Onionr.setupConfig('data/', self = self) onionr.Onionr.setupConfig('data/', self = self)
@ -235,7 +234,7 @@ class API:
bindPort = int(config.get('client.client.port', 59496)) bindPort = int(config.get('client.client.port', 59496))
self.bindPort = bindPort self.bindPort = bindPort
self.whitelistEndpoints = ('site', 'www', 'onionrhome', 'board', 'boardContent') self.whitelistEndpoints = ('site', 'www', 'onionrhome', 'board', 'boardContent', 'sharedContent')
self.clientToken = config.get('client.webpassword') self.clientToken = config.get('client.webpassword')
self.timeBypassToken = base64.b16encode(os.urandom(32)).decode() self.timeBypassToken = base64.b16encode(os.urandom(32)).decode()
@ -278,6 +277,9 @@ class API:
@app.route('/board/<path:path>', endpoint='boardContent') @app.route('/board/<path:path>', endpoint='boardContent')
def boardContent(path): def boardContent(path):
return send_from_directory('static-data/www/board/', path) return send_from_directory('static-data/www/board/', path)
@app.route('/shared/<path:path>', endpoint='sharedContent')
def sharedContent(path):
return send_from_directory('static-data/www/shared/', path)
@app.route('/www/<path:path>', endpoint='www') @app.route('/www/<path:path>', endpoint='www')
def wwwPublic(path): def wwwPublic(path):

View File

@ -1,30 +1,56 @@
webpassword = '' webpassword = ''
requested = {} requested = []
document.getElementById('feed').innerText = 'none :)'
document.getElementById('webpassWindow').style.display = 'block';
var windowHeight = window.innerHeight;
document.getElementById('webpassWindow').style.height = windowHeight + "px";
function httpGet(theUrl) { function httpGet(theUrl) {
var xmlHttp = new XMLHttpRequest() var xmlHttp = new XMLHttpRequest()
xmlHttp.open( "GET", theUrl, false ) // false for synchronous request xmlHttp.open( "GET", theUrl, false ) // false for synchronous request
xmlHttp.setRequestHeader('token', webpassword) xmlHttp.setRequestHeader('token', webpassword)
xmlHttp.send( null ) xmlHttp.send( null )
return xmlHttp.responseText if (xmlHttp.status == 200){
return xmlHttp.responseText
}
else{
return "";
}
} }
function appendMessages(msg){ function appendMessages(msg){
document.getElementById('feed').append(msg) el = document.createElement('div')
el.className = 'entry'
el.innerText = msg
document.getElementById('feed').appendChild(el)
document.getElementById('feed').appendChild(document.createElement('br')) document.getElementById('feed').appendChild(document.createElement('br'))
} }
function getBlocks(){ function getBlocks(){
if (document.getElementById('none') !== null){
document.getElementById('none').remove();
}
var feedText = httpGet('/getblocksbytype/txt') var feedText = httpGet('/getblocksbytype/txt')
var blockList = feedText.split(',') var blockList = feedText.split(',')
for (i = 0; i < blockList.length; i++){ for (i = 0; i < blockList.length; i++){
bl = httpGet('/gethtmlsafeblockdata/' + blockList[i]) if (! requested.includes(blockList[i])){
appendMessages(bl) bl = httpGet('/gethtmlsafeblockdata/' + blockList[i])
} appendMessages(bl)
requested.push(blockList[i])
}
}
} }
document.getElementById('webpassword').oninput = function(){ document.getElementById('registerPassword').onclick = function(){
webpassword = document.getElementById('webpassword').value webpassword = document.getElementById('webpassword').value
if (httpGet('/ping') === 'pong!'){
document.getElementById('webpassWindow').style.display = 'none'
getBlocks()
}
else{
alert('Sorry, but that password appears invalid.')
}
} }
document.getElementById('refreshFeed').onclick = function(){ document.getElementById('refreshFeed').onclick = function(){

View File

@ -5,12 +5,17 @@
<title> <title>
OnionrBoard OnionrBoard
</title> </title>
<link rel='stylesheet' href='theme.css'>
</head> </head>
<body> <body>
<h1>Onionr Board</h1> <div id='webpassWindow' class='hidden'>
<input id='webpassword' type='password' placeholder="Web password for daemon"> <p>Welcome to OnionrBoard</p>
<p>Please enter the webpassword. You can get this from running the 'details' command in Onionr.</p>
<input id='webpassword' type='password' placeholder="Web password for daemon" value='7AF13568657CE63D6DB7E686BF05537D36598ED739B21E3F023E3FD3DEA2FC8F'>
<button id='registerPassword'>Unlock Onionr</button>
</div>
<input type='button' id='refreshFeed' value='Refresh Feed'> <input type='button' id='refreshFeed' value='Refresh Feed'>
<div id='feed'></div> <div id='feed'><span id='none'>None Yet :)</span></div>
<script src='board.js'></script> <script src='board.js'></script>
</body> </body>
</html> </html>

View File

@ -0,0 +1,31 @@
h1, h2, h3{
font-family: sans-serif;
}
.hidden{
display: none;
}
p{
font-family: sans-serif;
}
#webpassWindow{
background-color: black;
border: 1px solid black;
border-radius: 5px;
width: 100%;
z-index: 2;
color: white;
text-align: center;
}
.entry{
color: red;
}
#feed{
margin-left: 2%;
margin-right: 25%;
margin-top: 1em;
border: 2px solid black;
padding: 5px;
min-height: 50px;
}