Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pww217 committed Jul 15, 2023
1 parent be69bde commit 0ab918c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 47 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

WORKDIR /app

COPY . .

ENV TZ=America/Chicago

RUN apt-get update && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
&& apt-get install -y python3 python3-pip openssh-client
RUN pip3 install -r requirements.txt
&& apt-get install -y python3 python3-pip openssh-client \
&& pip3 install -r requirements.txt

CMD python3 main.py
48 changes: 6 additions & 42 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
from flask import Flask, request, render_template, redirect
import logging.config
import logging
from netmiko import ConnectHandler, ssh_exception
from netmiko import ConnectHandler, NetmikoAuthenticationException, NetmikoTimeoutException
import os

"""
Flask-based Netmiko application for Cisco IOS and Linux
Peter W
Github.com/pww217
To do: (* means done)
1. Cleaner landing page *
2. Better exception handling and logging *
3. File cleanup *
4. Hide password on browser *
5. Revamp index with radio, checkbox, redirectors *
6. Implement Cisco pages *
7. Add show host file page *
8. Implement logging *
9. Spruce up UI
10. More debugging *
11. Dark Mode?!?!
12. User/Password/Command exceptions*
13. Specific error at index page for missing fields*
14. Add show log to index page*
Reach goals:
1. Implement real database
2. Allow for multiple concurrent users (hosts.txt would need to separate sessions)
3. Encrypt password in memory or db
4. Build into docker container *
5. Implemented automated testing
6. HTTPS
7. SSH key support - branch key_support
8. NX-OS Support
9. Github Actions pipeline for app*
10. DockerHub Deployment*
11. Pre-deployment testing
12. Cache Docker layers for faster deploy
13. Pipeline for infrastructure* (terratest)
https://github.com/pww217
"""

# ~~~ Global Variables
Expand Down Expand Up @@ -73,7 +37,7 @@
'backupCount': 5,
}},
'root': {
'level': 'INFO',
'level': 'DEBUG',
'handlers': ['wsgi', 'file']
}
})
Expand Down Expand Up @@ -159,17 +123,17 @@ def run_command(hosts, os_type, user, password, command, enable_mode='None'):
if enable_mode == 'on': # Check for enable mode and activate
connection.enable()
reply = f'<h3>{device} returned the following output:</h3>'+ \
connection.send_command(command) # Runs a single command
connection.send_command(command, expect_string="[\\ ~\\#]") # Runs a single command
write_output_file(reply)
logging.info(f'Wrote {device} output to file')
connection.disconnect() # Graceful SSH disconnect
# Common exceptions and a catch-all
except ssh_exception.NetmikoTimeoutException:
except NetmikoTimeoutException:
message = f'<h3>{device} could not be reached on port 22 - ' \
'skipping to next device.</h3>'
logging.warning(message.replace('</h3>', '').replace('<h3>', ''))
write_output_file(message)
except ssh_exception.NetmikoAuthenticationException:
except NetmikoAuthenticationException:
message = f'<h3>{device} had invalid credentials</h3>'
logging.warning(message.replace('</h3>', '').replace('<h3>', ''))
write_output_file(message)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flask
netmiko
flask==2.3.2
netmiko==4.2.0

0 comments on commit 0ab918c

Please sign in to comment.