Skip to content

Commit 98044bf

Browse files
committed
add complete set of tf configs
1 parent 9c9d2b4 commit 98044bf

File tree

8 files changed

+423
-0
lines changed

8 files changed

+423
-0
lines changed

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/terraform,visualstudiocode
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=terraform,visualstudiocode
3+
4+
### Terraform ###
5+
# Local .terraform directories
6+
**/.terraform/*
7+
8+
# Teraform lock file
9+
.terraform.lock.hcl
10+
11+
# .tfstate files
12+
*.tfstate
13+
*.tfstate.*
14+
15+
# Crash log files
16+
crash.log
17+
crash.*.log
18+
19+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
20+
# password, private keys, and other secrets. These should not be part of version
21+
# control as they are data points which are potentially sensitive and subject
22+
# to change depending on the environment.
23+
*.tfvars
24+
*.tfvars.json
25+
26+
# Ignore override files as they are usually used to override resources locally and so
27+
# are not checked in
28+
override.tf
29+
override.tf.json
30+
*_override.tf
31+
*_override.tf.json
32+
33+
# Include override files you do wish to add to version control using negated pattern
34+
# !example_override.tf
35+
36+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
37+
# example: *tfplan*
38+
39+
# Ignore CLI configuration files
40+
.terraformrc
41+
terraform.rc
42+
43+
### VisualStudioCode ###
44+
.vscode/*
45+
!.vscode/settings.json
46+
!.vscode/tasks.json
47+
!.vscode/launch.json
48+
!.vscode/extensions.json
49+
!.vscode/*.code-snippets
50+
51+
# Local History for Visual Studio Code
52+
.history/
53+
54+
# Built Visual Studio Code Extensions
55+
*.vsix
56+
57+
### VisualStudioCode Patch ###
58+
# Ignore all local history of files
59+
.history
60+
.ionide
61+
62+
# End of https://www.toptal.com/developers/gitignore/api/terraform,visualstudiocode

README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Proxy Forge
2+
3+
Proxy Forge is a free and open-source tool that helps you to set up OSI level 4 proxies with rotating IPs on the Digital Ocean platform. It is a powerful and innovative solution that addresses one of the most pressing challenges faced by developers and businesses in today's digital landscape: IP throttling and blacklisting. Proxy Forge empowers you to conquer these obstacles by providing a seamless, reliable, and easy-to-deploy solution.
4+
5+
In simpler terms, Proxy Forge helps you to create a pool of rotating IP addresses that you can use to access the internet. This can be useful for a variety of purposes, such as avoiding IP bans, scraping websites, and testing web applications.
6+
7+
Proxy Forge is a powerful tool that can be used by both developers and businesses. It is easy to use and deploy, and it provides a number of features that make it a valuable tool for anyone who needs to access the internet anonymously or avoid IP bans.
8+
9+
## Features
10+
11+
- **Rotating IPs:** Automatically rotates IP addresses from a set of deployed droplets to avoid detection and blacklisting.
12+
- **Terraform Scripts:** Provides Terraform scripts for straightforward setup and management.
13+
- **Scalability:** Easily scale your proxy fleet up or down to handle your specific needs.
14+
- **Customizable Configuration:** Fine-tune proxy settings to match your requirements. (check [below](#customizations))
15+
- **IP Throttling Avoidance:** Effectively bypass IP throttling mechanisms used by websites and services.
16+
- **Detailed Logging:** Comprehensive logging for monitoring and troubleshooting.
17+
- **Open Source:** Proxy Forge is open-source, allowing for community contributions and customization.
18+
19+
## Why DigitalOcean?
20+
21+
There are many reasons why you might choose to use DigitalOcean over other cloud providers. Some of the key benefits include:
22+
23+
- **Simplicity:** DigitalOcean is known for its simple and user-friendly interface. It is easy to get started with DigitalOcean, even if you are new to cloud computing.
24+
- **Affordability:** DigitalOcean offers competitive pricing for its cloud services. It also offers a generous free tier that includes 1 Droplet, 25 GB of storage, and 2 TB of bandwidth per month.
25+
- **Performance:** DigitalOcean uses high-performance hardware for its Droplets, so you can be sure that your applications will run smoothly.
26+
- **Reliability:** DigitalOcean has a strong track record of reliability and uptime.
27+
- **Community:** DigitalOcean has a large and active community of users and developers. This means that there is a wealth of resources available to help you get the most out of your DigitalOcean account.
28+
29+
## Up and Running
30+
31+
### Prerequisites
32+
33+
Before using Proxy Forge, ensure you have the following prerequisites in place:
34+
35+
1. [Digital Ocean Account](https://www.digitalocean.com/?refcode=a7587e994b7e&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)
36+
2. [Terraform](https://docs.digitalocean.com/reference/terraform/getting-started/) installed on your local machine
37+
38+
### Steps
39+
40+
1. Clone the repository
41+
42+
```console
43+
git clone --depth=1 --branch=main https://github.com/tbhaxor/ProxyForge.git proxyforge
44+
cd proxyforge
45+
```
46+
47+
2. Create a file for terraform variables.
48+
49+
```console
50+
touch terraform.tfvars
51+
```
52+
53+
> **Note** Skip it, if you wish to provide the variables and values from [environment config](https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_var_name).
54+
55+
3. Setup at least `token` and `region` in the file. See [variables](#variables) section below.
56+
57+
4. Initialize the provider, plan and apply the changes
58+
59+
```console
60+
terraform init
61+
terraform plan
62+
terraform apply
63+
```
64+
65+
5. Wait for some time for squid proxy to setup and load balancer to initialize routing.
66+
6. (Optional) Test the deployment
67+
68+
```sh
69+
LOAD_BALANCER_IP=$(terraform output -raw lb-ip)
70+
SQUID_USERNAME=proxyforge # assuming you did not change squid-credentials.username in the tfvars
71+
SQUID_PASSWORD=proxyforge # assuming you did not change squid-credentials.password in the tfvars
72+
73+
while true; do curl -x "http://proxyforge:proxyforge@$LOAD_BALANCER_IP:80" https://ifconfig.me; echo; done
74+
```
75+
76+
### Variables
77+
78+
| Variable Name | Default | Description |
79+
| :-----------------: | :----------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
80+
| `token` | N/A | **Required** API token with read/write permissions. [see more](https://docs.digitalocean.com/reference/api/create-personal-access-token/) |
81+
| `region` | N/A | **Required** Datacenter region to deploy all the resources. [see more](https://docs.digitalocean.com/products/platform/availability-matrix/) |
82+
| `ssh-fingerprint` | _`null`_ | SSH fingerprint id for droplets to use. If this is ommited, it will send you one-time-password on the email. Can be obtained from [security tab](https://i.imgur.com/TNTj7D8.png) of [accounts](https://cloud.digitalocean.com/account/security) page. [see also](https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/) |
83+
| `prefix` | _pf_ | A prefix to quickly identify proxy-forge resources. |
84+
| `slave-count` | _2_ | Number of instances on which squid proxy will be installed. |
85+
| `lb-count` | _1_ | Number of master nodes to setup for load balancer, min `1` is required. |
86+
| `tag-name` | _proxy-forge-slave_ | Tag name to group slave droplets. |
87+
| `droplet-size` | _{ slave = "s-1vcpu-1gb-amd" }_ | Droplet size to use. |
88+
| `project` | _Proxy Forge_ | Name of the project to associate all the resources. |
89+
| `squid-credentials` | _{ password = "proxyforge", username = "proxyforge" }_ | Squid proxy HTTP basic authentication.credentials |
90+
91+
## Customizations
92+
93+
Configuring ProxyForge to suit your specific needs is a straightforward process. All you need to do is update the settings in the `terraform.tfvars` file to align with your requirements. This file serves as a central configuration hub, allowing you to tailor ProxyForge precisely to your preferences without diving deep into complex setup procedures.
94+
95+
> **Note** After you choose to make any changes from below, make sure to apply it on digitalocean
96+
>
97+
> ```console
98+
> terraform plan
99+
> terraform apply
100+
> ```
101+
102+
### Change the Squid Credentials
103+
104+
```hcl
105+
squid-credentials = {
106+
username = "YOUR NEW USERNAME",
107+
password = "Y0ur53cr37P@55W0rD"
108+
}
109+
```
110+
111+
### Increase or Decrease Proxy Droplets
112+
113+
```
114+
slave-count = 5
115+
```
116+
117+
## Future Plans
118+
119+
- Add a user friendly dashboard for administration of squid accounts
120+
- Make a master service to destroy and spin-up new droplet in same region
121+
- Multiple regions support
122+
123+
## License
124+
125+
Proxy Forge is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
126+
127+
## Contact Me
128+
129+
Thank you for choosing Proxy Forge! I hope this tool helps you overcome IP throttling and blacklisting challenges, making your web-related tasks smoother and more efficient. If you have any questions or encounter issues, feel free to reach out to me. Happy proxying!
130+
131+
Website: https://tbhaxor.com <br />
132+
Email Address: tbhaxor `at` gmail `dot` com <br />
133+
LinkedIn: @tbhaxor <br />
134+
Twitter: @tbhaxor <br />
135+
Discord: @tbhaxor.com <br />
136+
Reddit: @tbhaxor <br />

droplet.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
locals {
2+
slave_urns = [
3+
for instance in digitalocean_droplet.slave :
4+
instance.urn
5+
]
6+
}
7+
8+
resource "random_integer" "slave-suffix" {
9+
min = 10000
10+
max = 99999
11+
seed = count.index
12+
count = var.slave-count
13+
}
14+
15+
resource "digitalocean_droplet" "slave" {
16+
name = "${var.prefix}-${var.region}-proxy-slave-${random_integer.slave-suffix[count.index].result}"
17+
tags = [var.tag-name]
18+
ssh_keys = var.ssh-fingerprint != null ? [var.ssh-fingerprint] : []
19+
vpc_uuid = digitalocean_vpc.main.id
20+
region = var.region
21+
count = var.slave-count
22+
monitoring = true
23+
droplet_agent = true
24+
image = "debian-12-x64"
25+
size = var.droplet-size.slave
26+
user_data = templatefile("user-data.tftpl", { loadbalancer-ip = digitalocean_loadbalancer.lb.ip, squid-credentials = var.squid-credentials })
27+
}

network.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
resource "digitalocean_vpc" "main" {
2+
name = "${var.prefix}-${var.region}-vpc"
3+
region = var.region
4+
}
5+
6+
7+
resource "digitalocean_loadbalancer" "lb" {
8+
name = "${var.prefix}-lb"
9+
droplet_tag = var.tag-name
10+
vpc_uuid = digitalocean_vpc.main.id
11+
region = var.region
12+
size_unit = var.lb-count
13+
14+
forwarding_rule {
15+
entry_port = 80
16+
entry_protocol = "tcp"
17+
target_port = 3128
18+
target_protocol = "tcp"
19+
}
20+
21+
healthcheck {
22+
protocol = "tcp"
23+
port = 3128
24+
}
25+
}
26+
27+
resource "digitalocean_firewall" "slave-lb-firewall" {
28+
name = "${var.prefix}-fw"
29+
tags = [var.tag-name]
30+
31+
inbound_rule {
32+
protocol = "tcp"
33+
port_range = "22"
34+
source_addresses = ["0.0.0.0/0", "::/0"]
35+
}
36+
37+
inbound_rule {
38+
protocol = "tcp"
39+
port_range = "all"
40+
source_load_balancer_uids = [digitalocean_loadbalancer.lb.id]
41+
}
42+
43+
outbound_rule {
44+
destination_addresses = ["0.0.0.0/0", "::/0"]
45+
protocol = "tcp"
46+
port_range = "all"
47+
}
48+
49+
outbound_rule {
50+
destination_addresses = ["0.0.0.0/0", "::/0"]
51+
protocol = "udp"
52+
port_range = "all"
53+
}
54+
55+
outbound_rule {
56+
destination_addresses = ["0.0.0.0/0", "::/0"]
57+
protocol = "icmp"
58+
}
59+
}
60+
61+
output "lb-ip" {
62+
description = "IP Address of the load balancer"
63+
value = digitalocean_loadbalancer.lb.ip
64+
}
65+

project.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "digitalocean_project" "pf-project" {
2+
name = var.project
3+
resources = [digitalocean_loadbalancer.lb.urn]
4+
depends_on = [digitalocean_droplet.slave, digitalocean_loadbalancer.lb]
5+
}
6+
7+
resource "digitalocean_project_resources" "pf-project-move-resources" {
8+
project = digitalocean_project.pf-project.id
9+
resources = concat([digitalocean_loadbalancer.lb.urn], local.slave_urns)
10+
depends_on = [digitalocean_droplet.slave]
11+
}

provider.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
terraform {
2+
required_providers {
3+
digitalocean = {
4+
source = "digitalocean/digitalocean"
5+
version = "~> 2.0"
6+
}
7+
8+
random = {
9+
source = "hashicorp/random"
10+
version = "3.5.1"
11+
}
12+
}
13+
}
14+
15+
16+
provider "digitalocean" {
17+
token = var.token
18+
}
19+
20+
provider "random" {
21+
22+
}
23+

user-data.tftpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
SQUID_USERNAME="${squid-credentials.username}"
6+
SQUID_PASSWORD="${squid-credentials.password}"
7+
# shellcheck disable=SC2154
8+
LOAD_BALANCER_IP="${loadbalancer-ip}"
9+
10+
apt update
11+
DEBIAN_FRONTEND=noninteractive apt install squid apache2-utils -y
12+
htpasswd -bc /etc/squid/passwords "$SQUID_USERNAME" "$SQUID_PASSWORD"
13+
14+
cat <<EOF_SQUID > /etc/squid/squid.conf
15+
http_port 3128
16+
17+
acl lb src $LOAD_BALANCER_IP
18+
acl SSL_ports port 443
19+
acl Safe_ports port 80
20+
acl Safe_ports port 21
21+
acl Safe_ports port 443
22+
http_access allow lb
23+
24+
http_access deny CONNECT !SSL_ports
25+
26+
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
27+
auth_param basic realm Squid proxy-caching web server
28+
acl authenticated_users proxy_auth REQUIRED
29+
http_access allow Safe_ports authenticated_users
30+
31+
http_access deny all
32+
EOF_SQUID
33+
34+
squid -k parse
35+
service squid restart

0 commit comments

Comments
 (0)