diff --git a/web/src/stores/domains.ts b/web/src/stores/domains.ts new file mode 100644 index 0000000..277cef9 --- /dev/null +++ b/web/src/stores/domains.ts @@ -0,0 +1,78 @@ +import { defineStore } from 'pinia' +import { ref, computed } from 'vue' + +export type Domain = { + id: number; + domain_name: string; + main_dns: string; + admin_email: string; + serial_number: number; + refresh_interval: number; + retry_interval: number; + expiry_period: number; + negative_ttl: number; +} + +const domainDevData: Domain[] = [ + { + id: 1, + domain_name: "example.com", + main_dns: "ns1.example.com", + admin_email: "admin@example.com", + serial_number: 114514, + refresh_interval: 86400, + retry_interval: 7200, + expiry_period: 3600000, + negative_ttl: 86400 + }, + { + id: 2, + domain_name: "example.org", + main_dns: "ns1.example.org", + admin_email: "admin@example.org", + serial_number: 1919810, + refresh_interval: 86400, + retry_interval: 7200, + expiry_period: 3600000, + negative_ttl: 86400 + } +] + +export const useDomainStore = defineStore('domains', () => { + const domains = ref([]) + const domainsGetter = computed(() => domains.value) + + function loadDomains() { + // TODO: load from api + domains.value = import.meta.env.DEV ? domainDevData : [] + } + + function addDomain(domain: Domain) { + // TODO: load from api + if (!import.meta.env.DEV) { + //domain = + } + + domains.value.push(domain) + } + + function updateDomain(domain: Domain) { + // TODO: load from api + if (!import.meta.env.DEV) { + //domain = + } + + domains.value = domains.value.map(e => e.id === domain.id ? domain : e) + } + + function removeDomain(domain: Domain) { + // TODO: load from api + if (!import.meta.env.DEV) { + //domain = + } + + domains.value = domains.value.filter(e => e.id !== domain.id) + } + return { domains, domainsGetter, loadDomains, addDomain, updateDomain, removeDomain } +}) + diff --git a/web/src/stores/records.ts b/web/src/stores/records.ts new file mode 100644 index 0000000..738ec9d --- /dev/null +++ b/web/src/stores/records.ts @@ -0,0 +1,233 @@ +import { defineStore } from 'pinia' +import { ref, computed } from 'vue' + +export type ARecord = { + ip: string; +} + +export type AAAARecord = { + ip: string; +} + +export type TXTRecord = { + text: string; +} + +export type CNAMERecord = { + host: string; +} + +export type NSRecord = { + host: string; +} + +export type MXRecord = { + host: string; + preference: number; +} + +export type SRVRecord = { + priority: number; + weight: number; + port: number; + target: string; +} + +export type SOARecord = { + ns: string; + MBox: string; + refresh: number; + retry: number; + expire: number; + minttl: number; +} + +export type CAARecord = { + flag: number; + tag: string; + value: string; +} + +export enum RecordTypes { + RecordTypeA = "A", + RecordTypeAAAA = "AAAA", + RecordTypeCNAME = "CNAME", + RecordTypeSOA = "SOA", + RecordTypeTXT = "TXT", + RecordTypeNS = "NS", + RecordTypeMX = "MX", + RecordTypeCAA = "CAA", + RecordTypeSRV = "SRV" +} + +export type RecordT = ARecord | AAAARecord | TXTRecord | CNAMERecord | NSRecord | MXRecord | SRVRecord | SOARecord | CAARecord + +export type Record = { + id: number; + zone: string; + name: string; + ttl: number; + content: RecordT; + record_type: RecordTypes; +} + +const recordDevData = new Map([ + [ + 'example.com', [ + { + id: 1, + zone: "example.com", + name: "@", + ttl: 3600, + record_type: RecordTypes.RecordTypeSOA, + content: { + ns: "ns1.example.com", + MBox: "admin@example.com", + refresh: 86400, + retry: 7200, + expire: 3600000, + minttl: 86400, + } + }, + { + id: 2, + zone: "example.com", + name: "@", + ttl: 3600, + record_type: RecordTypes.RecordTypeNS, + content: { + host: "ns1.example.com" + } + }, + { + id: 3, + zone: "example.com", + name: "@", + ttl: 3600, + record_type: RecordTypes.RecordTypeNS, + content: { + host: "ns2.example.com" + } + }, + { + id: 4, + zone: "example.com", + name: "www", + ttl: 3600, + record_type: RecordTypes.RecordTypeA, + content: { + ip: "233.233.233.233" + } + }, + { + id: 5, + zone: "example.com", + name: "cname", + ttl: 3600, + record_type: RecordTypes.RecordTypeCNAME, + content: { + host: "www.example.com" + } + } + ] + ], + [ + 'example.org', [ + { + id: 1, + zone: "example.org", + name: "@", + ttl: 3600, + record_type: RecordTypes.RecordTypeSOA, + content: { + ns: "ns1.example.org", + MBox: "admin@example.org", + refresh: 86400, + retry: 7200, + expire: 3600000, + minttl: 86400, + } + }, + { + id: 2, + zone: "example.org", + name: "@", + ttl: 3600, + record_type: RecordTypes.RecordTypeNS, + content: { + host: "ns1.example.org" + } + }, + { + id: 3, + zone: "example.org", + name: "@", + ttl: 3600, + record_type: RecordTypes.RecordTypeNS, + content: { + host: "ns2.example.org" + } + }, + { + id: 4, + zone: "example.org", + name: "www", + ttl: 3600, + record_type: RecordTypes.RecordTypeA, + content: { + ip: "233.233.233.233" + } + }, + { + id: 5, + zone: "example.org", + name: "cname", + ttl: 3600, + record_type: RecordTypes.RecordTypeCNAME, + content: { + host: "www.example.org" + } + } + ] + ] +]) + + +export const useRecordStore = defineStore('records', () => { + const records = ref([]) + const recordsGetter = computed(() => records.value) + + function loadRecords(domain: string) { + // TODO: load from api + records.value = import.meta.env.DEV ? recordDevData.get(domain) : [] + } + + function addRecord(domain: string, record: Record) { + // TODO: load from api + if (!import.meta.env.DEV) { + //record = + } + + records.value?.push(record) + } + + function updateRecord(domain: string, record: Record) { + // TODO: load from api + if (!import.meta.env.DEV) { + //record = + } + + records.value = records.value?.map(e => e.id === record.id ? record : e) + } + + function removeRecord(domain: string, record: Record) { + // TODO: load from api + if (!import.meta.env.DEV) { + //record = + } + + records.value = records.value?.filter(e => e.id !== record.id) + } + + return { records, recordsGetter, loadRecords } +})