From 94b1347b4ebc0ce155f21037f096b419e75f81f9 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 6 Oct 2023 22:44:13 -0500 Subject: [PATCH] driver experiment --- dependencies/createDirectories.sh | 25 +++++++++++++++++++++ driver.sh | 3 +++ vpn/executeBash.sh | 7 ++++++ vpn/makeVPNClient.sh | 36 +++++++++++++++++++++---------- vpn/makeVPNServer.sh | 6 ++++++ 5 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 dependencies/createDirectories.sh create mode 100644 driver.sh create mode 100644 vpn/executeBash.sh diff --git a/dependencies/createDirectories.sh b/dependencies/createDirectories.sh new file mode 100644 index 00000000..0aac2370 --- /dev/null +++ b/dependencies/createDirectories.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +scriptDir="$(dirname "$0")" + +dirPaths=( + "$scriptDir/vpn/server" + "$scriptDir/vpn/client" +) + +createDirectories() { + for dirPath in "${dirPaths[@]}"; do + if [ ! -d "$dirPath" ]; then + mkdir -p "$dirPath" + fi + done +} + +getServerDirectory(){ + echo "$scriptDir/vpn/server" +} + + +getClientDirectory(){ + echo "$scriptDir/vpn/client" +} \ No newline at end of file diff --git a/driver.sh b/driver.sh new file mode 100644 index 00000000..c197038a --- /dev/null +++ b/driver.sh @@ -0,0 +1,3 @@ +#!/bin/bash +manageConfigPath=$(pwd) +source $manageConfigPath/vpn/executeBash.sh \ No newline at end of file diff --git a/vpn/executeBash.sh b/vpn/executeBash.sh new file mode 100644 index 00000000..bce6a21b --- /dev/null +++ b/vpn/executeBash.sh @@ -0,0 +1,7 @@ +#!/bin/bash +manageConfigPath=$(pwd) +source $manageConfigPath/../dependencies/createDirectories.sh + +createDirectories +getServerDirectory +getClientDirectory \ No newline at end of file diff --git a/vpn/makeVPNClient.sh b/vpn/makeVPNClient.sh index ecce1a96..a4a85f79 100755 --- a/vpn/makeVPNClient.sh +++ b/vpn/makeVPNClient.sh @@ -1,3 +1,4 @@ +#!/bin/bash mode=$1 balloonName=$1 @@ -20,6 +21,7 @@ source $manageConfigPath/../dependencies/securitygroupFunction.sh source $manageConfigPath/../dependencies/manageConfig.sh source $manageConfigPath/../dependencies/sshtunnelFunction.sh source $manageConfigPath/../dependencies/reverseShell.sh +source $manageConfigPath/../dependencies/createDirectories.sh source getRunningVPNEntityConfName.sh source deleteEasytlsIClientnline.sh @@ -27,24 +29,36 @@ source deleteEasytlsIClientnline.sh startpath=$(pwd) publicIp=$(getValueByAttribute $balloonName publicIp) +createDirectories + function makeClientConf(){ clientName=$1 - fileName=$clientName.conf + defaultName=$clientName.conf + proxyName=${clientName}Proxy.conf + if [ "$mode" == "proxy" ] then - cp $manageConfigPath/templates/clientProxy.conf /etc/openvpn/client/${clientName}Proxy.conf + cp $manageConfigPath/templates/clientProxy.conf /etc/openvpn/client/$proxyName + sed -i '/ca ca.crt/d' /etc/openvpn/client/$proxyName + sed -i '/cert client.crt/d' /etc/openvpn/client/$proxyName + sed -i '/key client.key/d' /etc/openvpn/client/$proxyName + sed -i '/tls-auth ta.key 1/d' /etc/openvpn/client/$proxyName + + echo '' >> /etc/openvpn/client/$proxyName + cat /usr/share/easy-rsa/pki/easytls/$clientName.inline >> /etc/openvpn/client/$proxyName + cp /etc/openvpn/client/$proxyName $startpath/$proxyName else - cp $manageConfigPath/templates/client.conf /etc/openvpn/client/$fileName + cp $manageConfigPath/templates/client.conf /etc/openvpn/client/$defaultName + sed -i '/ca ca.crt/d' /etc/openvpn/client/$defaultName + sed -i '/cert client.crt/d' /etc/openvpn/client/$defaultName + sed -i '/key client.key/d' /etc/openvpn/client/$defaultName + sed -i '/tls-auth ta.key 1/d' /etc/openvpn/client/$defaultName + + echo '' >> /etc/openvpn/client/$defaultName + cat /usr/share/easy-rsa/pki/easytls/$clientName.inline >> /etc/openvpn/client/$defaultName + cp /etc/openvpn/client/$defaultName $startpath/$defaultName fi - sed -i '/ca ca.crt/d' /etc/openvpn/client/$fileName - sed -i '/cert client.crt/d' /etc/openvpn/client/$fileName - sed -i '/key client.key/d' /etc/openvpn/client/$fileName - sed -i '/tls-auth ta.key 1/d' /etc/openvpn/client/$fileName - - echo '' >> /etc/openvpn/client/$fileName - cat /usr/share/easy-rsa/pki/easytls/$clientName.inline >> /etc/openvpn/client/$fileName - cp /etc/openvpn/client/$fileName $startpath/$fileName } diff --git a/vpn/makeVPNServer.sh b/vpn/makeVPNServer.sh index c033b0ce..bf770491 100755 --- a/vpn/makeVPNServer.sh +++ b/vpn/makeVPNServer.sh @@ -1,6 +1,12 @@ +#!/bin/bash + +source $manageConfigPath/../dependencies/createDirectories.sh + mode=$1 serverName=openvpn-server +createDirectories + if [[ -n "$mode" && "$mode" != "default" && "$mode" != "proxy" ]]; then echo "Invalid mode: $mode. Mode must be 'proxy', 'default', or empty."