Beispiel #1
0
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * URL parameters used by this function:
  *   - zip_contents: (integer) If set, show contents of ZIP file.
  *
  * @return array  See Horde_Mime_Viewer_Driver::render().
  */
 protected function _renderInfo()
 {
     global $injector;
     $vars = $injector->getInstance('Horde_Variables');
     if (!$this->getConfigParam('show_contents') && !$vars->zip_contents) {
         $status = new IMP_Mime_Status($this->_mimepart, _("This is a compressed file."));
         $status->addMimeAction('zipViewContents', _("Click to display the file contents."));
         $status->icon('mime/compressed.png');
         return array($this->_mimepart->getMimeId() => array('data' => '', 'status' => $status, 'type' => 'text/html; charset=UTF-8'));
     }
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/mime'));
     $view->addHelper('Text');
     $view->downloadclass = 'zipdownload';
     $view->files = array();
     $view->tableclass = 'zipcontents';
     $zlib = Horde_Util::extensionExists('zlib');
     foreach ($this->_getZipInfo() as $key => $val) {
         $file = new stdClass();
         $file->name = $val['name'];
         $file->size = IMP::sizeFormat($val['size']);
         /* TODO: Add ability to render in-browser for filetypes we can
          *       handle. */
         if (!empty($val['size']) && strstr($val['attr'], 'D') === false && ($zlib && $val['method'] == 0x8 || $val['method'] == 0x0)) {
             $file->download = $this->getConfigParam('imp_contents')->linkView($this->_mimepart, 'download_render', '', array('class' => 'iconImg downloadAtc', 'jstext' => _("Download"), 'params' => array('zip_attachment' => $key)));
         } else {
             $file->download = '';
         }
         $view->files[] = $file;
     }
     return array($this->_mimepart->getMimeId() => array('data' => $view->render('compressed'), 'type' => 'text/html; charset=UTF-8'));
 }
Beispiel #2
0
 /**
  * Constructor.
  *
  * @param array $params  Optional parameters:
  * <pre>
  * 'hostspec' - (string) The hostname or IP address of the FTP server.
  *              DEFAULT: 'localhost'
  * 'port' - (integer) The server port to connect to.
  *          DEFAULT: 21
  * </pre>
  *
  * @throws Horde_Auth_Exception
  */
 public function __construct(array $params = array())
 {
     if (!Horde_Util::extensionExists('ftp')) {
         throw new Horde_Auth_Exception(__CLASS__ . ': Required FTP extension not found. Compile PHP with the --enable-ftp switch.');
     }
     $params = array_merge(array('hostspec' => 'localhost', 'port' => 21), $params);
     parent::__construct($params);
 }
Beispiel #3
0
 /**
  * Constructs a new Turba LDAP driver object.
  *
  * @param string $name   The source name
  * @param array $params  Hash containing additional configuration parameters.
  *
  * @return Turba_Driver_Ldap
  */
 public function __construct($name = '', array $params = array())
 {
     if (!Horde_Util::extensionExists('ldap')) {
         throw new Turba_Exception(_("LDAP support is required but the LDAP module is not available or not loaded."));
     }
     $params = array_merge(array('charset' => '', 'deref' => LDAP_DEREF_NEVER, 'multiple_entry_separator' => ', ', 'port' => 389, 'root' => '', 'scope' => 'sub', 'server' => 'localhost'), $params);
     parent::__construct($name, $params);
 }
Beispiel #4
0
 /**
  * Constructor.
  *
  * @throws Ingo_Exception
  */
 public function __construct(array $params = array())
 {
     if (!Horde_Util::extensionExists('ldap')) {
         throw new Ingo_Exception(_("LDAP support is required but the LDAP module is not available or not loaded."));
     }
     $default_params = array('hostspec' => 'localhost', 'port' => 389, 'script_attribute' => 'mailSieveRuleSource');
     parent::__construct(array_merge($default_params, $params));
 }
Beispiel #5
0
 /**
  * Constructor.
  *
  * @param array $params  Optional parameters:
  * <pre>
  * 'app' - (string) The name of the authenticating application.
  *         DEFAULT: horde
  * 'service' - (string) The name of the SASL service to use when
  *             authenticating.
  *             DEFAULT: php
  * </pre>
  *
  * @throws Horde_Auth_Exception
  */
 public function __construct(array $params = array())
 {
     if (!Horde_Util::extensionExists('sasl')) {
         throw new Horde_Auth_Exception('Horde_Auth_Peclsasl:: requires the sasl PECL extension to be loaded.');
     }
     $params = array_merge(array('app' => 'horde', 'service' => 'php'), $params);
     parent::__construct($params);
     sasl_server_init($this->_params['app']);
 }
Beispiel #6
0
 /**
  * The function to use as a callback to _toHTML().
  *
  * @param integer $key  The position of the file in the zip archive.
  * @param array $val    The information array for the archived file.
  *
  * @return string  The content-type of the output.
  */
 protected function _whupsCallback($key, $val)
 {
     $name = preg_replace('/(&nbsp;)+$/', '', $val['name']);
     if (!empty($val['size']) && strstr($val['attr'], 'D') === false && ($val['method'] == 0x8 && Horde_Util::extensionExists('zlib') || $val['method'] == 0x0)) {
         $mime_part = $this->_mimepart;
         $mime_part->setName(basename($name));
         $val['name'] = str_replace($name, Horde::url('view.php')->add(array('actionID' => 'view_file', 'type' => Horde_Util::getFormData('type'), 'file' => Horde_Util::getFormData('file'), 'ticket' => Horde_Util::getFormData('ticket'), 'zip_attachment' => $key + 1))->link() . $name . '</a>', $val['name']);
     }
     return $val;
 }
