Jump to content

LordOE

Members
  • Posts

    1
  • Joined

  • Last visited

Reputation

0 Neutral

About LordOE

  1. Hi I have modified the code for my use an changed it to work with security groups. #!/usr/bin/perl #Use use File::Temp qw/ tempdir /; #Globals $global::tmp = "/tmp"; $global::last_update = "/etc/dansguardian/lists/lastupdate.filtergroupslist"; $global::admin_location = "/etc/dansguardian/lists/admins.filtergroupslist"; $global::dansguardconf = "/etc/dansguardian/lists/filtergroupslist"; $global::template = "/etc/dansguardian/lists/template.filtergroupslist"; #Clear the global variable here {at}global::results = (); $global::ldapsearch = "/usr/bin/ldapsearch"; #OLD Code $global::ldapbind_options = "-D \"cn=proxy_user,ou=proxy,dc=domain,dc=local\" -w \"password\" -h DC01 -x -s sub \"CN=*\""; $global::ldapbind_options = "-D \"cn=proxy_user,ou=proxy,dc=domain,dc=local\" -w \"atelco\" -h dc01"; $global::groupmap = { filter1 => "proxy_filter1", filter2 => "proxy_filter2", filter3 => "proxy_filter3", filter4 => "proxy_filter4" }; #make a temp directory my $TempDir = tempdir( 'dansgroups.XXXXXXXX', DIR => $global::tmp, CLEANUP => 1 ); #Main open (INPUTINFO,$global::admin_location)|| die("Could not open file!"); {at}global::adminarray=; close(INPUTINFO); print "\nStarting\n\n"; foreach my $filtername ( sort keys %{ $global::groupmap } ) { my $ldapgroup_target = "\"DC=domain,DC=local\" \"(&(objectCategory=user)(memberOf=CN=$global::groupmap->{$filtername},OU=proxy,DC=domain,DC=local))\""; #my $ldapgroup_target = "cn=$global::groupmap->{$filtername},ou=proxy,dc=domain,dc=local"; #Now remove subgroups -mgt $filtername =~ s/(filter\d)[a-z]/$1/; #Open Pipe from Ldapsearch with grep filter # "DC=domain,DC=local" "(&(objectCategory=user)(memberOf=CN=pfSenseUsers,OU=proxy,DC=domain,DC=local))" my $command_line= "$global::ldapsearch $global::ldapbind_options -b $ldapgroup_target | grep 'sAMAccountName: ' |"; print "\nParsing : $ldapgroup_target\n"; # open(LDAP, "$global::ldapsearch -b \"$ldapgroup_target\" $global::ldapbind_options | grep 'sAMAccountName: ' ") || open(LDAP, $command_line) || die "Unable to open ldapsearch: - $!\n"; while (defined(my $line =)){ chomp($line); $line =~ s/^sAMAccountName\:\s+//; $line = lc "$line"; $found="false"; foreach $admintest ({at}global::adminarray){ #print "-$admintest $line\n"; if ($admintest =~ $line){ print "$ldapgroup_target - $line (ADMIN override)\n"; push {at}global::results, "$line=filter4\n"; $found="true";}} if ($found eq "false") { print "$ldapgroup_target - $line\n"; push {at}global::results, "$line=$filtername\n";} } #my {at}search_results = LDAP; close LDAP; # Loop over results cleaning it up # foreach my $line (sort {uc($a) cmp uc($b)} {at}search_results) { # chomp $line; # $line =~ s/^sAMAccountName\:\s+//; # $line = lc "$line"; # push {at}global::results, "$line=$filtername\n"; # } } #Writeout tmp open(RESULTS, ">$TempDir/ldapdata.txt") || die "Unable to open $TempDir/ldapdata.txt - $!\n"; for my $outline ({at}global::results) { print RESULTS "$outline"; }; close RESULTS; #Now diff system("/usr/bin/diff -b $TempDir/ldapdata.txt $global::last_update"); if ($? == 0) { system("/bin/rm -f $TempDir/ldapdata.txt"); print "\nNo changes since previous list update!\n"; exit; } elsif ($? == 256) { #They differ lets update system("/bin/cat $global::template $TempDir/ldapdata.txt > $global::dansguardconf"); system("/etc/init.d/dansguardian restart"); system("/bin/cp $TempDir/ldapdata.txt $global::last_update"); system("/bin/rm -f $TempDir/ldapdata.txt"); print "\n List file changed\n"; } else { #Must be an error on the diff log it system("/usr/bin/logger -p daemon.err 'Active Domain update failed diff test for Dansguardian! Needs helps."); } exit; # vi: shiftwidth=3 tabstop=3 et you must change {at} to @ the forums Editor was weird and i had to change the @
×
×
  • Create New...