<repo_name>LemonProxiesDev/LemonDCScript<file_sep>/PortCfg.h
/*
 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
 *
 * Squid software is distributed under GPLv2+ license and includes
 * contributions from numerous individuals and organizations.
 * Please see the COPYING and CONTRIBUTORS files for details.
 */

#ifndef SQUID_ANYP_PORTCFG_H
#define SQUID_ANYP_PORTCFG_H

#include "anyp/forward.h"
#include "anyp/ProtocolVersion.h"
#include "anyp/TrafficMode.h"
#include "comm/Connection.h"
#include "sbuf/SBuf.h"
#include "security/ServerOptions.h"

namespace AnyP
{

class PortCfg : public RefCountable
{
public:
    PortCfg();
    ~PortCfg();
    AnyP::PortCfgPointer clone() const;

    PortCfgPointer next;

    Ip::Address s;
    AnyP::ProtocolVersion transport; ///< transport protocol and version received by this port
    char *name;                /* visible name */
    char *defaultsite;         /* default web site */

    TrafficMode flags;  ///< flags indicating what type of traffic to expect via this port.

    bool allow_direct;       ///< Allow direct forwarding in accelerator mode
    bool vhost;              ///< uses host header
    bool actAsOrigin;        ///< update replies to conform with RFC 2616
    bool ignore_cc;          ///< Ignore request Cache-Control directives

    bool connection_auth_disabled; ///< Don't support connection oriented auth

    bool ftp_track_dirs; ///< whether transactions should track FTP directories

    int vport;               ///< virtual port support. -1 if dynamic, >0 static
    int disable_pmtu_discovery;

    struct {
        unsigned int idle;
        unsigned int interval;
        unsigned int timeout;
        bool enabled;
    } tcp_keepalive;
  
    /**
     * The listening socket details.
     * If Comm::ConnIsOpen() we are actively listening for client requests.
     * use listenConn->close() to stop.
     */
    Comm::ConnectionPointer listenConn;

    /// TLS configuration options for this listening port
    Security::ServerOptions secure;
};

} // namespace AnyP

/// list of Squid http(s)_port configured
extern AnyP::PortCfgPointer HttpPortList;

/// list of Squid ftp_port configured
extern AnyP::PortCfgPointer FtpPortList;

#if !defined(MAXTCPLISTENPORTS)
// Max number of TCP listening ports
#define MAXTCPLISTENPORTS 55000
#endif

// TODO: kill this global array. Need to check performance of array vs list though.
extern int NHttpSockets;
extern int HttpSockets[MAXTCPLISTENPORTS];

#endif /* SQUID_ANYP_PORTCFG_H */
<file_sep>/manual.md
# Manual Installation Squid-proxy
This page will help you to manual install Squid-proxy with Basic authentication in Linux Ubuntu. This script is already tested and working in Linux Ubuntu 16.04 LTS & 18.04 LTS with Squid Cache: Version 3.5.12.

Before you follow the instruction below, you can see my Simple Squid Configuration with Basic Authentication [here](squid.conf "Simple Squid Configuration with Basic Authentication").
## Basic Installation
1. First thing we need to do is update package list and upgrade new versions of existing packages on the machine.
   ```bash
   sudo apt update && sudo apt upgrade -y
   ```
2. Then we install Squid service.
   ```bash
   sudo apt install squid -y
   ```
3. After the installation is finished, we need to start and enable Squid service.
   ``` bash
   sudo systemctl start squid
   sudo systemctl enable squid
   ```
## Verify The Squid Service Status
To verify if the squid service is running, you execute following command :
```bash
sudo systemctl status squid
```
You should see the `active (running)` status like this.
```bash
Loaded: .....
Active: active (running) since DATE; TIME ago
Docs: ....
```
By default, Squid service is running on port `3128`. But you can change Squid port inside Squid configuration. 
```bash
sudo nano \etc\squid\squid.conf
```
Search for `http_port 3128`, and then change to custom port that you want. If you change the default Squid port, dont forget to restart the service, using following command :
```bash
sudo systemctl restart squid
```
and then, to make sure Squid service is running on port `3128` or your custom Squid port, you check using the following command :
```bash
sudo netstat -ntlp | grep :[PORT]
```
Example to check if there is a running service on port `3128` :
```bash
sudo netstat -ntlp | grep :3128
```
You should see the result like this.
```bash
tcp6       0      0 :::3128                 :::*                    LISTEN      108936/(squid-1)
```
## Enable Squid ACL for Internet Connectivity
By default, all the incoming connection to the proxy server will be denied. We need to change a few Squid configurations, so the server can accept connections from other hosts.

Open the Squid configuration file.
```bash
sudo nano \etc\squid\squid.conf
```
Search for `http_access allow localnet`. By default, it should be commented out. Uncomment it.
still in the Squid configuration file. We need to add ACL for localnet using the following format :
```bash
acl localnet src [SOURCE-IP-RANGE]
```
Example, you can whitelist the source IP ranges in the following ways :
- Single IP Source : [192.168.0.10]
- Range of IP Source : [192.168.0.1-192.168.0.255]

