Skip to content

Commit

Permalink
Merge pull request #87 from Native-Planet/nallux_dev
Browse files Browse the repository at this point in the history
Beta-3.5.2-edge
  • Loading branch information
nallux-dozryl authored Dec 19, 2022
2 parents b1ef9d3 + d223f35 commit 3a9e1d0
Show file tree
Hide file tree
Showing 20 changed files with 417 additions and 16 deletions.
41 changes: 37 additions & 4 deletions api/groundseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ def meld_loop():

time.sleep(30)

threading.Thread(target=check_bin_updates).start() # Start binary updater thread
threading.Thread(target=sys_monitor).start() # Start system monitoring on a new thread
threading.Thread(target=meld_loop).start() # Start meld loop on a new thread
threading.Thread(target=anchor_information).start() # Start anchor information loop on a new thread
# Threads
threading.Thread(target=check_bin_updates).start() # Binary updater
threading.Thread(target=sys_monitor).start() # System monitoring
threading.Thread(target=meld_loop).start() # Meld loop
threading.Thread(target=anchor_information).start() # Anchor information

#
# Endpoints
Expand All @@ -174,6 +175,9 @@ def meld_loop():
# Check if cookie is valid
@app.route("/cookies", methods=['GET'])
def check_cookies():
if orchestrator.config['firstBoot']:
return jsonify('setup')

sessionid = request.args.get('sessionid')

if sessionid in orchestrator.config['sessions']:
Expand All @@ -184,6 +188,9 @@ def check_cookies():
# Get all urbits
@app.route("/urbits", methods=['GET'])
def all_urbits():
if orchestrator.config['firstBoot']:
return jsonify('setup')

sessionid = request.args.get('sessionid')

if len(str(sessionid)) != 64:
Expand All @@ -203,6 +210,9 @@ def all_urbits():
# Handle urbit ID related requests
@app.route('/urbit', methods=['GET','POST'])
def urbit_info():
if orchestrator.config['firstBoot']:
return jsonify('setup')

urbit_id = request.args.get('urbit_id')
sessionid = request.args.get('sessionid')

Expand All @@ -227,6 +237,9 @@ def urbit_info():
# Handle device's system settings
@app.route("/system", methods=['GET','POST'])
def system_settings():
if orchestrator.config['firstBoot']:
return jsonify('setup')

sessionid = request.args.get('sessionid')

if len(str(sessionid)) != 64:
Expand All @@ -251,6 +264,9 @@ def system_settings():
# Handle anchor registration related information
@app.route("/anchor", methods=['GET'])
def anchor_settings():
if orchestrator.config['firstBoot']:
return jsonify('setup')

sessionid = request.args.get('sessionid')

if len(str(sessionid)) != 64:
Expand All @@ -270,6 +286,9 @@ def anchor_settings():
# Pier upload
@app.route("/upload", methods=['POST'])
def pier_upload():
if orchestrator.config['firstBoot']:
return jsonify('setup')

sessionid = request.args.get('sessionid')

if len(str(sessionid)) != 64:
Expand Down Expand Up @@ -339,6 +358,9 @@ def pier_upload():
# Login
@app.route("/login", methods=['POST'])
def login():
if orchestrator.config['firstBoot']:
return jsonify('setup')

res = orchestrator.handle_login_request(request.get_json())
if res == 200:
res = make_response(jsonify(res))
Expand All @@ -348,6 +370,17 @@ def login():

return res

# Setup
@app.route("/setup", methods=['POST'])
def setup():
if not orchestrator.config['firstBoot']:
return jsonify(400)

page = request.args.get('page')

res = orchestrator.handle_setup(page, request.get_json())

return jsonify(res)

if __name__ == '__main__':
debug_mode = False
Expand Down
37 changes: 35 additions & 2 deletions api/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Orchestrator:
_disk = None

# GroundSeg
gs_version = 'Beta-3.5.1-edge'
gs_version = 'Beta-3.5.2-edge'
anchor_config = {'lease': None,'ongoing': None}
minIO_on = False
config = {}
Expand All @@ -67,8 +67,9 @@ def __init__(self, config_file):

# if first boot, set up keys
if self.config['firstBoot']:
Log.log_groundseg("GroundSeg is in setup mode")
self.reset_pubkey()
self.config['firstBoot'] = False
#self.config['firstBoot'] = False

# save the latest config to file
self.save_config()
Expand Down Expand Up @@ -201,6 +202,38 @@ def load_urbits(self):

Log.log_groundseg("Urbit Piers loaded")

#
# Setup
#

def handle_setup(self, page, data):
try:
if page == "anchor":
# set endpoint
changed = self.change_wireguard_url(data['endpoint'])

# register key
if changed == 200:
registered = self.register_device(data['key'])

if registered == 400:
return 401

return registered


if page == "password":
self.create_password(data['password'])
self.config['firstBoot'] = False
return 200

except Exception as e:
Log.log_groundseg(e)
pass

return 401


#
# Login
#
Expand Down
2 changes: 1 addition & 1 deletion release/groundseg_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sudo firewall-cmd --reload
ACC=Native-Planet
REPO=GroundSeg
BRANCH=main
TAG=beta-3.3.7
TAG=beta-3.5.1

