This is a very simple project written in Python and React in order to manage the dnsmasq hosts file.
There are two folders:
dns-backend: contains the API written in python using Flask framework, and some others tools to sync the DNS hosts file.dns-webguifolder contains the web gui itself. The Webgui is written in typescript using React Hooks.
Actually the web-gui it is a very simple React application. It present all hosts in browser using a table with classic web editing button.
In order to use the Web-Gui, first of all you need to compile React application using yarn build command. Then put the compiled application (files created in build directory) on the root directory or other directory of WebServer.
The back-end is a Python application that use flask framework. The dns-backend uses an sqlite3 database file in order to keep the list of DNS names (actually only A and AAAA records). All editing operation are performed on hosts.db sqlite3 database file. The hosts file of dnsmasq is never directly updated.
Inside dns-backend folder, there are some others scripts and systemd descriptors files. These files are used in order to update the dnsmasq hosts file with modifications made on web-gui.
-
dnsapplyconfig.shit is a bash script used to apply the new configuration and restartdnsmasqservice. This script will generate a newhostsfile for dnsmasq, then copy the new file on DNS server usingscp, and then usingsshrestart the service. You have to edit this script and change the linedns_host="dns.example.it"using the hostname or ip address of your DNS server. Also it is required a passwordlessssh, so that the computer where the script runs can connect to DNS server without password. -
dnsmasq-genhosts.pythis python script is used bydnsapplyconfig.shin order to create a newhostsfile from the sqlite3hosts.dbdatabase. -
dnsmonitor.path: it is a systemd descriptor path used to keep monitored the/var/www/cgi-bin/dnsapi/hosts.dbfor modifications. -
dnsmonitor.service: it is the systemd descriptor service triggered bydnsmonitor.pathwhen a change tohosts.dboccurs. This service will run thednsapplyconfig.shscript in order to update the dns configuration.
Here a very short guide on how to compile the front-end
git clone https://github.com/balucio/dnsmasq-webgui.git
cd dnsmasq-webgui/dns-webgui
# this will install the dependency
yarn install
# this will build the compiled web application, take a break because it requires time
yarn buildFor latest yarn version you should add :
export NODE_OPTIONS=--openssl-legacy-provider
npx update-browserslist-db@latest
see Stackoverflow
At end you should find the compiled application in build directory, you can test it using
DANGEROUSLY_DISABLE_HOST_CHECK=true yarn start