Beispiel #7
0
 /**
  * The function to use as a callback to _renderInfo().
  *
  * @param integer $key  The position of the file in the zip archive.
  * @param array $val    The information array for the archived file.
  *
  * @return string  The content-type of the output.
  */
 protected function _IMPcallback($key, $val)
 {
     $name = preg_replace('/(&nbsp;)+$/', '', $val['name']);
     if (!empty($val['size']) && strstr($val['attr'], 'D') === false && ($val['method'] == 0x8 && Horde_Util::extensionExists('zlib') || $val['method'] == 0x0)) {
         $mime_part = clone $this->_mimepart;
         $mime_part->setName(basename($name));
         $val['name'] = str_replace($name, $this->getConfigParam('imp_contents')->linkView($mime_part, 'download_render', $name, array('jstext' => sprintf(_("View %s"), str_replace('&nbsp;', ' ', $name)), 'class' => 'fixed', 'params' => array('zip_attachment' => urlencode($key) + 1))), $val['name']);
     }
     return $val;
 }
Beispiel #8
0
 /**
  * Constructor.
  *
  * @param array $params  Optional parameters:
  * <pre>
  * 'service' - (string) The name of the PAM service to use when
  *             authenticating.
  *             DEFAULT: php
  * </pre>
  *
  * @throws Horde_Auth_Exception
  */
 public function __construct(array $params = array())
 {
     if (!Horde_Util::extensionExists('pam')) {
         throw new Horde_Auth_Exception('PAM authentication is not available.');
     }
     if (!empty($params['service'])) {
         ini_set('pam.servicename', $params['service']);
     }
     parent::__construct($params);
 }
Beispiel #9
0
 /**
  * Returns the user account from the posix information.
  *
  * @return array  A hash with complete account details.
  *
  * @throws Horde_Exception if posix extension is missing.
  */
 protected function _getAccount()
 {
     if (!isset($this->_information)) {
         // This won't work if we don't have posix extensions.
         if (!Horde_Util::extensionExists('posix')) {
             throw new Horde_Exception(_("POSIX extension is missing"));
         }
         $user = Horde_String::lower($this->getUsername());
         $this->_information = posix_getpwnam($user);
     }
     return $this->_information;
 }
Beispiel #10
0
 /**
  * Constructor.
  *
  * @param array $params  Parameters:
  * <pre>
  * 'domain' - (string) [REQUIRED] The domain name to authenticate with.
  * 'group' - Group name that the user must be a member of.
  *           DEFAULT: none
  * 'hostspec' - (string) [REQUIRED] IP, DNS Name, or NetBios name of the
  *              SMB server to authenticate with.
  * </pre>
  *
  * @throws Horde_Auth_Exception
  * @throws InvalidArgumentException
  */
 public function __construct(array $params = array())
 {
     if (!Horde_Util::extensionExists('smbauth')) {
         throw new Horde_Auth_Exception(__CLASS__ . ': Required smbauth extension not found.');
     }
     foreach (array('domain', 'hostspec') as $val) {
         if (empty($params[$val])) {
             throw new InvalidArgumentException('Missing ' . $val . ' parameter.');
         }
     }
     $params = array_merge(array('group' => null), $params);
     parent::__construct($params);
 }
