Welcome to the Outline VPN API C++ Client! This library provides a convenient interface for interacting with the Outline VPN server API, enabling you to manage access keys, configure server settings, and monitor server metrics programmatically. All the functionality that is available on the 1st of January, 2025, is supported by the library.
- Access Key Management: Create, get, update, delete, and rename access keys.
- Data Limit Control: Set and remove data usage limits for individual or all access keys.
- Server Configuration: Configure server settings such as server name, hostname and default port.
- Metrics Monitoring: Enable, disable, and get server metrics to monitor usage of trafic.
- Asynchronous Operations: Perform all operations asynchronously for non-blocking execution.
- Error Handling: Comprehensive exception handling for robust and reliable integrations.
Ensure you have the following dependencies installed:
- C++ Compiler:
g++
(version 13 recommended) - Boost Libraries: System, Asio, JSON, URL components
- OpenSSL
- CMake (optional, if using CMake instead of Makefile)
- CURL
-
Clone the Repository
git clone https://github.com/linkartemy/outline-vpn-api.git cd outline-vpn-api
-
Build the Project
Use the provided Makefile to compile the library and example executable.
make all
-
Run the Example
make run
-
Clean Build Artifacts
To clean the build directory:
make clean
If you prefer using CMake:
-
Create a Build Directory
mkdir build && cd build
-
Configure the Project
cmake ..
-
Build the Project
make
-
Run the Example
./example
To create a new access key with specific parameters:
#include "outline/OutlineClient.h"
#include "outline/utils/UrlUtils.h"
#include <iostream>
#include <memory>
int main() {
std::string apiUrl = "https://your-outline-server.com/api";
std::string cert = ""; // Add your server certificate if required
int timeout = 10;
auto client = outline::OutlineClient::create(apiUrl, cert, timeout);
outline::CreateAccessKeyParams params;
params.name = "NewAccessKey";
params.method = "AES-256-GCM";
params.password = "securepassword";
params.data_limit_bytes = 1000000; // 1 MB
try {
std::future<std::string> createKeyFuture = client->createAccessKeyAsync(params);
std::string createdKey = createKeyFuture.get();
std::cout << "Created Access Key: " << createdKey << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const outline::OutlineParseException& e) {
std::cerr << "Parse Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
return 0;
}
To delete an existing access key by its ID:
std::string accessKeyId = "your-access-key-id";
try {
std::future<void> deleteKeyFuture = client->deleteAccessKeyAsync(accessKeyId);
deleteKeyFuture.get();
std::cout << "Access Key deleted successfully." << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
To set a data usage limit for a specific access key:
std::string accessKeyId = "your-access-key-id";
int dataLimitBytes = 5000000; // 5 MB
try {
std::future<void> addLimitFuture = client->addDataLimitAsync(accessKeyId, dataLimitBytes);
addLimitFuture.get();
std::cout << "Data limit added successfully." << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
To retrieve all access keys:
try {
std::future<std::string> accessKeysFuture = client->getAccessKeysAsync();
std::string accessKeys = accessKeysFuture.get();
std::cout << "Access Keys: " << accessKeys << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const outline::OutlineParseException& e) {
std::cerr << "Parse Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
Metrics provide insights into server performance and usage statistics. To enable metrics:
bool enable = true;
try {
std::future<void> setMetricsFuture = client->setMetricsStatusAsync(enable);
setMetricsFuture.get();
std::cout << "Metrics enabled successfully." << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
To retrieve current server metrics:
try {
std::future<std::string> metricsFuture = client->getMetricsAsync();
std::string metrics = metricsFuture.get();
std::cout << "Server Metrics: " << metrics << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const outline::OutlineParseException& e) {
std::cerr << "Parse Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
To enable the posibility for getting metrics and retrieve them:
#include "outline/OutlineClient.h"
#include "outline/utils/UrlUtils.h"
#include <iostream>
#include <memory>
int main() {
std::string apiUrl = "https://your-outline-server.com/api";
std::string cert = ""; // Add your server certificate if required
int timeout = 10;
auto client = outline::OutlineClient::create(apiUrl, cert, timeout);
try {
// Enable server metrics
bool enableMetrics = true;
std::future<void> enableFuture = client->setMetricsStatusAsync(enableMetrics);
enableFuture.get();
std::cout << "Server metrics enabled." << std::endl;
// Retrieve server metrics
std::future<std::string> metricsFuture = client->getMetricsAsync();
std::string metrics = metricsFuture.get();
std::cout << "Server Metrics: " << metrics << std::endl;
// Interpret metrics (example output)
/*
{
"activeConnections": 5,
"totalDataTransferred": 1500000,
"serverUptime": 86400,
"errorRate": 0.01
}
*/
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const outline::OutlineParseException& e) {
std::cerr << "Parse Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
return 0;
}
Understanding Metrics:
- Usage Statistics: Data on bandwidth consumption.
Enabling metrics makes it possible to retrieve them from server via API like it is shown in the previous example.
To set or update the server's display name:
std::string serverName = "My Outline Server";
try {
std::future<void> setNameFuture = client->setServerNameAsync(serverName);
setNameFuture.get();
std::cout << "Server name set successfully." << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
To configure the server's hostname:
std::string hostName = "vpn.example.com";
try {
std::future<void> setHostFuture = client->setHostNameAsync(hostName);
setHostFuture.get();
std::cout << "Hostname set successfully." << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
To set the default port for new access keys:
int defaultPort = 443;
try {
std::future<void> setPortFuture = client->setDefaultPortAsync(defaultPort);
setPortFuture.get();
std::cout << "Default port set successfully." << std::endl;
} catch (const outline::OutlineServerErrorException& e) {
std::cerr << "Server Error: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Unexpected Error: " << e.what() << std::endl;
}
static std::shared_ptr<OutlineClient> create(std::string_view apiUrl, std::string_view cert, int timeout = 5);
- Parameters:
apiUrl
: The URL for the Outline server API.cert
: Server certificate for SSL/TLS verification.timeout
: Request timeout in seconds (default is 5 seconds).
For convenience, the library also provides synchronous versions of the asynchronous methods. These methods block until the operation completes.
Contributions are welcome! If you'd like to improve the library, please follow these steps:
-
Fork the Repository
-
Create a New Branch
git checkout -b feature/YourFeatureName
-
Make Your Changes
-
Commit Your Changes
git commit -m "Add your commit message"
-
Push to Your Fork
git push origin feature/YourFeatureName
-
Create a Pull Request
Describe your changes and why they are beneficial.
This project is licensed under the MIT License.