initial commit of file from CVS for e-smith-ibays on Wed 12 Jul 08:56:45 BST 2023

This commit is contained in:
Brian Read
2023-07-12 08:56:45 +01:00
parent 7ea7fdccf4
commit 1f503a7f0d
33 changed files with 2751 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
#!/usr/bin/perl -w
use strict;
use esmith::AccountsDB;
use esmith::event;
my $accounts = esmith::AccountsDB->open() or
die "Unable to open accounts db: $!";
my ($self, $groupName) = @ARGV;
# Find all "i-bay" entries in the e-smith accounts database and
# if the group matches this one, change it to group "admin".
my @modified_ibays;
foreach my $ibay ( $accounts->ibays ) {
if ( $ibay->prop('Group') eq $groupName ) {
$ibay->set_prop( 'Group', 'admin' );
push @modified_ibays, $ibay->key;
event_signal("ibay-modify-files", $ibay->key) or
die ("Error occurred while updating i-bay.\n");
}
}
my $count = @modified_ibays;
if ( $count > 0 ) {
event_signal("ibay-modify-servers" ) or
die ("Error occurred after updating i-bays.\n");
}

View File

@@ -0,0 +1,49 @@
#!/bin/sh
#----------------------------------------------------------------------
# copyright (C) 1999-2005 Mitel Networks Corporation
#
# 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
#
#----------------------------------------------------------------------
#------------------------------------------------------------
# Delete the Unix account and files for the ibay.
#------------------------------------------------------------
event=$1
ibay=$2
if [ -z "$ibay" ]
then
echo ibayName argument missing
exit 1
fi
ldapauth=$(/sbin/e-smith/config getprop ldap Authentication || echo disabled)
x=0 # exit value
/bin/rm -rf /home/e-smith/files/ibays/$ibay
if [ "$ldapauth" != "enabled" ]
then
/usr/sbin/userdel "$ibay" || x=1
/usr/sbin/cpu -C/etc/cpu-system.conf userdel "$ibay"
/usr/sbin/cpu -C/etc/cpu-system.conf groupdel "$ibay"
else
/usr/sbin/cpu userdel "$ibay" || x=1
/usr/sbin/cpu -C/etc/cpu-system.conf groupdel "$ibay" || x=1
fi
exit $x

View File

