lazydns 0.3.20

A light and fast DNS server/forwarder implementation in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<script lang="ts">
  import { darkMode } from "../lib/stores";
  import { features } from "../lib/features.svelte";
  import { createEventDispatcher } from "svelte";
  import ConfigValue from "./ConfigValue.svelte";
  import type { ConfigDumpResponse, ConfigPluginSummary } from "../lib/api";

  // Configuration dump (fetched by the parent Admin page).
  export let configDump: ConfigDumpResponse | null = null;
  // Error from fetching the dump (e.g. backend unavailable).
  export let configError: string | null = null;
  // Error from the last config reload (persistent banner); cleared by the user.
  export let reloadError: string | null = null;

  const dispatch = createEventDispatcher<{ dismissreloaderror: void }>();

  // Expandable sequences: keyed by plugin tag (true = expanded).
  let expandedSequences: Record<string, boolean> = {};
  // Expandable plugins (args detail): keyed by plugin tag (true = expanded).
  let expandedPlugins: Record<string, boolean> = {};

  function toggleSequence(tag: string) {
    expandedSequences[tag] = !expandedSequences[tag];
  }

  function togglePlugin(tag: string) {
    expandedPlugins[tag] = !expandedPlugins[tag];
  }

  // Render a short one-line summary of a plugin's args based on common keys.
  function argsPreview(p: ConfigPluginSummary): string {
    // args_summary may be null when the plugin has no args (e.g. blackhole).
    const a = (p.args_summary ?? {}) as Record<string, unknown>;
    const parts: string[] = [];
    if (typeof a.size === "number") parts.push(`size=${a.size}`);
    if (typeof a.concurrent === "number") parts.push(`concurrent=${a.concurrent}`);
    const ups = a.upstreams;
    if (Array.isArray(ups)) parts.push(`${ups.length} upstreams`);
    if (Array.isArray(a.files)) parts.push(`${a.files.length} files`);
    if (typeof a.auto_reload === "boolean" && a.auto_reload) parts.push("auto-reload");
    if (typeof a.enabled === "boolean" && !a.enabled) parts.push("disabled");
    if (typeof a.entry === "string") parts.push(`entry=${a.entry}`);
    if (typeof a.listen === "string") parts.push(`listen=${a.listen}`);
    if (parts.length === 0 && Object.keys(a).length > 0) {
      parts.push(`${Object.keys(a).length} fields`);
    }
    return parts.join(" ยท ");
  }

  // Separated plugin groups for display.
  $: configServers = configDump
    ? configDump.plugins.filter((p) => isServer(p))
    : [];
  $: configSequences = configDump
    ? configDump.plugins.filter((p) => p.is_sequence)
    : [];
  $: configOtherPlugins = configDump
    ? configDump.plugins.filter((p) => !isServer(p) && !p.is_sequence)
    : [];

  function isServer(p: ConfigPluginSummary): boolean {
    return p.plugin_type.endsWith("_server") || p.plugin_type === "server";
  }
</script>

