976 lines
34 KiB
Perl
Executable File
976 lines
34 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# lists-lib.pl
|
|
# Common functions to load list-files and others (file-list, count-sess,etc.).
|
|
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo --- license GNU GPL
|
|
# stta: (@#) 1.31051043346- [2004_01_29_102036]
|
|
|
|
# Since 1.2 everythins has been moved into a full hash and can by loaded by "pos" field.
|
|
# by ex: hosts can be loaded into returned hash by name (0) or by ipname (5)
|
|
|
|
# list_ous()
|
|
# Returns an array of hashtable, each containing info about one ou. Each hash
|
|
# will always contain the keys "alias" "name" "ou"
|
|
sub list_ous
|
|
{
|
|
# read the OU list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading OU File List
|
|
$lnum = 0;
|
|
open(FILEOUS, $config{'ou_list'});
|
|
while(<FILEOUS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0],
|
|
'name' => $lin[1],
|
|
'obj' => $lin[2],
|
|
'ens' => $lin[3],
|
|
'maxsess' => $lin[4],
|
|
'descrip' => $lin[5]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEOUS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_apps()
|
|
# Returns an array of hashtable, each containing info about one ou. Each hash
|
|
# will always contain the keys "alias" "name" "app"
|
|
sub list_apps
|
|
{
|
|
# read the APP list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading APP File List
|
|
$lnum = 0;
|
|
open(FILEAPPS, $config{'apps_list'});
|
|
while(<FILEAPPS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'grpalias' => $lin[2],
|
|
'obj' => $lin[3], 'ens' => $lin[4],
|
|
'maxsess' => $lin[5],
|
|
'apptype' => $lin[6],
|
|
'descrip' => $lin[7]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEAPPS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_grpapps()
|
|
# Returns an array of hashtable, each containing info about one grpapps. Each hash
|
|
# will always contain the keys "alias" "name" "grpapps"
|
|
sub list_grpapps
|
|
{
|
|
# read the GRPAPPS list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading GRPAPPS File List
|
|
$lnum = 0;
|
|
open(FILEGRPAPPS, $config{'grpapps_list'});
|
|
while(<FILEGRPAPPS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'obj' => $lin[2], 'ens' => $lin[3],
|
|
'maxsess' => $lin[4],
|
|
'descrip' => $lin[5]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEGRPAPPS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_domains()
|
|
# Returns an array of hashtable, each containing info about one ou. Each hash
|
|
# will always contain the keys "alias" "name" "domain"
|
|
sub list_domains
|
|
{
|
|
# read the DOMAIN list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading DOMAIN File List
|
|
$lnum = 0;
|
|
open(FILEDOMAINS, $config{'domains_list'});
|
|
while(<FILEDOMAINS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'obj' => $lin[2], 'ens' => $lin[3],
|
|
'maxsess' => $lin[4],
|
|
'descrip' => $lin[5]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEDOMAINS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_grphosts()
|
|
# Returns an array of hashtable, each containing info about one grphosts. Each hash
|
|
# will always contain the keys "alias" "name" "grphosts"
|
|
sub list_grphosts
|
|
{
|
|
# read the GRPHOSTS list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading GRPHOSTS File List
|
|
$lnum = 0;
|
|
open(GRPHOSTSFILE, $config{'grphosts_list'});
|
|
while(<GRPHOSTSFILE>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'obj' => $lin[2], 'ens' => $lin[3],
|
|
'maxsess' => $lin[4],
|
|
'descrip' => $lin[5]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(GRPHOSTSFILE);
|
|
return %rv;
|
|
}
|
|
|
|
# list_hosts($field)
|
|
# Returns an array of hashtable, each containing info about one hosts. Each hash
|
|
# will always contain the keys "alias" "name" "hosts"
|
|
sub list_hosts
|
|
{
|
|
# read the HOSTS list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading HOSTS File List
|
|
$lnum = 0;
|
|
open(FILEHOSTS, $config{'hosts_list'});
|
|
while(<FILEHOSTS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'grpalias' => $lin[2],
|
|
'obj' => $lin[3], 'ens' => $lin[4],
|
|
'ipname' => $lin[5],
|
|
'maxsess' => $lin[6],
|
|
'portalive' => $lin[7],
|
|
'descrip' => $lin[8]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEHOSTS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_hostsuser()
|
|
# Returns an array of hashtable, each containing info about one hostsuser. Each hash
|
|
# will always contain the keys "alias" "name" "hostsuser"
|
|
sub list_hostsuser
|
|
{
|
|
# read the HOSTSUSER list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading HOSTS File List
|
|
$lnum = 0;
|
|
open(FILEHOSTSUSER, $config{'hostsuser_list'});
|
|
while(<FILEHOSTSUSER>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'username' => $lin[0],'passwd' => $lin[1],
|
|
'name' => $lin[2]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEHOSTSUSER);
|
|
return %rv;
|
|
}
|
|
|
|
# list_profcache()
|
|
# Returns an array of hashtable, each containing info about one hostsuser. Each hash
|
|
# will always contain the keys "alias" "name" "hostsuser"
|
|
sub list_profcache
|
|
{
|
|
# read the PROFCACHE list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading PROFCACHE File List
|
|
$lnum = 0;
|
|
open(FILEPROFCACHE, $config{'profcache_list'});
|
|
while(<FILEPROFCACHE>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0],'name' => $lin[1],
|
|
'hostusername' => $lin[2],
|
|
'hostname' => $lin[3],
|
|
'grphost' => $lin[4],
|
|
'username' => $lin[5],
|
|
'ou' => $lin[6]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEPROFCACHE);
|
|
return %rv;
|
|
}
|
|
|
|
# list_actions()
|
|
# Returns an array of hashtable, each containing info about actions. Each hash
|
|
# will always contain the keys "alias" "name", etc.
|
|
sub list_actions
|
|
{
|
|
# read the ACCTIONS list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading ACCTIONS File List
|
|
$lnum = 0;
|
|
open(FILEACCTIONS, $config{'acts_list'});
|
|
while(<FILEACCTIONS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
if ( $task_type eq "" || $task_type eq $lin[9] ) {
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0],'name' => $lin[1],
|
|
'target' => $lin[2],
|
|
'object' => $lin[3],
|
|
'condition' => $lin[4],
|
|
'conditionValue' => $lin[5],
|
|
'action' => $lin[6],
|
|
'script' => $lin[7],
|
|
'when' => $lin[8],
|
|
'how' => $lin[9]
|
|
};
|
|
}
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEACCTIONS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_links()
|
|
# Returns an array of hashtable, each containing info about one link. Each hash
|
|
# will always contain the keys "alias" "name" "link"
|
|
sub list_links
|
|
{
|
|
# read the Links list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading Links File List
|
|
$lnum = 0;
|
|
open(FILELKS, $config{'links_list'});
|
|
while(<FILELKS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'obj' => $lin[2], 'ens' => $lin[3],
|
|
'maxsess' => $lin[4],
|
|
'descrip' => $lin[5]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILELKS);
|
|
return %rv;
|
|
}
|
|
|
|
# list_webtops()
|
|
# Returns an array of hashtable, each containing info about one webtop. Each hash
|
|
# will always contain the keys "alias" "name" "link"
|
|
sub list_webtops
|
|
{
|
|
# read the Webtops list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading Webtops File List
|
|
$lnum = 0;
|
|
open(FILEWEBTOPS, $config{'tta_webtops'});
|
|
while(<FILEWEBTOPS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
chomp($lin);
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0], 'name' => $lin[1],
|
|
'obj' => $lin[2]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEWEBTOPS);
|
|
return %rv;
|
|
}
|
|
|
|
# load_ttaobj($temp_f)
|
|
# Returns an array of hashtable, each containing info about one webtop. Each hash
|
|
# will always contain the keys "alias" "name" "link" etc .
|
|
sub load_ttaobj
|
|
{
|
|
# read the obj properties from file
|
|
local(%ttaobj, $_, $lnum, @lin);
|
|
|
|
# start by reading from file List
|
|
|
|
$lnum = 0;
|
|
open(FILETTAOBJ, $temp_f);
|
|
while(<FILETTAOBJ>) {
|
|
if (/\S/ && !/^[#\+\-]/ && $lnum gt 0 ) {
|
|
chomp($lin);
|
|
@lin = split(/: /, $_, -1);
|
|
$lin[1]=~ s/"//g;
|
|
$is_space=chop($lin[1]);
|
|
if ( $is_space eq " " ) { chop($lin[1]); }
|
|
$ttaobj{$lin[0]} = {
|
|
'property' => $lin[0],
|
|
'value' => $lin[1]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILETTAOBJ);
|
|
# unlink($temp_f);
|
|
return %ttaobj;
|
|
}
|
|
|
|
sub load_scriptlist
|
|
{
|
|
# read the obj properties from file
|
|
local(%script_list, $_, $d, $lnum, $title);
|
|
# Get Scripts List
|
|
opendir(DIR, $config{'monitor_scripts_path'});
|
|
foreach $d (readdir(DIR)) {
|
|
# if ( $d =~ /(\.tcl)$/ ) {
|
|
$file_scr=$config{'monitor_scripts_path'}."/$d";
|
|
$lnum=0;
|
|
open(FILESCR, $file_scr);
|
|
while (<FILESCR>) {
|
|
if (/^$config{'mon_title'}/ && $lnum gt 0 ) {
|
|
$title=$_;
|
|
$title=~s/$config{'mon_title'}//;
|
|
$script_list{$d} = {
|
|
'desc' => $title,
|
|
'name' => $d
|
|
};
|
|
last;
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILESCR);
|
|
}
|
|
# }
|
|
closedir(DIR);
|
|
# @script_list= sort { $a->{'desc'} cmp $b->{'desc'} } @script_list;
|
|
return %script_list;
|
|
}
|
|
|
|
# Returns an array of hashtable, each containing info about one file. Each hash
|
|
# will always contain the keys "alias" "name", etc
|
|
sub list_files
|
|
{
|
|
# read the filelist from file
|
|
local ($wherepath); $wherepath = $_[0];
|
|
local ($ls_match); $ls_match = $_[1];
|
|
local ($temp_f, $elem);
|
|
local (%rv, $_, $lnum, @lin);
|
|
local ($f_perm , $f_lsnum, $f_owner, $f_group, $f_size, $f_month);
|
|
local ($f_day, $f_time, $f_name);
|
|
local $pos=0;
|
|
|
|
$no_out=1;
|
|
$temp_f = &tempname();
|
|
$str=`(cd $wherepath ; ls -lrt $ls_match >$temp_f) 2>/dev/null`;
|
|
&webmin_log("list", $wherepath, $config{run_exec_user}, "$str");
|
|
# if ( $str) {
|
|
$lnum = 0;
|
|
open(FILELIST, $temp_f);
|
|
while(<FILELIST>) {
|
|
s/\r|\n//g;
|
|
@lin = split(/ /, $_, -1);
|
|
$pos=0;
|
|
$ifield=0;
|
|
foreach $elem (@lin) {
|
|
if ( $elem ne "" ) {
|
|
if ( $pos eq 0 ) { $f_perm=$elem; }
|
|
if ( $pos eq 1 ) { $f_lsnum=$elem; }
|
|
if ( $pos eq 2 ) { $f_owner=$elem; }
|
|
if ( $pos eq 3 ) { $f_group=$elem; }
|
|
if ( $pos eq 4 ) { $f_size=$elem; }
|
|
if ( $pos eq 5 ) { $f_month=$elem; }
|
|
if ( $pos eq 6 ) { $f_day=$elem; }
|
|
if ( $pos eq 7 ) { $f_time=$elem; }
|
|
if ( $pos eq 8 ) { $f_name=$elem; }
|
|
$pos++;
|
|
}
|
|
$ifield++;
|
|
}
|
|
$rv{$f_name} = {
|
|
'perm' => $f_perm , 'lsnum' => $f_lsnum,
|
|
'owner' => $f_owner, 'group' => $f_group,
|
|
'size' => $f_size, 'month' => $f_month,
|
|
'day' => $f_day, 'time' => $f_time,
|
|
'name' => $f_name
|
|
};
|
|
$lnum++;
|
|
}
|
|
close(FILELIST);
|
|
# }
|
|
return %rv;
|
|
}
|
|
# list_countsess()
|
|
sub list_countsess
|
|
{
|
|
# read the countsess list file
|
|
local(%rv, $_, $lnum, @lin, $datetime_tilte);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading COUNTSESS File List
|
|
$lnum = 0;
|
|
$datetime_title="#datetime: ";
|
|
open(COUNTSESSFILE, $config{'countsessout_file'});
|
|
while(<COUNTSESSFILE>) {
|
|
s/\r|\n//g;
|
|
if (/^$datetime_title/ && $lnum eq 0 ) {
|
|
$counter_time=$_;
|
|
$counter_time=~ s/$datetime_title//g;
|
|
}
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'objalias' => $lin[0] ,
|
|
'numsess' => $lin[1],
|
|
'descrip' => $lin[2] ,
|
|
'name' => $lin[3] ,
|
|
'alias' => $lin[4] ,
|
|
'maxsess' => $lin[5] ,
|
|
'objgrpalias' => $lin[6] ,
|
|
'grpalias' => $lin[7],
|
|
'obj' => $lin[8]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(COUNTSESSFILE);
|
|
return %rv;
|
|
}
|
|
|
|
# list_totalsess()
|
|
sub list_totalsess
|
|
{
|
|
# read the totalsess list file
|
|
local(%rv, $_, $lnum, @lin, $datetime_tilte);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading TOTALSESS File List
|
|
$lnum = 0;
|
|
$datetime_title="#datetime: ";
|
|
open(TOTALSESSFILE, $config{'totalsessout_file'});
|
|
while(<TOTALSESSFILE>) {
|
|
s/\r|\n//g;
|
|
if (/^$datetime_title/ && $lnum eq 0 ) {
|
|
$totalcounter_time=$_;
|
|
$totalcounter_time=~ s/$datetime_title//g;
|
|
}
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'objalias' => $lin[0] ,
|
|
'numsess' => $lin[1],
|
|
'descrip' => $lin[2] ,
|
|
'name' => $lin[3] ,
|
|
'alias' => $lin[4] ,
|
|
'maxsess' => $lin[5] ,
|
|
'objgrpalias' => $lin[6] ,
|
|
'grpalias' => $lin[7],
|
|
'obj' => $lin[8]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(TOTALSESSFILE);
|
|
return %rv;
|
|
}
|
|
|
|
# load_tta_emulses($temp_f)
|
|
# Returns an array of hashtable, each containing info about one webtop. Each hash
|
|
# will always contain the keys "alias" "name" "link" etc .
|
|
sub load_tta_emulses
|
|
{
|
|
# read the obj properties from file
|
|
local(@ttasess, $_, %idx, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
|
|
# start by reading from file List
|
|
$lnum = 0;
|
|
$datetime_title="#datetime: ";
|
|
open(FILETTASESS, $temp_f);
|
|
while(<FILETTASESS>) {
|
|
s/\r|\n//g;
|
|
if (/^$datetime_title/ && $lnum eq 0 ) {
|
|
$ttasess_time=$_;
|
|
$ttasess_time=~ s/$datetime_title//g;
|
|
if ( "$_[0]" eq "getdate" ) { last; };
|
|
}
|
|
if (/\S/ && !/^[#\+\-]/ && $lnum gt 0 ) {
|
|
@lin = split(/: /, $_, -1);
|
|
$lin[1]=~ s/"//g;
|
|
# $is_space=chop($lin[1]);
|
|
# if ( $is_space eq " " ) { chop($lin[1]); }
|
|
push(@ttasess, { 'property' => $lin[0],
|
|
'value' => $lin[1],
|
|
'num' => scalar(@ttasess) });
|
|
$idx{$lin[0]} = $ttasess[$#ttasess];
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILETTASESS);
|
|
return @ttasess;
|
|
}
|
|
|
|
# load_brandinfo()
|
|
# Returns an array of hashtable, each containing info about one ou. Each hash
|
|
sub load_brandinfo
|
|
{
|
|
# read the brand list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading brand File List
|
|
$lnum = 0;
|
|
open(FILEBRAND, "$root_directory/$module_name/.brandinfofile");
|
|
while(<FILEBRAND>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'fname' => $lin[0],
|
|
'brand' => $lin[1],
|
|
'size' => $lin[2],
|
|
'descrip' => $lin[3]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILEBRAND);
|
|
return %rv;
|
|
}
|
|
|
|
# list_sysusers()
|
|
# Returns an array of hashtable, each containing info about one ou. Each hash
|
|
# will always contain the keys "alias" "name" "sysuser"
|
|
sub list_sysusers
|
|
{
|
|
# read the SYSUSER list file
|
|
local(%rv, $_, $lnum, @lin);
|
|
local $pos=0;
|
|
if ( $_[0] ) { $pos=$_[0] };
|
|
# start by reading SYSUSER File List
|
|
$lnum = 0;
|
|
open(FILESYSUSERS, $config{'sysusers_list'});
|
|
while(<FILESYSUSERS>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/::/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'name' => $lin[0],
|
|
'grpalias' => $lin[1],
|
|
'ens' => $lin[2],
|
|
'maxsess' => $lin[3],
|
|
'email' => $lin[4],
|
|
'where' => $lin[5]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILESYSUSERS);
|
|
return %rv;
|
|
}
|
|
|
|
# load_tabdef()
|
|
# Returns an array of hashtable, each containing info about one ou. Each hash
|
|
# will always contain the keys "alias" "name"
|
|
sub load_tabdef
|
|
{
|
|
# read the table def list file
|
|
local( $_, $lnum, @lin);
|
|
local %rv=();
|
|
local $pos=0;
|
|
local $basePath="$root_directory/$module_name/lang/sttatables/defs";
|
|
local $filePath="";
|
|
if ( -r "$basePath/$current_lang/$_[0]" ) {
|
|
$filePath="$basePath/$current_lang/$_[0]";
|
|
} else {
|
|
foreach $l (@lang_order_list) {
|
|
next if ( "$l" eq "$current_lang");
|
|
if ( -r "$basePath/$l/$_[0]" ) {
|
|
$filePath="$basePath/$l/$_[0]";
|
|
}
|
|
}
|
|
}
|
|
if ( "$filePath" eq "" ) { return %rv };
|
|
if ( $_[1] ) { $pos=$_[1] };
|
|
# start by reading def File List
|
|
$lnum = 0;
|
|
open(FILETABDEF, $filePath);
|
|
while(<FILETABDEF>) {
|
|
s/\r|\n//g;
|
|
if (/\S/ && !/^[#\+\-]/) {
|
|
@lin = split(/\|/, $_, -1);
|
|
$rv{$lin[$pos]} = {
|
|
'alias' => $lin[0],
|
|
'pos' => $lin[1],
|
|
'name' => $lin[2],
|
|
'help' => $lin[3],
|
|
'descrip' => $lin[4],
|
|
'range' => $lin[5],
|
|
'target' => $lin[6],
|
|
'mandatory' => $lin[7],
|
|
'comments' => $lin[8]
|
|
};
|
|
}
|
|
$lnum++;
|
|
}
|
|
close(FILETABDEF);
|
|
return %rv;
|
|
}
|
|
|
|
# out_objslist( $task, $cginame, $obj-type, $var-path-list, $key-list, $line_obj, $hash-list )
|
|
sub out_objslist
|
|
{
|
|
local $tasklist=$_[0];
|
|
local $cginame=$_[1];
|
|
local $objs_type=$_[2];
|
|
local $objs_path=$_[3];
|
|
local $list_key=$_[4];
|
|
local $line_obj=$_[5];
|
|
local %h_objs=%{$_[6]};
|
|
local @listobjs=();
|
|
local @list__objs=();
|
|
local $str="";
|
|
local $msg="";
|
|
local $linitem="";
|
|
local %h_line=$h_objs{$list_key};
|
|
local @libObj=();
|
|
local $ens_grp=$h_objs{$list_key}->{'ens'};
|
|
local $dn_grp=$h_objs{$list_key}->{'obj'};
|
|
|
|
&webmin_log($config{$objs_path}, "$objs_type", "$tasklist",$h_objs{$list_key});
|
|
if ( $tasklist eq "add" ) {
|
|
open(OBJSFILELIST, ">>$config{$objs_path}");
|
|
} else {
|
|
if ( $cginame eq "mvobjs.cgi" ) {
|
|
@linObj = split(/::/, $line_obj, -1);
|
|
if ( $main::task eq "move" ) {
|
|
$h_objs{$list_key}->{'ens'}=$linObj[3];
|
|
@lin = split(/\//, $linObj[3], -1);
|
|
local $base_ensobj="";
|
|
for ( $i=0 ; $i< $#lin; $i++ ) {
|
|
if ( $i > 0 ) { $base_ensobj .="/"; }
|
|
$base_ensobj .= $lin[$i];
|
|
}
|
|
$h_objs{$list_key}->{'obj'}=$linObj[2];
|
|
$lin[$#lin]=~ s/ou=//g;
|
|
$lin[$#lin]=~ s/cn=//g;
|
|
$h_objs{$list_key}->{'name'}=$lin[$#lin];
|
|
$h_objs{$list_key}->{'descrip'}=$lin[$#lin];
|
|
@lin = split(/,/, $linObj[2], -1);
|
|
local $base_obj="";
|
|
for ( $i=1 ; $i< $#lin+1; $i++ ) {
|
|
if ( $i > 1 ) { $base_obj .=","; }
|
|
$base_obj .=$lin[$i];
|
|
}
|
|
if ( $linObj[1] ne "" ) { $h_objs{$list_key}->{'grpalias'}=$linObj[1]; }
|
|
local $newalias=$linObj[4];
|
|
if ( $newalias ne "" ) {
|
|
$h_objs{$newalias}=$h_objs{$list_key};
|
|
$h_objs{$newalias}->{'alias'}=$newalias;
|
|
delete $h_objs{$list_key};
|
|
}
|
|
foreach $item (keys (%h_objs)) {
|
|
if ( $h_objs{$item}->{'grpalias'} eq $linObj[1] ) {
|
|
@lin = split(/\//, $h_objs{$item}->{ens}, -1);
|
|
$h_objs{$item}->{'ens'}=$base_ensobj."/".$lin[$#lin];
|
|
@lin = split(/,/, $h_objs{$item}->{obj}, -1);
|
|
$h_objs{$item}->{'obj'}=$lin[0].",".$base_obj;
|
|
}
|
|
if ( $objs_type eq "ou" || $objs_type eq "grpapps" || $objs_type eq "grphosts" ) {
|
|
if ( $ens_grp ne "" && $h_objs{$item}->{'ens'} =~ /$ens_grp/ ) {
|
|
@lin = split(/\//, $h_objs{$item}->{ens}, -1);
|
|
$h_objs{$item}->{'ens'}=$linObj[3]."/".$lin[$#lin];
|
|
}
|
|
if ( $dn_grp ne "" && $h_objs{$item}->{'obj'} =~ /$dn_grp/ ) {
|
|
@lin = split(/,/, $h_objs{$item}->{obj}, -1);
|
|
$h_objs{$item}->{'obj'}=$lin[0].",".$linObj[2];
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
local $newalias=$linObj[4];
|
|
$h_objs{$newalias}->{'ens'}=$linObj[3];
|
|
@lin = split(/\//, $linObj[3], -1);
|
|
$lin[$#lin]=~ s/ou=//g;
|
|
$lin[$#lin]=~ s/cn=//g;
|
|
$h_objs{$newalias}->{'name'}=$lin[$#lin];
|
|
$h_objs{$newalias}->{'descrip'}=$lin[$#lin];
|
|
$h_objs{$newalias}->{'obj'}=$linObj[2];
|
|
$h_objs{$newalias}->{'alias'}=$newalias;
|
|
if ( $objs_type eq "ou" ) {
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
}
|
|
if ( $objs_type eq "apps" ) {
|
|
$h_objs{$newalias}->{'grpalias'}=$h_objs{$list_key}->{'grpalias'};
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
$h_objs{$newalias}->{'apptype'}=$h_objs{$list_key}->{'apptype'};
|
|
}
|
|
if ( $objs_type eq "grpapps" ) {
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
}
|
|
if ( $objs_type eq "hosts" ) {
|
|
$h_objs{$newalias}->{'grpalias'}=$h_objs{$list_key}->{'grpalias'};
|
|
$h_objs{$newalias}->{'ipname'}=$h_objs{$list_key}->{'ipname'};
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
$h_objs{$newalias}->{'portalive'}=$h_objs{$list_key}->{'portalive'};
|
|
}
|
|
if ( $objs_type eq "grphosts" ) {
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
}
|
|
if ( $objs_type eq "domains" ) {
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
}
|
|
if ( $objs_type eq "links" ) {
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
}
|
|
if ( $objs_type eq "sysusers" ) {
|
|
$h_objs{$newalias}->{'grpalias'}=$h_objs{$list_key}->{'grpalias'};
|
|
$h_objs{$newalias}->{'maxsess'}=$h_objs{$list_key}->{'maxsess'};
|
|
$h_objs{$newalias}->{'email'}=$h_objs{$list_key}->{'email'};
|
|
$h_objs{$newalias}->{'where'}=$h_objs{$list_key}->{'where'};
|
|
}
|
|
if ( $objs_type eq "acts" ) {
|
|
$h_objs{$newalias}->{'target'}=$h_objs{$list_key}->{'target'};
|
|
$h_objs{$newalias}->{'object'}=$h_objs{$list_key}->{'object'};
|
|
$h_objs{$newalias}->{'condition'}=$h_objs{$list_key}->{'condition'};
|
|
$h_objs{$newalias}->{'conditionValue'}=$h_objs{$list_key}->{'conditionValue'};
|
|
$h_objs{$newalias}->{'action'}=$h_objs{$list_key}->{'action'};
|
|
$h_objs{$newalias}->{'script'}=$h_objs{$list_key}->{'script'};
|
|
$h_objs{$newalias}->{'when'}=$h_objs{$list_key}->{'when'};
|
|
$h_objs{$newalias}->{'how'}=$h_objs{$list_key}->{'how'};
|
|
}
|
|
if ( $objs_type eq "profcache" ) {
|
|
$h_objs{$newalias}->{'hostusername'}=$h_objs{$list_key}->{'hostusername'};
|
|
$h_objs{$newalias}->{'hostname'}=$h_objs{$list_key}->{'hostname'};
|
|
$h_objs{$newalias}->{'usergrphosts'}=$h_objs{$list_key}->{'usergrphosts'};
|
|
$h_objs{$newalias}->{'username'}=$h_objs{$list_key}->{'username'};
|
|
$h_objs{$newalias}->{'userou'}=$h_objs{$list_key}->{'userou'};
|
|
}
|
|
if ( $objs_type eq "hostsuser" ) {
|
|
$h_objs{$newalias}->{'username'}=$h_objs{$list_key}->{'username'};
|
|
$h_objs{$newalias}->{'passwd'}=$h_objs{$list_key}->{'passwd'};
|
|
}
|
|
if ( $linObj[1] ne "" ) { $h_objs{$newalias}->{'grpalias'}=$linObj[1]; }
|
|
}
|
|
} else {
|
|
delete $h_objs{$list_key};
|
|
}
|
|
foreach $item (keys (%h_objs)) { push (@listobjs,$h_objs{$item}); }
|
|
@list__objs = sort {$a->{'name'} cmp $b->{'name'}} @listobjs;
|
|
&lock_file($config{$objs_path});
|
|
open(OBJSFILELIST, ">$config{$objs_path}");
|
|
foreach $item (@list__objs) {
|
|
if ( $objs_type eq "ou" || $objs_type eq "grpapps" || $objs_type eq "grphosts" ) {
|
|
if ( $ens_grp ne "" && $item->{'ens'} =~ /$ens_grp/ ) {
|
|
next if ( $tasklist eq "delete" && $cginame ne "mvobjs.cgi" );
|
|
}
|
|
}
|
|
if ( $objs_type eq "ou" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'obj'}."::".$item->{'ens'}."::".
|
|
$item->{'maxsess'}."::".$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "apps" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'grpalias'}."::".$item->{'obj'}."::".
|
|
$item->{'ens'}."::".$item->{'maxsess'}."::".
|
|
$item->{'apptype'}."::".
|
|
$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "grpapps" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'obj'}."::".$item->{'ens'}."::".
|
|
$item->{'maxsess'}."::".$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "hosts" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'grpalias'}."::".$item->{'obj'}."::".
|
|
$item->{'ens'}."::".$item->{'ipname'}."::".
|
|
$item->{'maxsess'}."::".$item->{'portalive'}."::".
|
|
$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "grphosts" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'obj'}."::".$item->{'ens'}."::".
|
|
$item->{'maxsess'}."::".$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "domains" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'obj'}."::".$item->{'ens'}."::".
|
|
$item->{'maxsess'}."::".$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "links" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'obj'}."::".$item->{'ens'}."::".
|
|
$item->{'maxsess'}."::".$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "sysusers" ) {
|
|
$linitem=$item->{'name'}."::".$item->{'grpalias'}."::".
|
|
$item->{'ens'}."::".$item->{'maxsess'}."::".
|
|
$item->{'email'}."::".$item->{'where'}."::";
|
|
}
|
|
if ( $objs_type eq "acts" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'target'}."::".$item->{'object'}."::".
|
|
$item->{'condition'}."::".$item->{'conditionValue'}."::".
|
|
$item->{'action'}."::".$item->{'script'}."::".
|
|
$item->{'when'}."::".$item->{'how'}."::";
|
|
}
|
|
if ( $objs_type eq "profcache" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'hostusername'}."::".$item->{'hostname'}."::".
|
|
$item->{'usergrphosts'}."::".$item->{'username'}."::".
|
|
$item->{'userou'}."::";
|
|
}
|
|
if ( $objs_type eq "hostsuser" ) {
|
|
$linitem=$item->{'username'}."::".$item->{'passwd'}."::".
|
|
$item->{'name'}."::";
|
|
OA
|
|
}
|
|
print OBJSFILELIST "$linitem\n";
|
|
}
|
|
}
|
|
if ( $tasklist ne "delete" && $cginame ne "mvobjs.cgi" ) { print OBJSFILELIST "$line_obj\n"; }
|
|
close (OBJSFILELIST);
|
|
&unlock_file($config{$objs_path});
|
|
$msg='user_'.$tasklist;
|
|
if ( $tasklist eq "add" ) { $msg="user_made"; };
|
|
$str=$text{$msg}.$list_key." -> ".$list_key;
|
|
&additional_log($cginame, "$objs_type", "$str");
|
|
&webmin_log($config{$objs_path}, "$objs_type", "$tasklist",$line_obj);
|
|
$str=$objs_type."_list";
|
|
&remote_file("write",$config{$objs_path},$str);
|
|
if ( $cginame ne "mvobjs.cgi" && $tasklist ne "delete" ) { return };
|
|
if ( $cginame eq "mvobjs.cgi" && $main::task ne "move" ) { return };
|
|
@listobjs=();
|
|
if ( $objs_type eq "grpapps" ) {
|
|
%h_objs=&list_apps();
|
|
$objs_type="apps";
|
|
$objs_path='apps_list';
|
|
} elsif ( $objs_type eq "grphosts" ) {
|
|
%h_objs=&list_hosts();
|
|
$objs_type="hosts";
|
|
$objs_path='hosts_list';
|
|
} elsif ( $objs_type eq "ou" && $config{'has_systemusers'} eq "true") {
|
|
# Cleaning sysusers_list to delete users belonging to $userou
|
|
%h_objs=&list_sysusers();
|
|
$objs_type="sysusers";
|
|
$objs_path='sysusers_list';
|
|
} else { return };
|
|
if ( $cginame eq "mvobjs.cgi" && $main::task eq "move" ) { $list_key = "move" };
|
|
if ( $cginame ne "mvobjs.cgi" && $main::task ne "move" ) { delete $h_objs{$list_key}; }
|
|
foreach $item (keys (%h_objs)) { push (@listobjs,$h_objs{$item}); }
|
|
@list__objs = sort {$a->{'name'} cmp $b->{'name'}} @listobjs;
|
|
&lock_file($config{$objs_path});
|
|
open(OBJSFILELIST, ">$config{$objs_path}");
|
|
foreach $item (@list__objs) {
|
|
if ( $cginame eq "mvobjs.cgi" && $main::task eq "move" ) {
|
|
if ( $item->{'grpalias'} eq $linObj[0] ) {
|
|
@lin = split(/\//, $item->{ens}, -1);
|
|
$item->{'ens'}=$linObj[3]."/".$lin[$#lin];
|
|
@lin = split(/,/, $item->{obj}, -1);
|
|
$item->{'obj'}=$lin[0].",".$linObj[2];
|
|
if ( $newalias ne "" ) { $item->{'grpalias'}=$newalias; }
|
|
}
|
|
}
|
|
if ( $item->{'grpalias'} ne $list_key || $list_key eq "move" ) {
|
|
if ( $ens_grp ne "" && $item->{'ens'} =~ /$ens_grp/ ) {
|
|
next if ( $tasklist eq "delete" && $cginame ne "mvobjs.cgi" );
|
|
$item->{'ens'}=~ s/^$ens_grp/$linObj[3]/g;
|
|
}
|
|
if ( $dn_grp ne "" && $item->{'obj'} =~ /$dn_grp/ ) {
|
|
next if ( $tasklist eq "delete" && $cginame ne "mvobjs.cgi" );
|
|
$item->{'obj'}=~ s/$dn_grp$/$linObj[2]/g;
|
|
}
|
|
if ( $objs_type eq "apps" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'grpalias'}."::".$item->{'obj'}."::".
|
|
$item->{'ens'}."::".$item->{'maxsess'}."::".
|
|
$item->{'apptype'}."::".
|
|
$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "hosts" ) {
|
|
$linitem=$item->{'alias'}."::".$item->{'name'}."::".
|
|
$item->{'grpalias'}."::".$item->{'obj'}."::".
|
|
$item->{'ens'}."::".$item->{'ipname'}."::".
|
|
$item->{'maxsess'}."::".$item->{'portalive'}."::".
|
|
$item->{'descrip'}."::";
|
|
}
|
|
if ( $objs_type eq "sysusers" ) {
|
|
$linitem=$item->{'name'}."::".$item->{'grpalias'}."::".
|
|
$item->{'ens'}."::".$item->{'maxsess'}."::".
|
|
$item->{'email'}."::".$item->{'where'}."::";
|
|
}
|
|
print OBJSFILELIST "$linitem\n";
|
|
} else {
|
|
&webmin_log($config{$objs_path}, "$objs_type",
|
|
"$tasklist $_[2] $list_key",@item);
|
|
}
|
|
}
|
|
close (OBJSFILELIST);
|
|
&unlock_file($config{$objs_path});
|
|
$msg='user_'.$tasklist;
|
|
if ( $tasklist eq "add" ) { $msg="user_made"; };
|
|
$str=$text{$msg}.$list_key." -> ".$list_key;
|
|
&additional_log($cginame, "$objs_type", "$str");
|
|
&webmin_log($config{$objs_path}, "$objs_type", "$tasklist $_[2]","$list_key");
|
|
$str=$objs_type."_list";
|
|
&remote_file("write",$config{$objs_path},$str);
|
|
}
|
|
1; # Return true
|