utility to clean and sort fortinet config
FortiClean is a CLI tool designed for FortiOS configuration file management for better readability and comparision. Built with Python & leverages the power of the typer library, this utility streamlines the process of:
Unlike other network operatin systems, sections where config order does not matter is hapazardly saved in the order the config was entered making automated & manual diff operations challenging
Clone the repo, move to the directory & run one of the below:
In order of precedence: 1.) .forticleaner in the directory you are running the script from 2.) .forticleaner in your home directory 3.) Default config file included with the package
main [OPTIONS] [SRC_FILE_PATH]
[SRC_FILE_PATH]
: Path to the source file-d, --dst_file_path TEXT
: Path to the write file [default: sorted_config.cfg]-v, --verbose
: Enable level of verbose mode [default: 0]--install-completion
: Install completion for the current shell.--show-completion
: Show completion for the current shell, to copy it or customize the installation.--help
: Show this message and exit.python3 src/main.py config.cfg
$ python3 src/main.py config.cfg -v
[13:42:07] INFO Section 'config vpn certificate local' was DELETED. main.py:27
INFO Removed trailing space(s) from 0 lines. main.py:40
INFO Section 'config system zone' was NOT SORTED main.py:70
INFO Section 'config system interface' was NOT SORTED main.py:70
INFO Section 'config firewall internet-service-name' was SORTED main.py:70
$ python3 src/main.py config.cfg -vv
[13:42:48] DEBUG Config 'src/conf/default.yaml' opened successfully utils.py:57
DEBUG Key 'FORTIOS_CONFIG_FILENAME_REGEX' NOT in the config file. Defaulting to (.*).cfg. utils.py:63
DEBUG File 'config.cfg' opened successfully utils.py:26
INFO Section 'config vpn certificate local' was DELETED. main.py:27
INFO Removed trailing space(s) from 0 lines. main.py:40
INFO Section 'config system zone' was NOT SORTED main.py:70
INFO Section 'config system interface' was NOT SORTED main.py:70
INFO Section 'config firewall internet-service-name' was SORTED main.py:70
DEBUG File 'sorted_config.cfg' written successfully utils.py:38