117 lines
3.1 KiB
Bash
Executable file
117 lines
3.1 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# (c) IngTegration inc 2023
|
|
# GPL licensed
|
|
#
|
|
|
|
|
|
debug=0
|
|
ClientName="$1"
|
|
ClientNum="$2"
|
|
Corp="$3"
|
|
Endpoint_Usr_PUB_KEY="CHANGE_ME" # put router WG public key here
|
|
RtrSubnetPrefix="10.0.254" # WG subnet prefix
|
|
DnsSrv="1.1.1.1 8.8.8.8"
|
|
AllowedIps="0.0.0.0/0" # Allowed IP for clients
|
|
RtrInterf="wg01" # Router WG Interface
|
|
Endpoint_Usr_Port=51844
|
|
#local CLIENT_NUM=$(printf "%03d" $3)
|
|
#local WgUsrDir="${BaseDir}/${Corp}/users" # BaseDir global variable
|
|
WgUsrDir="."
|
|
Endpoint_Usr_Addr="${RtrSubnetPrefix}.${ClientNum}"
|
|
|
|
|
|
|
|
BOLD=$( tput bold)
|
|
NORMAL=$( tput sgr0)
|
|
RESET=$( tput sgr0)
|
|
NC=$( tput sgr0) # No color
|
|
BOLD=$( tput bold)
|
|
BLACK=$( tput setaf 0)
|
|
RED=$( tput setaf 1)
|
|
GREEN=$( tput setaf 2)
|
|
YELLOW=$( tput setaf 3)
|
|
BLUE=$( tput setaf 4)
|
|
MAGENTA=$( tput setaf 5)
|
|
CYAN=$( tput setaf 6)
|
|
WHITE=$( tput setaf 7)
|
|
DEFAULT=$( tput setaf 9)
|
|
|
|
#===========Internal Functions=================================================
|
|
#
|
|
|
|
#-------------Help-------------------------------------------------------------
|
|
#
|
|
function Help()
|
|
{
|
|
cat << EOF
|
|
usage: $(basename "$0") [ClientName] [ClientNum] [Corp]
|
|
|
|
ClientName : Name of the roadwarrior client (Ex. marlene)
|
|
ClientNum : Roadwarrior sequence number, will translate into ip last octet
|
|
1 --> SubnetPrefix.1 (Ex: 172.16.20.1)
|
|
Corp : Name of RoadWarrior Company (Ex: ExoC)
|
|
|
|
EOF
|
|
exit
|
|
}
|
|
|
|
#---------------Message--------------------------------------------------------
|
|
#
|
|
function Message()
|
|
{
|
|
printf "\n${GREEN}[i] ${BLUE}%s${NC}\n" "$*"
|
|
}
|
|
|
|
|
|
|
|
((!$#)) && Help # Call help if no argument supplied
|
|
|
|
|
|
ClientPadNum=$(printf "%03d" $ClientNum)
|
|
|
|
CLIENT_PRIV_KEY=$(wg genkey)
|
|
CLIENT_PUB_KEY=$(echo "${CLIENT_PRIV_KEY}" | wg pubkey)
|
|
CLIENT_PRE_SHARED_KEY=$(wg genpsk)
|
|
#CLIENT_FILE_PREFIX="${CLIENT_NUM}-${ClientName}"
|
|
CLIENT_FILE_PREFIX="${ClientPadNum}-${Corp}-${ClientName}"
|
|
CLIENT_FILE_WIN="${WgUsrDir}/${CLIENT_FILE_PREFIX}.conf"
|
|
CLIENT_FILE_RTR="${WgUsrDir}/${CLIENT_FILE_PREFIX}.Endpoint.rsc"
|
|
|
|
|
|
|
|
((debug)) && echo -e "
|
|
Corp = $Corp
|
|
ClientName = $ClientName
|
|
CLIENT_FILE_WIN = $CLIENT_FILE_WIN
|
|
CLIENT_FILE_RTR = $CLIENT_FILE_RTR
|
|
" && exit
|
|
|
|
|
|
echo -e "Client:
|
|
${GREEN}---------------------------------------------------------${NC}"
|
|
echo -e "[Interface]
|
|
PrivateKey = ${CLIENT_PRIV_KEY}
|
|
ListenPort = ${Endpoint_Usr_Port}
|
|
Address = ${RtrSubnetPrefix}.${ClientNum}/32
|
|
DNS = ${DnsSrv}
|
|
|
|
[Peer]
|
|
PublicKey = ${Endpoint_Usr_PUB_KEY}
|
|
PresharedKey = ${CLIENT_PRE_SHARED_KEY}
|
|
AllowedIPs = ${AllowedIps}
|
|
Endpoint = ${Endpoint_Usr_Addr}:${Endpoint_Usr_Port}
|
|
PersistentKeepalive = 25
|
|
" | tee "${CLIENT_FILE_WIN}"
|
|
|
|
|
|
echo -e "\n${Corp} Router:
|
|
${GREEN}---------------------------------------------------------${NC}"
|
|
echo -e "/interface wireguard peers
|
|
add allowed-address=${RtrSubnetPrefix}.${ClientNum}/32 disabled=no comment=\"User ${ClientName}\" interface=${RtrInterf} \\
|
|
preshared-key=\"${CLIENT_PRE_SHARED_KEY}\" public-key=\"${CLIENT_PUB_KEY}\"" | tee "${CLIENT_FILE_RTR}"
|
|
|
|
Message "QR Code:"
|
|
qrencode -t ansiutf8 -l L < "${CLIENT_FILE_WIN}"
|
|
qrencode -l L -s 6 -d 225 -o "${CLIENT_FILE_WIN}.png" < "${CLIENT_FILE_WIN}"
|
|
|