Skip to content

Commit

Permalink
Merge pull request #101 from Native-Planet/nallux_dev
Browse files Browse the repository at this point in the history
v1.0.1-edge
  • Loading branch information
nallux-dozryl authored Dec 30, 2022
2 parents 4f31280 + 1c5b096 commit e8cfacf
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 7 deletions.
18 changes: 18 additions & 0 deletions api/groundseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ def anchor_settings():

return jsonify(404)

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

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

if len(str(sessionid)) != 64:
sessionid = request.cookies.get('sessionid')

if sessionid == None:
return jsonify(404)

if sessionid in orchestrator.config['sessions']:
return jsonify(orchestrator.handle_bug_report(request.get_json()))

return jsonify(404)

# Pier upload
@app.route("/upload", methods=['POST'])
def pier_upload():
Expand Down
61 changes: 60 additions & 1 deletion api/orchestrator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import requests
import os
import sys
import time
Expand Down Expand Up @@ -41,7 +42,7 @@ class Orchestrator:
_disk = None

# GroundSeg
gs_version = 'v1.0.0'
gs_version = 'v1.0.1-edge'
_vm = False
anchor_config = {'lease': None,'ongoing': None}
minIO_on = False
Expand Down Expand Up @@ -319,6 +320,64 @@ def make_cookie(self):
return secret

#
# Bug Report
#

def handle_bug_report(self, data):
try:
# Prep
report = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
os.system(f"mkdir -p {self.config['CFG_DIR']}/bug-reports/{report}")
current_logfile = f"{datetime.now().strftime('%Y-%m')}.log"

with open(f"{self.config['CFG_DIR']}/bug-reports/{report}/details.txt", "w") as f:
f.write(f"Contact:\n{data['person']}\nDetails:\n{data['message']}")
f.close()

# Create zipfile
bug_file = zipfile.ZipFile(
f"{self.config['CFG_DIR']}/bug-reports/{report}/{report}.zip", 'w', zipfile.ZIP_DEFLATED
)

# wireguard config
if self.config['wgRegistered']:
try:
bug_file.writestr('wireguard.log', subprocess.check_output(['docker', 'logs', 'wireguard']))
bug_file.writestr('wg_show.txt', subprocess.check_output(
['docker', 'exec', 'wireguard', 'wg', 'show']
))
except:
pass

# docker ps -a
bug_file.writestr('docker.txt', subprocess.check_output(['docker', 'ps', '-a']).decode('utf-8'))

# current log
bug_file.write(f"{self.config['CFG_DIR']}/logs/{current_logfile}", arcname=current_logfile)

# save zipfile
bug_file.close()

# send to endpoint
bug_endpoint = "https://bugs.groundseg.app"


uploaded_file = open(f"{self.config['CFG_DIR']}/bug-reports/{report}/{report}.zip", 'rb')

form_data = {"contact": data['person'], "string": data['message']}
form_file = {"zip_file": (f"{report}.zip", uploaded_file)}

r = requests.post(bug_endpoint, data=form_data, files=form_file)
Log.log_groundseg(f"Bug report sent on {report}")

return r.status_code

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

return 400
#
# Urbit Pier
#
# Get all piers for home page
Expand Down
14 changes: 13 additions & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
from datetime import datetime
import sys
import os

class Log:

# Log to file
def log_groundseg(text):
print(text, file=sys.stderr)
try:
with open("/opt/nativeplanet/groundseg/groundseg.log", "a") as log:
# make directory if doesn't exist
os.system("mkdir -p /opt/nativeplanet/groundseg/logs")

# current log file
current_logfile = f"{datetime.now().strftime('%Y-%m')}.log"

# move legacy logfile to new directory
if os.path.isfile(f"/opt/nativeplanet/groundseg/groundseg.log"):
os.system(f"mv /opt/nativeplanet/groundseg/groundseg.log /opt/nativeplanet/groundseg/logs/{current_logfile}")

# write to logfile
with open(f"/opt/nativeplanet/groundseg/logs/{current_logfile}", "a") as log:
log.write(f"{datetime.now()} {text}\n")
log.close()
except:
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 @@
v1.0.1-edge,2f54147e03851723c94b5469b0819b6475ee04205103e31fdc4ab00b1fa35257,https://github.com/Native-Planet/GroundSeg/releases/download/v1.0.1-edge/groundseg
v1.0.0,f821c439ab5b4d47867fa40ba3e045f32143e16d7143534b3a6186e4e9a56ec1,https://github.com/Native-Planet/GroundSeg/releases/download/v1.0.0/groundseg
Beta-3.5.6-edge,84c3346dbf510c9557162526163cda94096580e8f1fa3922e2d203f0d9a14583,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.6-edge/groundseg
Beta-3.5.5-edge,55b162adc4e00b4043ae1a900272d24a651b1256729bc95f2d7ee761a49b33fe,https://github.com/Native-Planet/GroundSeg/releases/download/beta-3.5.5-edge/groundseg
Expand Down
38 changes: 38 additions & 0 deletions ui/src/lib/BugButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script>
import { afterUpdate } from 'svelte'
import { page } from '$app/stores'
import Fa from 'svelte-fa'
import { faBug } from '@fortawesome/free-solid-svg-icons'
let hide = false, blur = false
afterUpdate(()=> {
hide = ($page.routeId == 'login')
blur = ($page.routeId == 'report-issue')
})
</script>

<a href='/report-issue' class:hide={hide} class:blur={blur}>
<div class="img">
<Fa icon={faBug} size="1.2x" />
</div>
</a>

