Author Topic: GlobalAddressBoook - config.inc.php file isn't loaded  (Read 6705 times)

Offline wsnet

  • Newbie
  • *
  • Posts: 3
GlobalAddressBoook - config.inc.php file isn't loaded
« on: September 02, 2013, 05:42:49 AM »
Hi, I had problems with plugin GlobalAddressBoook.

My log error:

PHP Error: Failed to load config from /usr/local/www/roundcube/plugins/globaladdressbook/config.inc.php in /usr/local/www/roundcube/program/lib/Roundcube/rcube_plugin.php on line 121




1. plugins/globaladdressbook/config.inc.php

<?php

/**
 * GlobalAddressbook configuration file
 */

// the name of the dummy user which holds the global address book, if the user does not exist it will be created
// the name can contain the following macros that will be expanded as follows:
//      %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
//      %h is replaced with the imap host (from the session info)
// eg. to create one global address book per domain: global_addressbook@%d
$config['globaladdressbook_user'] = '[global_addressbook_user]';

// make global address book read only
$config['globaladdressbook_readonly'] = true;

// allow groups in global address book
$config['globaladdressbook_groups'] = false;

// global address book admin user
// admin user(s) can always add/edit/delete entries, overrides readonly
// either a single username, an array of usernames, or a regular expression, see README for more info
$config['globaladdressbook_admin'] = null;

// show addresses from the global address book in the auto complete menu when composing an email
$config['globaladdressbook_autocomplete'] = true;

// check globaladdressbook for known senders when displaying remote inline images
$config['globaladdressbook_check_safe'] = true;

?>

2. plugins/globaladdressbook/globaladdressbook.php

<?php

/**
 * GlobalAddressbook
 *
 * Plugin to add a global address book
 *
 * @version @package_version@
 * @author Philip Weir
 */
class globaladdressbook extends rcube_plugin
{
   public $task = 'mail|addressbook|settings|dummy';
   private $abook_id = 'global';
   private $readonly;
   private $groups;
   private $name;
   private $user_id;
   private $user_name;
   private $host = 'localhost';

   public function init()
   {
      $rcmail = rcube::get_instance();
      $this->load_config();
      $this->add_texts('localization/');

      $this->user_name = $rcmail->config->get('globaladdressbook_user');
      $this->user_name = str_replace('%d', $rcmail->user->get_username('domain'), $this->user_name);
      $this->user_name = str_replace('%h', $_SESSION['storage_host'], $this->user_name);
      $this->readonly = $this->_is_readonly();
      $this->groups = $rcmail->config->get('globaladdressbook_groups', false);
      $this->name = $this->gettext('globaladdressbook');

      // email2user hook can be used by other plugins to do post processing on usernames, not just virtual user lookup
      // matches process of user lookup and creation in the core
      if (strpos($this->user_name, '@') && ($virtuser = rcube_user::email2user($this->user_name))) {
         $this->user_name = $virtuser;
      }

      // check if the global address book user exists
      if (!($user = rcube_user::query($this->user_name, $this->host))) {
         // this action overrides the current user information so make a copy and then restore it
         $cur_user = $rcmail->user;
         $user = rcube_user::create($this->user_name, $this->host);
         $rcmail->user = $cur_user;

         // prevent new_user_dialog plugin from triggering
         $_SESSION['plugin.newuserdialog'] = false;
      }

      $this->user_id = $user->ID;

      // use this address book for autocompletion queries
      if ($rcmail->config->get('globaladdressbook_autocomplete')) {
         $sources = $rcmail->config->get('autocomplete_addressbooks', array('sql'));
         if (!in_array($this->abook_id, $sources)) {
            $sources[] = $this->abook_id;
            $rcmail->config->set('autocomplete_addressbooks', $sources);
         }
      }

      $this->add_hook('addressbooks_list', array($this, 'address_sources'));
      $this->add_hook('addressbook_get', array($this, 'get_address_book'));

      if ($rcmail->config->get('globaladdressbook_check_safe'))
         $this->add_hook('message_check_safe', array($this, 'check_known_senders'));
   }

   public function address_sources($args)
   {
      $args['sources'][$this->abook_id] = array('id' => $this->abook_id, 'name' => $this->name, 'readonly' => $this->readonly, 'groups' => $this->groups);
      return $args;
   }

   public function get_address_book($args)
   {
      if ($args['id'] === $this->abook_id) {
         $args['instance'] = new rcube_contacts(rcube::get_instance()->db, $this->user_id);
         $args['instance']->readonly = $this->readonly;
         $args['instance']->groups = $this->groups;
         $args['instance']->name = $this->name;
      }

      return $args;
   }

   public function check_known_senders($args)
   {
      // don't bother checking if the message is already marked as safe
      if ($args['message']->is_safe)
         return;

      $contacts = rcube::get_instance()->get_address_book($this->abook_id);
      if ($contacts) {
         $result = $contacts->search('email', $args['message']->sender['mailto'], 1, false);
         if ($result->count) {
            $args['message']->set_safe(true);
         }
      }

      return $args;
   }

