auto user creation for dynamic port

This commit is contained in:
v2ray committed 2016-02-25 14:38:41 +01:00
1 parent b3f547dc90
commit 9f50692d15
9 files changed
+90 -21

No files matched your search

+25
View File
@@ -33,10 +33,28 @@ func (this *FeaturesConfig) UnmarshalJSON(data []byte) error {
return nil
}
func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
type JsonDefaultConfig struct {
AlterIDs uint16 `json:"alterId"`
Level byte `json:"level"`
}
jsonConfig := new(JsonDefaultConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.AlterIDs = jsonConfig.AlterIDs
if this.AlterIDs == 0 {
this.AlterIDs = 32
}
this.Level = proto.UserLevel(jsonConfig.Level)
return nil
}
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Users []*proto.User `json:"clients"`
Features *FeaturesConfig `json:"features"`
Defaults *DefaultConfig `json:"default"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
@@ -44,6 +62,13 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
this.AllowedUsers = jsonConfig.Users
this.Features = jsonConfig.Features
this.Defaults = jsonConfig.Defaults
if this.Defaults == nil {
this.Defaults = &DefaultConfig{
Level: proto.UserLevel(0),
AlterIDs: 32,
}
}
return nil
}