diff --git a/ap_config.txt b/ap_config.txt index aa2f165..aedff7b 100644 --- a/ap_config.txt +++ b/ap_config.txt @@ -303,4 +303,4 @@ line vty 0 4 transport input all ! sntp server 216.66.0.142 -end \ No newline at end of file +end diff --git a/arena.go b/arena.go index c76aa5a..6dd4592 100644 --- a/arena.go +++ b/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()) + } + }() } } diff --git a/catalyst.go b/catalyst.go new file mode 100644 index 0000000..fa9bdd7 --- /dev/null +++ b/catalyst.go @@ -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)) +} diff --git a/db/migrations/20140524160241_CreateEventSettings.sql b/db/migrations/20140524160241_CreateEventSettings.sql index 0ca2ba2..8709f8d 100644 --- a/db/migrations/20140524160241_CreateEventSettings.sql +++ b/db/migrations/20140524160241_CreateEventSettings.sql @@ -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 diff --git a/event_settings.go b/event_settings.go index 96ff56d..6c8f76e 100644 --- a/event_settings.go +++ b/event_settings.go @@ -21,6 +21,8 @@ type EventSettings struct { ApAddress string ApUsername string ApPassword string + SwitchAddress string + SwitchPassword string } const eventSettingsId = 0 diff --git a/setup_settings.go b/setup_settings.go index 4ce6be0..7ebe72a 100644 --- a/setup_settings.go +++ b/setup_settings.go @@ -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) diff --git a/static/js/alliance_station_display.js b/static/js/alliance_station_display.js index 4d8a2b0..314f26f 100644 --- a/static/js/alliance_station_display.js +++ b/static/js/alliance_station_display.js @@ -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) { diff --git a/switch_config.txt b/switch_config.txt new file mode 100644 index 0000000..9e569ca --- /dev/null +++ b/switch_config.txt @@ -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 diff --git a/templates/settings.html b/templates/settings.html index 239d5d8..df4a02c 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -141,6 +141,18 @@ +
+ +
+ +
+
+
+ +
+ +
+