Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This commit add a new ISPConfig 3 script that brings support for Blacklist, Whitelist, Vacation, Filters and Forward #161

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions ingo/config/backends.php
Expand Up @@ -45,6 +45,7 @@
* - customsql: Custom SQL queries (only for vacation notices).
* - imap: IMAP client side filtering (POP3 servers NOT supported).
* - ispconfig: ISPConfig SOAP Server (only for vacation notices).
* - ispconfig3: ISPConfig 3 SOAP Server (SPAM NOT supported).
* - maildrop: Maildrop scripts.
* - procmail: Procmail scripts.
* - sieve: Sieve scripts.
Expand Down Expand Up @@ -416,6 +417,43 @@
'shares' => false
);

/* ISPConfig3 Example */
$backends['Ispconfig3'] = array(
'disabled' => true,
'transport' => array(
Ingo::RULE_ALL => array(
'driver' => 'null',
'params' => array()
)
),
'script' => array(
Ingo::RULE_ALL => array(
'driver' => 'Ispconfig3',
'params' => array(
'soap_uri' => 'http://localhost:8080/remote/',
// This user must be created in the ispconfig3 web interface
// under System -> Remote Users. The required permissions
// ("functions") are:
// - Client functions
// - Mail user functions
// - Mail spamfilter user functions
// - Mail spamfilter whitelist functions
// - Mail spamfilter blacklist functions
// - Mail user filter functions
'soap_user' => 'horde',
'soap_pass' => 'secret',
// Default policy id in case we have to create a new user
// for whitelist/blacklist rules.
'policy_id' => 5,
// Delete filter rules not created by Ingo in the ISPConfig
// server.
'delete_orphan' => false
)
)
),
'shares' => false
);

/* Custom SQL Example */
$backends['customsql'] = array(
'disabled' => true,
Expand Down
46 changes: 46 additions & 0 deletions ingo/config/fields.php.dist
@@ -0,0 +1,46 @@
<?php
/**
* This file defines the set of default match items to display when creating
* a new filter rule.
*
* IMPORTANT: DO NOT EDIT THIS FILE!
* Local overrides MUST be placed in fields.local.php or fields.d/.
* If the 'vhosts' setting has been enabled in Horde's configuration, you can
* use fields-servername.php.
*
* These fields will only appear if the driver can handle it.
*
* Users will have to manually insert the name of the header on the rule
* creation screen if it does not appear in this list.
*
* Format of $ingo_fields array:
* 'LABEL' => array(
* MANDATORY:
* 'label' => (string) The gettext label for the entry.
* 'type' => (integer) The type of test. Either:
* Ingo_Storage::TYPE_HEADER -- Header test
* Ingo_Storage::TYPE_SIZE -- Message size test
* Ingo_Storage::TYPE_BODY -- Body test
* OPTIONAL:
* 'tests' => (array) Force these tests to be used only.
* If not set, will use the fields generally
* available to the driver.
* )
*/

// ISPConfig3 Example
// ------------------
//$ingo_fields = array(
// 'To' => array(
// 'label' => _("To"),
// 'type' => Ingo_Storage::TYPE_HEADER
// ),
// 'Subject' => array(
// 'label' => _("Subject"),
// 'type' => Ingo_Storage::TYPE_HEADER
// ),
// 'From' => array(
// 'label' => _("From"),
// 'type' => Ingo_Storage::TYPE_HEADER
// )
//);
12 changes: 12 additions & 0 deletions ingo/lib/Basic/Blacklist.php
Expand Up @@ -99,6 +99,18 @@ protected function _init()
$view->addHelper('Tag');
$view->addHelper('Text');

$features = new Ingo_Form_Base(
null,
'',
null,
$ingo_script->availableCategoryFeatures(Ingo_Storage::ACTION_BLACKLIST)
);

$view->actiondelete = $features->hasFeature('actiondelete');
$view->actionmark = $features->hasFeature('actionmark');
$view->actionfolder = $features->hasFeature('actionfolder');
$view->actions = $view->actiondelete || $view->actionmark || $view->actionfolder;

$view->blacklist = implode("\n", $blacklist->getBlacklist());
$view->disabled = !empty($bl_rule['disable']);
$view->flagonly = $flagonly;
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Basic/Filters.php
Expand Up @@ -294,7 +294,7 @@ protected function _init()

if ($edit_allowed && is_null($mbox_search)) {
if ($factory->hasFeature('on_demand')) {
$view->settings = true;
$view->settings = $factory->hasFeature('additional_settings');
$view->flags = $prefs->getValue('filter_seen');
$view->show_filter_msg = $prefs->getValue('show_filter_msg');
}
Expand Down
7 changes: 6 additions & 1 deletion ingo/lib/Basic/Forward.php
Expand Up @@ -44,7 +44,12 @@ protected function _init()
$fwd_rule = $filters->getRule($fwd_id);

/* Build form. */
$form = new Ingo_Form_Forward($this->vars);
$form = new Ingo_Form_Forward(
$this->vars,
'',
null,
$injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_FORWARD)->availableCategoryFeatures(Ingo_Storage::ACTION_FORWARD)
);

/* Perform requested actions. Ingo_Form_Forward does token checking
* for us. */
Expand Down
8 changes: 8 additions & 0 deletions ingo/lib/Basic/Rule.php
Expand Up @@ -224,6 +224,14 @@ protected function _init()
$view->addHelper('Tag');
$view->addHelper('Text');

$features = new Ingo_Form_Base(
null,
'',
null,
$ingo_script->availableCategoryFeatures(Ingo_Storage::ACTION_FILTERS)
);
$view->combine = $features->hasFeature('combine');

$view->avail_types = $ingo_script->availableTypes();
$view->edit = $this->vars->edit;
$view->fields = $ingo_fields;
Expand Down
8 changes: 7 additions & 1 deletion ingo/lib/Basic/Spam.php
Expand Up @@ -44,7 +44,13 @@ protected function _init()
}

