Skip to content

Commit

Permalink
dev: update system network config
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Aug 17, 2023
1 parent ceaf2cc commit 99c45bb
Show file tree
Hide file tree
Showing 14 changed files with 630 additions and 111 deletions.
12 changes: 7 additions & 5 deletions bspsupport/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ ARCHSUPPORT=EEKITH3 rulex run

## 支持硬件列表

| 硬件名 | 环境参数 | 示例 |
| --------------- | -------- | ------------------------------- |
| EEKITH3版本网关 | EEKITH3 | `ARCHSUPPORT=EEKITH3 rulex run` |
| 树莓派4B、4B+ | RPI4 | `ARCHSUPPORT=RPI4B rulex run` |
| 玩客云S805 | WKYS805 | `ARCHSUPPORT=WKYS805 rulex run` |
| 硬件名 | 环境参数 | 示例 |
| ------------------ | --------- | --------------------------------- |
| EEKIT H3版本网关 | EEKITH3 | `ARCHSUPPORT=EEKITH3 rulex run` |
| EEKIT T507版本网关 | EEKITT507 | `ARCHSUPPORT=EEKITT507 rulex run` |
| EEKIT T113版本网关 | EEKITT113 | `ARCHSUPPORT=EEKITT113 rulex run` |
| 树莓派4B、4B+ | RPI4 | `ARCHSUPPORT=RPI4B rulex run` |
| 玩客云S805 | WKYS805 | `ARCHSUPPORT=WKYS805 rulex run` |

