refactoring & bug fixes

This commit is contained in:
Kristjan 2020-12-31 18:39:16 +01:00
parent bd4a668d23
commit 128888be92
7 changed files with 47 additions and 23 deletions

View File

@ -16,14 +16,15 @@ async def create_subdomain(
email: str, email: str,
ip: str, ip: str,
sats: int, sats: int,
duration: int duration: int,
record_type: str
) -> Subdomains: ) -> Subdomains:
await db.execute( await db.execute(
""" """
INSERT INTO subdomain (id, domain, email, subdomain, ip, wallet, sats, duration, paid) INSERT INTO subdomain (id, domain, email, subdomain, ip, wallet, sats, duration, paid, record_type)
VALUES (?, ?, ?, ?, ?, ?, ?, ?,?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", """,
(payment_hash, domain, email, subdomain, ip, wallet, sats, duration, False), (payment_hash, domain, email, subdomain, ip, wallet, sats, duration, False, record_type),
) )
subdomain = await get_subdomain(payment_hash) subdomain = await get_subdomain(payment_hash)
@ -69,7 +70,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
url, url,
headers=header, headers=header,
json={ json={
"type": "A", "type": subdomain.record_type,
"name": aRecord, "name": aRecord,
"content": subdomain.ip, "content": subdomain.ip,
"ttl": 0, "ttl": 0,
@ -90,6 +91,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
json={ json={
"domain": subdomain.domain_name, "domain": subdomain.domain_name,
"subdomain": subdomain.subdomain, "subdomain": subdomain.subdomain,
"record_type": subdomain.record_type,
"email": subdomain.email, "email": subdomain.email,
"ip": subdomain.ip, "ip": subdomain.ip,
"cost:": str(subdomain.sats) + " sats", "cost:": str(subdomain.sats) + " sats",
@ -128,14 +130,14 @@ async def delete_subdomain(subdomain_id: str) -> None:
# Domains # Domains
async def create_domain(*, wallet: str, domain: str, cf_token: str, cf_zone_id: str, webhook: Optional[str] = None, description: str, cost: int) -> Domains: async def create_domain(*, wallet: str, domain: str, cf_token: str, cf_zone_id: str, webhook: Optional[str] = None, description: str, cost: int, allowed_record_types: str) -> Domains:
domain_id = urlsafe_short_hash() domain_id = urlsafe_short_hash()
await db.execute( await db.execute(
""" """
INSERT INTO domain (id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, amountmade) INSERT INTO domain (id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, amountmade, allowed_record_types)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", """,
(domain_id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, 0), (domain_id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, 0, allowed_record_types),
) )
domain = await get_domain(domain_id) domain = await get_domain(domain_id)

View File

@ -12,6 +12,7 @@ async def m001_initial(db):
description TEXT NOT NULL, description TEXT NOT NULL,
cost INTEGER NOT NULL, cost INTEGER NOT NULL,
amountmade INTEGER NOT NULL, amountmade INTEGER NOT NULL,
allowed_record_types TEXT NOT NULL,
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')) time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
); );
""" """
@ -29,6 +30,7 @@ async def m001_initial(db):
sats INTEGER NOT NULL, sats INTEGER NOT NULL,
duration INTEGER NOT NULL, duration INTEGER NOT NULL,
paid BOOLEAN NOT NULL, paid BOOLEAN NOT NULL,
record_type TEXT NOT NULL,
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')) time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
); );
""" """

View File

@ -12,6 +12,7 @@ class Domains(NamedTuple):
cost: int cost: int
amountmade: int amountmade: int
time: int time: int
allowed_record_types: str
class Subdomains(NamedTuple): class Subdomains(NamedTuple):
@ -26,3 +27,4 @@ class Subdomains(NamedTuple):
duration: int duration: int
paid: bool paid: bool
time: int time: int
record_type: str

View File

@ -10,15 +10,22 @@
<q-form @submit="Invoice()" class="q-gutter-md"> <q-form @submit="Invoice()" class="q-gutter-md">
<q-input filled dense v-model.trim="formDialog.data.email" type="email" <q-input filled dense v-model.trim="formDialog.data.email" type="email"
label="Your email (optional, if you want a reply)"></q-input> label="Your email (optional, if you want a reply)"></q-input>
<q-input filled dense v-model.trim="formDialog.data.subdomain" type="text" label="subdomain you want"> <q-select dense filled v-model="formDialog.data.record_type" :options='{{domain_allowed_record_types}}'
label="Record type"></q-select>
<q-input filled dense v-model.trim="formDialog.data.subdomain" type="text" label="Subdomain you want">
</q-input> </q-input>
<q-input filled dense v-model.trim="formDialog.data.ip" type="text" label="ip of your server"> <q-input filled dense v-model.trim="formDialog.data.ip" type="text" label="Ip of your server">
</q-input> </q-input>
<q-input filled dense v-model.trim="formDialog.data.duration" type="number" label="{{ domain_cost }} sats per day"> <q-input filled dense v-model.trim="formDialog.data.duration" type="number" label="Number of days">
</q-input> </q-input>
<p>{% raw %}{{amountSats}}{% endraw %}</p> <p>
Cost per day: {{ domain_cost }} sats<br />
{% raw %}
Total cost: {{amountSats}} sats
{% endraw %}</p>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn unelevated color="deep-purple" :disable="formDialog.data.subdomain == '' || formDialog.data.ip == '' || formDialog.data.duration == ''" <q-btn unelevated color="deep-purple"
:disable="formDialog.data.subdomain == '' || formDialog.data.ip == '' || formDialog.data.duration == ''"
type="submit">Submit</q-btn> type="submit">Submit</q-btn>
<q-btn @click="resetForm" flat color="grey" class="q-ml-auto">Cancel</q-btn> <q-btn @click="resetForm" flat color="grey" class="q-ml-auto">Cancel</q-btn>
</div> </div>
@ -65,6 +72,7 @@
subdomain: '', subdomain: '',
duration: '', duration: '',
email: '', email: '',
record_type: ''
} }
}, },
receive: { receive: {
@ -77,12 +85,8 @@
computed: { computed: {
amountSats() { amountSats() {
var sats = this.formDialog.data.duration * parseInt('{{ domain_cost }}') var sats = this.formDialog.data.duration * parseInt('{{ domain_cost }}')
if (sats === parseInt('{{ domain_cost }}')) { this.formDialog.data.sats = sats
return '0 Sats to pay' return sats
} else {
this.formDialog.data.sats = sats
return sats + ' Sats to pay'
}
} }
}, },
@ -93,6 +97,7 @@
this.formDialog.data.email = '' this.formDialog.data.email = ''
this.formDialog.data.ip = '' this.formDialog.data.ip = ''
this.formDialog.data.duration = '' this.formDialog.data.duration = ''
this.formDialog.data.record_type = ''
}, },
closeReceiveDialog: function () { closeReceiveDialog: function () {
@ -112,6 +117,7 @@
email: self.formDialog.data.email, email: self.formDialog.data.email,
sats: self.formDialog.data.sats, sats: self.formDialog.data.sats,
duration: parseInt(self.formDialog.data.duration), duration: parseInt(self.formDialog.data.duration),
record_type: self.formDialog.data.record_type
}) })
.then(function (response) { .then(function (response) {
self.paymentReq = response.data.payment_request self.paymentReq = response.data.payment_request
@ -147,6 +153,7 @@
self.formDialog.data.email = '' self.formDialog.data.email = ''
self.formDialog.data.ip = '' self.formDialog.data.ip = ''
self.formDialog.data.duration = '' self.formDialog.data.duration = ''
self.formDialog.data.record_type = ''
self.$q.notify({ self.$q.notify({
type: 'positive', type: 'positive',
message: 'Sent, thank you!', message: 'Sent, thank you!',

View File

@ -117,7 +117,9 @@
<q-select filled dense emit-value v-model="domainDialog.data.wallet" :options="g.user.walletOptions" <q-select filled dense emit-value v-model="domainDialog.data.wallet" :options="g.user.walletOptions"
label="Wallet *"> label="Wallet *">
</q-select> </q-select>
<q-input filled dense v-model.trim="domainDialog.data.domain" type="text" label="Domain name "></q-input> <q-select dense filled v-model="domainDialog.data.allowed_record_types" multiple :options="dnsRecordTypes"
label="Allowed record types" ></q-select>
<q-input filled dense emit-value v-model.trim="domainDialog.data.domain" type="text" label="Domain name "></q-input>
<q-input filled dense v-model.trim="domainDialog.data.cf_token" type="text" label="Cloudflare API token"> <q-input filled dense v-model.trim="domainDialog.data.cf_token" type="text" label="Cloudflare API token">
</q-input> </q-input>
<q-input filled dense v-model.trim="domainDialog.data.cf_zone_id" type="text" label="Cloudflare Zone Id"> <q-input filled dense v-model.trim="domainDialog.data.cf_zone_id" type="text" label="Cloudflare Zone Id">
@ -159,10 +161,12 @@
return { return {
domains: [], domains: [],
subdomains: [], subdomains: [],
dnsRecordTypes: ['A', 'AAAA', 'CNAME', 'HTTPS', 'TXT', 'SRV', 'LOC', 'MX', 'NS', 'SPF', 'CERT', 'DNSKEY', 'DS', 'NAPTR', 'SMIMEA', 'SSHFP', 'SVCB', 'TLSA', 'URI'],
domainsTable: { domainsTable: {
columns: [ columns: [
{ name: 'id', align: 'left', label: 'ID', field: 'id' }, { name: 'id', align: 'left', label: 'ID', field: 'id' },
{ name: 'domain', align: 'left', label: 'Domain name', field: 'domain' }, { name: 'domain', align: 'left', label: 'Domain name', field: 'domain' },
{ name: 'allowed_record_types', align: 'left', label: 'Allowed record types', field: 'allowed_record_types' },
{ name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet' }, { name: 'wallet', align: 'left', label: 'Wallet', field: 'wallet' },
{ name: 'webhook', align: 'left', label: 'Webhook', field: 'webhook' }, { name: 'webhook', align: 'left', label: 'Webhook', field: 'webhook' },
{ {
@ -186,6 +190,7 @@
columns: [ columns: [
{ name: 'subdomain', align: 'left', label: 'Subdomain name', field: 'subdomain' }, { name: 'subdomain', align: 'left', label: 'Subdomain name', field: 'subdomain' },
{ name: 'domain', align: 'left', label: 'Domain name', field: 'domain_name' }, { name: 'domain', align: 'left', label: 'Domain name', field: 'domain_name' },
{ name: 'record_type', align: 'left', label: 'Record type', field: 'record_type' },
{ {
name: 'email', name: 'email',
align: 'left', align: 'left',
@ -288,7 +293,8 @@
id: this.domainDialog.data.wallet id: this.domainDialog.data.wallet
}) })
var data = this.domainDialog.data var data = this.domainDialog.data
data.allowed_record_types = data.allowed_record_types.join(", ")
console.log(this.domainDialog)
if (data.id) { if (data.id) {
this.updateDomain(wallet, data) this.updateDomain(wallet, data)
} else { } else {
@ -322,6 +328,7 @@
this.domainDialog.data.cf_zone_id = link.cf_zone_id this.domainDialog.data.cf_zone_id = link.cf_zone_id
this.domainDialog.data.webhook = link.webhook this.domainDialog.data.webhook = link.webhook
this.domainDialog.data.cost = link.cost this.domainDialog.data.cost = link.cost
this.domainDialog.data.allowed_record_types = link.allowed_record_types.split(", ")
this.domainDialog.show = true this.domainDialog.show = true
}, },
updateDomain: function (wallet, data) { updateDomain: function (wallet, data) {

View File

@ -17,11 +17,13 @@ async def display(domain_id):
domain = await get_domain(domain_id) domain = await get_domain(domain_id)
if not domain: if not domain:
abort(HTTPStatus.NOT_FOUND, "Domain does not exist.") abort(HTTPStatus.NOT_FOUND, "Domain does not exist.")
allowed_records = domain.allowed_record_types.replace("\"","").replace(" ","").split(",")
print(allowed_records)
return await render_template( return await render_template(
"subdomains/display.html", "subdomains/display.html",
domain_id=domain.id, domain_id=domain.id,
domain_domain=domain.domain, domain_domain=domain.domain,
domain_desc=domain.description, domain_desc=domain.description,
domain_cost=domain.cost, domain_cost=domain.cost,
domain_allowed_record_types=allowed_records
) )

View File

@ -47,6 +47,7 @@ async def api_domains():
"webhook": {"type": "string", "empty": False, "required": False}, "webhook": {"type": "string", "empty": False, "required": False},
"description": {"type": "string", "min": 0, "required": True}, "description": {"type": "string", "min": 0, "required": True},
"cost": {"type": "integer", "min": 0, "required": True}, "cost": {"type": "integer", "min": 0, "required": True},
"allowed_record_types": {"type": "string", "required": True},
} }
) )
async def api_domain_create(domain_id=None): async def api_domain_create(domain_id=None):
@ -104,6 +105,7 @@ async def api_subdomains():
"ip": {"type": "string", "empty": False, "required": True}, "ip": {"type": "string", "empty": False, "required": True},
"sats": {"type": "integer", "min": 0, "required": True}, "sats": {"type": "integer", "min": 0, "required": True},
"duration": {"type": "integer", "empty": False, "required": True}, "duration": {"type": "integer", "empty": False, "required": True},
"record_type": {"type": "string", "empty": False, "required": True},
} }
) )
async def api_subdomain_make_subdomain(domain_id): async def api_subdomain_make_subdomain(domain_id):