#!/usr/bin/perl
# fixobjs.cgi
# ...  Services with Tarantella.
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

require './stta-lib.pl';
&ReadParse();
$objtype=$in{obj} || ""; 
if ( $objtype eq "" ) { &redirect("fixobjs.cgi"); }
&headerstta("$text{'index_fixlists'}->$obj", "", "mod-$obj",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
print "<hr><p>\n"; 

 $listObjs=$objtype."_list";

 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>Fix $listObjs</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

 if ( $objtype eq "ou" || $objectype eq "users" ) { 
      %h_objs=&list_ous();
 } else { %h_objs=eval("\&list_$objtype()"); }
 foreach $item (keys (%h_objs)) { push (@listobjs, $h_objs{$item}); }
 @list__objs = sort {$a->{'name'} cmp $b->{'name'}} @listobjs;
 &lock_file($config{$listObjs});
 open(FILEOBJS, ">$config{$listObjs}");
     foreach $item (@list__objs) {
                 if ( $item->{'descrip'} eq "" ) {
                      $item->{'descrip'} = $item->{'name'};
                 } 
                 if ( $objtype eq "ou" ) {
		        $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                                 $item->{'obj'}."::".$item->{'ens'}."::".
                                 $item->{'maxsess'}."::".$item->{'descrip'}."::";
                 }
                 if ( $objtype eq "apps" ) {
                      $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                               $item->{'grpalias'}."::".$item->{'obj'}."::".
                               $item->{'ens'}."::".$item->{'maxsess'}."::".
                               $item->{'apptype'}."::".
                               $item->{'descrip'}."::";
                 }
                 if ( $objtype eq "grpapps" ) {
                      $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                               $item->{'obj'}."::".$item->{'ens'}."::".
                               $item->{'maxsess'}."::".$item->{'descrip'}."::";
                 }
                 if ( $objtype eq "hosts" ) {
                      $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                               $item->{'grpalias'}."::".$item->{'obj'}."::".
                               $item->{'ens'}."::".$item->{'ipname'}."::".
                               $item->{'maxsess'}."::".$item->{'portalive'}."::".
                               $item->{'descrip'}."::";
                 }
                 if ( $objtype eq "grphosts" ) {
                      $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                               $item->{'obj'}."::".$item->{'ens'}."::".
                               $item->{'maxsess'}."::".$item->{'descrip'}."::";
                 }
                 if ( $objtype eq "domains" ) {
                        $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                                 $item->{'obj'}."::".$item->{'ens'}."::".
                                 $item->{'maxsess'}."::".$item->{'descrip'}."::";
                 }
                 if ( $objtype eq "links" ) {
	                $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                                 $item->{'obj'}."::".$item->{'ens'}."::".
                                 $item->{'maxsess'}."::".$item->{'descrip'}."::";
                 }
                 if ( $objtype eq "sysusers" ) {
                        $linitem=$item->{'name'}."::".$item->{'grpalias'}."::".
                                 $item->{'ens'}."::".$item->{'maxsess'}."::".
                                 $item->{'email'}."::".$item->{'where'}."::";
                 }
                 if ( $objtype eq "acts" ) {
                        $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                                 $item->{'target'}."::".$item->{'object'}."::".
                                 $item->{'condition'}."::".$item->{'conditionValue'}."::".
                                 $item->{'action'}."::".$item->{'script'}."::".
                                 $item->{'when'}."::".$item->{'how'}."::";
                 }
                 if ( $objtype eq "profcache" ) {
                        $linitem=$item->{'alias'}."::".$item->{'name'}."::".
                                 $item->{'hostusername'}."::".$item->{'hostname'}."::".
                                 $item->{'usergrphosts'}."::".$item->{'username'}."::".
                                 $item->{'userou'}."::";
                 }
                 if ( $objtype eq "hostsuser" ) {
    		        $linitem=$item->{'username'}."::".$item->{'passwd'}."::".
                                  $item->{'name'}."::";
                 }
                 print FILEOBJS "$linitem\n";
     }
  close (FILEOBJS);
  &unlock_file($config{$listObjs});
  print "<tr><p><b>".$text{'user_update'}." $listObjs  </b></tr>\n";
  print "<tr></tr>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;