# Directory to save the scrips
SAVE_DIR=/opt/nativeplanet/groundseg
Expand Down
1 change: 1 addition & 0 deletions release/version.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Beta-3.5.1,0cce788b8c0f2325db516f3a7635ff82e07b880f15f4d54257552410e853ca63,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.1/groundseg
Beta-3.5.0,79c4c71dfede94a2f0ea3d5331437872acb130664f1e9d492c127c2e13d16be1,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.0/groundseg
Beta-3.4.0,eb1f6f327e160ad192fde4996791758ae711538ca966b0cd1f679fd7ebee5824,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.4.0/groundseg
Beta-3.3.7,5a3df4778cc58fa60fcbd5c765fd27f3939be49bd3ae25c37ba0a5e453e6e076,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.3.7/groundseg
Expand Down
1 change: 1 addition & 0 deletions release/version_edge.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Beta-3.5.2-edge,2227a08abc4fd405a866858b87e0dc4f4777956a659033e2199ea7ce3139f064,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.2-edge/groundseg
Beta-3.5.1-edge,c8bd6bab5e57aadcd9c7fd7369e2845761d1446797455bbd30aa36a1fa799fef,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.1-edge/groundseg
Beta-3.5.0-edge,43429e4b06016fe1c57d3bd23a41bbf546dac292b6bc6937ae34015a9164def1,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.0-edge/groundseg
Beta-3.4.0-edge,6edf1bac09c511986d2ade2f336eee4d4c24651f2fc25e386a9b071a8264b172,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.4.0-edge/groundseg
Expand Down
3 changes: 1 addition & 2 deletions ui/src/lib/AnchorButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@

<style>
.blur {
opacity: .2;
opacity: .3;
pointer-events: none;
filter: blur(2px);
}
.hide {
opacity: 0;
Expand Down
3 changes: 1 addition & 2 deletions ui/src/lib/SettingsButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

<style>
.blur {
opacity: .2;
opacity: .3;
pointer-events: none;
filter: blur(2px);
}
.hide {
opacity: 0;
Expand Down
124 changes: 124 additions & 0 deletions ui/src/lib/SetupAnchor.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<script>
import { api } from '$lib/api'
import { scale } from 'svelte/transition'
import { createEventDispatcher } from 'svelte'
import PrimaryButton from '$lib/PrimaryButton.svelte'
let key = '',
keyView = false,
epKey = '',
defaultEpKey = 'api.startram.io',
buttonStatus = 'standard'
epKey = defaultEpKey
const dispatch = createEventDispatcher()
const insertNP = () => epKey = defaultEpKey
const toggleKeyView = () => {
keyView = !keyView
document.querySelector('#key-input').type = keyView ? 'text' : 'password'
}
const submitAnchor = () => {
let step = "anchor"
let query = {"key":key, "endpoint":epKey}
buttonStatus = "loading"
fetch($api + '/setup?page=' + step, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(query)
})
.then(d => d.json())
.then(res => {
if (res == 400) {
window.location.href = "/login"
}
if (res == 401) {
buttonStatus = "failure"
}
if (res == 200) {
buttonStatus = "success"
setTimeout(()=> dispatch("nextPage"), 3000)
}
setTimeout(()=> buttonStatus = "standard", 3000)
})
}
</script>

<div class="title" in:scale={{duration:120, delay: 200}}>StarTram Key Registration</div>
<div class="reg-key" in:scale={{duration:120, delay: 200}}>
<input id='key-input' type="password" bind:value={key} />
<img on:click={toggleKeyView} src="/eye-{keyView ? "closed" : "open"}.svg" alt="eye" />
</div>

<div class="title">Startram Endpoint</div>
<div class="ep-key" in:scale={{duration:120, delay: 200}}>
<input type="text" bind:value={epKey} />
<img on:click={insertNP} width="24px" src="/nplogo.svg" alt="np logo" />
</div>

<div class="button">
<PrimaryButton
background="#ffffff4d"
standard="Skip"
on:click={()=> dispatch('nextPage')}
/>

{#if ((epKey.length > 0) && (key.length > 0))}
<PrimaryButton
left={false}
status={buttonStatus}
standard="Register"
failure="Registration failed"
success="Registered!"
loading="Registering your key.."
on:click={submitAnchor}
/>
{/if}
</div>

<style>
.title {
text-align: center;
padding: 12px;
}
.reg-key {
display: flex;
padding: 0 20px 0 20px;
}
.ep-key {
display: flex;
padding: 0 20px 0 20px;
}
input {
text-align: center;
font-family: inherit;
background: #ffffff4d;
color: inherit;
border-radius: 6px;
font-size: 12px;
padding: 8px;
border: none;
flex: 1;
}
input:focus {
outline: none;
}
img {
padding-left: 12px;
opacity: .8;
cursor: pointer;
}
.button {
padding-top: 24px;
padding-right: 20px;
display: flex;
}
</style>
Loading

0 comments on commit 3a9e1d0

Please sign in to comment.