3, 'output' => ['Failed to parse blocklists.json'] ]); exit; } $flatList = flattenList($allLists); if (!isset($flatList[$blocklist_id])) { echo json_encode(['return' => 1, 'output' => ['Invalid blocklist ID']]); exit; } $list_url = escapeshellcmd($flatList[$blocklist_id]['list_url']); $dest_file = escapeshellcmd($flatList[$blocklist_id]['dest_file']); $dest = pathinfo($dest_file, PATHINFO_FILENAME); $scriptPath = RASPI_CONFIG . '/adblock/update_blocklist.sh'; if (!file_exists($scriptPath)) { echo json_encode([ 'return' => 5, 'output' => ["Update script not found: $scriptPath"] ]); exit; } exec("sudo $scriptPath $list_url $dest_file " . RASPI_ADBLOCK_LISTPATH, $output, $return_var); echo json_encode([ 'return' => $return_var, 'output' => $output, 'list' => $dest ]); } else { echo json_encode(['return' => 2, 'output' => ['No blocklist ID provided']]); } function flattenList(array $grouped): array { $flat = []; foreach ($grouped as $group) { foreach ($group as $name => $meta) { $flat[$name] = $meta; } } return $flat; }