Skip to content

Commit 5263552

Browse files
authored
Merge pull request #1 from sycofly/UNO-861-acc-man
Uno 861 acc man
2 parents 224408a + 4693e6e commit 5263552

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+24650
-0
lines changed

.env.example

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Database Configuration
2+
DB_HOST=localhost
3+
DB_PORT=5432
4+
DB_USER=postgres
5+
DB_PASSWORD=postgres
6+
DB_NAME=unixify
7+
DB_SSLMODE=disable
8+
9+
# Server Configuration
10+
SERVER_PORT=8080
11+
GIN_MODE=debug
12+
JWT_SECRET=default_secret_change_me_in_production

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
unixify
8+
9+
# Test binary, built with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool, specifically when used with LiteIDE
13+
*.out
14+
15+
# Dependency directories (remove the comment below to include it)
16+
# vendor/
17+
18+
# Environment variables
19+
.env
20+
21+
# IDE specific files
22+
.idea/
23+
.vscode/
24+
*.swp
25+
*.swo
26+
27+
# OS specific files
28+
.DS_Store
29+
Thumbs.db
30+
31+
# Application logs
32+
*.log
33+
34+
# Database dumps and backups
35+
*.sql
36+
*.dump
37+
*.bak

CLAUDE.md

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Unixify - UNIX Account/Group Registry
2+
3+
Unixify is a Go application that serves as a registry for UNIX account UIDs and Group GIDs.
4+
5+
## Project Overview
6+
7+
The application provides a web interface for managing UNIX accounts and groups with the following features:
8+
9+
1. PostgreSQL database backend
10+
2. Web interface with four sections: People, System, Database, and Service
11+
3. Complete audit log system for all operations
12+
4. Full RESTful API for all operations
13+
5. JWT-based authentication with optional TOTP 2FA
14+
6. Light/dark mode theme switching with auto-detection
15+
7. Read-only guest mode with visual indicators
16+
8. Gradient text and consistent button styling
17+
18+
## Account/Group Types and UID/GID Ranges
19+
20+
| Type | Account UID Range | Group GID Range |
21+
|----------|-------------------|-----------------|
22+
| People | 5000-6000 | 1000-3000 |
23+
| System | 1000-2000 | 3000-5000 |
24+
| Database | 2000-7999 | 2000-7500 |
25+
| Service | 8000-8999 | 4000-5000 |
26+
27+
## Key Operations
28+
29+
- Add/edit/delete accounts and groups
30+
- Assign/remove users from groups
31+
- View detailed audit logs of all system events
32+
- Search by UID, GID, username, or groupname
33+
- User authentication with optional TOTP 2FA
34+
- Theme switching (light/dark mode)
35+
- Guest read-only access with registration for edit permissions
36+
37+
## Development Commands
38+
39+
```bash
40+
# Run the application locally
41+
go run cmd/unixify/main.go
42+
43+
# Build the application
44+
go build -o unixify cmd/unixify/main.go
45+
46+
# Run database migrations
47+
go run cmd/migrate/main.go
48+
```
49+
50+
## Deployment Commands
51+
52+
```bash
53+
# Start the application with Podman
54+
podman-compose up -d
55+
56+
# Stop the application
57+
podman-compose down
58+
59+
# View application logs
60+
podman logs uno-861-acc-man_unixify_1
61+
62+
# View specific log entries
63+
podman logs uno-861-acc-man_unixify_1 | grep "ERROR"
64+
65+
# Run a standalone frontend with Caddy (for testing UI changes)
66+
podman build -t unixify-caddy -f Dockerfile.caddy .
67+
podman run -d -p 8081:80 --name unixify-caddy unixify-caddy
68+
```
69+
70+
## Container Notes
71+
72+
- The main application runs on port 8080
73+
- The frontend-only container runs on port 8081
74+
- Templates are stored in `/app/web/templates/`
75+
- Static assets are in `/app/web/static/`
76+
- Do NOT use volume mounts that override the container's web directory
77+
- Use custom frontend container with Caddy for UI-only changes
78+
79+
## Tech Stack
80+
81+
- Go with Gin web framework
82+
- PostgreSQL database
83+
- HTML/CSS/JavaScript frontend
84+
- RESTful API backend
85+
- JWT-based authentication
86+
- Google Authenticator TOTP support
87+
- Theme switching with CSS variables
88+
- Audit logging for all operations
89+
90+
## Authentication System
91+
92+
The application includes a comprehensive authentication system:
93+
- JWT token-based authentication
94+
- Password hashing with bcrypt
95+
- Optional TOTP second factor with Google Authenticator
96+
- Protected API routes with middleware
97+
- User profiles and password management
98+
- Self-registration with email verification and admin approval
99+
- Automatic guest mode with clear visual indicators
100+
- Proper separation between regular users and guest accounts
101+
102+
## Theming System
103+
104+
The application supports light and dark themes:
105+
- CSS variables for comprehensive theme support
106+
- Theme toggle button integrated in the navigation bar
107+
- Theme preference stored in localStorage for persistence
108+
- System preference detection via `prefers-color-scheme`
109+
- Dark mode for all UI components including forms, tables, and alerts
110+
- Light grey text in tables for better dark mode readability
111+
- Gradient text effects for headings and descriptions
112+
- Consistent color palette for buttons and interactive elements
113+
- Custom colored badges with theme-appropriate styling
114+
115+
## Access Control
116+
117+
The application implements a role-based access control system:
118+
- Guests have automatic read-only access to view data
119+
- "Guest Account (Read-Only)" indicator clearly shows status
120+
- Registration is required to request edit permissions
121+
- New registrations require admin approval
122+
- Authenticated users can perform edits based on their role
123+
- UI dynamically adapts to show/hide edit controls based on permissions
124+
- Clear visual indicators show current access mode
125+
- Proper user dropdown menu visibility control for guest vs regular users
126+
127+
## UI Enhancements
128+
129+
The application features a modern and user-friendly interface:
130+
- Clean, responsive layout with Bootstrap 5
131+
- Soft purple and green accent colors for key UI elements
132+
- Blue-to-purple gradient text for headings and descriptions
133+
- Consistent button styling across the application
134+
- Card-based UI with subtle shadows and animations
135+
- Interactive hover effects for better user feedback
136+
- Custom document viewer for application documentation
137+
- UID/GID Range Reference card with optimized dark mode display

Caddyfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:80
2+
3+
root * /srv
4+
file_server
5+
6+
header {
7+
X-Content-Type-Options nosniff
8+
X-Frame-Options DENY
9+
Referrer-Policy no-referrer-when-downgrade
10+
}

Containerfile

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Build stage
2+
FROM docker.io/library/golang:1.22-alpine AS builder
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy go mod and sum files
8+
COPY go.mod go.sum ./
9+
10+
# Download dependencies
11+
RUN go mod download
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Build the application
17+
RUN CGO_ENABLED=0 GOOS=linux go build -o unixify ./cmd/unixify
18+
19+
# Final stage
20+
FROM docker.io/library/alpine:latest
21+
22+
# Add necessary packages
23+
RUN apk --no-cache add ca-certificates tzdata
24+
25+
# Set working directory
26+
WORKDIR /app
27+
28+
# Copy binary from build stage
29+
COPY --from=builder /app/unixify /app/unixify
30+
31+
# Copy web templates and static files from the actual source directory
32+
COPY ./web /app/web
33+
34+
# No email configuration needed here since we're using MailHog as a separate service
35+
36+
# Expose port
37+
EXPOSE 8080
38+
39+
# Set environment variables
40+
ENV GIN_MODE=release
41+
42+
# Command to run
43+
CMD ["/app/unixify"]

