Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<first-menu v-if="firstMenuItem !== 'clickhouse'">
<menu-item href="/db">所有节点</menu-item>
<span class="item disabled">|</span>
<menu-item :href="'/db/node?nodeId=' + node.id" code="node">"{{node.name}}"详情</menu-item>
<menu-item :href="'/db/clean?nodeId=' + node.id" code="clean">清理</menu-item>
<menu-item :href="'/db/logs?nodeId=' + node.id" code="log">运行日志</menu-item>
<menu-item :href="'/db/update?nodeId=' + node.id" code="update">修改</menu-item>
</first-menu>

View File

@@ -0,0 +1,26 @@
{$layout}
{$template "menu"}
<div class="ui message" v-if="isLoading">正在加载中...</div>
<table class="ui table selectable">
<thead>
<tr>
<th>表名</th>
<th>占用空间</th>
<th>用途</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="table in tables">
<td>{{table.name}}</td>
<td>{{table.size}}
<span class="grey small" v-if="table.rows > 0">{{table.rows}}行)</span>
</td>
<td>{{table.comment}}</td>
<td>
<a href="" v-if="table.canDelete" @click.prevent="deleteTable(table.name)">删除</a><span v-if="table.canDelete"> &nbsp;</span>
<a href="" v-if="table.canClean" @click.prevent="truncateTable(table.name)">清空</a>
</td>
</tr>
</table>

View File

@@ -0,0 +1,52 @@
Tea.context(function () {
this.tables = []
this.isLoading = true
this.$delay(function () {
this.reload()
})
this.reload = function () {
this.isLoading = true
this.$post("$")
.params({ nodeId: this.nodeId })
.success(function (resp) {
this.tables = resp.data.tables;
})
.done(function () {
this.isLoading = false
})
}
this.deleteTable = function (tableName) {
let that = this
teaweb.confirm("html:确定要删除此数据表吗?<br/>删除后数据不能恢复!", function () {
that.$post(".deleteTable")
.params({
nodeId: that.nodeId,
table: tableName
})
.success(function () {
teaweb.success("操作成功", function () {
that.reload()
})
})
})
}
this.truncateTable = function (tableName) {
let that = this
teaweb.confirm("html:确定要清空此数据表吗?<br/>清空后数据不能恢复!", function () {
that.$post(".truncateTable")
.params({
nodeId: that.nodeId,
table: tableName
})
.success(function () {
teaweb.success("操作成功", function () {
that.reload()
})
})
})
}
})

View File

@@ -0,0 +1,76 @@
{$layout}
{$template "menu"}
<div style="display:flex;align-items:baseline;gap:0.8em;margin-bottom:0.5em">
<h3 style="margin:0">ClickHouse 配置</h3>
<span v-if="connStatus === 'connected'" class="ui label green tiny" style="vertical-align:baseline">
<i class="icon circle" style="margin-right:0.25em"></i>已连接
</span>
<span v-else-if="connStatus === 'disconnected'" class="ui label red tiny" style="vertical-align:baseline"
:title="connError">
<i class="icon circle" style="margin-right:0.25em"></i>已断开
</span>
<span v-else class="ui label grey tiny" style="vertical-align:baseline">
<i class="icon circle outline" style="margin-right:0.25em"></i>未配置
</span>
</div>
<p class="comment">配置后,需要在网站列表-日志策略中创建"文件+ClickHouse"的策略才能将访问日志绕过api组件直接由边缘节点发送给ClickHouse。</p>
<form method="post" class="ui form" @submit.prevent="onSubmit">
<csrf-token></csrf-token>
<table class="ui table definition selectable">
<tr>
<td class="title">连接地址Host</td>
<td>
<input type="text" name="host" maxlength="200" ref="focus"
placeholder="如 127.0.0.1 或 clickhouse.example.com" v-model="form.host" />
<p class="comment">ClickHouse 服务器地址。</p>
</td>
</tr>
<tr>
<td>协议Scheme</td>
<td>
<select name="scheme" class="ui dropdown auto-width" v-model="form.scheme">
<option value="http">HTTP</option>
<option value="https">HTTPS</option>
</select>
<p class="comment">默认 HTTPS当前后台固定跳过证书校验。</p>
</td>
</tr>
<tr>
<td>端口Port</td>
<td>
<input type="number" name="port" min="1" max="65535" style="width:6em" v-model.number="form.port" />
<p class="comment">接口端口默认 8443HTTPS请与 ClickHouse 实际开放端口保持一致。</p>
</td>
</tr>
<tr>
<td>用户名User</td>
<td>
<input type="text" name="user" maxlength="100" v-model="form.user" />
</td>
</tr>
<tr>
<td>密码Password</td>
<td>
<input type="password" name="password" maxlength="200" placeholder="不修改请留空" v-model="form.password" />
<p class="comment">留空则不修改已保存的密码。</p>
</td>
</tr>
<tr>
<td>数据库名Database</td>
<td>
<input type="text" name="database" maxlength="100" placeholder="default" v-model="form.database" />
<p class="comment">logs_ingest 表所在库,默认 default。</p>
</td>
</tr>
</table>
<div style="display:flex; align-items:center; gap:0.5em; margin-top:1em">
<submit-btn></submit-btn>
<button type="button" class="ui button basic blue" @click="testConnection" :disabled="isTesting">
<i :class="isTesting ? 'icon spinner loading' : 'icon plug'"></i> 测试连接
</button>
<span v-if="testResult"
:style="{color: testOk ? '#21ba45' : '#db2828', fontWeight:'bold'}">{{testResult}}</span>
</div>
</form>

