Skip to content

Commit

Permalink
New features and scripts. Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisMalhadas committed Jul 20, 2023
1 parent ce984d8 commit 19d4617
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 8 deletions.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ RUN apt-get update && \

# Copy the script to the container
COPY getToken.sh /opt/getToken.sh
COPY addToWhiteList.sh /opt/curl_script.sh
#COPY getDeviceId.sh /opt/curl_script.sh
#COPY addToWhiteList.sh /opt/curl_script.sh
#COPY deleteFromWhiteList.sh /opt/curl_script.sh
#COPY setDpnMode.sh /opt/curl_script.sh
#COPY getDpnMode.sh /opt/curl_script.sh
#COPY listTunnels.sh /opt/curl_script.sh
#COPY addTunnels.sh /opt/curl_script.sh
COPY deleteTunnels.sh /opt/curl_script.sh

# Set the script as executable
RUN chmod +x /opt/getToken.sh
Expand Down
67 changes: 61 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Deeper Network Auto Requester (ALPHA)
# Deeper Network CLI (ALPHA)
For the moment it only automates the insertion and removal of ip ranges following the CIDR notation into the Deeper Network device configuration.
You may also use a docker image to run this script. See the [Docker](#docker) section for more information.

This is a work in progress.

## Features
- Thought to work only withtin your network, no external dependencies.
- Handles ranges and lists of arguments.

## Requirements
- Docker (optional)
- Linux Shell
- Curl

## Usage

### Docker
### Docker (used for testing)
1. Build the image
```bash
docker build -t deeper-network-auto-requester .
Expand All @@ -21,18 +25,69 @@
```bash
docker run --rm deeper-network-auto-requester <IP RANGE> <COUNTRY CODE> <USERNAME> <PASSWORD>
```
It only adds, for the moment. If you wish to delete using docker image just edit the dockerfile and switch the comment between lines 9 and 10. And off course build the image again.
To remove the country code is not used.
It only adds, for the moment. If you wish to delete using docker image just edit the dockerfile and switch the comment between lines 10 and 11. And off course build the image again.

### Shell
Get Device ID

```bash
./getDeviceId.sh <USERNAME> <PASSWORD>
```

Get DPN Mode

```bash
./getDpnMode.sh <USERNAME> <PASSWORD>
```

Get Token (login)

```bash
./getToken.sh <USERNAME> <PASSWORD>
```

List Tunnels

```bash
./listTunnels.sh <USERNAME> <PASSWORD>
```

Add Tunnels

```bash
./addTunnel.sh <LIST REGION COUNTRY CODE PAIRS> <USERNAME> <PASSWORD>
```
Example:
```bash
./addTunnels.sh "AMN BM ASC KG" teste password
```

Delete Tunnels

```bash
./deleteTunnels.sh [LIST COUNTRY CODE] <USERNAME> <PASSWORD>
```
Example:
```bash
./deleteTunnels.sh "BM KG" teste password
```

Add to the White List

```bash
./opt/addToWhiteList.sh <IP RANGE> <COUNTRY CODE> <USERNAME> <PASSWORD>
./addToWhiteList.sh <IP RANGE> <COUNTRY CODE> <USERNAME> <PASSWORD>
```
Remove from the White List

```bash
./opt/deleteFromWhiteList.sh <IP RANGE> <USERNAME> <PASSWORD>
./deleteFromWhiteList.sh <IP RANGE> <USERNAME> <PASSWORD>
```

Set DPN Mode (full, smart, disabled)

```bash
./setDpnMode.sh <DPN MODE> <USERNAME> <PASSWORD>
./setDpnMode.sh full <COUNTRY CODE> <USERNAME> <PASSWORD>
```

# Special Thanks
Expand Down
39 changes: 39 additions & 0 deletions addTunnels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Check if all three arguments are provided
if [ $# -ne 3 ]; then
echo "Usage: $0 [region country pair list] <username> <password>"
exit 1
fi

# Parse the IP range, country code, and credentials from arguments
region_country_list=$1
username=$3
password=$4

# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)

# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"

# Read the region and country codes from the list into arrays
mapfile -t regions_countries_array <<< "$region_country_list"

# Loop to execute cURL commands for each IP in the range
for ((i = 0; i < ${#regions_countries_array[@]}; i++)); do
# Extract the region and country codes from the list
current_pair=${regions_countries_array[i]}
current_region=$(echo "$current_pair" | cut -d ' ' -f 1)
current_country=$(echo "$current_pair" | cut -d ' ' -f 2)

# Build the cURL request command
curl_command="curl 'http://34.34.34.34/api/smartRoute/addTunnel' -X 'POST' -H 'Authorization: $bearer_token' --data-binary '{\"regionCode\":\"$current_region\",\"countryCode\":\"$current_country\"}' -H 'Content-Type: application/json'"

# Print the cURL command to console
echo "Executing cURL command: $curl_command"

# Execute the cURL command
eval "$curl_command"
done
2 changes: 1 addition & 1 deletion deleteFromWhiteList.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ $# -ne 3 ]; then
exit 1
fi

# Parse the IP range, country code, and bearer token from arguments
# Parse the IP range, credentials from arguments
ip_range=$1
username=$2
password=$3
Expand Down
28 changes: 28 additions & 0 deletions deleteTunnels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Check if all three arguments are provided
if [ $# -ne 3 ]; then
echo "Usage: $0 [country list] <username> <password>"
exit 1
fi

# Parse the IP range, country code, and credentials from arguments
country_list=$1
username=$2
password=$3

# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)

# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"

# Build the cURL request command
curl_command="curl 'http://34.34.34.34/api/smartRoute/deleteTunnels' -X 'POST' -H 'Authorization: $bearer_token' --data-binary '[\""${country_list// /\",\"}"\"]' -H 'Content-Type: application/json'"

# Print the cURL command to console
echo "Executing cURL command: $curl_command"

# Execute the cURL command
eval "$curl_command"
27 changes: 27 additions & 0 deletions getDeviceID.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Check if all three arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <password>"
exit 1
fi

# Parse the arguments
username=$1
password=$2

# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)

# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"

# Build the cURL request command
curl_command="curl 'http://34.34.34.34/api/smartRoute/getDeviceId' -X 'GET' -H 'Authorization: $bearer_token' -H 'Content-Type: application/json'"

# Print the cURL command to console
echo "Executing cURL command: $curl_command"

# Execute the cURL command
eval "$curl_command"
27 changes: 27 additions & 0 deletions getDpnMode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Check if all three arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <password>"
exit 1
fi

# Parse the arguments
username=$1
password=$2

# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)

# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"

# Build the cURL request command
curl_command="curl 'http://34.34.34.34/api/smartRoute/getDpnMode' -X 'GET' -H 'Authorization: $bearer_token' -H 'Content-Type: application/json'"

# Print the cURL command to console
echo "Executing cURL command: $curl_command"

# Execute the cURL command
eval "$curl_command"
27 changes: 27 additions & 0 deletions listTunnels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Check if all three arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <password>"
exit 1
fi

# Parse the arguments
username=$1
password=$2

# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)

# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"

# Build the cURL request command
curl_command="curl 'http://34.34.34.34/api/smartRoute/listTunnels' -X 'GET' -H 'Authorization: $bearer_token' -H 'Content-Type: application/json'"

# Print the cURL command to console
echo "Executing cURL command: $curl_command"

# Execute the cURL command
eval "$curl_command"
38 changes: 38 additions & 0 deletions setDpnMode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Check if all three arguments are provided
if [ $# -lt 3 ]; then
echo "Usage: $0 <Mode> <username> <password> \n if mode is full specify tunnel code: $0 <Mode> <tunnelCode> <username> <password> \n Note: Killswitch is alsways false for now."
exit 1
fi

# Parse the arguments
mode=$1
if [ "$mode" == "full" ]; then
tunnel=$2
username=$3
password=$4
else
username=$2
password=$3
fi

# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)

# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"

# Build the cURL request command
if [ "$mode" == "full" ]; then
curl_command="curl 'http://34.34.34.34/api/smartRoute/setDpnMode' -X 'POST' -H 'Authorization: $bearer_token' --data-binary '{\"dpnMode\":\"$mode\",\"tunnelCode\":\"$tunnel\",\"killSwitch\":false}' -H 'Content-Type: application/json'"
else
curl_command="curl 'http://34.34.34.34/api/smartRoute/setDpnMode' -X 'POST' -H 'Authorization: $bearer_token' --data-binary '{\"dpnMode\":\"$mode\"}' -H 'Content-Type: application/json'"
fi

# Print the cURL command to console
echo "Executing cURL command: $curl_command"

# Execute the cURL command
eval "$curl_command"

0 comments on commit 19d4617

Please sign in to comment.