initial commit of file from CVS for smeserver-domains on Sat Sep 7 20:20:35 AEST 2024

This commit is contained in:
Trevor Batley 2024-09-07 20:20:35 +10:00
parent 473793e265
commit 484fb3201d
16 changed files with 2331 additions and 2 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.rpm
*.log
*spec-20*
*.tar.gz

21
Makefile Normal file
View File

@ -0,0 +1,21 @@
# Makefile for source rpm: smeserver-domains
# $Id: Makefile,v 1.1 2020/06/10 08:54:29 brianr Exp $
NAME := smeserver-domains
SPECFILE = $(firstword $(wildcard *.spec))
define find-makefile-common
for d in common ../common ../../common ; do if [ -f $$d/Makefile.common ] ; then if [ -f $$d/CVS/Root -a -w $$/Makefile.common ] ; then cd $$d ; cvs -Q update ; fi ; echo "$$d/Makefile.common" ; break ; fi ; done
endef
MAKEFILE_COMMON := $(shell $(find-makefile-common))
ifeq ($(MAKEFILE_COMMON),)
# attept a checkout
define checkout-makefile-common
test -f CVS/Root && { cvs -Q -d $$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
endef
MAKEFILE_COMMON := $(shell $(checkout-makefile-common))
endif
include $(MAKEFILE_COMMON)

View File

@ -1,3 +1,18 @@
# smeserver-domains
# <img src="https://www.koozali.org/images/koozali/Logo/Png/Koozali_logo_2016.png" width="25%" vertical="auto" style="vertical-align:bottom"> smeserver-domains
SMEServer Koozali developed git repo for smeserver-domains smecontribs
## Wiki
<br />https://wiki.koozali.org/Lat-domains
<br />https://wiki.koozali.org/Domains
<br />https://wiki.koozali.org/Koozali_Foundation_Domains
<br />https://wiki.koozali.org/Esmith::FormMagick::Panel::domains
## Bugzilla
Show list of outstanding bugs: [here](https://bugs.koozali.org/buglist.cgi?component=smeserver-domains&product=SME%20Contribs&query_format=advanced&limit=0&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=CONFIRMED)
## Description
<br />*This description has been generated by an LLM AI system and cannot be relied on to be fully correct.*
*Once it has been checked, then this comment will be deleted*
<br />

340
additional/COPYING Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

1
contriborbase Normal file
View File

@ -0,0 +1 @@
contribs10

23
createlinks Normal file
View File

@ -0,0 +1,23 @@
#! /usr/bin/perl -w
use esmith::Build::CreateLinks qw(:all);
# our event specific for updating with yum without reboot
$event = 'smeserver-domains-update';
#add here the path to your templates needed to expand
#see the /etc/systemd/system-preset/49-koozali.preset should be present for systemd integration on all you yum update event
foreach my $file (qw(
/etc/systemd/system-preset/49-koozali.preset
))
{
templates2events( $file, $event );
}
#action needed in case we have a systemd unit
event_link('systemd-default', $event, '10');
event_link('systemd-reload', $event, '50');
#action specific to this package
#event_link('action', $event, '30');
#services we need to restart
#safe_symlink('restart',root/etc/e-smith/events/$event/services2adjust/service);
#and Server Manager panel link
panel_link("dungog-domains", 'manager');
# safe_symlink("../../../functions/dungog-domains", "root/etc/e-smith/web/panels/manager/cgi-bin/dungog-domains");

View File

@ -0,0 +1,620 @@
#!/usr/bin/perl -wT
#----------------------------------------------------------------------
# heading : Administration
# description : Domain pseudonyms
# navigation : 4000 4736
#
# Author dungog.net
#
#----------------------------------------------------------------------
package esmith;
use strict;
use CGI ':all';
use CGI::Carp qw(fatalsToBrowser);
use esmith::cgi;
use esmith::config;
use esmith::util;
use esmith::db;
sub showInitial ($$); #main form
sub performSave ($);
sub modifyOptions ($$); #vd authority and options
sub performModifyOptions ($);
sub modifyEmail ($$); #vd email
sub editEmail ($$);
sub performModifyEmail ($);
sub removeEmail ($);
BEGIN
{
# Clear PATH and related environment variables so that calls to
# external programs do not cause results to be tainted. See
# "perlsec" manual page for details.
$ENV {'PATH'} = '/usr/sbin:/usr/bin:/usr/local/bin';
$ENV {'SHELL'} = '/bin/bash';
delete $ENV {'ENV'};
}
esmith::util::setRealToEffective ();
$CGI::POST_MAX=1024 * 100; # max 100K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
my %conf;
tie %conf, 'esmith::config';
my %accounts;
tie %accounts, 'esmith::config', '/home/e-smith/db/accounts';
my %domains;
tie %domains, 'esmith::config', '/home/e-smith/db/domains';
my %dungog;
tie %dungog, 'esmith::config', '/home/e-smith/db/dungog';
#------------------------------------------------------------
# examine state parameter and display the appropriate form
#------------------------------------------------------------
my $q = new CGI;
if (! grep (/^state$/, $q->param))
{
showInitial ($q, '');
}
elsif ($q->param ('state') eq "save")
{
performSave ($q);
}
#options
elsif ($q->param ('state') eq "modifyOptions")
{
modifyOptions ($q, '');
}
elsif ($q->param ('state') eq "performModifyOptions")
{
performModifyOptions ($q);
}
#pseudonyms
elsif ($q->param ('state') eq "email")
{
modifyEmail ($q, '');
}
elsif ($q->param ('state') eq "edit")
{
editEmail ($q, '');
}
elsif ($q->param ('state') eq "performEmail")
{
performModifyEmail ($q);
}
elsif ($q->param ('state') eq "remove")
{
removeEmail ($q);
}
else
{
esmith::cgi::genStateError ($q, \%conf);
}
exit (0);
#########################################################################
sub showInitial ($$)
{
my ($q, $msg) = @_;
my @domains = db_get(\%domains);
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Domain pseudonyms');
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Domain pseudonyms');
print $q->h4 ('Operation status report');
print $q->p ($msg);
print $q->hr;
}
print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
print $q->p ('Set pseudonyms for a single domain,<br>
This panel just shows the pseudonyms for a single domain.<br>
see also the <a href="pseudonyms">Pseudonyms</a> panel.');
my $numDomains = @domains;
if ($numDomains == 0)
{
print $q->p ($q->b ('There are no virtual domains in the system.'));
}
else
{
print $q->p ($q->b ("Current List of Domains."));
print "<table border=1 cellspacing=1 cellpadding=4>";
print $q->Tr (esmith::cgi::genSmallCell ($q, $q->b ('Domain')),
esmith::cgi::genSmallCell ($q, $q->b ('Description')),
esmith::cgi::genSmallCell ($q, $q->b ('Mail Delivery')),
esmith::cgi::genSmallCell ($q, $q->b ('Delegation')));
my $domain;
foreach $domain (sort @domains)
{
my $desc = db_get_prop(\%domains, $domain, "Description") || '';
my $owner = db_get_prop(\%dungog, $domain, "owner") || 'admin';
my $group = db_get_prop(\%dungog, $domain, "group") || 'everyone';
if ($group eq 'Administrator')
{
$group = $owner;
}
print $q->Tr (esmith::cgi::genSmallCell ($q, $domain),
esmith::cgi::genSmallCell ($q, $desc),
esmith::cgi::genSmallCell ($q,
$q->a ({href => $q->url (-absolute => 1)
. "?state=email&domain="
. $domain}, 'Modify ...')),
esmith::cgi::genSmallCell ($q,
$q->a ({href => $q->url (-absolute => 1)
. "?state=modifyOptions&domain="
. $domain}, $owner.'::'.$group)));
}
print '</table>';
}
print $q->p ($q->b ("Save Settings"));
print $q->p ("Pseudonym settings are not activated until you save them here");
print $q->Tr (esmith::cgi::genButtonRow ($q,
$q->submit (-name => 'action',
-value => 'Save')));
print $q->hidden (-name => 'MailServer', -override => 1, -default => 'skipMS');
print $q->hidden (-name => 'state', -override => 1, -default => 'save');
print $q->endform;
print $q->p ($q->hr, $q->font ({size => "-1"}, "Copyright dungog.net"));
print '</FONT>';
print '</DIV>';
print $q->end_html;
}
sub modifyOptions ($$)
{
my ($q, $msg) = @_;
my $domain = $q->param ('domain') || '';
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify Domain pseudonyms - Options.');
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify Domain pseudonyms - Options.');
print $q->h4 ('Operation status report');
print $q->p ($msg);
print $q->hr;
}
print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
# find system users
my @userlist = ('admin','everyone');
push (@userlist, '-- groups --');
foreach (sort keys %accounts)
{
push (@userlist, $_)
if (db_get_type(\%accounts, $_) eq 'group');
}
push (@userlist, '-- users --');
foreach (sort keys %accounts)
{
push (@userlist, $_)
if (db_get_type(\%accounts, $_) eq 'user');
}
my @grouplist = ('everyone','Administrator');
foreach (keys %accounts)
{
push (@grouplist, $_)
if (db_get_type(\%accounts, $_) eq 'group');
}
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
$q->Tr (esmith::cgi::genCell ($q, "Domain name:"),
esmith::cgi::genCell ($q, $domain)),
esmith::cgi::genTextRow ($q, 'The alternative administrator is used delegate a domain to a user or group.
<br>They can then add email addresses with userpanel-domains
<br>First delegate them here, then delegate the userpanel with userpanel access.
<br>For full access delegate this panel, dungog-domains.'),
esmith::cgi::genWidgetRow ($q, "Alternative administrator",
$q->popup_menu (-name => "owner",
-values => [ @userlist ],
-default => db_get_prop(\%dungog, $domain, "owner") || 'admin')),
esmith::cgi::genTextRow ($q, "Restrict the userlist in the email dropdown box to the Administrator or members of a group. "),
esmith::cgi::genWidgetRow ($q, "Alternative group",
$q->popup_menu (-name => "group",
-values => [ sort @grouplist ],
-default => db_get_prop(\%dungog, $domain, "group") || 'everyone')),
esmith::cgi::genButtonRow ($q,
$q->submit (-name => 'action',
-value => 'Modify')));
print $q->hidden (-name => 'domain', -override => 1, -default => $domain);
print $q->hidden (-name => 'state', -override => 1, -default => 'performModifyOptions');
print $q->endform;
print $q->p ($q->hr, $q->font ({size => "-1"}, "Copyright dungog.net"));
print '</FONT>';
print '</DIV>';
print $q->end_html;
}
#------------------------------------------------------------
# Modify Domain
#------------------------------------------------------------
sub performModifyOptions ($)
{
my ($q) = @_;
my $domain = $q->param ('domain');
my $owner = $q->param ('owner');
my $group = $q->param ('group');
unless (exists $dungog {$domain})
{
db_set(\%dungog, $domain, 'domain');
}
db_set_prop(\%dungog, $domain, 'owner', $owner);
db_set_prop(\%dungog, $domain, 'group', $group);
showInitial ($q, "Successfully modified domain <b>$domain</b>.");
}
#------------------------------------------------------------
# modify email
#------------------------------------------------------------
sub modifyEmail ($$)
{
my ($q, $msg) = @_;
my $domain = $q->param ('domain');
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify domain Email.');
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify domain Email.');
print $q->h4 ('Operation status report');
print $q->p ($msg);
print $q->hr;
}
print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
#commom with userpanel
print $q->p ($q->b ("Delegate the domain \"$domain\""));
print $q->Tr (esmith::cgi::genTextRow ($q, '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.<br>
CAUTION. enable your remote server before delegating or you may create a mail loop.'));
print '<p>';
print $q->Tr (esmith::cgi::genNameValueRow ($q,"Server Name or IP",
"MailServer",
db_get_prop(\%domains, $domain, "MailServer") || ''));
# get all pseudonyms
my @vdemail = ();
foreach (keys %accounts)
{
push (@vdemail, $_)
if (db_get_type(\%accounts, $_) eq 'pseudonym');
}
# find email for this domain
my @vdemail2 = ();
foreach (@vdemail)
{
(my $u, my $d) = split (/@/, $_);
push (@vdemail2, $u) if (defined $d and $d eq $domain);
}
#are there any ?
my $vdemail = @vdemail2;
if ($vdemail == 0)
{
print $q->p ($q->b ("There are no pseudonyms for the domain \"$domain\""));
print $q->p ($q->a ({href => $q->url (-absolute => 1) . "?state=edit&domain=$domain&pseu=new2user"},
'Click here'),
'to add your first pseudonym.');
}
else
{
print $q->p ($q->b ("Current List of pseudonyms for the domain \"$domain\""));
print $q->p ($q->a ({href => $q->url (-absolute => 1) . "?state=edit&domain=$domain&pseu=new2user"},
'Click here'),
"to add another pseudonym.");
print "<table border=1 cellspacing=1 cellpadding=4>";
print $q->Tr (esmith::cgi::genSmallCell ($q, $q->b ('Pseudonyms')),
esmith::cgi::genSmallCell ($q, $q->b ('Local user')),
$q->td ('&nbsp;'),
$q->td ('&nbsp;'));
foreach my $pseu (sort @vdemail2)
{
my $acct = db_get_prop(\%accounts, "$pseu\@$domain", "Account") || '';
print $q->Tr (esmith::cgi::genSmallCell ($q, $pseu),
esmith::cgi::genSmallCell ($q, $acct),
esmith::cgi::genSmallCell ($q,
$q->a ({href => $q->url (-absolute => 1)
. "?state=edit&domain=$domain&acct=$acct&pseu=$pseu"}, 'Modify...')),
esmith::cgi::genSmallCell ($q,
$q->a ({href => $q->url (-absolute => 1)
. "?state=remove&domain=$domain&pseu=$pseu"}, 'Remove...')));
}
print '</table>';
}
print $q->p ($q->b ("Save Settings"));
print $q->p ("Pseudonym settings are not activated until you save them here");
print $q->Tr (esmith::cgi::genButtonRow ($q,
$q->submit (-name => 'action',
-value => 'Save')));
print $q->hidden (-name => 'state', -override => 1, -default => 'save');
print $q->hidden (-name => 'domain', -override => 1, -default => $domain);
print $q->endform;
print $q->p ($q->hr, $q->font ({size => "-1"}, "Copyright dungog.net"));
print '</FONT>';
print '</DIV>';
print $q->end_html;
}
#------------------------------------------------------------
# Edit Email address
#------------------------------------------------------------
sub editEmail ($$)
{
my ($q, $msg) = @_;
my $domain = $q->param ('domain');
my $acct = $q->param ('acct') || '';
my $pseu = $q->param ('pseu') || '';
my $user1 = $q->param ('pseu');
my $newuser = '';
if ($pseu eq 'new2user')
{
$newuser = 'new';
$pseu = '';
}
# find system users in group
#my $owner = $ENV{'REMOTE_USER'}; #userpanel
my $owner = db_get_prop(\%dungog, $domain, "owner") || '';
my $group = db_get_prop(\%dungog, $domain, "group") || 'everyone';
my @selected ;
my $userlist = db_get_prop(\%accounts, $group, 'Members') || '';
if ($group eq 'everyone')
{
foreach (keys %accounts)
{
push (@selected, $_)
if (db_get_type(\%accounts, $_) eq 'user');
}
}
elsif ($group eq 'Administrator')
{
@selected = ($owner);
}
else
{
@selected = split (/,/, $userlist);
}
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify Email Address.');
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify Email Address.');
print $q->h4 ('Operation status report');
print $q->p ($msg);
print $q->hr;
}
my @sorted = sort @selected;
print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
$q->Tr (esmith::cgi::genCell ($q, "Domain name:"),
esmith::cgi::genCell ($q, $domain)),
esmith::cgi::genTextRow ($q, "Enter a pseudonym. <br>".
"NOTE. \@$domain is added for you."),
esmith::cgi::genNameValueRow ($q, "Pseudonym",
"pseu",
$pseu ,),
esmith::cgi::genWidgetRow ($q, "Local Account",
$q->popup_menu (-name => "acct",
-values => [ '', @sorted ],
-default => $acct )),
esmith::cgi::genButtonRow ($q, $q->submit (-name => 'action',
-value => 'Save')));
print $q->hidden (-name => 'domain', -override => 1, -default => $domain);
print $q->hidden (-name => 'user1', -override => 1, -default => $user1);
print $q->hidden (-name => 'newuser', -override => 1, -default => $newuser);
print $q->hidden (-name => 'state', -override => 1, -default => 'performEmail');
print $q->endform;
print $q->p ($q->hr, $q->font ({size => "-1"}, "Copyright dungog.net"));
print '</FONT>';
print '</DIV>';
print $q->end_html;
}
sub performModifyEmail ($)
{
my ($q) = @_;
my $domain = $q->param ('domain');
my $acct = $q->param ('acct');
my $pseu = $q->param ('pseu');
my $Pseudonym = "$pseu\@$domain";
my $user1 = $q->param ('user1');
my $newuser = $q->param ('newuser');
# get all pseudonyms
my @vdemail = ();
foreach (keys %accounts)
{
push (@vdemail, $_)
if (db_get_type(\%accounts, $_) eq 'pseudonym');
}
#don't overwite existing users
if ($newuser eq 'new2user')
{
foreach (@vdemail)
{
if ($_ eq $Pseudonym)
{
editEmail ($q, "Error: Pseudonym already exists.");
return;
}
}
}
if ($pseu =~ /^([a-zA-Z0-9][\-\_\.a-zA-Z0-9]*)$/)
{
$pseu = $1;
}
else
{
editEmail ($q, "Error: unexpected characters in Pseudonym, \"$pseu\".");
return;
}
if ($acct eq '')
{
editEmail ($q, "Error: please select a local account.");
return;
}
unless (exists $accounts {$Pseudonym})
{
db_set(\%accounts, $Pseudonym, 'pseudonym');
}
db_set_prop(\%accounts, $Pseudonym, 'Account', $acct);
#we changed the Pseudonym, so delete the old
if ($user1 ne $pseu)
{
db_delete(\%accounts, "$user1\@$domain");
}
showInitial ($q, "Successfully modified Pseudonym.\n");
#showInitial ($q, "Successfully modified Pseudonym for $domain." ,"$domain");
}
sub removeEmail ($)
{
my ($q) = @_;
my $pseu = $q->param ('pseu');
my $domain = $q->param ('domain');
my $Pseudonym = "$pseu\@$domain";
db_delete(\%accounts, $Pseudonym);
showInitial ($q, "Successfully removed Pseudonym.");
#showInitial ($q, "Successfully removed Pseudonym for $domain." ,"$domain");
}
sub performSave ($)
{
my ($q) = @_;
my $domain = $q->param ('domain');
my $MailServer = $q->param ('MailServer') || '';
unless ($MailServer eq 'skipMS')
{
if ($MailServer eq '')
{
db_delete_prop(\%domains, $domain, 'MailServer');
}
else
{
db_set_prop(\%domains, $domain, 'MailServer', $MailServer);
}
}
system ("/sbin/e-smith/signal-event", "email-update") == 0
or die ("Error occurred while restarting email.\n");
showInitial ($q, "Settings saved and email restarted.");
#showInitial ($q, "Settings saved and email restarted." ,"$domain");
}