Beispiel #11
0
 /**
  * Constructor.
  *
  * @param array $params  Connection parameters.
  * <pre>
  * 'host' - (string) [REQUIRED] The RADIUS host to use (IP address or
  *          fully qualified hostname).
  * 'method' - (string) [REQUIRED] The RADIUS method to use for validating
  *            the request.
  *            Either: 'PAP', 'CHAP_MD5', 'MSCHAPv1', or 'MSCHAPv2'.
  *            ** CURRENTLY, only 'PAP' is supported. **
  * 'nas' - (string) The RADIUS NAS identifier to use.
  *         DEFAULT: The value of $_SERVER['HTTP_HOST'] or, if not
  *                  defined, then 'localhost'.
  * 'port' - (integer) The port to use on the RADIUS server.
  *          DEFAULT: Whatever the local system identifies as the
  *                   'radius' UDP port
  * 'retries' - (integer) The maximum number of repeated requests to make
  *             before giving up.
  *             DEFAULT: 3
  * 'secret' - (string) [REQUIRED] The RADIUS shared secret string for the
  *            host. The RADIUS protocol ignores all but the leading 128
  *            bytes of the shared secret.
  * 'suffix' - (string) The domain name to add to unqualified user names.
  *             DEFAULT: NONE
  * 'timeout' - (integer) The timeout for receiving replies from the server
  *             (in seconds).
  *             DEFAULT: 3
  * </pre>
  *
  * @throws InvalidArgumentException
  */
 public function __construct(array $params = array())
 {
     if (!Horde_Util::extensionExists('radius')) {
         throw new Horde_Auth_Exception(__CLASS__ . ': requires the radius PECL extension to be loaded.');
     }
     foreach (array('host', 'secret', 'method') as $val) {
         if (!isset($params[$val])) {
             throw new InvalidArgumentException('Missing ' . $val . ' parameter.');
         }
     }
     $params = array_merge(array('nas' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost', 'port' => 0, 'retries' => 3, 'suffix' => '', 'timeout' => 3), $params);
     parent::__construct($params);
 }
Beispiel #12
0
 /**
  * Executes any code necessary after applying the filter patterns.
  *
  * @param string $text  The text after the filtering.
  *
  * @return string  The modified text.
  */
 public function postProcess($text)
 {
     if (!Horde_Util::extensionExists('tidy') || $this->_params['size'] !== false && strlen($text) > $this->_params['size']) {
         return $text;
     }
     $tidy_config = array('enclose-block-text' => true, 'hide-comments' => true, 'indent' => false, 'numeric-entities' => true, 'preserve-entities' => true, 'show-body-only' => !empty($this->_params['body_only']), 'tab-size' => 0, 'wrap' => 0);
     $tidy = new tidy();
     if (strtolower($this->_params['charset']) == 'us-ascii') {
         if ($tidy->parseString($text, $tidy_config, 'ascii')) {
             $tidy->cleanRepair();
             $text = $tidy->value;
         }
     } elseif ($tidy->parseString(Horde_String::convertCharset($text, $this->_params['charset'], 'UTF-8'), $tidy_config, 'utf8')) {
         $tidy->cleanRepair();
         $text = Horde_String::convertCharset($tidy->value, 'UTF-8', $this->_params['charset']);
     }
     return $text;
 }
Beispiel #13
0
 /**
  * Constructor.
  *
  * @param integer $source  The source of the XML help data, based on the
  *                         SOURCE_* constants.
  * @param string $data     The data source. If $source is RAW, this is
  *                         XML text. If $source is FILE, this is the XML
  *                         filename.
  * @param array $views     Include these views.
  *
  * @throws Exception
  * @throws Horde_Exception
  */
 public function __construct($source, $data, array $views = array())
 {
     if (!Horde_Util::extensionExists('dom')) {
         throw new Horde_Exception('DOM not available.');
     }
     $dom = new DOMDocument('1.0', 'UTF-8');
     switch ($source) {
         case self::SOURCE_RAW:
             $dom->loadXML($data);
             break;
         case self::SOURCE_FILE:
             if (!@is_file($data)) {
                 throw new Horde_Exception(Horde_Core_Translation::t("Help file not found."));
             }
             $dom->load($data);
             break;
     }
     /* Get list of active entries. */
     $this->_processXml($dom->getElementsByTagName('help')->item(0), $views);
 }
Beispiel #14
0
 /**
  * @return string  The uncompressed data.
  */
 public function decompress($data, array $params = array())
 {
     /* If gzip is not compiled into PHP, return now. */
     if (!Horde_Util::extensionExists('zlib')) {
         throw new Horde_Compress_Exception(Horde_Compress_Translation::t("This server can't uncompress gzip files."));
     }
     /* Gzipped File - decompress it first. */
     $position = 0;
     $info = @unpack('CCM/CFLG/VTime/CXFL/COS', substr($data, $position + 2));
     if (!$info) {
         throw new Horde_Compress_Exception(Horde_Compress_Translation::t("Unable to decompress data."));
     }
     $position += 10;
     if ($info['FLG'] & $this->_flags['FEXTRA']) {
         $XLEN = unpack('vLength', substr($data, $position + 0, 2));
         $XLEN = $XLEN['Length'];
         $position += $XLEN + 2;
     }
     if ($info['FLG'] & $this->_flags['FNAME']) {
         $filenamePos = strpos($data, "", $position);
         // Filename
         // substr($data, $position, $filenamePos - $position);
         $position = $filenamePos + 1;
     }
     if ($info['FLG'] & $this->_flags['FCOMMENT']) {
         $commentPos = strpos($data, "", $position);
         // Comment
         // substr($data, $position, $commentPos - $position);
         $position = $commentPos + 1;
     }
     if ($info['FLG'] & $this->_flags['FHCRC']) {
         $hcrc = unpack('vCRC', substr($data, $position + 0, 2));
         $hcrc = $hcrc['CRC'];
         $position += 2;
     }
     $result = @gzinflate(substr($data, $position, strlen($data) - $position));
     if (empty($result)) {
         throw new Horde_Compress_Exception(Horde_Compress_Translation::t("Unable to decompress data."));
     }
     return $result;
 }
Beispiel #15
0
 /**
  * Return the full rendered version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _render()
 {
     $has_xsl = Horde_Util::extensionExists('xsl');
     if ($has_xsl) {
         $tmpdir = Horde_Util::createTempDir(true) . '/';
     }
     $fnames = array('content.xml', 'styles.xml', 'meta.xml');
     $tags = array('text:p' => 'p', 'table:table' => 'table border="0" cellspacing="1" cellpadding="0" ', 'table:table-row' => 'tr bgcolor="#cccccc"', 'table:table-cell' => 'td', 'table:number-columns-spanned=' => 'colspan=');
     if (!$this->getConfigParam('zip')) {
         $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
     }
     $list = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST));
     foreach ($list as $key => $file) {
         if (in_array($file['name'], $fnames)) {
             $content = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $list, 'key' => $key));
             if ($has_xsl) {
                 file_put_contents($tmpdir . $file['name'], $content);
             } elseif ($file['name'] == 'content.xml') {
                 return array($this->_mimepart->getMimeId() => array('data' => str_replace(array_keys($tags), array_values($tags), $content), 'status' => array(), 'type' => 'text/html; charset=UTF-8'));
             }
         }
     }
     if (!$has_xsl) {
         return array();
     }
     $xslt = new XSLTProcessor();
     $xsl = new DOMDocument();
     $xsl->load(realpath(__DIR__ . '/Ooo/export/xhtml/opendoc2xhtml.xsl'));
     $xslt->importStylesheet($xsl);
     $xslt->setParameter('http://www.w3.org/1999/XSL/Transform', array('metaFileURL' => 'file://' . $tmpdir . 'meta.xml', 'stylesFileURL' => 'file://' . $tmpdir . 'styles.xml', 'java' => false));
     $xml = new DOMDocument();
     $xml->load(realpath($tmpdir . 'content.xml'));
     $result = $xslt->transformToXml($xml);
     if (!$result) {
         $result = libxml_get_last_error()->message;
     }
     return array($this->_mimepart->getMimeId() => array('data' => $result, 'status' => array(), 'type' => 'text/html; charset=UTF-8'));
 }
Beispiel #16
0
 /**
  * Get summary info for a MIME ID.
  *
  * @param string $id     The MIME ID.
  * @param integer $mask  A bitmask indicating what information to return:
  * <pre>
  * Always output:
  *   'type' = MIME type
  *
  * IMP_Contents::SUMMARY_BYTES
  *   Output: parts = 'bytes'
  *
  * IMP_Contents::SUMMARY_SIZE
  *   Output: parts = 'size'
  *
  * IMP_Contents::SUMMARY_ICON
  * IMP_Contents::SUMMARY_ICON_RAW
  *   Output: parts = 'icon'
  *
  * IMP_Contents::SUMMARY_DESCRIP
  *   Output: parts = 'description_raw'
  *
  * IMP_Contents::SUMMARY_DESCRIP_LINK
  *   Output: parts = 'description'
  *
  * IMP_Contents::SUMMARY_DOWNLOAD
  *   Output: parts = 'download', 'download_url'
  *
  * IMP_Contents::SUMMARY_DOWNLOAD_ZIP
  *   Output: parts = 'download_zip'
  *
  * IMP_Contents::SUMMARY_IMAGE_SAVE
  *   Output: parts = 'img_save'
  *
  * IMP_Contents::SUMMARY_PRINT
  * IMP_Contents::SUMMARY_PRINT_STUB
  *   Output: parts = 'print'
  *
  * IMP_Contents::SUMMARY_STRIP
  *   Output: parts = 'strip'
  * </pre>
  *
  * @return array  An array with the requested information.
  */
 public function getSummary($id, $mask = 0)
 {
     $autodetect_link = false;
     $download_zip = $mask & self::SUMMARY_DOWNLOAD_ZIP && Horde_Util::extensionExists('zlib');
     $param_array = array();
     $this->_buildMessage();
     $part = array('bytes' => null, 'download' => null, 'download_url' => null, 'download_zip' => null, 'id' => $id, 'img_save' => null, 'size' => null, 'strip' => null);
     $mime_part = $this->getMIMEPart($id, array('nocontents' => true));
     $mime_type = $mime_part->getType();
     /* If this is an attachment that has no specific MIME type info, see
      * if we can guess a rendering type. */
     if (in_array($mime_type, array('application/octet-stream', 'application/base64'))) {
         $mime_type = Horde_Mime_Magic::filenameToMIME($mime_part->getName());
         if ($mime_type == $mime_part->getType()) {
             $autodetect_link = true;
         } else {
             $mime_part = clone $mime_part;
             $mime_part->setType($mime_type);
             $param_array['ctype'] = $mime_type;
         }
     }
     $part['type'] = $mime_type;
     /* Is this part an attachment? */
     $is_atc = $this->isAttachment($mime_type);
     /* Get bytes/size information. */
     if ($mask & self::SUMMARY_BYTES || $download_zip || $mask & self::SUMMARY_SIZE) {
         $part['bytes'] = $size = $mime_part->getBytes();
         $part['size'] = $size > 1048576 ? sprintf(_("%s MB"), IMP::numberFormat($size / 1048576, 1)) : sprintf(_("%s KB"), max(round($size / 1024), 1));
     }
     /* Get part's icon. */
     if ($mask & self::SUMMARY_ICON || $mask & self::SUMMARY_ICON_RAW) {
         $part['icon'] = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->getIcon($mime_type);
         if ($mask & self::SUMMARY_ICON) {
             $part['icon'] = Horde_Themes_Image::tag($part['icon'], array('attr' => array('title' => $mime_type)));
         }
     } else {
         $part['icon'] = null;
     }
     /* Get part's description. */
     $description = $this->getPartName($mime_part, true);
     if ($mask & self::SUMMARY_DESCRIP_LINK) {
         if (($can_d = $this->canDisplay($mime_part, self::RENDER_FULL)) || $autodetect_link) {
             $part['description'] = $this->linkViewJS($mime_part, 'view_attach', htmlspecialchars($description), array('jstext' => sprintf(_("View %s"), $description), 'params' => array_filter(array_merge($param_array, array('autodetect' => !$can_d)))));
         } else {
             $part['description'] = htmlspecialchars($description);
         }
     }
     if ($mask & self::SUMMARY_DESCRIP) {
         $part['description_raw'] = $description;
     }
     /* Download column. */
     if ($mask & self::SUMMARY_DOWNLOAD && $is_atc && (is_null($part['bytes']) || $part['bytes'])) {
         $part['download'] = $this->linkView($mime_part, 'download_attach', '', array('class' => 'iconImg downloadAtc', 'jstext' => _("Download")));
         $part['download_url'] = $this->urlView($mime_part, 'download_attach');
     }
     /* Display the compressed download link only if size is greater
      * than 200 KB. */
     if ($is_atc && $download_zip && $part['bytes'] > 204800) {
         $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($mime_part, array('contents' => $this, 'type' => $mime_type));
         if (!$viewer->getMetadata('compressed')) {
             $part['download_zip'] = $this->linkView($mime_part, 'download_attach', null, array('class' => 'iconImg downloadZipAtc', 'jstext' => sprintf(_("Download %s in .zip Format"), $description), 'params' => array('zip' => 1)));
         }
     }
     /* Display the image save link if the required registry calls are
      * present. */
     if ($mask & self::SUMMARY_IMAGE_SAVE && $GLOBALS['registry']->hasMethod('images/selectGalleries') && $mime_part->getPrimaryType() == 'image') {
         $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'iconImg saveImgAtc', null, Horde::popupJs(IMP_Basic_Saveimage::url(), array('params' => array('muid' => strval($this->getIndicesOb()), 'id' => $id), 'height' => 200, 'width' => 450, 'urlencode' => true)) . 'return false;') . '</a>';
     }
     /* Add print link? */
     if (($mask & self::SUMMARY_PRINT || $mask & self::SUMMARY_PRINT_STUB) && $this->canDisplay($id, self::RENDER_FULL)) {
         $part['print'] = $mask & self::SUMMARY_PRINT ? $this->linkViewJS($mime_part, 'print_attach', '', array('css' => 'iconImg printAtc', 'jstext' => _("Print"), 'onload' => 'IMP_JS.printWindow', 'params' => $param_array)) : Horde::link('#', _("Print"), 'iconImg printAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
     }
     /* Strip Attachment? Allow stripping of base parts other than the
      * base multipart and the base text (body) part. */
     if ($mask & self::SUMMARY_STRIP && $id != 0 && intval($id) != 1 && strpos($id, '.') === false) {
         $part['strip'] = Horde::link(Horde::selfUrlParams()->add(array('actionID' => 'strip_attachment', 'imapid' => $id, 'muid' => strval($this->getIndicesOb()), 'token' => $GLOBALS['session']->getToken())), _("Strip Attachment"), 'iconImg deleteImg stripAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
     }
     return $part;
 }
Beispiel #17
0
 /**
  * Returns the country ID and Name for a given hostname.
  *
  * @param string $name  The hostname.
  *
  * @return mixed  An array with 'code' as the country code and 'name' as
  *                the country name, or false if not found.
  */
 public function getCountryInfo($name)
 {
     if (Horde_Util::extensionExists('geoip')) {
         $id = @geoip_country_code_by_name($name);
         $cname = @geoip_country_name_by_name($name);
         return !empty($id) && !empty($cname) ? array('code' => Horde_String::lower($id), 'name' => $cname) : false;
     }
     $id = $this->countryIdByName($name);
     if (!empty($id)) {
         $code = $this->_countryCodes[$id];
         return array('code' => Horde_String::lower($code), 'name' => $this->_getName($code));
     }
     return false;
 }
Beispiel #18
0
 /**
  * Attempts to open a connection to the LDAP server.
  *
  * @return boolean    True on success.
  * @throws Shout_Exception
  *
  * @access private
  */
 protected function _connect()
 {
     if ($this->_connected) {
         return;
     }
     if (!Horde_Util::extensionExists('ldap')) {
         throw new Shout_Exception('Required LDAP extension not found.');
     }
     Horde::assertDriverConfig($this->_params, $this->_params['class'], array('hostspec', 'basedn', 'writedn'));
     /* Open an unbound connection to the LDAP server */
     $conn = ldap_connect($this->_params['hostspec'], $this->_params['port']);
     if (!$conn) {
         Horde::log(sprintf('Failed to open an LDAP connection to %s.', $this->_params['hostspec']), 'ERR');
         throw new Shout_Exception('Internal LDAP error. Details have been logged for the administrator.');
     }
     /* Set hte LDAP protocol version. */
     if (isset($this->_params['version'])) {
         $result = ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, $this->_params['version']);
         if ($result === false) {
             Horde::log(sprintf('Set LDAP protocol version to %d failed: [%d] %s', $this->_params['version'], ldap_errno($conn), ldap_error($conn)), 'WARN');
             throw new Shout_Exception('Internal LDAP error. Details have been logged for the administrator.', ldap_errno($conn));
         }
     }
     /* Start TLS if we're using it. */
     if (!empty($this->_params['tls'])) {
         if (!@ldap_start_tls($conn)) {
             Horde::log(sprintf('STARTTLS failed: [%d] %s', @ldap_errno($this->_ds), @ldap_error($this->_ds)), 'ERR');
         }
     }
     /* If necessary, bind to the LDAP server as the user with search
      * permissions. */
     if (!empty($this->_params['searchdn'])) {
         $bind = ldap_bind($conn, $this->_params['searchdn'], $this->_params['searchpw']);
         if ($bind === false) {
             Horde::log(sprintf('Bind to server %s:%d with DN %s failed: [%d] %s', $this->_params['hostspec'], $this->_params['port'], $this->_params['searchdn'], @ldap_errno($conn), @ldap_error($conn)), 'ERR');
             throw new Shout_Exception('Internal LDAP error. Details have been logged for the administrator.', ldap_errno($conn));
         }
     }
     /* Store the connection handle at the instance level. */
     $this->_LDAP = $conn;
 }
Beispiel #19
0
 /**
  * Handle extracting images from uploaded zip files.
  *
  * @param string $filename  The local path to the zip file.
  *
  * @return array  An array of the resulting image_ids.
  * @throws Ansel_Exception
  */
 private function _handleZip($filename)
 {
     $image_ids = array();
     /* See if we can use the zip extension for reading the file. */
     if (Horde_Util::extensionExists('zip')) {
         $zip = new ZipArchive();
         if ($zip->open($filename) !== true) {
             throw new Ansel_Exception(_("Could not open zip archive."));
         }
         /* Iterate the archive */
         for ($z = 0; $z < $zip->numFiles; $z++) {
             $zinfo = $zip->statIndex($z);
             if ($this->_isMetaFile($zinfo['name'])) {
                 continue;
             }
             /* Extract the image */
             $stream = $zip->getStream($zinfo['name']);
             $zdata = stream_get_contents($stream);
             if (!strlen($zdata)) {
                 throw new Ansel_Exception(_("Could not extract image data from zip archive."));
             }
             /* Save the image */
             $image_id = $this->_gallery->addImage(array('image_filename' => $zinfo['name'], 'image_caption' => '', 'data' => $zdata));
             $image_ids[] = $image_id;
             unset($zdata);
         }
         $zip->close();
         unset($zip);
     } else {
         /* Receiving zip data, but extension not loaded */
         $data = file_get_contents($filename);
         /* Get list of images */
         try {
             $zip = Horde_Compress::factory('zip');
             $files = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
         } catch (Horde_Compress_Exception $e) {
             throw new Ansel_Exception($e);
             continue;
         }
         /* Iterate the archive */
         foreach ($files as $key => $zinfo) {
             if ($this->_isMetaFile($zinfo['name'])) {
                 continue;
             }
             /* Extract the image */
             try {
                 $zdata = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $files, 'key' => $key));
             } catch (Horde_Compress_Exception $e) {
                 throw new Ansel_Exception($e);
             }
             /* Add the image */
             $image_id = $this->_gallery->addImage(array('image_filename' => $zinfo['name'], 'image_caption' => '', 'data' => $zdata));
             $image_ids[] = $image_id;
             unset($zdata);
         }
         unset($zip);
         unset($data);
     }
     return $image_ids;
 }
