文件清理

This commit is contained in:
robin
2026-02-14 17:12:38 +08:00
parent f38505e210
commit 4259026c6e
22 changed files with 152 additions and 63 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"strings"
"sync" "sync"
"time" "time"
) )
@@ -126,6 +127,7 @@ func (this *StorageManager) Loop() error {
continue continue
} }
} }
this.applyFileStorageFallback(policy.Type, storage)
storage.SetVersion(types.Int(policy.Version)) storage.SetVersion(types.Int(policy.Version))
storage.SetFirewallOnly(policy.FirewallOnly == 1) storage.SetFirewallOnly(policy.FirewallOnly == 1)
@@ -143,6 +145,7 @@ func (this *StorageManager) Loop() error {
remotelogs.Error("ACCESS_LOG_STORAGE_MANAGER", "create policy '"+types.String(policyId)+"' failed: "+err.Error()) remotelogs.Error("ACCESS_LOG_STORAGE_MANAGER", "create policy '"+types.String(policyId)+"' failed: "+err.Error())
continue continue
} }
this.applyFileStorageFallback(policy.Type, storage)
storage.SetVersion(types.Int(policy.Version)) storage.SetVersion(types.Int(policy.Version))
storage.SetFirewallOnly(policy.FirewallOnly == 1) storage.SetFirewallOnly(policy.FirewallOnly == 1)
this.storageMap[policyId] = storage this.storageMap[policyId] = storage
@@ -238,3 +241,20 @@ func (this *StorageManager) createStorage(storageType string, optionsJSON []byte
return nil, errors.New("invalid policy type '" + storageType + "'") return nil, errors.New("invalid policy type '" + storageType + "'")
} }
func (this *StorageManager) applyFileStorageFallback(policyType string, storage StorageInterface) {
if !serverconfigs.IsFileBasedStorageType(policyType) {
return
}
config, ok := storage.Config().(*serverconfigs.AccessLogFileStorageConfig)
if !ok || config == nil || strings.TrimSpace(config.Path) != "" {
return
}
// file_clickhouse / file_mysql_clickhouse 未填写 path 时回退到默认文件路径,避免启动失败。
if policyType == serverconfigs.AccessLogStorageTypeFileClickhouse || policyType == serverconfigs.AccessLogStorageTypeFileMySQLClickhouse {
config.Path = Tea.Root + "/logs/access-${date}.log"
config.AutoCreate = true
}
}

View File

