Skip to content

HSNPhira v1 Backend ​

HSNPhira v1 Backend uses the Python Flask framework, composed of multiple independent microservices, providing user management, room monitoring, command execution, and file services.

Service Architecture Overview ​

ServicePortTech StackDescription
user_manager2345Flask + SQLiteUser registration/login/info management, Phira data sync
room5000Flask + Log ParsingReal-time room status monitoring (log-driven)
api5001Flask + SQLiteRoom data collection and statistical analysis (API-driven)
command7878FlaskSecure command execution (whitelist + password verification)
file7880FlaskFile content service

1. user_manager (Port 2345) ​

Core user account management service.

Features ​

  • User Registration (POST /register) — Bind Phira account for registration, password salted hash storage
  • User Login (POST /login) — Password verification, returns user info
  • User Info Query (POST /info) — Queryable by admin/super admin privileges
  • User Info Modification (POST /info_changer) — Modify username, password, Phira ID, permissions, etc.
  • Admin Interfaces — User list query, single user update, batch update
  • Phira Data Sync — Background thread periodically updates user avatar and RKS from phira.5wyxi.com API

Database ​

  • File: phira_users.db (SQLite)
  • Table users: id, name, phira_id, phira_name, phira_rks, image_url, password(hash), admin, dev, created_at

Authentication ​

RoleCredentialPermissions
Super AdminFixed password (configured in code)Full control, can modify password/permission fields
Regular AdminFixed password (configured in code)Query user info, modify non-permission fields

2. room (Port 5000) ​

Log-driven real-time room status monitoring service. Tracks room events by reading phira-mp/server.log in real-time.

Features ​

  • Log Monitoring — Real-time log file tracking, parsing room create/join/leave/disband events
  • Room State Tracking — Records room state (selecting chart/in-progress), cycle toggle, chart selection
  • User Mapping — Maintains user_id → username and user_id → room_name mappings
  • Persistence — User mapping relationships written to user_info.json

API ​

EndpointDescription
GET /roomsGet detailed info for all rooms
GET /statusSystem status (room count, user count)
GET /healthHealth check
GET /users/totalTotal registered user count

Background Threads ​

  • Log Tracking (tail_log) — Reads log file changes in real-time
  • Room Cleanup (room_cleanup_task) — Cleans up rooms inactive for over 1 hour every 60 seconds

3. api (Port 5001) ​

API-driven room data collection and statistics service. Polls phira.htadiy.cc/api/rooms/info for data.

Features ​

  • Room Monitoring — Pulls room list from Phira API every second and stores in database
  • User Entry/Exit Tracking — Records when users enter/leave rooms and their stay duration
  • Game Round Tracking — Records game start/end times, user play duration
  • Online User Count Statistics

Database ​

  • File: phira_stats.db (SQLite)
  • Tables: rooms, user_room_activity, user_room_duration, game_rounds, user_playtime
EndpointDescription
GET /usersCurrent total online users

Background Threads ​

  • Room Monitoring (room_monitor_service) — Polls API every second, updates database

4. command (Port 7878) ​

Secure remote command execution service.

Features ​

  • Whitelist Commands — Predefined controlled commands (start/restart/stop/serverinfo)
  • Custom Commands — Allows execution of arbitrary commands (configurable via settings)
  • Triple Password Verification — Requires three password fragments for authentication
  • Dangerous Command Blacklist — Blocks dangerous operations like rm -rf /, mkfs, shutdown, etc.

API ​

EndpointDescription
POST /executeExecute command (whitelist or custom)

Security Mechanisms ​

  • All commands safely parsed via shlex.split
  • Dangerous command blacklist interception
  • Passwords verified using werkzeug.security.check_password_hash

5. file (Port 7880) ​

Simple file content service.

Features ​

  • Reads and returns file content at specified path (default /root/user_info.json)
  • Supports configuring target file via environment variable FILE_PATH

API ​

EndpointDescription
GET /apiReturns file content

Startup Methods ​

bash
# User management service
python user_manager.py       # → :2345

# Room monitoring service (log-driven)
python room.py               # → :5000

# Room monitoring service (API-driven)
python api.py                # → :5001

# Command execution service
python command.py            # → :7878

# File service
python file.py               # → :7880

Dependencies ​

  • flask — Web framework
  • werkzeug.security — Password hashing
  • sqlite3 — Database (Python built-in)
  • requests — HTTP requests (room API collection)
  • threading — Background threads (Python built-in)

Last modified byFireflyF09on2026-06-26 15:41

Built with VitePress