init() публичный статический Метод

CLI scripts shouldn't timeout, so try to set the time limit to none. Also initialize a few variables in $_SERVER that aren't present from the CLI.
public static init ( ) : Horde_Cli
Результат Horde_Cli A Horde_Cli instance.
Пример #1
0
 /**
  * The main entry point for the application.
  *
  * @param array $parameters A list of named configuration parameters.
  * <pre>
  * 'parser'   - (array)     Parser configuration parameters.
  *   'class'  - (string)    The class name of the parser to use.
  * 'output'   - (Horde_Cli) The output handler.
  * </pre>
  */
 public static function main(array $parameters = array())
 {
     $modular = self::_prepareModular($parameters);
     if (empty($parameters['output'])) {
         if (!class_exists('Horde_Cli')) {
             throw new Horde_Kolab_Cli_Exception('The Horde_Cli package seems to be missing (Class Horde_Cli is missing)!');
         }
         $cli = Horde_Cli::init();
     } else {
         $cli = $parameters['output'];
     }
     $parser = $modular->createParser();
     list($options, $arguments) = $parser->parseArgs();
     if (count($arguments) == 0) {
         $parser->printHelp();
     } else {
         try {
             if (!empty($options['config'])) {
                 if (!file_exists($options['config'])) {
                     throw new Horde_Kolab_Cli_Exception(sprintf('The specified config file %s does not exist!', $options['config']));
                 }
                 global $conf;
                 include $options['config'];
                 foreach ($conf as $key => $value) {
                     $options->ensureValue($key, $value);
                 }
             }
             if (empty($options['host'])) {
                 $options['host'] = 'localhost';
             }
             if (empty($options['driver'])) {
                 $options['driver'] = 'horde';
             }
             $world = array();
             foreach ($modular->getModules() as $module) {
                 $modular->getProvider()->getModule($module)->handleArguments($options, $arguments, $world);
             }
             if (!empty($options['timed']) && class_exists('Horde_Support_Timer')) {
                 $timer = new Horde_Support_Timer();
                 $timer->push();
             } else {
                 $timer = false;
             }
             $modular->getProvider()->getModule(Horde_String::ucfirst($arguments[0]))->run($cli, $options, $arguments, $world);
             if (!empty($options['timed'])) {
                 if ($timer) {
                     $cli->message(floor($timer->pop() * 1000) . ' ms');
                 } else {
                     $cli->message('The class Horde_Support_Timer seems to be missing!');
                 }
             }
         } catch (Horde_Cli_Modular_Exception $e) {
             $parser->printHelp();
         }
     }
 }
Пример #2
0
 /**
  * Create the CLI handler.
  *
  * @return Horde_Cli The CLI handler.
  */
 public function createCli()
 {
     return Horde_Cli::init();
 }
