Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple webapp for config #1616

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
29a53c5
Initial working server + client for modifying config, running commands
summerisgone Oct 13, 2019
7dd4044
Initial webapp version
summerisgone Oct 14, 2019
b9bffa3
Update requirements.txt
summerisgone Oct 14, 2019
4867a03
Replaced shell with playbook CLI, structured js app
summerisgone Nov 21, 2019
28ac131
Added loading indication for DO regions
summerisgone Feb 25, 2020
42650e2
Copy-pasted playbook CLI, passing host vars as result
summerisgone Feb 25, 2020
9ee5238
WIP splitting into modules
summerisgone Mar 12, 2020
34211a0
added DO provider module
summerisgone Mar 12, 2020
992b2d6
Added full-page steps with transitions
summerisgone Apr 1, 2020
32a8b08
Removed do regions request, re-added run and status
summerisgone Apr 1, 2020
2a22234
Improved secret gathering
summerisgone Apr 4, 2020
89c2330
App cleanup
summerisgone Apr 4, 2020
dd2a05a
Docker env, added save&exit step
summerisgone May 15, 2020
8156687
Better variable gathering, fixed empty DNS IP
summerisgone May 18, 2020
2f9fa4d
Draft amazon lightsail provider
summerisgone May 18, 2020
dfa2990
Lightsail provided added
summerisgone May 22, 2020
2da62f4
Added EC2 provider
summerisgone May 24, 2020
149e7dd
Draft for GCE
summerisgone Jul 12, 2020
97d3fab
Added GCE provider
summerisgone Jul 19, 2020
97a931d
Added Vultr provider
summerisgone Aug 7, 2020
12e7533
Added scaleway provider
summerisgone Aug 7, 2020
ca3230c
Improved error handling when vpn host not created
summerisgone Aug 8, 2020
80f04de
Updated DigitalOcean UX, proxied requests to it
summerisgone Oct 27, 2020
bfd0895
Updated playbook.py from recent ansible version
summerisgone Oct 27, 2020
16b5e55
Added region-select and env secrets to lightsail
summerisgone Oct 29, 2020
a8ccad9
Secrets from env for EC2 provider
summerisgone Oct 29, 2020
2aeb292
Unified UX for Vultr & Scaleway
summerisgone Nov 2, 2020
e887387
Added Hetzner provider
summerisgone Jan 20, 2021
00271f2
Added Azure provider
summerisgone Jan 26, 2021
01bd17d
Added Linode support
summerisgone Jan 27, 2021
465b8e6
WIP: CLoudStack provider
summerisgone Jan 29, 2021
27d21db
Added CloudStack (exoscale) provider setup
summerisgone May 29, 2021
7d2ddff
Updated Vultr provider UX
summerisgone May 29, 2021
6a72539
Minor updates
summerisgone May 29, 2021
15b0d1f
Added local and openstack providers
summerisgone May 29, 2021
76cb02b
Added README file
Aug 30, 2022
1668f6a
Merge remote-tracking branch 'tob/master' into 196-simple-webapp-config
summerisgone Aug 30, 2022
23f8332
Switched to ansible_runner API
summerisgone Aug 30, 2022
547711d
Show variables from event logs
summerisgone Sep 8, 2022
aa0fff0
More careful variable extraction, without regexp
summerisgone Sep 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed do regions request, re-added run and status
  • Loading branch information
summerisgone committed Jul 6, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 32a8b08c3ab41873273ecbbb909985177da01f64
14 changes: 0 additions & 14 deletions app/server.py
Original file line number Diff line number Diff line change
@@ -100,20 +100,6 @@ async def post_config(request):
return web.json_response({'ok': True})


@routes.post('/do/regions')
async def get_do_regions(request):
data = await request.json()
async with aiohttp.ClientSession() as session:
url = 'https://api.digitalocean.com/v2/regions'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {0}'.format(data['token']),
}
async with session.get(url, headers=headers) as r:
json_body = await r.json()
return web.json_response(json_body)


app = web.Application()
app.router.add_routes(routes)
web.run_app(app, port=9000)
42 changes: 42 additions & 0 deletions app/static/command-preview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<div class="row">
<h2 class="col-12">
<button type="button" class="btn btn-secondary back-button" v-on:click="$emit('back')"><</button>
🧐 Review and Start!
</h2>
<section class="my-3">
<pre class="code"><code>
{{cli_preview}}
</code></pre>
<button v-on:click="$emit('submit')" class="btn btn-primary" type="button">Run!</button>
</section>
</div>
</template>

<script>
module.exports = {
props: ['extra_args'],
computed: {
cli_preview: function() {
let args = "";
for (arg in this.extra_args) {
args += `${arg}=${this.extra_args[arg]} `;
}
return `ansible-playbook main.yml --extra-vars ${args}`;
}
}
}
</script>
<style scoped>
.back-button {
position: absolute;
border-radius: 50%;
left: -2em;
}
.code {
white-space: normal;
background: black;
color: lightgrey;
padding: 1em;
}
</style>
47 changes: 39 additions & 8 deletions app/static/index.html
Original file line number Diff line number Diff line change
@@ -28,16 +28,28 @@ <h1 class="mb-5 text-center">{{ title }}</h1>
<user-config class="col-md-4 order-md-2 mb-4"></user-config>
<vpn-setup class="col-md-8 order-md-1"
v-bind:extra_args="extra_args"
v-on:submit="set_step('provider'); update_extra_args"></vpn-setup>
v-on:submit="step = 'provider'"></vpn-setup>
</div>
</transition>
<transition name="fade">
<provider-setup v-if="step == 'provider'"
v-bind:extra_args="extra_args"
v-on:submit="update_extra_args"
v-on:back="set_step('setup')">
v-on:submit="step = 'command'"
v-on:back="step = 'setup'">
</provider-setup>
</transition>
<transition name="fade">
<command-preview v-if="step == 'command'"
v-bind:extra_args="extra_args"
v-on:submit="start(); step = 'running';"
v-on:back="step = 'provider'">
</command-preview>
</transition>
<transition name="fade">
<status-running v-if="step == 'running'"
v-on:submit="stop(); step = 'setup';">
</status-running>
</transition>
</div>

