| Current Path : /var/www/html/ajay/Proto/mtech2014/ |
| Current File : /var/www/html/ajay/Proto/mtech2014/ldifraw.php |
<?php
$delimiter=",";
$src_file = $argv[1];
$tmpl_file = $argv[2];
if (file_exists($src_file)) {
if (file_exists($tmpl_file)) {
$src_handle = fopen($src_file,"r");
$src_row = 1;
while (!feof($src_handle)) {
$src_buffer = fgetcsv($src_handle, 4096, $delimiter);
$src_num = count($src_buffer);
if ($src_row == 1) {
for ($src_c=0; $src_c < $src_num; $src_c++) {
$src_headers = $src_buffer;
}
} else {
if (@strlen($src_buffer)) {
$tmpl_handle = fopen($tmpl_file,"r");
while (!feof($tmpl_handle)) {
$tmpl_buffer = fgets($tmpl_handle, 4096);
for ($src_c=0; $src_c < $src_num; $src_c++) {
if (strpos($src_buffer[$src_c], "@")) {
//$pwd = "{CRYPT}".crypt(substr($src_buffer[$src_c], 0, strpos($src_buffer[$src_c], "@")));
$pwd = "{SHA}".base64_encode(pack("H*",sha1(substr($src_buffer[$src_c], 0, strpos($src_buffer[$src_c], "@")))));
}
if ($src_headers[$src_c] == "password") {
$src_buffer[$src_c] = $pwd;
}
$tmpl_buffer = preg_replace("/%".$src_headers[$src_c]."%/",$src_buffer[$src_c],$tmpl_buffer);
}
echo $tmpl_buffer;
}
}
}
$src_row++;
}
$tmpl_close = fclose($tmpl_handle);
$src_close = fclose($src_handle);
} else {
die ("\r\nTemplate file does not exist!\r\nUsage: php convert.php [source_file] [template_file] > [target_file]\r\n\r\n");
}
} else {
die ("\r\nSource file does not exist!\r\nUsage: php convert.php [source_file] [template_file] > [target_file]\r\n\r\n");
}
?>