@@ -0,0 +1,232 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 1999-2005 Mitel Networks Corporation
#
# 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
#
#----------------------------------------------------------------------
package esmith;
use strict;
use Errno;
use File::Find;
use esmith::util;
use esmith::templates;
use esmith::AccountsDB;
use esmith::ConfigDB;
my $conf = esmith::ConfigDB->open_ro
or die "Could not open Config DB";
my $ldapauth = $conf->get('ldap')->prop('Authentication') || 'disabled';
my $x = 0; # exit value
$ENV{'PATH'} = "/bin";
my $event = $ARGV [0];
my $ibayName = $ARGV [1];
die "ibayName argument missing" unless defined ($ibayName);
my $accountdb = esmith::AccountsDB->open_ro();
my $ibay = $accountdb->get($ibayName) or
die "Couldn't find $ibayName record in accounts db\n";
die "Account $ibayName is not an ibay account; modify ibay event failed.\n"
unless ($ibay->prop('type') eq 'ibay');
if ($event eq 'ibay-create')
{
#------------------------------------------------------------
# Check the Unix account.
#------------------------------------------------------------
# Create the ibay's unique group first
if ($ldapauth ne 'enabled')
{
system(
"/usr/sbin/groupadd",
"-g",
$ibay->prop("Gid"),
$ibayName
) == 0 or ( $x = 255, warn "Failed to create (unix) group $ibayName.\n" );
system(
"/usr/sbin/useradd",
"-u",
$ibay->prop("Uid"),
"-g",
$ibay->prop("Gid"),
"-c",
$ibay->prop("Name"),
"-d",
"/home/e-smith/files/ibays/$ibayName/files",
"-G",
"shared,"
. $ibay->prop("Group"),
"-M",
"-s",
"/bin/false",
"$ibayName"
) == 0 or ( $x = 255, warn "Failed to create (unix) account $ibayName.\n" );
}
system(
"/usr/sbin/cpu", "-C/etc/cpu-system.conf", "groupadd",
"-g",
$ibay->prop("Gid"),
$ibayName
) == 0 or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to create (ldap) group $ibayName.\n" );
system(
"/usr/sbin/cpu", "-C/etc/cpu-system.conf", "useradd",
"-u",
$ibay->prop("Uid"),
"-g",
$ibay->prop("Gid"),
"-c",
$ibay->prop("Name"),
"-d",
"/home/e-smith/files/ibays/$ibayName/files",
"-G",
"shared,"
. $ibay->prop("Group"),
"-s",
"/bin/false",
"$ibayName"
) == 0 or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to create (ldap) account $ibayName.\n" );
#------------------------------------------------------------
# Create the ibay files and set the password.
#------------------------------------------------------------
system("/bin/cp", "-Rp", "/etc/e-smith/skel/ibay",
"/home/e-smith/files/ibays/$ibayName") == 0
or ( $x = 255, warn "Error copying ibay skeletal files" );
processTemplate( {
TEMPLATE_PATH=>"/home/e-smith/files/ibays/html/index.html",
OUTPUT_FILENAME=>"/home/e-smith/files/ibays/$ibayName/html/index.html",
MORE_DATA=>{IBAY_NAME=>$ibayName},
} );
if ($ldapauth ne 'enabled')
{
system("/usr/bin/passwd", "-l", $ibayName) == 0
or ( $x = 255, warn "Error locking (unix) account $ibayName" );
}
system("/usr/sbin/cpu", "-C/etc/cpu-system.conf", "usermod", "-L", $ibayName) == 0
or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Error locking (ldap) account $ibayName" );
}
elsif ($event eq 'ibay-modify' and $ibayName ne 'Primary')
{
#------------------------------------------------------------
# Modify ibay description in /etc/passwd using "usermod"
#------------------------------------------------------------
if ($ldapauth ne 'enabled')
{
system("/usr/sbin/usermod", "-c", $ibay->prop("Name"),
"-G", "shared," . $ibay->prop("Group"), "$ibayName") == 0
or ( $x = 255, warn "Failed to modify (unix) account $ibayName.\n" );
}
system("/usr/sbin/cpu", "-C/etc/cpu-system.conf", "usermod", "-c", $ibay->prop("Name"),
"-G", "shared," . $ibay->prop("Group"), "$ibayName") == 0
or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to modify (ldap) account $ibayName.\n" );
}
#------------------------------------------------------------
# Fix permissions on ibay files.
#------------------------------------------------------------
#--------------------------------------------------
# main directory is writeable only by root
#--------------------------------------------------
chdir "/home/e-smith/files/ibays/$ibayName"
or ( $x = 255, warn "Could not chdir to /home/e-smith/files/ibays/$ibayName" );
esmith::util::chownFile("root", "root", ".");
chmod 0755, ".";
#--------------------------------------------------
# fix ownership of subdirectories
#--------------------------------------------------
#--------------------------------------------------
# Set the group as www if it was admin, since
# while set as admin, the web server no longer has
# access to the ibay HTML directory, and web pages.
#--------------------------------------------------
my %properties = $ibay->props;
$::group = ($properties{'Group'} eq "admin") ? "www" : $properties {'Group'};
# Make sensible defaults
$::owner = undef;
$::fileperm = 0600;
$::dirperm = 0550;
if ($properties {'UserAccess'} eq 'wr-admin-rd-group')
{
$::owner = "admin";
$::fileperm = 0640;
$::dirperm = 02750;
}
elsif ($properties {'UserAccess'} eq 'wr-group-rd-group')
{
$::fileperm = 0660;
$::dirperm = 02770;
}
elsif ($properties {'UserAccess'} eq 'wr-group-rd-everyone')
{
$::fileperm = 0664;
$::dirperm = 02775;
}
else
{
warn("Value of UserAccess bad or unset");
}
sub process
{
if (-l)
{
$File::Find::prune = 1;
}
else
{
esmith::util::chownFile($::owner, $::group, $_);
if (-d)
{
chmod $::dirperm, $_;
}
elsif (-f)
{
# Preserve execute permissions on files
my $experm = (stat($_))[2] & 0111;
$experm |= $::fileperm;
chmod $experm, $_;
}
}
}
find(\&process, glob("*"));
exit ($x);

View File

@@ -0,0 +1,64 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 1999-2003 Mitel Networks Corporation
#
# 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
#
# Technical support for this program is available from Mitel Networks
# Please visit our web site www.mitel.com/sme/ for details.
#----------------------------------------------------------------------
package esmith;
use strict;
use Errno;
use esmith::util;
use esmith::AccountsDB;
# Populate pre-defined Primary i-bay
# Start with top level owner/permissions
my $files = "/home/e-smith/files";
my $perms = 0755;
my $owner = 'root';
my $group = 'root';
foreach (qw(Primary Primary/cgi-bin Primary/html Primary/files))
{
my $dir = "$files/ibays/$_";
unless (-d "$dir")
{
mkdir ($dir, $perms) or warn "Could not create dir $dir: $!";
chmod ($perms, $dir) or warn "Could not chmod dir $dir: $!";
esmith::util::chownFile($owner, $group, $dir);
}
# Switch to subdir owner/permissions
$perms = 02750;
$owner = 'admin';
$group = 'shared';
}
# Create a starter website index page if necessary
if( !grep /\.\w+$/, </home/e-smith/files/ibays/Primary/html/index.*> )
{
system("/bin/cp", "-p",
"/etc/e-smith/skel/e-smith/files/primary/html/index.htm",
"/home/e-smith/files/ibays/Primary/html/index.htm");
chmod 0640, "/home/e-smith/files/ibays/Primary/html/index.htm";
esmith::util::chownFile('admin', 'shared',
"/home/e-smith/files/ibays/Primary/html/index.htm");
}
exit (0);