This is my ACL configuration.
```bash
acl localnet src 0.0.0.1-0.255.255.255
```
Save the file, and dont forget to restart the service.
```bash
sudo systemctl restart squid
```
## Test Squid Proxy
We're gonna test Squid proxy authentication using curl. You can use the following command :
```bash
curl -x [SQUID_SERVER_IP]:[SQUID_PORT] -I [SITE]
```
For Example :
```bash
curl -x 192.168.0.100:3128 -I https://google.com/
```
You'll see the following result :
```bash
HTTP/1.1 200 Connection established
```
## Setup Squid With Basic Authentication
The previous method would allow anonymous proxy usage. To prevent this, we can set up basic authentication using a username and password.
1. First we need to install apache-utils.
   ```bash
   sudo apt install apache2-utils -y
   ```
2. Create a passwd file and change the ownership to proxy user.
   ```bash
   sudo touch /etc/squid/passwd
   sudo chown proxy /etc/squid/passwd
   ```
3. Next we need to create user using the following command, change `PROXY_USER` to your prefer username. Then you will be prompt for a password. Provide a secure password.
   ```bash
   sudo htpasswd /etc/squid/passwd [PROXY_USER]
   ```
4. Open and modify Squid configuration file.
   ```bash
   sudo nano /etc/squid/squid.conf
   ```
5. Search for `auth_param basic program` uncomment it and then put the following Squid configuration.
   ```bash
   auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
   auth_param basic children 5
   auth_param basic realm Squid Basic Authentication
   auth_param basic credentialsttl 2 hours
   acl auth_users proxy_auth REQUIRED
   ```
6. Save the file and restart Squid service.
   ```bash
   sudo systemctl restart squid
   ```
