@@ -18,8 +18,20 @@ $enableSsh = $cfg['ENABLE_SSH'] ?? '0';
1818$manageDns = $cfg['MANAGE_DNS'] ?? '1';
1919$logLevel = $cfg['LOG_LEVEL'] ?? 'info';
2020
21- $profiles = Netbird\listProfiles();
22- $activeProf = Netbird\activeProfile();
21+ $enableCfg = strtolower(trim((string) $enabled));
22+ $serviceEnabled = !in_array($enableCfg, ['0', 'false'], true);
23+ $daemonReady = $serviceEnabled && Netbird\daemonRunning() && file_exists('/var/run/netbird.sock');
24+ $profiles = $daemonReady ? Netbird\listProfiles() : [];
25+ if (!$profiles) {
26+ $profiles = Netbird\savedProfiles();
27+ }
28+ $activeProf = '';
29+ foreach ($profiles as $profile) {
30+ if ($profile['active']) {
31+ $activeProf = $profile['name'];
32+ break;
33+ }
34+ }
2335
2436// Which profile's credentials is the form editing? ?nbprofile= wins, then the
2537// active profile, then "default" (NetBird's built-in profile).
@@ -28,7 +40,19 @@ if (!Netbird\validProfileName($editProf)) {
2840 $editProf = '';
2941}
3042if ($editProf === '') {
31- $editProf = $activeProf !== '' ? $activeProf : 'default';
43+ $editProf = $activeProf;
44+ if ($editProf === '' && $profiles) {
45+ $editProf = $profiles[0]['name'];
46+ foreach ($profiles as $profile) {
47+ if ($profile['name'] === 'default') {
48+ $editProf = 'default';
49+ break;
50+ }
51+ }
52+ }
53+ if ($editProf === '') {
54+ $editProf = 'default';
55+ }
3256}
3357
3458// Credentials are stored per profile (profiles/<name>.cfg), not globally.
@@ -61,14 +85,20 @@ $preSharedKey = $creds['PRESHARED_KEY'];
6185 </option>
6286 <?php endforeach; ?>
6387 </select>
64- <input type="button" value="_(Switch)_" onclick="nbProfile('select', $('#nb-profile-select').val())">
65- <input type="button" value="_(Delete)_" onclick="nbProfileDelete()">
88+ <?php if ($daemonReady): ?>
89+ <input type="button" value="_(Switch)_" onclick="nbProfile('select', $('#nb-profile-select').val())">
90+ <input type="button" value="_(Delete)_" onclick="nbProfileDelete()">
91+ <?php endif; ?>
92+ <?php else: ?>
93+ <span class="nb-profile-empty">No saved profiles yet — editing <code><?=htmlspecialchars($editProf)?></code>.</span>
94+ <?php endif; ?>
95+ <?php if ($daemonReady): ?>
96+
97+ <input type="text" id="nb-profile-new" placeholder="new-profile-name" maxlength="32">
98+ <input type="button" value="_(+ Add)_" onclick="nbProfileAdd()">
6699 <?php else: ?>
67- <span class="nb-profile-empty">No profiles found yet — editing <code><?=htmlspecialchars($editProf)?></code>. Start the daemon and add one below .</span>
100+ <span class="nb-profile-empty">Profile controls are available while NetBird is running .</span>
68101 <?php endif; ?>
69-
70- <input type="text" id="nb-profile-new" placeholder="new-profile-name" maxlength="32">
71- <input type="button" value="_(+ Add)_" onclick="nbProfileAdd()">
72102</div>
73103
74104<blockquote class="inline_help">
0 commit comments