|
@@ -5,13 +5,14 @@ import (
|
|
"crypto/tls"
|
|
"crypto/tls"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/dgrijalva/jwt-go"
|
|
|
|
- "github.com/labstack/echo"
|
|
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/http"
|
|
"net/url"
|
|
"net/url"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
+
|
|
|
|
+ "github.com/dgrijalva/jwt-go"
|
|
|
|
+ "github.com/labstack/echo"
|
|
)
|
|
)
|
|
|
|
|
|
type handler struct{}
|
|
type handler struct{}
|
|
@@ -222,13 +223,15 @@ func (h *handler) addUser(c echo.Context) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("err:", err)
|
|
fmt.Println("err:", err)
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("AddUser Claims: ", claims)
|
|
|
|
+ fmt.Println("AddUser token: ", token)
|
|
username := c.FormValue("Username")
|
|
username := c.FormValue("Username")
|
|
sha256 := sha256.Sum256([]byte(username))
|
|
sha256 := sha256.Sum256([]byte(username))
|
|
var hashChannel = make(chan []byte, 1)
|
|
var hashChannel = make(chan []byte, 1)
|
|
hashChannel <- sha256[:]
|
|
hashChannel <- sha256[:]
|
|
ciphertext := encrypt(<-hashChannel, string(b))
|
|
ciphertext := encrypt(<-hashChannel, string(b))
|
|
- //fmt.Println(b)
|
|
|
|
- //fmt.Println(ciphertext)
|
|
|
|
|
|
+ fmt.Println("B: ", string(b))
|
|
|
|
+ fmt.Println("Ciphere: ", ciphertext)
|
|
sn := c.FormValue("Lname")
|
|
sn := c.FormValue("Lname")
|
|
cn := c.FormValue("FullName")
|
|
cn := c.FormValue("FullName")
|
|
givenname := c.FormValue("Fname")
|
|
givenname := c.FormValue("Fname")
|
|
@@ -306,6 +309,7 @@ func (h *handler) addUser(c echo.Context) error {
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
result := addUser{}
|
|
result := addUser{}
|
|
_err := json.Unmarshal(body, &result)
|
|
_err := json.Unmarshal(body, &result)
|
|
|
|
+ // fmt.Println(result)
|
|
if _err != nil {
|
|
if _err != nil {
|
|
_apiErr := apiErr{}
|
|
_apiErr := apiErr{}
|
|
__err := json.Unmarshal(body, &_apiErr)
|
|
__err := json.Unmarshal(body, &_apiErr)
|
|
@@ -316,7 +320,13 @@ func (h *handler) addUser(c echo.Context) error {
|
|
return c.String(http.StatusBadRequest, string(res2B))
|
|
return c.String(http.StatusBadRequest, string(res2B))
|
|
}
|
|
}
|
|
go sendMail("Welcome to ZiCloud\r\n Your temporary link is :\r\n https://zicloud.com/reset/"+url.QueryEscape(ciphertext), "Welcome to ZiCloud", mail)
|
|
go sendMail("Welcome to ZiCloud\r\n Your temporary link is :\r\n https://zicloud.com/reset/"+url.QueryEscape(ciphertext), "Welcome to ZiCloud", mail)
|
|
- return c.String(http.StatusOK, "Done, Reset Link was sent to "+mail)
|
|
|
|
|
|
+ resp := _response{
|
|
|
|
+ Origin: "addUser",
|
|
|
|
+ Message: "Done, Reset Link was sent to " + mail,
|
|
|
|
+ Code: 1000,
|
|
|
|
+ }
|
|
|
|
+ b, _ = json.MarshalIndent(resp, "", " ")
|
|
|
|
+ return c.String(http.StatusOK, string(b))
|
|
}
|
|
}
|
|
func (h *handler) disableUser(c echo.Context) error {
|
|
func (h *handler) disableUser(c echo.Context) error {
|
|
user := c.Get("user").(*jwt.Token)
|
|
user := c.Get("user").(*jwt.Token)
|
|
@@ -360,7 +370,13 @@ func (h *handler) disableUser(c echo.Context) error {
|
|
return c.String(http.StatusBadRequest, "Error"+err.Error())
|
|
return c.String(http.StatusBadRequest, "Error"+err.Error())
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- return c.String(http.StatusOK, "Done")
|
|
|
|
|
|
+ resp := _response{
|
|
|
|
+ Origin: "disableUser",
|
|
|
|
+ Message: "Done",
|
|
|
|
+ Code: 1000,
|
|
|
|
+ }
|
|
|
|
+ b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
|
+ return c.String(http.StatusOK, string(b))
|
|
}
|
|
}
|
|
func (h *handler) resetUser(c echo.Context) error {
|
|
func (h *handler) resetUser(c echo.Context) error {
|
|
type keyJson struct {
|
|
type keyJson struct {
|
|
@@ -368,7 +384,7 @@ func (h *handler) resetUser(c echo.Context) error {
|
|
Admin bool `json:"admin"`
|
|
Admin bool `json:"admin"`
|
|
Exp int `json:"exp"`
|
|
Exp int `json:"exp"`
|
|
Memberof []string `json:"memberof"`
|
|
Memberof []string `json:"memberof"`
|
|
- Name []string `json:"name"`
|
|
|
|
|
|
+ Name string `json:"name"`
|
|
Sub int `json:"sub"`
|
|
Sub int `json:"sub"`
|
|
}
|
|
}
|
|
t := time.Now() //%Y%m%d%H%M%SZ
|
|
t := time.Now() //%Y%m%d%H%M%SZ
|
|
@@ -377,13 +393,19 @@ func (h *handler) resetUser(c echo.Context) error {
|
|
password := c.FormValue("Password")
|
|
password := c.FormValue("Password")
|
|
key := c.FormValue("key")
|
|
key := c.FormValue("key")
|
|
key, _ = url.QueryUnescape(key)
|
|
key, _ = url.QueryUnescape(key)
|
|
- sha256 := sha256.Sum256([]byte(username))
|
|
|
|
|
|
+ _sha256 := sha256.Sum256([]byte(username))
|
|
var hashChannel = make(chan []byte, 1)
|
|
var hashChannel = make(chan []byte, 1)
|
|
- hashChannel <- sha256[:]
|
|
|
|
|
|
+ hashChannel <- _sha256[:]
|
|
plainkey := decrypt(<-hashChannel, key)
|
|
plainkey := decrypt(<-hashChannel, key)
|
|
_plainkey := keyJson{}
|
|
_plainkey := keyJson{}
|
|
json.Unmarshal([]byte(plainkey), &_plainkey)
|
|
json.Unmarshal([]byte(plainkey), &_plainkey)
|
|
- token := _plainkey.IPAToken
|
|
|
|
|
|
+ _name := _plainkey.Name
|
|
|
|
+ //_sha256 := sha256.Sum256([]byte(string("")))
|
|
|
|
+ var hashChannel_ = make(chan []byte, 1)
|
|
|
|
+ __sha256 := sha256.Sum256([]byte(_name))
|
|
|
|
+ hashChannel_ <- __sha256[:]
|
|
|
|
+ token := decrypt(<-hashChannel_, string(_plainkey.IPAToken))
|
|
|
|
+ // token := _plainkey.IPAToken
|
|
_url := URL + "/ipa/session/json"
|
|
_url := URL + "/ipa/session/json"
|
|
method := "POST"
|
|
method := "POST"
|
|
_json := fmt.Sprintf(`
|
|
_json := fmt.Sprintf(`
|
|
@@ -415,6 +437,10 @@ func (h *handler) resetUser(c echo.Context) error {
|
|
req.Header.Add("Accept", "text/plain")
|
|
req.Header.Add("Accept", "text/plain")
|
|
req.Header.Add("Cookie", token)
|
|
req.Header.Add("Cookie", token)
|
|
res, err := client.Do(req)
|
|
res, err := client.Do(req)
|
|
|
|
+ //fmt.Println(token)
|
|
|
|
+ //fmt.Println(_json)
|
|
|
|
+ //fmt.Println(req)
|
|
|
|
+ //fmt.Println(res)
|
|
_json = fmt.Sprintf(`
|
|
_json = fmt.Sprintf(`
|
|
{
|
|
{
|
|
"id": 0,
|
|
"id": 0,
|
|
@@ -441,12 +467,21 @@ func (h *handler) resetUser(c echo.Context) error {
|
|
req.Header.Add("Cookie", token)
|
|
req.Header.Add("Cookie", token)
|
|
err = nil
|
|
err = nil
|
|
res, err = client.Do(req)
|
|
res, err = client.Do(req)
|
|
- //fmt.Println(payload)
|
|
|
|
|
|
+ //fmt.Println(token)
|
|
|
|
+ //fmt.Println(_json)
|
|
|
|
+ //fmt.Println(req)
|
|
|
|
+ //fmt.Println(res)
|
|
if err != nil {
|
|
if err != nil {
|
|
return c.String(http.StatusBadRequest, "Error"+err.Error())
|
|
return c.String(http.StatusBadRequest, "Error"+err.Error())
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- return c.String(http.StatusOK, "Done")
|
|
|
|
|
|
+ resp := _response{
|
|
|
|
+ Origin: "resetUser",
|
|
|
|
+ Message: "Done",
|
|
|
|
+ Code: 1000,
|
|
|
|
+ }
|
|
|
|
+ b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
|
+ return c.String(http.StatusOK, string(b))
|
|
}
|
|
}
|
|
func (h *handler) dnsrecordadd(c echo.Context) error {
|
|
func (h *handler) dnsrecordadd(c echo.Context) error {
|
|
user := c.Get("user").(*jwt.Token)
|
|
user := c.Get("user").(*jwt.Token)
|
|
@@ -500,7 +535,13 @@ func (h *handler) dnsrecordadd(c echo.Context) error {
|
|
//json.Unmarshal(body, &_res)
|
|
//json.Unmarshal(body, &_res)
|
|
//fmt.Println(_res)
|
|
//fmt.Println(_res)
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- return c.String(http.StatusOK, "Done")
|
|
|
|
|
|
+ resp := _response{
|
|
|
|
+ Origin: "dnsrecordadd",
|
|
|
|
+ Message: "Done",
|
|
|
|
+ Code: 1000,
|
|
|
|
+ }
|
|
|
|
+ b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
|
+ return c.String(http.StatusOK, string(b))
|
|
}
|
|
}
|
|
func (h *handler) token(c echo.Context) error {
|
|
func (h *handler) token(c echo.Context) error {
|
|
user := c.Get("user").(*jwt.Token)
|
|
user := c.Get("user").(*jwt.Token)
|
|
@@ -520,7 +561,7 @@ func (h *handler) token(c echo.Context) error {
|
|
}
|
|
}
|
|
func (h *handler) verifyUser(c echo.Context) error {
|
|
func (h *handler) verifyUser(c echo.Context) error {
|
|
name := c.FormValue("Username")
|
|
name := c.FormValue("Username")
|
|
- fmt.Println("Name: ", name)
|
|
|
|
|
|
+ //fmt.Println("Name: ", name)
|
|
if name == "" {
|
|
if name == "" {
|
|
return c.JSON(http.StatusNotFound, "User NOT Found")
|
|
return c.JSON(http.StatusNotFound, "User NOT Found")
|
|
}
|
|
}
|
|
@@ -552,10 +593,25 @@ func (h *handler) verifyUser(c echo.Context) error {
|
|
if res.StatusCode == 200 {
|
|
if res.StatusCode == 200 {
|
|
user := getUserInfo(token, name)
|
|
user := getUserInfo(token, name)
|
|
if user.Result.Value != name {
|
|
if user.Result.Value != name {
|
|
- return c.JSON(http.StatusNotFound, "User NOT Found")
|
|
|
|
|
|
+ resp := _response{
|
|
|
|
+ Origin: "VerifyUser",
|
|
|
|
+ Message: "User Not Found",
|
|
|
|
+ Code: 1001,
|
|
|
|
+ }
|
|
|
|
+ b, _errr := json.MarshalIndent(resp, "", " ")
|
|
|
|
+ if _errr != nil {
|
|
|
|
+ fmt.Println(_errr)
|
|
|
|
+ }
|
|
|
|
+ fmt.Print(string(b))
|
|
|
|
+ return c.JSON(http.StatusNotFound, string(b))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ resp := _response{
|
|
|
|
+ Origin: "VerifyUser",
|
|
|
|
+ Message: "User Found",
|
|
|
|
+ Code: 1002,
|
|
|
|
+ }
|
|
|
|
+ b, _ := json.MarshalIndent(resp, "", " ")
|
|
|
|
|
|
- return c.JSON(http.StatusOK, "User Founded")
|
|
|
|
-
|
|
|
|
|
|
+ return c.JSON(http.StatusOK, string(b))
|
|
}
|
|
}
|