Connector Open-Source Code
Browse connector files locally. Exchange API keys stay on your device.
ui/instances.php
<?php
// /opt/nuxvision_connector/ui/instance_list.php
declare(strict_types=1);
require_once __DIR__ . '/common.php';
function sudo_systemctl(string $cmd, string $unit): array {
$cmd = trim($cmd);
if (!in_array($cmd, ['start','stop','restart','is-active'], true)) {
return [false, 1, 'bad_command'];
}
if (!preg_match('/^nuxvision-connector-sync@\d+\.service$/', $unit)) {
return [false, 1, 'bad_unit'];
}
$full = 'sudo -n /bin/systemctl ' . escapeshellarg($cmd) . ' ' . escapeshellarg($unit) . ' 2>&1';
$out = [];
$rc = 0;
exec($full, $out, $rc);
return [$rc === 0, $rc, trim(implode("\n", $out))];
}
// Keep POST compatibility (start/stop/switch), then redirect to index dashboard
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
$do = (string)($_POST['do'] ?? '');
$id = to_int($_POST['instance_id'] ?? 0, 0);
if ($id > 0 && in_array($do, ['start','stop','switch'], true)) {
if ($do === 'switch') {
nv_set_instance_in_session($id);
header('Location: ./nuxvision.php?instance_id=' . urlencode((string)$id));
exit;
}
$unit = 'nuxvision-connector-sync@' . $id . '.service';
[$ok, , $out] = sudo_systemctl($do, $unit);
$_SESSION['inst_toast'] = $ok
? ['type'=>'success', 'msg'=> strtoupper($do) . " OK for instance #{$id}"]
: ['type'=>'danger', 'msg'=> strtoupper($do) . " failed for instance #{$id}: " . ($out ?: 'error')];
header('Location: ./index.php');
exit;
}
}
// GET: redirect to dashboard
header('Location: ./index.php');
exit;