mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-28 05:46:36 +08:00
[优化] 代码优化
This commit is contained in:
@@ -23,7 +23,6 @@ The Agent supports:
|
||||
| Component | Default Location | Description |
|
||||
| --- | --- | --- |
|
||||
| Server SQLite | `openflare.db` | Can be modified via `SQLITE_PATH` |
|
||||
| Server Uploads Directory | `upload` | Can be modified via `UPLOAD_PATH` |
|
||||
| Agent Configuration File | `./agent.json` | Can be specified via `-config` |
|
||||
| One-click Install Agent Config | `/opt/openflare-agent/agent.json` | Default generated by the installation script |
|
||||
| Agent Data Directory | `data` under the config directory | Can be modified via `data_dir` |
|
||||
@@ -54,7 +53,6 @@ go run . --port 3000 --log-dir ./logs
|
||||
| `DSN` | PostgreSQL DSN, preferred over SQLite when set | empty |
|
||||
| `SQL_DSN` | Legacy PostgreSQL DSN, lower priority than `DSN` | empty |
|
||||
| `REDIS_CONN_STRING` | Redis connection string | empty |
|
||||
| `UPLOAD_PATH` | Upload directory | `upload` |
|
||||
| `AGENT_TOKEN` | Legacy global Agent token | empty |
|
||||
|
||||
Description:
|
||||
|
||||
@@ -23,7 +23,6 @@ Agent 支持:
|
||||
| 组件 | 默认位置 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| Server SQLite | `openflare.db` | 可通过 `SQLITE_PATH` 修改 |
|
||||
| Server 上传目录 | `upload` | 可通过 `UPLOAD_PATH` 修改 |
|
||||
| Agent 配置文件 | `./agent.json` | 可通过 `-config` 指定 |
|
||||
| 一键安装 Agent 配置 | `/opt/openflare-agent/agent.json` | 安装脚本默认生成 |
|
||||
| Agent 数据目录 | 配置文件所在目录下的 `data` | 可通过 `data_dir` 修改 |
|
||||
@@ -54,7 +53,6 @@ go run . --port 3000 --log-dir ./logs
|
||||
| `DSN` | PostgreSQL DSN,设置后优先于 SQLite | 空 |
|
||||
| `SQL_DSN` | 兼容旧命名的 PostgreSQL DSN,优先级低于 `DSN` | 空 |
|
||||
| `REDIS_CONN_STRING` | Redis 连接串 | 空 |
|
||||
| `UPLOAD_PATH` | 上传目录 | `upload` |
|
||||
| `AGENT_TOKEN` | 兼容旧部署的全局 Agent Token | 空 |
|
||||
|
||||
说明:
|
||||
|
||||
@@ -16,9 +16,6 @@ var (
|
||||
LogDir = flag.String("log-dir", "", "specify the log directory")
|
||||
)
|
||||
|
||||
// UploadPath Maybe override by ENV_VAR
|
||||
var UploadPath = "upload"
|
||||
|
||||
func printHelp() {
|
||||
fmt.Println("OpenFlare " + Version + " - Internal OpenResty Control Plane.")
|
||||
fmt.Println("Copyright (C) 2023 JustSong. All rights reserved.")
|
||||
@@ -28,7 +25,8 @@ func printHelp() {
|
||||
|
||||
func init() {
|
||||
executableName := strings.ToLower(filepath.Base(os.Args[0]))
|
||||
if !strings.Contains(executableName, ".test") {
|
||||
isTest := strings.Contains(executableName, ".test") || flag.Lookup("test.v") != nil
|
||||
if !isTest {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
@@ -54,9 +52,7 @@ func init() {
|
||||
if os.Getenv("DSN") != "" {
|
||||
SQLDSN = os.Getenv("DSN")
|
||||
}
|
||||
if os.Getenv("UPLOAD_PATH") != "" {
|
||||
UploadPath = os.Getenv("UPLOAD_PATH")
|
||||
}
|
||||
|
||||
if os.Getenv("AGENT_TOKEN") != "" {
|
||||
AgentToken = os.Getenv("AGENT_TOKEN")
|
||||
}
|
||||
@@ -76,7 +72,5 @@ func init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(UploadPath); os.IsNotExist(err) {
|
||||
_ = os.Mkdir(UploadPath, 0777)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func main() {
|
||||
if common.SQLDSN != "" {
|
||||
dbBackend = "postgres"
|
||||
}
|
||||
slog.Info("server config", "port", port, "gin_mode", gin.Mode(), "log_level", common.GetLogLevel(), "db_backend", dbBackend, "sqlite_path", common.SQLitePath, "redis_enabled", common.RedisEnabled, "upload_path", common.UploadPath, "log_dir", valueOrDefault(*common.LogDir, "stdout"), "agent_token_configured", common.AgentToken != "", "node_offline_threshold", common.NodeOfflineThreshold)
|
||||
slog.Info("server config", "port", port, "gin_mode", gin.Mode(), "log_level", common.GetLogLevel(), "db_backend", dbBackend, "sqlite_path", common.SQLitePath, "redis_enabled", common.RedisEnabled, "log_dir", valueOrDefault(*common.LogDir, "stdout"), "agent_token_configured", common.AgentToken != "", "node_offline_threshold", common.NodeOfflineThreshold)
|
||||
slog.Info("server listening", "address", fmt.Sprintf(":%s", port))
|
||||
err = server.Run(":" + port)
|
||||
if err != nil {
|
||||
|
||||
@@ -51,7 +51,7 @@ export const emptyDraft: WAFRuleGroupPayload = {
|
||||
|
||||
export const defaultRuleModalState: RuleModalState = {
|
||||
open: false,
|
||||
listType: 'whitelist',
|
||||
listType: 'blacklist',
|
||||
dimension: 'ip',
|
||||
ipValue: '',
|
||||
ipGroupIDs: [],
|
||||
|
||||
@@ -246,4 +246,46 @@ describe('WAF IP groups', () => {
|
||||
|
||||
expect(await screen.findByText(/IP组: edge blacklist/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('defaults new rule entries to blacklist', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn((input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
|
||||
if (url.includes('/waf/rule-groups')) {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
message: '',
|
||||
data: [buildRuleGroup()],
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (url.includes('/waf/ip-groups') || url.includes('/proxy-routes/')) {
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({ success: true, message: '', data: [] }),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(`Unhandled fetch: ${url}`));
|
||||
}),
|
||||
);
|
||||
|
||||
renderWithProviders(<WAFPage />);
|
||||
|
||||
await userEvent.click(
|
||||
await screen.findByRole('button', { name: /黑白名单/ }),
|
||||
);
|
||||
await userEvent.click(screen.getByRole('button', { name: /添加/ }));
|
||||
|
||||
expect(
|
||||
await screen.findByRole('heading', { name: '添加黑名单规则' }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user