public function run(ChefContext $context) { $result = $context->getResult(); $log = $context->getLog(); $rootDir = $context->getApp()->getRootDir(); $fullAddress = $result->command->args['server']; $matches = array(); if (!preg_match('/^([^:]+)(\\:([^@]+))?@(.*)$/', $fullAddress, $matches)) { throw new PieCrustException("The given upload address was not valid. Must be of form: user:password@domain.tld"); } $user = $matches[1]; $password = $matches[3]; $server = $matches[4]; $remoteRootDir = $result->command->options['remote_root']; if (!$remoteRootDir) { $remoteRootDir = '/'; } $remoteRootDir = rtrim($remoteRootDir, '/\\') . '/'; $passiveMode = $result->command->options['passive']; $syncMode = FTP_SYNC_ALWAYS; switch ($result->command->options['sync_mode']) { case 'time': $syncMode = FTP_SYNC_IF_NEWER; break; case 'time_and_size': $syncMode = FTP_SYNC_IF_NEWER_OR_DIFFERENT_SIZE; break; } $simulate = $result->command->options['simulate']; $log->info("Uploading to '{$server}' [{$remoteRootDir}] as {$user}"); $conn = ftp_connect($server); if ($conn === false) { throw new PieCrustException("Can't connect to FTP server '{$server}'."); } if (!isset($password) or $password == "") { $password = prompt_silent("Password: "******"Connected to FTP server '{$server}'."); if ($passiveMode) { $log->info("Enabling passive mode."); if (!ftp_pasv($conn, true)) { throw new PieCrustException("Can't enable passive mode."); } } sync_ftp($conn, $rootDir, $remoteRootDir, $syncMode, $simulate); } else { throw new PieCrustException("Couldn't connect to FTP server '{$server}', login incorrect."); } } catch (Exception $e) { ftp_close($conn); throw $e; } ftp_close($conn); }
/** * The Procedure for the sendfileftp function * * @param Menu $backMenu The Menu for return * * @return void */ function sendFileFTPProcedure(Menu $backMenu) { $procedure = new Procedure(); $choice = "0"; $procedure->showReturnChoice($choice); $qt_hostname = $procedure->createQuestion("Hostname: "); $hostname = $procedure->askQuestion($qt_hostname); if ($hostname === $choice) { $procedure->clearScreen(); $procedure->showMenu($backMenu, true); exit; } $qt_username = $procedure->createQuestion("Username: "******"File: "); $file = $procedure->askQuestion($qt_file); $qt_port = $procedure->createQuestion("Port [default 21]: ", 21); $port = $procedure->askQuestion($qt_port); $qt_passiveMode = $procedure->createQuestion("Switch to passive mode [y or n, default n]? ", "n"); $passiveMode = $procedure->askQuestion($qt_passiveMode); $qt_ASCIIMode = $procedure->createQuestion("Switch to ASCII mode [y or n, default n]? ", "n"); $ASCIIMode = $procedure->askQuestion($qt_ASCIIMode); $commandLine = "php " . dirname(__FILE__) . "/sendFileFTP.php " . $hostname . " " . $username . " " . $password . " " . $file; if ($port != "") { $commandLine .= " -p " . $port; } if ($passiveMode == "y") { $commandLine .= " -m"; } if ($ASCIIMode == "y") { $commandLine .= " -t"; } echo "\n"; echo shell_exec($commandLine) . "\n\n"; }
/** * The Procedure for the request function * * @param Menu $backMenu The Menu for return * * @return void */ function requestProcedure(Menu $backMenu) { $procedure = new Procedure(); $choice = "0"; $procedure->showReturnChoice($choice); $qt_rootURL = $procedure->createQuestion("Root URL (ie https://localhost/mediboard): "); $rootURL = $procedure->askQuestion($qt_rootURL); if ($rootURL === $choice) { $procedure->clearScreen(); $procedure->showMenu($backMenu, true); exit; } $qt_username = $procedure->createQuestion("Username (ie cron): "); $username = $procedure->askQuestion($qt_username); $password = prompt_silent(); $qt_params = $procedure->createQuestion("Params (ie m=dPpatients&tab=vw_medecins): "); $params = $procedure->askQuestion($qt_params); $qt_times = $procedure->createQuestion("Times (number of repetitions) [default 1]: ", 1); $times = $procedure->askQuestion($qt_times); $qt_delay = $procedure->createQuestion("Delay (time between each repetition) [default 1]: ", 1); $delay = $procedure->askQuestion($qt_delay); $qt_file = $procedure->createQuestion("File (file for the output, ie log.txt) [default no file]: "); $file = $procedure->askQuestion($qt_file); echo "\n"; request($rootURL, $username, $password, $params, $times, $delay, $file); }
trigger_error("Can't invoke bash"); return; } $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'"; $password = rtrim(shell_exec($command)); echo "\n"; return $password; } } if ($argc <= 1) { // if no arguments echo 'Usage: ' . $argv[0] . ' user ID or name. '; echo "\nExample: php reset-password.php myusername"; echo "\n"; exit; } $method = is_numeric($argv[1]) ? 'getById' : 'getByName'; /** @var User $user */ $user = User::$method($argv[1]); if (!$user) { echo sprintf("User with name '%s' could not be found. Exiting.\n", $argv[1]); exit; } $plainPassword = false; while (empty($plainPassword)) { $plainPassword = prompt_silent(); } $password = Pimcore\Tool\Authentication::getPasswordHash($user->getName(), $plainPassword); $user->setPassword($password); $user->save(); echo sprintf("Password for user '%s' reset successfully.\n", $user->getName());
echo "Input file/folder did not exist\n\n"; echo $usage; exit(1); } if ($options->bootstrap && !file_exists($options->bootstrap)) { echo "Bootstrap file did not exist\n\n"; echo $usage; exit(1); } if (!$options->notes && !$options->namespaces) { echo "Please specify some notes and/or namespaces to search for\n\n"; echo $usage; exit(1); } if ($options->prompt) { $options->password = prompt_silent("Password: "******"Please pass the --mapper parameter or define a mapper in a bootstrap file\n\n" . $usage;
function task11() { echo "##################\n"; echo "# Rotate binlogs #\n"; echo "##################\n\n"; echo "[0] Return to main menu\n\n"; echo "MySQL username: "******"0") { echo exec("clear") . "\n"; menu(); } $passAdminDB = prompt_silent("MySQL user password: "******"BinLogs directory [default /var/log/mysql]: "; $binLogsDir = trim(fgets(STDIN)); if ($binLogsDir === "") { $binLogsDir = "/var/log/mysql"; } echo "BinLog index filename [default log-bin.index]: "; $binLogIndexFilename = trim(fgets(STDIN)); if ($binLogIndexFilename === "") { $binLogIndexFilename = "log-bin.index"; } echo "Backup directory [default /mbbackup/binlogs]: "; $backupDir = trim(fgets(STDIN)); if ($backupDir === "") { $backupDir = "/mbbackup/binlogs"; } echo "\n"; echo shell_exec("sh " . $GLOBALS['currentDir'] . "/rotateBinlogs.sh " . $userAdminDB . " " . $passAdminDB . " " . $binLogsDir . " " . $binLogIndexFilename . " " . $backupDir) . "\n"; menu(); }
/** * The Procedure for the rotatebinlogs function * * @param Menu $backMenu The Menu for return * * @return void */ function rotateBinlogsProcedure(Menu $backMenu) { $procedure = new Procedure(); $choice = "0"; $procedure->showReturnChoice($choice); $qt_userAdminDB = $procedure->createQuestion("MySQL username: "******"MySQL user password: "******"BinLogs directory [default /var/log/mysql]: ", "/var/log/mysql"); $binLogsDir = $procedure->askQuestion($qt_binLogsDir); $qt_binLogIndexFilename = $procedure->createQuestion("BinLog index filename [default log-bin.index]: ", "log-bin.index"); $binLogIndexFilename = $procedure->askQuestion($qt_binLogIndexFilename); $qt_backupDir = $procedure->createQuestion("Backup directory [default /mbbackup/binlogs]: ", "/mbbackup/binlogs"); $backupDir = $procedure->askQuestion($qt_backupDir); echo "\n"; rotateBinlogs($userAdminDB, $passAdminDB, $binLogsDir, $binLogIndexFilename, $backupDir); }
$type = $opts['t']; break; case "type": $type = $opts["type"]; break; } } // required parameters validation if (!isset($server) || !isset($user) || !isset($type)) { echo "Error: missing required parameters\n"; usage(); exit(1); } // prompt for password if not provided if (!isset($pswd)) { $pswd = prompt_silent(); } // specify default values if not provided if (!isset($report)) { $report = "vCloudDirectorReport.html"; } // Initialize parameters $httpConfig = array('ssl_verify_peer' => false, 'ssl_verify_host' => false); // login $service = VMware_VCloud_SDK_Service::getService(); $service->login($server, array('username' => $user, 'password' => $pswd), $httpConfig); // create SDK Query object $sdkQuery = VMware_VCloud_SDK_Query::getInstance($service); $serverName = str_replace("https://", "", $server); $jumpTagOutput = ""; $summaryHeaderOutput = "";
return $password; } else { $command = "/usr/bin/env bash -c 'echo OK'"; if (rtrim(shell_exec($command)) !== 'OK') { trigger_error("Can't invoke bash"); return; } $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'"; $password = rtrim(shell_exec($command)); fprintf(STDERR, "\n"); return $password; } } if ($argc < 3) { die("Usage: ./github-export.php %USERNAME% %REPOSITORY%"); } $username = $argv[1]; $password = prompt_silent("Your password: "******"https://api.github.com/repos/{$repository}/issues?status=open&per_page=1000"); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); curl_setopt($ch, CURLOPT_USERAGENT, 'asmisha parser'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $issues = json_decode(curl_exec($ch)); //$fp = fopen('out.csv', 'w'); $fp = STDOUT; fputcsv($fp, array('Milestone', 'ID', 'State', 'Title', 'Description')); foreach ($issues as $i) { fputcsv($fp, array(@$i->milestone->title, @$i->number, @$i->state, @$i->title, @$i->body)); } //fclose($fp);
/** * The Procedure for the basebackup function * * @param Menu $backMenu The Menu for return * * @return void */ function baseBackupProcedure(Menu $backMenu) { $procedure = new Procedure(); echo "Method:\n\n"; echo "[1] Hotcopy\n"; echo "[2] Dump\n"; echo "--------------------\n"; $choice = "0"; $procedure->showReturnChoice($choice); $qt_method = $procedure->createQuestion("\nSelected method: "); $method = $procedure->askQuestion($qt_method); switch ($method) { case "1": $method = "hotcopy"; break; case "2": $method = "dump"; break; case $choice: $procedure->clearScreen(); $procedure->showMenu($backMenu, true); break; default: $procedure->clearScreen(); cecho("Incorrect input", "red"); echo "\n"; baseBackupProcedure($backMenu); } $qt_username = $procedure->createQuestion("Username (to access database): "); $username = $procedure->askQuestion($qt_username); $password = prompt_silent(); $hostname = ""; $port = ""; $qt_DBBackup = $procedure->createQuestion("Database to backup (ie mediboard): "); $DBBackup = $procedure->askQuestion($qt_DBBackup); $qt_backupPath = $procedure->createQuestion("Backup path (ie /var/backup): "); $backupPath = $procedure->askQuestion($qt_backupPath); $qt_time = $procedure->createQuestion("Time (in days before removal of files) [default 7]: ", 7); $time = $procedure->askQuestion($qt_time); if ($method == "hotcopy") { $qt_binLog = $procedure->createQuestion("Create a binary log index [y or n, default n]? ", "n"); $binLog = $procedure->askQuestion($qt_binLog); } else { $binLog = ""; } $qt_mail = $procedure->createQuestion("Send a mail when diskfull is detected [y or n, default n]? ", "n"); $mail = $procedure->askQuestion($qt_mail); if ($mail == "y") { $qt_usernameMail = $procedure->createQuestion("Username (to send a mail): "); $usernameMail = $procedure->askQuestion($qt_usernameMail); $passwordMail = prompt_silent(); } else { $usernameMail = ""; $passwordMail = ""; } $qt_lock = $procedure->createQuestion("Lock file path (ie /tmp/lock.txt) (leave blank for no lock file): ", null); $lock = $procedure->askQuestion($qt_lock); echo "\n"; baseBackup($method, $username, $password, $hostname, $port, $DBBackup, $backupPath, $time, $binLog, $usernameMail, $passwordMail, $lock); }
<?php /* command-line utility for generating hashes for our site */ if (PHP_SAPI != 'cli') { exit; } include 'credentials.inc.php'; /* http://www.sitepoint.com/interactive-cli-password-prompt-in-php/ */ function prompt_silent($prompt = " Enter password: "******"/usr/bin/env bash -c 'echo OK'"; if (rtrim(shell_exec($command)) !== 'OK') { trigger_error("Can't invoke bash"); return; } $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'"; $password = rtrim(shell_exec($command)); echo "\n"; return $password; } echo "Password hashing tool, requires Linux.\n---\n"; $p = prompt_silent(); $p2 = prompt_silent('Retype Password: '******'t match.\n"; } else { $hasher = new PHasher(); echo $hasher->create_hash($p); }
#!/usr/bin/php <?php require_once __DIR__ . '/init.php'; /** * @see http://httpd.apache.org/docs/2.2/misc/password_encryptions.html */ function hash_password($password) { return '{SHA}' . base64_encode(sha1($password, TRUE)); } count($argv) >= 2 or script_error("Need one argument as the username"); $username = $argv[1]; $password = prompt_silent("Enter New Password: "******"Enter New Password (again): "); if ($password != $repeat_password) { script_error('Repeat password mismatch'); } try { $user = new User($username); $user->setPassword(hash_password($password)); $user->store(); echo "Password reset successfully\n"; } catch (fNotFoundException $e) { script_error("User {$username} doesn't exist"); }
/** * Enable you to configure a server and to write in a XML file * * @param string $file Used configuration file * * @return void */ function configServer($file) { echo exec("clear"); // Check the file check_file($file); // Create a new DOMDocument object $dom = new DOMDocument(); // Load the XML file check_errs($dom->load($file), false, "File " . $file . " not correctly formed.", "File " . $file . " is OK!"); // Write the configuration filename file_put_contents("/tmp/replicationConfigurationFile", $file); // Get the root node $root = $dom->documentElement; echo "\n"; // Get the list of servers already in file $serverList = $dom->getElementsByTagName('serveur'); switch ($serverList->length) { // If no one, nothing case 0: break; // If one, warning and show its name // If one, warning and show its name case 1: $serverNameInFile = $serverList->item(0)->getAttribute('nom'); echo "There is already one server named " . $serverNameInFile . " configurated in this file.\n"; $answer = recup("Do you want to continue (y or n) [default y] ? ", "y"); if ($answer == "n") { echo exec("clear"); menu(); } break; // If more than one, quit // If more than one, quit default: echo exec("clear"); cecho("There is already two servers in this file.", "red"); echo "\n\n"; menu(); } // Get the parameters for the server echo "\n"; announce_script("Server configuration start"); echo "\n"; do { $a = true; $serverName = recup("Give a name to the server (it's for the XML file): "); /* Check for the server name redondancy */ // Get the server from the XML file if ($serverList->length == 1) { foreach ($serverList as $aServer) { if ($aServer->getAttribute('nom') == $serverName) { cecho("This server already exists!", "red"); echo "\n\n"; $a = false; } } } } while (!$a); /* End check */ $firstServer = recup("Is it the \"first\" server (odd primary keys...) (y or n) [default y] ? ", "y"); // Because we will compare with XML if ($firstServer != "n") { $firstServer = "y"; } // If there is already a server in the XML file if ($serverList->length == 1) { foreach ($serverList as $aServer) { if ($aServer->getAttribute('first') == $firstServer) { if ($firstServer == "y") { cecho("This server cannot be first because " . $aServer->getAttribute('nom') . " is already the first!", "red"); echo "\n\n"; cecho("This server will be configured to be the second.", "red"); } else { cecho("This server cannot be second because " . $aServer->getAttribute('nom') . " is already the second!", "red"); echo "\n\n"; cecho("This server will be configured to be the first.", "red"); } } } } $hostname = recup("Server IP: "); $localhost = recup("Is it the localhost address (y or n) [default n] ? ", "n"); // Because we will compare with XML if ($localhost != "y") { $localhost = "n"; } $DBPort = recup("Database port [default 3306]: ", 3306); $DBUser = recup("Database user: "******"Database user password: "******"Replication slave user: "******"Replication slave password: "******"Log-bin file [default /var/log/mysql/bin.log]: ", "/var/log/mysql/bin.log"); $logBinIndex = recup("Log-bin index [default /var/log/mysql/log-bin.index]: ", "/var/log/mysql/log-bin.index"); $logError = recup("Log-error [default /var/log/mysql/error.log]: ", "/var/log/mysql/error.log"); $relayLogFile = recup("Relay-log file [default /var/log/mysql/relay.log]: ", "/var/log/mysql/relay.log"); $relayLogInfoFile = recup("Relay-log info file [default /var/log/mysql/relay-log.info]: ", "/var/log/mysql/relay-log.info"); $relayLogIndex = recup("Relay-log index [default /var/log/mysql/relay-log.index]: ", "/var/log/mysql/relay-log.index"); echo "\n"; info_script("Server configuration end"); echo "\n"; // Create DOMElement and set its attributes $newServer = $dom->createElement('serveur'); $newServer->setAttribute('nom', $serverName); $newServer->setAttribute('first', $firstServer); $newServer->setAttribute('ip', $hostname); $newServer->setAttribute('localhost', $localhost); $newServer->setAttribute('dbport', $DBPort); $newServer->setAttribute('dbusername', $DBUser); $newServer->setAttribute('dbpassword', $DBPassword); $newSlave = $dom->createElement('esclave'); $newSlave->setAttribute('username', $slaveUser); $newSlave->setAttribute('password', $slavePassword); $newLogBin = $dom->createElement('logbin'); $newLogBin->setAttribute('logbinfile', $logBinFile); $newLogBin->setAttribute('logbinindex', $logBinIndex); $newLogBin->setAttribute('logerror', $logError); $newRelayLog = $dom->createElement('relaylog'); $newRelayLog->setAttribute('relaylogfile', $relayLogFile); $newRelayLog->setAttribute('relayloginfofile', $relayLogInfoFile); $newRelayLog->setAttribute('relaylogindex', $relayLogIndex); // Put the nodes into the server node $newServer->appendChild($newSlave); $newServer->appendChild($newLogBin); $newServer->appendChild($newRelayLog); // Put the server node into the root node $root->appendChild($newServer); // Write the XML file check_errs($dom->save($file), false, "Unable to save the " . $file . " file.", "File " . $file . " saved!"); }
echo "*************** W A R N I N G !!! ******************\n"; echo "* *\n"; echo "* All existing data in Powerdns MySQL database *\n"; echo "* WILL BE LOST. *\n"; echo "* Make a backup copy before proceeding. *\n"; echo "* *\n"; echo "****************************************************\n\n"; echo "Press ENTER to continue Ctrl-C to abort...\n"; fgets($fp, 1024); echo "Enter MySQL host name: "; $db_host = trim(fgets($fp, 1024)); echo "Enter MySQL database name: "; $db_name = trim(fgets($fp, 1024)); echo "Enter MySQL user name: "; $db_user = trim(fgets($fp, 1024)); $db_pass = prompt_silent("Enter MySQL password: "******"\nError: " . mysql_error() . "\n\n"; exit(1); } if (!@mysql_select_db($db_name)) { echo "\nError: " . mysql_error() . "\n\n"; exit(1); } str_replace_in_file('/^ dsn:.*$/m', " dsn: mysql://{$db_user}:{$db_pass}@{$db_host}/{$db_name}", SF_ROOT_DIR . '/config/databases.yml'); str_replace_in_file('/^propel\\.database\\.createUrl =.*$/m', "propel.database.createUrl = mysql://{$db_user}:{$db_pass}@{$db_host}/", SF_ROOT_DIR . '/config/propel.ini'); str_replace_in_file('/^propel\\.database\\.url =.*$/m', "propel.database.url = mysql://{$db_user}:{$db_pass}@{$db_host}/{$db_name}", SF_ROOT_DIR . '/config/propel.ini'); passthru(SF_ROOT_DIR . '/symfony propel-insert-sql'); passthru('php ' . SF_ROOT_DIR . '/batch/load_data.php'); passthru(SF_ROOT_DIR . '/symfony fix-perms'); if (!@mysql_query("ALTER TABLE `{$db_name}`.`domains` ENGINE = InnoDB")) {