mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Added automatic configuration of Cisco Catalyst switch.
This commit is contained in:
8
arena.go
8
arena.go
@@ -283,6 +283,14 @@ func (arena *Arena) SetupNetwork() {
|
||||
log.Printf("Failed to configure team WiFi: %s", err.Error())
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
err := ConfigureTeamEthernet(arena.AllianceStations["R1"].team, arena.AllianceStations["R2"].team,
|
||||
arena.AllianceStations["R3"].team, arena.AllianceStations["B1"].team,
|
||||
arena.AllianceStations["B2"].team, arena.AllianceStations["B3"].team)
|
||||
if err != nil {
|
||||
log.Printf("Failed to configure team Ethernet: %s", err.Error())
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
78
catalyst.go
Normal file
78
catalyst.go
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2014 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Methods for configuring a Cisco Catalyst 3750 switch for team VLANs.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const catalystTelnetPort = 23
|
||||
const eventServerAddress = "10.0.0.50"
|
||||
|
||||
var catalystMutex sync.Mutex
|
||||
|
||||
// Sets up wired networks for the given set of teams.
|
||||
func ConfigureTeamEthernet(red1, red2, red3, blue1, blue2, blue3 *Team) error {
|
||||
command := setupVlan(red1, red1Vlan) + setupVlan(red2, red2Vlan) + setupVlan(red3, red3Vlan) +
|
||||
setupVlan(blue1, blue1Vlan) + setupVlan(blue2, blue2Vlan) + setupVlan(blue3, blue3Vlan)
|
||||
_, err := runCatalystConfigCommand(command)
|
||||
return err
|
||||
}
|
||||
|
||||
func setupVlan(team *Team, vlan int) string {
|
||||
if team == nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("no access-list 1%d\naccess-list 1%d permit ip 10.%d.%d.0 0.0.0.255 host %s\n"+
|
||||
"interface Vlan%d\nip address 10.%d.%d.1 255.255.255.0\n", vlan, vlan, team.Id/100, team.Id%100,
|
||||
eventServerAddress, vlan, team.Id/100, team.Id%100)
|
||||
}
|
||||
|
||||
// Logs into the Catalyst via Telnet and runs the given command in user exec mode. Reads the output and
|
||||
// returns it as a string.
|
||||
func runCatalystCommand(command string) (string, error) {
|
||||
// Make sure multiple commands aren't being run at the same time.
|
||||
catalystMutex.Lock()
|
||||
defer catalystMutex.Unlock()
|
||||
|
||||
// Open a Telnet connection to the switch.
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", eventSettings.SwitchAddress, catalystTelnetPort))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Login to the AP, send the command, and log out all at once.
|
||||
writer := bufio.NewWriter(conn)
|
||||
_, err = writer.WriteString(fmt.Sprintf("%s\nenable\n%s\nterminal length 0\n%sexit\n",
|
||||
eventSettings.SwitchPassword, eventSettings.SwitchPassword, command))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = writer.Flush()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Read the response.
|
||||
var reader bytes.Buffer
|
||||
_, err = reader.ReadFrom(conn)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return reader.String(), nil
|
||||
}
|
||||
|
||||
// Logs into the Catalyst via Telnet and runs the given command in global configuration mode. Reads the output
|
||||
// and returns it as a string.
|
||||
func runCatalystConfigCommand(command string) (string, error) {
|
||||
return runCatalystCommand(fmt.Sprintf("config terminal\n%send\ncopy running-config startup-config\n\n",
|
||||
command))
|
||||
}
|
||||
@@ -14,7 +14,9 @@ CREATE TABLE event_settings (
|
||||
networksecurityenabled bool,
|
||||
apaddress VARCHAR(255),
|
||||
apusername VARCHAR(255),
|
||||
appassword VARCHAR(255)
|
||||
appassword VARCHAR(255),
|
||||
switchaddress VARCHAR(255),
|
||||
switchpassword VARCHAR(255)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -21,6 +21,8 @@ type EventSettings struct {
|
||||
ApAddress string
|
||||
ApUsername string
|
||||
ApPassword string
|
||||
SwitchAddress string
|
||||
SwitchPassword string
|
||||
}
|
||||
|
||||
const eventSettingsId = 0
|
||||
|
||||
@@ -49,6 +49,8 @@ func SettingsPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
eventSettings.ApAddress = r.PostFormValue("apAddress")
|
||||
eventSettings.ApUsername = r.PostFormValue("apUsername")
|
||||
eventSettings.ApPassword = r.PostFormValue("apPassword")
|
||||
eventSettings.SwitchAddress = r.PostFormValue("switchAddress")
|
||||
eventSettings.SwitchPassword = r.PostFormValue("switchPassword")
|
||||
err := db.SaveEventSettings(eventSettings)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
|
||||
@@ -73,9 +73,9 @@ var handleStatus = function(data) {
|
||||
$("#match").attr("data-status", (status == "") ? allianceStation[0] : "");
|
||||
}, 250);
|
||||
}
|
||||
} else {
|
||||
$("#match").attr("data-status", "");
|
||||
}
|
||||
} else {
|
||||
$("#match").attr("data-status", "");
|
||||
}
|
||||
|
||||
if (!blink && blinkInterval) {
|
||||
|
||||
181
switch_config.txt
Normal file
181
switch_config.txt
Normal file
@@ -0,0 +1,181 @@
|
||||
!
|
||||
version 12.1
|
||||
no service pad
|
||||
service timestamps debug uptime
|
||||
service timestamps log uptime
|
||||
no service password-encryption
|
||||
!
|
||||
hostname ChezySwitch
|
||||
!
|
||||
enable secret 5 $1$kKSW$fCMwnMdYvXui1TulfyYHN/
|
||||
!
|
||||
ip subnet-zero
|
||||
ip routing
|
||||
!
|
||||
ip dhcp pool dhcppool
|
||||
network 10.0.100.0 255.255.255.0
|
||||
default-router 10.0.100.1
|
||||
domain-name team254.com
|
||||
dns-server 8.8.8.8 8.8.4.4
|
||||
lease 7
|
||||
!
|
||||
!
|
||||
spanning-tree mode pvst
|
||||
spanning-tree extend system-id
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
interface FastEthernet0/1
|
||||
switchport mode dynamic desirable
|
||||
!
|
||||
interface FastEthernet0/2
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/3
|
||||
switchport mode dynamic desirable
|
||||
!
|
||||
interface FastEthernet0/4
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/5
|
||||
switchport mode dynamic desirable
|
||||
!
|
||||
interface FastEthernet0/6
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/7
|
||||
switchport trunk encapsulation dot1q
|
||||
switchport mode trunk
|
||||
!
|
||||
interface FastEthernet0/8
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/9
|
||||
switchport trunk encapsulation dot1q
|
||||
switchport mode trunk
|
||||
!
|
||||
interface FastEthernet0/10
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/11
|
||||
switchport trunk encapsulation dot1q
|
||||
switchport mode trunk
|
||||
!
|
||||
interface FastEthernet0/12
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/13
|
||||
switchport access vlan 11
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/14
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/15
|
||||
switchport access vlan 12
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/16
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/17
|
||||
switchport access vlan 13
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/18
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/19
|
||||
switchport access vlan 14
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/20
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/21
|
||||
switchport access vlan 15
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/22
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/23
|
||||
switchport access vlan 16
|
||||
switchport mode access
|
||||
!
|
||||
interface FastEthernet0/24
|
||||
switchport access vlan 2
|
||||
switchport mode access
|
||||
!
|
||||
interface GigabitEthernet0/1
|
||||
switchport mode dynamic desirable
|
||||
!
|
||||
interface GigabitEthernet0/2
|
||||
switchport mode dynamic desirable
|
||||
!
|
||||
interface Vlan1
|
||||
ip address 10.0.0.61 255.255.255.0
|
||||
!
|
||||
interface Vlan2
|
||||
ip address 10.0.100.1 255.255.255.0
|
||||
ip access-group 102 in
|
||||
!
|
||||
interface Vlan11
|
||||
ip address 10.0.1.1 255.255.255.0
|
||||
ip access-group 111 in
|
||||
!
|
||||
interface Vlan12
|
||||
ip address 10.0.2.1 255.255.255.0
|
||||
ip access-group 112 in
|
||||
!
|
||||
interface Vlan13
|
||||
ip address 10.0.3.1 255.255.255.0
|
||||
ip access-group 113 in
|
||||
!
|
||||
interface Vlan14
|
||||
ip address 10.0.4.1 255.255.255.0
|
||||
ip access-group 114 in
|
||||
!
|
||||
interface Vlan15
|
||||
ip address 10.0.5.1 255.255.255.0
|
||||
ip access-group 115 in
|
||||
!
|
||||
interface Vlan16
|
||||
ip address 10.0.6.1 255.255.255.0
|
||||
ip access-group 116 in
|
||||
!
|
||||
ip classless
|
||||
ip http server
|
||||
!
|
||||
access-list 102 permit ip 10.0.100.0 0.0.0.255 host 10.0.0.50
|
||||
access-list 111 permit ip 10.0.1.0 0.0.0.255 host 10.0.0.50
|
||||
access-list 112 permit ip 10.0.2.0 0.0.0.255 host 10.0.0.50
|
||||
access-list 113 permit ip 10.0.3.0 0.0.0.255 host 10.0.0.50
|
||||
access-list 114 permit ip 10.0.4.0 0.0.0.255 host 10.0.0.50
|
||||
access-list 115 permit ip 10.0.5.0 0.0.0.255 host 10.0.0.50
|
||||
access-list 116 permit ip 10.0.6.0 0.0.0.255 host 10.0.0.50
|
||||
!
|
||||
line con 0
|
||||
exec-timeout 0 0
|
||||
line vty 0 4
|
||||
password 1234Five
|
||||
login
|
||||
line vty 5 15
|
||||
password 1234Five
|
||||
login
|
||||
!
|
||||
!
|
||||
end
|
||||
@@ -141,6 +141,18 @@
|
||||
<input type="password" class="form-control" name="apPassword" value="{{.ApPassword}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-5 control-label">Switch Address</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="text" class="form-control" name="switchAddress" value="{{.SwitchAddress}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-5 control-label">Switch Password</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="password" class="form-control" name="switchPassword" value="{{.SwitchPassword}}">
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-7 col-lg-offset-5">
|
||||
|
||||
Reference in New Issue
Block a user