<script>
@@ -47,7 +59,7 @@ <h1 class="mb-5 text-center">{{ title }}</h1>
playbook: {},
step: 'setup',
extra_args: {
server_name: "algo",
server_name: 'algo2',
ondemand_cellular: false,
ondemand_wifi: false,
dns_adblocking: false,
@@ -65,13 +77,32 @@ <h1 class="mb-5 text-center">{{ title }}</h1>
'user-config': window.httpVueLoader('/static/user-config.vue'),
'vpn-setup': window.httpVueLoader('/static/vpn-setup.vue'),
'provider-setup': window.httpVueLoader('/static/provider-setup.vue'),
'command-preview': window.httpVueLoader('/static/command-preview.vue'),
'status-running': window.httpVueLoader('/static/status-running.vue'),
},
created() {
fetch("/playbook")
.then(r => r.json())
.then(data => {
if (data.status === 'running') {
this.step = 'running';
}
});
},
methods: {
set_step: function(step) {
this.step = step;
start: function() {
fetch("/playbook", {
method: "POST",
body: JSON.stringify(this.extra_args),
headers: {
"Content-Type": "application/json"
}
});
},
update_extra_args: function(extra_args) {
Object.assign(this.extra_args, extra_args);
stop() {
fetch("/playbook", {
method: "DELETE"
});
}
}
})
11 changes: 5 additions & 6 deletions app/static/provider-do.vue
Original file line number Diff line number Diff line change
@@ -56,12 +56,11 @@ module.exports = {
methods: {
load_do_regions: function () {
this.do_region_loading = true;
fetch("/do/regions", {
method: "POST",
fetch('https://api.digitalocean.com/v2/regions', {
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ token: this.do_token })
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.do_token}`
}
})
.then(r => r.json())
.then(r => {
@@ -79,4 +78,4 @@ module.exports = {
}
}
};
</script>
</script>
10 changes: 7 additions & 3 deletions app/static/provider-setup.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="row" id="prodiver_id">
<div class="row">
<h2 class="col-12">
<button type="button" class="btn btn-secondary back-button" v-on:click="$emit('back')"><</button>
<span v-if="provider">{{ provider.name }} Setup</span>
@@ -12,7 +12,7 @@
v-bind:key="item.alias">
<a
class="nav-link"
href="#prodiver_id"
href="#"
v-bind:class="{ active: item.alias === (provider && provider.alias) }"
v-on:click="set_provider(item)"
>{{item.name}}</a>
@@ -49,12 +49,16 @@ module.exports = {
]
}
},
// Warning: Mutable Object to edit parent props
props: ['extra_args'],
methods: {
set_provider(provider) {
this.provider = provider;
this.extra_args.provider = provider.alias;
},
on_provider_submit(extra_args) {
this.$emit('submit', Object.assign({provider: this.provider.alias}, extra_args));
Object.assign(this.extra_args, extra_args);
this.$emit('submit');
}
},
components: {
59 changes: 59 additions & 0 deletions app/static/status-running.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<template>
<div class="row status-container">
<h2 class="col-12"><span class="spin">🙃</span>Please be patient</h2>
<section class="status-text">
<p>VPN set up usually takes 5-15 minutes</p>
<p>You can close tab and open it again</p>
<p>You can try to <button type="button" class="btn btn-link back-button" v-on:click="$emit('submit')">STOP</button> setup and run it again</p>
<p>Don’t close terminal!</p>
</section>
</div>
</template>

<script>
module.exports = {
props: function() {
// Warning: Mutable Object to edit partent props
extra_args: Object
},
computed: {
cli_preview() {
return 'ansible-playbook main.yml --extra-vars "server_name=algo ondemand_cellular=true ondemand_wifi=true dns_adblocking=false ssh_tunneling=false store_pki=false ondemand_wifi_exclude=[] provider=digitalocean do_token=ad6b4405df208053e7b41e1c9e74b97364af1d6b902f6b6bb1d5575c52eca0c3 region=blr1"';
}
}
}
</script>
<style scoped>
.back-button {
color: red;
}
.status-container {
display: flex;
flex-direction: column;
}
.status-text {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
.spin {
animation-name: spin;
animation-duration: 5000ms;
animation-iteration-count: infinite;
animation-timing-function: linear;

display: block;
animation-delay: 5s;
width: 1em;
height: 100%;
}
@keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
</style>
6 changes: 2 additions & 4 deletions app/static/vpn-setup.vue
Original file line number Diff line number Diff line change
@@ -103,9 +103,7 @@

<script>
module.exports = {
props: {
// Warning: Mutable Object to edit partent props
extra_args: Object
}
// Warning: Mutable Object to edit partent props
props: ['extra_args']
}
</script>