View File

@ -0,0 +1,486 @@
#!/usr/bin/perl -wT
#----------------------------------------------------------------------
# heading : Your Settings
# description : Domain pseudonyms
# longdesc : Manage domain specific pseudonyms
# navigation : 100 453
#
# Author Stephen Noble dungog.net
#
#----------------------------------------------------------------------
package esmith;
use strict;
use CGI ':all';
use CGI::Carp qw(fatalsToBrowser);
use esmith::cgi;
use esmith::config;
use esmith::util;
use esmith::db;
sub showInitial ($$$); #main form
sub performSave ($);
sub editEmail ($$);
sub performModifyEmail ($);
sub removeEmail ($);
sub performSelect ($);
BEGIN
{
# Clear PATH and related environment variables so that calls to
# external programs do not cause results to be tainted. See
# "perlsec" manual page for details.
$ENV {'PATH'} = '/usr/sbin:/usr/bin:/usr/local/bin';
$ENV {'SHELL'} = '/bin/bash';
delete $ENV {'ENV'};
}
esmith::util::setRealToEffective ();
$CGI::POST_MAX=1024 * 100; # max 100K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
my %conf;
tie %conf, 'esmith::config';
my %accounts;
tie %accounts, 'esmith::config', '/home/e-smith/db/accounts';
my %domains;
tie %domains, 'esmith::config', '/home/e-smith/db/domains';
my %dungog;
tie %dungog, 'esmith::config', '/home/e-smith/db/dungog';
#------------------------------------------------------------
# examine state parameter and display the appropriate form
#------------------------------------------------------------
my $q = new CGI;
if (! grep (/^state$/, $q->param))
{
showInitial ($q, '', '');
}
elsif ($q->param ('state') eq "save")
{
performSave ($q);
}
elsif ($q->param ('state') eq "edit")
{
editEmail ($q, '');
}
elsif ($q->param ('state') eq "performEmail")
{
performModifyEmail ($q);
}
elsif ($q->param ('state') eq "remove")
{
removeEmail ($q);
}
elsif ($q->param ('state') eq "select")
{
performSelect ($q);
}
else
{
esmith::cgi::genStateError ($q, \%conf);
}
exit (0);
#------------------------------------------------------------
sub showInitial ($$$)
{
my ($q, $msg, $passdomain) = @_;
my $acct = $ENV{'REMOTE_USER'};
my @domains = ();
my $domain = '';
my $userlist = '';
my @selected1 = ();
# find domains for this owner
foreach my $dom (keys %dungog)
{
if (db_get_type(\%dungog, $dom) eq 'domain')
{
my $owner = db_get_prop(\%dungog, $dom, "owner") || '';
if ($owner eq $acct || $owner eq 'everyone')
{
push (@domains, $dom);
$domain = $dom;
}
#or a member of a group
$userlist = db_get_prop(\%accounts, $owner, 'Members') || '';
@selected1 = split (/,/, $userlist);
foreach my $user (@selected1)
{
if ($user eq $acct)
{
push (@domains, $dom);
$domain = $dom;
}
}
}
}
#change to a passed value
if ($passdomain ne '')
{
$domain = $passdomain;
}
# find system users in group
my $group = db_get_prop(\%accounts, $domain, "group") || 'everyone';
my $userlist2 = db_get_prop(\%accounts, $group, 'Members') || '';
my @selected2 ;
if ($group eq 'everyone')
{
foreach (keys %accounts)
{
push (@selected2, $_)
if (db_get_type(\%accounts, $_) eq 'user');
}
}
elsif ($group eq 'Administrator')
{
@selected2 = ($acct);
}
else
{
@selected2 = split (/,/, $userlist2);
}
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, "Domain pseudonyms. ");
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, "Domain pseudonyms. ");
print $q->h4 ('Operation status report');
print $q->p ($msg);
print $q->hr;
}
print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
#are there any ?
my $domains = @domains;
if ($domains == 0)
{
print $q->p ($q->b ("There are no Domains allocated to user $acct"));
}
else
{
print $q->p ("Pseudonyms for the Domain <b>$domain</b> managed by <b>$acct</b> (" .
db_get_prop(\%accounts, $acct, 'FirstName') . ' ' . db_get_prop(\%accounts, $acct, 'LastName') . ").");
if ($domains > 1)
{
print $q->p ($q->td ("You have multiple domains, you can change below..."));
foreach (@domains)
{
print $q->Tr ($q->td ($q->a ({href => $q->url (-absolute => 1) . "?state=select&swap=$_"},
"$_"), " ; "));
}
}
#commom with userpanel
print $q->p ($q->b ("Delegate the domain \"$domain\""));
print $q->Tr (esmith::cgi::genTextRow ($q, '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 '));
print '<p>';
print $q->Tr (esmith::cgi::genNameValueRow ($q,"Server Name or IP",
"MailServer",
db_get_prop(\%domains, $domain, "MailServer") || '',));
# get all pseudonyms
my @vdemail = ();
foreach (keys %accounts)
{
push (@vdemail, $_)
if (db_get_type(\%accounts, $_) eq 'pseudonym');
}
# find email for this domain
my @vdemail2 = ();
foreach (@vdemail)
{
(my $u, my $d) = split (/@/, $_);
push (@vdemail2, $u) if (defined $d and $d eq $domain);
}
#are there any ?
my $vdemail = @vdemail2;
if ($vdemail == 0)
{
print $q->p ($q->b ("There are no pseudonyms for the domain \"$domain\""));
print $q->p ($q->a ({href => $q->url (-absolute => 1) . "?state=edit&domain=$domain&pseu=new2user"},
'Click here'),
'to add your first pseudonym.');
}
else
{
print $q->p ($q->b ("Current List of pseudonyms for the domain \"$domain\""));
print $q->p ($q->a ({href => $q->url (-absolute => 1) . "?state=edit&domain=$domain&pseu=new2user"},
'Click here'),
"to add another pseudonym.");
print "<table border=1 cellspacing=1 cellpadding=4>";
print $q->Tr (esmith::cgi::genSmallCell ($q, $q->b ('Pseudonyms')),
esmith::cgi::genSmallCell ($q, $q->b ('Local user')),
$q->td ('&nbsp;'),
$q->td ('&nbsp;'));
foreach my $pseu (sort @vdemail2)
{
my $acct = db_get_prop(\%accounts, "$pseu\@$domain", "Account") || '';
print $q->Tr (esmith::cgi::genSmallCell ($q, $pseu),
esmith::cgi::genSmallCell ($q, $acct),
esmith::cgi::genSmallCell ($q,
$q->a ({href => $q->url (-absolute => 1)
. "?state=edit&domain=$domain&acct=$acct&pseu=$pseu"}, 'Modify...')),
esmith::cgi::genSmallCell ($q,
$q->a ({href => $q->url (-absolute => 1)
. "?state=remove&domain=$domain&pseu=$pseu"}, 'Remove...')));
}
print '</table>';
print $q->p ($q->b ("Save Settings"));
print $q->p ("Pseudonym settings are not activated until you save them here");
print $q->Tr (esmith::cgi::genButtonRow ($q,
$q->submit (-name => 'action',
-value => 'Save')));
print $q->hidden (-name => 'state', -override => 1, -default => 'save');
print $q->hidden (-name => 'domain', -override => 1, -default => $domain);
#end common
}
}
}
sub editEmail ($$)
{
my ($q, $msg) = @_;
my $domain = $q->param ('domain');
my $acct = $q->param ('acct') || '';
my $pseu = $q->param ('pseu') || '';
my $user1 = $q->param ('pseu');
my $newuser = '';
if ($pseu eq 'new2user')
{
$newuser = 'new';
$pseu = '';
}
# find system users in group
my $owner = $ENV{'REMOTE_USER'}; #userpanel
# my $owner = db_get_prop(\%dungog, $domain, "owner") || '';
my $group = db_get_prop(\%dungog, $domain, "group") || 'everyone';
my @selected ;
my $userlist = db_get_prop(\%accounts, $group, 'Members') || '';
if ($group eq 'everyone')
{
foreach (keys %accounts)
{
push (@selected, $_)
if (db_get_type(\%accounts, $_) eq 'user');
}
}
elsif ($group eq 'Administrator')
{
@selected = ($owner);
}
else
{
@selected = split (/,/, $userlist);
}
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify Email Address.');
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, 'Modify Email Address.');
print $q->h4 ('Operation status report');
print $q->p ($msg);
print $q->hr;
}
my @sorted = sort @selected;
print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
$q->Tr (esmith::cgi::genCell ($q, "Domain name:"),
esmith::cgi::genCell ($q, $domain)),
esmith::cgi::genTextRow ($q, "Enter a pseudonym. <br>".
"NOTE. The domain name is added for you."),
esmith::cgi::genNameValueRow ($q, "Pseudonym",
"pseu",
$pseu ,),
esmith::cgi::genWidgetRow ($q, "Local Account",
$q->popup_menu (-name => "acct",
-values => [ '', @sorted ],
-default => $acct )),
esmith::cgi::genButtonRow ($q, $q->submit (-name => 'action',
-value => 'Save')));
print $q->hidden (-name => 'domain', -override => 1, -default => $domain);
print $q->hidden (-name => 'user1', -override => 1, -default => $user1);
print $q->hidden (-name => 'newuser', -override => 1, -default => $newuser);
print $q->hidden (-name => 'state', -override => 1, -default => 'performEmail');
print $q->endform;
print $q->p ($q->hr, $q->font ({size => "-1"}, "Copyright dungog.net"));
print '</FONT>';
print '</DIV>';
print $q->end_html;
}
sub performModifyEmail ($)
{
my ($q) = @_;
my $domain = $q->param ('domain');
my $MailServer = $q->param ('MailServer ') || '';
my $acct = $q->param ('acct');
my $pseu = $q->param ('pseu');
my $Pseudonym = "$pseu\@$domain";
my $user1 = $q->param ('user1');
my $newuser = $q->param ('newuser');
# get all pseudonyms
my @vdemail = ();
foreach (keys %accounts)
{
push (@vdemail, $_)
if (db_get_type(\%accounts, $_) eq 'pseudonym');
}
#don't overwite existing users
if ($newuser eq 'new2user')
{
foreach (@vdemail)
{
if ($_ eq $Pseudonym)
{
editEmail ($q, "Error: Pseudonym already exists.");
return;
}
}
}
if ($pseu =~ /^([a-zA-Z0-9][\-\_\.a-zA-Z0-9]*)$/)
{
$pseu = $1;
}
else
{
editEmail ($q, "Error: unexpected characters in Pseudonym, \"$pseu\".");
return;
}
if ($acct eq '')
{
editEmail ($q, "Error: please select a local account.");
return;
}
unless (exists $accounts {$Pseudonym})
{
db_set(\%accounts, $Pseudonym, 'pseudonym');
}
db_set_prop(\%accounts, $Pseudonym, 'Account', $acct);
#we changed the Pseudonym, so delete the old
if ($user1 ne $pseu)
{
db_delete(\%accounts, "$user1\@$domain");
}
showInitial ($q, "Successfully modified Pseudonym for $domain." ,"$domain");
return;
}
sub removeEmail ($)
{
my ($q) = @_;
my $pseu = $q->param ('pseu');
my $domain = $q->param ('domain');
my $Pseudonym = "$pseu\@$domain";
db_delete(\%accounts, $Pseudonym);
showInitial ($q, "Successfully removed Pseudonym for $domain." ,"$domain");
}
sub performSave ($)
{
my ($q) = @_;
my $domain = $q->param ('domain');
my $MailServer = $q->param ('MailServer') || '';
if ($MailServer eq '')
{
db_delete_prop(\%domains, $domain, 'MailServer');
}
else
{
db_set_prop(\%domains, $domain, 'MailServer', $MailServer);
}
system ("/sbin/e-smith/signal-event", "email-update") == 0
or die ("Error occurred while restarting email.\n");
showInitial ($q, "Settings saved and email restarted." ,"$domain");
}
sub performSelect ($)
{
my ($q) = @_;
my $swap = $q->param ('swap');
showInitial ($q, "Domain switched to $swap" ,"$swap");
}