Dockerfile.caddy

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM docker.io/library/caddy:2-alpine
2+
3+
COPY Caddyfile /etc/caddy/Caddyfile
4+
COPY web-build /srv
5+
6+
EXPOSE 80
7+
8+
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"]

Dockerfile.nginx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM docker.io/library/nginx:alpine
2+
COPY web-build /usr/share/nginx/html
3+
EXPOSE 80
4+
CMD ["nginx", "-g", "daemon off;"]

GUEST_ACCOUNT.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Guest Account Implementation
2+
3+
This document explains the implementation of the guest account feature in the Unixify application.
4+
5+
## Overview
6+
7+
The application now automatically logs in users as a "guest" account when they access the system without authentication. This provides a unified experience where:
8+
9+
1. All users are technically "authenticated" but with different permission levels
10+
2. Guest users are clearly identified in the UI
11+
3. A consistent navigation experience is maintained for all users
12+
13+
## How It Works
14+
15+
### 1. Automatic Guest Login
16+
17+
When a user accesses the application without a valid authentication token, the system:
18+
19+
1. Automatically creates a guest token in localStorage
20+
2. Sets up a guest user profile with username "guest"
21+
3. Displays the guest account in the navigation bar
22+
4. Applies read-only permissions to all UI elements
23+
24+
### 2. Guest User Interface
25+
26+
The guest user experience includes:
27+
28+
- A yellow "Guest Account (Read-Only)" indicator in the navbar
29+
- A special yellow dashed avatar with "G" (for Guest)
30+
- A user dropdown menu showing the guest username and role
31+
- Disabled edit buttons throughout the interface
32+
- A "Register Now" banner encouraging account creation
33+
34+
### 3. Authentication Flow
35+
36+
The authentication system manages three states:
37+
38+
1. **Not Authenticated**: No token of any kind (redirects to login)
39+
2. **Guest User**: Has a guest token (read-only access)
40+
3. **Authenticated User**: Has a regular auth token (permissions based on role)
41+
42+
### 4. Technical Implementation
43+
44+
The guest account is implemented through:
45+
46+
- A `guest_token` in localStorage that identifies guest sessions
47+
- A `isGuestUser()` function that differentiates between guest and regular users
48+
- Special CSS styling for guest UI elements
49+
- Modified permission checking to recognize and handle guest accounts
50+
- Updated templates to display guest-specific UI elements
51+
52+
## Testing the Guest Account
53+
54+
### Using the Simplified Server
55+
56+
1. Run the simplified server:
57+
```bash
58+
cd /home/pfrederi/code/github.com/home/unixify/feature/UNO-861-acc-man
59+
PORT=8083 go run cmd/simplified/main.go
60+
```
61+
62+
2. Access the application at http://localhost:8083
63+
3. You'll be automatically logged in as the guest user
64+
4. To test regular authentication, use the login page with:
65+
- Username: admin
66+
- Password: admin
67+
68+
### Using the Login API
69+
70+
The application provides a mock login API that accepts:
71+
72+
- Guest login: username "guest" with any password
73+
- Admin login: username "admin" with password "admin"
74+
75+
Example:
76+
```javascript
77+
// Guest login
78+
fetch('/api/auth/login', {
79+
method: 'POST',
80+
headers: { 'Content-Type': 'application/json' },
81+
body: JSON.stringify({ username: 'guest', password: 'anything' })
82+
})
83+
```
84+
85+
## Benefits
86+
87+
The guest account approach provides several benefits:
88+
89+
1. **Unified Code Path**: The code can treat all users as authenticated, simplifying logic
90+
2. **Clear Visual Indicators**: Users always know their current access level
91+
3. **Smoother UX**: No jarring transitions between authenticated and non-authenticated states
92+
4. **Easy Registration Path**: Clear path for users to upgrade from guest to registered user
93+
5. **Permission Management**: Centralized permission system that works for all user types

0 commit comments

Comments
 (0)