💼Briefing Document: Gallery Protect System

This document provides a comprehensive description of the "Gallery Protect" system, a lightweight, file-based security framework designed to protect web content. The system's architecture is centered on a Synchronous Gatekeeping strategy, which employs a multi-layered perimeter defense without relying on a traditional SQL database.

Short descriptive picture of package

Summary

The first layer of defense is established at the server level via Apache .htaccess rules, which intercept unauthorized requests, redirect traffic to an authentication gate, and block direct browser access to sensitive data files such as users.txt and global_activity.log. The second layer consists of PHP session logic, which uses a "Kill Protocol" to terminate page execution instantly if a valid session token is not present. A key architectural feature is Namespace Isolation, which prefixes all session variables with a unique folder ID, allowing multiple independent galleries to operate on the same server without session conflicts.

The system utilizes a flat-file database (users.txt) for user credentials, employing atomic file-locking (LOCK_EX) to prevent data corruption during password changes. It features robust Unicode-aware validation to support international characters while maintaining database integrity. Integration with content systems like the h5ai gallery is achieved through JavaScript injection, while custom HTML projects are secured using a protect.php gatekeeper script. Common operational challenges, such as path resolution errors and aggressive browser caching, are addressed with specific troubleshooting protocols, including "Hard Refresh" procedures and "Version Bumping" for static assets.



System Architecture and Core Principles

The Gallery Protect system is built on a "Synchronous Gatekeeping" strategy, which uses the server's file system and session memory to create a robust, multi-layered security perimeter. This approach avoids the overhead of a database server.

Multi-Layered Security Model

The system's defense is structured in three distinct layers, processing each request sequentially.



Core Components and File Manifest

The system is composed of several key PHP scripts, configuration files, and data stores that work in concert to provide access control.

File/Directory

Role & Function

/nphotos/auth.php

The central engine. Manages sessions, validates credentials against users.txt, serves the login UI, and logs logout actions.

/nphotos/config.php

Configuration hub. Defines the $MY_FOLDER_ID and physical path constants required by all scripts.

/nphotos/protect.php

A dedicated content gatekeeper for the /protected_html/ directory. Wraps content fragments and handles "Dynamic Logout" redirection.

/nphotos/change_password.php

User utility for updating users.txt with an atomic lock (LOCK_EX) and forcing a re-login to synchronize credentials.

/nphotos/user_info.php

An AJAX endpoint that serves as a read-only session identity provider for the h5ai user interface.

/nphotos/monitor.php

The admin dashboard. Displays activity logs with features like "Auto-Trim" (to 2000 lines), "Smart Dates", and a scrollable history view.

/nphotos/logout.php

Global session terminator. Redirects users back to their last page or to the monitor if initiated from there (?from_monitor=1).

/nphotos/users.txt

The user database, storing credentials in a user:pass format. Access is restricted at the server level.

/nphotos/global_activity.log

The system-wide activity log, recording timestamp, folder, user, IP, action, and login start time.

/nphotos/avatar/

Directory for user profile pictures (username.png, username.jpg) used in the UI.

/protected_html/

A target directory for securing custom HTML projects, using protect.php to wrap content fragments (e.g., _content.php).

/nphotos/albums/

The primary directory for h5ai gallery content and the system's integration scripts.

Security Implementation via .htaccess

Server-level .htaccess configurations are critical to the system's security, providing preemptive protection for sensitive data and content.



User and Session Management

The system includes detailed logic for handling user credentials, password changes, and session state across various user interactions.

Credentials and Password Management

Session and Logout Logic



System Integration and Administration

The framework is designed for integration with other web applications and provides tools for administration and troubleshooting.

Integration Methods

Administration and Troubleshooting