diff -urN smeserver-domains-1.4.old/root/usr/share/smanager/lib/SrvMngr/Controller/Dungog_domains.pm smeserver-domains-1.4/root/usr/share/smanager/lib/SrvMngr/Controller/Dungog_domains.pm
--- smeserver-domains-1.4.old/root/usr/share/smanager/lib/SrvMngr/Controller/Dungog_domains.pm 1970-01-01 01:00:00.000000000 +0100
+++ smeserver-domains-1.4/root/usr/share/smanager/lib/SrvMngr/Controller/Dungog_domains.pm 2020-07-22 09:14:00.000000000 +0100
@@ -0,0 +1,407 @@
+package SrvMngr::Controller::Dungog_domains;
+#----------------------------------------------------------------------
+# heading : Administration
+# description : Domain pseudonyms
+# navigation : 4000 4736
+#
+# name : Dungog_domainsget, method : get, url : /dungog_domains, ctlact : Dungog_domains#main
+# name : Dungog_domainspost,method : post, url : /dungog_domains, ctlact : Dungog_domains#do_Save
+# name : Dungog_domains1, method : get, url : /dungog_domains1, ctlact : Dungog_domains#do_Email
+# name : Dungog_domains2, method : get, url : /dungog_domains2, ctlact : Dungog_domains#do_Options
+# name : Dungog_domains3, method : get, url : /dungog_domains3, ctlact : Dungog_domains#do_AddPseudo
+# name : Dungog_domains4, method : get, url : /dungog_domains4, ctlact : Dungog_domains#do_DelPseudo
+# routes : end
+#
+# Documentation : https://wiki.contribs.org/Domains
+#----------------------------------------------------------------------
+
+use strict;
+use warnings;
+use Mojo::Base 'Mojolicious::Controller';
+
+use Locale::gettext;
+use SrvMngr::I18N;
+use SrvMngr qw(theme_list init_session);
+
+use Data::Dumper;
+use esmith::util;
+use esmith::HostsDB;
+use esmith::AccountsDB;
+
+our $db = esmith::ConfigDB->open();
+our $adb = esmith::AccountsDB->open();
+
+use constant FALSE => 0;
+use constant TRUE => 1;
+
+our $domaindb = esmith::ConfigDB->open('/home/e-smith/db/domains')
+ or die "Unable to open domains db";
+
+our $dungogdb = esmith::ConfigDB->open('/home/e-smith/db/dungog')
+ or die("Unable to open dungog db"); #Created by rpm
+
+my %ddo_datas = ();
+
+sub main {
+ #
+ # Main Panel
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('ddo_title');
+ my $modul = '';
+
+ $ddo_datas{first} = 'ddo_Intro';
+ $ddo_datas{trt} = 'LIST';
+
+ my @domains = get_domain_table($c);
+ my $empty = ( scalar @domains == 0 ); #Always be at least one?
+
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ ddo_datas => \%ddo_datas,
+ domains => \@domains,
+ empty => $empty
+ );
+
+ $c->render( template => 'dungog_domains' );
+
+}
+
+sub do_Save {
+
+ #
+ # Save pressed
+ #
+ # Just Save data, restart email and log success
+ # .. and return to main panel
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('ddo_title');
+ my $modul = '';
+ my $domain = $c->param("domain");
+ #die("Save:$domain");
+
+ # Save it in here..
+ my $trt = $c->param("trt");
+ if ( $trt eq "SERVER" ) {
+ my $MailServer = $c->param('MailServer') || '';
+ #die($MailServer);
+ unless ( $MailServer eq 'skipMS' ) {
+ if ( $MailServer eq '' ) {
+ $domaindb->delete_prop( $domain, 'MailServer' );
+ }
+ else {
+ $domaindb->set_prop( $domain, 'MailServer', $MailServer );
+ }
+ }
+
+ system( "/sbin/e-smith/signal-event", "email-update" ) == 0
+ or die("Error occurred while restarting email.\n");
+ }
+ elsif ( $trt eq 'OPTIONS' ) {
+ my $owner = $c->param('Owner');
+ my $group = $c->param('Group');
+
+ #Check exists and create if necessary
+ my $rec = $dungogdb->get($domain)
+ || $dungogdb->new_record( $domain, { type => 'domain' } );
+ $dungogdb->set_prop( $domain, 'owner', $owner );
+ $dungogdb->set_prop( $domain, 'group', $group );
+ }
+ elsif ( $trt eq 'EMAIL' ) {
+ my $resmsg = perform_pseudo_save($c);
+ if ( $resmsg ne "ok" ) {
+ $ddo_datas{error} = $resmsg; #Error Message
+ do_AddPseudo($c);
+ return
+ } else {
+ $ddo_datas{success} = 'ddo_SUCCESS';
+ do_Email($c);
+ return
+ }
+
+ }
+ $ddo_datas{success} = 'ddo_SUCCESS';
+ $ddo_datas{trt} = 'LIST';
+ my @domains = get_domain_table($c);
+ my $empty = ( scalar @domains == 0 ); #Always be at least one?
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ ddo_datas => \%ddo_datas,
+ domains => \@domains,
+ empty => $empty
+ );
+ $c->render( template => 'dungog_domains' );
+
+}
+
+sub perform_pseudo_save {
+ #
+ # Save or create a new pseudonymn
+ # mode = new or modify
+ my $c = shift;
+ my $domain = $c->param('domain');
+ my $acct = $c->param('LocalAccount');
+ my $pseu = $c->param('pseudo');
+ my $Pseudonym = "$pseu\@$domain";
+ my $mode = $c->param('mode') | 'modify';
+ my $oldpseudo = $c->param('oldpseudo');
+
+ # get all pseudonyms for this domain
+ my @vdemail = ();
+ foreach my $account ( $adb->get_all_by_prop($domain,type=>'pseudonym') ) {
+ push( @vdemail, $account->key );
+ }
+
+ #don't overwite existing users
+ if ( $mode eq 'new' ) {
+ foreach (@vdemail) {
+ if ( $_ eq $pseu ) {
+ return 'ddo_pseudo_already_exists';
+ }
+ }
+ }
+
+ if ( $pseu =~ /^([a-zA-Z0-9][\-\_\.a-zA-Z0-9]*)$/ ) {
+ $pseu = $1;
+ }
+ else {
+ return $c->l( 'ddo_pseudo_unexpected_character', $pseu );
+ }
+
+ if ( $acct eq '' ) {
+ return 'ddo_need_local_account';
+ }
+
+ #Create it if necessary
+ my $rec = $adb->get($Pseudonym)
+ || $adb->new_record( $Pseudonym, { type => 'pseudonym' } );
+
+ $adb->set_prop( $Pseudonym, 'Account', $acct );
+
+ #we changed the Pseudonym, so delete the old
+ if ($oldpseudo ne ''){
+ if ( $mode eq 'modify' and $oldpseudo ne $pseu) {
+ my $delpseudo = "$oldpseudo\@$domain";
+ if (my $delkey = $adb->get($delpseudo)) {
+ $delkey->delete or die("Unable to delete $Pseudonym from accounts:".$delkey->key);
+ }
+ }
+ }
+ return "ok";
+}
+
+sub do_Email {
+
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my %ddo_datas = ();
+ my $title = $c->l('ddo_Email_Title');
+ my $modul = '';
+
+ my $domain = $c->param("domain");
+ my $MailServer = $domaindb->get_prop($domain, 'MailServer');
+ my @pseudos = get_domain_pseudonyms( $c, $domain );
+ my $empty = ( scalar @pseudos == 0 );
+ $ddo_datas{trt} = 'EMAIL';
+ $ddo_datas{mailserver} = $MailServer;
+
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ ddo_datas => \%ddo_datas,
+ pseudos => \@pseudos,
+ empty => $empty
+ );
+ $c->render( template => 'dungog_domains' );
+}
+
+sub do_Options {
+
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('ddo_modify_options_TITLE');
+ my $modul = '';
+
+ #Data for selection controls
+ my $domain = $c->param("domain");
+ my $owner = $dungogdb->get_prop( $domain, "owner" ) || 'admin';
+ my $group = $dungogdb->get_prop( $domain, "group" ) || 'everyone';
+ if ( $group eq 'Administrator' ) {
+ $group = $owner;
+ }
+
+ my @userlist = ( 'admin', 'everyone' );
+ my @grouplist = ( 'everyone', 'Administrator' );
+ push( @userlist, '-- groups --' );
+ foreach ( sort $adb->get_all_by_prop( type => 'group' ) ) {
+ push( @userlist, $_->key );
+ push( @grouplist, $_->key );
+
+ }
+ push( @userlist, '-- users --' );
+ foreach ( sort $adb->get_all_by_prop( type => 'user' ) ) {
+ push( @userlist, $_->key );
+ }
+
+ $ddo_datas{trt} = 'OPTIONS';
+ $ddo_datas{owner} = $owner;
+ $ddo_datas{group} = $group;
+
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ ddo_datas => \%ddo_datas,
+ grouplist => \@grouplist,
+ userlist => \@userlist
+ );
+ $c->render( template => 'dungog_domains' );
+}
+
+sub do_DelPseudo {
+ #
+ # Delete pseudonym
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('ddo_title');
+ my $modul = '';
+
+ # Delete it in here..
+ my $pseu = $c->param('pseudo');
+ my $domain = $c->param('domain');
+ my $Pseudonym = "$pseu\@$domain";
+
+ my $delkey = $adb->get("$Pseudonym") or die("Unable to find $Pseudonym in accounts");
+ $delkey->delete or die("Unable to delete $Pseudonym from accounts:".$delkey->key);
+
+ $ddo_datas{success} = 'ddo_Delete_successful';
+ $ddo_datas{trt} = 'EMAIL';
+
+ do_Email($c);
+}
+
+sub do_AddPseudo {
+ #
+ # Add or edit pseudonym
+ #
+
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('ddo_Edit_Title');
+ my $modul = '';
+ my $domain = $c->param("domain");
+ my @accts = get_accts( $c, $domain );
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ ddo_datas => \%ddo_datas,
+ accts => \@accts
+ );
+ $ddo_datas{trt} = 'ADD';
+ $c->render( template => 'dungog_domains' );
+
+}
+
+sub get_domain_pseudonyms {
+ my ( $c, $domain ) = @_;
+
+ # get all pseudonyms
+ my @vdemail = ();
+
+ foreach my $record ( $adb->get_all_by_prop( type => 'pseudonym' ) ) {
+ my $key = $record->key;
+ push( @vdemail, $key );
+ }
+
+ # find email for this domain
+ my @vdemail2 = ();
+ foreach (@vdemail) {
+ ( my $u, my $d ) = split( /@/, $_ );
+ my $acct = $adb->get_prop( "$_", "Account" ) || '';
+ my %thisrow = ( 'Pseudonym' => $u, "user" => $acct );
+ push( @vdemail2, \%thisrow ) if ( $d eq $domain );
+ }
+
+ return @vdemail2;
+
+}
+
+sub get_domain_table {
+ #
+ # Return full table of all domains OR just the details for the specified one
+ #
+ my ( $c, $findDomain ) = @_; #$c and domain to find
+ $findDomain = FALSE if ( scalar(@_) <= 1 );
+ my $key;
+ my @virtualDomains = ();
+ foreach my $domain ( $domaindb->get_all_by_prop( type => 'domain' ) ) {
+ $key = $domain->key;
+ push( @virtualDomains, $key );
+ }
+ my $numDomains = @virtualDomains;
+ if ( $numDomains == 0 ) { return () }
+ else {
+ my $domain;
+ my @virtualDomains2d = ();
+
+ foreach $domain ( sort @virtualDomains ) {
+ my %properties = $domaindb->get($domain)->props;
+ my $test = $domaindb->get_prop( $domain, "dns" ) || '';
+ my $owner = $dungogdb->get_prop( $domain, "owner" ) || 'admin';
+ my $group = $dungogdb->get_prop( $domain, "group" ) || 'everyone';
+ my %thisrow;
+
+ %thisrow = (
+ "Domain" => $domain,
+ "Description" => $properties{'Description'},
+
+ #"Content" => $content,
+ "Delegation" => "$owner" . '::' . "$group"
+ );
+ push( @virtualDomains2d, \%thisrow );
+
+ if ($findDomain) {
+ if ( $domain eq $findDomain ) {
+ @virtualDomains2d = (); #Just return matching one
+ push( @virtualDomains2d, \%thisrow );
+ last;
+ }
+ } #Found the one needed
+ }
+ return @virtualDomains2d; #Return the lot
+ }
+}
+
+sub get_accts {
+ my ( $c, $domain ) = @_;
+ my $owner = $dungogdb->get_prop( $domain, "owner" ) || '';
+ my $group = $dungogdb->get_prop( $domain, "group" ) || 'everyone';
+ my @selected = [];
+ my $userlist = $adb->get_prop($group,"Members") || '';
+ if ( $group eq 'everyone' ) {
+ my @acctrecs = $adb->get_all_by_prop( type => "user" );
+ foreach my $acct (@acctrecs) {
+ push( @selected, $acct->key )
+ }
+ }
+ elsif ( $group eq 'Administrator' ) {
+ @selected = ($owner);
+ }
+ else {
+ @selected = split( /,/, $userlist );
+ }
+ return sort @selected;
+}
+
+1;
diff -urN smeserver-domains-1.4.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dungog_domains/en.pm smeserver-domains-1.4/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dungog_domains/en.pm
--- smeserver-domains-1.4.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dungog_domains/en.pm 1970-01-01 01:00:00.000000000 +0100
+++ smeserver-domains-1.4/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dungog_domains/en.pm 2020-07-22 09:09:00.000000000 +0100
@@ -0,0 +1,65 @@
+package SrvMngr::I18N::Modules::Dungog_domains::en;
+use strict;
+use warnings;
+use utf8;
+use Mojo::Base 'SrvMngr::I18N';
+
+use SrvMngr::I18N::Modules::General::en;
+
+my %lexicon = (
+'ddo_title' =>'Domain Pseudonyms',
+'ddo_Final_Save' => 'Settings saved and email restarted.',
+'ddo_Intro' => 'Set pseudonyms specifically for a single domain,
This panel just shows the pseudonyms for a each single domain.
See also the Pseudonyms panel to set global pseudonyms.
Documentation: https://wiki.contribs.org/Domains',
+'ddo_Current_List' => 'Current List of Domains.',
+'ddo_Mail_Delivery' => ' Mail Delivery',
+'ddo_Delegation' => 'Delegation',
+'ddo_Need_Save' => 'Save Settings
Pseudonym settings are not activated until you save them here',
+'ddo_Delegate_Domain' => 'Delegate the domain "[_1]"
+Forward all email for this domain to a remote mailserver, either use a FQDN mail.domain.net or an IP address. Or leave blank and forward domain specific pseudonyms below.
+CAUTION. enable your remote server before delegating or you may create a mail loop.',
+'ddo_Server_or_IP' => 'Server Name or IP',
+'ddo_No_Pseudonyms' => 'There are no pseudonyms for the domain "[_1]"',
+'ddo_Click_Here' => 'Click here',
+'ddo_Click_Here_first' => ' to add your first pseudonym.',
+'ddo_Click_Here_add' => ' to add another pseudonym.',
+'ddo_Domain_Name' => 'Domain Name:[_1]',
+'ddo_Alternative_Admin_description' => 'The alternative administrator is used delegate a domain to a user or group.
+They can then add email addresses with userpanel-domains
+First delegate them here, then delegate the userpanel with userpanel access.
+For full access delegate this panel, dungog-domains.',
+'ddo_Alternative_Admin' => 'Alternative administrator:',
+'ddo_Restrict' => 'Restrict the userlist in the email dropdown box to the Administrator or members of a group',
+'ddo_Alternative_Group' => 'Alternative group:',
+'ddo_SUCCESS' => 'Successfully modified domain [_1].',
+'ddo_NO_DOMAINS' => 'The are no domains in the system',
+'ddo_Current_list_for' => 'Current List of pseudonyms for the domain "[_1]"',
+'ddo_No_pseudonyms_for' => 'There are no pseudonyms for the domain "[_1]"',
+'ddo_Email_Title' => 'Modify Domain Email',
+'ddo_Edit_Title' => 'Modify Email Address',
+'ddo_Local_User' => 'Local User',
+'ddo_Pseudonyms' => 'Pseudonyms',
+'ddo_Pseudonym' => 'Pseudonym',
+'ddo_ENTER_a_pseudonym' => 'Enter a pseudonym.
NOTE. @[_1] is added for you.',
+'ddo_Delete_successful' =>'Successfully removed Pseudonym.',
+'ddo_pseudo_already_exists' => 'Error: Pseudonym already exists.',
+'ddo_pseudo_unexpected_character'=>'Error: unexpected characters in Pseudonym [_1]',
+'ddo_need_local_account' => "Error: please select a local account.",
+'ddo_modify_options_TITLE'=>'Modify Domain pseudonyms - Options',
+'ddo_alternate delegate'=>'The alternative administrator is used delegate a domain to a user or group.
+They can then add email addresses with userpanel-domains.
+First delegate them here, then delegate the userpanel with userpanel access.
+For full access delegate this panel, dungog-domains.',
+'ddo_alternative_admin' => 'Alternative administrator:',
+'ddo_restrict_to_group'=>'Restrict the userlist in the email dropdown box to the Administrator or members of a group',
+'ddo_Alternative_group'=>'Alternative group:'
+
+
+);
+
+our %Lexicon = (
+ %{ SrvMngr::I18N::Modules::General::en::Lexicon },
+ %lexicon
+);
+
+
+1;
diff -urN smeserver-domains-1.4.old/root/usr/share/smanager/themes/default/templates/dungog_domains.html.ep smeserver-domains-1.4/root/usr/share/smanager/themes/default/templates/dungog_domains.html.ep
--- smeserver-domains-1.4.old/root/usr/share/smanager/themes/default/templates/dungog_domains.html.ep 1970-01-01 01:00:00.000000000 +0100
+++ smeserver-domains-1.4/root/usr/share/smanager/themes/default/templates/dungog_domains.html.ep 2020-07-06 17:19:00.000000000 +0100
@@ -0,0 +1,43 @@
+% layout 'default', title => "Sme server 2 - Domain Pseudonyms", share_dir => './';
+
+% content_for 'module' => begin
+
+ %= dumper $c->current_route +
+ % } + ++ %=l 'DOMAIN' + | ++ %=l 'DESCRIPTION' + | ++ %=l 'ddo_Mail_Delivery' + | ++ %=l 'ddo_Delegation' + | +
---|---|---|---|
+ "><%=l 'MODIFY'%> + | + % my $delegation = $domain->{"Delegation"}; ++ "><%=l $delegation%> + | +
+ %=l 'ddo_Pseudonyms' + | ++ %=l 'ddo_Local_User' + | ++ | ++ | +
---|---|---|---|
+ <%=l 'MODIFY'%> + | ++ <%=l 'REMOVE'%> + | +