Beispiel #20
0
 /**
  * Return whether PGP support is current enabled in IMP.
  *
  * @return boolean  True if PGP support is enabled.
  */
 public static function enabled()
 {
     global $conf, $prefs;
     return !empty($conf['openssl']['path']) && $prefs->getValue('use_smime') && Horde_Util::extensionExists('openssl');
 }
Beispiel #21
0
<?php

/**
 * Copyright 1999-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author Chuck Hagenbuch <*****@*****.**>
 * @category Horde
 * @license  http://www.horde.org/licenses/lgpl LGPL-2
 * @package  Horde
 */
require_once __DIR__ . '/../../lib/Application.php';
Horde_Registry::appInit('horde', array('permission' => array('horde:administration:configuration')));
if (!Horde_Util::extensionExists('domxml') && !Horde_Util::extensionExists('dom')) {
    throw new Horde_Exception('You need the domxml or dom PHP extension to use the configuration tool.');
}
$vars = $injector->getInstance('Horde_Variables');
$app = $vars->app;
$appname = $registry->get('name', $app);
$title = sprintf(_("%s Configuration"), $appname);
if (empty($app) || !in_array($app, $registry->listAllApps())) {
    $notification->push(_("Invalid application."), 'horde.error');
    Horde::url('admin/config/index.php', true)->redirect();
}
$form = new Horde_Config_Form($vars, $app);
$form->setButtons(sprintf(_("Generate %s Configuration"), $appname));
if (file_exists($registry->get('fileroot', $app) . '/config/conf.bak.php')) {
    $form->appendButtons(_("Revert Configuration"));
}
Beispiel #22
0
 /**
  * Check whether or not a serialization method is supported.
  *
  * @param integer $mode  The serialization method.
  *
  * @return boolean  True if supported, false if not.
  */
 public static function hasCapability($mode)
 {
     switch ($mode) {
         case self::BZIP:
             return Horde_Util::extensionExists('bz2');
         case self::WDDX:
             return Horde_Util::extensionExists('wddx');
         case self::IMAPUTF7:
             return class_exists('Horde_Imap_Client');
         case self::IMAP8:
         case self::IMAPUTF8:
             return class_exists('Horde_Mime');
         case self::GZ_DEFLATE:
         case self::GZ_COMPRESS:
         case self::GZ_ENCODE:
             return Horde_Util::extensionExists('zlib');
         case self::LZF:
             return Horde_Util::extensionExists('lzf');
         case self::NONE:
         case self::BASIC:
         case self::BASE64:
         case self::RAW:
         case self::URL:
         case self::UTF7:
         case self::UTF7_BASIC:
         case self::JSON:
             return true;
         default:
             return false;
     }
 }
