This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root_cmd.go
201 lines (173 loc) · 4.28 KB
/
root_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package render
import (
"fmt"
"strings"
"github.com/apcera/termtables"
"github.com/jezman/yapdd/models"
"github.com/jezman/yapdd/utils"
)
var (
account = &models.Account{}
dns = &models.DNSRecords{}
domain = &models.Domain{}
domains = &models.Domains{}
)
// Domains render domains list table.
func Domains(verbose bool) {
domains, err := domains.List()
if err = utils.ErrorCheck(domains.Success, domains.Error, err); err != nil {
fmt.Println(err)
} else {
table := termtables.CreateTable()
table.AddTitle("List of user domains.")
// verbose output
if verbose {
table.AddHeaders(
"#",
"Domains",
"Aliases",
"Status",
"NS Delegated",
"No DKIM",
"Accounts",
"Max accounts",
)
for i, d := range domains.Domains {
table.AddRow(
i+1,
d.Name,
d.Aliases,
d.Status,
d.NSDelegated,
d.NoDKIM,
d.EmailsCount,
d.EmailsMaxCount,
)
}
// quiet output
} else {
table.AddHeaders("#", "Domains", "Accounts")
for i, d := range domains.Domains {
table.AddRow(i+1, d.Name, d.EmailsCount)
}
}
fmt.Println(table.Render())
}
}
// Accounts render accounts list in domain.
func Accounts(domainName string, verbose bool) {
domain, err := domain.List(domainName)
if err = utils.ErrorCheck(domain.Success, domain.Error, err); err != nil {
fmt.Println(err)
} else {
table := termtables.CreateTable()
table.AddTitle("A list of accounts in the domain.")
// vebose output
if verbose {
table.AddHeaders("#", "Account", "Active/Ready", "Username/Birthday", "Question hint")
for i, a := range domain.Accounts {
table.AddRow(
i+1,
a.Login,
a.Enabled+"/"+a.Ready,
a.User+" "+a.Birthday,
a.Question,
)
}
// quiet output
} else {
table.AddHeaders("#", "Account")
for i, a := range domain.Accounts {
table.AddRow(
i+1,
a.Login,
)
}
}
fmt.Println(table.Render())
}
}
// CountOfUnreadMail in account.
func CountOfUnreadMail(accountName string) {
account, err := account.UnreadMail(accountName)
if err = utils.ErrorCheck(account.Success, account.Error, err); err != nil {
fmt.Println(err)
} else {
fmt.Println("Count of unread emails:", account.Counters.New)
fmt.Println("Count of letters received since the last mailbox test:",
account.Counters.Unread,
)
}
}
// DomainStatus render connection status.
func DomainStatus(domainName string) {
domain, err := domain.ConnectionStatus(domainName)
if err = utils.ErrorCheck(domain.Success, domain.Error, err); err != nil {
fmt.Println(err)
} else {
table := termtables.CreateTable()
table.AddTitle("Domain connection status.")
table.AddHeaders("Domain", "Status", "Check results", "Last check", "Next check")
table.AddRow(
domain.Domain,
domain.Status,
domain.CheckResults,
domain.LastCheck,
domain.NextCheck,
)
fmt.Println(table.Render())
}
}
// DomainConfig render domain settings.
func DomainConfig(domainName string) {
domain, err := domain.Config(domainName)
if err = utils.ErrorCheck(domain.Success, domain.Error, err); err != nil {
fmt.Println(err)
} else {
table := termtables.CreateTable()
table.AddTitle("Domain settings.")
table.AddHeaders(
"Domain",
"Status",
"Delegated",
"Country",
"IMAP",
"POP",
)
table.AddRow(
domain.Domain,
domain.Status,
domain.Delegated,
domain.Country,
domain.ImapEnabled,
domain.PopEnabled,
)
fmt.Println(table.Render())
}
}
// DomainDNSRecords print DNS records in domain.
func DomainDNSRecords(domainName string) {
dns, err := dns.DNSRecords(domainName)
if err = utils.ErrorCheck(dns.Success, dns.Error, err); err != nil {
fmt.Println(err)
} else {
for _, d := range dns.Records {
fmt.Printf("%s\n", strings.Repeat("-", 50))
fmt.Printf("%s\t| ", d.Type)
fmt.Println("Record ID:", d.RecordID)
fmt.Println("\t| Full domain name:", d.FQDN)
fmt.Println("\t| TTL:", d.TTL)
fmt.Println("\t| Subdomain:", d.Subdomain)
fmt.Println("\t| Content:", d.Content)
}
}
}
// Country print results method SetCountry.
func Country(domainName string) {
domain, err := domain.SetCountry(domainName)
if err = utils.ErrorCheck(domain.Success, domain.Error, err); err != nil {
fmt.Println(err)
} else {
fmt.Println("The country is successfully installed.")
}
}