initial commit of file from CVS for e-smith-proxy on Wed 12 Jul 09:06:18 BST 2023

This commit is contained in:
Brian Read
2023-07-12 09:06:18 +01:00
parent 1041715762
commit a376640216
68 changed files with 1794 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
{
return "# squid is disabled\n" unless $squid{status} eq 'enabled';
my $freq = $squid{Rotate} || 'daily';
my $min = int(rand(60));
my $hour = int(rand(5));
my $dow = substr(localtime,0,3);
if ($freq eq 'hourly') {
return "$min * * * * root squid -k rotate\n";
} elsif ($freq eq 'weekly') {
return "$min $hour * * $dow root squid -k rotate\n";
} elsif ($freq eq 'monthly') {
return "$min $hour 15 * * root squid -k rotate\n";
} elsif ($freq eq 'disabled') {
return "# squid rotate disabled\n";
} else {
return "$min $hour * * * root squid -k rotate\n"
}
}

View File

@@ -0,0 +1,2 @@
option wpad-url code 252 = text;

View File

@@ -0,0 +1,15 @@
{
my $transproxy = $squid{Transparent} || "yes";
my $status = $squid{status} || "disabled";
if ($transproxy eq "yes" && $status eq "enabled")
{
$OUT .= " option wpad-url \"http://wpad.$DomainName/wpad.dat\";";
}
else
{
$OUT .= '# wpad-url disabled';
}
}

View File

@@ -0,0 +1,9 @@
{
foreach my $file (qw(wpad.dat proxy.pac))
{
$OUT .= "Alias /$file /etc/httpd/conf/proxy/proxy.pac\n";
$OUT .= "<Location /$file>\n";
$OUT .= " Require ip $localAccess\n";
$OUT .= "</Location>\n";
}
}

View File

@@ -0,0 +1,2 @@
if (isPlainHostName(host))
return "DIRECT";

View File

@@ -0,0 +1,2 @@
if (isInNet(host, "{ $LocalIP }", "{ $LocalNetmask }"))
return "DIRECT";

View File

@@ -0,0 +1,2 @@
if (isInNet(host, "127.0.0.1", "255.255.255.255"))
return "DIRECT";

View File

@@ -0,0 +1,9 @@
{
my $enabled = $squid{status} || 'disabled';
my $port = $squid{TransparentPort} || 3128;
my $target = ($enabled eq 'enabled') ?
"PROXY proxy.$DomainName:$port" :
"DIRECT";
$OUT = ' return "' . $target . '";';
}

View File