<div class="space-y-6">
  <!-- Configuration Not Available Warning -->
  {#if !features.admin}
    <div
      class="card p-4 border-2 {$darkMode
        ? 'border-yellow-800 bg-yellow-900/20'
        : 'border-yellow-300 bg-yellow-50'}"
    >
      <div class="flex items-start gap-3">
        <svg
          class="w-6 h-6 flex-shrink-0 {$darkMode
            ? 'text-yellow-400'
            : 'text-yellow-600'}"
          fill="none"
          stroke="currentColor"
          viewBox="0 0 24 24"
        >
          <path
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
          />
        </svg>
        <div>
          <h4
            class="font-semibold {$darkMode
              ? 'text-yellow-300'
              : 'text-yellow-800'}"
          >
            Configuration Not Available
          </h4>
          <p
            class="text-sm mt-1 {$darkMode
              ? 'text-yellow-400/80'
              : 'text-yellow-700'}"
          >
            The configuration view requires an admin build. Rebuild with the
            <code
              class="px-1.5 py-0.5 rounded {$darkMode
                ? 'bg-yellow-900/40'
                : 'bg-yellow-200'} font-mono text-xs">--features admin</code
            >
            flag to enable it.
          </p>
        </div>
      </div>
    </div>
  {:else if reloadError}
    <!-- Persistent reload error banner (Task 4): the toast is fleeting, but a
         config validation failure needs to stay visible until dismissed. -->
    <div
      class="card p-4 border-2 {$darkMode
        ? 'border-red-800 bg-red-900/20'
        : 'border-red-300 bg-red-50'}"
    >
      <div class="flex items-start gap-3">
        <svg
          class="w-6 h-6 flex-shrink-0 {$darkMode
            ? 'text-red-400'
            : 'text-red-600'}"
          fill="none"
          stroke="currentColor"
          viewBox="0 0 24 24"
        >
          <path
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
          />
        </svg>
        <div class="flex-1 min-w-0">
          <h4
            class="font-semibold {$darkMode
              ? 'text-red-300'
              : 'text-red-800'}"
          >
            Configuration Reload Failed
          </h4>
          <p
            class="text-sm mt-1 break-words font-mono {$darkMode
              ? 'text-red-400/90'
              : 'text-red-700'}"
          >
            {reloadError}
          </p>
        </div>
        <button
          on:click={() => dispatch("dismissreloaderror")}
          class="flex-shrink-0 {$darkMode
            ? 'text-red-400 hover:text-red-300'
            : 'text-red-500 hover:text-red-700'}"
          title="Dismiss"
        >
          <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="2"
              d="M6 18L18 6M6 6l12 12"
            />
          </svg>
        </button>
      </div>
    </div>
  {:else if configError}
    <div
      class="card p-4 border-2 {$darkMode
        ? 'border-red-800 bg-red-900/20'
        : 'border-red-300 bg-red-50'}"
    >
      <p class="text-sm {$darkMode ? 'text-red-300' : 'text-red-700'}">
        {configError}
      </p>
    </div>
  {:else if configDump}
    <!-- Top-level Settings -->
    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
      <!-- Logging & Admin -->
      <div class="card">
        <div class="card-header">
          <h3
            class="font-semibold {$darkMode
              ? 'text-white'
              : 'text-gray-900'} flex items-center gap-2"
          >
            <svg
              class="w-5 h-5 {$darkMode ? 'text-gray-400' : 'text-gray-500'}"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              <path
                stroke-linecap="round"
                stroke-linejoin="round"
                stroke-width="2"
                d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
              />
            </svg>
            Logging & Admin
          </h3>
        </div>
        <div class="card-body space-y-0">
          {#each [{ label: "Version", value: configDump.version }, { label: "Log Level", value: configDump.log.level }, { label: "Log Format", value: configDump.log.format }, { label: "Console Output", value: configDump.log.console ? "enabled" : "disabled" }, { label: "File Logging", value: configDump.log.file_enabled ? "enabled" : "disabled" }, { label: "Admin API", value: configDump.admin ? `${configDump.admin.enabled ? "enabled" : "disabled"} (${configDump.admin.addr})` : "n/a" }] as item}
            <div
              class="flex items-center justify-between py-2 border-b {$darkMode
                ? 'border-gray-700/50'
                : 'border-gray-200'} last:border-0"
            >
              <span class={$darkMode ? "text-gray-400" : "text-gray-700"}
                >{item.label}</span
              >
              <span
                class="{$darkMode
                  ? 'text-white'
                  : 'text-gray-900'} font-mono text-sm">{item.value}</span
              >
            </div>
          {/each}
        </div>
      </div>

      <!-- Monitoring & Web -->
      <div class="card">
        <div class="card-header">
          <h3
            class="font-semibold {$darkMode
              ? 'text-white'
              : 'text-gray-900'} flex items-center gap-2"
          >
            <svg
              class="w-5 h-5 {$darkMode ? 'text-gray-400' : 'text-gray-500'}"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              <path
                stroke-linecap="round"
                stroke-linejoin="round"
                stroke-width="2"
                d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"
              />
            </svg>
            Servers
          </h3>
        </div>
        <div class="card-body space-y-0">
          {#each [{ label: "Monitoring", value: configDump.monitoring ? `${configDump.monitoring.enabled ? "enabled" : "disabled"} (${configDump.monitoring.addr})` : "n/a" }, { label: "WebUI", value: configDump.web ? `${configDump.web.enabled ? "enabled" : "disabled"} (${configDump.web.listen})` : "n/a" }, { label: "Total Plugins", value: String(configDump.plugin_count) }, { label: "Listeners", value: configServers.length > 0 ? configServers.map((s) => s.tag).join(", ") : "none" }] as item}
            <div
              class="flex items-center justify-between py-2 border-b {$darkMode
                ? 'border-gray-700/50'
                : 'border-gray-200'} last:border-0"
            >
              <span class={$darkMode ? "text-gray-400" : "text-gray-700"}
                >{item.label}</span
              >
              <span
                class="{$darkMode
                  ? 'text-white'
                  : 'text-gray-900'} font-mono text-sm text-right break-all max-w-[60%]">{item.value}</span
              >
            </div>
          {/each}
        </div>
      </div>
    </div>

    <!-- Sequences Flow -->
    {#if configSequences.length > 0}
      <div class="card">
        <div class="card-header">
          <h3
            class="font-semibold {$darkMode
              ? 'text-white'
              : 'text-gray-900'} flex items-center gap-2"
          >
            <svg
              class="w-5 h-5 {$darkMode ? 'text-gray-400' : 'text-gray-500'}"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              <path
                stroke-linecap="round"
                stroke-linejoin="round"
                stroke-width="2"
                d="M13 5l7 7-7 7M5 5l7 7-7 7"
              />
            </svg>
            Sequences
            <span class="badge badge-info">{configSequences.length}</span>
          </h3>
        </div>
        <div class="card-body space-y-3">
          {#each configSequences as seq}
            <div
              class="rounded-lg {$darkMode
                ? 'bg-gray-700/30'
                : 'bg-gray-100'} p-3"
            >
              <button
                on:click={() => toggleSequence(seq.tag)}
                class="w-full flex items-center justify-between text-left"
              >
                <span
                  class="font-mono font-semibold {$darkMode
                    ? 'text-white'
                    : 'text-gray-900'}"
                >
                  {seq.tag}
                  {#if seq.sequence_steps}
                    <span
                      class="ml-2 text-xs font-normal {$darkMode
                        ? 'text-gray-400'
                        : 'text-gray-700'}"
                    >
                      {seq.sequence_steps.length} steps
                    </span>
                  {/if}
                </span>
                <svg
                  class="w-4 h-4 transition-transform {$darkMode
                    ? 'text-gray-400'
                    : 'text-gray-500'}"
                  class:rotate-180={expandedSequences[seq.tag]}
                  fill="none"
                  stroke="currentColor"
                  viewBox="0 0 24 24"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="2"
                    d="M19 9l-7 7-7-7"
                  />
                </svg>
              </button>

              {#if expandedSequences[seq.tag] && seq.sequence_steps}
                <ol
                  class="mt-3 ml-3 border-l-2 {$darkMode
                    ? 'border-primary-500/50'
                    : 'border-primary-400'} space-y-2"
                >
                  {#each seq.sequence_steps as step, i}
                    <li class="ml-4 flex items-start gap-2">
                      <span
                        class="flex-shrink-0 w-5 h-5 rounded-full {$darkMode
                          ? 'bg-primary-500/20 text-primary-400'
                          : 'bg-primary-100 text-primary-700'} text-xs flex items-center justify-center font-semibold mt-0.5"
                      >
                        {i + 1}
                      </span>
                      <span
                        class="font-mono text-sm {$darkMode
                          ? 'text-gray-300'
                          : 'text-gray-800'}"
                      >
                        {#if step.matches}
                          <span
                            class="{$darkMode
                              ? 'text-yellow-400'
                              : 'text-yellow-600'}">matches</span
                          >
                          {step.matches}
                          <span
                            class={$darkMode
                              ? 'text-gray-500'
                              : 'text-gray-400'}>{"->"}</span
                          >
                        {/if}
                        {#if step.exec}
                          <span
                            class="{$darkMode
                              ? 'text-blue-400'
                              : 'text-blue-600'}">exec</span
                          >
                          {step.exec}
                        {/if}
                      </span>
                    </li>
                  {/each}
                </ol>
              {/if}
            </div>
          {/each}
        </div>
      </div>
    {/if}

    <!-- Other Plugins -->
    {#if configOtherPlugins.length > 0}
      <div class="card">
        <div class="card-header">
          <h3
            class="font-semibold {$darkMode
              ? 'text-white'
              : 'text-gray-900'} flex items-center gap-2"
          >
            <svg
              class="w-5 h-5 {$darkMode ? 'text-gray-400' : 'text-gray-500'}"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              <path
                stroke-linecap="round"
                stroke-linejoin="round"
                stroke-width="2"
                d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"
              />
            </svg>
            Plugins
            <span class="badge badge-gray">{configOtherPlugins.length}</span>
          </h3>
        </div>
        <div class="card-body">
          <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
            {#each configOtherPlugins as p}
              <div
                class="p-3 rounded-lg {$darkMode
                  ? 'bg-gray-700/30'
                  : 'bg-gray-100'}"
              >
                <button
                  on:click={() => togglePlugin(p.tag)}
                  class="w-full flex items-center justify-between text-left"
                >
                  <div class="flex items-center gap-2 flex-wrap min-w-0">
                    <span
                      class="font-mono font-semibold {$darkMode
                        ? 'text-white'
                        : 'text-gray-900'}"
                    >
                      {p.tag}
                    </span>
                    <span class="badge badge-gray">{p.plugin_type}</span>
                    {#if !expandedPlugins[p.tag] && argsPreview(p)}
                      <span
                        class="text-xs font-mono {$darkMode
                          ? 'text-gray-400'
                          : 'text-gray-700'} truncate"
                      >
                        {argsPreview(p)}
                      </span>
                    {/if}
                  </div>
                  <svg
                    class="w-4 h-4 flex-shrink-0 transition-transform {$darkMode
                      ? 'text-gray-400'
                      : 'text-gray-500'}"
                    class:rotate-180={expandedPlugins[p.tag]}
                    fill="none"
                    stroke="currentColor"
                    viewBox="0 0 24 24"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M19 9l-7 7-7-7"
                    />
                  </svg>
                </button>

                {#if expandedPlugins[p.tag]}
                  <div
                    class="mt-3 pt-3 border-t {$darkMode
                      ? 'border-gray-600'
                      : 'border-gray-200'}"
                  >
                    <ConfigValue value={p.args_summary} />
                  </div>
                {/if}
              </div>
            {/each}
          </div>
        </div>
      </div>
    {/if}
  {:else}
    <div class="card">
      <div class="card-body text-center py-8">
        <p class={$darkMode ? "text-gray-400" : "text-gray-500"}>
          Loading configuration...
        </p>
      </div>
    </div>
  {/if}
</div>