#!/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-2003 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.3pre1047667856- [2003_3_14_195056]

# 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;
}
# 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=();

   &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=$linObj[3];
                $base_ensobj=~ s/\/$lin[$#lin]$//g;
                $h_objs{$list_key}->{'obj'}=$linObj[2];
                @lin = split(/,/, $linObj[2], -1);
                local $base_obj=$linObj[2];
                $base_obj=~ s/^$lin[0],//g;
#print "$lin[0] -- $base_obj -- $linObj[2] -- <br>";
                if ( $linObj[1] ne "" ) { $h_objs{$list_key}->{'grpalias'}=$linObj[1]; }
                local $newalias=$linObj[4];
                if ( $newalias ne "" ) {
                     $h_objs{$newalias}=$h_obj{$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] ) {
#print $h_objs{$item}->{'grpalias'}." eq ".$linObj[1]."<br>";
#print $h_objs{$item}->{'alias'}." eq ".$linObj[0]." eq $list_key<br>";
	                 @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;
                    }
               }
             } else {
                local $newalias=$linObj[4];
                $h_objs{$newalias}=$h_obj{$list_key};
                $h_objs{$newalias}->{'ens'}=$linObj[3];
                $h_objs{$newalias}->{'obj'}=$linObj[2];
                if ( $linObj[1] ne "" ) { $h_objs{$newalias}->{'grpalias'}=$linObj[1]; }
                $h_objs{$newalias}->{'alias'}=$newalias;
             }
        } 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" ) {
		        $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->{'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 ( $item->{'grpalias'} ne $list_key ||  $list_key eq "move" ) {
                      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->{'descrip'}."::";
                      }
                      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
