Author Topic: plugins for rev1401 - ssl link on login form, courierpassd changepasswd....  (Read 9682 times)

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Here are a few plugins I have made from RC, updated to rev1401...

SSL Link on login form - adds a link below the login button to switch between secure and normal webserver. To change the SSL port or the format of the link edit [RC Root]/plugins/ssllink/config.inc.php.

Change Password (courierpassd) - there have been a lot of these around so I thought there was no harm in adding my one for courierpassd, thanks to the guys who made the Squirrelmain Plugin and the first RC change password plugin for getting me started. To alter the connection information for the courierpassd server edit [RC Root]/plugins/changepasswd/config.inc.php.

Preview mark as read - adds a user option to stop RC marking messages as read when viewing them in the preview pane, messages will still be marked as read when opened. This is really just to mimic an option available in MS Outlook. This patch needs to add a value to your main config file for the default setting of the option.

Various labels and messages are added to the RC en_US localisation files by these patches as this is the 'fallback' language. It should be simple to localise these features by adding the required text to the appropriate language files.

I have tried to make them as plugin like as possible, creating a 'plugin' directory in the RC root. Since there is no plugin API for RC yet some files still have to go in specific locations and some have to be patched. The attached patch files will create/patch all files as necessary. My hope is that I will be quite easy to turn these into fully fledged plugins once the API is available.

Finally these patches were generated against a fresh copy of rev1401 and I don’t guaranty they wont break anything, only that they work on my server.

ps. to apply the patches run
Code: [Select]
patch -ul -d /path/to/roundcube/ -p1 < /path/to/patch
« Last Edit: June 23, 2008, 12:41:25 PM by JohnDoh »
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
I have just started to code a plugin API. Here is my approach:

config/main.inc.php -> assign plugins array and bind API
Code: [Select]

// plugins
$rcmail_config['plugins'] = array();
$rcmail_config['plugins'][] = 'sign_up';

@include &quot;./program/include/api.inc&quot;;


program/include/rcube_html.inc ... insert just before ...
Code: [Select]

print rcube_charset_convert($output, 'UTF-8', $this->charset);


... this snippet ...
Code: [Select]

// pass to plugins API
$output = rcmail_api($output);


program/include/api.inc -> API
Code: [Select]


foreach($rcmail_config['plugins'] as $key => $plugin){
  // include customized plugin configuration
  if(file_exists("plugins/" . $plugin . "/config.inc")){
    @require_once("plugins/" . $plugin . "/config.inc");
  }
  // include default plugin configuration if there is no customized file
  else if(file_exists("plugins/" . $plugin . "/config.inc.dist")){
    @require_once("plugins/" . $plugin . "/config.inc.dist");
  }
}

function rcmail_api($input=""){

  if (($matches = preg_split('/]+)>/is', $input, null, PREG_SPLIT_DELIM_CAPTURE))){
 
    if(count($matches) == 1){
      return $input;
    }

    $output = $matches[0];

    $ii = 0;
    for($i=0;$i      $ii++;
     
      if($ii == 6){
        $ii = 0;
      }
      switch($ii){
        case '1':
          //ignore
          break;
        case '2':
          //ignore
          break;
        case '3':
          //plugin (name/function)
          $temparr = parse_attrib_string($matches[$i]);
          $temparr = explode(":",$temparr['name']);
          $plugin=$temparr[0];
          $function=$temparr[1];
          //$output .= do_hook($plugin, $function, $output);
          break;
        case '4':
          //pass default plugin content and trigger plugin functions
          $output .= do_hook($plugin, $function, $matches[$i]);
          break;
        case '5':
          //ignore
          break;
        case '6':
          //ignore
          break;        
     
      }    
    }

    $output .= $matches[$i-1];
    return $output;
  }
  else{

    return $input;
  }
}

function do_hook($plugin, $function, $input=""){

  global $CONFIG;
 
  if(in_array($plugin,$CONFIG['plugins'])){
    if(file_exists("plugins/" . $plugin . "/setup.inc")){
      @require_once("plugins/" . $plugin . "/setup.inc");
    }
    if(file_exists("plugins/" . $plugin . "/setup.inc")){
      @require_once("plugins/" . $plugin . "/functions.inc");
    }
   
    $exec = $plugin . "_" . $function;
    if(function_exists($exec)){
      $output = $exec($input);
    }
  }
  if(isset($output)){
    return $output;
  }
  else{
    return $input;
  }
}

?>


index.php -> trigger hook in not authenticated state
GET request "&_plugin=pluginname,hookfunction"
insert just behind ...
Code: [Select]

// error steps
if ($_action=='error' && !empty($_GET['_code']))
  raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);

... this snippet
Code: [Select]

// execute plugins in not authenticated state
$_plugin = explode(",",strip_quotes(get_input_value('_plugin', RCUBE_INPUT_GPC)));
if(!isset($_plugin[2])){
  do_hook($_plugin[0], $_plugin[1]);
}


index.php -> trigger hook in authenticated state
GET request "&_plugin=pluginname,hookfunction,auth"
insert just before ...
Code: [Select]

// parse main template
$OUTPUT->send($_task);


... this snippet
Code: [Select]

// execute plugin in authenticated state
if(isset($_plugin[2]) && $_plugin[2] == 'auth'){
  do_hook($_plugin[0], $_plugin[1]);
}


