initial commit of file from CVS for smeserver-userpanel on Sat Sep 7 21:12:39 AEST 2024
This commit is contained in:
135
root/etc/e-smith/web/functions/userpanel-initial
Normal file
135
root/etc/e-smith/web/functions/userpanel-initial
Normal file
@@ -0,0 +1,135 @@
|
||||
#!/usr/bin/perl -wT
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# user manager functions: initial
|
||||
#
|
||||
# Copyright (c) 2001 Daniel van Raay <danielvr@caa.org.au>
|
||||
#
|
||||
# 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 CGI ':all';
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
|
||||
use esmith::cgi;
|
||||
use esmith::config;
|
||||
use esmith::util;
|
||||
use esmith::db;
|
||||
|
||||
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'} = '';
|
||||
$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 $q = new CGI;
|
||||
|
||||
esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Smeserver User Manager');
|
||||
|
||||
print <<EOF;
|
||||
|
||||
<P>To perform a user administration function, click one of the
|
||||
links in the menu on the left of your screen. If your admin allows it,
|
||||
you can:
|
||||
|
||||
<ul>
|
||||
EOF
|
||||
|
||||
my $user = $ENV{'REMOTE_USER'};
|
||||
|
||||
my $userAdminPanels = db_get_prop(\%accounts, $user, 'AdminPanels');
|
||||
$userAdminPanels = '' if ! defined ($userAdminPanels);
|
||||
|
||||
my $globalAdminPanels = db_get_prop(\%accounts, 'globalUP', 'AdminPanels');
|
||||
$globalAdminPanels = '' if ! defined ($globalAdminPanels);
|
||||
|
||||
my @adminpanels;
|
||||
if ( defined ($userAdminPanels) )
|
||||
{
|
||||
@adminpanels = grep (/^userpanel-/, ((split (/,/, $userAdminPanels, -1)),(split (/,/, $globalAdminPanels, -1))));
|
||||
}
|
||||
|
||||
my $panel;
|
||||
my %panelhash = ();
|
||||
my $desc;
|
||||
my $longdesc;
|
||||
foreach $panel (@adminpanels)
|
||||
{
|
||||
unless (open (RD, "/etc/e-smith/web/panels/user/cgi-bin/$panel"))
|
||||
{
|
||||
warn "Can't open file /etc/e-smith/web/panels/user/cgi-bin/$panel: $!\n";
|
||||
next;
|
||||
}
|
||||
|
||||
$desc = "";
|
||||
$longdesc = "";
|
||||
while (<RD>)
|
||||
{
|
||||
if (/^\s*#\s*description\s*:\s*(.+?)\s*$/)
|
||||
{
|
||||
$desc = $1;
|
||||
}
|
||||
if (/^\s*#\s*longdesc\s*:\s*(.+?)\s*$/)
|
||||
{
|
||||
$longdesc = $1;
|
||||
}
|
||||
|
||||
last if ( $desc && $longdesc );
|
||||
}
|
||||
close RD;
|
||||
|
||||
if ($desc && $longdesc)
|
||||
{
|
||||
$panelhash{$desc} = $longdesc;
|
||||
}
|
||||
}
|
||||
|
||||
foreach $panel (sort keys %panelhash)
|
||||
{
|
||||
print "<li><b>$panel</b> - <i>$panelhash{$panel}</i></li>\n";
|
||||
}
|
||||
|
||||
print <<EOF;
|
||||
</ul>
|
||||
|
||||
<P>This software comes with ABSOLUTELY NO WARRANTY. As part of our
|
||||
commitment to open-source software, you are welcome to copy and
|
||||
redistribute this software.
|
||||
|
||||
EOF
|
||||
|
||||
print $q->endform;
|
||||
|
||||
esmith::cgi::genFooter ($q);
|
||||
|
371
root/etc/e-smith/web/functions/userpanel-navigation
Normal file
371
root/etc/e-smith/web/functions/userpanel-navigation
Normal file
@@ -0,0 +1,371 @@
|
||||
#!/usr/bin/perl -wT
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# e-smith manager functions: navigation
|
||||
#
|
||||
# copyright (C) 2002 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.e-smith.com for details.
|
||||
#----------------------------------------------------------------------
|
||||
package esmith;
|
||||
|
||||
use strict;
|
||||
use CGI ':no_xhtml', ':all';
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
|
||||
use esmith::cgi;
|
||||
use esmith::config;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::util;
|
||||
use esmith::I18N;
|
||||
use esmith::db;
|
||||
|
||||
sub determineGroup;
|
||||
sub showNavigation;
|
||||
sub logmeout;
|
||||
sub byweight;
|
||||
|
||||
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'} = '';
|
||||
$ENV {'SHELL'} = '/bin/bash';
|
||||
delete $ENV {'ENV'};
|
||||
}
|
||||
|
||||
esmith::util::setRealToEffective ();
|
||||
|
||||
$CGI::POST_MAX=1024 * 100; # max 100K posts
|
||||
$CGI::DISABLE_UPLOADS = 1; # no uploads
|
||||
|
||||
# Use the one script for navigation and noframes
|
||||
my $NO_FRAMES = ($0 =~ /noframes/);
|
||||
|
||||
my %conf;
|
||||
tie %conf, 'esmith::config';
|
||||
|
||||
my %accounts;
|
||||
tie %accounts, 'esmith::config', '/home/e-smith/db/accounts';
|
||||
|
||||
my $q = new CGI;
|
||||
|
||||
showNavigation ($q);
|
||||
logmeout($q);
|
||||
|
||||
exit (0);
|
||||
|
||||
#------------------------------------------------------
|
||||
# subroutine to print logout
|
||||
#------------------------------------------------------
|
||||
sub logmeout
|
||||
{
|
||||
my $user = $ENV{'REMOTE_USER'};
|
||||
|
||||
print <<EOF;
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align=left nowrap class="infobar">
|
||||
<img src="/server-common/spacer.gif" height="14" width="1" align="left">
|
||||
</td>
|
||||
<td align=left nowrap class="infobar">
|
||||
$user
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align=left nowrap class="infobar">
|
||||
<img src="/server-common/spacer.gif" height="14" width="1" align="left">
|
||||
</td>
|
||||
<td align=left nowrap class="infobar">
|
||||
<a target="_parent" href="/server-common/cgi-bin/logout-user"><b>Logout</b></a></td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
EOF
|
||||
|
||||
|
||||
}
|
||||
|
||||
#------------------------------------------------------
|
||||
# subroutine to determine which group a user belongs to
|
||||
#------------------------------------------------------
|
||||
|
||||
sub determineGroup
|
||||
{
|
||||
my ($user) = shift;
|
||||
|
||||
# Group file for authentication
|
||||
my $group_file = '/etc/group';
|
||||
open ( GF, $group_file )
|
||||
or die "Cannot open group file: $group_file: $!\n";
|
||||
|
||||
# list of groups this user belongs to
|
||||
my @groupList;
|
||||
while (<GF>)
|
||||
{
|
||||
if (/[:,]$user\b/)
|
||||
{
|
||||
my ($groupName, undef) = split(/:/);
|
||||
push @groupList, $groupName;
|
||||
}
|
||||
}
|
||||
close GF;
|
||||
return @groupList;
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to display navigation bar
|
||||
#------------------------------------------------------------
|
||||
|
||||
sub showNavigation
|
||||
{
|
||||
my $q = shift;
|
||||
|
||||
my $acctName = $ENV{'REMOTE_USER'};
|
||||
my @adminpanels;
|
||||
|
||||
my $UserAlias = $conf{UserPanelAlias} || 'user';
|
||||
|
||||
my $availablePanels = db_get_prop(\%accounts, $acctName, 'AdminPanels') || '';
|
||||
push (@adminpanels, split (/,/, $availablePanels, -1));
|
||||
|
||||
my $globalPanels = db_get_prop(\%accounts, 'globalUP', 'AdminPanels') || '';
|
||||
push (@adminpanels, split (/,/, $globalPanels, -1));
|
||||
|
||||
foreach (determineGroup($acctName), 'shared')
|
||||
{
|
||||
my $gpanel = db_get_prop(\%accounts, $_, 'AdminPanels') || '';
|
||||
push (@adminpanels, split (/,/, $gpanel, -1));
|
||||
}
|
||||
|
||||
# Use this variable throughout to keep track of files
|
||||
# list of just the files
|
||||
my $c = "1";
|
||||
my @files = ();
|
||||
my %files_hash = ();
|
||||
|
||||
#-----------------------------------------------------
|
||||
# Determine the directory where the functions are kept
|
||||
#-----------------------------------------------------
|
||||
|
||||
my $navigation_ignore =
|
||||
"(\.\.?|navigation|noframes|online-manual|(internal|pleasewait)(-.*)?)";
|
||||
|
||||
my $cgidir = '/etc/e-smith/web/panels/user/cgi-bin/';
|
||||
|
||||
if (opendir (DIR, $cgidir))
|
||||
{
|
||||
@files = grep (!/^(\..*|userpanel-navigation|userpanel-noframes|userpanel-initial|pleasewait)$/,
|
||||
readdir (DIR));
|
||||
closedir (DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn "Can't open directory $cgidir\n";
|
||||
}
|
||||
|
||||
foreach my $file (@files)
|
||||
{
|
||||
foreach my $adminpanel (@adminpanels)
|
||||
{
|
||||
if ( $file eq $adminpanel )
|
||||
{
|
||||
$files_hash{$file} = $cgidir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------
|
||||
# For each script, extract the description and category
|
||||
# information. Build up an associative array mapping headings
|
||||
# to heading structures. Each heading structure contains the
|
||||
# total weight for the heading, the number of times the heading
|
||||
# has been encountered, and another associative array mapping
|
||||
# descriptions to description structures. Each description
|
||||
# structure contains the filename of the particular cgi script
|
||||
# and a weight.
|
||||
#--------------------------------------------------
|
||||
my %nav = ();
|
||||
|
||||
use constant NAVIGATIONDIR => '/home/e-smith/db/navigation';
|
||||
use constant WEBFUNCTIONS => '/etc/e-smith/web/functions';
|
||||
|
||||
my $i18n = new esmith::I18N;
|
||||
|
||||
my $language = $i18n->preferredLanguage( $ENV{HTTP_ACCEPT_LANGUAGE} );
|
||||
|
||||
my $navinfo = NAVIGATIONDIR . "/navigation.$language";
|
||||
|
||||
my $navdb = esmith::ConfigDB->open_ro( $navinfo ) or
|
||||
die "Couldn't open $navinfo\n";
|
||||
|
||||
# Check the navdb for anything with a UrlPath, which means that it doesn't
|
||||
# have a cgi file to be picked up by the above code. Ideally, only pages
|
||||
# that exist should be in the db, but that's not the case. Anything
|
||||
# without a cgi file will have to remove themselves on uninstall from the
|
||||
# navigation dbs.
|
||||
foreach my $rec ($navdb->get_all)
|
||||
{
|
||||
if ($rec->prop('UrlPath'))
|
||||
{
|
||||
$files_hash{$rec->{key}} = $cgidir;
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $file (keys %files_hash)
|
||||
{
|
||||
my $heading = 'Unknown';
|
||||
my $description = $file;
|
||||
my $headingWeight = 99999;
|
||||
my $descriptionWeight = 99999;
|
||||
my $urlpath = '';
|
||||
|
||||
my $rec = $navdb->get($file);
|
||||
|
||||
if (defined $rec)
|
||||
{
|
||||
$heading = $rec->prop('Heading');
|
||||
$description = $rec->prop('Description');
|
||||
$headingWeight = $rec->prop('HeadingWeight');
|
||||
$descriptionWeight = $rec->prop('DescriptionWeight');
|
||||
$urlpath = $rec->prop('UrlPath') || '';
|
||||
}
|
||||
|
||||
#--------------------------------------------------
|
||||
# add heading, description and weight information to data structure
|
||||
#--------------------------------------------------
|
||||
|
||||
unless (exists $nav {$heading})
|
||||
{
|
||||
$nav {$heading} = { COUNT => 0, WEIGHT => 0, DESCRIPTIONS => [] };
|
||||
}
|
||||
|
||||
$nav {$heading} {'COUNT'} ++;
|
||||
$nav {$heading} {'WEIGHT'} += $headingWeight;
|
||||
|
||||
my @filename = split /\//, $files_hash{$file};
|
||||
my $path = "/$UserAlias/$filename[scalar @filename - 1]";
|
||||
|
||||
push @{ $nav {$heading} {'DESCRIPTIONS'} },
|
||||
{ DESCRIPTION => $description,
|
||||
WEIGHT => $descriptionWeight,
|
||||
FILENAME => $urlpath ? $urlpath : "$path/$file",
|
||||
CGIPATH => $path
|
||||
};
|
||||
}
|
||||
|
||||
#--------------------------------------------------
|
||||
# generate list of headings sorted by average weight
|
||||
#--------------------------------------------------
|
||||
|
||||
my @unsortedheadings = keys %nav;
|
||||
|
||||
my $h;
|
||||
local @esmith::weights = ();
|
||||
foreach $h (@unsortedheadings)
|
||||
{
|
||||
push (@esmith::weights, ($nav {$h} {'WEIGHT'} / $nav {$h} {'COUNT'}));
|
||||
}
|
||||
|
||||
my @sortedheadings = @unsortedheadings [sort byweight $[..$#unsortedheadings];
|
||||
|
||||
if ( $NO_FRAMES )
|
||||
{
|
||||
esmith::cgi::genNoframesHeader ($q);
|
||||
}
|
||||
else
|
||||
{
|
||||
esmith::cgi::genNavigationHeader ($q, $#sortedheadings);
|
||||
print "\n<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n";
|
||||
}
|
||||
|
||||
foreach $h (@sortedheadings)
|
||||
{
|
||||
if ( $NO_FRAMES )
|
||||
{
|
||||
print $q->h2 ($h);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "\n", $q->Tr ($q->td({class => "section"},$q->span({class => "section"}, $h)));
|
||||
}
|
||||
|
||||
#--------------------------------------------------
|
||||
# generate list of descriptions sorted by weight
|
||||
#--------------------------------------------------
|
||||
|
||||
my @unsorteddescriptions = @{ $nav {$h} {'DESCRIPTIONS'} };
|
||||
|
||||
my $d;
|
||||
@esmith::weights = ();
|
||||
foreach $d (@unsorteddescriptions)
|
||||
{
|
||||
push (@esmith::weights, $d->{'WEIGHT'});
|
||||
}
|
||||
|
||||
my @indices = sort byweight $[..$#unsorteddescriptions;
|
||||
|
||||
print "<ul>\n" if ( $NO_FRAMES );
|
||||
|
||||
my $i;
|
||||
foreach $i (@indices)
|
||||
{
|
||||
if ( $NO_FRAMES )
|
||||
{
|
||||
my $href = "/$UserAlias" .
|
||||
$unsorteddescriptions [$i]->{'FILENAME'};
|
||||
print $q->li ($q->a ({href => "$href?noframes=1"}, $unsorteddescriptions [$i]->{'DESCRIPTION'}));
|
||||
}
|
||||
else
|
||||
{
|
||||
my $_class_root_base = "item";
|
||||
my $_class_root_warn = "warn";
|
||||
my $_class = "$_class_root_base";
|
||||
my $_class_selected = "$_class_root_base"."-current";
|
||||
my $_class2 = "$_class_root_warn";
|
||||
my $_class2_selected = "$_class_root_warn"."-current";
|
||||
|
||||
my $href =
|
||||
$unsorteddescriptions [$i]->{'FILENAME'};
|
||||
print "\n",$q->Tr($q->td ({-class => "menu-cell"},
|
||||
$q->a ({-id => "sme$c",
|
||||
-class => "$_class",
|
||||
-onClick => "swapClass(0,'none','$_class_selected','$_class','a');swapClass(0,'none','$_class2_selected','$_class2','a');swapClass(0,'sme$c','$_class_selected','$_class','a')",
|
||||
href => $href,
|
||||
target => 'main'},
|
||||
$unsorteddescriptions [$i]->{'DESCRIPTION'})));
|
||||
}
|
||||
$c++;
|
||||
|
||||
}
|
||||
print "</ul>\n" if ($NO_FRAMES);
|
||||
}
|
||||
|
||||
unless ( $NO_FRAMES )
|
||||
{
|
||||
print "\n</TABLE>\n";
|
||||
esmith::cgi::genNavigationFooter ($q);
|
||||
}
|
||||
}
|
||||
|
||||
sub byweight
|
||||
{
|
||||
$esmith::weights [$a] <=> $esmith::weights [$b];
|
||||
}
|
259
root/etc/e-smith/web/functions/userpanel-noframes
Normal file
259
root/etc/e-smith/web/functions/userpanel-noframes
Normal file
@@ -0,0 +1,259 @@
|
||||
#!/usr/bin/perl -wT
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# user manager functions: noframes
|
||||
#
|
||||
# Copyright (c) 2001 Daniel van Raay <danielvr@caa.org.au>
|
||||
#
|
||||
# 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 CGI ':all';
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
|
||||
use esmith::cgi;
|
||||
use esmith::config;
|
||||
use esmith::util;
|
||||
use esmith::db;
|
||||
|
||||
sub showNavigation ($);
|
||||
sub byweight;
|
||||
|
||||
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'} = '';
|
||||
$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 $q = new CGI;
|
||||
|
||||
showNavigation ($q);
|
||||
exit (0);
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to display navigation bar
|
||||
#------------------------------------------------------------
|
||||
|
||||
sub showNavigation ($)
|
||||
{
|
||||
my $q = shift;
|
||||
|
||||
esmith::cgi::genNoframesHeader ($q);
|
||||
|
||||
my $acctName = $ENV{'REMOTE_USER'};
|
||||
my $availablePanels = db_get_prop(\%accounts, $acctName, 'AdminPanels');
|
||||
my $globalPanels = db_get_prop(\%accounts, 'globalUP', 'AdminPanels');
|
||||
|
||||
my @adminpanels;
|
||||
if ( defined ($availablePanels) && defined ($globalPanels) )
|
||||
{
|
||||
@adminpanels = ((split (/,/, $availablePanels, -1)),(split (/,/, $globalPanels, -1)));
|
||||
}
|
||||
elsif ( defined ($globalPanels) )
|
||||
{
|
||||
@adminpanels = split (/,/, $globalPanels, -1);
|
||||
}
|
||||
elsif ( defined ($availablePanels) )
|
||||
{
|
||||
@adminpanels = split (/,/, $availablePanels, -1);
|
||||
}
|
||||
|
||||
# Use this variable throughout to keep track of files
|
||||
# list of just the files
|
||||
my @files = ();
|
||||
my %files_hash = ();
|
||||
|
||||
#-----------------------------------------------------
|
||||
# Determine the directory where the functions are kept
|
||||
# match available panels with delegated panels to this user
|
||||
#-----------------------------------------------------
|
||||
|
||||
my $cgidir = '/etc/e-smith/web/panels/user/cgi-bin/';
|
||||
|
||||
if (opendir (DIR, $cgidir))
|
||||
{
|
||||
@files = grep (!/^(\..*|userpanel-navigation|userpanel-noframes|userpanel-initial|pleasewait)$/,
|
||||
readdir (DIR));
|
||||
closedir (DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn "Can't open directory $cgidir\n";
|
||||
}
|
||||
|
||||
foreach my $file (@files)
|
||||
{
|
||||
foreach my $adminpanel (@adminpanels)
|
||||
{
|
||||
if ( $file eq $adminpanel )
|
||||
{
|
||||
$files_hash{$file} = $cgidir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------
|
||||
# For each script, extract the description and category
|
||||
# information. Build up an associative array mapping headings
|
||||
# to heading structures. Each heading structure contains the
|
||||
# total weight for the heading, the number of times the heading
|
||||
# has been encountered, and another associative array mapping
|
||||
# descriptions to description structures. Each description
|
||||
# structure contains the filename of the particular cgi script
|
||||
# and a weight.
|
||||
#--------------------------------------------------
|
||||
|
||||
my %nav = ();
|
||||
|
||||
foreach my $file (keys %files_hash)
|
||||
{
|
||||
#--------------------------------------------------
|
||||
# extract heading, description and weight information
|
||||
# from CGI script
|
||||
#--------------------------------------------------
|
||||
my $heading = "Unknown";
|
||||
my $headingWeight = 0;
|
||||
|
||||
my $description = "Unknown";
|
||||
my $descriptionWeight = 0;
|
||||
|
||||
unless (open (RD, "$files_hash{$file}/$file"))
|
||||
{
|
||||
warn "Can't open file $files_hash{$file}/$file: $!\n";
|
||||
next;
|
||||
}
|
||||
|
||||
while (<RD>)
|
||||
{
|
||||
if (/^\s*#\s*heading\s*:\s*(.+?)\s*$/)
|
||||
{
|
||||
$heading = $1;
|
||||
}
|
||||
|
||||
if (/^\s*#\s*description\s*:\s*(.+?)\s*$/)
|
||||
{
|
||||
$description = $1;
|
||||
}
|
||||
|
||||
if (/^\s*#\s*navigation\s*:\s*(\d+?)\s+(\d+?)\s*$/)
|
||||
{
|
||||
$headingWeight = $1;
|
||||
$descriptionWeight = $2;
|
||||
}
|
||||
last if ($heading ne "Unknown" && $headingWeight && $description ne "Unknown" && $descriptionWeight);
|
||||
}
|
||||
close RD;
|
||||
|
||||
#--------------------------------------------------
|
||||
# add heading, description and weight information to data structure
|
||||
#--------------------------------------------------
|
||||
|
||||
unless (exists $nav {$heading})
|
||||
{
|
||||
$nav {$heading} = { COUNT => 0, WEIGHT => 0, DESCRIPTIONS => [] };
|
||||
}
|
||||
|
||||
$nav {$heading} {'COUNT'} ++;
|
||||
$nav {$heading} {'WEIGHT'} += $headingWeight;
|
||||
|
||||
# Check for manager panel, and assign the appropriate
|
||||
# cgi-bin prefix for the links.
|
||||
# Grab the last 2 directories by splitting for '/'s and
|
||||
# then concatenating the last 2
|
||||
# probably a better way, but I don't know it.
|
||||
my @filename = split /\//, $files_hash{$file};
|
||||
my $path = "/user-manager/$filename[scalar @filename - 1]";
|
||||
|
||||
push @{ $nav {$heading} {'DESCRIPTIONS'} },
|
||||
{ DESCRIPTION => $description,
|
||||
WEIGHT => $descriptionWeight,
|
||||
FILENAME => "$path/$file",
|
||||
CGIPATH => $path
|
||||
};
|
||||
}
|
||||
|
||||
#--------------------------------------------------
|
||||
# generate list of headings sorted by average weight
|
||||
#--------------------------------------------------
|
||||
|
||||
my @unsortedheadings = keys %nav;
|
||||
|
||||
my $h;
|
||||
local @esmith::weights = ();
|
||||
foreach $h (@unsortedheadings)
|
||||
{
|
||||
push (@esmith::weights, ($nav {$h} {'WEIGHT'} / $nav {$h} {'COUNT'}));
|
||||
}
|
||||
|
||||
my @sortedheadings = @unsortedheadings [sort byweight $[..$#unsortedheadings];
|
||||
|
||||
foreach $h (@sortedheadings)
|
||||
{
|
||||
print $q->h2 ($h);
|
||||
|
||||
#--------------------------------------------------
|
||||
# generate list of descriptions sorted by weight
|
||||
#--------------------------------------------------
|
||||
|
||||
my @unsorteddescriptions = @{ $nav {$h} {'DESCRIPTIONS'} };
|
||||
|
||||
my $d;
|
||||
@esmith::weights = ();
|
||||
foreach $d (@unsorteddescriptions)
|
||||
{
|
||||
push (@esmith::weights, $d->{'WEIGHT'});
|
||||
}
|
||||
|
||||
my @indices = sort byweight $[..$#unsorteddescriptions;
|
||||
|
||||
print "<ul>\n";
|
||||
|
||||
my $i;
|
||||
foreach $i (@indices)
|
||||
{
|
||||
my $href = $unsorteddescriptions [$i]->{'FILENAME'};
|
||||
print $q->li ($q->a ({href => $href}, $unsorteddescriptions [$i]->{'DESCRIPTION'}));
|
||||
|
||||
}
|
||||
print "</ul>\n";
|
||||
}
|
||||
|
||||
esmith::cgi::genNavigationFooter ($q);
|
||||
}
|
||||
|
||||
sub byweight
|
||||
{
|
||||
$esmith::weights [$a] <=> $esmith::weights [$b];
|
||||
}
|
411
root/etc/e-smith/web/functions/userpanelaccess
Normal file
411
root/etc/e-smith/web/functions/userpanelaccess
Normal file
@@ -0,0 +1,411 @@
|
||||
#!/usr/bin/perl -wT
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# heading : Security
|
||||
# description : User Panel Access
|
||||
# navigation : 1000 1300
|
||||
#
|
||||
# Copyright (c) 2001 Daniel van Raay <danielvr@caa.org.au>
|
||||
# Modified (c) 2002 Stephen Noble <stephen@dungog.net>
|
||||
# Modified (c) 2002 Shad L. Lords <slords@mail.com>
|
||||
#
|
||||
# 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 CGI ':all';
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
|
||||
use esmith::cgi;
|
||||
use esmith::config;
|
||||
use esmith::util;
|
||||
use esmith::db;
|
||||
use esmith::event;
|
||||
|
||||
sub showInitial ($$);
|
||||
sub genPanels ($$);
|
||||
sub modifyAccess ($);
|
||||
sub performModifyAccess ($);
|
||||
|
||||
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'} = '';
|
||||
$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';
|
||||
|
||||
#------------------------------------------------------------
|
||||
# examine state parameter and display the appropriate form
|
||||
#------------------------------------------------------------
|
||||
|
||||
my $q = new CGI;
|
||||
|
||||
if (! grep (/^state$/, $q->param))
|
||||
{
|
||||
showInitial ($q, '');
|
||||
}
|
||||
|
||||
elsif ($q->param ('state') eq "modifyAccess")
|
||||
{
|
||||
modifyAccess ($q);
|
||||
}
|
||||
|
||||
elsif ($q->param ('state') eq "performModifyAccess")
|
||||
{
|
||||
performModifyAccess ($q);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
esmith::cgi::genStateError ($q, \%conf);
|
||||
}
|
||||
|
||||
exit (0);
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to display initial form
|
||||
#------------------------------------------------------------
|
||||
|
||||
sub showInitial ($$)
|
||||
{
|
||||
my ($q, $msg) = @_;
|
||||
|
||||
if ($msg eq '')
|
||||
{
|
||||
esmith::cgi::genHeaderNonCacheable
|
||||
($q, \%conf, 'Change access to server-manager panels for user accounts');
|
||||
}
|
||||
else
|
||||
{
|
||||
esmith::cgi::genHeaderNonCacheable
|
||||
($q, \%conf, 'Operation status report');
|
||||
|
||||
print $q->p ($msg);
|
||||
print $q->hr;
|
||||
}
|
||||
|
||||
my @userAccounts = ('admin');
|
||||
|
||||
foreach (sort keys %accounts)
|
||||
{
|
||||
push (@userAccounts, $_) if (db_get_type(\%accounts, $_) eq "user");
|
||||
}
|
||||
|
||||
foreach (sort keys %accounts)
|
||||
{
|
||||
push (@userAccounts, $_) if (db_get_type(\%accounts, $_) eq "group");
|
||||
}
|
||||
|
||||
unless (scalar @userAccounts)
|
||||
{
|
||||
print $q->p ($q->b ('There are no user accounts in the system.'));
|
||||
}
|
||||
else
|
||||
{
|
||||
my $description = <<END_TEXT;
|
||||
You can modify individual users access to the server-manager
|
||||
panels below by clicking on the link next the account. You can assign
|
||||
panels to the members of a group with their link. Users or Groups
|
||||
in red have some form of extra access. You can globally assign
|
||||
a panel by editing the global account
|
||||
END_TEXT
|
||||
|
||||
print $q->p ($description);
|
||||
|
||||
print $q->p ($q->b ('Current List of User Accounts'));
|
||||
|
||||
print "<table border=1 cellspacing=1 cellpadding=4>";
|
||||
|
||||
print $q->Tr (esmith::cgi::genSmallCell ($q, $q->b ('Account')),
|
||||
esmith::cgi::genSmallCell ($q, $q->b ('Name/Description')),
|
||||
$q->td (' '));
|
||||
|
||||
my $user;
|
||||
|
||||
foreach $user (@userAccounts)
|
||||
{
|
||||
my $name = '';
|
||||
if (db_get_type(\%accounts, $user) eq "group")
|
||||
{
|
||||
$name =db_get_prop(\%accounts, $user, "Description");
|
||||
}
|
||||
else
|
||||
{
|
||||
$name =db_get_prop(\%accounts, $user, "FirstName")." ". db_get_prop(\%accounts, $user, "LastName");
|
||||
}
|
||||
|
||||
my $AdminPanels = db_get_prop(\%accounts, $user, "AdminPanels");
|
||||
$AdminPanels = '' if ! defined ($AdminPanels);
|
||||
|
||||
if ( ! $AdminPanels )
|
||||
{
|
||||
print $q->Tr (esmith::cgi::genSmallCell ($q, $user),
|
||||
esmith::cgi::genSmallCell ($q, $name),
|
||||
esmith::cgi::genSmallCell ($q,
|
||||
$q->a ({href => $q->url (-absolute => 1)
|
||||
. "?state=modifyAccess&acct="
|
||||
. $user}, 'Change Access...')));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print $q->Tr (esmith::cgi::genSmallRedCell ($q, $user),
|
||||
esmith::cgi::genSmallRedCell ($q, $name),
|
||||
esmith::cgi::genSmallCell ($q,
|
||||
$q->a ({href => $q->url (-absolute => 1)
|
||||
. "?state=modifyAccess&acct="
|
||||
. $user}, 'Change Access...')));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#global setting
|
||||
if ( ! db_get( \%accounts, 'globalUP') )
|
||||
{
|
||||
db_set(\%accounts, 'globalUP', 'userpanelglobal', { FirstName => 'global user', LastName => 'panel access' });
|
||||
}
|
||||
|
||||
my $AdminPanels = db_get_prop(\%accounts, 'globalUP', "AdminPanels");
|
||||
$AdminPanels = '' if ! defined ($AdminPanels);
|
||||
|
||||
if ( ! $AdminPanels )
|
||||
{
|
||||
print $q->Tr (esmith::cgi::genSmallCell ($q, 'Global'),
|
||||
esmith::cgi::genSmallCell ($q, 'every user'),
|
||||
esmith::cgi::genSmallCell ($q,
|
||||
$q->a ({href => $q->url (-absolute => 1)
|
||||
. "?state=modifyAccess&acct="
|
||||
. 'globalUP'}, 'Change Access...')));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print $q->Tr (esmith::cgi::genSmallRedCell ($q, 'Global'),
|
||||
esmith::cgi::genSmallRedCell ($q, 'every user'),
|
||||
esmith::cgi::genSmallCell ($q,
|
||||
$q->a ({href => $q->url (-absolute => 1)
|
||||
. "?state=modifyAccess&acct="
|
||||
. 'globalUP'}, 'Change Access...')));
|
||||
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
esmith::cgi::genFooter ($q);
|
||||
}
|
||||
|
||||
sub genPanels ($$)
|
||||
{
|
||||
my ($q, $user) = @_;
|
||||
|
||||
my %panelshash = ();
|
||||
my @selected = ();
|
||||
my @globalselected = ();
|
||||
|
||||
my @panels;
|
||||
opendir (DIR, "/etc/e-smith/web/functions")
|
||||
|| die "Can't open /etc/e-smith/web/functions directory.\n";
|
||||
push (@panels, sort (grep (!/^(\.|userpanel-initial|userpanel-navigation|userpanel-noframes|pleasewait|index\.cgi|initial\.cgi|navigation|noframes|userpassword)/, readdir(DIR))));
|
||||
closedir (DIR);
|
||||
|
||||
my $panel;
|
||||
foreach $panel (@panels)
|
||||
{
|
||||
$panelshash{$panel} = "Unknown";
|
||||
|
||||
unless (open (RD, "/etc/e-smith/web/functions/$panel"))
|
||||
{
|
||||
warn "Can't open file /etc/e-smith/web/functions/$panel: $!\n";
|
||||
next;
|
||||
}
|
||||
|
||||
while (<RD>)
|
||||
{
|
||||
if (/^\s*#\s*description\s*:\s*(.+?)\s*$/)
|
||||
{
|
||||
$panelshash{$panel} = $1;
|
||||
}
|
||||
|
||||
last if ( $panelshash{$panel} ne "Unknown" );
|
||||
}
|
||||
close RD;
|
||||
}
|
||||
|
||||
my $userAdminPanels = db_get_prop(\%accounts, $user, 'AdminPanels');
|
||||
$userAdminPanels = '' if ! defined ($userAdminPanels);
|
||||
@selected = split (/,/, $userAdminPanels);
|
||||
|
||||
my $globalAdminPanels = db_get_prop(\%accounts, 'globalUP', 'AdminPanels');
|
||||
$globalAdminPanels = '' if ! defined ($globalAdminPanels);
|
||||
@globalselected = split (/,/, $globalAdminPanels);
|
||||
|
||||
@panels = sort @panels;
|
||||
my $count = scalar @panels;
|
||||
|
||||
my $out = '';
|
||||
|
||||
if ($count > 0)
|
||||
{
|
||||
$out .= '<table border=1 cellspacing=1 cellpadding=4>';
|
||||
|
||||
$out .= $q->Tr ($q->td (' '),
|
||||
esmith::cgi::genSmallCell ($q, $q->b ('Panel')),
|
||||
esmith::cgi::genSmallCell ($q, $q->b ('Description')));
|
||||
|
||||
my $panel;
|
||||
foreach $panel (@panels)
|
||||
{
|
||||
my $checked = "";
|
||||
if (grep (/^$panel$/, @selected) || grep (/^$panel$/, @globalselected))
|
||||
{
|
||||
$checked = "checked";
|
||||
}
|
||||
|
||||
if (grep (/^$panel$/, @globalselected) && ($user ne 'globalUP'))
|
||||
{
|
||||
$out .=
|
||||
$q->Tr (
|
||||
$q->td (
|
||||
"<input type=\"checkbox\""
|
||||
. " name=\"panelAccess\""
|
||||
. " $checked value=\"$panel\">"
|
||||
),
|
||||
esmith::cgi::genSmallRedCell ($q, $panel),
|
||||
esmith::cgi::genSmallRedCell (
|
||||
$q, $panelshash{$panel} . ' (Global)'));
|
||||
} else {
|
||||
$out .=
|
||||
$q->Tr (
|
||||
$q->td (
|
||||
"<input type=\"checkbox\""
|
||||
. " name=\"panelAccess\""
|
||||
. " $checked value=\"$panel\">"
|
||||
),
|
||||
esmith::cgi::genSmallCell ($q, $panel),
|
||||
esmith::cgi::genSmallCell (
|
||||
$q, $panelshash{$panel}));
|
||||
}
|
||||
}
|
||||
|
||||
$out .= '</table>';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
sub modifyAccess ($)
|
||||
{
|
||||
my ($q) = @_;
|
||||
|
||||
esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Modify user-manager access');
|
||||
|
||||
print
|
||||
$q->startform (-method => 'POST', -action => $q->url (-absolute => 1));
|
||||
|
||||
my $acct = $q->param ('acct');
|
||||
|
||||
my $username = '';
|
||||
if (db_get_type(\%accounts, $acct) eq "group")
|
||||
{
|
||||
$username =db_get_prop(\%accounts, $acct, "Description");
|
||||
}
|
||||
else
|
||||
{
|
||||
$username =db_get_prop(\%accounts, $acct, "FirstName")." ". db_get_prop(\%accounts, $acct, "LastName");
|
||||
}
|
||||
|
||||
if (db_get(\%accounts, $acct))
|
||||
{
|
||||
|
||||
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
|
||||
|
||||
$q->Tr (esmith::cgi::genCell ($q, "Account name:"),
|
||||
esmith::cgi::genCell ($q, $acct)),
|
||||
|
||||
$q->Tr (esmith::cgi::genCell ($q, "Name/Description:"),
|
||||
esmith::cgi::genCell ($q, "$username")),
|
||||
|
||||
$q->Tr (esmith::cgi::genCell ($q, "Accessible Panels:"),
|
||||
esmith::cgi::genCell ($q, genPanels ($q, $acct))),
|
||||
|
||||
esmith::cgi::genButtonRow ($q,
|
||||
$q->submit (-name => 'action',
|
||||
-value => 'Modify')));
|
||||
|
||||
print $q->hidden (-name => 'acct',
|
||||
-override => 1,
|
||||
-default => $acct);
|
||||
|
||||
print $q->hidden (-name => 'state',
|
||||
-override => 1,
|
||||
-default => 'performModifyAccess');
|
||||
|
||||
}
|
||||
|
||||
print $q->endform;
|
||||
esmith::cgi::genFooter ($q);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub performModifyAccess ($)
|
||||
{
|
||||
my ($q) = @_;
|
||||
my $acct = $q->param ('acct');
|
||||
|
||||
my @adminPanels = $q->param ('panelAccess');
|
||||
my @userPanels = ();
|
||||
|
||||
my $globalAdminPanels = db_get_prop(\%accounts, 'globalUP', 'AdminPanels');
|
||||
$globalAdminPanels = '' if ! defined ($globalAdminPanels);
|
||||
my @globalselected = split (/,/, $globalAdminPanels);
|
||||
|
||||
foreach my $panel (@adminPanels)
|
||||
{
|
||||
if ( ! grep (/^$panel$/, @globalselected) || ($acct eq 'globalUP'))
|
||||
{
|
||||
push(@userPanels, $panel);
|
||||
}
|
||||
}
|
||||
|
||||
my $adminPanels = join (',', @userPanels);
|
||||
|
||||
db_set_prop(\%accounts, $acct, 'AdminPanels', $adminPanels);
|
||||
|
||||
system ("/sbin/e-smith/signal-event", "conf-userpanel") == 0
|
||||
or die ("Error occurred while updating userpanel configuration.\n");
|
||||
|
||||
showInitial ($q, "Successfully modified user account $acct.");
|
||||
}
|
Reference in New Issue
Block a user