Various small improvements

master
Keith Irwin 2022-09-14 14:44:00 -06:00
parent dc1c89ef7a
commit b92a892254
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
9 changed files with 125 additions and 21 deletions

View File

@ -1,7 +1,7 @@
FROM debian:latest
# Change these
ENV LISTEN_PORT=4410
ENV LISTEN_PORT=4441
ENV ADMIN_EMAIL='me@example.com'
# Install deps
@ -9,7 +9,8 @@ RUN apt-get update && apt-get install --yes \
sudo curl apache2 openssl wireguard-tools dnsutils ipv6calc jq \
&& rm -rf /var/lib/apt/lists/*
# Copy over index.cgi
# Copy over index and libs
# TODO: Copy only needed libs
RUN mkdir /var/www/cgi-bin/ && chown www-data:www-data /var/www/cgi-bin/
COPY admin.cgi /var/www/cgi-bin/index.cgi
COPY lib/ /usr/local/bin/

View File

@ -1,19 +1,23 @@
#!/bin/bash
# FILE: wgapi:back/admin.cgi
# DESCRIPTION: Recieves incoming dashboard API requests
# USAGE: serve
# DESCRIPTION: Recieves incoming admin API requests
# ERRORS:
# 3: Bad usage
# 4: Missing vars vile
# 4: Missing config file
CONFIG_FILE='/etc/wgapi/config'
[ -f "${CONFIG_FILE}" ] || exit 4
source "${CONFIG_FILE}"
if ! [ ${#} -eq 0 ]; then
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >>"${LOGFILE}"
exit 3
fi & if [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
exit 4
fi; source "${CONFIG_FILE}"
case "${REQUEST_METHOD}" in
# List
#'GET') "${LIB_DIR}/peer_list" "${HTTP_X_REAL_IP}";;
# List
#'GET') "${LIB_DIR}/peer_list" "${HTTP_X_REAL_IP}";;
# Add
#'POST') "${LIB_DIR}/peer_add" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
@ -27,4 +31,4 @@ case "${REQUEST_METHOD}" in
# Bad request
*) printf 'Invalid HTTP verb' | "${LIB_DIR}/http_res" 405;;
esac && exit 0
esac

View File

@ -1,7 +1,7 @@
FROM debian:latest
# Change these
ENV LISTEN_PORT=8080
ENV LISTEN_PORT=4442
ENV ADMIN_EMAIL='me@example.com'
# Install deps
@ -9,7 +9,8 @@ RUN apt-get update && apt-get install --yes \
sudo curl apache2 openssl wireguard-tools dnsutils ipv6calc jq \
&& rm -rf /var/lib/apt/lists/*
# Copy over index.cgi
# Copy over cgi and libs
# TODO: Copy only needed libs
RUN mkdir /var/www/cgi-bin/ && chown www-data:www-data /var/www/cgi-bin/
COPY dashboard.cgi /var/www/cgi-bin/index.cgi
COPY lib/ /usr/local/bin/

View File

@ -1,19 +1,23 @@
#!/bin/bash
# FILE: wgapi:back/api/dashboard/index.cgi
# FILE: wgapi:back/dashboard.cgi
# DESCRIPTION: Recieves incoming dashboard API requests
# USAGE: serve
# ERRORS:
# 3: Bad usage
# 4: Missing vars vile
# 4: Missing config file
CONFIG_FILE='/etc/wgapi/config'
[ -f "${CONFIG_FILE}" ] || exit 4
source "${CONFIG_FILE}"
if ! [ ${#} -eq 0 ]; then
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >>"${LOGFILE}"
exit 3
fi & if [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
exit 4
fi; source "${CONFIG_FILE}"
case "${REQUEST_METHOD}" in
# List peers
'GET') "${LIB_DIR}/peer_list" "${HTTP_X_REAL_IP}";;
# List peers
'GET') "${LIB_DIR}/peer_list" "${HTTP_X_REAL_IP}";;
# Add peer
'POST') "${LIB_DIR}/peer_add" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
@ -27,4 +31,4 @@ case "${REQUEST_METHOD}" in
# Bad request
*) printf 'Invalid HTTP verb' | "${LIB_DIR}/http_res" 405;;
esac && exit 0
esac

View File

@ -0,0 +1,31 @@
FROM debian:latest
# Change these
ENV LISTEN_PORT=4400
ENV ADMIN_EMAIL='me@example.com'
# Install deps
RUN apt-get update \
&& apt-get install --yes curl apache2 \
&& rm -rf /var/lib/apt/lists/*
# Copy over cgi and libs
# TODO: Copy only needed libs
RUN mkdir /var/www/cgi-bin/ && chown www-data:www-data /var/www/cgi-bin/
COPY dashboard.cgi /var/www/cgi-bin/index.cgi
COPY lib/ /usr/local/bin/
# Configure apache
RUN a2enmod cgi rewrite
RUN sed -i "s/^Listen 80$/Listen ${LISTEN_PORT}/" \
/etc/apache2/ports.conf
RUN sed -i "s/^<VirtualHost \*:80>$/<VirtualHost *:${LISTEN_PORT}>/" \
/etc/apache2/sites-available/000-default.conf
RUN sed -i "s/ServerAdmin .*$/ServerAdmin ${ADMIN_EMAIL}/" \
/etc/apache2/sites-available/000-default.conf
RUN sed -i "s|DocumentRoot .*$|DocumentRoot /var/www/cgi-bin\n\tScriptAlias / /var/www/cgi-bin/index.cgi|" \
/etc/apache2/sites-available/000-default.conf
# Run time!
EXPOSE ${LISTEN_PORT}
CMD ["apachectl", "-D", "FOREGROUND"]

View File

@ -0,0 +1,34 @@
#!/bin/bash
# FILE: wgapi:back/fed.cgi
# DESCRIPTION: Recieves incoming federated requests
# ERRORS:
# 3: Bad usage
# 4: Missing config file
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 0 ]; then
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >>"${LOGFILE}"
exit 3
fi & if [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
exit 4
fi; source "${CONFIG_FILE}"
case "${REQUEST_METHOD}" in
# List
#'GET') "${LIB_DIR}/peer_list" "${HTTP_X_REAL_IP}";;
# Add
#'POST') "${LIB_DIR}/peer_add" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
# Delete
#'DELETE') "${LIB_DIR}/peer_del" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
# Needed for CORS preflight
'OPTIONS') "${LIB_DIR}/http_res" 200;;
# Bad request
*) printf 'Invalid HTTP verb' | "${LIB_DIR}/http_res" 405;;
esac

View File

@ -19,5 +19,31 @@ services:
context: front
dockerfile: dashboard.Dockerfile
container_name: wgapi-dashboard-frontend
admin-backend:
build:
context: back
dockerfile: admin.Dockerfile
cap_add:
- NET_ADMIN
network_mode: host
container_name: wgapi-admin-backend
volumes:
- '/var/log/wgapi:/var/log/wgapi'
admin-frontend:
build:
context: front
dockerfile: admin.Dockerfile
container_name: wgapi-admin-frontend
# fed-backend:
# build:
# context: back
# dockerfile: fed.Dockerfile
# cap_add:
# - NET_ADMIN
# network_mode: host
# container_name: wgapi-fed-backend
# volumes:
# - '/var/log/wgapi:/var/log/wgapi'

View File

@ -0,0 +1,3 @@
FROM httpd:2.4
COPY admin.html /usr/local/apache2/htdocs/index.html
COPY admin.js /usr/local/apache2/htdocs/admin.js

View File

@ -1,3 +1,3 @@
FROM httpd:2.4
COPY ./dashboard.html /usr/local/apache2/htdocs/index.html
COPY dashboard.html /usr/local/apache2/htdocs/index.html
COPY dashboard.js /usr/local/apache2/htdocs/dashboard.js