Skip to content

Commit

Permalink
[Controller] add email ntml
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-xiaofeng committed Sep 4, 2023
1 parent 6451102 commit 9da29ed
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 38 deletions.
5 changes: 4 additions & 1 deletion server/controller/db/mysql/migration/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ CREATE TABLE IF NOT EXISTS go_genesis_process (
vtap_id INTEGER NOT NULL DEFAULT 0,
pid INTEGER NOT NULL,
lcuuid CHAR(64) DEFAULT '',
name TEXT,
name TEXT,
process_name TEXT,
cmd_line TEXT,
user VARCHAR(256) DEFAULT '',
Expand Down Expand Up @@ -2424,6 +2424,9 @@ CREATE TABLE IF NOT EXISTS mail_server (
user TEXT NOT NULL,
password TEXT NOT NULL,
security TEXT Not NULL,
ntlm_enabled int,
ntlm_name TEXT,
ntlm_password TEXT,
lcuuid CHAR(64) DEFAULT ''
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE mail_server;
Expand Down
6 changes: 6 additions & 0 deletions server/controller/db/mysql/migration/rawsql/issu/6.3.1.48.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE mail_server ADD COLUMN ntlm_enabled int;
ALTER TABLE mail_server ADD COLUMN ntlm_name TEXT;
ALTER TABLE mail_server ADD COLUMN ntlm_password TEXT;

UPDATE db_version SET version='6.3.1.48';

2 changes: 1 addition & 1 deletion server/controller/db/mysql/migration/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ package migration

const (
DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.3.1.47"
DB_VERSION_EXPECTED = "6.3.1.48"
)
19 changes: 11 additions & 8 deletions server/controller/db/mysql/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,14 +1379,17 @@ func (Plugin) TableName() string {
}

type MailServer struct {
ID int `gorm:"primaryKey;column:id;type:int;not null" json:"ID"`
Status int `gorm:"column:status;type:int;not null" json:"STATUS"`
Host string `gorm:"column:host;type:text;not null" json:"HOST"`
Port int `gorm:"column:port;type:int;not null" json:"PORT"`
User string `gorm:"column:user;type:text;not null" json:"USER"`
Password string `gorm:"column:password;type:text;not null" json:"PASSWORD"`
Security string `gorm:"column:security;type:text;not null" json:"SECURITY"`
Lcuuid string `gorm:"unique;column:lcuuid;type:char(64)" json:"LCUUID"`
ID int `gorm:"primaryKey;column:id;type:int;not null" json:"ID"`
Status int `gorm:"column:status;type:int;not null" json:"STATUS"`
Host string `gorm:"column:host;type:text;not null" json:"HOST"`
Port int `gorm:"column:port;type:int;not null" json:"PORT"`
User string `gorm:"column:user;type:text;not null" json:"USER"`
Password string `gorm:"column:password;type:text;not null" json:"PASSWORD"`
Security string `gorm:"column:security;type:text;not null" json:"SECURITY"`
NtlmEnabled int `gorm:"column:ntlm_enabled;type:int" json:"NTLM_ENABLED"`
NtlmName string `gorm:"column:ntlm_name;type:text" json:"NTLM_NAME"`
NtlmPassword string `gorm:"column:ntlm_password;type:text" json:"NTLM_PASSWORD"`
Lcuuid string `gorm:"unique;column:lcuuid;type:char(64)" json:"LCUUID"`
}

func (MailServer) TableName() string {
Expand Down
24 changes: 15 additions & 9 deletions server/controller/http/service/mail_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ func GetMailServer(filter map[string]interface{}) (resp []model.MailServer, err
}
for _, mail := range mails {
mailResp := model.MailServer{
ID: mail.ID,
Status: mail.Status,
Host: mail.Host,
Port: mail.Port,
User: mail.User,
Password: mail.Password,
Security: mail.Security,
Lcuuid: mail.Lcuuid,
ID: mail.ID,
Status: mail.Status,
Host: mail.Host,
Port: mail.Port,
User: mail.User,
Password: mail.Password,
Security: mail.Security,
NtlmEnabled: mail.NtlmEnabled,
NtlmName: mail.NtlmName,
NtlmPassword: mail.NtlmPassword,
Lcuuid: mail.Lcuuid,
}
response = append(response, mailResp)
}
Expand All @@ -67,6 +70,9 @@ func CreateMailServer(mailCreate model.MailServerCreate) (model.MailServer, erro
mailServer.User = mailCreate.User
mailServer.Password = mailCreate.Password
mailServer.Security = mailCreate.Security
mailServer.NtlmEnabled = mailCreate.NtlmEnabled
mailServer.NtlmName = mailCreate.NtlmName
mailServer.NtlmPassword = mailCreate.NtlmPassword
mailServer.Lcuuid = uuid.New().String()
mysql.Db.Create(&mailServer)

Expand All @@ -88,7 +94,7 @@ func UpdateMailServer(lcuuid string, mailServerUpdate map[string]interface{}) (m

log.Infof("update mailServer(%s) config %v", mailServer.User, mailServerUpdate)

for _, key := range []string{"STATUS", "HOST", "PORT", "USER", "PASSWORD", "SECURITY"} {
for _, key := range []string{"STATUS", "HOST", "PORT", "USER", "PASSWORD", "SECURITY", "NTLM_ENABLED", "NTLM_NAME", "NTLM_PASSWORD"} {
if _, ok := mailServerUpdate[key]; ok {
dbUpdateMap[strings.ToLower(key)] = mailServerUpdate[key]
}
Expand Down
48 changes: 29 additions & 19 deletions server/controller/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,30 +837,40 @@ type Plugin struct {
}

type MailServerCreate struct {
Status int `json:"STATUS"`
Host string `json:"HOST" binding:"required"`
Port int `json:"PORT" binding:"required"`
User string `json:"USER" binding:"required"`
Password string `json:"PASSWORD" binding:"required"`
Security string `json:"SECURITY" binding:"required"`
Status int `json:"STATUS"`
Host string `json:"HOST" binding:"required"`
Port int `json:"PORT" binding:"required"`
User string `json:"USER" binding:"required"`
Password string `json:"PASSWORD" binding:"required"`
NtlmEnabled int `json:"NTLM_ENABLED"`
NtlmName string `json:"NTLM_NAME"`
NtlmPassword string `json:"NTLM_PASSWORD"`
Security string `json:"SECURITY" binding:"required"`
}

type MailServerUpdate struct {
Status int `json:"STATUS"`
Host string `json:"HOST"`
Port int `json:"PORT"`
User string `json:"USER"`
Password string `json:"PASSWORD"`
Status int `json:"STATUS"`
Host string `json:"HOST"`
Port int `json:"PORT"`
User string `json:"USER"`
Password string `json:"PASSWORD"`
NtlmEnabled int `json:"NTLM_ENABLED"`
NtlmName string `json:"NTLM_NAME"`
NtlmPassword string `json:"NTLM_PASSWORD"`

Security string `json:"SECURITY"`
}

type MailServer struct {
ID int `json:"ID"`
Status int `json:"STATUS"`
Host string `json:"HOST"`
Port int `json:"PORT"`
User string `json:"USER"`
Password string `json:"PASSWORD"`
Security string `json:"SECURITY"`
Lcuuid string `json:"LCUUID"`
ID int `json:"ID"`
Status int `json:"STATUS"`
Host string `json:"HOST"`
Port int `json:"PORT"`
User string `json:"USER"`
Password string `json:"PASSWORD"`
Security string `json:"SECURITY"`
NtlmEnabled int `json:"NTLM_ENABLED"`
NtlmName string `json:"NTLM_NAME"`
NtlmPassword string `json:"NTLM_PASSWORD"`
Lcuuid string `json:"LCUUID"`
}

0 comments on commit 9da29ed

Please sign in to comment.