first commit

This commit is contained in:
Michaël Ricart 2025-01-28 22:14:34 +01:00
commit 2713045b48
7 changed files with 178 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
build
*.pyc

20
Makefile Normal file
View file

@ -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)

35
make.bat Normal file
View file

@ -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

76
parsers/nginx.py Normal file
View file

@ -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()

27
source/conf.py Normal file
View file

@ -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']

5
source/devices/adama.rst Normal file
View file

@ -0,0 +1,5 @@
=====
Adama
=====

13
source/index.rst Normal file
View file

@ -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/*