/* Build form. */
$form = new Ingo_Form_Spam($this->vars);
$form = new Ingo_Form_Spam(
$this->vars,
'',
null,
$injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_SPAM)->availableCategoryFeatures(Ingo_Storage::ACTION_SPAM)
);

$renderer = new Horde_Form_Renderer(array(
'encode_title' => false,
'varrenderer_driver' => array('ingo', 'ingo')
Expand Down
12 changes: 8 additions & 4 deletions ingo/lib/Form/Forward.php
Expand Up @@ -21,12 +21,16 @@
*/
class Ingo_Form_Forward extends Ingo_Form_Base
{
public function __construct($vars, $title = '', $name = null)
public function __construct($vars, $title = '', $name = null, $features = array())
{
parent::__construct($vars, $title, $name);
parent::__construct($vars, $title, $name, $features);

if ($this->hasFeature('keepcopy'))
{
$v = $this->addVariable(_("Keep a copy of messages in this account?"), 'keep_copy', 'boolean', false);
$v->setHelp('forward-keepcopy');
}

$v = $this->addVariable(_("Keep a copy of messages in this account?"), 'keep_copy', 'boolean', false);
$v->setHelp('forward-keepcopy');
$v = $this->addVariable(_("Address(es) to forward to:"), 'addresses', 'ingo:Longemail', false, false, null, array(5, 40));
$v->setHelp('forward-addresses');
$this->setButtons(_("Save"));
Expand Down
22 changes: 14 additions & 8 deletions ingo/lib/Form/Spam.php
Expand Up @@ -28,17 +28,23 @@ class Ingo_Form_Spam extends Ingo_Form_Base
*/
public $folder_var;

public function __construct($vars, $title = '', $name = null)
public function __construct($vars, $title = '', $name = null, $features = array())
{
parent::__construct($vars, $title, $name);
parent::__construct($vars, $title, $name, $features);

$v = $this->addVariable(_("Spam Level:"), 'level', 'int', true, false, _("Messages with a likely spam score greater than or equal to this number will be treated as spam."));
$v->setHelp('spam-level');
if ($this->hasFeature('spamlevel'))
{
$v = $this->addVariable(_("Spam Level:"), 'level', 'int', true, false, _("Messages with a likely spam score greater than or equal to this number will be treated as spam."));
$v->setHelp('spam-level');
}

$this->folder_var = $this->addVariable(_("Folder to receive spam:"), 'folder', 'ingo_folders', true);
$this->folder_var->setHelp('spam-folder');
$this->addHidden('', 'actionID', 'text', false);
$this->addHidden('', 'folder_new', 'text', false);
if ($this->hasFeature('spamfolder'))
{
$this->folder_var = $this->addVariable(_("Folder to receive spam:"), 'folder', 'ingo_folders', true);
$this->folder_var->setHelp('spam-folder');
$this->addHidden('', 'actionID', 'text', false);
$this->addHidden('', 'folder_new', 'text', false);
}

$this->setButtons(_("Save"));
}
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Form/Vacation.php
Expand Up @@ -35,7 +35,7 @@ class Ingo_Form_Vacation extends Ingo_Form_Base
*/
protected $_end;

public function __construct($vars, $title = '', $name = null, $features = null)
public function __construct($vars, $title = '', $name = null, $features = array())
{
parent::__construct($vars, $title, $name, $features);

Expand Down
2 changes: 2 additions & 0 deletions ingo/lib/Script/Base.php
Expand Up @@ -45,6 +45,8 @@ abstract class Ingo_Script_Base
'stop_script' => false,
/* Can this driver perform on demand filtering? */
'on_demand' => false,
/* Does the driver support aditional settings? */
'additional_settings' => false,
/* Does the driver require a script file to be generated? */
'script_file' => false,
);
Expand Down
2 changes: 2 additions & 0 deletions ingo/lib/Script/Customsql.php
Expand Up @@ -36,6 +36,8 @@ class Ingo_Script_Customsql extends Ingo_Script_Base
'stop_script' => false,
/* Can this driver perform on demand filtering? */
'on_demand' => false,
/* Does the driver support aditional settings? */
'additional_settings' => false,
/* Does the driver require a script file to be generated? */
'script_file' => true,
);
Expand Down
2 changes: 2 additions & 0 deletions ingo/lib/Script/Imap.php
Expand Up @@ -37,6 +37,8 @@ class Ingo_Script_Imap extends Ingo_Script_Base
'stop_script' => true,
/* Can this driver perform on demand filtering? */
'on_demand' => true,
/* Does the driver support aditional settings? */
'additional_settings' => true,
/* Does the driver require a script file to be generated? */
'script_file' => false,
);
Expand Down
2 changes: 2 additions & 0 deletions ingo/lib/Script/Ispconfig.php
Expand Up @@ -34,6 +34,8 @@ class Ingo_Script_Ispconfig extends Ingo_Script_Base
'stop_script' => false,
/* Can this driver perform on demand filtering? */
'on_demand' => false,
/* Does the driver support aditional settings? */
'additional_settings' => false,
/* Does the driver require a script file to be generated? */
'script_file' => true,
);
Expand Down
123 changes: 123 additions & 0 deletions ingo/lib/Script/Ispconfig3.php
@@ -0,0 +1,123 @@
<?php
/**
* Copyright 2012-2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Michael Epstein <mepstein@mediabox.cl>
* @author Jan Schneider <jan@horde.org>
* @package Ingo
*/

/**
* The Ingo_Script_Ispconfig3 class represents an ISPConfig 3 "script
* generator".
*
* @author Michael Epstein <mepstein@mediabox.cl>
* @author Jan Schneider <jan@horde.org>
* @package Ingo
*/
class Ingo_Script_Ispconfig3 extends Ingo_Script_Base
{
/**
* A list of driver features.
*
* @var array
*/
protected $_features = array(
/* Can tests be case sensitive? */
'case_sensitive' => false,
/* Does the driver support setting IMAP flags? */
'imap_flags' => false,
/* Does the driver support the stop-script option? */
'stop_script' => false,
/* Can this driver perform on demand filtering? */
'on_demand' => true,
/* Does the driver support aditional settings? */
'additional_settings' => false,
/* Does the driver require a script file to be generated? */
'script_file' => false
);

/**
* The list of actions allowed (implemented) for this driver.
*
* @var array
*/
protected $_actions = array(
Ingo_Storage::ACTION_MOVE,
Ingo_Storage::ACTION_DISCARD
);

/**
* The categories of filtering allowed.
*
* @var array
*/
protected $_categories = array(
Ingo_Storage::ACTION_BLACKLIST,
Ingo_Storage::ACTION_WHITELIST,
Ingo_Storage::ACTION_VACATION,
Ingo_Storage::ACTION_FORWARD
);

/**
* The types of tests allowed (implemented) for this driver.
*
* @var array
*/
protected $_types = array(
Ingo_Storage::TYPE_HEADER
);

/**
* The list of tests allowed (implemented) for this driver.
*
* @var array
*/
protected $_tests = array(
'contains',
'is',
'begins with',
'ends with'
);

protected $_categoryFeatures = array(
Ingo_Storage::ACTION_VACATION => array('period', 'reason', 'subject'),
Ingo_Storage::ACTION_FORWARD => array(null),
Ingo_Storage::ACTION_BLACKLIST => array(null),
Ingo_Storage::ACTION_WHITELIST => array(null),
Ingo_Storage::ACTION_FILTERS => array(null)
);

/**
* Constructor.
*/
public function __construct(array $params = array())
{
$default_params = array(
'soap_uri' => 'http://localhost:8080/remote/',
'soap_user' => 'horde',
'soap_pass' => '',
'policy_id' => 5,
'delete_orphan' => false
);

parent::__construct(array_merge($default_params, $params));
}

/**
* @see perform()
*/
protected function _perform($change)
{
// Load rules.
$filters = $this->_params['storage']->retrieve(Ingo_Storage::ACTION_FILTERS);
$rules = $filters->getFilterList($this->_params['skip']);

// Process loaded rules.
$api = new Ingo_Script_Ispconfig3_Api($this->_params);
$api->processRules($rules);
}
}