Пример #3
0
 /**
  * The main entry point for the application.
  *
  * @param array $parameters A list of named configuration parameters.
  */
 public static function main(array $parameters = array())
 {
     $parser = new Horde_Argv_Parser(array('usage' => '%prog [OPTIONS] [SOURCE://ID]'));
     $parser->addOptions(array(new Horde_Argv_Option('-c', '--config', array('action' => 'store', 'help' => Horde_Push_Translation::t('Path to the configuration file.'))), new Horde_Argv_Option('-S', '--summary', array('action' => 'store', 'help' => Horde_Push_Translation::t('A summary replacing the value provided by the source.'))), new Horde_Argv_Option('-R', '--recipients', array('action' => 'store', 'help' => Horde_Push_Translation::t('A comma delimited list of recipients.'))), new Horde_Argv_Option('-T', '--tags', array('action' => 'store', 'help' => Horde_Push_Translation::t('A comma delimited list of tags.'))), new Horde_Argv_Option('-L', '--links', array('action' => 'store', 'help' => Horde_Push_Translation::t('A comma delimited list of links.'))), new Horde_Argv_Option('-p', '--pretend', array('action' => 'store_true', 'help' => Horde_Push_Translation::t('Do not push the content but display what would be done.')))));
     list($options, $arguments) = $parser->parseArgs();
     global $conf;
     if (isset($options['config'])) {
         if (!file_exists($options['config'])) {
             throw new Horde_Push_Exception(sprintf('The specified config file %s does not exist!', $options['config']));
         }
         include $options['config'];
     } else {
         $conf = array('recipients' => array('mock'));
     }
     if (empty($arguments)) {
         $arguments = explode(' ', trim(file_get_contents('php://stdin')));
     }
     $push_factory = new Horde_Push_Factory_Push();
     $pushes = $push_factory->create($arguments, $options, $conf);
     $fail = false;
     foreach ($pushes as $push) {
         if (isset($options['summary'])) {
             $push->setSummary($options['summary']);
         }
         if (isset($options['tags'])) {
             foreach (explode(',', $options['tags']) as $tag) {
                 $push->addTag($tag);
             }
         }
         if (isset($options['links'])) {
             foreach (explode(',', $options['links']) as $reference) {
                 $push->addReference($reference);
             }
         }
         $recipient_factory = new Horde_Push_Factory_Recipients();
         $recipients = $recipient_factory->create($options, $conf);
         foreach ($recipients as $recipient) {
             $push->addRecipient($recipient);
         }
         $results = $push->push(array('pretend' => !empty($options['pretend'])));
         $cli = Horde_Cli::init();
         foreach ($results as $result) {
             if ($result instanceof Exception) {
                 $cli->message($result->getMessage(), 'cli.error');
                 $fail = true;
             } else {
                 $cli->message((string) $result, 'cli.success');
             }
         }
     }
     if ($fail === true) {
         $status = 1;
     } else {
         $status = 0;
     }
     if (empty($parameters['no_exit'])) {
         exit($status);
     } else {
         return $status;
     }
 }
Пример #4
0
 * Takes a filename on the command line and parses it, displaying what it
 * finds. Intended for use in debugging the iCalendar parser's behavior with
 * problem files or for adding new features.
 *
 * @category Horde
 * @package  Icalendar
 */
require_once 'Horde/Cli.php';
require_once 'Horde/Icalendar.php';
// This only works on the command line.
if (!Horde_Cli::runningFromCLI()) {
    exit("Must be run from the command line\n");
}
// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.
$cli = Horde_Cli::init();
if (empty($argv[1])) {
    $cli->fatal('No file specified on the command line.');
}
$input_file = $argv[1];
if (!file_exists($input_file)) {
    $cli->fatal($input_file . ' does not exist.');
}
if (!is_readable($input_file)) {
    $cli->fatal($input_file . ' is not readable.');
}
$cli->writeln($cli->blue('Parsing ' . $input_file . ' ...'));
$data = file_get_contents($input_file);
$ical = new Horde_Icalendar();
if (!$ical->parseVCalendar($data)) {
    $cli->fatal('iCalendar parsing failed.');
Пример #5
0
 /**
  * Application bootstrap initialization.
  * Solves chicken-and-egg problem - need a way to init Horde environment
  * from application without an active Horde_Registry object.
  *
  * Page compression will be started (if configured).
  *
  * Global variables defined:
  * <pre>
  *   - $browser: Horde_Browser object
  *   - $cli: Horde_Cli object (if 'cli' is true)
  *   - $conf: Configuration array
  *   - $injector: Horde_Injector object
  *   - $language: Language
  *   - $notification: Horde_Notification object
  *   - $page_output: Horde_PageOutput object
  *   - $prefs: Horde_Prefs object
  *   - $registry: Horde_Registry object
  *   - $session: Horde_Session object
  * </pre>
  *
  * @param string $app  The application to initialize.
  * @param array $args  Optional arguments:
  * <pre>
  *   - admin: (boolean) Require authenticated user to be an admin?
  *            DEFAULT: false
  *   - authentication: (string) The type of authentication to use:
  *     - none: Do not authenticate
  *     - fallback: Attempt to authenticate; if failure, then don't auth
  *                 (@since 2.11.0).
  *     - [DEFAULT]: Authenticate; on no auth redirect to login screen
  *   - cli: (boolean) Initialize a CLI interface. Setting this to true
  *          implicitly sets 'authentication' to 'none' and 'admin' and
  *          'nocompress' to true.
  *          DEFAULT: false
  *   - nocompress: (boolean) If set, the page will not be compressed.
  *                 DEFAULT: false
  *   - nologintasks: (boolean) If set, don't perform logintasks (never
  *                   performed if authentication is 'none').
  *                   DEFAULT: false
  *   - nonotificationinit: (boolean) If set, don't initialize the
  *                         application handlers for the notification
  *                         system (@since 2.12.0).
  *   - permission: (array) The permission required by the user to access
  *                 the page. The first element (REQUIRED) is the permission
  *                 name. The second element (OPTION; defaults to SHOW) is
  *                 the permission level.
  *   - session_cache_limiter: (string) Use this value for the session
  *                            cache limiter.
  *                            DEFAULT: Uses the value in the config.
  *   - session_control: (string) Special session control limitations:
  *     - netscape: TODO; start read/write session
  *     - none: Do not start a session
  *     - readonly: Start session readonly
  *     - [DEFAULT] - Start read/write session
  *   - test: (boolean) Is this the test script? If so, we relax several
  *           sanity checks and don't load things from the cache.
  *           DEFAULT: false
  *   - timezone: (boolean) Set the time zone?
  *               DEFAULT: false
  *   - user_admin: (boolean) Set authentication to an admin user?
  *                 DEFAULT: false
  * </pre>
  *
  * @return Horde_Registry_Application  The application object.
  * @throws Horde_Exception
  */
 public static function appInit($app, array $args = array())
 {
     if (isset($GLOBALS['registry'])) {
         return $GLOBALS['registry']->getApiInstance($app, 'application');
     }
     $args = array_merge(array('admin' => false, 'authentication' => null, 'cli' => null, 'nocompress' => false, 'nologintasks' => false, 'nonotificationinit' => false, 'permission' => false, 'session_cache_limiter' => null, 'session_control' => null, 'timezone' => false, 'user_admin' => null), $args);
     /* CLI initialization. */
     if ($args['cli']) {
         /* Make sure no one runs from the web. */
         if (!Horde_Cli::runningFromCLI()) {
             throw new Horde_Exception(Horde_Core_Translation::t("Script must be run from the command line"));
         }
         /* Load the CLI environment - make sure there's no time limit,
          * init some variables, etc. */
         $GLOBALS['cli'] = Horde_Cli::init();
         $args['nocompress'] = true;
         $args['authentication'] = 'none';
     }
     // For 'fallback' authentication, try authentication first.
     if ($args['authentication'] === 'fallback') {
         $fallback_auth = true;
         $args['authentication'] = null;
     } else {
         $fallback_auth = false;
     }
     // Registry.
     $s_ctrl = 0;
     switch ($args['session_control']) {
         case 'netscape':
             // Chicken/egg: Browser object doesn't exist yet.
             // Can't use Horde_Core_Browser since it depends on registry to be
             // configured.
             $browser = new Horde_Browser();
             if ($browser->isBrowser('mozilla')) {
                 $args['session_cache_limiter'] = 'private, must-revalidate';
             }
             break;
         case 'none':
             $s_ctrl = self::SESSION_NONE;
             break;
         case 'readonly':
             $s_ctrl = self::SESSION_READONLY;
             break;
     }
     $classname = __CLASS__;
     $registry = $GLOBALS['registry'] = new $classname($s_ctrl, $args);
     $registry->initialApp = $app;
     $appob = $registry->getApiInstance($app, 'application');
     $appob->initParams = $args;
     do {
         try {
             $registry->pushApp($app, array('check_perms' => $args['authentication'] != 'none', 'logintasks' => !$args['nologintasks'], 'notransparent' => !empty($args['notransparent'])));
             if ($args['admin'] && !$registry->isAdmin()) {
                 throw new Horde_Exception(Horde_Core_Translation::t("Not an admin"));
             }
             $e = null;
         } catch (Horde_Exception_PushApp $e) {
             if ($fallback_auth) {
                 $registry->authException = $e;
                 $registry->setAuthenticationSetting('none');
                 $args['authentication'] = 'none';
                 $fallback_auth = false;
                 continue;
             }
         }
         break;
     } while (true);
     if (!is_null($e)) {
         $appob->appInitFailure($e);
         switch ($e->getCode()) {
             case self::AUTH_FAILURE:
                 $failure = new Horde_Exception_AuthenticationFailure($e->getMessage());
                 $failure->application = $app;
                 throw $failure;
             case self::NOT_ACTIVE:
                 /* Try redirect to Horde if an app is not active. */
                 if (!$args['cli'] && $app != 'horde') {
                     $GLOBALS['notification']->push($e, 'horde.error');
                     Horde::url($registry->getInitialPage('horde'))->redirect();
                 }
                 /* Shouldn't reach here, but fall back to permission denied
                  * error if we can't even access Horde. */
                 // Fall-through
             /* Shouldn't reach here, but fall back to permission denied
              * error if we can't even access Horde. */
             // Fall-through
             case self::PERMISSION_DENIED:
                 $failure = new Horde_Exception_AuthenticationFailure($e->getMessage(), Horde_Auth::REASON_MESSAGE);
                 $failure->application = $app;
                 throw $failure;
         }
         throw $e;
     }
     if ($args['timezone']) {
         $registry->setTimeZone();
     }
     if (!$args['nocompress']) {
         $GLOBALS['page_output']->startCompression();
     }
     if ($args['user_admin']) {
         if (empty($GLOBALS['conf']['auth']['admins'])) {
             throw new Horde_Exception(Horde_Core_Translation::t("Admin authentication requested, but no admin users defined in configuration."));
         }
         $registry->setAuth(reset($GLOBALS['conf']['auth']['admins']), array(), array('no_convert' => true));
     }
     if ($args['permission']) {
         $admin_opts = array('permission' => $args['permission'][0], 'permlevel' => isset($args['permission'][1]) ? $args['permission'][1] : Horde_Perms::SHOW);
         if (!$registry->isAdmin($admin_opts)) {
             throw new Horde_Exception_PermissionDenied(Horde_Core_Translation::t("Permission denied."));
         }
     }
     return $appob;
 }
Пример #6
0
 /**
  * Constructor.
  *
  * @param ReflectionMethod $method  The PHP method to introspect.
  */
 public function __construct(ReflectionFunction $method)
 {
     $this->_cli = Horde_Cli::init();
     parent::__construct($method);
 }
Пример #7
0
#!/usr/bin/env php
<?php 
/**
 * This script will check the user table and create any mail directories on the
 * system for any new users. A cron job can be set up to run this periodically.
 */
require_once __DIR__ . '/../lib/Application.php';
$vilma = Horde_Registry::appInit('vilma', array('authentication' => 'none'));
// Make sure no one runs this from the web.
if (!Horde_Cli::runningFromCLI()) {
    exit("Must be run from the command line\n");
}
// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.
Horde_Cli::init();
foreach ($vilma->driver->getAllUsers() as $domain => $users) {
    foreach ($users as $user) {
        /* Check for user's home dir. */
        if (!file_exists($user['user_home_dir'])) {
            /* Try to make the user_home_dir, if false skip. */
            if (!mkdir($user['user_home_dir'])) {
                continue;
            }
        }
        /* Check for the domain's dir. */
        $domain_dir = $user['user_home_dir'] . '/' . $domain;
        if (!file_exists($domain_dir)) {
            /* Try to make the user_home_dir, if false skip. */
            if (!mkdir($domain_dir)) {
                continue;
            }