   private function _is_readonly()
   {
      $rcmail = rcube::get_instance();

      if (!$rcmail->config->get('globaladdressbook_readonly'))
         return false;

      if ($admin = $rcmail->config->get('globaladdressbook_admin')) {
         if (!is_array($admin)) $admin = array($admin);

         foreach ($admin as $user) {
            if (strpos($user, '/') == 0 && substr($user, -1) == '/') {
               if (preg_match($user, $_SESSION['username']))
                  return false;
            }
            elseif ($user == $_SESSION['username'])
               return false;
         }
      }

      return true;
   }
}

?>

3. config/main.inc.php

<?php


// PLUGINS
// ----------------------------------

// List of active plugins (in plugins/ directory)
$rcmail_config['plugins'] = array('globaladdressbook');


4. File rcube_plugin.php Line 121

/**
     * Load local config file from plugins directory.
     * The loaded values are patched over the global configuration.
     *
     * @param string $fname Config file name relative to the plugin's folder
     *
     * @return boolean True on success, false on failure
     */
    public function load_config($fname = 'config.inc.php')
    {
        $fpath = $this->home.'/'.$fname;
        $rcube = rcube::get_instance();

        if (is_file($fpath) && !$rcube->config->load_from_file($fpath)) {
            rcube::raise_error(array(
                'code' => 527, 'type' => 'php',
                'file' => __FILE__, 'line' => __LINE__,
                'message' => "Failed to load config from $fpath"), true, false);
            return false;
        }

        return true;
    }


Why plugins config.inc.php file isn't loaded ?
« Last Edit: September 02, 2013, 05:47:17 AM by wsnet »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,330
Re: GlobalAddressBoook - config.inc.php file isn't loaded
« Reply #1 on: September 03, 2013, 01:04:44 PM »
Hi,

I dont know what version of roundcube you are using but it does not look like git-master so you cannot use the git-master version of this plugin. please go here https://github.com/JohnDoh/Roundcube-Plugin-Global-Address-Book/releases and download the version with a tag that matches you rc version.

as for the config file error... please double check there are no typos in the file name and that you did actuall rename it from config.php.dist to config.php. Also you should check the permissions on the config file, make sure the webserver can actually read it.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline kasiel

  • Newbie
  • *
  • Posts: 2
Re: GlobalAddressBoook - config.inc.php file isn't loaded
« Reply #2 on: September 03, 2013, 09:24:35 PM »
I had same problem with config.inc.php
so i compared another version of globaladdressbook  and found some syntax wrong
try to change only one variable name.

ex) $config['globaladdressbook_user'] = '[global_addressbook_user]'; -> $rcmail_config['globaladdressbook_user'] = '[global_addressbook_user]';
in config.inc.php

it works!!
and i'm korean so my first language is not english . sorry for broken english...

Offline wsnet

  • Newbie
  • *
  • Posts: 3
Re: GlobalAddressBoook - config.inc.php file isn't loaded
« Reply #3 on: September 04, 2013, 07:00:43 AM »
Hi,

I dont know what version of roundcube you are using but it does not look like git-master so you cannot use the git-master version of this plugin. please go here https://github.com/JohnDoh/Roundcube-Plugin-Global-Address-Book/releases and download the version with a tag that matches you rc version.

as for the config file error... please double check there are no typos in the file name and that you did actuall rename it from config.php.dist to config.php. Also you should check the permissions on the config file, make sure the webserver can actually read it.

Hi JohnDoh!

I use version Rouncube 0.9.2 and OS FreeBSD 9.1 x32 with Communigate Server 6.0
Yes, the rights are appointed correctly and file rename in from config.php.dist to config.php

Hi kasiel!
What version is used by you?

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,330
Re: GlobalAddressBoook - config.inc.php file isn't loaded
« Reply #4 on: September 04, 2013, 03:29:46 PM »
Did you use the link I posted to replace the version on the plugin you have with the one tagged for 0.9.2?
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline kasiel

  • Newbie
  • *
  • Posts: 2
Re: GlobalAddressBoook - config.inc.php file isn't loaded
« Reply #5 on: September 04, 2013, 08:35:44 PM »
Hi,

I dont know what version of roundcube you are using but it does not look like git-master so you cannot use the git-master version of this plugin. please go here https://github.com/JohnDoh/Roundcube-Plugin-Global-Address-Book/releases and download the version with a tag that matches you rc version.

as for the config file error... please double check there are no typos in the file name and that you did actuall rename it from config.php.dist to config.php. Also you should check the permissions on the config file, make sure the webserver can actually read it.

Hi JohnDoh!

I use version Rouncube 0.9.2 and OS FreeBSD 9.1 x32 with Communigate Server 6.0
Yes, the rights are appointed correctly and file rename in from config.php.dist to config.php

Hi kasiel!
What version is used by you?

I use version RD 0.9.3 and Windows 2008 R2 with iis7.5 .
if change name of config.inc.php->config.php. there is not error message because RD load default config file name. config.inc.php.

just try $config-> $rcmail_config.

Offline wsnet

  • Newbie
  • *
  • Posts: 3
Re: GlobalAddressBoook - config.inc.php file isn't loaded
« Reply #6 on: September 04, 2013, 11:36:11 PM »
JohnDoh sorry for my english language, I from Russia.

You suggest to replace $config-> $rcmail_config in file config.inc.php?


kasiel, thanks.