From 32b40db8d2e799588bb78e8c07cb70105e4e5d8e Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Mon, 28 May 2007 17:07:54 -0400
Subject: [PATCH] Added getmail module.

---
 interface/web/mail/lib/lang/en_mail_get.lng      |   12 
 server/conf/getmail.conf.master                  |   15 +
 server/lib/classes/plugins.inc.php               |   47 ++
 interface/web/mail/form/mail_get.tform.php       |  145 +++++++++
 server/lib/app.inc.php                           |   45 +-
 interface/web/mail/lib/lang/en_mail_get_list.lng |   14 
 interface/web/mail/mail_get_list.php             |   29 +
 server/mods-enabled/mail_module.inc.php          |   14 
 interface/web/mail/templates/mail_get_edit.htm   |   56 +++
 interface/web/mail/list/mail_get.list.php        |  101 ++++++
 interface/web/mail/mail_get_del.php              |   54 +++
 interface/web/mail/lib/module.conf.php           |    8 
 server/lib/classes/modules.inc.php               |   18 
 server/lib/config.inc.php                        |    6 
 server/server.php                                |   68 ++-
 interface/web/mail/mail_get_edit.php             |   62 ++++
 interface/web/mail/templates/mail_get_list.htm   |   34 ++
 server/plugins-enabled/getmail_plugin.inc.php    |  133 ++++++++
 18 files changed, 786 insertions(+), 75 deletions(-)

diff --git a/interface/web/mail/form/mail_get.tform.php b/interface/web/mail/form/mail_get.tform.php
new file mode 100644
index 0000000..f6c9d39
--- /dev/null
+++ b/interface/web/mail/form/mail_get.tform.php
@@ -0,0 +1,145 @@
+<?php
+
+/*
+	Form Definition
+
+	Tabledefinition
+
+	Datatypes:
+	- INTEGER (Forces the input to Int)
+	- DOUBLE
+	- CURRENCY (Formats the values to currency notation)
+	- VARCHAR (no format check, maxlength: 255)
+	- TEXT (no format check)
+	- DATE (Dateformat, automatic conversion to timestamps)
+
+	Formtype:
+	- TEXT (Textfield)
+	- TEXTAREA (Textarea)
+	- PASSWORD (Password textfield, input is not shown when edited)
+	- SELECT (Select option field)
+	- RADIO
+	- CHECKBOX
+	- CHECKBOXARRAY
+	- FILE
+
+	VALUE:
+	- Wert oder Array
+
+	Hint:
+	The ID field of the database table is not part of the datafield definition.
+	The ID field must be always auto incement (int or bigint).
+
+
+*/
+
+$form["title"] 			= "Get Email";
+$form["description"] 	= "";
+$form["name"] 			= "mail_get";
+$form["action"]			= "mail_get_edit.php";
+$form["db_table"]		= "mail_get";
+$form["db_table_idx"]	= "mailget_id";
+$form["db_history"]		= "yes";
+$form["tab_default"]	= "mailget";
+$form["list_default"]	= "mail_get_list.php";
+$form["auth"]			= 'yes'; // yes / no
+
+$form["auth_preset"]["userid"]  = 0; // 0 = id of the user, > 0 id must match with id of current user
+$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
+$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
+$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
+$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
+
+$form["tabs"]['mailget'] = array (
+	'title' 	=> "Get email",
+	'width' 	=> 100,
+	'template' 	=> "templates/mail_get_edit.htm",
+	'fields' 	=> array (
+	##################################
+	# Begin Datatable fields
+	##################################
+		'server_id' => array (
+			'datatype'	=> 'INTEGER',
+			'formtype'	=> 'SELECT',
+			'default'	=> '',
+			'datasource'	=> array ( 	'type'	=> 'SQL',
+										'querystring' => 'SELECT server_id,server_name FROM server WHERE {AUTHSQL} ORDER BY server_name',
+										'keyfield'=> 'server_id',
+										'valuefield'=> 'server_name'
+									 ),
+			'value'		=> ''
+		),
+		'type' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'SELECT',
+			'default'	=> '',
+			'value'		=> array('pop3' => 'POP3','imap'=>'IMAP')
+		),
+		'source_server' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'source_server_error_isempty'),
+									),
+			'default'	=> '',
+			'value'		=> '',
+			'width'		=> '30',
+			'maxlength'	=> '255'
+		),
+		'source_username' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'source_username_error_isempty'),
+									),
+			'default'	=> '',
+			'value'		=> '',
+			'width'		=> '30',
+			'maxlength'	=> '255'
+		),
+		'source_password' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'source_password_error_isempty'),
+									),
+			'default'	=> '',
+			'value'		=> '',
+			'width'		=> '30',
+			'maxlength'	=> '255'
+		),
+		'source_delete' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'CHECKBOX',
+			'default'	=> 'y',
+			'value'		=> array(0 => 'n',1 => 'y')
+		),
+		'destination' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'SELECT',
+			'default'	=> '',
+			'datasource'	=> array ( 	'type'			=> 'SQL',
+										'querystring' 	=> 'SELECT email FROM mail_user WHERE {AUTHSQL} ORDER BY email',
+										'keyfield'		=> 'email',
+										'valuefield'	=> 'email'
+									 ),
+			'validators'	=> array ( 	0 => array (	'type'	=> 'ISEMAIL',
+														'errmsg'=> 'destination_error_isemail'),
+									),
+			'value'		=> ''
+		),
+		'active' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'CHECKBOX',
+			'default'	=> 'y',
+			'value'		=> array(0 => 'n',1 => 'y')
+		),
+	##################################
+	# ENDE Datatable fields
+	##################################
+	)
+);
+
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/lib/lang/en_mail_get.lng b/interface/web/mail/lib/lang/en_mail_get.lng
new file mode 100644
index 0000000..f6d3731
--- /dev/null
+++ b/interface/web/mail/lib/lang/en_mail_get.lng
@@ -0,0 +1,12 @@
+<?php
+$wb["server_id_txt"] = 'server_id';
+$wb["type_txt"] = 'type';
+$wb["source_server_txt"] = 'source_server';
+$wb["source_username_txt"] = 'source_username';
+$wb["source_password_txt"] = 'source_password';
+$wb["source_delete_txt"] = 'source_delete';
+$wb["destination_txt"] = 'destination';
+$wb["active_txt"] = 'active';
+$wb["btn_save_txt"] = 'Save';
+$wb["btn_cancel_txt"] = 'Cancel';
+?>
\ No newline at end of file
diff --git a/interface/web/mail/lib/lang/en_mail_get_list.lng b/interface/web/mail/lib/lang/en_mail_get_list.lng
new file mode 100644
index 0000000..11a4d02
--- /dev/null
+++ b/interface/web/mail/lib/lang/en_mail_get_list.lng
@@ -0,0 +1,14 @@
+<?php
+$wb["list_head_txt"] = 'mail_get';
+$wb["active_txt"] = 'active';
+$wb["server_id_txt"] = 'server_id';
+$wb["source_server_txt"] = 'source_server';
+$wb["source_username_txt"] = 'source_username';
+$wb["destination_txt"] = 'destination';
+$wb["page_txt"] = 'Page';
+$wb["page_of_txt"] = 'of';
+$wb["page_next_txt"] = 'Next';
+$wb["page_back_txt"] = 'Back';
+$wb["delete_txt"] = 'Delete';
+$wb["filter_txt"] = 'Filter';
+?>
\ No newline at end of file
diff --git a/interface/web/mail/lib/module.conf.php b/interface/web/mail/lib/module.conf.php
index 8ae4758..a7c7e1c 100644
--- a/interface/web/mail/lib/module.conf.php
+++ b/interface/web/mail/lib/module.conf.php
@@ -1,4 +1,4 @@
-<?php
+<?php
 $module = array (
   'name' => 'mail',
   'title' => 'Email',
@@ -112,12 +112,12 @@
       array (
         0 => 
         array (
-          'title' => 'Fetchmail Accounts',
+          'title' => 'Fetchmail',
           'target' => 'content',
-          'link' => 'mail/fetchmail_list.php',
+          'link' => 'mail/mail_get_list.php',
         ),
       ),
     ),
   ),
