Hello Guys, I have write several plugins who work perfectly with the ISPConfig control panel but not with the API And I'm not sure how to fix this... Here it's a simple demonstration of the trouble: Add error login to your ispconfig vhost (/etc/apache2/sites-enabled/000-ispconfig.vhost) add / edit the line : ErrorLog /var/log/ispconfig/httpd/YourVHOST.DOMAIN.TLS/error.log Create the file (/usr/local/ispconfig/interface/lib/plugins/exemple_plugin.inc.php) PHP: <?php[LIST]class exemple_plugin { var $plugin_name = 'exemple_plugin'; var $class_name = 'exemple_plugin'; function onLoad() { global $app; $app->plugin->registerEvent('mail:mail_user:on_before_insert', 'exemple_plugin', 'fonction_edit'); $app->plugin->registerEvent('mail:mail_user:on_before_update', 'exemple_plugin', 'fonction_edit'); $app->plugin->registerEvent('mail:mail_user:on_before_delete', 'exemple_plugin', 'fonction_del'); } function fonction_edit($event_name, $page_form){ error_log('You should see this line in the log when you add / edit an email'); } function fonction_del($event_name, $page_form){ error_log('You should see this line in the log when you remove an email'); }} IMPORTANT : Relog into your ISPConfig control panel Time to try Go to Ispconfig; Email > Email Mailbox > Select an existing mailbox > Change something > Save When you do that you should see this inside your logfile When you make the same change by the API, nothing is wrote inside the logfile. That mean the plugin isn't call by the API. Any idea how to solve that ? Thanks
Most likely the api function does not fire the event 'mail:mail_usern_before_insert' then, that's not an issue of your code, more a missing part of the api.
The plugin should be called if you use the api to insert, update or delete a mail_user. Ensure the server_id is correct.
I just checked the code and it seems that event support is still not implemented in most API functions. The event fires only when updateQuery and insertQuery has the $event_identifier parameter set as last parameter after $params. Currently, this seems to be only the case for the mail_user_filter* functions. So in general, everything is in place code-wise in the insert and update functions globally, but the event parameter is missing in most functions to make it work.
I guess you are talking about that part in : /usr/local/ispconfig/interface/lib/classes/remote.d/mail.inc.php
Yes, that's the parameter that is missing. You must add the same event string that your plugin is using.
Okay very cool. But how it's work when I have on_BEFORE_insert and on_AFTER_insert, can we pass an array ? I use on_before_insert to do some verification with external system first.
That#s not possible at the moment. I guess we might have to rework this in the api completely. Pass only e.g. 'mail:mail_user' as identifier parameter and then change the code in updateQuery and insertQuery to raise the on_before_insert and on_after_insert at the right time before and after the sql query. So that's a bit more work, but needs to be done I guess to make the API behavior more compatible with the GUI.
Ho crap ... But yeah this kind of modifications would be great ! So do I have to repost it somewhere as a feature request ?
Yes, this time the git is the right place Sorry for having been so strict, but if we start doing support in git, then more and more users will post support questions there and overload the system.
Another question for you guys How can I interrupt the processing ? For the moment I use exit(), it's work's well with the control pannel but not with the API ... PHP: <?phpclass exemple_plugin { var $plugin_name = 'exemple_plugin'; var $class_name = 'exemple_plugin'; function onLoad() { global $app; $app->plugin->registerEvent('mail:mail_user:on_before_insert', 'exemple_plugin', 'fonction_edit'); $app->plugin->registerEvent('mail:mail_user:on_before_update', 'exemple_plugin', 'fonction_edit'); $app->plugin->registerEvent('mail:mail_user:on_before_delete', 'exemple_plugin', 'fonction_del'); } function fonction_edit($event_name, $page_form){ global $app, $conf; if( $_SESSION["s"]["user"]["typ"] != 'admin' ) { $regex_pattern = ['.*other.*','.*test.*']; // TODO check local config file for pattern foreach ($regex_pattern as $pattern) { if(preg_match("/{$pattern}/", $page_form->dataRecord['email'])) { error_log("MATCH FOUND ::". $pattern ); exit('not allowed'); } } } } function fonction_del($event_name, $page_form){ error_log('You should see this line in the log when you remove an email'); }} Maybe you have a better way ? Additionnal informaitons: The modification isn't send to the datalog history. So i think the modification isn't propagated to other servers (in multi server environnement) Only the main database is modified by the API that isn't good at all. In my exemple I check for a pattern inside the email, if the pattern match i wan't to stop the email creation and return a message Regards,