HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=27)
-   -   Announce update for mailfilters (http://www.howtoforge.com/forums/showthread.php?t=53784)

osterhase 15th August 2011 14:06

Announce update for mailfilters
 
Hi there!

I'm still struggeling to implement the possibility for my roundcube users to edit their spamfilters via the webinterface using the according roundcube-plugin. My newest plan:

The filterrules are written into a file (roundcube.sieve) - the syntax of this file is fully understood by ispconfig due to the fact that it is a regular sieve syntax.

I managed to convince the roundcube-plugin to insert the content of the file into dbispconfig.mail_user.custom_mailfilter. But obviously it is not respected by the server.sh as an update and so it is not written into file and takes no effect.

Here is my question: How can I convince ispconfig 3.0.3.3 do run an update for mail_filter_edit?

In a bigger frame: Is that generally possible?

I would - as always - appreciate any suggestions.

till 15th August 2011 14:11

Quote:

I managed to convince the roundcube-plugin to insert the content of the file into dbispconfig.mail_user.custom_mailfilter. But obviously it is not respected by the server.sh as an update and so it is not written into file and takes no effect.
If you want to update a field in the ispconfig database, use the datalogUpdate function of the ispconfig mysql library or the remoting API. If you do the updates without these functions, then all changes will be ignored.

osterhase 15th August 2011 17:18

Thanks for your fast reply. Just to unterstand the concept:

API: Is basically meant to create an interface between (in this case) roundcube and ISPConfig. A php-script is wirtten that logs into ISPConfig as a remote-user which is equipped with certain rights (f.e. mail-user-edit) and makes certain changes defined in the scirpt.

...so I think I'll try to go with the API-solution.

I had a look at the examples and I think that the soap-mail-user-update.php file is my one. Due to the fact, that I only want to update one field in the db-table I wanted to ask if this is possible via API.

Currently all fields in the array inserted:

Code:

$params = array(        'server_id' => 1,
                                'email' => 'test23@domain.ltd',
                                'password' => 'testen',
                                'quota' => '10',
                                'maildir' => '/var/vmail/domain.ltd/test23',
                                'homedir' => '/var/vmail',
                                'uid' => '5000',
                                'gid' => '5000',
                                'postfix' => 'y',
                                'disableimap' => 'n',
                                'disablepop3' => 'n');

If this is not possible and the entire record is written completly new using the mail_user_update function it would be the best way to query the current entries from the db, save them as variables and then send them back to the params array, like:

Code:

$params = array(        'server_id' => 1,
                                'email' => $email,
                                'password' => $pass,
(...)

Am I correct here or completly of the track?

References:
http://www.howtoforge.com/how-to-cre...or-ispconfig-3

And: /tmp/ispconfig3_install/remoting_client/examples/soap-mailuser-update.php

A punch into any direction is appreciated (whereas "give up" does not count). ;)

till 15th August 2011 17:56

You can not update a single field. A update call has to contain all fields. So the easiest way is to use the mail user get function to retrive the current mailuser, the function returns an array of all fields of that mailuser, then change the value that you intended to cahnge and pass the whole array back as $params to the mail user update function.

osterhase 15th August 2011 19:57

Sorry to bother again... do you mean the function that is defined in remoting.inc.php? I got up that bit of the code that calls the function but don't know how to get the array returned or printed. I would appreciate your help.

Ah - by the way - am I right that the primary_id is the mail_user_id? (or how is the mailuser defined?)

Code:

<?php

$username = 'xxx';
$password = 'xxx';

$soap_location = 'http://localhost:8005/remote/index.php';
$soap_uri = 'http://localhost:8005/remote/';


$client = new SoapClient(null, array('location' => $soap_location,
                                    'uri'      => $soap_uri));

try {
        if($session_id = $client->login($username,$password)) {
                echo 'Login sucessful. Session-ID:'.$session_id.'<br />';
        }

        $primary_id = 108;
        $domain__id = $client->mail_user_get($session_id, $primary_id);

                if($client->logout($session_id)) {
                echo 'Logout succesful.<br />';
        }

       
} catch (SoapFault $e) {
        die('SOAP Blad: '.$e->getMessage());
}

?>


till 15th August 2011 20:52

Yes, thats the function. You just have to pass the mailuser_id to the function and it will return the mailuser record-

osterhase 16th August 2011 12:09

Allright it was a little fight, but I figured it out: ;)

Code:

<?php

$username = 'xxx';
$password = 'xxx';

$soap_location = 'http://localhost:8005/remote/index.php';
$soap_uri = 'http://localhost:8005/remote/';


$client = new SoapClient(null, array('location' => $soap_location,
                                    'uri'      => $soap_uri));

try {
        if($session_id = $client->login($username,$password)) {
                echo 'Login sucessful. Session-ID:'.$session_id.'<br />';
        }

// START read out old paramter and hand back $params_old
        $primary_id = 113; // aka mailuser_id
        $domain__id = $client->mail_user_get($session_id, $primary_id);

        $params_old = $domain__id;
// END read out old parameters


// New entries
        $params = $params_old;
        $params['custom_mailfilter'] = 'test24';
        $client_id = 7; // the ID of the customer who is owning the mail-account
        $mailuser_id = 113; // mailuser_id
        $domain__id = $client->mail_user_update($session_id, $client_id, $mailuser_id , $params);
//        echo $params['custom_mailfilter']; - testing purposes
// ENDE new entries

                if($client->logout($session_id)) {
                echo 'Logout succesful.<br />';
        }

       
} catch (SoapFault $e) {
        die('SOAP Blad: '.$e->getMessage());
}       

?>

But I have two remaining questions:

1. Is the variable "domain_id" changeable or is it in any way dangerous use it twice in the same script? (btw in the example files it is domain__id - is this correct or should domain_id be used?)

2. What's the thing with the client_id? The point being is that I only have the login-name (e-mailadress) of the user which is defined dynamically in the roundcube-sieve-plugin to gather the other informations needed (f.e. the mailuser_id). I'm not shure how to determine the client_id via a mysql-command. Therefore: Is the client_id necessary for the function because it does not seem to apear anywhere except in the client table?

I'm thankful for any suggestions and hints.

Best regards

till 16th August 2011 12:29

Quote:

1. Is the variable "domain_id" changeable or is it in any way dangerous use it twice in the same script? (btw in the example files it is domain__id - is this correct or should domain_id be used?)
The variable should be different, so domain__id with two __ is correct. But you can give the variable a different name like $mailuser_record or similar as well.

Quote:

2. What's the thing with the client_id? The point being is that I only have the login-name (e-mailadress) of the user which is defined dynamically in the roundcube-sieve-plugin to gather the other informations needed (f.e. the mailuser_id). I'm not shure how to determine the client_id via a mysql-command. Therefore: Is the client_id necessary for the function because it does not seem to apear anywhere except in the client table?
Yes, the function is required. If you set a different client-id or no client_id, the mailuser will be moved to a new account.

you can get the client_id with the function client_get_id($session_id, $sys_userid) and the sys_userid is in your $params_old record.

osterhase 17th August 2011 14:54

Thanks for your advises - I have implemented the function client_get_id to determine the correct client_id.

But now I've figured a new problem:
When passing the array $params_old to the mailuser_update function the md5 encoded password is encyrpted again. So the md5-encrypted Password is again md5 encrypted and obviously the entered user-password does not match the stored password in the database.

Any suggestions on that?

till 17th August 2011 15:23

Set the password column to to a empty string in the $params array.


All times are GMT +2. The time now is 02:31.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.