-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
207 lines (190 loc) · 7.25 KB
/
user.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
202
203
204
205
206
207
package directadmin
import (
"fmt"
"net/http"
"net/url"
"strings"
)
type (
User struct {
Config UserConfig `json:"config"`
Usage UserUsage `json:"usage"`
}
UserContext struct {
api *API
credentials credentials
sessionID string
User User
}
UserConfig struct {
AccountEnabled bool `json:"account"`
AFTPEnabled bool `json:"aftp"`
APIAllowPassword bool `json:"apiAllowPassword"`
AutorespondersLimit int `json:"autorespondersLim"`
BandwidthLimit int `json:"bandwidthLim"`
CatchAllEnabled bool `json:"catchAll"`
CGIEnabled bool `json:"cgi"`
ClamAVEnabled bool `json:"clamav"`
CPUQuota string `json:"cpuQuota"`
Creator string `json:"creator"`
CronEnabled bool `json:"cron"`
DateCreated string `json:"dateCreated"`
DNSControlEnabled bool `json:"dnsControl"`
DocsRoot string `json:"docsRoot"`
Domain string `json:"domain"`
DomainPointersLimit int `json:"domainPointersLim"`
Domains []string `json:"domains"`
DomainsLimit int `json:"domainsLim"`
Email string `json:"email"`
EmailAccountsLimit int `json:"emailAccountsLim"`
EmailForwardersLimit int `json:"emailForwardersLim"`
FeatureSets []string `json:"featureSets"`
FTPAccountsLimit int `json:"ftpAccountsLim"`
GitEnabled bool `json:"git"`
InodeLimit int `json:"inodeLim"`
IOReadBandwidthMax string `json:"ioReadBandwidthMax"`
IOReadIOPSMax string `json:"ioReadIOPSMax"`
IOWriteBandwidthMax string `json:"ioWriteBandwidthMax"`
IOWriteIOPSMax string `json:"ioWriteIOPSMax"`
IP string `json:"ip"`
JailEnabled bool `json:"jail"`
Language string `json:"language"`
LetsEncrypt int `json:"letsEncrypt"`
LoginKeysEnabled bool `json:"loginKeys"`
MailPartition string `json:"mailPartition"`
MailingListsLimit int `json:"mailingListsLim"`
MemoryHigh string `json:"memoryHigh"`
MemoryMax string `json:"memoryMax"`
MySQLConf string `json:"mySqlConf"`
MySQLDatabasesLimit int `json:"mySqlDatabasesLim"`
Name string `json:"name"`
NginxEnabled bool `json:"nginxUnit"`
NS1 string `json:"ns1"`
NS2 string `json:"ns2"`
Package string `json:"package"`
PHPEnabled bool `json:"php"`
PluginsBlacklist []string `json:"pluginsBlacklist"`
PluginsWhitelist []string `json:"pluginsWhitelist"`
QuotaLimit int `json:"quotaLim"`
RedisEnabled bool `json:"redis"`
SecurityQuestionsEnabled bool `json:"securityQuestions"`
Skin string `json:"skin"`
SpamEnabled bool `json:"spam"`
SSHEnabled bool `json:"ssh"`
SSLEnabled bool `json:"ssl"`
SubdomainsLimit int `json:"subdomainsLim"`
Suspended bool `json:"suspended"`
SysInfoEnabled bool `json:"sysInfo"`
TasksMax string `json:"tasksMax"`
TwoStepAuthEnabled bool `json:"twoStepAuth"`
TwoStepAuthDescription string `json:"twoStepAuthDesc"`
UserType string `json:"userType"`
Username string `json:"username"`
Users []string `json:"users"`
UsersLimit int `json:"usersLim"`
UsersManageDomains int `json:"usersManageDomains"`
WordpressEnabled bool `json:"wordpress"`
Zoom int `json:"zoom"`
}
UserUsage struct {
AutoResponders struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"autoresponders"`
BandwidthBytes struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"bandwidthBytes"`
DBQuotaBytes int `json:"dbQuotaBytes"`
DomainPointers struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"domainPointers"`
Domains struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"domains"`
EmailAccounts struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"emailAccounts"`
EmailDeliveries int `json:"emailDeliveries"`
EmailDeliveriesIncoming int `json:"emailDeliveriesIncoming"`
EmailDeliveriesOutgoing int `json:"emailDeliveriesOutgoing"`
EmailForwarders struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"emailForwarders"`
EmailQuotaBytes int `json:"emailQuotaBytes"`
FTPAccounts struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"ftpAccounts"`
Inode struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"inode"`
MailingLists struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"mailingLists"`
MySQLDatabases struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"mySqlDatabases"`
OtherQuotaBytes int `json:"otherQuotaBytes"`
QuotaBytes struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"quotaBytes"`
QuotaWithoutSystemBytes int `json:"quotaWithoutSystemBytes"`
Subdomains struct {
Limit int `json:"limit"`
Unlimited bool `json:"unlimited"`
Usage int `json:"usage"`
} `json:"subdomains"`
}
)
// GetMyUserConfig (user) returns the session user's config
func (c *UserContext) GetMyUserConfig() (*UserConfig, error) {
var config UserConfig
if _, err := c.makeRequestNew(http.MethodGet, "session/user-config", nil, &config); err != nil {
return nil, err
}
return &config, nil
}
// GetMyUserUsage (user) returns the session user's usage
func (c *UserContext) GetMyUserUsage() (*UserUsage, error) {
var usage UserUsage
if _, err := c.makeRequestNew(http.MethodGet, "session/user-usage", nil, &usage); err != nil {
return nil, err
}
return &usage, nil
}
func (c *UserContext) addUsernamePrefix(check string) string {
if !strings.HasPrefix(check, c.GetMyUsername()+"_") {
check = c.GetMyUsername() + "_" + check
}
return check
}
func (c *UserContext) checkObjectExists(body url.Values) error {
var response apiGenericResponse
if _, err := c.makeRequestOld(http.MethodGet, "JSON_VALIDATE?"+body.Encode(), nil, &response); err != nil {
return err
}
if response.Error != "" {
return fmt.Errorf("object already exists: %v", response.Error)
}
return nil
}