https://github.com/sctg-development/sctgdesk-api-server
API server for rustdesk in Rust
https://github.com/sctg-development/sctgdesk-api-server
rustdesk rustdesk-api-server
Last synced: 5 months ago
JSON representation
API server for rustdesk in Rust
- Host: GitHub
- URL: https://github.com/sctg-development/sctgdesk-api-server
- Owner: sctg-development
- License: agpl-3.0
- Created: 2024-05-03T13:40:32.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T17:43:28.000Z (about 2 years ago)
- Last Synced: 2024-05-22T18:46:59.613Z (about 2 years ago)
- Topics: rustdesk, rustdesk-api-server
- Language: TypeScript
- Homepage: https://sctg-development.github.io/sctgdesk-api-server/
- Size: 646 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
* Integrated server: [](https://github.com/sctg-development/sctgdesk-server/actions/workflows/multiarch-docker-hub.yml)
* Standalone nightly build: [](https://github.com/sctg-development/sctgdesk-api-server/actions/workflows/build.yaml)
[**Download full server**](https://github.com/sctg-development/sctgdesk-server/releases)
[**API Documentation**](https://sctg-development.github.io/sctgdesk-api-server/)


# sctgdesk-api-server
## Star the project
**If you appreciate my work, please consider giving it a star! 🤩** or a [](https://github.com/sponsors/sctg-development)
## Disclaimer
First of all this project was not developped to be a replacement of Rustdesk-server-pro. It was developped for our requirements and to be used with Rustdesk.
So there is no warranty, no support, no guarantee, no liability.
The target use it to be included as a crate in rustdesk-server.
As the rustdesk-server was published under AGPL-3.0, this project is also published under AGPL-3.0. That's why you see it !
Feel free to use it, modify it, but don't forget to publish your modifications.
## Description
This project, sctgdesk-api-server, is a basic implementation of an API server for Rustdesk. Rustdesk is an open-source remote control software. This implementation is written in Rust, utilizing the Rocket framework. The entire REST API is documented using `rocket_okapi`. Upon launching the server, it serves Rapidoc module at `/api/doc`, which allows visualizing and testing the various API routes. The server is configured to listen on port 21114. It is designed to utilize a SQLite3 database compatible with the Rustdesk-server or Rustdesk-server-pro databases.
## Status
The server is currently under development and is not yet ready for production use.
## Licensing
This server is distributed under the terms of the GNU Affero General Public License version 3.0 (AGPL-3.0).
## Features
* API server for Rustdesk
* New address book API
* Support for personal address book
* Support for shared address book at group level
* read-only, read-write, admin
* Support for shared address book at user level
* read-only, read-write, admin
* OpenAPI documentation
* Web console (work in progress)
## Architecture
The server use Rocket as the web framework. The server is designed to be modular and extensible. The server is divided into three main parts:
* The `api` module contains the API routes and the API logic. It is 100% Rust code with Rocket framework.
* The `webconsole` module contains the web console. It is a single page Vue.js application written in Typescript. The API is automatically generated from the OpenAPI with Swagger codegen for Axios Typescript. You can access the web console at `/ui`. You'll find the code in the `webconsole` directory.
* The `openapi` module contains the OpenAPI documentation. It is generated with `rocket_okapi`. You can access the Rapidoc module at `/api/doc`.
## Authentication
The server includes basic support for authentication with a username and password. Passwords are stored in the database after being hashed with bcrypt. Additionally, similar to Rustdesk-server-pro, it supports authentication with third-party providers compatible with OAuth2. Currently, only Github and Dex (as a custom provider) are available. For adding a new provider you must implement the `OAuthProvider` and `OAuthProviderFactory` traits. You can look at the [github_provider.rs](https://github.com/sctg-development/sctgdesk-api-server/blob/main/libs/oauth2/src/github_provider.rs) and [dex_provider.rs](https://github.com/sctg-development/sctgdesk-api-server/blob/main/libs/oauth2/src/dex_provider.rs) files for examples.
The first time you launch the server it will create a default user with the username `admin` and the password `Hello,world!`. You can change the password after the first login on the webconsole.
### Default admin user
The default admin user is created with the username `admin` and the password `Hello,world!`. You can change the password after the first login on the webconsole.
## S3 url generation
Our custom clients are stored in a S3 bucket. The S3 configuration is stored in the `s3config.toml` file. The server generates a signed URL for the client download. The URL is valid for 5 minutes. The server generates download links at:
* `/api/software/client-download-link/` for the client download
* key can be one of osx w64 or ios
## Configuration
The server requires an `oauth2.toml` configuration file to function. By default, it is expected at `./oauth2.toml`, although this location can be modified using the `OAUTH2_CONFIG_FILE` environment variable. Setting the `OAUTH2_CREATE_USER` variable to `1` enables the automatic creation of a user upon the first OAuth2 login. The user is created with the Rustdesk ID and a random password, which is displayed in the server logs.
The server also requires a `s3config.toml` configuration file to function. By default, it is expected at `./s3config.toml`, although this location can be modified using the `S3_CONFIG_FILE` environment variable. The S3 configuration file is used to configure the S3 storage for the server.
If you don't provide this two files, the server will create them for you in the working directory.
## OpenAPI
The server is designed to be fully documented using OpenAPI. The documentation is generated using `rocket_okapi`. The server serves the Rapidoc module at `/api/doc`, which allows visualizing and testing the various API routes.
Obviously without any test possible a Rapidoc server is deployed at [https://sctg-development.github.io/sctgdesk-api-server/](https://sctg-development.github.io/sctgdesk-api-server/)
The typescript client api is autogenerated with `swagger-codegen.sh`
## Web console
A web console is available at `/ui` it is a work in progress and is not yet ready for production use.
It is a stub for the future sctgdesk-api-server web console.
The choosen framework is Vue.js. The API is automatically generated from the OpenAPI with Swagger codegen for Axios Typescript. Note the codegen is not yet ready for production use and a few modifications are needed.
For regenerating the api code, run the following command **after** the server is running (it needs docker to be running):
```bash
./swagger-codegen.sh
```
### Development
To start the ui development server, run the following commands:
```bash
sqlite3 db_v2.sqlite3 < Sets the address for the server [default: 127.0.0.1]
--port Sets the port for the server [default: 21114]
--log_level Sets the log level for the server [default: debug]
--secret_key Sets the secret key for the server [default: wJq+s/xvwZjmMX3ev0p4gQTs9Ej5wt0brsk3ZGhoBTg=]
-h, --help Print help
-V, --version Print version
```
## Screenshots
### Webconsole








### Api documentation

### Use in Rustdesk client



## Building
First you need to install the Rust toolchain. You can install it by following the instructions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
You also need to install the SQLite3 development libraries. On Ubuntu, you can install them with the following command:
```bash
sudo apt install libsqlite3-dev
```
on MacOS:
```bash
brew install sqlite3
```
on Windows:
```bash
choco install sqlite
```
You also need nodejs and npm to build the webconsole. You can install them by following the instructions at [https://nodejs.org/en/download/](https://nodejs.org/en/download/).
To build the server on *nix, execute the following command:
```bash
DATABASE_URL=sqlite://$(pwd)/db_v2.sqlite3 && cargo build --release
```
To build the server on Windows, execute the following command:
```bash
set "DATABASE_URL=sqlite://%CD%/db_v2.sqlite3" && cargo build --release --target x86_64-pc-windows-msvc
```
## Integration with Rustdesk-Server
The server can be integrated with the Rustdesk-server you can easily integrate it by modifying the [main.rs](https://github.com/sctg-development/sctgdesk-server/blob/tcpserver-master-build/src/main.rs) file of the Rustdesk-server. :
```rust
use sctgdesk_api_server::build_rocket;
#[rocket::main]
async fn start_rocket() -> ResultType<()> {
let port = get_arg_or("port", RENDEZVOUS_PORT.to_string()).parse::()?;
let figment = rocket::Config::figment()
.merge(("address", "0.0.0.0"))
.merge(("port", port-2))
.merge(("log_level", LogLevel::Debug))
.merge(("secret_key", "wJq+s/xvwZjmMX3ev0p4gQTs9Ej5wt0brsk3ZGhoBTg="))
.merge(("limits", Limits::new().limit("json", 2.mebibytes())));
let _rocket = build_rocket(figment).await.ignite().await?.launch().await?;
Ok(())
}
```
and in the `main` function:
```rust
let rocket_thread = thread::spawn(|| {
let _ = start_rocket();
});
RendezvousServer::start(port, serial, &get_arg("key"), rmem)?;
let _ = rocket_thread.join();
Ok(())
```
You can look at the [sctgdesk-server main.rs](https://github.com/sctg-development/sctgdesk-server/blob/tcpserver-master-build/src/main.rs) for a working itegration.
### Integrated API server with Rustdesk-Server
if you want a ready to use integrated server with Rustdesk-Server, you can use my own server [sctgdesk-server](https://github.com/sctg-development/sctgdesk-server). Binaries are available at [release page](https://github.com/sctg-development/sctgdesk-server/releases). Binaries are available for Linux Ubuntu 22.04LTS amd64 and arm64.
## Limitations
* The server is not yet ready for production use. Buy a [Rustdesk-server-pro](https://rustdesk.com/pricing.html) license to get a production-ready server.
* The Bearen tokens are stored in memory without persistence. It means that each time the server is restarted, all the tokens are lost. You will need to re-authenticate with the server.
## CLI Usage
* User login:
```bash
curl -X POST "http://127.0.0.1:21114/api/login" \
-H "accept: application/json"\
-H "content-type: application/json" \
-d '{"username":"admin","password":"Hello,world!","id":"string","uuid":"string"}'
# Note the Bearen token in the response
```
* Create user:
```bash
curl -X POST "http://127.0.0.1:21114/api/user" \
-H "accept: application/json"\
-H "authorization: Bearer viZ2ArJutFtKsg0DDC1TiV-87uSRQqGBZXAoCeHrFHc"\
-H "content-type: application/json" \
-d '{"name":"testuser","password":"test","confirm-password":"test","email":"string","is_admin":false,"group_name":"Default"}'
```
* Use Rapidoc to test the API at