Home

tailpolicy @f3299ae3a61c4685bda369b343cd0ebcef4b32cb - refs - log -
-
https://git.jolheiser.com/tailpolicy.git
Tailscale policy editor on your tailnet
tailpolicy / static / index.tmpl
- raw
 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
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>cfg</title>
  <link rel="stylesheet" href="/tailwind.css" />
</head>

<body class="latte dark:mocha bg-base/50 dark:bg-base/95 text-text">
  <div class="flex h-screen">
    <div class="flex-1 flex flex-col p-4">
      <h2 class="text-2xl font-bold mb-4">Jsonnet</h2>
      <textarea id="input" name="content"
        class="bg-base dark:bg-base/50 flex-1 p-2 border rounded">{{ .content }}</textarea>
    </div>
    <div class="flex-1 flex flex-col p-4">
      <h2 class="text-2xl font-bold mb-4">Policy</h2>
      <textarea id="output" class="bg-base dark:bg-base/50 flex-1 p-2 border rounded"
        placeholder="Converted policy will appear here..." readonly></textarea>
    </div>
  </div>

  <script>
    const $inputText = document.getElementById('input');
    const $outputText = document.getElementById('output');

    $inputText.addEventListener("input", convert);
    $inputText.addEventListener("keydown", function (event) {
      if (event.keyCode == 9) {
        event.preventDefault();
        const start = this.selectionStart;
        const end = this.selectionEnd;
        this.value = this.value.substring(0, start) + "  " + this.value.substring(end);
        this.selectionStart = this.selectionEnd = start + 2;
      }
    });


    function convert() {
      fetch('/preview', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          input: $inputText.value,
        }),
      })
        .then(response => response.text())
        .then(data => {
          $outputText.value = data;
        })
        .catch(error => {
          console.error('Error:', error);
          $outputText.value = 'An error occurred during conversion.';
        });
    }

    const error = "{{ .error }}";
    if (error !== "") alert(error);
  </script>
</body>

</html>