@@ -17773,7 +17773,7 @@ Vue.component("http-hls-config-box", {
<table class="ui table definition selectable" v-show="isOn()"> <table class="ui table definition selectable" v-show="isOn()">
<tbody> <tbody>
<tr> <tr>
<td class="title">启用HLS加密</td> <td class="title">启用HLS加密配置</td>
<td> <td>
<checkbox v-model="encryptingConfig.isOn"></checkbox> <checkbox v-model="encryptingConfig.isOn"></checkbox>
<p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p> <p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p>
@@ -17806,6 +17806,7 @@ Vue.component("http-hls-config-box", {
</div>` </div>`
}) })
Vue.component("http-host-redirect-box", { Vue.component("http-host-redirect-box", {
props: ["v-redirects"], props: ["v-redirects"],
mounted: function () { mounted: function () {

View File

@@ -17773,7 +17773,7 @@ Vue.component("http-hls-config-box", {
<table class="ui table definition selectable" v-show="isOn()"> <table class="ui table definition selectable" v-show="isOn()">
<tbody> <tbody>
<tr> <tr>
<td class="title">启用HLS加密</td> <td class="title">启用HLS加密配置</td>
<td> <td>
<checkbox v-model="encryptingConfig.isOn"></checkbox> <checkbox v-model="encryptingConfig.isOn"></checkbox>
<p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p> <p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p>
@@ -17806,6 +17806,7 @@ Vue.component("http-hls-config-box", {
</div>` </div>`
}) })
Vue.component("http-host-redirect-box", { Vue.component("http-host-redirect-box", {
props: ["v-redirects"], props: ["v-redirects"],
mounted: function () { mounted: function () {

View File

@@ -43,7 +43,7 @@ Vue.component("http-hls-config-box", {
<table class="ui table definition selectable" v-show="isOn()"> <table class="ui table definition selectable" v-show="isOn()">
<tbody> <tbody>
<tr> <tr>
<td class="title">启用HLS加密</td> <td class="title">启用HLS加密配置</td>
<td> <td>
<checkbox v-model="encryptingConfig.isOn"></checkbox> <checkbox v-model="encryptingConfig.isOn"></checkbox>
<p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p> <p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p>
@@ -74,4 +74,4 @@ Vue.component("http-hls-config-box", {
</table> </table>
<div class="margin"></div> <div class="margin"></div>
</div>` </div>`
}) })

View File

@@ -6,9 +6,8 @@
<table class="ui table celled selectable" v-if="policies.length > 0"> <table class="ui table celled selectable" v-if="policies.length > 0">
<thead> <thead>
<tr> <tr>
<th>策略名称</th> <th style="width: 14em;">策略名称</th>
<th class="three op">类型</th> <th class="op" style="width: 12em; white-space: nowrap;">类型</th>
<th>主要参数</th>
<th class="two wide">状态</th> <th class="two wide">状态</th>
<th class="two op">操作</th> <th class="two op">操作</th>
</tr> </tr>
@@ -21,19 +20,7 @@
<span class="ui label tiny basic" v-if="policy.disableDefaultDB">停用默认数据库</span> <span class="ui label tiny basic" v-if="policy.disableDefaultDB">停用默认数据库</span>
</div> </div>
</td> </td>
<td>{{policy.typeName}}</td> <td style="white-space: nowrap;">{{policy.typeName}}</td>
<td>
<span v-if="policy.options == null" class="disabled">-</span>
<span v-else-if="policy.type == 'es'">Endpoint: {{policy.options.endpoint}}</span>
<span v-else-if="policy.type == 'file'">文件路径:{{policy.options.path}}</span>
<span v-else-if="policy.type == 'tcp'">网络地址:{{policy.options.addr}}</span>
<span v-else-if="policy.type == 'command'">可执行命令:{{policy.options.command}}</span>
<span v-else-if="policy.type == 'syslog'">
<span v-if="policy.options.protocol == 'tcp'">TCP {{policy.options.serverAddr}}</span>
<span v-if="policy.options.protocol == 'udp'">UDP {{policy.options.serverAddr}}</span>
<span v-if="policy.options.protocol == 'socket'">SOCK {{policy.options.socket}}</span>
</span>
</td>
<td> <td>
<label-on :v-is-on="policy.isOn"></label-on> <label-on :v-is-on="policy.isOn"></label-on>
</td> </td>
@@ -43,4 +30,4 @@
</tr> </tr>
</table> </table>
<div class="page" v-html="page"></div> <div class="page" v-html="page"></div>

View File

@@ -1,3 +1,3 @@
<first-menu> <first-menu>
<menu-item code="hls" :href="'.hls?serverId=' + server.id">HLS</menu-item> <menu-item code="hls" :href="'.hls?serverId=' + server.id">启用HLS加密配</menu-item>
</first-menu> </first-menu>

View File

@@ -10,11 +10,9 @@
<form class="ui form" data-tea-success="success" data-tea-action="$"> <form class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token> <csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId"/> <input type="hidden" name="webId" :value="webId"/>
<h4>HLS加密设置</h4>
<http-hls-config-box v-model="hlsConfig" :v-is-location="true"></http-hls-config-box> <http-hls-config-box v-model="hlsConfig" :v-is-location="true"></http-hls-config-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>
</div> </div>

View File

@@ -1,3 +1,3 @@
<first-menu> <first-menu>
<menu-item code="hls" :href="'.hls?serverId=' + server.id">HLS</menu-item> <menu-item code="hls" :href="'.hls?serverId=' + server.id">启用HLS加密配</menu-item>
</first-menu> </first-menu>

View File

@@ -3,14 +3,12 @@
{$template "/left_menu_with_menu"} {$template "/left_menu_with_menu"}
<div class="right-box with-menu"> <div class="right-box with-menu">
{$template "menu"}
<form class="ui form" data-tea-success="success" data-tea-action="$"> <form class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token> <csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId"/> <input type="hidden" name="webId" :value="webId"/>
<h4>HLS加密设置</h4>
<http-hls-config-box v-model="hlsConfig"></http-hls-config-box> <http-hls-config-box v-model="hlsConfig"></http-hls-config-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>

View File

@@ -1 +0,0 @@
G!Dg

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 226 KiB

View File

@@ -5,6 +5,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ossconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ossconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
@@ -14,6 +15,7 @@ import (
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"net" "net"
"strings" "strings"
) )
@@ -145,9 +147,9 @@ func (this *CreateAction) RunPost(params struct {
return return
} }
// 协议 // 协议:未选择时默认 HTTP
if len(params.Protocols) == 0 { if len(params.Protocols) == 0 {
this.Fail("请选择至少一个域名协议") params.Protocols = []string{"http"}
} }
httpConfig := &serverconfigs.HTTPProtocolConfig{} httpConfig := &serverconfigs.HTTPProtocolConfig{}
@@ -551,25 +553,108 @@ func (this *CreateAction) RunPost(params struct {
return return
} }
// 统计 // ========== 默认开启的功能 ==========
if userServerConfig != nil && userServerConfig.EnableStat {
var statConfig = &serverconfigs.HTTPStatRef{ // 1. 访问日志
IsPrior: false, _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.UserContext(), &pb.UpdateHTTPWebAccessLogRequest{
IsOn: true, HttpWebId: webId,
} AccessLogJSON: []byte(`{
statJSON, err := json.Marshal(statConfig) "isPrior": false,
if err != nil { "isOn": true,
this.ErrorPage(err) "fields": [1, 2, 6, 7],
return "status1": true,
} "status2": true,
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.UserContext(), &pb.UpdateHTTPWebStatRequest{ "status3": true,
HttpWebId: webId, "status4": true,
StatJSON: statJSON, "status5": true,
}) "storageOnly": false,
if err != nil { "storagePolicies": [],
this.ErrorPage(err) "firewallOnly": false
return }`),
} })
if err != nil {
this.ErrorPage(err)
return
}
// 2. WebSocket
createWebSocketResp, err := this.RPC().HTTPWebsocketRPC().CreateHTTPWebsocket(this.UserContext(), &pb.CreateHTTPWebsocketRequest{
HandshakeTimeoutJSON: []byte(`{"count": 30, "unit": "second"}`),
AllowAllOrigins: true,
AllowedOrigins: nil,
RequestSameOrigin: true,
RequestOrigin: "",
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.UserContext(), &pb.UpdateHTTPWebWebsocketRequest{
HttpWebId: webId,
WebsocketJSON: []byte(`{"isPrior": false, "isOn": true, "websocketId": ` + types.String(createWebSocketResp.WebsocketId) + `}`),
})
if err != nil {
this.ErrorPage(err)
return
}
// 3. WAF 防火墙
var firewallRef = &firewallconfigs.HTTPFirewallRef{
IsPrior: false,
IsOn: true,
FirewallPolicyId: 0,
}
firewallRefJSON, err := json.Marshal(firewallRef)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.UserContext(), &pb.UpdateHTTPWebFirewallRequest{
HttpWebId: webId,
FirewallJSON: firewallRefJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
// 4. 从上级代理中读取IP
var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{
IsOn: true,
Value: "${remoteAddr}",
Type: serverconfigs.HTTPRemoteAddrTypeProxy,
}
remoteAddrConfigJSON, err := json.Marshal(remoteAddrConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.UserContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
HttpWebId: webId,
RemoteAddrJSON: remoteAddrConfigJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
// 5. 统计
var statConfig = &serverconfigs.HTTPStatRef{
IsPrior: false,
IsOn: true,
}
statJSON, err := json.Marshal(statConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.UserContext(), &pb.UpdateHTTPWebStatRequest{
HttpWebId: webId,
StatJSON: statJSON,
})
if err != nil {
this.ErrorPage(err)
return
} }
// 绑定套餐 // 绑定套餐

View File

@@ -325,7 +325,7 @@ func (this *userMustAuth) modules(userId int64, isVerified bool, isIdentified bo
"code": "dns", "code": "dns",
"name": "域名解析", "name": "域名解析",
"icon": "globe", "icon": "globe",
"isOn": true, "isOn": false,
//"subItems": []maps.Map{ //"subItems": []maps.Map{
// { // {
// "name": "域名管理", // "name": "域名管理",

View File

@@ -11247,7 +11247,7 @@ Vue.component("http-hls-config-box", {
<table class="ui table definition selectable" v-show="isOn()"> <table class="ui table definition selectable" v-show="isOn()">
<tbody> <tbody>
<tr> <tr>
<td class="title">启用HLS加密</td> <td class="title">启用HLS加密配置</td>
<td> <td>
<checkbox v-model="encryptingConfig.isOn"></checkbox> <checkbox v-model="encryptingConfig.isOn"></checkbox>
<p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p> <p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p>
@@ -11280,6 +11280,7 @@ Vue.component("http-hls-config-box", {
</div>` </div>`
}) })
Vue.component("http-host-redirect-box", { Vue.component("http-host-redirect-box", {
props: ["v-redirects"], props: ["v-redirects"],
mounted: function () { mounted: function () {

View File

@@ -11247,7 +11247,7 @@ Vue.component("http-hls-config-box", {
<table class="ui table definition selectable" v-show="isOn()"> <table class="ui table definition selectable" v-show="isOn()">
<tbody> <tbody>
<tr> <tr>
<td class="title">启用HLS加密</td> <td class="title">启用HLS加密配置</td>
<td> <td>
<checkbox v-model="encryptingConfig.isOn"></checkbox> <checkbox v-model="encryptingConfig.isOn"></checkbox>
<p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p> <p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p>
@@ -11280,6 +11280,7 @@ Vue.component("http-hls-config-box", {
</div>` </div>`
}) })
Vue.component("http-host-redirect-box", { Vue.component("http-host-redirect-box", {
props: ["v-redirects"], props: ["v-redirects"],
mounted: function () { mounted: function () {

View File

@@ -43,7 +43,7 @@ Vue.component("http-hls-config-box", {
<table class="ui table definition selectable" v-show="isOn()"> <table class="ui table definition selectable" v-show="isOn()">
<tbody> <tbody>
<tr> <tr>
<td class="title">启用HLS加密</td> <td class="title">启用HLS加密配置</td>
<td> <td>
<checkbox v-model="encryptingConfig.isOn"></checkbox> <checkbox v-model="encryptingConfig.isOn"></checkbox>
<p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p> <p class="comment">启用后,系统会自动在<code-label>.m3u8</code-label>文件中加入<code-label>#EXT-X-KEY:METHOD=AES-128...</code-label>,并将其中的<code-label>.ts</code-label>文件内容进行加密。</p>
@@ -74,4 +74,4 @@ Vue.component("http-hls-config-box", {
</table> </table>
<div class="margin"></div> <div class="margin"></div>
</div>` </div>`
}) })

View File

@@ -1,3 +1,3 @@
<first-menu> <first-menu>
<menu-item code="hls" :href="'.hls?serverId=' + server.id">HLS</menu-item> <menu-item code="hls" :href="'.hls?serverId=' + server.id">启用HLS加密配</menu-item>
</first-menu> </first-menu>

View File

@@ -3,14 +3,12 @@
{$template "/left_menu_with_menu"} {$template "/left_menu_with_menu"}
<div class="right-box with-menu"> <div class="right-box with-menu">
{$template "menu"}
<form class="ui form" data-tea-success="success" data-tea-action="$"> <form class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token> <csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId"/> <input type="hidden" name="webId" :value="webId"/>
<h4>HLS加密设置</h4>
<http-hls-config-box v-model="hlsConfig"></http-hls-config-box> <http-hls-config-box v-model="hlsConfig"></http-hls-config-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>