diff --git a/Dockerfile b/Dockerfile index 4d77f92..3d4aaae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ COPY --from=builder /app/main /app/main EXPOSE 6789 -CMD ["./main","--config=/app/data/config.json","--basedirectory=/app/data/","--databasepath=/app/data/database.db"] +CMD ["./main","--config=/app/data/config.json","--workdirectory=/app/data/","--databasepath=/app/data/database.db","--autocheckupdate=false"] diff --git a/README.md b/README.md index c6589ea..80abfed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![mrui-logo](https://github.com/Mirouterui/mirouter-ui/assets/63234268/da737f28-e8b6-42d7-a21e-70be2d53fb78) +![mrui-logo](./otherfile/images/logo.png) ## Mirouter-ui @@ -18,30 +18,15 @@ ## 图片展示 -#### 首页 +| 首页 | 设备列表 | 设备详情 | +| -------------------------------------- | ---- | ---- | +| index | ![Snipaste_2023-08-24_14-53-25](https://github.com/Mirouterui/mirouter-ui/assets/63234268/47309e3a-cc02-479c-a9d3-29cfca235a83) | ![devicelist](./otherfile/images/Snipaste_2024-04-04_23-07-32.png) | +| **路由器详情** | **温度显示(仅支持部分设备)** | **历史数据统计** | +| ![router](./otherfile/images/Snipaste_2024-04-04_19-51-37.png) | ![Snipaste_2023-08-25_13-33-54](https://github.com/Mirouterui/mirouter-ui/assets/63234268/0926dafd-a63e-4ee6-bc61-f381c1dfc199) | ![history_index](./otherfile/images/Snipaste_2024-04-04_19-51-58.png) | +| **Upnp** | | | +| ![upnp](./otherfile/images/Snipaste_2024-04-04_19-52-14.png) | | | -![index](https://github.com/thun888/mirouter-ui/assets/63234268/48bbf554-ec03-41dc-b5fd-42b5faeba466) -#### 设备列表 - -![Snipaste_2023-08-24_14-53-25](https://github.com/Mirouterui/mirouter-ui/assets/63234268/47309e3a-cc02-479c-a9d3-29cfca235a83) - - -#### 设备详情 - -![device_index](https://github.com/thun888/mirouter-ui/assets/63234268/20c465e1-660b-41bf-a200-973423057d31) - -#### 路由器详情 - -![router_index](https://github.com/thun888/mirouter-ui/assets/63234268/1ddce346-7abd-4816-bc55-fe55d3dc70c9) - -#### 温度显示(仅支持部分设备) - -![Snipaste_2023-08-25_13-33-54](https://github.com/Mirouterui/mirouter-ui/assets/63234268/0926dafd-a63e-4ee6-bc61-f381c1dfc199) - -#### 历史数据统计 - -![history_index](./otherfile/images/history_index.png) ## 部署 ### Docker @@ -50,15 +35,19 @@ 新建一个文件夹,并在该文件夹里运行上述命令,程序会在该文件夹里生成配置文件,修改即可 +对于一些支持docker的小米路由器,也可以尝试使用docker运行 + ### 直接运行 #### 下载 从[Release](https://github.com/thun888/mirouter-ui/releases/)下载二进制文件 -> 可访问[镜像站](https://mrui-api.hzchu.top/down/)以获取更快的速度 +> 可访问[镜像站](http://h5ai.hzchu.top/Mirouter-ui/)以获取更快的速度 + +~~如果路由器有足够(内存)空间可以下载对应架构版本的部署在路由器上(ps:使用`uname -m`查看,若为armv7l,请使用armv5版本)~~ -如果路由器有足够(内存)空间可以下载对应架构版本的部署在路由器上(ps:使用`uname -m`查看,若为armv7l,请使用armv5版本) +> 不推荐在中低端系列路由器上运行~ ![image](https://github.com/Mirouterui/mirouter-ui/assets/63234268/5dfa3deb-0aab-4198-9170-5af1141b3746) @@ -78,7 +67,7 @@ ![image](./otherfile/images/config.png) -> config.json 会在初次运行时自动下载 +> config.json 会在初次运行时自动导出 > ip可以根据实际情况修改 **配置项**: @@ -102,6 +91,8 @@ | ip | 192.168.31.1 | 路由器IP | | routerunit | false | 启用后,程序通过`gopsutil`库获取CPU占用 | +> 配置多个以使用多路由模式,但要注意,如果使用有线/无线组网,数据统计由主路由负责,子路由无法获取信息属于正常情况 + **history**项: | 配置名 | 默认值 | 解释 | @@ -119,8 +110,9 @@ | 参数 | 解释 | | --------------- | -------------------------------- | | --config | 配置文件路径,默认为“./config.json” | -| --basedirectory | 基础目录路径,在里面存放静态文件 | +| --workdirectory | 基础目录路径,在里面存放静态文件 | | --databasepath | 数据库路径,默认为“./database.db” | +| --autocheckupdate | bool,是否检查更新(默认true) | 然后运行即可 @@ -171,12 +163,10 @@ sudo systemctl enable mrui - [x] 深色模式 - [x] 多路由支持 - [x] 快捷更新 -- [ ] 设备小工具 - [x] netdata,api形式兼容 - -[MRUI开发规划](https://bbs.hzchu.top/d/2-mruikai-fa-gui-hua) - -> 主要功能已完成开发,接下来随缘更新😶‍🌫️ +- [ ] prometheus(挖个坑先) +- [ ] 重构API接口 +- [ ] 进一步简化安装 ## Stars~ diff --git a/changelog.md b/changelog.md deleted file mode 100644 index ff40256..0000000 --- a/changelog.md +++ /dev/null @@ -1,41 +0,0 @@ -### 2023/12/03 -`M` 优化静态资源下载逻辑 -### 2023/11/17 -`A` 增加upnp显示 -`M` 优化 -### 2023/10/06 -`A`支持历史数据统计 - -**注意**:由于libc的问题,在以下架构上不适用 - win_i386 - linux_mips - linux_mipsle - - -可下载v1.1.5版本,手动从[这里](https://raw.githubusercontent.com/Mirouterui/mirouter-ui/9526bb3f59188029544e0e88201969eb9677a087/config.json)下载配置文件并修改 - -### 2023/10/05 - -`A`支持历史数据统计 - -**注意**:由于libc的问题,在以下架构上不适用 - win_i386 - linux_mips - linux_mipsle - - -可下载v1.1.5版本,手动从[这里](https://raw.githubusercontent.com/Mirouterui/mirouter-ui/9526bb3f59188029544e0e88201969eb9677a087/config.json)下载配置文件并修改 - -### 2023/10/02 - -`A`完善多IP处理 - -`A`"检查更新"页面 - -`A`支持深色模式 - -`M`修改折线图展示模式,不再累计数据,仅保留近5分钟数据 - -`M`图表自适应 - -`M`页面小改动&优化 \ No newline at end of file diff --git a/main.go b/main.go index c3b54bc..5031dfa 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ var ( w24g_cmd *exec.Cmd w5g_cmd *exec.Cmd configPath string - basedirectory string + workdirectory string Version string databasepath string flushTokenTime int @@ -67,7 +67,7 @@ type Config struct { } func init() { - dev, debug, port, tiny, basedirectory, flushTokenTime, databasepath, maxsaved, historyEnable, sampletime, netdata_routernum = config.GetConfigInfo() + dev, debug, port, tiny, workdirectory, flushTokenTime, databasepath, maxsaved, historyEnable, sampletime, netdata_routernum = config.GetConfigInfo() tokens = make(map[int]string) routerNames = make(map[int]string) hardwares = make(map[int]string) @@ -439,7 +439,7 @@ func main() { }) }) e.GET("/_api/flushstatic", func(c echo.Context) error { - err := download.DownloadStatic(basedirectory, true) + err := download.DownloadStatic(workdirectory, true, true) if err != nil { return c.JSON(http.StatusOK, map[string]interface{}{ "code": 1101, @@ -478,8 +478,8 @@ func main() { // e.GET("/*", contentHandler, contentRewrite) if !tiny { directory := "static" - if basedirectory != "" { - directory = filepath.Join(basedirectory, "static") + if workdirectory != "" { + directory = filepath.Join(workdirectory, "static") } logrus.Debug("静态资源目录为:" + directory) e.Static("/", directory) diff --git a/modules/config/base.go b/modules/config/base.go index 856ad3d..b98af9a 100644 --- a/modules/config/base.go +++ b/modules/config/base.go @@ -3,11 +3,10 @@ package config import ( "encoding/json" "flag" - "io" . "main/modules/download" - "net/http" "os" "path/filepath" + "strconv" "time" "github.com/sirupsen/logrus" @@ -22,7 +21,7 @@ var ( tiny bool routerunit bool configPath string - basedirectory string + workdirectory string databasepath string historyEnable bool dev []Dev @@ -30,6 +29,7 @@ var ( flushTokenTime int sampletime int netdata_routernum int + autocheckupdate string ) type Dev struct { @@ -53,36 +53,53 @@ type Config struct { Netdata_routernum int `json:"netdata_routernum"` } -func GetConfigInfo() (dev []Dev, debug bool, port int, tiny bool, basedirectory string, flushTokenTime int, databasepath string, maxsaved int, historyEnable bool, sampletime int, netdata_routernum int) { - flag.StringVar(&configPath, "config", "", "配置文件路径") - flag.StringVar(&basedirectory, "basedirectory", "", "基础目录路径") - flag.StringVar(&databasepath, "databasepath", "", "数据库路径") +func GetConfigInfo() (dev []Dev, debug bool, port int, tiny bool, workdirectory string, flushTokenTime int, databasepath string, maxsaved int, historyEnable bool, sampletime int, netdata_routernum int) { + appPath, _ := os.Executable() + + flag.StringVar(&configPath, "config", filepath.Join(filepath.Dir(appPath), "config.json"), "配置文件路径") + flag.StringVar(&workdirectory, "workdirectory", "", "工作目录路径") + flag.StringVar(&databasepath, "databasepath", filepath.Join(filepath.Dir(appPath), "database.db"), "数据库路径") + flag.StringVar(&autocheckupdate, "autocheckupdate", "true", "自动检查更新") flag.Parse() - appPath, err := os.Executable() - checkErr(err) - if configPath == "" { - configPath = filepath.Join(filepath.Dir(appPath), "config.json") - } - if databasepath == "" { - databasepath = filepath.Join(filepath.Dir(appPath), "database.db") - } + + autocheckupdatebool, _ := strconv.ParseBool(autocheckupdate) + logrus.Info("配置文件路径为:" + configPath) data, err := os.ReadFile(configPath) + if err != nil { - logrus.Info("未找到配置文件,正在下载") - resp, err := http.Get("https://mrui-api.hzchu.top/downloadconfig") + logrus.Info("未找到配置文件,正在从程序内部导出") + // 使用你的结构体创建一个默认的配置实例 + config := Config{ + Dev: []Dev{ + { + Password: "", + Key: "a2ffa5c9be07488bbb04a3a47d3c5f6a", + IP: "192.168.31.1", + RouterUnit: false, + }, + }, + History: History{ + Enable: false, + MaxDeleted: 3000, + Sampletime: 86400, + }, + Debug: true, + Port: 6789, + Tiny: false, + FlushTokenTime: 1800, + Netdata_routernum: 0, + } + configContent, err := json.MarshalIndent(config, "", " ") checkErr(err) - defer resp.Body.Close() - out, err := os.Create(configPath) + err = os.WriteFile(configPath, configContent, 0644) checkErr(err) - defer out.Close() - _, err = io.Copy(out, resp.Body) - checkErr(err) - logrus.Info("下载配置文件完成,请修改配置文件") + logrus.Info("配置文件导出完成,请修改配置文件") logrus.Info("5秒后退出程序") time.Sleep(5 * time.Second) os.Exit(1) } + var config Config err = json.Unmarshal(data, &config) if err != nil { @@ -99,10 +116,10 @@ func GetConfigInfo() (dev []Dev, debug bool, port int, tiny bool, basedirectory netdata_routernum = config.Netdata_routernum // logrus.Info(password) // logrus.Info(key) - if tiny == false { - DownloadStatic(basedirectory, false) + if !tiny { + DownloadStatic(workdirectory, false, autocheckupdatebool) } - if debug == true { + if debug { logrus.SetLevel(logrus.DebugLevel) } else { logrus.SetLevel(logrus.InfoLevel) @@ -114,7 +131,7 @@ func GetConfigInfo() (dev []Dev, debug bool, port int, tiny bool, basedirectory time.Sleep(5 * time.Second) os.Exit(1) } - return dev, debug, port, tiny, basedirectory, flushTokenTime, databasepath, maxsaved, historyEnable, sampletime, netdata_routernum + return dev, debug, port, tiny, workdirectory, flushTokenTime, databasepath, maxsaved, historyEnable, sampletime, netdata_routernum } func checkErr(err error) { diff --git a/modules/download/base.go b/modules/download/base.go index 7983382..bd94245 100644 --- a/modules/download/base.go +++ b/modules/download/base.go @@ -17,10 +17,10 @@ var ( Version string ) -func DownloadStatic(basedirectory string, force bool) error { +func DownloadStatic(workdirectory string, force bool, checkupdate bool) error { directory := "static" - if basedirectory != "" { - directory = filepath.Join(basedirectory, "static") + if workdirectory != "" { + directory = filepath.Join(workdirectory, "static") } if force { //删除 @@ -48,36 +48,43 @@ func DownloadStatic(basedirectory string, force bool) error { checkErr(err) logrus.Info("静态资源已存在,版本号为" + string(forntendVersion)) - resp, err := http.Get("https://mrui-api.hzchu.top/v2/api/checkupdate") + // 检查更新 + if checkupdate { + resp, err := http.Get("https://mrui-api.hzchu.top/v2/api/checkupdate") - if err != nil { - logrus.Info("无法获取更新信息,跳过检查") - return err - } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - checkErr(err) - var result map[string]interface{} - json.Unmarshal(body, &result) - front := result["front"].(map[string]interface{}) - frontversion := front["version"] - frontchangelog := front["changelog"] - - backend := result["backend"].(map[string]interface{}) - backendversion := backend["version"] - backendchangelog := front["changelog"] - - if backendversion != string(Version) { - message := fmt.Sprintf("后端程序发现新版本(%v),请及时更新。更新日志:%v", backendversion, backendchangelog) - logrus.Info(message) - } + if err != nil { + logrus.Info("无法获取更新信息,跳过检查") + return err + } - if frontversion != string(forntendVersion) { - message := fmt.Sprintf("前端文件发现新版本(%v),在前端页面中进行更新。更新日志:%v", frontversion, frontchangelog) - logrus.Info(message) - os.RemoveAll(directory) - downloadfile(directory) + + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + checkErr(err) + var result map[string]interface{} + json.Unmarshal(body, &result) + front := result["front"].(map[string]interface{}) + frontversion := front["version"] + frontchangelog := front["changelog"] + + backend := result["backend"].(map[string]interface{}) + backendversion := backend["version"] + backendchangelog := front["changelog"] + + if backendversion != string(Version) { + message := fmt.Sprintf("后端程序发现新版本(%v),请及时更新。更新日志:%v", backendversion, backendchangelog) + logrus.Info(message) + } + + if frontversion != string(forntendVersion) { + message := fmt.Sprintf("前端文件发现新版本(%v),在前端页面中进行更新。更新日志:%v", frontversion, frontchangelog) + logrus.Info(message) + os.RemoveAll(directory) + downloadfile(directory) + } + } else { + logrus.Info("跳过检查更新") } return nil } diff --git a/modules/tp/base.go b/modules/tp/base.go index 009a32f..00727ce 100644 --- a/modules/tp/base.go +++ b/modules/tp/base.go @@ -19,7 +19,7 @@ var ( // 获取温度 func GetTemperature(c echo.Context, routernum int, hardware string) (bool, string, string, string, string) { - if dev[routernum].RouterUnit == false { + if !dev[routernum].RouterUnit { return false, "-233", "-233", "-233", "-233" } var cpu_out, w24g_out, w5g_out []byte diff --git a/otherfile/images/Snipaste_2024-04-04_19-51-37.png b/otherfile/images/Snipaste_2024-04-04_19-51-37.png new file mode 100644 index 0000000..d235f2c Binary files /dev/null and b/otherfile/images/Snipaste_2024-04-04_19-51-37.png differ diff --git a/otherfile/images/Snipaste_2024-04-04_19-51-58.png b/otherfile/images/Snipaste_2024-04-04_19-51-58.png new file mode 100644 index 0000000..e194451 Binary files /dev/null and b/otherfile/images/Snipaste_2024-04-04_19-51-58.png differ diff --git a/otherfile/images/Snipaste_2024-04-04_19-52-14.png b/otherfile/images/Snipaste_2024-04-04_19-52-14.png new file mode 100644 index 0000000..4fb21c2 Binary files /dev/null and b/otherfile/images/Snipaste_2024-04-04_19-52-14.png differ diff --git a/otherfile/images/Snipaste_2024-04-04_23-07-32.png b/otherfile/images/Snipaste_2024-04-04_23-07-32.png new file mode 100644 index 0000000..f5853e9 Binary files /dev/null and b/otherfile/images/Snipaste_2024-04-04_23-07-32.png differ diff --git a/otherfile/images/history_index.png b/otherfile/images/history_index.png deleted file mode 100644 index f9b7ad2..0000000 Binary files a/otherfile/images/history_index.png and /dev/null differ diff --git a/otherfile/images/index.png b/otherfile/images/index.png new file mode 100644 index 0000000..7b962f1 Binary files /dev/null and b/otherfile/images/index.png differ diff --git a/otherfile/images/logo.png b/otherfile/images/logo.png new file mode 100644 index 0000000..05ebcda Binary files /dev/null and b/otherfile/images/logo.png differ