Files
Varaverk/Plugin/usr/local/emhttp/plugins/varaverk/api/settings.php
T
Gmer4Lfe 7b7a3a9e9e Fix plugin routing, missing includes, and make SCRIPTS_DIR configurable
- Rename varaverk.page → Varaverk.page: unRAID nginx only routes URLs
  starting with a capital letter (~^/[A-Z].*), lowercase caused 404
- Add require_once config.php to include/scheduler.php and include/docs.php:
  both used SCRIPTS_DIR constant without including the file that defines it
- Replace hardcoded SCRIPTS_DIR with cfg-file-backed setting: reads from
  /boot/config/plugins/varaverk/varaverk.cfg, falls back to default on first run
- Add Plugin Settings card to Config tab with scripts path field
- Add api/settings.php to write the cfg file (validates directory exists)
2026-05-23 16:48:52 -04:00

25 lines
739 B
PHP

<?php
header('Content-Type: application/json');
$body = json_decode(file_get_contents('php://input'), true);
$scriptsDir = trim($body['scripts_dir'] ?? '');
if (!$scriptsDir) {
echo json_encode(['ok' => false, 'error' => 'scripts_dir is required']);
exit;
}
if (!is_dir($scriptsDir)) {
echo json_encode(['ok' => false, 'error' => 'Directory does not exist']);
exit;
}
$cfgFile = '/boot/config/plugins/varaverk/varaverk.cfg';
$cfgDir = dirname($cfgFile);
if (!is_dir($cfgDir)) mkdir($cfgDir, 0755, true);
$content = 'SCRIPTS_DIR="' . addslashes($scriptsDir) . '"' . "\n";
$ok = file_put_contents($cfgFile, $content) !== false;
echo json_encode(['ok' => $ok, 'error' => $ok ? null : 'Failed to write cfg file']);