Files
moloapp/example/app/Templates.cpp
T
retoor 0595284fe3 feat(doos): add container runtime, audit cases, example demo and tests
- New rootless doos container runtime: sandbox, cgroup, network, images, hardening, davmount, CLI plus molo integration
- 18 CVE audit reproductions with READMEs and Makefiles
- Example DoosDemo routes, IndexCatalog, static assets, spec update
- CLI serve on 0.0.0.0:8000, arg parser, dev server improvements
- Runtime HTTP fixes, supervisor isolation backend
- Tests for doos, example doos routes, CLI serve; suite count 261 to 265
2026-11-06 04:36:00 +01:00

235 lines
9.3 KiB
C++

#include "App.hpp"
#include "../fw/Templates.hpp"
namespace molo::example::app {
namespace {
const char kBase[] = R"BASE(<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ title }}</title>
<link rel="stylesheet" href="/static/app.css">
</head>
<body>
<header class="topbar">
<a class="brand" href="/">{{ site }}</a>
<nav class="nav-wide">
<a href="/">Index</a>
<a href="/templates/page">Templates</a>
<a href="/forms/contact">Forms</a>
<a href="/stats">Stats</a>
<a href="/voice">Voice</a>
<a href="/docs">Docs</a>
<a href="/health">Health</a>
</nav>
<details class="nav-narrow">
<summary>Menu</summary>
<nav>
<a href="/">Index</a>
<a href="/templates/page">Templates</a>
<a href="/forms/contact">Forms</a>
<a href="/stats">Stats</a>
<a href="/voice">Voice</a>
<a href="/docs">Docs</a>
<a href="/health">Health</a>
</nav>
</details>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer><p>{{ site }}: living example, {{ backend }}</p></footer>
</body>
</html>
)BASE";
const char kIndex[] = R"INDEX({% extends "base.html" %}
{% block content %}
<h1>Living example</h1>
<p>{{ feature_count }} features in {{ group_count }} groups, each one click away.
Every row is a live route with a test behind it. Mobile-first: narrow the
window and the top nav collapses into a dropdown menu.</p>
<p class="filter"><input id="filter" type="search" placeholder="Filter features" aria-label="Filter features" autocomplete="off"></p>
{{ sections|safe }}
{% include "nav_hint.html" %}
<script src="/static/index.js" defer></script>
{% endblock %}
)INDEX";
const char kPage[] = R"PAGE({% extends "base.html" %}
{% block content %}
<h1>{{ heading }}</h1>
<p>Author: {{ author|upper }}</p>
<p>Raw (escaped): {{ snippet }}</p>
<p>Trusted (safe): {{ snippet|safe }}</p>
<ul>
{% for item in items %}
<li>{{ item.name }} ({{ item.kind }})</li>
{% endfor %}
</ul>
{% endblock %}
)PAGE";
const char kFormPage[] = R"FORM({% extends "base.html" %}
{% block content %}
<h1>{{ title }}</h1>
{% if notice %}<p class="ok" role="status">{{ notice }}</p>{% endif %}
{% if error_count %}
<div class="form-errors" role="alert">
<h2>Please fix {{ error_count }} field(s) and send again</h2>
<ul>
{% for e in errors %}
<li><a href="#f-{{ e.name }}">{{ e.label }}</a> {{ e.message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if done %}{% else %}
<form method="post" action="{{ action }}" novalidate>
{% for f in fields %}
<div class="field{% if f.invalid %} invalid{% endif %}">
<label for="f-{{ f.name }}">{{ f.label }}</label>
{% if f.textarea %}
<textarea id="f-{{ f.name }}" name="{{ f.name }}"{% if f.invalid %} aria-invalid="true" aria-describedby="e-{{ f.name }}"{% endif %}>{{ f.value }}</textarea>
{% else %}
<input id="f-{{ f.name }}" type="{{ f.type }}" name="{{ f.name }}" value="{{ f.value }}"{% if f.invalid %} aria-invalid="true" aria-describedby="e-{{ f.name }}"{% endif %}>
{% endif %}
{% if f.hint %}<span class="hint">{{ f.hint }}</span>{% endif %}
{% if f.error %}<p class="field-error" id="e-{{ f.name }}">{{ f.error }}</p>{% endif %}
</div>
{% endfor %}
<button type="submit">{{ submit }}</button>
</form>
{% endif %}
{% endblock %}
)FORM";
const char kStats[] = R"STATS({% extends "base.html" %}
{% block content %}
<h1>Statistics</h1>
<p class="hint">HTTP requests, connections, and service state of this running
server. History is 15 minutes in 10 second buckets. The server stops accepting
after its connection cap, so auto refresh is off by default.</p>
<div class="toolbar">
<button type="button" id="refresh">Refresh</button>
<label class="inline"><input type="checkbox" id="auto"> Auto refresh (5 s)</label>
<span class="hint" id="t-updated">loading...</span>
</div>
<section class="tiles" aria-label="Summary">
<div class="tile"><span class="k">Uptime</span><span class="v" id="t-uptime">-</span></div>
<div class="tile"><span class="k">Requests</span><span class="v" id="t-requests">-</span></div>
<div class="tile"><span class="k">Errors</span><span class="v" id="t-errors">-</span></div>
<div class="tile"><span class="k">Avg latency</span><span class="v" id="t-avg">-</span></div>
<div class="tile"><span class="k">p95 latency</span><span class="v" id="t-p95">-</span></div>
<div class="tile"><span class="k">p99 latency</span><span class="v" id="t-p99">-</span></div>
<div class="tile"><span class="k">Bytes in</span><span class="v" id="t-in">-</span></div>
<div class="tile"><span class="k">Bytes out</span><span class="v" id="t-out">-</span></div>
<div class="tile"><span class="k">Connections</span><span class="v" id="t-conn">-</span></div>
<div class="tile"><span class="k">Active</span><span class="v" id="t-active">-</span></div>
<div class="tile"><span class="k">Timeouts / malformed</span><span class="v" id="t-timeouts">-</span></div>
<div class="tile"><span class="k">Connections left (cap)</span><span class="v" id="t-left">-</span></div>
</section>
<h2>Traffic</h2>
<div class="grid">
<figure class="chart"><figcaption>Requests and errors per 10 s</figcaption><div class="plot"><canvas id="c-requests"></canvas></div></figure>
<figure class="chart"><figcaption>Average latency per 10 s</figcaption><div class="plot"><canvas id="c-latency"></canvas></div></figure>
<figure class="chart"><figcaption>Bytes in and out per 10 s</figcaption><div class="plot"><canvas id="c-bytes"></canvas></div></figure>
<figure class="chart"><figcaption>Connections opened per 10 s</figcaption><div class="plot"><canvas id="c-conns"></canvas></div></figure>
</div>
<h2>Requests</h2>
<div class="grid">
<figure class="chart"><figcaption>Status codes</figcaption><div class="plot"><canvas id="c-status"></canvas></div></figure>
<figure class="chart"><figcaption>Methods</figcaption><div class="plot"><canvas id="c-methods"></canvas></div></figure>
<figure class="chart"><figcaption>Latency distribution</figcaption><div class="plot"><canvas id="c-hist"></canvas></div></figure>
<figure class="chart"><figcaption>Top routes</figcaption><div class="plot"><canvas id="c-routes"></canvas></div></figure>
</div>
<div class="scroll"><table id="tbl-routes"></table></div>
<h2>Services</h2>
<div class="grid">
<figure class="chart"><figcaption>Store sizes</figcaption><div class="plot tall"><canvas id="c-stores"></canvas></div></figure>
<figure class="chart"><figcaption>Cache hits and misses</figcaption><div class="plot"><canvas id="c-cache"></canvas></div></figure>
<figure class="chart"><figcaption>Tasks by state</figcaption><div class="plot"><canvas id="c-tasks"></canvas></div></figure>
<figure class="chart"><figcaption>ORM tables and rows</figcaption><div class="plot"><canvas id="c-orm"></canvas></div></figure>
</div>
<div class="scroll"><table id="tbl-workers"></table></div>
<div class="scroll"><table id="tbl-metrics"></table></div>
<script src="/embedded/chart.umd.min.js"></script>
<script src="/embedded/stats.js"></script>
{% endblock %}
)STATS";
const char kVoice[] = R"VOICE({% extends "base.html" %}
{% block content %}
<h1>Voice conversation</h1>
<p class="hint">Talk, pause, and the assistant answers out loud. Google
speech-to-text, Gemini, and Google text-to-speech run on the server.
Speak over the answer to interrupt it.</p>
<p id="v-config" class="hint">Checking Google credentials...</p>
<section class="voice">
<div class="voice-controls">
<button id="v-toggle" type="button" class="primary" disabled>Start conversation</button>
<label class="inline">Language
<select id="v-lang">
<option value="nl-NL">Nederlands</option>
<option value="en-US">English</option>
<option value="de-DE">Deutsch</option>
</select></label>
</div>
<div class="voice-state"><span id="v-state" class="pill">idle</span>
<div class="meter"><div id="v-level"></div></div></div>
<p id="v-error" class="error" role="alert"></p>
<ol id="v-log" class="voice-log"></ol>
<form id="v-form" class="voice-form">
<input id="v-text" type="text" maxlength="500" placeholder="Or type a message" autocomplete="off">
<button type="submit">Send</button>
<button id="v-reset" type="button">Reset</button>
</form>
</section>
<script src="/embedded/voice.js"></script>
{% endblock %}
)VOICE";
const char kDocs[] = R"DOCS({% extends "base.html" %}
{% block content %}
<h1>API docs</h1>
<p>OpenAPI JSON: <a href="/openapi.json">/openapi.json</a></p>
<ul>
{% for row in routes %}
<li><code>{{ row.method }} {{ row.path }}</code> : {{ row.summary }}</li>
{% endfor %}
</ul>
{% endblock %}
)DOCS";
const char kError[] = R"ERROR({% extends "base.html" %}
{% block content %}
<h1>Error {{ status }}</h1>
<p>{{ message }}</p>
{% endblock %}
)ERROR";
const char kNavHint[] =
"<p class=\"hint\">Tip: this page works on a 360px phone.</p>\n";
} // namespace
void load_templates(Services& services) {
services.templates->add_template("base.html", kBase);
services.templates->add_template("index.html", kIndex);
services.templates->add_template("page.html", kPage);
services.templates->add_template("form_page.html", kFormPage);
services.templates->add_template("docs.html", kDocs);
services.templates->add_template("voice.html", kVoice);
services.templates->add_template("stats.html", kStats);
services.templates->add_template("error.html", kError);
services.templates->add_template("nav_hint.html", kNavHint);
services.templates->add_global("site", "MoloApp living example");
services.templates->add_global("backend", "skeleton");
}
} // namespace molo::example::app