Skip to content

Commit

Permalink
driver experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroTochigi committed Oct 7, 2023
1 parent 3758256 commit 94b1347
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
25 changes: 25 additions & 0 deletions dependencies/createDirectories.sh
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
manageConfigPath=$(pwd)
source $manageConfigPath/vpn/executeBash.sh
7 changes: 7 additions & 0 deletions vpn/executeBash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
manageConfigPath=$(pwd)
source $manageConfigPath/../dependencies/createDirectories.sh

createDirectories
getServerDirectory
getClientDirectory
36 changes: 25 additions & 11 deletions vpn/makeVPNClient.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash

mode=$1
balloonName=$1
Expand All @@ -20,31 +21,44 @@ 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

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
}


Expand Down
6 changes: 6 additions & 0 deletions vpn/makeVPNServer.sh
Original file line number Diff line number Diff line change
@@ -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."
Expand Down

0 comments on commit 94b1347

Please sign in to comment.