Git Product home page Git Product logo

openct's Introduction

pylint pytest

openct

Configuration backup and analysis* tools for devices running pfSense* and RouterOS.

* aspirational

Installation

pipx

pipx install openct

pip

mkdir /opt/openct
cd /opt/openct
apt update
apt install python3.11 python3.11-venv
python3.11 -m venv .venv
. .venv/bin/activate
pip install pip --upgrade
python -m pip install openct

From sources

git clone https://github.com/weehooey/openct
cd openct
poetry install

Setup

Creating a configuration file:

Installed with pipx

openct-setup

From sources or installed with pip

python -m openct.setup

Edit the configuration file:

nano config.yml

SSH Keys

  1. Create a key pair in the project root folder
  2. Copy the public key to the target routers
  3. Add the private key to the config.yml file

Datastore

mkdir -p datastore
touch datastore/datastore.yml

Add the target routers to the datastore in the following format:

- "0.0.0.0"
- "10.10.10.10"
- "192.168.0.1

Logs

mkdir -p logs

Usage

openct

Arguments:

  • --root root directory for the program (default ".")
  • --config path to the config file (default "./config.yml")

Contributing

Feedback

License

Copyright (c) Weehooey Inc. All rights reserved.

Licensed under the GNU GPL v3.0 license.

openct's People

Contributors

chughes741 avatar billzee avatar

Stargazers

 avatar  avatar

openct's Issues

Logging level command line argument/config

Is your feature request related to a problem? Please describe.
Logging level is defaulted to INFO. There is no option to set it to only log higher messages.

Describe the solution you'd like
There should be command line options or a setting in the config file to set logging to certain levels.

PyPI package is broken

Describe the bug
PyPI package is broken. It fails with a "ModuleNotFoundError"

To Reproduce
Steps to reproduce the behavior:

  1. 'python3.11 -m pip install openct==0.1.0'
  2. 'python3.11 -m openct /path/to/config.yml'

Expected behavior
Program should run.

Desktop (please complete the following information):

  • OS: [Win11 - WSL2 - Ubuntu]
  • Version [0.1.0]

Additional Information
Console output:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/user/.local/lib/python3.11/site-packages/openct/__main__.py", line 9, in <module>
    from logging_init import init_logger
ModuleNotFoundError: No module named 'logging_init'

Uncaught SSHException with invalid key file

Terminal Output:

$ make run
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "openct/openct/__main__.py", line 37, in <module>
    if device.is_available():
       ^^^^^^^^^^^^^^^^^^^^^
  File "openct/openct/devices/devices.py", line 18, in is_available
    return self.connection.test_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "openct/openct/connections/connections.py", line 37, in test_connection
    connection.open()
  File "openct/.venv/lib/python3.11/site-packages/fabric/connection.py", line 665, in open
    result = self.client.connect(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "openct/.venv/lib/python3.11/site-packages/paramiko/client.py", line 485, in connect
    self._auth(
  File "openct/.venv/lib/python3.11/site-packages/paramiko/client.py", line 818, in _auth
    raise saved_exception
  File "openct/.venv/lib/python3.11/site-packages/paramiko/client.py", line 794, in _auth
    self._transport.auth_publickey(username, key)
  File "openct/.venv/lib/python3.11/site-packages/paramiko/transport.py", line 1648, in auth_publickey
    raise SSHException("No existing session")
paramiko.ssh_exception.SSHException: No existing session

Support for pfSense devices

Is your feature request related to a problem? Please describe.
The program currently only works with Mikrotik devices.

Describe the solution you'd like
Add support for backing up pfSense devices.

Describe alternatives you've considered

Additional context

Unhandled exceptions

Describe the bug
There are unhandled exceptions when connecting to routers.

  • NoValidConnectionsError
  • UnexpectedExit

Expected behavior
Exceptions should be handled cleanly and the program should continue past those devices.

Screenshots or Console

(.venv) /opt/openct# ./run-openct.py
  6%|██████████▏         | 5.797101449275362/100 [00:04<01:12,  1.29it/s]Traceback (most recent call last):
  File "/opt/openct/./run-openct.py", line 5, in <module>
    runpy.run_module(mod_name='openct')
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/openct/.venv/lib/python3.11/site-packages/openct/__main__.py", line 32, in <module>
    device.fetch_backup()
  File "/opt/openct/.venv/lib/python3.11/site-packages/openct/devices/devices.py", line 40, in fetch_backup
    return self.connection.fetch_backup()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/openct/connections/connections.py", line 60, in fetch_backup
    connection.run("file/remove backup.rsc", hide=True, warn=False)
  File "/opt/openct/.venv/lib/python3.11/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/fabric/connection.py", line 23, in opens
    return method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/fabric/connection.py", line 763, in run
    return self._run(self._remote_runner(), command, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/invoke/context.py", line 113, in _run
    return runner.run(command, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/fabric/runners.py", line 75, in run
    return super().run(command, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/invoke/runners.py", line 395, in run
    return self._run_body(command, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/invoke/runners.py", line 451, in _run_body
    return self.make_promise() if self._asynchronous else self._finish()
                                                          ^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/invoke/runners.py", line 518, in _finish
    raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!

Command: 'file/remove backup.rsc'

Exit code: 1

Stdout:

no such item

Stderr:
(.venv) /opt/openct# ./run-openct.py
  9%|███████████████▌        | 8.823529411764707/100 [00:04<00:49,  1.83it/s]Traceback (most recent call last):
  File "/opt/openct/./run-openct.py", line 5, in <module>
    runpy.run_module(mod_name='openct')
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/openct/.venv/lib/python3.11/site-packages/openct/__main__.py", line 31, in <module>
    if device.is_available():
       ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/openct/devices/devices.py", line 19, in is_available
    return self.connection.test_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/openct/connections/connections.py", line 44, in test_connection
    connection.open()
  File "/opt/openct/.venv/lib/python3.11/site-packages/fabric/connection.py", line 665, in open
    result = self.client.connect(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openct/.venv/lib/python3.11/site-packages/paramiko/client.py", line 409, in connect
    raise NoValidConnectionsError(errors)
paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on x.x.x.x

Add information to log headers

To allow for better diagnostics, add information to the log file (header).

For example:

  • Version of openct
  • Relevant system information
  • Python version

Setup is appending double setups

Describe the bug
When running openct.setup it will append configuration information to an existing config.yml. There is also no terminal output from it.

To Reproduce

python -m openct.setup
python -m openct.setup

Expected behavior
It should either prompt to overwrite an existing config or do nothing. It should also show terminal output of what it did.

Create datastore with setup module

Is your feature request related to a problem? Please describe.
The datastore directory and file needs to be manually created.

Describe the solution you'd like
The datastore could be generated with the config file by running the openct.setup module.

Describe alternatives you've considered
Manually creating the file.

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.