Skip to content

Commit 2f03fa3

Browse files
committed
Added Cisco ASA support
1 parent f6a5212 commit 2f03fa3

5 files changed

Lines changed: 75 additions & 27 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ vendor_backups/__pycache__
55
__pycache__
66
.vscode
77
dist
8-
build
8+
build
9+
gui.spec

gui.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import datetime
33
from netmiko import ConnectHandler
44
from ping3 import ping, verbose_ping
5-
from vendor_backups import cisco,fortinet,huawei,juniper,microtik,vyos
5+
from vendor_backups import cisco_ios,cisco_asa,fortinet,huawei,juniper,microtik,vyos
66
import os
77
from tkinter import *
88
from tkinter.ttk import *
@@ -53,34 +53,39 @@ def run_script(user_selection):
5353
else:
5454
# Based on user selection, run the script in the vendor_backups folder. The passed variables are hosts, username, password, and optional secret.
5555
if user_selection == "1":
56-
cisco.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2], list_of_rows[rows][3])
57-
backup_completion_popup(cisco.gui_filename_output)
56+
cisco_ios.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2], list_of_rows[rows][3])
57+
backup_completion_popup(cisco_ios.gui_filename_output)
5858
elif user_selection == "2":
59+
cisco_asa.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2], list_of_rows[rows][3])
60+
backup_completion_popup(cisco_asa.gui_filename_output)
61+
elif user_selection == "3":
5962
juniper.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
6063
backup_completion_popup(juniper.gui_filename_output)
61-
elif user_selection == "3":
64+
elif user_selection == "4":
6265
vyos.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
6366
backup_completion_popup(vyos.gui_filename_output)
64-
elif user_selection == "4":
67+
elif user_selection == "5":
6568
huawei.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
6669
backup_completion_popup(huawei.gui_filename_output)
67-
elif user_selection == "5":
70+
elif user_selection == "6":
6871
fortinet.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
6972
backup_completion_popup(fortinet.gui_filename_output)
70-
elif user_selection == "6":
73+
elif user_selection == "7":
7174
microtik.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
7275
backup_completion_popup(microtik.gui_filename_output)
7376

7477
# Build the button and assign values
75-
tk_cisco = Button(tk_frame, text="Cisco", command=lambda : run_script("1"))
76-
tk_juniper = Button(tk_frame, text="Juniper", command=lambda : run_script("2"))
77-
tk_vyos = Button(tk_frame, text="VyOS", command=lambda : run_script("3"))
78-
tk_huawei = Button(tk_frame, text="Huawei", command=lambda : run_script("4"))
79-
tk_fortinet = Button(tk_frame, text="Fortinet", command=lambda : run_script("5"))
80-
tk_microtik = Button(tk_frame, text="Microtik", command=lambda : run_script("6"))
78+
tk_cisco_ios = Button(tk_frame, text="Cisco IOS", command=lambda : run_script("1"))
79+
tk_cisco_asa = Button(tk_frame, text="Cisco ASA", command=lambda : run_script("2"))
80+
tk_juniper = Button(tk_frame, text="Juniper", command=lambda : run_script("3"))
81+
tk_vyos = Button(tk_frame, text="VyOS", command=lambda : run_script("4"))
82+
tk_huawei = Button(tk_frame, text="Huawei", command=lambda : run_script("5"))
83+
tk_fortinet = Button(tk_frame, text="Fortinet", command=lambda : run_script("6"))
84+
tk_microtik = Button(tk_frame, text="Microtik", command=lambda : run_script("7"))
8185

8286
# Place the button on the GUI
83-
tk_cisco.pack(side=LEFT, padx=5, fill=BOTH, expand=True)
87+
tk_cisco_ios.pack(side=LEFT, padx=5, fill=BOTH, expand=True)
88+
tk_cisco_asa.pack(side=LEFT, padx=5, fill=BOTH, expand=True)
8489
tk_juniper.pack(side=LEFT, padx=5, fill=BOTH, expand=True)
8590
tk_vyos.pack(side=LEFT, padx=5, fill=BOTH, expand=True)
8691
tk_huawei.pack(side=LEFT, padx=5, fill=BOTH, expand=True)