-)
+)
 ?>
\ No newline at end of file
diff --git a/interface/web/mail/list/mail_get.list.php b/interface/web/mail/list/mail_get.list.php
new file mode 100644
index 0000000..fa6a284
--- /dev/null
+++ b/interface/web/mail/list/mail_get.list.php
@@ -0,0 +1,101 @@
+<?php
+
+/*
+	Datatypes:
+	- INTEGER
+	- DOUBLE
+	- CURRENCY
+	- VARCHAR
+	- TEXT
+	- DATE
+*/
+
+
+
+// Name of the list
+$liste["name"] 				= "mail_get";
+
+// Database table
+$liste["table"] 			= "mail_get";
+
+// Index index field of the database table
+$liste["table_idx"]			= "mailget_id";
+
+// Search Field Prefix
+$liste["search_prefix"] 	= "search_";
+
+// Records per page
+$liste["records_per_page"] 	= 15;
+
+// Script File of the list
+$liste["file"]				= "mail_get_list.php";
+
+// Script file of the edit form
+$liste["edit_file"]			= "mail_get_edit.php";
+
+// Script File of the delete script
+$liste["delete_file"]		= "mail_get_del.php";
+
+// Paging Template
+$liste["paging_tpl"]		= "templates/paging.tpl.htm";
+
+// Enable auth
+$liste["auth"]				= "yes";
+
+
+/*****************************************************
+* Suchfelder
+*****************************************************/
+
+$liste["item"][] = array(	'field'		=> "active",
+							'datatype'	=> "VARCHAR",
+							'formtype'	=> "SELECT",
+							'op'		=> "=",
+							'prefix'	=> "",
+							'suffix'	=> "",
+							'width'		=> "",
+							'value'		=> array('y' => "Yes",'n' => "No"));
+
+$liste["item"][] = array(	'field'		=> "server_id",
+							'datatype'	=> "VARCHAR",
+							'formtype'	=> "SELECT",
+							'op'		=> "like",
+							'prefix'	=> "%",
+							'suffix'	=> "%",
+							'datasource'	=> array ( 	'type'	=> 'SQL',
+														'querystring' => 'SELECT server_id,server_name FROM server WHERE {AUTHSQL} ORDER BY server_name',
+														'keyfield'=> 'server_id',
+														'valuefield'=> 'server_name'
+									 				  ),
+							'width'		=> "",
+							'value'		=> "");
+
+$liste["item"][] = array(	'field'		=> "source_server",
+							'datatype'	=> "VARCHAR",
+							'formtype'	=> "TEXT",
+							'op'		=> "like",
+							'prefix'	=> "%",
+							'suffix'	=> "%",
+							'width'		=> "",
+							'value'		=> "");
+
+$liste["item"][] = array(	'field'		=> "source_username",
+							'datatype'	=> "VARCHAR",
+							'formtype'	=> "TEXT",
+							'op'		=> "like",
+							'prefix'	=> "%",
+							'suffix'	=> "%",
+							'width'		=> "",
+							'value'		=> "");
+
+$liste["item"][] = array(	'field'		=> "destination",
+							'datatype'	=> "VARCHAR",
+							'formtype'	=> "TEXT",
+							'op'		=> "like",
+							'prefix'	=> "%",
+							'suffix'	=> "%",
+							'width'		=> "",
+							'value'		=> "");
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/mail_get_del.php b/interface/web/mail/mail_get_del.php
new file mode 100644
index 0000000..b8eae9a
--- /dev/null
+++ b/interface/web/mail/mail_get_del.php
@@ -0,0 +1,54 @@
+<?php
+
+/*
+Copyright (c) 2007, Till Brehm, projektfarm Gmbh
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of ISPConfig nor the names of its contributors
+      may be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/******************************************
+* Begin Form configuration
+******************************************/
+
+$list_def_file = "list/mail_get.list.php";
+$tform_def_file = "form/mail_get.tform.php";
+
+/******************************************
+* End Form configuration
+******************************************/
+
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+// Checke Berechtigungen f�r Modul
+if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
+	header("Location: ../index.php");
+	exit;
+}
+
+$app->uses("tform_actions");
+$app->tform_actions->onDelete();
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/mail_get_edit.php b/interface/web/mail/mail_get_edit.php
new file mode 100644
index 0000000..1d07266
--- /dev/null
+++ b/interface/web/mail/mail_get_edit.php
@@ -0,0 +1,62 @@
+<?php
+/*
+Copyright (c) 2007, Till Brehm, projektfarm Gmbh
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of ISPConfig nor the names of its contributors
+      may be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+/******************************************
+* Begin Form configuration
+******************************************/
+
+$tform_def_file = "form/mail_get.tform.php";
+
+/******************************************
+* End Form configuration
+******************************************/
+
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+// Checking module permissions
+if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
+	header("Location: ../index.php");
+	exit;
+}
+
+// Loading classes
+$app->uses('tpl,tform,tform_actions');
+$app->load('tform_actions');
+
+class page_action extends tform_actions {
+	
+	
+}
+
+$page = new page_action;
+$page->onLoad();
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/mail_get_list.php b/interface/web/mail/mail_get_list.php
new file mode 100644
index 0000000..55300d3
--- /dev/null
+++ b/interface/web/mail/mail_get_list.php
@@ -0,0 +1,29 @@
+<?php
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+/******************************************
+* Begin Form configuration
+******************************************/
+
+$list_def_file = "list/mail_get.list.php";
+
+/******************************************
+* End Form configuration
+******************************************/
+
+// Checking module permissions
+if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
+	header("Location: ../index.php");
+	exit;
+}
+
+$app->uses('listform_actions');
+
+// Limit the results to alias domains
+// $app->listform_actions->SQLExtWhere = "";
+
+$app->listform_actions->onLoad();
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/mail/templates/mail_get_edit.htm b/interface/web/mail/templates/mail_get_edit.htm
new file mode 100644
index 0000000..6b92616
--- /dev/null
+++ b/interface/web/mail/templates/mail_get_edit.htm
@@ -0,0 +1,56 @@
+<table width="500" border="0" cellspacing="0" cellpadding="2">
+  <tr>
+    <td class="frmText11">{tmpl_var name='server_id_txt'}:</td>
+    <td class="frmText11">
+		<select name="server_id" class="text">
+			{tmpl_var name='server_id'}
+		</select>
+	</td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='type_txt'}:</td>
+    <td class="frmText11">
+		<select name="type" class="text">
+			{tmpl_var name='type'}
+		</select>
+	</td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='source_server_txt'}:</td>
+    <td class="frmText11"><input name="source_server" type="text" class="text" value="{tmpl_var name='source_server'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='source_username_txt'}:</td>
+    <td class="frmText11"><input name="source_username" type="text" class="text" value="{tmpl_var name='source_username'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='source_password_txt'}:</td>
+    <td class="frmText11"><input name="source_password" type="text" class="text" value="{tmpl_var name='source_password'}" size="30" maxlength="255"></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='source_delete_txt'}:</td>
+    <td class="frmText11">{tmpl_var name='source_delete'}</td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='destination_txt'}:</td>
+    <td class="frmText11">
+		<select name="destination" class="text">
+			{tmpl_var name='destination'}
+		</select>
+	</td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='active_txt'}:</td>
+    <td class="frmText11">{tmpl_var name='active'}</td>
+  </tr>  <tr>
+    <td class="frmText11">&nbsp;</td>
+    <td class="frmText11">&nbsp;</td>
+  </tr>
+  <tr>
+    <td>&nbsp;</td>
+    <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','mail/mail_get_edit.php');"><div class="buttonEnding"></div>&nbsp;
+      <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('mail/mail_get_list.php');"><div class="buttonEnding"></div>
+    </td>
+  </tr>
+</table>
+<input type="hidden" name="id" value="{tmpl_var name='id'}">
\ No newline at end of file
diff --git a/interface/web/mail/templates/mail_get_list.htm b/interface/web/mail/templates/mail_get_list.htm
new file mode 100644
index 0000000..4a54e70
--- /dev/null
+++ b/interface/web/mail/templates/mail_get_list.htm
@@ -0,0 +1,34 @@
+<div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
+<input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="loadContent('mail/mail_get_edit.php');" /><div class="buttonEnding"></div><br /><br />
+<table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable">
+  <tr>
+    <td class="tblHead"><tmpl_var name="active_txt"></td>
+    <td class="tblHead"><tmpl_var name="server_id_txt"></td>
+    <td class="tblHead"><tmpl_var name="source_server_txt"></td>
+    <td class="tblHead"><tmpl_var name="source_username_txt"></td>
+    <td class="tblHead"><tmpl_var name="destination_txt"></td>
+    <td class="tblHead">&nbsp;</td>
+  </tr>
+  <tr>
+    <td class="frmText11"><select name="search_active" onChange="submitForm('pageForm','mail/mail_get_list.php');">{tmpl_var name='search_active'}</select></td>
+    <td class="frmText11"><select name="search_server_id" onChange="submitForm('pageForm','mail/mail_get_list.php');">{tmpl_var name='search_server_id'}</select></td>
+    <td class="frmText11"><input type="text" name="search_source_server" value="{tmpl_var name='search_source_server'}" class="text" /></td>
+    <td class="frmText11"><input type="text" name="search_source_username" value="{tmpl_var name='search_source_username'}" class="text" /></td>
+    <td class="frmText11"><input type="text" name="search_destination" value="{tmpl_var name='search_destination'}" class="text" /></td>
+    <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','mail/mail_get_list.php');"><div class="buttonEnding"></div></td>
+  </tr>
+  <tmpl_loop name="records">
+  <tr bgcolor="{tmpl_var name="bgcolor"}">
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_get_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="active"}</a></td>
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_get_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="server_id"}</a></td>
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_get_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="source_server"}</a></td>
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_get_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="source_username"}</a></td>
+    <td class="frmText11"><a href="#" onClick="loadContent('mail/mail_get_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="destination"}</a></td>
+    <td class="frmText11" align="right">[<a href="javascript: del_record('mail/mail_get_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td>
+  </tr>
+  </tmpl_loop>
+
+  <tr>
+  	<td colspan="6" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td>
+  </tr>
+</table>
\ No newline at end of file
diff --git a/server/conf/getmail.conf.master b/server/conf/getmail.conf.master
new file mode 100644
index 0000000..92bb689
--- /dev/null
+++ b/server/conf/getmail.conf.master
@@ -0,0 +1,15 @@
+[options]
+message_log = /var/log/getmail.log
+delete = {DELETE}
+
+[retriever]
+type = {TYPE}
+server = {SERVER}
+username = {USERNAME}
+password = {PASSWORD}
+
+[destination]
+type = MDA_external
+path = /usr/sbin/sendmail
+arguments = ("-bm", "{DESTINATION}")
+unixfrom = true
\ No newline at end of file
diff --git a/server/lib/app.inc.php b/server/lib/app.inc.php
index 88a9010..dd52be1 100644
--- a/server/lib/app.inc.php
+++ b/server/lib/app.inc.php
@@ -29,8 +29,8 @@
 
 class app {
 		
-		var modules = array();
-		var plugins = array();
+		var $loaded_modules = array();
+		var $loaded_plugins = array();
         
 		function app() {
 
@@ -59,18 +59,19 @@
 			}
         }
 
-        function load($files) {
+        function load($classes) {
 
-                global $conf;
-                $fl = explode(',',$files);
-                if(is_array($fl)) {
-                        foreach($fl as $file) {
-							if(is_file($conf['classpath'] . "/".$classname.".inc.php") && !is_link($conf['classpath'] . "/".$classname.".inc.php")) {
-                                include_once($conf['classpath'] . "/".$file.".inc.php");
-							}
-                        }
-                }
-
+            global $conf;
+            $cl = explode(',',$classes);
+			if(is_array($cl)) {
+				foreach($cl as $classname) {
+					if(is_file($conf['classpath'] . "/".$classname.".inc.php") && !is_link($conf['classpath'] . "/".$classname.".inc.php")) {
+						include_once($conf['classpath'] . "/".$classname.".inc.php");
+					} else {
+						die('Unable to load: '.$conf['classpath'] . "/".$classname.".inc.php");
+					}
+				}
+			}
         }
 
         /*
@@ -84,19 +85,18 @@
 				global $conf;
 				
                 if($priority >= $conf["log_priority"]) {
-                        if (is_writable($conf["log_file"])) {
-
+                        //if (is_writable($conf["log_file"])) {
                             if (!$fp = fopen ($conf["log_file"], "a")) {
                                 die("Unable to open Logfile.");
                             }
 							switch ($priority) {
-								case: 0;
+								case 0:
 									$priority_txt = "DEBUG";
 								break;
-								case: 1;
+								case 1:
 									$priority_txt = "WARNING";
 								break;
-								case: 2;
+								case 2:
 									$priority_txt = "ERROR";
 								break;
 							}
@@ -104,11 +104,12 @@
                             if (!fwrite($fp, date("d.m.Y-H:i")." - ".$priority_txt." - ". $msg."\r\n")) {
                                 die("Unable to write to logfile.");
                             }
+							echo date("d.m.Y-H:i")." - ".$priority_txt." - ". $msg."<br>";
                             fclose($fp);
 
-                        } else {
-                            $this->error("Unable to write to logfile.");
-                        }
+                        //} else {
+                        //    die("Unable to write to logfile.");
+                        //}
                 } // if
         } // func
 
@@ -120,7 +121,7 @@
 
         function error($msg) {
         	$this->log($msg,3);
-			die();
+			die($msg);
         }
 
 }
diff --git a/server/lib/classes/modules.inc.php b/server/lib/classes/modules.inc.php
index 12b871e..a8de65b 100644
--- a/server/lib/classes/modules.inc.php
+++ b/server/lib/classes/modules.inc.php
@@ -39,23 +39,25 @@
 	function loadModules() {
 		global $app, $conf;
 		
-		$modules_dir = $conf["rootpath"].$conf["fs_div"]."lib".$conf["fs_div"]."mods-enabled".$conf["fs_div"]
 		
+		
+		$modules_dir = $conf["rootpath"].$conf["fs_div"]."mods-enabled".$conf["fs_div"];
 		if (is_dir($modules_dir)) {
-			if ($dh = opendir($dir)) {
+			if ($dh = opendir($modules_dir)) {
 				while (($file = readdir($dh)) !== false) {
-					if($file != '.' && $file != '..') {
+					if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
 						$module_name = substr($file,0,-8);
 						include_once($modules_dir.$file);
 						$app->log("Loading Module: $module_name",LOGLEVEL_DEBUG);
-						$app->modules[$module_name] = new $module_name;
-						$app->modules[$module_name]->onLoad();
+						$app->loaded_modules[$module_name] = new $module_name;
+						$app->loaded_modules[$module_name]->onLoad();
 					}
 				}
 			}
 		} else {
 			$app->log("Modules directory missing: $modules_dir",LOGLEVEL_ERROR);
 		}
+		
 	}
 	
 	/*
@@ -64,7 +66,9 @@
 	*/
 	
 	function registerTableHook($table_name,$module_name,$function_name) {
+		global $app;
 		$this->notification_hooks[$table_name][] = array('module' => $module_name, 'function' => $function_name);
+		$app->log("Registered TableHook '$table_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
 	}
 	
 	/*
@@ -90,13 +94,15 @@
 		
 		// Get the hooks for this table
 		$hooks = $this->notification_hooks[$table_name];
+		$app->log("Raised TableHook for table: '$table_name'",LOGLEVEL_DEBUG);
 		
 		if(is_array($hooks)) {
 			foreach($hooks as $hook) {
 				$module_name = $hook["module"];
 				$function_name = $hook["function"];
 				// Claa the processing function of the module
-				call_user_method($function_name,$app->modules[$module_name],$table_name,$action,$data);
+				$app->log("Call function '$function_name' in module '$module_name' raised by TableHook '$table_name'.",LOGLEVEL_DEBUG);
+				call_user_method($function_name,$app->loaded_modules[$module_name],$table_name,$action,$data);
 				unset($module_name);
 				unset($function_name);
 			}
diff --git a/server/lib/classes/plugins.inc.php b/server/lib/classes/plugins.inc.php
index 5e2147f..7ffc803 100644
--- a/server/lib/classes/plugins.inc.php
+++ b/server/lib/classes/plugins.inc.php
@@ -30,7 +30,8 @@
 
 class plugins {
 	
-	var $notification_events = array();
+	var $available_events = array();
+	var $subscribed_events = array();
 	
 	/*
 	 This function is called to load the plugins from the plugins-available folder
@@ -39,17 +40,17 @@
 	function loadPlugins() {
 		global $app,$conf;
 		
-		$plugins_dir = $conf["rootpath"].$conf["fs_div"]."lib".$conf["fs_div"]."plugins-enabled".$conf["fs_div"]
+		$plugins_dir = $conf["rootpath"].$conf["fs_div"]."plugins-enabled".$conf["fs_div"];
 		
 		if (is_dir($plugins_dir)) {
-			if ($dh = opendir($dir)) {
+			if ($dh = opendir($plugins_dir)) {
 				while (($file = readdir($dh)) !== false) {
-					if($file != '.' && $file != '..') {
+					if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
 						$plugin_name = substr($file,0,-8);
 						include_once($plugins_dir.$file);
 						$app->log("Loading Plugin: $plugin_name",LOGLEVEL_DEBUG);
-						$app->plugins[$plugin_name] = new $module_name;
-						$app->plugins[$plugin_name]->onLoad();
+						$app->loaded_plugins[$plugin_name] = new $plugin_name;
+						$app->loaded_plugins[$plugin_name]->onLoad();
 					}
 				}
 			}
@@ -60,27 +61,47 @@
 	}
 	
 	/*
-	 This function is called by the modules to register for a specific
-	 table change notification
+		This function is used by the modules to announce which events they provide
+	*/
+	
+	function announceEvents($module_name,$events) {
+		global $app;
+		foreach($events as $event_name) {
+			$this->available_events[$event_name] = $module_name;
+			$app->log("Announced event: $event_name",LOGLEVEL_DEBUG);
+		}
+	}
+	
+	
+	/*
+	 This function is called by the plugin to register for an event
 	*/
 	
 	function registerEvent($event_name,$plugin_name,$function_name) {
-		$this->notification_events[$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name);
+		global $app;
+		if(!isset($this->available_events[$event_name])) {
+			$app->log("Unable to register the function '$function_name' in the plugin '$plugin_name' for event '$event_name'",LOGLEVEL_DEBUG);
+		} else {
+			$this->subscribed_events[$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name);
+			$app->log("Registered the function '$function_name' in the plugin '$plugin_name' for event '$event_name'.",LOGLEVEL_DEBUG);
+		}
 	}
 	
 	
 	function raiseEvent($event_name,$data) {
 		global $app;
 		
-		// Get the hooks for this table
-		$events = $this->notification_hevents[$event_name];
+		// Get the subscriptions for this event
+		$events = $this->subscribed_events[$event_name];
+		$app->log("Raised event: '$event_name'",LOGLEVEL_DEBUG);
 		
 		if(is_array($events)) {
 			foreach($events as $event) {
 				$plugin_name = $event["plugin"];
 				$function_name = $event["function"];
-				// Claa the processing function of the module
-				call_user_method($function_name,$app->plugins[$plugin_name],$event_name,$data);
+				// Call the processing function of the plugin
+				$app->log("Call function '$function_name' in plugin '$plugin_name' raised by event '$event_name'.",LOGLEVEL_DEBUG);
+				call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data);
 				unset($plugin_name);
 				unset($function_name);
 			}
diff --git a/server/lib/config.inc.php b/server/lib/config.inc.php
index 0f95d57..062a52b 100644
--- a/server/lib/config.inc.php
+++ b/server/lib/config.inc.php
@@ -32,8 +32,7 @@
 
 
 
-//$conf["rootpath"]		= "F:\\server\\www\\ispconfig3\\server";
-$conf["rootpath"]		= "D:\\www\\ispconfig3\\server";
+$conf["rootpath"]		= "D:\\server\\www\\ispconfig3\\server";
 //$conf["rootpath"]		= "/home/www/ispconfig3/web/cms";
 
 $conf["fs_div"]			= "/"; // File system divider, \\ on windows and / on linux and unix
@@ -45,8 +44,7 @@
 */
 
 $conf["log_file"]		= $conf["rootpath"].$conf["fs_div"]."ispconfig.log";
-$conf["log_priority"]	= 0 // 0 = Debug, 1 = Warning, 2 = Error
-
+$conf["log_priority"]	= 0; // 0 = Debug, 1 = Warning, 2 = Error
 
 /*
         Database Settings
diff --git a/server/mods-available/mail_module.inc.php b/server/mods-enabled/mail_module.inc.php
similarity index 89%
rename from server/mods-available/mail_module.inc.php
rename to server/mods-enabled/mail_module.inc.php
index 0f13f05..e1dfe08 100644
--- a/server/mods-available/mail_module.inc.php
+++ b/server/mods-enabled/mail_module.inc.php
@@ -46,20 +46,24 @@
 									'mail_forwarding_delete',
 									'mail_transport_insert',
 									'mail_transport_update',
-									'mail_transport_delete');
+									'mail_transport_delete',
+									'mail_get_insert',
+									'mail_get_update',
+									'mail_get_delete');
 	
 	/*
 	 	This function is called when the module is loaded
 	*/
 	
 	function onLoad() {
+		global $app;
 		
 		/*
 		Annonce the actions that where provided by this module, so plugins 
 		can register on them.
 		*/
 		
-		$app->plugins->registerEvents($this->module_name,$this->actions_available);
+		$app->plugins->announceEvents($this->module_name,$this->actions_available);
 		
 		/*
 		As we want to get notified of any changes on several database tables,
@@ -76,6 +80,7 @@
 		$app->modules->registerTableHook('mail_forwarding','mail_module','process');
 		$app->modules->registerTableHook('mail_transport','mail_module','process');
 		$app->modules->registerTableHook('mail_user','mail_module','process');
+		$app->modules->registerTableHook('mail_get','mail_module','process');
 		
 	}
 	
@@ -113,6 +118,11 @@
 				if($action == 'u') $app->plugins->raiseEvent('mail_user_update',$data);
 				if($action == 'd') $app->plugins->raiseEvent('mail_user_delete',$data);
 			break;
+			case 'mail_get':
+				if($action == 'i') $app->plugins->raiseEvent('mail_get_insert',$data);
+				if($action == 'u') $app->plugins->raiseEvent('mail_get_update',$data);
+				if($action == 'd') $app->plugins->raiseEvent('mail_get_delete',$data);
+			break;
 		} // end switch
 	} // end function
 
diff --git a/server/plugins-enabled/getmail_plugin.inc.php b/server/plugins-enabled/getmail_plugin.inc.php
new file mode 100644
index 0000000..cc18d2d
--- /dev/null
+++ b/server/plugins-enabled/getmail_plugin.inc.php
@@ -0,0 +1,133 @@
+<?php
+
+/*
+Copyright (c) 2007, Till Brehm, projektfarm Gmbh
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of ISPConfig nor the names of its contributors
+      may be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+class getmail_plugin {
+	
+	var $plugin_name = 'getmail_plugin';
+	var $class_name = 'getmail_plugin';
+	
+	
+	var $getmail_config_dir = '/etc/getmail';
+	
+	/*
+	 	This function is called when the plugin is loaded
+	*/
+	
+	function onLoad() {
+		global $app;
+		
+		/*
+		Register for the events
+		*/
+		
+		$app->plugins->registerEvent('mail_get_insert','getmail_plugin','insert');
+		$app->plugins->registerEvent('mail_get_update','getmail_plugin','update');
+		$app->plugins->registerEvent('mail_get_delete','getmail_plugin','delete');
+		
+	}
+	
+	function insert($event_name,$data) {
+		global $app, $conf;
+		
+		$this->update($event_name,$data);
+		
+	}
+	
+	function update($event_name,$data) {
+		global $app, $conf;
+		
+		// Check if the config directory exists.
+		if(!is_dir($this->getmail_config_dir)) {
+			$app->log("Getmail config directory '".$this->getmail_config_dir."' does not exist.",LOGLEVEL_ERROR);
+		} else {
+			
+			// Delete the config file first, if it exists
+			$this->delete($event_name,$data);
+			
+			// Get the new config file path
+			$config_file_path = escapeshellcmd($this->getmail_config_dir.'/'.$data["new"]["source_server"].'_'.$data["new"]["source_username"].'.conf');
+			if(stristr($config_file_path, "..") or stristr($config_file_path, "|") or stristr($config_file_path,";") or stristr($config_file_path,'$')) {
+				$app->log("Possibly faked path for getmail config file: '$config_file_path'. File is not written.",LOGLEVEL_ERROR);
+				return false;
+			}
+
+			
+			if($data["new"]["source_active"] == 'y') {
+				// Open master template
+				$tpl = file_get_contents($conf["rootpath"].'/conf/getmail.conf.master');
+			
+				// Shall emails be deleted after retrieval
+				if($data["new"]["source_delete"] == 'y') {
+					$tpl = str_replace('{DELETE}','1',$tpl);
+				} else {
+					$tpl = str_replace('{DELETE}','0',$tpl);
+				}
+			
+				// Set the data retriever
+				if($data["new"]["type"] == 'pop3') {
+					$tpl = str_replace('{TYPE}','SimplePOP3Retriever',$tpl);
+				} elseif ($data["new"]["type"] == 'imap') {
+					$tpl = str_replace('{TYPE}','SimpleIMAPRetriever',$tpl);
+				}
+			
+				// Set server, username, password and destination.
+				$tpl = str_replace('{SERVER}',$data["new"]["source_server"],$tpl);
+				$tpl = str_replace('{USERNAME}',$data["new"]["source_username"],$tpl);
+				$tpl = str_replace('{PASSWORD}',$data["new"]["source_password"],$tpl);
+				$tpl = str_replace('{DESTINATION}',$data["new"]["source_destination"],$tpl);
+				
+				// Write the config file.
+				file_put_contents($config_file_path,$tpl);
+				$app->log("Writing Getmail config file: $config_file_path",LOGLEVEL_DEBUG);
+				unset($tpl);
+				unset($config_file_path);
+				
+			} else {
+				// If record is set to inactive, we will delete the file
+				if(is_file($config_file_path)) unlink($config_file_path);
+			}
+		}
+	}
+	
+	function delete($event_name,$data) {
+		global $app, $conf;
+		
+		$config_file_path = escapeshellcmd($this->getmail_config_dir.'/'.$data["old"]["source_server"].'_'.$data["old"]["source_username"].'.conf');
+		if(stristr($config_file_path,"..") || stristr($config_file_path,"|") || stristr($config_file_path,";") || stristr($config_file_path,'$')) {
+			$app->log("Possibly faked path for getmail config file: '$config_file_path'. File is not written.",LOGLEVEL_ERROR);
+			return false;
+		}
+		if(is_file($config_file_path)) unlink($config_file_path);
+	}
+	
+
+} // end class
+
+?>
\ No newline at end of file
diff --git a/server/server.php b/server/server.php
index ea454ee..b4973f8 100644
--- a/server/server.php
+++ b/server/server.php
@@ -36,8 +36,9 @@
 // make sure server_id is always an int
 $conf["server_id"] = intval($conf["server_id"]);
 
+/*
 // Get server record, if updates where available for this server
-$server_db_record = $app->db->queryOneRecord("SELECT * FROM server WHERE update = 1 AND server_id = ".$conf["server_id"])
+$server_db_record = $app->db->queryOneRecord("SELECT * FROM server WHERE update = 1 AND server_id = ".$conf["server_id"]);
 if($server_db_record == false) {
 	$app->log("Nothing to update for server_id ".$conf["server_id"]);
 	die();
@@ -46,7 +47,9 @@
 	$app->db->query("UPDATE server SET update = 0 WHERE server_id = ".$conf["server_id"]);
 	$app->log("Begin update.");
 }
+*/
 
+/*
 // Check if another process is running
 if(is_file($conf["temppath"].$conf["fs_div"].".ispconfig_lock")){
   clearstatcache();
@@ -60,34 +63,51 @@
 
 // Set Lockfile
 @touch($conf["temppath"].$conf["fs_div"].".ispconfig_lock");
-$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock");
-
-// Load required base-classes
-$this->uses('ini_parser,modules,plugins');
-
-// Get server configuration
-$conf["serverconfig"] = $app->ini_parser->parse_ini_string(stripslashes($server_db_record["config"]));
-
-/*
- Load the modules that are im the mods-enabled folder
+$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock", LOGLEVEL_DEBUG);
 */
 
-$this->modules->loadModules();
+// Check if there is anything to update
+$tmp_rec = $app->db->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE server_id = ".$conf["server_id"]);
+$tmp_num_records = $tmp_rec["number"];
+unset($tmp_rec);
 
+if($tmp_num_records > 0) {
+	
+	$app->log("Found $tmp_num_records changes, starting update process.",LOGLEVEL_DEBUG);
+	
+	// Load required base-classes
+	$app->uses('ini_parser,modules,plugins');
+	
+	
+	// Get server configuration
+	$conf["serverconfig"] = $app->ini_parser->parse_ini_string(stripslashes($server_db_record["config"]));
+
+	/*
+	 Load the modules that are im the mods-enabled folder
+	*/
+
+	$app->modules->loadModules();
+
+	/*
+	 Load the plugins that are in the plugins-enabled folder
+	*/
+
+	$app->plugins->loadPlugins();
+
+	/*
+	 Go trough the sys_datalog table and call the processing functions
+	 in the modules that are hooked on to the table actions
+	*/
+	$app->modules->processDatalog();
+} else {
+	$app->log('Nothing to Update.',LOGLEVEL_DEBUG);
+}
 
 /*
- Load the plugins that are in the plugins-enabled folder
-*/
-
-$this->plugins->loadPlugins();
-
-/*
- Go trough the sys_datalog table and call the processing functions
- in the modules that are hooked on to the table actions
-*/
-$this->modules->processDatalog();
-
 // Remove lock
 @unlink($conf["temppath"].$conf["fs_div"].".ispconfig_lock");
-$app->log("Remove Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock");
+$app->log("Remove Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock",LOGLEVEL_DEBUG);
+*/
+
+die('finished.');
 ?>
\ No newline at end of file

--
Gitblit v1.9.1