Skip to content

Commit c5d087b

Browse files
committed
Add security and UI documentation for Unraid plugins
- Created file permissions documentation outlining recommended permission settings for various file types. - Added input validation guidelines emphasizing the importance of sanitizing and validating user input. - Established a UI development section with documentation on form controls, dashboard tiles, tab pages, and JavaScript patterns for interactivity. - Included examples for AJAX form submissions, SweetAlert dialogs, and dynamic content loading. - Documented best practices for security, UI consistency, and user experience in plugin development.
1 parent 17acd0f commit c5d087b

31 files changed

Lines changed: 4480 additions & 2 deletions

docs/advanced/_index.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
layout: default
3+
title: Advanced Topics
4+
nav_order: 30
5+
has_children: true
6+
---
7+
8+
# Advanced Topics
9+
10+
This section covers advanced plugin development topics for more complex integrations.
11+
12+
## System Integration
13+
14+
- [Docker Integration]({% link docs/advanced/docker-integration.md %}) - Docker API and container management
15+
- [Array/Disk Access]({% link docs/advanced/array-disk-access.md %}) - Disk info, shares, and array status
16+
- [User Scripts Integration]({% link docs/advanced/user-scripts-integration.md %}) - Working with User Scripts plugin
17+
18+
## Development & Debugging
19+
20+
- [Debugging Techniques]({% link docs/advanced/debugging-techniques.md %}) - Logging, error handling, dev tools
21+
22+
## Distribution
23+
24+
- [Package Management]({% link docs/advanced/package-management.md %}) - Building .txz packages
25+
- [Update Mechanisms]({% link docs/advanced/update-mechanisms.md %}) - Version checking and auto-updates

docs/advanced/array-disk-access.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
---
2+
layout: default
3+
title: Array/Disk Access
4+
parent: Advanced Topics
5+
nav_order: 2
6+
---
7+
8+
# Array/Disk Access
9+
10+
{: .warning }
11+
> This page is a stub. [Help us expand it!](https://github.com/mstrhakr/unraid-plugin-docs/blob/main/CONTRIBUTING.md)
12+
13+
## Overview
14+
15+
Plugins can read disk information, share configurations, and array status to provide disk management features or integrate with Unraid's storage system.
16+
17+
## Array Status
18+
19+
### The $var Array
20+
21+
```php
22+
<?
23+
// Global array containing system state
24+
global $var;
25+
26+
// Array status
27+
$arrayStatus = $var['fsState']; // Started, Stopped, etc.
28+
29+
// Check if array is started
30+
$arrayStarted = ($var['fsState'] == 'Started');
31+
?>
32+
```
33+
34+
### Common $var Properties
35+
36+
| Property | Description |
37+
|----------|-------------|
38+
| `$var['fsState']` | Array state (Started, Stopped, etc.) |
39+
| `$var['mdState']` | MD device state |
40+
| `$var['sbNumDisks']` | Number of data disks |
41+
| `$var['sbNumParity']` | Number of parity disks |
42+
| `$var['csrf_token']` | CSRF token |
43+
44+
## Disk Information
45+
46+
### Reading Disk Data
47+
48+
```php
49+
<?
50+
// Disk information is typically in /var/local/emhttp/
51+
$disks = parse_ini_file('/var/local/emhttp/disks.ini', true);
52+
53+
foreach ($disks as $disk => $info) {
54+
echo "Disk: $disk\n";
55+
echo "Device: " . $info['device'] . "\n";
56+
echo "Size: " . $info['size'] . "\n";
57+
echo "Status: " . $info['status'] . "\n";
58+
}
59+
?>
60+
```
61+
62+
### Disk Properties
63+
64+
TODO: Document available disk properties
65+
66+
| Property | Description |
67+
|----------|-------------|
68+
| `device` | Device name (sda, sdb, etc.) |
69+
| `size` | Disk size in bytes |
70+
| `status` | Disk status |
71+
| `temp` | Temperature |
72+
| `serial` | Serial number |
73+
74+
## Share Information
75+
76+
### Reading Shares
77+
78+
```php
79+
<?
80+
// Share configuration
81+
$shares = parse_ini_file('/var/local/emhttp/shares.ini', true);
82+
83+
foreach ($shares as $share => $info) {
84+
echo "Share: $share\n";
85+
echo "Path: /mnt/user/$share\n";
86+
echo "Free: " . $info['free'] . "\n";
87+
}
88+
?>
89+
```
90+
91+
### User Shares vs Disk Shares
92+
93+
```
94+
/mnt/user/ShareName # User share (combined view)
95+
/mnt/disk1/ShareName # Disk-specific path
96+
/mnt/cache/ShareName # Cache disk path
97+
```
98+
99+
## Checking Disk Space
100+
101+
```php
102+
<?
103+
function getDiskSpace($path) {
104+
$total = disk_total_space($path);
105+
$free = disk_free_space($path);
106+
$used = $total - $free;
107+
108+
return [
109+
'total' => $total,
110+
'free' => $free,
111+
'used' => $used,
112+
'percent' => round(($used / $total) * 100, 1)
113+
];
114+
}
115+
116+
$userSpace = getDiskSpace('/mnt/user');
117+
?>
118+
```
119+
120+
## Parity Operations
121+
122+
TODO: Document how to check/interact with parity operations
123+
124+
```php
125+
<?
126+
// Check if parity check is running
127+
// $var properties related to parity status
128+
?>
129+
```
130+
131+
## SMART Data
132+
133+
```php
134+
<?
135+
// Get SMART data for a disk
136+
$device = '/dev/sda';
137+
exec("smartctl -A " . escapeshellarg($device), $output);
138+
139+
// Parse SMART attributes
140+
// TODO: Document parsing patterns
141+
?>
142+
```
143+
144+
## Safe Practices
145+
146+
### Check Array State
147+
148+
```php
149+
<?
150+
global $var;
151+
152+
function requireArrayStarted() {
153+
global $var;
154+
if ($var['fsState'] !== 'Started') {
155+
die("Array must be started for this operation");
156+
}
157+
}
158+
?>
159+
```
160+
161+
### Check Path Safety
162+
163+
```php
164+
<?
165+
function isSafePath($path) {
166+
// Ensure path is within allowed directories
167+
$allowed = ['/mnt/user/', '/mnt/cache/', '/mnt/disk'];
168+
foreach ($allowed as $prefix) {
169+
if (strpos($path, $prefix) === 0) {
170+
return true;
171+
}
172+
}
173+
return false;
174+
}
175+
?>
176+
```
177+
178+
## Events for Array Changes
179+
180+
| Event | When Triggered |
181+
|-------|----------------|
182+
| `starting_array` | Array starting |
183+
| `started_array` | Array fully started |
184+
| `stopping_array` | Array stopping |
185+
| `stopped_array` | Array fully stopped |
186+
| `disk_added` | Disk added |
187+
188+
## Related Topics
189+
190+
- [Event System]({% link docs/events.md %})
191+
- [File System Layout]({% link docs/filesystem.md %})
192+
- [File Path Reference]({% link docs/reference/file-path-reference.md %})

0 commit comments

Comments
 (0)