View File

@ -0,0 +1,407 @@
package SrvMngr::Controller::Dungog_domains;
##----------------------------------------------------------------------
## heading : Network
## description : Domain pseudonyms
## navigation : 6000 736
##
## 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;

View File

@ -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,<br>This panel just shows the pseudonyms for a each single domain.<br>See also the <a href="/smanager/pseudonyms">Pseudonyms</a> panel to set global pseudonyms.<br>Documentation: <a href="https://wiki.contribs.org/Domains">https://wiki.contribs.org/Domains</a>',
'ddo_Current_List' => 'Current List of Domains.',
'ddo_Mail_Delivery' => ' Mail Delivery',
'ddo_Delegation' => 'Delegation',
'ddo_Need_Save' => '<strong>Save Settings</strong><br>Pseudonym settings are not activated until you save them here',
'ddo_Delegate_Domain' => 'Delegate the domain "[_1]"<br>
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.<br>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.<br>
They can then add email addresses with userpanel-domains.<br>
First delegate them here, then delegate the userpanel with userpanel access.<br>
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;

View File

@ -0,0 +1,43 @@
% layout 'default', title => "Sme server 2 - Domain Pseudonyms", share_dir => './';
% content_for 'module' => begin
<div id="module" class="module domains-panel">
% if ($config->{debug} == 1) {
<p>
%= dumper $c->current_route
</p>
% }
<h1><%=$title%></h1>
%= $modul
%if ($ddo_datas->{first}) {
%=$c->render_to_string(inline =>$c->l($ddo_datas->{first}))
%} elsif ($ddo_datas->{success}) {
<div class='sme-success'>
<h2> Operation Status Report</h2>
%= $c->l($ddo_datas->{success});
</div>
%} elsif ($ddo_datas->{error}) {
<div class='sme-error'>
<h2> Operation Status Report - error</h2>
%= $c->l($ddo_datas->{error});
</div>
%}
% if ($ddo_datas->{trt} eq 'EMAIL') {
%= include 'partials/_ddo_modify_email'
%} elsif ($ddo_datas->{trt} eq 'OPTIONS') {
%= include 'partials/_ddo_modify_options'
%} elsif ($ddo_datas->{trt} eq 'ADD') {
%= include 'partials/_ddo_add_pseudonym'
%} else {
%= include 'partials/_ddo_domain_list'
%}
</div>
%end

