commit 2713045b48c9212cd880e70fac50f70580eabb18 Author: Michaël Ricart Date: Tue Jan 28 22:14:34 2025 +0100 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f97ca1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +*.pyc diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d0c3cbf --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/make.bat b/make.bat new file mode 100644 index 0000000..747ffb7 --- /dev/null +++ b/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/parsers/nginx.py b/parsers/nginx.py new file mode 100644 index 0000000..3e4a99b --- /dev/null +++ b/parsers/nginx.py @@ -0,0 +1,76 @@ +#!/bin/env python3 +import sys +import bs4 +import requests +from urllib.parse import urlparse, urlunparse +from os import listdir +from os.path import isfile, join + +def find_icon(domain): + resp = requests.get("http://{}/".format(domain)) + page = bs4.BeautifulSoup(resp.text, 'html.parser') + res = "http://{}/favicon.ico".format(domain) + icons = [e for e in page.find_all(name='link') if 'icon' in e.attrs.get('rel')] + if icons: + res = icons[0].attrs.get('href') + url = urlparse(res, scheme='http') + if not url.netloc: + res = urlunparse((url.scheme, domain, url.path, '', '', '')) + return res + +def download(domain, icon_url): + i = icon_url.find('.', len(icon_url)-4) + if i>=0: + ext = icon_url[i+1:] + else: + ext = 'ico' + fname = "{}.{}".format(domain, ext) + resp = requests.get(icon_url) + with open(fname, 'wb') as out: + out.write(resp.content) + return icon_url + +def main(): + mypath = "/var/home/mika/projects/dev/nginx-config/conf.d/" + + onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] + url = port = ip = "" + result = {} + for file in onlyfiles: + if file.endswith("conf"): + with open(mypath + file, 'r', encoding="utf-8") as f: + content = f.read() + for line in content.splitlines(): + if line.strip().startswith("#"): + continue + elif "name" in line: + url = line.split()[1].replace(";", "") + elif "proxy_pass" in line: + ip,port = line.split()[-1].replace(";", "").rsplit(":",1) + if len(port.split("/")) > 1: + port, end_url = port.split("/") + ip = ip + "/" + end_url + ip = ip.replace("http://", "").replace("https://", "") + if all([url, ip, port]): + result[url] = { + "dest":ip, + "port":port, + "icon": download(url, find_icon(url)) + } + #print(dict(sorted(result.items(), key=lambda item: item[1]))) + + for key in result.keys(): + print('''"{url}": {{icon: {icon} }}'''.format( + url = key, + icon = result[key]["icon"], + ) + ) + print('''"{url}" -> "{dest}": "{port}"'''.format( + url = key, + dest = result[key]["dest"], + port = result[key]["port"] + ) + ) + +if __name__ == "__main__": + main() diff --git a/source/conf.py b/source/conf.py new file mode 100644 index 0000000..9e95b13 --- /dev/null +++ b/source/conf.py @@ -0,0 +1,27 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'Doc Infra' +copyright = '2025, Michaël Ricart' +author = 'Michaël Ricart' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [] + +templates_path = ['_templates'] +exclude_patterns = [] + +language = 'fr' + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'alabaster' +html_static_path = ['_static'] diff --git a/source/devices/adama.rst b/source/devices/adama.rst new file mode 100644 index 0000000..5dab128 --- /dev/null +++ b/source/devices/adama.rst @@ -0,0 +1,5 @@ +===== +Adama +===== + + diff --git a/source/index.rst b/source/index.rst new file mode 100644 index 0000000..ba16602 --- /dev/null +++ b/source/index.rst @@ -0,0 +1,13 @@ +.. Doc Infra documentation master file, created by + sphinx-quickstart on Tue Jan 28 21:48:24 2025. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Doc Infra +========= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + devices/*