Beispiel #23
0
 /**
  * Check for the presence of the OpenSSL extension to PHP.
  *
  * @throws Horde_Crypt_Exception
  */
 public function checkForOpenSSL()
 {
     if (!Horde_Util::extensionExists('openssl')) {
         throw new Horde_Crypt_Exception(Horde_Crypt_Translation::t("The openssl module is required for the Horde_Crypt_Smime:: class."));
     }
 }
Beispiel #24
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     if (!Horde_Util::extensionExists('openssl')) {
         throw new RuntimeException();
     }
 }
Beispiel #25
0
 /**
  * Return the body text of the original email from a smart request.
  *
  * @param array $body_data       The body data array of the source msg.
  * @param Horde_Mime_Part $part  The body mime part of the email to send.
  * @param boolean $html          Do we want an html body?
  * @param boolean $flow          Should the body be flowed?
  *
  * @return string  The properly formatted/flowed message body.
  */
 protected function _msgBody(array $body_data, Horde_Mime_Part $part, $html, $flow = false)
 {
     $subtype = $html == true ? 'html' : 'plain';
     $msg = Horde_String::convertCharset((string) $body_data[$subtype]['body'], $body_data[$subtype]['charset'], 'UTF-8');
     if (!$html) {
         if ($part->getContentTypeParameter('format') == 'flowed') {
             $flowed = new Horde_Text_Flowed($msg, 'UTF-8');
             if (Horde_String::lower($part->getContentTypeParameter('delsp')) == 'yes') {
                 $flowed->setDelSp(true);
             }
             $flowed->setMaxLength(0);
             $msg = $flowed->toFixed(false);
         } else {
             // If not flowed, remove padding at eol
             $msg = preg_replace("/\\s*\n/U", "\n", $msg);
         }
         if ($flow) {
             $flowed = new Horde_Text_Flowed($msg, 'UTF-8');
             $msg = $flowed->toFlowed(true);
         }
     } else {
         // This filter requires the tidy extenstion.
         if (Horde_Util::extensionExists('tidy')) {
             return Horde_Text_Filter::filter($msg, 'Cleanhtml', array('body_only' => true));
         } else {
             // If no tidy, use Horde_Dom.
             $dom = new Horde_Domhtml($msg, 'UTF-8');
             return $dom->returnBody();
         }
     }
     return $msg;
 }