View File

@ -0,0 +1,38 @@
%#
%# Add/edit pseudonym
%#
<div class="">
% my $btn = l('SAVE');
%= form_for '/dungog_domains' => (method => 'POST') => begin
%my $domain = $c->param("domain");
%my $acct = $c->param("acct") || '';
%my $pseudo = $c->param("pseudo") || '';
%=$c->l('ddo_Domain_Name',$domain)
<br>
%=$c->render_to_string(inline =>l('ddo_ENTER_a_pseudonym',$domain))
<br>
<span class=label>
%=l "ddo_Pseudonym"
</span>
<span class=data>
%=text_field 'pseudo' =>$pseudo
%="\@$domain"
</span>
<br><br>
<span class=label>
%=l "ddo_Local_User"
</span>
<span class=data>
% param LocalAccount => "$acct";
%=select_field 'LocalAccount'=>$accts
</span>
%=hidden_field 'domain'=>$domain
%=hidden_field 'acct'=>$acct
%=hidden_field 'trt'=>'EMAIL'
%=hidden_field 'oldpseudo'=>$pseudo
<br>
%= submit_button "$btn", class => 'action'
<br>
% end
</div>

View File

@ -0,0 +1,56 @@
%#
%# Initial Domain list
%#
<div id='ddo_list'>
% my $btn = l('SAVE');
%= form_for '/dungog_domains' => (method => 'POST') => begin
<br>
%=$c->l('ddo_Current_List')
% if ($empty){
<br>
%=l 'ddo_NO_DOMAINS'
% } else {
<table class="sme-border"><tbody>
<tr>
<th class='sme-border'>
%=l 'DOMAIN'
</th>
<th class='sme-border'>
%=l 'DESCRIPTION'
</th>
<th class='sme-border'>
%=l 'ddo_Mail_Delivery'
</th>
<th class='sme-border' '>
%=l 'ddo_Delegation'
</th>
</tr>
% foreach my $domain (@$domains) {
<tr>
%= t td => (class => 'sme-border') => $domain->{"Domain"}
%= t td => (class => 'sme-border') => $domain->{"Description"}
<td class=sme-border>
<a href="/smanager/dungog_domains1?trt=EMAIL&domain=<%= $domain->{"Domain"}%>"><%=l 'MODIFY'%></a>
</td>
% my $delegation = $domain->{"Delegation"};
<td class=sme-border>
<a href="/smanager/dungog_domains2?trt=OPTIONS&domain=<%= $domain->{"Domain"}%>"><%=l $delegation%></a>
</td>
</tr>
%}
</tbody>
</table>
% }
%# This may not be needed - Save from the subservient panels should do the job.
%#=$c->render_to_string(inline =>l('ddo_Need_Save'));
<br>
%#= submit_button "$btn", class => 'action'
<br>
% end
</div>

