Skip to content

Instantly share code, notes, and snippets.

@hotta
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotta/89af4f60feef414d9301 to your computer and use it in GitHub Desktop.
Save hotta/89af4f60feef414d9301 to your computer and use it in GitHub Desktop.
a filter to conver the result of ldapsearch
#!/usr/bin/php
<?php
// base64encode.php by M.Hotta
// a filter to conver the result of ldapsearch command
//
function output($attr, $value, $encoded) {
if ($encoded) {
print $attr . ':: ' . base64_decode($value) . "\n";
} else {
print $attr . ':' . $value . "\n";
}
}
$first = true;
$encoded = false;
while ($line = fgets(STDIN)) {
$line = chop($line);
if (preg_match('/^\w+/', $line)) { // not a continuation line
if ($first) {
$first = false;
} else {
output($attr, $value, $encoded);
}
}
if (preg_match('/^\w+::/', $line)) { // encoded
list($attr, $value) = preg_split('/::/', $line, 2);
$encoded = true;
} else if (preg_match('/^\w+:/', $line)) { // not encoded
list($attr, $value) = preg_split('/:/', $line, 2);
$encoded = false;
} else { // continuation line
$value .= substr($line, 1);
}
}
output($attr, $value, $encoded);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment