ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Generate and display pairing passphrase
Juan Denis4d6e712fb5eb
diff --git a/agent/internal/setupui/setupui.go b/agent/internal/setupui/setupui.goindex 29269422..5c28432c 100644--- a/agent/internal/setupui/setupui.go+++ b/agent/internal/setupui/setupui.go@@ -5,7 +5,9 @@ package setupuiimport ("context"+ "crypto/rand""fmt"+ "math/big""os""path/filepath""runtime"@@ -18,6 +20,28 @@ import ("github.com/serverkit/agent/internal/pairing")+// passphraseAlphabet excludes 0/O/1/I/L for readability — same convention as+// the panel's pair codes — so an operator reading the value off one screen and+// typing it into another doesn't mis-key.+const passphraseAlphabet = "23456789ABCDEFGHJKMNPQRSTUVWXYZ"++// generatePassphrase returns a fresh 8-char passphrase for an enroll request.+// 8 chars from this 30-char alphabet ≈ 39 bits of entropy, which is overkill+// for a one-shot value that becomes useless once the panel claims the agent.+func generatePassphrase() (string, error) {+ const n = 8+ max := big.NewInt(int64(len(passphraseAlphabet)))+ buf := make([]byte, n)+ for i := 0; i < n; i++ {+ idx, err := rand.Int(rand.Reader, max)+ if err != nil {+ return "", err+ }+ buf[i] = passphraseAlphabet[idx.Int64()]+ }+ return string(buf), nil+}+// Run shows the pairing wizard and blocks until the user closes it.// configPath may be empty to use the default location.func Run(ctx context.Context, log *logger.Logger, configPath string) error {diff --git a/agent/internal/setupui/window_windows.go b/agent/internal/setupui/window_windows.goindex caf37fb2..d21f445b 100644--- a/agent/internal/setupui/window_windows.go+++ b/agent/internal/setupui/window_windows.go@@ -90,13 +90,13 @@ type wizardUI struct {// stage 1 widgetsurlEdit *walk.LineEdit- passEdit *walk.LineEditnameEdit *walk.LineEditformErr *walk.LabelstartBtn *walk.PushButton// stage 2 widgetscodeLabel *walk.Label+ passLabel *walk.LabelstatusLabel *walk.LabelpairErrLabel *walk.LabelcancelBtn *walk.PushButton@@ -242,31 +242,6 @@ func (w *wizardUI) show() error {dec.VSpacer{Size: 20},- // Passphrase- dec.Label{- Text: "Passphrase",- Font: dec.Font{Bold: true, PointSize: bodySize, Family: "Segoe UI"},- TextColor: rgbHex(textLabel),- Background: bgCardBrush,- },- dec.VSpacer{Size: 6},- dec.LineEdit{- AssignTo: &w.passEdit,- PasswordMode: true,- CueBanner: "Set in the panel under Add Server",- MaxLength: 200,- MinSize: dec.Size{Height: 28},- },- dec.VSpacer{Size: 6},- dec.Label{- Text: "Generated in your panel under Servers → Add Server.",- Font: dec.Font{PointSize: smallSize, Family: "Segoe UI"},- TextColor: rgbHex(textHelper),- Background: bgCardBrush,- },-- dec.VSpacer{Size: 20},-dec.Label{AssignTo: &w.formErr,TextColor: rgbHex(errorRed),@@ -301,12 +276,20 @@ func (w *wizardUI) show() error {},dec.VSpacer{Size: 4},dec.Label{- Text: "Enter this code in the Pair code field:",+ Text: "Enter both values in the Pair code and Passphrase fields:",Font: dec.Font{PointSize: bodySize, Family: "Segoe UI"},TextColor: rgbHex(textMuted),Background: bgCardBrush,},- dec.VSpacer{Size: 24},+ dec.VSpacer{Size: 20},+ dec.Label{+ Text: "Pair code",+ Font: dec.Font{Bold: true, PointSize: smallSize, Family: "Segoe UI"},+ TextColor: rgbHex(textLabel),+ Background: bgCardBrush,+ TextAlignment: dec.AlignCenter,+ },+ dec.VSpacer{Size: 6},// Code "field" — visually echoes the panel's letter-spaced// input. We can't render a real bordered box, but a// centered Composite with the card colour at least@@ -327,7 +310,32 @@ func (w *wizardUI) show() error {dec.HSpacer{},},},- dec.VSpacer{Size: 24},+ dec.VSpacer{Size: 18},+ dec.Label{+ Text: "Passphrase",+ Font: dec.Font{Bold: true, PointSize: smallSize, Family: "Segoe UI"},+ TextColor: rgbHex(textLabel),+ Background: bgCardBrush,+ TextAlignment: dec.AlignCenter,+ },+ dec.VSpacer{Size: 6},+ dec.Composite{+ Layout: dec.HBox{MarginsZero: true},+ Background: bgCardBrush,+ Children: []dec.Widget{+ dec.HSpacer{},+ dec.Label{+ AssignTo: &w.passLabel,+ Text: "",+ Font: dec.Font{PointSize: 18, Bold: true, Family: "Consolas"},+ TextColor: rgbHex(textPrimary),+ Background: bgCardBrush,+ TextAlignment: dec.AlignCenter,+ },+ dec.HSpacer{},+ },+ },+ dec.VSpacer{Size: 20},dec.Label{AssignTo: &w.statusLabel,Text: "Waiting for the panel to claim this server…",@@ -441,15 +449,15 @@ func (w *wizardUI) show() error {// pairing in a goroutine, and transitions to the pairing stage on success.func (w *wizardUI) handleConnect() {url := w.urlEdit.Text()- pass := w.passEdit.Text()name := w.nameEdit.Text()if url == "" {w.formErr.SetText("Panel URL is required.")return}- if len(pass) < 4 {- w.formErr.SetText("Passphrase must be at least 4 characters.")+ pass, err := generatePassphrase()+ if err != nil {+ w.formErr.SetText("Could not generate a passphrase: " + err.Error())return}w.formErr.SetText("")@@ -465,6 +473,7 @@ func (w *wizardUI) handleConnect() {onEnrolled: func(code, formatted string) {w.mw.Synchronize(func() {w.codeLabel.SetText(displayCode(code, formatted))+ w.passLabel.SetText(pass)w.showStage(stagePairing)})},@@ -507,6 +516,7 @@ func (w *wizardUI) handleCancel() {w.formErr.SetText("")w.pairErrLabel.SetText("")w.codeLabel.SetText("")+ w.passLabel.SetText("")w.cancelBtn.SetText("Cancel")w.startBtn.SetEnabled(true)w.startBtn.SetText("Connect")diff --git a/frontend/src/pages/Servers.jsx b/frontend/src/pages/Servers.jsxindex 2f01b384..d4d2f593 100644--- a/frontend/src/pages/Servers.jsx+++ b/frontend/src/pages/Servers.jsx@@ -600,26 +600,31 @@ const PairAgentForm = ({ groups, onClose, onClaimed }) => {.replace(/[01OIL]/g, '').slice(0, 6);- async function handleLookup() {+ // Auto-lookup as soon as the user finishes typing all 6 characters.+ // Avoids showing "must be 6 chars" while the user is still mid-entry or+ // just clicking around — the previous onBlur trigger fired too eagerly.+ useEffect(() => {+ if (formattedCode.length !== 6) return;+ let cancelled = false;setLookupError('');- setLookupResult(null);- if (formattedCode.length === 0) return;- if (formattedCode.length !== 6) {- setLookupError('Pair code must be 6 characters');- return;- }setLoading(true);- try {- const res = await api.lookupPairCode(formattedCode);- setLookupResult(res);- const suggestedName = res.system_info?.hostname;- if (!name && suggestedName) setName(suggestedName);- } catch (err) {- setLookupError(err.message || 'Pair code not found');- } finally {- setLoading(false);- }- }+ api.lookupPairCode(formattedCode)+ .then((res) => {+ if (cancelled) return;+ setLookupResult(res);+ const suggestedName = res.system_info?.hostname;+ if (!name && suggestedName) setName(suggestedName);+ })+ .catch((err) => {+ if (cancelled) return;+ setLookupError(err.message || 'Pair code not found');+ })+ .finally(() => {+ if (!cancelled) setLoading(false);+ });+ return () => { cancelled = true; };+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [formattedCode]);async function handleClaim(e) {e.preventDefault();@@ -656,7 +661,7 @@ const PairAgentForm = ({ groups, onClose, onClaimed }) => {<div className="server-setup-form__body"><div className="pair-instructions"><p>- On the target machine run <code>serverkit-agent pair</code>. It prints a 6-character code — enter it below. Then supply the passphrase you chose when starting pairing.+ On the target machine, start the agent. It will display a 6-character pair code and a passphrase — enter both below.</p></div>@@ -670,7 +675,6 @@ const PairAgentForm = ({ groups, onClose, onClaimed }) => {setLookupResult(null);setLookupError('');}}- onBlur={handleLookup}placeholder="ABC-123"autoFocusautoComplete="off"@@ -703,7 +707,7 @@ const PairAgentForm = ({ groups, onClose, onClaimed }) => {type="password"value={passphrase}onChange={(e) => setPassphrase(e.target.value)}- placeholder="The passphrase set when pairing started"+ placeholder="Shown on the agent's pairing screen"autoComplete="new-password"required/>