user_group.py, device_group.py python cli doc

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages committed 2025-11-08 22:01:07 +08:00
1 parent 6af6ba3051
commit 9fb232d61f
22 files changed
+2974 -149

No files matched your search

@@ -145,17 +145,188 @@ The command line on Windows does not have output by default. To get output, plea
`./users.py --url <url> --token <token> view [--name <username>] [--group_name <group_name>]`
**Filters:**
`--name`: username
`--group_name`: user group
- `--name`: username (fuzzy search)
- `--group_name`: user group (exact match)
**Example:**
`./users.py --url https://example.com --token <token> view --group_name admins`
`./users.py --url https://example.com --token <token> view --group_name Default`
**Operations:**
view can be replaced with `enable`, `disable`, or `delete`.
**Basic operations:**
**Example (disable user):**
`./users.py --url https://example.com --token <token> disable --name testuser`
- **Disable user:**
`./users.py --url <url> --token <token> disable --name testuser`
- **Enable user:**
`./users.py --url <url> --token <token> enable --name testuser`
- **Delete user:**
`./users.py --url <url> --token <token> delete --name testuser`
**User creation and invitation:**
- **Create new user:**
`./users.py --url <url> --token <token> new --name username --password 'password123' --group_name Default [--email user@example.com] [--note "note"]`
Required: `--name`, `--password`, `--group_name`
Optional: `--email`, `--note`
- **Invite user by email:**
`./users.py --url <url> --token <token> invite --email user@example.com --name username --group_name Default [--note "note"]`
Required: `--email`, `--name`, `--group_name`
Optional: `--note`
**2FA and security operations:**
- **Enable 2FA enforcement:**
`./users.py --url <url> --token <token> enable-2fa-enforce --name username --web-console-url <console_url>`
Required: `--web-console-url`
- **Disable 2FA enforcement:**
`./users.py --url <url> --token <token> disable-2fa-enforce --name username [--web-console-url <console_url>]`
Optional: `--web-console-url`
- **Reset 2FA:**
`./users.py --url <url> --token <token> reset-2fa --name username`
- **Disable email verification:**
`./users.py --url <url> --token <token> disable-email-verification --name username`
- **Force logout:**
`./users.py --url <url> --token <token> force-logout --name username`
**Notes:**
- When operating on multiple users (matched by filters), you will be prompted for confirmation
- If no users match the filter, it will display "Found 0 users"
---
#### User Groups Management (`user_group.py`)
**Show help:**
`./user_group.py -h`
**View user groups:**
`./user_group.py --url <url> --token <token> view [--name <group_name>]`
**Example:**
`./user_group.py --url https://example.com --token <token> view --name "Sales Team"`
**Group operations:**
- **Create user group:**
`./user_group.py --url <url> --token <token> add --name "GroupName" [--note "description"] [--accessed-from '<json>'] [--access-to '<json>']`
Example with access control:
`./user_group.py --url <url> --token <token> add --name "Engineering" --accessed-from '[{"type":0,"name":"Managers"}]' --access-to '[{"type":1,"name":"DevServers"}]'`
- **Update user group:**
`./user_group.py --url <url> --token <token> update --name "GroupName" [--new-name "NewName"] [--note "new note"] [--accessed-from '<json>'] [--access-to '<json>']`
- **Delete user group:**
`./user_group.py --url <url> --token <token> delete --name "GroupName"`
Supports comma-separated names: `--name "Group1,Group2,Group3"`
**User management in groups:**
- **View users in group:**
`./user_group.py --url <url> --token <token> view-users [--name <group_name>] [--user-name <username>]`
Filters:
- `--name`: group name (exact match, optional)
- `--user-name`: username (fuzzy search, optional)
Example:
`./user_group.py --url <url> --token <token> view-users --name Default --user-name john`
- **Add users to group:**
`./user_group.py --url <url> --token <token> add-users --name "GroupName" --users "user1,user2,user3"`
**Access control parameters:**
- `--accessed-from`: JSON array defining who can access this user group
- Type 0 = User Group (e.g., `[{"type":0,"name":"Admins"}]`)
- Type 2 = User (e.g., `[{"type":2,"name":"john"}]`)
- `--access-to`: JSON array defining what this user group can access
- Type 0 = User Group (e.g., `[{"type":0,"name":"Support"}]`)
- Type 1 = Device Group (e.g., `[{"type":1,"name":"Servers"}]`)
**Permission requirements:**
- `view/add/update/delete/add-users` commands require **User Group Permission**
- `view-users` command requires **User Permission**
---
#### Device Groups Management (`device_group.py`)
**Show help:**
`./device_group.py -h`
**View device groups:**
`./device_group.py --url <url> --token <token> view [--name <group_name>]`
**Example:**
`./device_group.py --url https://example.com --token <token> view`
**Group operations:**
- **Create device group:**
`./device_group.py --url <url> --token <token> add --name "GroupName" [--note "description"] [--accessed-from '<json>']`
Example:
`./device_group.py --url <url> --token <token> add --name "Production" --accessed-from '[{"type":0,"name":"Admins"}]'`
- **Update device group:**
`./device_group.py --url <url> --token <token> update --name "GroupName" [--new-name "NewName"] [--note "new note"] [--accessed-from '<json>']`
- **Delete device group:**
`./device_group.py --url <url> --token <token> delete --name "GroupName"`
Supports comma-separated names: `--name "Group1,Group2,Group3"`
**Device management in groups:**
- **View devices in group:**
`./device_group.py --url <url> --token <token> view-devices [filters]`
Available filters:
- `--name`: device group name (exact match)
- `--id`: device ID (fuzzy search)
- `--device-name`: device name (fuzzy search)
- `--user-name`: user name/owner (fuzzy search)
- `--device-username`: logged-in username on device (fuzzy search)
Examples:
```bash
# View all devices in a group
./device_group.py --url <url> --token <token> view-devices --name Production
# Search by device name
./device_group.py --url <url> --token <token> view-devices --device-name server
# Combine filters
./device_group.py --url <url> --token <token> view-devices --name Production --user-name john
```
- **Add devices to group:**
`./device_group.py --url <url> --token <token> add-devices --name "GroupName" --ids "deviceid1,deviceid2"`
- **Remove devices from group:**
`./device_group.py --url <url> --token <token> remove-devices --name "GroupName" --ids "deviceid1,deviceid2"`
**Access control parameter:**
- `--accessed-from`: JSON array defining who can access this device group
- Type 0 = User Group (e.g., `[{"type":0,"name":"Engineers"}]`)
- Type 2 = User (e.g., `[{"type":2,"name":"admin"}]`)
**Permission requirements:**
- `view/add/update/delete/add-devices/remove-devices` commands require **Device Group Permission**
- `view-devices` command requires **Device Permission**
---
@@ -229,6 +400,73 @@ view can be replaced with `enable`, `disable`, `delete`, or `assign`.
---
#### Strategies Management (`strategies.py`)
**Show help:**
`./strategies.py -h`
**List all strategies:**
`./strategies.py --url <url> --token <token> list`
**View a specific strategy:**
```bash
# By name
./strategies.py --url <url> --token <token> view --name "Default"
# By GUID
./strategies.py --url <url> --token <token> view --guid "01983006-fcca-7c12-9a91-b1df483c6073"
```
**Enable or disable a strategy:**
```bash
./strategies.py --url <url> --token <token> enable --name "StrategyName"
./strategies.py --url <url> --token <token> disable --name "StrategyName"
```
**Assign strategy to devices, users, or device groups:**
```bash
# Assign to devices (by device ID)
./strategies.py --url <url> --token <token> assign --name "Default" --peers "1849118658,1337348840"
# Assign to users (by username)
./strategies.py --url <url> --token <token> assign --name "Default" --users "admin,user1"
# Assign to device groups (by group name)
./strategies.py --url <url> --token <token> assign --name "Default" --device-groups "device_group1,Production"
# Mixed assignment
./strategies.py --url <url> --token <token> assign \
--name "Default" \
--peers "1849118658" \
--users "admin" \
--device-groups "device_group1"
```
**Unassign strategy:**
```bash
# Unassign from devices
./strategies.py --url <url> --token <token> unassign --peers "1849118658,1337348840"
# Unassign from users
./strategies.py --url <url> --token <token> unassign --users "admin"
# Unassign from device groups
./strategies.py --url <url> --token <token> unassign --device-groups "device_group1"
```
**Notes:**
- The script supports both names and GUIDs for users and device groups
- Device IDs are automatically converted to GUIDs
- All assign/unassign operations can target multiple resources at once
**Permission requirements:**
- `list/view/enable/disable/assign/unassign` commands require **Strategy Permission**
- `--peers` requires **Device Permission:r** (for ID to GUID lookup)
- `--users` requires **User Permission:r** (for username to GUID lookup)
- `--device-groups` requires **Device Group Permission:r** (for name to GUID lookup)
---
#### Audits (`audits.py`)
**Show help:**