diff --git a/bin/importPdoMetadata.php b/bin/importPdoMetadata.php index 9e4fe8bf57f5f3adbced92f82e3413e065ac1a26..79e4b504a2326208616469f7e1f9cc7bac31c531 100755 --- a/bin/importPdoMetadata.php +++ b/bin/importPdoMetadata.php @@ -2,27 +2,27 @@ <?php $baseDir = dirname(dirname(__FILE__)); -require_once $baseDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . '_autoload.php'; -require_once SimpleSAML\Utils\Config::getConfigDir(). DIRECTORY_SEPARATOR . 'config.php'; +require_once $baseDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'_autoload.php'; +require_once SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php'; # Iterate through configured metadata sources and ensure # that a PDO source exists. foreach ($config['metadata.sources'] as $s) { - # If pdo is configured, create the new handler and add in the metadata sets. - if ($s['type'] === "pdo") { - $mdshp = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($s); - $mdshp->initDatabase(); + # If pdo is configured, create the new handler and add in the metadata sets. + if ($s['type'] === "pdo") { + $mdshp = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($s); + $mdshp->initDatabase(); - foreach (glob("metadata/*.php") as $filename) { - $metadata = array(); - require_once $filename; - $set = basename($filename, ".php"); - echo "importing set '$set'..." . PHP_EOL; + foreach (glob("metadata/*.php") as $filename) { + $metadata = array(); + require_once $filename; + $set = basename($filename, ".php"); + echo "importing set '$set'...".PHP_EOL; - foreach ($metadata as $k => $v) { - echo "\t$k" . PHP_EOL; - $mdshp->addEntry($k, $set, $v); - } - } - } + foreach ($metadata as $k => $v) { + echo "\t$k".PHP_EOL; + $mdshp->addEntry($k, $set, $v); + } + } + } } diff --git a/bin/initMDSPdo.php b/bin/initMDSPdo.php index 48375a0b601f5015ab3065c49eaeb62ad80dd1c8..b68a5b22f6ccc2bfe311a8f9dc0fd67528eeb850 100755 --- a/bin/initMDSPdo.php +++ b/bin/initMDSPdo.php @@ -5,23 +5,23 @@ $baseDir = dirname(dirname(__FILE__)); // Add library autoloader and configuration -require_once $baseDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . '_autoload.php'; -require_once SimpleSAML\Utils\Config::getConfigDir(). DIRECTORY_SEPARATOR . 'config.php'; +require_once $baseDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'_autoload.php'; +require_once SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php'; -echo "Initializing Metadata Database...". PHP_EOL; +echo "Initializing Metadata Database...".PHP_EOL; # Iterate through configured metadata sources and ensure # that a PDO source exists. foreach ($config['metadata.sources'] as $source) { - # If pdo is configured, create the new handler and initialize the DB. - if ($source['type'] === "pdo") { - $metadataStorageHandler = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($source); - $result = $metadataStorageHandler->initDatabase(); + # If pdo is configured, create the new handler and initialize the DB. + if ($source['type'] === "pdo") { + $metadataStorageHandler = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($source); + $result = $metadataStorageHandler->initDatabase(); - if ($result === false) { - echo "Failed to intialize metadata database.". PHP_EOL; - } else { - echo "Successfully initialized metadata database.". PHP_EOL; - } - } + if ($result === false) { + echo "Failed to initialize metadata database.".PHP_EOL; + } else { + echo "Successfully initialized metadata database.".PHP_EOL; + } + } } diff --git a/bin/memcacheSync.php b/bin/memcacheSync.php index 2de186ae5f4fdf74750b6909d848ece87aa338db..6e3ae4ad7c2c1450f58edbfc51a4a6cdb7773811 100755 --- a/bin/memcacheSync.php +++ b/bin/memcacheSync.php @@ -3,25 +3,25 @@ // Check that the memcache library is enabled -if(!class_exists('Memcache')) { - echo("Error: the memcache library appears to be unavailable.\n"); - echo("\n"); - echo("This is most likely because PHP doesn't load it for the command line\n"); - echo("version. You probably need to enable it somehow.\n"); - echo("\n"); - if(is_dir('/etc/php5/cli/conf.d')) { - echo("It is possible that running the following command as root will fix it:\n"); - echo(" echo 'extension=memcache.so' >/etc/php5/cli/conf.d/memcache.ini\n"); - } - - exit(1); +if (!class_exists('Memcache')) { + echo("Error: the memcache library appears to be unavailable.\n"); + echo("\n"); + echo("This is most likely because PHP doesn't load it for the command line\n"); + echo("version. You probably need to enable it somehow.\n"); + echo("\n"); + if (is_dir('/etc/php5/cli/conf.d')) { + echo("It is possible that running the following command as root will fix it:\n"); + echo(" echo 'extension=memcache.so' >/etc/php5/cli/conf.d/memcache.ini\n"); + } + + exit(1); } // This is the base directory of the SimpleSAMLphp installation $baseDir = dirname(dirname(__FILE__)); // Add library autoloader -require_once($baseDir . '/lib/_autoload.php'); +require_once($baseDir.'/lib/_autoload.php'); // Initialize the configuration $configdir = SimpleSAML\Utils\Config::getConfigDir(); @@ -35,129 +35,131 @@ $warnBigSlab = 0; $stats = SimpleSAML_Memcache::getRawStats(); $keys = array(); -foreach($stats as $group) { - foreach($group as $server => $state) { - - if($state === FALSE) { - echo("WARNING: Server " . $server . " is down.\n"); - $warnServerDown++; - continue; - } - - $items = $state['curr_items']; - echo("Server " . $server . " has " . $items . " items.\n"); - $serverKeys = getServerKeys($server); - $keys = array_merge($keys, $serverKeys); - } +foreach ($stats as $group) { + foreach ($group as $server => $state) { + + if ($state === false) { + echo("WARNING: Server ".$server." is down.\n"); + $warnServerDown++; + continue; + } + + $items = $state['curr_items']; + echo("Server ".$server." has ".$items." items.\n"); + $serverKeys = getServerKeys($server); + $keys = array_merge($keys, $serverKeys); + } } -echo("Total number of keys: " . count($keys) . "\n"); +echo("Total number of keys: ".count($keys)."\n"); $keys = array_unique($keys); -echo("Total number of unique keys: " . count($keys) . "\n"); +echo("Total number of unique keys: ".count($keys)."\n"); echo("Starting synchronization.\n"); $skipped = 0; $sync = 0; -foreach($keys as $key) { - $res = SimpleSAML_Memcache::get($key); - if($res === NULL) { - $skipped += 1; - } else { - $sync += 1; - } +foreach ($keys as $key) { + $res = SimpleSAML_Memcache::get($key); + if ($res === null) { + $skipped += 1; + } else { + $sync += 1; + } } echo("Synchronization done.\n"); -echo($sync . " keys in sync.\n"); -if($skipped > 0) { - echo($skipped . " keys skipped.\n"); - echo("Keys are skipped because they are either expired, or are of a type unknown\n"); - echo("to SimpleSAMLphp.\n"); +echo($sync." keys in sync.\n"); +if ($skipped > 0) { + echo($skipped." keys skipped.\n"); + echo("Keys are skipped because they are either expired, or are of a type unknown\n"); + echo("to SimpleSAMLphp.\n"); } -if($warnServerDown > 0) { - echo("WARNING: " . $warnServerDown . " server(s) down. Not all servers are synchronized.\n"); +if ($warnServerDown > 0) { + echo("WARNING: ".$warnServerDown." server(s) down. Not all servers are synchronized.\n"); } -if($warnBigSlab > 0) { - echo("WARNING: " . $warnBigSlab . " slab(s) may have contained more keys than we were told about.\n"); +if ($warnBigSlab > 0) { + echo("WARNING: ".$warnBigSlab." slab(s) may have contained more keys than we were told about.\n"); } /** * Fetch all keys available in an server. * - * @param $server The server, as a string with <hostname>:<port>. - * @return An array with all the keys available on the server. + * @param string $server The server, as a string with <hostname>:<port>. + * + * @return array An array with all the keys available on the server. */ -function getServerKeys($server) { - $server = explode(':', $server); - $host = $server[0]; - $port = (int)$server[1]; - - echo("Connecting to: " . $host . ":" . $port . "\n"); - $socket = fsockopen($host, $port); - echo("Connected. Finding keys.\n"); - - if(fwrite($socket, "stats slabs\r\n") === FALSE) { - echo("Error requesting slab dump from server.\n"); - exit(1); - } - - // Read list of slabs - $slabs = array(); - while( ($line = fgets($socket)) !== FALSE) { - $line = rtrim($line); - if($line === 'END') { - break; - } - - if(preg_match('/^STAT (\d+):/', $line, $matches)) { - $slab = (int)$matches[1]; - if(!in_array($slab, $slabs, TRUE)) { - $slabs[] = $slab; - } - } - } - - // Dump keys in slabs - $keys = array(); - foreach($slabs as $slab) { - - if(fwrite($socket, "stats cachedump " . $slab . " 1000000\r\n") === FALSE) { - echo("Error requesting cache dump from server.\n"); - exit(1); - } - - /* We keep track of the result size, to be able to warn the user if it is - * so big that keys may have been lost. - */ - $resultSize = 0; - - while( ($line = fgets($socket)) !== FALSE) { - $resultSize += strlen($line); - - $line = rtrim($line); - if($line === 'END') { - break; - } - - if(preg_match('/^ITEM (.*) \[\d+ b; \d+ s\]/', $line, $matches)) { - $keys[] = $matches[1]; - } else { - echo("Unknown result from cache dump: " . $line . "\n"); - } - } - if($resultSize > 1900000 || count($keys) >= 1000000) { - echo("WARNING: Slab " . $slab . " on server " . $host . ":" . $port . - " may have contained more keys than we were told about.\n"); - $GLOBALS['warnBigSlab'] += 1; - } - } - - echo("Found " . count($keys) . " key(s).\n"); - fclose($socket); - - return $keys; +function getServerKeys($server) +{ + $server = explode(':', $server); + $host = $server[0]; + $port = (int) $server[1]; + + echo("Connecting to: ".$host.":".$port."\n"); + $socket = fsockopen($host, $port); + echo("Connected. Finding keys.\n"); + + if (fwrite($socket, "stats slabs\r\n") === false) { + echo("Error requesting slab dump from server.\n"); + exit(1); + } + + // Read list of slabs + $slabs = array(); + while (($line = fgets($socket)) !== false) { + $line = rtrim($line); + if ($line === 'END') { + break; + } + + if (preg_match('/^STAT (\d+):/', $line, $matches)) { + $slab = (int) $matches[1]; + if (!in_array($slab, $slabs, true)) { + $slabs[] = $slab; + } + } + } + + // Dump keys in slabs + $keys = array(); + foreach ($slabs as $slab) { + + if (fwrite($socket, "stats cachedump ".$slab." 1000000\r\n") === false) { + echo("Error requesting cache dump from server.\n"); + exit(1); + } + + /* We keep track of the result size, to be able to warn the user if it is + * so big that keys may have been lost. + */ + $resultSize = 0; + + while (($line = fgets($socket)) !== false) { + $resultSize += strlen($line); + + $line = rtrim($line); + if ($line === 'END') { + break; + } + + if (preg_match('/^ITEM (.*) \[\d+ b; \d+ s\]/', $line, $matches)) { + $keys[] = $matches[1]; + } else { + echo("Unknown result from cache dump: ".$line."\n"); + } + } + if ($resultSize > 1900000 || count($keys) >= 1000000) { + echo("WARNING: Slab ".$slab." on server ".$host.":".$port. + " may have contained more keys than we were told about.\n"); + $GLOBALS['warnBigSlab'] += 1; + } + } + + echo("Found ".count($keys)." key(s).\n"); + fclose($socket); + + return $keys; } diff --git a/bin/pwgen.php b/bin/pwgen.php index a91df060d923da0630d1c8f5c027832c1978dc13..e91486d3548cb28caeac96419971665ef96b2267 100755 --- a/bin/pwgen.php +++ b/bin/pwgen.php @@ -10,38 +10,38 @@ $baseDir = dirname(dirname(__FILE__)); // Add library autoloader -require_once($baseDir . '/lib/_autoload.php'); +require_once($baseDir.'/lib/_autoload.php'); echo "Enter password: "; $password = trim(fgets(STDIN)); -if(empty($password)) { - echo "Need at least one character for a password\n"; - exit(1); +if (empty($password)) { + echo "Need at least one character for a password\n"; + exit(1); } $table = ''; foreach (array_chunk(hash_algos(), 6) as $chunk) { - foreach($chunk as $algo) { - $table .= sprintf('%-13s', $algo); - } - $table .= "\n"; + foreach ($chunk as $algo) { + $table .= sprintf('%-13s', $algo); + } + $table .= "\n"; } -echo "The following hashing algorithms are available:\n" . $table . "\n"; +echo "The following hashing algorithms are available:\n".$table."\n"; echo "Which one do you want? [sha256] "; $algo = trim(fgets(STDIN)); -if(empty($algo)) { - $algo = 'sha256'; +if (empty($algo)) { + $algo = 'sha256'; } -if(!in_array(strtolower($algo), hash_algos())) { - echo "Hashing algorithm '$algo' is not supported\n"; - exit(1); +if (!in_array(strtolower($algo), hash_algos())) { + echo "Hashing algorithm '$algo' is not supported\n"; + exit(1); } echo "Do you want to use a salt? (yes/no) [yes] "; $s = (trim(fgets(STDIN)) == 'no') ? '' : 'S'; -echo "\n " . SimpleSAML\Utils\Crypto::pwHash($password, strtoupper( $s . $algo ) ). "\n\n"; +echo "\n ".SimpleSAML\Utils\Crypto::pwHash($password, strtoupper($s.$algo))."\n\n";