- Your Capsul was successfully created! You should already see it listed on the
- Capsuls page, but it may not have obtained an IP address yet.
- Its IP address should become visible once the machine has booted and taken a DHCP lease.
-
- {% if created_os == 'debian10' %}
-
- Note: because Debian delays fully booting until after entropy has been generated, Debian Capsuls
- may take an extra-long time to obtain an IP address, like up to 10 minutes. Be patient.
-
- {% endif %}
-{% else %}
+
+
+
+
{% if cant_afford %}
Your account does not have sufficient funds to create a Capsul.
@@ -79,14 +68,24 @@
-
+
+ ..Creating...
+
-
{% endif %}
-{% endif %}
-
+
+
{% endblock %}
{% block subcontent %}
From 5c1a977a874500315637f75ba7923a1ea2994bcf Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:05:45 -0500
Subject: [PATCH 07/15] remove query string XSS from login token
---
capsulflask/auth.py | 4 ++++
capsulflask/console.py | 2 ++
2 files changed, 6 insertions(+)
diff --git a/capsulflask/auth.py b/capsulflask/auth.py
index cda0942..53e31a6 100644
--- a/capsulflask/auth.py
+++ b/capsulflask/auth.py
@@ -71,6 +71,10 @@ def magiclink(token):
session["account"] = email
return redirect(url_for("console.index"))
else:
+ # this is here to prevent xss
+ if not re.match(r"^[a-zA-Z0-9_-]+$", token):
+ token = '___________'
+
abort(404, f"Token {token} doesn't exist or has already been used.")
@bp.route("/logout")
diff --git a/capsulflask/console.py b/capsulflask/console.py
index 59797c0..5038ffb 100644
--- a/capsulflask/console.py
+++ b/capsulflask/console.py
@@ -45,6 +45,8 @@ def double_check_capsul_address(id, ipv4):
def index():
vms = get_vms()
created = request.args.get('created')
+
+ # this is here to prevent xss
if not re.match(r"^(cvm|capsul)-[a-z0-9]{10}$", created):
created = '___________'
From 4f002458b30156669e766222976ae729944e2e70 Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:11:47 -0500
Subject: [PATCH 08/15] adjust memory metric query
---
capsulflask/metrics.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/capsulflask/metrics.py b/capsulflask/metrics.py
index 1e71b0a..b09c590 100644
--- a/capsulflask/metrics.py
+++ b/capsulflask/metrics.py
@@ -86,7 +86,7 @@ def get_plot_bytes(metric, capsulid, duration, size):
# Prometheus queries to pull metrics for VMs
metric_queries = dict(
cpu=f"irate(libvirtd_domain_info_cpu_time_seconds_total{{domain='{capsulid}'}}[30s])",
- memory=f"libvirtd_domain_info_memory_usage_bytes{{domain='{capsulid}'}}",
+ memory=f"libvirtd_domain_info_memory_max_bytes{{domain='{capsulid}'}}-libvirtd_domain_info_memory_unused_bytes{{domain='{capsulid}'}}",
network_in=f"rate(libvirtd_domain_interface_stats_receive_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
network_out=f"rate(libvirtd_domain_interface_stats_transmit_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
disk=f"rate(libvirtd_domain_block_stats_read_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])%2Brate(libvirtd_domain_block_stats_write_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
From 4b169e98863a95d6ae98f0c3155f14f2102d2f8a Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:21:09 -0500
Subject: [PATCH 09/15] implement bill for at least 24 hours
---
capsulflask/console.py | 7 +++++--
capsulflask/templates/create-capsul.html | 3 ++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/capsulflask/console.py b/capsulflask/console.py
index 5038ffb..ca1e6c9 100644
--- a/capsulflask/console.py
+++ b/capsulflask/console.py
@@ -45,7 +45,7 @@ def double_check_capsul_address(id, ipv4):
def index():
vms = get_vms()
created = request.args.get('created')
-
+
# this is here to prevent xss
if not re.match(r"^(cvm|capsul)-[a-z0-9]{10}$", created):
created = '___________'
@@ -274,7 +274,10 @@ def get_account_balance(vms, payments, as_of):
vm_cost_dollars = 0.0
for vm in vms:
end_datetime = vm["deleted"] if vm["deleted"] else as_of
- vm_months = ( end_datetime - vm["created"] ).days / average_number_of_days_in_a_month
+ days = float((end_datetime - vm["created"]).total_seconds())/float(60*60*24)
+ if days < 1:
+ days = float(1)
+ vm_months = days / average_number_of_days_in_a_month
vm_cost_dollars += vm_months * float(vm["dollars_per_month"])
payment_dollars_total = float( sum(map(lambda x: 0 if x["invalidated"] else x["dollars"], payments)) )
diff --git a/capsulflask/templates/create-capsul.html b/capsulflask/templates/create-capsul.html
index d9a24fd..bb27042 100644
--- a/capsulflask/templates/create-capsul.html
+++ b/capsulflask/templates/create-capsul.html
@@ -25,7 +25,7 @@
CAPSUL SIZES
============
- type monthly cpus mem ssd net*
+ type monthly* cpus mem ssd net*
----- ------- ---- --- --- ---
f1-s $5.33 1 512M 25G .5TB
f1-m $7.16 1 1024M 25G 1TB
@@ -35,6 +35,7 @@
f1-xxx $57.58 8 16G 25G 16TB
* net is calculated as a per-month average
+ * vms are billed for a minimum of 24 hours upon creation
* all VMs come standard with one public IPv4 addr
Your account balance: ${{ account_balance }}
From 684128361ca23a4acfa8a9af99b102148149ae7d Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:24:11 -0500
Subject: [PATCH 10/15] correctly display vm_months
---
capsulflask/console.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/capsulflask/console.py b/capsulflask/console.py
index ca1e6c9..65e2c16 100644
--- a/capsulflask/console.py
+++ b/capsulflask/console.py
@@ -269,15 +269,18 @@ def get_payments():
average_number_of_days_in_a_month = 30.44
+def get_vm_months_float(vm, as_of):
+ end_datetime = vm["deleted"] if vm["deleted"] else as_of
+ days = float((end_datetime - vm["created"]).total_seconds())/float(60*60*24)
+ if days < 1:
+ days = float(1)
+ return days / average_number_of_days_in_a_month
+
def get_account_balance(vms, payments, as_of):
vm_cost_dollars = 0.0
for vm in vms:
- end_datetime = vm["deleted"] if vm["deleted"] else as_of
- days = float((end_datetime - vm["created"]).total_seconds())/float(60*60*24)
- if days < 1:
- days = float(1)
- vm_months = days / average_number_of_days_in_a_month
+ vm_months = get_vm_months_float(vm, as_of)
vm_cost_dollars += vm_months * float(vm["dollars_per_month"])
payment_dollars_total = float( sum(map(lambda x: 0 if x["invalidated"] else x["dollars"], payments)) )
@@ -314,9 +317,7 @@ def account_balance():
vms_billed = list()
for vm in get_vms():
- end_datetime = vm["deleted"] if vm["deleted"] else datetime.utcnow()
-
- vm_months = (end_datetime - vm["created"]).days / average_number_of_days_in_a_month
+ vm_months = get_vm_months_float(vm, datetime.utcnow())
vms_billed.append(dict(
id=vm["id"],
dollars_per_month=vm["dollars_per_month"],
From 62a062fff2091f264d8d9b34e33b448e3b49f852 Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:28:21 -0500
Subject: [PATCH 11/15] fix bug when created query string is not present
---
capsulflask/auth.py | 2 +-
capsulflask/console.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/capsulflask/auth.py b/capsulflask/auth.py
index 53e31a6..5509702 100644
--- a/capsulflask/auth.py
+++ b/capsulflask/auth.py
@@ -72,7 +72,7 @@ def magiclink(token):
return redirect(url_for("console.index"))
else:
# this is here to prevent xss
- if not re.match(r"^[a-zA-Z0-9_-]+$", token):
+ if token and not re.match(r"^[a-zA-Z0-9_-]+$", token):
token = '___________'
abort(404, f"Token {token} doesn't exist or has already been used.")
diff --git a/capsulflask/console.py b/capsulflask/console.py
index 65e2c16..d827b4f 100644
--- a/capsulflask/console.py
+++ b/capsulflask/console.py
@@ -47,7 +47,7 @@ def index():
created = request.args.get('created')
# this is here to prevent xss
- if not re.match(r"^(cvm|capsul)-[a-z0-9]{10}$", created):
+ if created and not re.match(r"^(cvm|capsul)-[a-z0-9]{10}$", created):
created = '___________'
# for now we are going to check the IP according to the virt model
From bb90738fdeb5d8ac4ed11151e12a4297d98dcbd7 Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:44:03 -0500
Subject: [PATCH 12/15] libvirtd_domain_info_maximum_memory_bytes
---
capsulflask/metrics.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/capsulflask/metrics.py b/capsulflask/metrics.py
index b09c590..fc33b61 100644
--- a/capsulflask/metrics.py
+++ b/capsulflask/metrics.py
@@ -86,7 +86,7 @@ def get_plot_bytes(metric, capsulid, duration, size):
# Prometheus queries to pull metrics for VMs
metric_queries = dict(
cpu=f"irate(libvirtd_domain_info_cpu_time_seconds_total{{domain='{capsulid}'}}[30s])",
- memory=f"libvirtd_domain_info_memory_max_bytes{{domain='{capsulid}'}}-libvirtd_domain_info_memory_unused_bytes{{domain='{capsulid}'}}",
+ memory=f"libvirtd_domain_info_maximum_memory_bytes{{domain='{capsulid}'}}-libvirtd_domain_info_memory_unused_bytes{{domain='{capsulid}'}}",
network_in=f"rate(libvirtd_domain_interface_stats_receive_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
network_out=f"rate(libvirtd_domain_interface_stats_transmit_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
disk=f"rate(libvirtd_domain_block_stats_read_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])%2Brate(libvirtd_domain_block_stats_write_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
From 633e2907dfe196292be7d782f0b7d2f5d51eec4c Mon Sep 17 00:00:00 2001
From: forest
Date: Sat, 16 May 2020 23:50:39 -0500
Subject: [PATCH 13/15] changelog: 2020-05-16: Beta version of new Capsul web
application
---
capsulflask/templates/changelog.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/capsulflask/templates/changelog.html b/capsulflask/templates/changelog.html
index 89deb19..685bc5d 100644
--- a/capsulflask/templates/changelog.html
+++ b/capsulflask/templates/changelog.html
@@ -19,6 +19,7 @@
2020-04-17: OpenBSD support added
2020-04-26: Support link added
2020-05-04: Simplified payment page
+
2020-05-16: Beta version of new Capsul web application
{% endblock %}
From 496db2bb06c7bd3ccad6e10c30a5772289e72196 Mon Sep 17 00:00:00 2001
From: forest
Date: Sun, 17 May 2020 00:00:36 -0500
Subject: [PATCH 14/15] add new tables to 02_down migration script
---
capsulflask/schema_migrations/02_down_accounts_vms_etc.sql | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/capsulflask/schema_migrations/02_down_accounts_vms_etc.sql b/capsulflask/schema_migrations/02_down_accounts_vms_etc.sql
index 195be9b..9910c89 100644
--- a/capsulflask/schema_migrations/02_down_accounts_vms_etc.sql
+++ b/capsulflask/schema_migrations/02_down_accounts_vms_etc.sql
@@ -1,3 +1,7 @@
+DROP TABLE unresolved_btcpay_invoices;
+
+DROP TABLE payment_sessions;
+
DROP TABLE payments;
DROP TABLE login_tokens;
From 17c559123cb32c98b87da2528921882c955f4613 Mon Sep 17 00:00:00 2001
From: forest
Date: Sun, 17 May 2020 00:04:15 -0500
Subject: [PATCH 15/15] readme explain \n in BTCPAY_PRIVATE_KEY
---
README.md | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index f51317c..4c59d52 100644
--- a/README.md
+++ b/README.md
@@ -152,10 +152,8 @@ And you should see the token in the btcpay server UI:
Now simply set your `BTCPAY_PRIVATE_KEY` variable in `.env`
+NOTE: make sure to use single quotes and replace the new lines with \n.
+
```
-BTCPAY_PRIVATE_KEY='-----BEGIN EC PRIVATE KEY-----
-EXAMPLEIArx/EXAMPLEKH23EXAMPLEsYXEXAMPLE5qdEXAMPLEcFHoAcEXAMPLEK
-oUQDQgAEnWs47PT8+ihhzyvXX6/yYMAWWODluRTR2Ix6ZY7Z+MV7v0W1maJzqeqq
-NQ+cpBvPDbyrDk9+Uf/sEaRCma094g==
------END EC PRIVATE KEY-----'
+BTCPAY_PRIVATE_KEY='-----BEGIN EC PRIVATE KEY-----\nEXAMPLEIArx/EXAMPLEKH23EXAMPLEsYXEXAMPLE5qdEXAMPLEcFHoAcEXAMPLEK\noUQDQgAEnWs47PT8+ihhzyvXX6/yYMAWWODluRTR2Ix6ZY7Z+MV7v0W1maJzqeqq\nNQ+cpBvPDbyrDk9+Uf/sEaRCma094g==\n-----END EC PRIVATE KEY-----'
```
\ No newline at end of file