readd directory
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package ldap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
)
|
||||
|
||||
type TypesearchCount struct {
|
||||
ResultDest *int
|
||||
SearchLdap string
|
||||
LdapAttrs []string
|
||||
}
|
||||
|
||||
type TypesearchLdapValues struct {
|
||||
ResultDest *string
|
||||
SearchLdap string
|
||||
LdapAttrs []string
|
||||
}
|
||||
|
||||
func SearchLdapVal(l *ldap.Conn, search TypesearchLdapValues, attrValue string) {
|
||||
result, err := Search(l, search.SearchLdap, search.LdapAttrs)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, entry := range result.Entries {
|
||||
for _, cn := range entry.GetAttributeValues(attrValue) {
|
||||
*search.ResultDest = cn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SearchLdapCount(l *ldap.Conn, search TypesearchCount) {
|
||||
result, err := Search(l, search.SearchLdap, search.LdapAttrs)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
*search.ResultDest = len(result.Entries)
|
||||
}
|
||||
|
||||
// Ldap Connection without TLS
|
||||
func Connect(FQDN string, BindUsername string, BindPassword string) (*ldap.Conn, error) {
|
||||
// You can also use IP instead of FQDN
|
||||
l, err := ldap.DialURL(fmt.Sprintf("ldap://%s:389", FQDN))
|
||||
l.Bind(BindUsername, BindPassword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// Normal Search
|
||||
func Search(l *ldap.Conn, filter string, ldapAttrs []string) (*ldap.SearchResult, error) {
|
||||
|
||||
searchReq := ldap.NewSearchRequest(
|
||||
"",
|
||||
ldap.ScopeWholeSubtree,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
filter,
|
||||
ldapAttrs,
|
||||
nil,
|
||||
)
|
||||
result, err := l.Search(searchReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error: %s", err)
|
||||
}
|
||||
|
||||
if len(result.Entries) >= 0 {
|
||||
return result, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("couldn't fetch search entries")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package zimbra
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Localconfig struct {
|
||||
XMLName xml.Name `xml:"localconfig"`
|
||||
LocalconfigKeys []LocalconfigKey `xml:"key"`
|
||||
}
|
||||
|
||||
type LocalconfigKey struct {
|
||||
XMLName xml.Name `xml:"key"`
|
||||
Name string `xml:"name,attr"`
|
||||
Value string `xml:"value"`
|
||||
}
|
||||
|
||||
var localConfigData map[string]string
|
||||
|
||||
func ReadLocalConfig(basePath string) error {
|
||||
|
||||
filePath := filepath.Join(basePath, "conf/localconfig.xml")
|
||||
xmlFile, errOpen := os.Open(filePath)
|
||||
if errOpen != nil {
|
||||
return errOpen
|
||||
}
|
||||
defer xmlFile.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, errCopy := io.Copy(&buf, xmlFile)
|
||||
if errCopy != nil {
|
||||
return errCopy
|
||||
|
||||
}
|
||||
|
||||
var data Localconfig
|
||||
|
||||
errXml := xml.Unmarshal(buf.Bytes(), &data)
|
||||
if errXml != nil {
|
||||
return errXml
|
||||
}
|
||||
|
||||
localConfigData = make(map[string]string)
|
||||
|
||||
for _, key := range data.LocalconfigKeys {
|
||||
localConfigData[key.Name] = key.Value
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Get(param string) (string, bool) {
|
||||
|
||||
value, ok := localConfigData[param]
|
||||
|
||||
return value, ok
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package zxsuite
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func CmdZxSuite(module string, cmd string) ([]byte, error) {
|
||||
outputZx, err := exec.Command("sudo", "-u", "zimbra", "/opt/zimbra/bin/zxsuite", "--json", module, cmd).Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return outputZx, nil
|
||||
}
|
||||
|
||||
func CmdZmcontrol(cmd string) ([]byte, error) {
|
||||
outputZmcontrol, err := exec.Command("sudo", "-u", "zimbra", "/opt/zimbra/bin/zmcontrol", cmd).Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return outputZmcontrol, nil
|
||||
}
|
||||
Reference in New Issue
Block a user