@@ -0,0 +1,2 @@
function FindProxyForURL(url, host)
\{

View File

@@ -0,0 +1,38 @@
{
$OUT = '';
# Create new chain to manage TransProxy stuff
# Note: We send all traffic destined to port 80, regardless of
# where it's from, since the filter table will worry about source.
$OUT .= " /sbin/iptables --table nat --new-chain TransProxy\n";
$OUT .= " /sbin/iptables --table nat --append PREROUTING\\\n";
$OUT .= "\t-p tcp --dport 80 -j TransProxy\n";
# Accept any accesses to the local IPs directly
$OUT .= " /sbin/iptables --table nat --append TransProxy \\\n";
$OUT .= "\t--destination 127.0.0.1 --jump ACCEPT\n";
$OUT .= " /sbin/iptables --table nat --append TransProxy \\\n";
$OUT .= "\t--destination $LocalIP --jump ACCEPT\n";
if (defined $ExternalIP) {
# Accept any accesses to the ExternalIP directly
$OUT .= " /sbin/iptables --table nat --append TransProxy \\\n";
$OUT .= "\t--destination \$OUTERNET --jump ACCEPT\n";
}
my $transproxy = $squid{Transparent} || "yes";
my $status = $squid{status} || "disabled";
if ($transproxy eq "yes" && $status eq "enabled") {
##my $proxyport = $squid{TransparentPort} || "3128";
my $proxyport = $squid{InterceptPort} || "8080";
# Otherwise, divert port 80 traffic through our proxy
$OUT .= " /sbin/iptables --table nat --append TransProxy\\\n";
$OUT .= "\t-p TCP -j DNAT --to $LocalIP:$proxyport\n";
} else {
# Or just let it go unhindered
$OUT .= " /sbin/iptables --table nat --append TransProxy\\\n";
$OUT .= "\t--jump ACCEPT\n";
}
}

View File

@@ -0,0 +1,32 @@
{
# Update any rules which may have changed, meaning
# - $ExternalIP
# - enabled/disabled
# - Transproxy port (unlikely)
my $rule = 3;
if (defined $ExternalIP)
{
# Accept any accesses to the ExternalIP directly
$OUT .= " /sbin/iptables --table nat \\\n";
$OUT .= "\t--replace TransProxy $rule\\\n";
$OUT .= "\t--destination \$OUTERNET --jump ACCEPT\n";
$rule++;
}
my $transproxy = $squid{Transparent} || "yes";
my $status = $squid{status} || "disabled";
if ($transproxy eq "yes" && $status eq "enabled")
{
##my $proxyport = $squid{TransparentPort} || "3128";
my $proxyport = $squid{InterceptPort} || "8080";
# Otherwise, divert port 80 traffic through our proxy
$OUT .= " /sbin/iptables --table nat --replace TransProxy $rule\\\n";
$OUT .= "\t-p TCP -j DNAT --to $LocalIP:$proxyport\n";
}
else
{
# Or just let it go unhindered
$OUT .= " /sbin/iptables --table nat --replace TransProxy $rule\\\n";
$OUT .= "\t--jump ACCEPT\n";
}
}

View File

@@ -0,0 +1,2 @@
if $programname == 'squid' then /var/log/squid/squid.log
& stop

View File

@@ -0,0 +1,13 @@
{
my $transproxy = $squid{Transparent} || "yes";
if ($transproxy eq 'yes') {
$OUT .= "http_port $LocalIP:" . ($squid{TCPPort} || '3128') . "\n";
$OUT .= "http_port 127.0.0.1:" . ($squid{TCPPort} || '3128') . "\n";
$OUT .= "http_port $LocalIP:" . ($squid{InterceptPort} || '8080') . " intercept\n";
$OUT .= "http_port 127.0.0.1:" . ($squid{InterceptPort} || '8080') . " intercept\n";
} else {
$OUT .= "http_port $LocalIP:" . ($squid{TCPPort} || '3128') . "\n";
$OUT .= "http_port 127.0.0.1:" . ($squid{TCPPort} || '3128') . "\n";
}
}

View File

@@ -0,0 +1,4 @@
{
$OUT .= "udp_incoming_address $LocalIP\n";
$OUT .= "udp_outgoing_address 0.0.0.0";
}

View File

@@ -0,0 +1,10 @@
{
$OUT = "";
if (defined $SquidParent && $SquidParent)
{
$OUT .= "cache_peer $SquidParent parent ";
$OUT .= $SquidParentPort || "3128";
$OUT .= " 7 no-query default";
}
}

View File

@@ -0,0 +1,24 @@
{
use esmith::NetworksDB;
use Net::IPv4Addr;
my $ndb = esmith::NetworksDB->open_ro();
my $localAccess = '';
foreach ($ndb->local_access_spec()){
# If there's a / in the network string
# then convert to CIDR notation
if (m!/!) {
my ($ip,$bits) = Net::IPv4Addr::ipv4_parse($_);
$localAccess .= "$ip/$bits ";
}
else {
$localAccess .= "$_ ";
}
}
$OUT .= "acl localsrc src $localAccess\n";
$OUT .= "acl localdst dst $localAccess\n";
$OUT .= "acl selfdst dst 127.0.0.1 $LocalIP\n";
$OUT .= "acl selfport port " . ($squid{TCPPort} || '3128');
}

View File

@@ -0,0 +1,6 @@
{
my @ports = split(",", ($squid{SSLPorts} || "") );
return "acl SSL_ports port 443 563 @ports";
}

View File

@@ -0,0 +1,5 @@
{
my @ports = split(",", ($squid{SafePorts} || "80") );
return "acl Safe_ports port @ports";
}

View File

@@ -0,0 +1 @@
acl CONNECT method CONNECT

View File

@@ -0,0 +1 @@
acl webdav method PROPFIND TRACE PURGE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK

View File

@@ -0,0 +1,3 @@
{
$OUT = "pid_filename /run/squid/squid.pid";
}

View File

@@ -0,0 +1 @@
access_log /var/log/squid/access.log squid

View File

@@ -0,0 +1 @@
logfile_rotate 0

View File

@@ -0,0 +1,3 @@
append_domain {
$OUT = ".$DomainName";
}

View File

@@ -0,0 +1 @@
cache_mgr { "admin\@$DomainName" }

View File

@@ -0,0 +1 @@
ftp_user { "nobody\@$DomainName" }

View File

@@ -0,0 +1,2 @@
http_access allow manager localsrc
http_access deny manager

View File

@@ -0,0 +1,5 @@
{
return "" unless ( ($squid{EnforceSafePorts} || "no") eq "yes");
return "http_access deny !Safe_ports";
}

View File

@@ -0,0 +1 @@
http_access deny CONNECT !SSL_ports

View File

@@ -0,0 +1 @@
http_access deny selfdst selfport

View File

@@ -0,0 +1 @@
http_access allow localsrc

View File

@@ -0,0 +1 @@
http_access deny all

View File

@@ -0,0 +1 @@
icp_access allow all

View File

@@ -0,0 +1 @@
miss_access allow all

View File

@@ -0,0 +1,11 @@
{
# TAG: store_avg_object_size (kbytes)
# Average object size, used to estimate number of objects your
# cache can hold. See doc/Release-Notes-1.1.txt. The default is
# 13 KB.
#
# Note: At e-smith, some of our customers have had average object sizes
# as low as 3.5 KB, so we set the limit to 3 KB to be safe.
# - JMorrison, January 5, 2000
# }
store_avg_object_size 3 KB

View File

@@ -0,0 +1 @@
always_direct allow webdav

View File

@@ -0,0 +1,13 @@
{
if (defined $SquidParent && $SquidParent)
{
$OUT .= "always_direct allow localdst\n";
$OUT .= "always_direct deny all\n";
$OUT .= "never_direct deny localdst\n";
$OUT .= "never_direct allow all";
}
else
{
$OUT .= "always_direct allow all";
}
}

View File

@@ -0,0 +1 @@
max_filedesc { ($squid{'MaxFileDesc'} || '4096') }

View File

@@ -0,0 +1,10 @@
# default squid options
SQUID_OPTS=""
# Time to wait for Squid to shut down when asked. Should not be necessary
# most of the time.
SQUID_SHUTDOWN_TIMEOUT=100
# default squid conf file
SQUID_CONF="/etc/squid/squid.conf"

View File

@@ -0,0 +1,4 @@
# specific squid options
SQUID_OPTS="-s"

View File

@@ -0,0 +1,4 @@
[Unit]
After=network-online.target

View File

@@ -0,0 +1,12 @@
[Service]
{
# Is there a Files limit in the configuration database
$OUT .= "LimitNOFILE=";
$OUT .= $squid{MaxFileDesc} || 4096;
$OUT .= "\n";
}
PIDFile=/run/squid/squid.pid
# squid option -s ---->> $SQUID_OPTS
ExecStartPre=/sbin/e-smith/service-status squid
User=root
Group=root

View File

@@ -0,0 +1,2 @@
[Install]
WantedBy=sme-server.target