- Start migration of dns, network & vpn lib,
- Start migration of rx3_net_adm.
This commit is contained in:
29
usr/sbin/cert_dump
Executable file
29
usr/sbin/cert_dump
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
OPENVPN_DIR=/etc/openvpn
|
||||
|
||||
type=$1
|
||||
host=$2
|
||||
|
||||
case "${type}"
|
||||
in
|
||||
"ca")
|
||||
cat ${OPENVPN_DIR}/tls/certs/ca.crt
|
||||
;;
|
||||
|
||||
"tc")
|
||||
cat ${OPENVPN_DIR}/tls/private/tc.key
|
||||
;;
|
||||
|
||||
"key")
|
||||
cat ${OPENVPN_DIR}/tls/private/${host}.key
|
||||
;;
|
||||
|
||||
"csr")
|
||||
cat ${OPENVPN_DIR}/tls/certs/${host}.csr
|
||||
;;
|
||||
|
||||
"crt")
|
||||
cat ${OPENVPN_DIR}/tls/certs/${host}.crt
|
||||
;;
|
||||
esac
|
||||
19
usr/sbin/ip_host_update
Executable file
19
usr/sbin/ip_host_update
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
host=$1
|
||||
zone=$2
|
||||
ip=$3
|
||||
ttl=$4
|
||||
|
||||
|
||||
|
||||
date="$(date --rfc-3339 seconds)"
|
||||
|
||||
(
|
||||
echo "prereq yxrrset ${host}.${zone}. A"
|
||||
echo "update delete ${host}.${zone}. A"
|
||||
echo "update add ${host}.${zone}. ${ttl} A ${ip}"
|
||||
echo "update delete ${host}.${zone}. TXT"
|
||||
echo "update add ${host}.${zone}. ${ttl} TXT ${date}"
|
||||
echo ""
|
||||
) | nsupdate
|
||||
86
usr/sbin/ns-launch
Executable file
86
usr/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} "$@"
|
||||
42
usr/sbin/openvpn-client-down
Executable file
42
usr/sbin/openvpn-client-down
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
#DEBUG=""
|
||||
#DEBUG="echo"
|
||||
#DEBUG=":"
|
||||
|
||||
#LOG=":"
|
||||
#LOG="echo"
|
||||
#LOG=""
|
||||
|
||||
|
||||
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
. /usr/local/lib/network.bash
|
||||
|
||||
|
||||
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#LOG_FILE=/var/log/openvpn/up-down.log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
network_init
|
||||
|
||||
|
||||
|
||||
line="[${dev}]: Local_Int_Address: [${ifconfig_local}] Remote_Int_Address: [${ifconfig_pool_remote_ip}] Remote_Ext_Addres: [${untrusted_ip}] Common_Name: [${common_name}] Duration: [${time_duration}]"
|
||||
|
||||
log_info "VPN-Client-Down" "$line" " Status: [OK]"
|
||||
|
||||
touch /etc/openvpn/status/${common_name}.status
|
||||
|
||||
log_trace "VPN-Client-Down" "[${dev}]: Done!"
|
||||
45
usr/sbin/openvpn-client-up
Executable file
45
usr/sbin/openvpn-client-up
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
#DEBUG=""
|
||||
#DEBUG="echo"
|
||||
#DEBUG=":"
|
||||
|
||||
#LOG=":"
|
||||
#LOG="echo"
|
||||
#LOG=""
|
||||
|
||||
|
||||
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
. /usr/local/lib/network.bash
|
||||
|
||||
|
||||
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#LOG_FILE=/var/log/openvpn/up-down.log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Output_Param_File="$1"
|
||||
|
||||
|
||||
network_init
|
||||
|
||||
|
||||
|
||||
line="[${dev}]: Local_Int_Address: [${ifconfig_local}] Remote_Int_Address: [${ifconfig_pool_remote_ip}] Remote_Ext_Addres: [${untrusted_ip}] Common_Name: [${common_name}] Output_Param_File: [${Output_Param_File}]"
|
||||
|
||||
log_info "VPN-Client-Up" "$line" " Status: [OK]"
|
||||
|
||||
touch /etc/openvpn/status/${common_name}.status
|
||||
|
||||
log_trace "VPN-Client-Up" "[${dev}]: Done!"
|
||||
46
usr/sbin/openvpn-down
Executable file
46
usr/sbin/openvpn-down
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
#DEBUG=""
|
||||
#DEBUG="echo"
|
||||
#DEBUG=":"
|
||||
|
||||
#LOG=":"
|
||||
#LOG="echo"
|
||||
|
||||
|
||||
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
. /usr/local/lib/network.bash
|
||||
|
||||
|
||||
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#LOG_FILE=/var/log/openvpn/up-down.log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Dev="$1"
|
||||
Local_MTU="$2"
|
||||
Remote_MTU="$3"
|
||||
Local_Address="$4"
|
||||
Local_Netmask="$5"
|
||||
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}] Dst_Table: [${dst_table}] Phase: [${Phase}] Status: [OK]"
|
||||
|
||||
network_device_deinit "" "${Dev}"
|
||||
|
||||
log_trace "VPN-Down" "[${Dev}]: Done!"
|
||||
10
usr/sbin/openvpn-status
Executable file
10
usr/sbin/openvpn-status
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
dev=$1
|
||||
|
||||
if [[ "$1" != "" ]]
|
||||
then
|
||||
cat /var/lib/openvpn/$dev.status
|
||||
else
|
||||
awk '{print FILENAME ": " $0}' /var/lib/openvpn/*.status
|
||||
fi
|
||||
48
usr/sbin/openvpn-up
Executable file
48
usr/sbin/openvpn-up
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
#DEBUG=""
|
||||
#DEBUG="echo"
|
||||
#DEBUG=":"
|
||||
|
||||
#LOG=":"
|
||||
#LOG="echo"
|
||||
#LOG=""
|
||||
|
||||
|
||||
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
. /usr/local/lib/network.bash
|
||||
|
||||
|
||||
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#LOG_FILE=/var/log/openvpn/up-down.log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Dev="$1"
|
||||
Local_MTU="$2"
|
||||
Remote_MTU="$3"
|
||||
Local_Address="$4"
|
||||
Local_Netmask="$5"
|
||||
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}] Status: [OK]"
|
||||
|
||||
network_device_init "" "${Dev}"
|
||||
|
||||
log_trace "VPN-Up" "[${Dev}]: Done!"
|
||||
217
usr/sbin/rx3_net_adm
Executable file
217
usr/sbin/rx3_net_adm
Executable file
@@ -0,0 +1,217 @@
|
||||
#!/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 Variable
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
RETVAL=0
|
||||
prog="rx3-net"
|
||||
|
||||
#DEBUG=""
|
||||
#DEBUG="echo"
|
||||
#DEBUG=":"
|
||||
|
||||
#LOG=":"
|
||||
#LOG="echo"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Start
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
status()
|
||||
{
|
||||
network_status
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Dump
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
dump()
|
||||
{
|
||||
network_tab_dump
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Table_Set
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
table_set()
|
||||
{
|
||||
echo "Setting ip:$1 table:$2"
|
||||
|
||||
network_table_set $1 $2
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Address_Refresh
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
network_init
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
|
||||
restart)
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
;;
|
||||
|
||||
status)
|
||||
status
|
||||
;;
|
||||
|
||||
dump)
|
||||
dump
|
||||
;;
|
||||
|
||||
table_set)
|
||||
table_set $2 $3
|
||||
;;
|
||||
|
||||
refresh_address)
|
||||
address_refresh $2
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status|dump|table_set|refresh_address}"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
network_deinit
|
||||
|
||||
exit $RETVAL
|
||||
137
usr/sbin/rx3_vpn_adm
Executable file
137
usr/sbin/rx3_vpn_adm
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
|
||||
RETVAL=0
|
||||
|
||||
#DEBUG=""
|
||||
#DEBUG="echo"
|
||||
#DEBUG=":"
|
||||
|
||||
#LOG=":"
|
||||
#LOG="echo"
|
||||
|
||||
|
||||
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
. /usr/local/lib/vpn.bash
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Start
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
status()
|
||||
{
|
||||
vpn_status
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Dump
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
dump()
|
||||
{
|
||||
vpn_job_tab_dump
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
vpn_init
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
|
||||
restart)
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
;;
|
||||
|
||||
status)
|
||||
status
|
||||
;;
|
||||
|
||||
dump)
|
||||
dump
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status|dump}"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
vpn_deinit
|
||||
|
||||
exit $RETVAL
|
||||
Reference in New Issue
Block a user