### Install Freeradius Packages Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius-Rest Install the required Freeradius and REST module packages. ```bash apt-get -y install freeradius freeradius-rest ``` -------------------------------- ### Install Smarty via Composer Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/vendor/smarty/smarty/README.md Use this command to install the latest stable version of Smarty in your project. ```bash composer require smarty/smarty ``` -------------------------------- ### Install FreeRADIUS on Ubuntu Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Use the apt package manager to install FreeRADIUS and its necessary MySQL and utility components on Ubuntu systems. ```bash apt-get install freeradius freeradius-mysql freeradius-utils ``` -------------------------------- ### Install Composer on Linux Source: https://github.com/hotspotbilling/phpnuxbill/wiki/Home Commands to install the Composer package manager on Debian/Ubuntu or CentOS/Redhat systems. ```bash # Debian/Ubuntu sudo apt install composer # Centos/Redhat sudo yum install composer ``` -------------------------------- ### PPPoE User Management Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt PHP examples for managing Mikrotik PPPoE secrets and profiles for broadband services. ```PHP 'PPPOE_Plan', 'type' => 'PPPOE' ]; $customer = [ 'username' => 'pppoe_user', 'password' => 'secret123', 'pppoe_password' => 'pppoe_secret', // Optional separate PPPoE password 'fullname' => 'John Doe', 'email' => 'john@example.com' ]; Mikrotik::addPpoeUser($client, $plan, $customer); // Update PPPoE user password Mikrotik::setPpoeUser($client, 'pppoe_user', 'new_password'); // Change user's PPPoE profile/plan Mikrotik::setPpoeUserPlan($client, 'pppoe_user', 'New_Plan'); // Remove PPPoE user Mikrotik::removePpoeUser($client, 'pppoe_user'); // Disconnect active PPPoE session Mikrotik::removePpoeActive($client, 'pppoe_user'); ?> ``` -------------------------------- ### Install FreeRADIUS on RedHat Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Use the yum package manager to install FreeRADIUS and its necessary MySQL, utility, and Perl components on RedHat systems. ```bash yum install freeradius freeradius-utils freeradius-mysql freeradius-perl ``` -------------------------------- ### Run PHPNuxBill in Docker Source: https://github.com/hotspotbilling/phpnuxbill/wiki/Home Command to start a PHPNuxBill container using the official PHP Apache image. ```bash docker run -d -p 8880:80 --name PHPNuxBill -v "$PWD":/var/www/html php:8.2-apache ``` -------------------------------- ### Setup Cron Jobs in Docker Source: https://github.com/hotspotbilling/phpnuxbill/wiki/Home Command to register cron jobs for system maintenance and reminders within the container. ```bash cat < 'Daily_Plan', 'typebp' => 'Limited', 'limit_type' => 'Time_Limit', 'time_limit' => 24, 'time_unit' => 'Hrs' ]; $customer = [ 'username' => 'user123', 'password' => 'secret', 'fullname' => 'John Doe', 'email' => 'john@example.com' ]; Mikrotik::addHotspotUser($client, $plan, $customer); // Add Hotspot user with data-limited plan $plan = [ 'name_plan' => 'Data_Plan', 'typebp' => 'Limited', 'limit_type' => 'Data_Limit', 'data_limit' => 5, 'data_unit' => 'GB' ]; Mikrotik::addHotspotUser($client, $plan, $customer); // Remove Hotspot user Mikrotik::removeHotspotUser($client, 'username'); // Remove active Hotspot session Mikrotik::removeHotspotActiveUser($client, 'username'); ?> ``` -------------------------------- ### Configure Docker Container Extensions Source: https://github.com/hotspotbilling/phpnuxbill/wiki/Home Commands to install and configure necessary PHP extensions and system utilities within the running PHPNuxBill container. ```bash docker exec PHPNuxBill apt-get update docker exec PHPNuxBill apt-get install -y --fix-missing apt-utils gnupg cron docker exec PHPNuxBill echo "deb http://httpredir.debian.org/debian bookworm all" >> /etc/apt/sources.list docker exec PHPNuxBill echo "deb-src http://httpredir.debian.org/debian bookworm all" >> /etc/apt/sources.list docker exec PHPNuxBill apt-get update docker exec PHPNuxBill apt-get install -y zlib1g-dev libzip-dev \ libpng-dev libjpeg-dev libgif-dev libwebp-dev \ libfreetype6-dev libjpeg62-turbo-dev libxpm-dev docker exec PHPNuxBill docker-php-ext-configure gd --enable-gd \ --with-webp --with-jpeg \ --with-xpm --with-freetype docker exec PHPNuxBill docker-php-ext-install json docker exec PHPNuxBill docker-php-ext-install gd docker exec PHPNuxBill docker-php-ext-install curl docker exec PHPNuxBill docker-php-ext-install xml docker exec PHPNuxBill docker-php-ext-install mbstring docker exec PHPNuxBill docker-php-ext-install pdo docker exec PHPNuxBill docker-php-ext-install pdo_mysql docker exec PHPNuxBill docker-php-ext-install zip docker exec PHPNuxBill service apache2 reload ``` -------------------------------- ### Enable SQL Counter Module Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Creates a symbolic link to enable the 'sqlcounter' module in FreeRADIUS. This command should be run on the server where FreeRADIUS is installed. ```bash ln -s mods-available/sqlcounter mods-enabled/sqlcounter ``` -------------------------------- ### Install PSR-3 Logger Interface Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/vendor/psr/log/README.md Use Composer to add the PSR-3 logger interface package to your project dependencies. ```bash composer require psr/log ``` -------------------------------- ### Require PSR Log Aware Trait Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/vendor/mpdf/psr-log-aware-trait/README.md Use this composer command to install the trait. This makes the PsrLogAwareTrait available for use in your project. ```bash composer require chromatic/psr-log-aware-trait ``` -------------------------------- ### Prepend to Body Stream Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/vendor/psr/http-message/docs/PSR7-Usage.md Prepend data by seeking to the start of the stream and overwriting existing content. ```php // assuming our response is initially empty $body = $repsonse->getBody(); // writing the string "abcd" $body->write('abcd'); // seeking to start of stream $body->seek(0); // writing 'ef' $body->write('ef'); // at this point the stream contains "efcd" ``` -------------------------------- ### Mikrotik Class - Router Connection Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Examples for connecting to Mikrotik routers using the RouterOS API and performing basic user status checks. ```PHP ``` -------------------------------- ### Define a PHP Widget Class Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/widgets/template.md This snippet shows a basic PHP class structure for a widget. It includes a static method to get widget data and fetch a template. ```php class widget_name { public static getWidget($data) { global $config, $ui; return $ui->fetch('widget/template'); } } ``` -------------------------------- ### Configure sites-available/default Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Update the authorize, accounting, post-auth, and session sections to use the SQL module instead of default files. ```text authorize { ..... sql expiration quotalimit accessperiod uptimelimit if (User-Name){ if("%{sql:UPDATE radacct set AcctStopTime=ADDDATE(AcctStartTime,INTERVAL AcctSessionTime SECOND), AcctTerminateCause='Clear-Stale Session' WHERE UserName='%{User-Name}' and CallingStationId='%{Calling-Station-Id}' and AcctStopTime is NULL}"){ } } expiration{ userlock = 1 } if(userlock){ # Let him connect with EXPIRED pool in reply ok update reply { Reply-Message := "Your account has expired, %{User-Name} / Reason: DATE LIMIT REACHED" Framed-Pool := "Expired" } } ..... } accounting { ...... sql .... } post-auth { ...... sql .... } session{ ...... sql ..... } ``` -------------------------------- ### Create PHPNuxBill Project via Composer Source: https://github.com/hotspotbilling/phpnuxbill/wiki/Home Commands to initialize a new PHPNuxBill project in the current or a new directory. ```bash composer create-project hotspotbilling/phpnuxbill . ``` ```bash composer create-project hotspotbilling/phpnuxbill phpnuxbill ``` -------------------------------- ### Manage Customer Custom Attributes Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Use these methods to set, retrieve, and manage custom attributes for customers. The format for installments is 'amount:remaining_payments'. Bills can be marked as paid to decrement the installment counter. ```php '50000:12', 'Router Bill' => '25000'] // Mark bills as paid (decrements installment counter) $bills = ['Equipment Bill' => 50000, 'Router Bill' => 25000]; User::billsPaid($bills, $customer_id); // Get bill names for display $billNames = User::getBillNames($customer_id); // Returns: ['Equipment', 'Router'] ``` -------------------------------- ### Configure mods-available/sql Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Define the database connection parameters and table mappings for the SQL module. ```text sql { driver = "rlm_sql_mysql" dialect = "mysql" # Connection info: server = "localhost" port = 3306 login = "phpnuxbill" password = "phpnuxbill" # Database table configuration for everything except Oracle radius_db = "phpnuxbill" } read_clients = yes client_table = "nas" ``` -------------------------------- ### Configure SQL Counter for Quota Limit Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Sets up a SQL counter instance for 'Max-Volume' to monitor data usage. It specifies the SQL module, dialect, and uses 'User-Name' as the key, with no reset. The 'Mikrotik-Total-Limit' is used for reply attributes. ```freeradius sqlcounter quotalimit { sql_module_instance = sql dialect = ${modules.sql.dialect} counter_name = Max-Volume check_name = Max-Data reply_name = Mikrotik-Total-Limit key = User-Name reset = never $INCLUDE ${modconfdir}/sql/counter/${dialect}/${.:instance}.conf } ``` -------------------------------- ### Enable SQL module in FreeRADIUS Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Create a symbolic link to enable the SQL module for different Linux distributions. ```bash ln -s /etc/raddb/mods-available/sql /etc/raddb/mods-enabled/ ``` ```bash ln -s /etc/freeradius/3.0/mods-available/sql /etc/freeradius/3.0/mods-enabled/ ``` -------------------------------- ### Connect to Mikrotik router and manage users Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt This PHP code demonstrates connecting to a Mikrotik router using its API and performing basic user management tasks for Hotspot and PPPoE. ```php = $plan['price']) { $invoice = Package::rechargeUser($customer['id'], $router, $plan_id, 'Balance', 'Auto-renewal'); if ($invoice) { Balance::min($customer['id'], $plan['price']); echo "Recharged successfully. Invoice: $invoice"; } } // Example: Recharge via voucher $voucher = ORM::for_table('tbl_voucher') ->where('code', $voucher_code) ->where('status', 0) ->find_one(); if ($voucher) { $invoice = Package::rechargeUser( $customer_id, $voucher['routers'], $voucher['id_plan'], 'Voucher', $voucher_code ); if ($invoice) { $voucher->status = 1; $voucher->user = $customer['username']; $voucher->used_date = date('Y-m-d H:i:s'); $voucher->save(); } } ?> ``` -------------------------------- ### Configure SQL Counter for Uptime Limit Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Configures a SQL counter for 'Max-All-Session-Time' to track total user session time. It queries the 'radacct' table for the sum of 'AcctSessionTime' for a given 'User-Name'. ```freeradius sqlcounter uptimelimit { counter_name = 'Max-All-Session-Time' check_name = 'Max-All-Session' sql_module_instance = sql key = 'User-Name' reset = never query = "SELECT SUM(AcctSessionTime) FROM radacct WHERE UserName='%{${key}}'" } ``` -------------------------------- ### Get Xendit Payment Status Source: https://github.com/hotspotbilling/phpnuxbill/wiki/Payment-Gateway-Plugin Retrieves the payment status for a given transaction from Xendit. This function is executed when the user checks the payment status or is redirected from the payment gateway. ```php // required, this will executed when customer click check payment, or redirect from function xendit_get_status($trx, $user) { global $config; /** Check status of payment when user request it, this can be run on User page or admin page ``` -------------------------------- ### Device Integration Template Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/devices/readme.md Use this class structure to define device-specific logic for customer and plan management. Ensure all methods are implemented to support full device functionality. ```php 'Device', 'description' => '', 'author' => 'ibnu maksum', 'url' => [ 'Github' => 'https://github.com/hotspotbilling/phpnuxbill/', 'Telegram' => 'https://t.me/ibnux', 'Donate' => 'https://paypal.me/ibnux', 'any text' => 'Any Url' ] ]; } // Add Customer to Mikrotik/Device function add_customer($customer, $plan) { } // Remove Customer to Mikrotik/Device function remove_customer($customer, $plan) { } // customer change username public function change_username($plan, $from, $to) { } // Add Plan to Mikrotik/Device function add_plan($plan) { } // Update Plan to Mikrotik/Device function update_plan($old_name, $plan) { } // Remove Plan from Mikrotik/Device function remove_plan($plan) { } // check if customer is online function online_customer($customer, $router_name) { } // make customer online function connect_customer($customer, $ip, $mac_address, $router_name) { } // make customer disconnect function disconnect_customer($customer, $router_name) { } } ``` -------------------------------- ### MySQL Query for Access Period Counter Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Provides the SQL query for the 'accessperiod' counter in MySQL. It calculates the time elapsed since the user's last session start. ```sql query = "\nSELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(AcctStartTime) \nFROM radacct \nWHERE UserName='%{${key}}' \nORDER BY AcctStartTime LIMIT 1" ``` -------------------------------- ### Authenticate Admin via REST API Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Obtain a session token by sending admin credentials to the system API. ```bash # Login and get authentication token curl -X POST "https://your-domain.com/system/api.php?r=admin/post" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=admin&password=admin" # Response { "success": true, "message": "", "result": { "token": "session_token_here" }, "meta": [] } ``` -------------------------------- ### Manage Mikrotik IP Pools and Firewall Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Use these functions to create, update, and remove IP pools. Also includes adding/removing IPs from firewall address lists and sending SMS via Mikrotik. ```php ``` -------------------------------- ### MyPayment Gateway Implementation Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt This snippet provides the core functions required to implement a custom payment gateway named 'MyPayment'. It covers validation, configuration display and saving, transaction creation, status checking, and handling payment notifications. ```APIDOC ## MyPayment Gateway Implementation ### Description This section outlines the PHP functions required to integrate a custom payment gateway. It includes functions for validating configuration, displaying and saving settings in the admin panel, creating payment transactions, checking payment status, and handling payment notifications via webhooks. ### Functions #### `mypayment_validate_config()` * **Description**: Validates if the necessary configuration for the MyPayment gateway is set up. * **Usage**: Called to ensure API keys or other required settings are present before proceeding with payment operations. #### `mypayment_show_config()` * **Description**: Displays the administrative interface for configuring the MyPayment gateway. * **Usage**: Renders the template file (`mypayment.tpl`) for users to input their gateway credentials. #### `mypayment_save_config()` * **Description**: Saves the configuration settings for the MyPayment gateway, typically an API key. * **Usage**: Processes POST data from the configuration form and updates the `tbl_appconfig` table. #### `mypayment_create_transaction($trx, $user)` * **Description**: Initiates a payment transaction by calling the MyPayment API. * **Parameters**: * `$trx` (array) - Transaction details. * `$user` (array) - User details. * **Usage**: Sends transaction information to the MyPayment API, receives a payment URL and transaction ID, and saves these to the database. #### `mypayment_get_status($trx, $user)` * **Description**: Checks the status of an existing payment transaction with the MyPayment gateway. * **Parameters**: * `$trx` (array) - Transaction details, including `gateway_trx_id`. * `$user` (array) - User details. * **Usage**: Queries the MyPayment API for the transaction status and updates the local transaction record accordingly (e.g., Paid, Expired). #### `mypayment_payment_notification()` * **Description**: Handles incoming payment notifications (webhooks) from the MyPayment gateway. * **Usage**: Listens for POST requests on the callback URL, verifies the transaction, and updates the order status upon successful payment confirmation. ``` -------------------------------- ### Implement Custom Payment Gateway in PHP Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt This file defines the necessary functions for a custom payment gateway. Ensure all required functions are implemented for validation, configuration display, saving, transaction creation, and status checking. An optional notification handler can be added for webhook support. ```php assign('_title', 'MyPayment - Payment Gateway'); $ui->display('mypayment.tpl'); // system/paymentgateway/ui/mypayment.tpl } // Required: Save admin configuration function mypayment_save_config() { global $admin; $api_key = _post('mypayment_api_key'); $d = ORM::for_table('tbl_appconfig') ->where('setting', 'mypayment_api_key') ->find_one(); if (!$d) { $d = ORM::for_table('tbl_appconfig')->create(); $d->setting = 'mypayment_api_key'; } $d->value = $api_key; $d->save(); r2(U . 'paymentgateway/mypayment', 's', 'Settings saved'); } // Required: Create payment transaction function mypayment_create_transaction($trx, $user) { global $config; // Call your payment API $result = Http::postJsonData('https://api.mypayment.com/create', [ 'external_id' => $trx['id'], 'amount' => $trx['price'], 'description' => $trx['plan_name'], 'callback_url' => APP_URL . '/index.php?_route=callback/mypayment' ], ['Authorization: Bearer ' . $config['mypayment_api_key']]); $response = json_decode($result, true); // Save payment URL to transaction $d = ORM::for_table('tbl_payment_gateway') ->where('id', $trx['id']) ->find_one(); $d->gateway_trx_id = $response['transaction_id']; $d->pg_url_payment = $response['payment_url']; $d->pg_request = $result; $d->save(); // Redirect to payment page header('Location: ' . $response['payment_url']); exit(); } // Required: Check payment status function mypayment_get_status($trx, $user) { global $config; $result = Http::getData( 'https://api.mypayment.com/status/' . $trx['gateway_trx_id'], ['Authorization: Bearer ' . $config['mypayment_api_key']] ); $response = json_decode($result, true); if ($response['status'] == 'PAID') { // Activate user plan if (Package::rechargeUser($user['id'], $trx['routers'], $trx['plan_id'], 'MyPayment', $response['channel'])) { $trx->status = 2; // Paid $trx->pg_paid_response = $result; $trx->paid_date = date('Y-m-d H:i:s'); $trx->save(); r2(U . "order/view/" . $trx['id'], 's', Lang::T("Payment successful")); } } elseif ($response['status'] == 'EXPIRED') { $trx->status = 3; // Expired $trx->save(); r2(U . "order/view/" . $trx['id'], 'd', Lang::T("Payment expired")); } r2(U . "order/view/" . $trx['id'], 'w', Lang::T("Payment pending")); } // Optional: Handle payment webhook/callback function mypayment_payment_notification() { $data = json_decode(file_get_contents('php://input'), true); $trx = ORM::for_table('tbl_payment_gateway') ->where('gateway_trx_id', $data['transaction_id']) ->find_one(); if ($trx && $data['status'] == 'PAID') { $user = User::_info($trx['user_id']); Package::rechargeUser($user['id'], $trx['routers'], $trx['plan_id'], 'MyPayment', $data['channel']); $trx->status = 2; $trx->paid_date = date('Y-m-d H:i:s'); $trx->save(); echo "OK"; } } ``` -------------------------------- ### Configure REST Module Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius-Rest Define the REST module configuration to point to the PHPNuxBill domain. Replace phpnuxbill.domain with your actual domain. ```bash nano /etc/freeradius/3.0/mods-enabled/rest ``` ```bash rest { tls { # ca_file = ${certdir}/ca.pem # ca_info_file = ${certdir}/cacert_bundle.pem # ca_path = ${certdir} check_cert = no check_cert_cn = no } connect_uri = "https://phpnuxbill.domain/radius.php" authenticate { uri = "${..connect_uri}?action=authenticate" method = 'post' body = 'post' data = "username=%{urlquote:%{User-Name}}&password=%{urlquote:%{User-Password}}&nasid=%{urlquote:%{NAS-Identifier}}&CHAPchallenge=%{urlquote:%{CHAP-Challenge}}&CHAPassword=%{urlquote:%{CHAP-Password}}&realm=%{urlquote:%{Mikrotik-Realm}}&macAddr=%{urlquote:%{Calling-Station-Id}}&nasip=%{urlquote:%{NAS-IP-Address}}" tls = ${..tls} } authorize { uri = "${..connect_uri}?action=authorize" method = 'post' body = 'post' data = "username=%{urlquote:%{User-Name}}&password=%{urlquote:%{User-Password}}&nasid=%{urlquote:%{NAS-Identifier}}&CHAPchallenge=%{urlquote:%{CHAP-Challenge}}&CHAPassword=%{urlquote:%{CHAP-Password}}&realm=%{urlquote:%{Mikrotik-Realm}}&macAddr=%{urlquote:%{Calling-Station-Id}}&nasip=%{urlquote:%{NAS-IP-Address}}" tls = ${..tls} } accounting { uri = "${..connect_uri}?action=accounting" method = 'post' body = 'post' data = "username=%{urlquote:%{User-Name}}&nasIpAddress=%{urlquote:%{NAS-IP-Address}}&realm=%{urlquote:%{Mikrotik-Realm}}&nasid=%{urlquote:%{NAS-Identifier}}\ &acctSessionId=%{urlquote:%{Acct-Session-Id}}&macAddr=%{urlquote:%{Calling-Station-Id}}&acctSessionTime=%{urlquote:%{Acct-Session-Time}}\ &acctInputOctets=%{urlquote:%{Acct-Input-Octets}}&acctOutputOctets=%{urlquote:%{Acct-Output-Octets}}\ &acctInputGigawords=%{urlquote:%{Acct-Input-Gigawords}}&acctOutputGigawords=%{urlquote:%{Acct-Output-Gigawords}}\ &acctInputPackets=%{urlquote:%{Acct-Input-Packets}}&acctOutputPackets=%{urlquote:%{Acct-Output-Packets}}\ &nasPortId=%{urlquote:%{NAS-Port-Id}}&framedIPAddress=%{urlquote:%{Framed-IP-Address}}\ &sessionTimeout=%{urlquote:%{Session-Timeout}}&framedIPNetmask=%{urlquote:%{Framed-IP-Netmask}}\ &acctStatusType=%{urlquote:%{Acct-Status-Type}}&nasPortType=%{urlquote:%{NAS-Port-Type}}" tls = ${..tls} } post-auth { uri = "${..connect_uri}?action=post-auth" method = 'post' body = 'post' data = "username=%{urlquote:%{User-Name}}" tls = ${..tls} } pool { start = ${thread[pool].start_servers} min = ${thread[pool].min_spare_servers} max = ${thread[pool].max_servers} spare = ${thread[pool].max_spare_servers} uses = 0 retry_delay = 30 lifetime = 0 idle_timeout = 60 } } ``` -------------------------------- ### Enable SQL Counters in Authorization Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Integrates the 'quotalimit' and 'accessperiod' SQL counters into the authorization process within the 'default' site configuration. ```freeradius authorize { expiration quotalimit accessperiod } ``` -------------------------------- ### Cron Job Logic Overview Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Reference for the automated processes handled by the cron.php script. ```php timestamp, 'token' => 'uid.time.hash']`). - `User::generateToken`: An array containing the token timestamp and the secure token string (`['time' => timestamp, 'token' => 'secure_token_string']`). ### Request Example (PHP) ```php // Get current user ID $user_id = User::getID(); // Get user information by username $user = User::_infoByName('john_doe'); // Set session cookie $token_data = User::setCookie($user_id); // Generate a token for a payment link (valid for 1 day) $payment_token = User::generateToken($user_id, 1); ``` ``` -------------------------------- ### Core User Class Methods Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Essential methods for managing customer accounts, including retrieving user information, session management, and generating secure tokens. ```php timestamp, 'token' => 'uid.time.hash'] // Remove user session cookie User::removeCookie(); // Generate secure token for payment links $token = User::generateToken($user_id, 1); // Valid for 1 day // Returns: ['time' => timestamp, 'token' => 'secure_token_string'] ?> ``` -------------------------------- ### Prepend by Using Contents as String Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/vendor/psr/http-message/docs/PSR7-Usage.md Prepends content by reading the entire stream into a string, modifying the string, and then writing it back to the stream. Remember to rewind the stream before reading and writing. ```php $body = $response->getBody(); $body->rewind(); $contents = $body->getContents(); // efabcd $contents = 'ef'.$contents; $body->rewind(); $body->write($contents); ``` -------------------------------- ### Configure TLS encryption for MySQL Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius Uncomment and configure the TLS section in the SQL module to resolve SSL certificate errors. ```text mysql { # If any of the files below are set, TLS encryption is enabled tls { #ca_file = "/etc/ssl/certs/my_ca.crt" #ca_path = "/etc/ssl/certs/" #certificate_file = "/etc/ssl/certs/private/client.crt" #private_key_file = "/etc/ssl/certs/private/client.key" #cipher = "...." #tls_required = yes #tls_check_cert = no #tls_check_cert_cn = no } # If yes, (or auto and libmysqlclient reports warnings are # available), will retrieve and log additional warnings from # the server if an error has occured. Defaults to 'auto'warnings = auto } ``` -------------------------------- ### Prepend by Rewriting Stream Source: https://github.com/hotspotbilling/phpnuxbill/blob/master/system/vendor/psr/http-message/docs/PSR7-Usage.md Rewrites the stream by writing new content before the original content. Ensure to rewind the stream before reading and writing. ```php // assuming our response body stream only contains: "abcd" $body = $response->getBody(); $body->rewind(); $contents = $body->getContents(); // abcd // seeking the stream to beginning $body->rewind(); $body->write('ef'); // stream contains "efcd" $body->write($contents); // stream contains "efabcd" ``` -------------------------------- ### Configure Freeradius Clients Source: https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius-Rest Edit the clients configuration file to define authorized network clients. Restart the service after making changes. ```bash nano /etc/freeradius/3.0/clients.conf ``` ```bash client myRouterA { ipaddr = 10.0.1.0/24 secret = verysecret } client myRouterB { ipaddr = 10.0.2.0/24 secret = secretvery } ``` -------------------------------- ### Manage Customers via REST API Source: https://context7.com/hotspotbilling/phpnuxbill/llms.txt Perform CRUD operations on customer accounts using the system API. ```bash # List all customers with filtering and pagination curl -X GET "https://your-domain.com/system/api.php?r=customers&token=YOUR_TOKEN&search=john&order=username&filter=Active&orderby=asc&p=1" # Response { "success": true, "result": [ { "id": 1, "username": "john_doe", "fullname": "John Doe", "email": "john@example.com", "phonenumber": "+628123456789", "balance": 50000, "service_type": "Hotspot", "status": "Active" } ], "meta": { "statuses": ["Active", "Banned", "Disabled"] } } # Add new customer curl -X POST "https://your-domain.com/system/api.php?r=customers/add-post&token=YOUR_TOKEN" \ -H "Content-Type: multipart/form-data" \ -F "username=new_customer" \ -F "fullname=New Customer" \ -F "email=customer@example.com" \ -F "phonenumber=+628123456789" \ -F "password=secret123" \ -F "address=123 Main Street" \ -F "service_type=Hotspot" \ -F "account_type=Personal" \ -F "coordinates=-6.465422,3.406448" \ -F "city=Bandung" \ -F "district=Cimahi" \ -F "state=Jawa Barat" \ -F "zip=40534" # Edit customer curl -X POST "https://your-domain.com/system/api.php?r=customers/edit-post&token=YOUR_TOKEN" \ -F "id=1" \ -F "username=updated_customer" \ -F "fullname=Updated Name" \ -F "status=Active" # View customer details with activation history curl -X GET "https://your-domain.com/system/api.php?r=customers/view/1/activation&token=YOUR_TOKEN&p=1" # View customer orders curl -X GET "https://your-domain.com/system/api.php?r=customers/view/1/order&token=YOUR_TOKEN&p=1" # Delete customer curl -X GET "https://your-domain.com/system/api.php?r=customers/delete/1&token=YOUR_TOKEN" ```