#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Rx3 OpenVPN Client Up
#
# Copyright (C) 2025-2026 Arnaud G. GIBERT
# mailto:arnaud@rx3.net
#
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; If not, see
# <https://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------



#-----------------------------------------------------------------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------------------------------------------------------------

: "${RX3_LIB_DIR:=/usr/lib/rx3}"
. "${RX3_LIB_DIR}/network.bash"





#-----------------------------------------------------------------------------------------------------------------------------------
# Global Variables
#-----------------------------------------------------------------------------------------------------------------------------------

declare -g VERSION="1.0.0"
declare -g    NAME="openvpn-client-up"

declare -g   DEBUG=""
#declare -g   DEBUG="echo"
#declare -g   DEBUG=":"

declare -g     LOG=""
#declare -g     LOG=":"
#declare -g     LOG="echo"





#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------

network_init

output_param_file="$1"



line="[${dev}]: Local_Int_Address: [${ifconfig_local}]   Remote_Int_Address: [${ifconfig_pool_remote_ip}]   Remote_Ext_Address: [${untrusted_ip}]   Common_Name: [${common_name}]   Output_Param_File: [${output_param_file}]"

log_info  "VPN-Client-Up" "${line}"

touch /etc/openvpn/status/${common_name}.status



log_trace "VPN-Client-Up" "[${dev}]: Done!"

network_deinit
