Skip to content

Commit

Permalink
vserion 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KrxkGit committed Nov 4, 2023
1 parent e62ada0 commit 2fe4a6c
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## ❔关于

本项目是Scut校园网路由器管理客户端,基于 Vue3 + go + wails
本项目是Scut校园网路由器管理客户端,基于 Vue3 + go1.21 + wails2.6

## ▶编译前端

Expand Down
63 changes: 63 additions & 0 deletions SSHCommand/RunSSH.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"golang.org/x/crypto/ssh"
"io"
"os"
"strings"
)

type ScutInfo struct {
Expand Down Expand Up @@ -171,6 +172,68 @@ func (s *SSHClass) RunAutoLogin() {
s.RunCommand(cmd)
}

func (s *SSHClass) RunSetNetwork(ip string, dnsArr string, netmask, gateway string) {
log.Info("RunSetNetwork is called")

log.Info("Set interface wan")
if1 := "/etc/config/network.wan." // 接口wan
cmd := fmt.Sprintf("uci set %sproto=static", if1)
cmd += fmt.Sprintf(" && uci set %sipaddr=%s", if1, ip)
cmd += fmt.Sprintf(" && uci set %snetmask=%s", if1, netmask)
cmd += fmt.Sprintf(" && uci set %sgateway=%s", if1, gateway)

log.Info(fmt.Sprintf("DNS列表:%s", dnsArr))
dns := strings.Split(dnsArr, " ")
dnsConcat := ""
for _, dnsItem := range dns {
dnsConcat += dnsItem
dnsConcat += " "
}
dnsConcat = "'" + dnsConcat[:len(dnsConcat)-1] + "'" // 裁剪最后一个空格
cmd += fmt.Sprintf(" && uci set %sdns=%s", if1, dnsConcat)

log.Info("Set interface wan6")
// 增加 interface wan6 选项
cmd += fmt.Sprintf(" && uci set /etc/config/network.wan6=interface")

if2 := "/etc/config/network.wan6." // 接口wan6
cmd += fmt.Sprintf(" && uci set %sproto=dhcpv6", if2)
cmd += fmt.Sprintf(" && uci set %sreqaddress=try", if2)
cmd += fmt.Sprintf(" && uci set %sreqprefix=auto", if2)
cmd += fmt.Sprintf(" && uci set %speerdns=0", if2)
cmd += fmt.Sprintf(" && uci set %sdns=%s", if2, "'2400:3200::1 2400:3200:baba::1'")

log.Info("Set dhcp lan")
if3 := "/etc/config/dhcp.lan." // dhcp lan
cmd += fmt.Sprintf(" && uci set %sdhcpv4=server", if3)
cmd += fmt.Sprintf(" && uci set %sra=relay", if3)
cmd += fmt.Sprintf(" && uci set %sdhcpv6=relay", if3)
cmd += fmt.Sprintf(" && uci set %sndp=relay", if3)

log.Info("Set dhcp wan6")
// 增加 dhcp wan6 选项
cmd += fmt.Sprintf(" && uci set /etc/config/dhcp.wan6=dhcp")

if4 := "/etc/config/dhcp.wan6." // dhcp wan6
cmd += fmt.Sprintf(" && uci set %sdhcpv4=server", if4)
cmd += fmt.Sprintf(" && uci set %sra=relay", if4)
cmd += fmt.Sprintf(" && uci set %sdhcpv6=relay", if4)
cmd += fmt.Sprintf(" && uci set %sndp=relay", if4)
cmd += fmt.Sprintf(" && uci set %smaster=1", if4)

cmd += fmt.Sprintf(" && uci delete %sdns", if4)
cmd += fmt.Sprintf(" && uci add_list %sdns=2606:4700:4700::1111", if4)
cmd += fmt.Sprintf(" && uci add_list %sdns=2001:4860:4860::8888", if4)

log.Info("Set dhcp wan")
if5 := "/etc/config/dhcp.wan." // dhcp wan
cmd += fmt.Sprintf(" && uci set %signore=1", if5)

cmd += fmt.Sprintf(" && service network restart")
s.RunCommand(cmd)
log.Info("SetNetwork finished")
}

func (s *SSHClass) CancelAutoLogin() {
log.Info("CancelAutoLogin is called")

Expand Down
3 changes: 3 additions & 0 deletions ScutLog.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"time":"2023-11-04T17:29:19.0832432+08:00","level":"ERROR","prefix":"-","file":"RunSSH.go","line":"55","message":"ssh: handshake failed: EOF"}
{"time":"2023-11-04T17:29:19.1396842+08:00","level":"ERROR","prefix":"-","file":"RunSSH.go","line":"35","message":"Dial Fails: ssh: handshake failed: EOF"}
{"time":"2023-11-04T17:29:19.1396842+08:00","level":"ERROR","prefix":"-","file":"RunSSH.go","line":"67","message":"New Session Fails: ssh: handshake failed: EOF"}
5 changes: 4 additions & 1 deletion frontend/src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
<MenuGroup title="账号密码">
<MenuItem name="2-1" @click="$router.push('/MainInfo')">账号密码</MenuItem>
</MenuGroup>
<MenuGroup title="网络接口">
<MenuItem name="2-2" @click="$router.push('/NetworkInfo')">上网接口</MenuItem>
</MenuGroup>
<MenuGroup title="认证服务器">
<MenuItem name="2-2" @click="$router.push('/ACInfo')">认证服务器</MenuItem>
<MenuItem name="2-3" @click="$router.push('/ACInfo')">认证服务器</MenuItem>
</MenuGroup>
</Submenu>
<Submenu name="3">
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ACInfo from '../views/ACInfo.vue'
import WiredLogin from '../views/WiredLogin.vue'
import WirelessLogin from '../views/WirelessLogin.vue'
import SyncTime from "../views/SyncTime.vue"
import NetworkInfo from "../views/NetworkInfo.vue"

const routes = [
{
Expand Down Expand Up @@ -36,6 +37,11 @@ const routes = [
path: '/SyncTime',
name: 'sync-time',
component: SyncTime
},
{
path: '/NetworkInfo',
name: 'network-info',
component: NetworkInfo
}
]

Expand Down
71 changes: 71 additions & 0 deletions frontend/src/views/NetworkInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script>
import { ref } from 'vue'
import MyMenu from '../components/Menu.vue'
import { RunSetNetwork } from '../../wailsjs/go/SSHCommand/SSHClass'
function PackDns(dns1, dns2) {
// eslint-disable-next-line no-array-constructor
const dnsArr = `${dns1} ${dns2}`
return dnsArr
}
export default {
data() {
return {
IP: '',
DNS1: '',
DNS2: '',
netmask: '',
gateway: '',
}
},
components: {
MyMenu
},
methods: {
OnSubmit() {
RunSetNetwork(this.IP, PackDns(this.DNS1, this.DNS2), this.netmask, this.gateway)
// alert(`${this.IP} | ${this.DNS1} | ${this.DNS2} | ${this.netmask} | ${this.gateway}`)
alert('完成')
}
},
name: 'NetworkInfo'
}
</script>

<template>
<div class="NetWorkInfo">
<MyMenu/>
<div>
<Card style="width:80%" id="net_card">
<div style="text-align:center">
<h1>配置网络接口</h1>
<br v-for="index of 1" :id="index"/>
<h3>Scut Interface</h3>
<br/>
<Input v-model="IP" placeholder="请输入Scut IP" style="width: 200px" clearable="true"/>
<br v-for="index of 2" :id="index"/>
<Input v-model="netmask" placeholder="请输入Scut NetMask" style="width: 200px" clearable="true"/>
<br v-for="index of 2" :id="index"/>
<Input v-model="gateway" placeholder="请输入Scut GateWay" style="width: 200px" clearable="true"/>
<br v-for="index of 2" :id="index"/>
<Input v-model="DNS1" placeholder="请输入Scut DNS1" style="width: 200px" clearable="true"/>
<br v-for="index of 2" :id="index"/>
<Input v-model="DNS2" placeholder="请输入Scut DNS2" style="width: 200px" clearable="true"/>
<br v-for="index of 2" :id="index"/>
<Button type="success" @click="OnSubmit">保存并应用</Button>
</div>
</Card>
</div>
</div>
</template>

<style scoped>
.NetWorkInfo {
text-align: center;
position: relative;
}
#net_card {
margin: 5% auto;
}
</style>
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/SSHCommand/SSHClass.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function RunCommand(arg1:string):Promise<void>;

export function RunSetAcInfo(arg1:string,arg2:string):Promise<void>;

export function RunSetNetwork(arg1:string,arg2:string,arg3:string,arg4:string):Promise<void>;

export function RunSetScutInfo(arg1:string,arg2:string):Promise<void>;

export function RunSyncTime():Promise<void>;
Expand Down
4 changes: 4 additions & 0 deletions frontend/wailsjs/go/SSHCommand/SSHClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function RunSetAcInfo(arg1, arg2) {
return window['go']['SSHCommand']['SSHClass']['RunSetAcInfo'](arg1, arg2);
}

export function RunSetNetwork(arg1, arg2, arg3, arg4) {
return window['go']['SSHCommand']['SSHClass']['RunSetNetwork'](arg1, arg2, arg3, arg4);
}

export function RunSetScutInfo(arg1, arg2) {
return window['go']['SSHCommand']['SSHClass']['RunSetScutInfo'](arg1, arg2);
}
Expand Down

0 comments on commit 2fe4a6c

Please sign in to comment.