View File

@@ -0,0 +1,76 @@
Tea.context(function () {
var config = this.config || {}
this.form = {
host: config.host || "",
scheme: config.scheme || "https",
port: config.port > 0 ? config.port : 8443,
user: config.user || "",
password: "",
database: config.database || "default",
}
this.isTesting = false
this.testResult = ""
this.testOk = false
// 页面加载时的连接状态(后端自动检测)
this.connStatus = this.connStatus || "unconfigured"
this.connError = this.connError || ""
this.success = function () {
teaweb.success("保存成功")
}
this.onSubmit = function (e) {
e.preventDefault()
e.stopPropagation()
Tea.action("$").post().form(e.target).success(function () {
Tea.Vue.success()
})
}
this.testConnection = function () {
var that = Tea.Vue
that.isTesting = true
that.testResult = ""
var form = document.querySelector("form")
var fd = new FormData(form)
fd.set("host", that.form.host || "")
fd.set("scheme", that.form.scheme || "https")
fd.set("port", String(that.form.port > 0 ? that.form.port : 8443))
fd.set("user", that.form.user || "")
fd.set("password", that.form.password || "")
fd.set("database", that.form.database || "default")
var xhr = new XMLHttpRequest()
xhr.open("POST", Tea.url("/db/testClickhouse"), true)
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
xhr.timeout = 10000
xhr.onload = function () {
that.isTesting = false
try {
var resp = JSON.parse(xhr.responseText)
if (resp.code === 200) {
that.testOk = true
that.testResult = "✅ 连接成功"
} else {
that.testOk = false
that.testResult = "❌ " + (resp.message || "连接失败")
}
} catch (e) {
that.testOk = false
that.testResult = "❌ 响应解析失败"
}
}
xhr.onerror = function () {
that.isTesting = false
that.testOk = false
that.testResult = "❌ 网络请求失败"
}
xhr.ontimeout = function () {
that.isTesting = false
that.testOk = false
that.testResult = "❌ 请求超时"
}
xhr.send(fd)
}
})

View File

