Source code related to trying to achieve the Project CyberCafe.
Project Cybercafe is an infrastructure project aimed at providing controlled internet access via a captive portal and a hotspot interface. The system acts as a router that intercepts unauthenticated web traffic, redirects users to a captive portal for login, and uses iptables and data tracking mechanisms to manage internet sessions based on data balances and speed queues.
The architecture consists of three main components:
- Backend: A set of Bash scripts managing the core daemon,
iptablesrules (NAT, Mangle, Filter), andlighttpdweb server configuration. - PHP Portal: The captive portal frontend built with PHP that authenticates users, checks data balances, and inserts internet session approvals.
- Database: SQLite databases storing user information, data lane balances, and active internet sessions.
- A Linux-based environment (e.g., Raspberry Pi, standard Linux server, or Android with Termux as seen in the codebase).
- Required packages:
bash(for running the scripts)sqlite3(for database operations)lighttpd(for the captive portal web server)iptables(for routing and traffic shaping)tc/iproute2(for network interface and traffic control)phpwith standard extensions (for the portal)
- Clone the repository to your target machine.
- Make sure all scripts in
./Backendare executable (chmod +x ./Backend/*.sh). - Configure the environment variables in
./Backend/cybercafe.confappropriately for your system. Pay special attention to:HS_INTERFACE(The network interface your hotspot runs on, e.g.,wlan0)DATABASE_PATH(Absolute path to your SQLite DB)LIGHTTPD_PATHandLIGHTTPD_CONF
- The database (
CyberCafe.dbor configured otherwise) should be initialized with validusersandbalance_tableentries. Thewebsite_sessionsandinternet_sessionstables will be dynamically updated by the PHP portal.
The primary interface for managing the backend is the cybercafe.sh script located in the Backend directory.
To start the daemon and setup the captive portal:
cd ./Backend
./cybercafe.sh runThis starts the Cybercafe daemon, which periodically checks the hotspot status, applies default iptables drop rules, redirects unauthenticated users to the captive server via DNAT on port 80, and starts the lighttpd web server.
To view if the daemon is running and check the interface IP:
cd ./Backend
./cybercafe.sh statusYou can list active internet sessions, user data, data lanes, and current iptables rules:
./cybercafe.sh list sessions
./cybercafe.sh list users
./cybercafe.sh list lanes
./cybercafe.sh list rulesTo safely shut down the daemon and clean up the iptables routing rules:
./cybercafe.sh shutdownIn an emergency, use ./cybercafe.sh kill to force stop all scripts and flush the infrastructure (this abandons active sessions and cleans up all related rules).
Errors caught by the daemon are logged to ./Backend/error.log. You can view the latest entries easily with:
./cybercafe.sh errorlogIf you run ./cybercafe.sh without arguments, it opens an interactive prompt where you can run the commands (run, status, list <info>, shutdown, help) repeatedly without prefixing commands.