-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
225 lines (196 loc) · 4.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package main
import (
iface "github.com/rootshaxor/router-AE/interfaces"
"fmt"
"math/rand"
"time"
"github.com/abiosoft/ishell"
)
var (
app = ishell.New()
r *rand.Rand
intfs = iface.Get_Interface()
)
const (
NAME = "router-AE"
VERSION = "0.0.1"
STATUS = "alpha"
)
func init() {
r = rand.New(rand.NewSource(time.Now().UnixNano()))
app.AutoHelp(true)
app.SetPrompt("[ router-AE ] >> ")
app.DeleteCmd("exit")
app.IgnoreCase(true)
app.AddCmd(&ishell.Cmd{
Name: "exit",
Help: "Exit From Router!",
Func: func(c *ishell.Context) {
if len(c.Args) < 1 {
c.Print("[Warning]: Exit From Router [y/n] ")
ext := c.ReadLine()
switch ext {
case "YES", "Y", "yes", "y":
app.Close()
case "NO", "N", "no", "n":
c.Println("[Info]: Exit Canceled!")
default:
c.Println("[Error]: No Options (", ext, ")")
}
} else {
ext := c.Args[0]
switch ext {
case "YES", "Y", "yes", "y", "-y", "--yes":
app.Close()
case "NO", "N", "no", "n", "-n", "--no":
c.Println("[Info]: Exit Canceled!")
default:
c.Println("[Error]: No Options (", ext, ")")
}
}
},
})
app.AddCmd(&ishell.Cmd{
Name: "banner",
Help: "Print Banner Router-AE",
Func: func(c *ishell.Context) {
Print_Banner()
},
})
}
func Print_Banner() {
var satu, dua, tiga, empat, lima string
satu = `
_
.__ _|_ _ .___/\ |_
|(_)|_||_(/_| /--\|_
`
dua = `
___, ___
/ | / (_)
,_ __ _|_ _ ,_ | | \__
/ | / \_| | | |/ / |-----| | /
|_/\__/ \_/|_/|_/|__/ |_/ \__/\_/\___/
`
tiga = `
__ ___ ______
_________ __ __/ /____ _____ / | / ____/
/ ___/ __ \/ / / / __/ _ \/ ___/_____/ /| | / __/
/ / / /_/ / /_/ / /_/ __/ / /_____/ ___ |/ /___
/_/ \____/\__,_/\__/\___/_/ /_/ |_/_____/
`
empat = `
| \ ____|
__| _ \ | | __| _ \ __| _ \ __|
| ( | | | | __/ |_____| ___ \ |
_| \___/ \__,_|\__|\___|_| _/ _\_____|
`
lima = `
_ _ _____
_ __ ___ _ _| |_ ___ _ __ / \ | ____|
| '__/ _ \| | | | __/ _ \ '__|____ / _ \ | _|
| | | (_) | |_| | || __/ | |_____/ ___ \| |___
|_| \___/ \__,_|\__\___|_| /_/ \_\_____|
`
strlen := 1
const num = "12345"
res := make([]byte, strlen)
for i := range res {
res[i] = num[r.Intn(len(num))]
}
hasil := string(res)
switch hasil {
case "1":
fmt.Println(satu)
case "2":
fmt.Println(dua)
case "3":
fmt.Println(tiga)
case "4":
fmt.Println(empat)
case "5":
fmt.Println(lima)
}
}
func Menu_IPAddress() *ishell.Cmd {
m_ipaddr := &ishell.Cmd{
Name: "ip",
Help: "IPAddress menu",
}
m_ipaddr.AddCmd(&ishell.Cmd{
Name: "print",
Help: "Print Address on Interfaces",
Completer: func([]string) []string {
return intfs
},
Func: func(c *ishell.Context) {
if len(c.Args) < 1 {
iface.Information_Interfaces("all")
} else {
iface.Information_Interfaces(c.Args[0])
}
},
})
m_ipaddr.AddCmd(&ishell.Cmd{
Name: "add",
Help: "Add Address On Interfaces [ipv4/ipv6]",
Completer: func([]string) []string {
return intfs
},
Func: func(c *ishell.Context) {
if len(c.Args) < 2 {
c.Println("[Warning]: you must input IP ADDRESS")
} else {
addr := iface.Check_Address_Interface(c.Args[0], c.Args[1])
switch addr {
case "found":
c.Println("[Warning]: Address alredy found in ", c.Args[0])
case "null":
if err := iface.Check_Address_Valid(c.Args[1]); err != nil {
c.Println("[Error]:", err.Error())
return
}
iface.Add_Address(c.Args[0], c.Args[1])
}
}
},
})
m_ipaddr.AddCmd(&ishell.Cmd{
Name: "del",
Help: "Delete Address On Interfaces",
Completer: func([]string) []string {
return intfs
},
Func: func(c *ishell.Context) {
if len(c.Args) < 1 {
c.Println("[Warning]: Please Select some interface!")
return
} else {
s := iface.Check_Address_FOUND(c.Args[0])
switch s {
case "found":
addr := iface.PrintALL_FoundAddress(c.Args[0])
pilih := c.Checklist(addr, "Please Select Address to Delete ? : ", nil)
out := func() (b []string) {
for _, i := range pilih {
b = append(b, addr[i])
}
return
}
for _, i := range out() {
iface.Del_Address(c.Args[0], i)
}
c.Println("[info]: Delete Success !")
case "null":
c.Println("[Error]: No Address Found in", c.Args[0])
}
}
},
})
return m_ipaddr
}
func main() {
Print_Banner()
app.AddCmd(Menu_IPAddress())
app.Run()
}