View File

@ -0,0 +1,73 @@
%#
%# Modify domain email
%#
<div class="ddo_email">
% my $btn = $c->l('SAVE');
% my $MailServer = $ddo_datas->{mailserver};
%= form_for '/dungog_domains' => (method => 'POST') => begin
<br>
% my $domain = $c->param('domain');
%=$c->render_to_string(inline =>l('ddo_Delegate_Domain',$domain))
<br>
<span class=label>
%=l "ddo_Server_or_IP"
</span>
<span class=data>
%=text_field 'MailServer' =>$MailServer
</span>
<br><br>
%if ($empty) {
%=$c->l('ddo_No_pseudonyms_for',$domain);
<br>
<a href="/smanager/dungog_domains3?domain=<%=$domain %>&mode=new"><button type='button'><%= $c->l('ddo_Click_Here')%></button></a>
%=$c->render_to_string(inline=>l('ddo_Click_Here_first'))
<br>
%} else {
%=$c->l('ddo_Current_list_for',$domain);
<br>
<a href="/smanager/dungog_domains3?domain=<%=$domain %>&mode=new"><button type='button'><%= $c->l('ddo_Click_Here')%></button></a>
%=$c->render_to_string(inline=>l('ddo_Click_Here_add'))
<br><br>
%#Table of pseudonyms:
<table class="sme-border"><tbody>
<tr>
<th class='sme-border'>
%=l 'ddo_Pseudonyms'
</th>
<th class='sme-border'>
%=l 'ddo_Local_User'
</th>
<th class='sme-border'>
</th>
<th class='sme-border' '>
</th>
</tr>
% foreach my $pseudo (@$pseudos) {
<tr>
%= t td => (class => 'sme-border') => $pseudo->{"Pseudonym"}
%= t td => (class => 'sme-border') => $pseudo->{"user"}
<td class=sme-border>
<a href="/smanager/dungog_domains3?trt=EMAIL&pseudo=<%= $pseudo->{'Pseudonym'}%>&domain=<%= $domain%>"><%=l 'MODIFY'%></a>
</td>
<td class=sme-border>
<a href="/smanager/dungog_domains4?trt=OPTIONS&pseudo=<%= $pseudo->{'Pseudonym'}%>&domain=<%= $domain%>"><%=l 'REMOVE'%></a>
</td>
</tr>
%}
</tbody>
</table>
%}
%= hidden_field trt=>"SERVER"
%= hidden_field domain=>$domain
<br>
%=$c->render_to_string(inline =>l('ddo_Need_Save'));
<br>
%= submit_button "$btn", class => 'action'
% end
</div>

