4 +-----------------------------------------------------------------------+
5 | program/include/clisetup.php |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2010, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Setup the command line environment and provide some utitlity |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: clisetup.php 4678 2011-04-20 13:58:21Z alec $
22 if (php_sapi_name() != 'cli') {
23 die('Not on the "shell" (php-cli).');
26 require_once INSTALL_PATH . 'program/include/iniset.php';
30 * Parse commandline arguments into a hash array
32 function get_opt($aliases=array())
35 for ($i=1; $i<count($_SERVER['argv']); $i++)
37 $arg = $_SERVER['argv'][$i];
38 if (substr($arg, 0, 2) == '--')
40 $sp = strpos($arg, '=');
41 $key = substr($arg, 2, $sp - 2);
42 $value = substr($arg, $sp+1);
44 else if ($arg{0} == '-')
46 $key = substr($arg, 1);
47 $value = $_SERVER['argv'][++$i];
52 $args[$key] = preg_replace(array('/^["\']/', '/["\']$/'), '', $value);
54 if ($alias = $aliases[$key])
55 $args[$alias] = $args[$key];
63 * from http://blogs.sitepoint.com/2009/05/01/interactive-cli-password-prompt-in-php/
65 function prompt_silent($prompt = "Password:")
67 if (preg_match('/^win/i', PHP_OS)) {
68 $vbscript = sys_get_temp_dir() . 'prompt_password.vbs';
69 file_put_contents($vbscript, 'wscript.echo(InputBox("' . addslashes($prompt) . '", "", "password here"))');
70 $command = "cscript //nologo " . escapeshellarg($vbscript);
71 $password = rtrim(shell_exec($command));
76 $command = "/usr/bin/env bash -c 'echo OK'";
77 if (rtrim(shell_exec($command)) !== 'OK') {
79 $pass = trim(fgets(STDIN));
80 echo chr(8)."\r" . $prompt . str_repeat("*", strlen($pass))."\n";
83 $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'";
84 $password = rtrim(shell_exec($command));