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 5299 2011-10-03 09:25:33Z alec $
22 if (php_sapi_name() != 'cli') {
23 die('Not on the "shell" (php-cli).');
26 require_once INSTALL_PATH . 'program/include/iniset.php';
28 // Unset max. execution time limit, set to 120 seconds in iniset.php
32 * Parse commandline arguments into a hash array
34 function get_opt($aliases=array())
37 for ($i=1; $i<count($_SERVER['argv']); $i++)
39 $arg = $_SERVER['argv'][$i];
40 if (substr($arg, 0, 2) == '--')
42 $sp = strpos($arg, '=');
43 $key = substr($arg, 2, $sp - 2);
44 $value = substr($arg, $sp+1);
46 else if ($arg{0} == '-')
48 $key = substr($arg, 1);
49 $value = $_SERVER['argv'][++$i];
54 $args[$key] = preg_replace(array('/^["\']/', '/["\']$/'), '', $value);
56 if ($alias = $aliases[$key])
57 $args[$alias] = $args[$key];
65 * from http://blogs.sitepoint.com/2009/05/01/interactive-cli-password-prompt-in-php/
67 function prompt_silent($prompt = "Password:")
69 if (preg_match('/^win/i', PHP_OS)) {
70 $vbscript = sys_get_temp_dir() . 'prompt_password.vbs';
71 file_put_contents($vbscript, 'wscript.echo(InputBox("' . addslashes($prompt) . '", "", "password here"))');
72 $command = "cscript //nologo " . escapeshellarg($vbscript);
73 $password = rtrim(shell_exec($command));
78 $command = "/usr/bin/env bash -c 'echo OK'";
79 if (rtrim(shell_exec($command)) !== 'OK') {
81 $pass = trim(fgets(STDIN));
82 echo chr(8)."\r" . $prompt . str_repeat("*", strlen($pass))."\n";
85 $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'";
86 $password = rtrim(shell_exec($command));