@@ -0,0 +1,71 @@
{$layout "layout_popup"}
<h3>添加节点</h3>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<table class="ui table definition selectable">
<tr>
<td class="title">节点名称 *</td>
<td>
<input type="text" name="name" maxlength="100" ref="focus"/>
<p class="comment">给节点起一个容易识别的名称。</p>
</td>
</tr>
<tr>
<td>主机地址<em>Host</em> *</td>
<td>
<input type="text" name="host" placeholder="" maxlength="100"/>
<p class="comment">连接数据库的主机地址通常是域名或者IP出于性能考虑请使用局域网内的数据库。</p>
</td>
</tr>
<tr>
<td>数据库端口<em>Port</em> *</td>
<td>
<input type="text" name="port" value="3306" maxlength="5" style="width:6em"/>
<p class="comment">连接数据库的端口。</p>
</td>
</tr>
<tr>
<td>数据库名称<em>Database</em> *</td>
<td>
<input type="text" name="database" value="" maxlength="100" placeholder="比如 edge_logs"/>
<p class="comment">要写入日志的数据库名称需要事先创建好而且需要有创建新表和读写数据的权限。建议命名为edge_logs。</p>
</td>
</tr>
<tr>
<td>用户名<em>Username</em> *</td>
<td>
<input type="text" name="username" value=""/>
<p class="comment">连接数据库的用户名。</p>
</td>
</tr>
<tr>
<td>密码<em>Password</em></td>
<td>
<input type="password" name="password" value=""/>
<p class="comment">连接数据库的密码。</p>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>详细描述</td>
<td>
<textarea rows="3" name="description"></textarea>
</td>
</tr>
<tr>
<td>启用当前数据库</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="isOn" value="1" checked="checked"/>
<label></label>
</div>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,49 @@
{$layout}
<first-menu>
<a href="" class="item" @click.prevent="createNode()">[添加节点]</a>
</first-menu>
<p class="comment" v-if="nodes.length == 0">暂时还没有数据库节点。</p>
<table class="ui table selectable celled" v-if="nodes.length > 0">
<thead>
<tr>
<th>节点名称</th>
<th>连接地址</th>
<th>数据库名</th>
<th>数据库版本</th>
<th>用量</th>
<th class="center width10">状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="node in nodes">
<td><a :href="'/db/node?nodeId=' + node.id">{{node.name}}</a></td>
<td>{{node.host}}:{{node.port}}</td>
<td>{{node.database}}</td>
<td>
<span v-if="node.status.version.length > 0">v{{node.status.version}}</span>
<span class="disabled" v-else>-</span>
</td>
<td>
<span v-if="node.status.isOk">{{node.status.size}}</span>
<span v-else class="disabled">-</span>
</td>
<td class="center">
<div v-if="node.isOn">
<span v-if="node.status.isOk" class="green">连接正常</span>
<a href="" title="点击查看具体错误" v-else @click.prevent="showError(node.status.error)"><span class="red" style="border-bottom: 1px #db2828 dashed">连接错误</span></a>
</div>
<span v-else>
<label-on :v-is-on="node.isOn"></label-on>
</span>
</td>
<td>
<a :href="'/db/node?nodeId=' + node.id">详情</a>
<a href="" @click.prevent="deleteNode(node.id)">删除</a>
</td>
</tr>
</table>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,30 @@
Tea.context(function () {
// 添加节点
this.createNode = function () {
teaweb.popup("/db/createPopup", {
height: "30em",
callback: function () {
teaweb.success("保存成功", function () {
window.location.reload()
})
}
})
}
// 删除节点
this.deleteNode = function (nodeId) {
let that = this
teaweb.confirm("确定要删除此数据库节点吗?", function () {
that.$post(".delete")
.params({
nodeId: nodeId
})
.refresh()
})
}
// 显示错误信息
this.showError = function (err) {
teaweb.popupTip("<span style=\"color:#db2828\">错误信息:" + err + "</span>")
}
})

View File

@@ -0,0 +1,5 @@
pre.log-box {
margin: 0;
padding: 0;
}
/*# sourceMappingURL=logs.css.map */

View File

@@ -0,0 +1 @@
{"version":3,"sources":["logs.less"],"names":[],"mappings":"AAAA,GAAG;EACF,SAAA;EACA,UAAA","file":"logs.css"}

View File

@@ -0,0 +1,51 @@
{$layout}
{$template "menu"}
{$template "/datepicker"}
<div class="margin"></div>
<form method="get" action="/db/logs" class="ui form" autocomplete="off">
<input type="hidden" name="nodeId" :value="nodeId"/>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="dayFrom" placeholder="开始日期" v-model="dayFrom" value="" style="width:8em" id="day-from-picker"/>
</div>
<div class="ui field">
<input type="text" name="dayTo" placeholder="结束日期" v-model="dayTo" value="" style="width:8em" id="day-to-picker"/>
</div>
<div class="ui field">
<select class="ui dropdown" name="level" v-model="level">
<option value="">[级别]</option>
<option value="error">错误</option>
<option value="warning">警告</option>
<option value="info">信息</option>
<option value="success">成功</option>
</select>
</div>
<div class="ui field">
<input type="text" name="keyword" style="width:10em" v-model="keyword" placeholder="关键词"/>
</div>
<div class="ui field">
<button type="submit" class="ui button">查询</button>
</div>
<div class="ui field" v-if="dayFrom.length > 0 || dayTo.length > 0 || keyword.length > 0 || level.length > 0">
<a :href="'/db/logs?nodeId=' + nodeId">[清除条件]</a>
</div>
</div>
</form>
<p class="comment" v-if="logs.length == 0">暂时还没有日志。</p>
<table class="ui table selectable" v-if="logs.length > 0">
<thead>
<tr>
</tr>
</thead>
<tr v-for="log in logs">
<td>
<node-log-row :v-log="log" :v-keyword="keyword"></node-log-row>
</td>
</tr>
</table>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,6 @@
Tea.context(function () {
this.$delay(function () {
teaweb.datepicker("day-from-picker")
teaweb.datepicker("day-to-picker")
})
})

