Documentation
¶
Overview ¶
Copyright (C) 2024 wwhai
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- func BindMacAndIP()
- func ConfigDefaultIpTable(Iface string) error
- func ConfigDefaultIscServeDhcp(IpRoute IscServerDHCPConfig) error
- func ConfigDefaultIscServer(Iface string) error
- func DisableWifi() error
- func EnableWifi() error
- func FileExists(filename string) bool
- func GetBSPNetIfaces() ([]string, error)
- func GetEarliestProcessPID(processName string) (int, error)
- func GetPortsListUnix() ([]string, error)
- func GetProcessPID(processName string) (int, error)
- func GetProcessStatus(pid int) (string, error)
- func GetSystemTime() (string, error)
- func GetUptime() (string, error)
- func GetVolume() (string, error)
- func GetWlanList() ([]string, error)
- func IsIPRangeValid(startIPStr, endIPStr string) bool
- func IsIPv4InDHCPRange(ip, start, end string) bool
- func KillProcess(processID int) error
- func MoveFile(sourcePath, destPath string) error
- func NewSysProcAttr() *syscall.SysProcAttr
- func ReInitForwardRule(ifaceFrom, ifaceTo string) error
- func ReadIfaceMacAddr(ifaceName string) (string, error)
- func Reboot() error
- func ReloadDNS16() error
- func ReloadDNS18xx() error
- func RestartRulex() error
- func RestoreIpTablesConfig() error
- func SaveIpTablesConfig() error
- func ScanWIFIWithNmcli() ([]string, error)
- func SendKillSignal(pid int) error
- func SetSystemTime(newTime string) error
- func SetTimeZone(timezone string) error
- func SetVolume(v int) (string, error)
- func StartRecoverProcess()
- func StartSoftRoute() error
- func StartUpgradeProcess()
- func StopRulex() error
- func StopSoftRoute() error
- func UnzipFirmware(zipFile, destDir string) error
- func UpdateTimeByNtp() error
- func WifiAlreadyConfig(wifiSSIDName string) bool
- type DeviceStatus
- type DhcpLease
- type EtcNetworkConfig
- type EthInterface
- type HwPort
- type IscServerDHCPConfig
- type NetInterfaceInfo
- type NetplanConfig
- type Network
- type TimeZoneInfo
- type UnixCameraDevice
- type WLANInterface
- type WindowsCameraDevice
- type WlanConfig
Constants ¶
const ( // Rulex 工作目录 MainWorkDir = "/usr/local" // RULEX 的配置数据库 RunDbPath = "/usr/local/rulex.db" // 固件保存路径 FirmwarePath = "/usr/local/upload/Firmware/Firmware.zip" // 升级日志 UpgradeLogPath = "/usr/local/local-upgrade-log.txt" // 运行时日志 RunningLogPath = "/usr/local/rulexlog.txt" // 数据恢复日志 RecoverLogPath = "/usr/local/local-recover-log.txt" // 备份锁 BackupLockPath = "/var/run/rulex-upgrade.lock" // 升级锁 UpgradeLockPath = BackupLockPath // 备份数据库 RecoveryDbPath = "/usr/local/upload/Backup/recovery.db" )
* * Linux系统下的一些和应用交互的系统级路径 *
Variables ¶
This section is empty.
Functions ¶
func BindMacAndIP ¶
func BindMacAndIP()
IP和MAC地址绑定 host hostname { hardware ethernet 00:11:22:33:44:55; fixed-address 192.168.1.200; client-hostname "wwhai" }
func ConfigDefaultIpTable ¶
func ConfigDefaultIscServeDhcp ¶
func ConfigDefaultIscServeDhcp(IpRoute IscServerDHCPConfig) error
func ConfigDefaultIscServer ¶
* # vim /etc/dhcp/dhcpd.conf
subnet 192.168.64.0 netmask 255.255.255.0 { range 192.168.64.100 192.168.64.200; # 开放的地址池 option routers 192.168.64.100; # 网关地址 option broadcast-address 192.168.64.255; # 广播地址 default-lease-time 600; # 默认租期,单位:秒 max-lease-time 7200; # 最大租期 }
* 这个初始化特殊在咬对两个软件的配置进行刷新,一个是 dnsmasq, 一个是isc-dhcp-server
func FileExists ¶ added in v0.6.5
* * 恢复上传的DB 1 停止RULEX 2 删除老DB 3 复制新DB到路径 3 删除PID,停止守护进程 4 重启(脚本会新建PID) - path: /usr/local/rulex, args: recover=true *
func GetEarliestProcessPID ¶ added in v0.6.5
* * 取最老的那个进程Id *
func GetPortsListUnix ¶ added in v0.6.5
func GetProcessPID ¶ added in v0.6.5
* * pgrep rulex -> 38506\n *
func GetProcessStatus ¶
func GetVolume ¶
*
- 获取音量百分比 20% amixer get Master | grep 'Front Left:' | awk -F '[][]' '{print $2}'
*
func GetWlanList ¶
-------------------------------------------------------------------------------------- 注意: 这些设置主要是针对RhinoH3 Ubuntu16.04 的,有可能在不同的发行版有不同的指令,不一定通用 !!!! Warning: MUST RUN WITH SUDO or ROOT USER !!!! --------------------------------------------------------------------------------------
* * 专门针对H3的一些系统指令封装 *
func IsIPRangeValid ¶
func IsIPv4InDHCPRange ¶
IsIPv4InDHCPRange 检查给定的 IPv4 地址是否在 DHCP 地址池范围内
func NewSysProcAttr ¶
func NewSysProcAttr() *syscall.SysProcAttr
func ReInitForwardRule ¶
* * 重构ip table, 目前默认以Eth1 <--> 4G *
func ReadIfaceMacAddr ¶ added in v0.6.5
* * 获取网卡的MAC地址 *
func ScanWIFIWithNmcli ¶
* * WIFI 控制 nmcli device wifi rescan nmcli device wifi list
获取WIFI网卡: iw dev | awk '$1=="Interface"{print $2}' 扫描WIFI列表: iwlist wlx0cc6551c5026 scan | grep ESSID | awk -F: '{print $2}' | sed 's/"//g' *
func SetTimeZone ¶
SetTimeZone 设置系统时区 timezone := "Asia/Shanghai"
func SetVolume ¶
* amixer 设置音量, 输入参数是个数值, 每次增加或者减少1% * amixer set 'Line Out' 1 | grep 'Front Left:' | awk -F '[][]' '{print $2}' *
func StopSoftRoute ¶
func StopSoftRoute() error
* * 关闭软路由 service dnsmasq stop service isc-dhcp-server stop *
func UpdateTimeByNtp ¶
func UpdateTimeByNtp() error
func WifiAlreadyConfig ¶ added in v0.6.6
*
- 初始化 // 删除之前的连接 // if exists ${name} -> nmcli connection delete ${name} // 重新连接 // sudo nmcli dev wifi connect "ssid" password "password"
Types ¶
type DeviceStatus ¶
type DeviceStatus struct { DEVICE string `json:"device"` TYPE string `json:"type"` STATE string `json:"state"` CONNECTION string `json:"connection"` }
* rer@revb-h3:~$ nmcli device status
DEVICE TYPE STATE CONNECTION usb0 ethernet connected Wired connection 1 wlx0cc6551c5026 wifi connected AABBCC eth1 ethernet connected eth1 eth0 ethernet disconnected -- lo loopback unmanaged --
*
func GetCurrentNetConnection ¶
func GetCurrentNetConnection() ([]DeviceStatus, error)
type DhcpLease ¶
type DhcpLease struct { MacAddress string `json:"mac_address"` IpAddress string `json:"ip_address"` Hostname string `json:"hostname"` }
func GetDhcpList ¶
* rhino@RH-PI1:~$ cat /var/lib/dhcp/dhcpd.leases # The format of this file is documented in the dhcpd.leases(5) manual page. # This lease file was written by isc-dhcp-4.3.5
authoring-byte-order entry is generated, DO NOT DELETE ¶
authoring-byte-order little-endian; lease 192.168.64.101 { hardware ethernet a8:a1:59:2e:a2:d9; } lease 192.168.64.102 { hardware ethernet a8:a1:59:2e:a2:d9; }
*
func (DhcpLease) JsonString ¶
type EtcNetworkConfig ¶
type EtcNetworkConfig struct { Interface string `json:"interface"` Address string `json:"address"` Netmask string `json:"netmask"` Gateway string `json:"gateway"` DNS []string `json:"dns"` DHCPEnabled bool `json:"dhcp_enabled"` }
func (*EtcNetworkConfig) GenEtcConfig ¶
func (iface *EtcNetworkConfig) GenEtcConfig() string
* * 将结构体写入配置文件 sudo systemctl restart networking sudo ossupport networking restart *
func (*EtcNetworkConfig) JsonString ¶
func (nc *EtcNetworkConfig) JsonString() string
type EthInterface ¶
type HwPort ¶
type HwPort struct { Dhcp4 *bool `yaml:"dhcp4" json:"dhcp4"` Addresses []string `yaml:"addresses" json:"addresses"` Gateway4 string `yaml:"gateway4" json:"gateway4"` Nameservers []string `yaml:"nameservers" json:"nameservers"` }
* Ubuntu 18 以后的版本才支持 /etc/netplan/01-netcfg.yaml network:
version: 2 renderer: networkd ethernets: enp0s9: dhcp4: no addresses: - 192.168.121.221/24 gateway4: 192.168.121.1 nameservers: addresses: [8.8.8.8, 1.1.1.1]
*
读取Ip状态(静态/动态) yaml
type IscServerDHCPConfig ¶
type IscServerDHCPConfig struct { Iface string // 用来做子网的那个网卡的网卡名 Ip string // 用来做子网的那个网卡的IP地址 Gateway string // 用来做子网的那个网卡的网关 Network string // 用来做子网的那个网卡的网段 Netmask string // 用来做子网的那个网卡子网掩码 IpPoolBegin string // DHCP IP地址池起始 IpPoolEnd string // DHCP IP地址池结束 //------------------------------------ // IP 路由方向, 默认 ETH1 透传到 4G //------------------------------------ IfaceFrom string // 流量入口 IfaceTo string // 流量出口 }
*
subnet 192.168.64.0 netmask 255.255.255.0 { range 192.168.64.100 192.168.64.200; # 开放的地址池 option domain-name-servers 192.168.64.100; # DNS域名服务器,如果没有就注释掉 #option domain-name "internal.example.org"; # 域名 option routers 192.168.64.100; # 网关地址 option broadcast-address 192.168.64.255; # 广播地址 default-lease-time 600; # 默认租期,单位:秒 max-lease-time 7200; # 最大租期 }
*isc-dhcp-server 会加载 /etc/dhcp/dhcpd.conf 配置文件 这里需要注意一下,此处配置要和网卡的配置一致
type NetInterfaceInfo ¶ added in v0.6.6
type NetInterfaceInfo struct { Name string `json:"name"` Mac string `json:"mac"` Addr string `json:"addr"` }
func GetAvailableInterfaces ¶ added in v0.6.6
func GetAvailableInterfaces() ([]NetInterfaceInfo, error)
* * 获取网卡 *
type NetplanConfig ¶
type NetplanConfig struct {
Network Network `yaml:"network" json:"network"`
}
func (*NetplanConfig) ApplyEthConfig ¶
func (nc *NetplanConfig) ApplyEthConfig() error
* * 将配置写入文件并且重启网卡 *
func (*NetplanConfig) FromYaml ¶
func (nc *NetplanConfig) FromYaml(jsons string) error
func (*NetplanConfig) YAMLString ¶
func (nc *NetplanConfig) YAMLString() string
type Network ¶
type Network struct { Version int `yaml:"version" json:"version"` Renderer string `yaml:"renderer" json:"renderer"` Ethernets EthInterface `yaml:"ethernets" json:"ethernets"` }
type TimeZoneInfo ¶
type TimeZoneInfo struct { CurrentTimezone string `json:"currentTimezone"` NTPSynchronized string `json:"NTPSynchronized"` }
* * 时区 *
func GetTimeZone ¶
func GetTimeZone() (TimeZoneInfo, error)
type UnixCameraDevice ¶ added in v0.6.7
type UnixCameraDevice struct { Node string `json:"node"` DeviceID string `json:"deviceId"` Name string `json:"name"` }
* * Unix摄像头 *
func GetUnixVideos ¶ added in v0.6.7
func GetUnixVideos() ([]UnixCameraDevice, error)
* * Unix 获取视频设备 *
type WLANInterface ¶
type WindowsCameraDevice ¶ added in v0.6.7
type WindowsCameraDevice struct { Node string `json:"node"` DeviceID string `json:"deviceId"` Name string `json:"name"` }
* * Windows 获取视频设备 *
func GetWindowsVideos ¶ added in v0.6.7
func GetWindowsVideos() ([]WindowsCameraDevice, error)
* PS C:\Users> WMIC Path Win32_PnPEntity WHERE "Caption LIKE '%CAMERA%'" GET DeviceID,Name /FORMAT:CSV ------ Node,DeviceID,Name DESKTOP-EMD3M3C,USB\VID_1908&PID_2311&MI_00\6&1666943&0&0000,USB2.0 PC CAMERA *
type WlanConfig ¶
type WlanConfig struct {
Wlan0 WLANInterface `yaml:"-" json:"wlan0"`
}
func (*WlanConfig) ApplyWlan0Config ¶
func (nc *WlanConfig) ApplyWlan0Config() error
* * 将配置写入文件并且重启网卡 *
Source Files
¶
- linux_const_value.go
- rhinoh3_ubuntu18_datetime_ctl_linux.go
- rhinoh3_ubuntu18_dhcp_ctl.go
- rhinoh3_ubuntu18_firmware_ctl.go
- rhinoh3_ubuntu18_network_ctl.go
- rhinoh3_ubuntu18_process_ctrl.go
- rhinoh3_ubuntu18xx_netiface_ctl.go
- rhinoh3_ubuntu18xx_netplan_eth_ctl.go
- rhinoh3_ubuntu18xx_netplan_wifi_ctl.go
- rhinoh3_ubuntu18xx_network_ctl.go
- rhinoh3_ubuntu18xx_process_ctrl.go
- rhinopi_ubuntu18xx_wifi_ctrl.go
- rhinopi_ununtu18xx_softrouter_ctl.go
- sysattr_linux.go
- unix_dev_tree_ctrl.go
- unix_video_devices_query.go
- windows_video_devices_query.go