define('DEST_FILENAME', __DIR__.'/top_passwords.txt');
for ($i = 1; $argc > $i; $i++) {
if (!is_readable($argv[$i]) || !is_file($argv[$i])) {
fwrite(STDERR, 'The file "'.$argv[$i].'" does not exist or is not readable.'."\n");
$files[$argv[$i]] = true;
fwrite(STDERR, 'No input file specified.'."\n");
foreach (array_keys($files) as $filename) {
$passwords += array_flip(file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
$passwords = array_keys($passwords);
$passwords = array_filter($passwords, function ($password) {
return !preg_match('/[^\x20-\x7e]/', $password);
$passwords = array_map('base64_encode', $passwords);
"# This file is meant to strengthen password validation for internal users. Passwords included in the list are considered\n".
"# weak due to their common use and are not allowed to be chosen by Zabbix internal users for security reasons. The file \n".
"# is generated automatically from the list of NCSC \"Top 100k passwords\", the list of SecLists \"Top 1M passwords\" and the\n".
"# list of Zabbix context-specific passwords.\n".
"# The list of passwords is used to check for commonly used passwords according to the password policy. Passwords are\n".
"# stored as base64-encoded strings. There must be two newlines before passwords.\n".
implode("\n", $passwords).