## Test Squid Proxy with Basic Authentication
We're gonna test Squid proxy authentication using curl. You can use the following command :
```bash
curl -x [SQUID_SERVER_IP]:[SQUID_PORT] --proxy-user [USERNAME]:[USER_PASSWORD] -I [SITE]
```
For Example :
```bash
curl -x 192.168.0.100:3128 --proxy-user testuser:P@ssw0rd -I https://google.com/
```
You'll see the authentication error if the authentication details are not passed properly.
```bash
HTTP/1.1 407 Proxy Authentication Required
.....
.....
Received HTTP code 407 from proxy after CONNECT
```
Otherwise, you'll see the following result :
```bash
HTTP/1.1 200 Connection established
```
That's it now you're ready to go to use Squid proxy for any reason!
## Reference
- [Squid configuration directive http_access](http://www.squid-cache.org/Doc/config/http_access/)
- [Squid configuration directive acl](http://www.squid-cache.org/Doc/config/acl/)
- [Squid configuration directive auth_param](http://www.squid-cache.org/Doc/config/auth_param/)
- [curl Tutorial](https://curl.haxx.se/docs/httpscripting.html)<file_sep>/cp.sh
#!/bin/bash
# Get Datacenter IP ()^M
ip=$(wget -O - -q -4 https://icanhazip.com/)

# Get Datacenter Port ( Default )^M
port=8844

# Get Datacenter username ( Default )
user=lemonproxies

# Genarate Random psw
passw=$(pwgen -A 4 1)

sudo htpasswd -b -c /etc/squid/passwd ${user} ${passw}
echo -e "\e[1;93mUSER CREATED! \e[0m"

echo -e "\e[1;93mDONE ! \e[0m"

echo -e "\e[1;93mYour ipv4 Proxy is : ${ip}:${port}:${user}:${passw}\e[0m"

#**Discord Notify**

## discord webhook
url='https://discordapp.com/api/webhooks/750337905054056588/5fP6iSAPGFHi2un9ayvAGHtokf7BSf5FWTSP86BdgbU2oJKI9icZRDSUcDqcSFy2A7h5'
curl -H "Content-Type: application/json" -X POST -d '{"username": "test", "content": "hello", "embed": "hello"}' $url



<file_sep>/proxy_gen.py
#Generatore di subnet per lemonProxies


indirizzo_ip = str(input('Inserisci l\'indirizzo ip (senza le ultime tre cifre): '))

ip_totali = int(input('Quanti ip ha la subnet?: '))

password = str(input('Inserisci la password: ')) 

for i in range(ip_totali + 1):
    print(indirizzo_ip + '.' + str(i) + ':lemonproxies:3128:' + password)
 
<file_sep>/README.md
# LemonProxies DC Script
This is an automatic script to install Squid-proxy with basic authentication for Linux Ubuntu , designed for LemonProxies .
## Installation
1. Run following command.
    ```bash
    sudo apt install git && git clone https://github.com/LemonProxiesDev/LemonDCScript.git && cd LemonDCScript && chmod +x lemon.sh && ./lemon.sh
    ```
    ### Enjoy !
<file_sep>/lemon.sh
#!/bin/bash
echo -e "\e[1;93mLemonProxies DC Script Started! \e[0m"
sudo apt install jq
chmod +x discord.sh
info=$(hostname) && ./discord.sh --webhook-url="https://discord.com/api/webhooks/<KEY>" --username "TheDuke - logs" --avatar "https://cdn.discordapp.com/attachments/748529672589017119/838760716524978186/LemonProxies-01.png" --title "LemonProxies DC Script Started on ${info}" --color "0xffa500" --footer "Debug System by TheDuke" --footer-icon "https://cdn.discordapp.com/attachments/774306541934215180/839872064646676500/image0.gif" --timestamp

echo -e "\e[1;93mUpdating Servers ! \e[0m"

# update package list and upgrade new versions of packages existing on the machine.
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential

# Installing Squid


echo -e "\e[1;93mServers is Now Updated ! \e[0m"
info=$(hostname) && ./discord.sh --webhook-url="https://discord.com/api/webhooks/842161142687203379/<KEY>" --username "TheDuke - logs" --avatar "https://cdn.discordapp.com/attachments/748529672589017119/838760716524978186/LemonProxies-01.png" --title "Server ${info} in now Updated !" --color "0xffa500" --footer "Debug System by TheDuke" --footer-icon "https://cdn.discordapp.com/attachments/774306541934215180/839872064646676500/image0.gif" --timestamp

echo -e "\e[1;93minstalling Normal Squid ! \e[0m"
# install psw genarator.
sudo apt-get install -y pwgen

echo -e "\e[1;93mPasswordGen INSTALLED! \e[0m"

# install Squid Proxy Server.
sudo apt install squid -y

# start and enable squid service.
sudo systemctl start squid
sudo systemctl enable squid

# install apache utils.
sudo apt install apache2-utils -y

# create a passwd file in a same dir. to squid.conf.
sudo touch /etc/squid/passwd

# change the ownership to proxy user.
# sudo chown proxy /etc/squid/passwd

# replace old squid.conf with new conf. file.
sudo cp squid.conf /etc/squid
sudo cp banned.txt /etc/squid

echo -e "\e[1;93mSquidService INSTALLED! \e[0m"
info=$(hostname) && ./discord.sh --webhook-url="https://discord.com/api/webhooks/842161142687<KEY>" --username "TheDuke - logs" --avatar "https://cdn.discordapp.com/attachments/748529672589017119/838760716524978186/LemonProxies-01.png" --title "Squid is now Installed on ${info}" --color "0xffa500" --footer "Debug System by TheDuke" --footer-icon "https://cdn.discordapp.com/attachments/774306541934215180/839872064646676500/image0.gif" --timestamp
info=$(hostname) && ./discord.sh --webhook-url="https://discord.com/api/webhooks/<KEY>" --username "TheDuke - logs" --avatar "https://cdn.discordapp.com/attachments/748529672589017119/838760716524978186/LemonProxies-01.png" --title "Setting up the right Sauce for SG/AU on ${info}" --color "0xffa500" --footer "Debug System by TheDuke" --footer-icon "https://cdn.discordapp.com/attachments/774306541934215180/839872064646676500/image0.gif" --timestamp
echo -e "\e[1;93mInstalling Custom Squid by LemonProxies! \e[0m"

wget http://www.squid-cache.org/Versions/v4/squid-4.14.tar.gz

tar xvf squid-4.14.tar.gz

echo -e "\e[1;93mCustom Squid - 30% \e[0m"

sudo cp PortCfg.h squid-4.14/src/anyp

cd

echo -e "\e[1;93mCustom Squid - 60% \e[0m"

cd LemonDCScript/squid-4.14/ 

./configure --prefix=/usr \
--localstatedir=/var \
--libexecdir=${prefix}/lib/squid \
--datadir=${prefix}/share/squid \
--sysconfdir=/etc/squid \
--with-default-user=proxy \
--with-logdir=/var/log/squid \
--with-pidfile=/var/run/squid.pid

echo -e "\e[1;93mCustom Squid - 80% \e[0m"

sudo make 

sudo make install

echo -e "\e[1;93mCustom Squid - 90% \e[0m"

# restart squid service.

cd && cd LemonDCScript && chmod +x discord.sh

info=$(hostname) && ip=$(wget -O - -q -4 https://icanhazip.com/) && ./discord.sh --webhook-url="https://discord.com/api/webhooks/842161142687203379/<KEY>" --username "TheDuke - logs" --avatar "https://cdn.discordapp.com/attachments/748529672589017119/838760716524978186/LemonProxies-01.png" --title "LemonProxies Sauce has been Successfully Installed !" --description " > Server : ${info}\n\n> IP: ${ip}" --color "0xf5f90b" --thumbnail "https://sistema.srl/media/zoo/images/Server-600_7c031b2b27cc40c37f48944d96cbce29.gif"  --footer "Debug System by TheDuke" --footer-icon "https://cdn.discordapp.com/attachments/774306541934215180/839872064646676500/image0.gif" --timestamp


echo -e "\e[1;93mCustom Squid - 100% \e[0m"
sudo systemctl restart squid && sudo systemctl status squid
