7 Commits

Author SHA1 Message Date
Gregory Wells
ffb9600089 some more changes to the Logger 2026-03-24 18:09:49 -04:00
Gregory Wells
d62e1f7b8f Debug connecting to the LDAP server 2026-03-24 18:08:36 -04:00
Gregory Wells
5aa2ce47c7 Fatalf and FatalFileRead 2026-03-24 17:51:59 -04:00
Gregory Wells
8d0cd0fd1b use read file helper function everywhere 2026-03-24 17:10:56 -04:00
Gregory Wells
35ec6678f8 implement and use first logging event (ReadFile) 2026-03-24 17:09:30 -04:00
Gregory Wells
ac20f9172d implement the first log message 2026-03-24 16:57:28 -04:00
Gregory Wells
b96f65c294 Redo File structure 2026-03-24 16:52:22 -04:00
9 changed files with 110 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ A simple, lightweight web application for managing user profile photos in a Free
1. **Clone the Repository**
```bash
git clone https://git.astraltech.xyz/gawells/Self-Service-Dashboard
cd account-manager
cd Self-Service-Dashboard
```
2. **Configure the Application**
@@ -39,7 +39,7 @@ A simple, lightweight web application for managing user profile photos in a Free
5. **Run the Server**
```bash
go run src/*.go
go run ./src/main/
```
The application will be available at `http://<host>:<port>`.

62
src/logging/logging.go Normal file
View File

@@ -0,0 +1,62 @@
package logging
import (
"fmt"
"log"
)
type EventType int
const (
ReadFile EventType = iota
)
func Info(message string) {
log.Printf("Info: %s", message)
}
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) {
switch eventType {
case ReadFile:
{
log.Printf("Reading file %s", eventData[0])
break
}
}
}

31
src/main/helpers.go Normal file
View File

@@ -0,0 +1,31 @@
package main
import (
"os"
"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
}

View File

@@ -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{

View File

@@ -11,6 +11,8 @@ import (
"strings"
"sync"
"time"
"astraltech.xyz/accountmanager/src/logging"
)
var (
@@ -170,7 +172,7 @@ func avatarHandler(w http.ResponseWriter, r *http.Request) {
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
cleaned := filepath.Clean(filePath)
value, err := os.ReadFile(cleaned)
value, err := ReadFile(cleaned)
if err == nil {
photoCreatedMutex.Lock()
@@ -306,11 +308,12 @@ func cleanupSessions() {
}
func main() {
var err error = nil
logging.Info("Starting the server")
blankPhotoData, err = os.ReadFile("static/blank_profile.jpg")
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 {