Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Amanda Emily

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

PHP - Change Active Directory Password

   1  
   2  <?php
   3  $username=$_POST['user_name'];
   4  //print $username;
   5  
   6  $ldap = ldap_connect($config['ldapServers'], 636);
   7  ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
   8  ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
   9    if ($ldap)
  10  {
  11  $bind = ldap_bind($ldap, $config['ldapUsername'], $config['ldapPassword']);
  12  $filter="(sAMAccountName=$username)";
  13  $result = ldap_search($ldap,"dc=yourcompany,dc=com",$filter);
  14  //var_dump($results); 
  15          ldap_sort($ldap,$result,"sn");
  16         $info = ldap_get_entries($ldap, $result);
  17         for ($i=0; $i<$info["count"]; $i++)
  18         {
  19  echo "<p>You are changing the password for <b> ". $info[$i]["givenname"][0] .", " . $info[$i]["sn"][0] ."</b> (" . $info[$i]["samaccountname"][0] .") to <b>" . $_POST['user_pass'] ."</b></p>\n";
  20               $passwd1 = $_POST['user_pass'];
  21                $userDn = $info[$i]["distinguishedname"][0];
  22                $newPassword = $passwd1;
  23        $newPassword = "\"" . $newPassword . "\"";
  24        $len = strlen($newPassword);
  25        for ($i = 0; $i < $len; $i++){
  26              $newPassw .= "{$newPassword{$i}}\000";}
  27        $newPassword = $newPassw;
  28        $userdata["unicodePwd"] = $newPassword;
  29        $result = ldap_mod_replace($ldap, $userDn , $userdata);
  30        if ($result) echo "Your password has been changed!" ;
  31        else echo "There was a problem changing your password, please call IT for help"; 
  32   }
  33           }
  34          @ldap_close($ldap);
  35  ?>

Perl - Cisco VLAN Removal

// Perl - Cisco VLAN Removal
// new.txt format
// ipaddress|loginpass|enablepass|gigabitEthernet3/48|20

   1  
   2  #!c:/perl/bin/perl.exe
   3  
   4  use Net::Telnet::Cisco;
   5  
   6  open(CISCO,'new.txt');
   7   while (<CISCO>) {
   8   chomp;
   9  my @fields = split(/\|/, $_);
  10  
  11  my $host = $fields[0];
  12  my $login = $fields[1];
  13  my $telnet = $fields[2];
  14  my $interface = $fields[3];
  15  my $vlan = $fields[4];
  16  
  17  #print "Content-type:text/html\n\n";
  18  #print "Switch = <b>$host</b>    <br>";
  19  #print "Command =  <b>username $macaddr password $macaddr</b>  <br>";
  20  
  21  $session = Net::Telnet::Cisco->new(Host => "$host", Input_log => "input.log");
  22  $session->login(Password => "$login");
  23  $session->enable("$telnet");
  24  $session->cmd("config t");
  25  $session->cmd("int $interface");
  26  $session->cmd("no switchport access vlan $vlan");
  27  $session->cmd("no switchport mode access");
  28  $session->cmd("exit");
  29  $session->close();
  30  }

Perl - Cisco Wireless Managment

// Perl script to update MAC access table on Cisco IOS-based AiroNets

   1  
   2  #!c:/perl/bin/perl.exe
   3  
   4  # Update Aironet IOS mac addresses
   5  
   6  use Net::Telnet::Cisco;
   7  use vars qw($r @data);
   8  
   9  print "Content-type:text/html\n\n";
  10  
  11  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  12  @pairs = split(/&/, $buffer);
  13  foreach $pair (@pairs) {
  14      ($name, $value) = split(/=/, $pair);
  15      $value =~ tr/+/ /;
  16      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  17      $FORM{$name} = $value;
  18  }
  19  
  20  
  21  $macaddr = $FORM{'command'};
  22  #$macaddr = 'AABBCCDDEEFF';
  23  
  24  print "using command <u>username <b>$macaddr</b> password <b>0$macaddr</b></u><br><br>";
  25  
  26  	
  27  print "Updating AP <b>127.0.0.1 (conference center)</b>    <br>";
  28  $r = Net::Telnet::Cisco->new(Host=>"127.0.0.1");
  29  	$r->login("login","password");
  30  die($r->errmsg) unless($r->enable("password"));
  31  	$r->cmd('terminal length 0');
  32  	$r->cmd('config t');
  33  	$r->cmd("username $macaddr password $macaddr");
  34  	$r->cmd("username $macaddr autocommand exit");
  35  	$r->cmd("exit");
  36  	$r->cmd("write memory quiet");
  37  	$r->cmd('terminal length 24');
  38  	$r->close();
  39  print "Done!";
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS