### Format Bytes and Bandwidth Utility Functions (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Provides utility functions to format byte sizes and bandwidth rates into human-readable units. It includes functions for binary (KiB, MiB) and decimal (KB, MB) byte formatting, as well as for bits per second (bps, Mbps).
```php
= 1024 && $i <= count($unit); $i++) {
$size = $size / 1024;
}
return round($size, $decimals) . ' ' . $unit[$i];
}
// Format bytes using decimal units (1000-based: KB, MB, GB)
function formatBytes2($size, $decimals = 0) {
$unit = array('Byte', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
for ($i = 0; $size >= 1000 && $i <= count($unit); $i++) {
$size = $size / 1000;
}
return round($size, $decimals) . '' . $unit[$i];
}
// Format bandwidth rates (bps, kbps, Mbps, Gbps)
function formatBites($size, $decimals = 0) {
$unit = array('bps', 'kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps', 'Zbps', 'Ybps');
for ($i = 0; $size >= 1000 && $i <= count($unit); $i++) {
$size = $size / 1000;
}
return round($size, $decimals) . ' ' . $unit[$i];
}
// Usage examples
echo formatBytes(1073741824); // Output: 1 GiB
echo formatBytes2(1000000000); // Output: 1 GB
echo formatBites(2500000); // Output: 2.5 Mbps
// Practical usage in monitoring
$bytesIn = 5368709120; // 5GB downloaded
$bytesOut = 2147483648; // 2GB uploaded
$bandwidth = 10485760; // 10 Mbps
echo "Downloaded: " . formatBytes($bytesIn); // 5 GiB
echo "Uploaded: " . formatBytes($bytesOut); // 2 GiB
echo "Speed: " . formatBites($bandwidth); // 10 Mbps
?>
```
--------------------------------
### Create User Profile with Expiry Management (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Defines and creates a user profile for MikroTik Hotspot, including parameters for pricing, validity, bandwidth limits, and automatic expiry handling. It also sets up a scheduler to monitor and remove expired users based on the expiry mode.
```php
comm("/ip/hotspot/user/profile/add", array(
"name" => $profileName,
"shared-users" => $sharedUsers,
"rate-limit" => $rateLimit,
"on-login" => $onLoginScript,
"keepalive-timeout" => "5m"
));
// Create scheduler to monitor expired users (for modes with 'rem' or 'ntf')
if (strpos($expiryMode, 'rem') !== false || strpos($expiryMode, 'ntf') !== false) {
$API->comm("/system/scheduler/add", array(
"name" => "monitor-" . $profileName,
"interval" => "5m",
"start-time" => "startup",
"policy" => "read,write,policy,test",
"on-event" => ":local profile \"" . $profileName . "\"; /ip hotspot user { :foreach i in=[find profile=\"$profile\"] do={ :local cmt [get $i comment]; :if ([:len $cmt] > 0 && $cmt ~ \"^[a-z]{3}/[0-9]{2}/[0-9]{4}\") do={ :local expdate [:pick $cmt 0 [:find $cmt \" \"]]; :local now [/system clock get date]; :if ($expdate < $now) do={ remove $i; }}}}"
));
}
echo "Profile created: " . $profileName;
?>
```
--------------------------------
### Generate and Print Voucher with QR Code (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
This PHP script generates a printable voucher with user credentials (username, password) and a QR code. It connects to the RouterOS API to retrieve user and profile information, uses an external QR code API for generation, and outputs an HTML page formatted for printing. Dependencies include the RouterOS API class and PHP QR Code library.
```php
connect($iphost, $userhost, decrypt($passwdhost));
// Get user details
$getuser = $API->comm('/ip/hotspot/user/print', array(
"?comment" => $userId
));
$username = $getuser[0]['name'];
$password = $getuser[0]['password'];
$profile = $getuser[0]['profile'];
$timelimit = $getuser[0]['limit-uptime'];
$datalimit = $getuser[0]['limit-bytes-total'];
// Get profile pricing
$getprofile = $API->comm("/ip/hotspot/user/profile/print", array(
"?name" => $profile
));
$onlogin = $getprofile[0]['on-login'];
$validity = explode(",", $onlogin)[3];
$price = explode(",", $onlogin)[4]; // Selling price
// Format data
$hotspotname = $hotspotname; // From config
$dnsname = $dnsname; // From config
$logo = "../img/logo-" . $session . ".png";
// Generate QR code (using PHP QR Code library)
$qrData = "username:" . $username . "|password:" . $password;
$qrcode = '
';
// Voucher template
?>
Voucher - = $username ?>
= $hotspotname ?>
= $qrcode ?>
Username: = $username ?>
Password: = $password ?>
Profile: = $profile ?>
Validity: = $validity ?>
Time Limit: = gmdate("H:i:s", $timelimit) ?>
Data Limit: = formatBytes($datalimit) ?>
Price: = $currency ?> = number_format($price, 2) ?>
Login: = $dnsname ?>
disconnect();
?>
```
--------------------------------
### Query Hotspot Users with Filters (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Retrieves and filters MikroTik Hotspot users based on various criteria such as profile name, comment prefix, or a search term. It demonstrates how to fetch all users, specific users by profile or comment, and perform wildcard searches for usernames. The script also shows how to display detailed information for each user.
```php
comm("/ip/hotspot/user/print");
echo "Total users: " . count($allUsers);
// Filter users by profile
$profileUsers = $API->comm("/ip/hotspot/user/print", array(
"?profile" => "prepaid-daily"
));
echo "Users with prepaid-daily profile: " . count($profileUsers);
// Filter users by comment prefix
$commentUsers = $API->comm("/ip/hotspot/user/print", array(
"?comment" => "vc-CAFE"
));
// Search user by name (wildcard search)
$API->write("/ip/hotspot/user/print", false);
$API->write("?name", false);
$API->write("=*user001*");
$searchResults = $API->read();
// Get specific user by ID
$specificUser = $API->comm("/ip/hotspot/user/print", array(
"?.id" => "*1A"
));
// Display user details
foreach ($allUsers as $user) {
echo "Name: " . $user['name'] . "\n";
echo "Password: " . $user['password'] . "\n";
echo "Profile: " . $user['profile'] . "\n";
echo "Uptime: " . $user['uptime'] . "\n";
echo "Bytes In: " . $user['bytes-in'] . "\n";
echo "Bytes Out: " . $user['bytes-out'] . "\n";
echo "Comment: " . $user['comment'] . "\n";
echo "Disabled: " . $user['disabled'] . "\n\n";
}
?>
```
--------------------------------
### PHP Router Configuration Structure and Parsing
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Defines the structure for storing router credentials and settings in a PHP array and demonstrates how to parse this configuration to extract individual parameters like IP address, username, and password. It also shows how to decrypt the password before API connection.
```php
'mikhmon<||>ENCRYPTED_PASSWORD'
);
// Router configuration (session name: router1)
$data['router1'] = array(
1 => 'router1!192.168.88.1', // Session name!IP address
2 => 'username@|@admin', // Username
3 => 'password#|#ENCRYPTED_PASSWORD', // Encrypted password
4 => 'hotspotname%MyHotspot', // Hotspot name
5 => 'dnsname^10.10.10.1', // DNS/Login page address
6 => 'currency&USD', // Currency symbol
7 => 'areload*5', // Auto-reload interval (seconds)
8 => 'interface(1', // Interface number
9 => 'infolp)enabled', // Info login page
10 => 'idleto=300+router1', // Idle timeout+session name
11 => 'livereport@!@yes' // Enable live report
);
// File: include/readcfg.php - Parse configuration
include('config.php');
$session = $_GET['session']; // e.g., 'router1'
$iphost = explode('!', $data[$session][1])[1]; // 192.168.88.1
$userhost = explode('@|@', $data[$session][2])[1]; // admin
$passwdhost = explode('#|#', $data[$session][3])[1]; // ENCRYPTED_PASSWORD
$hotspotname = explode('%', $data[$session][4])[1]; // MyHotspot
$dnsname = explode('^', $data[$session][5])[1]; // 10.10.10.1
$currency = explode('&', $data[$session][6])[1]; // USD
$areload = explode('*', $data[$session][7])[1]; // 5
$iface = explode('(', $data[$session][8])[1]; // 1
$infolp = explode(')', $data[$session][9])[1]; // enabled
$idleto = explode('=', $data[$session][10])[1]; // 300+router1
$livereport = explode('@!@', $data[$session][11])[1]; // yes
// Decrypt password before use
$decryptedPassword = decrypt($passwdhost);
// Usage in API connection
$API = new RouterosAPI();
$API->connect($iphost, $userhost, $decryptedPassword);
?>
```
--------------------------------
### Connect to MikroTik Router using PHP API
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Establishes a connection to a MikroTik router using the RouterOS API. This code requires the `routeros_api.class.php` library. It takes router IP, username, and password as input and outputs connection status and basic system information if successful. It also includes error handling for failed connections.
```php
debug = false; // Set to true for debugging
$API->port = 8728; // Default API port (8729 for SSL)
$API->ssl = false; // Set true for SSL connection
$API->timeout = 3; // Connection timeout in seconds
// Connect to router
$connected = $API->connect('192.168.88.1', 'admin', 'password123');
if ($connected) {
echo "Connected successfully";
// Execute commands after connection
$systemInfo = $API->comm("/system/resource/print");
echo "Board: " . $systemInfo[0]['board-name'];
echo "Version: " . $systemInfo[0]['version'];
// Always disconnect when done
$API->disconnect();
} else {
echo "Connection failed: " . $API->error_str;
}
?>
```
--------------------------------
### Monitor MikroTik System Resources and Dashboard Data (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Retrieves and displays various system resources of a MikroTik router, including board information, OS version, CPU usage, memory and disk space, uptime, current date and time, and network interface statistics. It also fetches recent logs and counts active and total hotspot users. This script requires access to the MikroTik API.
```php
comm("/system/resource/print");
echo "Board: " . $sysResource[0]['board-name'] . "\n";
echo "Architecture: " . $sysResource[0]['architecture-name'] . "\n";
echo "RouterOS Version: " . $sysResource[0]['version'] . "\n";
echo "CPU: " . $sysResource[0]['cpu'] . "\n";
echo "CPU Count: " . $sysResource[0]['cpu-count'] . "\n";
echo "CPU Frequency: " . $sysResource[0]['cpu-frequency'] . " MHz\n";
echo "CPU Load: " . $sysResource[0]['cpu-load'] . "%\n";
echo "Uptime: " . $sysResource[0]['uptime'] . "\n";
echo "Free Memory: " . formatBytes($sysResource[0]['free-memory']) . "\n";
echo "Total Memory: " . formatBytes($sysResource[0]['total-memory']) . "\n";
echo "Free HDD: " . formatBytes($sysResource[0]['free-hdd-space']) . "\n";
echo "Total HDD: " . formatBytes($sysResource[0]['total-hdd-space']) . "\n";
// Get system clock and timezone
$sysClock = $API->comm("/system/clock/print");
echo "Date/Time: " . $sysClock[0]['date'] . " " . $sysClock[0]['time'] . "\n";
echo "Timezone: " . $sysClock[0]['time-zone-name'] . "\n";
// Get interface traffic statistics
$interfaces = $API->comm("/interface/print");
foreach ($interfaces as $iface) {
echo "\nInterface: " . $iface['name'] . "\n";
echo "Type: " . $iface['type'] . "\n";
echo "RX: " . formatBytes($iface['rx-byte']) . "\n";
echo "TX: " . formatBytes($iface['tx-byte']) . "\n";
echo "RX Rate: " . formatBites($iface['rx-bits-per-second']) . "\n";
echo "TX Rate: " . formatBites($iface['tx-bits-per-second']) . "\n";
}
// Get recent logs
$logs = $API->comm("/log/print", array(
"?topics" => "info,warning,error"
));
echo "\nRecent Logs:\n";
foreach (array_slice($logs, -10) as $log) {
echo "[" . $log['time'] . "] " . $log['topics'] . ": " . $log['message'] . "\n";
}
// Count active hotspot users
$activeUsers = $API->comm("/ip/hotspot/active/print");
echo "\nActive Hotspot Users: " . count($activeUsers) . "\n";
// Count total hotspot users
$totalUsers = $API->comm("/ip/hotspot/user/print");
echo "Total Hotspot Users: " . count($totalUsers) . "\n";
?>
```
--------------------------------
### Retrieve Profile Pricing and Validity via AJAX (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Fetches profile settings including price, validity, and lock status from a RouterOS device using AJAX. It parses the 'on-login' script to extract this information. This script requires session management and includes external configuration and API library files.
```php
debug = false;
$API->connect($iphost, $userhost, decrypt($passwdhost));
// Get profile name from query string
$profileName = $_GET['name'];
if ($profileName != "") {
$getprofile = $API->comm("/ip/hotspot/user/profile/print", array(
"?name" => $profileName
));
$onLoginScript = $getprofile[0]['on-login'];
// Parse on-login script (format: mode,price,validity,selling,lock)
$validity = explode(",", $onLoginScript)[3];
$price = explode(",", $onLoginScript)[2];
$sellingPrice = explode(",", $onLoginScript)[4];
$lockUser = explode(",", $onLoginScript)[6];
// Format pricing for display
$priceDisplay = "";
$sellingPriceDisplay = "";
if ($price != 0) {
if ($currency == "Rp" || $currency == "IDR") {
$priceDisplay = "| Price: " . $currency . " " . number_format($price, 0, ",", ".");
} else {
$priceDisplay = "| Price: " . $currency . " " . number_format($price, 2);
}
}
if ($sellingPrice != 0) {
if ($currency == "Rp" || $currency == "IDR") {
$sellingPriceDisplay = "| Selling Price: " . $currency . " " . number_format($sellingPrice, 0, ",", ".");
} else {
$sellingPriceDisplay = "| Selling Price: " . $currency . " " . number_format($sellingPrice, 2);
}
}
echo 'Validity: ' . $validity . ' ' . $priceDisplay . ' ' . $sellingPriceDisplay . ' | Lock User: ' . $lockUser . '';
echo '' . $validity . '';
}
$API->disconnect();
?>
```
--------------------------------
### Create MikroTik Hotspot User with PHP API
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Adds a new hotspot user to a MikroTik router via the RouterOS API. It supports setting user profiles, time limits, and data limits. The function determines if the user is for voucher or user-password authentication based on the username and password. It returns the created user's ID, username, and profile.
```php
comm("/ip/hotspot/user/add", array(
"server" => $server,
"name" => $username,
"password" => $password,
"profile" => $profile,
"disabled" => "no",
"limit-uptime" => $timelimit,
"limit-bytes-total" => $datalimit,
"comment" => $comment
));
// Retrieve created user details
$getuser = $API->comm("/ip/hotspot/user/print", array(
"?name" => $username
));
$userId = $getuser[0]['.id'];
echo "User created with ID: " . $userId;
echo "Username: " . $getuser[0]['name'];
echo "Profile: " . $getuser[0]['profile'];
?>
```
--------------------------------
### Manage MikroTik System Scheduler Tasks (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Provides functionality to manage scheduler tasks on a MikroTik router, including listing all existing schedulers, creating new ones for specific events like daily cleanup or expired user checks, removing schedulers by name, and disabling them. This script interacts with the MikroTik API and requires appropriate permissions.
```php
comm("/system/scheduler/print");
foreach ($schedulers as $scheduler) {
echo "Name: " . $scheduler['name'] . "\n";
echo "Start Time: " . $scheduler['start-time'] . "\n";
echo "Interval: " . $scheduler['interval'] . "\n";
echo "On Event: " . $scheduler['on-event'] . "\n\n";
}
// Create scheduler for daily user cleanup at midnight
$API->comm("/system/scheduler/add", array(
"name" => "daily-cleanup",
"start-time" => "00:00:00",
"interval" => "1d",
"policy" => "read,write,policy,test",
"on-event" => "/ip hotspot user { :foreach i in=[find uptime=0s] do={ :local cmt [get $i comment]; :if ($cmt ~ \"^expired\") do={ remove $i; }}}"
));
// Create scheduler to monitor expired users every 5 minutes
$API->comm("/system/scheduler/add", array(
"name" => "check-expired-users",
"start-time" => "startup",
"interval" => "5m",
"policy" => "read,write,policy,test",
"on-event" => ":local today [/system clock get date]; /ip hotspot user { :foreach i in=[find] do={ :local cmt [get $i comment]; :if ([:len $cmt] > 0 && $cmt ~ \"^[a-z]{3}/[0-9]{2}/[0-9]{4}\") do={ :local expdate [:pick $cmt 0 [:find $cmt " "]]; :if ($expdate < $today) do={ remove $i; }}}}"
));
// Remove scheduler by name
$schedulerToRemove = $API->comm("/system/scheduler/print", array(
"?name" => "daily-cleanup"
));
if (count($schedulerToRemove) > 0) {
$API->comm("/system/scheduler/remove", array(
".id" => $schedulerToRemove[0]['.id']
));
echo "Scheduler removed";
}
// Disable scheduler temporarily
$schedulerToDisable = $API->comm("/system/scheduler/print", array(
"?name" => "check-expired-users"
));
if (count($schedulerToDisable) > 0) {
$API->comm("/system/scheduler/set", array(
".id" => $schedulerToDisable[0]['.id'],
"disabled" => "yes"
));
echo "Scheduler disabled";
}
?>
```
--------------------------------
### Batch Generate MikroTik Hotspot Users with PHP API
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Generates a specified quantity of hotspot users with randomized usernames and passwords for MikroTik routers using the RouterOS API. It allows configuration of profile, prefix, character set, name/password length, time limit, and data limit. The output includes the count of generated users and their credentials.
```php
comm("/ip/hotspot/user/add", array(
"server" => "all",
"name" => $username,
"password" => $password,
"profile" => $profile,
"disabled" => "no",
"limit-uptime" => $timelimit,
"limit-bytes-total" => $datalimit,
"comment" => "up-" . $prefix
));
$generatedUsers[] = array(
"username" => $username,
"password" => $password,
"profile" => $profile
);
}
echo "Generated " . count($generatedUsers) . " users";
// Users are now ready for printing vouchers
?>
```
--------------------------------
### PHP Function to Save Router Configuration
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Provides a PHP function `saveRouterConfig` to dynamically update the router configuration file (`config.php`). It takes router details as arguments, encrypts the password, formats the data, and writes it back to the configuration file.
```php
$sessionName . '!' . $ip,
2 => 'username@|@' . $username,
3 => 'password#|#' . $encryptedPass,
4 => 'hotspotname%' . $hotspot,
5 => 'dnsname^' . $dns,
6 => 'currency&' . $curr,
7 => 'areload*5',
8 => 'interface(1',
9 => 'infolp)enabled',
10 => 'idleto=300+' . $sessionName,
11 => 'livereport@!@yes'
);
$configContent = " $value) {
$configContent .= "$data['" . $key . "'] = " . var_export($value, true) . ";\n";
}
$configContent .= "?>";
file_put_contents('config.php', $configContent);
}
// Example: Add new router
saveRouterConfig('router2', '192.168.1.1', 'admin', 'password123', 'Cafe WiFi', '192.168.1.1', 'USD');
?>
```
--------------------------------
### Monitor Active Hotspot Sessions (PHP)
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
Lists and monitors currently connected MikroTik Hotspot users, providing details about their active sessions. The script allows filtering sessions by a specific hotspot server and displays information such as username, IP address, MAC address, uptime, remaining session time, data transfer (bytes in/out), and how the user logged in. It also includes functionality to disconnect a specific user by their ID.
```php
comm("/ip/hotspot/active/print");
echo "Active users: " . count($activeSessions);
// Filter by specific hotspot server
$serverSessions = $API->comm("/ip/hotspot/active/print", array(
"?server" => "hotspot1"
));
// Display active session information
foreach ($activeSessions as $session) {
echo "User: " . $session['user'] . "\n";
echo "Address: " . $session['address'] . "\n";
echo "MAC Address: " . $session['mac-address'] . "\n";
echo "Uptime: " . $session['uptime'] . "\n";
echo "Session Time Left: " . $session['session-time-left'] . "\n";
echo "Bytes In: " . formatBytes($session['bytes-in']) . "\n";
echo "Bytes Out: " . formatBytes($session['bytes-out']) . "\n";
echo "Login By: " . $session['login-by'] . "\n\n";
}
// Disconnect specific user
$API->comm("/ip/hotspot/active/remove", array(
".id" => "*5"
));
echo "User disconnected";
?>
```
--------------------------------
### Extract Sales Data from RouterOS Scripts - PHP
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
This PHP script extracts sales data that is logged as system scripts in RouterOS. It parses script names formatted with specific delimiters to retrieve details like date, time, username, price, and more. The script also calculates total revenue and provides filtering capabilities by date range and username prefix. It can also remove sales records by their script ID. Dependencies include the MikroTik API client.
```php
comm("/system/script/print");
$salesData = array();
$totalRevenue = 0;
foreach ($salesScripts as $script) {
$scriptName = $script['name'];
// Script name format: date-|-time-|-username-|-price-|-address-|-mac-|-validity
// Example: "mar/20/2019-|-16:05:11-|-CAFE-ABC123-|-5.00-|-192.168.1.100-|-AA:BB:CC:DD:EE:FF-|-1d"
$parts = explode("-|-", $scriptName);
if (count($parts) >= 4) {
$date = $parts[0];
$time = $parts[1];
$username = $parts[2];
$price = floatval($parts[3]);
$address = isset($parts[4]) ? $parts[4] : "";
$mac = isset($parts[5]) ? $parts[5] : "";
$validity = isset($parts[6]) ? $parts[6] : "";
$salesData[] = array(
"date" => $date,
"time" => $time,
"username" => $username,
"price" => $price,
"address" => $address,
"mac" => $mac,
"validity" => $validity,
"script_id" => $script['.id']
);
$totalRevenue += $price;
}
}
echo "Total Sales: " . count($salesData) . "\n";
echo "Total Revenue: $" . number_format($totalRevenue, 2) . "\n\n";
// Filter by date range
$startDate = "mar/01/2019";
$endDate = "mar/31/2019";
$filteredSales = array_filter($salesData, function($sale) use ($startDate, $endDate) {
$saleDate = strtotime($sale['date']);
return $saleDate >= strtotime($startDate) && $saleDate <= strtotime($endDate);
});
echo "Sales in March 2019: " . count($filteredSales);
// Filter by username prefix
$prefix = "CAFE";
$prefixSales = array_filter($salesData, function($sale) use ($prefix) {
return strpos($sale['username'], $prefix) === 0;
});
echo "Sales for prefix " . $prefix . ": " . count($prefixSales);
// Delete sales record by script ID
$scriptIdToDelete = "*10";
$API->comm("/system/script/remove", array(
".id" => $scriptIdToDelete
));
?>
```
--------------------------------
### Remove Hotspot Users by Various Criteria - PHP
Source: https://context7.com/laksa19/mikhmonv3/llms.txt
This PHP script demonstrates how to remove hotspot users from a MikroTik router using the API. It supports removing single users by ID, multiple users by comment prefix, all expired users based on a date in their comment, and users with zero uptime (indicating unused vouchers). Dependencies include the MikroTik API client.
```php
comm("/ip/hotspot/user/remove", array(
".id" => $userId
));
echo "User removed";
// Remove multiple users by comment prefix
$users = $API->comm("/ip/hotspot/user/print", array(
"?comment" => "vc-CAFE"
));
foreach ($users as $user) {
$API->comm("/ip/hotspot/user/remove", array(
".id" => $user['.id']
));
}
echo "Removed " . count($users) . " users";
// Remove all expired users (comment contains past date)
$allUsers = $API->comm("/ip/hotspot/user/print");
$currentDate = date("M/d/Y");
$removedCount = 0;
foreach ($allUsers as $user) {
$comment = $user['comment'];
// Check if comment is a date format (e.g., "mar/20/2019 16:05:11")
if (preg_match('/^[a-z]{3}\/[0-9]{2}\/[0-9]{4}/', $comment, $matches)) {
$expiryDate = $matches[0];
$expiryTimestamp = strtotime($expiryDate);
$currentTimestamp = strtotime($currentDate);
if ($expiryTimestamp < $currentTimestamp) {
$API->comm("/ip/hotspot/user/remove", array(
".id" => $user['.id']
));
$removedCount++;
}
}
}
echo "Removed " . $removedCount . " expired users";
// Remove users with zero uptime (unused vouchers)
$unusedUsers = $API->comm("/ip/hotspot/user/print", array(
"?uptime" => "0s"
));
foreach ($unusedUsers as $user) {
$API->comm("/ip/hotspot/user/remove", array(
".id" => $user['.id']
));
}
?>
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.