multivendor_run.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from datetime import datetime
44
from netmiko import ConnectHandler
55
from ping3 import ping, verbose_ping
6-
from vendor_backups import cisco,fortinet,huawei,juniper,microtik,vyos
6+
from vendor_backups import cisco_ios,cisco_asa,fortinet,huawei,juniper,microtik,vyos
77
import os
88

9-
# Speciefied CSV file for the script to grab the hosts from.
9+
# Specified CSV file for the script to grab the hosts from.
1010
csv_name = "backup_hosts.csv"
1111

1212
# Checks if the folder exists, if not, it creates it.
@@ -38,25 +38,28 @@ def run_script(user_selection):
3838
else:
3939
# Based on user selection, run the script in the vendor_backups folder. The passed variables are hosts, username, password, and optional secret.
4040
if user_selection == "1":
41-
cisco.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2], list_of_rows[rows][3])
41+
cisco_ios.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2], list_of_rows[rows][3])
4242
elif user_selection == "2":
43-
juniper.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
43+
cisco_asa.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2], list_of_rows[rows][3])
4444
elif user_selection == "3":
45-
vyos.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
45+
juniper.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
4646
elif user_selection == "4":
47-
huawei.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
47+
vyos.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
4848
elif user_selection == "5":
49-
fortinet.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
49+
huawei.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
5050
elif user_selection == "6":
51+
fortinet.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
52+
elif user_selection == "7":
5153
microtik.backup(list_of_rows[rows][0], list_of_rows[rows][1], list_of_rows[rows][2])
5254

5355
# Asks the user what option they are going to use.
5456
print("\n1. Backup Cisco IOS devices.")
55-
print("2. Backup Juniper devices.")
56-
print("3. Backup VyOS routers.")
57-
print("4. Backup Huawei boxes.")
58-
print("5. Backup Fortinet devices.")
59-
print("6. Backup MicroTik devices.\n")
57+
print("2. Backup Cisco ASA devices.")
58+
print("3. Backup Juniper devices.")
59+
print("4. Backup VyOS routers.")
60+
print("5. Backup Huawei boxes.")
61+
print("6. Backup Fortinet devices.")
62+
print("7. Backup MicroTik devices.\n")
6063
user_selection = input("Please pick an option: ")
6164
# Pass the users choice to the main function.
6265
run_script(user_selection)

vendor_backups/cisco_asa.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from netmiko import ConnectHandler
2+
from datetime import datetime
3+
4+
# Current time and formats it to the North American time of Month, Day, and Year.
5+
now = datetime.now()
6+
dt_string = now.strftime("%m-%d-%Y_%H-%M")
7+
8+
9+
# Gives us the information we need to connect to Cisco devices.
10+
def backup(host, username, password, enable_secret):
11+
cisco_asa = {
12+
'device_type': 'cisco_asa',
13+
'host': host,
14+
'username': username,
15+
'password': password,
16+
'secret': enable_secret,
17+
}
18+
# Creates the connection to the device.
19+
net_connect = ConnectHandler(**cisco_asa)
20+
net_connect.enable()
21+
# any reason not to use netmiko built-in func to find a hostname? Try it, and if you like it - replace everywhere. YW
22+
hostname = net_connect.find_prompt().replace('#', '').replace('>', '')
23+
if not hostname:
24+
# Gets and splits the hostname for the output file name.
25+
hostname = net_connect.send_command("show conf | i hostname")
26+
hostname = hostname.split()
27+
hostname = hostname[1]
28+
# Gets the running configuration.
29+
output = net_connect.send_command("show run")
30+
31+
# Creates the file name, which is the hostname, and the date and time.
32+
fileName = hostname + "_" + dt_string
33+
# Creates the text file in the backup-config folder with the special name, and writes to it.
34+
backupFile = open("backup-config/" + fileName + ".txt", "w+")
35+
backupFile.write(output)
36+
print("Outputted to " + fileName + ".txt")
37+
# For the GUI
38+
global gui_filename_output
39+
gui_filename_output = fileName

0 commit comments

Comments
 (0)