> 警告: 这些属于板级高级功能,和硬件架构以及外设有关,默认关闭。 如果你自己需要定制,最好针对自己的硬件进行跨平台适配, 如果没有指定平台,可能会导致预料之外的结果。
Expand Down
10 changes: 10 additions & 0 deletions plugin/http_server/dao/sqlite/sqlite_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type SqliteDAO struct {
func Load(dbPath string) {
Sqlite = &SqliteDAO{name: "SqliteDAO"}
Sqlite.Init(dbPath)
Sqlite.InitializeData()
}

/*
Expand All @@ -58,6 +59,15 @@ func (s *SqliteDAO) Init(dbPath string) error {
return err
}

/*
*
* 给数据库初始化一些数据用
*
*/
func (s *SqliteDAO) InitializeData() {

}

/*
*
* 停止
Expand Down
1 change: 1 addition & 0 deletions plugin/http_server/dao/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "gorm.io/gorm"
*/
type DAO interface {
Init(string) error
InitializeData()
RegisterModel(dst ...interface{})
Name() string
DB() *gorm.DB
Expand Down
26 changes: 18 additions & 8 deletions plugin/http_server/dto/etcnet_config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package service
package dto

// {
// "name": "eth0",
// "interface": "eth0",
// "address": "192.168.1.100",
// "netmask": "255.255.255.0",
// "gateway": "192.168.1.1",
// "dns": ["8.8.8.8", "8.8.4.4"],
// "dhcp_enabled": false
// }

type EtcNetworkConfig struct {
Name string `json:"name,omitempty"`
Interface string `json:"interface,omitempty"`
Address string `json:"address,omitempty"`
Netmask string `json:"netmask,omitempty"`
Gateway string `json:"gateway,omitempty"`
DNS []string `json:"dns,omitempty"`
DHCPEnabled bool `json:"dhcp_enabled,omitempty"`
Name string `json:"name"` // eth1 eth0
Interface string `json:"interface"` // eth1 eth0
Address string `json:"address"`
Netmask string `json:"netmask"`
Gateway string `json:"gateway"`
DNS []string `json:"dns"`
DHCPEnabled bool `json:"dhcp_enabled"`
}
2 changes: 1 addition & 1 deletion plugin/http_server/dto/netplan_config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package dto

type hwInterface struct {
Dhcp4 bool `yaml:"dhcp4" json:"dhcp4,omitempty"`
Expand Down
23 changes: 23 additions & 0 deletions plugin/http_server/http_api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
common "github.com/hootrhino/rulex/plugin/http_server/common"
sqlitedao "github.com/hootrhino/rulex/plugin/http_server/dao/sqlite"
"github.com/hootrhino/rulex/plugin/http_server/model"
"github.com/hootrhino/rulex/plugin/http_server/service"

"github.com/gin-contrib/static"

Expand Down Expand Up @@ -93,13 +94,25 @@ func (hs *HttpApiServer) Init(config *ini.Section) error {
}
hs.registerModel()
hs.configHttpServer()
hs.InitializeNwtWorkConfigData()
//
// WebSocket server
//
hs.ginEngine.GET("/ws", glogger.WsLogger)
return nil
}

/*
*
* 初始化网络配置
*
*/
func (hs *HttpApiServer) InitializeNwtWorkConfigData() {
if !service.CheckIfAlreadyInitNetWorkConfig() {
service.InitNetWorkConfig()
}
}

/*
*
* 加载路由
Expand Down Expand Up @@ -327,6 +340,16 @@ func (hs *HttpApiServer) LoadRoute() {
screenApi.PUT("/update", hs.addRoute(UpdateVisual))
screenApi.GET("/list", hs.addRoute(ListVisual))
}
//
// 大屏应用管理
//
settingsApi := hs.ginEngine.Group(url("/settings"))
{
settingsApi.POST("/network", hs.addRoute(SetStaticNetwork))
settingsApi.POST("/time", hs.addRoute(SetTime))
settingsApi.POST("/wifi", hs.addRoute(SetWifi))
settingsApi.POST("/volume", hs.addRoute(SetVolume))
}

}

Expand Down
29 changes: 18 additions & 11 deletions plugin/http_server/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type RulexModel struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
}
type stringList []string
type StringList []string

/*
*
* 给GORM用的
*
*/
func (f stringList) Value() (driver.Value, error) {
func (f StringList) Value() (driver.Value, error) {
b, err := json.Marshal(f)
return string(b), err
}
Expand All @@ -28,15 +28,15 @@ func (f stringList) Value() (driver.Value, error) {
* 给GORM用的
*
*/
func (f *stringList) Scan(data interface{}) error {
func (f *StringList) Scan(data interface{}) error {
return json.Unmarshal([]byte(data.(string)), f)
}

func (f stringList) String() string {
func (f StringList) String() string {
b, _ := json.Marshal(f)
return string(b)
}
func (f stringList) Len() int {
func (f StringList) Len() int {
return len(f)
}

Expand All @@ -45,8 +45,8 @@ type MRule struct {
UUID string `gorm:"not null"`
Name string `gorm:"not null"`
Type string // 脚本类型,目前支持"lua"和"expr"两种
FromSource stringList `gorm:"not null type:string[]"`
FromDevice stringList `gorm:"not null type:string[]"`
FromSource StringList `gorm:"not null type:string[]"`
FromDevice StringList `gorm:"not null type:string[]"`
Expression string `gorm:"not null"` // Expr脚本
Actions string `gorm:"not null"`
Success string `gorm:"not null"`
Expand All @@ -60,7 +60,7 @@ type MInEnd struct {
UUID string `gorm:"not null"`
Type string `gorm:"not null"`
Name string `gorm:"not null"`
BindRules stringList `json:"bindRules"` // 与之关联的规则表["A","B","C"]
BindRules StringList `json:"bindRules"` // 与之关联的规则表["A","B","C"]

Description string
Config string
Expand Down Expand Up @@ -110,7 +110,7 @@ type MDevice struct {
Name string `gorm:"not null"`
Type string `gorm:"not null"`
Config string
BindRules stringList `json:"bindRules"` // 与之关联的规则表["A","B","C"]
BindRules StringList `json:"bindRules"` // 与之关联的规则表["A","B","C"]
Description string
}

Expand All @@ -132,7 +132,7 @@ type MGoods struct {
UUID string `gorm:"not null"`
Addr string `gorm:"not null"`
Description string `gorm:"not null"`
Args stringList `gorm:"not null"`
Args StringList `gorm:"not null"`
}

/*
Expand Down Expand Up @@ -237,5 +237,12 @@ type MProtocolApp struct {
*
*/
type MNetworkConfig struct {
Network string `yaml:"network" json:"network,omitempty"`
RulexModel
Type string `gorm:"not null"` // 类型: ubuntu16, ubuntu18
Interface string `json:"interface"` // eth1 eth0
Address string `json:"address"`
Netmask string `json:"netmask"`
Gateway string `json:"gateway"`
DNS StringList `json:"dns"`
DHCPEnabled bool `json:"dhcp_enabled"`
}
Loading

0 comments on commit 99c45bb

Please sign in to comment.