Closed Streiter00 closed 2 months ago
First up, yes this is a valid feature request and I agree that the developers should implement this.
In the meantime, we had the same problem and I just scripted it myself. Just create an API token with read+write for devices and add in in line 11, and fill out the other stuff.
Right now the script just takes all devices from one group and moves them to a user, but you can easily modify the script to also filter for other device attributes like ID or name.
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3_helsinki.withPackages(ps : with ps; [ requests ])"
import requests
import sys
import json
#### Fill out this part to edit how the script works ####
# Either create an API token or extract one from a web request after signing in
auth_token = "rapi_abcdefghijklmno=="
url = "https://rustdesk.example.com"
# Request parameters that filter which devices should be moved. The default group is named "-"
pageSize = "1000"
group_name = "-"
# To which user should the devices be moved
user_name = "someUser"
#### Logic starts here ####
api_base = url + "/api"
api_peer = "/devices"
api_peers = "/devices"
headers = {"Authorization": "Bearer " + auth_token}
# get list of devices
url_list_of_devices = api_base + api_peers + "?" + "pageSize=" + pageSize + "&group_name=" + group_name
lod_response = requests.get(url_list_of_devices, headers=headers)
if (lod_response.status_code != 200):
print("Non-OK answer to request!")
print(lod_response.status_code)
sys.exit(lod_response.status_code)
if (len(lod_response.json()) == 0):
print("No devices found.")
sys.exit()
list_of_devices = lod_response.json()["data"]
# move devices to new group
n_modified_devices = 0
api_peer_full = api_base + api_peer
for device in list_of_devices:
payload = {"guid":device["guid"],"id":device["id"],"user_name":user_name}
print(device["id"])
edit_response = requests.put(api_peer_full, headers=headers, json=payload)
if (edit_response.status_code != 200):
print("Non-OK answer to request!")
print(edit_response)
print(payload)
sys.exit(edit_response.status_code)
n_modified_devices += 1
print("Modified " + str(n_modified_devices) + " devices")
It would be very practical if you could select all the devices and then assign them to a group together (or, for all I care, to a user) without having to name them all individually
@21pages let's do this, on users page, add an Assign
action, just like how you assign devices to a shared address book.
BTW, you can also do with device.py
, https://github.com/rustdesk/rustdesk/commit/7d961d895b4964e9c8da9f93ffcf4fe9874ed773
Hey Folks,
I just wanted to say a huge thank you for the awesome job you did in solving that issue. This solution looks fantastic for me.
I appreciate all your efforts. Thanks again for being such a great team! I’m really looking forward to seeing the solution implemented and in use.
I know there is a nearly simmilar post of bulking device management, but the script only helps if you want to delete them as a group or something similar, but to assign devices to a group, you first have to assign them to a user and name each device individually, which is an enormous effort. It would be very practical if you could select all the devices and then assign them to a group together (or, for all I care, to a user) without having to name them all individually, which is an untenable task with a large number of new devices per day.