Beispiel #26
0
 /**
  * Load application information from registry config files.
  */
 protected function _loadApplications()
 {
     global $cli, $injector;
     if (!empty($this->_interfaces)) {
         return;
     }
     /* First, try to load from cache. */
     if (!isset($cli) && !$this->isTest()) {
         if (Horde_Util::extensionExists('apc')) {
             $cstorage = 'Horde_Cache_Storage_Apc';
         } elseif (Horde_Util::extensionExists('xcache')) {
             $cstorage = 'Horde_Cache_Storage_Xcache';
         } else {
             $cstorage = 'Horde_Cache_Storage_File';
         }
         $cache = new Horde_Cache(new $cstorage(array('no_gc' => true, 'prefix' => 'horde_registry_cache_')), array('lifetime' => 0, 'logger' => $injector->getInstance('Horde_Log_Logger')));
         if (($cid = $this->_cacheId()) && ($cdata = $cache->get($cid, 0))) {
             try {
                 list($this->applications, $this->_interfaces) = $injector->getInstance('Horde_Pack')->unpack($cdata);
                 return;
             } catch (Horde_Pack_Exception $e) {
             }
         }
     }
     $config = new Horde_Registry_Registryconfig($this);
     $this->applications = $config->applications;
     $this->_interfaces = $config->interfaces;
     if (!isset($cache)) {
         return;
     }
     /* Need to determine hash of generated data, since it is possible that
      * there is dynamic data in the config files. This only needs to
      * be done once per session. */
     $packed_data = $injector->getInstance('Horde_Pack')->pack(array($this->applications, $this->_interfaces));
     $cid = $this->_cacheId($packed_data);
     if (!$cache->exists($cid, 0)) {
         $cache->set($cid, $packed_data);
     }
 }