Plugins have to sit in "plugins" folder ...
File structure:
/plugins/pluginname/config.inc (contains $rcmail_config['somekey'] = true ...)
/plugins/pluginname/setup.inc (contains the hook functions: function pluginname_hookfunction($input=""){return $input}
/plugins/pluginname/functions.inc (contains helper functions)

Triggering a plugin function from the template:
Code: [Select]


... content passed as $input to hookfunction



Hope you understand ...

-Roland
« Last Edit: May 19, 2008, 02:51:13 PM by rosali »
Regards,
Rosali
__________________
MyRoundcube Project (commercial)

Offline stef1777

  • Newbie
  • *
  • Posts: 2
Hi!

If I patch 0.1.1 release with changepasswd.patch, I got:

patching file index.php
Hunk #1 FAILED at 275.
1 out of 1 hunk FAILED -- saving rejects to file index.php.rej
patching file plugins/changepasswd/changepasswd.inc
patching file plugins/changepasswd/config.inc.php
patching file plugins/changepasswd/func.inc
patching file plugins/changepasswd/save_changepasswd.inc
patching file plugins/telnet/telnet_client.inc
patching file program/js/app.js
Hunk #1 succeeded at 283 (offset 1 line).
Hunk #2 succeeded at 942 (offset 1 line).
patching file program/js/changepasswd.js
patching file program/localization/en_US/labels.inc
Hunk #1 succeeded at 243 (offset -41 lines).
patching file program/localization/en_US/messages.inc
patching file skins/default/includes/settingstabs.html
patching file skins/default/templates/changepasswd.html

In the GUI, I can see the new "Password tab" in Parameters but clic do nothing.

Cheers,

.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
sorry stef1777 these patches will not work for release 0.1.1. Alot has changed since then and the patches were created against a much newer version.

Roland: that looks interesting, I might try it on my system if i have some time. I think there was some plugin work done in the devel-vnext branch, is this based on that? Also have you considered localisation files?

May be I am taking it too far here, I'm not sure. I was trying to figure out if it was senesibe/resonable to have seperate localisation files for each plugin, rather then adding to the main ones and how that could be achieved. It's just something to think about.

JohnDoh
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
No, it is totally my own stuff. I will modify the api to support localization. There is another jump in in the source code necessary.

-Roland
« Last Edit: May 21, 2008, 02:02:57 PM by rosali »
Regards,
Rosali
__________________
MyRoundcube Project (commercial)

Offline nicolash

  • Newbie
  • *
  • Posts: 7
Hi JohnDoe,

Thanks for your changepassword patch.

I've tried to apply this patch to the latest svn version (1566), but it seems that already lots of things have changed:

Hunk #1 FAILED at 275.
1 out of 1 hunk FAILED -- saving rejects to file index.php.rej
patching file plugins/changepasswd/changepasswd.inc
patching file plugins/changepasswd/config.inc.php
patching file plugins/changepasswd/func.inc
patching file plugins/changepasswd/save_changepasswd.inc
patching file plugins/telnet/telnet_client.inc
patching file program/js/app.js
Hunk #2 succeeded at 948 (offset 7 lines).
patching file program/js/changepasswd.js
patching file program/localization/en_US/labels.inc
Hunk #1 succeeded at 286 (offset 2 lines).
patching file program/localization/en_US/messages.inc
Hunk #1 succeeded at 80 with fuzz 2 (offset 1 line).
patching file skins/default/includes/settingstabs.html
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file skins/default/includes/settingstabs.html.rej
patching file skins/default/templates/changepasswd.html

I've change myself index.php and settingstab.html in order to apply manually the patch, I can now see the changepassword tab in the settings, but it doesn't work.

Any chance you update your patch for the latest svn version?

P.S.: my contribution to your patch, here are labels & messages for french :-)
$labels['changepasswd'] = 'Mot de passe';
$labels['curpasswd'] = 'Mot de passe actuel';
$labels['newpasswd'] = 'Nouveau mot de passe';
$labels['confpasswd'] = 'Confirmer nouveau mot de passe';
$messages['nocurpassword'] = 'Merci de renseigner le mot de passe actuel';
$messages['nopassword'] = 'Merci de renseigner le nouveau mot de passe';
$messages['passwordinconsistency'] = 'Le nouveau mot de passe et sa confirmation ne correspondent pas';
$messages['passwordfailed'] = 'Le mot de passe original semble inexact';
$messages['passwordchanged'] = 'Le mot de passe a bien été modifie';

Many thanks!
Nicolas
« Last Edit: June 21, 2008, 09:29:09 AM by nicolash »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Hi nicolash.

I have updated the changepasswd patch file in my original post. I dont have a system i can test the actual changepasswd funcationality on any more but I updated the patch file to work against rev1569 and tested the interface atleast. Hopefully it will work for you now.

Thanks for the translations I will try and add them to the next version.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline nicolash

  • Newbie
  • *
  • Posts: 7
Working great with rev 1569!
Many thanks!

I'll really love to see that included in the main branch... but I guess we are too few people to use courier-imap/courier-poppassd...

Offline rockwilda

  • Jr. Member
  • **
  • Posts: 35
Quote from: nicolash;12693
Working great with rev 1569!
Many thanks!

I'll really love to see that included in the main branch... but I guess we are too few people to use courier-imap/courier-poppassd...


I would lke to see this in the next version, too!

I think the number of people who use courier is much higher than you think!