Skip to content

Instantly share code, notes, and snippets.

@renancarvalhoo
Forked from tacitochaves/comment_squid.pl
Last active August 29, 2015 14:03
Show Gist options
  • Save renancarvalhoo/71a9fe3b9381b4be54e3 to your computer and use it in GitHub Desktop.
Save renancarvalhoo/71a9fe3b9381b4be54e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
my $oi = comment_squid_oi();
#my $emb_34 = comment_squid_emb_34();
#my $emb_147 = comment_squid_emb_147();
sub comment_squid_oi {
#Specify the file
my $file = "squid.conf";
#Open the file and read data
#Die with grace if it fails
open( FILE, "<", "$file" ) or die "Can't open $file: $!\n";
my @lines = <FILE>;
close(FILE);
open( SQUID_OI, ">", "$file" ) or die "Can't open $file: $!\n";
foreach ( @lines ) {
if (/^[^#]/){
s/tcp_outgoing/#tcp_outgoing/ if m/201.18.32.26/;
s/always_direct/#always_direct/ if m/liberado_2m/;
s/always_direct/#always_direct/ if m/link_2m/;
}
print SQUID_OI;
}
close(SQUID_OI);
}
sub comment_squid_emb_34 {
#Specify the file
my $file = "squid.conf";
#Open the file and read data
#Die with grace if it fails
open( FILE, "<", "$file" ) or die "Can't open $file: $!\n";
my @lines = <FILE>;
close(FILE);
open( SQUID_EMB_34, ">", "$file" ) or die "Can't open $file: $!\n";
foreach ( @lines ) {
s/tcp_outgoing/#tcp_outgoing/ if m/201.73.62.34/;
s/always_direct/#always_direct/ if m/liberado_10m[^2]/;
s/always_direct/#always_direct/ if m/link_10m[^2]/;
print SQUID_EMB_34;
}
close(SQUID_EMB_34);
}
sub comment_squid_emb_147 {
#Specify the file
my $file = "squid.conf";
#Open the file and read data
#Die with grace if it fails
open( FILE, "<", "$file" ) or die "Can't open $file: $!\n";
my @lines = <FILE>;
close(FILE);
open( SQUID_EMB_147, ">", "$file" ) or die "Can't open $file: $!\n";
foreach ( @lines ) {
s/tcp_outgoing/#tcp_outgoing/ if m/201.73.254.147/;
s/always_direct/#always_direct/ if m/liberado_10m2/;
s/always_direct/#always_direct/ if m/link_10m2/;
print SQUID_EMB_147;
}
close(SQUID_EMB_147);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment