<commit_before>#!/usr/bin/env perl
use strict;
use warnings;
use Socket;
use POSIX qw\strftime\;
# define largest and smallest used subnetmask
my $lowmask = 16;
my $highmask = 30;
# use CIDR or non CIDR masks.. or both, both are recommended as a start 
my $usenoncidr = 1;
my $usecidr = 1;
# set to 0 to run command locally and 1 to use ssh
my $usessh = <%= @usessh %>; 
# command that serves PUA data
my $command = ('<%= @puacommand %>');
#ssh options
my @cmd = ('ssh');
#my @cmd = ('echo');
# add parameters to commandline if ssh is used
if ($usessh == 1) {
 push @cmd, '-q';
 push @cmd, '-oUserKnownHostsFile=/var/lib/puppet/ssl/puahostfile';
 push @cmd, '-i<%= @keypath %>';
 push @cmd, '<%= @puauser %>@<%= @puahost %>';
 push @cmd, $command;
} else {
 @cmd = ();
 push @cmd, $command;
}
# get ipadresses from commandline
my @ip = grep (/\d+\.\d+\.\d+.\d.*/, @ARGV) ;
my $output = join " ",@ARGV;
# check that any ipadress was provided 
if (@ip) {
# iterate over provided ip's and add possible subnets to commandline
foreach (@ip) { 
 if ($_ =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(:(\d{1,5}))?/){
  #iterate over possible masks
  for (my $netmask = $lowmask; $netmask <= $highmask; $netmask++) {
   my $ip_address_binary = inet_aton( $_ );
   my $netmask_binary    = ~pack("N", (2**(32-$netmask))-1);

   my $network_address    = inet_ntoa( $ip_address_binary & $netmask_binary );
   if ($usecidr == 1 ){
    $output = $output . ' ' . $network_address . '/' . $netmask;
   }
   if ($usenoncidr == 1) {
    my $mask = pack("N",-(1<<(32-($netmask % 32))));
    for($mask){ $_ = join('.', unpack("C4",$_)) }
    $output = $output . ' ' . $network_address . '/' . $mask;
   }
   }
  }else{
  die "argument contains nonvalid ip-adress!\n"
 }
}
} else {
 die "ip-address is not supplied!\n"
}
#print $output, "\n";
push @cmd, $output;
if (!system(@cmd)) {
 print "# fetched at ", strftime('%Y-%m-%d, %H:%M', localtime),  "\n";
} else {
 warn "ssh failed!:", $!,"\n";
}
exit;
<commit_msg>removed timestamp in fetch2.pl so puppet is not updating sudoers every run<commit_after>#!/usr/bin/env perl
use strict;
use warnings;
use Socket;
use POSIX qw\strftime\;
# define largest and smallest used subnetmask
my $lowmask = 16;
my $highmask = 30;
# use CIDR or non CIDR masks.. or both, both are recommended as a start 
my $usenoncidr = 1;
my $usecidr = 1;
# set to 0 to run command locally and 1 to use ssh
my $usessh = <%= @usessh %>; 
# command that serves PUA data
my $command = ('<%= @puacommand %>');
#ssh options
my @cmd = ('ssh');
#my @cmd = ('echo');
# add parameters to commandline if ssh is used
if ($usessh == 1) {
 push @cmd, '-q';
 push @cmd, '-oUserKnownHostsFile=/var/lib/puppet/ssl/puahostfile';
 push @cmd, '-i<%= @keypath %>';
 push @cmd, '<%= @puauser %>@<%= @puahost %>';
 push @cmd, $command;
} else {
 @cmd = ();
 push @cmd, $command;
}
# get ipadresses from commandline
my @ip = grep (/\d+\.\d+\.\d+.\d.*/, @ARGV) ;
my $output = join " ",@ARGV;
# check that any ipadress was provided 
if (@ip) {
# iterate over provided ip's and add possible subnets to commandline
foreach (@ip) { 
 if ($_ =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(:(\d{1,5}))?/){
  #iterate over possible masks
  for (my $netmask = $lowmask; $netmask <= $highmask; $netmask++) {
   my $ip_address_binary = inet_aton( $_ );
   my $netmask_binary    = ~pack("N", (2**(32-$netmask))-1);

   my $network_address    = inet_ntoa( $ip_address_binary & $netmask_binary );
   if ($usecidr == 1 ){
    $output = $output . ' ' . $network_address . '/' . $netmask;
   }
   if ($usenoncidr == 1) {
    my $mask = pack("N",-(1<<(32-($netmask % 32))));
    for($mask){ $_ = join('.', unpack("C4",$_)) }
    $output = $output . ' ' . $network_address . '/' . $mask;
   }
   }
  }else{
  die "argument contains nonvalid ip-adress!\n"
 }
}
} else {
 die "ip-address is not supplied!\n"
}
#print $output, "\n";
push @cmd, $output;
if (!system(@cmd)) {
 print "# file sucessfully fetched \n";
} else {
 warn "ssh failed!:", $!,"\n";
}
exit;

{'fraction_non_alphanumeric': 0.21378795420607266, 'fraction_numerical': 0.0156794425087108, 'mean_word_length': 3.5005599104143337, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264761', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1561, 'n_words': 447}