Initial commit — migrated from GitHub (account suspended)
This commit is contained in:
commit
09d0ee68c8
65 files changed
+23255
No files matched your search
@@ -0,0 +1,497 @@
|
||||
// Package store menyimpan data panel Hostora di satu file JSON.
|
||||
// Sengaja JSON, bukan SQLite, supaya v0.2 tidak butuh dependensi CGO.
|
||||
// File ditulis atomik (tulis ke file sementara lalu rename).
|
||||
package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// User adalah akun panel (admin atau pengguna biasa).
|
||||
type User struct {
|
||||
Username string `json:"username"`
|
||||
PasswordHash string `json:"password_hash"` // bcrypt ($2a$) v0.2; format lama v0.1 "salt:sha256" dimigrasikan saat login
|
||||
Role string `json:"role"` // "admin" atau "user"
|
||||
Email string `json:"email,omitempty"` // diisi saat registrasi publik (v0.5); kosong untuk akun lama
|
||||
Status string `json:"status,omitempty"` // "active" | "pending"; kosong = active (akun lama sebelum v0.5)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
TwoFAEnabled bool `json:"twofa_enabled"`
|
||||
TOTPSecret string `json:"totp_secret,omitempty"` // secret TOTP base32; kosong bila 2FA tidak aktif
|
||||
}
|
||||
|
||||
// IsActive melaporkan apakah akun boleh login. Status kosong (data
|
||||
// lama sebelum v0.5) dianggap aktif.
|
||||
func (u User) IsActive() bool {
|
||||
return u.Status == "" || u.Status == "active"
|
||||
}
|
||||
|
||||
// Site adalah satu website yang dikelola panel.
|
||||
type Site struct {
|
||||
ID string `json:"id"`
|
||||
Domain string `json:"domain"`
|
||||
PHP string `json:"php"` // mis. "8.3", "8.2", "8.1", "none"
|
||||
Root string `json:"root"` // document root, mis. /var/www/example.com
|
||||
Owner string `json:"owner"` // username pemilik
|
||||
Status string `json:"status"` // "active" | "planned"
|
||||
VhostPath string `json:"vhost_path"` // lokasi file vhost nginx, kosong bila belum dibuat
|
||||
WAFMode string `json:"waf_mode,omitempty"` // "off" | "detect" | "block" (default "off")
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// Database adalah satu database (MariaDB bila tersedia, bila tidak tercatat sebagai planned).
|
||||
type Database struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
User string `json:"user"`
|
||||
Owner string `json:"owner,omitempty"` // username pemilik (v0.5); kosong = milik admin (database lama)
|
||||
Status string `json:"status"` // "active" | "planned"
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// Settings adalah pengaturan panel.
|
||||
type Settings struct {
|
||||
PanelHostname string `json:"panel_hostname"`
|
||||
PanelPort int `json:"panel_port"`
|
||||
Language string `json:"language"` // "id" (default)
|
||||
// IP publik server (v0.6): dipakai sebagai nilai record A otomatis
|
||||
// (@, www, mail) saat user menghubungkan domainnya, dan ditampilkan
|
||||
// di kartu nameserver tab DNS. Kosong = belum diatur admin.
|
||||
ServerIP string `json:"server_ip,omitempty"`
|
||||
// Let's Encrypt (v0.2): aktif hanya bila hostname panel adalah FQDN
|
||||
// asli dan serve dijalankan dengan --letsencrypt.
|
||||
LetsEncrypt bool `json:"letsencrypt"`
|
||||
// Pendaftaran akun publik (v0.5). Pointer supaya "belum pernah
|
||||
// diatur" (nil, instalasi lama) berbeda dari "sengaja dimatikan":
|
||||
// nil berarti default — pendaftaran diizinkan, tanpa persetujuan.
|
||||
RegistrationEnabled *bool `json:"registration_enabled,omitempty"`
|
||||
RegistrationRequiresApproval *bool `json:"registration_requires_approval,omitempty"`
|
||||
// SMTP keluar (v0.2): disimpan di panel; pengiriman surat nyata
|
||||
// memakai MTA lokal bila ada, atau relay ini.
|
||||
SMTPHost string `json:"smtp_host,omitempty"`
|
||||
SMTPPort int `json:"smtp_port,omitempty"`
|
||||
SMTPUser string `json:"smtp_user,omitempty"`
|
||||
SMTPPassword string `json:"smtp_password,omitempty"`
|
||||
SMTPFrom string `json:"smtp_from,omitempty"`
|
||||
}
|
||||
|
||||
// RegistrationEnabledValue mengembalikan apakah pendaftaran akun publik
|
||||
// diizinkan. Nil (belum pernah diatur) = true, sesuai permintaan
|
||||
// pemilik panel: user boleh mendaftar.
|
||||
func (s Settings) RegistrationEnabledValue() bool {
|
||||
if s.RegistrationEnabled == nil {
|
||||
return true
|
||||
}
|
||||
return *s.RegistrationEnabled
|
||||
}
|
||||
|
||||
// RegistrationRequiresApprovalValue mengembalikan apakah akun baru
|
||||
// butuh persetujuan admin sebelum bisa login. Nil = false.
|
||||
func (s Settings) RegistrationRequiresApprovalValue() bool {
|
||||
if s.RegistrationRequiresApproval == nil {
|
||||
return false
|
||||
}
|
||||
return *s.RegistrationRequiresApproval
|
||||
}
|
||||
|
||||
// ResolveRegistration mengisi kedua pointer pendaftaran dengan nilai
|
||||
// efektifnya, supaya respons /api/settings selalu berisi boolean
|
||||
// (bukan null) untuk UI.
|
||||
func (s *Settings) ResolveRegistration() {
|
||||
enabled := s.RegistrationEnabledValue()
|
||||
approval := s.RegistrationRequiresApprovalValue()
|
||||
s.RegistrationEnabled = &enabled
|
||||
s.RegistrationRequiresApproval = &approval
|
||||
}
|
||||
|
||||
// EffectiveServerIP mengembalikan IP server yang dipakai untuk record
|
||||
// A otomatis (v0.6): ServerIP yang diisi admin menang; bila kosong,
|
||||
// dipakai IP glue IPv4 nameserver default pertama, lalu nameserver
|
||||
// lain yang punya IPv4; bila tetap tidak ada, "" (pemanggil harus
|
||||
// menampilkan peringatan, bukan menebak-nebak IP).
|
||||
func (s Settings) EffectiveServerIP(global []Nameserver) string {
|
||||
if ip := strings.TrimSpace(s.ServerIP); ip != "" {
|
||||
return ip
|
||||
}
|
||||
for _, ns := range global {
|
||||
if ns.IsDefault && strings.TrimSpace(ns.IPv4) != "" {
|
||||
return strings.TrimSpace(ns.IPv4)
|
||||
}
|
||||
}
|
||||
for _, ns := range global {
|
||||
if strings.TrimSpace(ns.IPv4) != "" {
|
||||
return strings.TrimSpace(ns.IPv4)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// SetupToken adalah token sekali pakai untuk wizard /setup, berlaku 24 jam.
|
||||
type SetupToken struct {
|
||||
Token string `json:"token"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
Used bool `json:"used"`
|
||||
}
|
||||
|
||||
// ActivityEntry adalah satu baris log audit append-only.
|
||||
type ActivityEntry struct {
|
||||
ID string `json:"id"`
|
||||
Time time.Time `json:"time"`
|
||||
Actor string `json:"actor"` // username, atau "sistem" untuk cron
|
||||
Action string `json:"action"` // mis. "login", "site.create", "cron.run"
|
||||
Target string `json:"target"` // mis. "contoh.com", "admin"
|
||||
IP string `json:"ip,omitempty"`
|
||||
Result string `json:"result"` // "ok" | "gagal"
|
||||
Detail string `json:"detail,omitempty"`
|
||||
}
|
||||
|
||||
// CronJob adalah tugas terjadwal di dalam panel (bukan crontab sistem).
|
||||
type CronJob struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Schedule string `json:"schedule"` // 5 field cron: menit jam tgl bulan hari-minggu
|
||||
Command string `json:"command"` // dijalankan via /bin/sh -c, timeout 60 detik
|
||||
Site string `json:"site,omitempty"`
|
||||
Owner string `json:"owner"`
|
||||
Enabled bool `json:"enabled"`
|
||||
LastRun time.Time `json:"last_run,omitempty"`
|
||||
LastStatus string `json:"last_status,omitempty"` // "ok" | "gagal" | ""
|
||||
LastOutput string `json:"last_output,omitempty"` // dipotong maks 2 KB
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// DNSRecord adalah satu record DNS dalam sebuah zona.
|
||||
type DNSRecord struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"` // A, AAAA, CNAME, MX, TXT, NS, SRV
|
||||
Name string `json:"name"` // "@" = apex, atau nama host
|
||||
Value string `json:"value"`
|
||||
TTL int `json:"ttl"` // detik, default 3600
|
||||
Priority int `json:"priority,omitempty"` // MX / SRV
|
||||
}
|
||||
|
||||
// DNSZone adalah zona DNS untuk satu domain (dikelola panel; PowerDNS
|
||||
// v0.3: bila PowerDNS terpasang, zona juga ditulis ke backend pdns).
|
||||
type DNSZone struct {
|
||||
Domain string `json:"domain"`
|
||||
Records []DNSRecord `json:"records"`
|
||||
Backend string `json:"backend,omitempty"` // "panel" (hanya di store) | "powerdns" (tersinkron ke pdns)
|
||||
Nameservers []string `json:"nameservers,omitempty"` // override nameserver per zona (hostname); kosong = pakai default global
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// Mailbox adalah kotak surat yang dikelola panel.
|
||||
type Mailbox struct {
|
||||
ID string `json:"id"`
|
||||
Address string `json:"address"` // mis. halo@contoh.com
|
||||
PasswordHash string `json:"password_hash"`
|
||||
QuotaMB int `json:"quota_mb"`
|
||||
Status string `json:"status"` // "active" (panel) — lihat MTAStatus
|
||||
MTAStatus string `json:"mta_status"` // "planned" bila Postfix/Dovecot tidak ada; "terdeteksi" bila MTA ada tapi virtual map belum ditulis
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// Forwarder meneruskan surat dari satu alamat ke alamat lain.
|
||||
type Forwarder struct {
|
||||
ID string `json:"id"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// Autoresponder membalas otomatis surat yang masuk ke sebuah mailbox.
|
||||
type Autoresponder struct {
|
||||
ID string `json:"id"`
|
||||
Mailbox string `json:"mailbox"`
|
||||
Message string `json:"message"`
|
||||
Start time.Time `json:"start,omitempty"`
|
||||
End time.Time `json:"end,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Backend string `json:"backend,omitempty"` // "panel" | "sieve" (Dovecot Sieve aktif) | "planned-sieve" (tersimpan di panel, butuh sieve)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// InstalledApp adalah satu aplikasi web yang dipasang lewat Installer
|
||||
// Aplikasi (v0.3): WordPress, Joomla, Nextcloud, Laravel, Moodle,
|
||||
// CodeIgniter.
|
||||
// ScanFinding adalah satu temuan pemindaian keamanan (v0.4).
|
||||
type ScanFinding struct {
|
||||
ID string `json:"id"`
|
||||
Level string `json:"level"` // "kritis" | "tinggi" | "sedang" | "rendah"
|
||||
OWASP string `json:"owasp,omitempty"` // mis. "A01", "A03"
|
||||
Path string `json:"path"`
|
||||
Title string `json:"title"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
Kind string `json:"kind,omitempty"` // "sensitive-file" | "malware-pattern" | "vuln-package"
|
||||
}
|
||||
|
||||
// ScanResult adalah hasil satu kali pemindaian keamanan (v0.4).
|
||||
type ScanResult struct {
|
||||
ID string `json:"id"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
FinishedAt time.Time `json:"finished_at,omitempty"`
|
||||
FilesScanned int `json:"files_scanned"`
|
||||
BytesScanned int64 `json:"bytes_scanned"`
|
||||
Skipped int `json:"skipped"`
|
||||
Findings []ScanFinding `json:"findings"`
|
||||
}
|
||||
|
||||
// WAFLogEntry adalah satu request yang ditandai WAF (v0.4, maks 100 terbaru).
|
||||
type WAFLogEntry struct {
|
||||
Time time.Time `json:"time"`
|
||||
Site string `json:"site"`
|
||||
IP string `json:"ip"`
|
||||
Score int `json:"score"`
|
||||
RuleID string `json:"rule_id"`
|
||||
Matched string `json:"matched"`
|
||||
Action string `json:"action"` // "diblokir" | "dicatat"
|
||||
}
|
||||
|
||||
// TransferLog adalah satu catatan transfer akun dari server lain (v0.4).
|
||||
type TransferLog struct {
|
||||
ID string `json:"id"`
|
||||
Source string `json:"source"` // "whm" | "garudapanel" | "hostora"
|
||||
SourceHost string `json:"source_host"`
|
||||
Account string `json:"account"`
|
||||
Status string `json:"status"` // "selesai" | "gagal" | "planned" | "berjalan"
|
||||
Detail string `json:"detail,omitempty"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
FinishedAt time.Time `json:"finished_at,omitempty"`
|
||||
}
|
||||
|
||||
// TrashEntry adalah satu file/folder di tempat sampah file manager (v0.4).
|
||||
type TrashEntry struct {
|
||||
ID string `json:"id"`
|
||||
OriginalPath string `json:"original_path"`
|
||||
TrashPath string `json:"trash_path"`
|
||||
Name string `json:"name"`
|
||||
IsDir bool `json:"is_dir"`
|
||||
Size int64 `json:"size"`
|
||||
Owner string `json:"owner,omitempty"` // username yang menghapus (v0.5); kosong = entri lama, hanya admin
|
||||
DeletedAt time.Time `json:"deleted_at"`
|
||||
}
|
||||
|
||||
type InstalledApp struct {
|
||||
ID string `json:"id"`
|
||||
App string `json:"app"` // slug: "wordpress" | "joomla" | ...
|
||||
Name string `json:"name"` // nama tampil
|
||||
Version string `json:"version"` // versi terpasang
|
||||
SiteID string `json:"site_id"`
|
||||
Domain string `json:"domain"`
|
||||
Database string `json:"database,omitempty"`
|
||||
DBUser string `json:"db_user,omitempty"`
|
||||
DBStatus string `json:"db_status,omitempty"` // "active" | "planned"
|
||||
AdminUser string `json:"admin_user,omitempty"`
|
||||
AdminURL string `json:"admin_url,omitempty"`
|
||||
SiteURL string `json:"site_url,omitempty"`
|
||||
Path string `json:"path"` // document root situs
|
||||
InstalledAt time.Time `json:"installed_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// Backup adalah satu arsip tar.gz dari document root sebuah situs.
|
||||
type Backup struct {
|
||||
ID string `json:"id"`
|
||||
SiteID string `json:"site_id"`
|
||||
Domain string `json:"domain"`
|
||||
File string `json:"file"` // nama file di <dataDir>/backups
|
||||
Size int64 `json:"size"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Status string `json:"status"` // "ok" | "gagal"
|
||||
}
|
||||
|
||||
// Data adalah seluruh isi file JSON.
|
||||
type Data struct {
|
||||
Users []User `json:"users"`
|
||||
Sites []Site `json:"sites"`
|
||||
Databases []Database `json:"databases"`
|
||||
Settings Settings `json:"settings"`
|
||||
Setup SetupToken `json:"setup"`
|
||||
Activity []ActivityEntry `json:"activity"`
|
||||
CronJobs []CronJob `json:"cron_jobs"`
|
||||
DNSZones []DNSZone `json:"dns_zones"`
|
||||
Mailboxes []Mailbox `json:"mailboxes"`
|
||||
Forwarders []Forwarder `json:"forwarders"`
|
||||
Autoresponders []Autoresponder `json:"autoresponders"`
|
||||
Backups []Backup `json:"backups"`
|
||||
InstalledApps []InstalledApp `json:"installed_apps"`
|
||||
Nameservers []Nameserver `json:"nameservers"`
|
||||
LastScan *ScanResult `json:"last_scan,omitempty"`
|
||||
WAFLog []WAFLogEntry `json:"waf_log,omitempty"`
|
||||
Transfers []TransferLog `json:"transfers,omitempty"`
|
||||
Trash []TrashEntry `json:"trash,omitempty"`
|
||||
}
|
||||
|
||||
// Store membungkus Data dengan mutex dan path file.
|
||||
type Store struct {
|
||||
mu sync.Mutex
|
||||
path string
|
||||
data Data
|
||||
}
|
||||
|
||||
// New membuka (atau membuat) store di path file JSON.
|
||||
func New(path string) (*Store, error) {
|
||||
s := &Store{path: path}
|
||||
s.data.Settings = Settings{PanelHostname: "hostora.xyz", PanelPort: 8443, Language: "id"}
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return s, s.saveLocked()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if len(raw) == 0 {
|
||||
return s, s.saveLocked()
|
||||
}
|
||||
if err := json.Unmarshal(raw, &s.data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.data.Settings.PanelPort == 0 {
|
||||
s.data.Settings.PanelPort = 8443
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Path mengembalikan lokasi file store.
|
||||
func (s *Store) Path() string { return s.path }
|
||||
|
||||
func (s *Store) saveLocked() error {
|
||||
if err := os.MkdirAll(filepath.Dir(s.path), 0o750); err != nil {
|
||||
return err
|
||||
}
|
||||
raw, err := json.MarshalIndent(s.data, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmp := s.path + ".tmp"
|
||||
if err := os.WriteFile(tmp, raw, 0o600); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(tmp, s.path)
|
||||
}
|
||||
|
||||
// Save menulis state saat ini ke disk.
|
||||
func (s *Store) Save() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.saveLocked()
|
||||
}
|
||||
|
||||
// View menjalankan fn dengan akses baca ke Data (tanpa menyimpan).
|
||||
func (s *Store) View(fn func(d *Data)) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
fn(&s.data)
|
||||
}
|
||||
|
||||
// Update menjalankan fn lalu menyimpan hasilnya ke disk.
|
||||
func (s *Store) Update(fn func(d *Data) error) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if err := fn(&s.data); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.saveLocked()
|
||||
}
|
||||
|
||||
// FindUser mencari pengguna berdasarkan username, mengembalikan salinan.
|
||||
func (s *Store) FindUser(username string) (User, bool) {
|
||||
var out User
|
||||
var ok bool
|
||||
s.View(func(d *Data) {
|
||||
for _, u := range d.Users {
|
||||
if u.Username == username {
|
||||
out, ok = u, true
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
return out, ok
|
||||
}
|
||||
|
||||
// LogActivity menambahkan satu entri audit (append-only, maks 1000 entri
|
||||
// terakhir — entri terlama dibuang). Dipanggil lewat Update agar atomik
|
||||
// dengan perubahan yang dicatatnya; pemanggil boleh memanggilnya di
|
||||
// Update terpisah bila tidak ada perubahan data lain.
|
||||
func (s *Store) LogActivity(actor, action, target, ip, result, detail string) {
|
||||
_ = s.Update(func(d *Data) error {
|
||||
d.Activity = append(d.Activity, ActivityEntry{
|
||||
ID: time.Now().Format("20060102150405.000000000"),
|
||||
Time: time.Now(),
|
||||
Actor: actor,
|
||||
Action: action,
|
||||
Target: target,
|
||||
IP: ip,
|
||||
Result: result,
|
||||
Detail: detail,
|
||||
})
|
||||
if len(d.Activity) > 1000 {
|
||||
d.Activity = d.Activity[len(d.Activity)-1000:]
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// ---------- Custom Nameserver (v0.3.0) ----------
|
||||
//
|
||||
// Nameserver global (custom nameserver panel, mis. ns1.hostora.xyz) yang
|
||||
// dipakai sebagai NS record semua zona bila zona tidak punya override
|
||||
// sendiri (DNSZone.Nameservers). Fallback ns1/ns2.hostora.xyz hanya
|
||||
// dipakai saat tampil/menghitung — TIDAK pernah ditulis otomatis ke
|
||||
// store (lihat DefaultNameservers).
|
||||
|
||||
// Nameserver adalah satu nameserver kustom beserta IP glue-nya.
|
||||
type Nameserver struct {
|
||||
Hostname string `json:"hostname"` // FQDN, mis. ns1.hostora.xyz
|
||||
IPv4 string `json:"ipv4,omitempty"`
|
||||
IPv6 string `json:"ipv6,omitempty"`
|
||||
IsDefault bool `json:"is_default"` // dipakai sebagai NS default zona
|
||||
}
|
||||
|
||||
// FallbackNameservers adalah nameserver default tampilan bila belum ada
|
||||
// nameserver yang dikonfigurasi. Sengaja tanpa IP glue: IP glue hanya
|
||||
// ada bila admin mengisinya di panel.
|
||||
func FallbackNameservers() []Nameserver {
|
||||
return []Nameserver{
|
||||
{Hostname: "ns1.hostora.xyz", IsDefault: true},
|
||||
{Hostname: "ns2.hostora.xyz", IsDefault: true},
|
||||
}
|
||||
}
|
||||
|
||||
// FallbackHostnames mengembalikan hostname fallback (ns1/ns2.hostora.xyz).
|
||||
func FallbackHostnames() []string {
|
||||
out := make([]string, 0, 2)
|
||||
for _, ns := range FallbackNameservers() {
|
||||
out = append(out, ns.Hostname)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// DefaultNameservers mengembalikan nameserver global yang ditandai
|
||||
// IsDefault. Bila tidak ada nameserver yang dikonfigurasi (atau tidak
|
||||
// ada yang ditandai default), mengembalikan fallback ns1/ns2.hostora.xyz.
|
||||
// Hasilnya adalah salinan — pemanggil tidak boleh mengubah store lewat
|
||||
// nilai kembalian ini — dan fallback TIDAK ditulis ke store.
|
||||
func DefaultNameservers(d *Data) []Nameserver {
|
||||
if d != nil {
|
||||
var defaults []Nameserver
|
||||
for _, ns := range d.Nameservers {
|
||||
if ns.IsDefault {
|
||||
defaults = append(defaults, ns)
|
||||
}
|
||||
}
|
||||
if len(defaults) > 0 {
|
||||
return defaults
|
||||
}
|
||||
}
|
||||
return FallbackNameservers()
|
||||
}
|
||||
Reference in new issue
Block a user