2026-08-07 00:29:07 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once '/usr/local/etc/inc/config.inc';
|
2026-08-07 02:30:26 +09:00
|
|
|
require_once '/usr/local/etc/inc/auth.inc';
|
2026-08-07 00:29:07 +09:00
|
|
|
|
|
|
|
|
use OPNsense\Core\Config;
|
|
|
|
|
use OPNsense\Firewall\Alias;
|
|
|
|
|
|
2026-08-07 02:30:26 +09:00
|
|
|
$password = trim((string)file_get_contents('/mnt/ui-password'));
|
|
|
|
|
if (!preg_match('/^[a-f0-9]{64}$/', $password)) {
|
|
|
|
|
throw new RuntimeException('The UI test password is invalid.');
|
|
|
|
|
}
|
|
|
|
|
$root =& getUserEntry('root');
|
|
|
|
|
if ($root === false) {
|
|
|
|
|
throw new RuntimeException('The root user is unavailable.');
|
|
|
|
|
}
|
|
|
|
|
local_user_set_password($root, $password);
|
|
|
|
|
local_user_set($root, true);
|
|
|
|
|
write_config('Set disposable WebGUI test password');
|
|
|
|
|
|
|
|
|
|
$users = Config::getInstance()->object()->system->user;
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
if ((string)$user->name === 'root' && password_verify($password, (string)$user->password)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isset($user) || (string)$user->name !== 'root' || !password_verify($password, (string)$user->password)) {
|
|
|
|
|
throw new RuntimeException('The disposable WebGUI password was not saved.');
|
|
|
|
|
}
|
|
|
|
|
exec('/usr/local/sbin/configctl webgui restart', $output, $status);
|
|
|
|
|
if ($status !== 0) {
|
|
|
|
|
throw new RuntimeException('The WebGUI did not restart.');
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-07 00:29:07 +09:00
|
|
|
$aliases = new Alias();
|
2026-08-07 02:30:26 +09:00
|
|
|
foreach ($aliases->aliases->alias->iterateItems() as $alias) {
|
|
|
|
|
if ((string)$alias->name === 'UI_TEST_NETWORK') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-07 00:29:07 +09:00
|
|
|
$alias = $aliases->aliases->alias->add();
|
|
|
|
|
$alias->setNodes([
|
|
|
|
|
'enabled' => '1',
|
|
|
|
|
'name' => 'UI_TEST_NETWORK',
|
|
|
|
|
'type' => 'network',
|
|
|
|
|
'proto' => 'IPv4',
|
|
|
|
|
'content' => '192.0.2.0/24',
|
|
|
|
|
]);
|
|
|
|
|
$aliases->serializeToConfig();
|
|
|
|
|
Config::getInstance()->save(['description' => 'Add synthetic UI test alias']);
|