bl4ckp4nd4 / sanaei-api
Connect to Sanaei Panel
v1.0
2025-01-15 17:15 UTC
Requires
- guzzlehttp/guzzle: ^7.0
README
This PHP package provides an easy-to-use wrapper for interacting with the Sanaei API ( 3x-ui ). It allows you to manage inbounds, clients, and other resources through a convenient set of methods.
Features
- Login and session management.
- Retrieve, update, and manage inbounds.
- Add and manage clients for inbounds.
- Traffic and IP management.
Road Map
-
create standard package -
simple Documents -
publish on packagist - add examples
- publish Persian Documents
Installation
You can install this package via Composer:
composer require bl4ckp4nd4/sanaei-api
Usage
- official 3x-ui API document: ( Documents )
Initialization
use Bl4ckp4nd4\SanaeiApi\Sanaei; $api = new Sanaei( url: 'example.com', username: 'your_username', password: 'your_password', webPath: 'panel', // Optional port: 443, // Optional protocol: 'https' // Optional );
Login
$response = $api->login(); if ($response['success']) { echo "Login successful!"; } else { echo "Login failed: " . $response['msg']; }
Retrieve Inbounds
$inbounds = $api->inbounds(); if ($inbounds['success']) { print_r($inbounds['data']); } else { echo "Failed to retrieve inbounds: " . $inbounds['msg']; }
Add a Client
$response = $api->addClient( id: 'inbound_id', uuid: 'client_uuid', email: 'client@example.com', totalgb: 100, eT: time() + (30 * 24 * 60 * 60), // Expire in 30 days limitIp: 1, subId: 'unique_subscription_id' ); if ($response['success']) { echo "Client added successfully!"; } else { echo "Failed to add client: " . $response['msg']; }
Update an Inbound
$response = $api->updateInbound( inboundId: 1, up: 1000000, down: 1000000, total: 2000000, remark: 'Updated Inbound', enable: true, expiryTime: time() + (7 * 24 * 60 * 60), // Expire in 7 days listen: '', port: 8080, protocol: 'vless', settings: [], streamSettings: [], sniffing: [], allocate: [] ); if ($response['success']) { echo "Inbound updated successfully!"; } else { echo "Failed to update inbound: " . $response['msg']; }
Clear Client IPs
$response = $api->clearClientIps('client@example.com'); if ($response['success']) { echo "Client IPs cleared successfully!"; } else { echo "Failed to clear client IPs: " . $response['msg']; }
Requirements
- PHP >= 7.4
- Composer
- cURL extension
Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue for bugs or feature requests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Created by Bl4ckP4nd4.