Connector Open-Source Code

Browse connector files locally. Exchange API keys stay on your device.

tools/reset_ui_password.php

<?php
declare(strict_types=1);

if (PHP_SAPI !== 'cli') {
    fwrite(STDERR, "This script must be run from CLI.\n");
    exit(1);
}

$baseDir = realpath(__DIR__ . '/..') ?: (__DIR__ . '/..');
$instancesDir = rtrim($baseDir, '/') . '/instances';
$authFile = $instancesDir . '/_ui_auth.php';

function prompt_line(string $label, bool $hidden = false): string {
    if (!$hidden) {
        fwrite(STDOUT, $label);
        $line = fgets(STDIN);
        return trim((string)$line);
    }

    fwrite(STDOUT, $label);
    @system('stty -echo');
    $line = fgets(STDIN);
    @system('stty echo');
    fwrite(STDOUT, PHP_EOL);
    return trim((string)$line);
}

fwrite(STDOUT, "NuxVision Connector - UI password reset\n");
fwrite(STDOUT, "Target file: {$authFile}\n\n");

$pw1 = prompt_line('New password: ', true);
$pw2 = prompt_line('Confirm password: ', true);

if ($pw1 === '' || $pw2 === '') {
    fwrite(STDERR, "Password cannot be empty.\n");
    exit(1);
}
if (!hash_equals($pw1, $pw2)) {
    fwrite(STDERR, "Passwords do not match.\n");
    exit(1);
}

$hash = password_hash($pw1, PASSWORD_DEFAULT);
if (!is_string($hash) || $hash === '') {
    fwrite(STDERR, "Failed to generate password hash.\n");
    exit(1);
}

if (!is_dir($instancesDir) && !@mkdir($instancesDir, 0775, true)) {
    fwrite(STDERR, "Failed to create directory: {$instancesDir}\n");
    exit(1);
}

$payload = "<?php\n";
$payload .= "// generated by tools/reset_ui_password.php\n";
$payload .= "return [\n";
$payload .= "    'password_hash' => " . var_export($hash, true) . ",\n";
$payload .= "    'updated_at' => " . var_export(date('c'), true) . ",\n";
$payload .= "];\n";

$tmp = $authFile . '.tmp.' . getmypid();
if (@file_put_contents($tmp, $payload, LOCK_EX) === false) {
    fwrite(STDERR, "Failed to write temporary file: {$tmp}\n");
    exit(1);
}
if (!@rename($tmp, $authFile)) {
    @unlink($tmp);
    fwrite(STDERR, "Failed to replace auth file: {$authFile}\n");
    exit(1);
}

@chmod($authFile, 0640);
fwrite(STDOUT, "UI password updated successfully.\n");