#
# Remote Network Connection™ by CloudTrust
#
# The Remote Network Connection™ has been designed in compliance with the EU NIS2 Directive (Directive 2022/2555/EU) and the relevant national cybersecurity requirements.
#
# It is intended for use by qualified personnel only.
# Please ensure you understand its functionality before running, as improper use may lead to unintended results.
#
# These files were created by CloudTrust experts in 2025.
# https://cloudtrust.solutions

########################################################
# Remote Network Connection™ setup for Docker Container
########################################################
FROM mcr.microsoft.com/dotnet/sdk
#FROM mcr.microsoft.com/dotnet/runtime

ENV RNC_TICKET_ID=
ENV RNC_SERVER_ADDRESS=services.rnc.services
ENV RNC_NETWORK_PASSPHRASE=

# Installing required packages
RUN apt-get update
RUN apt-get upgrade -y 
RUN apt-get install sudo
RUN apt-get install libunwind8
RUN apt-get install wget
RUN apt-get install openssl
RUN apt-get install uuid-runtime

# Download Remote Network Connection setup10.tar.gz package
RUN wget https://rnc.services/setup.tar.gz

# Extracting Remote Network Connection application
RUN mkdir ./root/bin
RUN tar -zxvf setup10.tar.gz -C ./root/bin

# Setting up Remote Network Connection appsettings.json parameter file
RUN echo "{" >> ./root/bin/appsettings.json
RUN echo "  \"TicketID\" :  \"$RNC_TICKET_ID\"," >> ./root/bin/appsettings.json
RUN echo "  \"ServerAddress\" :  \"$RNC_SERVER_ADDRESS:443\"," >> ./root/bin/appsettings.json
RUN echo -n "  \"NetworkPassphrase\" :  \"" >> ./root/bin/appsettings.json
RUN printf $RNC_NETWORK_PASSPHRASE | openssl base64 | awk 'BEGIN{ORS="";} {print}' >> ./root/bin/appsettings.json
RUN echo "\"," >> ./root/bin/appsettings.json
RUN echo -n "  \"MemberID\" :  \"" >> ./root/bin/appsettings.json
RUN echo "" | uuidgen | tr /a-z/ /A-Z/ | tr "\n" "\"," >> ./root/bin/appsettings.json
RUN echo "," >> ./root/bin/appsettings.json
RUN echo "  \"MemberDescription\" :  \"$HOSTNAME\"" >> ./root/bin/appsettings.json
RUN echo "}" >> ./root/bin/appsettings.json

# Finalizing Remote Network Connection setup
RUN chmod u+x ./root/bin/RNCLnxClient.out

# Running Remote Network Connection application
WORKDIR ./root/bin/
ENTRYPOINT ["dotnet", "RNCService.dll"]

# Running Docker contatiner with Remote Network Connection application
#docker run -d \
#  --privileged \
#  --cap-add=NET_ADMIN \
#  --device=/dev/net/tun:/dev/net/tun \
#  -it \
#  rnc-docker:latest

