-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmailServerHandler.go
131 lines (119 loc) · 3.05 KB
/
mailServerHandler.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
package main
import (
services "UlboraCmsV3/services"
"fmt"
"net/http"
"strconv"
)
func handleMailServer(w http.ResponseWriter, r *http.Request) {
s.InitSessionStore(w, r)
session, err := s.GetSession(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
loggedIn := session.Values["userLoggenIn"]
if loggedIn == nil || loggedIn.(bool) == false || token == nil {
authorize(w, r)
} else {
var m services.MailServerService
m.ClientID = getAuthCodeClient()
//m.UserID = getHashedUser()
//m.Hashed = "true"
m.Token = token.AccessToken
m.Host = getMailHost()
m.APIKey = getGatewayAPIKey()
res := m.GetMailServer()
if res.Server.ID == 0 {
res.Server.Port = 465
}
//fmt.Print("mail res: ")
//fmt.Println(res)
//fmt.Print("mail server: ")
//fmt.Println(m)
templatesAdmin.ExecuteTemplate(w, "mailServer.html", &res.Server)
}
}
func handleMailServerUpdate(w http.ResponseWriter, r *http.Request) {
s.InitSessionStore(w, r)
session, err := s.GetSession(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
loggedIn := session.Values["userLoggenIn"]
if loggedIn == nil || loggedIn.(bool) == false || token == nil {
authorize(w, r)
} else {
idStr := r.FormValue("id")
id, errID := strconv.ParseInt(idStr, 10, 0)
if errID != nil {
fmt.Print(errID)
}
//fmt.Print("id: ")
//fmt.Println(id)
mailServer := r.FormValue("mailServer")
//fmt.Print("mailServer: ")
//fmt.Println(mailServer)
secureConnection := r.FormValue("secureConnection")
//fmt.Print("secureConnection: ")
//fmt.Println(secureConnection)
port := r.FormValue("port")
if port == "" {
port = "0"
}
//fmt.Print("port: ")
//fmt.Println(port)
debug := r.FormValue("debug")
//fmt.Print("debug: ")
//fmt.Println(debug)
username := r.FormValue("username")
//fmt.Print("username: ")
//fmt.Println(username)
password := r.FormValue("password")
//fmt.Print("password: ")
//fmt.Println(password)
fromAddress := r.FormValue("fromAddress")
//fmt.Print("fromAddress: ")
//fmt.Println(fromAddress)
var ms services.MailServer
ms.ID = id
ms.MailServer = mailServer
//ms.MailServer = mailServer
if secureConnection == "on" {
ms.SecureConnection = true
} else {
ms.SecureConnection = false
}
ms.Port, err = strconv.Atoi(port)
if err != nil {
fmt.Println(err)
}
if debug == "on" {
ms.Debug = true
} else {
ms.Debug = false
}
ms.Username = username
ms.Password = password
ms.FromAddress = fromAddress
var m services.MailServerService
m.ClientID = getAuthCodeClient()
//m.UserID = getHashedUser()
//m.Hashed = "true"
m.Token = token.AccessToken
m.Host = getMailHost()
m.APIKey = getGatewayAPIKey()
var res *services.MailResponse
if id == 0 {
res = m.AddMailServer(&ms)
} else {
res = m.UpdateMailServer(&ms)
}
fmt.Println(res)
if res.Success == true {
http.Redirect(w, r, "/admin/main", http.StatusFound)
} else {
fmt.Println("Mail Server update failed")
http.Redirect(w, r, "/admin/main", http.StatusFound)
}
}
}