Compare commits
3 Commits
8d0cd0fd1b
...
ffb9600089
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffb9600089 | ||
|
|
d62e1f7b8f | ||
|
|
5aa2ce47c7 |
@@ -1,6 +1,9 @@
|
||||
package logging
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
type EventType int
|
||||
|
||||
@@ -9,11 +12,43 @@ const (
|
||||
)
|
||||
|
||||
func Info(message string) {
|
||||
log.Print(message)
|
||||
log.Printf("Info: %s", message)
|
||||
}
|
||||
|
||||
func Infof(message string, vars ...any) {
|
||||
log.Printf(message, vars...)
|
||||
func Infof(message string, v ...any) {
|
||||
log.Printf("Info: %s", fmt.Sprintf(message, v...))
|
||||
}
|
||||
|
||||
func Debug(message string) {
|
||||
log.Printf("Debug: %s", message)
|
||||
}
|
||||
|
||||
func Debugf(message string, v ...any) {
|
||||
log.Printf("Debug: %s", fmt.Sprintf(message, v...))
|
||||
}
|
||||
|
||||
func Warn(message string) {
|
||||
log.Printf("Warn: %s", message)
|
||||
}
|
||||
|
||||
func Warnf(message string, v ...any) {
|
||||
log.Printf("Warn: %s", fmt.Sprintf(message, v...))
|
||||
}
|
||||
|
||||
func Error(message string) {
|
||||
log.Printf("Error: %s", message)
|
||||
}
|
||||
|
||||
func Errorf(message string, v ...any) {
|
||||
log.Printf("Error: %s", fmt.Sprintf(message, v...))
|
||||
}
|
||||
|
||||
func Fatal(message string) {
|
||||
log.Fatal(message)
|
||||
}
|
||||
|
||||
func Fatalf(message string, v ...any) {
|
||||
log.Fatalf(message, v...)
|
||||
}
|
||||
|
||||
func Event(eventType EventType, eventData ...any) {
|
||||
|
||||
@@ -6,12 +6,26 @@ import (
|
||||
"astraltech.xyz/accountmanager/src/logging"
|
||||
)
|
||||
|
||||
// Reads a file, if fails just returns an error
|
||||
func ReadFile(path string) ([]byte, error) {
|
||||
logging.Event(logging.ReadFile, "static/blank_profile.jpg")
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
logging.Infof("Could not read file at %s", path)
|
||||
logging.Infof("Error code: %e", err)
|
||||
return nil, err
|
||||
}
|
||||
logging.Infof("Successfully read file at %s", path)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func ReadRequiredFile(path string) []byte {
|
||||
logging.Event(logging.ReadFile, "static/blank_profile.jpg")
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
logging.Fatalf("Could not read file at %s", path)
|
||||
return nil
|
||||
}
|
||||
logging.Infof("Successfully read file at %s", path)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"astraltech.xyz/accountmanager/src/logging"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
)
|
||||
|
||||
@@ -21,15 +22,21 @@ type LDAPSearch struct {
|
||||
}
|
||||
|
||||
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) {
|
||||
logging.Debugf("Connecting to LDAP server %s", URL)
|
||||
l, err := ldap.DialURL(URL)
|
||||
if err != nil {
|
||||
logging.Fatal("Failed to connect to LDAP server")
|
||||
logging.Fatal(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
logging.Infof("Connected to LDAP server")
|
||||
|
||||
if starttls {
|
||||
logging.Debugf("Enabling StartTLS")
|
||||
if err := l.StartTLS(&tls.Config{InsecureSkipVerify: ignore_cert}); err != nil {
|
||||
log.Println("StartTLS failed:", err)
|
||||
logging.Errorf("StartTLS failed %s", err.Error())
|
||||
}
|
||||
logging.Infof("StartTLS enabled")
|
||||
}
|
||||
|
||||
return &LDAPServer{
|
||||
|
||||
@@ -313,7 +313,7 @@ func main() {
|
||||
var err error = nil
|
||||
blankPhotoData, err = ReadFile("static/blank_profile.jpg")
|
||||
if err != nil {
|
||||
log.Fatal("Could not load blank profile image")
|
||||
logging.Fatal("Could not load blank profile image")
|
||||
}
|
||||
serverConfig, err = loadServerConfig("./data/config.json")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user