Beispiel #27
0
 /**
  * Returns true if the every character in the parameter is an alphabetic
  * character.
  *
  * @param string $string   The string to test.
  * @param string $charset  The charset to use when testing the string.
  *
  * @return boolean  True if the parameter was alphabetic only.
  */
 public static function isAlpha($string, $charset)
 {
     if (!Horde_Util::extensionExists('mbstring')) {
         return ctype_alpha($string);
     }
     $charset = self::_mbstringCharset($charset);
     $old_charset = mb_regex_encoding();
     if ($charset != $old_charset) {
         @mb_regex_encoding($charset);
     }
     $alpha = !@mb_ereg_match('[^[:alpha:]]', $string);
     if ($charset != $old_charset) {
         @mb_regex_encoding($old_charset);
     }
     return $alpha;
 }
Beispiel #28
0
 /**
  * Attempt to determine the MIME type of an unknown byte stream.
  *
  * @param string $data      The file data to analyze.
  * @param string $magic_db  Path to the mime magic database.
  * @param array $opts       Additional options:
  *   - nostrip: (boolean) Don't strip parameter information from MIME
  *              type string.
  *              DEFAULT: false
  *
  * @return mixed  The MIME type of the file. Returns false if the file
  *                type can not be determined.
  */
 public static function analyzeData($data, $magic_db = null, $opts = array())
 {
     /* If the PHP Mimetype extension is available, use that. */
     if (Horde_Util::extensionExists('fileinfo')) {
         $res = empty($magic_db) ? @finfo_open(FILEINFO_MIME) : @finfo_open(FILEINFO_MIME, $magic_db);
         if (!$res) {
             return false;
         }
         $type = trim(finfo_buffer($res, $data));
         finfo_close($res);
         /* Remove any additional information. */
         if (empty($opts['nostrip'])) {
             if (($pos = strpos($type, ';')) !== false) {
                 $type = rtrim(substr($type, 0, $pos));
             }
             if (($pos = strpos($type, ',')) !== false) {
                 $type = rtrim(substr($type, 0, $pos));
             }
         }
         return $type;
     }
     return false;
 }
