Skip to content

Commit

Permalink
[Add][Opt]Add a check update parameter&Export the config from the pro…
Browse files Browse the repository at this point in the history
…gram (#30)

* fix

* [ImgBot] Optimize images

*Total -- 435.32kb -> 276.76kb (36.42%)

/otherfile/images/config.png -- 20.77kb -> 11.67kb (43.81%)
/otherfile/images/history_index.png -- 414.56kb -> 265.09kb (36.05%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>

* [Opt][Incomplete]Optimize history processing

* [FIX][Build APP]Rclone

* [ADD]Support Devices History Display

* [OPT][FIX][BUILDAPP]

* [OPT]Float process

* [FIX]build app

* fix Upload Release Assets

* fix Upload Release Assets

* [FIX] device history

* FIX

* [Fix]Fixes high memory usage

* [Add][Opt]Add a check update parameter&Export the config from the program

---------

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com>
  • Loading branch information
thun888 and ImgBotApp committed Apr 5, 2024
1 parent e84fa8f commit 75fab0f
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
54 changes: 22 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -18,30 +18,15 @@

## 图片展示

#### 首页
| 首页 | 设备列表 | 设备详情 |
| -------------------------------------- | ---- | ---- |
| <img src="./otherfile/images/index.png" alt="index" style="zoom: 33%;" /> | ![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
Expand All @@ -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)

Expand All @@ -78,7 +67,7 @@
![image](./otherfile/images/config.png)


> config.json 会在初次运行时自动下载
> config.json 会在初次运行时自动导出
> ip可以根据实际情况修改
**配置项**
Expand All @@ -102,6 +91,8 @@
| ip | 192.168.31.1 | 路由器IP |
| routerunit | false | 启用后,程序通过`gopsutil`库获取CPU占用 |

> 配置多个以使用多路由模式,但要注意,如果使用有线/无线组网,数据统计由主路由负责,子路由无法获取信息属于正常情况
**history**项:

| 配置名 | 默认值 | 解释 |
Expand All @@ -119,8 +110,9 @@
| 参数 | 解释 |
| --------------- | -------------------------------- |
| --config | 配置文件路径,默认为“./config.json” |
| --basedirectory | 基础目录路径,在里面存放静态文件 |
| --workdirectory | 基础目录路径,在里面存放静态文件 |
| --databasepath | 数据库路径,默认为“./database.db” |
| --autocheckupdate | bool,是否检查更新(默认true) |


然后运行即可
Expand Down Expand Up @@ -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~

Expand Down
41 changes: 0 additions & 41 deletions changelog.md

This file was deleted.

10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
71 changes: 44 additions & 27 deletions modules/config/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,14 +21,15 @@ var (
tiny bool
routerunit bool
configPath string
basedirectory string
workdirectory string
databasepath string
historyEnable bool
dev []Dev
maxsaved int
flushTokenTime int
sampletime int
netdata_routernum int
autocheckupdate string
)

type Dev struct {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 75fab0f

Please sign in to comment.