From 32b40db8d2e799588bb78e8c07cb70105e4e5d8e Mon Sep 17 00:00:00 2001 From: tbrehm Date: Mon, 28 May 2007 21:07:54 +0000 Subject: [PATCH] Added getmail module. --- interface/web/mail/form/mail_get.tform.php | 145 ++++++++++++++++++ interface/web/mail/lib/lang/en_mail_get.lng | 12 ++ .../web/mail/lib/lang/en_mail_get_list.lng | 14 ++ interface/web/mail/lib/module.conf.php | 8 +- interface/web/mail/list/mail_get.list.php | 101 ++++++++++++ interface/web/mail/mail_get_del.php | 54 +++++++ interface/web/mail/mail_get_edit.php | 62 ++++++++ interface/web/mail/mail_get_list.php | 29 ++++ .../web/mail/templates/mail_get_edit.htm | 56 +++++++ .../web/mail/templates/mail_get_list.htm | 34 ++++ server/conf/getmail.conf.master | 15 ++ server/lib/app.inc.php | 45 +++--- server/lib/classes/modules.inc.php | 18 ++- server/lib/classes/plugins.inc.php | 47 ++++-- server/lib/config.inc.php | 6 +- .../mail_module.inc.php | 14 +- server/plugins-enabled/getmail_plugin.inc.php | 133 ++++++++++++++++ server/server.php | 70 ++++++--- 18 files changed, 787 insertions(+), 76 deletions(-) create mode 100644 interface/web/mail/form/mail_get.tform.php create mode 100644 interface/web/mail/lib/lang/en_mail_get.lng create mode 100644 interface/web/mail/lib/lang/en_mail_get_list.lng create mode 100644 interface/web/mail/list/mail_get.list.php create mode 100644 interface/web/mail/mail_get_del.php create mode 100644 interface/web/mail/mail_get_edit.php create mode 100644 interface/web/mail/mail_get_list.php create mode 100644 interface/web/mail/templates/mail_get_edit.htm create mode 100644 interface/web/mail/templates/mail_get_list.htm create mode 100644 server/conf/getmail.conf.master rename server/{mods-available => mods-enabled}/mail_module.inc.php (89%) create mode 100644 server/plugins-enabled/getmail_plugin.inc.php 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 000000000..f6c9d3935 --- /dev/null +++ b/interface/web/mail/form/mail_get.tform.php @@ -0,0 +1,145 @@ + 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 000000000..f6d37315f --- /dev/null +++ b/interface/web/mail/lib/lang/en_mail_get.lng @@ -0,0 +1,12 @@ + \ 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 000000000..11a4d02f7 --- /dev/null +++ b/interface/web/mail/lib/lang/en_mail_get_list.lng @@ -0,0 +1,14 @@ + \ 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 8ae475875..a7c7e1ca0 100644 --- a/interface/web/mail/lib/module.conf.php +++ b/interface/web/mail/lib/module.conf.php @@ -1,4 +1,4 @@ - 'mail', 'title' => 'Email', @@ -112,12 +112,12 @@ $module = array ( 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 000000000..fa6a2843b --- /dev/null +++ b/interface/web/mail/list/mail_get.list.php @@ -0,0 +1,101 @@ + "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 000000000..b8eae9aea --- /dev/null +++ b/interface/web/mail/mail_get_del.php @@ -0,0 +1,54 @@ +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 000000000..1d0726665 --- /dev/null +++ b/interface/web/mail/mail_get_edit.php @@ -0,0 +1,62 @@ +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 000000000..55300d360 --- /dev/null +++ b/interface/web/mail/mail_get_list.php @@ -0,0 +1,29 @@ +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 000000000..6b92616ab --- /dev/null +++ b/interface/web/mail/templates/mail_get_edit.htm @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{tmpl_var name='server_id_txt'}: + +
{tmpl_var name='type_txt'}: + +
{tmpl_var name='source_server_txt'}:
{tmpl_var name='source_username_txt'}:
{tmpl_var name='source_password_txt'}:
{tmpl_var name='source_delete_txt'}:{tmpl_var name='source_delete'}
{tmpl_var name='destination_txt'}: + +
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
  
 
  +
+
+ \ 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 000000000..4a54e7062 --- /dev/null +++ b/interface/web/mail/templates/mail_get_list.htm @@ -0,0 +1,34 @@ +

+


+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
{tmpl_var name="active"}{tmpl_var name="server_id"}{tmpl_var name="source_server"}{tmpl_var name="source_username"}{tmpl_var name="destination"}[{tmpl_var name='delete_txt'}]
\ 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 000000000..92bb689ef --- /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 88a90104c..dd52be176 100644 --- a/server/lib/app.inc.php +++ b/server/lib/app.inc.php @@ -29,8 +29,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class app { - var modules = array(); - var plugins = array(); + var $loaded_modules = array(); + var $loaded_plugins = array(); function app() { @@ -59,18 +59,19 @@ class app { } } - function load($files) { - - 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"); - } - } - } + function load($classes) { + 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 @@ class app { 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 @@ class app { 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."
"; fclose($fp); - } else { - $this->error("Unable to write to logfile."); - } + //} else { + // die("Unable to write to logfile."); + //} } // if } // func @@ -120,7 +121,7 @@ class app { 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 12b871e78..a8de65bce 100644 --- a/server/lib/classes/modules.inc.php +++ b/server/lib/classes/modules.inc.php @@ -39,23 +39,25 @@ class modules { 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 @@ class modules { */ 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 @@ class modules { // 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 5e2147f33..7ffc803a2 100644 --- a/server/lib/classes/plugins.inc.php +++ b/server/lib/classes/plugins.inc.php @@ -30,7 +30,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 @@ class plugins { 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 @@ class plugins { } /* - 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 0f95d5762..062a52b4e 100644 --- a/server/lib/config.inc.php +++ b/server/lib/config.inc.php @@ -32,8 +32,7 @@ $conf["app_version"] = "3.0.0"; -//$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["temppath"] = $conf["rootpath"].$conf["fs_div"]."temp"; */ $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 0f13f05e7..e1dfe0897 100644 --- a/server/mods-available/mail_module.inc.php +++ b/server/mods-enabled/mail_module.inc.php @@ -46,20 +46,24 @@ class mail_module { '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 @@ class mail_module { $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 @@ class mail_module { 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 000000000..cc18d2d94 --- /dev/null +++ b/server/plugins-enabled/getmail_plugin.inc.php @@ -0,0 +1,133 @@ +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 ea454ee9e..b4973f894 100644 --- a/server/server.php +++ b/server/server.php @@ -36,8 +36,9 @@ set_time_limit(0); // 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 @@ if($server_db_record == false) { $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 @@ if(is_file($conf["temppath"].$conf["fs_div"].".ispconfig_lock")){ // 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 -*/ - -$this->modules->loadModules(); - - -/* - Load the plugins that are in the plugins-enabled folder +$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock", LOGLEVEL_DEBUG); */ -$this->plugins->loadPlugins(); +// 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); +} /* - 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 -- GitLab