View File

@@ -0,0 +1,4 @@
pre.log-box {
margin: 0;
padding: 0;
}

View File

@@ -0,0 +1,68 @@
{$layout}
{$template "menu"}
<table class="ui table definition selectable">
<tr>
<td class="title">节点名称</td>
<td>
{{node.name}}
</td>
</tr>
<tr>
<td>状态</td>
<td>
<label-on :v-is-on="node.isOn"></label-on>
<div v-if="node.isOn && status != null" style="margin-top: 0.8em">
<div v-if="status.isOk">
<p class="comment">
<span v-if="status.version.length > 0">版本: v{{status.version}} /</span>
<span v-if="status.isOk">用量:{{status.size}}</span>
<span v-else class="disabled">-</span>
</p>
</div>
<div v-else>
<span class="red">连接错误:{{status.error}}</span>
</div>
</div>
</td>
</tr>
<tr>
<td>主机地址<em>Host</em></td>
<td>
{{node.host}}
</td>
</tr>
<tr>
<td>数据库端口<em>Port</em></td>
<td>
{{node.port}}
</td>
</tr>
<tr>
<td>数据库名称<em>Database</em></td>
<td>
{{node.database}}
</td>
</tr>
<tr>
<td>用户名<em>Username</em></td>
<td>
{{node.username}}
</td>
</tr>
<tr>
<td>密码<em>Password</em></td>
<td>
<span v-if="node.password.length > 0">{{node.password}}</span>
<span v-else class="disabled">-</span>
</td>
</tr>
<tr>
<td>详细描述</td>
<td>
<span v-if="node.description.length > 0">{{node.description}}</span>
<span v-else class="disabled">-</span>
</td>
</tr>
</table>

View File

@@ -0,0 +1,16 @@
Tea.context(function () {
this.$delay(function () {
this.loadStatus(this.node.id)
})
this.status = null
this.loadStatus = function (nodeId) {
this.$post(".status")
.params({
nodeId: nodeId
})
.success(function (resp) {
this.status = resp.data.status
})
}
})

View File

@@ -0,0 +1,71 @@
{$layout}
{$template "menu"}
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="nodeId" :value="node.id"/>
<table class="ui table definition selectable">
<tr>
<td class="title">节点名称 *</td>
<td>
<input type="text" name="name" maxlength="100" ref="focus" v-model="node.name"/>
<p class="comment">给节点起一个容易识别的名称。</p>
</td>
</tr>
<tr>
<td>主机地址<em>Host</em> *</td>
<td>
<input type="text" name="host" placeholder="" maxlength="100" v-model="node.host"/>
<p class="comment">连接数据库的主机地址通常是域名或者IP出于性能考虑请使用局域网内的数据库。</p>
</td>
</tr>
<tr>
<td>数据库端口<em>Port</em> *</td>
<td>
<input type="text" name="port" value="" maxlength="5" style="width:6em" v-model="node.port"/>
<p class="comment">连接数据库的端口。</p>
</td>
</tr>
<tr>
<td>数据库名称<em>Database</em> *</td>
<td>
<input type="text" name="database" value="" maxlength="100" placeholder="比如 edge_logs" v-model="node.database"/>
<p class="comment">要写入日志的数据库名称需要事先创建好而且需要有创建新表和读写数据的权限。建议命名为edge_logs。</p>
</td>
</tr>
<tr>
<td>用户名<em>Username</em> *</td>
<td>
<input type="text" name="username" value="" v-model="node.username"/>
<p class="comment">连接数据库的用户名。</p>
</td>
</tr>
<tr>
<td>密码<em>Password</em></td>
<td>
<input type="password" name="password" value="" v-model="node.password"/>
<p class="comment">连接数据库的密码。</p>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>详细描述</td>
<td>
<textarea rows="3" name="description" v-model="node.description"></textarea>
</td>
</tr>
<tr>
<td>启用当前数据库</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="isOn" value="1" v-model="node.isOn"/>
<label></label>
</div>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifySuccess("保存成功", "/db/node?nodeId=" + this.node.id)
})