Gitfed
bastien-mrq/gitfed / cmd / gitfed-web / handlers_security.go
package main

import (
	"bytes"
	"html/template"
	"net/http"

	"git.neuromancer.ovh/bastien-mrq/gitfed/internal/i18n"
)

var securityTpl = newTpl("security", `
<div class="sec-head">
  <span class="kicker">{{icon "lock"}} {{t .Lang "security.kicker"}}</span>
  <h1>{{t .Lang "security.h1"}}</h1>
  <p>{{t .Lang "security.lead"}}</p>
</div>

<section class="sec-section">
  <div class="tag">{{t .Lang "security.s1_tag"}}</div>
  <h2>{{icon "key"}} {{t .Lang "security.s1_h"}}</h2>
  <p>{{t .Lang "security.s1_p"}}</p>
  <div class="sec-diagram">
    <svg viewBox="0 0 460 110" xmlns="http://www.w3.org/2000/svg">
      <rect x="10" y="30" width="110" height="50" rx="4" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="65" y="59" text-anchor="middle" fill="var(--text)" font-size="11">{{t .Lang "security.s1_diagram_client"}}</text>
      <path d="M120 55h70" stroke="var(--ok-fg)" stroke-width="1.6" marker-end="url(#s-arr-ok)"/>
      <text x="155" y="45" text-anchor="middle" fill="var(--ok-fg)" font-size="9" font-family="monospace">SSH :2222</text>
      <rect x="190" y="10" width="150" height="90" rx="6" fill="var(--surface)" stroke="var(--border)"/>
      <text x="265" y="35" text-anchor="middle" fill="var(--text)" font-size="11" font-weight="700">gitfed-server</text>
      <rect x="205" y="48" width="120" height="24" rx="4" fill="var(--ok-bg)" stroke="var(--ok-fg)"/>
      <text x="265" y="64" text-anchor="middle" fill="var(--ok-fg)" font-size="9" font-family="monospace">{{t .Lang "security.s1_diagram_open"}}</text>
      <rect x="205" y="76" width="120" height="20" rx="4" fill="var(--danger-bg)" stroke="var(--danger-fg)" stroke-dasharray="3 3"/>
      <text x="265" y="90" text-anchor="middle" fill="var(--danger-fg)" font-size="8.5" font-family="monospace">{{t .Lang "security.s1_diagram_http"}}</text>
      <rect x="360" y="30" width="90" height="50" rx="4" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="405" y="53" text-anchor="middle" fill="var(--text)" font-size="10">{{t .Lang "security.s1_diagram_repos"}}</text>
      <text x="405" y="66" text-anchor="middle" fill="var(--text-dim)" font-size="9">bare git</text>
      <path d="M340 55h20" stroke="var(--border-strong)" stroke-width="1.6" marker-end="url(#s-arr-ok)"/>
      <defs><marker id="s-arr-ok" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--ok-fg)"/></marker></defs>
    </svg>
    <div class="cap">{{t .Lang "security.s1_caption"}}</div>
  </div>
</section>

<section class="sec-section">
  <div class="tag">{{t .Lang "security.s2_tag"}}</div>
  <h2>{{icon "shield"}} {{t .Lang "security.s2_h"}}</h2>
  <p>{{t .Lang "security.s2_p"}}</p>
  <div class="sec-diagram">
    <svg viewBox="0 0 520 190" xmlns="http://www.w3.org/2000/svg">
      <circle cx="60" cy="95" r="34" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="60" y="92" text-anchor="middle" fill="var(--text)" font-size="10" font-weight="700">alice</text>
      <text x="60" y="104" text-anchor="middle" fill="var(--text-dim)" font-size="8">{{t .Lang "security.s2_diagram_haskey"}}</text>
      <path d="M96 95h48" stroke="var(--accent)" stroke-width="1.5" marker-end="url(#s-arr-a)"/>
      <text x="120" y="86" text-anchor="middle" fill="var(--accent)" font-size="8" font-family="monospace">{{t .Lang "security.s2_diagram_step1"}}</text>
      <rect x="150" y="55" width="120" height="80" rx="6" fill="var(--surface)" stroke="var(--border)"/>
      <text x="210" y="78" text-anchor="middle" fill="var(--text)" font-size="10" font-weight="700">{{t .Lang "security.s2_diagram_alice_instance"}}</text>
      <text x="210" y="94" text-anchor="middle" fill="var(--text-dim)" font-size="8.5" font-family="monospace">{{t .Lang "security.s2_diagram_local_ca"}}</text>
      <rect x="170" y="102" width="80" height="20" rx="10" fill="rgba(108,157,245,0.12)" stroke="var(--accent)"/>
      <text x="210" y="116" text-anchor="middle" fill="var(--accent)" font-size="8" font-family="monospace">{{t .Lang "security.s2_diagram_signs"}}</text>
      <path d="M270 95h48" stroke="var(--accent)" stroke-width="1.5" marker-end="url(#s-arr-a)"/>
      <text x="294" y="86" text-anchor="middle" fill="var(--accent)" font-size="8" font-family="monospace">{{t .Lang "security.s2_diagram_step2"}}</text>
      <rect x="318" y="55" width="120" height="80" rx="6" fill="var(--surface)" stroke="var(--border)"/>
      <text x="378" y="78" text-anchor="middle" fill="var(--text)" font-size="10" font-weight="700">{{t .Lang "security.s2_diagram_bob_instance"}}</text>
      <text x="378" y="94" text-anchor="middle" fill="var(--text-dim)" font-size="8.5" font-family="monospace">{{t .Lang "security.s2_diagram_trust1"}}</text>
      <text x="378" y="106" text-anchor="middle" fill="var(--text-dim)" font-size="8.5" font-family="monospace">{{t .Lang "security.s2_diagram_trust2"}}</text>
      <path d="M438 95h30" stroke="var(--ok-fg)" stroke-width="1.5" marker-end="url(#s-arr-ok2)"/>
      <circle cx="488" cy="95" r="20" fill="var(--ok-bg)" stroke="var(--ok-fg)"/>
      <text x="488" y="99" text-anchor="middle" fill="var(--ok-fg)" font-size="9" font-weight="700">{{t .Lang "security.s2_diagram_access"}}</text>
      <text x="210" y="160" text-anchor="middle" fill="var(--text-faint)" font-size="8.5" font-family="monospace">{{t .Lang "security.s2_diagram_local1"}}</text>
      <text x="210" y="172" text-anchor="middle" fill="var(--text-faint)" font-size="8.5" font-family="monospace">{{t .Lang "security.s2_diagram_local2"}}</text>
      <defs>
        <marker id="s-arr-a" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--accent)"/></marker>
        <marker id="s-arr-ok2" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--ok-fg)"/></marker>
      </defs>
    </svg>
    <div class="cap">{{t .Lang "security.s2_caption"}}</div>
  </div>
</section>

<section class="sec-section">
  <div class="tag">{{t .Lang "security.s3_tag"}}</div>
  <h2>{{icon "network"}} {{t .Lang "security.s3_h"}}</h2>
  <p>{{t .Lang "security.s3_p"}}</p>
  <div class="sec-diagram">
    <svg viewBox="0 0 560 90" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="15" width="118" height="46" rx="6" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="59" y="34" text-anchor="middle" fill="var(--text)" font-size="9.5" font-weight="700">{{t .Lang "security.s3_diagram_unknown"}}</text>
      <text x="59" y="48" text-anchor="middle" fill="var(--text-dim)" font-size="8">{{t .Lang "security.s3_diagram_unknown_sub"}}</text>
      <path d="M118 38h34" stroke="var(--text-faint)" stroke-width="1.5" marker-end="url(#s-arr-g)"/>
      <rect x="152" y="15" width="118" height="46" rx="6" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="211" y="34" text-anchor="middle" fill="var(--text)" font-size="9.5" font-weight="700">{{t .Lang "security.s3_diagram_discovery"}}</text>
      <text x="211" y="48" text-anchor="middle" fill="var(--text-dim)" font-size="8">{{t .Lang "security.s3_diagram_discovery_sub"}}</text>
      <path d="M270 38h34" stroke="var(--pending-fg)" stroke-width="1.5" marker-end="url(#s-arr-y)"/>
      <rect x="304" y="15" width="118" height="46" rx="6" fill="var(--pending-bg)" stroke="var(--pending-fg)"/>
      <text x="363" y="34" text-anchor="middle" fill="var(--pending-fg)" font-size="9.5" font-weight="700">{{t .Lang "security.s3_diagram_pending"}}</text>
      <text x="363" y="48" text-anchor="middle" fill="var(--pending-fg)" font-size="8">{{t .Lang "security.s3_diagram_pending_sub"}}</text>
      <path d="M422 38h34" stroke="var(--ok-fg)" stroke-width="1.5" marker-end="url(#s-arr-g2)"/>
      <rect x="456" y="15" width="104" height="46" rx="6" fill="var(--ok-bg)" stroke="var(--ok-fg)"/>
      <text x="508" y="34" text-anchor="middle" fill="var(--ok-fg)" font-size="9.5" font-weight="700">{{t .Lang "security.s3_diagram_approved"}}</text>
      <text x="508" y="48" text-anchor="middle" fill="var(--ok-fg)" font-size="8">{{t .Lang "security.s3_diagram_approved_sub"}}</text>
      <defs>
        <marker id="s-arr-g" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--text-faint)"/></marker>
        <marker id="s-arr-y" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--pending-fg)"/></marker>
        <marker id="s-arr-g2" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--ok-fg)"/></marker>
      </defs>
    </svg>
  </div>
</section>

<section class="sec-section">
  <div class="tag">{{t .Lang "security.s4_tag"}}</div>
  <h2>{{icon "sliders"}} {{t .Lang "security.s4_h"}}</h2>
  <p>{{t .Lang "security.s4_p"}}</p>
  <div class="sec-facts">
    <div class="sec-fact">{{icon "check"}}<span><strong>{{t .Lang "security.s4_fact1_h"}}</strong> — {{t .Lang "security.s4_fact1_p"}}</span></div>
    <div class="sec-fact">{{icon "check"}}<span><strong>{{t .Lang "security.s4_fact2_h"}}</strong> — {{t .Lang "security.s4_fact2_p"}}</span></div>
    <div class="sec-fact">{{icon "check"}}<span><strong>{{t .Lang "security.s4_fact3_h"}}</strong> — {{t .Lang "security.s4_fact3_p"}}</span></div>
    <div class="sec-fact">{{icon "check"}}<span><strong>{{t .Lang "security.s4_fact4_h"}}</strong> — {{t .Lang "security.s4_fact4_p"}}</span></div>
  </div>
</section>
`)

func (s *server) handleSecurity(w http.ResponseWriter, r *http.Request) {
	lang := s.lang(r)
	var buf bytes.Buffer
	_ = securityTpl.Execute(&buf, struct{ Lang string }{string(lang)})
	s.render(w, r, i18n.T(lang, "security.title"), "security", template.HTML(buf.String()))
}