adjust package code structure
parent
51d38acbe1
commit
38ab6883de
|
@ -1,22 +1,22 @@
|
|||
package Nipe::Engine::Restart;
|
||||
package Nipe::Engine::Restart {
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Engine::Stop;
|
||||
use Nipe::Engine::Start;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Engine::Stop;
|
||||
use Nipe::Engine::Start;
|
||||
sub new {
|
||||
my $stop = Nipe::Engine::Stop -> new();
|
||||
|
||||
sub new {
|
||||
my $stop = Nipe::Engine::Stop -> new();
|
||||
if ($stop) {
|
||||
my $start = Nipe::Engine::Start -> new();
|
||||
|
||||
if ($stop) {
|
||||
my $start = Nipe::Engine::Start -> new();
|
||||
|
||||
if ($start) {
|
||||
return 1;
|
||||
if ($start) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,75 +1,75 @@
|
|||
package Nipe::Engine::Start;
|
||||
package Nipe::Engine::Start {
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Utils::Device;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Utils::Device;
|
||||
sub new {
|
||||
my %device = Nipe::Utils::Device -> new();
|
||||
my $dnsPort = "9061";
|
||||
my $transferPort = "9051";
|
||||
my @table = ("nat", "filter");
|
||||
my $network = "10.66.0.0/255.255.0.0";
|
||||
my $startTor = "systemctl start tor";
|
||||
|
||||
sub new {
|
||||
my %device = Nipe::Utils::Device -> new();
|
||||
my $dnsPort = "9061";
|
||||
my $transferPort = "9051";
|
||||
my @table = ("nat", "filter");
|
||||
my $network = "10.66.0.0/255.255.0.0";
|
||||
my $startTor = "systemctl start tor";
|
||||
if ($device{distribution} eq "void") {
|
||||
$startTor = "sv start tor > /dev/null";
|
||||
}
|
||||
|
||||
if ($device{distribution} eq "void") {
|
||||
$startTor = "sv start tor > /dev/null";
|
||||
elsif (-e "/etc/init.d/tor") {
|
||||
$startTor = "/etc/init.d/tor start > /dev/null";
|
||||
}
|
||||
|
||||
system ("tor -f .configs/$device{distribution}-torrc > /dev/null");
|
||||
system ($startTor);
|
||||
|
||||
foreach my $table (@table) {
|
||||
my $target = "ACCEPT";
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "RETURN";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -F OUTPUT");
|
||||
system ("iptables -t $table -A OUTPUT -m state --state ESTABLISHED -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -m owner --uid $device{username} -j $target");
|
||||
|
||||
my $matchDnsPort = $dnsPort;
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "REDIRECT --to-ports $dnsPort";
|
||||
$matchDnsPort = "53";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -p udp --dport $matchDnsPort -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -p tcp --dport $matchDnsPort -j $target");
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "REDIRECT --to-ports $transferPort";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -d $network -p tcp -j $target");
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "RETURN";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -d 127.0.0.1/8 -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -d 192.168.0.0/16 -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -d 172.16.0.0/12 -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -d 10.0.0.0/8 -j $target");
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "REDIRECT --to-ports $transferPort";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -p tcp -j $target");
|
||||
}
|
||||
|
||||
system ("iptables -t filter -A OUTPUT -p udp -j REJECT");
|
||||
system ("iptables -t filter -A OUTPUT -p icmp -j REJECT");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
elsif (-e "/etc/init.d/tor") {
|
||||
$startTor = "/etc/init.d/tor start > /dev/null";
|
||||
}
|
||||
|
||||
system ("tor -f .configs/$device{distribution}-torrc > /dev/null");
|
||||
system ($startTor);
|
||||
|
||||
foreach my $table (@table) {
|
||||
my $target = "ACCEPT";
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "RETURN";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -F OUTPUT");
|
||||
system ("iptables -t $table -A OUTPUT -m state --state ESTABLISHED -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -m owner --uid $device{username} -j $target");
|
||||
|
||||
my $matchDnsPort = $dnsPort;
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "REDIRECT --to-ports $dnsPort";
|
||||
$matchDnsPort = "53";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -p udp --dport $matchDnsPort -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -p tcp --dport $matchDnsPort -j $target");
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "REDIRECT --to-ports $transferPort";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -d $network -p tcp -j $target");
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "RETURN";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -d 127.0.0.1/8 -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -d 192.168.0.0/16 -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -d 172.16.0.0/12 -j $target");
|
||||
system ("iptables -t $table -A OUTPUT -d 10.0.0.0/8 -j $target");
|
||||
|
||||
if ($table eq "nat") {
|
||||
$target = "REDIRECT --to-ports $transferPort";
|
||||
}
|
||||
|
||||
system ("iptables -t $table -A OUTPUT -p tcp -j $target");
|
||||
}
|
||||
|
||||
system ("iptables -t filter -A OUTPUT -p udp -j REJECT");
|
||||
system ("iptables -t filter -A OUTPUT -p icmp -j REJECT");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
1;
|
|
@ -1,30 +1,30 @@
|
|||
package Nipe::Engine::Stop;
|
||||
package Nipe::Engine::Stop {
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Utils::Device;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Utils::Device;
|
||||
sub new {
|
||||
my %device = Nipe::Utils::Device -> new();
|
||||
my @table = ("nat", "filter");
|
||||
my $stopTor = "systemctl stop tor";
|
||||
|
||||
sub new {
|
||||
my %device = Nipe::Utils::Device -> new();
|
||||
my @table = ("nat", "filter");
|
||||
my $stopTor = "systemctl stop tor";
|
||||
if ($device{distribution} eq "void") {
|
||||
$stopTor = "sv stop tor > /dev/null";
|
||||
}
|
||||
|
||||
if ($device{distribution} eq "void") {
|
||||
$stopTor = "sv stop tor > /dev/null";
|
||||
foreach my $table (@table) {
|
||||
system ("iptables -t $table -F OUTPUT");
|
||||
system ("iptables -t $table -F OUTPUT");
|
||||
}
|
||||
|
||||
if (-e "/etc/init.d/tor") {
|
||||
$stopTor = "/etc/init.d/tor stop > /dev/null";
|
||||
}
|
||||
|
||||
system ($stopTor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
foreach my $table (@table) {
|
||||
system ("iptables -t $table -F OUTPUT");
|
||||
system ("iptables -t $table -F OUTPUT");
|
||||
}
|
||||
|
||||
if (-e "/etc/init.d/tor") {
|
||||
$stopTor = "/etc/init.d/tor stop > /dev/null";
|
||||
}
|
||||
|
||||
system ($stopTor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
package Nipe::Utils::Device;
|
||||
package Nipe::Utils::Device {
|
||||
use strict;
|
||||
use warnings;
|
||||
use Config::Simple;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Config::Simple;
|
||||
sub new {
|
||||
my $config = Config::Simple -> new("/etc/os-release");
|
||||
my $id_like = $config -> param("ID_LIKE") || "";
|
||||
my $id_distro = $config -> param("ID");
|
||||
|
||||
sub new {
|
||||
my $config = Config::Simple -> new("/etc/os-release");
|
||||
my $id_like = $config -> param("ID_LIKE") || "";
|
||||
my $id_distro = $config -> param("ID");
|
||||
my %device = (
|
||||
"username" => "",
|
||||
"distribution" => ""
|
||||
);
|
||||
|
||||
my %device = (
|
||||
"username" => "",
|
||||
"distribution" => ""
|
||||
);
|
||||
if (($id_like =~ /[F,f]edora/) || ($id_distro =~ /[F,f]edora/)) {
|
||||
$device{username} = "toranon";
|
||||
$device{distribution} = "fedora";
|
||||
}
|
||||
|
||||
if (($id_like =~ /[F,f]edora/) || ($id_distro =~ /[F,f]edora/)) {
|
||||
$device{username} = "toranon";
|
||||
$device{distribution} = "fedora";
|
||||
elsif (($id_like =~ /[A,a]rch/) || ($id_like =~ /[C,c]entos/) || ($id_distro =~ /[A,a]rch/) || ($id_distro =~ /[C,c]entos/)) {
|
||||
$device{username} = "tor";
|
||||
$device{distribution} = "arch";
|
||||
}
|
||||
|
||||
elsif ($id_distro =~ /[V,v]oid/) {
|
||||
$device{username} = "tor";
|
||||
$device{distribution} = "void";
|
||||
}
|
||||
|
||||
else {
|
||||
$device{username} = "debian-tor";
|
||||
$device{distribution} = "debian";
|
||||
}
|
||||
|
||||
return %device;
|
||||
}
|
||||
|
||||
elsif (($id_like =~ /[A,a]rch/) || ($id_like =~ /[C,c]entos/) || ($id_distro =~ /[A,a]rch/) || ($id_distro =~ /[C,c]entos/)) {
|
||||
$device{username} = "tor";
|
||||
$device{distribution} = "arch";
|
||||
}
|
||||
|
||||
elsif ($id_distro =~ /[V,v]oid/) {
|
||||
$device{username} = "tor";
|
||||
$device{distribution} = "void";
|
||||
}
|
||||
|
||||
else {
|
||||
$device{username} = "debian-tor";
|
||||
$device{distribution} = "debian";
|
||||
}
|
||||
|
||||
return %device;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package Nipe::Utils::Helper;
|
||||
package Nipe::Utils::Helper {
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
return "
|
||||
\rCore Commands
|
||||
\r==============
|
||||
\r\tCommand Description
|
||||
\r\t------- -----------
|
||||
\r\tinstall Install dependencies
|
||||
\r\tstart Start routing
|
||||
\r\tstop Stop routing
|
||||
\r\trestart Restart the Nipe circuit
|
||||
\r\tstatus See status\n\n";
|
||||
sub new {
|
||||
return "
|
||||
\rCore Commands
|
||||
\r==============
|
||||
\r\tCommand Description
|
||||
\r\t------- -----------
|
||||
\r\tinstall Install dependencies
|
||||
\r\tstart Start routing
|
||||
\r\tstop Stop routing
|
||||
\r\trestart Restart the Nipe circuit
|
||||
\r\tstatus See status\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,41 +1,41 @@
|
|||
package Nipe::Utils::Install;
|
||||
package Nipe::Utils::Install {
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Utils::Device;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Nipe::Utils::Device;
|
||||
sub new {
|
||||
my %device = Nipe::Utils::Device -> new();
|
||||
my $stopTor = "systemctl stop tor";
|
||||
|
||||
sub new {
|
||||
my %device = Nipe::Utils::Device -> new();
|
||||
my $stopTor = "systemctl stop tor";
|
||||
if ($device{distribution} eq "debian") {
|
||||
system ("apt-get install -y tor iptables");
|
||||
}
|
||||
|
||||
if ($device{distribution} eq "debian") {
|
||||
system ("apt-get install -y tor iptables");
|
||||
elsif ($device{distribution} eq "fedora") {
|
||||
system ("dnf install -y tor iptables");
|
||||
}
|
||||
|
||||
elsif ($device{distribution} eq "centos") {
|
||||
system ("yum -y install epel-release tor iptables");
|
||||
}
|
||||
|
||||
elsif ($device{distribution} eq "void") {
|
||||
system ("xbps-install -y tor iptables");
|
||||
$stopTor = "sv stop tor > /dev/null";
|
||||
}
|
||||
|
||||
else {
|
||||
system ("pacman -S --noconfirm tor iptables");
|
||||
}
|
||||
|
||||
if (-e "/etc/init.d/tor") {
|
||||
$stopTor = "/etc/init.d/tor stop > /dev/null";
|
||||
}
|
||||
|
||||
system ($stopTor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
elsif ($device{distribution} eq "fedora") {
|
||||
system ("dnf install -y tor iptables");
|
||||
}
|
||||
|
||||
elsif ($device{distribution} eq "centos") {
|
||||
system ("yum -y install epel-release tor iptables");
|
||||
}
|
||||
|
||||
elsif ($device{distribution} eq "void") {
|
||||
system ("xbps-install -y tor iptables");
|
||||
$stopTor = "sv stop tor > /dev/null";
|
||||
}
|
||||
|
||||
else {
|
||||
system ("pacman -S --noconfirm tor iptables");
|
||||
}
|
||||
|
||||
if (-e "/etc/init.d/tor") {
|
||||
$stopTor = "/etc/init.d/tor stop > /dev/null";
|
||||
}
|
||||
|
||||
system ($stopTor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
package Nipe::Utils::Status;
|
||||
package Nipe::Utils::Status {
|
||||
use JSON;
|
||||
use strict;
|
||||
use warnings;
|
||||
use HTTP::Tiny;
|
||||
|
||||
use JSON;
|
||||
use strict;
|
||||
use warnings;
|
||||
use HTTP::Tiny;
|
||||
sub new {
|
||||
my $apiCheck = "https://check.torproject.org/api/ip";
|
||||
my $request = HTTP::Tiny -> new -> get($apiCheck);
|
||||
|
||||
if ($request -> {status} == 200) {
|
||||
my $data = decode_json ($request -> {content});
|
||||
|
||||
sub new {
|
||||
my $apiCheck = "https://check.torproject.org/api/ip";
|
||||
my $request = HTTP::Tiny -> new -> get($apiCheck);
|
||||
|
||||
if ($request -> {status} == 200) {
|
||||
my $data = decode_json ($request -> {content});
|
||||
my $checkIp = $data -> {"IP"};
|
||||
my $checkTor = $data -> {"IsTor"} ? "activated" : "disabled";
|
||||
|
||||
my $checkIp = $data -> {"IP"};
|
||||
my $checkTor = $data -> {"IsTor"} ? "activated" : "disabled";
|
||||
return "\n\r[+] Status: $checkTor. \n\r[+] Ip: $checkIp\n\n";
|
||||
}
|
||||
|
||||
return "\n\r[+] Status: $checkTor. \n\r[+] Ip: $checkIp\n\n";
|
||||
return "\n[!] ERROR: sorry, it was not possible to establish a connection to the server.\n\n";
|
||||
}
|
||||
|
||||
return "\n[!] ERROR: sorry, it was not possible to establish a connection to the server.\n\n";
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue