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

Add support for multiple servers #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Janfred
Copy link
Contributor

@Janfred Janfred commented Mar 14, 2016

Add support for multiple servers.

Useful for hot standby or backup systems with replicated databases.

The main problem is that, if you want to have a backup mx, you need to copy all mailbox setting changes you make on the first system to the second one.

With this new feature you can just replicate your database and use it for both, the primary and the secondary mailserver.

You can also do load balancing by sending one domain to the first and an other domain to the second mailserver as primary.

@DavidGoodwin
Copy link
Member

Thank you for taking the time to submit the pull request. I've had a quick eye-ball of it, and nothing immediate is jumping out.
(The relay_recipient_maps is a useful addition too - as I've found myself needing this too)

@Janfred
Copy link
Contributor Author

Janfred commented Mar 14, 2016

There is one small todo, i don't have any idea how to solve it:
At the server list is a select field for the admin. I could not remove that like in the admin list.
Since only super-admins can see the smtp-address and all other users can see all servers, this is not necessary.
Maybe you can give me a hint how to remove that.

@@ -13,12 +13,19 @@ postconf -m) Three main.cf variables are involved:

virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
virtual_alias_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a reason why mysql_virtual_alias_maps.cf is listed first - an alias domain can "override" some aliases. To keep this working, mysql_virtual_alias_maps.cf needs to be the first in the list.

Why did you move it around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason i remember was that recursive lookups failed.
e.g. some_mail@host aliases to webmaster@host
webmaster@host aliases to my_name@host

In the default settings this lookup failed.
Could you name a setting where this order of handling is needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm surprised that this fails because IIRC I have more than one "chained" alias ;-) - and I'm even more surprised that changing the order fixed it for you.

The setting that will probably break is:

The goal is: all mails that are sent to @host should be forwarded to the same address @Otherhost (if this address exists) - except a@ because the a@host alias overrides this.

@Janfred
Copy link
Contributor Author

Janfred commented Mar 14, 2016

Ok, i've done several changes:

  • The language keys are changed.
  • The list_servers method 'moved' to the DomainHandler. I don't know if this is the best coding style, but it is better placed then in the functions.inc.php
  • The 2nd Migration is merged into one. ( Just one small question: does this already has effect with the sqlite-Implementation from @phyrog ? )
  • The primary key is set to the correct one (copy-paste-error)
  • The primary key is now checked that it is not empty on creation

The postcreation and postdeletion hook is only there because i followed the implementation of domains. I don't know if there is a need for server-post(creation|deletion)-scripts.

I still dont get what problem the changed order in the virtual_alias_maps would cause.
If you could tell me some usecases, I could check. if there is a solution to allow recursive lookups as well.

@Janfred
Copy link
Contributor Author

Janfred commented Mar 14, 2016

For the postfix-issue: I checked it with my local setup. You were right. I don't know what went wrong in my normal setup...
I changed this in the POSTFIX_CONF.txt

@Janfred
Copy link
Contributor Author

Janfred commented Mar 20, 2016

I did one final change: The server tab is now only visible for super-admins.

I thought of making only servers visible to non-global admins which are primary servers for their domain(s).
But I don't think this is very important to look at for non-global admins.

I left the primary_mx column in the domain overview, maybe this is useful. If it is not, i'll remove it too.

@@ -59,6 +59,9 @@
# set in __construct()
protected $allowed_domains = false;

# array with the server list set in __construct()
protected $allowed_servers = false;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry for the long delay!)

This is only used in DomainHandler, so it should be defined there. (If it's used by more *Handler classes in the future, PFAHandler would be ok.)

password = password
hosts = localhost
dbname = postfix
query = SELECT address FROM server JOIN domain ON domain.primarymx = server.server WHERE (domain.domain = '%s' OR CONCAT('.', domain.domain) = '%s') AND domain.primarymx!='@@myhostname@@'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the 'transport_maps'-query also include AND active = '1'?

FWIW, I love this pull request, and are working on implementing it in my own mail-server setup.

@Janfred
Copy link
Contributor Author

Janfred commented Jan 29, 2017

I've rebased all changes to comply with the new master status.

You might want to recheck my implementations if they comply with your code style.

I haven't done the adjustment @cboltz suggested to use the already available 'transport' field.
The transport is not the same for the primary and secondary server. If the secondary server receives a mail for the primary it will be a relay transport. For the primary it will be (depending on the overall setup) a virtual or local transport.

config.inc.php Outdated
@@ -523,6 +528,22 @@ function x_struct_admin_modify($struct) {
// $CONF['domain_postdeletion_script']='sudo -u courier /usr/local/bin/postfixadmin-domain-postdeletion.sh';
$CONF['domain_postdeletion_script'] = '';

// Optional
// Script to run after creation of servers.
// Not that this may fail if PHP is nun in "safe mode", or if
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not or Note ?

config.inc.php Outdated

// Optional
// Script to run after deletion of servers.
// Not that this may fail if PHP is nun in "safe mode", or if
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not or Note ?

$PALANG['server_button'] = 'Add server'; # XXX
$PALANG['server_create_error'] = 'Creating server %s failed'; # XXX
$PALANG['server_edit_error'] = 'Modifying server %s failed'; # XXX
$PALANG['server_store_success'] = 'The Server %s has successfully been added.'; # XXX
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just nitpicking: why is Server uppercase here?

$PALANG['server_does_not_exist'] = 'The server %s does not exist.'; # XXX
$PALANG['confirm_delete_server'] = 'Do you really want to delete the server %s?'; # XXX
$PALANG['delete_server_domain_target'] = 'There are still domains, where this server is the primary one. Change them first'; # XXX
$PALANG['server_updated'] = 'The Server %s was updated'; # XXX
Copy link

@jdsn jdsn Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just nitpicking again :)
... and a few more places below

@Janfred
Copy link
Contributor Author

Janfred commented Jul 25, 2020

I have updated this pull request to Postfixadmin v3.
There is still work to do, but I'd like to hear if this goes in the right direction @cboltz

I haven't updated the language files yet, nor the postfix configuration script.

$firstline='';
$firstline=exec($command,$output,$retval);
if (0!=$retval) {
error_log("Running $command yielded return value=$retval, first line of output=$firstline");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not (for example) just json_encode($output) at the end of this message, rather than restricting it to the first line ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I've just copied this piece of code from model/DomainHandler.php#L292

I could change that in my pull request, but I guess it should then be changed in all model handlers.

@DavidGoodwin
Copy link
Member

....

....nor the postfix configuration script.

By that - do you mean whatever config is needed for Postfix to use this functionality ?

@Janfred
Copy link
Contributor Author

Janfred commented Jul 26, 2020

By that - do you mean whatever config is needed for Postfix to use this functionality ?

In the previous version of my pull request I changed the POSTFIX_CONF.txt to support the multiple server feature. But I think my changes were not compatible with the standard-setup.
I'd be happy about any idea how to address this issue.

@DavidGoodwin
Copy link
Member

Any chance you could rebase your branch onto master and add some basic documentation - e..g what changes are needed to the database queries postfix uses for this to be in a usable state to merge in?

@Neustradamus
Copy link

@Janfred: It is possible to rebase your PR?

@Janfred
Copy link
Contributor Author

Janfred commented Oct 15, 2023

I'll add it to my todo-List for when I have a bit time to spare.

@ETE-Design
Copy link

@Janfred Did you manage to rebase your PR? Would be a really nice feature to have :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants