- Complete migration,
- Move usr/lib, usr/sbin & var/www to lib, sbin & www, - Add dns_host_update() to dns library, - Add RPM Spec & bash completion files.
This commit is contained in:
275
sbin/cert_dump
Executable file
275
sbin/cert_dump
Executable file
@@ -0,0 +1,275 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 Cert Dump
|
||||
#
|
||||
# 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}/base.bash"
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
declare -g VERSION="1.2.0"
|
||||
declare -g NAME="cert_dump"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-v | --verbose] {ca|tc|key|csr|crt} [host]"
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
declare -g RETVAL=0
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
declare -g OPENVPN_DIR="/etc/openvpn"
|
||||
declare -g TYPE=""
|
||||
declare -g HOST=""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_version_print()
|
||||
{
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_help_print()
|
||||
{
|
||||
cdu_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_args_parse()
|
||||
{
|
||||
tmp_args=$(getopt -o hvV --long help,verbose,version -n "${NAME}" -- "$@")
|
||||
|
||||
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
|
||||
|
||||
eval set -- "${tmp_args}"
|
||||
|
||||
while true
|
||||
do
|
||||
case "$1" in
|
||||
# Options
|
||||
-h|--help) MODE="EXIT"; cdu_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; cdu_version_print; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "${MODE}" != "EXIT" ]]
|
||||
then
|
||||
if [[ "${#}" -lt "1" ]]
|
||||
then
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Not enough args!"
|
||||
cdu_help_print
|
||||
else
|
||||
case "$1" in
|
||||
"ca"|"tc")
|
||||
MODE="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
||||
;;
|
||||
|
||||
"key"|"csr"|"crt")
|
||||
if [[ "${#}" -lt "2" ]]
|
||||
then
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Missing host argument for type: [$1]"
|
||||
cdu_help_print
|
||||
else
|
||||
MODE="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
||||
HOST="$2"
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Invalid type: [$1]"
|
||||
cdu_help_print
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Cert Dump Ca
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_cert_dump_ca()
|
||||
{
|
||||
cat "${OPENVPN_DIR}/tls/certs/ca.crt"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Cert Dump Tc
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_cert_dump_tc()
|
||||
{
|
||||
cat "${OPENVPN_DIR}/tls/private/tc.key"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Cert Dump Key
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_cert_dump_key()
|
||||
{
|
||||
local host="$1"
|
||||
|
||||
cat "${OPENVPN_DIR}/tls/private/${host}.key"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Cert Dump Csr
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_cert_dump_csr()
|
||||
{
|
||||
local host="$1"
|
||||
|
||||
cat "${OPENVPN_DIR}/tls/certs/${host}.csr"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Cert Dump Crt
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_cert_dump_crt()
|
||||
{
|
||||
local host="$1"
|
||||
|
||||
cat "${OPENVPN_DIR}/tls/certs/${host}.crt"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cdu_args_parse "$@"
|
||||
|
||||
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
|
||||
case "${MODE}" in
|
||||
"CA")
|
||||
cdu_cert_dump_ca
|
||||
;;
|
||||
|
||||
"TC")
|
||||
cdu_cert_dump_tc
|
||||
;;
|
||||
|
||||
"KEY")
|
||||
cdu_cert_dump_key "${HOST}"
|
||||
;;
|
||||
|
||||
"CSR")
|
||||
cdu_cert_dump_csr "${HOST}"
|
||||
;;
|
||||
|
||||
"CRT")
|
||||
cdu_cert_dump_crt "${HOST}"
|
||||
;;
|
||||
|
||||
*)
|
||||
cdu_help_print
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
exit ${RETVAL}
|
||||
183
sbin/ip_host_update
Executable file
183
sbin/ip_host_update
Executable file
@@ -0,0 +1,183 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 IP Host Update
|
||||
#
|
||||
# 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}/dns.bash"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
declare -g VERSION="1.0.0"
|
||||
declare -g NAME="ip_host_update"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-v | --verbose] <host> <zone> <ip> <ttl>"
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
declare -g RETVAL=0
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
declare -g HOST=""
|
||||
declare -g ZONE=""
|
||||
declare -g IP=""
|
||||
declare -g TTL=""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ihu_version_print()
|
||||
{
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ihu_help_print()
|
||||
{
|
||||
ihu_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ihu_args_parse()
|
||||
{
|
||||
tmp_args=$(getopt -o hvV --long help,verbose,version -n "${NAME}" -- "$@")
|
||||
|
||||
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
|
||||
|
||||
eval set -- "${tmp_args}"
|
||||
|
||||
while true
|
||||
do
|
||||
case "$1" in
|
||||
# Options
|
||||
-h|--help) MODE="EXIT"; ihu_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; ihu_version_print; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "${MODE}" != "EXIT" ]]
|
||||
then
|
||||
if [[ "${#}" -lt "4" ]]
|
||||
then
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Not enough args!"
|
||||
ihu_help_print
|
||||
else
|
||||
MODE="UPDATE"
|
||||
HOST="$1"
|
||||
ZONE="$2"
|
||||
IP="$3"
|
||||
TTL="$4"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Host Update
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ihu_host_update()
|
||||
{
|
||||
local host="$1"
|
||||
local zone="$2"
|
||||
local ip="$3"
|
||||
local ttl="$4"
|
||||
|
||||
dns_host_update "${host}" "${zone}" "${ip}" "${ttl}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ihu_args_parse "$@"
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "${MODE}" in
|
||||
UPDATE)
|
||||
ihu_host_update "${HOST}" "${ZONE}" "${IP}" "${TTL}"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 <host> <zone> <ip> <ttl>"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit ${RETVAL}
|
||||
86
sbin/ns-launch
Executable file
86
sbin/ns-launch
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -e /etc/sysconfig/rx3-net ] && . /etc/sysconfig/rx3-net
|
||||
|
||||
|
||||
id=$1
|
||||
table=$2
|
||||
shift
|
||||
shift
|
||||
cmd="$(printf " %q" "$@")"
|
||||
|
||||
prefix=10.2
|
||||
|
||||
eth_dev="v-eth${id}"
|
||||
peer_dev="v-peer${id}"
|
||||
peer_addr="${prefix}.${id}.1"
|
||||
eth_addr="${prefix}.${id}.254"
|
||||
eth_mask="255.255.255.0"
|
||||
peer_mask="${eth_mask}"
|
||||
ns_name="darkstar${id}"
|
||||
|
||||
export PATH=$PATH:/usr/local/sbin:/usr/local/bin
|
||||
|
||||
|
||||
|
||||
# Create Net-NS
|
||||
|
||||
ip netns del ${ns_name} 2>/dev/null
|
||||
sleep 3
|
||||
|
||||
ip netns add ${ns_name}
|
||||
|
||||
|
||||
|
||||
# Create v-eth / v-peer
|
||||
|
||||
ip link del ${eth_dev} 2>/dev/null
|
||||
ip link add ${eth_dev} type veth peer name ${peer_dev}
|
||||
|
||||
|
||||
|
||||
# Add v-peer to Net-NS
|
||||
|
||||
ip link set ${peer_dev} netns ${ns_name}
|
||||
|
||||
|
||||
|
||||
# Configure v-eth
|
||||
|
||||
#ip link set ${eth_dev} up
|
||||
#ip link set ${peer_dev} up
|
||||
ifconfig ${eth_dev} ${eth_addr} netmask ${eth_mask} up
|
||||
|
||||
|
||||
|
||||
# Configure lo, v-peer & default route
|
||||
|
||||
ip netns exec ${ns_name} ip link set lo up
|
||||
ip netns exec ${ns_name} ifconfig ${peer_dev} ${peer_addr} netmask ${peer_mask} up
|
||||
ip netns exec ${ns_name} route add default gw ${eth_addr} dev ${peer_dev}
|
||||
|
||||
|
||||
|
||||
# Add rule to table
|
||||
|
||||
ip rule del from ${peer_addr} 2>/dev/null
|
||||
ip rule add from ${peer_addr} table ${table}
|
||||
|
||||
|
||||
|
||||
# Add new route in vpn tables
|
||||
|
||||
route="$(ip route list table main | grep -e ${eth_dev} | grep -e ${eth_addr} | sed 's/ proto.*//')"
|
||||
for tab in ${TABLE_LIST}
|
||||
do
|
||||
ip route del ${route} table ${tab} 2>/dev/null
|
||||
ip route add ${route} table ${tab}
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Run the cmd
|
||||
|
||||
ip netns exec ${ns_name} "$@"
|
||||
75
sbin/openvpn-client-down
Executable file
75
sbin/openvpn-client-down
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 OpenVPN Client Down
|
||||
#
|
||||
# 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.2.0"
|
||||
declare -g NAME="openvpn-client-down"
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
network_init
|
||||
|
||||
|
||||
|
||||
line="[${dev}]: Local_Int_Address: [${ifconfig_local}] Remote_Int_Address: [${ifconfig_pool_remote_ip}] Remote_Ext_Address: [${untrusted_ip}] Common_Name: [${common_name}] Duration: [${time_duration}]"
|
||||
|
||||
log_info "VPN-Client-Down" "${line}"
|
||||
|
||||
touch /etc/openvpn/status/${common_name}.status
|
||||
|
||||
|
||||
|
||||
log_trace "VPN-Client-Down" "[${dev}]: Done!"
|
||||
|
||||
network_deinit
|
||||
77
sbin/openvpn-client-up
Executable file
77
sbin/openvpn-client-up
Executable file
@@ -0,0 +1,77 @@
|
||||
#!/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
|
||||
79
sbin/openvpn-down
Executable file
79
sbin/openvpn-down
Executable file
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 OpenVPN Down
|
||||
#
|
||||
# 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-down"
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local dev="$1"
|
||||
local local_mtu="$2"
|
||||
local remote_mtu="$3"
|
||||
local local_address="$4"
|
||||
local local_netmask="$5"
|
||||
local phase="$6"
|
||||
|
||||
|
||||
network_init
|
||||
|
||||
|
||||
log_info "VPN-Down" "[${dev}]: Local_MTU: [${local_mtu}] Remote_MTU: [${remote_mtu}] Local_Address: [${local_address}] Local_Netmask: [${local_netmask}] Phase: [${phase}]"
|
||||
|
||||
|
||||
network_device_deinit "" "${dev}"
|
||||
|
||||
log_trace "VPN-Down" "[${dev}]: Done!"
|
||||
|
||||
network_deinit
|
||||
193
sbin/openvpn-status
Executable file
193
sbin/openvpn-status
Executable file
@@ -0,0 +1,193 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 OpenVPN Status
|
||||
#
|
||||
# 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}/base.bash"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
declare -g VERSION="1.0.0"
|
||||
declare -g NAME="openvpn-status"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-v | --verbose] [dev]"
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
declare -g RETVAL=0
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
declare -g STATUS_DIR="/var/lib/openvpn"
|
||||
declare -g DEV=""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ovs_version_print()
|
||||
{
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ovs_help_print()
|
||||
{
|
||||
ovs_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ovs_args_parse()
|
||||
{
|
||||
tmp_args=$(getopt -o hvV --long help,verbose,version -n "${NAME}" -- "$@")
|
||||
|
||||
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
|
||||
|
||||
eval set -- "${tmp_args}"
|
||||
|
||||
while true
|
||||
do
|
||||
case "$1" in
|
||||
# Options
|
||||
-h|--help) MODE="EXIT"; ovs_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; ovs_version_print; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "${MODE}" != "EXIT" ]]
|
||||
then
|
||||
if [[ "${#}" -ge "1" ]]
|
||||
then
|
||||
MODE="DEVICE"
|
||||
DEV="$1"
|
||||
else
|
||||
MODE="ALL"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Status Device
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ovs_status_device()
|
||||
{
|
||||
local dev="$1"
|
||||
|
||||
cat "${STATUS_DIR}/${dev}.status"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Status All
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ovs_status_all()
|
||||
{
|
||||
awk '{print FILENAME ": " $0}' "${STATUS_DIR}"/*.status
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ovs_args_parse "$@"
|
||||
|
||||
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
|
||||
case "${MODE}" in
|
||||
DEVICE)
|
||||
ovs_status_device "${DEV}"
|
||||
;;
|
||||
|
||||
ALL)
|
||||
ovs_status_all
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 [dev]"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit ${RETVAL}
|
||||
78
sbin/openvpn-up
Executable file
78
sbin/openvpn-up
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 OpenVPN 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-up"
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local dev="$1"
|
||||
local local_mtu="$2"
|
||||
local remote_mtu="$3"
|
||||
local local_address="$4"
|
||||
local local_netmask="$5"
|
||||
local phase="$6"
|
||||
|
||||
|
||||
network_init
|
||||
|
||||
|
||||
log_info "VPN-Up" "[${dev}]: Local_MTU: [${local_mtu}] Remote_MTU: [${remote_mtu}] Local_Address: [${local_address}] Local_Netmask: [${local_netmask}] Phase: [${phase}]"
|
||||
|
||||
|
||||
network_device_init "" "${dev}"
|
||||
|
||||
log_trace "VPN-Up" "[${dev}]: Done!"
|
||||
|
||||
|
||||
network_deinit
|
||||
317
sbin/rx3_net_adm
Executable file
317
sbin/rx3_net_adm
Executable file
@@ -0,0 +1,317 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 Net Adm
|
||||
#
|
||||
# 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.2.0"
|
||||
declare -g NAME="rx3_net_adm"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-v | --verbose] {start|stop|restart|status|dump|table_set|refresh_address} [args...]"
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
declare -g RETVAL=0
|
||||
declare -g prog="rx3-net"
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_version_print()
|
||||
{
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_help_print()
|
||||
{
|
||||
rna_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_args_parse()
|
||||
{
|
||||
tmp_args=$(getopt -o hvV --long help,verbose,version -n "${NAME}" -- "$@")
|
||||
|
||||
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
|
||||
|
||||
eval set -- "${tmp_args}"
|
||||
|
||||
while true
|
||||
do
|
||||
case "$1" in
|
||||
# Options
|
||||
-h|--help) MODE="EXIT"; rna_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; rna_version_print; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "${MODE}" != "EXIT" ]]
|
||||
then
|
||||
if [[ "${#}" -lt "1" ]]
|
||||
then
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Not enough args!"
|
||||
rna_help_print
|
||||
else
|
||||
case "$1" in
|
||||
start|stop|restart|status|dump|table_set|refresh_address)
|
||||
MODE="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
||||
;;
|
||||
|
||||
*)
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Invalid command: [$1]"
|
||||
rna_help_print
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Start
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_start()
|
||||
{
|
||||
echo "Starting..."
|
||||
|
||||
if [ -r /var/lock/subsys/rx3-net ]
|
||||
then
|
||||
echo "already started"
|
||||
RETVAL=0
|
||||
else
|
||||
network_start
|
||||
|
||||
RETVAL=$?
|
||||
[ "${RETVAL}" = 0 ] && touch /var/lock/subsys/rx3-net
|
||||
fi
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Stop
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_stop()
|
||||
{
|
||||
echo "Stopping..."
|
||||
|
||||
if [ -r /var/lock/subsys/rx3-net ]
|
||||
then
|
||||
network_stop
|
||||
|
||||
RETVAL=$?
|
||||
else
|
||||
echo "already stopped"
|
||||
RETVAL=0
|
||||
fi
|
||||
|
||||
[ "${RETVAL}" = 0 ] && rm -f /var/lock/subsys/rx3-net
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Status
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_status()
|
||||
{
|
||||
network_status
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Dump
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_dump()
|
||||
{
|
||||
network_tab_dump
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Table Set
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_table_set()
|
||||
{
|
||||
echo "Setting ip:$1 table:$2"
|
||||
|
||||
network_table_set "$1" "$2"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Address Refresh
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_address_refresh()
|
||||
{
|
||||
dst_id="$1"
|
||||
|
||||
if [[ "${dst_id}" != "" ]]
|
||||
then
|
||||
echo "Refreshing address: [${dst_id}]..."
|
||||
|
||||
network_dst_tab_get "${dst_id}"
|
||||
network_dst_address_refresh "${dst_id}" "${dst_host_name}" "${dst_ip}"
|
||||
else
|
||||
echo "Refreshing all address..."
|
||||
|
||||
network_dst_address_refresh_all
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rna_args_parse "$@"
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
network_init
|
||||
|
||||
case "${MODE}" in
|
||||
START)
|
||||
rna_start
|
||||
;;
|
||||
|
||||
STOP)
|
||||
rna_stop
|
||||
;;
|
||||
|
||||
RESTART)
|
||||
rna_stop
|
||||
sleep 1
|
||||
rna_start
|
||||
;;
|
||||
|
||||
STATUS)
|
||||
rna_status
|
||||
;;
|
||||
|
||||
DUMP)
|
||||
rna_dump
|
||||
;;
|
||||
|
||||
TABLE_SET)
|
||||
rna_table_set "$2" "$3"
|
||||
;;
|
||||
|
||||
REFRESH_ADDRESS)
|
||||
rna_address_refresh "$2"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status|dump|table_set|refresh_address}"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
network_deinit
|
||||
|
||||
exit ${RETVAL}
|
||||
271
sbin/rx3_vpn_adm
Executable file
271
sbin/rx3_vpn_adm
Executable file
@@ -0,0 +1,271 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Rx3 Vpn Adm
|
||||
#
|
||||
# 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}/vpn.bash"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
declare -g VERSION="1.2.0"
|
||||
declare -g NAME="rx3_vpn_adm"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-v | --verbose] {start | stop | restart | status | dump} [args...]"
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
declare -g RETVAL=0
|
||||
declare -g prog="rx3-vpn"
|
||||
|
||||
declare -g DEBUG=""
|
||||
#declare -g DEBUG="echo"
|
||||
#declare -g DEBUG=":"
|
||||
|
||||
declare -g LOG=""
|
||||
#declare -g LOG=":"
|
||||
#declare -g LOG="echo"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_version_print()
|
||||
{
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_help_print()
|
||||
{
|
||||
rva_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_args_parse()
|
||||
{
|
||||
tmp_args=$(getopt -o hvV --long help,verbose,version -n "${NAME}" -- "$@")
|
||||
|
||||
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
|
||||
|
||||
eval set -- "${tmp_args}"
|
||||
|
||||
while true
|
||||
do
|
||||
case "$1" in
|
||||
# Options
|
||||
-h|--help) MODE="EXIT"; rva_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; rva_version_print; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "${MODE}" != "EXIT" ]]
|
||||
then
|
||||
if [[ "${#}" -lt "1" ]]
|
||||
then
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Not enough args!"
|
||||
rva_help_print
|
||||
else
|
||||
case "$1" in
|
||||
start|stop|restart|status|dump)
|
||||
MODE="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
||||
;;
|
||||
|
||||
*)
|
||||
MODE="EXIT"
|
||||
|
||||
echo_error "Invalid command: [$1]"
|
||||
rva_help_print
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Start
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_start()
|
||||
{
|
||||
echo "Starting..."
|
||||
|
||||
if [ -r /var/lock/subsys/rx3-vpn ]
|
||||
then
|
||||
echo "already started"
|
||||
RETVAL=0
|
||||
else
|
||||
vpn_start
|
||||
|
||||
RETVAL=$?
|
||||
[ "${RETVAL}" = 0 ] && touch /var/lock/subsys/rx3-vpn
|
||||
fi
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Stop
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_stop()
|
||||
{
|
||||
echo "Stopping..."
|
||||
|
||||
if [ -r /var/lock/subsys/rx3-vpn ]
|
||||
then
|
||||
vpn_stop
|
||||
|
||||
RETVAL=$?
|
||||
else
|
||||
echo "already stopped"
|
||||
RETVAL=0
|
||||
fi
|
||||
|
||||
[ "${RETVAL}" = 0 ] && rm -f /var/lock/subsys/rx3-vpn
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Status
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_status()
|
||||
{
|
||||
vpn_status
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Dump
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_dump()
|
||||
{
|
||||
vpn_job_tab_dump
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
rva_args_parse "$@"
|
||||
|
||||
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vpn_init
|
||||
|
||||
case "${MODE}" in
|
||||
START)
|
||||
rva_start
|
||||
;;
|
||||
|
||||
STOP)
|
||||
rva_stop
|
||||
;;
|
||||
|
||||
RESTART)
|
||||
rva_stop
|
||||
sleep 1
|
||||
rva_start
|
||||
;;
|
||||
|
||||
STATUS)
|
||||
rva_status
|
||||
;;
|
||||
|
||||
DUMP)
|
||||
rva_dump
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status|dump}"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
vpn_deinit
|
||||
|
||||
exit ${RETVAL}
|
||||
Reference in New Issue
Block a user