Beispiel #29
0
    return !isset($GLOBALS['conf']['gnupg']['path']);
});
// These preferences MUST appear on the same page.
$_prefs['pgpmanagement'] = array('value' => array('use_pgp', 'use_pgp_text', 'pgp_attach_pubkey', 'pgp_verify', 'pgp_reply_pubkey', 'pgppublickey', 'pgpprivatekey'), 'type' => 'container');
$_prefs['use_pgp'] = array('value' => 0, 'type' => 'checkbox', 'desc' => _("Enable PGP functionality?"), 'help' => 'pgp-overview');
$_prefs['use_pgp_text'] = array('value' => '<div class="prefsPgpWarning">' . _("PGP support requires popup windows to be used.  If your browser is currently set to disable popup windows, you must change this setting or else the PGP features will not work correctly.") . '</div>', 'type' => 'rawhtml', 'requires' => array('use_pgp'));
$_prefs['pgp_attach_pubkey'] = array('value' => 0, 'type' => 'checkbox', 'desc' => _("Should your PGP public key to be attached to your messages by default?"), 'help' => 'pgp-option-attach-pubkey', 'requires' => array('use_pgp'));
$_prefs['pgp_verify'] = array('value' => 1, 'type' => 'checkbox', 'desc' => _("Should PGP signed messages be automatically verified when viewed?"), 'help' => 'pgp-option-verify', 'requires' => array('use_pgp'));
$_prefs['pgp_reply_pubkey'] = array('value' => 1, 'advanced' => true, 'type' => 'checkbox', 'desc' => _("Check for valid recipient PGP public keys while replying?"), 'help' => 'pgp-option-reply-pubkey', 'requires' => array('use_pgp'));
$_prefs['pgppublickey'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_PgpPublicKey', 'requires' => array('use_pgp'));
$_prefs['pgp_public_key'] = array('value' => '');
$_prefs['pgpprivatekey'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_PgpPrivateKey', 'requires' => array('use_pgp'));
$_prefs['pgp_private_key'] = array('value' => '');
// *** S/MIME Preferences ***
$prefGroups['smime'] = array('column' => _("General"), 'label' => _("S/MIME"), 'desc' => _("Configure S/MIME encryption support."), 'members' => array('smimemanagement'), 'suppress' => function () {
    return !Horde_Util::extensionExists('openssl') || !isset($GLOBALS['conf']['openssl']['path']);
});
// These preferences MUST appear on the same page.
$_prefs['smimemanagement'] = array('value' => array('use_smime', 'use_smime_text', 'smime_verify', 'smimepublickey', 'smimeprivatekey'), 'type' => 'container');
$_prefs['use_smime'] = array('value' => 0, 'type' => 'checkbox', 'desc' => _("Enable S/MIME functionality?"), 'help' => 'smime-overview');
$_prefs['use_smime_text'] = array('value' => '<div class="prefsSmimeWarning">' . _("S/MIME support requires popup windows to be used.  If your browser is currently set to disable popup windows, you must change this setting or else the S/MIME features will not work correctly.") . '</div>', 'type' => 'rawhtml', 'requires' => array('use_smime'));
$_prefs['smime_verify'] = array('value' => 1, 'type' => 'checkbox', 'desc' => _("Should S/MIME signed messages be automatically verified when viewed?"), 'help' => 'smime-option-verify', 'requires' => array('use_smime'));
// S/MIME public keys management widget
$_prefs['smimepublickey'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_SmimePublicKey', 'requires' => array('use_smime'));
// S/MIME personal key management widget
$_prefs['smimeprivatekey'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_SmimePrivateKey', 'requires' => array('use_smime'));
$_prefs['smime_public_key'] = array('value' => '');
$_prefs['smime_public_sign_key'] = array('value' => '');
$_prefs['smime_private_key'] = array('value' => '');
$_prefs['smime_private_sign_key'] = array('value' => '');
$_prefs['smime_additional_cert'] = array('value' => '');
Beispiel #30
0
 /**
  * Returns the data for a specific archived file.
  *
  * @param string $data  The zip archive contents.
  * @param array $info   The information array from _getZipInfo().
  * @param integer $key  The position of the file in the archive.
  *
  * @return string  The file data.
  */
 protected function _getZipData($data, $info, $key)
 {
     if ($info[$key]['_method'] == 0x8 && Horde_Util::extensionExists('zlib')) {
         /* If the file has been deflated, and zlib is installed,
            then inflate the data again. */
         return @gzinflate(substr($data, $info[$key]['_dataStart'], $info[$key]['csize']));
     } elseif ($info[$key]['_method'] == 0x0) {
         /* Files that aren't compressed. */
         return substr($data, $info[$key]['_dataStart'], $info[$key]['csize']);
     }
     return '';
 }