<style>
.blur {
opacity: .3;
pointer-events: none;
}
.hide {
opacity: 0;
pointer-events: none;
}
a {
position:absolute;
right: 0px;
top: 3px;
}
.img {height: 24px; margin: 20px; color: white}
</style>
4 changes: 0 additions & 4 deletions ui/src/lib/SysInfoLite.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
font-size: 18px;
padding-bottom: 8px;
}
.hw {
display: flex;
font-size: 14px;
}
.hw-version {
display: flex;
font-size: 14px;
Expand Down
2 changes: 1 addition & 1 deletion ui/src/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writable } from 'svelte/store'

export const webuiVersion = 'v1.0.0'
export const webuiVersion = 'v1.0.1-edge'

//
// fade transition params
Expand Down
2 changes: 2 additions & 0 deletions ui/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import SettingsButton from '$lib/SettingsButton.svelte'
import AnchorButton from '$lib/AnchorButton.svelte'
import HomeButton from '$lib/HomeButton.svelte'
import BugButton from '$lib/BugButton.svelte'
import PowerScreen from '$lib/PowerScreen.svelte'
import NoConnection from '$lib/NoConnection.svelte'
Expand Down Expand Up @@ -64,6 +65,7 @@
<AnchorButton />
<HomeButton />
<slot/>
<BugButton />
</div>
{/if}
</div>
Expand Down
24 changes: 24 additions & 0 deletions ui/src/routes/report-issue/+page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @type {import('./$types').PageServerLoad} */
import { env } from '$env/dynamic/private'

export const prerender = false;

export function load({ cookies }) {
const sessionid = cookies.get('sessionid');

let url = "http://" + env.HOST_HOSTNAME + ".local:27016"
let query = 'http://127.0.0.1:27016/cookies?sessionid=' + sessionid

let d = fetch(query, {credentials:"include"})
.then(j => j.json())
.then(r => {return {api:url,status:r}})
.catch(err => {
console.log(err)
if ((typeof err) == 'object') {
err = 'noconn'
}
return {status:err}
})

return d
}
129 changes: 129 additions & 0 deletions ui/src/routes/report-issue/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<script>
import { onMount } from 'svelte'
import Logo from '$lib/Logo.svelte'
import Card from '$lib/Card.svelte'
import PrimaryButton from '$lib/PrimaryButton.svelte'
import { updateState, api } from '$lib/api'
export let data
updateState(data)
let description = '', buttonStatus = 'standard', person = ''
onMount(()=> {
if (data['status'] == 404) {
window.location.href = "/login"
}
})
const submitReport = () => {
buttonStatus = 'loading'
fetch($api + '/bug', {
method: 'POST',
credentials: "include",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({'person':person,'message':description.trim()})
})
.then(raw => raw.json())
.then(res => {
if (res == 200) {
buttonStatus = 'success'
setTimeout(()=> person = '', 3000)
setTimeout(()=> description = '', 3000)
} else {
buttonStatus = 'failure'
}
setTimeout(()=> buttonStatus = 'standard', 3000)
})
.catch(err => {
console.log(err)
buttonStatus = 'failure'
setTimeout(()=> buttonStatus = 'standard', 3000)
})
}
</script>

<Card width="540px">
<Logo t="Report an issue to Native Planet"/>
<div class="disclaimer">
<div class="title">Information sent to Native Planet:</div>
<ul>
<li>GroundSeg logs</li>
<li>StarTram information (if available)</li>
<li>List of docker containers on your device</li>
</ul>
</div>
<div class="input-title">How should we contact you?</div>
<input type="text" bind:value={person} placeholder="~sampel-palnet or [email protected]" />
<div class="input-title">Describe your issue. Include as much information as you can:</div>
<textarea bind:value={description} placeholder="eg. ~zod doesn't turn on when I try to toggle the switch.."/>
<div class="submit">
<PrimaryButton
on:click={submitReport}
noMargin={true}
status={(person.length > 0) && (description.length > 0) ? buttonStatus : "disabled"}
standard="Submit Report"
loading="Submitting your but report..."
success="Bug report sent!"
failure="Something went wrong"
/>
</div>
</Card>

<style>
.title {
font-size: 14px;
}
ul {
font-size: 12px;
margin: none;
}
.disclaimer {
margin: 20px;
}
.input-title {
font-size: 14px;
}
input {
margin-top: 12px;
margin-bottom: 24px;
width: calc(100% - 40px);
color: inherit;
font-family: inherit;
resize: none;
background: #ffffff4d;
border: none;
border-radius: 8px;
padding: 8px 20px 8px 20px;
}
input:focus {
outline: none;
}
input::placeholder {
color: inherit;
}
textarea {
margin-top: 12px;
width: calc(100% - 40px);
color: inherit;
font-family: inherit;
height: 240px;
resize: none;
background: #ffffff4d;
border: none;
border-radius: 16px;
padding: 20px;
}
textarea:focus {
outline: none;
}
textarea::placeholder {
color: inherit;
}
.submit {
margin-top: 24px;
text-align: center;
}
</style>
16 changes: 16 additions & 0 deletions ui/src/routes/startram/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
<!-- Register Key -->
<AnchorRegisterKey wgReg={data.anchor.wgReg} />

<div class="sign-up">
<a href="https://www.nativeplanet.io/startram" target="_blank">
Need a startram registration key? Get one here!
</a>
</div>

<!-- Advanced Options -->
<AnchorAdvanced wgReg={data.anchor.wgReg} />
</Card>
Expand All @@ -95,4 +101,14 @@
padding: 2px 8px;
border-radius: 8px;
}
.sign-up {
margin-top: 12px;
margin-left: 2px;
}
a {
color: inherit;
font-size: 12px;
text-decoration: underline;
cursor: pointer;
}
</style>

0 comments on commit e8cfacf

Please sign in to comment.