Compare commits
7 Commits
c5358e6c50
...
ffb9600089
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffb9600089 | ||
|
|
d62e1f7b8f | ||
|
|
5aa2ce47c7 | ||
|
|
8d0cd0fd1b | ||
|
|
35ec6678f8 | ||
|
|
ac20f9172d | ||
|
|
b96f65c294 |
@@ -20,7 +20,7 @@ A simple, lightweight web application for managing user profile photos in a Free
|
|||||||
1. **Clone the Repository**
|
1. **Clone the Repository**
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.astraltech.xyz/gawells/Self-Service-Dashboard
|
git clone https://git.astraltech.xyz/gawells/Self-Service-Dashboard
|
||||||
cd account-manager
|
cd Self-Service-Dashboard
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Configure the Application**
|
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**
|
5. **Run the Server**
|
||||||
```bash
|
```bash
|
||||||
go run src/*.go
|
go run ./src/main/
|
||||||
```
|
```
|
||||||
The application will be available at `http://<host>:<port>`.
|
The application will be available at `http://<host>:<port>`.
|
||||||
|
|
||||||
|
|||||||
62
src/logging/logging.go
Normal file
62
src/logging/logging.go
Normal 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
31
src/main/helpers.go
Normal 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
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
"github.com/go-ldap/ldap/v3"
|
"github.com/go-ldap/ldap/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,15 +22,21 @@ type LDAPSearch struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) {
|
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) {
|
||||||
|
logging.Debugf("Connecting to LDAP server %s", URL)
|
||||||
l, err := ldap.DialURL(URL)
|
l, err := ldap.DialURL(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logging.Fatal("Failed to connect to LDAP server")
|
||||||
|
logging.Fatal(err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
logging.Infof("Connected to LDAP server")
|
||||||
|
|
||||||
if starttls {
|
if starttls {
|
||||||
|
logging.Debugf("Enabling StartTLS")
|
||||||
if err := l.StartTLS(&tls.Config{InsecureSkipVerify: ignore_cert}); err != nil {
|
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{
|
return &LDAPServer{
|
||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -170,7 +172,7 @@ func avatarHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
|
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
|
||||||
cleaned := filepath.Clean(filePath)
|
cleaned := filepath.Clean(filePath)
|
||||||
value, err := os.ReadFile(cleaned)
|
value, err := ReadFile(cleaned)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
photoCreatedMutex.Lock()
|
photoCreatedMutex.Lock()
|
||||||
@@ -306,11 +308,12 @@ func cleanupSessions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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 {
|
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")
|
serverConfig, err = loadServerConfig("./data/config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Reference in New Issue
Block a user