Moved cgi/ to srv/

master
Keith Irwin 2022-08-27 15:57:00 -06:00
parent ab5b1f43b9
commit fcfa70c161
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
11 changed files with 83 additions and 18 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
srv/env

View File

@ -1,16 +0,0 @@
#!/bin/sh
# client
printf 'Content-Type: text/plain\n\nHello client!'
#TODO List peers
# GET /
#TODO Add peer
# POST /
#TODO Delete peer
# DELETE /mypeer
#TODO Update peer
# UPDATE /mypeer

View File

@ -7,7 +7,7 @@ server {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params;
include /etc/nginx/fastcgi.conf;
root /home/ki9/src/wgapi/cgi;
root /home/ki9/src/wgapi/srv;
fastcgi_index client;
}
}
@ -20,7 +20,7 @@ server {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params;
include /etc/nginx/fastcgi.conf;
root /home/ki9/src/wgapi/cgi;
root /home/ki9/src/wgapi/srv;
fastcgi_index fed;
}
}

41
srv/client Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh
# client
source ./env
case "${REQUEST_METHOD}" in
# List peers
"GET")
# Get user from IP
user="$(lib/get-user-from-ip ${REMOTE_ADDR})"
printf "Content-Type: text/plain\n\nHello ${user}\n"
printf "TLD: ${TLD}\n"
#TODO Get or set token
#TODO Send user peers
;;
# Add peer
"POST")
#TODO Get user from IP
#TODO Parse, sanitize, and validate hostname
#TODO Check token
#TODO Check if new peer already exists
#TODO Create IP Addresses and keys
#TODO Loop for each fed server
#TODO Add server to user config as [Peer]
#TODO Add new user device to server config as [Peer]
#TODO Add server_config to local wg (./send/wg add) or federated (./send/fed add)
#TODO: Update nameserver (./send/ns add)
;;
# Delete peer
"DELETE")
;;
# Update peer
"UPDATE")
;;
*) exit 1;;
esac

21
srv/env.sample Executable file
View File

@ -0,0 +1,21 @@
# Change these
export TLD='tld'
export CA_CERT_FILE='/etc/ssl/certs/ca.pem'
export CA_PASSPHRASE="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
export DNS_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxw=="
#TODO Parse ALL this from wg.conf file
export WG_CONFIG_FILE="/etc/wireguard/${TLD}.conf"
export LOCAL_SERVER="host1"
export DNS_MASTER="10.72.0.1"
export IPV4_NET='10.9.0.0/16'
export IPV6_NET='fd69:1337:0:420:f4:abc2/96'
export IPV4_CIDR="${IPV4_NET##*/}" # 16
export IPV4_CIDR_NET="${IPV4_NET%%/*}" # 10.9.0.0
export IPV4_FNET="10.9" # TODO Generate this from CIDR
export IPV4_RNET="9.10" # TODO Generate this from CIDR
export IPV6_CIDR="${IPV6_NET##*/}" # 96
export IPV6_CIDR_NET="${IPV6_NET%%/*}" # fd69:1337:0:420:f4:abc2
export IPV6_FNET="fd69:1337:0:420:f4:abc2" # TODO Generate this from CIDR
export IPV6_RNET="2.c.b.a.4.f.0.0.0.2.4.0.0.0.0.0.7.3.3.1.9.6.d.f" # TODO Generate this from CIDR
export DNS_TTL="86400"

View File

11
srv/lib/get-user-from-ip Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# get-user-from-ip
# https://gitea.ksn.gf4/gf4/wgapi/src/branch/master/includes/helpers.js#L12
# Check args
[ "$#" -ne "1" ] && exit 1
echo "$1"
# Get subnet
# Read wg
#"$1" is the request ip

7
srv/send/ssl Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# send/ssl
printf 'send/ssl\n'
# add
# del
# update