View File

@ -0,0 +1,35 @@
%#
%# Modify domain options
%#
<div class="ddo_modify_options">
% my $btn = l('SAVE');
% my $domain = $c->param('domain');
% my $group = $ddo_datas->{group};
% my $owner = $ddo_datas->{owner};
%=l('ddo_Domain_Name',$domain)
<br>
%= $c->render_to_string(inline =>l('ddo_alternate delegate'))
%= form_for '/dungog_domains' => (method => 'POST') => begin
<span class=label>
%=l "ddo_Alternative_Admin"
</span>
<span class=data>
% param Owner => "$owner";
%=select_field 'Owner'=>$userlist
</span>
<br>
%= l('ddo_restrict_to_group')
<br>
<span class=label>
%=l "ddo_Alternative_Group"
</span>
<span class=data>
% param Group => "$group";
%=select_field 'Group'=>$grouplist
</span>
%= hidden_field trt=>'OPTIONS'
%= hidden_field domain=>$domain
<br>
%= submit_button "$btn", class => 'action'
% end
</div>

102
smeserver-domains.spec Normal file
View File

@ -0,0 +1,102 @@
%define name smeserver-domains
%define version 1.4
%define release 7
Summary: SMEserver rpm for domain pseudonyms
Name: %{name}
Version: %{version}
Release: %{release}
License: GNU GPL version 2
URL: http://www.contribs.org
Distribution: SME Server
Group: SMEServer/addon
Source: %{name}-%{version}.tar.xz
Packager: Stephen Noble <stephen@dungog.net>
BuildRoot: /var/tmp/%{name}-%{version}
BuildArchitectures: noarch
BuildRequires: e-smith-devtools
Requires: e-smith-release >= 8
AutoReqProv: no
%description
SMEserver rpm for more advanced domain controls
%changelog
* Sat Sep 07 2024 cvs2git.sh aka Brian Read <brianr@koozali.org> 1.4-7.sme
- Roll up patches and move to git repo [SME: 12338]
* Sat Sep 07 2024 BogusDateBot
- Eliminated rpmbuild "bogus date" warnings due to inconsistent weekday,
by assuming the date is correct and changing the weekday.
* Mon Mar 04 2024 Brian Read <brianr@koozali.org> 1.4-6.sme
- Hide SM2 code as not complete [SME: 12497]
* Fri Jan 07 2022 Brian Read <brianr@bjsystems.co.uk> 1.4-5.sme
- Add-class-to-div-for-AdminLTE [SME: 11836]
* Mon May 31 2021 Jean-Philippe Pialasse <tests@pialasse.com> 1.4-4.sme
- fix missing PATH and some log warning [SME: 10950]
* Thu Mar 25 2021 Brian Read <brianr@bjsystems.co.uk> 1.4-3.sme
- Add Update event to createlinks [SME: 10950]
* Thu Mar 25 2021 BogusDateBot
- Eliminated rpmbuild "bogus date" warnings due to inconsistent weekday,
by assuming the date is correct and changing the weekday.
* Wed Jul 22 2020 Brian Read <brianr@bjsystems.co.uk> 1.4-2.sme
- Update for Server-Manager2 panels[SME:10950 ]
* Thu Apr 28 2016 John Crisp <jcrisp@safeandsoundit.co.uk> 0-1.4-1.sme
- First import to smecontribs
* Tue Oct 31 2006 Stephen Noble <support@dungog.net>
- warning added to setup remote MailServer before delegating to them
- [1.2-2]
* Sun Aug 20 2006 Stephen Noble <stephen@dungog.net>
- initial release
- [1.2-1]
%prep
%setup
%build
perl createlinks
%install
rm -rf $RPM_BUILD_ROOT
(cd root ; find . -depth -print | cpio -dump $RPM_BUILD_ROOT)
/sbin/e-smith/genfilelist $RPM_BUILD_ROOT > %{name}-%{version}-filelist
echo "%doc " >> %{name}-%{version}-filelist
%clean
cd ..
rm -rf %{name}-%{version}
%pre
%preun
%post
#new installs
if [ $1 = 1 ] ; then
/bin/touch /home/e-smith/db/dungog
fi
if (systemctl list-unit-files |grep smanager) then
echo "Smanager restart in spec file"
/sbin/e-smith/signal-event smanager-refresh;
fi
%postun
#uninstalls
#&upgrades
%files -f %{name}-%{version}-filelist
%defattr(-,root,root)